IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Jul 12, 2004, 3:37:59 PM (22 years ago)
Author:
desonia
Message:

removed the dependency creation stuff, as George hated it ALOT!

File:
1 edited

Legend:

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

    r1193 r1212  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-07-08 01:05:01 $
     8 *  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-07-13 01:37:58 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2424static int testImageSubset(void);
    2525static int testImageCopy(void);
    26 static int testImageClip(void);
    27 static int testImageClipNAN(void);
    28 static int testImageOverlay(void);
    2926
    3027testDescription tests[] = {
     
    3431                              {testImageSubset,550,"psImageSubset",0,true},
    3532                              {testImageCopy,551,"psImageCopy",0,false},
    36                               {testImageClip,571,"psImageClip",0,false},
    37                               {testImageClipNAN,572,"psImageClipNAN",0,false},
    38                               {testImageOverlay,573,"psImageOverlay",0,false},
    3933                              {NULL}
    4034                          };
     
    623617}
    624618
    625 int testImageClip(void)
    626 {
    627     psImage* img = NULL;
    628     unsigned int c = 128;
    629     unsigned int r = 256;
    630     psF32 min;
    631     psF32 max;
    632     int numClipped = 0;
    633     int retVal;
    634 
    635     psLogMsg(__func__,PS_LOG_INFO,
    636              "psImageClip shall limit the minimum and maximum data value within a psImage structure");
    637 
    638     /*
    639 
    640         psImageClip shall limit the minimum and maximum data value within a
    641         psImage structure to a specified min and max value.
    642 
    643         Verify the returned integer is equal to the number of pixels clipped,
    644         if the input psImage structure contains known values and input parameters
    645         min and max have know values.
    646 
    647         Verify the psImage structure specified by the input parameter input is
    648         modified to contain the expected values, if the input psImage structure
    649         contains known values, min and max are specified and vmin and vmax
    650         parameters are known.
    651 
    652         Verify the retuned integer is zero, psImage structure input is unmodified
    653         and program executions doesn't stop, if input parameter psImage structure
    654         pointer is null.
    655 
    656         Verify the retuned integer is zero, psImage structure input is unmodified
    657         and program executions doesn't stop, if input parameter min is larger than max.
    658     */
    659 
    660     // create image
    661     #define testImageClipByType(datatype) \
    662     img = psImageAlloc(c,r,PS_TYPE_##datatype); \
    663     for (unsigned int row=0;row<r;row++) { \
    664         ps##datatype* imgRow = img->data.datatype[row]; \
    665         for (unsigned int col=0;col<c;col++) { \
    666             imgRow[col] = (ps##datatype)(row+col); \
    667         } \
    668     } \
    669     min = (float)r/2.0f; \
    670     max = (float)r; \
    671     \
    672     retVal = psImageClip(img,min,-1.0f,max,-2.0f); \
    673     \
    674     numClipped = 0; \
    675     for (unsigned int row=0;row<r;row++) { \
    676         ps##datatype* imgRow = img->data.datatype[row]; \
    677         for (unsigned int col=0;col<c;col++) { \
    678             ps##datatype value = (ps##datatype)(row+col); \
    679             if (value < (ps##datatype)min) { \
    680                 numClipped++; \
    681                 value = -1; \
    682             } else if (value > (ps##datatype)max) { \
    683                 numClipped++; \
    684                 value = -2; \
    685             } \
    686             if (fabsf(imgRow[col]-value) > FLT_EPSILON) { \
    687                 psError(__func__,"Pixel value is not as expected (%d vs %d) at %u,%u", \
    688                         imgRow[col],value,col,row); \
    689                 return 1; \
    690             } \
    691         } \
    692     } \
    693     if (retVal != numClipped) { \
    694         psError(__func__,"Expected %d clips, but got %d", \
    695                 numClipped,retVal); \
    696         return 2; \
    697     } \
    698     psFree(img);
    699 
    700     #define testImageClipByComplexType(datatype) \
    701     img = psImageAlloc(c,r,PS_TYPE_##datatype); \
    702     for (unsigned int row=0;row<r;row++) { \
    703         ps##datatype* imgRow = img->data.datatype[row]; \
    704         for (unsigned int col=0;col<c;col++) { \
    705             imgRow[col] = (ps##datatype)(row+I*col); \
    706         } \
    707     } \
    708     min = (float)r/2.0f; \
    709     max = (float)r; \
    710     \
    711     retVal = psImageClip(img,min,-1.0f,max,-2.0f); \
    712     \
    713     numClipped = 0; \
    714     for (unsigned int row=0;row<r;row++) { \
    715         ps##datatype* imgRow = img->data.datatype[row]; \
    716         for (unsigned int col=0;col<c;col++) { \
    717             ps##datatype value = row+I*col; \
    718             if (cabs(value) < min) { \
    719                 numClipped++; \
    720                 value = -1.0f; \
    721             } else if (cabs(value) > max) { \
    722                 numClipped++; \
    723                 value = -2.0f; \
    724             } \
    725             if (fabsf(creal(imgRow[col])-creal(value)) > FLT_EPSILON || \
    726                     fabsf(cimag(imgRow[col])-cimag(value)) > FLT_EPSILON) { \
    727                 psError(__func__,"Pixel value is not as expected (%.2f+%.2fi vs %.2f+%.2fi) at %u,%u", \
    728                         creal(imgRow[col]),cimag(imgRow[col]),creal(value),cimag(value),col,row); \
    729                 return 1; \
    730             } \
    731         } \
    732     } \
    733     if (retVal != numClipped) { \
    734         psError(__func__,"Expected %d clips, but got %d", \
    735                 numClipped,retVal); \
    736         return 2; \
    737     } \
    738     psFree(img);
    739 
    740     psLogMsg(__func__,PS_LOG_INFO,"Testing clipping of F64 imagery");
    741     testImageClipByType(F64);
    742     psLogMsg(__func__,PS_LOG_INFO,"Testing clipping of F32 imagery");
    743     testImageClipByType(F32);
    744     psLogMsg(__func__,PS_LOG_INFO,"Testing clipping of S32 imagery");
    745     testImageClipByType(S32);
    746     psLogMsg(__func__,PS_LOG_INFO,"Testing clipping of S16 imagery");
    747     testImageClipByType(S16);
    748     psLogMsg(__func__,PS_LOG_INFO,"Testing clipping of S8 imagery");
    749     testImageClipByType(S8);
    750     psLogMsg(__func__,PS_LOG_INFO,"Testing clipping of U32 imagery");
    751     testImageClipByType(U32);
    752     psLogMsg(__func__,PS_LOG_INFO,"Testing clipping of U16 imagery");
    753     testImageClipByType(U16);
    754     psLogMsg(__func__,PS_LOG_INFO,"Testing clipping of U8 imagery");
    755     testImageClipByType(U8);
    756     psLogMsg(__func__,PS_LOG_INFO,"Testing clipping of C32 imagery");
    757     testImageClipByComplexType(C32);
    758     psLogMsg(__func__,PS_LOG_INFO,"Testing clipping of C64 imagery");
    759     testImageClipByComplexType(C64);
    760 
    761     // Verify the retuned integer is zero, psImage structure input is unmodified
    762     // and program executions doesn't stop, if input parameter psImage structure
    763     // pointer is null.
    764     retVal = psImageClip(NULL,min,-1.0f,max,-2.0f);
    765     if (retVal != 0) {
    766         psError(__func__,"Expected zero return for clips of a NULL image.");
    767         return 3;
    768     }
    769 
    770     // Verify the retuned integer is zero, psImage structure input is unmodified
    771     // and program executions doesn't stop, if input parameter min is larger than max.
    772     psLogMsg(__func__,PS_LOG_INFO,"Following should be an error (max<min)");
    773     retVal = psImageClip(img,max,-1.0f,min,-2.0f);
    774     if (retVal != 0) {
    775         psError(__func__,"Expected zero return for clips when max < min.");
    776         return 4;
    777     }
    778 
    779     return 0;
    780 }
    781 
    782 int testImageClipNAN(void)
    783 {
    784     psImage* img = NULL;
    785     unsigned int c = 128;
    786     unsigned int r = 256;
    787     int numClipped = 0;
    788     int retVal;
    789 
    790     psLogMsg(__func__,PS_LOG_INFO,
    791              "psImageClipNaN shall modified pixel values of NaN with a specified value");
    792 
    793     /*
    794         psImageClipNaN shall modify a psImage structure with pixel values set
    795         to NaN to a value specified as an input parameter.
    796 
    797         Verify the returned integer is equal to the number of pixels modified
    798         and the psImage is modified at locations where NaN pixels where
    799         located to the value specified in the input parameter value.
    800 
    801         Verify the returned integer is zero and program execution doesn't stop,
    802         if the input parameter psImage structure pointer is null.
    803     */
    804 
    805     // create image
    806     #define testImageClipNaNByType(datatype) \
    807     img = psImageAlloc(c,r,PS_TYPE_##datatype); \
    808     for (unsigned row=0;row<r;row++) { \
    809         ps##datatype* imgRow = img->data.datatype[row]; \
    810         for (unsigned col=0;col<c;col++) { \
    811             if (row == col) { \
    812                 imgRow[col] = NAN; \
    813             } else if (row+1 == col) { \
    814                 imgRow[col] = INFINITY; \
    815             } else { \
    816                 imgRow[col] = (ps##datatype)(row+col); \
    817             } \
    818         } \
    819     } \
    820     \
    821     retVal = psImageClipNaN(img,-1.0f); \
    822     \
    823     numClipped = 0; \
    824     for (unsigned row=0;row<r;row++) { \
    825         ps##datatype* imgRow = img->data.datatype[row]; \
    826         for (unsigned col=0;col<c;col++) { \
    827             ps##datatype value = (ps##datatype)(row+col); \
    828             if ( (row == col) || (row+1 == col) ) { \
    829                 numClipped++; \
    830                 value = -1.0; \
    831             } \
    832             if (fabsf(imgRow[col]-value) > FLT_EPSILON) { \
    833                 psError(__func__,"Pixel value is not as expected (%f vs %f) at %d,%d", \
    834                         imgRow[col],value,col,row); \
    835                 return 1; \
    836             } \
    837         } \
    838     } \
    839     if (retVal != numClipped) { \
    840         psError(__func__,"Expected %d clips, but got %d", \
    841                 numClipped,retVal); \
    842         return 2; \
    843     } \
    844     psFree(img);
    845 
    846     testImageClipNaNByType(F32);
    847     testImageClipNaNByType(F64);
    848 
    849     // Verify the retuned integer is zero, psImage structure input is unmodified
    850     // and program executions doesn't stop, if input parameter psImage structure
    851     // pointer is null.
    852     retVal = psImageClipNaN(NULL,-1.0f);
    853     if (retVal != 0) {
    854         psError(__func__,"Expected zero return for clips of a NULL image.");
    855         return 3;
    856     }
    857 
    858     return 0;
    859 }
    860 
    861 int testImageOverlay(void)
    862 {
    863 
    864     psImage* img = NULL;
    865     psImage* img2 = NULL;
    866     unsigned int c = 128;
    867     unsigned int r = 256;
    868     int retVal;
    869 
    870     /*
    871     psImageSectionOverlay shall modified pixel values in a psImage structure to
    872     be equal to the value of the originaldata and an overlay image with a
    873     specified operation. Valid operations include =, +, -, *, /.
    874 
    875     Verify the returned integer is zero
    876     and the input parameter psImage structure is modified at the specified
    877     location and range with the given overlay image and the specified
    878     function. Cases should include all the valid operations. Comparison of
    879     expected values should include a delta to allow for testing on
    880     different platforms.
    881 
    882     */
    883 
    884 
    885 
    886     #define testOverlayTypeOP(DATATYPE,OP,OPSTRING) \
    887     img = psImageAlloc(c,r,PS_TYPE_##DATATYPE); \
    888     for (unsigned row=0;row<r;row++) { \
    889         ps##DATATYPE* imgRow = img->data.DATATYPE[row]; \
    890         for (unsigned col=0;col<c;col++) { \
    891             imgRow[col] = 6.0; \
    892         } \
    893     } \
    894     img2 = psImageAlloc(c/2,r/2,PS_TYPE_##DATATYPE); \
    895     for (unsigned row=0;row<r/2;row++) { \
    896         ps##DATATYPE* img2Row = img2->data.DATATYPE[row]; \
    897         for (unsigned col=0;col<c/2;col++) { \
    898             img2Row[col] = 2.0; \
    899         } \
    900     } \
    901     retVal = psImageOverlaySection(img,img2,c/4,r/4,OPSTRING); \
    902     if (retVal != 0) { \
    903         psError(__func__,"psImageOverlaySection returned non-zero %s op",OPSTRING); \
    904         return 1; \
    905     } \
    906     for (unsigned row=0;row<r;row++) { \
    907         ps##DATATYPE* imgRow = img->data.DATATYPE[row]; \
    908         ps##DATATYPE* img2Row = img2->data.DATATYPE[row]; \
    909         for (unsigned col=0;col<c;col++) { \
    910             ps##DATATYPE val = 6.0; \
    911             if ( ! (row < r/4 || row >= r/2+r/4 || col < c/4 || col >= c/2+c/4)) { \
    912                 val OP 2.0; \
    913             } \
    914             if (fabsf(imgRow[col] - val) > FLT_EPSILON) { \
    915                 psError(__func__,"Value incorrect at %d,%d (%.2f vs %.2f for %s)", \
    916                         col,row,imgRow[col],val,OPSTRING); \
    917                 return 2; \
    918             } \
    919             if (row < r/2 && col < c/2 && fabsf(img2Row[col] - 2.0) > FLT_EPSILON) { \
    920                 psError(__func__,"Overlay modified at %d,%d (%.2f for %s)", \
    921                         col,row,img2Row[col],OPSTRING); \
    922                 return 2; \
    923             } \
    924         } \
    925     } \
    926     psFree(img); \
    927     psFree(img2);
    928 
    929     #define testOverlayType(DATATYPE) \
    930     testOverlayTypeOP(DATATYPE,+=,"+"); \
    931     testOverlayTypeOP(DATATYPE,-=,"-"); \
    932     testOverlayTypeOP(DATATYPE,*=,"*");\
    933     testOverlayTypeOP(DATATYPE,/=,"/");\
    934     testOverlayTypeOP(DATATYPE,=,"=");
    935 
    936     testOverlayType(C64);
    937     testOverlayType(C32);
    938     testOverlayType(F64);
    939     testOverlayType(F32);
    940     testOverlayType(S16);
    941     testOverlayType(S8);
    942     testOverlayType(U16);
    943     testOverlayType(U8);
    944 
    945     /*
    946     Verify the returned integer is equal to non-zero and the input psImage structure
    947     is unmodified, if the overlay specified is not within the data range of the
    948     input psImage structure.
    949     */
    950 
    951     img = psImageAlloc(c,r,PS_TYPE_F32);
    952     for (unsigned row=0;row<r;row++) {
    953         psF32* imgRow = img->data.F32[row];
    954         for (unsigned col=0;col<c;col++) {
    955             imgRow[col] = 6.0f;
    956         }
    957     }
    958     img2 = psImageAlloc(c,r,PS_TYPE_F32);
    959     for (unsigned row=0;row<r;row++) {
    960         psF32* img2Row = img2->data.F32[row];
    961         for (unsigned col=0;col<c;col++) {
    962             img2Row[col] = 2.0f;
    963         }
    964     }
    965 
    966     psLogMsg(__func__,PS_LOG_INFO,"Following should error as overlay isn't within image boundaries");
    967     retVal = psImageOverlaySection(img,img2,c/4,r/4,"+");
    968     if (retVal == 0) {
    969         psError(__func__,"psImageOverlaySection returned zero even though "
    970                 "overlay too big");
    971         return 3;
    972     }
    973     for (unsigned row=0;row<r;row++) {
    974         psF32* imgRow = img->data.F32[row];
    975         for (unsigned col=0;col<c;col++) {
    976             if (imgRow[col] != 6.0f) {
    977                 psError(__func__,"Input image modified when overlay size too big");
    978                 return 4;
    979             }
    980         }
    981     }
    982 
    983     /*
    984     Verify the returned integer is equal to non-zero, the input psImage
    985     structure is unmodified and program execution doesn't stop, if the
    986     overlay specified is null.
    987     */
    988 
    989     psLogMsg(__func__,PS_LOG_INFO,"Following should error as overlay is NULL");
    990     retVal = psImageOverlaySection(img,NULL,c/4,r/4,"+");
    991     if (retVal == 0) {
    992         psError(__func__,"psImageOverlaySection returned zero even though "
    993                 "overlay too big");
    994         return 5;
    995     }
    996     for (unsigned row=0;row<r;row++) {
    997         psF32* imgRow = img->data.F32[row];
    998         for (unsigned col=0;col<c;col++) {
    999             if (imgRow[col] != 6.0f) {
    1000                 psError(__func__,"Input image modified when overlay NULL");
    1001                 return 6;
    1002             }
    1003         }
    1004     }
    1005 
    1006     /*
    1007     Verify the returned integer is equal to non-zero and program execution
    1008     doesn't stop, if the input parameter image is null.
    1009     */
    1010 
    1011     psLogMsg(__func__,PS_LOG_INFO,"Following should error as image input is NULL");
    1012     retVal = psImageOverlaySection(NULL,img2,c/4,r/4,"+");
    1013     if (retVal == 0) {
    1014         psError(__func__,"psImageOverlaySection returned zero even though "
    1015                 "overlay too big");
    1016         return 7;
    1017     }
    1018 
    1019     /*
    1020     Verify program execution doen't stop, if the overly image contains
    1021     zero values with division operation is specified.
    1022     */
    1023     for (unsigned row=0;row<r;row++) {
    1024         psF32* img2Row = img2->data.F32[row];
    1025         for (unsigned col=0;col<c;col++) {
    1026             img2Row[col] = 0.0f;
    1027         }
    1028     }
    1029     retVal = psImageOverlaySection(img,img2,0,0,"/");
    1030     if (retVal != 0) {
    1031         psError(__func__,"psImageOverlaySection returned non-zero when "
    1032                 "checking divide-by-zero.");
    1033         return 8;
    1034     }
    1035 
    1036     psFree(img);
    1037     psFree(img2);
    1038 
    1039     return 0;
    1040 }
Note: See TracChangeset for help on using the changeset viewer.