]> Sergey Matveev's repositories - dotfiles.git/blobdiff - bin/bin/scan.sh
Huge tmux-fzf simplification with files quoting
[dotfiles.git] / bin / bin / scan.sh
index e32f998594dd65e5be6ad5cd99d34cc8083938dd..d5c905feb48c57a1a4edf10e872f9ebd733ec30b 100755 (executable)
@@ -6,28 +6,40 @@ cur=noname.ppm
 ctr=${1:-1}
 ctr=$(( $ctr - 1 ))
 
-[ -z "$NEGATIVE" ] && SRC="Flatbed" || SRC="Transparency Adapter"
-
 scan() {
-    resolution=$1
+    preview=$1
     shift
-    scanimage --format=pnm --mode=Color --depth 16 --progress --resolution=$resolution --source="$SRC" $@ > tmp.ppm
+    [ -z "$NEGATIVE" ] && src="Flatbed" || src="Transparency Adapter"
+    [ -z "$NEGATIVE" ] && depth=8 || depth=16
+    [ -z "$NEGATIVE" ] && resolution=800 || resolution=1600
+    if [ "$preview" = "yes" ]; then
+        depth=8
+        resolution=150
+    fi
+    scanimage \
+        --format=pnm \
+        --mode=Color \
+        --depth $depth \
+        --progress \
+        --resolution=$resolution \
+        --source="$src" \
+        $@ > tmp.ppm
 }
 
 process() {
-    [ -z "$NEGATIVE" ] && inverter=cat || inverter=pnminvert
     [ $rotate -eq 0 ] && rotator=cat || rotator="pamflip -rotate$rotate"
+    [ -z "$NEGATIVE" ] && inverter=cat || inverter=pnminvert
     $rotator | pnmcrop -closeness=$crop | $inverter
 }
 
 preview() {
-    pamdepth 8 < tmp.ppm | pnmscale -w 600 | process > preview.ppm
+    process < tmp.ppm | pamdepth 255 | pnmscale -w 600 > preview.ppm
     sxiv preview.ppm
 }
 
 do_next() {
     rotate=180
-    [ -z "$NEGATIVE" ] && crop=50 || crop=10
+    [ -z "$NEGATIVE" ] && crop=40 || crop=10
     ctr=$(( $ctr + 1 ))
     cur=`printf "%03d.ppm" $ctr`
 }
@@ -35,15 +47,15 @@ do_next() {
 do_next
 
 while : ; do
-    echo "$cur: (v)iew r(otate) c(rop) (s)can (p)review (n)ext"
+    echo -n "$cur: crop:$crop rotate:$rotate v/r/c/s/p/n> "
     read c
     case $c in
     v)
-        scan 150 --preview=yes
+        scan yes --preview=yes
         preview
         ;;
     s)
-        scan 1600 --preview=no --high-quality=yes
+        scan no --preview=no --high-quality=yes
         preview
         ;;
     p)
@@ -54,24 +66,14 @@ while : ; do
         do_next
         ;;
     r)
-        echo -n Rotate:
+        echo -n "Rotate (n/r/l/t):"
         read rotate
         case $rotate in
-        n)
-            rotate=180
-            ;;
-        r)
-            rotate=90
-            ;;
-        l)
-            rotate=270
-            ;;
-        t)
-            rotate=0
-            ;;
-        *)
-            echo ?
-            ;;
+        n) rotate=180 ;;
+        r) rotate=90 ;;
+        l) rotate=270 ;;
+        t) rotate=0 ;;
+        *) echo ? ;;
         esac
         ;;
     c)