Index: trunk/psModules/src/pmImageCombine.c
===================================================================
--- trunk/psModules/src/pmImageCombine.c	(revision 4425)
+++ trunk/psModules/src/pmImageCombine.c	(revision 4992)
@@ -8,6 +8,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-06-29 01:39:10 $
+ *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-09-11 22:25:39 $
  *
  *  XXX: pmRejectPixels() has a known bug with the pmImageTransform() call.
@@ -308,9 +308,11 @@
 /******************************************************************************
 XXX: Directly from Paul Price
-XXX: Must add mask parameter, use it in gradient calculation.
  *****************************************************************************/
-static psF32 CalcGradient(psImage *image,
-                          psS32 x,
-                          psS32 y)
+static psF32 CalcGradient(
+    psImage *image,
+    psImage *imageMask,
+    psS32 x,
+    psS32 y
+)
 {
     psTrace("ImageCombine.CalcGradient", 4, "Calling CalcGradient(%d, %d)\n", x, y);
@@ -324,13 +326,34 @@
     int yMin = PS_MAX(y - 1, 0);
     int yMax = PS_MIN(y + 1, image->numRows - 1);
-    for (int j = yMin; j <= yMax; j++) {
-        for (int i = xMin; i <= xMax; i++) {
-            if ((i != x) && (j != y)) {
-                pixels->data.F32[num] = image->data.F32[j][i];
-                mask->data.U8[num] = 0;
-                num++;
+    if (imageMask != NULL) {
+        for (int j = yMin; j <= yMax; j++) {
+            for (int i = xMin; i <= xMax; i++) {
+                if ((i != x) && (j != y) && (0 == imageMask->data.U8[j][i])) {
+                    pixels->data.F32[num] = image->data.F32[j][i];
+                    mask->data.U8[num] = 0;
+                    num++;
+                } else {
+                    mask->data.U8[num] = 1;
+                }
             }
         }
-    }
+    } else {
+        //
+        // This code is simply the previous loop without the imageMask.
+        // XXX: Consider restructuring this.
+        //
+        for (int j = yMin; j <= yMax; j++) {
+            for (int i = xMin; i <= xMax; i++) {
+                if ((i != x) && (j != y)) {
+                    pixels->data.F32[num] = image->data.F32[j][i];
+                    mask->data.U8[num] = 0;
+                    num++;
+                } else {
+                    mask->data.U8[num] = 1;
+                }
+            }
+        }
+    }
+
     pixels->n = num;
     mask->n = num;
@@ -472,16 +495,32 @@
 XXX: The inToOut and outToIn transforms are confusing.  Verify that what
      I think they mean syncs with PWP.
-XXX: Must add mask parameter, use it in gradient calculation.
  *****************************************************************************/
-psArray *pmRejectPixels(const psArray *images,          ///< Array of input images
-                        const psArray *errors,          ///< The pixels which were rejected in the combination
-                        const psArray *inToOut,         ///< Transformation from input to output system
-                        const psArray *outToIn,         ///< Transformation from output to input system
-                        psF32 rejThreshold,             ///< Rejection threshold
-                        psF32 gradLimit                 ///< Gradient limit
-                       )
+psArray *pmRejectPixels(
+    const psArray *images,              ///< Array of input images
+    const psArray *masks,               ///< Array of input image masks
+    const psArray *errors,              ///< The pixels which were rejected in the combination
+    const psArray *inToOut,             ///< Transformation from input to output system
+    const psArray *outToIn,             ///< Transformation from output to input system
+    psF32 rejThreshold,                 ///< Rejection threshold
+    psF32 gradLimit                     ///< Gradient limit
+)
 {
     psTrace("ImageCombine.pmRejectPixels", 3, "Calling pmRejectPixels()\n");
     PS_ASSERT_PTR_NON_NULL(images, NULL);
+    for (psS32 im = 0 ; im < images->n ; im++) {
+        psImage *tmpImage = (psImage *) images->data[im];
+        PS_ASSERT_IMAGE_NON_NULL(tmpImage, NULL);
+        PS_ASSERT_IMAGE_NON_EMPTY(tmpImage, NULL);
+        PS_ASSERT_IMAGE_TYPE(tmpImage, PS_TYPE_F32, NULL);
+        if (masks != NULL) {
+            PS_ASSERT_INT_EQUAL(images->n, masks->n, NULL);
+            psImage *tmpMask = (psImage *) masks->data[im];
+            PS_ASSERT_IMAGE_NON_NULL(tmpMask, NULL);
+            PS_ASSERT_IMAGE_NON_EMPTY(tmpMask, NULL);
+            PS_ASSERT_IMAGE_TYPE(tmpMask, PS_TYPE_F32, NULL);
+            PS_ASSERT_IMAGES_SIZE_EQUAL(tmpImage, tmpMask, NULL);
+        }
+        PS_ASSERT_IMAGES_SIZE_EQUAL(((psImage *) images->data[0]), tmpImage, NULL);
+    }
     PS_ASSERT_PTR_NON_NULL(errors, NULL);
     PS_ASSERT_PTR_NON_NULL(inToOut, NULL);
@@ -492,5 +531,4 @@
     PS_ASSERT_INT_EQUAL(numImages, inToOut->n, NULL);
     PS_ASSERT_INT_EQUAL(numImages, outToIn->n, NULL);
-    // XXX: Loop through all images, ensure their sizes are equal
 
     //
@@ -570,4 +608,8 @@
                     if (im != otherImg) {
                         // Map the outCoords to inCoords that for otherImg space.
+                        psImage *tmpMask = NULL;
+                        if (masks != NULL) {
+                            tmpMask = masks->data[otherImg];
+                        }
                         psPlaneTransformApply(inCoords,
                                               (psPlaneTransform * )outToIn->data[otherImg],
@@ -577,5 +619,5 @@
                         if ((xPix >= 0) && (xPix <= ((psImage*)(images->data[otherImg]))->numCols - 1) &&
                                 (yPix >= 0) && (yPix <= ((psImage*)(images->data[otherImg]))->numRows - 1)) {
-                            meanGrads += CalcGradient(images->data[otherImg], xPix, yPix);
+                            meanGrads += CalcGradient(images->data[otherImg], tmpMask, xPix, yPix);
                             numGrads++;
                         }
