Index: trunk/pswarp/src/pswarpTransformTile.c
===================================================================
--- trunk/pswarp/src/pswarpTransformTile.c	(revision 18839)
+++ trunk/pswarp/src/pswarpTransformTile.c	(revision 18890)
@@ -34,6 +34,6 @@
     int outCol0 = args->output->image->col0;
     int outRow0 = args->output->image->row0;
-    // int outNcol = args->output->image->numCols;
-    // int outNrow = args->output->image->numRows;
+    int outNcol = args->output->image->numCols;
+    int outNrow = args->output->image->numRows;
 
     // get the coordinate range for this grid tile
@@ -56,8 +56,15 @@
     psMaskType maskValue;
 
+    // Bounds for iteration
+    int xMin = PS_MAX(minPt.x, 0);
+    int xMax = PS_MIN(maxPt.x, outNcol);
+    int yMin = PS_MAX(minPt.y, 0);
+    int yMax = PS_MIN(maxPt.y, outNrow);
+
+
     // Iterate over the output image pixels (parent frame)
     long goodPixels = 0;                // Number of input pixels landing on the output image
-    for (int y = minPt.y; y < maxPt.y; y++) {
-        for (int x = minPt.x; x < maxPt.x; x++) {
+    for (int y = yMin; y < yMax; y++) {
+        for (int x = xMin; x < xMax; x++) {
 
             // Only transform those pixels requested
@@ -68,6 +75,6 @@
             pswarpMapApply (&xInRaw, &yInRaw, map, x + 0.5, y + 0.5);
 
-            double xIn = xInRaw - outCol0;	// Position on input image
-	    double yIn = yInRaw - outRow0;	// Position on input image
+            double xIn = xInRaw - outCol0;      // Position on input image
+            double yIn = yInRaw - outRow0;      // Position on input image
 
             if (xIn < 0) continue;
@@ -85,10 +92,10 @@
 
             int xOut = x - outCol0;     // Position on output image
-	    int yOut = y - outRow0;	// Position on output image
+            int yOut = y - outRow0;     // Position on output image
 
-	    // not all images need be transformed
-	    if (outImageData) {
-		outImageData[yOut][xOut] = imageValue;
-	    }
+            // not all images need be transformed
+            if (outImageData) {
+                outImageData[yOut][xOut] = imageValue;
+            }
             if (outVarData) {
                 outVarData[yOut][xOut] = varValue;
