1
0
mirror of https://github.com/mt-mods/unifieddyes.git synced 2024-12-25 02:00:27 +01:00

Rewrite gentextures.sh a bit, added an option to allow the overlay to be

colored while the base remains unmodified.  Clarified usage information
regarding the use of alpha translucency.
This commit is contained in:
Vanessa Ezekowitz 2012-07-19 17:39:46 -04:00
parent e27c093d14
commit 132c1ec9f4

View File

@ -1,36 +1,49 @@
#!/bin/bash #!/bin/bash
TEXTURE=$1 if [ $1 = "-t" ] ; then {
TINT_OVERLAY=$1
BASE=$2
COMPOSITE=$3
} else {
TINT_OVERLAY=""
BASE=$1
COMPOSITE=$2 COMPOSITE=$2
} fi
base_texture="red_base_"$TEXTURE".png" if [ -z $1 ] || [ $1 == "--help" ] || [ $1 == "-h" ] || [[ $1 == "-t" && -z $3 ]] ; then {
if [ -z $TEXTURE ] || [ $TEXTURE == "--help" ] || [ $TEXTURE == "-h" ] ; then { echo -e "\nUsage:
\ngentextures.sh basename [overlay_filename]
echo -e "\nUsage:" gentextures.sh -t basename overlay_filename
echo -e "\ngentextures.sh basename [overlay filename]" \nThis script requires up to three parameters which supply the base filename
echo -e "\nThis script requires one or two parameters which supply the" of the textures, an optional overlay, and possibly the '-t' switch. The
echo -e "base filename of the textures, and an optional overlay. The" 'basename' is the first part of the filename that your textures will use when
echo -e "<basename> is the first part of the filename that your textures" your mod is done, which should almost always be the same as the one-word name
echo -e "will use when your mod is done. For example, if you supply the" of your mod. For example, if you supply the word 'mymod', this script will
echo -e "word 'cotton', this script will produce filenames like cotton_red.png" produce filenames like mymod_red.png or 'mymod_dark_blue_s50.png'. The
echo -e "or 'cotton_dark_blue_s50.png'. The texture that this script will" texture that this script will read and recolor is derived from this parameter,
echo -e "read and recolor is derived from this parameter, and will be of" and will be of the form 'basename_base.png', i.e. 'mymod_base.png'.
echo -e "the form 'red_base_xxxxx.png', where 'xxxx' is the basename." \nYou can also supply an optional overlay image filename. This image will be
echo -e "\nYou can also supply an optional overlay image filename." composited onto the output files after they have been colorized, but without
echo -e "This image will be composited onto the output files after they" being modified. This is useful when you have some part of your base image
echo -e "have been colorized, but without being modified. This is useful" that will either get changed undesirably (for example, the mortar among
echo -e "when you have some part of your base image that will either get" several bricks, or the shading detail of a stone pattern). Simply draw two
echo -e "changed unpredictably or undesirably. Simply draw two images -" images: one containing the whole image to be colored, and one containing the
echo -e "one containing the whole image to be colored, and one containing" parts that should not be changed, with either full or partial alpha
echo -e "the parts that should not be changed, with transparency where the" transparency where the re-colored base image should show through. Skilled use
echo -e "base image should show through.\n" of color and alpha on this overlay can lead to some interesting effects.
\nIf you add '-t' as the first parameter, the script will switch to 'tint
overlay' mode. For this mode to work, you must also supply the base name as
usual, and you must include an overlay image filename. Rather than re-color
the base texture, the script will alter the hue/saturation/value of the
overlay texture file instead, and leave the base texture unchanged. When
using this mode, the base texture should be drawn in some neutral color, but
any color is fine if it results in what you wanted.\n"
exit 1 exit 1
} fi } fi
if [[ ! -e $BASE"_base.png" ]]; then {
if [[ ! -z $TEXTURE && ! -e $base_texture ]]; then { echo -e "\nThe basename '"$BASE"_base.png' was not found."
echo -e "\nThe basename 'red_base_"$TEXTURE".png' was not found."
echo -e "\nAborting.\n" echo -e "\nAborting.\n"
exit 1 exit 1
} fi } fi
@ -41,22 +54,19 @@ if [[ ! -z $COMPOSITE && ! -e $COMPOSITE ]]; then {
exit 1 exit 1
} fi } fi
convert $BASE"_base.png" -modulate 1,2,3 tempfile.png 1>/dev/null 2>/dev/null
convert $base_texture -modulate 1,2,3 tempfile.png 1>/dev/null 2>/dev/null
if (( $? )) ; then { if (( $? )) ; then {
echo -e "\nImagemagick failed while testing the base texture file." echo -e "\nImagemagick failed while testing the base texture file."
echo -e "\nEither the base file 'red_base_"$TEXTURE".png isn't an image," echo -e "\nEither the base file '"$BASE"_base.png' isn't an image,"
echo "or it is broken, or Imagemagick itself just didn't work." echo "or it is broken, or Imagemagick itself just didn't work."
echo -e "\nPlease check and correct your base image and try again." echo -e "\nPlease check and correct your base image and try again."
echo -e "\nAborting.\n" echo -e "\nAborting.\n"
exit 1 exit 1
} fi } fi
composite_file=""
if [ ! -z $COMPOSITE ] ; then { if [ ! -z $COMPOSITE ] ; then {
convert $base_texture -modulate 1,2,3 $COMPOSITE -composite tempfile.png 1>/dev/null 2>/dev/null convert $BASE"_base.png" -modulate 1,2,3 $COMPOSITE -composite tempfile.png 1>/dev/null 2>/dev/null
if (( $? )) ; then { if (( $? )) ; then {
echo -e "\nImagemagick failed while testing the composite file." echo -e "\nImagemagick failed while testing the composite file."
@ -66,53 +76,72 @@ if [ ! -z $COMPOSITE ] ; then {
echo -e "\nAborting.\n" echo -e "\nAborting.\n"
exit 1 exit 1
} fi } fi
composite_file=$COMPOSITE" -composite"
} fi } fi
rm tempfile.png rm tempfile.png
base_colors="red orange yellow lime green aqua cyan skyblue blue violet magenta redviolet" base_colors="red orange yellow lime green aqua cyan skyblue blue violet magenta redviolet"
echo -e -n "\nGenerating filenames based on "$base_texture echo -e -n "\nGenerating filenames based on "$BASE"_base.png"
if [ ! -z $COMPOSITE ] ; then { if [ ! -z $COMPOSITE ] ; then {
echo "," echo ","
echo -n "using "$COMPOSITE" as an overlay" echo -n "using "$COMPOSITE" as an overlay"
} fi } fi
if [ ! -z $TINT_OVERLAY ] ; then {
echo ","
echo -n "and tinting the overlay instead of the base texture"
} fi
echo -e "...\n" echo -e "...\n"
rm -rf generated-textures mkdir -p generated-textures
mkdir generated-textures
function generate_texture () {
name=$1
h=$2
s=$3
v=$4
if [ -z $TINT_OVERLAY ]; then {
if [ -z $COMPOSITE ]; then {
convert $BASE"_base.png" -modulate $v,$s,$h "generated-textures/"$BASE"_"$name".png"
} else {
convert $BASE"_base.png" -modulate $v,$s,$h $COMPOSITE -composite "generated-textures/"$BASE"_"$name".png"
} fi
} else {
convert $COMPOSITE -modulate $v,$s,$h MIFF:- | composite MIFF:- $BASE"_base.png" "generated-textures/"$BASE"_"$name".png"
} fi
}
hue=0 hue=0
for name in $base_colors ; do for color_name in $base_colors ; do
hue2=`echo "scale=10; ("$hue"*200/360)+100" |bc` hue2=`echo "scale=10; ("$hue"*200/360)+100" |bc`
echo $name "("$hue" degrees)" echo $color_name "("$hue" degrees)"
echo " dark" echo " dark"
convert $base_texture -modulate 33,100,$hue2 $composite_file "generated-textures/"$TEXTURE"_dark_"$name".png" generate_texture "dark_"$color_name $hue2 100 33
echo " medium" echo " medium"
convert $base_texture -modulate 66,100,$hue2 $composite_file "generated-textures/"$TEXTURE"_medium_"$name".png" generate_texture "medium_"$color_name $hue2 100 66
echo " full" echo " full"
convert $base_texture -modulate 100,100,$hue2 $composite_file "generated-textures/"$TEXTURE"_"$name".png" generate_texture $color_name $hue2 100 100
echo " light" echo " light"
convert $base_texture -modulate 150,100,$hue2 $composite_file "generated-textures/"$TEXTURE"_light_"$name".png" generate_texture "light_"$color_name $hue2 100 150
echo " dark, 50% saturation" echo " dark, 50% saturation"
convert $base_texture -modulate 33,50,$hue2 $composite_file "generated-textures/"$TEXTURE"_dark_"$name"_s50.png" generate_texture "dark_"$color_name"_s50" $hue2 50 33
echo " medium, 50% saturation" echo " medium, 50% saturation"
convert $base_texture -modulate 66,50,$hue2 $composite_file "generated-textures/"$TEXTURE"_medium_"$name"_s50.png" generate_texture "medium_"$color_name"_s50" $hue2 50 66
echo " full, 50% saturation" echo " full, 50% saturation"
convert $base_texture -modulate 100,50,$hue2 $composite_file "generated-textures/"$TEXTURE"_"$name"_s50.png" generate_texture $color_name"_s50" $hue2 50 100
hue=$((hue+30)) hue=$((hue+30))
done done
echo "greyscales" echo "greyscales"
echo " black" echo " black"
convert $base_texture -modulate 15,0,0 $composite_file "generated-textures/"$TEXTURE"_black.png" generate_texture black 0 0 15
echo " dark grey" echo " dark grey"
convert $base_texture -modulate 50,0,0 $composite_file "generated-textures/"$TEXTURE"_darkgrey.png" generate_texture darkgrey 0 0 50
echo " medium grey" echo " medium grey"
convert $base_texture -modulate 100,0,0 $composite_file "generated-textures/"$TEXTURE"_grey.png" generate_texture grey 0 0 100
echo " light grey" echo " light grey"
convert $base_texture -modulate 150,0,0 $composite_file "generated-textures/"$TEXTURE"_lightgrey.png" generate_texture lightgrey 0 0 150
echo " white" echo " white"
convert $base_texture -modulate 190,0,0 $composite_file "generated-textures/"$TEXTURE"_white.png" generate_texture white 0 0 190