IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 2835


Ignore:
Timestamp:
Dec 27, 2004, 3:43:17 PM (22 years ago)
Author:
desonia
Message:

Bug #1066 - psImageOverlaySection shall return the number of pixels overlaid.

Location:
trunk/psLib
Files:
2 edited

Legend:

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

    r2807 r2835  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-12-23 19:14:15 $
     12 *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
     13 *  @date $Date: 2004-12-28 01:42:28 $
    1414 *
    1515 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    195195    psU32 imageColLimit;
    196196    psElemType type;
     197    psU32 pixelsOverlaid = 0;
    197198
    198199    if (image == NULL || overlay == NULL) {
    199200        psError(PS_ERR_BAD_PARAMETER_NULL, true,
    200201                PS_ERRORTEXT_psImage_IMAGE_NULL);
    201         return 1;
     202        return pixelsOverlaid;
    202203    }
    203204
     
    205206        psError(PS_ERR_BAD_PARAMETER_NULL, true,
    206207                PS_ERRORTEXT_psImageManip_OPERATION_NULL);
    207         return 1;
     208        return pixelsOverlaid;
    208209    }
    209210
     
    218219                PS_ERRORTEXT_psImageManip_OVERLAY_TYPE_MISMATCH,
    219220                typeStrOverlay, typeStr);
    220         return 2;
     221        return pixelsOverlaid;
    221222    }
    222223
     
    238239                col0, imageColLimit, row0, imageRowLimit,
    239240                imageNumCols, imageNumRows);
    240         return 3;
    241     }
    242 
    243     switch (type) {
    244 
    245         #define psImageOverlayCase(DATATYPE) \
    246     case PS_TYPE_##DATATYPE: \
    247         for (psU32 row=row0;row<imageRowLimit;row++) { \
     241        return pixelsOverlaid;
     242    }
     243
     244
     245    #define psImageOverlayLoop(DATATYPE,OP) { \
     246        for (int row=row0;row<imageRowLimit;row++) { \
    248247            ps##DATATYPE* imageRow = image->data.DATATYPE[row]; \
    249248            ps##DATATYPE* overlayRow = overlay->data.DATATYPE[row-row0]; \
    250             for (psU32 col=col0;col<imageColLimit;col++) { \
    251                 switch (*op) { \
    252                 case '+': \
    253                     imageRow[col] += overlayRow[col-col0]; \
    254                     break; \
    255                 case '-': \
    256                     imageRow[col] -= overlayRow[col-col0]; \
    257                     break; \
    258                 case '*': \
    259                     imageRow[col] *= overlayRow[col-col0]; \
    260                     break; \
    261                 case '/': \
    262                     imageRow[col] /= overlayRow[col-col0]; \
    263                     break; \
    264                 case '=': \
    265                     imageRow[col] = overlayRow[col-col0]; \
    266                     break; \
    267                 default: \
    268                     psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
    269                             PS_ERRORTEXT_psImageManip_OVERLAY_OPERATOR_INVALID, \
    270                             op); \
    271                     return 5; \
    272                 } \
    273             } \
    274         } \
    275         break;
    276 
     249            for (int col=col0;col<imageColLimit;col++) { \
     250                imageRow[col] OP overlayRow[col-col0]; \
     251            } \
     252        } \
     253        pixelsOverlaid += (imageRowLimit - row0) * (imageColLimit - col0); \
     254    }
     255
     256    #define psImageOverlayCase(DATATYPE) \
     257case PS_TYPE_##DATATYPE: \
     258    switch (*op) { \
     259    case '+': \
     260        psImageOverlayLoop(DATATYPE,+=); \
     261        break; \
     262    case '-': \
     263        psImageOverlayLoop(DATATYPE,-=); \
     264        break; \
     265    case '*': \
     266        psImageOverlayLoop(DATATYPE,*=); \
     267        break; \
     268    case '/': \
     269        psImageOverlayLoop(DATATYPE,/=); \
     270        break; \
     271    case '=': \
     272        psImageOverlayLoop(DATATYPE,=); \
     273        break; \
     274    default: \
     275        psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
     276                PS_ERRORTEXT_psImageManip_OVERLAY_OPERATOR_INVALID, \
     277                op); \
     278        return pixelsOverlaid; \
     279    } \
     280    break;
     281
     282    switch (type) {
    277283        psImageOverlayCase(U8);
    278284        psImageOverlayCase(U16);
    279         //        psImageOverlayCase(U32);      Not a requirement
    280         //        psImageOverlayCase(U64);      Not a requirement
     285        psImageOverlayCase(U32);       // Not a requirement
     286        psImageOverlayCase(U64);       // Not a requirement
    281287        psImageOverlayCase(S8);
    282288        psImageOverlayCase(S16);
    283         //        psImageOverlayCase(S32);      Not a requirement
    284         //        psImageOverlayCase(S64);      Not a requirement
     289        psImageOverlayCase(S32);       // Not a requirement
     290        psImageOverlayCase(S64);       // Not a requirement
    285291        psImageOverlayCase(F32);
    286292        psImageOverlayCase(F64);
     
    294300                    PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
    295301                    typeStr);
    296             return 6;
    297         }
    298     }
    299 
    300     return 0;
     302            return pixelsOverlaid;
     303        }
     304    }
     305
     306    return pixelsOverlaid;
    301307}
    302308
     
    832838
    833839        /* optimized public domain rotation routine by Karl Lager
    834          * 
    835          * float cosT,sinT; 
    836          * cosT = cos(t); 
    837          * sinT = sin(t); 
    838          * for (y = min_y; y <= max_y; y++) { 
    839          *     x' = min_x * cosT + y * sinT + x1'; 
    840          *     y' = y * cosT - min_x * sinT + y1'; 
    841          *     for (x = min_x; x <= max_x; x++) { 
     840         *
     841         * float cosT,sinT;
     842         * cosT = cos(t);
     843         * sinT = sin(t);
     844         * for (y = min_y; y <= max_y; y++) {
     845         *     x' = min_x * cosT + y * sinT + x1';
     846         *     y' = y * cosT - min_x * sinT + y1';
     847         *     for (x = min_x; x <= max_x; x++) {
    842848         *         if (x', y') is in the bounds of the bitmap, get pixel
    843          *            (x', y') and plot the pixel to (x, y) on screen. 
    844          *         x' += cosT; 
    845          *         y' -= sinT; 
     849         *            (x', y') and plot the pixel to (x, y) on screen.
     850         *         x' += cosT;
     851         *         y' -= sinT;
    846852         *     }
    847          * } 
     853         * }
    848854         */
    849855
  • trunk/psLib/test/image/tst_psImageManip.c

    r2754 r2835  
    66 *  @author Robert DeSonia, MHPCC
    77 *
    8  *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
    9  *  @date $Date: 2004-12-18 00:01:08 $
     8 *  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
     9 *  @date $Date: 2004-12-28 01:43:17 $
    1010 *
    1111 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    331331    1. Create a complex image with a wide range of complex values
    332332
    333     2. call psImageClipComplexRegion with min and max where there is at least 
     333    2. call psImageClipComplexRegion with min and max where there is at least
    334334       2 pixels in the image above) that is:
    335335        a) real(p) < real(min) && complex(p) < complex(min),
     
    347347    4. verify that all pixels in case (d) are unchanged from input
    348348
    349     5. verify that all pixels in case (e), (f), (g), (h), and (i) have the 
     349    5. verify that all pixels in case (e), (f), (g), (h), and (i) have the
    350350       value vmax
    351351
     
    606606    */
    607607
    608 
    609 
    610608    #define testOverlayTypeOP(DATATYPE,OP,OPSTRING) \
    611609    img = psImageAlloc(c,r,PS_TYPE_##DATATYPE); \
     
    624622    } \
    625623    retVal = psImageOverlaySection(img,img2,c/4,r/4,OPSTRING); \
    626     if (retVal != 0) { \
    627         psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned non-zero %s op",OPSTRING); \
     624    if (retVal == 0) { \
     625        psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned zero with %s op", \
     626                OPSTRING); \
    628627        return 1; \
    629628    } \
     
    705704             "within image boundaries");
    706705    retVal = psImageOverlaySection(img,img2,c/4,r/4,"+");
    707     if (retVal == 0) {
    708         psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned zero even though "
    709                 "overlay too big");
     706    if (retVal != 0) {
     707        psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection did not return "
     708                "zero even though overlay too big");
    710709        return 3;
    711710    }
     
    728727    psLogMsg(__func__,PS_LOG_INFO,"Following should error as overlay is NULL");
    729728    retVal = psImageOverlaySection(img,NULL,c/4,r/4,"+");
    730     if (retVal == 0) {
    731         psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned zero even though "
    732                 "overlay too big");
     729    if (retVal != 0) {
     730        psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection did not return "
     731                "zero even though overlay too big");
    733732        return 5;
    734733    }
     
    750749    psLogMsg(__func__,PS_LOG_INFO,"Following should error as image input is NULL");
    751750    retVal = psImageOverlaySection(NULL,img2,c/4,r/4,"+");
    752     if (retVal == 0) {
    753         psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned zero even though "
     751    if (retVal != 0) {
     752        psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned non-zero even though "
    754753                "overlay too big");
    755754        return 7;
     
    763762    psLogMsg(__func__,PS_LOG_INFO,"Following should error as operator is invalid");
    764763    retVal = psImageOverlaySection(img,img2,0,0,"$");
    765     if (retVal == 0) {
    766         psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned zero even though "
     764    if (retVal != 0) {
     765        psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned non-zero even though "
    767766                "overlay operator is invalid");
    768767        return 8;
     
    776775    psLogMsg(__func__,PS_LOG_INFO,"Following should error as operator is invalid");
    777776    retVal = psImageOverlaySection(img,img2,0,0,NULL);
    778     if(retVal == 0) {
    779         psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned zero even though "
     777    if(retVal != 0) {
     778        psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned non-zero even though "
    780779                "overlay operator is NULL");
    781780        return 9;
     
    783782
    784783    /*
    785     Verify the return integer is equal to non-zero and program execution 
     784    Verify the return integer is equal to non-zero and program execution
    786785    doesn't stop, if overlay image is a different type than the input image
    787786    */
     
    789788             "a different type");
    790789    retVal = psImageOverlaySection(img,img3,0,0,"+");
    791     if(retVal == 0) {
    792         psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned zero eventhough "
     790    if(retVal != 0) {
     791        psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned nonzero eventhough "
    793792                " overlay image type is different than input image.");
    794793        return 10;
    795     }
    796 
    797     /*
    798     Verify the return integer is equal to non-zero and program execution
    799     doesn't stop, if invalid input and overlay images
    800     */
    801     psLogMsg(__func__,PS_LOG_INFO,"Following should error as overlay and "
    802              "image are not valid for the psImageOverlaySection function.");
    803     retVal = psImageOverlaySection(img3,img4,0,0,"+");
    804     if(retVal == 0) {
    805         psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned zero eventhough "
    806                 "overlay and image type are invalid type.");
    807         return 11;
    808794    }
    809795
     
    819805    }
    820806    retVal = psImageOverlaySection(img,img2,0,0,"/");
    821     if (retVal != 0) {
    822         psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned non-zero when "
     807    if (retVal == 0) {
     808        psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned zero when "
    823809                "checking divide-by-zero.");
    824810        return 12;
     
    837823
    838824    /*
    839     This function shall generate a rescaled version of a psImage structure 
     825    This function shall generate a rescaled version of a psImage structure
    840826    derived from a specified statistics method.
    841827    */
     
    852838
    853839    /*
    854     Verify the returned psImage structure contains expected values, if the 
    855     input parameter input contains known data, the input scale is a known 
    856     value with a known statistical method specified in stats. Cases should 
    857     include at least two different scales and statistical methods. Comparison 
    858     of expected values should include a delta to allow testing on different 
     840    Verify the returned psImage structure contains expected values, if the
     841    input parameter input contains known data, the input scale is a known
     842    value with a known statistical method specified in stats. Cases should
     843    include at least two different scales and statistical methods. Comparison
     844    of expected values should include a delta to allow testing on different
    859845    platforms.
    860846    */
     
    10941080
    10951081    /*
    1096      The function psImageRoll shall generate a new psImage structure by 
     1082     The function psImageRoll shall generate a new psImage structure by
    10971083     rolling the input image the correponding number of pixels in the vertical
    10981084     and/or horizontal direction. The image output image shall be the same size
    1099      as the input image. Values which roll off the image are wrapped to the 
     1085     as the input image. Values which roll off the image are wrapped to the
    11001086     other side.
    11011087
    1102      Verify the returned psImage structure contains expected values, if the 
    1103      input image contains known values and the roll performed is known. 
    1104      Cases should include no roll, vertical roll, horizontal roll and 
    1105      combination vertical/horizontal rolls. Positive and negative rolls 
     1088     Verify the returned psImage structure contains expected values, if the
     1089     input image contains known values and the roll performed is known.
     1090     Cases should include no roll, vertical roll, horizontal roll and
     1091     combination vertical/horizontal rolls. Positive and negative rolls
    11061092     should be performed.
    11071093    */
     
    12741260    /*
    12751261
    1276     This function shall calculate a new psImage structure based upon the 
    1277     rotation of a given psImage structure. The center of rotation shall be the 
     1262    This function shall calculate a new psImage structure based upon the
     1263    rotation of a given psImage structure. The center of rotation shall be the
    12781264    center pixel of the input image.
    12791265
    1280     The following steps of the testpoint are done manually via inspection of 
     1266    The following steps of the testpoint are done manually via inspection of
    12811267    temp/fOut.fits & temp/sOut.fits.
    12821268
    1283         * Verify the returned psImage structure contains expected values, if 
    1284           the input parameter psImage contains known values. Cases should 
    1285           include rotations of 0, 45, 90, 135, 180, 225, 270, 315, 360 and at leat one 
     1269        * Verify the returned psImage structure contains expected values, if
     1270          the input parameter psImage contains known values. Cases should
     1271          include rotations of 0, 45, 90, 135, 180, 225, 270, 315, 360 and at leat one
    12861272          other arbitrary angle. Cases of the input image should include image
    12871273          with a center pixel and an image without a center pixel.
     
    15411527    /* psImageShift:
    15421528
    1543        This functions shall generate a new psImage structure by shifting the 
    1544        input psImage structure a specified number of pixels in the horizontal 
     1529       This functions shall generate a new psImage structure by shifting the
     1530       input psImage structure a specified number of pixels in the horizontal
    15451531       and/or vertical directions.
    15461532
    1547        Verify the returned psImage structure contains expected values, if the 
    1548        input psImage structure contains known values and a know shift in the 
    1549        vertical and/or horizontal directions. Cases should include no shift, 
    1550        vertical only(up,down), horizontal only(right, left), and combination 
    1551        shift. Cases should include fractional shifts. Comparison of expected 
    1552        values should include a delta to allow for testing on different 
     1533       Verify the returned psImage structure contains expected values, if the
     1534       input psImage structure contains known values and a know shift in the
     1535       vertical and/or horizontal directions. Cases should include no shift,
     1536       vertical only(up,down), horizontal only(right, left), and combination
     1537       shift. Cases should include fractional shifts. Comparison of expected
     1538       values should include a delta to allow for testing on different
    15531539       platforms.
    15541540
    1555        Verify the returned psImage structure contains values for pixels not in 
     1541       Verify the returned psImage structure contains values for pixels not in
    15561542       the original image set to the input parameter exposed.
    15571543
     
    15901576
    15911577    /*
    1592        Verify the returned psImage structure pointer is equal to the input 
     1578       Verify the returned psImage structure pointer is equal to the input
    15931579       parameter out if provided.
    15941580    */
     
    16031589
    16041590    /*
    1605        Verify the returned psImage structure pointer is null and program 
     1591       Verify the returned psImage structure pointer is null and program
    16061592       execution doesn't stop, if the input psImage structure pointer is null.
    16071593    */
     
    18201806    psErrorClear();
    18211807    psImage* invImage = psImageAlloc(cols,rows,PS_TYPE_PTR);
     1808    memset(invImage->rawDataBuffer,0,cols*rows*sizeof(psPtr)); // make sure the image is of all NULLs
    18221809    result = psImageResample(result,invImage,2,PS_INTERPOLATE_FLAT);
    18231810    if (result != NULL) {
Note: See TracChangeset for help on using the changeset viewer.