More scripts for converting and pixelating images for the game.
This commit is contained in:
		
							parent
							
								
									cdd58ee21a
								
							
						
					
					
						commit
						74a1801069
					
				
					 4 changed files with 690 additions and 0 deletions
				
			
		
							
								
								
									
										347
									
								
								scripts/magick/tileimage
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										347
									
								
								scripts/magick/tileimage
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,347 @@ | |||
| #!/bin/bash | ||||
| # | ||||
| # Developed by Fred Weinhaus 8/10/2015 .......... revised 8/10/2015 | ||||
| # | ||||
| # ------------------------------------------------------------------------------ | ||||
| #  | ||||
| # Licensing: | ||||
| #  | ||||
| # Copyright © Fred Weinhaus | ||||
| #  | ||||
| # My scripts are available free of charge for non-commercial use, ONLY. | ||||
| #  | ||||
| # For use of my scripts in commercial (for-profit) environments or  | ||||
| # non-free applications, please contact me (Fred Weinhaus) for  | ||||
| # licensing arrangements. My email address is fmw at alink dot net. | ||||
| #  | ||||
| # If you: 1) redistribute, 2) incorporate any of these scripts into other  | ||||
| # free applications or 3) reprogram them in another scripting language,  | ||||
| # then you must contact me for permission, especially if the result might  | ||||
| # be used in a commercial or for-profit environment. | ||||
| #  | ||||
| # My scripts are also subject, in a subordinate manner, to the ImageMagick  | ||||
| # license, which can be found at: http://www.imagemagick.org/script/license.php | ||||
| #  | ||||
| # ------------------------------------------------------------------------------ | ||||
| #  | ||||
| #### | ||||
| # | ||||
| # USAGE: tileimage [-a arrangement] [-o orientation ] [-r repeats] [-w width ]   | ||||
| # [-h height] [-b bgcolor] infile outfile | ||||
| # | ||||
| # USAGE: tileimage [-help] | ||||
| # | ||||
| # OPTIONS: | ||||
| # | ||||
| # -a     arrangement     tiling arrangement; choices are: repeat, halfdrop,   | ||||
| #                        brick, verticalmirror, horizontalmirror or rotate;  | ||||
| #                        default=repeat | ||||
| # -o     orientation     orientation mode for image repeats; choices are: 0,  | ||||
| #                        90, 180, 270, flip, flop, transpose, transverse;  | ||||
| #                        default=0 | ||||
| # -r     repeats         number of horizontal repeats; integer>0; default=4 | ||||
| # -w     width           width of canvas in pixels; integer>0; default=512 | ||||
| # -h     height          height of canvas in pixels; integer>0; default=512 | ||||
| # -b     bgcolor         background color for canvas, if image is transparent; | ||||
| #                        any valid IM color; default="white" | ||||
| # | ||||
| ### | ||||
| # | ||||
| # NAME: TILEIMAGE  | ||||
| #  | ||||
| # PURPOSE: To tile an image to a given size with various tile arrangements. | ||||
| #  | ||||
| # DESCRIPTION: TILEIMAGE tiles an image to a given size. Several arrangements  | ||||
| # are possible as well as several orientations. The user can also specify the  | ||||
| # number of repeats across the width of the image. This script is typically  | ||||
| # used to tile objects on a constant color background. | ||||
| #  | ||||
| # OPTIONS:  | ||||
| #  | ||||
| # -a arrangement ... tiling ARRANGEMENT. The choices are: repeat (r),  | ||||
| # halfdrop (h), brick (b), verticalmirror (vm), horizontalmirror (hm), or .  | ||||
| # rotate (ro). The default=repeat. | ||||
| #  | ||||
| # -o orientation ... ORIENTATION mode for the image repeats. The choices are:  | ||||
| # 0 (degree rotation), 90 (degree rotation), 180 (degree rotation),  | ||||
| # 270 (degree rotation), flip, flop, transpose, transverse. The default=0. | ||||
| #  | ||||
| # -r repeats ... REPEATS is the number of horizontal repeats across the image.  | ||||
| # Values are integers>0. The default=4. | ||||
| #  | ||||
| # -w width ... WIDTH of output image in pixels. Values are integers>0. The  | ||||
| # default=512. | ||||
| #  | ||||
| # -h height ... HEIGHT of output image in pixels. Values are integers>0. The  | ||||
| # default=512. | ||||
| #  | ||||
| # -b bgcolor ... BGCOLOR is the desired background color for the output image,  | ||||
| # if the input image is transparent. Any valid IM color. The default="white". | ||||
| #  | ||||
| # CAVEAT: No guarantee that this script will work on all platforms,  | ||||
| # nor that trapping of inconsistent parameters is complete and  | ||||
| # foolproof. Use At Your Own Risk.  | ||||
| #  | ||||
| ###### | ||||
| # | ||||
| 
 | ||||
| # set default values | ||||
| arrangement="repeat" | ||||
| orientation="0" | ||||
| repeats=4 | ||||
| width=512 | ||||
| height=512 | ||||
| bgcolor="white" | ||||
| 
 | ||||
