#!/bin/sh
#
#	This script is part of rtfdtohtml.
#	Copyright (c) 1996  Elmar Ludwig - Universitaet Osnabrueck
#
#	Convert tiff to gif (needs OmniImageFilter, ppm).

pbname=${PASTEBOARD:-TiffToGif_PBoard_$$}
pbtype=${PBTYPENAME:-"image format rppm"}	# for OmniImageFilter

if [ $# = 0 ]; then
    put -tiff "$pbname"
else
    put -tiff "$pbname" <"$1"
fi

trafo "$pbname" "$pbtype" | ppmtogif -interlace -sort
result=$?

if [ $result = 1 ]; then
    echo "`basename "$0" .sh`: Error detected, retrying..." >&2
    trafo "$pbname" "$pbtype" | ppmquant -floyd 256 |
    ppmtogif -interlace -sort

elif [ $result -gt 127 ]; then
    echo "`basename "$0" .sh`: Error detected, retrying..." >&2
    trafo "$pbname" "$pbtype" | ppmtogif -sort
fi
