IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 938


Ignore:
Timestamp:
Jun 8, 2004, 1:57:00 PM (22 years ago)
Author:
desonia
Message:

added test for psImageClip().

Location:
trunk/psLib
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/image/psImage.c

    r889 r938  
    99 *  @author Ross Harman, MHPCC
    1010 *
    11  *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-06-07 00:32:53 $
     11 *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-06-08 23:56:34 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    21202120        return 0;
    21212121    }
     2122
     2123    if (max < min) {
     2124        psError(__func__,"psImageClip can not be invoked with max < min.");
     2125        return 0;
     2126    }
     2127
    21222128    numRows = input->numRows;
    21232129    numCols = input->numCols;
  • trunk/psLib/src/mathtypes/psImage.c

    r889 r938  
    99 *  @author Ross Harman, MHPCC
    1010 *
    11  *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-06-07 00:32:53 $
     11 *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-06-08 23:56:34 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    21202120        return 0;
    21212121    }
     2122
     2123    if (max < min) {
     2124        psError(__func__,"psImageClip can not be invoked with max < min.");
     2125        return 0;
     2126    }
     2127
    21222128    numRows = input->numRows;
    21232129    numCols = input->numCols;
  • trunk/psLib/test/image/tst_psImage.c

    r856 r938  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-06-04 03:12:11 $
     8 *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-06-08 23:57:00 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2424static int testImageSubset(void);
    2525static int testImageCopy(void);
     26static int testImageClip(void);
    2627
    2728testDescription tests[] = {
     
    2930                              {testImageSubset,"547/550-testImageSubset",0},
    3031                              {testImageCopy,"551-testImageCopy",0},
     32                              {testImageClip,"571-testImageClip",0},
    3133                              {NULL}
    3234                          };
     
    618620    return 0;
    619621}
     622
     623int testImageClip(void)
     624{
     625    psImage* img = NULL;
     626    unsigned int c = 128;
     627    unsigned int r = 256;
     628    psF32 min;
     629    psF32 max;
     630    int currentId = psMemGetId();
     631    int numClipped = 0;
     632    int retVal;
     633
     634    psLogMsg(__func__,PS_LOG_INFO,
     635             "psImageClip shall limit the minimum and maximum data value within a psImage structure");
     636
     637    /*
     638
     639        psImageClip shall limit the minimum and maximum data value within a
     640        psImage structure to a specified min and max value.
     641
     642        Verify the returned integer is equal to the number of pixels clipped,
     643        if the input psImage structure contains known values and input parameters
     644        min and max have know values.
     645
     646        Verify the psImage structure specified by the input parameter input is
     647        modified to contain the expected values, if the input psImage structure
     648        contains known values, min and max are specified and vmin and vmax
     649        parameters are known.
     650
     651        Verify the retuned integer is zero, psImage structure input is unmodified
     652        and program executions doesn't stop, if input parameter psImage structure
     653        pointer is null.
     654
     655        Verify the retuned integer is zero, psImage structure input is unmodified
     656        and program executions doesn't stop, if input parameter min is larger than max.
     657    */
     658
     659    // create image
     660    #define testImageClipByType(datatype) \
     661    img = psImageAlloc(c,r,PS_TYPE_##datatype); \
     662    for (unsigned row=0;row<r;row++) { \
     663        ps##datatype* imgRow = img->data.datatype[row]; \
     664        for (unsigned col=0;col<c;col++) { \
     665            imgRow[col] = (ps##datatype)(row+col); \
     666        } \
     667    } \
     668    min = (float)r/2.0f; \
     669    max = (float)r; \
     670    \
     671    retVal = psImageClip(img,min,-1.0f,max,-2.0f); \
     672    \
     673    numClipped = 0; \
     674    for (unsigned row=0;row<r;row++) { \
     675        ps##datatype* imgRow = img->data.datatype[row]; \
     676        for (unsigned col=0;col<c;col++) { \
     677            ps##datatype value = (ps##datatype)(row+col); \
     678            if (value < (ps##datatype)min) { \
     679                numClipped++; \
     680                value = -1; \
     681            } else if (value > (ps##datatype)max) { \
     682                numClipped++; \
     683                value = -2; \
     684            } \
     685            if (fabsf(imgRow[col]-value) > FLT_EPSILON) { \
     686                psError(__func__,"Pixel value is not as expected (%d vs %d) at %d,%d", \
     687                        imgRow[col],value,col,row); \
     688                return 1; \
     689            } \
     690        } \
     691    } \
     692    if (retVal != numClipped) { \
     693        psError(__func__,"Expected %d clips, but got %d", \
     694                numClipped,retVal); \
     695        return 2; \
     696    } \
     697    psImageFree(img);
     698
     699    testImageClipByType(F64);
     700    testImageClipByType(F32);
     701    testImageClipByType(S64);
     702    testImageClipByType(S32);
     703    testImageClipByType(S16);
     704    testImageClipByType(S8);
     705    testImageClipByType(U64);
     706    testImageClipByType(U32);
     707    testImageClipByType(U16);
     708    testImageClipByType(U8);
     709
     710    // Verify the retuned integer is zero, psImage structure input is unmodified
     711    // and program executions doesn't stop, if input parameter psImage structure
     712    // pointer is null.
     713    retVal = psImageClip(NULL,min,-1.0f,max,-2.0f);
     714    if (retVal != 0) {
     715        psError(__func__,"Expected zero return for clips of a NULL image.");
     716        return 3;
     717    }
     718
     719    // Verify the retuned integer is zero, psImage structure input is unmodified
     720    // and program executions doesn't stop, if input parameter min is larger than max.
     721    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error (max<min)");
     722    retVal = psImageClip(img,max,-1.0f,min,-2.0f);
     723    if (retVal != 0) {
     724        psError(__func__,"Expected zero return for clips when max < min.");
     725        return 4;
     726    }
     727
     728    if (psMemCheckLeaks(currentId,NULL,NULL) != 0) {
     729        psAbort(__func__,"Memory Leaks!");
     730    }
     731    psMemCheckCorruption(1);
     732
     733    return 0;
     734}
Note: See TracChangeset for help on using the changeset viewer.