Index: /trunk/pswarp/src/pswarpArguments.c
===================================================================
--- /trunk/pswarp/src/pswarpArguments.c	(revision 12770)
+++ /trunk/pswarp/src/pswarpArguments.c	(revision 12771)
@@ -47,4 +47,5 @@
     }
 
+
     psArray *array;
 
@@ -58,4 +59,76 @@
     psFree (array);
 
+
+    // Parse the recipe and format into the arguments
+    {
+
+        // Select the appropriate recipe
+        psMetadata *recipe  = psMetadataLookupPtr (NULL, config->recipes, PSWARP_RECIPE);
+        if (!recipe) {
+            psError(PSWARP_ERR_CONFIG, true, "Can't find %s recipe!\n", PSWARP_RECIPE);
+            return false;
+        }
+
+        // Get grid size
+        bool status;                        // Status of MD lookup
+        int nGridX = psMetadataLookupS32 (&status, recipe, "GRID.NX");
+        if (!status) nGridX = 128;
+        int nGridY = psMetadataLookupS32 (&status, recipe, "GRID.NY");
+        if (!status) nGridY = 128;
+
+        // Get interpolation mode
+        psImageInterpolateMode interpolationMode; // Mode for interpolation
+        const char *name = psMetadataLookupStr (&status, recipe, "INTERPOLATION.MODE"); // Name of interp mode
+        if (!name) {
+            interpolationMode = PS_INTERPOLATE_BILINEAR;
+            psLogMsg ("pswarp", 3, "defaulting to bilinear interpolation\n");
+        } else {
+            interpolationMode = psImageInterpolateModeFromString (name);
+            if (interpolationMode == PS_INTERPOLATE_NONE) {
+                interpolationMode = PS_INTERPOLATE_BILINEAR;
+                psLogMsg ("pswarp", 3,
+                          "Unknown interpolation mode %s, defaulting to bilinear interpolation\n", name);
+            }
+        }
+
+        // Get mask parameters
+        psMaskType maskIn = psMetadataLookupU8(&status, recipe, "MASK.IN"); // Mask for input data
+        if (!status) {
+            maskIn = 0x00;
+            psWarning("MASK.IN is not set in the %s recipe --- defaulting to %x.", PSWARP_RECIPE, maskIn);
+        }
+        psMaskType maskPoor = psMetadataLookupU8(&status, recipe, "MASK.POOR"); // Mask for "poor" warped data
+        if (!status) {
+            maskPoor = 0x00;
+            psWarning("MASK.POOR is not set in the %s recipe --- defaulting to %x.", PSWARP_RECIPE, maskPoor);
+        }
+        psMaskType maskBad = psMetadataLookupU8(&status, recipe, "MASK.IN"); // Mask for bad warped data
+        if (!status) {
+            maskBad = 0x00;
+            psWarning("MASK.BAD is not set in the %s recipe --- defaulting to %x.", PSWARP_RECIPE, maskBad);
+        }
+        float poorFrac = psMetadataLookupF32(&status, recipe, "POOR.FRAC"); // Frac of bad flux for a "poor"
+        if (!status) {
+            poorFrac = 0.0;
+            psWarning("POOR.FRAC is not set in the %s recipe --- defaulting to %f.", PSWARP_RECIPE, poorFrac);
+        }
+
+        // Set recipe values in the arguments
+        psMetadataAddS32(config->arguments, PS_LIST_TAIL, "GRID.NX", 0,
+                         "Iso-astrom grid spacing in x", nGridX);
+        psMetadataAddS32(config->arguments, PS_LIST_TAIL, "GRID.NY", 0,
+                         "Iso-astrom grid spacing in x", nGridX);
+        psMetadataAddS32(config->arguments, PS_LIST_TAIL, "INTERPOLATION.MODE", 0,
+                         "Interpolation mode", interpolationMode);
+        psMetadataAddU8(config->arguments, PS_LIST_TAIL, "MASK.IN", 0,
+                         "Mask for input data", maskIn);
+        psMetadataAddU8(config->arguments, PS_LIST_TAIL, "MASK.POOR", 0,
+                         "Mask for poor warped data", maskPoor);
+        psMetadataAddU8(config->arguments, PS_LIST_TAIL, "MASK.BAD", 0,
+                         "Mask for bad warped data", maskBad);
+        psMetadataAddF32(config->arguments, PS_LIST_TAIL, "POOR.FRAC", 0,
+                         "Fraction of bad flux for a pixel to be marked as poor", poorFrac);
+    }
+
     psTrace("pswarp", 1, "Done with pswarpArguments...\n");
     return (config);
