gentextures.sh 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. #!/bin/bash
  2. # This program auto-generates colorized textures for all 89 of the Unified
  3. # Dyes colors, based on one or two input files.
  4. # Copyright (C) 2012-2013, Vanessa Ezekowitz
  5. # Email: vanessaezekowitz@gmail.com
  6. #
  7. # This program is free software; you can redistribute it and/or modify
  8. # it under the terms of the GNU General Public License as published by
  9. # the Free Software Foundation; either version 2 of the License, or
  10. # (at your option) any later version.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License along
  18. # with this program; if not, write to the Free Software Foundation, Inc.,
  19. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. if [ -z "`which convert`" ] ; then {
  21. echo "Please install Imagemagick."
  22. exit 1
  23. } fi
  24. if [ -z "`which bc`" ] ; then {
  25. echo "Please install GNU bc."
  26. exit 1
  27. } fi
  28. if [ $1 = "-t" ] ; then {
  29. TINT_OVERLAY=$1
  30. BASE=$2
  31. COMPOSITE=$3
  32. } else {
  33. TINT_OVERLAY=""
  34. BASE=$1
  35. COMPOSITE=$2
  36. } fi
  37. if [ -z $1 ] || [ $1 == "--help" ] || [ $1 == "-h" ] || [[ $1 == "-t" && -z $3 ]] ; then {
  38. echo -e "\nUsage:
  39. \ngentextures.sh basename [overlay_filename]
  40. gentextures.sh -t basename overlay_filename
  41. \nThis script requires up to three parameters which supply the base filename
  42. of the textures, an optional overlay, and possibly the '-t' switch. The
  43. 'basename' is the first part of the filename that your textures will use when
  44. your mod is done, which should almost always be the same as the one-word name
  45. of your mod. For example, if you supply the word 'mymod', this script will
  46. produce filenames like mymod_red.png or 'mymod_dark_blue_s50.png'. The
  47. texture that this script will read and recolor is derived from this parameter,
  48. and will be of the form 'basename_base.png', i.e. 'mymod_base.png'.
  49. \nYou can also supply an optional overlay image filename. This image will be
  50. composited onto the output files after they have been colorized, but without
  51. being modified. This is useful when you have some part of your base image
  52. that will either get changed undesirably (for example, the mortar among
  53. several bricks, or the shading detail of a stone pattern). Simply draw two
  54. images: one containing the whole image to be colored, and one containing the
  55. parts that should not be changed, with either full or partial alpha
  56. transparency where the re-colored base image should show through. Skilled use
  57. of color and alpha on this overlay can lead to some interesting effects.
  58. \nIf you add '-t' as the first parameter, the script will switch to 'tint
  59. overlay' mode. For this mode to work, you must also supply the base name as
  60. usual, and you must include an overlay image filename. Rather than re-color
  61. the base texture, the script will alter the hue/saturation/value of the
  62. overlay texture file instead, and leave the base texture unchanged. When
  63. using this mode, the base texture should be drawn in some neutral color, but
  64. any color is fine if it results in what you wanted.\n"
  65. exit 1
  66. } fi
  67. if [[ ! -e $BASE"_base.png" ]]; then {
  68. echo -e "\nThe basename '"$BASE"_base.png' was not found."
  69. echo -e "\nAborting.\n"
  70. exit 1
  71. } fi
  72. if [[ ! -z $COMPOSITE && ! -e $COMPOSITE ]]; then {
  73. echo -e "\nThe requested composite file '"$COMPOSITE"' was not found."
  74. echo -e "\nAborting.\n"
  75. exit 1
  76. } fi
  77. convert $BASE"_base.png" -modulate 1,2,3 tempfile.png 1>/dev/null 2>/dev/null
  78. if (( $? )) ; then {
  79. echo -e "\nImagemagick failed while testing the base texture file."
  80. echo -e "\nEither the base file '"$BASE"_base.png' isn't an image,"
  81. echo "or it is broken, or Imagemagick itself just didn't work."
  82. echo -e "\nPlease check and correct your base image and try again."
  83. echo -e "\nAborting.\n"
  84. exit 1
  85. } fi
  86. if [ ! -z $COMPOSITE ] ; then {
  87. convert $BASE"_base.png" -modulate 1,2,3 $COMPOSITE -composite tempfile.png 1>/dev/null 2>/dev/null
  88. if (( $? )) ; then {
  89. echo -e "\nImagemagick failed while testing the composite file."
  90. echo -e "\nEither the composite file '"$COMPOSITE"' isn't an image"
  91. echo "or it is broken, or Imagemagick itself just didn't work."
  92. echo -e "\nPlease check and correct your composite image and try again."
  93. echo -e "\nAborting.\n"
  94. exit 1
  95. } fi
  96. } fi
  97. rm tempfile.png
  98. base_colors="red orange yellow lime green aqua cyan skyblue blue violet magenta redviolet"
  99. echo -e -n "\nGenerating filenames based on "$BASE"_base.png"
  100. if [ ! -z $COMPOSITE ] ; then {
  101. echo ","
  102. echo -n "using "$COMPOSITE" as an overlay"
  103. } fi
  104. if [ ! -z $TINT_OVERLAY ] ; then {
  105. echo ","
  106. echo -n "and tinting the overlay instead of the base texture"
  107. } fi
  108. echo -e "...\n"
  109. mkdir -p generated-textures
  110. function generate_texture () {
  111. name=$1
  112. h=$2
  113. s=$3
  114. v=$4
  115. if [ -z $TINT_OVERLAY ]; then {
  116. if [ -z $COMPOSITE ]; then {
  117. convert $BASE"_base.png" -modulate $v,$s,$h "generated-textures/"$BASE"_"$name".png"
  118. } else {
  119. convert $BASE"_base.png" -modulate $v,$s,$h $COMPOSITE -composite "generated-textures/"$BASE"_"$name".png"
  120. } fi
  121. } else {
  122. convert $COMPOSITE -modulate $v,$s,$h MIFF:- | composite MIFF:- $BASE"_base.png" "generated-textures/"$BASE"_"$name".png"
  123. } fi
  124. }
  125. hue=0
  126. for color_name in $base_colors ; do
  127. hue2=`echo "scale=10; ("$hue"*200/360)+100" |bc`
  128. echo $color_name "("$hue" degrees)"
  129. echo " dark"
  130. generate_texture "dark_"$color_name $hue2 100 33
  131. echo " medium"
  132. generate_texture "medium_"$color_name $hue2 100 66
  133. echo " full"
  134. generate_texture $color_name $hue2 100 100
  135. echo " light"
  136. generate_texture "light_"$color_name $hue2 100 150
  137. echo " dark, 50% saturation"
  138. generate_texture "dark_"$color_name"_s50" $hue2 50 33
  139. echo " medium, 50% saturation"
  140. generate_texture "medium_"$color_name"_s50" $hue2 50 66
  141. echo " full, 50% saturation"
  142. generate_texture $color_name"_s50" $hue2 50 100
  143. hue=$((hue+30))
  144. done
  145. echo "greyscales"
  146. echo " black"
  147. generate_texture black 0 0 15
  148. echo " dark grey"
  149. generate_texture darkgrey 0 0 50
  150. echo " medium grey"
  151. generate_texture grey 0 0 100
  152. echo " light grey"
  153. generate_texture lightgrey 0 0 150
  154. echo " white"
  155. generate_texture white 0 0 190