First cut of pulling out the relevant parts of my original game to make a little framework.
This commit is contained in:
commit
6a0c9e8d46
177 changed files with 18197 additions and 0 deletions
1
scripts/animation_thing.ps1
Normal file
1
scripts/animation_thing.ps1
Normal file
|
|
@ -0,0 +1 @@
|
|||
magick montage -tile 3x1 -geometry +0+0 -background transparent .\assets\animations\torch_fixture_*.png assets/fixtures/torch_fixture.png
|
||||
41
scripts/build_assets.ps1
Normal file
41
scripts/build_assets.ps1
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
Param (
|
||||
[string]$Colors=16,
|
||||
[string]$Size="256x256"
|
||||
)
|
||||
|
||||
|
||||
function Build-Images {
|
||||
param (
|
||||
[string]$source,
|
||||
[string]$pixel_count
|
||||
)
|
||||
|
||||
$files = Get-ChildItem -Path "C:\Users\lcthw\Pictures\Games\Renders\Raycaster\$source"
|
||||
$out_dir = ".\assets\" + $source.ToLower()
|
||||
mkdir -force $out_dir
|
||||
|
||||
foreach($file in $files) {
|
||||
$in_name = $file.Name
|
||||
$out_file = "$out_dir\$in_name"
|
||||
Write-Output "In file: $in_name"
|
||||
Write-Output "Out file: $out_file"
|
||||
Write-Output "Size: $Size"
|
||||
|
||||
.\scripts\pixelize.ps1 -InFile $file.FullName -OutFile $out_file -Colors $Colors -Pixel $pixel_count -Size $Size
|
||||
}
|
||||
}
|
||||
|
||||
# Build-Images -Source "Textures" -pixel_count 12
|
||||
# Build-Images -Source "Sprites" -pixel_count 6
|
||||
# Build-Images -Source "Items" -pixel_count 2
|
||||
# Build-Images -Source "Animations" -pixel_count 24
|
||||
# Build-Images -Source "Hands" -pixel_count 6
|
||||
Build-Images -Source "Boss2" -pixel_count 4
|
||||
# Build-Images -Source "Fixtures" -pixel_count 24
|
||||
|
||||
|
||||
#magick montage -tile 3x1 -geometry +0+0 -background transparent .\assets\hands\female_hand_*.png .\assets\hands\female_hand.png
|
||||
|
||||
#magick montage -tile 3x1 -geometry +0+0 -background transparent .\assets\hands\male_hand_*.png .\assets\hands\male_hand.png
|
||||
|
||||
#cp -recurse -force C:\Users\lcthw\Pictures\Games\Renders\Raycaster\UI assets\ui
|
||||
13
scripts/coverage_report.ps1
Normal file
13
scripts/coverage_report.ps1
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
rm -recurse -force coverage/*
|
||||
cp *.cpp,*.hpp,*.rl builddir
|
||||
|
||||
. .venv/Scripts/activate
|
||||
|
||||
rm -recurse -force coverage
|
||||
cp scripts\gcovr_patched_coverage.py .venv\Lib\site-packages\gcovr\coverage.py
|
||||
|
||||
gcovr -o coverage/ --html --html-details --html-theme github.dark-blue --gcov-ignore-errors all --gcov-ignore-parse-errors negative_hits.warn_once_per_file -e builddir/subprojects -e builddir -e subprojects -e scratchpad -e tools -j 10 .
|
||||
|
||||
rm *.gcov.json.gz
|
||||
|
||||
start .\coverage\coverage_details.html
|
||||
7
scripts/coverage_reset.ps1
Normal file
7
scripts/coverage_reset.ps1
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
mv .\subprojects\packagecache .
|
||||
rm -recurse -force .\subprojects\,.\builddir\
|
||||
mkdir subprojects
|
||||
mv .\packagecache .\subprojects\
|
||||
mkdir builddir
|
||||
cp wraps\*.wrap subprojects\
|
||||
meson setup --default-library=static --prefer-static -Db_coverage=true builddir
|
||||
11
scripts/coverage_reset.sh
Normal file
11
scripts/coverage_reset.sh
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
mv -f ./subprojects/packagecache .
|
||||
rm -rf subprojects builddir
|
||||
mkdir subprojects
|
||||
mv packagecache ./subprojects/
|
||||
mkdir builddir
|
||||
cp wraps/*.wrap subprojects/
|
||||
# on OSX you can't do this with static
|
||||
meson setup -Db_coverage=true builddir
|
||||
1020
scripts/gcovr_patched_coverage.py
Normal file
1020
scripts/gcovr_patched_coverage.py
Normal file
File diff suppressed because it is too large
Load diff
188
scripts/magick/pixelize
Normal file
188
scripts/magick/pixelize
Normal file
|
|
@ -0,0 +1,188 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Developed by Fred Weinhaus 5/8/2008 .......... revised 4/25/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: pixelize [-s size] [-m mode] infile outfile
|
||||
# USAGE: pixelize [-h or -help]
|
||||
#
|
||||
# OPTIONS:
|
||||
#
|
||||
# -s size pixelization size; size>0; default=3
|
||||
# -m mode mode of minimizing; 1=resize; 2=sample; default=1
|
||||
#
|
||||
###
|
||||
#
|
||||
# NAME: PIXELIZE
|
||||
#
|
||||
# PURPOSE: To create a pixelized or blocky effect in an image.
|
||||
#
|
||||
# DESCRIPTION: PIXELIZE creates a pixelized or blocky effect in an
|
||||
# image where more pixelization (larger sizes) create larger blocky
|
||||
# effects.
|
||||
#
|
||||
# OPTIONS:
|
||||
#
|
||||
# -s size ... SIZE is the pixelization (block) size. Values are greater
|
||||
# than 0. The default is 3.
|
||||
#
|
||||
# -m mode ... MODE is the mode of minimizing. Choices are 1 for -resize
|
||||
# and 2 for -sample. The default=1
|
||||
#
|
||||
# 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
|
||||
size=3
|
||||
mode=1
|
||||
|
||||
# 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 6 ]
|
||||
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
|
||||
;;
|
||||
-s) # get size
|
||||
shift # to get the next parameter - scale
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID SIZE SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
size=`expr "$1" : '\([0-9]*\)'`
|
||||
[ "$size" = "" ] && errMsg "SIZE=$size MUST BE AN INTEGER"
|
||||
sizetest=`echo "$size <= 0" | bc`
|
||||
[ $sizetest -eq 1 ] && errMsg "--- SIZE=$size MUST BE A POSITIVE INTEGER ---"
|
||||
;;
|
||||
-m) # get mode
|
||||
shift # to get the next parameter - mode
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID MODE SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
mode=`expr "$1" : '\([0-9]*\)'`
|
||||
[ "$mode" = "" ] && errMsg "MODE=$mode MUST BE AN INTEGER"
|
||||
[ $mode -ne 1 -a $mode -ne 2 ] && errMsg "--- MODE=$mode MUST BE EITHER 1 OR 2 ---"
|
||||
;;
|
||||
-) # 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"
|
||||
|
||||
|
||||
# test if image an ordinary, readable and non-zero size
|
||||
if [ -f $infile -a -r $infile -a -s $infile ]
|
||||
then
|
||||
: 'Do Nothing'
|
||||
else
|
||||
errMsg "--- FILE $infile DOES NOT EXIST OR IS NOT AN ORDINARY FILE, NOT READABLE OR HAS ZERO SIZE ---"
|
||||
fi
|
||||
|
||||
# get parameters
|
||||
w=`convert $infile -format "%[fx:w]" info:`
|
||||
h=`convert $infile -format "%[fx:h]" info:`
|
||||
minify=`convert xc: -format "%[fx:100/$size]" info:`
|
||||
|
||||
# process image
|
||||
if [ $mode -eq 1 ]; then
|
||||
convert $infile -resize $minify% -scale ${w}x${h}! "$outfile"
|
||||
elif [ $mode -eq 2 ]; then
|
||||
convert $infile -sample $minify% -scale ${w}x${h}! "$outfile"
|
||||
fi
|
||||
exit 0
|
||||
372
scripts/magick/position
Normal file
372
scripts/magick/position
Normal file
|
|
@ -0,0 +1,372 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Developed by Fred Weinhaus 2/24/2022 .......... revised 2/24/2022
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
#
|
||||
# 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: position [-m method] [-d direction] [-o offset] [-l leftpt]
|
||||
# [-r rightpt] [-b bcolor] [-f format] [-T trim] infile1 infile2 outfile
|
||||
#
|
||||
# USAGE: position [-h or -help]
|
||||
#
|
||||
# OPTIONS:
|
||||
#
|
||||
# -m method positioning method; choices are: offset or cpoints;
|
||||
# default=offset
|
||||
# -d direction positioning direction; choices are: horizontal or
|
||||
# vertical; default=horizontal
|
||||
# -o offset offset +X+Y values for left/ope edge of second image
|
||||
# relative to right/bottom edge of first image. Used when
|
||||
# method=offset; positive or negative offsets are allowed;
|
||||
# default=+0+0
|
||||
# -l leftpt left (first) image control x,y point; default=0,0
|
||||
# -r rightpt right (second) image control x,y point; default=0,0
|
||||
# -b bcolor background color to fill empty spaces
|
||||
# -f format output color format; choices are: RG, GB, BR or RGB;
|
||||
# default=RGB
|
||||
# -T trim trim output to remove any background fill areas
|
||||
#
|
||||
###
|
||||
#
|
||||
# NAME: POSITION
|
||||
#
|
||||
# PURPOSE: To position one image relative to another image.
|
||||
#
|
||||
# DESCRIPTION: POSITION aligns or offsets one image relative to a another
|
||||
# image. The second image is positioned relative to the first image either
|
||||
# horizontally or vertically. Positioning can be done using X and Y offsets
|
||||
# or by specifying one controll point for each image.
|
||||
#
|
||||
# OPTIONS:
|
||||
#
|
||||
# -m method ... positioning METHOD. The choices are: offset (o) or cpoints (c).
|
||||
# The default=offset.
|
||||
#
|
||||
# -d direction ... positioning DIRECTION. The choices are: horizontal (h) or
|
||||
# vertical (v). The default=horizontal.
|
||||
#
|
||||
# -o offset ... OFFSET +X+Y values for left/top edge of second image relative
|
||||
# to right/bottom edge of first image. This is used when method=offset.
|
||||
# Position X and Y offsets may be either positive or negative. The default=+0+0
|
||||
#
|
||||
# -l leftpt ... LEFT (first) image control x,y POINT. Values are integers>0.
|
||||
# The default=0,0
|
||||
#
|
||||
# -r rightpt ... RIGHT (second) image control x,y POINT. Values are integers>0.
|
||||
# The default=0,0
|
||||
#
|
||||
# -b bcolor ... BGCOLOR is the background color to fill empty spaces. Any
|
||||
# Imagemagick color is allowed. The default=none (transparent)
|
||||
#
|
||||
# -f format ... output color FORMAT; The choices are: RG, GB, BR or RGB.
|
||||
# RGB is the normal color image. RG, for example, is first image in Red and
|
||||
# second image in Green and any overlay will show in yellow (mix of Red and
|
||||
# Green). The default=RGB.
|
||||
#
|
||||
# -T trim ... TRIM output to remove any background fill areas.
|
||||
# Choices are: yes (y) or no (n). The default=no. Background color must be
|
||||
# unique in the image for the trim to work properly.
|
||||
#
|
||||
# LIMITATIONS: TRIM option only works for Imagemagick 7.0.9-0 or higher.
|
||||
#
|
||||
# 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="offset" # offset or cpoints
|
||||
direction="horizontal" # horizontal or vertical
|
||||
offset=+0+0 # offset
|
||||
#offset=-90-40 # offset
|
||||
leftpt="0,0" # left image single control point
|
||||
rightpt="0,0" # right image single control point
|
||||
#leftpt="287,49" # left image single control point
|
||||
#rightpt="76,89" # right image single control point
|
||||
bcolor=none # background color
|
||||
format="RGB" # RG or GB or BR or RGB output color format
|
||||
trim="no" # trim output; yes or no
|
||||
|
||||
# set directory for temporary files
|
||||
tmpdir="/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 19 ]
|
||||
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) # method
|
||||
shift # to get the next parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID METHOD SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
method=`echo "$1" | tr "[:upper:]" "[:lower:]"`
|
||||
case "$method" in
|
||||
offset|o) method="offset" ;;
|
||||
cpoints|c) method="cpoints" ;;
|
||||
*) errMsg "--- METHOD=$method IS AN INVALID VALUE ---"
|
||||
esac
|
||||
;;
|
||||
-d) # direction
|
||||
shift # to get the next parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID DIRECTION SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
direction=`echo "$1" | tr "[:upper:]" "[:lower:]"`
|
||||
case "$direction" in
|
||||
horizontal|h) direction="horizontal" ;;
|
||||
vertical|v) direction="vertical" ;;
|
||||
*) errMsg "--- DIRECTION=$direction IS AN INVALID VALUE ---"
|
||||
esac
|
||||
;;
|
||||
-o) # offset
|
||||
shift # to get the next parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID OFFSET SPECIFICATION ---"
|
||||
#checkMinus "$1"
|
||||
offset=`expr "$1" : '\([-+][0-9]*[-+][0-9]*\)'`
|
||||
[ "$offset" = "" ] && errMsg "--- OFFSET=$offset IS INVALID ---"
|
||||
;;
|
||||
-l) # leftpt
|
||||
shift # to get the next parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID LEFTPT SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
leftpt=`expr "$1" : '\([0-9]*,[0-9]*\)'`
|
||||
[ "$leftpt" = "" ] && errMsg "--- LEFTPT=$leftpt IS INVALID ---"
|
||||
;;
|
||||
-r) # rightpt
|
||||
shift # to get the next parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID RIGHTPT SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
rightpt=`expr "$1" : '\([0-9]*,[0-9]*\)'`
|
||||
[ "$rightpt" = "" ] && errMsg "--- RIGHTPT=$rightpt IS INVALID ---"
|
||||
;;
|
||||
-b) # bcolor
|
||||
shift # to get the next parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID BCOLOR SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
bcolor="$1"
|
||||
;;
|
||||
-f) # format
|
||||
shift # to get the next parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID FORMAT SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
format=`echo "$1" | tr "[:lower:]" "[:upper:]"`
|
||||
case "$format" in
|
||||
RG) ;;
|
||||
GB) ;;
|
||||
BR) ;;
|
||||
RGB) ;;
|
||||
*) errMsg "--- FORMAT=$format IS AN INVALID VALUE ---"
|
||||
esac
|
||||
;;
|
||||
-T) # trim
|
||||
shift # to get the next parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID TRIM SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
trim=`echo "$1" | tr "[:upper:]" "[:lower:]"`
|
||||
case "$trim" in
|
||||
yes) ;;
|
||||
no) ;;
|
||||
*) errMsg "--- TRIM=$trim 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 infiles and outfile
|
||||
infile1="$1"
|
||||
infile2="$2"
|
||||
outfile="$3"
|
||||
fi
|
||||
|
||||
# test that infile1 provided
|
||||
[ "$infile1" = "" ] && errMsg "--- NO INPUT FILE 1 SPECIFIED ---"
|
||||
|
||||
# test that infile2 provided
|
||||
[ "$infile2" = "" ] && errMsg "--- NO INPUT FILE 2 SPECIFIED ---"
|
||||
|
||||
# test that outfile provided
|
||||
[ "$outfile" = "" ] && errMsg "--- NO OUTPUT FILE SPECIFIED ---"
|
||||
|
||||
|
||||
dir="$tmpdir/POSITION.$$"
|
||||
|
||||
mkdir "$dir" || echo "--- FAILED TO CREATE TEMPORARY FILE DIRECTORY ---"
|
||||
trap "rm -rf $dir; exit 0" 0
|
||||
trap "rm -rf $dir; exit 1" 1 2 3 15
|
||||
|
||||
# read input images
|
||||
# test if infile exists, is readable and is not zero size
|
||||
convert -quiet "$infile1" +repage $dir/tmpI1.mpc ||
|
||||
echo "--- FILE $infile1 DOES NOT EXIST OR IS NOT AN ORDINARY FILE, NOT READABLE OR HAS ZERO SIZE ---"
|
||||
|
||||
convert -quiet "$infile2" +repage $dir/tmpI2.mpc ||
|
||||
echo "--- FILE $infile2 DOES NOT EXIST OR IS NOT AN ORDINARY FILE, NOT READABLE OR HAS ZERO SIZE ---"
|
||||
|
||||
# get image1 dimensions
|
||||
ww=`convert $dir/tmpI1.mpc -format "%w" info:`
|
||||
hh=`convert $dir/tmpI1.mpc -format "%h" info:`
|
||||
#echo "ww=$ww; hh=$hh;"
|
||||
|
||||
# get page values for second image
|
||||
if [ "$method" = "cpoints" ]; then
|
||||
lx=`echo "$leftpt" | cut -d, -f1`
|
||||
ly=`echo "$leftpt" | cut -d, -f2`
|
||||
rx=`echo "$rightpt" | cut -d, -f1`
|
||||
ry=`echo "$rightpt" | cut -d, -f2`
|
||||
pagex=$((lx-rx))
|
||||
pagey=$((ly-ry))
|
||||
|
||||
else # offsets
|
||||
xoff=`echo $offset | sed -n 's/^\([+-].*\)[+-].*$/\1/p'`
|
||||
yoff=`echo $offset | sed -n 's/^[+-].*\([+-].*\)$/\1/p'`
|
||||
if [ "$direction" = "horizontal" ]; then
|
||||
pagex=$((ww+xoff))
|
||||
pagey=$((yoff))
|
||||
else
|
||||
# vertical
|
||||
pagex=$((xoff))
|
||||
pagey=$((hh+yoff))
|
||||
fi
|
||||
fi
|
||||
#echo "ww=$ww; hh=$hh; xoff=$xoff; yoff=$yoff; lx=$lx; ly=$ly; rx=$rx; ry=$ry; pagex=$pagex; pagey=$pagey;"
|
||||
|
||||
# set up for trim
|
||||
[ "$trim" = "yes" ] && trimming="-background $bcolor -define trim:percent-background=0% -trim +repage"
|
||||
|
||||
# align the two images
|
||||
if [ "$format" = "RG" ]; then
|
||||
convert \
|
||||
\( $dir/tmpI1.mpc -colorspace gray -set page +0+0 -write mpr:img1 +delete \) \
|
||||
\( $dir/tmpI2.mpc -colorspace gray -set page +${pagex}+${pagey} -write mpr:img2 +delete \) \
|
||||
\( \( mpr:img2 -background black -colorize 100 \) \( mpr:img1 +level-colors "black,red" \) \
|
||||
-background "$bcolor" -layers merge +repage \) \
|
||||
\( \( mpr:img1 -background black -colorize 100 \) \( mpr:img2 +level-colors "black,green1" \) \
|
||||
-background "$bcolor" -layers merge +repage \) \
|
||||
-compose over -compose blend -composite $trimming \
|
||||
"$outfile"
|
||||
|
||||
elif [ "$format" = "GB" ]; then
|
||||
convert \
|
||||
\( $dir/tmpI1.mpc -colorspace gray -set page +0+0 -write mpr:img1 +delete \) \
|
||||
\( $dir/tmpI2.mpc -colorspace gray -set page +${pagex}+${pagey} -write mpr:img2 +delete \) \
|
||||
\( \( mpr:img2 -background black -colorize 100 \) \( mpr:img1 +level-colors "black,green1" \) \
|
||||
-background "$bcolor" -layers merge +repage \) \
|
||||
\( \( mpr:img1 -background black -colorize 100 \) \( mpr:img2 +level-colors "black,blue" \) \
|
||||
-background "$bcolor" -layers merge +repage \) \
|
||||
-compose over -compose blend -composite $trimming \
|
||||
"$outfile"
|
||||
|
||||
elif [ "$format" = "BR" ]; then
|
||||
convert \
|
||||
\( $dir/tmpI1.mpc -colorspace gray -set page +0+0 -write mpr:img1 +delete \) \
|
||||
\( $dir/tmpI2.mpc -colorspace gray -set page +${pagex}+${pagey} -write mpr:img2 +delete \) \
|
||||
\( \( mpr:img2 -background black -colorize 100 \) \( mpr:img1 +level-colors "black,blue" \) \
|
||||
-background "$bcolor" -layers merge +repage \) \
|
||||
\( \( mpr:img1 -background black -colorize 100 \) \( mpr:img2 +level-colors "black,red" \) \
|
||||
-background "$bcolor" -layers merge +repage \) \
|
||||
-compose over -compose blend -composite $trimming \
|
||||
"$outfile"
|
||||
|
||||
else # RGB
|
||||
convert \
|
||||
\( $dir/tmpI1.mpc -set page +0+0 \) \
|
||||
\( $dir/tmpI2.mpc -set page +${pagex}+${pagey} \) \
|
||||
-background "$bcolor" -layers merge +repage $trimming \
|
||||
"$outfile"
|
||||
|
||||
|
||||
fi
|
||||
|
||||
exit 0
|
||||
268
scripts/magick/splitcrop
Normal file
268
scripts/magick/splitcrop
Normal file
|
|
@ -0,0 +1,268 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Developed by Fred Weinhaus revised 6/9/2012 .......... revised 4/25/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: splitcrop [-x xcoord] [-y ycoord] [-L] infile [outfile]
|
||||
# USAGE: splitcrop [-h or -help]
|
||||
#
|
||||
# OPTIONS:
|
||||
#
|
||||
# -x xcoord x coordinate for split; 0<integer<width; default=center
|
||||
# -y xcoord y coordinate for split; 0<integer<height; default=center
|
||||
# -L list crop dimensions and offsets to the terminal
|
||||
#
|
||||
# Note, the output images will be named automatically from the outfile name and
|
||||
# suffix. Two or four of the following: _left, _right, _top, _bottom,
|
||||
# _topleft, _topright, _bottomleft, _bottomright will be appended before the
|
||||
# suffix. If no outfile is provided, then the infile name and suffix will be
|
||||
# used for the output.
|
||||
#
|
||||
###
|
||||
#
|
||||
# NAME: SPLITCROP
|
||||
#
|
||||
# PURPOSE: To crop an image into two or four sections according to the given
|
||||
# x,y coordinates.
|
||||
#
|
||||
# DESCRIPTION: SPLITCROP crops an image into two or four sections according to
|
||||
# the given x,y coordinates. One or both of the x,y coordinates may be
|
||||
# specified. If one coordinate is specified, then the image will be split into
|
||||
# two parts. If two coordinate are specified, then the image will be split both
|
||||
# ways into four parts. Note that these are coordinates and not sizes. The top,
|
||||
# left or topleft section will include the coordinate specified. The size of
|
||||
# the split will be the coordinate plus 1. If the image dimension is odd,
|
||||
# then the top, left or topleft will contain the extra pixel(s).
|
||||
#
|
||||
# OPTIONS:
|
||||
#
|
||||
# -x xcoord ... XCOORD is the x coordinate for the split. Values are
|
||||
# 0<integers<width. The default=center of image
|
||||
#
|
||||
# -y ycoord ... YCOORD is the y coordinate for the split. Values are
|
||||
# 0<integers<height. The default=center of image
|
||||
#
|
||||
# -L ... LIST crop dimensions and offsets to the terminal
|
||||
#
|
||||
# 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
|
||||
xcoord="" # x coordinate for split
|
||||
ycoord="" # y coordinate for split
|
||||
list="off"
|
||||
|
||||
# set directory for temporary files
|
||||
dir="." # suggestions are dir="." or dir="/tmp"
|
||||
|
||||
# set up functions to report Usage and Usage with Description
|
||||
PROGNAME="splitcrop" # 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 6 ]
|
||||
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
|
||||
;;
|
||||
-x) # get xcoord
|
||||
shift # to get the next parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID XCOORD SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
xcoord=`expr "$1" : '\([0-9]*\)'`
|
||||
[ "$xcoord" = "" ] && errMsg "--- XCOORD=$xcoord MUST BE A NON-NEGATIVE INTEGER ---"
|
||||
;;
|
||||
-y) # get ycoord
|
||||
shift # to get the neyt parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID YCOORD SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
ycoord=`expr "$1" : '\([0-9]*\)'`
|
||||
[ "$ycoord" = "" ] && errMsg "--- YCOORD=$ycoord MUST BE A NON-NEGATIVE INTEGER ---"
|
||||
;;
|
||||
-L) # get list
|
||||
list="on"
|
||||
;;
|
||||
-) # 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
|
||||
|
||||
if [ "$outfile" = "" ]; then
|
||||
# separate infile to outname and suffix
|
||||
outname=`echo "$infile" | sed -n 's/^\(.*\)[\.].*$/\1/p'`
|
||||
suffix=`echo "$infile" | sed -n 's/^.*[\.]\(.*\)$/\1/p'`
|
||||
else
|
||||
# separate outfile to outname and suffix
|
||||
outname=`echo "$outfile" | sed -n 's/^\(.*\)[\.].*$/\1/p'`
|
||||
suffix=`echo "$outfile" | sed -n 's/^.*[\.]\(.*\)$/\1/p'`
|
||||
fi
|
||||
|
||||
# setup temporary images
|
||||
tmpA1="$dir/split_A_$$.mpc"
|
||||
tmpA2="$dir/split_A_$$.cache"
|
||||
trap "rm -f $tmpA1 $tmpA2;" 0
|
||||
trap "rm -f $tmpA1 $tmpA2; exit 1" 1 2 3 15
|
||||
trap "rm -f $tmpA1 $tmpA2; exit 1" ERR
|
||||
|
||||
|
||||
# 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 input dimensions
|
||||
ww=`convert $tmpA1 -format "%w" info:`
|
||||
hh=`convert $tmpA1 -format "%h" info:`
|
||||
#echo "ww=$ww; hh=$hh"
|
||||
|
||||
x=$xcoord
|
||||
y=$ycoord
|
||||
|
||||
# trap for no coordinates specified
|
||||
if [ "$x" = "" -a "$y" = "" ]; then
|
||||
x=`convert xc: -format "%[fx:round($ww/2)-1]" info:`
|
||||
y=`convert xc: -format "%[fx:round($hh/2)-1]" info:`
|
||||
fi
|
||||
|
||||
# trap for coordinates at boundary or outside image
|
||||
if [ "$x" != "" ]; then
|
||||
( [ $x -eq 0 ] || [ $x -ge $ww ] ) && errMsg "--- INVALID X COORDINATE SPECIFIED ---"
|
||||
fi
|
||||
if [ "$y" != "" ]; then
|
||||
( [ $y -eq 0 ] || [ $y -ge $ww ] ) && errMsg "--- INVALID Y COORDINATE SPECIFIED ---"
|
||||
fi
|
||||
|
||||
# options depending upon whether x or y or (x and y) specified
|
||||
if [ "$x" != "" -a "$y" != "" ]; then
|
||||
#split into four parts
|
||||
tlsize=`convert xc: -format "%[fx:$x+1]x%[fx:$y+1]+0+0" info:`
|
||||
trsize=`convert xc: -format "%[fx:$ww-$x-1]x%[fx:$y+1]+%[fx:$x+1]+0" info:`
|
||||
blsize=`convert xc: -format "%[fx:$x+1]x%[fx:$hh-$y-1]+0+%[fx:$y+1]" info:`
|
||||
brsize=`convert xc: -format "%[fx:$ww-$x-1]x%[fx:$hh-$y-1]+%[fx:$x+1]+%[fx:$y+1]" info:`
|
||||
if [ "$list" = "on" ]; then
|
||||
echo "tlsize=$tlsize"
|
||||
echo "trsize=$trsize"
|
||||
echo "blsize=$blsize"
|
||||
echo "brsize=$brsize"
|
||||
fi
|
||||
convert $tmpA1 -crop $tlsize +repage "${outname}_topleft.$suffix"
|
||||
convert $tmpA1 -crop $trsize +repage "${outname}_topright.$suffix"
|
||||
convert $tmpA1 -crop $blsize +repage "${outname}_bottomleft.$suffix"
|
||||
convert $tmpA1 -crop $brsize +repage "${outname}_bottomright.$suffix"
|
||||
elif [ "$x" != "" ]; then
|
||||
#split into two parts horizontally
|
||||
lsize=`convert xc: -format "%[fx:$x+1]x${hh}+0+0" info:`
|
||||
rsize=`convert xc: -format "%[fx:$ww-$x-1]x${hh}+%[fx:$x+1]+0" info:`
|
||||
if [ "$list" = "on" ]; then
|
||||
echo "lsize=$lsize"
|
||||
echo "rsize=$rsize"
|
||||
fi
|
||||
convert $tmpA1 -crop $lsize +repage "${outname}_left.$suffix"
|
||||
convert $tmpA1 -crop $rsize +repage "${outname}_right.$suffix"
|
||||
elif [ "$y" != "" ]; then
|
||||
#split into two parts vertically
|
||||
tsize=`convert xc: -format "${ww}x%[fx:$y+1]+0+0" info:`
|
||||
bsize=`convert xc: -format "${ww}x%[fx:$hh-$y-1]+0+%[fx:$y+1]" info:`
|
||||
if [ "$list" = "on" ]; then
|
||||
echo "tsize=$tsize"
|
||||
echo "bsize=$bsize"
|
||||
fi
|
||||
convert $tmpA1 -crop $tsize +repage "${outname}_top.$suffix"
|
||||
convert $tmpA1 -crop $bsize +repage "${outname}_bottom.$suffix"
|
||||
fi
|
||||
|
||||
exit 0
|
||||
514
scripts/magick/stainedglass
Normal file
514
scripts/magick/stainedglass
Normal file
|
|
@ -0,0 +1,514 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Developed by Fred Weinhaus 6/12/2010 .......... 11/12/2017
|
||||
#
|
||||
# ------------------------------------------------------------------------------
|
||||
#
|
||||
# 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: stainedglass [-k kind] [-s size] [-o offset] [-n ncolors] [-b bright]
|
||||
# [-e ecolor] [-t thick] [-r rseed] [-a] infile outfile
|
||||
# USAGE: stainedglass [-h or -help]
|
||||
#
|
||||
# OPTIONS:
|
||||
#
|
||||
# -k kind kind of stainedglass cell shape; choices are: square
|
||||
# (or s), hexagon (or h), random (or r); default=random
|
||||
# -s size size of cell; integer>0; default=16
|
||||
# -o offset random offset amount; integer>=0; default=6;
|
||||
# only applies to kind=random
|
||||
# -n ncolors number of desired reduced colors for the output;
|
||||
# integer>1; default is no color reduction
|
||||
# -b bright brightness value in percent for output image;
|
||||
# integer>=0; default=100
|
||||
# -e ecolor color for edge or border around each cell; any valid
|
||||
# IM color; default=black
|
||||
# -t thick thickness for edge or border around each cell;
|
||||
# integer>=0; default=1; zero means no edge or border
|
||||
# -r rseed random number seed value; integer>=0; if seed provided,
|
||||
# then image will reproduce; default is no seed, so that
|
||||
# each image will be randomly different; only applies
|
||||
# to kind=random
|
||||
# -a use average color of cell rather than color at center
|
||||
# of cell; default is center color
|
||||
#
|
||||
###
|
||||
#
|
||||
# NAME: STAINEDGLASS
|
||||
#
|
||||
# PURPOSE: Applies a stained glass cell effect to an image.
|
||||
#
|
||||
# DESCRIPTION: STAINEDGLASS applies a stained glass cell effect to an image. The
|
||||
# choices of cell shapes are hexagon, square and randomized square. The cell
|
||||
# size and border around the cell can be specified.
|
||||
#
|
||||
#
|
||||
# OPTIONS:
|
||||
#
|
||||
# -k kind ... KIND of stainedglass cell shape; choices are: square (or s),
|
||||
# hexagon (or h), random (or r). The latter is a square with each corner
|
||||
# randomly offset. The default=random.
|
||||
#
|
||||
# -s size ... SIZE of stained glass cells. Values are integers>=0. The
|
||||
# default=16.
|
||||
#
|
||||
# -o offset ... OFFSET is the random offset amount for the case of kind=random.
|
||||
# Values are integers>=0. The default=6.
|
||||
#
|
||||
# -n ncolors ... NCOLORS is the number of desired reduced colors in the output.
|
||||
# Values are integers>1. The default is no color reduction. Larger number of
|
||||
# colors takes more time to color reduce.
|
||||
#
|
||||
# -b bright ... BRIGHTNESS value in percent for the output image. Values are
|
||||
# integers>=0. The default=100 means no change in brightness.
|
||||
#
|
||||
# -e ecolor ... ECOLOR is the color for the edge or border around each cell.
|
||||
# Any valid IM color is allowed. The default=black.
|
||||
#
|
||||
# -t thick ... THICK is the thickness for the edge or border around each cell.
|
||||
# Values are integers>=0. The default=1. A value of zero means no edge or
|
||||
# border will be included.
|
||||
#
|
||||
# -r rseed ... RSEED is the random number seed value for kind=random. Values
|
||||
# are integers>=0. If a seed is provided, then the resulting image will be
|
||||
# reproducable. The default is no seed. In that case, each resulting image
|
||||
# will be randomly different.
|
||||
#
|
||||
# -a ... use AVERAGE color of cell rather than color at center of shell;
|
||||
# default is center color. The average value will be accurate only for odd
|
||||
# square shapes with IM 6.5.9.0 or higher. All others cases will use only an
|
||||
# approximate average.
|
||||
#
|
||||
# Thanks to Anthony Thyssen for critiqing the original version and for
|
||||
# several useful suggestions for improvement.
|
||||
#
|
||||
# NOTE: This script will be slow prior to IM 6.8.3.10 due to the need to
|
||||
# extract color values for each cell center point across the input image.
|
||||
# A progress meter is therefore provided to the terminal. A speed-up is
|
||||
# available via a -process function, getColors. To obtain getColors,
|
||||
# contact me. It requires IM 6.6.2-10 or higher.
|
||||
#
|
||||
# IMPORTANT: This script will fail due to an unintended restriction in the
|
||||
# txt: format starting with IM 6.9.9.1 and IM 7.0.6.2. It has been fixed at
|
||||
# IM 6.9.9.23 and IM 7.0.7.11.
|
||||
#
|
||||
# REQUIREMENTS: Does not produce a proper set of edges/borders around each
|
||||
# cell under Q8, due to insufficient graylevel resolution (0 and 255)
|
||||
# to handle more that 255 cells.
|
||||
#
|
||||
# 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
|
||||
kind="random" # random, square, hexagon
|
||||
size=16 # cell size
|
||||
offset=6 # pixel amount to randomly add or subtract to square corners
|
||||
ncolors="" # number of output colors
|
||||
bright=100 # brightness adjust
|
||||
ecolor="black" # edge color
|
||||
thick=1 # edge thickness
|
||||
rseed="" # seed for random
|
||||
average="no" # preprocess for cell average
|
||||
|
||||
# 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 19 ]
|
||||
then
|
||||
errMsg "--- TOO MANY ARGUMENTS WERE PROVIDED ---"
|
||||
else
|
||||
while [ $# -gt 0 ]
|
||||
do
|
||||
# get parameter values
|
||||
case "$1" in
|
||||
-help) # help information
|
||||
echo ""
|
||||
usage2
|
||||
exit 0
|
||||
;;
|
||||
-k) # get kind
|
||||
shift # to get the next parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID KIND SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
kind=`echo "$1" | tr '[A-Z]' '[a-z]'`
|
||||
case "$kind" in
|
||||
hexagon|h) kind="hexagon" ;;
|
||||
square|s) kind="square" ;;
|
||||
random|r) kind="random" ;;
|
||||
*) errMsg "--- KIND=$kind IS AN INVALID VALUE ---" ;;
|
||||
esac
|
||||
;;
|
||||
-s) # get size
|
||||
shift # to get the next parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID SIZE SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
size=`expr "$1" : '\([0-9]*\)'`
|
||||
[ "$size" = "" ] && errMsg "--- SIZE=$size MUST BE A NON-NEGATIVE INTEGER (with no sign) ---"
|
||||
test1=`echo "$size < 1" | bc`
|
||||
[ $test1 -eq 1 ] && errMsg "--- SIZE=$size MUST BE A POSITIVE INTEGER ---"
|
||||
;;
|
||||
-o) # get offset
|
||||
shift # to get the next parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID OFFSET SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
offset=`expr "$1" : '\([0-9]*\)'`
|
||||
[ "$offset" = "" ] && errMsg "--- OFFSET=$offset MUST BE A NON-NEGATIVE INTEGER ---"
|
||||
;;
|
||||
-n) # get ncolors
|
||||
shift # to get the next parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID NCOLORS SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
ncolors=`expr "$1" : '\([0-9]*\)'`
|
||||
[ "$ncolors" = "" ] && errMsg "--- NCOLORS=$ncolors MUST BE A NON-NEGATIVE INTEGER (with no sign) ---"
|
||||
test1=`echo "$ncolors < 2" | bc`
|
||||
[ $test1 -eq 1 ] && errMsg "--- NCOLORS=$ncolors MUST BE AN GREATER THAN 1 ---"
|
||||
;;
|
||||
-b) # get bright
|
||||
shift # to get the next parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID BRIGHT SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
bright=`expr "$1" : '\([0-9]*\)'`
|
||||
[ "$bright" = "" ] && errMsg "--- BRIGHT=$bright MUST BE A NON-NEGATIVE INTEGER ---"
|
||||
;;
|
||||
-e) # get ecolor
|
||||
shift # to get the next parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID ECOLOR SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
ecolor="$1"
|
||||
;;
|
||||
-t) # get thick
|
||||
shift # to get the next parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID THICK SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
thick=`expr "$1" : '\([0-9]*\)'`
|
||||
[ "$thick" = "" ] && errMsg "--- THICK=$thick MUST BE A NON-NEGATIVE INTEGER ---"
|
||||
;;
|
||||
-r) # get rseed
|
||||
shift # to get the next parameter
|
||||
# test if parameter starts with minus sign
|
||||
errorMsg="--- INVALID RSEED SPECIFICATION ---"
|
||||
checkMinus "$1"
|
||||
rseed=`expr "$1" : '\([0-9]*\)'`
|
||||
[ "$rseed" = "" ] && errMsg "--- RSEED=$rseed MUST BE A NON-NEGATIVE INTEGER ---"
|
||||
;;
|
||||
-a) # get average
|
||||
average="yes"
|
||||
;;
|
||||
-) # 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 and auto delete upon exit
|
||||
tmpA1="$dir/stainedglass_1_$$.mpc"
|
||||
tmpB1="$dir/stainedglass_1_$$.cache"
|
||||
tmpA2="$dir/stainedglass_2_$$.mpc"
|
||||
tmpB2="$dir/stainedglass_2_$$.cache"
|
||||
tmpA3="$dir/stainedglass_3_$$.mpc"
|
||||
tmpB3="$dir/stainedglass_3_$$.cache"
|
||||
tmpC="$dir/stainedglass_C_$$.txt"
|
||||
tmpG="$dir/stainedglass_G_$$.txt"
|
||||
trap "rm -f $tmpA1 $tmpB1 $tmpA2 $tmpB2 $tmpA3 $tmpB3 $tmpC $tmpG;" 0
|
||||
trap "rm -f $tmpA1 $tmpB1 $tmpA2 $tmpB2 $tmpA3 $tmpB3 $tmpC $tmpG; exit 1" 1 2 3 15
|
||||
# does not seem to produce output with the following????
|
||||
#trap "rm -f $tmpA1 $tmpB1 $tmpA2 $tmpB2 $tmpA3 $tmpB3 $tmpC $tmpG; exit 1" ERR
|
||||
|
||||
# set up color reduction
|
||||
if [ "$ncolors" != "" ]; then
|
||||
reduce="-monitor +dither -colors $ncolors +monitor"
|
||||
echo ""
|
||||
echo "Reducing Colors:"
|
||||
else
|
||||
reduce=""
|
||||
fi
|
||||
|
||||
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`
|
||||
# colorspace swapped at IM 6.7.5.5, but not properly fixed until 6.7.6.6
|
||||
# before swap verbose info reported colorspace=RGB after colorspace=sRGB
|
||||
if [ "$im_version" -ge "06070606" ]; then
|
||||
cspace1="sRGB"
|
||||
cspace2="sRGBA"
|
||||
else
|
||||
cspace1="RGB"
|
||||
cspace2="RGBA"
|
||||
fi
|
||||
# no need for setcspace for grayscale or channels after 6.8.5.4
|
||||
if [ "$im_version" -gt "06080504" ]; then
|
||||
cspace1=""
|
||||
cspace2=""
|
||||
fi
|
||||
|
||||
# get colorspace
|
||||
colorspace=`convert $infile -ping -format "%[colorspace]" info:`
|
||||
# set up for modulate
|
||||
# note there seems to be a change in -modulate (for HSL) between IM 6.8.4.6 and 6.8.4.7 that is noticeable in the output
|
||||
if [ "$bright" != "100" -a "$colorspace" = "CMYK" ]; then
|
||||
modulation="-colorspace $cspace1 -modulate ${bright},100,100 -colorspace cmyk"
|
||||
elif [ "$bright" != "100" -a "$colorspace" = "CMYKA" ]; then
|
||||
modulation="-colorspace $cspace2 -modulate ${bright},100,100 -colorspace cmyka"
|
||||
elif [ "$bright" != "100" ]; then
|
||||
modulation="-modulate ${bright},100,100"
|
||||
else
|
||||
modulation=""
|
||||
fi
|
||||
|
||||
# read the input image and filter image into the temp files and test validity.
|
||||
convert -quiet "$infile" $reduce $modulation +repage "$tmpA1" ||
|
||||
errMsg "--- FILE $infile DOES NOT EXIST OR IS NOT AN ORDINARY FILE, NOT READABLE OR HAS ZERO SIZE ---"
|
||||
|
||||
# preprocess for average color
|
||||
if [ "$average" = "yes" -a "$im_version" -ge "06050900" -a "$kind" = "square" ]; then
|
||||
dim=`convert xc: -format "%[fx:round(($size-1)/2)]" info:`
|
||||
convert $tmpA1 -define convolve:scale=! -morphology convolve square:$dim $tmpA1
|
||||
elif [ "$average" = "yes" -a "$im_version" -ge "06050900" -a "$kind" != "square" ]; then
|
||||
dim=`convert xc: -format "%[fx:round(($size-1)/2)+0.5]" info:`
|
||||
convert $tmpA1 -define convolve:scale=! -morphology convolve disk:$dim $tmpA1
|
||||
elif [ "$average" = "yes" ]; then
|
||||
dim=`convert xc: -format "%[fx:round(($size-1)/2)]" info:`
|
||||
convert $tmpA1 -blur ${dim}x65000 $tmpA1
|
||||
fi
|
||||
|
||||
# test if -process module getcolors exists
|
||||
if [ "$im_version" -ge "06050210" ]; then
|
||||
process_test=`convert -list module | grep "getColors"`
|
||||
fi
|
||||
#echo "process_test=$process_test;"
|
||||
|
||||
ww=`convert $tmpA1 -ping -format "%w" info:`
|
||||
hh=`convert $tmpA1 -ping -format "%h" info:`
|
||||
ww1=$(($ww-1))
|
||||
hh1=$(($hh-1))
|
||||
ww2=`convert xc: -format "%[fx:$ww1+round($size/2)]" info:`
|
||||
hh2=`convert xc: -format "%[fx:$hh1+round($size/2)]" info:`
|
||||
#echo "ww=$ww; hh=$hh; ww1=$ww1; hh1=$hh1; ww2=$ww2; hh2=$hh2;"
|
||||
|
||||
|
||||
# get qrange
|
||||
qrange=`convert xc: -format "%[fx:quantumrange]" info:`
|
||||
|
||||
# init colors file
|
||||
echo "# ImageMagick pixel enumeration: $ww,$hh,255,rgb" > $tmpC
|
||||
|
||||
# init increment grays file
|
||||
touch $tmpG
|
||||
|
||||
if [ "$kind" = "random" ]; then
|
||||
# need to add 1 to offset as awk rand is exclusive between 0 and 1
|
||||
offset=$(($offset+1))
|
||||
|
||||
awk -v size="$size" -v ww1="$ww1" -v hh1="$hh1" -v ww2="$ww2" -v hh2="$hh2" -v offset="$offset" -v rseed="$rseed" '
|
||||
BEGIN { if (rseed=="") {srand();} else {srand(rseed);} y=0; while ( y < hh2 )
|
||||
{ x=0; while (x < ww2 )
|
||||
{ if (x>ww1) {x=ww1;} if (y>hh1) {y=hh1;}
|
||||
rx=rand(); if (rx<0.5) {signx=-1;} else {signx=1;}
|
||||
offx=int(signx*rand()*offset);
|
||||
xx=x+offx; if (xx<0) {xx=0}; if (xx>ww1) {xx=ww1};
|
||||
ry=rand(); if (ry<0.5) {signy=-1;} else {signy=1;}
|
||||
offy=int(signy*rand()*offset);
|
||||
yy=y+offy; if (yy<0) {yy=0}; if (yy>hh1) {yy=hh1};
|
||||
print xx","yy": (255,255,255)"; x=x+size; }
|
||||
y=y+size; } }' >> $tmpC
|
||||
|
||||
awk -v size="$size" -v ww1="$ww1" -v hh1="$hh1" -v ww2="$ww2" -v hh2="$hh2" -v qrange="$qrange" -v offset="$offset" -v rseed="$rseed" '
|
||||
BEGIN { if (rseed=="") {srand();} else {srand(rseed);} k=0; y=0; while ( y < hh2 )
|
||||
{ x=0; while (x < ww2 )
|
||||
{ if (x>ww1) {x=ww1;} if (y>hh1) {y=hh1;}
|
||||
rx=rand(); if (rx<0.5) {signx=-1;} else {signx=1;}
|
||||
offx=int(signx*rand()*offset);
|
||||
xx=x+offx; if (xx<0) {xx=0}; if (xx>ww1) {xx=ww1};
|
||||
ry=rand(); if (ry<0.5) {signy=-1;} else {signy=1;}
|
||||
offy=int(signy*rand()*offset);
|
||||
yy=y+offy; if (yy<0) {yy=0}; if (yy>hh1) {yy=hh1};
|
||||
g=(k % 256);
|
||||
print xx,yy" gray("g")"; k++; x=x+size; }
|
||||
y=y+size; } }' >> $tmpG
|
||||
|
||||
elif [ "$kind" = "hexagon" ]; then
|
||||
awk -v size="$size" -v ww1="$ww1" -v hh1="$hh1" -v ww2="$ww2" -v hh2="$hh2" '
|
||||
BEGIN { j=0; y=0; while ( y < hh2 )
|
||||
{ if (j%2==0) {x=int((size+0.5)/2);} else {x=0;} while (x < ww2 )
|
||||
{ if (x>ww1) {x=ww1;} if (y>hh1) {y=hh1;} print x","y": (255,255,255)"; x=x+size; }
|
||||
j++; y=y+size; } }' >> $tmpC
|
||||
|
||||
awk -v size="$size" -v ww1="$ww1" -v hh1="$hh1" -v ww2="$ww2" -v hh2="$hh2" -v qrange="$qrange" '
|
||||
BEGIN { j=0; k=0; y=0; while ( y < hh2 )
|
||||
{ if (j%2==0) {x=int((size+0.5)/2);} else {x=0;} while (x < ww2 )
|
||||
{ if (x>ww1) {x=ww1;} if (y>hh1) {y=hh1;} g=(k % 256); print x,y" gray("g")"; k++; x=x+size; }
|
||||
j++; y=y+size; } }' >> $tmpG
|
||||
|
||||
elif [ "$kind" = "square" ]; then
|
||||
awk -v size="$size" -v ww1="$ww1" -v hh1="$hh1" -v ww2="$ww2" -v hh2="$hh2" '
|
||||
BEGIN { y=0; while ( y < hh2 )
|
||||
{ x=0; while (x < ww2 )
|
||||
{ if (x>ww1) {x=ww1;} if (y>hh1) {y=hh1;} print x","y": (255,255,255)"; x=x+size; }
|
||||
y=y+size; } }' >> $tmpC
|
||||
|
||||
awk -v size="$size" -v ww1="$ww1" -v hh1="$hh1" -v ww2="$ww2" -v hh2="$hh2" -v qrange="$qrange" '
|
||||
BEGIN { k=0; y=0; while ( y < hh2 )
|
||||
{ x=0; while (x < ww2 )
|
||||
{ if (x>ww1) {x=ww1;} if (y>hh1) {y=hh1;} g=(k % 256); print x,y" gray("g")"; k++; x=x+size; }
|
||||
y=y+size; } }' >> $tmpG
|
||||
|
||||
fi
|
||||
|
||||
if [ "$thick" = "0" ]; then
|
||||
if [ "$im_version" -ge "06080310" ]; then
|
||||
convert $tmpA1 \( -background black $tmpC \) \
|
||||
-alpha off -compose copy_opacity -composite \
|
||||
sparse-color:- |\
|
||||
convert -size ${ww}x${hh} xc: -sparse-color voronoi '@-' \
|
||||
"$outfile"
|
||||
elif [ "$im_version" -lt "06060210" -o "$process_test" != "getColors" ]; then
|
||||
echo ""
|
||||
echo "Progress:"
|
||||
echo ""
|
||||
convert $tmpA1 \( -background black $tmpC \) \
|
||||
-alpha off -compose copy_opacity -composite -monitor \
|
||||
txt:- |\
|
||||
sed '1d; / 0) /d; s/:.* /,/;' |\
|
||||
convert -size ${ww}x${hh} xc: -sparse-color voronoi '@-' \
|
||||
+monitor "$outfile"
|
||||
echo ""
|
||||
else
|
||||
convert $tmpA1 \( -background black $tmpC \) \
|
||||
-alpha off -compose copy_opacity -composite $tmpA1
|
||||
convert $tmpA1 -alpha on -process "getColors" null: > $tmpC
|
||||
convert -size ${ww}x${hh} xc: -sparse-color voronoi "@$tmpC" \
|
||||
"$outfile"
|
||||
fi
|
||||
|
||||
else
|
||||
if [ "$im_version" -ge "06080310" ]; then
|
||||
convert $tmpA1 \( -background black $tmpC \) \
|
||||
-alpha off -compose copy_opacity -composite \
|
||||
sparse-color:- |\
|
||||
convert -size ${ww}x${hh} xc: -sparse-color voronoi '@-' $tmpA2
|
||||
convert -size ${ww}x${hh} xc: -sparse-color voronoi "@$tmpG" \
|
||||
-auto-level -morphology edge diamond:$thick -threshold 0 -negate $tmpA3
|
||||
convert $tmpA2 $tmpA3 -alpha off -compose copy_opacity -composite \
|
||||
-compose over -background $ecolor -flatten \
|
||||
"$outfile"
|
||||
elif [ "$im_version" -lt "06060210" -o "$process_test" != "getColors" ]; then
|
||||
echo ""
|
||||
echo "Progress:"
|
||||
echo ""
|
||||
convert $tmpA1 \( -background black $tmpC \) \
|
||||
-alpha off -compose copy_opacity -composite -monitor \
|
||||
txt:- |\
|
||||
sed '1d; / 0) /d; s/:.* /,/;' |\
|
||||
convert -size ${ww}x${hh} xc: -sparse-color voronoi '@-' +monitor $tmpA2
|
||||
convert -size ${ww}x${hh} xc: -sparse-color voronoi "@$tmpG" \
|
||||
-auto-level -morphology edge diamond:$thick -threshold 0 -negate $tmpA3
|
||||
convert $tmpA2 $tmpA3 -alpha off -compose copy_opacity -composite \
|
||||
-compose over -background $ecolor -flatten \
|
||||
"$outfile"
|
||||
echo ""
|
||||
else
|
||||
convert $tmpA1 \( -background black $tmpC \) \
|
||||
-alpha off -compose copy_opacity -composite $tmpA1
|
||||
convert $tmpA1 -alpha on -process "getColors" null: > $tmpC
|
||||
convert -size ${ww}x${hh} xc: -sparse-color voronoi "@$tmpC" $tmpA2
|
||||
convert -size ${ww}x${hh} xc: -sparse-color voronoi "@$tmpG" \
|
||||
-auto-level -morphology edge diamond:$thick -threshold 0 -negate $tmpA3
|
||||
convert $tmpA2 $tmpA3 -alpha off -compose copy_opacity -composite \
|
||||
-compose over -background $ecolor -flatten \
|
||||
"$outfile"
|
||||
fi
|
||||
fi
|
||||
|
||||
exit 0
|
||||
10
scripts/magick/texture_setup.sh
Normal file
10
scripts/magick/texture_setup.sh
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/env bash
|
||||
set -ex
|
||||
|
||||
./splitcrop -x $1 -y $1 $2 corners.png
|
||||
|
||||
./position -d horizontal corners_bottomright.png corners_bottomleft.png bottom.png
|
||||
|
||||
./position -d horizontal corners_topright.png corners_topleft.png top.png
|
||||
|
||||
./position -d vertical bottom.png top.png result-grid.png
|
||||
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
|
||||
16
scripts/pixelize.ps1
Normal file
16
scripts/pixelize.ps1
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
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 poster.png
|
||||
|
||||
bash ./scripts/magick/pixelize -s $Pixel -m 2 poster.png pixels.png
|
||||
|
||||
magick.exe pixels.png -interpolate nearest -interpolative-resize $Size $OutFile
|
||||
7
scripts/reset_build.ps1
Normal file
7
scripts/reset_build.ps1
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
mv .\subprojects\packagecache .
|
||||
rm -recurse -force .\subprojects\,.\builddir\
|
||||
mkdir subprojects
|
||||
mv .\packagecache .\subprojects\
|
||||
mkdir builddir
|
||||
cp wraps\*.wrap subprojects\
|
||||
meson setup --default-library=static --prefer-static builddir
|
||||
10
scripts/reset_build.sh
Normal file
10
scripts/reset_build.sh
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
mv -f ./subprojects/packagecache .
|
||||
rm -rf subprojects builddir
|
||||
mkdir subprojects
|
||||
mv -f packagecache ./subprojects/ && true
|
||||
mkdir builddir
|
||||
cp wraps/*.wrap subprojects/
|
||||
# on OSX you can't do this with static
|
||||
meson setup --default-library=static --prefer-static builddir
|
||||
BIN
scripts/win_installer.ifp
Normal file
BIN
scripts/win_installer.ifp
Normal file
Binary file not shown.
Loading…
Add table
Add a link
Reference in a new issue