Index: /trunk/psLib/src/mathtypes/psImage.c
===================================================================
--- /trunk/psLib/src/mathtypes/psImage.c	(revision 6573)
+++ /trunk/psLib/src/mathtypes/psImage.c	(revision 6574)
@@ -9,6 +9,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.95 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-02-06 22:19:28 $
+ *  @version $Revision: 1.96 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-03-14 02:22:55 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -291,25 +291,76 @@
                 double complex value)
 {
-    if (image == NULL) {
-        psError(PS_ERR_BAD_PARAMETER_NULL, true, PS_ERRORTEXT_psImage_IMAGE_NULL);
+    /*    if (image == NULL) {
+            psError(PS_ERR_BAD_PARAMETER_NULL, true, PS_ERRORTEXT_psImage_IMAGE_NULL);
+            return false;
+        }
+        if (x >= image->numRows || y >= image->numCols) {
+            psError(PS_ERR_BAD_PARAMETER_SIZE, true,
+                "Invalid position %d.  Position out of range (%d-%d)\n", x, );
+            return false;
+        }
+     
+        if(x < 0)
+            x += image->numRows;
+        if(x < 0) {
+            psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Invalid x.  Negative number too large\n");
+            return false;
+        }
+     
+        if(y < 0)
+            y += image->numCols;
+        if(y < 0) {
+            psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Invalid y.  Negative number too large\n");
+            return false;
+        }
+     
+    */
+    PS_ASSERT_IMAGE_NON_NULL(image, false);
+    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);
+    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;
-    }
-    if (x >= image->numRows || y >= image->numCols) {
-        psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Invalid position.  Position too large\n");
+    } 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;
-    }
-
-    if(x < 0)
-        x += image->numRows;
-    if(x < 0) {
-        psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Invalid x.  Negative number too large\n");
+    } 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;
-    }
-
-    if(y < 0)
-        y += image->numCols;
-    if(y < 0) {
-        psError(PS_ERR_BAD_PARAMETER_SIZE, true, "Invalid y.  Negative number too large\n");
+    } 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;
     }
 
Index: /trunk/psLib/test/mathtypes/tst_psImage.c
===================================================================
--- /trunk/psLib/test/mathtypes/tst_psImage.c	(revision 6573)
+++ /trunk/psLib/test/mathtypes/tst_psImage.c	(revision 6574)
@@ -6,6 +6,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-09-29 01:15:38 $
+ *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-03-14 02:22:55 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -361,14 +361,110 @@
     image = psImageAlloc(5, 5, PS_TYPE_S32);
 
-    if ( !psImageSet(image, 0, 0, 10) )
-        fprintf(stderr, "ImageSet failed to set S32 at position 0\n");
-    if ( psImageSet(image, 10, 10, 100) )
-        fprintf(stderr, "ImageSet Improperly set S32 at out of range position\n");
-    if ( !psImageSet(image, -1, -1, 4) )
-        fprintf(stderr, "ImageSet Failed to set S32 at position 4,4\n");
-    if ( (psS32)psImageGet(image, 0, 0) != 10 )
-        fprintf(stderr, "ImageGet Failed to return the correct S32 from position 0,0\n");
-    if ( (psS32)psImageGet(image, -1, -1) != 4 )
-        fprintf(stderr, "ImageGet Failed to return the correct S32 from tail using -1,-1\n");
+    //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 set a position in a NULL psImage*
+    psImage *none = NULL;
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message");
+    if ( psImageSet(none, 1, 1, 1) ) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                "psImageSet failed to return false when passed a NULL image.\n");
+        return 1;
+    }
+
+    //Attempt to set 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 ( psImageSet(none, 1, 1, 1) ) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                "psImageSet 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 ( psImageSet(none, 1, 1, 1) ) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                "psImageSet failed to return false when passed an image with negative numRows.\n");
+        return 3;
+    }
+
+    //Attempt to set 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 ( psImageSet(none, 1, 1, 1) ) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                "psImageSet 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 ( psImageSet(none, 1, 1, 1) ) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                "psImageSet failed to return false when passed an image with negative col0.\n");
+        return 5;
+    }
+    psFree(none);
+
+    //Try to set a position inside of the subimage.
+    if ( !psImageSet(image, 13, 14, 666) ) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                "psImageSet failed to return true when passed valid parameters.\n");
+        return 6;
+    } else if (image->data.S32[3][4] != 666) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                "psImageSet failed to set the data values correctly.\n");
+        return 7;
+    }
+    //Try to set a position inside of the subimage from the tail.
+    if ( !psImageSet(image, -1, -1, 666) ) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                "psImageSet failed to return true when passed valid parameters.\n");
+        return 8;
+    } else if  (image->data.S32[4][4] != 666) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                "psImageSet failed to set (from the tail) the data values correctly.\n");
+        printf("\n value at 14,14 is %d\n", image->data.S32[4][4]);
+        return 9;
+    }
+
+    //Try to set a position outside of the subimage but inside of the parent image.
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message");
+    if ( psImageSet(image, 0, 0, 666) ) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
+                "psImageSet failed to return false when passed an invalid location.\n");
+        return 10;
+    }
+    psLogMsg(__func__,PS_LOG_INFO,"Following should generate error message");
+    if ( psImageSet(image, 9, 10, 666) ) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
+                "psImageSet failed to return false 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 ( psImageSet(image, 15, 14, 666) ) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
+                "psImageSet failed to return false 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 ( psImageSet(image, -6, -1, 666) ) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, false,
+                "psImageSet failed to return false when passed an invalid location.\n");
+        return 13;
+    }
+
 
     psFree(image);
Index: /trunk/psLib/test/mathtypes/verified/tst_psImage.stderr
===================================================================
--- /trunk/psLib/test/mathtypes/verified/tst_psImage.stderr	(revision 6573)
+++ /trunk/psLib/test/mathtypes/verified/tst_psImage.stderr	(revision 6574)
@@ -134,6 +134,40 @@
 \**********************************************************************************/
 
+<DATE><TIME>|<HOST>|I|testImageGetSet
+    Following should generate error message
 <DATE><TIME>|<HOST>|E|psImageSet (FILE:LINENO)
-    Invalid position.  Position too large
+    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
+    Following should generate error message
+<DATE><TIME>|<HOST>|E|psImageSet (FILE:LINENO)
+    Error: image->row0 is less than 0.
+<DATE><TIME>|<HOST>|I|testImageGetSet
+    Following should generate error message
+<DATE><TIME>|<HOST>|E|psImageSet (FILE:LINENO)
+    Error: image->col0 is less than 0.
+<DATE><TIME>|<HOST>|I|testImageGetSet
+    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
+    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)
