IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
May 18, 2005, 7:03:48 PM (21 years ago)
Author:
desonia
Message:

modified tests to match new psRegion functions.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/test/image/tst_psImageStructManip.c

    r3973 r3976  
    66*  @author Robert DeSonia, MHPCC
    77*
    8 *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
    9 *  @date $Date: 2005-05-19 02:49:40 $
     8*  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
     9*  @date $Date: 2005-05-19 05:03:48 $
    1010*
    1111*  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    1919
    2020static psS32 testImageSubset(void);
    21 static psS32 testImageSubsection(void);
     21static psS32 testImageCopy(void);
    2222static psS32 testImageTrim(void);
    2323
     
    2626                              {testImageSubset,547,"psImageSubset",0,false},
    2727                              {testImageSubset,550,"psImageSubset",0,true},
    28                               {testImageSubsection,730,"psImageSubsection",0,false},
     28                              {testImageCopy,551,"psImageCopy",0,false},
    2929                              {testImageTrim, 744, "psImageTrim", 0, false},
    3030                              {NULL}
     
    4646    psS32 c = 128;
    4747    psS32 r = 256;
    48     psRegion region1 = {0,0,c/2,r/2};
    49     psRegion region2 = {c/4,r/4,c/4+c/2,r/4+r/2};
     48    psRegion region1 = psRegionSet(0,c/2,0,r/2);
     49    psRegion region2 = psRegionSet(c/4,c/4+c/2,r/4,r/4+r/2);
    5050
    5151    original = psImageAlloc(c,r,PS_TYPE_U32);
     
    168168    memcpy(&preSubsetStruct,original,sizeof(psImage));
    169169    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    170     subset1 = psImageSubset(original,(psRegion) {
    171                                 0,r/2,c/2,r/2
    172                             }
    173                            );
     170    subset1 = psImageSubset(original, psRegionSet(0,c/2,r/2,r/2));
    174171    if (subset1 != NULL) {
    175172        psError(PS_ERR_UNKNOWN,true,"psImageSubset didn't return NULL when numRows=0.");
     
    177174    }
    178175    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    179     subset1 = psImageSubset(original,(psRegion) {
    180                                 c/2,0,c/2,r/2
    181                             }
    182                            );
     176    subset1 = psImageSubset(original,psRegionSet(c/2,c/2,0,r/2));
    183177    if (subset1 != NULL) {
    184178        psError(PS_ERR_UNKNOWN,true,"psImageSubset didn't return NULL when numCols=0.");
     
    196190
    197191    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    198     subset1 = psImageSubset(original,(psRegion) {
    199                                 0,0,c/2,r*2
    200                             }
    201                            );
     192    subset1 = psImageSubset(original, psRegionSet(0,c/2, 0,r*2));
    202193    if (subset1 != NULL) {
    203194        psError(PS_ERR_UNKNOWN,true,"psImageSubset didn't return NULL when subset origin was outside of "
     
    206197    }
    207198    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    208     subset1 = psImageSubset(original,(psRegion) {
    209                                 0,0,c*2,r/2
    210                             }
    211                            );
     199    subset1 = psImageSubset(original,psRegionSet(0,c*2,0,r/2));
    212200    if (subset1 != NULL) {
    213201        psError(PS_ERR_UNKNOWN,true,"psImageSubset didn't return NULL when subset origin was outside of "
     
    216204    }
    217205    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    218     subset1 = psImageSubset(original,(psRegion) {
    219                                 -1,0,c/2,r/2
    220                             }
    221                            );
     206    subset1 = psImageSubset(original, psRegionSet(-1,c/2,0,r/2));
    222207    if (subset1 != NULL) {
    223208        psError(PS_ERR_UNKNOWN,true,"psImageSubset didn't return NULL when subset origin was outside of "
     
    226211    }
    227212    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    228     subset1 = psImageSubset(original,(psRegion) {
    229                                 0,-1,c/2,r/2
    230                             }
    231                            );
     213    subset1 = psImageSubset(original, psRegionSet(0,c/2,-1,r/2));
    232214    if (subset1 != NULL) {
    233215        psError(PS_ERR_UNKNOWN,true,"psImageSubset didn't return NULL when subset origin was outside of "
     
    242224
    243225    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    244     subset1 = psImageSubset(original,(psRegion) {
    245                                 0,0,c/2,r+1
    246                             }
    247                            );
     226    subset1 = psImageSubset(original,psRegionSet(0,c/2,0,r+1));
    248227    if (subset1 != NULL) {
    249228        psError(PS_ERR_UNKNOWN,true,"psImageSubset didn't return NULL when subset was outside of image (via rows).");
     
    251230    }
    252231    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    253     subset1 = psImageSubset(original,(psRegion) {
    254                                 0,0,c+1,r/2
    255                             }
    256                            );
     232    subset1 = psImageSubset(original, psRegionSet(0,c+1,0,r/2));
    257233    if (subset1 != NULL) {
    258234        psError(PS_ERR_UNKNOWN,true,"psImageSubset didn't return NULL when subset was outside of image (via cols).");
     
    260236    }
    261237    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
    262     subset1 = psImageSubset(original,(psRegion) {
    263                                 0,0,c+1,r+1
    264                             }
    265                            );
     238    subset1 = psImageSubset(original,psRegionSet(0,c+1,0,r+1));
    266239    if (subset1 != NULL) {
    267240        psError(PS_ERR_UNKNOWN,true,"psImageSubset didn't return NULL when subset was outside of image (via row+cols).");
     
    298271}
    299272
    300 // #730: psImageSubsection shall create child image of a specified size from a parent psImage structure
    301 psS32 testImageSubsection(void)
     273psS32 testImageCopy(void)
    302274{
    303     psImage* original;
    304     psImage* subset;
    305     psS32 c = 128;
    306     psS32 r = 256;
    307     psS32 i;
    308     psS32 numRegions = 4;
    309     psS32 x1[] = {  0, 32, 64, 32};
    310     psS32 x2[] = { 32, 64,127, 64};
    311     psS32 y1[] = {  0, 32, 32,128};
    312     psS32 y2[] = { 32, 64, 64,255};
    313 
    314     original = psImageAlloc(c,r,PS_TYPE_U32);
    315     for (psS32 row=0;row<r;row++) {
    316         for (psS32 col=0;col<c;col++) {
    317             original->data.F32[row][col] = row*1000+col;
    318         }
    319     }
    320 
    321     for (i=0; i<numRegions; i++) {
    322         char sectionStr[64];
    323         sprintf(sectionStr,"[%d:%d,%d:%d]",x1[i],x2[i],y1[i],y2[i]);
    324 
    325         psLogMsg(__func__,PS_LOG_INFO,"Testing subsection %s.",
    326                  sectionStr);
    327 
    328         subset = psImageSubsection(original,sectionStr);
    329 
    330         if (subset == NULL) {
    331             psError(PS_ERR_UNKNOWN,true,"psImageSubsection returned a NULL with a subset of %s.",
    332                     sectionStr);
    333             return 10*i+1;
    334         }
    335 
    336         if (subset->type.type != PS_TYPE_U32) {
    337             psError(PS_ERR_UNKNOWN,true,"psImageSubsection output type was not proper(%d, should be %d).",
    338                     subset->type.type, PS_TYPE_U32);
    339             return 10*i+2;
    340         }
    341 
    342         if (subset->col0 != x1[i] || subset->row0 != y1[i]) {
    343             psError(PS_ERR_UNKNOWN,true,"psImageSubsection didn't set properly col0/row0 (%d/%d, should be %d/%d).",
    344                     subset->col0,subset->row0,x1[i],y1[i]);
    345             return 10*i+3;
    346         }
    347 
    348         if (subset->parent != original) {
    349             psError(PS_ERR_UNKNOWN,true,"psImageSubsection didn't set parent.");
    350             return 10*i+4;
    351         }
    352 
    353         if (subset->children != NULL) {
    354             psError(PS_ERR_UNKNOWN,true,"psImageSubsection didn't set children to NULL.");
    355             return 10*i+5;
    356         }
    357 
    358         if (original->children == NULL || original->children->n != i+1) {
    359             psError(PS_ERR_UNKNOWN,true,"psImageSubsection didn't increment number of children by one per subset.");
    360             return 10*i+6;
    361         }
    362 
    363 
    364         if (original->children->data[i] != subset) {
    365             psError(PS_ERR_UNKNOWN,true,"psImageSubsection didn't properly store the children pointer.");
    366             return 10*i+7;
    367         }
    368 
    369         psS32 numCols = x2[i]-x1[i]+1;
    370         psS32 numRows = y2[i]-y1[i]+1;
    371         if (subset->numCols != numCols || subset->numRows != numRows) {
    372             psError(PS_ERR_UNKNOWN,true,"psImageSubsection output size was not proper(%dx%d, should be %dx%d).",
    373                     subset->numCols, subset->numRows, numCols, numRows);
    374             return 10*i+8;
    375         }
    376 
    377         for (psS32 row=0;row<numRows;row++) {
    378             for (psS32 col=0;col<numCols;col++) {
    379                 if (subset->data.U32[row][col] != original->data.U32[row+y1[i]][col+x1[i]]) {
    380                     psError(PS_ERR_UNKNOWN,true,"psImageSubset output #1 was wrong at %dx%d (%d vs %d).",
    381                             row,col,subset->data.U32[row][col], original->data.U32[row+y1[i]][col+x1[i]]);
    382                     return 10*i+9;
    383                 }
     275    psImage* img = NULL;
     276    psImage* img2 = NULL;
     277    psImage* img3 = NULL;
     278    psImage* img4 = NULL;
     279    psU32 c = 128;
     280    psU32 r = 256;
     281
     282    img = psImageAlloc(c,r,PS_TYPE_F32);
     283    for (unsigned row=0;row<r;row++) {
     284        psF32* imgRow = img->data.F32[row];
     285        for (unsigned col=0;col<c;col++) {
     286            imgRow[col] = (psF32)(row+col);
     287        }
     288    }
     289    img2 = psImageAlloc(c,r,PS_TYPE_F32);
     290    for (unsigned row=0;row<r;row++) {
     291        psF32* img2Row = img2->data.F32[row];
     292        for (unsigned col=0;col<c;col++) {
     293            img2Row[col] = 0.0f;
     294        }
     295    }
     296
     297    img3 = psImageCopy(img2,img,PS_TYPE_F32);
     298
     299    // Verify the returned psImage structure pointer is equal to the input parameter output.
     300    if (img2 != img3) {
     301        psError(PS_ERR_UNKNOWN, true,"the image given for recycled wasn't");
     302        return 1;
     303    }
     304
     305    // Verify the returned psImage structure is the same type as the input image structure
     306    // if the specified output argument is NULL.
     307    img4 = psImageCopy(NULL,img,PS_TYPE_F32);
     308    if (img4 == NULL) {
     309        psError(PS_ERR_UNKNOWN, true,"output image doesn't exist");
     310        return 4;
     311    }
     312    if (img4->type.type != img->type.type) {
     313        psError(PS_ERR_UNKNOWN, true,"output image is not the same type as input image");
     314        return 4;
     315    }
     316    for (psU32 row=0;row<r;row++) {
     317        psF32* imgInRow = img->data.F32[row];
     318        psF32* imgOutRow = img4->data.F32[row];
     319        for (unsigned col=0;col<c;col++) {
     320            if( imgInRow[col] != imgOutRow[col] ) {
     321                psError(PS_ERR_UNKNOWN, true,"Input image not equal to output image at %d,%d!",
     322                        col, row);
     323                return 4;
    384324            }
    385325        }
    386326    }
    387327
    388     psLogMsg(__func__,PS_LOG_INFO,"An error should follow (x1>x2)");
    389     subset = psImageSubsection(original,"[64:32,32:64]");
    390     if (subset != NULL) {
    391         psError(PS_ERR_UNKNOWN,true,"psImageSubsection didn't return NULL when x1 > x2.");
    392         return 10*i+10;
    393     }
    394 
    395     psLogMsg(__func__,PS_LOG_INFO,"An error should follow (y1>y2)");
    396     subset = psImageSubsection(original,"[32:64,64:32]");
    397     if (subset != NULL) {
    398         psError(PS_ERR_UNKNOWN,true,"psImageSubsection didn't return NULL when y1 > y2.");
    399         return 10*i+11;
    400     }
    401 
    402     psLogMsg(__func__,PS_LOG_INFO,"An error should follow (x2>nCols)");
    403     subset = psImageSubsection(original,"[64:256,32:64]"); // assumes c<256
    404     if (subset != NULL) {
    405         psError(PS_ERR_UNKNOWN, true,"psImageSubsection didn't return NULL when x2 > c.");
    406         return 10*i+12;
    407     }
    408 
    409     psLogMsg(__func__,PS_LOG_INFO,"An error should follow (y2>=nRows)");
    410     subset = psImageSubsection(original,"[32:64,64:256]"); // assumes r==256
    411     if (subset != NULL) {
    412         psError(PS_ERR_UNKNOWN, true,"psImageSubsection didn't return NULL when y2 > r.");
    413         return 10*i+13;
    414     }
    415 
    416     psLogMsg(__func__,PS_LOG_INFO,"An error should follow (malformed string - no brackets)");
    417     subset = psImageSubsection(original,"32:64,32:64");
    418     if (subset != NULL) {
    419         psError(PS_ERR_UNKNOWN, true,"psImageSubsection didn't return NULL when subsection was '32:64,32:64'.");
    420         return 10*i+14;
    421     }
    422 
    423     psLogMsg(__func__,PS_LOG_INFO,"An error should follow (malformed string - no colons)");
    424     subset = psImageSubsection(original,"[32-64,32-64]");
    425     if (subset != NULL) {
    426         psError(PS_ERR_UNKNOWN, true,"psImageSubsection didn't return NULL when subsection was '[32-64,32-64]'.");
    427         return 10*i+15;
    428     }
    429 
    430     psLogMsg(__func__,PS_LOG_INFO,"An error should follow (malformed string - not four numbers)");
    431     subset = psImageSubsection(original,"[32:64,32]");
    432     if (subset != NULL) {
    433         psError(PS_ERR_UNKNOWN, true,"psImageSubsection didn't return NULL when subsection was '[32:64,32]'.");
    434         return 10*i+16;
    435     }
    436 
    437     psLogMsg(__func__,PS_LOG_INFO,"An error should follow (image is NULL)");
    438     subset = psImageSubsection(NULL,"[32:64,32:64]");
    439     if (subset != NULL) {
    440         psError(PS_ERR_UNKNOWN, true,"psImageSubsection didn't return NULL when image was NULL.");
    441         return 10*i+17;
    442     }
    443 
    444     psLogMsg(__func__,PS_LOG_INFO,"An error should follow (subsection string is NULL)");
    445     subset = psImageSubsection(original,NULL);
    446     if (subset != NULL) {
    447         psError(PS_ERR_UNKNOWN, true,"psImageSubsection didn't return NULL when subsection was NULL.");
    448         return 10*i+18;
    449     }
    450 
    451     psFree(original);
     328    // Verify the returned psImage structure member are equal to the values in
     329    // the input psImage structure input.
     330
     331    #define testImageCopyType(IN,OUT) \
     332    img = psImageRecycle(img,c,r,PS_TYPE_##IN); \
     333    for (unsigned row=0;row<r;row++) { \
     334        ps##IN* imgRow = img->data.IN[row]; \
     335        for (unsigned col=0;col<c;col++) { \
     336            imgRow[col] = (ps##IN)(row+col); \
     337        } \
     338    } \
     339    img2 = psImageCopy(img2,img,PS_TYPE_##OUT); \
     340    if (img2 == NULL) { \
     341        psError(PS_ERR_UNKNOWN, true,"psImageCopy failed to copy U8."); \
     342        return 2; \
     343    } \
     344    for (psU32 row=0;row<r;row++) { \
     345        ps##IN* imgRow = img->data.IN[row]; \
     346        ps##OUT* img2Row = img2->data.OUT[row]; \
     347        for (psU32 col=0;col<c;col++) { \
     348            if (abs(imgRow[col] - (ps##IN)(row+col)) > 0.5) { \
     349                psError(PS_ERR_UNKNOWN, true,"Input image was changed at %d,%d!", \
     350                        col,row); \
     351                return 2; \
     352            } \
     353            if (abs(img2Row[col] - (ps##OUT)(imgRow[col])) > 0.5) { \
     354                psError(PS_ERR_UNKNOWN, true,"returned psImage values after copy don't match at %d,%d " \
     355                        "(%d vs %d)",\
     356                        col,row,img2Row[col], (ps##OUT)(imgRow[col])); \
     357                return 2; \
     358            } \
     359        } \
     360    }
     361
     362    #define testImageCopyTypes(IN) \
     363    printf("to psF32\n"); \
     364    testImageCopyType(IN,F32);\
     365    printf("to psF64\n"); \
     366    testImageCopyType(IN,F64); \
     367    printf("to psU8\n"); \
     368    testImageCopyType(IN,U8); \
     369    printf("to psU16\n"); \
     370    testImageCopyType(IN,U16); \
     371    printf("to psU32\n"); \
     372    testImageCopyType(IN,U32); \
     373    printf("to psS8\n"); \
     374    testImageCopyType(IN,S8);\
     375    printf("to psS16\n"); \
     376    testImageCopyType(IN,S16);\
     377    printf("to psS32\n"); \
     378    testImageCopyType(IN,S32);
     379
     380    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psU8");
     381    testImageCopyTypes(U8);
     382    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psU16");
     383    testImageCopyTypes(U16);
     384    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psU32");
     385    testImageCopyTypes(U32);
     386    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psS8");
     387    testImageCopyTypes(S8);
     388    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psS16");
     389    testImageCopyTypes(S16);
     390    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psS32");
     391    testImageCopyTypes(S32);
     392    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psF32");
     393    testImageCopyTypes(F32);
     394    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psF64");
     395    testImageCopyTypes(F64);
     396
     397    // Verify the returned psImage structure pointer is null and program
     398    // execution doesn't stop, if the input parameter input is null.
     399    psLogMsg(__func__,PS_LOG_INFO,"An error should follow...");
     400    img3 = psImageCopy(NULL,NULL,PS_TYPE_F32);
     401    if (img3 != NULL) {
     402        psError(PS_ERR_UNKNOWN, true,"psImageCopy didn't return NULL when input image was NULL.");
     403        return 3;
     404    }
     405
     406    psFree(img);
     407    psFree(img2);
     408    psFree(img3);
     409    psFree(img4);
    452410
    453411    return 0;
     
    462420    psS32 halfR = r/2;
    463421    psS32 halfC = c/2;
    464     psRegion centerHalf = {qtrC,qtrR,qtrC+halfC,qtrR+halfR};
     422    psRegion centerHalf = {qtrC,qtrC+halfC,qtrR,qtrR+halfR};
    465423
    466424    psImage* image = psImageAlloc(c,r,PS_TYPE_F32);
     
    517475    */
    518476    image1 = psImageCopy(image1,image,PS_TYPE_F32);
    519     image2 = psImageTrim(image1,(psRegion) {
    520                              qtrC,qtrR,0,0
    521                          }
    522                         );
     477    image2 = psImageTrim(image1,psRegionSet(qtrC,0,qtrR,0));
    523478
    524479    if (image1 != image2) {
     
    559514    */
    560515    image1 = psImageCopy(image1,image,PS_TYPE_F32);
    561     image2 = psImageTrim(image1,(psRegion) {
    562                              qtrC,qtrR,-qtrC,-qtrR
    563                          }
    564                         );
     516    image2 = psImageTrim(image1,psRegionSet(qtrC,-qtrC, qtrR,-qtrR));
    565517
    566518    if (image1 != image2) {
     
    602554    */
    603555
    604     image2 = psImageTrim(NULL,(psRegion) {
    605                              qtrC,qtrR,0,0
    606                          }
    607                         );
     556    image2 = psImageTrim(NULL, psRegionSet(qtrC,0,qtrR,0));
    608557
    609558    if (image2 != NULL) {
     
    622571
    623572    image1 = psImageCopy(NULL,image,PS_TYPE_F32);
    624     image2 = psImageTrim(image1,(psRegion) {
    625                              -1,0,0,0
    626                          }
    627                         );
     573    image2 = psImageTrim(image1, psRegionSet(-1,0,0,0));
    628574
    629575    if (image2 != NULL) {
     
    642588
    643589    image1 = psImageCopy(NULL,image,PS_TYPE_F32);
    644     image2 = psImageTrim(image1,(psRegion) {
    645                              0,-1,0,0
    646                          }
    647                         );
     590    image2 = psImageTrim(image1, psRegionSet(0,0,-1,0));
    648591
    649592    if (image2 != NULL) {
     
    662605
    663606    image1 = psImageCopy(NULL,image,PS_TYPE_F32);
    664     image2 = psImageTrim(image1,(psRegion) {
    665                              0,0,image->numCols+1,0
    666                          }
    667                         );
     607    image2 = psImageTrim(image1, psRegionSet(0,image->numCols+1,0,0));
    668608
    669609    if (image2 != NULL) {
     
    682622
    683623    image1 = psImageCopy(NULL,image,PS_TYPE_F32);
    684     image2 = psImageTrim(image1,(psRegion) {
    685                              0,0,0,image->numRows+1
    686                          }
    687                         );
     624    image2 = psImageTrim(image1, psRegionSet(0,0,0,image->numRows+1));
    688625
    689626    if (image2 != NULL) {
     
    702639
    703640    image1 = psImageCopy(NULL,image,PS_TYPE_F32);
    704     image2 = psImageTrim(image1,(psRegion) {
    705                              0,0,-image->numCols,0
    706                          }
    707                         );
     641    image2 = psImageTrim(image1, psRegionSet(0,-image->numCols,0,0));
    708642
    709643    if (image2 != NULL) {
     
    722656
    723657    image1 = psImageCopy(NULL,image,PS_TYPE_F32);
    724     image2 = psImageTrim(image1,(psRegion) {
    725                              0,0,0,-image->numRows
    726                          }
    727                         );
     658    image2 = psImageTrim(image1, psRegionSet(0,0,0,-image->numRows));
    728659
    729660    if (image2 != NULL) {
Note: See TracChangeset for help on using the changeset viewer.