Index: /trunk/pswarp/src/pswarpPixelFraction.c
===================================================================
--- /trunk/pswarp/src/pswarpPixelFraction.c	(revision 17779)
+++ /trunk/pswarp/src/pswarpPixelFraction.c	(revision 17780)
@@ -39,4 +39,7 @@
     long numPix = numCols * numRows;
 
+    // Range of valid pixels
+    int xMin = INT_MAX, xMax = -INT_MAX, yMin = INT_MAX, yMax = -INT_MAX;
+
     long numBad = 0;                     // Number of bad pixels
     for (int y = 0; y < numRows; y++) {
@@ -44,4 +47,17 @@
             if (mask->data.PS_TYPE_MASK_DATA[y][x] & maskVal) {
                 numBad++;
+            } else {
+                if (y > yMax) {
+                    yMax = y;
+                }
+                if (y < yMin) {
+                    yMin = y;
+                }
+                if (x > xMax) {
+                    xMax = x;
+                }
+                if (x < xMin) {
+                    xMin = x;
+                }
             }
         }
@@ -53,4 +69,9 @@
     if (stats) {
         psMetadataAddBool(stats, PS_LIST_HEAD, "ACCEPT", 0, "Accept this readout?", accept);
+
+        psMetadataAddS32(stats, PS_LIST_TAIL, "RANGE.XMIN", 0, "Minimum valid x value", xMin);
+        psMetadataAddS32(stats, PS_LIST_TAIL, "RANGE.XMAX", 0, "Maximum valid x value", xMax);
+        psMetadataAddS32(stats, PS_LIST_TAIL, "RANGE.YMIN", 0, "Minimum valid y value", yMin);
+        psMetadataAddS32(stats, PS_LIST_TAIL, "RANGE.YMAX", 0, "Maximum valid y value", yMax);
     }
 
Index: /trunk/pswarp/src/pswarpTransformReadout_Opt.c
===================================================================
--- /trunk/pswarp/src/pswarpTransformReadout_Opt.c	(revision 17779)
+++ /trunk/pswarp/src/pswarpTransformReadout_Opt.c	(revision 17780)
@@ -97,4 +97,5 @@
         nextGridX = nextGridXo;
         map = grid->maps[gridX][gridY];
+        int yOut = y - outRow0;         // Position on image
         for (int x = minX; x < maxX; x++) {
             if (x >= nextGridX) {
@@ -127,21 +128,21 @@
                 psError(PS_ERR_UNKNOWN, false, "Unable to interpolate image.");
                 psFree(interp);
-                psFree (inPix);
-                psFree (grid);
+                psFree(inPix);
+                psFree(grid);
                 return false;
             }
-            outImageData[y-outRow0][x-outCol0] = imageValue;
+            int xOut = x - outCol0;     // Position on image
+            outImageData[yOut][xOut] = imageValue;
             if (inVar) {
-                outVarData[y-outRow0][x-outCol0] = varValue;
+                outVarData[yOut][xOut] = varValue;
             }
             if (outMaskData) {
-                outMaskData[y-outRow0][x-outCol0] = maskValue;
-            }
-        }
-    }
-
+                outMaskData[yOut][xOut] = maskValue;
+            }
+        }
+    }
     psFree(interp);
-    psFree (inPix);
-    psFree (grid);
+    psFree(inPix);
+    psFree(grid);
 
     // Transform sources
