Index: trunk/psLib/src/image/psImageExtraction.c
===================================================================
--- trunk/psLib/src/image/psImageExtraction.c	(revision 2067)
+++ trunk/psLib/src/image/psImageExtraction.c	(revision 2074)
@@ -9,6 +9,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-13 00:10:50 $
+ *  @version $Revision: 1.23 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-13 02:40:13 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -195,15 +195,24 @@
     }
 
+    if (col1 < 1) {
+        col1 += image->numCols;
+    }
+
+    if (row1 < 1) {
+        row1 += image->numRows;
+    }
+
     if (    col0 < 0 ||
             row0 < 0 ||
-            col1 >= image->numCols ||
-            row1 >= image->numRows ||
-            col0 > col1 ||
-            row0 > row1 ) {
+            col1 > image->numCols ||
+            row1 > image->numRows ||
+            col0 >= col1 ||
+            row0 >= row1 ) {
         psErrorMsg(PS_ERRORNAME_DOMAIN "psImageTrim",
                    PS_ERR_BAD_PARAMETER_VALUE, true,
                    PS_ERRORTEXT_psImage_SUBSET_RANGE_INVALID,
-                   col0, col1, row0, row1,
-                   image->numCols, image->numRows);
+                   col0, col1-1, row0, row1-1,
+                   image->numCols-1, image->numRows-1);
+        psFree(image);
         return NULL;
     }
@@ -212,12 +221,12 @@
 
     unsigned int elementSize = PSELEMTYPE_SIZEOF(image->type.type);
-    unsigned int numCols = col1-col0+1;
-    unsigned int numRows = row1-row0+1;
+    unsigned int numCols = col1-col0;
+    unsigned int numRows = row1-row0;
     unsigned int rowSize = elementSize*numCols;
     unsigned int colOffset = elementSize * col0;
-    void* imageData = image->rawDataBuffer;
+    psU8* imageData = image->rawDataBuffer;
     for (int row = row0; row < row1; row++) {
         memmove(imageData,image->data.U8[row] + colOffset,rowSize);
-        imageData = (psU8*)imageData + rowSize;
+        imageData += rowSize;
     }
 
@@ -265,9 +274,9 @@
     }
 
-    if (col1 < 0) {
+    if (col1 < 1) {
         col1 += in->numCols;
     }
 
-    if (row1 < 0) {
+    if (row1 < 1) {
         row1 += in->numRows;
     }
@@ -275,6 +284,6 @@
     if (    col0 < 0 ||
             row0 < 0 ||
-            col1 >= in->numCols ||
-            row1 >= in->numRows ||
+            col1 > in->numCols ||
+            row1 > in->numRows ||
             col0 >= col1 ||
             row0 >= row1) {