| # set directory for temporary files | ||||
| dir="."    # suggestions are dir="." or dir="/tmp" | ||||
| 
 | ||||
| # set up functions to report Usage and Usage with Description | ||||
| PROGNAME=`type $0 | awk '{print $3}'`  # search for executable on path | ||||
| PROGDIR=`dirname $PROGNAME`            # extract directory of program | ||||
| PROGNAME=`basename $PROGNAME`          # base name of program | ||||
| usage1()  | ||||
| 	{ | ||||
| 	echo >&2 "" | ||||
| 	echo >&2 "$PROGNAME:" "$@" | ||||
| 	sed >&2 -n '/^###/q;  /^#/!q;  s/^#//;  s/^ //;  4,$p' "$PROGDIR/$PROGNAME" | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| # function to report error messages | ||||
| errMsg() | ||||
| 	{ | ||||
| 	echo "" | ||||
| 	echo $1 | ||||
| 	echo "" | ||||
| 	usage1 | ||||
| 	exit 1 | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| # function to test for minus at start of value of second part of option 1 or 2 | ||||
| checkMinus() | ||||
| 	{ | ||||
| 	test=`echo "$1" | grep -c '^-.*$'`   # returns 1 if match; 0 otherwise | ||||
|     [ $test -eq 1 ] && errMsg "$errorMsg" | ||||
| 	} | ||||
| 
 | ||||
| # test for correct number of arguments and get values | ||||
| if [ $# -eq 0 ] | ||||
| 	then | ||||
| 	# help information | ||||
|    echo "" | ||||
|    usage1 | ||||
|    exit 0 | ||||
| elif [ $# -gt 14 ] | ||||
| 	then | ||||
| 	errMsg "--- TOO MANY ARGUMENTS WERE PROVIDED ---" | ||||
| else | ||||
| 	while [ $# -gt 0 ] | ||||
| 		do | ||||
| 			# get parameter values | ||||
| 			case "$1" in | ||||
| 		     -help)    # help information | ||||
| 					   echo "" | ||||
| 					   usage1 | ||||
| 					   exit 0 | ||||
| 					   ;; | ||||
| 		 		-a)    # arrangement | ||||
| 					   shift  # to get the next parameter | ||||
| 					   # test if parameter starts with minus sign  | ||||
| 					   errorMsg="--- INVALID ARRANGEMENT SPECIFICATION ---" | ||||
| 					   checkMinus "$1" | ||||
| 					   # test gravity values | ||||
| 					   arrangement="$1" | ||||
| 					   arrangement=`echo "$1" | tr '[A-Z]' '[a-z]'` | ||||
| 					   case "$arrangement" in  | ||||
| 					   		repeat|r) arrangement="repeat" ;; | ||||
| 					   		halfdrop|h) arrangement="halfdrop" ;; | ||||
| 					   		brick|b) arrangement="brick" ;; | ||||
| 					   		verticalmirror|vm) arrangement="verticalmirror" ;; | ||||
| 					   		horizontalmirror|hm) arrangement="horizontalmirror" ;; | ||||
| 					   		rotate|ro) arrangement="rotate" ;; | ||||
| 					   		*) errMsg "--- ARRANGEMENT=$arrangement IS AN INVALID OPTION ---" ;; | ||||
| 					   	esac | ||||
| 					   ;; | ||||
| 		 		-o)    # orientation | ||||
| 					   shift  # to get the next parameter | ||||
| 					   # test if parameter starts with minus sign  | ||||
| 					   errorMsg="--- INVALID ORIENTATION SPECIFICATION ---" | ||||
| 					   checkMinus "$1" | ||||
| 					   # test gravity values | ||||
| 					   orientation="$1" | ||||
| 					   orientation=`echo "$1" | tr '[A-Z]' '[a-z]'` | ||||
| 					   case "$orientation" in  | ||||
| 					   		0) orientation="0" ;; | ||||
| 					   		90) orientation="90" ;; | ||||
| 					   		180) orientation="180" ;; | ||||
| 					   		270) orientation="270" ;; | ||||
| 					   		flip) orientation="flip" ;; | ||||
| 					   		flop) orientation="flop" ;; | ||||
| 					   		transpose) orientation="transpose" ;; | ||||
| 					   		transverse) orientation="transverse" ;; | ||||
| 					   		*) errMsg "--- ORIENTATION=$orientation IS AN INVALID OPTION ---" ;; | ||||
| 					   	esac | ||||
| 					   ;; | ||||
| 				-w)    # get width | ||||
| 					   shift  # to get the next parameter | ||||
| 					   # test if parameter starts with minus sign  | ||||
| 					   errorMsg="--- INVALID WIDTH SPECIFICATION ---" | ||||
| 					   checkMinus "$1" | ||||
| 					   width=`expr "$1" : '\([.0-9]*\)'` | ||||
| 					   [ "$width" = "" ] && errMsg "--- WIDTH=$width MUST BE A NON-NEGATIVE FLOAT ---" | ||||
| 					   test=`echo "$width <= 0" | bc` | ||||
| 					   [ $test -eq 1 ] && errMsg "--- WIDTH=$width MUST BE A POSITIVE FLOAT ---" | ||||
| 					   ;; | ||||
| 				-h)    # get height | ||||
| 					   shift  # to get the next parameter | ||||
| 					   # test if parameter starts with minus sign  | ||||
| 					   errorMsg="--- INVALID HEIGHT SPECIFICATION ---" | ||||
| 					   checkMinus "$1" | ||||
| 					   height=`expr "$1" : '\([.0-9]*\)'` | ||||
| 					   [ "$height" = "" ] && errMsg "--- HEIGHT=$height MUST BE A NON-NEGATIVE FLOAT ---" | ||||
| 					   test=`echo "$height <= 0" | bc` | ||||
| 					   [ $test -eq 1 ] && errMsg "--- HEIGHT=$height MUST BE A POSITIVE FLOAT ---" | ||||
| 					   ;; | ||||
| 				-r)    # get repeats | ||||
| 					   shift  # to get the next parameter | ||||
| 					   # test if parameter starts with minus sign  | ||||
| 					   errorMsg="--- INVALID REPEATS SPECIFICATION ---" | ||||
| 					   checkMinus "$1" | ||||
| 					   repeats=`expr "$1" : '\([0-9]*\)'` | ||||
| 					   [ "$repeats" = "" ] && errMsg "--- REPEATS=$repeats MUST BE A NON-NEGATIVE INTEGER ---" | ||||
| 					   test=`echo "$repeats == 0" | bc` | ||||
| 					   [ $test -eq 1 ] && errMsg "--- REPEATS=$repeats MUST BE A POSITIVE INTEGER ---" | ||||
| 					   ;; | ||||
| 			    -b)    # get bgcolor | ||||
| 					   shift  # to get the next parameter | ||||
| 					   # test if parameter starts with minus sign  | ||||
| 					   errorMsg="--- INVALID BGCOLOR SPECIFICATION ---" | ||||
| 					   checkMinus "$1" | ||||
| 					   bgcolor="$1" | ||||
| 					   ;; | ||||
| 				 -)    # STDIN and end of arguments | ||||
| 					   break | ||||
| 					   ;; | ||||
| 				-*)    # any other - argument | ||||
| 					   errMsg "--- UNKNOWN OPTION ---" | ||||
| 					   ;; | ||||
| 		     	 *)    # end of arguments | ||||
| 					   break | ||||
| 					   ;; | ||||
| 			esac | ||||
| 			shift   # next option | ||||
| 	done | ||||
| 	# | ||||
| 	# get infile and outfile | ||||
| 	infile="$1" | ||||
| 	outfile="$2" | ||||
| fi | ||||
| 
 | ||||
