--- ldr	2010-11-18 11:44:25.210324795 +0300
+++ hdr	2010-11-18 11:45:02.875774064 +0300
@@ -1,4 +1,4 @@
-mkldrmf () {
+mkprocessrmf () {
     srcdef () {
         awk '
             BEGIN {
@@ -32,9 +32,8 @@
 sRGBPROFILE?=${sRGBPROFILE}
 
 CONV?=${CONV}
-REMAP?=${REMAPLDR}
+REMAP?=${REMAP}
 FFUSE?=${FFUSE}
-EFUSE?=${EFUSE}
 MERGE?=${MERGE}
 DEGHOST?=${DEGHOST}
 BLEND?=${BLEND} ${f}
@@ -59,7 +58,7 @@
 	@\${RM} ${BLIN}
 EOT
     }
-    epilogue1 () {
+    epilogueLDR1 () {
         cat <<EOT
 \${DST}.tiff: tmp.tiff
 	@\${CONV} tmp.tiff \\
@@ -68,6 +67,77 @@
 	@\${RM} tmp.tiff
 EOT
     }
+    epilogueHDR1 () {
+        bright=-1.67
+        light=0.35
+        chrom=0.95
+        r=0.9500
+        g=0.7000
+        b=1.2000
+        cat <<EOT
+\${DST}.tiff: tmp.tiff
+	@pfsin tmp.tiff \\
+	 | pfsclamp --min 1e-20: --max 1e+20 \\
+	 | pfswb -v -r ${r} -g ${g} -b ${b} \\
+	 | pfstmo_reinhard05 -v -b ${bright} -c ${chrom} -l ${light} \\
+	 | pfsoutimgmagick -s -b 16 \${DST}.tiff
+	@\${RM} tmp.tiff
+	@\${CONV} \${DST}.tiff \\
+		+matte +repage ${DARG} \\
+		-compress \${IMCOMP} \${DST}.tiff
+EOT
+    }
+    epilogueHDR2 () {
+        bright=1.33
+        light=0.50
+        chrom=0.95
+        #[ "${K}" = a ] && {
+        #    bright=1.33
+        #}
+        #[ "${K}" = b ] && {
+        #    bright=-5.00
+        #    light=0.30
+        #}
+        #[ "${K}" = b ] && bright=-1.50
+        #[ "${K}" = b ] && light=0.9625
+        cat <<EOT
+
+\${DST}.tiff: tmp.tiff
+	@pfsin tmp.tiff \\
+	 | pfsclamp --min 4 --max 65536 \\
+	 | pfswb -v -r 1.0500 -g 1.0000 -b 0.9750 \\
+	 | pfstmo_mantiuk08 -v -d pd=crt -c 0.9 -e 0.75 \\
+	 | pfsoutimgmagick -b 16 \${DST}.0.tiff
+	@pfsin tmp.tiff \\
+	 | pfsclamp --min 4 --max 65536 \\
+	 | pfswb -v -r 1.0500e-04 -g 1.0000e-04 -b 0.9750e-04 \\
+	 | pfstmo_reinhard05 -v -b ${bright} -c ${chrom} -l ${light} \\
+	 | pfsoutimgmagick -s -b 16 \${DST}.1.tiff
+	@\${RM} tmp.tiff
+	@\${CONV} \${DST}.0.tiff \\
+		-colorspace HSL -channel B -separate \\
+		-compress \${IMCOMP} \${DST}.2.tiff
+	@\${CONV} \${DST}.2.tiff \\
+		-negate \\
+		+level 0%,90%,1.0 \\
+		-compress \${IMCOMP} \${DST}.3.tiff
+	@\${CONV} \${DST}.2.tiff \${DST}.3.tiff \\
+		-compose lighten -composite \\
+		-level 49%,100%,1.2 \\
+		+level 0%,98%,1.0 \\
+		-compress \${IMCOMP} \${DST}.4.tiff
+	@\${CONV} \${DST}.1.tiff \${DST}.4.tiff \\
+		-compose copy-opacity -composite \\
+		-compress \${IMCOMP} \${DST}.5.tiff
+	@\${CONV} \${DST}.0.tiff \${DST}.5.tiff \\
+		-compose src-over -composite \\
+		+matte +repage ${DARG} \\
+		-compress \${IMCOMP} \${DST}.tiff
+	@\${RM} \${DST}.0.tiff \${DST}.1.tiff \\
+		\${DST}.2.tiff \${DST}.3.tiff \\
+		\${DST}.4.tiff \${DST}.5.tiff
+EOT
+    }
     remap () {
         SRC="${NAM}${ESF}${FSF}.tiff"
         eval "EV=\${EV${e}}; SEV=\${EV${e}S${s}}"
@@ -77,12 +147,16 @@
         [ -z "${EV}" ] || ESRC="${EV}"
         [ -z "${SEV}" ] || ESRC="${SEV}"
         [ -z "${ESRC}" ] || ESRC="-e ${ESRC}"
-        t=$(printf 'tmp-%04d.%s' ${ISRC} ${LDRSFX})
+        t=$(printf 'tmp-%04d.%s' ${ISRC} ${TMPSFX})
+        m=''
+        [ "${PROCESS}" = HDR ] \
+        && m=$(printf ' tmp-%04d_gray.pgm' ${ISRC})
         cat <<EOT
 ${t}: \${DST}.pto ${SRC}
 	@\${REMAP} -i ${ISRC} ${ESRC} \${DST}.pto
 EOT
-        RMIN="${RMIN} ${SRC}"
+        RMIN="${RMIN} ${SRC}${m}"
+        n="${SRC}"
         SRC="tmpf${NAM}${ESF}${FSF}.tiff"
         cat <<EOT
 ${SRC}: ${t}
@@ -109,6 +183,9 @@
 	@\${LN} ${t} ${SRC}
 EOT
         fi
+        [ "${PROCESS}" = HDR ] && cat <<EOT
+	@\${EXIFTFF} ${n} \${EXIFTAG} ${SRC}
+EOT
         cat <<EOT
 	@\${RM} ${t}
 EOT
@@ -122,6 +199,11 @@
             cat <<EOT
 ${t}: ${FFIN}
 	@\${FFUSE} -o ${t} ${FFIN}
+EOT
+            [ "${PROCESS}" = HDR ] && cat <<EOT
+	@\${EXIFTFF} ${FFIN%% *} \${EXIFTAG} ${t}
+EOT
+            cat <<EOT
 	@\${RM} ${FFIN}
 EOT
         fi
@@ -164,6 +246,9 @@
 EOT
         fi
         [ -z "${ap}" ] || echo "${ap}" | tail +2
+        [ "${PROCESS}" = HDR ] && cat <<EOT
+	@\${EXIFTFF} ${t} \${EXIFTAG} ${SRC}
+EOT
         cat <<EOT
 	@\${RM} ${t}
 EOT
@@ -281,5 +366,5 @@
         estack
     done
     epilogue
-    epilogue${EPL}
+    "epilogue${PROCESS}${EPL}"
 }
