Index: trunk/psLib/src/imageops/psImageBackground.c
===================================================================
--- trunk/psLib/src/imageops/psImageBackground.c	(revision 21172)
+++ trunk/psLib/src/imageops/psImageBackground.c	(revision 21183)
@@ -18,10 +18,10 @@
 // XXX allow the user to choose the stats method?
 // (SAMPLE_MEAN, CLIPPED_MEAN, ROBUST_MEDIAN, FITTED_MEAN)
-bool psImageBackground(psStats *stats, psVector **sample, const psImage *image, const psImage *mask, psMaskType maskValue, psRandom *rng)
+bool psImageBackground(psStats *stats, psVector **sample, const psImage *image, const psImage *mask, psImageMaskType maskValue, psRandom *rng)
 {
     PS_ASSERT_IMAGE_NON_NULL(image, NULL);
     if (mask) {
         PS_ASSERT_IMAGE_NON_NULL(mask, NULL);
-        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_U8, NULL);
+        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, NULL);
         PS_ASSERT_IMAGES_SIZE_EQUAL(mask, image, NULL);
     }
@@ -63,5 +63,5 @@
         int iy = pixel / nx;
 
-        if (!isfinite(image->data.F32[iy][ix]) || (mask && mask->data.U8[iy][ix] & maskValue)) {
+        if (!isfinite(image->data.F32[iy][ix]) || (mask && mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskValue)) {
             continue;
         }
Index: trunk/psLib/src/imageops/psImageBackground.h
===================================================================
--- trunk/psLib/src/imageops/psImageBackground.h	(revision 21172)
+++ trunk/psLib/src/imageops/psImageBackground.h	(revision 21183)
@@ -5,6 +5,6 @@
  *  @author EAM, IfA
  *
- *  $Revision: 1.6 $ $Name: not supported by cvs2svn $
- *  $Date: 2008-01-17 22:07:33 $
+ *  $Revision: 1.7 $ $Name: not supported by cvs2svn $
+ *  $Date: 2009-01-27 06:39:37 $
  *  Copyright 2004-2005 IfA, University of Hawaii
  */
@@ -27,5 +27,5 @@
                        const psImage *image, // Image for which to get the background
                        const psImage *mask, // Mask image
-                       psMaskType maskValue, // Mask pixels which this mask value
+                       psImageMaskType maskValue, // Mask pixels which this mask value
                        psRandom *rng // Random number generator (for pixel selection)
                       );
Index: trunk/psLib/src/imageops/psImageConvolve.c
===================================================================
--- trunk/psLib/src/imageops/psImageConvolve.c	(revision 21172)
+++ trunk/psLib/src/imageops/psImageConvolve.c	(revision 21183)
@@ -7,6 +7,6 @@
 /// @author Eugene Magnier, IfA
 ///
-/// @version $Revision: 1.81 $ $Name: not supported by cvs2svn $
-/// @date $Date: 2008-11-26 00:43:12 $
+/// @version $Revision: 1.82 $ $Name: not supported by cvs2svn $
+/// @date $Date: 2009-01-27 06:39:37 $
 ///
 /// Copyright 2004-2007 Institute for Astronomy, University of Hawaii
@@ -319,9 +319,9 @@
 }
 
-psImage *psImageConvolveMaskDirect(psImage *out, const psImage *mask, psMaskType maskVal,
-                                   psMaskType setVal, int xMin, int xMax, int yMin, int yMax)
+psImage *psImageConvolveMaskDirect(psImage *out, const psImage *mask, psImageMaskType maskVal,
+                                   psImageMaskType setVal, int xMin, int xMax, int yMin, int yMax)
 {
     PS_ASSERT_IMAGE_NON_NULL(mask, NULL);
-    PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, NULL);
+    PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, NULL);
     if (out == mask && ((maskVal & setVal) || !setVal)) {
         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
@@ -352,10 +352,10 @@
     if (!out) {
         // Propagate the non-masked values
-        out = (psImage*)psBinaryOp(NULL, (const psPtr)mask, "&", psScalarAlloc(~maskVal, PS_TYPE_MASK));
+        out = (psImage*)psBinaryOp(NULL, (const psPtr)mask, "&", psScalarAlloc(~maskVal, PS_TYPE_IMAGE_MASK));
     }
 
     // Dereference mask images
-    psMaskType **maskData = mask->data.PS_TYPE_MASK_DATA;
-    psMaskType **outData = out->data.PS_TYPE_MASK_DATA;
+    psImageMaskType **maskData = mask->data.PS_TYPE_IMAGE_MASK_DATA;
+    psImageMaskType **outData = out->data.PS_TYPE_IMAGE_MASK_DATA;
 
     if (setVal) {
@@ -376,5 +376,5 @@
         for (int row = 0; row < numRows; row++) {
             for (int col = 0; col < numCols; col++) {
-                psMaskType pixel = outData[row][col]; // Pixel value to set
+                psImageMaskType pixel = outData[row][col]; // Pixel value to set
                 if (pixel & maskVal) {
                     // Already done this one
@@ -395,9 +395,9 @@
 
 
-psImage *psImageConvolveMaskFFT(psImage *out, const psImage *mask, psMaskType maskVal,
-                                psMaskType setVal, int xMin, int xMax, int yMin, int yMax, float thresh)
+psImage *psImageConvolveMaskFFT(psImage *out, const psImage *mask, psImageMaskType maskVal,
+                                psImageMaskType setVal, int xMin, int xMax, int yMin, int yMax, float thresh)
 {
     PS_ASSERT_IMAGE_NON_NULL(mask, NULL);
-    PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, NULL);
+    PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, NULL);
     PS_ASSERT_FLOAT_LARGER_THAN(thresh, 0.0, NULL);
     PS_ASSERT_FLOAT_LESS_THAN(thresh, 1.0, NULL);
@@ -431,5 +431,5 @@
     for (int y = 0; y < numRows; y++) {
         for (int x = 0; x < numCols; x++) {
-            if (mask->data.PS_TYPE_MASK_DATA[y][x] & maskVal) {
+            if (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskVal) {
                 onoff->data.F32[y][x] = 1.0;
             }
@@ -452,10 +452,10 @@
 
     if (!out) {
-        out = psImageAlloc(numCols, numRows, PS_TYPE_MASK);
+        out = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK);
     }
     for (int y = 0; y < numRows; y++) {
         for (int x = 0; x < numCols; x++) {
-            out->data.PS_TYPE_MASK_DATA[y][x] = (convolved->data.F32[y][x] >= thresh) ?
-                (mask->data.PS_TYPE_MASK_DATA[y][x] | setVal) : mask->data.PS_TYPE_MASK_DATA[y][x];
+            out->data.PS_TYPE_IMAGE_MASK_DATA[y][x] = (convolved->data.F32[y][x] >= thresh) ?
+                (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] | setVal) : mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x];
         }
     }
@@ -651,5 +651,5 @@
 case PS_TYPE_##TYPE: { \
     psImage *calculation = psImageAlloc(numRows, numCols, PS_TYPE_##TYPE); /* Calculation image; BW */ \
-    psImage *calcMask = psImageAlloc(numRows, numCols, PS_TYPE_MASK); /* Mask for calculation image; BW */ \
+    psImage *calcMask = psImageAlloc(numRows, numCols, PS_TYPE_IMAGE_MASK); /* Mask for calculation image; BW */ \
     \
     /** Smooth in X direction **/ \
@@ -658,5 +658,5 @@
             int xMin = PS_MAX(i - size, 0); \
             int xMax = PS_MIN(i + size, xLast); \
-            const psMaskType *maskData = &mask->data.PS_TYPE_MASK_DATA[j][xMin]; \
+            const psImageMaskType *maskData = &mask->data.PS_TYPE_IMAGE_MASK_DATA[j][xMin]; \
             const ps##TYPE *imageData = &image->data.TYPE[j][xMin]; \
             int uMin = - PS_MIN(i, size); /* Minimum kernel index */ \
@@ -673,8 +673,8 @@
                 /* BW */ \
                 calculation->data.TYPE[i][j] = sumIG / sumG; \
-                calcMask->data.PS_TYPE_MASK_DATA[i][j] = 0; \
+                calcMask->data.PS_TYPE_IMAGE_MASK_DATA[i][j] = 0; \
             } else { \
                 /* BW */ \
-                calcMask->data.PS_TYPE_MASK_DATA[i][j] = 0xFF; \
+                calcMask->data.PS_TYPE_IMAGE_MASK_DATA[i][j] = 0xFF; \
             } \
         } \
@@ -688,5 +688,5 @@
             int yMin = PS_MAX(j - size, 0); \
             int yMax = PS_MIN(j + size, yLast); \
-            const psMaskType *maskData = &calcMask->data.PS_TYPE_MASK_DATA[i][yMin]; /* BW */ \
+            const psImageMaskType *maskData = &calcMask->data.PS_TYPE_IMAGE_MASK_DATA[i][yMin]; /* BW */ \
             const ps##TYPE *imageData = &calculation->data.TYPE[i][yMin]; /* BW */ \
             int vMin = - PS_MIN(j, size); /* Minimum kernel index */ \
@@ -714,5 +714,5 @@
                            const psImage *image,
                            const psImage *mask,
-                           psMaskType maskVal,
+                           psImageMaskType maskVal,
                            float sigma,
                            float numSigma,
@@ -721,5 +721,5 @@
     PS_ASSERT_IMAGE_NON_NULL(image, NULL);
     PS_ASSERT_IMAGE_NON_NULL(mask, NULL);
-    PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, NULL);
+    PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, NULL);
     PS_ASSERT_IMAGES_SIZE_EQUAL(image, mask, NULL);
 
@@ -751,5 +751,5 @@
       case PS_TYPE_F32: {
           psImage *calculation = psImageAlloc(numRows, numCols, PS_TYPE_F32); /* Calculation image; BW */
-          psImage *calcMask = psImageAlloc(numRows, numCols, PS_TYPE_MASK); /* Mask for calculation image; BW */
+          psImage *calcMask = psImageAlloc(numRows, numCols, PS_TYPE_IMAGE_MASK); /* Mask for calculation image; BW */
 
           /** Smooth in X direction **/
@@ -758,5 +758,5 @@
                   int xMin = PS_MAX(i - size, 0);
                   int xMax = PS_MIN(i + size, xLast);
-                  const psMaskType *maskData = &mask->data.PS_TYPE_MASK_DATA[j][xMin];
+                  const psImageMaskType *maskData = &mask->data.PS_TYPE_IMAGE_MASK_DATA[j][xMin];
                   const psF32 *imageData = &image->data.F32[j][xMin];
                   int uMin = - PS_MIN(i, size); /* Minimum kernel index */
@@ -776,8 +776,8 @@
                       /* BW */
                       calculation->data.F32[i][j] = sumIG / sumG;
-                      calcMask->data.PS_TYPE_MASK_DATA[i][j] = 0;
+                      calcMask->data.PS_TYPE_IMAGE_MASK_DATA[i][j] = 0;
                   } else {
                       /* BW */
-                      calcMask->data.PS_TYPE_MASK_DATA[i][j] = 0xFF;
+                      calcMask->data.PS_TYPE_IMAGE_MASK_DATA[i][j] = 0xFF;
                   }
               }