| # test that infile provided | ||||
| [ "$infile" = "" ] && errMsg "NO INPUT FILE SPECIFIED" | ||||
| 
 | ||||
| # test that outfile provided | ||||
| [ "$outfile" = "" ] && errMsg "NO OUTPUT FILE SPECIFIED" | ||||
| 
 | ||||
| 
 | ||||
| # setup temporary images | ||||
| tmpA1="$dir/tileimage_1_$$.mpc" | ||||
| tmpB1="$dir/tileimage_1_$$.cache" | ||||
| trap "rm -f $tmpA1 $tmpB1;" 0 | ||||
| trap "rm -f $tmpA1 $tmpB1; exit 1" 1 2 3 15 | ||||
| trap "rm -f $tmpA1 $tmpB1; exit 1" ERR | ||||
| 
 | ||||
| 
 | ||||
| # read the input image into the temporary cached image and test if valid | ||||
| # read the input image into the temporary cached image and test if valid | ||||
| convert -quiet "$infile" +repage "$tmpA1" || | ||||
| 	errMsg "--- FILE $infile DOES NOT EXIST OR IS NOT AN ORDINARY FILE, NOT READABLE OR HAS ZERO size  ---" | ||||
| 
 | ||||
| # get infile dimensions | ||||
| ww=`identify -ping -format "%w" $tmpA1` | ||||
| hh=`identify -ping -format "%h" $tmpA1` | ||||
| 
 | ||||
| # get scaling factor for infile in percent | ||||
| factor=`convert xc: -format "%[fx:100*$width/($repeats*$ww)]" info:`  | ||||
| 
 | ||||
| # scale the infile | ||||
| convert $tmpA1 -resize $factor% $tmpA1 | ||||
| 
 | ||||
| # compute resized dimensions | ||||
| ww=`identify -ping -format "%w" $tmpA1` | ||||
| hh=`identify -ping -format "%h" $tmpA1` | ||||
| 
 | ||||
| # get half sizes for offsets | ||||
| ww2=`convert xc: -format "%[fx:round($ww/2)]" info:`  | ||||
| hh2=`convert xc: -format "%[fx:round($hh/2)]" info:`  | ||||
| 
 | ||||
| 
 | ||||
