Index: trunk/psLib/test/image/tst_psImageStructManip.c
===================================================================
--- trunk/psLib/test/image/tst_psImageStructManip.c	(revision 3973)
+++ trunk/psLib/test/image/tst_psImageStructManip.c	(revision 3976)
@@ -6,6 +6,6 @@
 *  @author Robert DeSonia, MHPCC
 *
-*  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2005-05-19 02:49:40 $
+*  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2005-05-19 05:03:48 $
 *
 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -19,5 +19,5 @@
 
 static psS32 testImageSubset(void);
-static psS32 testImageSubsection(void);
+static psS32 testImageCopy(void);
 static psS32 testImageTrim(void);
 
@@ -26,5 +26,5 @@
                               {testImageSubset,547,"psImageSubset",0,false},
                               {testImageSubset,550,"psImageSubset",0,true},
-                              {testImageSubsection,730,"psImageSubsection",0,false},
+                              {testImageCopy,551,"psImageCopy",0,false},
                               {testImageTrim, 744, "psImageTrim", 0, false},
                               {NULL}
@@ -46,6 +46,6 @@
     psS32 c = 128;
     psS32 r = 256;
-    psRegion region1 = {0,0,c/2,r/2};
-    psRegion region2 = {c/4,r/4,c/4+c/2,r/4+r/2};
+    psRegion region1 = psRegionSet(0,c/2,0,r/2);
+    psRegion region2 = psRegionSet(c/4,c/4+c/2,r/4,r/4+r/2);
 
     original = psImageAlloc(c,r,PS_TYPE_U32);
@@ -168,8 +168,5 @@
     memcpy(&preSubsetStruct,original,sizeof(psImage));
     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
-    subset1 = psImageSubset(original,(psRegion) {
-                                0,r/2,c/2,r/2
-                            }
-                           );
+    subset1 = psImageSubset(original, psRegionSet(0,c/2,r/2,r/2));
     if (subset1 != NULL) {
         psError(PS_ERR_UNKNOWN,true,"psImageSubset didn't return NULL when numRows=0.");
@@ -177,8 +174,5 @@
     }
     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