Index: /trunk/pswarp/src/pswarpDataLoad.c
===================================================================
--- /trunk/pswarp/src/pswarpDataLoad.c	(revision 12770)
+++ /trunk/pswarp/src/pswarpDataLoad.c	(revision 12771)
@@ -17,6 +17,6 @@
     pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSWARP.INPUT");
     if (!input) {
-	psError(PSWARP_ERR_CONFIG, true, "Can't find input data!\n");
-	return false;
+        psError(PSWARP_ERR_CONFIG, true, "Can't find input data!\n");
+        return false;
     }
 
@@ -24,7 +24,7 @@
     pmFPAfile *astrom = psMetadataLookupPtr (NULL, config->files, "PSWARP.ASTROM");
     if (!astrom) {
-	astrom = input;
+        astrom = input;
     }
- 
+
     // select the output readout
     view = pmFPAviewAlloc (0);
@@ -34,6 +34,6 @@
     pmReadout  *output = pmFPAfileThisReadout (config->files, view, "PSWARP.OUTPUT");
     if (!output) {
-	psError(PSWARP_ERR_CONFIG, true, "Can't find output data!\n");
-	return false;
+        psError(PSWARP_ERR_CONFIG, true, "Can't find output data!\n");
+        return false;
     }
     psFree (view);
@@ -42,4 +42,6 @@
     pmFPAfileActivate (config->files, false, "PSWARP.SKYCELL");
     pmFPAfileActivate (config->files, false, "PSWARP.OUTPUT");
+    pmFPAfileActivate (config->files, false, "PSWARP.OUTPUT.MASK");
+    pmFPAfileActivate (config->files, false, "PSWARP.OUTPUT.WEIGHT");
 
     view = pmFPAviewAlloc (0);
@@ -52,12 +54,12 @@
     pmHDU *phu = pmFPAviewThisPHU (view, astrom->fpa);
     if (phu) {
-	char *ctype = psMetadataLookupStr (NULL, phu->header, "CTYPE1");
-	if (ctype) {
-	    bilevelAstrometry = !strcmp (&ctype[4], "-DIS");
-	}
+        char *ctype = psMetadataLookupStr (NULL, phu->header, "CTYPE1");
+        if (ctype) {
+            bilevelAstrometry = !strcmp (&ctype[4], "-DIS");
+        }
     }
     if (bilevelAstrometry) {
-	pmAstromReadBilevelMosaic (input->fpa, phu->header);
-    } 
+        pmAstromReadBilevelMosaic (input->fpa, phu->header);
+    }
 
     // files associated with the science image
@@ -67,34 +69,34 @@
         psTrace ("pswarp", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
         if (!chip->process || !chip->file_exists) { continue; }
-	pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
+        pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
 
         // read WCS data from the corresponding header
-	pmHDU *hdu = pmFPAviewThisHDU (view, astrom->fpa);
-	if (bilevelAstrometry) {
-	    pmAstromReadBilevelChip (chip, hdu->header); 
-	} else {
-	    // we use a default FPA pixel scale of 1.0
-	    pmAstromReadWCS (input->fpa, chip, hdu->header, 1.0);
-	}
+        pmHDU *hdu = pmFPAviewThisHDU (view, astrom->fpa);
+        if (bilevelAstrometry) {
+            pmAstromReadBilevelChip (chip, hdu->header);
+        } else {
+            // we use a default FPA pixel scale of 1.0
+            pmAstromReadWCS (input->fpa, chip, hdu->header, 1.0);
+        }
 
-	while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
+        while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
             psTrace ("pswarp", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
             if (!cell->process || !cell->file_exists) { continue; }
-	    pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
+            pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
 
-	    // process each of the readouts
-	    while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {
-		pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
-		if (! readout->data_exists) { continue; }
+            // process each of the readouts
+            while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {
+                pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
+                if (! readout->data_exists) { continue; }
 
-		// XXX _Opt version uses locally-linear map
-		// pswarpTransformReadout (output, readout, config);
-		pswarpTransformReadout_Opt (output, readout, config);
+                // XXX _Opt version uses locally-linear map
+                // pswarpTransformReadout (output, readout, config);
+                pswarpTransformReadout_Opt (output, readout, config);
 
-		pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
-	    }
-	    pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
-	}
-	pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
+                pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
+            }
+            pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
+        }
+        pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
     }
     pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
