# Base + Active -> Base, Active, Armed (2 in 3 out)
#!/bin/sh +xv
#set -o verbose
export VERBOSE=-v
export IMAGE=$1
export TmpDIR=$4

# Copy alpha from image into a separate file
$iSPL $VERBOSE  -i Icons/images/$IMAGE.sgi -oA $TmpDIR/A-.sgi

# Get inverse of light visibility image
$iI   $VERBOSE  Icons/images/$IMAGE-shadow.sgi  $TmpDIR/$IMAGE-shadowInv.sgi

# Darken alpha, so shadows won't crop around the image edges
#$iCN $EITHREADS  $VERBOSE  -c 0.75  $TmpDIR/$IMAGE-shadowInv.sgi  .sgi

# Add the result to the shadow image
$iCM  $VERBOSE  -i $TmpDIR/$IMAGE-shadowInv.sgi  -i $TmpDIR/A-$IMAGE.sgi  -o $TmpDIR/$IMAGE-A.sgi

# Merge image channels
$iCM  $VERBOSE  -iRGB Icons/images/$IMAGE.sgi  -iA $TmpDIR/$IMAGE-A.sgi  -o $TmpDIR/.sgi

$iS -ma $VERBOSE  -s $2 $3  $TmpDIR/$IMAGE.sgi         $TmpDIR/$IMAGE.c
#rm $TmpDIR/*.sgi

# Copy alpha from image into a separate file
$iSPL $VERBOSE  -i Icons/images/$IMAGE-Active.sgi -oA $TmpDIR/A-.sgi

# Get inverse of light visibility image
$iI   $VERBOSE  Icons/images/$IMAGE-Active-shadow.sgi  $TmpDIR/$IMAGE-shadowInv.sgi

# Darken alpha, so shadows won't crop around the image edges
#$iCN $EITHREADS  $VERBOSE  -c 0.75  $TmpDIR/$IMAGE-shadowInv.sgi  .sgi

# Add the result to the shadow image
$iCM  $VERBOSE  -i $TmpDIR/$IMAGE-shadowInv.sgi  -i $TmpDIR/A-$IMAGE-Active.sgi  -o $TmpDIR/$IMAGE-A.sgi

# Merge image channels
$iCM  $VERBOSE  -iRGB Icons/images/$IMAGE-Active.sgi  -iA $TmpDIR/$IMAGE-A.sgi  -o $TmpDIR/.sgi

$iS -ma $EITHREADS   $VERBOSE  -s $2 $3  $TmpDIR/$IMAGE-Active.sgi         $TmpDIR/$IMAGE-Active.c
$iS -ma $EITHREADS   $VERBOSE  -s $2 $3  $TmpDIR/$IMAGE-Active.sgi         $TmpDIR/$IMAGE-Armed.c
#rm $TmpDIR/*.sgi

rm -f $TmpDIR/$IMAGE-A.sgi $TmpDIR/$IMAGE-shadowInv.sgi $TmpDIR/$IMAGE.sgi $TmpDIR/$IMAGE-Active.sgi $TmpDIR/A-$IMAGE.sgi $TmpDIR/A-$IMAGE-Active.sgi

cat $TmpDIR/$IMAGE.c $TmpDIR/$IMAGE-Active.c $TmpDIR/$IMAGE-Armed.c > $TmpDIR/$IMAGE-all.c

rm -f $TmpDIR/$IMAGE.c $TmpDIR/$IMAGE-Active.c $TmpDIR/$IMAGE-Armed.c
