Index: /branches/eam_rel8_b2/psLib/src/imageops/psImageStats.c
===================================================================
--- /branches/eam_rel8_b2/psLib/src/imageops/psImageStats.c	(revision 5594)
+++ /branches/eam_rel8_b2/psLib/src/imageops/psImageStats.c	(revision 5595)
@@ -9,6 +9,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.83.4.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-11-16 22:50:22 $
+ *  @version $Revision: 1.83.4.1.4.1 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-11-25 23:24:49 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -652,17 +652,9 @@
         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;
-    }
+
+    // rationalize the region
+    region = psRegionForImage(mask, region);
+
+    // XXX EAM : should this really be an error, or simply return 0?
     if (region.x0 == region.x1 || region.y0 == region.y1) {
         psError(PS_ERR_BAD_PARAMETER_SIZE, true,
@@ -686,7 +678,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 ++;
                 }
