Index: trunk/psLib/src/imageops/psImageStats.c
===================================================================
--- trunk/psLib/src/imageops/psImageStats.c	(revision 5530)
+++ trunk/psLib/src/imageops/psImageStats.c	(revision 5783)
@@ -9,6 +9,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.84 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-11-16 23:06:14 $
+ *  @version $Revision: 1.85 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-12-14 00:47:27 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -652,17 +652,25 @@
         return -1;
     }
-    if (region.x1 > mask->numCols || region.y1 > mask->numRows) {
-        psError(PS_ERR_BAD_PARAMETER_SIZE, true,
-                "psRegion input is outside of image boundary\n");
-        return -1;
-    }
-    if (region.x0 <= 0 || region.x1 <= 0 || region.y0 <= 0 || region.y1 <= 0) {
-        region = psRegionForImage(mask, region);
-    }
-    if (region.x0 > region.x1 || region.y0 > region.y1) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
-                "Invalid region.  Lower boundary greater than upper boundary.\n");
-        return -1;
-    }
+
+    // this is not a valid error: a psRegion with ranges outside the valid pixels
+    // should saturate on the valid pixels, not result in an error (per SDRS)
+    //    if (region.x1 > mask->numCols || region.y1 > mask->numRows) {
+    //        psError(PS_ERR_BAD_PARAMETER_SIZE, true,
+    //                "psRegion input is outside of image boundary\n");
+    //        return -1;
+    //    }
+    //    if (region.x0 <= 0 || region.x1 <= 0 || region.y0 <= 0 || region.y1 <= 0) {
+    //        region = psRegionForImage(mask, region);
+    //    }
+    // not a valid error: if region coordinates are out of order, they should be flipped
+    //    if (region.x0 > region.x1 || region.y0 > region.y1) {
+    //        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+    //               "Invalid region.  Lower boundary greater than upper boundary.\n");
+    //        return -1;
+    //    }
+
+    // rationalize the region
+    region = psRegionForImage(mask, region);
+
     if (region.x0 == region.x1 || region.y0 == region.y1) {
         psError(PS_ERR_BAD_PARAMETER_SIZE, true,
@@ -686,7 +694,7 @@
     case PS_TYPE_U8:
     case PS_TYPE_U16:
-        for (long i = x0; i < x1; i++) {
-            for (long j = y0; j < y1; j++) {
-                if (mask->data.PS_TYPE_MASK_DATA[i][j] & value) {
+        for (long j = y0; j < y1; j++) {
+            for (long i = x0; i < x1; i++) {
+                if (mask->data.PS_TYPE_MASK_DATA[j][i] & value) {
                     Npixels ++;
                 }
