Index: /trunk/psLib/src/mathtypes/psImage.c
===================================================================
--- /trunk/psLib/src/mathtypes/psImage.c	(revision 6577)
+++ /trunk/psLib/src/mathtypes/psImage.c	(revision 6578)
@@ -9,6 +9,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.96 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-03-14 02:22:55 $
+ *  @version $Revision: 1.97 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-03-14 03:25:48 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -319,6 +319,6 @@
     PS_ASSERT_INT_NONNEGATIVE(image->col0, false);
     PS_ASSERT_INT_NONNEGATIVE(image->row0, false);
-    PS_ASSERT_INT_NONNEGATIVE(image->numCols, false);
-    PS_ASSERT_INT_NONNEGATIVE(image->numRows, false);
+    PS_ASSERT_INT_POSITIVE(image->numCols, false);
+    PS_ASSERT_INT_POSITIVE(image->numRows, false);
     if ( x >= (image->col0 + image->numCols) ) {
         psError(PS_ERR_BAD_PARAMETER_SIZE, true,
@@ -414,26 +414,76 @@
                           int y)
 {
-    if (image == NULL) {
-        psError(PS_ERR_BAD_PARAMETER_NULL, true, PS_ERRORTEXT_psImage_IMAGE_NULL);
-        return NAN;
-    }
-    if (x >= image->numRows || y >= image->numCols) {
-        psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Invalid position.  Position too large\n");
-        return NAN;
-    }
-
-    if(x < 0)
-        x += image->numRows;
-    if(x < 0) {
-        psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Invalid x.  Negative number too large\n");
-        return NAN;
-    }
-
-    if(y < 0)
-        y += image->numCols;
-    if(y < 0) {
-        psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Invalid y.  Negative number too large\n");
-        return NAN;
-    }
+    /*    if (image == NULL) {
+            psError(PS_ERR_BAD_PARAMETER_NULL, true, PS_ERRORTEXT_psImage_IMAGE_NULL);
+            return NAN;
+        }
+        if (x >= image->numRows || y >= image->numCols) {
+            psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Invalid position.  Position too large\n");
+            return NAN;
+        }
+     
+        if(x < 0)
+            x += image->numRows;
+        if(x < 0) {
+            psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Invalid x.  Negative number too large\n");
+            return NAN;
+        }
+     
+        if(y < 0)
+            y += image->numCols;
+        if(y < 0) {
+            psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Invalid y.  Negative number too large\n");
+            return NAN;
+        }
+    */
+    PS_ASSERT_IMAGE_NON_NULL(image, NAN);
+    PS_ASSERT_INT_NONNEGATIVE(image->col0, NAN);
+    PS_ASSERT_INT_NONNEGATIVE(image->row0, NAN);
+    PS_ASSERT_INT_POSITIVE(image->numCols, NAN);
+    PS_ASSERT_INT_POSITIVE(image->numRows, NAN);
+    if ( x >= (image->col0 + image->numCols) ) {
+        psError(PS_ERR_BAD_PARAMETER_SIZE, true,
+                "Invalid x-position %d.  Position out of range (%d-%d)\n",
+                x, image->col0, image->numCols+image->col0-1 );
+        return false;
+    } else if ( y >= (image->row0 + image->numRows) ) {
+        psError(PS_ERR_BAD_PARAMETER_SIZE, true,
+                "Invalid y-position %d.  Position out of range (%d-%d)\n",
+                y, image->row0, image->numRows+image->row0-1 );
+        return false;
+    } else if (x < image->col0 && x >= 0) {
+        psError(PS_ERR_BAD_PARAMETER_SIZE, true,
+                "Invalid x-position %d.  Position out of range (%d-%d)\n",
+                x, image->col0, image->numCols+image->col0-1 );
+        return false;
+    } else if (y < image->row0 && y >= 0) {
+        psError(PS_ERR_BAD_PARAMETER_SIZE, true,
+                "Invalid y-position %d.  Position out of range (%d-%d)\n",
+                y, image->row0, image->numRows+image->row0-1 );
+        return false;
+    } else if (x < 0 || y < 0) {
+        if (x < 0) {
+            x += image->numCols;
+        }
+        if (x < 0) {
+            psError(PS_ERR_BAD_PARAMETER_SIZE, true,
+                    "Invalid x-position %d.  Position out of range (%d-%d)\n",
+                    (x+image->col0), image->col0, image->numCols+image->col0-1 );
+            return false;
+        }
+        if (y < 0) {
+            y += image->numRows;
+        }
+        if (y < 0) {
+            psError(PS_ERR_BAD_PARAMETER_SIZE, true,
+                    "Invalid y-position %d.  Position out of range (%d-%d)\n",
+                    (y+image->row0), image->row0, image->numRows+image->row0-1 );
+            return false;
+        }
+    } else {
+        x -= image->col0;
+        y -= image->row0;
+    }
+
 
     switch (image->type.type) {
Index: /trunk/psLib/test/mathtypes/tst_psImage.c
===================================================================
--- /trunk/psLib/test/mathtypes/tst_psImage.c	(revision 6577)
+++ /trunk/psLib/test/mathtypes/tst_psImage.c	(revision 6578)
@@ -6,6 +6,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-03-14 02:22:55 $
+ *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-03-14 03:25:48 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -26,5 +26,6 @@
 static psS32 testRegion3(void);
 static psS32 testImageInit(void);
-static psS32 testImageGetSet(void);
+static psS32 testImageSet(void);
+static psS32 testImageGet(void);
 
 testDescription tests[] = {
@@ -36,5 +37,6 @@
                               {testRegion3,793,"psRegionForSquare",0,false},
                               {testImageInit,794,"psImageInit",0,false},
-                              {testImageGetSet,795,"psImageGetSet",0,false},
+                              {testImageSet,795,"psImageSet",0,false},
+                              {testImageGet,666,"psImageGet",0,false},
                               {NULL}
                           };
@@ -356,5 +358,5 @@
 }
 
-static psS32 testImageGetSet(void)
+static psS32 testImageSet(void)
 {
     psImage *image = NULL;
@@ -471,2 +473,110 @@
     return 0;
 }
+
+static psS32 testImageGet(void)
+{
+    psImage *image = NULL;
+    image = psImageAlloc(5, 5, PS_TYPE_S32);
+
+    //Set the position of the subimage relative to the parent.
+    image->col0 = 10;
+    image->row0 = 10;
+    for (int i = 0; i < 5; i++) {
+        for (int j = 0; j < 5; j++) {
+            image->data.S32[i][j] = i+j;
+        }
+    }
+
+    //Attempt to get a position in a NULL psImage*
+    psImage *none = NULL;
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message");
+    if ( !isnan( psImageGet(none, 1, 1) ) ) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                "psImageGet failed to return false when passed a NULL image.\n");
+        return 1;
+    }
+
+    //Attempt to get a position in a psImage* with negative numCols, numRows
+    none = psImageAlloc(2, 2, PS_TYPE_S32);
+    *(int*)&none->numCols = -1;
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message");
+    if ( !isnan( psImageGet(none, 1, 1) ) ) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                "psImageGet failed to return false when passed an image with negative numCols.\n");
+        return 2;
+    }
+    *(int*)&none->numCols = 2;
+    *(int*)&none->numRows = -1;
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message");
+    if ( !isnan( psImageGet(none, 1, 1) ) ) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                "psImageGet failed to return false when passed an image with negative numRows.\n");
+        return 3;
+    }
+
+    //Attempt to get a position in a psImage* with negative col0, row0
+    *(int*)&none->numRows = 2;
+    none->row0 = -1;
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message");
+    if ( !isnan( psImageGet(none, 1, 1) ) ) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                "psImageGet failed to return false when passed an image with negative col0.\n");
+        return 4;
+    }
+    none->row0 = 0;
+    none->col0 = -1;
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message");
+    if ( !isnan( psImageGet(none, 1, 1) ) ) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                "psImageGet failed to return false when passed an image with negative col0.\n");
+        return 5;
+    }
+    psFree(none);
+
+    //Try to get a position inside of the subimage.
+    if ( psImageGet(image, 13, 14) != 7 ) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                "psImageGet failed to return the correct value.\n");
+        return 6;
+    }
+    //Try to get a position inside of the subimage from the tail.
+    if ( psImageGet(image, -1, -1) != 8 ) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                "psImageGet failed to return the correct value.\n");
+        return 8;
+    }
+
+    //Try to get a position outside of the subimage but inside of the parent image.
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message");
+    if ( isnan( psImageGet(image, 1, 1) ) ) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
+                "psImageGet failed to return NAN when passed an invalid location.\n");
+        return 10;
+    }
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message");
+    if ( isnan( psImageGet(image, 9, 10) ) ) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
+                "psImageGet failed to return NAN when passed an invalid location.\n");
+        return 11;
+    }
+
+    //Try to set a position outside of the subimage.
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message");
+    if ( isnan( psImageGet(image, 15, 14) ) ) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
+                "psImageGet failed to return NAN when passed an invalid location.\n");
+        return 12;
+    }
+    //Try to set a position outside of the subimage, indexing from the tail.
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message");
+    if ( isnan( psImageGet(image, -6, -1) ) ) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
+                "psImageGet failed to return NAN when passed an invalid location.\n");
+        return 13;
+    }
+
+
+    psFree(image);
+    return 0;
+}
+
Index: /trunk/psLib/test/mathtypes/verified/tst_psImage.stderr
===================================================================
--- /trunk/psLib/test/mathtypes/verified/tst_psImage.stderr	(revision 6577)
+++ /trunk/psLib/test/mathtypes/verified/tst_psImage.stderr	(revision 6578)
@@ -130,45 +130,90 @@
 /***************************** TESTPOINT ******************************************\
 *             TestFile: tst_psImage.c                                              *
-*            TestPoint: psImage{psImageGetSet}                                     *
-*             TestType: Positive                                                   *
-\**********************************************************************************/
-
-<DATE><TIME>|<HOST>|I|testImageGetSet
+*            TestPoint: psImage{psImageSet}                                        *
+*             TestType: Positive                                                   *
+\**********************************************************************************/
+
+<DATE><TIME>|<HOST>|I|testImageSet
     Following should generate error message
 <DATE><TIME>|<HOST>|E|psImageSet (FILE:LINENO)
     Unallowable operation: psImage image or its data is NULL.
