Index: trunk/ppImage/src/ppImageParseCamera.c
===================================================================
--- trunk/ppImage/src/ppImageParseCamera.c	(revision 18422)
+++ trunk/ppImage/src/ppImageParseCamera.c	(revision 18556)
@@ -20,5 +20,5 @@
     }
 
-    // if MASK or WEIGHT was supplied on command line, bind files to 'input'
+    // if MASK or WEIGHT was supplied on command line, bind files to 'input'.
     // the mask and weight will be mosaicked with the image
     pmFPAfile *inputMask = pmFPAfileBindFromArgs(&status, input, config, "PPIMAGE.INPUT.MASK", "PPIMAGE.INPUT.MASK");
@@ -27,7 +27,9 @@
         return NULL;
     }
-    if (inputMask && inputMask->type != PM_FPA_FILE_MASK) {
+    if (inputMask) {
+      if (inputMask->type != PM_FPA_FILE_MASK) {
         psError(PS_ERR_IO, true, "PPIMAGE.INPUT.MASK is not of type MASK");
         return NULL;
+      }
     }
 
@@ -66,4 +68,5 @@
     }
     if (options->doMask) {
+
         if (!ppImageDefineFile (config, input->fpa, "PPIMAGE.MASK", "MASK", PM_FPA_FILE_MASK, PM_DETREND_TYPE_MASK)) {
             psError (PS_ERR_IO, false, "Can't find a mask image source");
@@ -71,5 +74,25 @@
             return NULL;
         }
-	// Need to read the names of bit masks from the mask header and set them in the recipe
+	// XXX have ppImageDefineFile return the pmFPAfile?
+	pmFPAfile *mask = psMetadataLookupPtr(&status, config->files, "PPIMAGE.MASK");
+	psAssert (mask, "mask not defined?  not possible!");
+
+	// Need to read the names of bit masks from the mask header and set them in the
+	// recipe.  If we are loading this from the detrend db, this action will happen
+	// when the file is resolved.
+	if (!mask->detrend) {
+	    // XXX need to load the mask bit names from one of the headers
+	    // this grabs the first available hdu : no guarantee that it will be valid, though
+	    pmHDU *hdu = pmHDUGetFirst (mask->fpa);
+	    if (!hdu) {
+		psError(PS_ERR_IO, true, "no valid HDU for PPIMAGE.INPUT.MASK");
+		return NULL;
+	    }
+	    // XXX is this consistent with the pmConfigMaskReadHeader call above?
+	    if (!pmConfigMaskReadHeader (config, hdu->header)) {
+		psError(PS_ERR_IO, false, "error in mask bits");
+		return NULL;
+	    }
+	}
     }
     if (options->doShutter) {