@@ -791,5 +791,5 @@
                   int yMin = PS_MAX(j - size, 0);
                   int yMax = PS_MIN(j + size, yLast);
-                  const psMaskType *maskData = &calcMask->data.PS_TYPE_MASK_DATA[i][yMin]; /* BW */
+                  const psImageMaskType *maskData = &calcMask->data.PS_TYPE_IMAGE_MASK_DATA[i][yMin]; /* BW */
                   const psF32 *imageData = &calculation->data.F32[i][yMin]; /* BW */
                   int vMin = - PS_MIN(j, size); /* Minimum kernel index */
@@ -832,5 +832,5 @@
                                      const psImage *image,
                                      const psImage *mask,
-                                     psMaskType maskVal,
+                                     psImageMaskType maskVal,
                                      psVector *gaussNorm,
                                      float minGauss,
@@ -848,5 +848,5 @@
             int xMin = PS_MAX(i - size, 0);
             int xMax = PS_MIN(i + size, xLast);
-            const psMaskType *maskData = &mask->data.PS_TYPE_MASK_DATA[j][xMin];
+            const psImageMaskType *maskData = &mask->data.PS_TYPE_IMAGE_MASK_DATA[j][xMin];
             const psF32 *imageData = &image->data.F32[j][xMin];
             int uMin = - PS_MIN(i, size); /* Minimum kernel index */
@@ -863,8 +863,8 @@
                 /* BW */
                 calculation->data.F32[i][j] = sumIG / sumG;
-                calcMask->data.PS_TYPE_MASK_DATA[i][j] = 0;
+                calcMask->data.PS_TYPE_IMAGE_MASK_DATA[i][j] = 0;
             } else {
                 /* BW */
-                calcMask->data.PS_TYPE_MASK_DATA[i][j] = 0xFF;
+                calcMask->data.PS_TYPE_IMAGE_MASK_DATA[i][j] = 0xFF;
             }
         }
@@ -876,5 +876,5 @@
                                      psImage *calculation,
                                      psImage *calcMask,
-                                     psMaskType maskVal,
+                                     psImageMaskType maskVal,
                                      psVector *gaussNorm,
                                      float minGauss,
@@ -892,5 +892,5 @@
             int yMin = PS_MAX(j - size, 0);
             int yMax = PS_MIN(j + size, yLast);
-            const psMaskType *maskData = &calcMask->data.PS_TYPE_MASK_DATA[i][yMin]; /* BW */
+            const psImageMaskType *maskData = &calcMask->data.PS_TYPE_IMAGE_MASK_DATA[i][yMin]; /* BW */
             const psF32 *imageData = &calculation->data.F32[i][yMin]; /* BW */
             int vMin = - PS_MIN(j, size); /* Minimum kernel index */
@@ -921,5 +921,5 @@
     const psImage *mask   = job->args->data[3]; // input mask
 
-    psMaskType maskVal    = PS_SCALAR_VALUE(job->args->data[4],U8);
+    psImageMaskType maskVal    = PS_SCALAR_VALUE(job->args->data[4],PS_TYPE_IMAGE_MASK_DATA);
     psVector *gaussNorm   = job->args->data[5]; // gauss kernel
     float minGauss        = PS_SCALAR_VALUE(job->args->data[6],F32);
@@ -941,5 +941,5 @@
     psImage *calculation  = job->args->data[1]; // calculation image
     psImage *calcMask     = job->args->data[2]; // calculation mask
-    psMaskType maskVal    = PS_SCALAR_VALUE(job->args->data[3],U8);
+    psImageMaskType maskVal    = PS_SCALAR_VALUE(job->args->data[3],PS_TYPE_IMAGE_MASK_DATA);
 
     psVector *gaussNorm   = job->args->data[4]; // gauss kernel
@@ -956,5 +956,5 @@
                                     const psImage *image,
                                     const psImage *mask,
-                                    psMaskType maskVal,
+                                    psImageMaskType maskVal,
                                     float sigma,
                                     float numSigma,
@@ -963,5 +963,5 @@
     PS_ASSERT_IMAGE_NON_NULL(image, NULL);
     PS_ASSERT_IMAGE_NON_NULL(mask, NULL);
-    PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, NULL);
+    PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, NULL);
     PS_ASSERT_IMAGES_SIZE_EQUAL(image, mask, NULL);
 
@@ -999,5 +999,5 @@
       case PS_TYPE_F32: {
           psImage *calculation = psImageAlloc(numRows, numCols, PS_TYPE_F32); /* Calculation image; BW */
-          psImage *calcMask = psImageAlloc(numRows, numCols, PS_TYPE_MASK); /* Mask for calculation image; BW */
+          psImage *calcMask = psImageAlloc(numRows, numCols, PS_TYPE_IMAGE_MASK); /* Mask for calculation image; BW */
 
           /** Smooth in X direction **/
@@ -1011,5 +1011,5 @@
               psArrayAdd(job->args, 1, (psImage *) image); // cast away const
               psArrayAdd(job->args, 1, (psImage *) mask); // cast away const
-              PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_U8);
+              PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
               psArrayAdd(job->args, 1, gaussNorm);
               PS_ARRAY_ADD_SCALAR(job->args, minGauss, PS_TYPE_F32);
@@ -1046,5 +1046,5 @@
               psArrayAdd(job->args, 1, calculation);
               psArrayAdd(job->args, 1, calcMask);
-              PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_U8);
+              PS_ARRAY_ADD_SCALAR(job->args, maskVal,  PS_TYPE_IMAGE_MASK);
               psArrayAdd(job->args, 1, gaussNorm);
               PS_ARRAY_ADD_SCALAR(job->args, minGauss, PS_TYPE_F32);
@@ -1091,5 +1091,5 @@
 bool psImageSmoothMaskF32 (psImage *image,
                            psImage *mask,
-                           psMaskType maskVal,
+                           psImageMaskType maskVal,
                            double  sigma,
                            double  Nsigma)
@@ -1122,5 +1122,5 @@
     psVector *calculation = psVectorAlloc(Nx, PS_TYPE_F32);
     for (int j = 0; j < Ny; j++) {
-        psU8  *vm = mask->data.U8[j];
+        psImageMaskType  *vm = mask->data.PS_TYPE_IMAGE_MASK_DATA[j];
         psF32 *vi = image->data.F32[j];
         psF32 *vo = calculation->data.F32;
@@ -1128,5 +1128,5 @@
         for (int i = 0; i < Nx; i++, vi++, vo++, vm++) {
             int offset = PS_MIN (i, Nrange);
-            psU8  *sm = vm - offset;
+            psImageMaskType  *sm = vm - offset;
             psF32 *si = vi - offset;
             psF32 *sg = gauss - offset;
@@ -1171,5 +1171,5 @@
         int yMax = PS_MIN (j + Nrange + 1, Ny);
         for (int n = yMin; n < yMax; n++) {
-            psU8  *vm = mask->data.U8[n];
+            psImageMaskType  *vm = mask->data.PS_TYPE_IMAGE_MASK_DATA[n];
             psF32 *vi = image->data.F32[n];
             psF32 *vo = output->data.F32;
@@ -1214,11 +1214,11 @@
                                      const psImage *input, // Input image
                                      int start, int stop, // Range of rows
-                                     psMaskType maskVal, // Value to mask; NOTE subtle difference!
+                                     psImageMaskType maskVal, // Value to mask; NOTE subtle difference!
                                      int xMin, int xMax // Range in x for kernel
                                      )
 {
     // Dereference mask images
-    psMaskType **inputData = input->data.PS_TYPE_MASK_DATA;
-    psMaskType **targetData = target->data.PS_TYPE_MASK_DATA;
+    psImageMaskType **inputData = input->data.PS_TYPE_IMAGE_MASK_DATA;
+    psImageMaskType **targetData = target->data.PS_TYPE_IMAGE_MASK_DATA;
 
     int numCols = input->numCols;       // Number of columns
@@ -1241,5 +1241,5 @@
                 min = PS_MAX(0, min);
                 max = PS_MIN(numCols - 1, max);
-                memset(&targetData[y][min], 0xff, (max - min + 1) * PSELEMTYPE_SIZEOF(PS_TYPE_MASK));
+                memset(&targetData[y][min], 0xff, (max - min + 1) * PSELEMTYPE_SIZEOF(PS_TYPE_IMAGE_MASK));
             }
         }
@@ -1247,5 +1247,5 @@
             // Mask from the minimum to the end of the row
             min = PS_MAX(0, min);
-            memset(&targetData[y][min], 0xff, (numCols - min) * PSELEMTYPE_SIZEOF(PS_TYPE_MASK));
+            memset(&targetData[y][min], 0xff, (numCols - min) * PSELEMTYPE_SIZEOF(PS_TYPE_IMAGE_MASK));
         }
     }
@@ -1256,11 +1256,11 @@
                                      const psImage *input, // Input image
                                      int start, int stop, // Range of rows
-                                     psMaskType setVal, // Value to set; NOTE subtle difference!
+                                     psImageMaskType setVal, // Value to set; NOTE subtle difference!
                                      int yMin, int yMax // Range in y for kernel
                                      )
 {
     // Dereference mask images
-    psMaskType **inputData = input->data.PS_TYPE_MASK_DATA;
-    psMaskType **targetData = target->data.PS_TYPE_MASK_DATA;
+    psImageMaskType **inputData = input->data.PS_TYPE_IMAGE_MASK_DATA;
+    psImageMaskType **targetData = target->data.PS_TYPE_IMAGE_MASK_DATA;
 
     int numRows = input->numRows;       // Number of rows
@@ -1308,5 +1308,5 @@
     int start = PS_SCALAR_VALUE(args->data[2], S32); // Row/col to start at
     int stop = PS_SCALAR_VALUE(args->data[3], S32); // Row/col to stop at
-    psMaskType maskVal = PS_SCALAR_VALUE(args->data[4], U8); // Value to mask/set
+    psImageMaskType maskVal = PS_SCALAR_VALUE(args->data[4], PS_TYPE_IMAGE_MASK_DATA); // Value to mask/set
     int kernelMin = PS_SCALAR_VALUE(args->data[5], S32); // Minimum range for kernel
     int kernelMax = PS_SCALAR_VALUE(args->data[6], S32); // Maximum range for kernel
@@ -1317,12 +1317,12 @@
 }
 
