about summary refs log tree commit diff
path: root/test/pnmpad-extend-enlarge.test
blob: fde609a69b9f71284cc17c5db115a800120a2db1 (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
#! /bin/sh
# This script tests: pnmpad pamenlarge
# Also requires: pamcat pamcut pamenlarge pbmmake pbmnoise pgmmake pgmnoise
# Also requires: ppmmake ppmpat

# If the padding function for -extend-edge is altered, make sure to run this
# test in a more thorough form.  Replace "for leftpad in 0 1 7 9 16"
# with "for leftpad in `seq 0 16`".

tmpdir=${tmpdir:-/tmp}
test_pnm=${tmpdir}/test.pnm

padded_pnm=${tmpdir}/padded.pnm
#middle_pnm=${tmpdir}/middle.pnm
left_pnm=${tmpdir}/left.pnm
right_pnm=${tmpdir}/right.pnm
top_pnm=${tmpdir}/top.pnm
bottom_pnm=${tmpdir}/bottom.pnm

echo "Test 1.  Should print match forty-eight (24x2) times"

for generator in "pbmnoise -randomseed=100 17 17" \
                 "ppmpat -tartan -randomseed=100 11 11"          
    do
    ${generator} > ${test_pnm}
    for leftpad in 0 1 7 9 16
    do
        for rightpad in  0 1 8
        do
            pnmpad -extend-edge -l=${leftpad} -r=${rightpad} ${test_pnm} > ${padded_pnm}
            pamcut -left=0 -width=1 ${test_pnm} |\
                pamenlarge -xscale=$(( ${leftpad} + 1 )) > ${left_pnm}
            pamcut -right=-1 -width=1  ${test_pnm} |\
                pamenlarge -xscale=$(( ${rightpad} + 1 )) > ${right_pnm}
            pamcut -cropleft=1 -cropright=1 ${test_pnm} |\
                pamcat -lr ${left_pnm} - ${right_pnm} |\
                cmp -s - ${padded_pnm} && echo "match" ||\
                    echo "no match: lr ${generator} ${leftpad} ${rightpad}";
            rm ${left_pnm} ${right_pnm} ${padded_pnm}
        done
    done
    
    for toppad in 0 2 5
    do
        for bottompad in  0 1 10
        do
            pnmpad -extend-edge -t=${toppad} -b=${bottompad} ${test_pnm} > ${padded_pnm}
            pamcut -top=0 -height=1 ${test_pnm} |\
                pamenlarge -yscale=$(( ${toppad} + 1 )) > ${top_pnm}
            pamcut -bottom=-1 -height=1  ${test_pnm} |\
                pamenlarge -yscale=$(( ${bottompad} + 1 )) > ${bottom_pnm}
            pamcut -croptop=1 -cropbottom=1 ${test_pnm} |\
            pamcat -tb ${top_pnm} - ${bottom_pnm} |\
                cmp -s - ${padded_pnm} && echo "match" ||\
                    echo "no match: tb ${generator} ${toppad} ${bottompad}";
            rm ${top_pnm} ${bottom_pnm} ${padded_pnm}
        done
    done
    rm ${test_pnm}
done


echo "Test 2.  Should print match thirty-six (18x2) times"

for generator in "pbmnoise -randomseed=100 17 17" \
                 "ppmpat -tartan -randomseed=100 11 11"
    do
    ${generator} > ${test_pnm}
    for leftpad in 0 1 2
    do
        for rightpad in  0 1 3
        do
            pnmpad -extend-edge -l=${leftpad} -r=${rightpad} ${test_pnm} > ${padded_pnm}
            pamcut -left=0 -width=1 ${test_pnm} |\
                pamenlarge -xscale=$(( ${leftpad} + 1 )) > ${left_pnm}
            pamcut -right=-1 -width=1  ${test_pnm} |\
                pamenlarge -xscale=$(( ${rightpad} + 1 )) > ${right_pnm}
            pamcut -cropleft=1 -cropright=1 ${test_pnm} |\
                pamcat -lr ${left_pnm} - ${right_pnm} |\
                cmp -s - ${padded_pnm} && echo "match" ||\
                    echo "no match: lr ${generator} ${leftpad} ${rightpad}";
            rm ${left_pnm} ${right_pnm} ${padded_pnm}
        done
    done
    
    for toppad in 0 1 12
    do
        for bottompad in 0 1 5
        do
            pnmpad -extend-edge -t=${toppad} -b=${bottompad} ${test_pnm} > ${padded_pnm}
            pamcut -top=0 -height=1 ${test_pnm} |\
                pamenlarge -yscale=$(( ${toppad} + 1 )) > ${top_pnm}
            pamcut -bottom=-1 -height=1  ${test_pnm} |\
                pamenlarge -yscale=$(( ${bottompad} + 1 )) > ${bottom_pnm}
            pamcut -croptop=1 -cropbottom=1 ${test_pnm} |\
                pamcat -tb ${top_pnm} - ${bottom_pnm} |\
                cmp -s - ${padded_pnm} && echo "match" ||\
                    echo "no match: tb ${generator} ${toppad} ${bottompad}";
            rm ${top_pnm} ${bottom_pnm} ${padded_pnm}
        done
    done
    rm ${test_pnm}
done


echo "Test 3.  Should print match twenty-four (4x6) times"

stretch_pnm=${tmpdir}/stretch.pnm

for generator in "pbmmake -b 1 1" \
                 "pbmmake -b 1 11" \
                 "pbmmake -w 1 1" \
                 "pbmmake -w 1 8" \
                 "pbmnoise -randomseed=100 1 17" \
                 "pgmnoise -randomseed=100 1 12"                 
    do
        ${generator} > ${test_pnm}
     pamenlarge -xscale=17 ${test_pnm} > ${stretch_pnm} 
        
    for leftpad in 0 1 7 16
    do
        pnmpad -extend-edge -l=${leftpad} -r=$((16 - ${leftpad})) ${test_pnm} |\
                cmp -s - ${stretch_pnm} && echo "match" ||\
                    echo "no match: ${generator} ${leftpad}";
    done
    rm ${stretch_pnm} ${test_pnm}
done


echo "Test 4.  Should print match eighteen (3x6) times"

stretch_pnm=${tmpdir}/stretch.pnm

for generator in "pbmmake -b 1 1" \
                 "pbmmake -b 8 1" \
                 "pbmmake -w 1 1" \
                 "pbmmake -w 3 1" \
                 "pbmnoise -randomseed=100 17 1" \
                 "pgmnoise -randomseed=100 8 1"          
    do
        ${generator} > ${test_pnm}
     pamenlarge -yscale=15 ${test_pnm} > ${stretch_pnm} 
        
    for toppad in  0 1 14
    do
        pnmpad -extend-edge -t=${toppad} -b=$((14 - ${toppad})) ${test_pnm} |\
                cmp -s - ${stretch_pnm} && echo "match" ||\
                    echo "no match: ${generator} ${toppad}";
    done
    rm ${stretch_pnm} ${test_pnm}
done


echo "Test 5.  Should print match thirty-two (8x4) times"

stretch_pnm=${tmpdir}/stretch.pnm

for generator in "pbmmake -b 1 1" \
                 "pbmmake -w 1 1" \
                 "pgmmake 0.3 1 1" \
                 "ppmmake rgbi:0.5/0.3/0.8 1 1"
    do
        ${generator} > ${test_pnm}
        pamenlarge -xscale=66 -yscale=10 ${test_pnm} > ${stretch_pnm}
        
    for toppad in  0 8
    do
    for leftpad in  0 1 15 64
    do
        pnmpad -extend-edge -t=${toppad} -b=$((9 - ${toppad})) \
         -l=${leftpad} -r=$((65 - ${leftpad})) ${test_pnm} |\
                cmp -s - ${stretch_pnm} && echo "match" ||\
                echo "no match: ${generator} ${toppad} ${leftpad}"
    done
    done
    rm ${stretch_pnm} ${test_pnm}
done