blob: 9c95db80d9b55abe995e42ebe3e3198f279643a0 (
plain) (
blame)
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
|
#! /bin/sh
# This script tests: pamarith
# Also requires: pamtopnm rgb3toppm pamenlarge pnmcat pamseq pbmmake pgmmake
# Also requires: ppmpat pamchannel
tmpdir=${tmpdir:-/tmp}
input1_pgm=${tmpdir}/input1.pgm
input2_pgm=${tmpdir}/input2.pgm
output_pgm=${tmpdir}/output.pgm
input1_ppm=${tmpdir}/input1.ppm
input2_ppm=${tmpdir}/input2.ppm
echo "Test 1"
pamseq 1 15 | pamtopnm -assume > ${input1_pgm}
pgmmake -maxval 15 0.15 16 1 > ${input2_pgm}
rgb3toppm ${input1_pgm} ${input1_pgm} ${input1_pgm} > ${input1_ppm}
rgb3toppm ${input2_pgm} ${input2_pgm} ${input2_pgm} > ${input2_ppm}
pnmcat -tb -plain ${input1_pgm} ${input2_pgm}
for fn in "-add" "-subtract" "-multiply" "-divide" "-difference" \
"-minimum" "-maximum" "-mean" "-compare" "-equal" \
"-and" "-or" "-nand" "-nor" "-xor" \
"-shiftleft" "-shiftright"
do
echo ${fn}
pamarith ${fn} -plain ${input1_pgm} ${input2_pgm} | tr '\n' ' '; echo
pamarith ${fn} ${input1_pgm} ${input2_pgm} > ${output_pgm}
rgb3toppm ${output_pgm} ${output_pgm} ${output_pgm} | cksum
pamarith ${fn} ${input1_ppm} ${input2_pgm} | cksum
pamarith ${fn} ${input1_ppm} ${input2_ppm} | cksum
done
rm ${input1_pgm} ${input2_pgm} ${output_pgm} ${input2_ppm}
input1_pbm=${tmpdir}/input1.pbm
input2_pbm=${tmpdir}/input2.pbm
echo "Test 2 PBM"
pbmmake -g 8 1 > ${input1_pbm}
pbmmake -g 2 1 | pamenlarge -xscale=4 > ${input2_pbm}
pnmcat -tb -plain ${input1_pbm} ${input2_pbm}
for fn in "-add" "-subtract" "-multiply" "-divide" "-difference" \
"-minimum" "-maximum" "-mean" "-compare" "-equal" \
"-and" "-or" "-nand" "-nor" "-xor" \
"-shiftleft" "-shiftright"
do
echo ${fn}
pamarith ${fn} -plain ${input1_pbm} ${input2_pbm} | tr '\n' ' '; echo
done
rm ${input1_pbm} ${input2_pbm}
echo "Test 3"
input3_ppm=${tmpdir}/input3.ppm
input4_ppm=${tmpdir}/input4.ppm
input4_pgm=${tmpdir}/input4.pgm
ppmpat -tartan -color=rgb:f0/f0/00,rgb:80/00/80,rgb:0f/00/0f 20 15 \
> ${input3_ppm}
ppmpat -argyle2 -color=rgb:01/01/01,rgb:02/02/02,rgb:05/05/05 20 15 \
> ${input4_ppm}
pamchannel -infile ${input4_ppm} 0 > ${input4_pgm}
for fn in "-add" "-multiply" "-difference" \
"-minimum" "-maximum" "-mean" "-equal" \
"-and" "-or" "-nand" "-nor" "-xor"
do
echo ${fn}
pamarith ${fn} ${input3_ppm} ${input4_ppm} | cksum
pamarith ${fn} ${input4_ppm} ${input3_ppm} | cksum
pamarith ${fn} ${input3_ppm} ${input4_pgm} | pamtopnm | cksum
done
for fn in "-subtract" "-divide" "-compare" "-shiftleft" "-shiftright"
do
echo ${fn}
pamarith ${fn} ${input3_ppm} ${input4_ppm} | cksum
pamarith ${fn} ${input3_ppm} ${input4_pgm} | pamtopnm | cksum
done
rm ${input3_ppm} ${input4_ppm} ${input4_pgm}
echo "Test 4 (input = output)"
echo "Prints 281226646 481 five times, then 2921940274 59 five times"
for image in maze.pbm ${input1_ppm}
do
echo "input image"
cat ${image} | cksum
for fn in "-minimum" "-maximum" "-mean" "-and" "-or"
do
echo ${fn}
pamarith ${fn} ${image} ${image} | cksum
done
done
echo "Test 5 (blank output)"
echo "Prints 2247801875 481 three times, then 320101399 59 three times"
for image in maze.pbm ${input1_ppm}
do
for fn in "-subtract" "-difference" "-xor"
do
echo ${fn}
pamarith ${fn} ${image} ${image} | cksum
done
done
rm ${input1_ppm}
echo "Invalid command-line argument combinations." 1>&2
echo "Error messages should appear below the line." 1>&2
echo "-----------------------------------------------------------" 1>&2
echo "Test Invalid"
test_out=${tmpdir}/test_out
# multiple functions
pamarith -add -subtract testimg.ppm testimg.ppm > ${test_out} || \
echo -n "Expected failure 1"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith -multiply -divide testimg.ppm testimg.ppm > ${test_out} || \
echo -n "Expected failure 2"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith -difference -minimum testimg.ppm testimg.ppm > ${test_out} || \
echo -n "Expected failure 3"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith -maximum -mean testimg.ppm testimg.ppm > ${test_out} || \
echo -n "Expected failure 4"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith -compare -and testimg.ppm testimg.ppm > ${test_out} || \
echo -n "Expected failure 5"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith -compare -equal testimg.ppm testimg.ppm > ${test_out} || \
echo -n "Expected failure 6"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith -or -nand testimg.ppm testimg.ppm > ${test_out} || \
echo -n "Expected failure 7"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith -nor -xor testimg.ppm testimg.ppm > ${test_out} || \
echo -n "Expected failure 8"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith -shiftleft -shiftright testimg.ppm testimg.ppm > ${test_out} || \
echo -n "Expected failure 9"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
# -add does not take a value
pamarith -add=1 testimg.ppm testimg.ppm > ${test_out} || \
echo -n "Expected failure 10"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
# No function
pamarith -plain testimg.ppm testimg.ppm > ${test_out} || \
echo -n "Expected failure 11"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith testimg.ppm testimg.ppm > ${test_out} || \
echo -n "Expected failure 12"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
# Just one input image file
pamarith -add testimg.ppm > ${test_out} || \
echo -n "Expected failure 13"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
# No input image file
pamarith -add > ${test_out} || \
echo -n "Expected failure 14"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
# Input images with different depth (number of planes)
pamchannel -infile testimg.ppm 0 1 | \
pamarith -add testimg.ppm - > ${test_out} || \
echo -n "Expected failure 15"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
# Input images with different x/y dimensions
pamarith -add testimg.ppm testgrid.pbm > ${test_out} || \
echo -n "Expected failure 16"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamenlarge -xscale=2 testgrid.pbm | \
pamarith -add testgrid.pbm - > ${test_out} || \
echo -n "Expected failure 17"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamenlarge -yscale=3 testgrid.pbm | \
pamarith -add testgrid.pbm - > ${test_out} || \
echo -n "Expected failure 18"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
# Invalid usage of -closeness
pamarith -equal -closeness=100.1 testgrid.pbm > ${test_out} || \
echo -n "Expected failure 19"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith -equal -closeness=-10 testgrid.pbm > ${test_out} || \
echo -n "Expected failure 20"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith -closeness -equal testgrid.pbm > ${test_out} || \
echo -n "Expected failure 21"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith -compare -closeness=10 testgrid.pbm > ${test_out} || \
echo -n "Expected failure 22"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
# Bit string functions
# Create PGM test input
input3_pgm=${tmpdir}/input3.pgm
input4_pgm=${tmpdir}/input4.pgm
input5_pgm=${tmpdir}/input5.pgm
pgmmake -maxval=4095 1.0 3 1 > ${input3_pgm}
pgmmake -maxval=4096 1.0 3 1 > ${input4_pgm}
pgmmake -maxval=8191 1.0 3 1 > ${input5_pgm}
# Bit string functions - Maxval must match
pamarith -and ${input3_pgm} ${input5_pgm} > ${test_out} || \
echo -n "Expected failure 23"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith -or ${input3_pgm} ${input5_pgm} > ${test_out} || \
echo -n "Expected failure 24"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith -nand ${input3_pgm} ${input5_pgm} > ${test_out} || \
echo -n "Expected failure 25"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith -nor ${input3_pgm} ${input5_pgm} > ${test_out} || \
echo -n "Expected failure 26"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith -xor ${input3_pgm} ${input5_pgm} > ${test_out} || \
echo -n "Expected failure 27"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
# Bit string functions - Maxval must be 2^n -1
pamarith -and ${input4_pgm} ${input4_pgm} > ${test_out} || \
echo -n "Expected failure 28"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith -or ${input4_pgm} ${input4_pgm} > ${test_out} || \
echo -n "Expected failure 29"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith -nand ${input4_pgm} ${input4_pgm} > ${test_out} || \
echo -n "Expected failure 30"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith -nor ${input4_pgm} ${input4_pgm} > ${test_out} || \
echo -n "Expected failure 31"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith -xor ${input4_pgm} ${input4_pgm} > ${test_out} || \
echo -n "Expected failure 32"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith -shiftleft ${input4_pgm} ${input4_pgm} > ${test_out} || \
echo -n "Expected failure 33"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith -shiftright ${input4_pgm} ${input4_pgm} > ${test_out} || \
echo -n "Expected failure 34"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
rm ${input3_pgm} ${input4_pgm} ${input5_pgm}
# Functions that do not allow more than two input images.
# Only the functions that are commutative and associative allow
# three or more inputs.
pamarith -subtract testimg.ppm testimg.ppm testimg.ppm > ${test_out} || \
echo -n "Expected failure 35"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith -divide testimg.ppm testimg.ppm testimg.ppm > ${test_out} || \
echo -n "Expected failure 36"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith -compare testimg.ppm testimg.ppm testimg.ppm > ${test_out} || \
echo -n "Expected failure 37"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith -difference testimg.ppm testimg.ppm testimg.ppm > ${test_out} || \
echo -n "Expected failure 38"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith -shiftleft testimg.ppm testimg.ppm testimg.ppm > ${test_out} || \
echo -n "Expected failure 39"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith -shiftright testimg.ppm testimg.ppm testimg.ppm > ${test_out} || \
echo -n "Expected failure 40"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
# Currently -equal and -mean do not allow more than two input images.
# These two cases should be removed once improvements are made.
pamarith -equal testgrid.pbm testgrid.pbm testgrid.pbm > ${test_out} || \
echo -n "Expected failure 41"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
pamarith -mean testgrid.pbm testgrid.pbm testgrid.pbm > ${test_out} || \
echo -n "Expected failure 42"
test -s ${test_out}; echo " "$?
rm -f ${test_out}
|