fukasawa e60969
#!/bin/sh
fukasawa e60969
#
fukasawa e60969
# Copyright (c) 2013 John Cunningham Bowler
fukasawa e60969
#
fukasawa e60969
# Last changed in libpng 1.6.0 [February 14, 2013]
fukasawa e60969
#
fukasawa e60969
# This code is released under the libpng license.
fukasawa e60969
# For conditions of distribution and use, see the disclaimer
fukasawa e60969
# and license in png.h
fukasawa e60969
#
fukasawa e60969
# Generate a set of PNG test images.  The images are generated in a
fukasawa e60969
# sub-directory called 'tests' by default, however a command line argument will
fukasawa e60969
# change that name.  The generation requires a built version of makepng in the
fukasawa e60969
# current directory.
fukasawa e60969
#
fukasawa e60969
usage(){
fukasawa e60969
   exec >&2
fukasawa e60969
   echo "$0 [<directory>]"</directory>
fukasawa e60969
   echo '  Generate a set of PNG test files in "directory" ("tests" by default)'
fukasawa e60969
   exit 1
fukasawa e60969
}
fukasawa e60969
fukasawa e60969
mp="$PWD/makepng"
fukasawa e60969
test -x "$mp" || {
fukasawa e60969
   exec >&2
fukasawa e60969
   echo "$0: the 'makepng' program must exist"
fukasawa e60969
   echo "  in the directory within which this program:"
fukasawa e60969
   echo "    $mp"
fukasawa e60969
   echo "  is executed"
fukasawa e60969
   usage
fukasawa e60969
}
fukasawa e60969
fukasawa e60969
# Just one argument: the directory
fukasawa e60969
testdir="tests"
fukasawa e60969
test $# -gt 1 && {
fukasawa e60969
   testdir="$1"
fukasawa e60969
   shift
fukasawa e60969
}
fukasawa e60969
test $# -eq 0 || usage
fukasawa e60969
fukasawa e60969
# Take care not to clobber something
fukasawa e60969
if test -e "$testdir"
fukasawa e60969
then
fukasawa e60969
   test -d "$testdir" || usage
fukasawa e60969
else
fukasawa e60969
   # mkdir -p isn't portable, so do the following
fukasawa e60969
   mkdir "$testdir" 2>/dev/null || mkdir -p "$testdir" || usage
fukasawa e60969
fi
fukasawa e60969
fukasawa e60969
# This fails in a very satisfactory way if it's not accessible
fukasawa e60969
cd "$testdir"
fukasawa e60969
:>"test$$.png" || {
fukasawa e60969
   exec >&2
fukasawa e60969
   echo "$testdir: directory not writable"
fukasawa e60969
   usage
fukasawa e60969
}
fukasawa e60969
rm "test$$.png" || {
fukasawa e60969
   exec >&2
fukasawa e60969
   echo "$testdir: you have create but not write privileges here."
fukasawa e60969
   echo "  This is unexpected.  You have a spurion; "'"'"test$$.png"'"'"."
fukasawa e60969
   echo "  You need to remove this yourself.  Try a different directory."
fukasawa e60969
   exit 1
fukasawa e60969
}
fukasawa e60969
fukasawa e60969
# Now call makepng ($mp) to create every file we can think of with a
fukasawa e60969
# reasonable name
fukasawa e60969
doit(){
fukasawa e60969
   for gamma in "" --sRGB --linear --1.8
fukasawa e60969
   do
fukasawa e60969
      case "$gamma" in
fukasawa e60969
         "")
fukasawa e60969
            gname=;;
fukasawa e60969
         --sRGB)
fukasawa e60969
            gname="-srgb";;
fukasawa e60969
         --linear)
fukasawa e60969
            gname="-lin";;
fukasawa e60969
         --1.8)
fukasawa e60969
            gname="-18";;
fukasawa e60969
         *)
fukasawa e60969
            gname="-$gamma";;
fukasawa e60969
      esac
fukasawa e60969
      "$mp" $gamma "$1" "$2" "test-$1-$2$gname.png"
fukasawa e60969
   done
fukasawa e60969
}
fukasawa e60969
#
fukasawa e60969
for ct in gray palette
fukasawa e60969
do
fukasawa e60969
   for bd in 1 2 4 8
fukasawa e60969
   do
fukasawa e60969
      doit "$ct" "$bd"
fukasawa e60969
   done
fukasawa e60969
done
fukasawa e60969
#
fukasawa e60969
doit "gray" "16"
fukasawa e60969
#
fukasawa e60969
for ct in gray-alpha rgb rgb-alpha
fukasawa e60969
do
fukasawa e60969
   for bd in 8 16
fukasawa e60969
   do
fukasawa e60969
      doit "$ct" "$bd"
fukasawa e60969
   done
fukasawa e60969
done