#!/bin/bash -x ###################### #### Same as "tractor-beam" composition except everything is performed backwards. ###################### trap "rm -f folder-list caller *.mpc *.cache" 1 2 3 15 trap "exit 0" 2 # These are variables for "tractor-beam" which only have to be set # once every time "tractor-beam" is used. Defaults () { BOTTOM=`convert "$1" -format "%h" info:` # heigth of the images !! WIDTH=`convert "$1" -format "%w" info:` # width of the images !! MID=$(echo "$WIDTH / 2" | bc) # mid-point of the width !! NEWMID=$(echo " scale=1; $MID - 0.5 " | bc ) # subtracts half-pixel from width: imagemagick half-pixel problem !! PERSP_CHANGE=$(echo "scale=3; ( ( $BOTTOM - 4 ) / 2 ) / $TRACTOR" | bc) # perspective distortion speed !! TOP=$(echo "scale=3; $PERSP_CHANGE * $TRACTOR" | bc) #Start position for outer top edge of beam NEWBOTTOM=$(echo "scale=3; $BOTTOM - $TOP " | bc) #Start position for outer bottom edge of beam GRAY=$(echo " $MID * 0.1" | bc) # grayscale width for wipe !! WHITE_SPEED=$(echo " scale=2; 3 / $FADE_TRACTOR" | bc) # white-out speed !! WHITE=$(echo " scale=2; 1 + ( $WHITE_SPEED * $FADE_TRACTOR )" | bc) #start brightness of white-in fade WIPE_SPEED=$(echo " scale=2; (( $WIDTH + $GRAY - ( $GRAY / 10 )) / 2 ) / $FADE_TRACTOR " | bc) # speed of wipe !! WIPE=$(echo " scale=2; $WIPE_SPEED * $FADE_TRACTOR " | bc) #start position of wipe-in BARREL_CHANGE=$(echo " scale=3; 1 / $COMPOSE " | bc) # speed of barrel distortion change BARRELA=$(echo " scale=3; $BARREL_CHANGE * $COMPOSE " | bc) # start value for barrel distortiong BARRELD=$(echo " scale=3; 1 - ( $BARREL_CHANGE * $COMPOSE ) " | bc) #start value for barrel distortion ENDBARRELA=$(echo " scale=3; $BARREL_CHANGE * $TRACTOR " | bc) # not sure what this is for ENDBARRELD=$(echo " scale=3; 1 - ( $BARREL_CHANGE * $TRACTOR )" | bc) #not sure what this is for # Defaults are saved in a file, so that they can be exported as # variable in the parent process "master" echo -e "export WIDTH=$WIDTH \n export BOTTOM=$BOTTOM \n export MID=$MID \n export NEWMID=$NEWMID \n export PERSP_CHANGE=$PERSP_CHANGE \n export WHITE_SPEED=$WHITE_SPEED \n export WIPE_SPEED=$WIPE_SPEED \n export BARREL_CHANGE=$BARREL_CHANGE \n export TOP=$TOP \n export NEWBOTTOM=$NEWBOTTOM ">defaults-tractor.list # Masks needed for the wipe at the end of the effect: A gradient and a # cookie cutter that gives the gradient the same shape as the image # who's perspective has been distorted. !! convert -size "$MID"x"$BOTTOM" xc:white \ \( -size "$BOTTOM"x"$GRAY" gradient:transparent-white -rotate 90 \) \ +append maskA.mpc # Writes various variables to file for first image in sequence needing that variable echo -e "BARRELA=$ENDBARRELA \n BARRELD=$ENDBARRELD ">vario.list } # Change to the top and bottom of the right and left sides to create a # squeeze effect on the sides, barrel distort gives edges a curve. The # file vario.list remembers the variables for when the process is # recalled for the next file. VarioPerspective () { TOP=$(echo "scale=2; $TOP - $PERSP_CHANGE " | bc) NEWBOTTOM=$(echo "scale=3; $NEWBOTTOM + $PERSP_CHANGE " | bc) BARRELA=$(echo " scale=3; $BARRELA - $BARREL_CHANGE " | bc ) BARRELD=$(echo " scale=3; $BARRELD + $BARREL_CHANGE " | bc ) echo -e "TOP=$TOP \n NEWBOTTOM=$NEWBOTTOM \n BARRELA=$BARRELA \n BARRELD=$BARRELD ">vario.list } # Set whiteout and wipe effects at the end of the composition. WIPE # and WHITE variables change file to file to create the # whiteout-wipe. The file vario-fade.list remembers the variables for # when the process is called for the next file. VarioFade () { WIPE=$(echo "scale=2; $WIPE - $WIPE_SPEED" | bc) WHITE=$(echo "scale=2; $WHITE - $WHITE_SPEED" | bc) BARRELA=$(echo " scale=3; $BARRELA - $BARREL_CHANGE " | bc ) BARRELD=$(echo " scale=3; $BARRELD + $BARREL_CHANGE " | bc ) LEFT_GRADIENT='-fx 'u*$WHITE' ( maskA.mpc -chop '$WIPE'x0 ) -compose dstin -composite' RIGHT_GRADIENT='-fx 'u*$WHITE' ( maskA.mpc -flop -gravity east -chop '$WIPE'x0 ) -compose dstin -composite' echo -e "WIPE=$WIPE\nWHITE=$WHITE\n BARRELA=$BARRELA \n BARRELD=$BARRELD">vario-fade.list } # Composition effect: squeezes together the top and bottom sides of # the right and left sides and then does a barndoor wipe which whites # out towards the sides Magick () { convert $2 \( $1 -crop 50%x100%+0+0 -alpha on -virtual-pixel transparent -distort perspective ' 0,0 0,'$TOP' 0,'$BOTTOM' 0,'$NEWBOTTOM' '$NEWMID','$BOTTOM' '$MID','$BOTTOM' '$NEWMID',0 '$MID',0 ' $LEFT_GRADIENT \( $1 -gravity east -crop 50%x100%+0+0 -alpha on -virtual-pixel transparent -distort perspective '0.5,0 0,0 0.5,'$BOTTOM' 0,'$BOTTOM' '$MID','$BOTTOM' '$MID','$NEWBOTTOM' '$MID',0 '$MID','$TOP'' $RIGHT_GRADIENT \) +append -distort barrel '0.0 0.0 0.0 1.0 '$BARRELA' 0.0 0.0 '$BARRELD'' \) -compose src-over -composite $3 } # Calls up infile and outfile names from caller.list file created by call-files script Caller () { INFILE2=`awk 'NR==1 {print $1}' caller.list` INFILE1=`awk 'NR==2 {print $1}' caller.list` OUTFILE=`awk 'NR==3' caller.list` } # Order of the composition. First runthrough makes sure default values # are saved, second does wipe-in white in, third does perspective # un-distort of side along with barrel distort. if [ $COUNT = $DEFAULT_FETCH ]; then Caller Defaults $INFILE1 VarioFade Magick $INFILE1 $INFILE2 $OUTFILE elif [ $COUNT -le $COMPOSE1 ]; then . vario-fade.list VarioFade Caller Magick $INFILE1 $INFILE2 $OUTFILE else . vario.list VarioPerspective Caller Magick $INFILE1 $INFILE2 $OUTFILE fi