1#!/bin/sh 2# 3# Copyright (c) 2013 John Cunningham Bowler 4# 5# Last changed in libpng 1.6.0 [February 14, 2013] 6# 7# This code is released under the libpng license. 8# For conditions of distribution and use, see the disclaimer 9# and license in png.h 10# 11# Generate a set of PNG test images. The images are generated in a 12# sub-directory called 'tests' by default, however a command line argument will 13# change that name. The generation requires a built version of makepng in the 14# current directory. 15# 16usage(){ 17 exec >&2 18 echo "$0 [<directory>]" 19 echo ' Generate a set of PNG test files in "directory" ("tests" by default)' 20 exit 1 21} 22 23mp="$PWD/makepng" 24test -x "$mp" || { 25 exec >&2 26 echo "$0: the 'makepng' program must exist" 27 echo " in the directory within which this program:" 28 echo " $mp" 29 echo " is executed" 30 usage 31} 32 33# Just one argument: the directory 34testdir="tests" 35test $# -gt 1 && { 36 testdir="$1" 37 shift 38} 39test $# -eq 0 || usage 40 41# Take care not to clobber something 42if test -e "$testdir" 43then 44 test -d "$testdir" || usage 45else 46 # mkdir -p isn't portable, so do the following 47 mkdir "$testdir" 2>/dev/null || mkdir -p "$testdir" || usage 48fi 49 50# This fails in a very satisfactory way if it's not accessible 51cd "$testdir" 52:>"test$$.png" || { 53 exec >&2 54 echo "$testdir: directory not writable" 55 usage 56} 57rm "test$$.png" || { 58 exec >&2 59 echo "$testdir: you have create but not write privileges here." 60 echo " This is unexpected. You have a spurion; "'"'"test$$.png"'"'"." 61 echo " You need to remove this yourself. Try a different directory." 62 exit 1 63} 64 65# Now call makepng ($mp) to create every file we can think of with a 66# reasonable name 67doit(){ 68 for gamma in "" --sRGB --linear --1.8 69 do 70 case "$gamma" in 71 "") 72 gname=;; 73 --sRGB) 74 gname="-srgb";; 75 --linear) 76 gname="-lin";; 77 --1.8) 78 gname="-18";; 79 *) 80 gname="-$gamma";; 81 esac 82 "$mp" $gamma "$1" "$2" "test-$1-$2$gname.png" 83 done 84} 85# 86for ct in gray palette 87do 88 for bd in 1 2 4 8 89 do 90 doit "$ct" "$bd" 91 done 92done 93# 94doit "gray" "16" 95# 96for ct in gray-alpha rgb rgb-alpha 97do 98 for bd in 8 16 99 do 100 doit "$ct" "$bd" 101 done 102done 103