#!/bin/ksh

#
# Normalize an image. I.e., color correct for a range of monitors.
# 

NORM_PROFILE=genrgb.pf
USAGE="Usage: $0 [-n normalization_profile] file ..."

while getopts n: f
do
    case $f in
        n) NORM_PROFILE=$OPTARG;;
        -) break;;
        \?) echo $USAGE; exit 2;; 
    esac
done
shift `expr $OPTIND - 1`

if [ $# = "0" ]
then
    echo $USAGE
    exit 2
fi

for i in $*
do
    case `filetype $i` in
        *STIFF93aImage|TIFFImage)
            COCOPROG=cocostiff
            EXT=.tif
            ;;
        *JPEGJFIFImage)
            COCOPROG=cocojpeg
            EXT=.jpg
            ;;
        *GIF?*Image)
            COCOPROG=cocogif
            EXT=.gif
            ;;
        *)
                echo "$0 only works with TIFF or STIFF format files."
    esac
    # Color correct the tiff file. cocostiff tags it with the profile.
    COCOFILE=${i%.*}.coco.$EXT
    $COCOPROG -d $NORM_PROFILE -o $COCOFILE $i
    mv $COCOFILE $i
done


