]> Sergey Matveev's repositories - dotfiles.git/blob - bin/bin/scan.sh
Less crop threshold
[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     resolution=$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     scanimage \
16         --format=pnm \
17         --mode=Color \
18         --depth $depth \
19         --progress \
20         --resolution=$resolution \
21         --source="$src" \
22         $@ > tmp.ppm
23 }
24
25 process() {
26     [ $rotate -eq 0 ] && rotator=cat || rotator="pamflip -rotate$rotate"
27     [ -z "$NEGATIVE" ] && inverter=cat || inverter=pnminvert
28     $rotator | pnmcrop -closeness=$crop | $inverter
29 }
30
31 preview() {
32     pamdepth 255 < tmp.ppm | pnmscale -w 600 | process > preview.ppm
33     sxiv preview.ppm
34 }
35
36 do_next() {
37     rotate=180
38     [ -z "$NEGATIVE" ] && crop=40 || crop=10
39     ctr=$(( $ctr + 1 ))
40     cur=`printf "%03d.ppm" $ctr`
41 }
42
43 do_next
44
45 while : ; do
46     echo "$cur: (v)iew r(otate) c(rop) (s)can (p)review (n)ext"
47     read c
48     case $c in
49     v)
50         scan 150 --preview=yes
51         preview
52         ;;
53     s)
54         scan 1600 --preview=no --high-quality=yes
55         preview
56         ;;
57     p)
58         preview
59         ;;
60     n)
61         cat tmp.ppm | process > $cur
62         do_next
63         ;;
64     r)
65         echo -n "Rotate (n/r/l/t):"
66         read rotate
67         case $rotate in
68         n) rotate=180 ;;
69         r) rotate=90 ;;
70         l) rotate=270 ;;
71         t) rotate=0 ;;
72         *) echo ? ;;
73         esac
74         ;;
75     c)
76         echo -n Crop:
77         read crop
78         ;;
79     *)
80         echo ?
81         ;;
82     esac
83 done