Index: trunk/ppImage/src/ppImageDetrendMask.c
===================================================================
--- trunk/ppImage/src/ppImageDetrendMask.c	(revision 6747)
+++ trunk/ppImage/src/ppImageDetrendMask.c	(revision 6817)
@@ -1,5 +1,3 @@
-#include <stdio.h>
-#include "psmodules.h"
-#include "ppImageDetrend.h"
+#include "ppImage.h"
 
 # define MASK_MODE (PM_MASK_TRAP | PM_MASK_BADCOL | PM_MASK_SAT)
@@ -7,13 +5,29 @@
 // XXX pass 'concepts' not 'cell' to this function?
 
-bool ppImageDetrendMask(pmCell *cell, pmReadout *input, pmReadout *mask) {
+bool ppImageDetrendMask(pmReadout *input, pmReadout *mask) {
 
-    float saturation = psMetadataLookupF32(NULL, cell->concepts, "CELL.SATURATION");
+    psImage *image = NULL;
+
+    float saturation = psMetadataLookupF32(NULL, input->parent->concepts, "CELL.SATURATION");
 
     // Need to change this later to grow the mask by the size of the convolution kernel
     // XXX does this function respect the mask / image cell region information?
     // XXX should probably take pmRegion *mask
-    pmMaskBadPixels(input, mask->image, MASK_MODE, saturation, PM_MASK_TRAP, 0);
+
+    if (mask->image->type.type != PS_TYPE_MASK) {
+	image = psImageCopy (NULL, mask->image, PS_TYPE_MASK);
+    } else {
+	image = psMemIncrRefCounter (mask->image);
+    }
+
+    pmMaskBadPixels(input, image, MASK_MODE, saturation, PM_MASK_TRAP, 0);
+    psFree (image);
 
     return true;
 }
+
+
+// XXX the translation here should not be needed
+// the mask should (but is not) be read in using the mask read functions
+// by identifying the image type as a mask (in pmFPAfile).
+// currently, pmFPAfileReadImage converts the image to F32
