Index: trunk/pswarp/src/pswarpLoop.c
===================================================================
--- trunk/pswarp/src/pswarpLoop.c	(revision 21178)
+++ trunk/pswarp/src/pswarpLoop.c	(revision 21183)
@@ -67,5 +67,5 @@
 
     // output mask bits
-    psMaskType maskValue = psMetadataLookupU8(&status, recipe, "MASK.OUTPUT");
+    psImageMaskType maskValue = psMetadataLookupImageMask(&status, recipe, "MASK.OUTPUT");
     psAssert (status, "MASK.OUTPUT was not defined");
 
Index: trunk/pswarp/src/pswarpPixelFraction.c
===================================================================
--- trunk/pswarp/src/pswarpPixelFraction.c	(revision 21178)
+++ trunk/pswarp/src/pswarpPixelFraction.c	(revision 21183)
@@ -20,5 +20,5 @@
     PS_ASSERT_IMAGE_NON_NULL(readout->mask, false);
     PS_ASSERT_IMAGES_SIZE_EQUAL(readout->mask, readout->image, false);
-    PS_ASSERT_IMAGE_TYPE(readout->mask, PS_TYPE_MASK, false);
+    PS_ASSERT_IMAGE_TYPE(readout->mask, PS_TYPE_IMAGE_MASK, false);
 
     if (stats) {
@@ -40,5 +40,5 @@
 
     // output mask bits
-    psMaskType maskValue = psMetadataLookupU8(&status, recipe, "MASK.OUTPUT"); 
+    psImageMaskType maskValue = psMetadataLookupImageMask(&status, recipe, "MASK.OUTPUT"); 
     psAssert (status, "MASK.OUTPUT was not defined");
 
@@ -55,5 +55,5 @@
     for (int y = 0; y < numRows; y++) {
         for (int x = 0; x < numCols; x++) {
-            if (mask->data.PS_TYPE_MASK_DATA[y][x] & maskValue) {
+            if (mask->data.PS_TYPE_IMAGE_MASK_DATA[y][x] & maskValue) {
                 numBad++;
             } else {
Index: trunk/pswarp/src/pswarpSetMaskBits.c
===================================================================
--- trunk/pswarp/src/pswarpSetMaskBits.c	(revision 21178)
+++ trunk/pswarp/src/pswarpSetMaskBits.c	(revision 21183)
@@ -10,8 +10,7 @@
 bool pswarpSetMaskBits (pmConfig *config) {
 
-    psMaskType maskIn = 0x00;			// mask for the input image
-    psMaskType markIn = 0x00;			// mark for the input image
-    psMaskType maskOut = 0x00;			// mask for the output image
-    psMaskType markOut = 0x00;			// mark for the output image
+    psImageMaskType maskIn = 0x00;			// mask for the input image
+    psImageMaskType markIn = 0x00;			// mark for the input image
+    psImageMaskType maskOut = 0x00;			// mask for the output image
 
     // this function sets the required single-image mask bits
@@ -22,5 +21,5 @@
 
     // mask for non-linear flat regions (default to DETECTOR if not defined)
-    psMaskType badMask = pmConfigMaskGet("BAD.WARP", config); 
+    psImageMaskType badMask = pmConfigMaskGet("BAD.WARP", config); 
     if (!badMask) {
 	badMask = 0x01;
@@ -30,5 +29,5 @@
 
     // mask for non-linear flat regions (default to DETECTOR if not defined)
-    psMaskType poorMask = pmConfigMaskGet("POOR.WARP", config); 
+    psImageMaskType poorMask = pmConfigMaskGet("POOR.WARP", config); 
     if (!poorMask) {
 	poorMask = 0x02;
@@ -38,18 +37,18 @@
 
     // search for an unset bit to use for MARK:
-    markOut = 0x80;
+    psImageMaskType markOut   = 0x00;
+    psImageMaskType markTrial = 0x01;
 
-    int nBits = sizeof(psMaskType) * 8;
+    int nBits = sizeof(psImageMaskType) * 8;
     for (int i = 0; !markOut && (i < nBits); i++) {
-	if (maskOut & markOut) {
-	    markOut >>= 1;
-	} else {
-	    markOut = markOut;
-	}
+        if (maskOut & markTrial) {
+            markTrial <<= 1;
+        } else {
+            markOut = markTrial;
+        }
     }
-
     if (!markOut) {
-	psError (PS_ERR_UNKNOWN, true, "Unable to define the MARK bit mask: all bits taken!");
-	return false;
+        psError (PS_ERR_UNKNOWN, true, "Unable to define the MARK bit mask: all bits taken!");
+        return false;
     }
 
@@ -63,8 +62,8 @@
     // set maskOut and markOut in the psphot recipe
     // NOTE: psphot works on the output images, not input images, so set the MARK and MASK correctly here
-    psMetadataAddU8 (warpRecipe, PS_LIST_TAIL, "MASK.INPUT",  PS_META_REPLACE, "user-defined mask", maskIn);
-    psMetadataAddU8 (warpRecipe, PS_LIST_TAIL, "MARK.INPUT",  PS_META_REPLACE, "user-defined mask", markIn);
-    psMetadataAddU8 (warpRecipe, PS_LIST_TAIL, "MASK.OUTPUT", PS_META_REPLACE, "user-defined mask", maskOut);
-    psMetadataAddU8 (warpRecipe, PS_LIST_TAIL, "MARK.OUTPUT", PS_META_REPLACE, "user-defined mask", markOut);
+    psMetadataAddImageMask (warpRecipe, PS_LIST_TAIL, "MASK.INPUT",  PS_META_REPLACE, "user-defined mask", maskIn);
+    psMetadataAddImageMask (warpRecipe, PS_LIST_TAIL, "MARK.INPUT",  PS_META_REPLACE, "user-defined mask", markIn);
+    psMetadataAddImageMask (warpRecipe, PS_LIST_TAIL, "MASK.OUTPUT", PS_META_REPLACE, "user-defined mask", maskOut);
+    psMetadataAddImageMask (warpRecipe, PS_LIST_TAIL, "MARK.OUTPUT", PS_META_REPLACE, "user-defined mask", markOut);
 
     // update the psphot recipe
@@ -77,6 +76,6 @@
     // set maskOut and markOut in the psphot recipe
     // NOTE: psphot works on the output images, not input images, so set the MARK and MASK correctly here
-    psMetadataAddU8 (psphotRecipe, PS_LIST_TAIL, "MARK.PSPHOT", PS_META_REPLACE, "user-defined mask", markOut);
-    psMetadataAddU8 (psphotRecipe, PS_LIST_TAIL, "MASK.PSPHOT", PS_META_REPLACE, "user-defined mask", maskOut);
+    psMetadataAddImageMask (psphotRecipe, PS_LIST_TAIL, "MARK.PSPHOT", PS_META_REPLACE, "user-defined mask", markOut);
+    psMetadataAddImageMask (psphotRecipe, PS_LIST_TAIL, "MASK.PSPHOT", PS_META_REPLACE, "user-defined mask", maskOut);
 
     return true;
Index: trunk/pswarp/src/pswarpTransformReadout.c
===================================================================
--- trunk/pswarp/src/pswarpTransformReadout.c	(revision 21178)
+++ trunk/pswarp/src/pswarpTransformReadout.c	(revision 21183)
@@ -22,7 +22,7 @@
 
     // output mask bits
-    psMaskType maskIn   = psMetadataLookupU8(&mdok, recipe, "MASK.INPUT");
-    psMaskType maskPoor = pmConfigMaskGet("POOR.WARP", config);
-    psMaskType maskBad  = pmConfigMaskGet("BAD.WARP", config);
+    psImageMaskType maskIn   = psMetadataLookupImageMask(&mdok, recipe, "MASK.INPUT");
+    psImageMaskType maskPoor = pmConfigMaskGet("POOR.WARP", config);
+    psImageMaskType maskBad  = pmConfigMaskGet("BAD.WARP", config);
     psAssert(mdok, "MASK.INPUT was not defined");
 
@@ -80,5 +80,5 @@
     }
     if ((input->mask || maskPoor || maskBad) && !output->mask) {
-        output->mask = psImageAlloc(output->image->numCols, output->image->numRows, PS_TYPE_MASK);
+        output->mask = psImageAlloc(output->image->numCols, output->image->numRows, PS_TYPE_IMAGE_MASK);
         psImageInit(output->mask, maskBad);
     }
Index: trunk/pswarp/src/pswarpTransformTile.c
===================================================================
--- trunk/pswarp/src/pswarpTransformTile.c	(revision 21178)
+++ trunk/pswarp/src/pswarpTransformTile.c	(revision 21183)
@@ -49,6 +49,6 @@
     psF32 **outImageData     = args->output->image->data.F32;
     psF32 **outVarData       = (args->output->weight) ? args->output->weight->data.F32 : NULL;
-    psMaskType **outMaskData = (args->output->mask)   ? args->output->mask->data.PS_TYPE_MASK_DATA : NULL;
-    psMaskType **inMaskData  = (args->input->mask)    ? args->input->mask->data.PS_TYPE_MASK_DATA : NULL;
+    psImageMaskType **outMaskData = (args->output->mask)   ? args->output->mask->data.PS_TYPE_IMAGE_MASK_DATA : NULL;
+    psImageMaskType **inMaskData  = (args->input->mask)    ? args->input->mask->data.PS_TYPE_IMAGE_MASK_DATA : NULL;
 
     pswarpMap *map = args->grid->maps[args->gridX][args->gridY]; // Map for this tile
@@ -67,5 +67,5 @@
 
             // Only transform those pixels requested
-            if (region && region->data.U8[y][x]) {
+            if (region && region->data.PS_TYPE_IMAGE_MASK_DATA[y][x]) {
                 continue;
             }
@@ -82,5 +82,5 @@
             // psImagePixelInterpolate determines the value at pixel coordinate (x,y) in child coordinates
             double imageValue, varValue; // Value of image and variance map
-            psMaskType maskValue = inMaskData ? inMaskData[(int)yIn][(int)xIn] : 0; // Value of mask
+            psImageMaskType maskValue = inMaskData ? inMaskData[(int)yIn][(int)xIn] : 0; // Value of mask
             if (!psImageInterpolate(&imageValue, &varValue, &maskValue, xIn, yIn, args->interp)) {
                 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image.");
