#!/bin/bash -x ########################## ###### With the help of a gradient mask, sigmoidal-contrast effect and ###### Absolute Distortion LUT Map, an image sequence is gradually ###### squished and pulled down to the bottom of the screen. The image ###### sequence gradually arcs downwards at the sides by using arc ###### distort on the above mask. Finally, another gradient mask uses ###### arc distort to create a sunset-like fade-away to a background ###### image sequence. ######################### trap "rm -f *.list *.mpc *.cache" 1 2 3 15 trap "exit 0" 2 # Defaults needed only once for each sequence 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 ! sig_con_end=50 # sigmoidal contrast with max effect ! sig_mid_end=100 # sigmoidal mid point with max effect ! arc_angle_end=150 # maximum radius of arc distortion ! # start position of the bottom and top radius of arc distort in the fade BOTTOM_RADIUS=$(echo " scale=2; sqrt ( ( $MID ^ 2 ) + ( $BOTTOM ^ 2 ) ) " | bc ) #X TOP_RADIUS=$(echo " scale=2; $BOTTOM_RADIUS * 1.3 " | bc ) #X SIG_CON_X=0 # start position for variable needed to calculate contrast of sigmoidal-contrast SIG_MID_X=0 # start position for variable needed to calculate mid-point of sigmoidal-contrast ARC_ANGLE=0 # start position of variable needed to calculate arc distort arc_angle_start=1 # arc distort with no effect ! sig_con_start=1 # sigmoidal-contrast contrast with no effect ! sig_mid_start=50 # sigmoidal-contrast mid point with no effect ! # frame-to-frame change in position of the bottom and top radius of arc distort ! BOTTOM_RADIUS_CHANGE=$(echo " scale=2; $BOTTOM_RADIUS / $FADE_SUNSET" | bc) # ! TOP_RADIUS_CHANGE=$(echo " scale=2; ( $TOP_RADIUS - 1 ) / $FADE_SUNSET" | bc) # ! # frame-to-frame change in sigmoidal-contrast contrast and mid-point SIG_CON_CHANGE=$(echo "scale=4; ( sqrt ( $sig_con_end - $sig_con_start ) ) / ( $SIG_ARC ) " | bc) # ! SIG_MID_CHANGE=$(echo "scale=4; ( sqrt ( $sig_mid_end - $sig_mid_start ) ) / ( $SIG_ARC )" | bc) # ! # frame-to-frame change in initial arc distort ARC_ANGLE_CHANGE=$(echo "scale=4; ( sqrt ( $arc_angle_end - $arc_angle_start ) ) / ( $ARC_COUNT )" | bc) # ! # Writes various default variables to file so that they can exported from the parent process. echo -e "export MID=$MID \n export WIDTH=$WIDTH \n export BOTTOM=$BOTTOM \n export sig_con_end=$sig_con_end \n export sig_con_start=$sig_con_start \n export sig_mid_end=$sig_mid_end \n export sig_mid_start=$sig_mid_start \n export arc_angle_end=$arc_angle_end \n export arc_angle_start=$arc_angle_start \n export TOP_RADIUS_CHANGE=$TOP_RADIUS_CHANGE \n export BOTTOM_RADIUS_CHANGE=$BOTTOM_RADIUS_CHANGE \n export SIG_CON_CHANGE=$SIG_CON_CHANGE \n export SIG_MID_CHANGE=$SIG_MID_CHANGE \n export ARC_ANGLE_CHANGE=$ARC_ANGLE_CHANGE">defaults-sunset.list # Writes various variables to file for first image in sequence needing that variable echo "ARC_ANGLE=$ARC_ANGLE">sigarc-vario.list echo -e "TOP_RADIUS=$TOP_RADIUS \n BOTTOM_RADIUS=$BOTTOM_RADIUS">sunset-fade-vario.list # Creates final LUT distortion mask before the fade ! convert -size "$WIDTH"x"$BOTTOM" gradient: -rotate 180 -sigmoidal-contrast "$sig_con_end","$sig_mid_end"% -distort arc "$arc_angle_end" +repage -gravity north -crop "$WIDTH"x"$BOTTOM"+0+0 -resize "$WIDTH"x"$BOTTOM"! +repage maskC.mpc # ! } # Calculates sigmoidal-contrast distortion variables and writes them to file for the next image SigVario () { SIG_CON_X=$(echo " scale=4; $SIG_CON_CHANGE + $SIG_CON_X " | bc ) SIG_MID_X=$(echo " scale=4; $SIG_MID_CHANGE + $SIG_MID_X " | bc ) SIG_CON=$(echo " scale=4; ( $SIG_CON_X ^ 2 ) + $sig_con_start " | bc ) SIG_MID=$(echo " scale=4; ( $SIG_MID_X ^ 2 ) + $sig_mid_start " | bc ) echo -e "SIG_CON_X=$SIG_CON_X \n SIG_MID_X=$SIG_MID_X">sig-vario.list } # Same as above, but adds arc distort variables and fill-ins for the arc distort command SigArcVario () { . sig-vario.list SigVario ANGLE=$(echo " scale=4; ( $ARC_ANGLE ^ 2 ) + $arc_angle_start " | bc ) ARKFILL=" -distort arc "$ANGLE" +repage " ARC_ANGLE=$(echo " scale=4; $ARC_ANGLE_CHANGE + $ARC_ANGLE " | bc ) MaskySigArc echo "ARC_ANGLE=$ARC_ANGLE">sigarc-vario.list } # LUT distortion mask: gradient with variable sigmoidal-contrast and arc distort MaskySigArc () { MASK_LUT=" ( -size "$WIDTH"x"$BOTTOM" gradient: -rotate 180 -sigmoidal-contrast "$SIG_CON","$SIG_MID"% "$ARKFILL" -gravity north -crop "$WIDTH"x"$BOTTOM"+0+0 -resize "$WIDTH"x"$BOTTOM"! +gravity ) " } # LUT distortion mask: gradient with variable sigmoidal-contrast MaskySig () { MASK_LUT=" ( -size "$WIDTH"x"$BOTTOM" gradient: -rotate 180 -sigmoidal-contrast "$SIG_CON","$SIG_MID"% ) " } SunsetFadeVario () { FILL_BACK=$1 # Adds background image to command # New position of bottom and top radius of arc distort for next image TOP_RADIUS=$(echo " scale=2; $TOP_RADIUS - $TOP_RADIUS_CHANGE " | bc ) BOTTOM_RADIUS=$(echo " scale=2; $BOTTOM_RADIUS - $BOTTOM_RADIUS_CHANGE " | bc ) SUNSET_FILL='( -filter point -size '$WIDTH'x'$BOTTOM' gradient: -set option:distort:viewport '$WIDTH'x'$BOTTOM'-'$MID'-'$BOTTOM' -distort arc 180,0,'$TOP_RADIUS','$BOTTOM_RADIUS' -negate ) -compose src-over -composite' echo -e "TOP_RADIUS=$TOP_RADIUS \n BOTTOM_RADIUS=$BOTTOM_RADIUS">sunset-fade-vario.list } # Imagemagick command. Two gradients are combined - the second one # having sigmoidal contrast and arc distort effects - and their RG # channels act as a look-up map for the foreground image. Later # another arc distorted gradient act as a mask to fade foreground to # background image. Sunset () { convert $FILL_BACK \( $1 \( \( -size "$BOTTOM"x"$WIDTH" gradient: -rotate 90 \) $MASK_LUT -channel RGB -combine \) -fx 'p{v.r*w,v.g*h}' \) $SUNSET_FILL $2 } # Calls only one infile first... Caller1 () { INFILE1=`awk 'NR==1 {print $1}' caller.list` OUTFILE=`awk 'NR==2' caller.list` } # and then calls the second one to act as the background Caller2 () { INFILE1=`awk 'NR==1 {print $1}' caller.list` INFILE2=`awk 'NR==2 {print $1}' caller.list` OUTFILE=`awk 'NR==3' caller.list` } if [ $COUNT = $DEFAULT_FETCH ]; then # Creates defaults for this sequence Caller1 Defaults $INFILE1 SigVario MaskySig Sunset $INFILE1 $OUTFILE elif [ $COUNT -le $COMPOSE1 ]; then # Only sigmoidal-contrast performed on LUT . sig-vario.list Caller1 SigVario MaskySig Sunset $INFILE1 $OUTFILE elif [ $COUNT -le $COMPOSE2 ]; then # Sigmoidal-contrast and arc-distort . sigarc-vario.list SigArcVario Caller1 Sunset $INFILE1 $OUTFILE else # Fade using mask . sunset-fade-vario.list Caller2 SunsetFadeVario $INFILE2 Sunset $INFILE1 $OUTFILE fi