From: Daniel Axtens Date: Mon, 28 Mar 2011 15:53:27 +0000 (+0800) Subject: DPI support and detection X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=3d2d99e7b6ce1522ad2c30ccfe24d3271c68cb47;p=dja%2Fscandal.git DPI support and detection --- diff --git a/scan2pages.sh b/scan2pages.sh index 45f6215..995c5a6 100755 --- a/scan2pages.sh +++ b/scan2pages.sh @@ -8,6 +8,7 @@ each with only one page. OPTIONS: -v: Be verbose. -d depth: Use given depth. Default is 1. Unpaper can only handle up to 8. + -D dpi: Use given DPI. Colour scans on library scanners are usually 300, bw 400. -s: skip masking/trimming. Overrides -m. -f: Forceably redo everything. -p: Forceably redo pdf conversion. Implies options below, equivalent to -f. @@ -34,15 +35,20 @@ forceclean= convertflags= unpaperflags= depthflags="-depth 1" +dpi= skipmask= +verbose= while getopts 'vd:sfpmuc' OPTION do case $OPTION in - v) convertflags="$convertflags -verbose" + v) verbose=1 + convertflags="$convertflags -verbose" unpaperflags="$unpaperflags -v --time" ;; d) depthflags="-depth $OPTARG" ;; + D) dpi=$OPTARG + ;; s) skipmask=1; ;; f) forcepdf=1; forcemask=1; forceunpaper=1; forceclean=1 @@ -88,6 +94,23 @@ pages=$(awk '$1 ~ "%%Pages" {print $2}' $dscname) echo "Got $pages page(s)." rm $dscname +# guess at DPI, unless it's been set +# the scans do not seem to accurately reflect their resolution. +if [[ "$dpi" = "" ]]; then + # %k gives the number of colours/shades in the image. + # 2 for b/w, and the scanner seems to default to 400 dpi for that + # 256 for greyscale, which has to be selected manually (so I'm assuming 300 for no good reason) + # 31564 for colour, which defaults to 300 + if [[ $( convert $file[0] -format "%k" info: || exit 1 ) == 2 ]]; then + dpi=400; + else + dpi=300 + fi + if [[ $verbose == 1 ]]; then + echo "DPI guessed at $dpi." + fi +fi + # process pages 1 by 1 to avoid convert gobbling all the memory for pg in `$my_seq 1 $pages`; do echo "Processing page $pg." @@ -97,7 +120,7 @@ for pg in `$my_seq 1 $pages`; do # convert from pdf origpnm=$dir/pg-${pgn}.pnm if [[ ! $([ -e $origpnm ]) || $forcepdf ]]; then - convert $convertflags $depthflags -density 300 $file[$(expr $pg - 1)] \ + convert $convertflags $depthflags -density $dpi $file[$(expr $pg - 1)] \ $origpnm || exit 1 fi;