-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscantool
executable file
·249 lines (225 loc) · 6.56 KB
/
scantool
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
#!/bin/bash
#
# Licensing:
#
# Copyright © Laurence Lumi 2017
# Licensed GNU General Public License v3
# which can be found here https://www.gnu.org/licenses/gpl-3.0.en.html
#
progname=`basename $0`
usage()
{
echo >&2 ""
echo >&2 "$progname:" "$@"
cat << MESSAGE1
USAGE: $progname frames | invert | both [-d] [-dd] [-n number] [-p name] [-fb R,G,B] [-dmax value] [+z] [-k] infile outfile_prefix
USAGE: $progname frames | invert | both [-d] [-dd] [-n number] [-p name] [-fb R,G,B] [-dmax value] [+z] [-k] infile1 infile2 ... outfile_prefix
USAGE: $progname [-h ] [-help]
OPTIONS:
+z zip dont zip compress the output (the default is too compress the output)
-k keep keep strips
-f fuzz threshold used for gaps between frames
MESSAGE1
exit 1
}
help()
{
echo >&2 ""
echo >&2 "$progname:" "$@"
cat >&2 << MESSAGE2
NAME: $progname
PURPOSE: to crop separate frames of a trimmed film strip
Arguments:
TODO
MESSAGE2
exit 1
}
function DEBUG()
{
[ ! "$debug" -eq 0 ] && $@
}
function cleanup {
#dont explicitly delete the mpc and cache files when in debug mode, allows the debug cache to be resused by child scripts
if [ ! -z "$tmpfileprefix" ] && [ "$debug" -eq 0 ]; then
rm -f "$tmpfileprefix"*
fi
exit 0
}
trap cleanup 0 1 2 3 6
tmpdir="./"
debug=0
tmpprefix=$tmpdir"_st_"
framenumber=1
zip="-z"
keep=0
if [ "$1" = "frames" ]; then
mode="frames"
shift
elif [ "$1" = "invert" ]; then
mode="invert"
shift
elif [ "$1" = "both" ]; then
mode="both"
shift
else
echo "must specify either frames or invert or both"
usage
fi
while [ $# -gt 0 ]
do
# get parameters
case "$1" in
-h|-help) # help information
echo ""
help
;;
-d) debug=1
;;
-dd) debug=2
v_debug="-d"
;;
-ddd) debug=3
v_debug="-d"
vv_debug="-d"
;;
-n) # number
shift
framenumber="$1"
if [[ ! "$framenumber" =~ ^[0-9]+$ ]]; then
echo "--- framenumber=$framenumber must be a integer value ---"
usage
fi
;;
-c1)
options+=" -c1"
;;
-m1)
options+=" -m1"
;;
-p) # profile name
shift
options+=" -p $1"
;;
-fb) # film base values
shift
foo=(`echo $1 |sed 's/,/\n/g'`)
for ((i=0;i<${#foo[*]};i++)); do
if [[ ! "${foo[i]}" =~ ^[0-9]+\.?[0-9]*$ ]];then
echo "--- fp=${foo[i]} must be a comma seperated positive float value ---"
usage
fi
done
options+=" -fb $1"
;;
-dmax) # dmax value
shift
dmax="$1"
if [[ ! "$dmax" =~ ^[0-9]+\.?[0-9]*$ ]] && [[ ! "$dmax" = "auto" ]];then
echo "--- dmax=$dmax must be a positive float value or auto---"
usage
fi
options+=" -dmax $1"
;;
+z)
zip="+z"
;;
-k)
keep=1
;;
-f) # fuzz
shift
fuzz="$1"
if [[ ! "$fuzz" =~ ^[0-9]+$ ]] || [ "$fuzz" -lt 0 -o "$fuzz" -gt 100 ]; then
echo "--- fuzz=$fuzz must be a positive integer value between 0 and 100 ---"
usage
fi
fuzz="-f $fuzz"
;;
-) # STDIN and end of arguments
break
;;
-*) # any other - argument
echo "--- UNKNOWN OPTION ---" $1
usage
;;
*) # end of arguments
break
;;
esac
shift # next option
done
infiles=()
for file in "$@"; do
shift
if [ -f "$file" ] && [ -r "$file" ]; then
DEBUG echo "adding $file to be processed"
infiles+=($file)
elif [ $# -eq 0 ];then
outprefix=$file
else
echo "Cannot open: $file"
exit 1
fi
done
DEBUG declare -p infiles
if [ ${#infiles[*]} -eq 0 ]; then
echo "must provide a filename"
usage
fi
if [ -z $outprefix ]; then
echo "must provide a outprefix"
usage
fi
if [ "$debug" -eq 0 ]; then
tmpfileprefix="$tmpprefix"`date +%N`_`basename "$outprefix"`
else
tmpfileprefix="$tmpprefix"debug_`basename "$outprefix"`
fi
DEBUG echo tmpfileprefix: $tmpfileprefix
DEBUG echo outprefix: $outprefix
if [ $mode = "frames" ] || [ $mode = "both" ]; then
invertfiles=()
DEBUG set -x;
for infile in "${infiles[@]}"; do
echo processing $infile
#because the strips of film will contain at some gaps the fuzz threshhold can be increased
mapfile files < <(vtrimscan vstrip $vv_debug -f 4 -t $infile $tmpfileprefix | grep CROPPING | sed 's/^CROPPING //g' )
DEBUG echo files: ${files[*]}
for ((i=0;i<${#files[*]};i++)); do
mapfile filesJ < <(vtrimscan ends $v_debug -r 90 -f 2 -t ${files[i]} | grep CROPPING | sed 's/^CROPPING //g' )
DEBUG echo files j:${filesJ[*]}
for ((j=0;j<${#filesJ[*]};j++)); do
mapfile filesK < <(vtrimscan gap $v_debug $fuzz $zip ${filesJ[j]} | grep CROPPING | sed 's/^CROPPING //g' )
DEBUG echo files k:${filesK[*]}
for ((k=0;k<${#filesK[*]};k++)); do
mkdir -p "$outprefix"
outfile="$outprefix"/"$outprefix"-`printf "%03d" "$framenumber"`.tif
framenumber=$((framenumber+1))
mv ${filesK[k]} $outfile
if [ "$debug" -gt 0 ]; then
ln -f $outfile ${filesK[k]}
fi
echo saving $outfile
invertfiles+=($outfile)
done
if [ "$keep" -eq 1 ]; then
mkdir -p "$outprefix"
outfile="$outprefix"/"$outprefix"-strip-`printf "%03d" "$stripnumber"`.tif
stripnumber=$((stripnumber+1))
mv ${filesJ[j]} $outfile
if [ "$debug" -gt 0 ]; then
ln -f $outfile ${filesJ[j]}
fi
echo saving $outfile
fi
done
done
done
fi
if [ $mode = "both" ]; then
for ((i=0;i<${#invertfiles[*]};i++)); do
mkdir -p "$outprefix"-P
outfile="$outprefix"-P/`basename ${invertfiles[i]%".tif"}-P.tif`
invertscan $options $zip ${invertfiles[i]} $outfile
done
fi