#!/bin/sh

if [ "$1" = "help"  -o "$1" = "" ]
	then
	echo " "
	echo "Usage:"
	echo "------"
	echo " "
	echo "makeTexGrp <xres> <yres> <outprefix> <srcpath> [ pix | sgi ]"
	echo
	echo "where:"
	echo " "
	echo "  <xres> ..... X resolution of each tile"
	echo " "
	echo "  <yres> ..... Y resolution of each tile"
	echo " "
	echo "  <outprefix> .. output image file prefix - this will be appended"
	echo "                 with the x and y res input and the .pix extension"
	echo "                 (for Alias pix file format)"
	echo " "
	echo "  sgi ........ If found as the fifth param then an sgi image file"
	echo "               will be generated & and the .rgb extension used"
	echo "               instead of .pix ... otherwise any other tag found"
	echo "               as the fifth param (or if none found) the image"
	echo "               generated will be an Alias pix file."
	echo " "
	exit 1
fi

echo

xres=$1
new_xres=$1

if [ $xres -lt "32" ]
	then
	mult=`expr 32 / $xres`
	echo "xres is $xres, mult is $mult"
	new_xres="0"
	c="0"
	while [ $c -lt $mult ]
	do
		new_xres=`expr $new_xres + $xres`
		c=`expr $c + 1`
	done
	echo "new_xres is $new_xres"
fi

echo

yres=$2
new_yres=$2

if [ $yres -lt "32" ]
	then
	mult=`expr 32 / $yres`
	echo "yres is $yres, mult is $mult"
	new_yres="0"
	c="0"
	while [ $c -lt $mult ]
	do
		new_yres=`expr $new_yres + $yres`
		c=`expr $c + 1`
	done
	echo "new_yres is $new_yres"
fi

echo

echo "Params:"
echo "-----------------------"
echo "1. input xres  $xres"
echo "2. input yres  $yres"
echo
echo "   tile xres  $new_xres"
echo "   tile yres  $new_yres"
echo
echo "3. output image prefix     $3"
echo "4. image source directory  $4"
echo

fname=$3"_x"$xres"_y"$yres

ftile -r 8 -c 8 -x $new_xres -y $new_yres -o $fname.pix $4/*.*

if [ $5 = "sgi" ]
	then
	fromalias $fname.pix $fname.rgb
fi
