Index: trunk/psModules/src/imcombine/pmImageCombine.c
===================================================================
--- trunk/psModules/src/imcombine/pmImageCombine.c	(revision 12742)
+++ trunk/psModules/src/imcombine/pmImageCombine.c	(revision 21183)
@@ -8,6 +8,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-04-04 22:42:48 $
+ *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:38 $
  *
  *  XXX: pmRejectPixels() has a known bug with the pmImageTransform() call.
@@ -17,4 +17,6 @@
  */
 
+// XXX this is somewhat messy and unclear on the masking.
+
 #ifdef HAVE_CONFIG_H
 #include <config.h>
@@ -53,5 +55,5 @@
 
     buffer->pixels = psVectorAlloc(numImages, PS_TYPE_F32);
-    buffer->masks = psVectorAlloc(numImages, PS_TYPE_MASK);
+    buffer->masks = psVectorAlloc(numImages, PS_TYPE_VECTOR_MASK);
     buffer->errors = psVectorAlloc(numImages, PS_TYPE_F32);
     buffer->stats = psStatsAlloc(PS_STAT_SAMPLE_MEAN | PS_STAT_SAMPLE_STDEV);
@@ -67,5 +69,5 @@
                           const psArray *errors, // Array of input error images
                           const psArray *masks, // Array of input masks
-                          psU32 maskVal, // Mask value
+                          psImageMaskType maskVal, // Mask value
                           psS32 numIter, // Number of rejection iterations
                           psF32 sigmaClip, // Number of standard deviations at which to reject
@@ -115,6 +117,7 @@
         if (masks) {
             psImage *mask = masks->data[i]; // Mask of interest
-            pixelMasks->data.U8[i] = mask->data.U8[y][x];
-        }        // Set the pixel error data, if necessary
+            pixelMasks->data.PS_TYPE_VECTOR_MASK_DATA[i] = (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal);
+        }        
+	// Set the pixel error data, if necessary
         if (errors) {
             psImage *error = errors->data[i]; // Error image of interest
@@ -128,5 +131,5 @@
     for (int iter = 0; iter < numIter; iter++) {
         // Combine all the pixels, using the specified stat.
-        if (!psVectorStats(stats, pixelData, pixelErrors, pixelMasks, maskVal)) {
+        if (!psVectorStats(stats, pixelData, pixelErrors, pixelMasks, 0xff)) {
             combine->data.F32[y][x] = NAN;
             psFree(buffer);
@@ -148,9 +151,9 @@
         float stdev = stats->sampleStdev;
         for (int i = 0; i < numImages; i++) {
-            if (!(pixelMasks->data.U8[i] & maskVal) &&
+            if (!(pixelMasks->data.PS_TYPE_VECTOR_MASK_DATA[i] & 0xff) &&
                     fabs(pixelData->data.F32[i] - combinedPixel) > sigmaClip * stdev) {
                 // Reject pixel as questionable
                 numRejects++;
-                pixelMasks->data.U8[i] = maskVal;
+                pixelMasks->data.PS_TYPE_IMAGE_MASK_DATA[i] = 0xff;
                 if (questionablePixels) {
                     // Mark the pixel as questionable
@@ -191,5 +194,5 @@
     const psArray *errors,              ///< Array of input error images
     const psArray *masks,               ///< Array of input masks
-    psU32 maskVal,                      ///< Mask value
+    psImageMaskType maskVal,                      ///< Mask value
     const psPixels *pixels,             ///< Pixels to combine
     psS32 numIter,                      ///< Number of rejection iterations
@@ -231,5 +234,5 @@
             psImage *mask  = masks->data[i];
             PS_ASSERT_IMAGE_SIZE(mask, numCols, numRows, NULL);
-            PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, NULL);
+            PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, NULL);
         }
     }
@@ -319,5 +322,5 @@
     int num = 0;
     psVector *pixels = psVectorAlloc(8, PS_TYPE_F32); // Array of pixels
-    psVector *mask = psVectorAlloc(8, PS_TYPE_U8); // Corresponding mask
+    psVector *mask = psVectorAlloc(8, PS_TYPE_VECTOR_MASK); // Corresponding mask
 
     // Get limits
@@ -329,10 +332,10 @@
         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])) {
+                if ((i != x) && (j != y) && (0 == imageMask->data.PS_TYPE_IMAGE_MASK_DATA[j][i])) {
                     pixels->data.F32[num] = image->data.F32[j][i];
-                    mask->data.U8[num] = 0;
+                    mask->data.PS_TYPE_VECTOR_MASK_DATA[num] = 0;
                     num++;
                 } else {
-                    mask->data.U8[num] = 1;
+                    mask->data.PS_TYPE_VECTOR_MASK_DATA[num] = 1;
                 }
             }
@@ -347,8 +350,8 @@
                 if ((i != x) && (j != y)) {
                     pixels->data.F32[num] = image->data.F32[j][i];
-                    mask->data.U8[num] = 0;
+                    mask->data.PS_TYPE_VECTOR_MASK_DATA[num] = 0;
                     num++;
                 } else {
-                    mask->data.U8[num] = 1;
+                    mask->data.PS_TYPE_VECTOR_MASK_DATA[num] = 1;
                 }
             }
@@ -473,5 +476,5 @@
     for (psS32 i = 0 ; i < image->numRows ; i++) {
         for (psS32 j = 0 ; j < image->numCols ; j++) {
-            imgF32->data.F32[i][j] = (psF32) image->data.U8[i][j];
+            imgF32->data.F32[i][j] = (psF32) image->data.PS_TYPE_IMAGE_MASK_DATA[i][j];
         }
     }
@@ -518,5 +521,5 @@
             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_IMAGE_TYPE(tmpMask, PS_TYPE_F32, NULL); // XXX really F32??
             PS_ASSERT_IMAGES_SIZE_EQUAL(tmpImage, tmpMask, NULL);
         }
@@ -571,5 +574,5 @@
 
         //
-        // Create a psU8 mask image from the list of cosmic pixels.
+        // Create a psImageMaskType mask image from the list of cosmic pixels.
         //
         psImage *maskImage = NULL;
