Index: trunk/psLib/src/imageops/psImagePixelExtract.c
===================================================================
--- trunk/psLib/src/imageops/psImagePixelExtract.c	(revision 6805)
+++ trunk/psLib/src/imageops/psImagePixelExtract.c	(revision 6806)
@@ -8,6 +8,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-04-06 04:12:27 $
+ *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-04-06 22:55:18 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -334,4 +334,12 @@
     }
 
+    //If [0,0,0,0] specified, the whole image is to be included
+    if (row0 == 0 && col0 == 0 && row1 == 0 && col1 == 0) {
+        row0 = input->row0;
+        col0 = input->col0;
+        row1 = input->row0 + input->numRows - 1;
+        col1 = input->col0 + input->numCols - 1;
+    }
+
     //Make sure x0 of region is inside image.  If so, set col0 to corresponding index number.
     if (col0 >= input->col0 && col0 < (input->col0 + input->numCols) ) {
@@ -341,4 +349,5 @@
                 "Specified psRegion parameter, x0=%f, is out of range [%d,%d].\n",
                 region.x0, input->col0, input->col0+input->numCols-1);
+        psFree(out);
         return NULL;
     }
@@ -350,13 +359,6 @@
                 "Specified psRegion parameter, y0=%f, is out of range [%d,%d].\n",
                 region.y0, input->row0, input->row0+input->numRows-1);
-        return NULL;
-    }
-
-    //If [0,0,0,0] specified, the whole image is to be included
-    if (row0 == 0 && col0 == 0 && row1 == 0 && col1 == 0) {
-        row0 = input->row0;
-        col0 = input->col0;
-        row1 = input->row0 + input->numRows;
-        col1 = input->col0 + input->numCols;
+        psFree(out);
+        return NULL;
     }
 
@@ -368,4 +370,5 @@
                     "Specified psRegion parameter, x1=%f=%d, is out of range [%d,%d].\n",
                     region.x1, col1+input->col0, input->col0, input->col0+input->numCols-1);
+            psFree(out);
             return NULL;
         }
@@ -376,4 +379,5 @@
                 "Specified psRegion parameter, x1=%f=%d, is out of range [%d,%d].\n",
                 region.x1, col1, input->col0, input->col0+input->numCols-1);
+        psFree(out);
         return NULL;
     }
@@ -385,4 +389,5 @@
                     "Specified psRegion parameter, y1=%f=%d, is out of range [%d,%d].\n",
                     region.y1, row1+input->row0, input->row0, input->row0+input->numRows-1);
+            psFree(out);
             return NULL;
         }
@@ -393,4 +398,5 @@
                 "Specified psRegion parameter, y1=%f=%d, is out of range [%d,%d].\n",
                 region.y1, row1, input->row0, input->row0+input->numRows-1);
+        psFree(out);
         return NULL;
     }
@@ -406,8 +412,10 @@
                     region.y0, row0, region.y1, row1);
         }
+        psFree(out);
         return NULL;
     } else if (col0 == col1 && row0 == row1) {
         psError(PS_ERR_BAD_PARAMETER_VALUE, true,
                 "Invalid psRegion specified.  Region contains only 1 pixel.\n");
+        psFree(out);
         return NULL;
     }
@@ -679,6 +687,6 @@
         row0 = input->row0;
         col0 = input->col0;
-        row1 = input->row0 + input->numRows;
-        col1 = input->col0 + input->numCols;
+        row1 = input->row0 + input->numRows - 1;
+        col1 = input->col0 + input->numCols - 1;
     }
 