-    subset1 = psImageSubset(original,(psRegion) {
-                                c/2,0,c/2,r/2
-                            }
-                           );
+    subset1 = psImageSubset(original,psRegionSet(c/2,c/2,0,r/2));
     if (subset1 != NULL) {
         psError(PS_ERR_UNKNOWN,true,"psImageSubset didn't return NULL when numCols=0.");
@@ -196,8 +190,5 @@
 
     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
-    subset1 = psImageSubset(original,(psRegion) {
-                                0,0,c/2,r*2
-                            }
-                           );
+    subset1 = psImageSubset(original, psRegionSet(0,c/2, 0,r*2));
     if (subset1 != NULL) {
         psError(PS_ERR_UNKNOWN,true,"psImageSubset didn't return NULL when subset origin was outside of "
@@ -206,8 +197,5 @@
     }
     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
-    subset1 = psImageSubset(original,(psRegion) {
-                                0,0,c*2,r/2
-                            }
-                           );
+    subset1 = psImageSubset(original,psRegionSet(0,c*2,0,r/2));
     if (subset1 != NULL) {
         psError(PS_ERR_UNKNOWN,true,"psImageSubset didn't return NULL when subset origin was outside of "
@@ -216,8 +204,5 @@
     }
     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
-    subset1 = psImageSubset(original,(psRegion) {
-                                -1,0,c/2,r/2
-                            }
-                           );
+    subset1 = psImageSubset(original, psRegionSet(-1,c/2,0,r/2));
     if (subset1 != NULL) {
         psError(PS_ERR_UNKNOWN,true,"psImageSubset didn't return NULL when subset origin was outside of "
@@ -226,8 +211,5 @@
     }
     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
-    subset1 = psImageSubset(original,(psRegion) {
-                                0,-1,c/2,r/2
-                            }
-                           );
+    subset1 = psImageSubset(original, psRegionSet(0,c/2,-1,r/2));
     if (subset1 != NULL) {
         psError(PS_ERR_UNKNOWN,true,"psImageSubset didn't return NULL when subset origin was outside of "
@@ -242,8 +224,5 @@
 
     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
-    subset1 = psImageSubset(original,(psRegion) {
-                                0,0,c/2,r+1
-                            }
-                           );
+    subset1 = psImageSubset(original,psRegionSet(0,c/2,0,r+1));
     if (subset1 != NULL) {
         psError(PS_ERR_UNKNOWN,true,"psImageSubset didn't return NULL when subset was outside of image (via rows).");
@@ -251,8 +230,5 @@
     }
     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
-    subset1 = psImageSubset(original,(psRegion) {
-                                0,0,c+1,r/2
-                            }
-                           );
+    subset1 = psImageSubset(original, psRegionSet(0,c+1,0,r/2));
     if (subset1 != NULL) {
         psError(PS_ERR_UNKNOWN,true,"psImageSubset didn't return NULL when subset was outside of image (via cols).");
@@ -260,8 +236,5 @@
     }
     psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
-    subset1 = psImageSubset(original,(psRegion) {
-                                0,0,c+1,r+1
-                            }
-                           );
+    subset1 = psImageSubset(original,psRegionSet(0,c+1,0,r+1));
     if (subset1 != NULL) {
         psError(PS_ERR_UNKNOWN,true,"psImageSubset didn't return NULL when subset was outside of image (via row+cols).");
@@ -298,156 +271,141 @@
 }
 
-// #730: psImageSubsection shall create child image of a specified size from a parent psImage structure
-psS32 testImageSubsection(void)
+psS32 testImageCopy(void)
 {
-    psImage* original;
-    psImage* subset;
-    psS32 c = 128;
-    psS32 r = 256;
-    psS32 i;
-    psS32 numRegions = 4;
-    psS32 x1[] = {  0, 32, 64, 32};
-    psS32 x2[] = { 32, 64,127, 64};
-    psS32 y1[] = {  0, 32, 32,128};
-    psS32 y2[] = { 32, 64, 64,255};
-
-    original = psImageAlloc(c,r,PS_TYPE_U32);
-    for (psS32 row=0;row<r;row++) {
-        for (psS32 col=0;col<c;col++) {
-            original->data.F32[row][col] = row*1000+col;
-        }
-    }
-
-    for (i=0; i<numRegions; i++) {
-        char sectionStr[64];
-        sprintf(sectionStr,"[%d:%d,%d:%d]",x1[i],x2[i],y1[i],y2[i]);
-
-        psLogMsg(__func__,PS_LOG_INFO,"Testing subsection %s.",
-                 sectionStr);
-
-        subset = psImageSubsection(original,sectionStr);
-
-        if (subset == NULL) {
-            psError(PS_ERR_UNKNOWN,true,"psImageSubsection returned a NULL with a subset of %s.",
-                    sectionStr);
-            return 10*i+1;
-        }
-
-        if (subset->type.type != PS_TYPE_U32) {
-            psError(PS_ERR_UNKNOWN,true,"psImageSubsection output type was not proper(%d, should be %d).",
-                    subset->type.type, PS_TYPE_U32);
-            return 10*i+2;
-        }
-
-        if (subset->col0 != x1[i] || subset->row0 != y1[i]) {
-            psError(PS_ERR_UNKNOWN,true,"psImageSubsection didn't set properly col0/row0 (%d/%d, should be %d/%d).",
-                    subset->col0,subset->row0,x1[i],y1[i]);
-            return 10*i+3;
-        }
-
-        if (subset->parent != original) {
-            psError(PS_ERR_UNKNOWN,true,"psImageSubsection didn't set parent.");
-            return 10*i+4;
-        }
-
-        if (subset->children != NULL) {
-            psError(PS_ERR_UNKNOWN,true,"psImageSubsection didn't set children to NULL.");
-            return 10*i+5;
-        }
-
-        if (original->children == NULL || original->children->n != i+1) {
-            psError(PS_ERR_UNKNOWN,true,"psImageSubsection didn't increment number of children by one per subset.");
-            return 10*i+6;
-        }
-
-
-        if (original->children->data[i] != subset) {
-            psError(PS_ERR_UNKNOWN,true,"psImageSubsection didn't properly store the children pointer.");
-            return 10*i+7;
-        }
-
-        psS32 numCols = x2[i]-x1[i]+1;
-        psS32 numRows = y2[i]-y1[i]+1;
-        if (subset->numCols != numCols || subset->numRows != numRows) {
-            psError(PS_ERR_UNKNOWN,true,"psImageSubsection output size was not proper(%dx%d, should be %dx%d).",
-                    subset->numCols, subset->numRows, numCols, numRows);
-            return 10*i+8;
-        }
-
-        for (psS32 row=0;row<numRows;row++) {
-            for (psS32 col=0;col<numCols;col++) {
-                if (subset->data.U32[row][col] != original->data.U32[row+y1[i]][col+x1[i]]) {
-                    psError(PS_ERR_UNKNOWN,true,"psImageSubset output #1 was wrong at %dx%d (%d vs %d).",
-                            row,col,subset->data.U32[row][col], original->data.U32[row+y1[i]][col+x1[i]]);
-                    return 10*i+9;
-                }
+    psImage* img = NULL;
+    psImage* img2 = NULL;
+    psImage* img3 = NULL;
+    psImage* img4 = NULL;
+    psU32 c = 128;
+    psU32 r = 256;
+
+    img = psImageAlloc(c,r,PS_TYPE_F32);
+    for (unsigned row=0;row<r;row++) {
+        psF32* imgRow = img->data.F32[row];
+        for (unsigned col=0;col<c;col++) {
+            imgRow[col] = (psF32)(row+col);
+        }
+    }
+    img2 = psImageAlloc(c,r,PS_TYPE_F32);
+    for (unsigned row=0;row<r;row++) {
+        psF32* img2Row = img2->data.F32[row];
+        for (unsigned col=0;col<c;col++) {
+            img2Row[col] = 0.0f;
+        }
+    }
+
+    img3 = psImageCopy(img2,img,PS_TYPE_F32);
+
+    // Verify the returned psImage structure pointer is equal to the input parameter output.
+    if (img2 != img3) {
+        psError(PS_ERR_UNKNOWN, true,"the image given for recycled wasn't");
+        return 1;
+    }
+
+    // Verify the returned psImage structure is the same type as the input image structure
+    // if the specified output argument is NULL.
+    img4 = psImageCopy(NULL,img,PS_TYPE_F32);
+    if (img4 == NULL) {
+        psError(PS_ERR_UNKNOWN, true,"output image doesn't exist");
+        return 4;
+    }
+    if (img4->type.type != img->type.type) {
+        psError(PS_ERR_UNKNOWN, true,"output image is not the same type as input image");
+        return 4;
+    }
+    for (psU32 row=0;row<r;row++) {
+        psF32* imgInRow = img->data.F32[row];
+        psF32* imgOutRow = img4->data.F32[row];
+        for (unsigned col=0;col<c;col++) {
+            if( imgInRow[col] != imgOutRow[col] ) {
+                psError(PS_ERR_UNKNOWN, true,"Input image not equal to output image at %d,%d!",
+                        col, row);
+                return 4;
             }
         }
     }
 
-    psLogMsg(__func__,PS_LOG_INFO,"An error should follow (x1>x2)");
-    subset = psImageSubsection(original,"[64:32,32:64]");
-    if (subset != NULL) {
-        psError(PS_ERR_UNKNOWN,true,"psImageSubsection didn't return NULL when x1 > x2.");
-        return 10*i+10;
-    }
-
-    psLogMsg(__func__,PS_LOG_INFO,"An error should follow (y1>y2)");
-    subset = psImageSubsection(original,"[32:64,64:32]");
-    if (subset != NULL) {
-        psError(PS_ERR_UNKNOWN,true,"psImageSubsection didn't return NULL when y1 > y2.");
-        return 10*i+11;
-    }
-
-    psLogMsg(__func__,PS_LOG_INFO,"An error should follow (x2>nCols)");
-    subset = psImageSubsection(original,"[64:256,32:64]"); // assumes c<256
-    if (subset != NULL) {
-        psError(PS_ERR_UNKNOWN, true,"psImageSubsection didn't return NULL when x2 > c.");
-        return 10*i+12;
-    }
-
-    psLogMsg(__func__,PS_LOG_INFO,"An error should follow (y2>=nRows)");
-    subset = psImageSubsection(original,"[32:64,64:256]"); // assumes r==256
-    if (subset != NULL) {
-        psError(PS_ERR_UNKNOWN, true,"psImageSubsection didn't return NULL when y2 > r.");
-        return 10*i+13;
-    }
-
-    psLogMsg(__func__,PS_LOG_INFO,"An error should follow (malformed string - no brackets)");
-    subset = psImageSubsection(original,"32:64,32:64");
-    if (subset != NULL) {
-        psError(PS_ERR_UNKNOWN, true,"psImageSubsection didn't return NULL when subsection was '32:64,32:64'.");
-        return 10*i+14;
-    }
-
-    psLogMsg(__func__,PS_LOG_INFO,"An error should follow (malformed string - no colons)");
-    subset = psImageSubsection(original,"[32-64,32-64]");
-    if (subset != NULL) {
-        psError(PS_ERR_UNKNOWN, true,"psImageSubsection didn't return NULL when subsection was '[32-64,32-64]'.");
-        return 10*i+15;
-    }
-
-    psLogMsg(__func__,PS_LOG_INFO,"An error should follow (malformed string - not four numbers)");
-    subset = psImageSubsection(original,"[32:64,32]");
-    if (subset != NULL) {
-        psError(PS_ERR_UNKNOWN, true,"psImageSubsection didn't return NULL when subsection was '[32:64,32]'.");
-        return 10*i+16;
-    }
-
-    psLogMsg(__func__,PS_LOG_INFO,"An error should follow (image is NULL)");
-    subset = psImageSubsection(NULL,"[32:64,32:64]");
-    if (subset != NULL) {
-        psError(PS_ERR_UNKNOWN, true,"psImageSubsection didn't return NULL when image was NULL.");
-        return 10*i+17;
-    }
-
-    psLogMsg(__func__,PS_LOG_INFO,"An error should follow (subsection string is NULL)");
-    subset = psImageSubsection(original,NULL);
-    if (subset != NULL) {
-        psError(PS_ERR_UNKNOWN, true,"psImageSubsection didn't return NULL when subsection was NULL.");
-        return 10*i+18;
-    }
-
-    psFree(original);
+    // Verify the returned psImage structure member are equal to the values in
+    // the input psImage structure input.
+
+    #define testImageCopyType(IN,OUT) \
+    img = psImageRecycle(img,c,r,PS_TYPE_##IN); \
+    for (unsigned row=0;row<r;row++) { \
+        ps##IN* imgRow = img->data.IN[row]; \
+        for (unsigned col=0;col<c;col++) { \
+            imgRow[col] = (ps##IN)(row+col); \
+        } \
+    } \
+    img2 = psImageCopy(img2,img,PS_TYPE_##OUT); \
+    if (img2 == NULL) { \
+        psError(PS_ERR_UNKNOWN, true,"psImageCopy failed to copy U8."); \
+        return 2; \
+    } \
+    for (psU32 row=0;row<r;row++) { \
+        ps##IN* imgRow = img->data.IN[row]; \
+        ps##OUT* img2Row = img2->data.OUT[row]; \
+        for (psU32 col=0;col<c;col++) { \
+            if (abs(imgRow[col] - (ps##IN)(row+col)) > 0.5) { \
+                psError(PS_ERR_UNKNOWN, true,"Input image was changed at %d,%d!", \
+                        col,row); \
+                return 2; \
+            } \
+            if (abs(img2Row[col] - (ps##OUT)(imgRow[col])) > 0.5) { \
+                psError(PS_ERR_UNKNOWN, true,"returned psImage values after copy don't match at %d,%d " \
+                        "(%d vs %d)",\
+                        col,row,img2Row[col], (ps##OUT)(imgRow[col])); \
+                return 2; \
+            } \
+        } \
+    }
+
+    #define testImageCopyTypes(IN) \
+    printf("to psF32\n"); \
+    testImageCopyType(IN,F32);\
+    printf("to psF64\n"); \
+    testImageCopyType(IN,F64); \
+    printf("to psU8\n"); \
+    testImageCopyType(IN,U8); \
+    printf("to psU16\n"); \
+    testImageCopyType(IN,U16); \
+    printf("to psU32\n"); \
+    testImageCopyType(IN,U32); \
+    printf("to psS8\n"); \
+    testImageCopyType(IN,S8);\
+    printf("to psS16\n"); \
+    testImageCopyType(IN,S16);\
+    printf("to psS32\n"); \
+    testImageCopyType(IN,S32);
+
+    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psU8");
+    testImageCopyTypes(U8);
+    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psU16");
+    testImageCopyTypes(U16);
+    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psU32");
+    testImageCopyTypes(U32);
+    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psS8");
+    testImageCopyTypes(S8);
+    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psS16");
+    testImageCopyTypes(S16);
+    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psS32");
+    testImageCopyTypes(S32);
+    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psF32");
+    testImageCopyTypes(F32);
+    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psF64");
+    testImageCopyTypes(F64);
+
+    // Verify the returned psImage structure pointer is null and program
+    // execution doesn't stop, if the input parameter input is null.
+    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
+    img3 = psImageCopy(NULL,NULL,PS_TYPE_F32);
+    if (img3 != NULL) {
+        psError(PS_ERR_UNKNOWN, true,"psImageCopy didn't return NULL when input image was NULL.");
+        return 3;
+    }
+
+    psFree(img);
+    psFree(img2);
+    psFree(img3);
+    psFree(img4);
 
     return 0;
@@ -462,5 +420,5 @@
     psS32 halfR = r/2;
     psS32 halfC = c/2;
-    psRegion centerHalf = {qtrC,qtrR,qtrC+halfC,qtrR+halfR};
+    psRegion centerHalf = {qtrC,qtrC+halfC,qtrR,qtrR+halfR};
 
     psImage* image = psImageAlloc(c,r,PS_TYPE_F32);
@@ -517,8 +475,5 @@
     */
     image1 = psImageCopy(image1,image,PS_TYPE_F32);
-    image2 = psImageTrim(image1,(psRegion) {
-                             qtrC,qtrR,0,0
-                         }
-                        );
+    image2 = psImageTrim(image1,psRegionSet(qtrC,0,qtrR,0));
 
     if (image1 != image2) {
@@ -559,8 +514,5 @@
     */
     image1 = psImageCopy(image1,image,PS_TYPE_F32);
-    image2 = psImageTrim(image1,(psRegion) {
-                             qtrC,qtrR,-qtrC,-qtrR
-                         }
-                        );
+    image2 = psImageTrim(image1,psRegionSet(qtrC,-qtrC, qtrR,-qtrR));
 
     if (image1 != image2) {
@@ -602,8 +554,5 @@
     */
 
-    image2 = psImageTrim(NULL,(psRegion) {
-                             qtrC,qtrR,0,0
-                         }
-                        );
+    image2 = psImageTrim(NULL, psRegionSet(qtrC,0,qtrR,0));
 
     if (image2 != NULL) {
@@ -622,8 +571,5 @@
 
     image1 = psImageCopy(NULL,image,PS_TYPE_F32);
-    image2 = psImageTrim(image1,(psRegion) {
-                             -1,0,0,0
-                         }
-                        );
+    image2 = psImageTrim(image1, psRegionSet(-1,0,0,0));
 
     if (image2 != NULL) {
@@ -642,8 +588,5 @@
 
     image1 = psImageCopy(NULL,image,PS_TYPE_F32);
-    image2 = psImageTrim(image1,(psRegion) {
-                             0,-1,0,0
-                         }
-                        );
+    image2 = psImageTrim(image1, psRegionSet(0,0,-1,0));
 
     if (image2 != NULL) {
@@ -662,8 +605,5 @@
 
     image1 = psImageCopy(NULL,image,PS_TYPE_F32);
-    image2 = psImageTrim(image1,(psRegion) {
-                             0,0,image->numCols+1,0
-                         }
-                        );
+    image2 = psImageTrim(image1, psRegionSet(0,image->numCols+1,0,0));
 
     if (image2 != NULL) {
@@ -682,8 +622,5 @@
 
     image1 = psImageCopy(NULL,image,PS_TYPE_F32);
-    image2 = psImageTrim(image1,(psRegion) {
-                             0,0,0,image->numRows+1
-                         }
-                        );
+    image2 = psImageTrim(image1, psRegionSet(0,0,0,image->numRows+1));
 
     if (image2 != NULL) {
@@ -702,8 +639,5 @@
 
     image1 = psImageCopy(NULL,image,PS_TYPE_F32);
-    image2 = psImageTrim(image1,(psRegion) {
-                             0,0,-image->numCols,0
-                         }
-                        );
+    image2 = psImageTrim(image1, psRegionSet(0,-image->numCols,0,0));
 
     if (image2 != NULL) {
@@ -722,8 +656,5 @@
 
     image1 = psImageCopy(NULL,image,PS_TYPE_F32);
-    image2 = psImageTrim(image1,(psRegion) {
-                             0,0,0,-image->numRows
-                         }
-                        );
+    image2 = psImageTrim(image1, psRegionSet(0,0,0,-image->numRows));
 
     if (image2 != NULL) {