-psImage *psImageConvolveMask(psImage *out, const psImage *mask, psMaskType maskVal,
-                             psMaskType setVal, int xMin, int xMax, int yMin, int yMax)
+psImage *psImageConvolveMask(psImage *out, const psImage *mask, psImageMaskType maskVal,
+                             psImageMaskType setVal, int xMin, int xMax, int yMin, int yMax)
 {
     PS_ASSERT_IMAGE_NON_NULL(mask, NULL);
-    PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, NULL);
+    PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, NULL);
     if (out) {
         PS_ASSERT_IMAGE_NON_NULL(out, NULL);
-        PS_ASSERT_IMAGE_TYPE(out, PS_TYPE_MASK, NULL);
+        PS_ASSERT_IMAGE_TYPE(out, PS_TYPE_IMAGE_MASK, NULL);
         PS_ASSERT_IMAGES_SIZE_EQUAL(out, mask, NULL);
         if (out == mask && ((maskVal & setVal) || !setVal)) {
@@ -1354,5 +1354,5 @@
 
     // Propagate the non-masked values
-    out = (psImage*)psBinaryOp(out, (const psPtr)mask, "&", psScalarAlloc(~setVal, PS_TYPE_MASK));
+    out = (psImage*)psBinaryOp(out, (const psPtr)mask, "&", psScalarAlloc(~setVal, PS_TYPE_IMAGE_MASK));
 
     if (!setVal) {
@@ -1360,5 +1360,5 @@
     }
 
-    psImage *conv = psImageAlloc(numCols, numRows, PS_TYPE_MASK); // Temporary convolved image
+    psImage *conv = psImageAlloc(numCols, numRows, PS_TYPE_IMAGE_MASK); // Temporary convolved image
     psImageInit(conv, 0);
 
@@ -1377,5 +1377,5 @@
             PS_ARRAY_ADD_SCALAR(job->args, start, PS_TYPE_S32);
             PS_ARRAY_ADD_SCALAR(job->args, stop, PS_TYPE_S32);
-            PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_MASK);
+            PS_ARRAY_ADD_SCALAR(job->args, maskVal, PS_TYPE_IMAGE_MASK);
             PS_ARRAY_ADD_SCALAR(job->args, xMin, PS_TYPE_S32);
             PS_ARRAY_ADD_SCALAR(job->args, xMax, PS_TYPE_S32);
@@ -1415,5 +1415,5 @@
             PS_ARRAY_ADD_SCALAR(job->args, start, PS_TYPE_S32);
             PS_ARRAY_ADD_SCALAR(job->args, stop, PS_TYPE_S32);
-            PS_ARRAY_ADD_SCALAR(job->args, setVal, PS_TYPE_MASK);
+            PS_ARRAY_ADD_SCALAR(job->args, setVal, PS_TYPE_IMAGE_MASK);
             PS_ARRAY_ADD_SCALAR(job->args, yMin, PS_TYPE_S32);
             PS_ARRAY_ADD_SCALAR(job->args, yMax, PS_TYPE_S32);
@@ -1460,5 +1460,5 @@
                 min = PS_MAX(0, min);
                 max = PS_MIN(numCols - 1, max);
-                memset(&convData[y][min], 0xff, (max - min + 1) * PSELEMTYPE_SIZEOF(PS_TYPE_MASK));
+                memset(&convData[y][min], 0xff, (max - min + 1) * PSELEMTYPE_SIZEOF(PS_TYPE_IMAGE_MASK));
             }
         }
@@ -1466,5 +1466,5 @@
             // Mask from the minimum to the end of the row
             min = PS_MAX(0, min);
-            memset(&convData[y][min], 0xff, (numCols - min) * PSELEMTYPE_SIZEOF(PS_TYPE_MASK));
+            memset(&convData[y][min], 0xff, (numCols - min) * PSELEMTYPE_SIZEOF(PS_TYPE_IMAGE_MASK));
         }
     }
Index: trunk/psLib/src/imageops/psImageConvolve.h
===================================================================
--- trunk/psLib/src/imageops/psImageConvolve.h	(revision 21172)
+++ trunk/psLib/src/imageops/psImageConvolve.h	(revision 21183)
@@ -5,6 +5,6 @@
  * @author Robert DeSonia, MHPCC
  *
- * @version $Revision: 1.38 $ $Name: not supported by cvs2svn $
- * @date $Date: 2008-11-26 00:43:12 $
+ * @version $Revision: 1.39 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:37 $
  * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
  */
@@ -148,6 +148,6 @@
 psImage *psImageConvolveMask(psImage *out, ///< Output image, or NULL
                              const psImage *mask, ///< Mask to convolve
-                             psMaskType maskVal, ///< Mask value to convolve
-                             psMaskType setVal, ///< Mask value to set; 0 to propagate maskVal
+                             psImageMaskType maskVal, ///< Mask value to convolve
+                             psImageMaskType setVal, ///< Mask value to set; 0 to propagate maskVal
                              int xMin, int xMax, int yMin, int yMax ///< Convolution bounds
     );
@@ -160,6 +160,6 @@
 psImage *psImageConvolveMaskDirect(psImage *out, ///< Output image, or NULL
                                    const psImage *mask, ///< Mask to convolve
-                                   psMaskType maskVal, ///< Mask value to convolve
-                                   psMaskType setVal, ///< Mask value to set; 0 to propagate maskVal
+                                   psImageMaskType maskVal, ///< Mask value to convolve
+                                   psImageMaskType setVal, ///< Mask value to set; 0 to propagate maskVal
                                    int xMin, int xMax, int yMin, int yMax ///< Convolution bounds
     );
@@ -174,6 +174,6 @@
 psImage *psImageConvolveMaskFFT(psImage *out, ///< Output image, or NULL
                                 const psImage *mask, ///< Mask to convolve
-                                psMaskType maskVal, ///< Mask value to convolve
-                                psMaskType setVal, ///< Mask value to set; 0 to use maskVal
+                                psImageMaskType maskVal, ///< Mask value to convolve
+                                psImageMaskType setVal, ///< Mask value to set; 0 to use maskVal
                                 int xMin, int xMax, int yMin, int yMax, ///< Convolution bounds
                                 float thresh ///< Threshold (0..1) for convolved floating-point image
@@ -201,5 +201,5 @@
     const psImage *image,               ///< Input image (F32 or F64)
     const psImage *mask,                ///< Mask image
-    psMaskType maskVal,                 ///< Mask value
+    psImageMaskType maskVal,		///< Mask value
     float sigma,                        ///< Width of the smoothing kernel (pixels)
     float numSigma,                     ///< Size of the smoothing box (sigma)
@@ -211,5 +211,5 @@
                                     const psImage *image,
                                     const psImage *mask,
-                                    psMaskType maskVal,
+                                    psImageMaskType maskVal,
                                     float sigma,
                                     float numSigma,
@@ -219,5 +219,5 @@
     psImage *image,                    ///< the image to be smoothed
     psImage *mask,                     ///< optional mask
-    psMaskType maskVal,
+    psImageMaskType maskVal,		///< masked bits
     double  sigma,                     ///< the width of the smoothing kernel in pixels
     double  Nsigma                     ///< the size of the smoothing box in sigmas
Index: trunk/psLib/src/imageops/psImageGeomManip.c
===================================================================
--- trunk/psLib/src/imageops/psImageGeomManip.c	(revision 21172)
+++ trunk/psLib/src/imageops/psImageGeomManip.c	(revision 21183)
@@ -10,6 +10,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.44 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-10-21 22:10:53 $
+ *  @version $Revision: 1.45 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:37 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -39,5 +39,5 @@
                       const psImage* in,
                       const psImage* mask,
-                      psMaskType maskVal,
+                      psImageMaskType maskVal,
                       int scale,
                       const psStats* stats)
@@ -47,8 +47,8 @@
     psS32 outRows;
     psS32 outCols;