-<DATE><TIME>|<HOST>|I|testImageGetSet
-    Following should generate error message
-<DATE><TIME>|<HOST>|E|psImageSet (FILE:LINENO)
-    Error: image->numCols is less than 0.
-<DATE><TIME>|<HOST>|I|testImageGetSet
-    Following should generate error message
-<DATE><TIME>|<HOST>|E|psImageSet (FILE:LINENO)
-    Error: image->numRows is less than 0.
-<DATE><TIME>|<HOST>|I|testImageGetSet
+<DATE><TIME>|<HOST>|I|testImageSet
+    Following should generate error message
+<DATE><TIME>|<HOST>|E|psImageSet (FILE:LINENO)
+    Error: image->numCols is 0 or less.
+<DATE><TIME>|<HOST>|I|testImageSet
+    Following should generate error message
+<DATE><TIME>|<HOST>|E|psImageSet (FILE:LINENO)
+    Error: image->numRows is 0 or less.
+<DATE><TIME>|<HOST>|I|testImageSet
     Following should generate error message
 <DATE><TIME>|<HOST>|E|psImageSet (FILE:LINENO)
     Error: image->row0 is less than 0.
-<DATE><TIME>|<HOST>|I|testImageGetSet
+<DATE><TIME>|<HOST>|I|testImageSet
     Following should generate error message
 <DATE><TIME>|<HOST>|E|psImageSet (FILE:LINENO)
     Error: image->col0 is less than 0.
