Index: trunk/psModules/src/camera/pmFPAMaskWeight.c
===================================================================
--- trunk/psModules/src/camera/pmFPAMaskWeight.c	(revision 24399)
+++ trunk/psModules/src/camera/pmFPAMaskWeight.c	(revision 24483)
@@ -199,7 +199,8 @@
 }
 
-bool pmReadoutSetVariance(pmReadout *readout, bool poisson)
+bool pmReadoutSetVariance(pmReadout *readout, const psImage *noiseMap, bool poisson)
 {
     PS_ASSERT_PTR_NON_NULL(readout, false);
+    // check that the noiseMap (if it exists) matches the readout variance size)
 
     pmCell *cell = readout->parent;     // The parent cell
@@ -240,7 +241,12 @@
     }
 
-    // XXX if readnoise is based on an image map, we need to apply it here
-    readout->variance = (psImage*)psBinaryOp(readout->variance, readout->variance, "+",
-                                           psScalarAlloc(readnoise*readnoise/gain/gain, PS_TYPE_F32));
+    // apply a supplied readnoise map (NOTE: in DN, not electrons):
+    if (noiseMap) {
+	psImage *rdVar = (psImage*)psBinaryOp(NULL, (const psPtr) noiseMap, "*", (const psPtr) noiseMap);
+	readout->variance = (psImage*)psBinaryOp(readout->variance, readout->variance, "+", rdVar);
+	psFree (rdVar);
+    } else {
+	readout->variance = (psImage*)psBinaryOp(readout->variance, readout->variance, "+", psScalarAlloc(readnoise*readnoise/gain/gain, PS_TYPE_F32));
+    }
 
     return true;
@@ -249,5 +255,5 @@
 // this function creates the variance pixels, or uses the existing variance pixels.  it will set
 // the noise pixel values only if the variance image is not supplied
-bool pmReadoutGenerateVariance(pmReadout *readout, bool poisson)
+bool pmReadoutGenerateVariance(pmReadout *readout, const psImage *noiseMap, bool poisson)
 {
     PS_ASSERT_PTR_NON_NULL(readout, false);
@@ -293,8 +299,8 @@
     readout->variance = variance;
 
-    return pmReadoutSetVariance(readout, poisson);
-}
-
-bool pmReadoutGenerateMaskVariance(pmReadout *readout, psImageMaskType satMask, psImageMaskType badMask, bool poisson)
+    return pmReadoutSetVariance(readout, noiseMap, poisson);
+}
+
+bool pmReadoutGenerateMaskVariance(pmReadout *readout, psImageMaskType satMask, psImageMaskType badMask, const psImage *noiseMap, bool poisson)
 {
     PS_ASSERT_PTR_NON_NULL(readout, false);
@@ -303,10 +309,10 @@
 
     success &= pmReadoutGenerateMask(readout, satMask, badMask);
-    success &= pmReadoutGenerateVariance(readout, poisson);
+    success &= pmReadoutGenerateVariance(readout, noiseMap, poisson);
 
     return success;
 }
 
-bool pmCellGenerateMaskVariance(pmCell *cell, psImageMaskType satMask, psImageMaskType badMask, bool poisson)
+bool pmCellGenerateMaskVariance(pmCell *cell, psImageMaskType satMask, psImageMaskType badMask, const psImage *noiseMap, bool poisson)
 {
     PS_ASSERT_PTR_NON_NULL(cell, false);
@@ -316,5 +322,5 @@
     for (int i = 0; i < readouts->n; i++) {
         pmReadout *readout = readouts->data[i]; // The readout
-        success &= pmReadoutGenerateMaskVariance(readout, poisson, satMask, badMask);
+        success &= pmReadoutGenerateMaskVariance(readout, satMask, badMask, noiseMap, poisson);
     }
 
