shun-iwasawa 82a8f5
#!/bin/bash
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
set -u
shun-iwasawa 82a8f5
set -e
shun-iwasawa 82a8f5
trap onexit INT
shun-iwasawa 82a8f5
trap onexit TERM
shun-iwasawa 82a8f5
trap onexit EXIT
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
onexit()
shun-iwasawa 82a8f5
{
shun-iwasawa 82a8f5
	if [ -d $OUTDIR ]; then
shun-iwasawa 82a8f5
		rm -rf $OUTDIR
shun-iwasawa 82a8f5
	fi
shun-iwasawa 82a8f5
}
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
runme()
shun-iwasawa 82a8f5
{
shun-iwasawa 82a8f5
	echo \*\*\* $*
shun-iwasawa 82a8f5
	$*
shun-iwasawa 82a8f5
}
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
IMAGE=vgl_6548_0026a.bmp
shun-iwasawa 82a8f5
WIDTH=128
shun-iwasawa 82a8f5
HEIGHT=95
shun-iwasawa 82a8f5
IMGDIR=@CMAKE_CURRENT_SOURCE_DIR@/testimages
shun-iwasawa 82a8f5
OUTDIR=`mktemp -d /tmp/__croptest_output.XXXXXX`
shun-iwasawa 82a8f5
EXEDIR=@CMAKE_CURRENT_BINARY_DIR@
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
if [ -d $OUTDIR ]; then
shun-iwasawa 82a8f5
	rm -rf $OUTDIR
shun-iwasawa 82a8f5
fi
shun-iwasawa 82a8f5
mkdir -p $OUTDIR
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
exec >$EXEDIR/croptest.log
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
echo "============================================================"
shun-iwasawa 82a8f5
echo "$IMAGE ($WIDTH x $HEIGHT)"
shun-iwasawa 82a8f5
echo "============================================================"
shun-iwasawa 82a8f5
echo
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
for PROGARG in "" -progressive; do
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
	cp $IMGDIR/$IMAGE $OUTDIR
shun-iwasawa 82a8f5
	basename=`basename $IMAGE .bmp`
shun-iwasawa 82a8f5
	echo "------------------------------------------------------------"
shun-iwasawa 82a8f5
	echo "Generating test images"
shun-iwasawa 82a8f5
	echo "------------------------------------------------------------"
shun-iwasawa 82a8f5
	echo
shun-iwasawa 82a8f5
	runme $EXEDIR/cjpeg $PROGARG -grayscale -outfile $OUTDIR/${basename}_GRAY.jpg $IMGDIR/${basename}.bmp
shun-iwasawa 82a8f5
	runme $EXEDIR/cjpeg $PROGARG -sample 2x2 -outfile $OUTDIR/${basename}_420.jpg $IMGDIR/${basename}.bmp
shun-iwasawa 82a8f5
	runme $EXEDIR/cjpeg $PROGARG -sample 2x1 -outfile $OUTDIR/${basename}_422.jpg $IMGDIR/${basename}.bmp
shun-iwasawa 82a8f5
	runme $EXEDIR/cjpeg $PROGARG -sample 1x2 -outfile $OUTDIR/${basename}_440.jpg $IMGDIR/${basename}.bmp
shun-iwasawa 82a8f5
	runme $EXEDIR/cjpeg $PROGARG -sample 1x1 -outfile $OUTDIR/${basename}_444.jpg $IMGDIR/${basename}.bmp
shun-iwasawa 82a8f5
	echo
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
	for NSARG in "" -nosmooth; do
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
		for COLORSARG in "" "-colors 256 -dither none -onepass"; do
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
			for Y in {0..16}; do
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
				for H in {1..16}; do
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
					X=$(( (Y*16)%128 ))
shun-iwasawa 82a8f5
					W=$(( WIDTH-X-7 ))
shun-iwasawa 82a8f5
					if [ $Y -le 15 ]; then
shun-iwasawa 82a8f5
						CROPSPEC="${W}x${H}+${X}+${Y}"
shun-iwasawa 82a8f5
					else
shun-iwasawa 82a8f5
						Y2=$(( HEIGHT-H ));
shun-iwasawa 82a8f5
						CROPSPEC="${W}x${H}+${X}+${Y2}"
shun-iwasawa 82a8f5
					fi
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
					echo "------------------------------------------------------------"
shun-iwasawa 82a8f5
					echo $PROGARG $NSARG $COLORSARG -crop $CROPSPEC
shun-iwasawa 82a8f5
					echo "------------------------------------------------------------"
shun-iwasawa 82a8f5
					echo
shun-iwasawa 82a8f5
					for samp in GRAY 420 422 440 444; do
shun-iwasawa 82a8f5
						$EXEDIR/djpeg $NSARG $COLORSARG -rgb -outfile $OUTDIR/${basename}_${samp}_full.ppm $OUTDIR/${basename}_${samp}.jpg
shun-iwasawa 82a8f5
						convert -crop $CROPSPEC $OUTDIR/${basename}_${samp}_full.ppm $OUTDIR/${basename}_${samp}_ref.ppm
shun-iwasawa 82a8f5
						runme $EXEDIR/djpeg $NSARG $COLORSARG -crop $CROPSPEC -rgb -outfile $OUTDIR/${basename}_${samp}.ppm $OUTDIR/${basename}_${samp}.jpg
shun-iwasawa 82a8f5
						runme cmp $OUTDIR/${basename}_${samp}.ppm $OUTDIR/${basename}_${samp}_ref.ppm
shun-iwasawa 82a8f5
					done
shun-iwasawa 82a8f5
					echo
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
				done
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
			done
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
		done
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
	done
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
done
shun-iwasawa 82a8f5
shun-iwasawa 82a8f5
echo SUCCESS!