IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 23989 for trunk/psLib


Ignore:
Timestamp:
Apr 28, 2009, 11:21:56 AM (17 years ago)
Author:
eugene
Message:

always handle psVectorStats false return status (is an error); check for NAN results and handle as possible

Location:
trunk/psLib/src/imageops
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/psLib/src/imageops/psImageGeomManip.c

    r21183 r23989  
    110110    out = psImageRecycle(out, outCols, outRows, in->type.type);
    111111
    112     #define PS_IMAGE_REBIN_CASE(TYPE) \
    113 case PS_TYPE_##TYPE: { \
    114         ps##TYPE *outRowData; \
    115         ps##TYPE *vecData = vec->data.TYPE; \
    116         psImageMaskType *inRowMask = NULL; \
    117         for (psS32 row = 0; row < outRows; row++) { \
    118             outRowData = out->data.TYPE[row]; \
    119             psS32 inCurrentRow = row * scale; \
    120             psS32 inNextRow = (row + 1) * scale; \
    121             for (psS32 col = 0; col < outCols; col++) { \
    122                 psS32 inCurrentCol = col * scale; \
    123                 psS32 inNextCol = (col + 1) * scale; \
    124                 psS32 n = 0; \
     112#define PS_IMAGE_REBIN_CASE(TYPE)                                       \
     113    case PS_TYPE_##TYPE: {                                              \
     114        ps##TYPE *outRowData;                                           \
     115        ps##TYPE *vecData = vec->data.TYPE;                             \
     116        psImageMaskType *inRowMask = NULL;                              \
     117        for (psS32 row = 0; row < outRows; row++) {                     \
     118            outRowData = out->data.TYPE[row];                           \
     119            psS32 inCurrentRow = row * scale;                           \
     120            psS32 inNextRow = (row + 1) * scale;                        \
     121            for (psS32 col = 0; col < outCols; col++) {                 \
     122                psS32 inCurrentCol = col * scale;                       \
     123                psS32 inNextCol = (col + 1) * scale;                    \
     124                psS32 n = 0;                                            \
    125125                for (psS32 inRow = inCurrentRow; inRow < inNextRow && inRow < inRows; inRow++) { \
    126                     ps##TYPE* inRowData = in->data.TYPE[inRow]; \
    127                     if (mask != NULL) { \
     126                    ps##TYPE* inRowData = in->data.TYPE[inRow];         \
     127                    if (mask != NULL) {                                 \
    128128                        inRowMask = mask->data.PS_TYPE_IMAGE_MASK_DATA[inRow]; \
    129                     } \
     129                    }                                                   \
    130130                    for (psS32 inCol = inCurrentCol; inCol < inNextCol && inCol < inCols; inCol++) { \
    131                         if (maskData != NULL) { \
     131                        if (maskData != NULL) {                         \
    132132                            maskData[n] = (inRowMask[inCol] & maskVal); \
    133                         } \
    134                         vecData[n++] = inRowData[inCol]; \
    135                     } \
    136                 } \
    137                 vec->n = n; \
    138                 if (maskVec) { \
    139                     maskVec->n = n; \
    140                 } \
    141                  psVectorStats(myStats, vec, NULL, maskVec, 0xff); /* the mask vector has only 0 or 1 */ \
    142                 outRowData[col] = (ps##TYPE)psStatsGetValue(myStats, statistic); \
    143             } \
    144         } \
    145     } \
     133                        }                                               \
     134                        vecData[n++] = inRowData[inCol];                \
     135                    }                                                   \
     136                }                                                       \
     137                vec->n = n;                                             \
     138                if (maskVec) {                                          \
     139                    maskVec->n = n;                                     \
     140                }                                                       \
     141                if (!psVectorStats(myStats, vec, NULL, maskVec, 0xff)) { /* the mask vector has only 0 or 1 */ \
     142                    psError(PS_ERR_UNKNOWN, false, "failure to measure stats"); \
     143                    psFree(out);                                        \
     144                    out = NULL;                                         \
     145                    goto escape;                                        \
     146                }                                                       \
     147                outRowData[col] = (ps##TYPE)psStatsGetValue(myStats, statistic); \
     148            }                                                           \
     149        }                                                               \
     150    }                                                                   \
    146151    break;
    147152
     
    161166            char* typeStr;
    162167            PS_TYPE_NAME(typeStr,in->type.type);
    163             psError(PS_ERR_BAD_PARAMETER_TYPE, true,
    164                     _("Specified psImage type, %s, is not supported."),
    165                     typeStr);
     168            psError(PS_ERR_BAD_PARAMETER_TYPE, true, _("Specified psImage type, %s, is not supported."), typeStr);
    166169            psFree(out);
    167170            out = NULL;
     
    169172    }
    170173
     174escape:
    171175    psFree(vec);
    172176    psFree(maskVec);
  • trunk/psLib/src/imageops/psImageMap.c

    r21183 r23989  
    211211            // XXX need to supply a mask and skip the masked pixels when calculating the centroid
    212212            // this will not in general be properly weighted...
    213             if (psVectorStats (map->stats, fCell, dfCell, NULL, 0)) {
     213            if (!psVectorStats (map->stats, fCell, dfCell, NULL, 0)) {
     214                psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     215                return false;
     216            }
     217
     218            // XXX ensure only one option is selected, or save both position and width
     219            map->map->data.F32[iy][ix] = psStatsGetValue (map->stats, map->stats->options);
     220
     221            if (isnan(map->map->data.F32[iy][ix])) {
     222                mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] = 1;
     223            } else {
    214224                mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] = 0;
    215                 // XXX ensure only one option is selected, or save both position and width
    216                 map->map->data.F32[iy][ix] = psStatsGetValue (map->stats, map->stats->options);
    217225
    218226                // calculate the mean position and save:
    219227                psStatsInit (meanStat);
    220                 psVectorStats (meanStat, xCell, NULL, NULL, 0);
     228                if (!psVectorStats (meanStat, xCell, NULL, NULL, 0)) {
     229                    psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     230                    return false;
     231                }
    221232                xCoord->data.F32[iy][ix] = psStatsGetValue (meanStat, meanStat->options);
    222233                psStatsInit (meanStat);
    223                 psVectorStats (meanStat, yCell, NULL, NULL, 0);
     234                if (!psVectorStats (meanStat, yCell, NULL, NULL, 0)) {
     235                    psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     236                    return false;
     237                }
    224238                yCoord->data.F32[iy][ix] = psStatsGetValue (meanStat, meanStat->options);
    225             } else {
    226                 mask->data.PS_TYPE_IMAGE_MASK_DATA[iy][ix] = 1;
    227239            }
    228240
  • trunk/psLib/src/imageops/psImageMapFit.c

    r21183 r23989  
    7373
    7474        // XXX does ROBUST_MEDIAN work with weight?
    75         psVectorStats(map->stats, f, NULL, mask, maskValue);
     75        if (!psVectorStats(map->stats, f, NULL, mask, maskValue)) {
     76            psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     77            return false;
     78        }
    7679
    7780        map->map->data.F32[0][0]   = psStatsGetValue(map->stats, mean);
  • trunk/psLib/src/imageops/psImagePixelExtract.c

    r21183 r23989  
    419419        }
    420420
    421 #define PSIMAGE_CUT_VERTICAL(TYPE) \
    422     case PS_TYPE_##TYPE: { \
    423             psVectorMaskType* maskVecData = NULL; \
    424             for (psS32 c = col0; c < col1; c++) { \
    425                 ps##TYPE *imgData = input->data.TYPE[row0] + c; \
    426                 ps##TYPE *imgVecData = imgVec->data.TYPE; \
    427                 if (maskVec != NULL) { \
     421#define PSIMAGE_CUT_VERTICAL(TYPE)                                      \
     422        case PS_TYPE_##TYPE: {                                          \
     423            psVectorMaskType* maskVecData = NULL;                       \
     424            for (psS32 c = col0; c < col1; c++) {                       \
     425                ps##TYPE *imgData = input->data.TYPE[row0] + c;         \
     426                ps##TYPE *imgVecData = imgVec->data.TYPE;               \
     427                if (maskVec != NULL) {                                  \
    428428                    maskVecData = maskVec->data.PS_TYPE_VECTOR_MASK_DATA; \
    429429                    maskData = &mask->data.PS_TYPE_IMAGE_MASK_DATA[row0][c]; /* XXX double check this... */ \
    430430                    /** old entry: maskData = (psMaskType* )(mask->data.PS_TYPE_IMAGE_MASK_DATA[row0]) + c; */ \
    431                 } \
    432                 for (psS32 r = row0; r < row1; r++) { \
    433                    *imgVecData = *imgData; \
    434                     imgVecData ++; \
    435                     imgData += inCols; \
    436                     if (maskVecData != NULL) { \
    437                         *maskVecData = (*maskData & maskVal); \
    438                         maskVecData ++; \
    439                         maskData += inCols; \
    440                     } \
    441                 } \
    442                 psVectorStats(myStats, imgVec, NULL, maskVec, 0xff); \
    443                 *outData = psStatsGetValue(myStats, statistic); \
    444                 if (outPosition != NULL) { \
    445                     outPosition->x = c; \
    446                     outPosition->y = row0; \
    447                     outPosition += delta; \
    448                 } \
    449                 outData += delta; \
    450             } \
    451             break; \
     431                }                                                       \
     432                for (psS32 r = row0; r < row1; r++) {                   \
     433                    *imgVecData = *imgData;                             \
     434                    imgVecData ++;                                      \
     435                    imgData += inCols;                                  \
     436                    if (maskVecData != NULL) {                          \
     437                        *maskVecData = (*maskData & maskVal);           \
     438                        maskVecData ++;                                 \
     439                        maskData += inCols;                             \
     440                    }                                                   \
     441                }                                                       \
     442                if (!psVectorStats(myStats, imgVec, NULL, maskVec, 0xff)) { \
     443                    psError(PS_ERR_UNKNOWN, false, "failure to measure stats"); \
     444                    psFree(out);                                        \
     445                    out = NULL;                                         \
     446                    break;                                              \
     447                }                                                       \
     448                *outData = psStatsGetValue(myStats, statistic);         \
     449                if (outPosition != NULL) {                              \
     450                    outPosition->x = c;                                 \
     451                    outPosition->y = row0;                              \
     452                    outPosition += delta;                               \
     453                }                                                       \
     454                outData += delta;                                       \
     455            }                                                           \
     456            break;                                                      \
    452457        }
    453458
     
    466471                char* typeStr;
    467472                PS_TYPE_NAME(typeStr,type);
    468                 psError(PS_ERR_BAD_PARAMETER_TYPE, true,
    469                         _("Specified psImage type, %s, is not supported."),
    470                         typeStr);
     473                psError(PS_ERR_BAD_PARAMETER_TYPE, true, _("Specified psImage type, %s, is not supported."), typeStr);
    471474                psFree(out);
    472475                out = NULL;
     
    534537            }
    535538
    536             psVectorStats(myStats, imgVec, NULL, maskVec, 0xff);
     539            if (!psVectorStats(myStats, imgVec, NULL, maskVec, 0xff)) {
     540                psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     541                psFree (out);
     542                out = NULL;
     543                break;
     544            }
    537545            *outData = psStatsGetValue(myStats, statistic);
    538546            if (outPosition != NULL) {
     
    933941
    934942    for (psS32 r = 0; r < numOut; r++) {
    935         psVectorStats(myStats, buffer[r], NULL, bufferMask[r], 0xff);
     943        if (!psVectorStats(myStats, buffer[r], NULL, bufferMask[r], 0xff)){
     944            psError(PS_ERR_UNKNOWN, false, "failure to measure stats");
     945            psFree(out);
     946            out = NULL;
     947            break;
     948        }
    936949        outData[r] = psStatsGetValue(myStats, statistic);
    937950    }
  • trunk/psLib/src/imageops/psImageStats.c

    r21183 r23989  
    104104    }
    105105
    106     psVectorStats(stats, junkData, NULL, junkMask, 0xff);
     106    if (!psVectorStats(stats, junkData, NULL, junkMask, 0xff)) {
     107        psFree(junkMask);
     108        psFree(junkData);
     109        return false;
     110    }
    107111
    108112    psFree(junkMask);
Note: See TracChangeset for help on using the changeset viewer.