#! /bin/csh -f

### could add compiled to distros (these are 64-bit Mac)
#/opt/local/bin/pnmtotiff:
# /opt/local/lib/libnetpbm.11.dylib (compat vers 11.0.0, current vers 10.62.2)
# /opt/local/lib/libtiff.5.dylib (compat vers 8.0.0, current version 8.0.0)
# /opt/local/lib/libjpeg.9.dylib (compat vers 10.0.0, current version 10.0.0)
# /opt/local/lib/libz.1.dylib (compat vers 1.0.0, current version 1.2.7)
# /usr/lib/libSystem.B.dylib (compat vers 1.0.0, current version 125.2.11)
#/opt/local/bin/sgitopnm:
# /opt/local/lib/libnetpbm.11.dylib (compat vers 11.0.0, current vers 10.62.2)
# /usr/lib/libSystem.B.dylib (compat vers 1.0.0, current version 125.2.11)

if ($#argv < 1) then
  echo "use: rgb2tiff <file.rgb> ...           [convert SGI image(s) to tiff]"
  exit
endif

foreach file ($argv)
  if ("$file" =~ *.rgb) then
    set stem = $file:r
    # convert
    echo "sgitopnm $file | pnmtotiff > $stem.tiff"
    sgitopnm $file | pnmtotiff > $stem.tiff
    # compress
    if (`uname -s` == "Linux") then
      echo "tiffcp -c lzw $stem.tiff zz.tiff"
      tiffcp -c lzw $stem.tiff zz.tiff
      mv zz.tiff $stem.tiff
    else if (`uname -s` == "Darwin") then
      echo "tiffutil -lzw $stem.tiff -out $stem.tiff"
      tiffutil -lzw $stem.tiff -out $stem.tiff
    else
      ;
    endif
  endif
end

