Blob Blame History Raw
#! /bin/bash
# This script tests: ppmchange
# Also requires: ppmrainbow pgmramp ppmhist


#  Failure message
## If this test fails and ppmchange-roundtrip.test succeeds,
## the probable cause is a problem with one of the options of
## ppmchange: -closeness or -remainder.

tmpdir=${tmpdir:-/tmp}
rainbow_ppm=${tmpdir}/rainbow.ppm
changed_ppm=${tmpdir}/changed.ppm

# Explicit values for intermediate colors: rgb.txt may not be the one
# Netpbm provides; they may be defined in unusual ways.

brown=rgb:67/43/00
cyan=rgb:00/ff/ff
yellow=rgb:ff/ff/00
gray=rgb:7f/7f/7f


# Test 1. Should print 22488533 203
pgmramp -lr 8 8 | ppmchange black black  white white  $gray $gray \
  -close=10 -remainder=blue | cksum


# Test 2. Should print 1008787190 613

ppmrainbow -tmpdir=$tmpdir -width=200 -height=1 red green blue | \
  tee ${rainbow_ppm} | \
  ppmchange red $brown   green $brown   blue $brown | cksum

# Validate ${rainbow_ppm}
# Should print 1983174784 613

cat ${rainbow_ppm} | cksum


# Test 3. Should print 2146447222 613

ppmchange red $brown   green $cyan   blue $yellow \
  -closeness=25 ${rainbow_ppm} | cksum


# Test 4. Should print 1216791938 613

ppmchange red rgb:64/00/01 rgb:00/ff/00 rgb:00/32/02 blue blue \
  -remainder=black -closeness=25 ${rainbow_ppm} | tee ${changed_ppm} | cksum

# Produce a histogram of the colors in the output image
# Should produce
#     0     0     0	    0	     78 
#     0     0   255	   29	     40 
#     0    50     2	   30	     41 
#   100     0     1	   30	     41 

ppmhist -sort=rgb -noheader ${changed_ppm}


rm ${rainbow_ppm} ${changed_ppm}