| # set up orientation | ||||
| if [ "$orientation" = "0" ]; then | ||||
| 	orienting="" | ||||
| elif [ "$orientation" = "90" ]; then | ||||
| 	orienting="-rotate 90" | ||||
| elif [ "$orientation" = "180" ]; then | ||||
| 	orienting="-rotate 180" | ||||
| elif [ "$orientation" = "270" ]; then | ||||
| 	orienting="-rotate 270" | ||||
| elif [ "$orientation" = "flip" ]; then | ||||
| 	orienting="-flip" | ||||
| elif [ "$orientation" = "flop" ]; then | ||||
| 	orienting="-flop" | ||||
| elif [ "$orientation" = "transpose" ]; then | ||||
| 	orienting="-transpose" | ||||
| elif [ "$orientation" = "transverse" ]; then | ||||
| 	orienting="-transverse" | ||||
| fi | ||||
| 
 | ||||
| # process image | ||||
| if [ "$arrangement" = "repeat" ]; then | ||||
| #echo "repeat; orient=$orienting; width=$width; height=$height; bgcolor=$bgcolor;" | ||||
| 	convert $tmpA1 $orienting -write mpr:cell +delete \ | ||||
| 		-size ${width}x${height} tile:mpr:cell \ | ||||
| 		-background $bgcolor -flatten "$outfile" | ||||
| 				 | ||||
| elif [ "$arrangement" = "halfdrop" ]; then | ||||
| 	convert $tmpA1 \ | ||||
| 		\( -clone 0 $orienting -roll +0+${hh2} \) +append \ | ||||
| 		-write mpr:cell +delete \ | ||||
| 		-size ${width}x${height} tile:mpr:cell \ | ||||
| 		-background "$bgcolor" -flatten "$outfile" | ||||
| 
 | ||||
| elif [ "$arrangement" = "brick" ]; then | ||||
| 	convert $tmpA1 \ | ||||
| 		\( -clone 0 $orienting -roll +${ww2}+0 \) -append \ | ||||
| 		-write mpr:cell +delete \ | ||||
| 		-size ${width}x${height} tile:mpr:cell \ | ||||
| 		-background "$bgcolor" -flatten "$outfile" | ||||
| 		 | ||||
| elif [ "$arrangement" = "verticalmirror" ]; then | ||||
| 	convert $tmpA1 \ | ||||
| 		\( -clone 0 $orienting \) +append \ | ||||
| 		\( -clone 0 -flip \) -append \ | ||||
| 		-write mpr:cell +delete \ | ||||
| 		-size ${width}x${height} tile:mpr:cell \ | ||||
| 		-background "$bgcolor" -flatten "$outfile" | ||||
| 
 | ||||
| elif [ "$arrangement" = "horizontalmirror" ]; then | ||||
| 	convert $tmpA1 \ | ||||
| 		\( -clone 0 $orienting \) -append \ | ||||
| 		\( -clone 0 -flop \) +append \ | ||||
| 		-write mpr:cell +delete \ | ||||
| 		-size ${width}x${height} tile:mpr:cell \ | ||||
| 		-background "$bgcolor" -flatten "$outfile" | ||||
| 
 | ||||
| elif [ "$arrangement" = "rotate" ]; then | ||||
| 	convert $tmpA1 $orienting \ | ||||
| 		\( -clone 0 -rotate 90 \) +append \ | ||||
| 		\( -clone 0 -rotate 180 \) -append \ | ||||
| 		-write mpr:cell +delete \ | ||||
| 		-size ${width}x${height} tile:mpr:cell \ | ||||
| 		-background "$bgcolor" -flatten "$outfile" | ||||
| 
 | ||||
| fi | ||||
| 
 | ||||
