]> Sergey Matveev's repositories - dotfiles.git/blob - bin/bin/scan.sh
Have not used zshfe for years
[dotfiles.git] / bin / bin / scan.sh
1 #!/bin/sh
2
3 rotate=0
4 crop=0
5 cur=noname.ppm
6 ctr=${1:-1}
7 ctr=$(( $ctr - 1 ))
8
9 scan() {
10     preview=$1
11     shift
12     [ -z "$NEGATIVE" ] && src="Flatbed" || src="Transparency Adapter"
13     [ -z "$NEGATIVE" ] && depth=8 || depth=16
14     [ -z "$NEGATIVE" ] && resolution=800 || resolution=1600
15     if [ "$preview" = "yes" ]; then
16         depth=8
17         resolution=150
18     fi
19     scanimage \
20         --format=pnm \
21         --mode=Color \
22         --depth $depth \
23         --progress \
24         --resolution=$resolution \
25         --source="$src" \
26         $@ > tmp.ppm
27 }
28
29 process() {
30     [ $rotate -eq 0 ] && rotator=cat || rotator="pamflip -rotate$rotate"
31     [ -z "$NEGATIVE" ] && inverter=cat || inverter=pnminvert
32     $rotator | pnmcrop -closeness=$crop | $inverter
33 }
34
35 preview() {
36     process < tmp.ppm | pamdepth 255 | pnmscale -w 600 > preview.ppm
37     sxiv preview.ppm
38 }
39
40 do_next() {
41     rotate=180
42     [ -z "$NEGATIVE" ] && crop=40 || crop=10
43     ctr=$(( $ctr + 1 ))
44     cur=`printf "%03d.ppm" $ctr`
45 }
46
47 do_next
48
49 while : ; do
50     echo -n "$cur: crop:$crop rotate:$rotate v/r/c/s/p/n> "
51     read c
52     case $c in
53     v)
54         scan yes --preview=yes
55         preview
56         ;;
57     s)
58         scan no --preview=no --high-quality=yes
59         preview
60         ;;
61     p)
62         preview
63         ;;
64     n)
65         cat tmp.ppm | process > $cur
66         do_next
67         ;;
68     r)
69         echo -n "Rotate (n/r/l/t):"
70         read rotate
71         case $rotate in
72         n) rotate=180 ;;
73         r) rotate=90 ;;
74         l) rotate=270 ;;
75         t) rotate=0 ;;
76         *) echo ? ;;
77         esac
78         ;;
79     c)
80         echo -n Crop:
81         read crop
82         ;;
83     *)
84         echo ?
85         ;;
86     esac
87 done