-<DATE><TIME>|<HOST>|I|testImageGetSet
+<DATE><TIME>|<HOST>|I|testImageSet
     Following should generate error message
 <DATE><TIME>|<HOST>|E|psImageSet (FILE:LINENO)
     Invalid x-position 0.  Position out of range (10-14)
-<DATE><TIME>|<HOST>|I|testImageGetSet
-    Following should generate error message
-<DATE><TIME>|<HOST>|E|psImageSet (FILE:LINENO)
-    Invalid x-position 9.  Position out of range (10-14)
-<DATE><TIME>|<HOST>|I|testImageGetSet
+<DATE><TIME>|<HOST>|I|testImageSet
+    Following should generate error message
+<DATE><TIME>|<HOST>|E|psImageSet (FILE:LINENO)
+    Invalid x-position 9.  Position out of range (10-14)
+<DATE><TIME>|<HOST>|I|testImageSet
     Following should generate error message
 <DATE><TIME>|<HOST>|E|psImageSet (FILE:LINENO)
     Invalid x-position 15.  Position out of range (10-14)
-<DATE><TIME>|<HOST>|I|testImageGetSet
-    Following should generate error message
-<DATE><TIME>|<HOST>|E|psImageSet (FILE:LINENO)
-    Invalid x-position 9.  Position out of range (10-14)
-
----> TESTPOINT PASSED (psImage{psImageGetSet} | tst_psImage.c)
-
+<DATE><TIME>|<HOST>|I|testImageSet
+    Following should generate error message
+<DATE><TIME>|<HOST>|E|psImageSet (FILE:LINENO)
+    Invalid x-position 9.  Position out of range (10-14)
+
+---> TESTPOINT PASSED (psImage{psImageSet} | tst_psImage.c)
+
+/***************************** TESTPOINT ******************************************\
+*             TestFile: tst_psImage.c                                              *
+*            TestPoint: psImage{psImageGet}                                        *
+*             TestType: Positive                                                   *
+\**********************************************************************************/
+
+<DATE><TIME>|<HOST>|I|testImageGet
+    Following should generate error message
+<DATE><TIME>|<HOST>|E|psImageGet (FILE:LINENO)
+    Unallowable operation: psImage image or its data is NULL.
+<DATE><TIME>|<HOST>|I|testImageGet
+    Following should generate error message
+<DATE><TIME>|<HOST>|E|psImageGet (FILE:LINENO)
+    Error: image->numCols is 0 or less.
+<DATE><TIME>|<HOST>|I|testImageGet
+    Following should generate error message
+<DATE><TIME>|<HOST>|E|psImageGet (FILE:LINENO)
+    Error: image->numRows is 0 or less.
+<DATE><TIME>|<HOST>|I|testImageGet
+    Following should generate error message
+<DATE><TIME>|<HOST>|E|psImageGet (FILE:LINENO)
+    Error: image->row0 is less than 0.
+<DATE><TIME>|<HOST>|I|testImageGet
+    Following should generate error message
+<DATE><TIME>|<HOST>|E|psImageGet (FILE:LINENO)
+    Error: image->col0 is less than 0.
+<DATE><TIME>|<HOST>|I|testImageGet
+    Following should generate error message
+<DATE><TIME>|<HOST>|E|psImageGet (FILE:LINENO)
+    Invalid x-position 1.  Position out of range (10-14)
+<DATE><TIME>|<HOST>|I|testImageGet
+    Following should generate error message
+<DATE><TIME>|<HOST>|E|psImageGet (FILE:LINENO)
+    Invalid x-position 9.  Position out of range (10-14)
+<DATE><TIME>|<HOST>|I|testImageGet
+    Following should generate error message
+<DATE><TIME>|<HOST>|E|psImageGet (FILE:LINENO)
+    Invalid x-position 15.  Position out of range (10-14)
+<DATE><TIME>|<HOST>|I|testImageGet
+    Following should generate error message
+<DATE><TIME>|<HOST>|E|psImageGet (FILE:LINENO)
+    Invalid x-position 9.  Position out of range (10-14)
+
+---> TESTPOINT PASSED (psImage{psImageGet} | tst_psImage.c)
+