| exit 0 | ||||
							
								
								
									
										302
									
								
								scripts/magick/tiler
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										302
									
								
								scripts/magick/tiler
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,302 @@ | |||
| #!/bin/bash | ||||
| # | ||||
| # Developed by Fred Weinhaus 4/8/2011 .......... revised 5/3/2015 | ||||
| # | ||||
| # ------------------------------------------------------------------------------ | ||||
| #  | ||||
| # Licensing: | ||||
| #  | ||||
| # Copyright © Fred Weinhaus | ||||
| #  | ||||
| # My scripts are available free of charge for non-commercial use, ONLY. | ||||
| #  | ||||
| # For use of my scripts in commercial (for-profit) environments or  | ||||
| # non-free applications, please contact me (Fred Weinhaus) for  | ||||
| # licensing arrangements. My email address is fmw at alink dot net. | ||||
| #  | ||||
| # If you: 1) redistribute, 2) incorporate any of these scripts into other  | ||||
| # free applications or 3) reprogram them in another scripting language,  | ||||
| # then you must contact me for permission, especially if the result might  | ||||
| # be used in a commercial or for-profit environment. | ||||
| #  | ||||
| # My scripts are also subject, in a subordinate manner, to the ImageMagick  | ||||
| # license, which can be found at: http://www.imagemagick.org/script/license.php | ||||
| #  | ||||
| # ------------------------------------------------------------------------------ | ||||
| #  | ||||
| #### | ||||
| # | ||||
| # USAGE: tiler [-m method] [-o overlap] [-v vpmethod] infile outfile | ||||
| # USAGE: tiler [-h or -help] | ||||
| # | ||||
| # OPTIONS: | ||||
| # | ||||
| # -m      method          method of overlap blending; choices are 1 or 2; | ||||
| #                         1 is simple average blending; 2 is ramped blending; | ||||
| #                         default=1 | ||||
| # -o      overlap         seam overlap amount in pixels; integer>=0; default=2 | ||||
| # -v      vpmethod        virtual-pixel method used to extend the quadrants;  | ||||
| #                         any valid IM non-background virtual-pixel method | ||||
| #                         is allowed. Best choices seem to be mirror or edge; | ||||
| #                         default=mirror | ||||
| # | ||||
| # NOTE: the input image (infile) must be square and have even dimensions. | ||||
| #  | ||||
| ### | ||||
| # | ||||
| # NAME: TILER  | ||||
| #  | ||||
| # PURPOSE: To convert an image into a tilable texture. | ||||
| #  | ||||
| # DESCRIPTION: TILER converts an image into a tilable texture. It does this  | ||||
| # by swapping diagonal quadrants, exending the borders to get overlap and  | ||||
| # then composite blending the extended quadrants. The extension and blending | ||||
| # attempt to minimize or avoid manual painting/blurring/cloning along the  | ||||
| # seams. | ||||
| #  | ||||
| # OPTIONS:  | ||||
| #  | ||||
| # -m method ... METHOD of overlap blending. The choices are 1 or 2. Method 1  | ||||
| # is a simple average blending. Method 2 is a ramped blending. The default=1. | ||||
| #  | ||||
| # -o overlap ... OVERLAP is amount of extension of the quadrants in order to  | ||||
| # cover the center horizontal and vertical seems. Values are integers>=0.  | ||||
| # The default=2 | ||||
| # | ||||
| # -v vpmethod ... VPMETHOD is the virtual-pixel method used to extend the  | ||||
| # quadrants. Any valid IM non-background virtual-pixel method is allowed. | ||||
| # Recommended values are either mirror or edge. The default is mirror. | ||||
| #  | ||||
| # Requirement: IM 6.5.3-4 or higher due to the use in method 1 of  | ||||
| # convert ... -compose blend -define compose:args=50,50 -composite ... | ||||
| #  | ||||
| # CAVEAT: No guarantee that this script will work on all platforms,  | ||||
| # nor that trapping of inconsistent parameters is complete and  | ||||
| # foolproof. Use At Your Own Risk.  | ||||
| #  | ||||
| ###### | ||||
| # | ||||
| 
 | ||||
| # set default values | ||||
| method=1		# blending method | ||||
| overlap=2		# overlap of quadrants | ||||
| vp="mirror"		# virtual pixel method for extending the quadrants | ||||
| 
 | ||||
| # set directory for temporary files | ||||
| dir="."    # suggestions are dir="." or dir="/tmp" | ||||
| 
 | ||||
