IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Dec 30, 2008, 10:40:00 AM (17 years ago)
Author:
eugene
Message:

upgrades to the masking concepts: added psImageMaskType & psVectorMaskType and associated macros; replaced psMaskType where appropriate (see src/mask.notes.txt)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/eam_branch_20081230/psLib/src/imageops/psImagePixelExtract.c

    r20306 r21074  
    88 *  @author Robert DeSonia, MHPCC
    99 *
    10  *  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
    11  *  @date $Date: 2008-10-22 02:10:37 $
     10 *  @version $Revision: 1.33.8.1 $ $Name: not supported by cvs2svn $
     11 *  @date $Date: 2008-12-30 20:40:00 $
    1212 *
    1313 *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
     
    206206                       const psImage* input,
    207207                       const psImage* mask,
    208                        psMaskType maskVal,
     208                       psImageMaskType maskVal,
    209209                       psRegion region,
    210210                       psImageCutDirection direction,
     
    357357            return NULL;
    358358        }
    359         if (mask->type.type != PS_TYPE_MASK) {
     359        if (mask->type.type != PS_TYPE_IMAGE_MASK) {
    360360            char* typeStr;
    361361            PS_TYPE_NAME(typeStr,mask->type.type);
    362362            psError(PS_ERR_BAD_PARAMETER_TYPE, true,
    363363                    _("Input psImage mask type, %s, is not the supported mask datatype of %s."),
    364                     typeStr, PS_TYPE_MASK_NAME);
     364                    typeStr, PS_TYPE_IMAGE_MASK_NAME);
    365365            psFree(out);
    366366            return NULL;
     
    394394        psVector* imgVec = psVectorAlloc(numRows, type);
    395395        psVector* maskVec = NULL;
    396         psMaskType* maskData = NULL;
     396        psImageMaskType* maskData = NULL;
    397397        psPixelCoord* outPosition = NULL;
    398398
     
    416416
    417417        if (mask != NULL) {
    418             maskVec = psVectorAlloc(numRows, mask->type.type);
    419         }
    420         #define PSIMAGE_CUT_VERTICAL(TYPE) \
     418            maskVec = psVectorAlloc(numRows, PS_TYPE_VECTOR_MASK);
     419        }
     420
     421#define PSIMAGE_CUT_VERTICAL(TYPE) \
    421422    case PS_TYPE_##TYPE: { \
    422             psMaskType* maskVecData = NULL; \
    423             for (psS32 c=col0;c<col1;c++) { \
     423            psVectorMaskType* maskVecData = NULL; \
     424            for (psS32 c = col0; c < col1; c++) { \
    424425                ps##TYPE *imgData = input->data.TYPE[row0] + c; \
    425426                ps##TYPE *imgVecData = imgVec->data.TYPE; \
    426427                if (maskVec != NULL) { \
    427                     maskVecData = maskVec->data.U8; \
    428                     maskData = (psMaskType* )(mask->data.U8[row0]) + c; \
     428                    maskVecData = maskVec->data.PS_TYPE_VECTOR_MASK_DATA; \
     429                    maskData = &mask->data.PS_TYPE_IMAGE_MASK_DATA[row0][c]; /* XXX double check this... */ \
     430                    /** old entry: maskData = (psMaskType* )(mask->data.PS_TYPE_IMAGE_MASK_DATA[row0]) + c; */ \
    429431                } \
    430                 for (psS32 r=row0;r<row1;r++) { \
    431                     *(imgVecData++) = *imgData; \
     432                for (psS32 r = row0; r < row1; r++) { \
     433                   *imgVecData = *imgData; \
     434                    imgVecData ++; \
    432435                    imgData += inCols; \
    433436                    if (maskVecData != NULL) { \
    434                         *(maskVecData++) = *maskData; \
     437                        *maskVecData = (*maskData & maskVal); \
     438                        maskVecData ++; \
    435439                        maskData += inCols; \
    436440                    } \
    437441                } \
    438                 psVectorStats(myStats,imgVec,NULL,maskVec,maskVal); \
     442                psVectorStats(myStats, imgVec, NULL, maskVec, 0xff); \
    439443                *outData = psStatsGetValue(myStats, statistic); \
    440444                if (outPosition != NULL) { \
     
    471475        psFree(imgVec);
    472476        psFree(maskVec);
     477
    473478    } else if (direction == PS_CUT_Y_POS || direction == PS_CUT_Y_NEG) {
    474479        // Cut in Y direction
     480        // XXX use this if we drop the hackish stuff below: psVector* imgVec = psVectorAlloc(numCols, type);
    475481        psVector* imgVec = NULL;
    476482        psVector* maskVec = NULL;
     
    479485
    480486        // fill in psVector to fake out the statistics functions.
     487        // XXX EAM : this seems rather hackish: just use the needed psVectorAlloc (like above)?
    481488        imgVec = psAlloc(sizeof(psVector));
    482489        imgVec->type = input->type;
    483490        P_PSVECTOR_SET_NALLOC(imgVec,numCols);
    484         if (mask != NULL) {
    485             maskVec = psAlloc(sizeof(psVector));
    486             maskVec->type = mask->type;
    487             P_PSVECTOR_SET_NALLOC(maskVec,numCols);
    488         }
     491        imgVec->n = imgVec->nalloc;
     492
    489493        // recycle output to make a proper sized/type output structure
    490494        // n.b. type is double as that is the type given for all stats in
     
    492496        out = psVectorRecycle(out, numRows, PS_TYPE_F64);
    493497        out->n = numRows;
    494         imgVec->n = imgVec->nalloc;
    495         maskVec->n = maskVec->nalloc;
    496498        if (coords != NULL) {
    497499            coords = psPixelsRealloc(coords, numRows);
     
    507509        }
    508510
     511        if (mask != NULL) {
     512            maskVec = psVectorAlloc(numRows, PS_TYPE_VECTOR_MASK);
     513            // XXX the old code (below) faked out the mask vector
     514            // maskVec = psAlloc(sizeof(psVector));
     515            // maskVec->type = mask->type;
     516            // P_PSVECTOR_SET_NALLOC(maskVec,numCols);
     517            // maskVec->n = maskVec->nalloc;
     518        }
     519
    509520        for (psS32 r = row0; r < row1; r++) {
    510521            // point the vector struct to the
    511522            // data to calculate the stats
    512523            imgVec->data.U8 = (psPtr )(input->data.U8[r] + col0 * elementSize);
     524
     525            // set the vector mask pixels based on the image pixels
    513526            if (maskVec != NULL) {
    514                 maskVec->data.U8 = (psPtr )(mask->data.U8[r] + col0 * sizeof(psMaskType));
    515             }
    516             psVectorStats(myStats, imgVec, NULL, maskVec, maskVal);
     527                psVectorMaskType *maskVecData = maskVec->data.PS_TYPE_VECTOR_MASK_DATA;
     528                psImageMaskType *maskData = &mask->data.PS_TYPE_IMAGE_MASK_DATA[r][col0];
     529                for (psS32 c = col0; c < col1; c++) {
     530                    *maskVecData = (*maskData & maskVal);
     531                    maskVecData ++;
     532                    maskData ++;
     533                }
     534            }
     535
     536            psVectorStats(myStats, imgVec, NULL, maskVec, 0xff);
    517537            *outData = psStatsGetValue(myStats, statistic);
    518538            if (outPosition != NULL) {
     
    544564                     const psImage* input,
    545565                     const psImage* mask,
    546                      psMaskType maskVal,
     566                     psImageMaskType maskVal,
    547567                     psRegion region,
    548568                     unsigned int nSamples,
     
    651671            return NULL;
    652672        }
    653         if (mask->type.type != PS_TYPE_MASK) {
     673        if (mask->type.type != PS_TYPE_IMAGE_MASK) {
    654674            char* typeStr;
    655675            PS_TYPE_NAME(typeStr,mask->type.type);
    656676            psError(PS_ERR_BAD_PARAMETER_TYPE, true,
    657677                    _("Input psImage mask type, %s, is not the supported mask datatype of %s."),
    658                     typeStr, PS_TYPE_MASK_NAME);
     678                    typeStr, PS_TYPE_IMAGE_MASK_NAME);
    659679            psFree(out);
    660680            return NULL;
     
    739759                           const psImage* input,
    740760                           const psImage* mask,
    741                            psMaskType maskVal,
     761                           psImageMaskType maskVal,
    742762                           float x,
    743763                           float y,
     
    765785            return NULL;
    766786        }
    767         if (mask->type.type != PS_TYPE_MASK) {
     787        if (mask->type.type != PS_TYPE_IMAGE_MASK) {
    768788            char* typeStr;
    769789            PS_TYPE_NAME(typeStr,mask->type.type);
    770790            psError(PS_ERR_BAD_PARAMETER_TYPE, true,
    771791                    _("Input psImage mask type, %s, is not the supported mask datatype of %s."),
    772                     typeStr, PS_TYPE_MASK_NAME);
     792                    typeStr, PS_TYPE_IMAGE_MASK_NAME);
    773793            psFree(out);
    774794            return NULL;
     
    868888        if (mask != NULL) {
    869889            bufferMask[lcv] = psVectorAllocEmpty(1+4*(rSq[lcv+1]-rSq[lcv]),
    870                                                  PS_TYPE_MASK);
     890                                                 PS_TYPE_VECTOR_MASK);
    871891        }
    872892    }
     
    877897    for (psS32 row=startRow; row <= endRow; row++) {
    878898        psF32* inRow = input->data.F32[row];
    879         psMaskType* maskRow = NULL;
     899        psImageMaskType* maskRow = NULL;
    880900        if (mask != NULL) {
    881             maskRow = mask->data.PS_TYPE_MASK_DATA[row];
     901            maskRow = mask->data.PS_TYPE_IMAGE_MASK_DATA[row];
    882902        }
    883903        for (psS32 col=startCol; col <= endCol; col++) {
     
    899919
    900920                    if (maskRow != NULL) {
    901                         bufferMask[r]->data.PS_TYPE_MASK_DATA[n] = maskRow[col];
     921                        bufferMask[r]->data.PS_TYPE_VECTOR_MASK_DATA[n] = (maskRow[col] & maskVal);
    902922                        bufferMask[r]->n = n+1;
    903923                    }
     
    913933
    914934    for (psS32 r = 0; r < numOut; r++) {
    915         psVectorStats(myStats,buffer[r], NULL, bufferMask[r],maskVal);
     935        psVectorStats(myStats, buffer[r], NULL, bufferMask[r], 0xff);
    916936        outData[r] = psStatsGetValue(myStats, statistic);
    917937    }
Note: See TracChangeset for help on using the changeset viewer.