#!/bin/bash -x # # Set yardmarkers A and B within the lookup table. Lookup table runs # from 0-256. The length of an interval is C. With each new image, # one interval in moved along the lookup table. The total number of # intervals used (H) must be as close to D (the total number of files) # as possible, but not more. Once yardmarker B is reached the # intervals are counted down. If yardmarker A is reached then # intervals are counted up. The way between the yardmarkers A and B # may be repeated G number of times. When H is reached we must always # end up within an interval length of yardmarker A. This is necessary # for looped animations. z=+ A=64 # position of first yardmarker B=192 # position of second yardmarker C=20 # lenght of one interval D=`ls $1 | wc -l` # the number intervals used must be as close to a multiple of D as possible, without going over E=1 # Number of the first and later current image F=`echo "scale=4; ( ( $B - $A ) * 2 ) / $C" | bc` # Number of images processed per trip from A to B and back G=`echo "scale=0; $D / $F" | bc` # Number of trips between A and B required # Rounded down to a whole number H=`echo "scale=0; $F * $G" | bc | awk '{printf "%.0f",$1}'` # Total number images used I=`expr $A + $C` #end position after the first interval J=`expr \( $B - $A \) \* 2` #Double the distance traveled between yardmarkers so we will always end #at the first yardmarker L=255 # lightness value for generating the rainbow S=255 # saturation value for generating the rainbow tmp0="coloration_0_$$.png" tmp1="coloration_1_$$.png" tmp2="coloration_2_$$.png" tmp3="coloration_3_$$.png" trap "rm -f $tmpB $tmp0 $tmp1 $tmp2 $tmp3 $tmp4; exit 0" 0 trap "rm -f $tmpB $tmp0 $tmp1 $tmp2 $tmp3 $tmp4; exit 1" 1 2 3 15 # create rainbow lut # create hue channel convert -size 1x256 gradient: $tmp0 # create saturation channel convert -size 1x256 xc:"rgb($S,$S,$S)" -channel Green -separate $tmp1 # create lightness channel convert -size 1x256 xc:"rgb($L,$L,$L)" -channel Blue -separate $tmp2 # combine channels to form rainbow lut convert $tmp0 -colorspace HSB $tmp0 \ -compose CopyRed -composite $tmp1 \ -compose CopyGreen -composite $tmp2 \ -compose CopyBlue -composite -colorspace RGB \ -rotate 90 $tmp3 I2=$I y=$z # keep track of when to stop processing and the current position on the color lookup table while [ $E -le $H ]; do VAR=`printf "%03d" $E` if [ $I -ge $B ]; then z="-" # $I is the current position on the lookup table I=`expr $B - \( $I - $B \)` elif [ $I -le $A ]; then z="+" I=`expr $A + \( $A - $I \)` # $I2 is needed so that we'll always end at Yardmarker A elif [ $I2 -ge $J ]; then y="-" I2=`expr $J - \( $I2 - $J \)` elif [ $I2 -le $A ]; then y="+" I2=`expr $A + \( $A - $I \)` fi # color the grayscale images with the color lookup table convert $1/$VAR.png \( $tmp3 -roll -$I+0 \) -clut $VAR.png I=`expr $I $z $C` I2=`expr $I2 $y $C` let E=$E+1 done