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 | #
|
---|
16 | usage(){
|
---|
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 |
|
---|
23 | mp="$PWD/makepng"
|
---|
24 | test -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
|
---|
34 | testdir="tests"
|
---|
35 | test $# -gt 1 && {
|
---|
36 | testdir="$1"
|
---|
37 | shift
|
---|
38 | }
|
---|
39 | test $# -eq 0 || usage
|
---|
40 |
|
---|
41 | # Take care not to clobber something
|
---|
42 | if test -e "$testdir"
|
---|
43 | then
|
---|
44 | test -d "$testdir" || usage
|
---|
45 | else
|
---|
46 | # mkdir -p isn't portable, so do the following
|
---|
47 | mkdir "$testdir" 2>/dev/null || mkdir -p "$testdir" || usage
|
---|
48 | fi
|
---|
49 |
|
---|
50 | # This fails in a very satisfactory way if it's not accessible
|
---|
51 | cd "$testdir"
|
---|
52 | :>"test$$.png" || {
|
---|
53 | exec >&2
|
---|
54 | echo "$testdir: directory not writable"
|
---|
55 | usage
|
---|
56 | }
|
---|
57 | rm "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
|
---|
67 | doit(){
|
---|
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 | #
|
---|
86 | for ct in gray palette
|
---|
87 | do
|
---|
88 | for bd in 1 2 4 8
|
---|
89 | do
|
---|
90 | doit "$ct" "$bd"
|
---|
91 | done
|
---|
92 | done
|
---|
93 | #
|
---|
94 | doit "gray" "16"
|
---|
95 | #
|
---|
96 | for ct in gray-alpha rgb rgb-alpha
|
---|
97 | do
|
---|
98 | for bd in 8 16
|
---|
99 | do
|
---|
100 | doit "$ct" "$bd"
|
---|
101 | done
|
---|
102 | done
|
---|