Index: /trunk/pswarp/src/pswarpDataSave.c
===================================================================
--- /trunk/pswarp/src/pswarpDataSave.c	(revision 12770)
+++ /trunk/pswarp/src/pswarpDataSave.c	(revision 12771)
@@ -16,6 +16,6 @@
     pmFPAfile *input = psMetadataLookupPtr (NULL, config->files, "PSWARP.INPUT");
     if (!input) {
-	psError(PSWARP_ERR_CONFIG, true, "Can't find input data!\n");
-	return false;
+        psError(PSWARP_ERR_CONFIG, true, "Can't find input data!\n");
+        return false;
     }
 
@@ -23,4 +23,6 @@
     pmFPAfileActivate (config->files, false, NULL);
     pmFPAfileActivate (config->files, true, "PSWARP.OUTPUT");
+    pmFPAfileActivate (config->files, true, "PSWARP.OUTPUT.MASK");
+    pmFPAfileActivate (config->files, true, "PSWARP.OUTPUT.WEIGHT");
     pmFPAview *view = pmFPAviewAlloc (0);
 
@@ -31,23 +33,23 @@
         psTrace ("pswarp", 4, "Chip %d: %x %x\n", view->chip, chip->file_exists, chip->process);
         if (!chip->process || !chip->file_exists) { continue; }
-	pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
+        pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
 
-	while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
+        while ((cell = pmFPAviewNextCell (view, input->fpa, 1)) != NULL) {
             psTrace ("pswarp", 4, "Cell %d: %x %x\n", view->cell, cell->file_exists, cell->process);
             if (!cell->process || !cell->file_exists) { continue; }
-	    pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
+            pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
 
-	    // process each of the readouts
-	    while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {
-		pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
-		if (! readout->data_exists) { continue; }
+            // process each of the readouts
+            while ((readout = pmFPAviewNextReadout (view, input->fpa, 1)) != NULL) {
+                pmFPAfileIOChecks (config, view, PM_FPA_BEFORE);
+                if (! readout->data_exists) { continue; }
 
-		// pswarpConvertReadout (readout, config);
+                // pswarpConvertReadout (readout, config);
 
-		pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
-	    }
-	    pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
-	}
-	pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
+                pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
+            }
+            pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
+        }
+        pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
     }
     pmFPAfileIOChecks (config, view, PM_FPA_AFTER);
Index: /trunk/pswarp/src/pswarpParseCamera.c
===================================================================
--- /trunk/pswarp/src/pswarpParseCamera.c	(revision 12770)
+++ /trunk/pswarp/src/pswarpParseCamera.c	(revision 12771)
@@ -11,6 +11,6 @@
     pmFPAfile *input = pmFPAfileDefineFromArgs (&status, config, "PSWARP.INPUT", "INPUT");
     if (!input) {
-	psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.INPUT");
-	return false;
+        psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.INPUT");
+        return false;
     }
 
@@ -19,17 +19,19 @@
     pmFPAfileDefineFromArgs (&status, config, "PSWARP.ASTROM", "ASTROM");
     if (status) {
-	psLogMsg ("pswarp", 3, "using supplied astrometry\n");
+        psLogMsg ("pswarp", 3, "using supplied astrometry\n");
     } else {
-	psLogMsg ("pswarp", 3, "using header astrometry\n");
+        psLogMsg ("pswarp", 3, "using header astrometry\n");
     }
 
     // the mask is not required - but must conform to input camera
-    if (!pmFPAfileBindFromArgs (NULL, input, config, "PSWARP.MASK", "MASK")) {
-	psLogMsg ("pswarp", 3, "no mask supplied\n");
-    } 
+    pmFPAfile *inMask = pmFPAfileBindFromArgs(NULL, input, config, "PSWARP.MASK", "MASK");
+    if (!inMask) {
+        psLogMsg ("pswarp", 3, "no mask supplied\n");
+    }
 
-    if (!pmFPAfileBindFromArgs (NULL, input, config, "PSWARP.WEIGHT", "WEIGHT")) {
-	psLogMsg ("pswarp", 3, "no weight supplied\n");
-    } 
+    pmFPAfile *inWeight = pmFPAfileBindFromArgs(NULL, input, config, "PSWARP.WEIGHT", "WEIGHT");
+    if (!inWeight) {
+        psLogMsg ("pswarp", 3, "no weight supplied\n");
+    }
 
     // the input skycell is a required argument: it defines the output image
@@ -37,6 +39,6 @@
     status = pswarpDefineSkycell (&skycell, &skyConfig, config, "PSWARP.SKYCELL", "SKYCELL");
     if (!status) {
-	psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.SKYCELL");
-	return false;
+        psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.SKYCELL");
+        return false;
     }
 
