#!/bin/bash

SRCDIR="Fist"
DSTDIR="P"
FTMP="/dev/shm/tmp.fimg"
FDST="/dev/shm/foo.fimg"

txtfont="Courier-Bold"
txtsz=" 240 "
small=" 72 "

#   ------------------------------------------------------------

NBRE=$(ls -1 ${SRCDIR}/*.fimg | wc -l)

OFFS=$(( 8 ))

> log.calcul

#   ------------------------------------------------------------
function tagpic {

fname=$1
echo "--------[${fname}]-----------"

texte='F.I.S.T'
infos="22 février | Mixart-Myrys"

colA=" Black "
colB=" MediumVioletRed "
colC=" SteelBlue "

mogrify 							\
        -font $txtfont						\
	 -gravity North 					\
	-pointsize $txtsz					\
	-fill ${colA}	-annotate +0+22   "${texte}"		\
	-fill ${colB}	-annotate +10+32  "${texte}"		\
	-gravity South 						\
	-pointsize $small 					\
	-fill ${colA} 	-annotate +0+22 "${infos}"		\
	-fill ${colC} 	-annotate +4+18 "${infos}"		\
         ${fname}
}
#   ------------------------------------------------------------

#		MAIN

for idx in $(seq 0 $NBRE)
do
	imgA=$(printf "$SRCDIR/%04d.fimg" $idx)
	vb=$(( $(( idx + OFFS )) % NBRE))
	imgB=$(printf "$SRCDIR/%04d.fimg" $vb)
	dst=$(printf "%s/%05d.png" ${DSTDIR} $idx)

	echo "======== " $idx $imgA $vb $imgB " === " $dst

	#
	# tryin to autocompute the mixing coefficient
	#
	compute=" s(${idx} / 8) "

	K=$(echo $compute | bc -l)

	printf " %25s  =>  %8.3f\n" "$compute" $K
	echo $idx $K >> log.calcul

	fimgfx xper ${imgB} ${FTMP}
	fimgops    -k ${K} ${FTMP} ${imgA} mix ${FDST}

	fimg2png ${FDST} ${dst}

	tagpic ${dst}

	echo

done

#   ------------------------------------------------------------

~/bin/encode.sh

#   ------------------------------------------------------------