| # set up functions to report Usage and Usage with Description | ||||
| PROGNAME=`type $0 | awk '{print $3}'`  # search for executable on path | ||||
| PROGDIR=`dirname $PROGNAME`            # extract directory of program | ||||
| PROGNAME=`basename $PROGNAME`          # base name of program | ||||
| usage1()  | ||||
| 	{ | ||||
| 	echo >&2 "" | ||||
| 	echo >&2 "$PROGNAME:" "$@" | ||||
| 	sed >&2 -e '1,/^####/d;  /^###/g;  /^#/!q;  s/^#//;  s/^ //;  4,$p' "$PROGDIR/$PROGNAME" | ||||
| 	} | ||||
| usage2()  | ||||
| 	{ | ||||
| 	echo >&2 "" | ||||
| 	echo >&2 "$PROGNAME:" "$@" | ||||
| 	sed >&2 -e '1,/^####/d;  /^######/g;  /^#/!q;  s/^#*//;  s/^ //;  4,$p' "$PROGDIR/$PROGNAME" | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| # function to report error messages | ||||
| errMsg() | ||||
| 	{ | ||||
| 	echo "" | ||||
| 	echo $1 | ||||
| 	echo "" | ||||
| 	usage1 | ||||
| 	exit 1 | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| # function to test for minus at start of value of second part of option 1 or 2 | ||||
| checkMinus() | ||||
| 	{ | ||||
| 	test=`echo "$1" | grep -c '^-.*$'`   # returns 1 if match; 0 otherwise | ||||
|     [ $test -eq 1 ] && errMsg "$errorMsg" | ||||
| 	} | ||||
| 
 | ||||
| # test for correct number of arguments and get values | ||||
| if [ $# -eq 0 ] | ||||
| 	then | ||||
| 	# help information | ||||
|    echo "" | ||||
|    usage2 | ||||
|    exit 0 | ||||
| elif [ $# -gt 8 ] | ||||
| 	then | ||||
| 	errMsg "--- TOO MANY ARGUMENTS WERE PROVIDED ---" | ||||
| else | ||||
| 	while [ $# -gt 0 ] | ||||
| 		do | ||||
| 			# get parameter values | ||||
| 			case "$1" in | ||||
| 		  -h|-help)    # help information | ||||
| 					   echo "" | ||||
| 					   usage2 | ||||
| 					   exit 0 | ||||
| 					   ;; | ||||
| 				-m)    # get method | ||||
| 					   shift  # to get the next parameter | ||||
| 					   # test if parameter starts with minus sign  | ||||
| 					   errorMsg="--- INVALID METHOD SPECIFICATION ---" | ||||
| 					   checkMinus "$1" | ||||
| 					   method=`expr "$1" : '\([0-2]*\)'` | ||||
| 					   [ "$method" = "" ] && errMsg "--- METHOD=$method MUST BE A NON-NEGATIVE INTEGER ---" | ||||
| 					   [ $method -ne 1 -a $method -ne 2 ] && errMsg "--- METHOD=$method MUST BE EITHER 1 OR 2 ---" | ||||
| 					   ;; | ||||
| 				-o)    # get overlap | ||||
| 					   shift  # to get the next parameter | ||||
| 					   # test if parameter starts with minus sign  | ||||
| 					   errorMsg="--- INVALID OVERLAP SPECIFICATION ---" | ||||
| 					   checkMinus "$1" | ||||
| 					   overlap=`expr "$1" : '\([0-9]*\)'` | ||||
| 					   [ "$overlap" = "" ] && errMsg "--- OVERLAP=$overlap MUST BE A NON-NEGATIVE INTEGER ---" | ||||
| 					   ;; | ||||
| 				-v)    # get  vpmethod | ||||
| 					   shift  # to get the next parameter | ||||
| 					   # test if parameter starts with minus sign  | ||||
| 					   errorMsg="--- INVALID VPMETHOD SPECIFICATION ---" | ||||
| 					   checkMinus "$1" | ||||
| 					   vp="$1" | ||||
| 					   vp=`echo "$vp" | tr "[:upper:]" "[:lower:]"` | ||||
| 					   case "$vp" in  | ||||
| 					   		black) ;; | ||||
| 					   		dither) ;; | ||||
| 					   		edge) ;; | ||||
| 					   		gray) ;; | ||||
| 					   		mirror) ;; | ||||
| 					   		random) ;; | ||||
| 					   		tile) ;; | ||||
| 					   		transparent) ;; | ||||
| 					   		white) ;; | ||||
| 					   		*) errMsg "--- VPMETHOD=$vp IS AN INVALID VALUE ---"  | ||||
| 					   	esac | ||||
| 					   ;; | ||||
| 				 -)    # STDIN and end of arguments | ||||
| 					   break | ||||
| 					   ;; | ||||
| 				-*)    # any other - argument | ||||
| 					   errMsg "--- UNKNOWN OPTION ---" | ||||
| 					   ;; | ||||
| 		     	 *)    # end of arguments | ||||
| 					   break | ||||
| 					   ;; | ||||
| 			esac | ||||
| 			shift   # next option | ||||
| 	done | ||||
| 	# | ||||
| 	# get infile and outfile | ||||
| 	infile="$1" | ||||
| 	outfile="$2" | ||||
| fi | ||||
| 
 | ||||
| # test that infile provided | ||||
| [ "$infile" = "" ] && errMsg "NO INPUT FILE SPECIFIED" | ||||
| 
 | ||||
| # test that outfile provided | ||||
| [ "$outfile" = "" ] && errMsg "NO OUTPUT FILE SPECIFIED" | ||||
| 
 | ||||
| 
 | ||||
| # set up temp files | ||||
| tmpA1="$dir/tiler_A_$$.mpc" | ||||
| tmpA2="$dir/tiler_A_$$.cache" | ||||
| tmpM1="$dir/tiler_M_$$.mpc" | ||||
| tmpM2="$dir/tiler_M_$$.cache" | ||||
| tmpN1="$dir/tiler_N_$$.mpc" | ||||
| tmpN2="$dir/tiler_N_$$.cache" | ||||
| trap "rm -f $tmpA1 $tmpA2 $tmpM1 $tmpM2 $tmpN1 $tmpN2;" 0 | ||||
| trap "rm -f $tmpA1 $tmpA2 $tmpM1 $tmpM2 $tmpN1 $tmpN2; exit 1" 1 2 3 15 | ||||
| trap "rm -f $tmpA1 $tmpA2 $tmpM1 $tmpM2 $tmpN1 $tmpN2; exit 1" ERR | ||||
| 
 | ||||
| 
 | ||||
| # read the input image into the tmp cached image. | ||||
| convert -quiet "$infile" +repage "$tmpA1" || | ||||
| 	errMsg "--- FILE $infile NOT READABLE OR HAS ZERO SIZE ---" | ||||
| 
 | ||||
| 
 | ||||
