#!/bin/csh -f
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
#  This is a csh script which is used to composite a series of images
#  over a static background.  It uses the Wavefront compositor: imf_comp.
#  For usage information see the "Usage" line below.
#
#  Author:     Wesley C. Barris
#              AHPCRC
#              Minnesota Supercomputer Center, Inc.
#  Date:       Sept. 12, 1990
#
#  Copyright @ 1990, Minnesota Supercomputer Center, Inc.
#
#  RESTRICTED RIGHTS LEGEND
#
#  Use, duplication, or disclosure of this software and its documentation
#  by the Government is subject to restrictions as set forth in subdivision
#  { (b) (3) (ii) } of the Rights in Technical Data and Computer Software
#  clause at 52.227-7013.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
set image = "rla"
set format = "qtl_ntsc"
set base = "im"
set out = "comp"
@ start = 0
@ end = 0
@ multiple = 0
@ static = 0
@ n = 1
while ($n <= $#argv)
   if ("$argv[$n]" == "-fs") then
      @ n++
      set start = $argv[$n]
   else if ("$argv[$n]" == "-fe") then
      @ n++
      set end = $argv[$n]
   else if ("$argv[$n]" == "-base") then
      @ n++
      set base = $argv[$n]
   else if ("$argv[$n]" == "-back") then
      @ n++
      set background = $argv[$n]
   else if ("$argv[$n]" == "-imf") then
      @ n++
      set image = $argv[$n]
   else if ("$argv[$n]" == "-i") then
      @ n++
      set out = $argv[$n]
   else if ("$argv[$n]" == "-m") then
      set multiple = 1
      @ n++
      @ bstart = $argv[$n]
   else if ("$argv[$n]" == "-s") then
      @ n++
      @ static = $argv[$n]
   else if ("$argv[$n]" == "-fmt") then
      @ n++
      set format = $argv[$n]
      if ($format == qtl) set format = "qtl_ntsc"
   else
      echo "Usage: composite -fs n -fe n -base fname -back fname"
      echo "                 [-imf {rla|qtl}] [-fmt ntsc_4d|qtl_ntsc] [-i name] [-m]"
      echo " "
      echo "If optional args aren't specified, the these defaults will be used:"
      echo "                 -base im"
      echo "                 -imf rla"
      echo "                 -fmt qtl_ntsc"
      echo "                 -i   comp"
      echo "                 -m multiple background files are assumed."
      exit
   endif
   @ n++
end
#
#  Do we have everything?
#
if ($start == 0) then
   echo "A start frame must be specified."
   exit
endif
if ($end == 0) then
   @ end = $start
endif
#
#  Ok, here we go.  Composite all these frames over a static background.
#
if ($multiple == 0) then
   echo "Compositing $base over $background (static), $start through $end..."
   imf_comp <<!
   init -fs $start -fe $end -i $out -v -fmt $format -imf $image
   a = file $base
   b = file -nf $background
   out = a over b
!
#
#  Composite one frames over a series of background images.
#
else if ($static) then
   echo "Compositing $base.$static over $background (multiple), $start through $end..."
   set file = `echo $base $static | awk '{printf "%s.%04d", $1, $2}'`
   imf_comp <<~
   init -fs $start -fe $end -i $out -v -fmt $format -imf $image
   a = file -nf $file
   b = file -fs $bstart $background
   out = a over b
~
#
#  Composite all these frames over a series of background images.
#
else
   echo "Compositing $base over $background (multiple), $start through $end..."
   imf_comp <<~
   init -fs $start -fe $end -i $out -v -fmt $format -imf $image
   a = file $base
   b = file -fs $bstart $background
   out = a over b
~
endif
#echo "Yippy Skippy, we're done\!"
echo " "
