about summary refs log tree commit diff
path: root/test/gif-transparent1.test
blob: 744967873ee59b8e01b0921d307dc77345c28ce3 (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
#! /bin/sh
# This script tests: giftopnm pamtogif ppmtogif
# Also requires: pamarith pamcomp pamdepth pamenlarge pamstack pbmmake
# Also requires: pnminvert ppmchange ppmpat ppmtopgm ppmtoppm 

tmpdir=${tmpdir:-/tmp}

madras_ppm=${tmpdir}/madras.ppm
gingham_ppm=${tmpdir}/gingham.ppm
argyle_ppm=${tmpdir}/argyle.ppm

alpha0_pbm=${tmpdir}/alpha0.pbm
alpha1_pbm=${tmpdir}/alpha1.pbm
clear_pbm=${tmpdir}/clear.pbm
opaque_pbm=${tmpdir}/opaque.pbm
alpha0_pam=${tmpdir}/alpha0.pam
alpha1_pam=${tmpdir}/alpha1.pam
clear_pam=${tmpdir}/clear.pam
opaque_pam=${tmpdir}/opaque.pam

image0_alpha_pam=${tmpdir}/image0.alpha.pam
image1_alpha_pam=${tmpdir}/image1.alpha.pam

out_pnm=${tmpdir}/out.pnm
out0_ppm=${tmpdir}/out0.ppm
out1_ppm=${tmpdir}/out1.ppm
out2_ppm=${tmpdir}/out2.ppm
a0_out_pbm=${tmpdir}/a0.out.pbm
a1_out_pbm=${tmpdir}/a1.out.pbm

# Make test images & alpha masks

ppmpat -argyle2 \
  -color=rgb:00/00/00,rgb:ff/ff/ff,rgb:ff/ff/ff 40 24 > ${argyle_ppm}
ppmpat -gingham3 \
  -color=rgb:3f/3f/3f,rgb:7f/7f/7f,rgb:ef/ef/ef 40 24 > ${gingham_ppm}
ppmpat -madras \
       -color=rgb:0f/0f/0f,rgb:ff/00/00,rgb:00/ff/00 40 24 > ${madras_ppm}

pbmmake -g 5 3 | pamenlarge 8 | tee ${alpha0_pbm} | \
  pamdepth 255 > ${alpha0_pam}
pnminvert ${alpha0_pbm} | tee ${alpha1_pbm} | \
  pamdepth 255 > ${alpha1_pam}

pbmmake -w 40 24 | tee ${clear_pbm} | pamdepth 255 > ${clear_pam}
pbmmake -b 40 24 | tee ${opaque_pbm} | pamdepth 255 > ${opaque_pam}


echo "Test 0."
echo "Should print 0 or 1 0."
i=1
for test_pnm in ${argyle_ppm} ${gingham_ppm} ${madras_ppm} \
			      ${alpha0_pbm} ${alpha1_pbm}
  do
  printf "Image $i: "; i=$((i+1));
  pamtogif ${test_pnm} | giftopnm | tee ${out_pnm} | \
    cmp -s - ${test_pnm}; result=$?

  if [ $result -eq 0 ];
    then echo $?;
  else
    ppmtoppm < ${out_pnm} | cmp -s - ${test_pnm}; echo $result $?
  fi
  # madras, alpha, alpha1 : should match
  # argyle: giftopnm produces PBM, gingham: giftopnm produces PGM
  rm ${out_pnm}
  done


echo "Test 1."  # Color + alpha channel
echo "Should print 0 unless otherwise stated."

i=1
for test_pnm in  ${argyle_ppm} ${gingham_ppm} ${madras_ppm}
  do
  echo "Image $i"; i=$((i+1));

  pamstack -tupletype="RGB_ALPHA" ${test_pnm} ${alpha0_pam} > \
    ${image0_alpha_pam}
  pamstack -tupletype="RGB_ALPHA" ${test_pnm} ${alpha1_pam} > \
    ${image1_alpha_pam}

  pamtogif ${image0_alpha_pam} | giftopnm -alphaout=${a0_out_pbm} | \
    ppmtoppm | tee ${out0_ppm} | \
    cmp -s - ${test_pnm}; echo "a1:" $? "(should print 1)"
  cmp -s ${alpha0_pbm} ${a0_out_pbm}; echo "a2:" $?  # Should match

  pamarith -multiply ${test_pnm} ${alpha0_pbm} | \
    cmp -s - ${out0_ppm}; echo "a3:" $? # Should match

  pamtogif ${image1_alpha_pam} | giftopnm -alphaout=${a1_out_pbm} | \
    ppmtoppm | tee ${out1_ppm} | \
    cmp -s - ${test_pnm}; echo "b1:" $? "(should print 1)"

  cmp -s ${alpha1_pbm} ${a1_out_pbm}; echo "b2:" $?  # Should match

  pamarith -multiply ${test_pnm} ${alpha1_pam} | \
    cmp -s - ${out1_ppm}; echo "b3:" $?    # Should match

  pamarith -multiply ${test_pnm} ${alpha0_pbm} | \
    cmp -s - ${out0_ppm}; echo "c1:" $?    # Should match

  pamarith -multiply ${test_pnm} ${alpha1_pbm} | \
    cmp -s - ${out1_ppm}; echo "c2:" $?    # Should match

  pamcomp -alpha=${alpha0_pbm} ${out0_ppm} ${out1_ppm} | \
    cmp -s - ${test_pnm}; echo "c3:" $?    # Should match

  pamcomp -alpha=${alpha1_pbm} ${out1_ppm} ${out0_ppm} | \
    cmp -s - ${test_pnm}; echo "c4:" $?    # Should match

  pamtogif ${image0_alpha_pam} -alphacolor=rgb:00/00/80 | \
    giftopnm  -alphaout=${a0_out_pbm} > /dev/null
    cmp -s ${a0_out_pbm} ${alpha0_pbm}; echo "d1:" $?    # Should match

  pamtogif ${image0_alpha_pam} -alphacolor=rgb:00/00/80 | \
    giftopnm | ppmtoppm | \
    ppmchange rgb:00/00/80 rgb:00/00/00 -remainder=rgb:ff/ff/ff | \
    ppmtopgm | \
    cmp -s - ${alpha0_pam}; echo "d2:" $?    # Should match

  rm ${image0_alpha_pam} ${image1_alpha_pam}
  rm ${out0_ppm} ${out1_ppm} # ${out0_pnm} ${out1_pnm}
  rm ${a0_out_pbm} ${a1_out_pbm}

  done

echo "Test 2."  # clear/opaque alpha channel
echo "Should print 0 unless otherwise stated."

i=1
for test_pnm in  ${argyle_ppm} ${gingham_ppm} ${madras_ppm}
  do
  echo "Image $i"; i=$((i+1));

  pamstack -tupletype="RGB_ALPHA" ${test_pnm} ${clear_pam} > \
    ${image0_alpha_pam}
  pamstack -tupletype="RGB_ALPHA" ${test_pnm} ${opaque_pam} > \
    ${image1_alpha_pam}

  # clear
  pamtogif ${image0_alpha_pam} | giftopnm -alphaout=${a0_out_pbm} | \
    ppmtoppm | tee ${out0_ppm} | \
    cmp -s - ${test_pnm}; echo "cl1:" $? # Should match
  cmp -s ${clear_pbm} ${a0_out_pbm}; echo "cl2:" $?  # Should match

  # opaque
  pamtogif ${image1_alpha_pam} | giftopnm -alphaout=${a1_out_pbm} | \
    tee ${out1_ppm} | \
    cmp -s - ${test_pnm}; echo "op1:" $? "(should print 1)"

  cmp -s ${opaque_pbm} ${a1_out_pbm}; echo "op2:" $?  # Should match

  rm ${image0_alpha_pam} ${image1_alpha_pam}
  rm ${out0_ppm} ${out1_ppm}
  rm ${a0_out_pbm} ${a1_out_pbm}

  done

rm ${clear_pbm} ${clear_pam} ${opaque_pbm} ${opaque_pam}


echo "Test 3."  # ppmtogif
echo "Should print 0 in all cases."

i=1
for test_pnm in  ${argyle_ppm} ${gingham_ppm} ${madras_ppm}
  do
  echo "Image $i"; i=$((i+1));

  ppmtogif -alpha=${alpha0_pbm} ${test_pnm} | \
    giftopnm -alphaout=${a0_out_pbm} | \
    ppmtoppm > ${out0_ppm}
    cmp -s ${alpha0_pbm} ${a0_out_pbm}; echo "a2:" $?  # Should match
  pamarith -multiply ${test_pnm} ${alpha0_pbm} | \
    cmp -s - ${out0_ppm}; echo "a3:" $? # Should match

  ppmtogif -alpha=${alpha1_pbm} ${test_pnm} | \
    giftopnm -alphaout=${a1_out_pbm} | \
    ppmtoppm > ${out1_ppm}
    cmp -s ${alpha1_pbm} ${a1_out_pbm}; echo "b2:" $?  # Should match
  pamarith -multiply ${test_pnm} ${alpha1_pam} | \
    cmp -s - ${out1_ppm}; echo "b3:" $?    # Should match

  pamcomp -alpha=${alpha1_pbm} ${out1_ppm} ${out0_ppm} | \
    cmp -s - ${test_pnm}; echo "c4:" $?    # Should match

  rm ${out0_ppm} ${out1_ppm}
  rm ${a0_out_pbm} ${a1_out_pbm}

  done

rm ${alpha0_pbm} ${alpha1_pbm}
rm ${alpha0_pam} ${alpha1_pam}
rm ${argyle_ppm} ${gingham_ppm}


echo "Test 4."
echo "Should print 0 in all cases."
# no separate alpha channel
# designate colors which appear in madras as transparent 

for color in "0f/0f/0f" "ff/00/00" "00/ff/00"
  do
  echo "color=rgb:"${color}
  pamtogif -transparent=rgb:${color} ${madras_ppm} | \
    giftopnm -alphaout=${a0_out_pbm} > ${out0_ppm}
    cmp -s ${madras_ppm} ${out0_ppm}; echo $?   # Should match 

  pbmmake -g 40 24 | pamdepth 255 | pamstack ${madras_ppm} - | 
  pamtogif -transparent=rgb:${color} - | \
    giftopnm -alphaout=${a1_out_pbm} > ${out1_ppm}
    cmp -s ${madras_ppm} ${out1_ppm}; echo $?   # Should match 

  ppmchange rgb:${color} rgb:00/00/00 \
    -remainder=rgb:ff/ff/ff ${madras_ppm} > ${out2_ppm}

  ppmtoppm < ${a0_out_pbm} | \
    cmp -s ${out2_ppm} -; echo $?   # Should match 

  rm ${out0_ppm} ${out1_ppm} ${out2_ppm} ${a0_out_pbm} ${a1_out_pbm}
  done

rm ${madras_ppm}