#! /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. echo "Test 1. Should print 1926073387 101484" rose_ppm=${tmpdir}/rose.ppm cp testimg.ppm ${rose_ppm} && ppmtorgb3 ${rose_ppm} rose_red=${tmpdir}/rose.red rose_grn=${tmpdir}/rose.grn rose_blu=${tmpdir}/rose.blu out_red=${tmpdir}/out.red out_grn=${tmpdir}/out.grn #out_blu=${tmpdir}/out.blu pamtogif ${rose_red} | giftopnm > ${out_red} && pamtogif ${rose_grn} | giftopnm > ${out_grn} && pamtogif ${rose_blu} | giftopnm | \ rgb3toppm ${out_red} ${out_grn} - | \ cksum rm ${rose_ppm} ${rose_grn} ${rose_blu} ${out_red} ${out_grn} echo "Test 2. Should produce 1571496937 33838 six times" rose_gif=${tmpdir}/rose.gif cat ${rose_red} | cksum pamtogif ${rose_red} | giftopnm | cksum pamtogif -interlace ${rose_red} | giftopnm | cksum pamtogif -noclear ${rose_red} | giftopnm | cksum pamtogif -sort ${rose_red} | tee ${rose_gif} | \ giftopnm | cksum echo "junk" >> ${rose_gif} && \ giftopnm -image=1 -quitearly ${rose_gif} | cksum rm ${rose_gif} ${rose_red} echo "Test 3. Should produce 281226646 481 six times" # maze.pbm is too small for -noclear to take effect cat maze.pbm | cksum pamtogif maze.pbm | giftopnm | cksum pamtogif -nolzw maze.pbm | giftopnm | cksum pamtogif -transparent=black maze.pbm | giftopnm | cksum pamtogif -alpha=maze.pbm maze.pbm | giftopnm | cksum pamtogif -transparent=white maze.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. echo "Test 4. Should produce P1 4 1 0101" 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 use up the string code table or # come close to doing so. echo "Test 5. Should produce: N : 0 0 0 0 : 0 , N : 0 0 0 0 : 0" echo "(N=238, 239, 240, 241, 255, 256, 257, 4030, 4031, 4097)" rose_pgm=${tmpdir}/rose.pgm # The following awk scripts produce a PGM file with no repeated # sequences. Obviously this cannot be compressed at all; the codes # are consumed without ever being used. # 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 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} > ${rose_pgm} && pamtogif -verbose ${rose_pgm} | giftopnm | pamdepth ${maxval} | \ cmp - ${rose_pgm} echo -n ${size} ":" ${PIPESTATUS[@]} ":" $? ", " pamtogif -nolzw -verbose ${rose_pgm} | giftopnm | pamdepth ${maxval} | \ cmp - ${rose_pgm} echo ${size} ":" ${PIPESTATUS[@]} ":" $? rm ${rose_pgm} done rm ${test257_pgm} test4097_pgm=${tmpdir}/testimg4097.pgm 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} > ${rose_pgm} && pamtogif -verbose ${rose_pgm} | giftopnm | pamdepth ${maxval} | \ cmp - ${rose_pgm} # pamdepth ${maxval} is necessary because # giftopnm output is maxval 255 echo -n ${size} ":" ${PIPESTATUS[@]} ":" $? ", " pamtogif -nolzw ${rose_pgm} | giftopnm | pamdepth ${maxval} | \ cmp - ${rose_pgm} echo ${size} ":" ${PIPESTATUS[@]} ":" $? rm ${rose_pgm} done rm ${test4097_pgm}