#!/bin/sh

NAMES='P1010101 P1010102 P1010103 P1010104 P1010105 P1010106 P1010107 P1010108 P1010109 P1010110 P1010111 P1010112'

NONA='nona -t 2'
ENBL='enblend -w -z -m 896'
CONV='convert'
COMP='composite'

for n in ${NAMES}
do
    convert "../${n}.JPG" -depth 16 -compress LZW "${n}.JPG.tiff"
done
exit

${NONA} -o tmp+1- spring-1-hdr+1.pto
${NONA} -o tmp+0- spring-1-hdr+0.pto
${NONA} -o tmp-1- spring-1-hdr-1.pto
rm -f *.JPG.tiff
${ENBL} -f 7474x8239 -o tmp+1.tiff tmp+1-000[0-3].tif
${ENBL} -f 7474x8239 -o tmp+0.tiff tmp+0-000[0-3].tif
${ENBL} -f 7474x8239 -o tmp-1.tiff tmp-1-000[0-3].tif
${CONV} tmp+10004.tif +contrast -modulate 137,50 -compress LZW tmp+10004.tif
${COMP} -geometry +3341+5264 tmp+10004.tif tmp+1.tiff -compress LZW tmp+1.tiff
${CONV} tmp-10004.tif +contrast -modulate 137,50 -compress LZW tmp-10004.tif
${COMP} -geometry +3341+5264 tmp-10004.tif tmp-1.tiff -compress LZW tmp-1.tiff
rm -f tmp+1-0*.tif tmp+0-0*.tif tmp-1-0*.tif
${CONV} tmp+1.tiff -crop 3392x6720+2066+29 +repage -compress LZW tmp+1.tiff
${CONV} tmp+0.tiff -crop 3392x6720+2042+45 +repage -compress LZW tmp+0.tiff
${CONV} tmp-1.tiff -crop 3712x7104+988+15 +repage -compress LZW tmp-1.tiff
#exit

${NONA} -o tmp- spring-1-hdr.pto
rm -f tmp+1.tiff tmp+0.tiff tmp-1.tiff
${CONV} tmp-0000.tif -support 1.4 -resize 50% -crop 1696x3344+145+133 +repage hdr+1.tiff
${CONV} tmp-0001.tif -support 1.4 -resize 50% -crop 1696x3344+145+133 +repage hdr+0.tiff
${CONV} tmp-0002.tif -support 1.4 -resize 50% -crop 1696x3344+145+133 +repage hdr-1.tiff
rm -f tmp-0*.tif
${CONV} hdr+1.tiff -channel red -fx 's.a<0.5?0:1' -separate -depth 1 -compress LZW alpha+1.tiff
${CONV} hdr+0.tiff -channel red -fx 's.a<0.5?0:1' -separate -depth 1 -compress LZW alpha+0.tiff
${CONV} hdr-1.tiff -channel red -fx 's.a<0.5?0:1' -separate -depth 1 -compress LZW alpha-1.tiff
${CONV} alpha+1.tiff alpha+0.tiff -compose multiply -composite -compress LZW mask.tiff
${CONV} alpha-1.tiff mask.tiff -compose multiply -composite -compress LZW mask.tiff
rm -f alpha*.tiff
${CONV} hdr+1.tiff mask.tiff -compose multiply -composite +matte -compress LZW hdr+1.tiff
${CONV} hdr+0.tiff mask.tiff -compose multiply -composite +matte -compress LZW hdr+0.tiff
${CONV} hdr-1.tiff mask.tiff -compose multiply -composite +matte -compress LZW hdr-1.tiff
rm -f mask.tiff