| # validate input image is square | ||||
| wd=`convert $tmpA1 -ping -format "%w" info:` | ||||
| ht=`convert $tmpA1 -ping -format "%h" info:` | ||||
| test0=`convert xc: -format "%[fx:$wd==$ht?1:0]" info:` | ||||
| [ $test0 -eq 0 ] && errMsg "--- FILE $infile IS NOT SQUARE ---" | ||||
| test1=`convert xc: -format "%[fx:mod($wd,2)]" info:` | ||||
| test2=`convert xc: -format "%[fx:mod($ht,2)]" info:` | ||||
| [ $test1 -eq 1 -o $test2 -eq 1 ] && errMsg "--- FILE $infile DOES NOT HAVE EVEN DIMENSIONS ---" | ||||
| 
 | ||||
| 
 | ||||
| # compute half width and other parameters | ||||
| ww=`convert xc: -format "%[fx:$wd/2]" info:` | ||||
| hh=`convert xc: -format "%[fx:$ht/2]" info:` | ||||
| wwo=`convert xc: -format "%[fx:$ww+$overlap]" info:` | ||||
| hho=`convert xc: -format "%[fx:$hh+$overlap]" info:` | ||||
| rollamount="+${ww}+${hh}" | ||||
| cropsize="${ww}x${hh}+0+0" | ||||
| www=$(($ww+$overlap)) | ||||
| hhh=$(($hh+$overlap)) | ||||
| sesize="${www}x${hhh}+0+0" | ||||
| swsize="${www}x${hhh}-$overlap+0" | ||||
| nesize="${www}x${hhh}+0-$overlap" | ||||
| nwsize="${www}x${hhh}-$overlap-$overlap" | ||||
| gsize=$(($overlap + 2)) | ||||
| 
 | ||||
| 
 | ||||
| # process image | ||||
| if [ $method -eq 1 ]; then | ||||
| 	# test for valid IM version | ||||
| 	im_version=`convert -list configure | \ | ||||
| 		sed '/^LIB_VERSION_NUMBER */!d;  s//,/;  s/,/,0/g;  s/,0*\([0-9][0-9]\)/\1/g' | head -n 1` | ||||
| 	[ "$im_version" -lt "06050304" ] && errMsg "--- REQUIRES IM VERSION 6.5.3-4 OR HIGHER ---" | ||||
| 	# Do simple average blending in overlap | ||||
| 	convert $tmpA1 \ | ||||
| 		\( -clone 0 -gravity southeast -crop $cropsize +repage -virtual-pixel $vp \ | ||||
| 			-define distort:viewport=$sesize -distort SRT 0 +repage \) \ | ||||
| 		\( -clone 0 -gravity southwest -crop $cropsize +repage -virtual-pixel $vp \ | ||||
| 			-define distort:viewport=$swsize -distort SRT 0 +repage \) \ | ||||
| 		\( -clone 0 -gravity northeast -crop $cropsize +repage -virtual-pixel $vp \ | ||||
| 			-define distort:viewport=$nesize -distort SRT 0 +repage \) \ | ||||
| 		\( -clone 0 -gravity northwest -crop $cropsize +repage -virtual-pixel $vp \ | ||||
| 			-define distort:viewport=$nwsize -distort SRT 0 +repage \) \ | ||||
| 		\( -clone 0 -roll $rollamount \ | ||||
| 			-clone 1 -gravity northwest -compose blend -define compose:args=50,50 -composite \ | ||||
| 			-clone 2 -gravity northeast -compose blend -define compose:args=50,50 -composite \ | ||||
| 			-clone 3 -gravity southwest -compose blend -define compose:args=50,50 -composite \ | ||||
| 			-clone 4 -gravity southeast -compose blend -define compose:args=50,50 -composite \) \ | ||||
| 		-delete 0-4 \ | ||||
| 		"$outfile" | ||||
| 
 | ||||
| elif [ $method -eq 2 ]; then | ||||
| 	# Create horizontal mask; black on left, gradient, white on right | ||||
| 	convert \( -size ${ww}x${hho} xc:black xc:white +append \) \ | ||||
| 		\( -size ${hho}x$gsize gradient: -rotate 90 \) -gravity center \ | ||||
| 		-compose over -composite +repage $tmpM1 | ||||
| 	# create vertical mask; black on top, gradient, white on bottom | ||||
| 	convert \( -size ${wd}x${hh} xc:black xc:white -append \) \ | ||||
| 		\( -size ${wd}x$gsize gradient: -rotate 180 \) -gravity center \ | ||||
| 		-compose over -composite +repage $tmpN1 | ||||
| 	# Do ramped blending in overlap | ||||
| 	convert $infile \ | ||||
| 		\( -clone 0 -gravity southeast -crop $cropsize +repage -virtual-pixel $vp \ | ||||
| 			-define distort:viewport=$sesize -distort SRT 0 +repage \) \ | ||||
| 		\( -clone 0 -gravity southwest -crop $cropsize +repage -virtual-pixel $vp \ | ||||
| 			-define distort:viewport=$swsize -distort SRT 0 +repage \) \ | ||||
| 		\( -clone 0 -gravity northeast -crop $cropsize +repage -virtual-pixel $vp \ | ||||
| 			-define distort:viewport=$nesize -distort SRT 0 +repage \) \ | ||||
| 		\( -clone 0 -gravity northwest -crop $cropsize +repage -virtual-pixel $vp \ | ||||
| 			-define distort:viewport=$nwsize -distort SRT 0 +repage \) \ | ||||
| 		\( -clone 1 -gravity northwest -extent ${wd}x${hho} -clone 2 $tmpM1 \ | ||||
| 			-gravity northeast -composite \) \ | ||||
| 		\( -clone 3 -gravity southwest -extent ${wd}x${hho} -clone 4 $tmpM1 \ | ||||
| 			-gravity southeast -composite \) \ | ||||
| 		\( -clone 5 -gravity north -extent ${wd}x${ht} -clone 6 $tmpN1 \ | ||||
| 			-gravity south -composite \) \ | ||||
| 		-delete 0-6 \ | ||||
| 		"$outfile" | ||||
| fi | ||||
| 
 | ||||