-    psVector* vec;                     // vector to hold the values of a single bin.
-    psVector* maskVec = NULL;          // vector to hold the mask of a single bin.
-    psMaskType* maskData = NULL;
-    psStats* myStats;
+    psVector *vec;                     // vector to hold the values of a single bin.
+    psVector *maskVec = NULL;          // vector to hold the mask of a single bin.
+    psVectorMaskType *maskData = NULL;
+    psStats *myStats;
 
     if (in == NULL) {
@@ -86,16 +86,16 @@
 
     if (mask != NULL) {
-        if (mask->type.type != PS_TYPE_MASK) {
+        if (mask->type.type != PS_TYPE_IMAGE_MASK) {
             char* typeStr;
             PS_TYPE_NAME(typeStr,mask->type.type);
             psError(PS_ERR_BAD_PARAMETER_TYPE, true,
                     _("Input psImage mask type, %s, is not the supported mask datatype of %s."),
-                    typeStr, PS_TYPE_MASK_NAME);
+                    typeStr, PS_TYPE_IMAGE_MASK_NAME);
             psFree(out);
             psFree(vec);
             return NULL;
         }
-        maskVec = psVectorAllocEmpty(scale * scale, PS_TYPE_MASK);
-        maskData = maskVec->data.PS_TYPE_MASK_DATA;
+        maskVec = psVectorAllocEmpty(scale * scale, PS_TYPE_VECTOR_MASK);
+        maskData = maskVec->data.PS_TYPE_VECTOR_MASK_DATA;
     }
 
@@ -114,5 +114,5 @@
         ps##TYPE *outRowData; \
         ps##TYPE *vecData = vec->data.TYPE; \
-        psMaskType *inRowMask = NULL; \
+        psImageMaskType *inRowMask = NULL; \
         for (psS32 row = 0; row < outRows; row++) { \
             outRowData = out->data.TYPE[row]; \
@@ -126,9 +126,9 @@
                     ps##TYPE* inRowData = in->data.TYPE[inRow]; \
                     if (mask != NULL) { \
-                        inRowMask = mask->data.PS_TYPE_MASK_DATA[inRow]; \
+                        inRowMask = mask->data.PS_TYPE_IMAGE_MASK_DATA[inRow]; \
                     } \
                     for (psS32 inCol = inCurrentCol; inCol < inNextCol && inCol < inCols; inCol++) { \
                         if (maskData != NULL) { \
-                            maskData[n] = inRowMask[inCol]; \
+                            maskData[n] = (inRowMask[inCol] & maskVal); \
                         } \
                         vecData[n++] = inRowData[inCol]; \
@@ -139,5 +139,5 @@
                     maskVec->n = n; \
                 } \
-                psVectorStats(myStats, vec, NULL, maskVec, maskVal); \
+                 psVectorStats(myStats, vec, NULL, maskVec, 0xff); /* the mask vector has only 0 or 1 */ \
                 outRowData[col] = (ps##TYPE)psStatsGetValue(myStats, statistic); \
             } \
@@ -659,5 +659,5 @@
 
 bool psImageShiftMask(psImage **out, psImage **outMask, const psImage* in, const psImage *inMask,
-                      psMaskType maskVal, float dx, float dy, double exposed, psMaskType blank,
+                      psImageMaskType maskVal, float dx, float dy, double exposed, psImageMaskType blank,
                       psImageInterpolateMode mode)
 {
@@ -667,5 +667,5 @@
         PS_ASSERT_IMAGE_NON_NULL(inMask, false);
         PS_ASSERT_IMAGES_SIZE_EQUAL(in, inMask, false);
-        PS_ASSERT_IMAGE_TYPE(inMask, PS_TYPE_MASK, false);
+        PS_ASSERT_IMAGE_TYPE(inMask, PS_TYPE_IMAGE_MASK, false);
     }
 
@@ -675,5 +675,5 @@
     *out = psImageRecycle(*out, numCols, numRows, type);
     if (outMask) {
-        *outMask = psImageRecycle(*outMask, numCols, numRows, PS_TYPE_MASK);
+        *outMask = psImageRecycle(*outMask, numCols, numRows, PS_TYPE_IMAGE_MASK);
     }
 
@@ -702,10 +702,10 @@
     for (int row = 0; row < numRows; row++) { \
         ps##TYPE* outRow = (*out)->data.TYPE[row]; \
-        psMaskType *outMaskRow = (outMask ? (*outMask)->data.PS_TYPE_MASK_DATA[row] : NULL); \
+        psImageMaskType *outMaskRow = (outMask ? (*outMask)->data.PS_TYPE_IMAGE_MASK_DATA[row] : NULL); \
         float y = row + 0.5 - dy; \
         for (int col = 0; col < numCols; col++) { \
             float x = col + 0.5 - dx; \
             double value; \
-            psMaskType valueMask = 0; \
+            psImageMaskType valueMask = 0; \
             if (!psImageInterpolate(&value, NULL, &valueMask, x, y, interp)) { \
                 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image."); \
@@ -750,5 +750,5 @@
                           const psImage *input,
                           const psImage *inputMask,
-                          psMaskType inputMaskVal,
+                          psImageMaskType inputMaskVal,
                           const psPlaneTransform *outToIn,
                           psRegion region,
@@ -778,10 +778,10 @@
             return NULL;
         }
-        if (inputMask->type.type != PS_TYPE_MASK) {
+        if (inputMask->type.type != PS_TYPE_IMAGE_MASK) {
             char* typeStr;
             PS_TYPE_NAME(typeStr,inputMask->type.type);
             psError(PS_ERR_BAD_PARAMETER_TYPE, true,
                     _("Input psImage mask type, %s, is not the supported mask datatype of %s."),
-                    typeStr, PS_TYPE_MASK_NAME);
+                    typeStr, PS_TYPE_IMAGE_MASK_NAME);
             psFree(output);
             return NULL;
Index: trunk/psLib/src/imageops/psImageGeomManip.h
===================================================================
--- trunk/psLib/src/imageops/psImageGeomManip.h	(revision 21172)
+++ trunk/psLib/src/imageops/psImageGeomManip.h	(revision 21183)
@@ -6,6 +6,6 @@
  * @author Robert DeSonia, MHPCC
  *
- * @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
- * @date $Date: 2008-03-11 00:41:30 $
+ * @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:37 $
  * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
  */
@@ -36,5 +36,5 @@
     const psImage* in,                 ///< input image
     const psImage* mask,               ///< mask for input image.  If NULL, no masking is done.
-    psMaskType maskVal,                ///< the bits to check in mask.
+    psImageMaskType maskVal,		///< the bits to check in mask.
     int scale,                         ///< the scale to rebin for each dimension
     const psStats* stats
@@ -106,8 +106,8 @@
     const psImage* in,                  ///< Input image
     const psImage *inMask,              ///< Input mask, or NULL
-    psMaskType maskVal,                 ///< Value to mask
+    psImageMaskType maskVal,		///< Value to mask
     float dx, float dy,                 ///< Shift to apply
     double exposed,                     ///< Value to give exposed pixels
-    psMaskType blank,                   ///< Mask value for exposed pixels
+    psImageMaskType blank,		///< Mask value for exposed pixels
     psImageInterpolateMode mode         ///< Interpolation mode
     );
@@ -159,5 +159,5 @@
     const psImage *input,              ///< psImage to apply transform to
     const psImage *inputMask,          ///< if not NULL, mask of input psImage
-    psMaskType inputMaskVal,           ///< masking value for inputMask
+    psImageMaskType inputMaskVal,	///< masking value for inputMask
     const psPlaneTransform *outToIn,   ///< the transform to apply
     psRegion region,                   ///< the size of the transformed image
Index: trunk/psLib/src/imageops/psImageInterpolate.c
===================================================================
--- trunk/psLib/src/imageops/psImageInterpolate.c	(revision 21172)
+++ trunk/psLib/src/imageops/psImageInterpolate.c	(revision 21183)
@@ -7,6 +7,6 @@
  *  @author Paul Price, IfA
  *
- *  @version $Revision: 1.30 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-11-15 03:09:34 $
+ *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:37 $
  *
  *  Copyright 2004-2007 Institute for Astronomy, University of Hawaii
@@ -205,7 +205,7 @@
 psImageInterpolation *psImageInterpolationAlloc(psImageInterpolateMode mode,
                                                 const psImage *image, const psImage *variance,
-                                                const psImage *mask, psMaskType maskVal,
+                                                const psImage *mask, psImageMaskType maskVal,
                                                 double badImage, double badVariance,
-                                                psMaskType badMask, psMaskType poorMask,
+                                                psImageMaskType badMask, psImageMaskType poorMask,
                                                 float poorFrac, int numKernels)
 {
@@ -274,5 +274,5 @@
 // Interpolation engine for flat mode (nearest pixel)
 static inline psImageInterpolateStatus interpolateFlat(double *imageValue, double *varianceValue,
-                                                       psMaskType *maskValue, float x, float y,
+                                                       psImageMaskType *maskValue, float x, float y,
                                                        const psImageInterpolation *interp)
 {
@@ -331,5 +331,5 @@
         if (maskValue) {
             if (interp->mask) {
-                *maskValue = interp->mask->data.PS_TYPE_MASK_DATA[yInt][xInt];
+                *maskValue = interp->mask->data.PS_TYPE_IMAGE_MASK_DATA[yInt][xInt];
             } else {
                 *maskValue = 0;
@@ -456,5 +456,5 @@
 // Interpolation engine for separable interpolation kernels
 static psImageInterpolateStatus interpolateSeparable(double *imageValue, double *varianceValue,
-                                                     psMaskType *maskValue, float x, float y,
+                                                     psImageMaskType *maskValue, float x, float y,
                                                      const psImageInterpolation *interp)
 {
@@ -465,5 +465,5 @@
     const psImage *mask = interp->mask; // Image mask
     const psImage *variance = interp->variance; // Image variance
-    psMaskType maskVal = interp->maskVal; // Value to mask
+    psImageMaskType maskVal = interp->maskVal; // Value to mask
     bool wantVariance = variance && varianceValue; // Does the user want the variance value?
     bool haveMask = mask && maskVal; // Does the user want the variance value?
@@ -582,5 +582,5 @@
                   const ps##TYPE *imageData = &image->data.TYPE[yPix][xMin]; \
                   const ps##TYPE *varianceData = &variance->data.TYPE[yPix][xMin]; \
-                  const psMaskType *maskData = &mask->data.PS_TYPE_MASK_DATA[yPix][xMin]; \
+                  const psImageMaskType *maskData = &mask->data.PS_TYPE_IMAGE_MASK_DATA[yPix][xMin]; \
                   const psF32 *xKernelData = xKernel; \
                   const psF32 *xKernel2Data = xKernel2; \
@@ -642,5 +642,5 @@
               /* Dereferenced versions of inputs */ \
               const ps##TYPE *imageData = &image->data.TYPE[yPix][xMin]; \
-              const psMaskType *maskData = &mask->data.PS_TYPE_MASK_DATA[yPix][xMin]; \
+              const psImageMaskType *maskData = &mask->data.PS_TYPE_IMAGE_MASK_DATA[yPix][xMin]; \
               const psF32 *xKernelData = xKernel; \
               const psF32 *xKernel2Data = xKernel2; \
@@ -713,5 +713,5 @@
 // Interpolation engine for (separable) interpolation kernels
 static psImageInterpolateStatus interpolateKernel(double *imageValue, double *varianceValue,
-                                                  psMaskType *maskValue, float x, float y,
+                                                  psImageMaskType *maskValue, float x, float y,
                                                   const psImageInterpolation *interp)
 {
@@ -722,5 +722,5 @@
     const psImage *mask = interp->mask; // Image mask
     const psImage *variance = interp->variance; // Image variance
-    psMaskType maskVal = interp->maskVal; // Value to mask
+    psImageMaskType maskVal = interp->maskVal; // Value to mask
     bool wantVariance = variance && varianceValue; // Does the user want the variance value?
     bool haveMask = mask && maskVal; // Does the user want the variance value?
@@ -790,5 +790,5 @@
                       float kernelValue = kernel[j][i]; /* Value of kernel */ \
                       float kernelValue2 = PS_SQR(kernelValue); /* Square of kernel */ \
-                      if (mask->data.PS_TYPE_MASK_DATA[yPix][xPix] & maskVal) { \
+                      if (mask->data.PS_TYPE_IMAGE_MASK_DATA[yPix][xPix] & maskVal) { \
                           sumBad += kernelValue2; \
                       } else { \
@@ -820,5 +820,5 @@
                   float kernelValue = kernel[j][i]; /* Value of kernel */ \
                   float kernelValue2 = PS_SQR(kernelValue); /* Square of kernel */ \
-                  if (mask->data.PS_TYPE_MASK_DATA[yPix][xPix] & maskVal) { \
+                  if (mask->data.PS_TYPE_IMAGE_MASK_DATA[yPix][xPix] & maskVal) { \
                       sumBad += kernelValue2; \
                   } else { \
@@ -866,5 +866,5 @@
 
 
-psImageInterpolateStatus psImageInterpolate(double *imageValue, double *varianceValue, psMaskType *maskValue,
+psImageInterpolateStatus psImageInterpolate(double *imageValue, double *varianceValue, psImageMaskType *maskValue,
                                             float x, float y, const psImageInterpolation *interp)
 {
@@ -885,5 +885,5 @@
     if (maskValue && mask) {
         PS_ASSERT_IMAGE_NON_NULL(mask, PS_INTERPOLATE_STATUS_ERROR);
-        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_MASK, PS_INTERPOLATE_STATUS_ERROR);
+        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, PS_INTERPOLATE_STATUS_ERROR);
         psAssert(image->numCols == mask->numCols && image->numRows == mask->numRows, "Image and mask sizes");
     }
Index: trunk/psLib/src/imageops/psImageInterpolate.h
===================================================================
--- trunk/psLib/src/imageops/psImageInterpolate.h	(revision 21172)
+++ trunk/psLib/src/imageops/psImageInterpolate.h	(revision 21183)
@@ -7,6 +7,6 @@
  * @author Paul Price, Institute for Astronomy
  *
- * @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
- * @date $Date: 2008-10-22 19:21:06 $
+ * @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:37 $
  * Copyright 2004-2007 Institute for Astronomy, University of Hawaii
  */
@@ -50,9 +50,9 @@
     const psImage *variance;            ///< Variance image for interpolation
     const psImage *mask;                ///< Mask image for interpolation
-    psMaskType maskVal;                 ///< Value to mask
+    psImageMaskType maskVal;		///< Value to mask
     double badImage;                    ///< Image value if x,y location is not good
     double badVariance;                 ///< Variance value if x,y location is not good
-    psMaskType badMask;                 ///< Mask value to give bad pixels
-    psMaskType poorMask;                ///< Mask value to give poor pixels
+    psImageMaskType badMask;		///< Mask value to give bad pixels
+    psImageMaskType poorMask;		///< Mask value to give poor pixels
     float poorFrac;                     ///< Fraction of flux in bad pixels before output is marked bad
     bool shifting;                      ///< Shifting images? Don't interpolate if the shift is exact.
@@ -69,9 +69,9 @@
     const psImage *variance,            // Variance image
     const psImage *mask,                // Mask image
-    psMaskType maskVal,                 // Value to mask
+    psImageMaskType maskVal,                 // Value to mask
     double badImage,                    // Value for image if bad
     double badVariance,                 // Value for variance if bad
-    psMaskType badMask,                 // Mask value for bad pixels
-    psMaskType poorMask,                // Mask value for poor pixels
+    psImageMaskType badMask,                 // Mask value for bad pixels
+    psImageMaskType poorMask,                // Mask value for poor pixels
     float poorFrac,                     // Fraction of flux for question
     int numKernels                      // Number of interpolation kernels to pre-calculate
@@ -83,5 +83,5 @@
     double *imageValue,                 ///< Return value for image
     double *varianceValue,              ///< Return value for variance
-    psMaskType *maskValue,              ///< Return value for mask
+    psImageMaskType *maskValue,              ///< Return value for mask
     float x, float y,                   ///< Location to which to interpolate
     const psImageInterpolation *options ///< Options
Index: trunk/psLib/src/imageops/psImageMap.c
===================================================================
--- trunk/psLib/src/imageops/psImageMap.c	(revision 21172)
+++ trunk/psLib/src/imageops/psImageMap.c	(revision 21183)
@@ -7,6 +7,6 @@
  *  @author Eugene Magnier, IfA
  *
- *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-01-27 00:00:21 $
+ *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:37 $
  *
  *  Copyright 2007 Institute for Astronomy, University of Hawaii
@@ -145,5 +145,5 @@
     }
 
-    psImage *mask = psImageAlloc (map->map->numCols, map->map->numRows, PS_TYPE_MASK);
+    psImage *mask = psImageAlloc (map->map->numCols, map->map->numRows, PS_TYPE_IMAGE_MASK);
     psImage *xCoord = psImageAlloc (map->map->numCols, map->map->numRows, PS_TYPE_F32);
     psImage *yCoord = psImageAlloc (map->map->numCols, map->map->numRows, PS_TYPE_F32);
@@ -212,5 +212,5 @@
             // this will not in general be properly weighted...
             if (psVectorStats (map->stats, fCell, dfCell, NULL, 0)) {
-                mask->data.U8[iy][ix] = 0;
+                mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] = 0;
                 // XXX ensure only one option is selected, or save both position and width
                 map->map->data.F32[iy][ix] = psStatsGetValue (map->stats, map->stats->options);
@@ -224,5 +224,5 @@
                 yCoord->data.F32[iy][ix] = psStatsGetValue (meanStat, meanStat->options);
             } else {
-                mask->data.U8[iy][ix] = 1;
+                mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] = 1;
             }
 
@@ -353,5 +353,5 @@
 }
 
-psVector *psImageMapEvalVector(const psImageMap *map, const psVector *mask, psMaskType maskValue, const psVector *x, const psVector *y)
+psVector *psImageMapEvalVector(const psImageMap *map, const psVector *mask, psVectorMaskType maskValue, const psVector *x, const psVector *y)
 {
     PS_ASSERT_IMAGE_MAP_NON_NULL(map, NULL);
@@ -365,5 +365,5 @@
 
     for (int i = 0; i < x->n; i++) {
-      if (mask && (mask->data.U8[i] & maskValue)) {
+      if (mask && (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskValue)) {
 	result->data.F32[i] = 0.0;
       } else {	
Index: trunk/psLib/src/imageops/psImageMapFit.c
===================================================================
--- trunk/psLib/src/imageops/psImageMapFit.c	(revision 21172)
+++ trunk/psLib/src/imageops/psImageMapFit.c	(revision 21183)
@@ -7,6 +7,6 @@
  *  @author Eugene Magnier, IfA
  *
- *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2009-01-27 00:00:21 $
+ *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:37 $
  *
  *  Copyright 2007 Institute for Astronomy, University of Hawaii
@@ -47,5 +47,5 @@
 
 // map defines the output image dimensions and scaling.
-bool psImageMapFit(psImageMap *map, const psVector *mask, psMaskType maskValue,
+bool psImageMapFit(psImageMap *map, const psVector *mask, psVectorMaskType maskValue,
                    const psVector *x, const psVector *y, const psVector *f, const psVector *df)
 {
@@ -145,5 +145,5 @@
             for (int i = 0; i < x->n; i++) {
 
-                if (mask && (mask->data.U8[i] & maskValue)) continue;
+                if (mask && (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskValue)) continue;
 
                 // base coordinate offset for this point (x,y) relative to this map element (n,m)
@@ -338,5 +338,5 @@
 
 // measure residuals on each pass and clip outliers based on stats
-bool psImageMapClipFit(psImageMap *map, psStats *stats, psVector *inMask, psMaskType maskValue,
+bool psImageMapClipFit(psImageMap *map, psStats *stats, psVector *inMask, psVectorMaskType maskValue,
                        const psVector *x, const psVector *y, const psVector *f, const psVector *df)
 {
@@ -377,5 +377,5 @@
     psVector *mask = inMask;
     if (!inMask) {
-        mask = psVectorAlloc (x->n, PS_TYPE_U8);
+        mask = psVectorAlloc (x->n, PS_TYPE_VECTOR_MASK);
         psVectorInit (mask, 0);
     }
@@ -429,5 +429,5 @@
         for (psS32 i = 0; i < resid->n; i++) {
             // XXX this prevents recovery of previously masked values
-            if (mask->data.U8[i] & maskValue) {
+            if (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskValue) {
                 continue;
             }
@@ -435,5 +435,5 @@
             if ((resid->data.F32[i] - meanValue > maxClipValue) || (resid->data.F32[i] - meanValue < minClipValue)) {
                 psTrace("psLib.imageops", 6, "Masking element %d  : %f vs %f : resid is %f\n", i, f->data.F32[i], fit->data.F32[i], resid->data.F32[i]);
-                mask->data.U8[i] |= 0x01;
+                mask->data.PS_TYPE_VECTOR_MASK_DATA[i] |= 0x01;
                 continue;
             }
@@ -455,5 +455,5 @@
 
 // map defines the output image dimensions and scaling.
-bool psImageMapFit1DinY(psImageMap *map, const psVector *mask, psMaskType maskValue,
+bool psImageMapFit1DinY(psImageMap *map, const psVector *mask, psVectorMaskType maskValue,
                         const psVector *x, const psVector *y, const psVector *f, const psVector *df)
 {
@@ -490,5 +490,5 @@
         for (int i = 0; i < y->n; i++) {
 
-            if (mask && (mask->data.U8[i] & maskValue)) continue;
+            if (mask && (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskValue)) continue;
 
             float dy = psImageBinningGetRuffY (map->binning, y->data.F32[i]) - (m + 0.5);
@@ -603,5 +603,5 @@
 
 // map defines the output image dimensions and scaling.
-bool psImageMapFit1DinX(psImageMap *map, const psVector *mask, psMaskType maskValue,
+bool psImageMapFit1DinX(psImageMap *map, const psVector *mask, psVectorMaskType maskValue,
                         const psVector *x, const psVector *y, const psVector *f, const psVector *df)
 {
@@ -638,5 +638,5 @@
         for (int i = 0; i < x->n; i++) {
 
-            if (mask && (mask->data.U8[i] & maskValue)) continue;
+            if (mask && (mask->data.PS_TYPE_VECTOR_MASK_DATA[i] & maskValue)) continue;
 
             float dx = psImageBinningGetRuffX (map->binning, x->data.F32[i]) - (m + 0.5);
Index: trunk/psLib/src/imageops/psImageMapFit.h
===================================================================
--- trunk/psLib/src/imageops/psImageMapFit.h	(revision 21172)
+++ trunk/psLib/src/imageops/psImageMapFit.h	(revision 21183)
@@ -10,5 +10,5 @@
 bool psImageMapFit(psImageMap *map,
                    const psVector *mask,
-                   psMaskType maskValue,
+                   psVectorMaskType maskValue, // 
                    const psVector *x,
                    const psVector *y,
@@ -21,5 +21,5 @@
                        psStats *stats,
                        psVector *mask,  // WARNING: Mask is modified!
-                       psMaskType maskValue,
+                       psVectorMaskType maskValue,
                        const psVector *x,
                        const psVector *y,
@@ -30,5 +30,5 @@
 bool psImageMapFit1DinY(psImageMap *map,
                         const psVector *mask,
-                        psMaskType maskValue,
+                        psVectorMaskType maskValue,
                         const psVector *x,
                         const psVector *y,
@@ -39,5 +39,5 @@
 bool psImageMapFit1DinX(psImageMap *map,
                         const psVector *mask,
-                        psMaskType maskValue,
+                        psVectorMaskType maskValue,
                         const psVector *x,
                         const psVector *y,
Index: trunk/psLib/src/imageops/psImageMaskOps.c
===================================================================
--- trunk/psLib/src/imageops/psImageMaskOps.c	(revision 21172)
+++ trunk/psLib/src/imageops/psImageMaskOps.c	(revision 21183)
@@ -8,6 +8,6 @@
  *  @author David Robbins, MHPCC
  *
- *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-07-12 21:08:33 $
+ *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:37 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -37,5 +37,5 @@
                        psRegion region,
                        const char *op,
-                       psMaskType maskValue)
+                       psImageMaskType maskValue)
 {
     if (image == NULL) {
@@ -53,5 +53,5 @@
 	  if ((i + image->col0) < region.x0) continue; \
 	  if ((i + image->col0) > region.x1) continue; /* is this correct (not >= ?) */ \
-	  image->data.PS_TYPE_MASK_DATA[j][i] OP maskValue; \
+	  image->data.PS_TYPE_IMAGE_MASK_DATA[j][i] OP maskValue; \
 	} \
       }
@@ -84,5 +84,5 @@
                        psRegion region,
                        const char *op,
-                       psMaskType maskValue)
+                       psImageMaskType maskValue)
 {
     if (image == NULL) {
@@ -100,5 +100,5 @@
 	    (i + image->col0) < region.x0 || \
 	    (i + image->col0) > region.x1 ) { \
-	  image->data.PS_TYPE_MASK_DATA[j][i] OP maskValue; \
+	  image->data.PS_TYPE_IMAGE_MASK_DATA[j][i] OP maskValue; \
 	} } }
 
@@ -131,5 +131,5 @@
                        double radius,
                        const char *op,
-                       psMaskType maskValue)
+                       psImageMaskType maskValue)
 {
     if (image == NULL) {
@@ -150,5 +150,5 @@
             r2 = PS_SQR(dx) + PS_SQR(dy); \
             if (r2 <= R2) { \
-	      image->data.PS_TYPE_MASK_DATA[iy][ix] OP maskValue; \
+	      image->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] OP maskValue; \
             } } }
 
@@ -182,5 +182,5 @@
                        double radius,
                        const char *op,
-                       psMaskType maskValue)
+                       psImageMaskType maskValue)
 {
 
@@ -201,5 +201,5 @@
             r2 = PS_SQR(dx) + PS_SQR(dy); \
             if (r2 > R2) { \
-	      image->data.PS_TYPE_MASK_DATA[iy][ix] OP maskValue; \
+	      image->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] OP maskValue; \
             } } }
 
@@ -228,7 +228,7 @@
 psImage *psImageGrowMask(psImage *out,
                          const psImage *in,
-                         psMaskType maskVal,
+                         psImageMaskType maskVal,
                          unsigned int growSize,
-                         psMaskType growVal)
+                         psImageMaskType growVal)
 {
     if (in == NULL) {
@@ -237,7 +237,7 @@
         return NULL;
     }
-    if (in->type.type != PS_TYPE_MASK) {
+    if (in->type.type != PS_TYPE_IMAGE_MASK) {
         psError(PS_ERR_BAD_PARAMETER_TYPE, true,
-                "Invalid input image.  Input image type must match psMaskType.\n");
+                "Invalid input image.  Input image type must match psImageMaskType.\n");
         return NULL;
     }
@@ -261,6 +261,6 @@
     for (k = 0; k < in->numRows; k++) {
         for (l = 0; l < in->numCols; l++) {
-            out->data.PS_TYPE_MASK_DATA[k][l] = in->data.PS_TYPE_MASK_DATA[k][l];
-            changed->data.PS_TYPE_MASK_DATA[k][l] = 0;
+            out->data.PS_TYPE_IMAGE_MASK_DATA[k][l] = in->data.PS_TYPE_IMAGE_MASK_DATA[k][l];
+            changed->data.PS_TYPE_IMAGE_MASK_DATA[k][l] = 0;
         }
     }
@@ -268,6 +268,6 @@
     for (int i = 0; i < in->numRows; i++) {
         for (int j = 0; j < in->numCols; j++) {
-            if ( (in->data.PS_TYPE_MASK_DATA[i][j] & maskVal) != 0 &&
-                    changed->data.PS_TYPE_MASK_DATA[i][j] == 0) {
+            if ( (in->data.PS_TYPE_IMAGE_MASK_DATA[i][j] & maskVal) != 0 &&
+                    changed->data.PS_TYPE_IMAGE_MASK_DATA[i][j] == 0) {
                 m = i - growSize;
                 if (m < 0) {
@@ -281,7 +281,7 @@
                     for (l = n; l <= (j + growSize) && l < in->numCols; l++) {
                         if (((k-i)*(k-i) + (l-j)*(l-j)) <= (growSize*growSize)) {
-                            out->data.PS_TYPE_MASK_DATA[k][l] |= growVal;
-                            if ( (in->data.PS_TYPE_MASK_DATA[i][j] & maskVal) == 0 ) {
-                                changed->data.PS_TYPE_MASK_DATA[k][l] = 1;
+                            out->data.PS_TYPE_IMAGE_MASK_DATA[k][l] |= growVal;
+                            if ( (in->data.PS_TYPE_IMAGE_MASK_DATA[i][j] & maskVal) == 0 ) {
+                                changed->data.PS_TYPE_IMAGE_MASK_DATA[k][l] = 1;
                             }
                         }
Index: trunk/psLib/src/imageops/psImageMaskOps.h
===================================================================
--- trunk/psLib/src/imageops/psImageMaskOps.h	(revision 21172)
+++ trunk/psLib/src/imageops/psImageMaskOps.h	(revision 21183)
@@ -6,6 +6,6 @@
  * @author David Robbins, MHPCC
  *
- * @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-01-23 22:47:23 $
+ * @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:37 $
  *
  * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -32,5 +32,5 @@
     psRegion region,                   ///< the specified region
     const char *op,                    ///< the logical operation
-    psMaskType maskValue               ///< the specified bits
+    psImageMaskType maskValue		///< the specified bits
 );
 
@@ -44,5 +44,5 @@
     psRegion region,                   ///< the specified region
     const char *op,                    ///< the logical operation
-    psMaskType maskValue               ///< the specified bits
+    psImageMaskType maskValue		///< the specified bits
 );
 
@@ -58,5 +58,5 @@
     double radius,                     ///< the radius of the specified circle
     const char *op,                    ///< the logical operation
-    psMaskType maskValue               ///< the specified bits
+    psImageMaskType maskValue		///< the specified bits
 );
 
@@ -72,5 +72,5 @@
     double radius,                     ///< the radius of the specified circle
     const char *op,                    ///< the logical operation
-    psMaskType maskValue               ///< the specified bits
+    psImageMaskType maskValue		///< the specified bits
 );
 
@@ -89,7 +89,7 @@
     psImage *out,                      ///< the image to set and return
     const psImage *in,                 ///< the input to image
-    psMaskType maskVal,                ///< the specified mask value
+    psImageMaskType maskVal,		///< the specified mask value
     unsigned int growSize,             ///< the range of values from maskVal
-    psMaskType growVal                 ///< the output value to set
+    psImageMaskType growVal		///< the output value to set
 );
 
Index: trunk/psLib/src/imageops/psImagePixelExtract.c
===================================================================
--- trunk/psLib/src/imageops/psImagePixelExtract.c	(revision 21172)
+++ trunk/psLib/src/imageops/psImagePixelExtract.c	(revision 21183)
@@ -8,6 +8,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-10-22 02:10:37 $
+ *  @version $Revision: 1.34 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:37 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -206,5 +206,5 @@
                        const psImage* input,
                        const psImage* mask,
-                       psMaskType maskVal,
+                       psImageMaskType maskVal,
                        psRegion region,
                        psImageCutDirection direction,
@@ -357,10 +357,10 @@
             return NULL;
         }
-        if (mask->type.type != PS_TYPE_MASK) {
+        if (mask->type.type != PS_TYPE_IMAGE_MASK) {
             char* typeStr;
             PS_TYPE_NAME(typeStr,mask->type.type);
             psError(PS_ERR_BAD_PARAMETER_TYPE, true,
                     _("Input psImage mask type, %s, is not the supported mask datatype of %s."),
-                    typeStr, PS_TYPE_MASK_NAME);
+                    typeStr, PS_TYPE_IMAGE_MASK_NAME);
             psFree(out);
             return NULL;
@@ -394,5 +394,5 @@
         psVector* imgVec = psVectorAlloc(numRows, type);
         psVector* maskVec = NULL;
-        psMaskType* maskData = NULL;
+        psImageMaskType* maskData = NULL;
         psPixelCoord* outPosition = NULL;
 
@@ -416,25 +416,29 @@
 
         if (mask != NULL) {
-            maskVec = psVectorAlloc(numRows, mask->type.type);
-        }
-        #define PSIMAGE_CUT_VERTICAL(TYPE) \
+            maskVec = psVectorAlloc(numRows, PS_TYPE_VECTOR_MASK);
+        }
+
+#define PSIMAGE_CUT_VERTICAL(TYPE) \
     case PS_TYPE_##TYPE: { \
-            psMaskType* maskVecData = NULL; \
-            for (psS32 c=col0;c<col1;c++) { \
+            psVectorMaskType* maskVecData = NULL; \
+            for (psS32 c = col0; c < col1; c++) { \
                 ps##TYPE *imgData = input->data.TYPE[row0] + c; \
                 ps##TYPE *imgVecData = imgVec->data.TYPE; \
                 if (maskVec != NULL) { \
-                    maskVecData = maskVec->data.U8; \
-                    maskData = (psMaskType* )(mask->data.U8[row0]) + c; \
+                    maskVecData = maskVec->data.PS_TYPE_VECTOR_MASK_DATA; \
+                    maskData = &mask->data.PS_TYPE_IMAGE_MASK_DATA[row0][c]; /* XXX double check this... */ \
+                    /** old entry: maskData = (psMaskType* )(mask->data.PS_TYPE_IMAGE_MASK_DATA[row0]) + c; */ \
                 } \
-                for (psS32 r=row0;r<row1;r++) { \
-                    *(imgVecData++) = *imgData; \
+                for (psS32 r = row0; r < row1; r++) { \
+                   *imgVecData = *imgData; \
+                    imgVecData ++; \
                     imgData += inCols; \
                     if (maskVecData != NULL) { \
-                        *(maskVecData++) = *maskData; \
+                        *maskVecData = (*maskData & maskVal); \
+                        maskVecData ++; \
                         maskData += inCols; \
                     } \
                 } \
-                psVectorStats(myStats,imgVec,NULL,maskVec,maskVal); \
+                psVectorStats(myStats, imgVec, NULL, maskVec, 0xff); \
                 *outData = psStatsGetValue(myStats, statistic); \
                 if (outPosition != NULL) { \
@@ -471,6 +475,8 @@
         psFree(imgVec);
         psFree(maskVec);
+
     } else if (direction == PS_CUT_Y_POS || direction == PS_CUT_Y_NEG) {
         // Cut in Y direction
+        // XXX use this if we drop the hackish stuff below: psVector* imgVec = psVectorAlloc(numCols, type);
         psVector* imgVec = NULL;
         psVector* maskVec = NULL;
@@ -479,12 +485,10 @@
 
         // fill in psVector to fake out the statistics functions.
+	// XXX EAM : this seems rather hackish: just use the needed psVectorAlloc (like above)?
         imgVec = psAlloc(sizeof(psVector));
         imgVec->type = input->type;
         P_PSVECTOR_SET_NALLOC(imgVec,numCols);
-        if (mask != NULL) {
-            maskVec = psAlloc(sizeof(psVector));
-            maskVec->type = mask->type;
-            P_PSVECTOR_SET_NALLOC(maskVec,numCols);
-        }
+        imgVec->n = imgVec->nalloc;
+
         // recycle output to make a proper sized/type output structure
         // n.b. type is double as that is the type given for all stats in
@@ -492,6 +496,4 @@
         out = psVectorRecycle(out, numRows, PS_TYPE_F64);
         out->n = numRows;
-        imgVec->n = imgVec->nalloc;
-        maskVec->n = maskVec->nalloc;
         if (coords != NULL) {
             coords = psPixelsRealloc(coords, numRows);
@@ -507,12 +509,30 @@
         }
 
+        if (mask != NULL) {
+            maskVec = psVectorAlloc(numRows, PS_TYPE_VECTOR_MASK);
+	    // XXX the old code (below) faked out the mask vector
+            // maskVec = psAlloc(sizeof(psVector));
+            // maskVec->type = mask->type;
+            // P_PSVECTOR_SET_NALLOC(maskVec,numCols);
+	    // maskVec->n = maskVec->nalloc;
+        }
+
         for (psS32 r = row0; r < row1; r++) {
             // point the vector struct to the
             // data to calculate the stats
             imgVec->data.U8 = (psPtr )(input->data.U8[r] + col0 * elementSize);
+
+	    // set the vector mask pixels based on the image pixels
             if (maskVec != NULL) {
-                maskVec->data.U8 = (psPtr )(mask->data.U8[r] + col0 * sizeof(psMaskType));
-            }
-            psVectorStats(myStats, imgVec, NULL, maskVec, maskVal);
+		psVectorMaskType *maskVecData = maskVec->data.PS_TYPE_VECTOR_MASK_DATA;
+		psImageMaskType *maskData = &mask->data.PS_TYPE_IMAGE_MASK_DATA[r][col0];
+                for (psS32 c = col0; c < col1; c++) { 
+		    *maskVecData = (*maskData & maskVal); 
+		    maskVecData ++; 
+		    maskData ++;
+                } 
+	    }
+
+            psVectorStats(myStats, imgVec, NULL, maskVec, 0xff);
             *outData = psStatsGetValue(myStats, statistic);
             if (outPosition != NULL) {
@@ -544,5 +564,5 @@
                      const psImage* input,
                      const psImage* mask,
-                     psMaskType maskVal,
+                     psImageMaskType maskVal,
                      psRegion region,
                      unsigned int nSamples,
@@ -651,10 +671,10 @@
             return NULL;
         }
-        if (mask->type.type != PS_TYPE_MASK) {
+        if (mask->type.type != PS_TYPE_IMAGE_MASK) {
             char* typeStr;
             PS_TYPE_NAME(typeStr,mask->type.type);
             psError(PS_ERR_BAD_PARAMETER_TYPE, true,
                     _("Input psImage mask type, %s, is not the supported mask datatype of %s."),
-                    typeStr, PS_TYPE_MASK_NAME);
+                    typeStr, PS_TYPE_IMAGE_MASK_NAME);
             psFree(out);
             return NULL;
@@ -739,5 +759,5 @@
                            const psImage* input,
                            const psImage* mask,
-                           psMaskType maskVal,
+                           psImageMaskType maskVal,
                            float x,
                            float y,
@@ -765,10 +785,10 @@
             return NULL;
         }
-        if (mask->type.type != PS_TYPE_MASK) {
+        if (mask->type.type != PS_TYPE_IMAGE_MASK) {
             char* typeStr;
             PS_TYPE_NAME(typeStr,mask->type.type);
             psError(PS_ERR_BAD_PARAMETER_TYPE, true,
                     _("Input psImage mask type, %s, is not the supported mask datatype of %s."),
-                    typeStr, PS_TYPE_MASK_NAME);
+                    typeStr, PS_TYPE_IMAGE_MASK_NAME);
             psFree(out);
             return NULL;
@@ -868,5 +888,5 @@
         if (mask != NULL) {
             bufferMask[lcv] = psVectorAllocEmpty(1+4*(rSq[lcv+1]-rSq[lcv]),
-                                                 PS_TYPE_MASK);
+                                                 PS_TYPE_VECTOR_MASK);
         }
     }
@@ -877,7 +897,7 @@
     for (psS32 row=startRow; row <= endRow; row++) {
         psF32* inRow = input->data.F32[row];
-        psMaskType* maskRow = NULL;
+        psImageMaskType* maskRow = NULL;
         if (mask != NULL) {
-            maskRow = mask->data.PS_TYPE_MASK_DATA[row];
+            maskRow = mask->data.PS_TYPE_IMAGE_MASK_DATA[row];
         }
         for (psS32 col=startCol; col <= endCol; col++) {
@@ -899,5 +919,5 @@
 
                     if (maskRow != NULL) {
-                        bufferMask[r]->data.PS_TYPE_MASK_DATA[n] = maskRow[col];
+                        bufferMask[r]->data.PS_TYPE_VECTOR_MASK_DATA[n] = (maskRow[col] & maskVal);
                         bufferMask[r]->n = n+1;
                     }
@@ -913,5 +933,5 @@
 
     for (psS32 r = 0; r < numOut; r++) {
-        psVectorStats(myStats,buffer[r], NULL, bufferMask[r],maskVal);
+        psVectorStats(myStats, buffer[r], NULL, bufferMask[r], 0xff);
         outData[r] = psStatsGetValue(myStats, statistic);
     }
Index: trunk/psLib/src/imageops/psImagePixelExtract.h
===================================================================
--- trunk/psLib/src/imageops/psImagePixelExtract.h	(revision 21172)
+++ trunk/psLib/src/imageops/psImagePixelExtract.h	(revision 21183)
@@ -5,6 +5,6 @@
  * @author Robert DeSonia, MHPCC
  *
- * @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-01-23 22:47:23 $
+ * @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:37 $
  *
  * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -84,5 +84,5 @@
     const psImage* input,              ///< the input image in which to perform the slice
     const psImage* mask,               ///< the mask for the input image.
-    psMaskType maskVal,                ///< the mask value to apply to the mask
+    psImageMaskType maskVal,		///< the mask value to apply to the mask
     psRegion region,                   ///< the slice region
     psImageCutDirection direction,     ///< the slice dimension and direction
@@ -112,5 +112,5 @@
     const psImage* input,              ///< the input image in which to perform the cut
     const psImage* mask,               ///< the mask for the input image.
-    psMaskType maskVal,                ///< the mask value to apply to the mask
+    psImageMaskType maskVal,		///< the mask value to apply to the mask
     psRegion region,                   ///< the start and end points to cut along
     unsigned int nSamples,             ///< the number of samples along the cut
@@ -135,5 +135,5 @@
     const psImage* input,              ///< the input image in which to perform the cut
     const psImage* mask,               ///< the mask for the input image.
-    psMaskType maskVal,                ///< the mask value to apply to the mask
+    psImageMaskType maskVal,		///< the mask value to apply to the mask
     float x,                           ///< the column of the center of the cut circle
     float y,                           ///< the row of the center of the cut circle
Index: trunk/psLib/src/imageops/psImagePixelInterpolate.c
===================================================================
--- trunk/psLib/src/imageops/psImagePixelInterpolate.c	(revision 21172)
+++ trunk/psLib/src/imageops/psImagePixelInterpolate.c	(revision 21183)
@@ -11,6 +11,6 @@
  *  @author Eugene Magnier, IfA
  *
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-10-09 19:25:44 $
+ *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:37 $
  *
  *  Copyright 2007 Institute for Astronomy, University of Hawaii
@@ -54,5 +54,5 @@
 		    /* do not test self */ \
 		    if (!jx && !jy) { continue; } \
-		    if (mask->data.PS_TYPE_MASK_DATA[iy+jy][ix+jx] & maskVal) { continue; } \
+		    if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+jy][ix+jx] & maskVal) { continue; } \
 		    nGood ++; \
 		} \
@@ -67,5 +67,5 @@
 // just the mask, the output image contains enum values which define the type of interpolation which
 // can be performed
-psImage *psImagePixelInterpolateState (int *nBad, int *nPoor, psImage *mask, psMaskType maskVal) {
+psImage *psImagePixelInterpolateState (int *nBad, int *nPoor, psImage *mask, psImageMaskType maskVal) {
 
     psImage *result = psImageAlloc (mask->numCols, mask->numRows, PS_TYPE_S32);
@@ -79,5 +79,5 @@
 
 	    // state of the good pixels (unmasked)
-	    if (!(mask->data.PS_TYPE_MASK_DATA[iy][ix] & maskVal)) { 
+	    if (!(mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskVal)) { 
 		// count good neighbor pixels (+ self)
 		int nGood = 0;
@@ -94,5 +94,5 @@
 			if (jx + ix < 0) { continue; }
 			if (jx + ix >= mask->numCols) { continue; }
-			if (mask->data.PS_TYPE_MASK_DATA[iy+jy][ix+jx] & maskVal) { continue; }
+			if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+jy][ix+jx] & maskVal) { continue; }
 			nGood ++;
 			minX = PS_MIN (minX, jx);
@@ -137,5 +137,5 @@
 
 // interpolate the poor pixels using the available options
-bool psImagePixelInterpolatePoor (psImage *image, psImage *state, psImage *mask, psMaskType maskVal) {
+bool psImagePixelInterpolatePoor (psImage *image, psImage *state, psImage *mask, psImageMaskType maskVal) {
 
     assert (image->numCols == state->numCols);
@@ -185,5 +185,5 @@
 			  if (!jx && !jy) { continue; } 
 			  // skip masked pixels
-			  if (mask->data.PS_TYPE_MASK_DATA[iy+jy][ix+jx] & maskVal) { continue; }
+			  if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+jy][ix+jx] & maskVal) { continue; }
 			  x->data.F32[n] = jx;
 			  y->data.F32[n] = jy;
@@ -241,5 +241,5 @@
     
 // interpolate the good pixels to their true centers
-bool psImagePixelInterpolateCenter (psImage *value, psImage *xCoord, psImage *yCoord, psImage *state, psImage *mask, psMaskType maskVal) {
+bool psImagePixelInterpolateCenter (psImage *value, psImage *xCoord, psImage *yCoord, psImage *state, psImage *mask, psImageMaskType maskVal) {
 
     assert (value->numCols == state->numCols);
@@ -299,5 +299,5 @@
 			  if (jx + ix >= value->numCols) { continue; } 
 			  // skip masked pixels
-			  if (mask->data.PS_TYPE_MASK_DATA[iy+jy][ix+jx] & maskVal) { continue; }
+			  if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+jy][ix+jx] & maskVal) { continue; }
 			  x->data.F32[n] = xCoord->data.F32[iy+jy][ix+jx];
 			  y->data.F32[n] = yCoord->data.F32[iy+jy][ix+jx];
@@ -331,5 +331,5 @@
 			  if (jx + ix >= value->numCols) { continue; } 
 			  // skip masked pixels
-			  if (mask->data.PS_TYPE_MASK_DATA[iy+jy][ix+jx] & maskVal) { continue; }
+			  if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy+jy][ix+jx] & maskVal) { continue; }
 			  x->data.F32[n] = xCoord->data.F32[iy+jy][ix+jx];
 			  y->data.F32[n] = yCoord->data.F32[iy+jy][ix+jx];
@@ -363,5 +363,5 @@
     for (int iy = 0; iy < value->numRows; iy++) {
 	for (int ix = 0; ix < value->numCols; ix++) {
-	  if (mask->data.PS_TYPE_MASK_DATA[iy][ix] & maskVal) { continue; }
+	  if (mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] & maskVal) { continue; }
 	  value->data.F32[iy][ix] = output->data.F32[iy][ix];
 	}
Index: trunk/psLib/src/imageops/psImagePixelInterpolate.h
===================================================================
--- trunk/psLib/src/imageops/psImagePixelInterpolate.h	(revision 21172)
+++ trunk/psLib/src/imageops/psImagePixelInterpolate.h	(revision 21183)
@@ -7,6 +7,6 @@
  *  @author Eugene Magnier, IfA
  *
- *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-09-20 23:54:25 $
+ *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:37 $
  *
  *  Copyright 2007 Institute for Astronomy, University of Hawaii
@@ -34,7 +34,7 @@
 } psImagePixelInterpolateType;
 
-psImage *psImagePixelInterpolateState (int *nBad, int *nPoor, psImage *mask, psMaskType maskVal);
-bool psImagePixelInterpolatePoor (psImage *image, psImage *state, psImage *mask, psMaskType maskVal);
-bool psImagePixelInterpolateCenter (psImage *value, psImage *xCoord, psImage *yCoord, psImage *state, psImage *mask, psMaskType maskVal);
+psImage *psImagePixelInterpolateState (int *nBad, int *nPoor, psImage *mask, psImageMaskType maskVal);
+bool psImagePixelInterpolatePoor (psImage *image, psImage *state, psImage *mask, psImageMaskType maskVal);
+bool psImagePixelInterpolateCenter (psImage *value, psImage *xCoord, psImage *yCoord, psImage *state, psImage *mask, psImageMaskType maskVal);
 
 /// @}
Index: trunk/psLib/src/imageops/psImageStats.c
===================================================================
--- trunk/psLib/src/imageops/psImageStats.c	(revision 21172)
+++ trunk/psLib/src/imageops/psImageStats.c	(revision 21183)
@@ -9,6 +9,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.106 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-03-14 00:39:50 $
+ *  @version $Revision: 1.107 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2009-01-27 06:39:37 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -53,5 +53,5 @@
                       const psImage* in,
                       const psImage* mask,
-                      psMaskType maskVal)
+                      psImageMaskType maskVal)
 {
     psVector *junkData = NULL;
@@ -62,7 +62,70 @@
     PS_ASSERT_IMAGE_NON_NULL(in, false)
     if (mask != NULL) {
-        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_U8, false);
+        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, false);
         PS_ASSERT_IMAGES_SIZE_EQUAL(in, mask, false);
     }
+
+    if (in->parent == NULL) {
+        // stuff the image data into a psVector struct.
+	// XXX this is a bit hackish: does it save much time? (avoids a Nx*Ny alloc)
+        junkData = (psVector *) psAlloc(sizeof(psVector));
+        junkData->type = in->type;
+        P_PSVECTOR_SET_NALLOC(junkData,in->numRows * in->numCols);
+        junkData->n = junkData->nalloc;
+        junkData->data.U8 = in->data.V[0];      // since psImage data is contiguous...
+    } else {
+        // image not necessarily contiguous
+        int numRows = in->numRows;
+        int numCols = in->numCols;
+        int rowSize = numCols * (PSELEMTYPE_SIZEOF(in->type.type));
+
+        junkData = psVectorAlloc(numRows*numCols, in->type.type);
+
+        psU8* data = junkData->data.U8;
+        for (int row = 0; row < numRows; row++) {
+            memcpy(data, in->data.V[row], rowSize);
+            data += rowSize;
+        }
+    }
+
+    if (mask != NULL) {
+	// image not necessarily contiguous, generate a temp vector to hold the full image
+	int numRows = mask->numRows;
+	int numCols = mask->numCols;
+
+	junkMask = psVectorAlloc(numRows*numCols, PS_TYPE_VECTOR_MASK);
+
+	psVectorMaskType *data = junkMask->data.PS_TYPE_VECTOR_MASK_DATA;
+	for (int row = 0, nVect = 0; row < numRows; row++) {
+	    for (int col = 0; col < numCols; col++, nVect++) {
+		data[nVect] = (mask->data.PS_TYPE_IMAGE_MASK_DATA[row][col] & maskVal);
+	    }
+	}
+    }
+
+    psVectorStats(stats, junkData, NULL, junkMask, 0xff);
+
+    psFree(junkMask);
+    psFree(junkData);
+    return true;
+}
+
+/*****************************************************************************
+NOTE: We assume that the psHistogram structure out has already been allocated
+and initialized.
+ *****************************************************************************/
+bool psImageHistogram(psHistogram* out,
+                              const psImage* in,
+                              const psImage* mask,
+                              psImageMaskType maskVal)
+{
+    PS_ASSERT_PTR_NON_NULL(out, false);
+    PS_ASSERT_PTR_NON_NULL(in, false);
+    if (mask != NULL) {
+        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_IMAGE_MASK, false);
+        PS_ASSERT_IMAGES_SIZE_EQUAL(in, mask, false);
+    }
+    psVector* junkData = NULL;
+    psVector* junkMask = NULL;
 
     if (in->parent == NULL) {
@@ -89,96 +152,16 @@
 
     if (mask != NULL) {
-        if (mask->parent == NULL) {
-            // stuff the mask data into a psVector struct.
-            junkMask = psAlloc(sizeof(psVector));
-            junkMask->type = mask->type;
-            P_PSVECTOR_SET_NALLOC(junkMask,mask->numRows * mask->numCols);
-            junkMask->n = junkMask->nalloc;
-            junkMask->data.U8 = mask->data.V[0];
-        } else {
-            // image not necessarily contiguous
-            int numRows = mask->numRows;
-            int numCols = mask->numCols;
-            int rowSize = numCols * (PSELEMTYPE_SIZEOF(mask->type.type));
-
-            junkMask = psVectorAlloc(numRows*numCols, mask->type.type);
-
-            psU8* data = junkMask->data.U8;
-            for (int row = 0; row < numRows; row++) {
-                memcpy(data, mask->data.V[row], rowSize);
-                data += rowSize;
-            }
-        }
-    }
-
-    psVectorStats(stats, junkData, NULL, junkMask, maskVal);
-
-    psFree(junkMask);
-    psFree(junkData);
-    return true;
-}
-
-/*****************************************************************************
-NOTE: We assume that the psHistogram structure out has already been allocated
-and initialized.
- *****************************************************************************/
-bool psImageHistogram(psHistogram* out,
-                              const psImage* in,
-                              const psImage* mask,
-                              psMaskType maskVal)
-{
-    PS_ASSERT_PTR_NON_NULL(out, false);
-    PS_ASSERT_PTR_NON_NULL(in, false);
-    if (mask != NULL) {
-        PS_ASSERT_IMAGE_TYPE(mask, PS_TYPE_U8, false);
-        PS_ASSERT_IMAGES_SIZE_EQUAL(in, mask, false);
-    }
-    psVector* junkData = NULL;
-    psVector* junkMask = NULL;
-
-    if (in->parent == NULL) {
-        // stuff the image data into a psVector struct.
-        junkData = (psVector *) psAlloc(sizeof(psVector));
-        junkData->type = in->type;
-        P_PSVECTOR_SET_NALLOC(junkData,in->numRows * in->numCols);
-        junkData->n = junkData->nalloc;
-        junkData->data.U8 = in->data.V[0];      // since psImage data is contiguous...
-    } else {
-        // image not necessarily contiguous
-        int numRows = in->numRows;
-        int numCols = in->numCols;
-        int rowSize = numCols * (PSELEMTYPE_SIZEOF(in->type.type));
-
-        junkData = psVectorAlloc(numRows*numCols, in->type.type);
-
-        psU8* data = junkData->data.U8;
-        for (int row = 0; row < numRows; row++) {
-            memcpy(data, in->data.V[row], rowSize);
-            data += rowSize;
-        }
-    }
-
-    if (mask != NULL) {
-        if (mask->parent == NULL) {
-            // stuff the mask data into a psVector struct.
-            junkMask = psAlloc(sizeof(psVector));
-            junkMask->type = mask->type;
-            P_PSVECTOR_SET_NALLOC(junkMask,mask->numRows * mask->numCols);
-            junkMask->n = junkMask->nalloc;
-            junkMask->data.U8 = mask->data.V[0];
-        } else {
-            // image not necessarily contiguous
-            int numRows = mask->numRows;
-            int numCols = mask->numCols;
-            int rowSize = numCols * (PSELEMTYPE_SIZEOF(mask->type.type));
-
-            junkMask = psVectorAlloc(numRows*numCols, mask->type.type);
-
-            psU8* data = junkMask->data.U8;
-            for (int row = 0; row < numRows; row++) {
-                memcpy(data, mask->data.V[row], rowSize);
-                data += rowSize;
-            }
-        }
+	// image not necessarily contiguous; vector & image mask types do not match
+	int numRows = mask->numRows;
+	int numCols = mask->numCols;
+
+	junkMask = psVectorAlloc(numRows*numCols, PS_TYPE_VECTOR_MASK);
+
+	psVectorMaskType *data = junkMask->data.PS_TYPE_VECTOR_MASK_DATA;
+	for (int row = 0, nVect = 0; row < numRows; row++) {
+	    for (int col = 0; col < numCols; col++, nVect++) {
+		data[nVect] = (mask->data.PS_TYPE_IMAGE_MASK_DATA[row][col] & maskVal);
+	    }
+	}
     }
 
@@ -472,5 +455,5 @@
 long psImageCountPixelMask (psImage *mask,
                             psRegion region,
-                            psMaskType value)
+                            psImageMaskType value)
 {
     long Npixels = 0;
@@ -479,5 +462,4 @@
     int x1 = 0;
     int y1 = 0;
-    psElemType type;
 
     // this is not a valid error: a psRegion with ranges outside the valid pixels
@@ -608,34 +590,30 @@
     y1 = row1;
 
-    type = mask->type.type;
-    if (type != PS_TYPE_MASK) {
-        psError(PS_ERR_BAD_PARAMETER_TYPE, true,
-                "psImage type does not match the specified psMaskType!\n");
-        return -1;
-    }
-
+# define PS_IMAGE_COUNT_PIXEL_MASK(NAME,TYPE) \
+    case PS_TYPE_##NAME: \
+        for (long j = y0; j < y1; j++) { \
+            for (long i = x0; i < x1; i++) { \
+                if (mask->data.TYPE[j][i] & value) { \
+                    Npixels ++; \
+                } \
+            } \
+        } \
+        break;
+
+    psElemType type = mask->type.type;
     switch (type) {
-    case PS_TYPE_U8:
-    case PS_TYPE_U16:
-        for (long j = y0; j < y1; j++) {
-            for (long i = x0; i < x1; i++) {
-                if (mask->data.PS_TYPE_MASK_DATA[j][i] & value) {
-                    Npixels ++;
-                }
-            }
-        }
-        break;
-    case PS_TYPE_S8:
-    case PS_TYPE_S16:
-    case PS_TYPE_S32:
-    case PS_TYPE_S64:
-    case PS_TYPE_U32:
-    case PS_TYPE_U64:
-    case PS_TYPE_F32:
-    case PS_TYPE_F64:
+	PS_IMAGE_COUNT_PIXEL_MASK(U8, U8);
+	PS_IMAGE_COUNT_PIXEL_MASK(U16,U16);
+	PS_IMAGE_COUNT_PIXEL_MASK(U32,U32);
+	PS_IMAGE_COUNT_PIXEL_MASK(U64,U64);
+	PS_IMAGE_COUNT_PIXEL_MASK(S8, S8);
+	PS_IMAGE_COUNT_PIXEL_MASK(S16,S16);
+	PS_IMAGE_COUNT_PIXEL_MASK(S32,S32);
+	PS_IMAGE_COUNT_PIXEL_MASK(S64,S64);
+
     default:
         // XXX this should include the mask type (as a string)
         psError(PS_ERR_BAD_PARAMETER_TYPE, true,
-                _("Input psImage mask type is not a supported mask datatype"));
+                _("Input psImage is an unsupported datatype"));
 
         return -1;
Index: trunk/psLib/src/imageops/psImageStats.h
===================================================================
--- trunk/psLib/src/imageops/psImageStats.h	(revision 21172)
+++ trunk/psLib/src/imageops/psImageStats.h	(revision 21183)
@@ -9,6 +9,6 @@
  * @author GLG, MHPCC
  *
- * @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
- * @date $Date: 2007-02-13 03:01:23 $
+ * @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
+ * @date $Date: 2009-01-27 06:39:37 $
  * Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
  */
@@ -42,5 +42,5 @@
     const psImage* in,                 ///< image (or subimage) to calculate stats
     const psImage* mask,               ///< mask data for image (NULL ok)
-    psMaskType maskVal                 ///< mask value for mask
+    psImageMaskType maskVal		///< mask value for mask
 );
 
@@ -57,5 +57,5 @@
     const psImage* in,                 ///< Image data to be histogramed.
     const psImage* mask,               ///< mask data for image (NULL ok)
-    psMaskType maskVal                 ///< mask Mask for mask
+    psImageMaskType maskVal		///< mask Mask for mask
 );
 
@@ -97,5 +97,5 @@
     psImage *mask,                     ///< input image to count
     psRegion region,                   ///< input region of image
-    psMaskType value                   ///< the mask value to satisfy
+    psImageMaskType value		///< the mask value to satisfy
 );
 
