Index: /trunk/psLib/src/mathtypes/psImage.c
===================================================================
--- /trunk/psLib/src/mathtypes/psImage.c	(revision 6578)
+++ /trunk/psLib/src/mathtypes/psImage.c	(revision 6579)
@@ -9,6 +9,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.97 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-03-14 03:25:48 $
+ *  @version $Revision: 1.98 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-03-14 03:35:14 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -168,5 +168,5 @@
 // - flip x0,x1 if x0>x1
 // - flip y0,y1 if y0>y1
-// psRegion in refers to coordinates in the
+// XXX EAM : psRegion refers to coordinates in the *parent* image
 psRegion psRegionForImage(psImage *image,
                           psRegion in)
@@ -178,16 +178,18 @@
 
     // convert non-positive upper-limits
-    in.x1 = (in.x1 <= 0) ? (image->numCols + in.x1) : in.x1;
-    in.y1 = (in.y1 <= 0) ? (image->numRows + in.y1) : in.y1;
-
-    // force the upper-limits to be on the image
-    in.x1 = PS_MIN(image->numCols, in.x1);
-    in.y1 = PS_MIN(image->numRows, in.y1);
-
-    // force the lower-limits to be on the image
-    in.x0 = PS_MAX(0, in.x0);
-    in.y0 = PS_MAX(0, in.y0);
-    in.x0 = PS_MIN(image->numCols, in.x0);
-    in.y0 = PS_MIN(image->numRows, in.y0);
+    // XXX note that the upper limit in these cases is defined relative to the subimage
+    // also note that truncation limits to the valid subimage pixels
+    in.x1 = (in.x1 <= 0) ? (image->col0 + image->numCols + in.x1) : in.x1;
+    in.y1 = (in.y1 <= 0) ? (image->row0 + image->numRows + in.y1) : in.y1;
+
+    // force the upper-limits to be on the subimage
+    in.x1 = PS_MIN(image->col0 + image->numCols, in.x1);
+    in.y1 = PS_MIN(image->row0 + image->numRows, in.y1);
+
+    // force the lower-limits to be on the subimage
+    in.x0 = PS_MAX(image->col0, in.x0);
+    in.y0 = PS_MAX(image->row0, in.y0);
+    in.x0 = PS_MIN(image->col0 + image->numCols, in.x0);
+    in.y0 = PS_MIN(image->row0 + image->numRows, in.y0);
 
     // flip start and end if out of order
@@ -300,5 +302,5 @@
             return false;
         }
-     
+
         if(x < 0)
             x += image->numRows;
@@ -307,5 +309,5 @@
             return false;
         }
-     
+
         if(y < 0)
             y += image->numCols;
@@ -314,5 +316,5 @@
             return false;
         }
-     
+
     */
     PS_ASSERT_IMAGE_NON_NULL(image, false);
@@ -422,5 +424,5 @@
             return NAN;
         }
-     
+
         if(x < 0)
             x += image->numRows;
@@ -429,5 +431,5 @@
             return NAN;
         }
-     
+
         if(y < 0)
             y += image->numCols;
