about summary refs log tree commit diff
path: root/test/gif-roundtrip.test
blob: 1e6c7760167735a074460e30fa4ed25a800ff81a (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
#! /bin/bash
# This script tests: giftopnm pamtogif
# Also requires: ppmtorgb3 rgb3toppm pbmmake pnminvert pamcut pamdepth

tmpdir=${tmpdir:-/tmp}

# Test 1. Break up input image into three monochrome planes,
# maxval 255.  Transform each plane to gif and back to pgm.
# Reassemble the planes.  Result should be identical to input.
# Should print 1926073387 101484

test_ppm=${tmpdir}/testimg.ppm

cp testimg.ppm ${tmpdir} &&
ppmtorgb3 ${test_ppm}

test_red=${tmpdir}/testimg.red
test_grn=${tmpdir}/testimg.grn
test_blu=${tmpdir}/testimg.blu
out_red=${tmpdir}/out.red
out_grn=${tmpdir}/out.grn
#out_blu=${tmpdir}/out.blu

pamtogif ${test_red} | giftopnm > ${out_red} &&
pamtogif ${test_grn} | giftopnm > ${out_grn} &&
pamtogif ${test_blu} | giftopnm | \
  rgb3toppm ${out_red} ${out_grn} - | \
  cksum

rm ${test_ppm} ${test_grn} ${test_blu} ${out_red} ${out_grn}


# Test 2. Should produce 1571496937 33838
# which is the result of cksum testimg.red
# five times

test_gif=${tmpdir}/testimg.gif

pamtogif ${test_red} | giftopnm | cksum
pamtogif -interlace ${test_red} | giftopnm | cksum
pamtogif -noclear ${test_red} | giftopnm | cksum
pamtogif -sort ${test_red} | tee ${test_gif} | \
  giftopnm | cksum
echo "junk" >> ${test_gif} && \
  giftopnm -image=1 -quitearly ${test_gif} | cksum

rm  ${test_gif} ${test_red}


# Test 3. Should produce 2425386270 41 five times.
# testgrid.pbm is too small for -noclear to take effect 

pamtogif testgrid.pbm | giftopnm | cksum
pamtogif -nolzw testgrid.pbm | giftopnm | cksum
pamtogif -transparent=black testgrid.pbm | giftopnm | cksum
pamtogif -alpha=testgrid.pbm testgrid.pbm | giftopnm | cksum
pamtogif -transparent=white testgrid.pbm | giftopnm -alpha=- | \
  pnminvert | cksum


# Test 4.
# In this gif file the code length changes after the last image data.
# Image data: 3 bits, end code 4 bits.
# Should produce P1 4 1 0 1 0 1

pbmmake -g 4 1 | \
  pamtogif -verbose | giftopnm -plain | \
  tr '\n' ' '
echo ""


# Test 5.
# Test whether saturated code tables are handled correctly.
# Test input images which most use up the string code table or
# come close to doing so.

# Should produce:
# 4030 0 , 4030 0
# 4031 0 , 4031 0
# 4097 0 , 4097 0
# 238 0 , 238 0
# 239 0 , 239 0
# 240 0 , 240 0
# 241 0 , 241 0
# 255 0 , 255 0
# 256 0 , 256 0
# 257 0 , 257 0

test4097_pgm=${tmpdir}/testimg4097.pgm
test_pgm=${tmpdir}/testimg.pgm

# The following awk script produces a PGM file with no repeated sequences.
# Here is a smaller example with the same property:
# P2
# 8 8
# 7
# 0 0 1 1 0 2 2 0
# 3 3 0 4 4 0 5 5
# 0 6 6 0 7 7 1 2
# 1 3 1 4 1 5 1 6
# 1 7 2 3 2 4 2 5
# 2 6 2 7 3 4 3 5
# 3 6 3 7 4 5 4 6
# 4 7 5 6 5 7 6 7

maxval=63
awk -v maxval=${maxval} 'BEGIN \
{ print "P2"
         print "1 "(maxval+1) * (maxval+1) +1
         print maxval
         print 0 
         for (j=i+1; j<=maxval; ++j)
	    {print 0; print j; print j }
         for (i=1; i<=maxval; ++i)
             for (j=i+1; j<=maxval; ++j)
                 {print i; print j }
         print 0
}' > ${test4097_pgm}

for size in 4030 4031 4097
  do
  pamcut -height ${size} ${test4097_pgm} > ${test_pgm} &&
  pamtogif -verbose ${test_pgm} | giftopnm | pamdepth ${maxval} | \
    cmp - ${test_pgm}
  # pamdepth ${maxval} is necessary because
  # giftopnm output is maxval 255
  echo -n ${size} ":" ${PIPESTATUS[@]} ":" $? ", "
  pamtogif -nolzw ${test_pgm} | giftopnm | pamdepth ${maxval} | \
    cmp - ${test_pgm}
  echo ${size} ":" ${PIPESTATUS[@]} ":" $?
  rm ${test_pgm}
  done 

rm ${test4097_pgm}
test257_pgm=${tmpdir}/testimg257.pgm

maxval=15
awk -v maxval=${maxval} 'BEGIN \
{ print "P2"
         print "1 "(maxval+1) * (maxval+1) +1
         print maxval
         print 0 
         for (j=i+1; j<=maxval; ++j)
	    {print 0; print j; print j }
         for (i=1; i<=maxval; ++i)
             for (j=i+1; j<=maxval; ++j)
                 {print i; print j }
         print 0
}' >  ${test257_pgm}

for size in 238 239 240 241 255 256 257
  do
  pamcut -height=${size} ${test257_pgm} > ${test_pgm} &&
  pamtogif -verbose ${test_pgm} | giftopnm | pamdepth ${maxval} | \
    cmp - ${test_pgm}
  echo -n ${size} ":" ${PIPESTATUS[@]} ":" $? ", "
  pamtogif -nolzw -verbose ${test_pgm} | giftopnm | pamdepth ${maxval} | \
    cmp - ${test_pgm}
  echo ${size} ":" ${PIPESTATUS[@]} ":" $?
  rm ${test_pgm}
  done 

rm ${test257_pgm}