#! /bin/csh -f
# Last edited on 2000-10-18 13:51:20 by stolfi

set usage = "$0 FILE.ppm[.gz]..."

if ( $#argv < 1 ) then
  echo "usage: ${usage}"; exit 1
endif

set gamma = "1.8"
set gammatag = "gm18"

set maplib = "${STOLFIHOME}/PUB/images/colormaps"
set pbmbin = "${STOLFIHOME}/pkg/netpbm-1mar1994-1/PUB/${PLATFORM}/bin"
set jsbin  = "${STOLFIHOME}/bin/${PLATFORM}"

foreach f ( $* )
  if ( ".${f:e}" == ".gz" ) set f = "${f:r}"
  if ( ".${f:e}" != ".ppm" ) then
    echo "${f} is not a ppm file"; exit 1
  endif
  set name = "${f:r}"
  set ppmfile = "${name}.ppm"
  set giffile = "${name}.gif"
  
  if ( -r ${ppmfile}.gz ) gunzip ${ppmfile}.gz

  echo "${ppmfile} -> ${giffile}"

  cat ${ppmfile} \
    | ${jsbin}/ppmvquant \
        -fs -rgb \
        -map ${maplib}/standard-6x6x6-colormap-${gammatag}.ppm \
    | ${pbmbin}/pnmgamma ${gamma} \
    | ${pbmbin}/ppmtogif \
    > ${giffile}

  gzip ${ppmfile}
end
