#! /bin/bash
# This script tests: pamtopdbimg pdbimgtopam
# Also requires: pbmnoise pgmramp pamtopnm pamdepth

tmpdir=${tmpdir:-/tmp}
noise_pbm=${tmpdir}/noise.pbm
ellipse_pgm=${tmpdir}/ellipse.pgm


echo "Test 1: pbm grid : Should print 2224198737 25671 three times"
for flag in "-compressed" "-maybecompressed" "-uncompressed"
   do
   pamtopdbimg ${flag} testgrid.pbm | pdbimgtopam | cksum
   done


echo "Test 2: pbmnoise : Should print 0 0 0 0 : 0 four times" 
pbmnoise -randomseed=1 160 160 > ${noise_pbm}
for flag in "" "-compressed" "-maybecompressed" "-uncompressed"
  do
  pamtopdbimg ${flag} ${noise_pbm} | pdbimgtopam | pamtopnm | \
    cmp -s - ${noise_pbm}
  echo ${PIPESTATUS[@]} ":" $?
  done
rm ${noise_pbm}


echo "Test 3: pgm ellipse : Should print 0 0 0 0 0 : 0 four times"
pgmramp -ellipse 160 160 -maxval=3 > ${ellipse_pgm}
for flag in "" "-compressed" "-maybecompressed" "-uncompressed"
    do
    pamtopdbimg ${flag} ${ellipse_pgm} | pdbimgtopam | \
      pamtopnm | pamdepth 3 | cmp -s - ${ellipse_pgm}
    echo ${PIPESTATUS[@]} ":" $?
    done
rm ${ellipse_pgm}


echo "Test 4: pgm ellipse -4depth : Should print 0 0 0 0 0 : 0 three times"
pgmramp -ellipse 160 160 -maxval=15 > ${ellipse_pgm}
for flag in "-compressed" "-maybecompressed" "-uncompressed"
    do
    pamtopdbimg -4depth ${flag} ${ellipse_pgm} | pdbimgtopam | \
      pamtopnm | pamdepth 15 | cmp -s - ${ellipse_pgm}
    echo ${PIPESTATUS[@]} ":" $?
    done
rm ${ellipse_pgm}
