#! /usr/bin/zsh if [ $# -lt 3 -o "$1" = "--help" ]; then echo echo 'Usage: virtualtex [--help | ] [e|E|w|W]' echo echo echo The shell script \'virtualtex\' is a tool for Celestia \> 1.3.0 echo that supports \'virtual textures\'. echo echo The script generates the required tiles tx_i_j of \ desired \(square\) size, echo \, in a specified format, \ = \ png, tga, jpg,..., echo from an input texture, \, in any popular graphics format. echo echo The optional 4th argument e\|E\|w\|W is for the case of tiling echo square /e/astern \| /w/estern halfes of the full texture separately! echo echo Besides Linux/Unix, the script also runs in a current Cygwin \ installation echo under Windows, \( http://www.cygwin.com \). If the z-shell \(\'zsh\'\) \ is unavailable, echo it also may be executed with the \'bash\' shell, by replacing \ \#\! /usr/bin/zsh by echo \#\! /bin/bash in the first line. echo echo The script assumes that a recent version of the ImageMagick package echo \( http://www.ImageMagick.org \) is installed \ \(either under Unix/Linux or Windows\). echo The utilities \'convert\' and \'identify\' of that package are used. echo echo You may increase the pixel cache size \$maxmem from the 80 MB default echo value to e.g. 80\% of your RAM size within the script with an editor. echo This will speed up the performance of \'virtualtex\' considerably. echo echo On a PIII/512MB RAM the tiling of a 16k x 8k texture into echo 32 \(2k x 2k\) tiles now only takes 15 minutes with a Linux OS! echo echo Author: Dr. Fridger Schrempp, fridger.schrempp@desy.de echo Version: 1.03, 08/16/03 echo else maxmem=80 texturesize=`identify $1|cut -d " " -f 3` texturewidth=`echo $texturesize|cut -d x -f 1` textureheight=`echo $texturesize|cut -d x -f 2` tilesize=$2 tileformat="$3" echo echo "Texture size = " $texturewidth "x" $textureheight "tilesize = " $tilesize echo "Number of tiles =" $(( ((texturewidth/tilesize)) * ((textureheight/tilesize)) )) echo "Image format of tiles:" $tileformat echo echo "Tile: " echo convert -cache $maxmem -crop ${tilesize}x${tilesize} $1 out%d.$tileformat j=0 while (( j * tilesize + tilesize <= textureheight )); do ((offy = j * tilesize)) if [ $# -eq 4 ]; then if [ "$4" = "e" -o "$4" = "E" ]; then ioff=$(( texturewidth/tilesize )) elif [ "$4" = "w" -o "$4" = "W" ]; then ioff=0 else echo echo "*** Incorrect 4th parameter! ***" echo return fi fi i=0 while (( i * tilesize + tilesize <= texturewidth )); do ((offx = i * tilesize)) echo "tx_"$((i + ioff))"_"${j}": x-offset:" $((offx + ioff * tilesize)) "y-offset:" $offy mv out$((i+ ((texturewidth/tilesize)) * j)).$tileformat tx_$((i + ioff))_${j}.$tileformat ((i++)) done ((j++)) done fi