Index: trunk/psModules/src/camera/pmFPAMaskWeight.c
===================================================================
--- trunk/psModules/src/camera/pmFPAMaskWeight.c	(revision 26893)
+++ trunk/psModules/src/camera/pmFPAMaskWeight.c	(revision 29544)
@@ -476,6 +476,29 @@
 }
 
-
-
+// find any pixels which are not already masked (with maskTest) which are not valid and raise maskSet bits
+bool pmReadoutMaskInvalid (const pmReadout *readout, psImageMaskType maskTest, psImageMaskType maskSet) {
+
+    if (!readout) return true;
+
+    psImage *image = readout->image;
+    psImage *mask  = readout->mask;
+    psImage *variance = readout->variance;
+    for (int y = 0; y < image->numRows; y++) {
+        for (int x = 0; x < image->numCols; x++) {
+            if (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskTest) continue;
+            bool valid = false;
+            valid = isfinite(image->data.F32[y][x]);
+            if (valid && variance) {
+                valid &= isfinite(variance->data.F32[y][x]);
+            }
+            if (valid) continue;
+            mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] |= maskSet;
+        }
+    }
+
+    return true;
+}
+
+// raise maskVal for any invalid pixels
 bool pmReadoutMaskNonfinite(pmReadout *readout, psImageMaskType maskVal)
 {
