#############################################
#                                           #
# Description:  CLIP SVJ Maker,             #
#               for FlipBook testing and    #
#               generating the final SVJ    #
#                                           #
# Program:      toclip                      #
#                                           #
# Date:         May 11 1995                 #
#                                           #
# Creator:      The Ray Rebels              #
#                                           #
# $1 Picture Name                           #
# $2 Current Frame                          #
# $3 Image Count                            #
# $4 Field                                  #
#                                           #
#############################################


if ( $SCSI_VIDEO_MODE == "SV_MODE_PAL" ) then
	set TV_res = 576
else
	set TV_res = 480
endif

if ( $3 == "0" ) then
	mv $1.svj $1.svj.bak
	infopic $1.$2 > tmp;head -7 tmp > tmp1
	echo ""
endif
set res = `cat tmp1`
set x_res = $res[14]
set y_res = $res[17]

set x_div = `echo "720 / $x_res" | bc`
set y_div = `echo "$TV_res / $y_res" | bc`

@ x_newres =  $x_res * $x_div
@ y_newres =  $y_res * $y_div

if ( $x_res == 720 && $y_res == $TV_res ) then
	echo "Full Resolution Picture, Creating final Cut"
	cp $1.$2.pic tmp.pic
else
	if ( $x_newres != 720 || $y_newres != $TV_res ) then
		zoom $1.$2 tmp -x 720 -y $TV_res 
		echo "X Res not multiple of 720, Using Zoom."
	else
		enlarge $1.$2 tmp $x_div $y_div 
	endif
endif

soft2svj -nframes=1 -start=$3 -count=$3 tmp.pic $1.svj >& /tmp/null.txt 

echo "[1m- Frame $2 Saved in $1.svj. -[0m"

rm tmp.pic

# END of Shell
