#!/bin/bash -x ########################## ###### Everything as in the sunset composition except backwards. ######################### trap "rm -f *.list *.mpc *.cache" 1 2 3 15 trap "exit 0" 2 # Defaults needed only once for each sequence Defaults () { 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 ) #!! TOP_RADIUS=$(echo " scale=2; $BOTTOM_RADIUS * 1.3 " | bc ) #!! 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) #!! TOP_RADIUS=1 BOTTOM_RADIUS=0 # 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 export sig_con_end=$sig_con_end \n export sig_mid_end=$sig_mid_end \n export arc_angle_end=$arc_angle_end \n export BOTTOM_RADIUS=$BOTTOM_RADIUS \n export TOP_RADIUS=$TOP_RADIUS \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 -e "SIG_CON_X=$SIG_CON_X \n SIG_MID_X=$SIG_MID_X ">sig-vario.list echo "ARC_ANGLE=$ARC_ANGLE">sigarc-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 +gravity 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_end - ( $SIG_CON_X ^ 2 ) " | bc ) SIG_MID=$(echo " scale=4; $sig_mid_end - ( $SIG_MID_X ^ 2 ) " | 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 () { SigVario ANGLE=$(echo " scale=4; $arc_angle_end - ( $ARC_ANGLE ^ 2 ) " | 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"! +repage ) " } # 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 () { INFILE2=`awk 'NR==1 {print $1}' caller.list` INFILE1=`awk 'NR==2 {print $1}' caller.list` OUTFILE=`awk 'NR==3' caller.list` } if [ $COUNT = $DEFAULT_FETCH ]; then # Creates defaults for this sequence Caller2 Defaults SunsetFadeVario $INFILE2 Sunset $INFILE1 $OUTFILE elif [ $COUNT -le $COMPOSE1 ]; then # unfades as in a sunrise using mask . sunset-fade-vario.list Caller2 SunsetFadeVario $INFILE2 Sunset $INFILE1 $OUTFILE elif [ $COUNT -le $COMPOSE2 ]; then # sigmoidal contrast and arc distortion effects . sig-vario.list . sigarc-vario.list SigArcVario Caller1 Sunset $INFILE1 $OUTFILE else # sigmoidal contrast effect . sig-vario.list SigVario MaskySig Caller1 Sunset $INFILE1 $OUTFILE fi