gentests.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. mp="$PWD/makepng"
  23. test -x "$mp" || {
  24. exec >&2
  25. echo "$0: the 'makepng' program must exist"
  26. echo " in the directory within which this program:"
  27. echo " $mp"
  28. echo " is executed"
  29. usage
  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. # Take care not to clobber something
  39. if test -e "$testdir"
  40. then
  41. test -d "$testdir" || usage
  42. else
  43. # mkdir -p isn't portable, so do the following
  44. mkdir "$testdir" 2>/dev/null || mkdir -p "$testdir" || usage
  45. fi
  46. # This fails in a very satisfactory way if it's not accessible
  47. cd "$testdir"
  48. :>"test$$.png" || {
  49. exec >&2
  50. echo "$testdir: directory not writable"
  51. usage
  52. }
  53. rm "test$$.png" || {
  54. exec >&2
  55. echo "$testdir: you have create but not write privileges here."
  56. echo " This is unexpected. You have a spurion; "'"'"test$$.png"'"'"."
  57. echo " You need to remove this yourself. Try a different directory."
  58. exit 1
  59. }
  60. # Now call makepng ($mp) to create every file we can think of with a
  61. # reasonable name
  62. doit(){
  63. for gamma in "" --sRGB --linear --1.8
  64. do
  65. case "$gamma" in
  66. "")
  67. gname=;;
  68. --sRGB)
  69. gname="-srgb";;
  70. --linear)
  71. gname="-lin";;
  72. --1.8)
  73. gname="-18";;
  74. *)
  75. gname="-$gamma";;
  76. esac
  77. "$mp" $gamma "$1" "$2" "test-$1-$2$gname.png"
  78. done
  79. }
  80. #
  81. for ct in gray palette
  82. do
  83. for bd in 1 2 4 8
  84. do
  85. doit "$ct" "$bd"
  86. done
  87. done
  88. #
  89. doit "gray" "16"
  90. #
  91. for ct in gray-alpha rgb rgb-alpha
  92. do
  93. for bd in 8 16
  94. do
  95. doit "$ct" "$bd"
  96. done
  97. done