IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Ignore:
Timestamp:
Sep 21, 2004, 12:30:19 PM (22 years ago)
Author:
desonia
Message:

Changed the image code to the new psErrorMsg error handling specification.

File:
1 edited

Legend:

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

    r1613 r1840  
    1010*  @author Robert DeSonia, MHPCC
    1111*
    12 *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
    13 *  @date $Date: 2004-08-25 00:04:01 $
     12*  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
     13*  @date $Date: 2004-09-21 22:30:19 $
    1414*
    1515*  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
     
    2222#include "psImageExtraction.h"
    2323#include "psError.h"
     24
     25#include "psImageErrors.h"
    2426
    2527psImage* psImageSubset(psImage* image,
     
    3436
    3537    if (image == NULL || image->data.V == NULL) {
    36         psError(__func__, "Can not subset image because input image or its pixel buffer is NULL.");
     38        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSubset",
     39                   PS_ERR_BAD_PARAMETER_NULL, true,
     40                   PS_ERRORTEXT_psImage_IMAGE_NULL);
    3741        return NULL;
    3842    }
    3943
    4044    if (image->type.dimen != PS_DIMEN_IMAGE) {
    41         psError(__func__, "Can not subset image because input image is not an image.");
     45        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSubset",
     46                   PS_ERR_BAD_PARAMETER_TYPE, true,
     47                   PS_ERRORTEXT_psImage_NOT_AN_IMAGE);
    4248        return NULL;
    4349    }
    4450
    4551    if (numCols < 1 || numRows < 1) {
    46         psError(__func__,
    47                 "Can not subset image because number of rows or columns are zero (%dx%d).", numCols, numRows);
    48         return NULL;
    49     }
    50 
    51     if (col0 >= image->numCols || row0 >= image->numRows) {
    52         psError(__func__,
    53                 "Can not subset image because col0,row0 (%d,%d) is not a valid pixel location.", col0, row0);
    54         return NULL;
    55     }
    56 
    57     /* validate subimage size */
    58     if (col0 + numCols >= image->numCols || row0 + numRows >= image->numRows) {
    59         psError(__func__,
    60                 "Can not subset image outside of image boundaries (size=%dx%d, "
    61                 "subset=[%d:%d,%d:%d]).",
    62                 image->numCols, image->numRows, col0, col0 + numCols, row0, row0 + numRows);
     52        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSubset",
     53                   PS_ERR_BAD_PARAMETER_VALUE, true,
     54                   PS_ERRORTEXT_psImage_AREA_NEGATIVE,
     55                   numCols,numRows);
     56        return NULL;
     57    }
     58
     59    if ( col0 >= image->numCols ||
     60            row0 >= image->numRows ||
     61            col0 + numCols >= image->numCols ||
     62            row0 + numRows >= image->numRows ) {
     63        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSubset",
     64                   PS_ERR_BAD_PARAMETER_VALUE, true,
     65                   PS_ERRORTEXT_psImage_SUBSET_RANGE_INVALID,
     66                   col0, col0 + numCols, row0, row0 + numRows,
     67                   image->numCols, image->numRows);
    6368        return NULL;
    6469    }
     
    104109    // section should be of the form '[x1:x2,y1:y2]'
    105110    if (section == NULL) {
    106         psError(__func__,"The subsection string input can not be NULL.");
     111        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSubsection",
     112                   PS_ERR_BAD_PARAMETER_NULL, true,
     113                   PS_ERRORTEXT_psImage_SUBSECTION_NULL);
    107114        return NULL;
    108115    }
    109116
    110117    if (sscanf(section,"[%d:%d,%d:%d]",&x1,&x2,&y1,&y2) < 4) {
    111         psError(__func__,"The subsection string (%s) can not be parsed.  "
    112                 "Needs to be of the form '[x1:x2,y1:y2]'",
    113                 section);
     118        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSubsection",
     119                   PS_ERR_BAD_PARAMETER_NULL, true,
     120                   PS_ERRORTEXT_psImage_SUBSECTION_INVALID,
     121                   section);
    114122        return NULL;
    115123    }
     
    120128{
    121129    if (image == NULL || image->data.V == NULL) {
    122         psError(__func__, "Can not subset image because input image or its "
    123                 "pixel buffer is NULL.");
     130        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageTrim",
     131                   PS_ERR_BAD_PARAMETER_NULL, true,
     132                   PS_ERRORTEXT_psImage_IMAGE_NULL);
    124133        return NULL;
    125134    }
    126135
    127136    if (image->parent != NULL) {
    128         psError(__func__, "Can not perform a trim on a child image.");
     137        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageTrim",
     138                   PS_ERR_BAD_PARAMETER_NULL, true,
     139                   PS_ERRORTEXT_psImage_NOT_PARENT);
    129140        return NULL;
    130141    }
     
    134145            y0 >= image->numRows || y1 >= image->numRows ||
    135146            x0 > x1 || y0 > y1 ) {
    136         psError(__func__, "Can not subset image because specified region "
    137                 "[%d:%d,%d:%d] is not valid for image of size %dx%d.",
    138                 x0,x1,y0,y1,image->numCols,image->numRows);
     147        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageTrim",
     148                   PS_ERR_BAD_PARAMETER_VALUE, true,
     149                   PS_ERRORTEXT_psImage_SUBSET_RANGE_INVALID,
     150                   x0, x1, y0, y1,
     151                   image->numCols, image->numRows);
    139152        return NULL;
    140153    }
     
    179192
    180193    if (input == NULL || input->data.V == NULL) {
    181         psError(__func__, "Can not copy image because input image or its pixel buffer is NULL.");
     194        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageCopy",
     195                   PS_ERR_BAD_PARAMETER_NULL, true,
     196                   PS_ERRORTEXT_psImage_IMAGE_NULL);
    182197        psFree(output);
    183198        return NULL;
     
    185200
    186201    if (input == output) {
    187         psError(__func__,
    188                 "Can not copy image because given input and output "
    189                 "parameter reference the same psImage struct.");
     202        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageCopy",
     203                   PS_ERR_BAD_PARAMETER_NULL, true,
     204                   PS_ERRORTEXT_psImage_INPLACE_NOTSUPPORTED);
    190205        psFree(output);
    191206        return NULL;
     
    193208
    194209    if (input->type.dimen != PS_DIMEN_IMAGE) {
    195         psError(__func__, "Can not copy image because input image is not actually an image.");
     210        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageCopy",
     211                   PS_ERR_BAD_PARAMETER_TYPE, true,
     212                   PS_ERRORTEXT_psImage_NOT_AN_IMAGE);
    196213        psFree(output);
    197214        return NULL;
     
    205222
    206223    if (inDatatype == PS_TYPE_PTR || type == PS_TYPE_PTR) {
    207         psError(__func__, "Can not copy image to/from a void* matrix");
     224        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageCopy",
     225                   PS_ERR_BAD_PARAMETER_TYPE, true,
     226                   PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
     227                   PS_TYPE_PTR_NAME);
    208228        psFree(output);
    209229        return NULL;
     
    220240        return output;
    221241    }
     242
    222243    #define PSIMAGE_ELEMENT_COPY(IN,INTYPE,OUT,OUTTYPE,ELEMENTS) { \
    223244        ps##INTYPE *in; \
     
    232253    }
    233254
    234     #define PSIMAGE_COPY_CASE(OUT,OUTTYPE) \
    235     switch (inDatatype) { \
    236     case PS_TYPE_S8: \
    237         PSIMAGE_ELEMENT_COPY(input,S8,OUT,OUTTYPE,elements); \
    238         break; \
    239     case PS_TYPE_S16: \
    240         PSIMAGE_ELEMENT_COPY(input,S16,OUT,OUTTYPE,elements); \
    241         break; \
    242     case PS_TYPE_S32: \
    243         PSIMAGE_ELEMENT_COPY(input,S32,OUT,OUTTYPE,elements); \
    244         break; \
    245     case PS_TYPE_S64: \
    246         PSIMAGE_ELEMENT_COPY(input,S64,OUT,OUTTYPE,elements); \
    247         break; \
    248     case PS_TYPE_U8: \
    249         PSIMAGE_ELEMENT_COPY(input,U8,OUT,OUTTYPE,elements); \
    250         break; \
    251     case PS_TYPE_U16: \
    252         PSIMAGE_ELEMENT_COPY(input,U16,OUT,OUTTYPE,elements); \
    253         break; \
    254     case PS_TYPE_U32: \
    255         PSIMAGE_ELEMENT_COPY(input,U32,OUT,OUTTYPE,elements); \
    256         break; \
    257     case PS_TYPE_U64: \
    258         PSIMAGE_ELEMENT_COPY(input,U64,OUT,OUTTYPE,elements); \
    259         break; \
    260     case PS_TYPE_F32: \
    261         PSIMAGE_ELEMENT_COPY(input,F32,OUT,OUTTYPE,elements); \
    262         break; \
    263     case PS_TYPE_F64: \
    264         PSIMAGE_ELEMENT_COPY(input,F64,OUT,OUTTYPE,elements); \
    265         break; \
    266     case PS_TYPE_C32: \
    267         PSIMAGE_ELEMENT_COPY(input,C32,OUT,OUTTYPE,elements); \
    268         break; \
    269     case PS_TYPE_C64: \
    270         PSIMAGE_ELEMENT_COPY(input,C64,OUT,OUTTYPE,elements); \
    271         break; \
    272     default: \
    273         break; \
     255    #define PSIMAGE_COPY_CASE(OUT,OUTTYPE) { \
     256        switch (inDatatype) { \
     257        case PS_TYPE_S8: \
     258            PSIMAGE_ELEMENT_COPY(input,S8,OUT,OUTTYPE,elements); \
     259            break; \
     260        case PS_TYPE_S16: \
     261            PSIMAGE_ELEMENT_COPY(input,S16,OUT,OUTTYPE,elements); \
     262            break; \
     263        case PS_TYPE_S32: \
     264            PSIMAGE_ELEMENT_COPY(input,S32,OUT,OUTTYPE,elements); \
     265            break; \
     266        case PS_TYPE_S64: \
     267            PSIMAGE_ELEMENT_COPY(input,S64,OUT,OUTTYPE,elements); \
     268            break; \
     269        case PS_TYPE_U8: \
     270            PSIMAGE_ELEMENT_COPY(input,U8,OUT,OUTTYPE,elements); \
     271            break; \
     272        case PS_TYPE_U16: \
     273            PSIMAGE_ELEMENT_COPY(input,U16,OUT,OUTTYPE,elements); \
     274            break; \
     275        case PS_TYPE_U32: \
     276            PSIMAGE_ELEMENT_COPY(input,U32,OUT,OUTTYPE,elements); \
     277            break; \
     278        case PS_TYPE_U64: \
     279            PSIMAGE_ELEMENT_COPY(input,U64,OUT,OUTTYPE,elements); \
     280            break; \
     281        case PS_TYPE_F32: \
     282            PSIMAGE_ELEMENT_COPY(input,F32,OUT,OUTTYPE,elements); \
     283            break; \
     284        case PS_TYPE_F64: \
     285            PSIMAGE_ELEMENT_COPY(input,F64,OUT,OUTTYPE,elements); \
     286            break; \
     287        case PS_TYPE_C32: \
     288            PSIMAGE_ELEMENT_COPY(input,C32,OUT,OUTTYPE,elements); \
     289            break; \
     290        case PS_TYPE_C64: \
     291            PSIMAGE_ELEMENT_COPY(input,C64,OUT,OUTTYPE,elements); \
     292            break; \
     293        default: \
     294            break; \
     295        } \
    274296    }
    275297
     
    311333        PSIMAGE_COPY_CASE(output, C64);
    312334        break;
    313     default:
    314         break;
     335    default: {
     336            char* typeStr;
     337            PS_TYPE_NAME(typeStr,type);
     338            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageCopy",
     339                       PS_ERR_BAD_PARAMETER_TYPE, true,
     340                       PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
     341                       typeStr);
     342            psFree(output);
     343
     344            break;
     345        }
    315346    }
    316347    return output;
     
    338369
    339370    if (in == NULL || in->data.V == NULL) {
    340         psError(__func__, "Input image can not be NULL.");
     371        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice",
     372                   PS_ERR_BAD_PARAMETER_NULL, true,
     373                   PS_ERRORTEXT_psImage_IMAGE_NULL);
    341374        psFree(out);
    342375        return NULL;
    343376    }
    344377
    345     if (numRows == 0 || numCols == 0) {
    346         psError(__func__, "The specified region contains no data (%dx%d)", numCols, numRows);
     378    if (numRows < 1 || numCols < 1) {
     379        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice",
     380                   PS_ERR_BAD_PARAMETER_NULL, true,
     381                   PS_ERRORTEXT_psImage_SUBSET_ZERO_SIZE,
     382                   col,col+numCols,row,row+numRows);
    347383        psFree(out);
    348384        return NULL;
     
    374410    if (mask != NULL) {
    375411        if (inRows != mask->numRows || inCols != mask->numCols) {
    376             psError(__func__,
    377                     "The mask and image dimensions did not match (%dx%d vs %dx%d)",
    378                     mask->numCols, mask->numRows, in->numCols, in->numRows);
     412            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice",
     413                       PS_ERR_BAD_PARAMETER_VALUE, true,
     414                       PS_ERRORTEXT_psImage_IMAGE_MASK_SIZE,
     415                       mask->numCols,mask->numRows,
     416                       inCols, inRows);
    379417            psFree(out);
    380418        }
    381419        if (mask->type.type != PS_TYPE_MASK) {
    382             psError(__func__, "The mask datatype (%d) must be %s.", mask->type.type, PS_TYPE_MASK_NAME);
     420            char* typeStr;
     421            PS_TYPE_NAME(typeStr,mask->type.type);
     422            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice",
     423                       PS_ERR_BAD_PARAMETER_TYPE, true,
     424                       PS_ERRORTEXT_psImage_IMAGE_MASK_TYPE,
     425                       typeStr, PS_TYPE_MASK_NAME);
    383426            psFree(out);
    384427        }
    385428    }
    386429
    387     if (row >= inRows || col >= inCols || col + numCols > in->numCols || row + numRows > in->numRows) {
    388         psError(__func__,
    389                 "The specified image region (%d,%d to %d,%d) is outside of image area (0,0 to %d,%d).",
    390                 col, row, col + numCols - 1, row + numRows - 1, in->numCols - 1, in->numRows - 1);
     430    if (row >= inRows || col >= inCols || col + numCols > inCols || row + numRows > inRows) {
     431        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice",
     432                   PS_ERR_BAD_PARAMETER_VALUE, true,
     433                   PS_ERRORTEXT_psImage_SUBSET_RANGE_INVALID,
     434                   col, row, col+numCols, row+numRows,
     435                   inCols, inRows);
    391436        psFree(out);
    392437        return NULL;
    393438    }
     439
     440    if (stats == NULL) {
     441        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice",
     442                   PS_ERR_BAD_PARAMETER_NULL, true,
     443                   PS_ERRORTEXT_psImage_STAT_NULL);
     444        psFree(out);
     445        return NULL;
     446    }
     447
    394448    // verify that the stats struct specifies a
    395449    // single stats operation
    396     if (stats == NULL || p_psGetStatValue(stats, &statVal) == false) {
    397         psError(__func__, "The stat options didn't specify a single supported statistic type.");
     450    if (p_psGetStatValue(stats, &statVal) == false) {
     451        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice",
     452                   PS_ERR_BAD_PARAMETER_VALUE, false,
     453                   PS_ERRORTEXT_psImage_BAD_STAT);
    398454        psFree(out);
    399455        return NULL;
     
    410466        psU32* outPosition = NULL;
    411467
    412         // recycle output to make a proper
    413         // sized/type output structure
    414         // n.b. type is double as that is the
    415         // type given for all stats in
     468        // recycle output to make a proper sized/type output structure
     469        // n.b. type is double as that is the type given for all stats is
    416470        // psStats.
    417471        out = psVectorRecycle(out, numCols, PS_TYPE_F64);
     
    474528            PSIMAGE_CUT_VERTICAL(C32);
    475529            PSIMAGE_CUT_VERTICAL(C64);
    476         default:
    477             psError(__func__, "Unsupported datatype (%d)", type);
    478             psFree(out);
    479             out = NULL;
     530        default: {
     531                char* typeStr;
     532                PS_TYPE_NAME(typeStr,type);
     533                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice",
     534                           PS_ERR_BAD_PARAMETER_TYPE, true,
     535                           PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
     536                           typeStr);
     537                psFree(out);
     538                out = NULL;
     539            }
    480540        }
    481541        psFree(imgVec);
    482542        psFree(maskVec);
    483     } else if (direction == PS_CUT_Y_POS || direction == PS_CUT_Y_NEG) {        // Cut
    484         //
    485         //
    486         //
    487         //
    488         //
    489         //
    490         //
    491         //
    492         //
    493         // in
    494         // Y
    495         // direction
     543    } else if (direction == PS_CUT_Y_POS || direction == PS_CUT_Y_NEG) {
     544        // Cut in Y direction
    496545        psVector* imgVec = NULL;
    497546        psVector* maskVec = NULL;
     
    509558            maskVec->n = maskVec->nalloc = numCols;
    510559        }
    511         // recycle output to make a proper
    512         // sized/type output structure
    513         // n.b. type is double as that is the
    514         // type given for all stats in
     560        // recycle output to make a proper sized/type output structure
     561        // n.b. type is double as that is the type given for all stats in
    515562        // psStats.
    516563        out = psVectorRecycle(out, numRows, PS_TYPE_F64);
     
    535582            }
    536583            myStats = psVectorStats(myStats, imgVec, maskVec, maskVal);
    537             (void)p_psGetStatValue(myStats, &statVal);  // we
    538             // know
    539             // it
    540             // works
    541             // cause we tested it
    542             // above
     584            (void)p_psGetStatValue(myStats, &statVal);  // we know it works cause we tested it above
    543585            *outData = statVal;
    544586            if (outPosition != NULL) {
     
    551593        psFree(imgVec);
    552594        psFree(maskVec);
    553     } else {                               // don't
    554         // know
    555         // what
    556         // the
    557         // direction
    558         // flag
    559         // is
    560         psError(__func__, "Invalid direction flag (%d)", direction);
     595    } else { // don't know what the direction flag is
     596        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice",
     597                   PS_ERR_BAD_PARAMETER_VALUE, true,
     598                   PS_ERRORTEXT_psImage_SLICE_DIRECTION_INVALID,
     599                   direction);
    561600        psFree(out);
    562601        out = NULL;
Note: See TracChangeset for help on using the changeset viewer.