Index: /trunk/psLib/src/image/psImageExtraction.c
===================================================================
--- /trunk/psLib/src/image/psImageExtraction.c	(revision 1923)
+++ /trunk/psLib/src/image/psImageExtraction.c	(revision 1924)
@@ -9,6 +9,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.17 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-28 23:26:48 $
+ *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-29 01:10:27 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -146,10 +146,10 @@
                            const char* section)
 {
-    int x1;
-    int x2;
-    int y1;
-    int y2;
-
-    // section should be of the form '[x1:x2,y1:y2]'
+    int col0;
+    int col1;
+    int row0;
+    int row1;
+
+    // section should be of the form '[col0:col1,row0:row1]'
     if (section == NULL) {
         psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSubsection",
@@ -159,5 +159,5 @@
     }
 
-    if (sscanf(section,"[%d:%d,%d:%d]",&x1,&x2,&y1,&y2) < 4) {
+    if (sscanf(section,"[%d:%d,%d:%d]",&col0,&col1,&row0,&row1) < 4) {
         psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSubsection",
                    PS_ERR_BAD_PARAMETER_NULL, true,
@@ -166,8 +166,8 @@
         return NULL;
     }
-    return imageSubset(NULL,image,x1,y1,x2,y2);
+    return imageSubset(NULL,image,col0,row0,col1,row1);
 }
 
-psImage* psImageTrim(psImage* image, int x0, int y0, int x1, int y1)
+psImage* psImageTrim(psImage* image, int col0, int row0, int col1, int row1)
 {
     if (image == NULL || image->data.V == NULL) {
@@ -181,18 +181,20 @@
         return imageSubset(image,
                            (psImage*)image->parent,
-                           x0+image->col0,
-                           y0+image->row0,
-                           x1+image->col0,
-                           y1+image->row0);
-    }
-
-    if (x0 < 0 || x1 < 0 || y0 < 0 || y1 < 0 ||
-            x0 >= image->numCols || x1 >= image->numCols ||
-            y0 >= image->numRows || y1 >= image->numRows ||
-            x0 > x1 || y0 > y1 ) {
+                           col0+image->col0,
+                           row0+image->row0,
+                           col1+image->col0,
+                           row1+image->row0);
+    }
+
+    if (    col0 < 0 ||
+            row0 < 0 ||
+            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,
-                   x0, x1, y0, y1,
+                   col0, col1, row0, row1,
                    image->numCols, image->numRows);
         return NULL;
@@ -202,10 +204,10 @@
 
     unsigned int elementSize = PSELEMTYPE_SIZEOF(image->type.type);
-    unsigned int numCols = x1-x0+1;
-    unsigned int numRows = y1-y0+1;
+    unsigned int numCols = col1-col0+1;
+    unsigned int numRows = row1-row0+1;
     unsigned int rowSize = elementSize*numCols;
-    unsigned int colOffset = elementSize * x0;
+    unsigned int colOffset = elementSize * col0;
     void* imageData = image->rawDataBuffer;
-    for (int row = y0; row < y1; row++) {
+    for (int row = row0; row < row1; row++) {
         memmove(imageData,image->data.U8[row] + colOffset,rowSize);
         imageData = (psU8*)imageData + rowSize;
@@ -399,8 +401,8 @@
                        const psImage* restrict mask,
                        unsigned int maskVal,
-                       unsigned int col,
-                       unsigned int row,
-                       unsigned int numCols,
-                       unsigned int numRows,
+                       int col0,
+                       int row0,
+                       int col1,
+                       int row1,
                        psImageCutDirection direction,
                        const psStats* stats)
@@ -422,9 +424,23 @@
     }
 
-    if (numRows < 1 || numCols < 1) {
+    if (col1 < 0) {
+        col1 += in->numCols;
+    }
+
+    if (row1 < 0) {
+        row1 += in->numRows;
+    }
+
+    if (    col0 < 0 ||
+            row0 < 0 ||
+            col1 >= in->numCols ||
+            row1 >= in->numRows ||
+            col0 >= col1 ||
+            row0 >= row1) {
         psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice",
-                   PS_ERR_BAD_PARAMETER_NULL, true,
-                   PS_ERRORTEXT_psImage_SUBSET_ZERO_SIZE,
-                   col,col+numCols,row,row+numRows);
+                   PS_ERR_BAD_PARAMETER_VALUE, true,
+                   PS_ERRORTEXT_psImage_SUBSET_RANGE_INVALID,
+                   col0, col1, row0, row1,
+                   in->numCols, in->numRows);
         psFree(out);
         return NULL;
@@ -437,19 +453,4 @@
     if (direction == PS_CUT_X_NEG || direction == PS_CUT_Y_NEG) {
         delta = -1;
-    }
-    // if numRows/numCols is negative, invert the
-    // problem to give positive
-    // numRows/numCols (and cut in opposite
-    // direction).
-    if (numRows < 0) {
-        numRows = -numRows;
-        row -= (numRows - 1);
-        delta = -delta;
-    }
-
-    if (numCols < 0) {
-        numCols = -numCols;
-        col -= (numCols - 1);
-        delta = -delta;
     }
 
@@ -474,14 +475,4 @@
     }
 
