IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 821


Ignore:
Timestamp:
Jun 1, 2004, 11:30:47 AM (22 years ago)
Author:
desonia
Message:

added psImageOverlay function.

Location:
trunk/psLib/src
Files:
2 edited

Legend:

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

    r820 r821  
    99 *  @author Ross Harman, MHPCC
    1010 *
    11  *  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-06-01 20:00:08 $
     11 *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-06-01 21:30:47 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    389389{
    390390    int numClipped = 0;
    391     psU32 numRows;
    392     psU32 numCols;
     391    unsigned int numRows;
     392    unsigned int numCols;
    393393
    394394    if (input == NULL) {
     
    400400    switch (input->type.type) {
    401401
    402         #define psImageClipCase(type) \
     402        #define psImageClipCase(type)\
    403403    case PS_TYPE_##type: { \
    404404            ps##type minimum = (ps##type) min; \
    405405            ps##type maximum = (ps##type) max; \
    406             for (psU32 row = 0;row<numRows;row++) { \
     406            for (unsigned int row = 0;row<numRows;row++) { \
    407407                ps##type* inputRow = input->data.type[row]; \
    408                 for (psU32 col = 0; col < numCols; col++) { \
     408                for (unsigned int col = 0; col < numCols; col++) { \
    409409                    if (inputRow[col] < minimum) { \
    410410                        inputRow[col] = (ps##type)vmin; \
     
    441441{
    442442    int numClipped = 0;
    443     psU32 numRows;
    444     psU32 numCols;
     443    unsigned int numRows;
     444    unsigned int numCols;
    445445
    446446    if (input == NULL) {
     
    453453
    454454        #define psImageClipNaNCase(type) \
    455     case PS_TYPE_##type: { \
    456             for (psU32 row = 0;row<numRows;row++) { \
    457                 ps##type* inputRow = input->data.type[row]; \
    458                 for (psU32 col = 0; col < numCols; col++) { \
    459                     if (! isfinite(inputRow[col])) { \
    460                         inputRow[col] = (ps##type)value; \
    461                         numClipped++; \
    462                     } \
     455    case PS_TYPE_##type: \
     456        for (unsigned int row = 0;row<numRows;row++) { \
     457            ps##type* inputRow = input->data.type[row]; \
     458            for (unsigned int col = 0; col < numCols; col++) { \
     459                if (! isfinite(inputRow[col])) { \
     460                    inputRow[col] = (ps##type)value; \
     461                    numClipped++; \
    463462                } \
    464463            } \
     
    478477    return numClipped;
    479478}
     479
     480int psImageOverlaySection(psImage* image, const psImage* overlay, int col0,
     481                          int row0, const char* op)
     482{
     483    unsigned int imageNumRows;
     484    unsigned int imageNumCols;
     485    unsigned int overlayNumRows;
     486    unsigned int overlayNumCols;
     487    unsigned int imageRowLimit;
     488    unsigned int imageColLimit;
     489    psElemType  type;
     490
     491    if (image == NULL || overlay == NULL) {
     492        psError(__func__,"one of the input images was NULL.");
     493        return 1;
     494    }
     495
     496    if (op == NULL) {
     497        psError(__func__,"Operation can not be NULL.");
     498        return 1;
     499    }
     500
     501    type = image->type.type;
     502
     503    if (type != overlay->type.type) {
     504        psError(__func__,"Image and overlay datatypes must match. (%d vs %d)",
     505                type,overlay->type.type);
     506        return 2;
     507    }
     508
     509    imageNumRows = image->numRows;
     510    imageNumCols = image->numCols;
     511    overlayNumRows = overlay->numRows;
     512    overlayNumCols = overlay->numCols;
     513
     514    /* check row0/col0 to see if it is within the image size */
     515    if (row0 < 0 || col0 < 0 || row0 >= imageNumRows || col0 >= imageNumCols) {
     516        psError(__func__, "Overlay origin of (%d,%d) is outside of the image dimensions (%d x %d).",
     517                col0, row0, imageNumCols, imageNumRows);
     518        return 3;
     519    }
     520
     521    /* check if overlay is totally withing input image */
     522    imageRowLimit = row0+overlayNumRows;
     523    imageColLimit = col0+overlayNumCols;
     524    if (imageRowLimit > imageNumRows || imageColLimit > imageNumCols) {
     525        psError(__func__, "Overlay image (%d,%d -> %d,%d) is partially outside"
     526                " of the input image (%d x %d).",
     527                col0, row0, col0+overlayNumCols-1, row0+overlayNumRows-1,
     528                imageNumCols,imageNumRows);
     529        return 4;
     530    }
     531
     532    switch (type) {
     533
     534        #define psImageOverlayCase(DATATYPE) \
     535    case PS_TYPE_##DATATYPE: \
     536        for (unsigned int row=row0;row<imageRowLimit;row++) { \
     537            ps##DATATYPE* imageRow = image->data.DATATYPE[row]; \
     538            ps##DATATYPE* overlayRow = overlay->data.DATATYPE[row-row0]; \
     539            for (unsigned int col=col0;col<imageColLimit;col++) { \
     540                switch (*op) { \
     541                case '+': \
     542                    imageRow[col] += overlayRow[col-col0]; \
     543                    break; \
     544                case '-': \
     545                    imageRow[col] -= overlayRow[col-col0]; \
     546                    break; \
     547                case '*': \
     548                    imageRow[col] *= overlayRow[col-col0]; \
     549                    break; \
     550                case '/': \
     551                    imageRow[col] /= overlayRow[col-col0]; \
     552                    break; \
     553                default: \
     554                    psError(__func__,"Unknown operation %s",op); \
     555                    return 5; \
     556                } \
     557            } \
     558        }
     559
     560        psImageOverlayCase(U8);
     561        psImageOverlayCase(U16);
     562        psImageOverlayCase(U32);
     563        psImageOverlayCase(U64);
     564        psImageOverlayCase(S8);
     565        psImageOverlayCase(S16);
     566        psImageOverlayCase(S32);
     567        psImageOverlayCase(S64);
     568        psImageOverlayCase(F32);
     569        psImageOverlayCase(F64);
     570        psImageOverlayCase(C32);
     571        psImageOverlayCase(C64);
     572
     573    default:
     574        psError(__func__,"Can not operate on type %d.",type);
     575    }
     576
     577    return 0;
     578}
  • trunk/psLib/src/mathtypes/psImage.c

    r820 r821  
    99 *  @author Ross Harman, MHPCC
    1010 *
    11  *  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
    12  *  @date $Date: 2004-06-01 20:00:08 $
     11 *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
     12 *  @date $Date: 2004-06-01 21:30:47 $
    1313 *
    1414 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    389389{
    390390    int numClipped = 0;
    391     psU32 numRows;
    392     psU32 numCols;
     391    unsigned int numRows;
     392    unsigned int numCols;
    393393
    394394    if (input == NULL) {
     
    400400    switch (input->type.type) {
    401401
    402         #define psImageClipCase(type) \
     402        #define psImageClipCase(type)\
    403403    case PS_TYPE_##type: { \
    404404            ps##type minimum = (ps##type) min; \
    405405            ps##type maximum = (ps##type) max; \
    406             for (psU32 row = 0;row<numRows;row++) { \
     406            for (unsigned int row = 0;row<numRows;row++) { \
    407407                ps##type* inputRow = input->data.type[row]; \
    408                 for (psU32 col = 0; col < numCols; col++) { \
     408                for (unsigned int col = 0; col < numCols; col++) { \
    409409                    if (inputRow[col] < minimum) { \
    410410                        inputRow[col] = (ps##type)vmin; \
     
    441441{
    442442    int numClipped = 0;
    443     psU32 numRows;
    444     psU32 numCols;
     443    unsigned int numRows;
     444    unsigned int numCols;
    445445
    446446    if (input == NULL) {
     
    453453
    454454        #define psImageClipNaNCase(type) \
    455     case PS_TYPE_##type: { \
    456             for (psU32 row = 0;row<numRows;row++) { \
    457                 ps##type* inputRow = input->data.type[row]; \
    458                 for (psU32 col = 0; col < numCols; col++) { \
    459                     if (! isfinite(inputRow[col])) { \
    460                         inputRow[col] = (ps##type)value; \
    461                         numClipped++; \
    462                     } \
     455    case PS_TYPE_##type: \
     456        for (unsigned int row = 0;row<numRows;row++) { \
     457            ps##type* inputRow = input->data.type[row]; \
     458            for (unsigned int col = 0; col < numCols; col++) { \
     459                if (! isfinite(inputRow[col])) { \
     460                    inputRow[col] = (ps##type)value; \
     461                    numClipped++; \
    463462                } \
    464463            } \
     
    478477    return numClipped;
    479478}
     479
     480int psImageOverlaySection(psImage* image, const psImage* overlay, int col0,
     481                          int row0, const char* op)
     482{
     483    unsigned int imageNumRows;
     484    unsigned int imageNumCols;
     485    unsigned int overlayNumRows;
     486    unsigned int overlayNumCols;
     487    unsigned int imageRowLimit;
     488    unsigned int imageColLimit;
     489    psElemType  type;
     490
     491    if (image == NULL || overlay == NULL) {
     492        psError(__func__,"one of the input images was NULL.");
     493        return 1;
     494    }
     495
     496    if (op == NULL) {
     497        psError(__func__,"Operation can not be NULL.");
     498        return 1;
     499    }
     500
     501    type = image->type.type;
     502
     503    if (type != overlay->type.type) {
     504        psError(__func__,"Image and overlay datatypes must match. (%d vs %d)",
     505                type,overlay->type.type);
     506        return 2;
     507    }
     508
     509    imageNumRows = image->numRows;
     510    imageNumCols = image->numCols;
     511    overlayNumRows = overlay->numRows;
     512    overlayNumCols = overlay->numCols;
     513
     514    /* check row0/col0 to see if it is within the image size */
     515    if (row0 < 0 || col0 < 0 || row0 >= imageNumRows || col0 >= imageNumCols) {
     516        psError(__func__, "Overlay origin of (%d,%d) is outside of the image dimensions (%d x %d).",
     517                col0, row0, imageNumCols, imageNumRows);
     518        return 3;
     519    }
     520
     521    /* check if overlay is totally withing input image */
     522    imageRowLimit = row0+overlayNumRows;
     523    imageColLimit = col0+overlayNumCols;
     524    if (imageRowLimit > imageNumRows || imageColLimit > imageNumCols) {
     525        psError(__func__, "Overlay image (%d,%d -> %d,%d) is partially outside"
     526                " of the input image (%d x %d).",
     527                col0, row0, col0+overlayNumCols-1, row0+overlayNumRows-1,
     528                imageNumCols,imageNumRows);
     529        return 4;
     530    }
     531
     532    switch (type) {
     533
     534        #define psImageOverlayCase(DATATYPE) \
     535    case PS_TYPE_##DATATYPE: \
     536        for (unsigned int row=row0;row<imageRowLimit;row++) { \
     537            ps##DATATYPE* imageRow = image->data.DATATYPE[row]; \
     538            ps##DATATYPE* overlayRow = overlay->data.DATATYPE[row-row0]; \
     539            for (unsigned int col=col0;col<imageColLimit;col++) { \
     540                switch (*op) { \
     541                case '+': \
     542                    imageRow[col] += overlayRow[col-col0]; \
     543                    break; \
     544                case '-': \
     545                    imageRow[col] -= overlayRow[col-col0]; \
     546                    break; \
     547                case '*': \
     548                    imageRow[col] *= overlayRow[col-col0]; \
     549                    break; \
     550                case '/': \
     551                    imageRow[col] /= overlayRow[col-col0]; \
     552                    break; \
     553                default: \
     554                    psError(__func__,"Unknown operation %s",op); \
     555                    return 5; \
     556                } \
     557            } \
     558        }
     559
     560        psImageOverlayCase(U8);
     561        psImageOverlayCase(U16);
     562        psImageOverlayCase(U32);
     563        psImageOverlayCase(U64);
     564        psImageOverlayCase(S8);
     565        psImageOverlayCase(S16);
     566        psImageOverlayCase(S32);
     567        psImageOverlayCase(S64);
     568        psImageOverlayCase(F32);
     569        psImageOverlayCase(F64);
     570        psImageOverlayCase(C32);
     571        psImageOverlayCase(C64);
     572
     573    default:
     574        psError(__func__,"Can not operate on type %d.",type);
     575    }
     576
     577    return 0;
     578}
Note: See TracChangeset for help on using the changeset viewer.