@@ -45,19 +47,31 @@
     // if (!pmFPAfileDefineFromFPA (skyConfig, skycell->fpa, 1, 1, "PSWARP.OUTPUT")) {
     if (!pmFPAfileDefineOutput (skyConfig, skycell->fpa, "PSWARP.OUTPUT")) {
-	psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.OUTPUT");
-	return false;
+        psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.OUTPUT");
+        return false;
+    }
+    if (inMask) {
+        if (!pmFPAfileDefineOutput (skyConfig, skycell->fpa, "PSWARP.OUTPUT.MASK")) {
+            psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.OUTPUT.MASK");
+            return false;
+        }
+    }
+    if (inWeight) {
+        if (!pmFPAfileDefineOutput (skyConfig, skycell->fpa, "PSWARP.OUTPUT.WEIGHT")) {
+            psError(PSWARP_ERR_CONFIG, false, "Failed to build FPA from PSWARP.OUTPUT.WEIGHT");
+            return false;
+        }
     }
 
     // Chip selection: turn on only the chips specified
-    char *chipLine = psMetadataLookupStr(NULL, config->arguments, "CHIP_SELECTIONS"); 
+    char *chipLine = psMetadataLookupStr(NULL, config->arguments, "CHIP_SELECTIONS");
     psArray *chips = psStringSplitArray (chipLine, ",", false);
     if (chips->n > 0) {
-	pmFPASelectChip (input->fpa, -1, true); // deselect all chips
-	for (int i = 0; i < chips->n; i++) {
-	    int chipNum = atoi(chips->data[i]);
-	    if (! pmFPASelectChip(input->fpa, chipNum, false)) {
-		psError(PSWARP_ERR_CONFIG, true, "Chip number %d doesn't exist in camera.\n", chipNum);
-		return false;
-	    }
+        pmFPASelectChip (input->fpa, -1, true); // deselect all chips
+        for (int i = 0; i < chips->n; i++) {
+            int chipNum = atoi(chips->data[i]);
+            if (! pmFPASelectChip(input->fpa, chipNum, false)) {
+                psError(PSWARP_ERR_CONFIG, true, "Chip number %d doesn't exist in camera.\n", chipNum);
+                return false;
+            }
         }
     }
Index: /trunk/pswarp/src/pswarpTransformReadout_Opt.c
===================================================================
--- /trunk/pswarp/src/pswarpTransformReadout_Opt.c	(revision 12770)
+++ /trunk/pswarp/src/pswarpTransformReadout_Opt.c	(revision 12771)
@@ -2,12 +2,6 @@
 
 // NOTE: in this function, the coordinates are transformed from the OUTPUT to the INPUT
-bool pswarpTransformReadout_Opt (pmReadout *output, pmReadout *input, pmConfig *config) {
-
-    bool status;
-    int minX, minY, maxX, maxY;
-    int gridXo, gridX, gridY, nextGridXo, nextGridX, nextGridY;
-    pswarpMap *map = NULL;
-    psImageInterpolateMode interpolationMode = PS_INTERPOLATE_NONE;
-
+bool pswarpTransformReadout_Opt (pmReadout *output, pmReadout *input, pmConfig *config)
+{
     // XXX this implementation currently ignores the use of the region
     psImage *region = NULL;
@@ -15,31 +9,13 @@
     psTimerStart ("warp");
 
-    // select the current recipe
-    psMetadata *recipe  = psMetadataLookupPtr (NULL, config->recipes, PSWARP_RECIPE);
-    if (!recipe) {
-        psError(PSWARP_ERR_CONFIG, true, "Can't find PSWARP recipe!\n");
-        return false;
-    }
-
-    int nGridX = psMetadataLookupS32 (&status, recipe, "GRID.NX");
-    if (!status) nGridX = 128;
-    int nGridY = psMetadataLookupS32 (&status, recipe, "GRID.NY");
-    if (!status) nGridY = 128;
-
-    char *name = psMetadataLookupStr (&status, recipe, "INTERPOLATION.MODE");
-    if (!name) {
-        interpolationMode = PS_INTERPOLATE_BILINEAR;
-        psLogMsg ("pswarp", 3, "defaulting to bilinear interpolation\n");
-    } else {
-        interpolationMode = psImageInterpolateModeFromString (name);
-        if (interpolationMode == PS_INTERPOLATE_NONE) {
-            interpolationMode = PS_INTERPOLATE_BILINEAR;
-            psLogMsg ("pswarp", 3, "unknown interpolation mode %s, defaulting to bilinear interpolation\n", name);
-        }
-    }
-
-    psPlane *inPix = psPlaneAlloc();    // Coordinates on the input detector
-    psImage *inImage = input->image;
-    psF32 **outData = output->image->data.F32;
+    // Get grid size
+    int nGridX = psMetadataLookupS32(NULL, config->arguments, "GRID.NX");
+    int nGridY = psMetadataLookupS32(NULL, config->arguments, "GRID.NY");
+    psImageInterpolateMode interpolationMode = psMetadataLookupS32(NULL, config->arguments,
+                                                                   "INTERPOLATION.MODE");
+    psMaskType maskIn = psMetadataLookupU8(NULL, config->arguments, "MASK.IN"); // Mask for input data
+    psMaskType maskPoor = psMetadataLookupU8(NULL, config->arguments, "MASK.POOR"); // Mask for "poor" data
+    psMaskType maskBad = psMetadataLookupU8(NULL, config->arguments, "MASK.IN"); // Mask for bad data
+    float poorFrac = psMetadataLookupF32(NULL, config->arguments, "POOR.FRAC"); // Flux fraction for "poor"
 
     // we need to apply the offset to convert parent coordinates to child coordinates for
@@ -54,4 +30,5 @@
 
     // find the output pixel range
+    int minX, minY, maxX, maxY;
     pswarpMatchRange (&minX, &minY, &maxX, &maxY, input, output);
 
@@ -64,7 +41,8 @@
     psLogMsg ("pswarp", 3, "maximum error using this grid sampling: %f\n", maxError);
 
+    int gridX, gridY, nextGridX, nextGridY;
     pswarpMapGridSetGrid (grid, minX, minY, &gridX, &gridY);
     nextGridY = pswarpMapGridNextGrid_Y (grid, gridY);
-    map = grid->maps[gridX][gridY];
+    pswarpMap *map = grid->maps[gridX][gridY];
 
     assert ((int)(minX - outCol0) >= 0);
@@ -73,9 +51,32 @@
     assert ((int)(maxY - outRow0) <= output->image->numRows);
 
-    gridXo = gridX;
-    nextGridXo = pswarpMapGridNextGrid_X (grid, gridX);
+    int gridXo = gridX;
+    int nextGridXo = pswarpMapGridNextGrid_X (grid, gridX);
 
-    psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(PS_INTERPOLATE_BILINEAR, inImage,
-                                                                       NULL, NULL, 0, NAN, NAN, 0, 0, 0.0);
+    psImage *inImage = input->image;    // Input image
+    psImage *inVar   = input->weight;   // Input weight map
+    psImage *inMask  = input->mask;     // Input mask
+
+    // Interpolation options
+    psImageInterpolateOptions *interp = psImageInterpolateOptionsAlloc(interpolationMode, inImage,
+                                                                       inVar, inMask, maskIn, NAN, NAN,
+                                                                       maskPoor, maskBad, poorFrac);
+
+    psPlane *inPix = psPlaneAlloc();    // Coordinates on the input detector
+    psF32 **outImageData = output->image->data.F32; // Output image pixels
+    psF32 **outVarData;                 // Output variance pixels
+    psMaskType **outMaskData;           // Output mask pixels
+    if (inVar) {
+        if (!output->weight) {
+            output->weight = psImageAlloc(output->image->numCols, output->image->numRows, PS_TYPE_F32);
+        }
+        outVarData = output->weight->data.F32;
+    }
+    if (inMask) {
+        if (!output->mask) {
+            output->mask = psImageAlloc(output->image->numCols, output->image->numRows, PS_TYPE_MASK);
+        }
+        outMaskData = output->mask->data.PS_TYPE_MASK_DATA;
+    }
 
     // Iterate over the output image pixels (parent frame)
@@ -112,6 +113,8 @@
             // XXX apply scale and offset?
             // psImagePixelInterpolate determines the value at pixel coordinate (x,y) in child coordinates
-            double value;
-            if (!psImageInterpolate(&value, NULL, NULL, inPix->x - inCol0, inPix->y - inRow0, interp)) {
+            double imageValue, varValue;
+            psMaskType maskValue;
+            if (!psImageInterpolate(&imageValue, &varValue, &maskValue,
+                                    inPix->x - inCol0, inPix->y - inRow0, interp)) {
                 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image.");
                 psFree(interp);
@@ -120,5 +123,11 @@
                 return false;
             }
-            outData[y-outRow0][x-outCol0] = value;
+            outImageData[y-outRow0][x-outCol0] = imageValue;
+            if (inVar) {
+                outVarData[y-outRow0][x-outCol0] = varValue;
+            }
+            if (inMask) {
+                outMaskData[y-outRow0][x-outCol0] = maskValue;
+            }
         }
     }
