DST?=0042

CPUS?=4
MEM?=1536
DEPTH?=16
IMCOMP?=zip
ENCOMP?=DEFLATE

CONV?=convert
REMAP?=eval nona -v -t ${CPUS} -m TIFF_m -r ldr -p UINT${DEPTH} -z DEFLATE -o tmp-
BLEND?=eval enblend -v --compression=${ENCOMP} -m ${MEM} -b 16384 --fine-mask -f 3072x2048+0+0
EFUSE?=eval enfuse -v --compression=${ENCOMP} -m ${MEM} -b 16384 --exposure-mu=0.6 --exposure-sigma=0.6
DEGHOST?=deghosting_mask -v -s 50 -c 1.0 -t 150 -i 6 -a mw

RM=echo
MV=mv

all: ${DST}.tiff

tmp-0000.tif: ${DST}.pto 00-e00.tiff 
	@${REMAP} -i 0 -e 0.0119726416660759 ${DST}.pto
	@${CONV} \
		-profile '../../tools/profiles/RGB(dcraw).icm' \
		tmp-0000.tif \
		-profile '../../tools/profiles/sRGB Color Space Profile.ICM' \
		-compress zip tmp-0000.tif
tmp-0001.tif: ${DST}.pto 00-e01.tiff tmp-0000.tif
	@${REMAP} -i 1 -e 1.01197264166608 ${DST}.pto
	@${CONV} \
		-profile '../../tools/profiles/RGB(dcraw).icm' \
		tmp-0001.tif \
		-profile '../../tools/profiles/sRGB Color Space Profile.ICM' \
		-compress zip tmp-0001.tif
tmp-0002.tif: ${DST}.pto 00-e02.tiff tmp-0001.tif
	@${REMAP} -i 2 -e 1.59693514238723 ${DST}.pto
	@${CONV} \
		-profile '../../tools/profiles/RGB(dcraw).icm' \
		tmp-0002.tif \
		-profile '../../tools/profiles/sRGB Color Space Profile.ICM' \
		-compress zip tmp-0002.tif
tmp-0003.tif: ${DST}.pto 00-e03.tiff tmp-0002.tif
	@${REMAP} -i 3 -e 2.59693514238723 ${DST}.pto
	@${CONV} \
		-profile '../../tools/profiles/RGB(dcraw).icm' \
		tmp-0003.tif \
		-profile '../../tools/profiles/sRGB Color Space Profile.ICM' \
		-compress zip tmp-0003.tif
tmp-0004.tif: ${DST}.pto 00-e04.tiff tmp-0003.tif
	@${REMAP} -i 4 -e 3.24079131066413 ${DST}.pto
	@${CONV} \
		-profile '../../tools/profiles/RGB(dcraw).icm' \
		tmp-0004.tif \
		-profile '../../tools/profiles/sRGB Color Space Profile.ICM' \
		-compress zip tmp-0004.tif
tmp-0005.tif: ${DST}.pto 00-e05.tiff tmp-0004.tif
	@${REMAP} -i 5 -e 4.24079131066413 ${DST}.pto
	@${CONV} \
		-profile '../../tools/profiles/RGB(dcraw).icm' \
		tmp-0005.tif \
		-profile '../../tools/profiles/sRGB Color Space Profile.ICM' \
		-compress zip tmp-0005.tif
tmp-0006.tif: ${DST}.pto 00-e06.tiff tmp-0005.tif
	@${REMAP} -i 6 -e 5.91886323727459 ${DST}.pto
	@${CONV} \
		-profile '../../tools/profiles/RGB(dcraw).icm' \
		tmp-0006.tif \
		-profile '../../tools/profiles/sRGB Color Space Profile.ICM' \
		-compress zip tmp-0006.tif
