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