#! /bin/bash -e
# Last edited on 2025-08-08 05:36:20 by stolfi

# Tests whether ImageMagick's '-level-colors' works.

cat <<EOF > .test-in.pgm 
P2
4 6
65535
65534 20 30 65534
65534 20 30 65534
65534 20  1 65534
65534  0 30 65534
65534 20 30 65534
65534 20 30 65534
EOF

hblack="#000100010001"
hwhite="#ffffffffffff"
convert .test-in.pgm \
    -set colorspace LinearGray \
    +level-colors "${hblack},${hwhite}" \
    -depth 16 \
    -colorspace LinearGray \
    PGM:- \
  | pnmtoplainpnm \
  > .test-ot.pgm 

cat .test-in.pgm | tr ' ' '\012' | egrep -e '[0-9]' > .in
cat .test-ot.pgm | tr ' ' '\012' | egrep -e '[0-9]' > .ot

prdiff -Bb .in .ot