| exit 0 | ||||
							
								
								
									
										27
									
								
								scripts/munge_color.ps1
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								scripts/munge_color.ps1
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,27 @@ | |||
| Param ( | ||||
|     [string]$Colors=16, | ||||
|     [string]$Size="256x256", | ||||
|     [string]$Pixel="7" | ||||
|     ) | ||||
| 
 | ||||
| .\scripts\pixelize.ps1 -InFile C:\Users\lcthw\Pictures\Games\armored_knight_1.png -OutFile .\assets\armored_knight_1-256.png -Colors $Colors -Pixel $Pixel -Size $Size | ||||
| 
 | ||||
| .\scripts\pixelize.ps1 -InFile C:\Users\lcthw\Pictures\Games\gold_savior_oil.png -OutFile .\assets\gold_savior_oil-256.png -Colors $Colors -Pixel $Pixel -Size $Size | ||||
| 
 | ||||
| .\scripts\pixelize.ps1 -InFile C:\Users\lcthw\Pictures\Games\ceiling_test.png -OutFile .\assets\ceiling_test-256.png -Colors $Colors -Pixel $Pixel -Size $Size | ||||
| 
 | ||||
| .\scripts\pixelize.ps1 -InFile C:\Users\lcthw\Pictures\Games\torch_pillar.png -OutFile .\assets\torch_pillar-256.png -Colors $Colors -Pixel $Pixel -Size $Size | ||||
| 
 | ||||
| .\scripts\pixelize.ps1 -InFile C:\Users\lcthw\Pictures\Games\torch_pillar.png -OutFile .\assets\torch_pillar-256.png -Colors $Colors -Pixel $Pixel -Size $Size | ||||
| 
 | ||||
| .\scripts\pixelize.ps1 -InFile C:\Users\lcthw\Pictures\Games\glowing_moss_wall.png -OutFile .\assets\glowing_moss_wall-256.png -Colors $Colors -Pixel $Pixel -Size $Size | ||||
| 
 | ||||
| .\scripts\pixelize.ps1 -InFile C:\Users\lcthw\Pictures\Games\large_stone_floor.png -OutFile .\assets\large_stone_floor-256.png -Colors $Colors -Pixel $Pixel -Size $Size | ||||
| 
 | ||||
| .\scripts\pixelize.ps1 -InFile C:\Users\lcthw\Pictures\Games\floor_tile_test.png -OutFile .\assets\floor_tile_test-256.png -Colors $Colors -Pixel $Pixel -Size $Size | ||||
| 
 | ||||
| .\scripts\pixelize.ps1 -InFile C:\Users\lcthw\Pictures\Games\wall_texture_test.png -OutFile .\assets\wall_texture_test-256.png -Colors $Colors -Pixel $Pixel -Size $Size | ||||
| 
 | ||||
| .\scripts\pixelize.ps1 -InFile C:\Users\lcthw\Pictures\Games\hairy_spider.png -OutFile .\assets\hairy_spider-256.png -Colors $Colors -Pixel $Pixel -Size $Size | ||||
| 
 | ||||
| .\scripts\pixelize.ps1 -InFile C:\Users\lcthw\Pictures\Games\axe_ranger.png -OutFile .\assets\axe_ranger-256.png -Colors $Colors -Pixel $Pixel -Size $Size | ||||
							
								
								
									
										14
									
								
								scripts/pixelize.ps1
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										14
									
								
								scripts/pixelize.ps1
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,14 @@ | |||
| Param ( | ||||
|     [string]$InFile, | ||||
|     [string]$OutFile, | ||||
|     [string]$Colors=16, | ||||
|     [string]$Size="256x256", | ||||
|     [string]$Pixel="7" | ||||
|     ) | ||||
| 
 | ||||
| cp $InFile temp.png | ||||
| # magick temp.png -colors $Colors -quantize sRGB -dither FloydSteinberg color.png | ||||
| 
 | ||||
| magick temp.png -posterize $Colors -quantize sRGB -dither FloydSteinberg color.png | ||||
| bash ./scripts/magick/pixelize -s $Pixel -m 2 color.png pixels.png | ||||
| magick.exe pixels.png -interpolate nearest -interpolative-resize $Size $OutFile | ||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue
	
	 Zed A. Shaw
						Zed A. Shaw