# ###################################################################
#
#	Fonctions d'effets spéciaux
#
# -------------------------------------------------------------------
GOTO_TGA ()
{
# echo $1 "GOTO TGA" $2

convert $1 				\
	-compress none			\
	-alpha off			\
	-colorspace RGB			\
	-type truecolor			\
	$2
}
# -------------------------------------------------------------------
GOTO_PNG ()
{
convert $1 -alpha off $2
#cho $IDX $2 >> $LOG_ENC
}
# ###################################################################
# et ici on a les fonction qui font un traitement sur une image
# -------------------------------------------------------------------
# nouveau 29 novembre 2022
do_blur ()
{
TMP=$TMPGA
GOTO_TGA       $1 $TMP
tga_filtres    $TMP liss2x2 $TMP 
GOTO_PNG       $TMP $2
}
# -------------------------------------------------------------------
# nouveau 6 juillet 2022
do_rotulacion ()
{
TMP=$TMPGA
local angle=$( echo "-233 + ($IDX / 4.51)" | bc -l )
echo rotulation $angle

GOTO_TGA       $1 $TMP
tga_effects    $TMP rotulacion $TMP $angle
GOTO_PNG       $TMP $2
}
# -------------------------------------------------------------------
# nouveau 5 juillet 2022
do_pixel_x ()
{
TMP=$TMPGA
GOTO_TGA       $1 $TMP
tga_effects    $TMP pixelX $TMP 
GOTO_PNG       $TMP $2
}
# -------------------------------------------------------------------
# nouveau 7 juillet 2022
do_pixel_y ()
{
TMP=$TMPGA
GOTO_TGA       $1 $TMP
tga_effects    $TMP pixelY $TMP 
GOTO_PNG       $TMP $2
}
# -------------------------------------------------------------------
do_palettes ()
{
TMP=$TMPGA
local TMPA="/dev/shm/pal_a.tga"
local TMPB="/dev/shm/pal_b.tga"

echo "double palette : " $1 $2

GOTO_TGA       $1                $TMP

tga_applymap 1 $TMP volcano.map      $TMPA
tga_applymap 1 $TMP neon.map         $TMPB

tga_combine    $TMPA $TMPB vsplit $TMP  540 0

GOTO_PNG       $TMP              $2
}
# -------------------------------------------------------------------
# nouveau 3 juillet 2022
do_warp0 ()
{
TMP=$TMPGA
GOTO_TGA       $1 $TMP
tga_effects    $TMP warp0 $TMP 22.222 300 300
tga_effects    $TMP updown $TMP 
GOTO_PNG       $TMP $2
}
# -------------------------------------------------------------------
do_double_television ()
{
TMP=$TMPGA
TMPA="/dev/shm/tb_a.tga"
TMPB="/dev/shm/tb_b.tga"

echo "double television : " $1 $2

GOTO_TGA       $1                $TMP

tga_television $TMP grink      $TMPA  16
tga_television $TMP gruud      $TMPB  0

tga_combine    $TMPA $TMPB vdeg $TMP  T

GOTO_PNG       $TMP              $2
}
# -------------------------------------------------------------------
do_combination ()
{
TMP=$TMPGA
BW="/dev/shm/bwfx-tmp.tga"

GOTO_TGA       $1 $TMP
tga_effects    $TMP gray $BW
tga_combine    $TMP $BW circle0 $TMP 0
GOTO_PNG       $TMP $2
}
# -------------------------------------------------------------------
do_binary_sobel ()
{
TMP=$TMPGA
GOTO_TGA       $1 $TMP
tga_effects    $TMP bicolor0   $TMP 100
tga_filtres    $TMP sobel      $TMP 4
tga_effects    $TMP gray       $TMP
GOTO_PNG       $TMP $2
}
# -------------------------------------------------------------------
do_canalplus ()
{
TMP=$TMPGA
GOTO_TGA       $1 $TMP
tga_television $TMP proto     $TMP 7
tga_filtres    $TMP liss2x2   $TMP
GOTO_PNG       $TMP $2
}
# -------------------------------------------------------------------
# en principe séquence 'timelapse'
#
do_incruste ()
{
local base="$1"		# come here in TGA format
local incr="$2"		# PNG image from grabber 
local dest="$3"		# PNG destination

local incrtga="/dev/shm/to-incrust.tga"
local outincrust="/dev/shm/outincrust.tga"

# printf "base = %20s\nincr = %20s\ndest = %20s\n" $base $incr $dest

cp -v $base $outincrust

GOTO_TGA $incr		$incrtga

tga_incrust $outincrust $incrtga poke $outincrust 130 530

GOTO_PNG $outincrust      $dest
# echo $dest written
}
# -------------------------------------------------------------------
do_brotched ()
{
# use the source, Luke !
# see brotche.cpp
./brotche $1 $2
}
# -------------------------------------------------------------------
do_water_lopass ()
{
# echo $1 " => water cracra => " $2

TMP=$TMPGA

GOTO_TGA $1 $TMP
tga_effects    $TMP water    $TMP  6
tga_filtres    $TMP lopass   $TMP
tga_effects    $TMP water    $TMP  6
tga_filtres    $TMP lopass   $TMP
tga_cadre      $TMP sweep    $TMP 50 50 50 60
GOTO_PNG $TMP $2
}
# -------------------------------------------------------------------
do_contour_2x2 ()
{
local TMP="/dev/shm/do_contour_2x2.tga"

# echo "contour 2x2 sur $1"

GOTO_TGA     $1 $TMP
tga_effects  $TMP cont2x2g   $TMP
tga_filtres  $TMP smooth     $TMP
tga_cadre    $TMP filet      $TMP
GOTO_PNG     $TMP $2
}
# -------------------------------------------------------------------
do_mosaic_blablanux ()
{
TMP=$TMPGA

GOTO_TGA     $1 $TMP
tga_effects  $TMP mosaic     $TMP
tga_equalize $TMP lumin      $TMP 130
tga_cadre    $TMP blablanux  $TMP 30 102 233 36
GOTO_PNG     $TMP $2
}
# -------------------------------------------------------------------
do_decomp_burp ()
{
TMP=$TMPGA

GOTO_TGA     $1 $TMP
tga_effects  $TMP decomp     $TMP  F
tga_cadre    $TMP burp2      $TMP 2 32 64 16
GOTO_PNG     $TMP $2
}
# -------------------------------------------------------------------
do_rastarecurse ()
{
TMP=$TMPGA

GOTO_TGA     $1 $TMP
tga_effects  $TMP recurse    $TMP  64
tga_cadre    $TMP rasta0     $TMP  12
GOTO_PNG     $TMP $2
}
# -------------------------------------------------------------------

# log_event "do effects loaded"


