summaryrefslogtreecommitdiff
path: root/Build/source/libs/libpng/libpng-1.6.2/contrib/libtests/gentests.sh
blob: f0f8d2395a5377cce9385cf9cdf3c12612b07f98 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#!/bin/sh
#
# Copyright (c) 2013 John Cunningham Bowler
#
# Last changed in libpng 1.6.0 [February 14, 2013]
#
# This code is released under the libpng license.
# For conditions of distribution and use, see the disclaimer
# and license in png.h
#
# Generate a set of PNG test images.  The images are generated in a
# sub-directory called 'tests' by default, however a command line argument will
# change that name.  The generation requires a built version of makepng in the
# current directory.
#
usage(){
   exec >&2
   echo "$0 [<directory>]"
   echo '  Generate a set of PNG test files in "directory" ("tests" by default)'
   exit 1
}

mp="$PWD/makepng"
test -x "$mp" || {
   exec >&2
   echo "$0: the 'makepng' program must exist"
   echo "  in the directory within which this program:"
   echo "    $mp"
   echo "  is executed"
   usage
}

# Just one argument: the directory
testdir="tests"
test $# -gt 1 && {
   testdir="$1"
   shift
}
test $# -eq 0 || usage

# Take care not to clobber something
if test -e "$testdir"
then
   test -d "$testdir" || usage
else
   # mkdir -p isn't portable, so do the following
   mkdir "$testdir" 2>/dev/null || mkdir -p "$testdir" || usage
fi

# This fails in a very satisfactory way if it's not accessible
cd "$testdir"
:>"test$$.png" || {
   exec >&2
   echo "$testdir: directory not writable"
   usage
}
rm "test$$.png" || {
   exec >&2
   echo "$testdir: you have create but not write privileges here."
   echo "  This is unexpected.  You have a spurion; "'"'"test$$.png"'"'"."
   echo "  You need to remove this yourself.  Try a different directory."
   exit 1
}

# Now call makepng ($mp) to create every file we can think of with a
# reasonable name
doit(){
   for gamma in "" --sRGB --linear --1.8
   do
      case "$gamma" in
         "")
            gname=;;
         --sRGB)
            gname="-srgb";;
         --linear)
            gname="-lin";;
         --1.8)
            gname="-18";;
         *)
            gname="-$gamma";;
      esac
      "$mp" $gamma "$1" "$2" "test-$1-$2$gname.png"
   done
}
#
for ct in gray palette
do
   for bd in 1 2 4 8
   do
      doit "$ct" "$bd"
   done
done
#
doit "gray" "16"
#
for ct in gray-alpha rgb rgb-alpha
do
   for bd in 8 16
   do
      doit "$ct" "$bd"
   done
done