-    if (row >= inRows || col >= inCols || col + numCols > inCols || row + numRows > inRows) {
-        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice",
-                   PS_ERR_BAD_PARAMETER_VALUE, true,
-                   PS_ERRORTEXT_psImage_SUBSET_RANGE_INVALID,
-                   col, row, col+numCols, row+numRows,
-                   inCols, inRows);
-        psFree(out);
-        return NULL;
-    }
-
     if (stats == NULL) {
         psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice",
@@ -505,4 +496,7 @@
     myStats = psAlloc(sizeof(psStats));
     *myStats = *stats;
+
+    int numCols = col1-col0;
+    int numRows = row1-row0;
 
     if (direction == PS_CUT_X_POS || direction == PS_CUT_X_NEG) {
@@ -534,12 +528,12 @@
     case PS_TYPE_##TYPE: { \
             psMaskType* maskVecData = NULL; \
-            for (int c=0;c<numCols;c++) { \
-                ps##TYPE *imgData = in->data.TYPE[row] + col + c; \
+            for (int c=col0;c<col1;c++) { \
+                ps##TYPE *imgData = in->data.TYPE[row0] + c; \
                 ps##TYPE *imgVecData = imgVec->data.TYPE; \
                 if (maskVec != NULL) { \
                     maskVecData = maskVec->data.V; \
-                    maskData = (psMaskType* )(mask->data.V[row]) + col + c; \
+                    maskData = (psMaskType* )(mask->data.V[row0]) + c; \
                 } \
-                for (int r=0;r<numRows;r++) { \
+                for (int r=row0;r<row1;r++) { \
                     *(imgVecData++) = *imgData; \
                     imgData += inCols; \
@@ -553,5 +547,5 @@
                 *outData = statVal; \
                 if (outPosition != NULL) { \
-                    *outPosition = col+c; \
+                    *outPosition = c; \
                     outPosition += delta; \
                 } \
@@ -594,6 +588,5 @@
         psU32* outPosition = NULL;
 
-        // fill in psVectors to fake out the
-        // statistics functions.
+        // fill in psVector to fake out the statistics functions.
         imgVec = psAlloc(sizeof(psVector));
         imgVec->type = in->type;
@@ -614,16 +607,16 @@
         outData = out->data.F64;
         if (delta < 0) {
-            outData += numRows - 1;
+            outData += numRows-1;
             if (outPosition != NULL) {
-                outPosition += numRows - 1;
+                outPosition += numRows-1;
             }
         }
 
-        for (int r = 0; r < numRows; r++) {
+        for (int r = row0; r < row1; r++) {
             // point the vector struct to the
             // data to calculate the stats
-            imgVec->data.V = (void *)(in->data.U8[row + r] + col * elementSize);
+            imgVec->data.V = (void *)(in->data.U8[r] + col0 * elementSize);
             if (maskVec != NULL) {
-                maskVec->data.V = (void *)(mask->data.U8[row + r] + col * sizeof(psMaskType));
+                maskVec->data.V = (void *)(mask->data.U8[r] + col0 * sizeof(psMaskType));
             }
             myStats = psVectorStats(myStats, imgVec, maskVec, maskVal);
@@ -631,5 +624,5 @@
             *outData = statVal;
             if (outPosition != NULL) {
-                *outPosition = row + r;
+                *outPosition = r;
                 outPosition += delta;
 
Index: /trunk/psLib/src/image/psImageExtraction.h
===================================================================
--- /trunk/psLib/src/image/psImageExtraction.h	(revision 1923)
+++ /trunk/psLib/src/image/psImageExtraction.h	(revision 1924)
@@ -10,6 +10,6 @@
 *  @author Robert DeSonia, MHPCC
 *
-*  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-09-28 23:26:48 $
+*  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-09-29 01:10:27 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -114,12 +114,22 @@
 /** Extract pixels from rectlinear region to a vector (array of floats).
  *
- *  The output vector contains either nx or ny elements, based on the value of 
- *  the direction: e.g., if direction is PS_CUT_X_POS, there are nx elements.
- *  The input region is collapsed in the perpendicular direction, and each 
- *  element of the output vectors is derived from the statistics of the pixels
- *  at that direction coordinate. The statistic used to derive the output 
- *  vector value is specified by stats. Only one of the statistics choices may 
- *  be specified, otherwise the function must return an error. This function 
- *  must be defined for the following types: psS8, psU16, psF32, psF64.
+ *  The output vector contains either col1-col0 or row1-row0 elements, based 
+ *  on the value of the direction: e.g., if direction is PS_CUT_X_POS, there 
+ *  are col1-col0 elements. The region to be  sliced  is defined by the 
+ *  lower-left corner, (col0,row0), and the upper-right corner, (col1,row1). 
+ *  Note that the row and column of the  upper right-hand corner  are NOT 
+ *  included in the region. In the event that col1 or row1 are negative, they
+ *  shall be interpreted as being relative to the size of the parent image in 
+ *  that dimension. The input region is collapsed in the direction perpendicular 
+ *  to that specified by direction, and each element of the output vectors is 
+ *  derived from the statistics of the pixels at that direction coordinate. The
+ *  statistic used to derive the output vector value is specified by stats. 
+ *  If mask is non-NULL, pixels for which the corresponding mask pixel 
+ *  matches maskVal are excluded from operations. If coords is not NULL, the 
+ *  calculated coordinates along the slice are returned in this vector. Only 
+ *  one of the statistics choices may be specified, otherwise the function 
+ *  must return an error.
+ *
+ *  This function is defined for the following types: psS8, psU16, psF32, psF64.
  *
  * @return psVector    the resulting vector
@@ -134,8 +144,8 @@
     const psImage* restrict mask,      ///< the mask for the input image.
     unsigned int maskVal,              ///< the mask value to apply to the mask
-    unsigned int col,                  ///< the leftmost column of the slice region
-    unsigned int row,                  ///< the bottommost row of the slice region
-    unsigned int numCols,              ///< the number of columns in the slice region
-    unsigned int numRows,              ///< the number of rows in the slice region
+    int col0,                          ///< the leftmost column of the slice region
+    int row0,                          ///< the bottommost row of the slice region
+    int col1,                          ///< exclusive end column of the slice region
+    int row1,                           ///< exclusive end row of the slice region
     psImageCutDirection direction,     ///< the slice dimension and direction
     const psStats* stats               ///< the statistic to perform in slice operation
Index: /trunk/psLib/test/image/tst_psImageExtraction.c
===================================================================
--- /trunk/psLib/test/image/tst_psImageExtraction.c	(revision 1923)
+++ /trunk/psLib/test/image/tst_psImageExtraction.c	(revision 1924)
@@ -6,6 +6,6 @@
 *  @author Robert DeSonia, MHPCC
 *
-*  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-09-11 02:55:29 $
+*  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-09-29 01:10:27 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -20,10 +20,6 @@
 
 testDescription tests[] = {
-                              {
-                                  testImageSlice, 552, "psImageSlice", 0, false
-                              },
-                              {
-                                  NULL
-                              }
+                              {testImageSlice, 552, "psImageSlice", 0, false},
+                              {NULL}
                           };
 
@@ -72,5 +68,5 @@
 
     #define PSIMAGESLICE_TEST1(M,N,DIRECTION,TRUTH_SIZE,TRUTHPIX_X,TRUTHPIX_Y,TESTNUM) \
-    out = psImageSlice(out,positions,image,mask,1,c/10,r/10,M,N,DIRECTION,stat); \
+    out = psImageSlice(out,positions,image,mask,1,c/10,r/10,c/10+M,r/10+N,DIRECTION,stat); \
     \
     if (out->n != TRUTH_SIZE) { \
@@ -136,5 +132,11 @@
     */
     psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." );
-    out = psImageSlice( out, NULL, NULL, NULL, 0, c / 10, r / 10, 1, 1, PS_CUT_X_POS, stat );
+    out = psImageSlice( out,
+                        NULL, NULL,
+                        NULL, 0,
+                        c/10, r/10,
+                        c/10 + 1, r/10 + 1,
+                        PS_CUT_X_POS,
+                        stat );
     if ( out != NULL ) {
         psError( __func__, "Giving a NULL image, psImageSlice didn't return NULL as expected" );
@@ -148,5 +150,12 @@
     */
     psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." );
-    out = psImageSlice( out, NULL, image, mask, 1, c / 10, r / 10, 1, 1, PS_CUT_X_POS, NULL );
+    out = psImageSlice( out,
+                        NULL, image,
+                        mask, 1,
+                        c/10, r/10,
+                        c/10 + 1,
+                        r/10 + 1,
+                        PS_CUT_X_POS,
+                        NULL );
     if ( out != NULL ) {
         psError( __func__, "Giving a NULL stat struct, psImageSlice didn't return NULL as expected" );
@@ -161,5 +170,11 @@
     */
     psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." );
-    out = psImageSlice( out, NULL, image, mask, 1, c / 10, r / 10, 1, 1, 5, stat );
+    out = psImageSlice( out, NULL,
+                        image,
+                        mask, 1,
+                        c/10, r/10,
+                        c/10+1, r/10+1,
+                        5,
+                        stat);
     if ( out != NULL ) {
         psError( __func__, "Giving a bogus direction flag, psImageSlice didn't return NULL as expected" );
@@ -172,5 +187,12 @@
     */
     psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." );
-    out = psImageSlice( out, NULL, image, mask, 1, c / 10, r / 10, 0, 0, PS_CUT_X_POS, stat );
+    out = psImageSlice( out,
+                        NULL,
+                        image,
+                        mask, 1,
+                        c/10, r/10,
+                        c/10, r/10,
+                        PS_CUT_X_POS,
+                        stat );
     if ( out != NULL ) {
         psError( __func__, "Giving a 0x0 region, psImageSlice didn't return NULL as expected" );
@@ -184,5 +206,11 @@
     */
     psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." );
-    out = psImageSlice( out, NULL, image, mask, 1, c + 1, r / 10, 1, 1, PS_CUT_X_POS, stat );
+    out = psImageSlice( out, NULL,
+                        image,
+                        mask, 1,
+                        c+1, r/10,
+                        c+2, r/10+10,
+                        PS_CUT_X_POS,
+                        stat );
     if ( out != NULL ) {
         psError( __func__, "Giving an invalid x position, psImageSlice didn't return NULL as expected" );
@@ -191,5 +219,11 @@
 
     psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." );
-    out = psImageSlice( out, NULL, image, mask, 1, c / 10, r + 1, 1, 1, PS_CUT_X_POS, stat );
+    out = psImageSlice( out, NULL,
+                        image,
+                        mask, 1,
+                        c/10, r+1,
+                        c/10+1,r+5,
+                        PS_CUT_X_POS,
+                        stat );
     if ( out != NULL ) {
         psError( __func__, "Giving an invalid y position, psImageSlice didn't return NULL as expected" );
@@ -198,5 +232,11 @@
 
     psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." );
-    out = psImageSlice( out, NULL, image, mask, 1, c / 10, r / 10, c, 1, PS_CUT_X_POS, stat );
+    out = psImageSlice( out, NULL,
+                        image,
+                        mask, 1,
+                        c/10, r/10,
+                        c+1, r/10+1,
+                        PS_CUT_X_POS,
+                        stat);
     if ( out != NULL ) {
         psError( __func__, "Giving an invalid numCols, psImageSlice didn't return NULL as expected" );
@@ -205,5 +245,11 @@
 
     psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." );
-    out = psImageSlice( out, NULL, image, mask, 1, c / 10, r / 10, 1, r, PS_CUT_X_POS, stat );
+    out = psImageSlice( out, NULL,
+                        image,
+                        mask, 1,
+                        c/10, r/10,
+                        c/10+1, r + 1,
+                        PS_CUT_X_POS,
+                        stat);
     if ( out != NULL ) {
         psError( __func__, "Giving an invalid numRows, psImageSlice didn't return NULL as expected" );
@@ -218,5 +264,11 @@
     psLogMsg( __func__, PS_LOG_INFO, "Following should be an error." );
     stat->options = 0;
-    out = psImageSlice( out, NULL, image, mask, 1, c / 10, r / 10, 1, 1, PS_CUT_X_POS, stat );
+    out = psImageSlice( out, NULL,
+                        image,
+                        mask, 1,
+                        c/10, r/10,
+                        c/10+1, r/10+1,
+                        PS_CUT_X_POS,
+                        stat);
     if ( out != NULL ) {
         psError( __func__, "Giving an invalid numRows, psImageSlice didn't return NULL as expected" );
Index: /trunk/psLib/test/image/verified/tst_psImageExtraction.stderr
===================================================================
--- /trunk/psLib/test/image/verified/tst_psImageExtraction.stderr	(revision 1923)
+++ /trunk/psLib/test/image/verified/tst_psImageExtraction.stderr	(revision 1924)
@@ -20,21 +20,21 @@
     Following should be an error.
 <DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
-    Specified subset, [200:<LINENO>,100:<LINENO>], contains no pixel data.
+    Specified subset range, [200:<LINENO>,100:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
 <DATE><TIME>|<HOST>|I|testImageSlice
     Following should be an error.
 <DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
-    Specified subset range, [2001:<LINENO>,2002:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
+    Specified subset range, [2001:<LINENO>,100:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
 <DATE><TIME>|<HOST>|I|testImageSlice
     Following should be an error.
 <DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
-    Specified subset range, [200:<LINENO>,201:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
+    Specified subset range, [200:<LINENO>,1001:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
 <DATE><TIME>|<HOST>|I|testImageSlice
     Following should be an error.
 <DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
-    Specified subset range, [200:<LINENO>,2200:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
+    Specified subset range, [200:<LINENO>,100:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
 <DATE><TIME>|<HOST>|I|testImageSlice
     Following should be an error.
 <DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
-    Specified subset range, [200:<LINENO>,201:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
+    Specified subset range, [200:<LINENO>,100:<LINENO>], is invalid or outside input psImage's boundaries, [0:<LINENO>,0:<LINENO>].
 <DATE><TIME>|<HOST>|I|testImageSlice
     Following should be an error.
