#!/usr/bin/ksh

GM=/scratch/bfriesen/build/GraphicsMagick-32-static/utilities/gm
GM_STD_OPT="-compress none"
MASTER_IMAGE_ORIGINAL='/home/bfriesen/images/david/112_1201-flowers.jpg'
MASTER_IMAGE_GRAY=gray.miff
MASTER_IMAGE_RGB=rgb.miff
MASTER_IMAGE_CMYK=cmyk.miff
COLUMNS=73
ROWS=43

GRAY_DEPTHS='2 4 6 8 10 12 14 16 24 32'
PSEUDO_DEPTHS='2 4 8 16'
TRUE_COLORS='2 4 8 10 12 14 16 24 32'
CMYK_COLORS='8 16'

SUMMARY=summary.txt
echo > $SUMMARY

$GM convert $MASTER_IMAGE_ORIGINAL +profile '*' -depth 32 -type Grayscale -density 72x72 -geometry "${COLUMNS}x${ROWS}" $MASTER_IMAGE_GRAY
$GM convert $MASTER_IMAGE_ORIGINAL +profile '*' -depth 32 -density 72x72 -geometry "${COLUMNS}x${ROWS}" $MASTER_IMAGE_RGB
$GM convert $MASTER_IMAGE_ORIGINAL +profile '*' -colorspace cmyk -depth 32 -density 72x72 -geometry "${COLUMNS}x${ROWS}" $MASTER_IMAGE_CMYK

# Gray images
for depth in $GRAY_DEPTHS
do
  outname=`printf "flower-minisblack-%02d.tif" $depth`
  echo "$outname\t${COLUMNS}x${ROWS} $depth-bit minisblack gray image" >> $SUMMARY
  $GM convert -verbose $MASTER_IMAGE_GRAY $GM_STD_OPT -type Grayscale -define tiff:bits-per-sample=$depth $outname
done

# Colormapped images
for depth in $PSEUDO_DEPTHS
do
  colors=`echo "2^${depth}" | bc`
  outname=`printf "flower-palette-%02d.tif" $depth`
  echo "$outname\t${COLUMNS}x${ROWS} ${colors}-entry colormapped image" >> $SUMMARY
  $GM convert -verbose $MASTER_IMAGE_RGB $GM_STD_OPT -colors $colors $outname
done

# Truecolor images
for depth in $TRUE_COLORS
do
  outname=`printf "flower-rgb-contig-%02d.tif" $depth`
  echo "$outname\t${COLUMNS}x${ROWS} $depth-bit contiguous RGB image" >> $SUMMARY
  $GM convert -verbose $MASTER_IMAGE_RGB $GM_STD_OPT -type TrueColor -define tiff:bits-per-sample=$depth $outname
done

# Truecolor planar images
for depth in $TRUE_COLORS
do
  outname=`printf "flower-rgb-planar-%02d.tif" $depth`
  echo "$outname\t${COLUMNS}x${ROWS} $depth-bit seperated RGB image" >> $SUMMARY
  $GM convert -verbose $MASTER_IMAGE_RGB $GM_STD_OPT -type TrueColor -interlace plane -define tiff:bits-per-sample=$depth $outname
done

# CMYK images
for depth in $CMYK_COLORS
do
  outname=`printf "flower-separated-contig-%02d.tif" $depth`
  echo "$outname\t${COLUMNS}x${ROWS} $depth-bit contiguous CMYK image" >> $SUMMARY
  $GM convert -verbose $MASTER_IMAGE_RGB $GM_STD_OPT -type ColorSeparation -define tiff:bits-per-sample=$depth $outname
done

# CMYK planar images
for depth in $CMYK_COLORS
do
  outname=`printf "flower-separated-planar-%02d.tif" $depth`
  echo "$outname\t${COLUMNS}x${ROWS} $depth-bit separated CMYK image" >> $SUMMARY
  $GM convert -verbose $MASTER_IMAGE_RGB $GM_STD_OPT -type ColorSeparation -interlace plane -define tiff:bits-per-sample=$depth $outname
done

rm -f $MASTER_IMAGE_GRAY $MASTER_IMAGE_RGB $MASTER_IMAGE_CMYK