about summary refs log tree commit diff
path: root/test/pamfunc.test
blob: b1b9edfca70e802efb7d232cd3ec9778b01913b5 (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
#! /bin/sh
# This script tests: pamfunc
# Also requires: pamseq pamtopnm pbmmake

tmpdir=${tmpdir:-/tmp}
input_pgm=${tmpdir}/input.pgm

echo "Test 1"

pamseq 1 15 | pamtopnm -assume > ${input_pgm}
pamtopnm -plain ${input_pgm} | tr '\n' ' '; echo

pamfunc -adder=3 -plain ${input_pgm} | tr '\n' ' '; echo
pamfunc -subtractor=3 -plain ${input_pgm} | tr '\n' ' '; echo
pamfunc -multiplier=3 -plain ${input_pgm} | tr '\n' ' '; echo
pamfunc -divisor=2 -plain ${input_pgm} | tr '\n' ' '; echo
pamfunc -max=6 -plain ${input_pgm} | tr '\n' ' '; echo
pamfunc -min=5 -plain ${input_pgm} | tr '\n' ' '; echo

pamfunc -shiftleft  1  -plain ${input_pgm} | tr '\n' ' '; echo
pamfunc -shiftright 1  -plain ${input_pgm} | tr '\n' ' '; echo
pamfunc -shiftleft  1 ${input_pgm} | pamfunc -shiftright 1 -plain | \
  tr '\n' ' '; echo
pamfunc -shiftright 1 ${input_pgm} | pamfunc -shiftleft 1  -plain | \
  tr '\n' ' '; echo


input_pbm=${tmpdir}/input.pbm

echo "Test 2"

pbmmake -g 8 1 > ${input_pbm}
pamtopnm -plain ${input_pbm} | tr '\n' ' '; echo

pamfunc -adder=1 -plain ${input_pbm} | tr '\n' ' '; echo
pamfunc -subtractor=1 -plain ${input_pbm} | tr '\n' ' '; echo
pamfunc -multiplier=1 -plain ${input_pbm} | tr '\n' ' '; echo
pamfunc -divisor=1 -plain ${input_pbm} | tr '\n' ' '; echo
pamfunc -max=1 -plain ${input_pbm} | tr '\n' ' '; echo
pamfunc -min=1 -plain ${input_pbm} | tr '\n' ' '; echo

pamfunc -shiftleft  1  -plain ${input_pbm} | tr '\n' ' '; echo
pamfunc -shiftright 1  -plain ${input_pbm} | tr '\n' ' '; echo
pamfunc -shiftleft  1 ${input_pbm} | pamfunc -shiftright 1 -plain | \
  tr '\n' ' '; echo
pamfunc -shiftright 1 ${input_pbm} | pamfunc -shiftleft 1  -plain | \
  tr '\n' ' '; echo


echo "Test 3 (-changemaxval)"

pamfunc -divisor 2 -changemaxval ${input_pgm} -plain | \
  tr '\n' ' '; echo
pamfunc -multiplier 0.25 -changemaxval ${input_pgm} -plain | \
  tr '\n' ' '; echo
pamfunc -divisor 2 -changemaxval ${input_pbm} -plain | \
  tr '\n' ' '; echo
pamfunc -multiplier 0.25 -changemaxval ${input_pbm} -plain | \
  tr '\n' ' '; echo

rm ${input_pgm} ${input_pbm}

echo "Test 4: Should print 1926073387 101484 eight times"

cat testimg.ppm | cksum

pamfunc -not testimg.ppm | pamfunc -not | cksum
pamfunc -andmask 0xff testimg.ppm | cksum
pamfunc -ormask  0x00 testimg.ppm | cksum
pamfunc -xormask 0x00 testimg.ppm | cksum
pamfunc -xormask 0xff testimg.ppm | pamfunc -xormask 0xff | cksum
pamfunc -shiftleft  0 testimg.ppm | cksum
pamfunc -shiftright 0 testimg.ppm | cksum


echo "Test 5: Should print 281226646 481 six times"

cat maze.pbm | cksum

pamfunc -andmask  0x1 maze.pbm | cksum
pamfunc -ormask   0x0 maze.pbm | cksum
pamfunc -xormask  0x1 maze.pbm | pamfunc -xormask 0x1 | cksum

pamfunc -shiftleft  0 maze.pbm | cksum
pamfunc -shiftright 0 maze.pbm | cksum


echo "Test Invalid"

. ${srcdir}/test-invalid.inc

invCmd "pamfunc -multiplier testimg.ppm"
invCmd "pamfunc -multiplier=-1 testimg.ppm"
invCmd "pamfunc -divisor testimg.ppm"
invCmd "pamfunc -divisor=-20 testimg.ppm"
invCmd "pamfunc -adder testimg.ppm"
invCmd "pamfunc -adder 0.5 testimg.ppm"
invCmd "pamfunc -subtractor testimg.ppm"
invCmd "pamfunc -subtractor 0.1 testimg.ppm"
invCmd "pamfunc -multiplier=1 -divisor=2 testimg.ppm"
invCmd "pamfunc -adder=2 -subtractor=3 testimg.ppm"
invCmd "pamfunc -min testimg.ppm"
invCmd "pamfunc -max testimg.ppm"
invCmd "pamfunc -andmask testimg.ppm"
invCmd "pamfunc -ormask testimg.ppm"
invCmd "pamfunc -xormask testimg.ppm"
invCmd "pamfunc -not 1 testimg.ppm"
invCmd "pamfunc -min=1 -max=2 testimg.ppm"
invCmd "pamfunc -andmask=1 -ormask=0 testimg.ppm"
invCmd "pamfunc -andmask=0xffff testimg.ppm"
invCmd "pamfunc -shiftleft testimg.ppm"
invCmd "pamfunc -shiftright testimg.ppm"
invCmd "pamfunc -changemaxval testimg.ppm"
invCmd "pamfunc -shiftleft=1 -shiftright=1 testimg.ppm"
invCmd "pamfunc -multiplier=0.5 -changemaxval=65535 testimg.ppm"