Index: trunk/psModules/src/imcombine/pmSubtractionStamps.c
===================================================================
--- trunk/psModules/src/imcombine/pmSubtractionStamps.c	(revision 14106)
+++ trunk/psModules/src/imcombine/pmSubtractionStamps.c	(revision 14195)
@@ -6,4 +6,5 @@
 #include <pslib.h>
 
+#include "pmSubtraction.h"
 #include "pmSubtractionStamps.h"
 
@@ -40,27 +41,23 @@
 
 
-psArray *pmSubtractionFindStamps(psArray *stamps, const psImage *image, const psImage *mask,
-                                 psMaskType maskVal, psMaskType used, float threshold,
-                                 float spacing, int border)
+psArray *pmSubtractionFindStamps(psArray *stamps, const psImage *image, const psImage *subMask,
+                                 float threshold, float spacing)
 {
     PS_ASSERT_IMAGE_NON_NULL(image, NULL);
     PS_ASSERT_IMAGE_TYPE(image, PS_TYPE_F32, NULL);
-    if (mask) {
-        PS_ASSERT_IMAGE_NON_NULL(mask, NULL);
-        PS_ASSERT_IMAGES_SIZE_EQUAL(image, mask, NULL);
-        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, NULL);
-    }
-    if (used == 0) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "The mask value for used stamps cannot be zero.");
-        return NULL;
+    if (subMask) {
+        PS_ASSERT_IMAGE_NON_NULL(subMask, NULL);
+        PS_ASSERT_IMAGES_SIZE_EQUAL(image, subMask, NULL);
+        PS_ASSERT_IMAGE_TYPE(subMask, PS_TYPE_MASK, NULL);
     }
     PS_ASSERT_FLOAT_LARGER_THAN(spacing, 0.0, NULL);
-    PS_ASSERT_INT_NONNEGATIVE(border, NULL);
-    PS_ASSERT_INT_LARGER_THAN(image->numCols, 2 * border, NULL);
-    PS_ASSERT_INT_LARGER_THAN(image->numRows, 2 * border, NULL);
 
-    maskVal |= used;                    // Make sure we don't get stamps we've already used
-    int xNumStamps = (image->numCols - 2 * border) / spacing + 1; // Number of stamps in x
-    int yNumStamps = (image->numRows - 2 * border) / spacing + 1; // Number of stamps in y
+    // Size of image
+    int numRows = image->numRows;
+    int numCols = image->numCols;
+
+    // Number of stamps
+    int xNumStamps = numCols / spacing + 1;
+    int yNumStamps = numRows / spacing + 1;
 
     if (stamps) {
@@ -78,7 +75,4 @@
         }
     }
-    // Footprint of image
-    int numRows = image->numRows;
-    int numCols = image->numCols;
 
     for (int j = 0, index = 0; j < yNumStamps; j++) {
@@ -96,39 +90,19 @@
 
                 // Bounds of region to search for stamp
-                int yMin = border + j * (numRows - border) / (yNumStamps + 1);
-                int yMax = border + (j + 1) * (numRows - border) / (yNumStamps + 1) - 1;
-                int xMin = border + i * (numCols - border) / (xNumStamps + 1);
-                int xMax = border + (i + 1) * (numCols - border) / (xNumStamps + 1) - 1;
-                assert(yMax < image->numRows - border && xMax < image->numCols - border &&
-                       yMin >= border && xMin >= border);
+                int yMin = j * numRows / (yNumStamps + 1);
+                int yMax = (j + 1) * numRows / (yNumStamps + 1) - 1;
+                int xMin = i * numCols / (xNumStamps + 1);
+                int xMax = (i + 1) * numCols / (xNumStamps + 1) - 1;
+                assert(yMax < image->numRows && xMax < image->numCols && yMin >= 0 && xMin >= 0);
 
                 for (int y = yMin; y <= yMax ; y++) {
                     for (int x = xMin; x <= xMax ; x++) {
-                        if (image->data.F32[y][x] > fluxBest) {
-                            bool ok = true;
-                            if (mask) {
-                                // Check kernel footprint for bad pixels
-                                if (mask->data.PS_TYPE_MASK_DATA[y][x] & maskVal) {
-                                    ok = false;
-                                } else {
-                                    for (int v = -border; v <= border && ok; v++) {
-                                        for (int u = -border; u <= border && ok; u++) {
-                                            if (mask->data.PS_TYPE_MASK_DATA[y + v][x + u] & maskVal) {
-                                                ok = false;
-#if 0
-                                                // Mark it so we don't have to look so hard next time
-                                                mask->data.PS_TYPE_MASK_DATA[y][x] |= maskVal;
-#endif
-                                            }
-                                        }
-                                    }
-                                }
-                            }
-
-                            if (ok) {
-                                fluxBest = image->data.F32[y][x];
-                                xBest = x;
-                                yBest = y;
-                            }
+                        if ((!subMask || !(subMask->data.PS_TYPE_MASK_DATA[y][x] &
+                                           (PM_SUBTRACTION_MASK_BORDER | PM_SUBTRACTION_MASK_FOOTPRINT |
+                                            PM_SUBTRACTION_MASK_REJ))) &&
+                            image->data.F32[y][x] > fluxBest) {
+                            fluxBest = image->data.F32[y][x];
+                            xBest = x;
+                            yBest = y;
                         }
                     }
