#!/bin/csh -f
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
#  This is a csh script that uses the Utah Raster Toolket (URT) to
#  convert raw color mapped image date into YUV files suitable for display
#  on the Abekas A60.
#
#  This script also incorporates the new text capability made possible
#  by the IRIS font manager routines.  This is done by creating a text
#  string and putting it in a separate URT file.  This text image can
#  later by composited on top of any image data.
#
#  Author:     Wesley C. Barris
#              AHPCRC
#              Minnesota Supercomputer Center, Inc.
#  Date:       Mar. 15, 1991
#
#  Copyright @ 1991, 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.
#
#-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
#
#  Edit these lines to customize this script.
#
@ aframe  = 410				#starting location on Abekas
@ xsize   = 512 			#image X size
@ ysize   = 512 			#image Y size
@ fsize   = 40				#font size
set font  = Inja			#font name
set cmap  = cmap	                #ASCII color map for the 8 bit files
set files = /work/i3b/wes/airfoil/*.rle
set my_name = "Put your name here"

#
#  Figure out this color map format.
#
if (-e $cmap) then
   @ cmapsize = `ls -l $cmap | awk '{print $5}'`
   if ($cmapsize == 4736) then
      echo "This is an indexed color map."
      echo "It must be converted to a non-indexed ASCII color map using icol."
      exit
   else if (`wc -l $cmap | awk '{print $1}'` == 256) then
#     echo "$cmap is a non-indexed ASCII color map."
   else
      echo "Unknown color map -- I don't know what to do."
      exit
   endif
else
   echo "I can't find your color map: $cmap"
   exit
endif
#
#  Make some static text.
#
texttorle $font $fsize 50 35 10 $my_name | repos -p 120 400 >title$$.rle
#
#  Make a nice background.
#
rlebg -s 720 486 -v 0.1 0.9 20 20 255 >back$$.rle
#
#  Execute this loop once for each file.
#
foreach file ($files)
#
#  First create an image containing the filename.
#
#             font  point red grn blu  text             xpos ypos
   texttorle $font $fsize 040 050 085 $file:t | repos -p 260 280 >text$$.rle
#
#  This is a list of what happens in the next chunk.
#  NOTE: Comments cannot be placed within the continuations.
#
#    Convert a raw grayscale image into URT format
#    Flip it right-side-up
#    Add the colormap
#    Apply the map to the pixels creating a 24 bit image
#    Scale it to roughly fit the Abekas screen
#    Locate the origin here
#    Composite the image over the background
#    Composite the text over the image
#    Convert the whole sh-bang into YUV format
#    Rcp it onto the Abekas A60
#
#
   echo "Converting $file..."
   rawtorle -w $xsize -h $ysize -n 1 $file \
	| rleflip -v \
	| rleldmap -t $cmap \
	| applymap \
	| fant -p 0 0 -s 0.94921875 0.94921875 \
	| repos -p 117 00 \
	| rlecomp - over back$$.rle \
	| rlecomp title$$.rle over - \
	| rlecomp text$$.rle over - \
	| rletoabA60 \
	>junk$$.yuv
   echo "Sending to frame $aframe on the Abekas A60..."
   rcp junk$$.yuv abekas:$aframe
#
#  Increment the frame counter for the Abekas and check if it's full.
#
   @ aframe++
   if ($aframe > 749) then
      echo "The Abekas is full."
      rm title$$.rle back$$.rle junk$$.yuv
      exit
   endif
end
#
#  Clean up shop.
#
rm title$$.rle back$$.rle junk$$.yuv text$$.rle