tmp-0007.tif: ${DST}.pto 00-e07.tiff tmp-0006.tif
	@${REMAP} -i 7 -e 7.65582877411325 ${DST}.pto
	@${CONV} \
		-profile '../../tools/profiles/RGB(dcraw).icm' \
		tmp-0007.tif \
		-profile '../../tools/profiles/sRGB Color Space Profile.ICM' \
		-compress zip tmp-0007.tif
tmp-0008.tif: ${DST}.pto 00-e08.tiff tmp-0007.tif
	@${REMAP} -i 8 -e 9.24079131066413 ${DST}.pto
	@${CONV} \
		-profile '../../tools/profiles/RGB(dcraw).icm' \
		tmp-0008.tif \
		-profile '../../tools/profiles/sRGB Color Space Profile.ICM' \
		-compress zip tmp-0008.tif
tmp-0009.tif: ${DST}.pto 00-e09.tiff tmp-0008.tif
	@${REMAP} -i 9 -e 10.8257537576407 ${DST}.pto
	@${CONV} \
		-profile '../../tools/profiles/RGB(dcraw).icm' \
		tmp-0009.tif \
		-profile '../../tools/profiles/sRGB Color Space Profile.ICM' \
		-compress zip tmp-0009.tif
tmp-0010.tif: ${DST}.pto 00-e10.tiff tmp-0009.tif
	@${REMAP} -i 10 -e 12.5627194592961 ${DST}.pto
	@${CONV} \
		-profile '../../tools/profiles/RGB(dcraw).icm' \
		tmp-0010.tif \
		-profile '../../tools/profiles/sRGB Color Space Profile.ICM' \
		-compress zip tmp-0010.tif
tmp-0011.tif: ${DST}.pto 00-e11.tiff tmp-0010.tif
	@${REMAP} -i 11 -e 14.2407913106641 ${DST}.pto
	@${CONV} \
		-profile '../../tools/profiles/RGB(dcraw).icm' \
		tmp-0011.tif \
		-profile '../../tools/profiles/sRGB Color Space Profile.ICM' \
		-compress zip tmp-0011.tif
	@${EFUSE} -o .tmp-0011.tif tmp-0000.tif tmp-0001.tif tmp-0002.tif tmp-0003.tif tmp-0004.tif tmp-0005.tif tmp-0006.tif tmp-0007.tif tmp-0008.tif tmp-0009.tif tmp-0010.tif tmp-0011.tif
	@${RM} tmp-0000.tif tmp-0001.tif tmp-0002.tif tmp-0003.tif tmp-0004.tif tmp-0005.tif tmp-0006.tif tmp-0007.tif tmp-0008.tif tmp-0009.tif tmp-0010.tif tmp-0011.tif
	@${MV} .tmp-0011.tif tmp-0011.tif

SRC=00-e00.tiff 00-e01.tiff 00-e02.tiff 00-e03.tiff 00-e04.tiff 00-e05.tiff 00-e06.tiff 00-e07.tiff 00-e08.tiff 00-e09.tiff 00-e10.tiff 00-e11.tiff
BLIN=tmp-0011.tif

tmp.tiff: ${BLIN}
	@${RM} ${SRC}
	@${BLEND} -o tmp.tiff ${BLIN}
	@${RM} ${BLIN}
${DST}.tiff: tmp.tiff
	@${CONV} tmp.tiff \
		+matte +repage \
		-compress ${IMCOMP} ${DST}.tiff
	@${RM} tmp.tiff
#		-rotate 90 \
#		-unsharp 0x0.20 \
#	@pfsin tmp.tiff \
#	 | pfstmo_reinhard02 -v -k 0.09 \
#	 | pfsgamma -m 0.9 -g 2.2 \
#	 | pfsoutimgmagick ${DST}.tiff
#	@${RM} tmp.tiff
#	@${CONV} ${DST}.tiff \
#		+matte +repage \
#		-unsharp 0x0.3 \
#		-compress ${IMCOMP} ${DST}.tiff
#		-unsharp 0x0.80+0.6+0.05 \
