Index: trunk/psModules/src/imcombine/pmSubtractionMask.c
===================================================================
--- trunk/psModules/src/imcombine/pmSubtractionMask.c	(revision 23849)
+++ trunk/psModules/src/imcombine/pmSubtractionMask.c	(revision 23851)
@@ -38,5 +38,5 @@
 
 psImage *pmSubtractionMask(const psImage *mask1, const psImage *mask2, psImageMaskType maskVal,
-                           int size, int footprint, float badFrac, bool useFFT)
+                           int size, int footprint, float badFrac, pmSubtractionMode mode)
 {
     PS_ASSERT_IMAGE_NON_NULL(mask1, NULL);
@@ -114,10 +114,4 @@
     }
 
-    // XXX Could do something smarter here --- we will get images that are predominantly masked (where the
-    // skycell isn't overlapped by a large fraction by the observation), so that convolving around every bad
-    // pixel is wasting time.  As a first cut, I've put in a check on the fraction of bad pixels, but we could
-    // imagine looking for the edge of big regions and convolving just at the edge.  As a second cut, allow
-    // use of FFT convolution.
-
     for (int y = 0; y < numRows; y++) {
         for (int x = 0; x < numCols; x++) {
@@ -131,12 +125,11 @@
     }
 
-    // Block out the entire stamp footprint around bad input pixels.
-
     // We want to block out with the CONVOLVE mask anything that would be bad if we convolved with a bad
-    // reference pixel (within 'size').  Then we want to block out with the FOOTPRINT mask everything within a
+    // reference pixel (within 'size').  Then we want to block out with the REJ mask everything within a
     // footprint's distance of those (within 'footprint').
 
     bool oldThreads = psImageConvolveSetThreads(true); // Old value of threading for psImageConvolve
 
+    // Pixels that will be bad (or poor) if we convolve with a bad reference pixel
     if (!psImageConvolveMask(mask, mask, PM_SUBTRACTION_MASK_BAD_1, PM_SUBTRACTION_MASK_CONVOLVE_1,
                              -size, size, -size, size)) {
@@ -148,4 +141,28 @@
                              -size, size, -size, size)) {
         psError(PS_ERR_UNKNOWN, false, "Unable to convolve bad pixels from mask 2.");
+        psFree(mask);
+        return NULL;
+    }
+
+    // Pixels that should not be chosen as stamps
+    psImageMaskType maskRej = PM_SUBTRACTION_MASK_BAD_1 | PM_SUBTRACTION_MASK_BAD_2 |
+        PM_SUBTRACTION_MASK_BORDER;     // Mask value for rejection
+    switch (mode) {
+      case PM_SUBTRACTION_MODE_1:
+        maskRej |= PM_SUBTRACTION_MASK_CONVOLVE_1;
+        break;
+      case PM_SUBTRACTION_MODE_2:
+        maskRej |= PM_SUBTRACTION_MASK_CONVOLVE_2;
+        break;
+      case PM_SUBTRACTION_MODE_UNSURE:
+      case PM_SUBTRACTION_MODE_DUAL:
+        maskRej |= PM_SUBTRACTION_MASK_CONVOLVE_1 | PM_SUBTRACTION_MASK_CONVOLVE_2;
+        break;
+      default:
+        psAbort("Unsupported subtraction mode: %x", mode);
+    }
+    if (!psImageConvolveMask(mask, mask, maskRej, PM_SUBTRACTION_MASK_REJ,
+                             -footprint, footprint, -footprint, footprint)) {
+        psError(PS_ERR_UNKNOWN, false, "Unable to convolve bad pixels.");
         psFree(mask);
         return NULL;
