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/psImageManip.c

    r1827 r1840  
    1010 *  @author Ross Harman, MHPCC
    1111 *
    12  *  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
    13  *  @date $Date: 2004-09-17 23:57:41 $
     12 *  @version $Revision: 1.21 $ $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
     
    2626#include "psMemory.h"
    2727#include "psImageExtraction.h"
     28
     29#include "psImageErrors.h"
    2830
    2931int psImageClip(psImage* input,
     
    4244
    4345    if (max < min) {
    44         psError(__func__, "psImageClip can not be invoked with max < min.");
     46        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageClip",
     47                   PS_ERR_BAD_PARAMETER_VALUE, true,
     48                   PS_ERRORTEXT_psImageManip_MAXMIN,
     49                   (double)min,(double)max);
    4550        return 0;
    4651    }
     
    5156    switch (input->type.type) {
    5257
    53         #define psImageClipCase(type,typename) \
     58        #define psImageClipCase(type) \
    5459    case PS_TYPE_##type: { \
    5560            if (vmin < PS_MIN_##type || vmin > PS_MAX_##type) { \
    56                 psError(__func__, "Specified vmin (%g) is outside of image's " \
    57                         typename " pixel range (%g to %g)", \
    58                         vmin,(psF64)PS_MIN_##type,(psF64)PS_MAX_##type); \
     61                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageClip", \
     62                           PS_ERR_BAD_PARAMETER_VALUE, true, \
     63                           PS_ERRORTEXT_psImage_PARAMETER_OUTOF_TYPERANGE, \
     64                           "vmin",vmin, PS_TYPE_##type##_NAME, \
     65                           (psF64)PS_MIN_##type,(psF64)PS_MAX_##type); \
    5966            } \
    6067            if (vmax > PS_MAX_##type || vmax < PS_MIN_##type) { \
    61                 psError(__func__, "Specified vmax (%g) is outside of image's " \
    62                         typename " pixel range (%g to %g)", \
    63                         vmax,(psF64)PS_MIN_##type,(psF64)PS_MAX_##type); \
     68                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageClip", \
     69                           PS_ERR_BAD_PARAMETER_VALUE, true, \
     70                           PS_ERRORTEXT_psImage_PARAMETER_OUTOF_TYPERANGE, \
     71                           "vmax",vmax, PS_TYPE_##type##_NAME, \
     72                           (psF64)PS_MIN_##type,(psF64)PS_MAX_##type); \
    6473            } \
    6574            for (unsigned int row = 0;row<numRows;row++) { \
     
    7887        break;
    7988
    80         #define psImageClipCaseComplex(type,typename,absfcn)\
     89        #define psImageClipCaseComplex(type,absfcn)\
    8190    case PS_TYPE_##type: { \
    8291            if (vmin < PS_MIN_##type || vmin > PS_MAX_##type) { \
    83                 psError(__func__, "Specified vmin (%g) is outside of image's " \
    84                         typename " pixel range", \
    85                         vmin); \
     92                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageClip", \
     93                           PS_ERR_BAD_PARAMETER_VALUE, true, \
     94                           PS_ERRORTEXT_psImage_PARAMETER_OUTOF_TYPERANGE, \
     95                           "vmin",vmin, PS_TYPE_##type##_NAME, \
     96                           (psF64)PS_MIN_##type,(psF64)PS_MAX_##type); \
    8697            } \
    8798            if (vmax > PS_MAX_##type || vmax < PS_MIN_##type) { \
    88                 psError(__func__, "Specified vmax (%g) is outside of image's " \
    89                         typename " pixel range", \
    90                         vmax); \
     99                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageClip", \
     100                           PS_ERR_BAD_PARAMETER_VALUE, true, \
     101                           PS_ERRORTEXT_psImage_PARAMETER_OUTOF_TYPERANGE, \
     102                           "vmax",vmax, PS_TYPE_##type##_NAME, \
     103                           (psF64)PS_MIN_##type,(psF64)PS_MAX_##type); \
    91104            } \
    92105            for (unsigned int row = 0;row<numRows;row++) { \
     
    105118        break;
    106119
    107         psImageClipCase(S8, "psS8")
    108         psImageClipCase(S16, "psS16")
    109         psImageClipCase(S32, "psS32")
    110         psImageClipCase(S64, "psS64")
    111         psImageClipCase(U8, "psU8")
    112         psImageClipCase(U16, "psU16")
    113         psImageClipCase(U32, "psU32")
    114         psImageClipCase(U64, "psU64")
    115         psImageClipCase(F32, "psF32")
    116         psImageClipCase(F64, "psF64")
    117         psImageClipCaseComplex(C32, "psC32", cabsf)
    118         psImageClipCaseComplex(C64, "psC64", cabs)
    119 
    120     default:
    121         psError(__func__, "psImageClip does not support the given datatype (%d)", input->type.type);
     120        psImageClipCase(S8)
     121        psImageClipCase(S16)
     122        psImageClipCase(S32)
     123        psImageClipCase(S64)
     124        psImageClipCase(U8)
     125        psImageClipCase(U16)
     126        psImageClipCase(U32)
     127        psImageClipCase(U64)
     128        psImageClipCase(F32)
     129        psImageClipCase(F64)
     130        psImageClipCaseComplex(C32, cabsf)
     131        psImageClipCaseComplex(C64, cabs)
     132
     133    default: {
     134            char* typeStr;
     135            PS_TYPE_NAME(typeStr,input->type.type);
     136            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageClip",
     137                       PS_ERR_BAD_PARAMETER_TYPE, true,
     138                       PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
     139                       typeStr);
     140        }
    122141    }
    123142
     
    158177        psImageClipNaNCase(C64)
    159178
    160     default:
    161         psError(__func__, "psImageClip does not support the given datatype (%d)", input->type.type);
     179    default: {
     180            char* typeStr;
     181            PS_TYPE_NAME(typeStr,input->type.type);
     182            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageClipNaN",
     183                       PS_ERR_BAD_PARAMETER_TYPE, true,
     184                       PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
     185                       typeStr);
     186        }
    162187    }
    163188
     
    180205
    181206    if (image == NULL || overlay == NULL) {
    182         psError(__func__, "one of the input images was NULL.");
     207        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageOverlaySection",
     208                   PS_ERR_BAD_PARAMETER_NULL, true,
     209                   PS_ERRORTEXT_psImage_IMAGE_NULL);
    183210        return 1;
    184211    }
    185212
    186213    if (op == NULL) {
    187         psError(__func__, "Operation can not be NULL.");
     214        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageOverlaySection",
     215                   PS_ERR_BAD_PARAMETER_NULL, true,
     216                   PS_ERRORTEXT_psImageManip_OPERATION_NULL);
    188217        return 1;
    189218    }
     
    192221
    193222    if (type != overlay->type.type) {
    194         psError(__func__, "Image and overlay datatypes must match. (%d vs %d)", type, overlay->type.type);
     223        char* typeStr;
     224        char* typeStrOverlay;
     225        PS_TYPE_NAME(typeStr,type);
     226        PS_TYPE_NAME(typeStrOverlay,overlay->type.type);
     227        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageOverlaySection",
     228                   PS_ERR_BAD_PARAMETER_TYPE, true,
     229                   PS_ERRORTEXT_psImageManip_OVERLAY_TYPE_MISMATCH,
     230                   typeStrOverlay, typeStr);
    195231        return 2;
    196232    }
     
    200236    overlayNumRows = overlay->numRows;
    201237    overlayNumCols = overlay->numCols;
    202 
    203     /* check row0/col0 to see if it is within the image size */
    204     if (row0 < 0 || col0 < 0 || row0 >= imageNumRows || col0 >= imageNumCols) {
    205         psError(__func__,
    206                 "Overlay origin of (%d,%d) is outside of the image dimensions (%d x %d).",
    207                 col0, row0, imageNumCols, imageNumRows);
    208         return 3;
    209     }
    210 
    211     /* check if overlay is totally withing input image */
    212238    imageRowLimit = row0 + overlayNumRows;
    213239    imageColLimit = col0 + overlayNumCols;
    214     if (imageRowLimit > imageNumRows || imageColLimit > imageNumCols) {
    215         psError(__func__,
    216                 "Overlay image (%d,%d -> %d,%d) is partially outside"
    217                 " of the input image (%d x %d).",
    218                 col0, row0, col0 + overlayNumCols - 1, row0 + overlayNumRows - 1, imageNumCols, imageNumRows);
    219         return 4;
     240
     241    /* check to see if overlay is within the input image */
     242    if ( row0 < 0 ||
     243            col0 < 0 ||
     244            imageRowLimit > imageNumRows ||
     245            imageColLimit > imageNumCols) {
     246
     247        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageOverlaySection",
     248                   PS_ERR_BAD_PARAMETER_VALUE, true,
     249                   PS_ERRORTEXT_psImage_SUBSET_RANGE_INVALID,
     250                   col0, imageColLimit, row0, imageRowLimit,
     251                   imageNumCols, imageNumRows);
     252        return 3;
    220253    }
    221254
     
    245278                    break; \
    246279                default: \
    247                     psError(__func__,"Unknown operation %s",op); \
     280                    psErrorMsg(PS_ERRORNAME_DOMAIN "psImageOverlaySection", \
     281                               PS_ERR_BAD_PARAMETER_VALUE, true, \
     282                               PS_ERRORTEXT_psImageManip_OVERLAY_OPERATOR_INVALID, \
     283                               op); \
    248284                    return 5; \
    249285                } \
     
    265301        psImageOverlayCase(C64);
    266302
    267     default:
    268         psError(__func__, "Can not operate on type %d.", type);
     303    default: {
     304            char* typeStr;
     305            PS_TYPE_NAME(typeStr,type);
     306            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageOverlaySection",
     307                       PS_ERR_BAD_PARAMETER_TYPE, true,
     308                       PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
     309                       typeStr);
     310        }
    269311    }
    270312
     
    287329
    288330    if (input == NULL) {
    289         psError(__func__, "Can not perform clip on NULL image");
     331        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageClipComplexRegion",
     332                   PS_ERR_BAD_PARAMETER_NULL, true,
     333                   PS_ERRORTEXT_psImage_IMAGE_NULL);
    290334        return 0;
    291335    }
    292336
    293337    if (realMax < realMin) {
    294         psError(__func__,
    295                 "psImageClipComplexRegion can not be invoked with " "max < min in the real image space.");
     338        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageClipComplexRegion",
     339                   PS_ERR_BAD_PARAMETER_VALUE, true,
     340                   PS_ERRORTEXT_psImageManip_MAXMIN_REAL,
     341                   (double)realMin, (double)realMax);
    296342        return 0;
    297343    }
    298344    if (imagMax < imagMin) {
    299         psError(__func__,
    300                 "psImageClipComplexRegion can not be invoked with "
    301                 "max < min in the imaginary image space.");
     345        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageClipComplexRegion",
     346                   PS_ERR_BAD_PARAMETER_VALUE, true,
     347                   PS_ERRORTEXT_psImageManip_MAXMIN_IMAG,
     348                   (double)imagMin, (double)imagMax);
    302349        return 0;
    303350    }
     
    306353    numCols = input->numCols;
    307354
    308     #define psImageClipComplexRegionCase(type,typename,realfcn,imagfcn) \
     355    #define psImageClipComplexRegionCase(type,realfcn,imagfcn) \
    309356case PS_TYPE_##type: { \
    310357        if (realfcn(vmin) < PS_MIN_##type || imagfcn(vmin) < PS_MIN_##type || \
    311358                realfcn(vmin) > PS_MAX_##type || imagfcn(vmin) > PS_MAX_##type ) { \
    312             psError(__func__, "Specified vmin (%g%+gi) is outside of image's " \
    313                     typename " pixel range", \
    314                     creal(vmin),cimag(vmin)); \
     359            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageClipComplexRegion", \
     360                       PS_ERR_BAD_PARAMETER_VALUE, true, \
     361                       PS_ERRORTEXT_psImageManip_CLIP_VALUE_INVALID, \
     362                       "vmin", creal(vmin), cimag(vmin), \
     363                       PS_TYPE_##type##_NAME, PS_MIN_##type, PS_MAX_##type); \
    315364            break; \
    316365        } \
    317366        if (realfcn(vmax) > PS_MAX_##type || imagfcn(vmax) > PS_MAX_##type || \
    318367                realfcn(vmax) < PS_MIN_##type || imagfcn(vmax) < PS_MIN_##type ) { \
    319             psError(__func__, "Specified vmax (%g%+gi) is outside of image's " \
    320                     typename " pixel range", \
    321                     creal(vmax),cimag(vmax)); \
     368            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageClipComplexRegion", \
     369                       PS_ERR_BAD_PARAMETER_VALUE, true, \
     370                       PS_ERRORTEXT_psImageManip_CLIP_VALUE_INVALID, \
     371                       "vmax", creal(vmax), cimag(vmax), \
     372                       PS_TYPE_##type##_NAME, PS_MIN_##type, PS_MAX_##type); \
    322373            break; \
    323374        } \
     
    339390    switch (input->type.type) {
    340391
    341         psImageClipComplexRegionCase(C32, "psC32", crealf, cimagf)
    342         psImageClipComplexRegionCase(C64, "psC64", creal, cimag)
    343 
    344     default:
    345         psError(__func__, "psImageClip does not support the given datatype (%d)", input->type.type);
     392        psImageClipComplexRegionCase(C32, crealf, cimagf)
     393        psImageClipComplexRegionCase(C64, creal, cimag)
     394
     395    default: {
     396            char* typeStr;
     397            PS_TYPE_NAME(typeStr,input->type.type);
     398            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageClipComplexRegion",
     399                       PS_ERR_BAD_PARAMETER_TYPE, true,
     400                       PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
     401                       typeStr);
     402        }
    346403    }
    347404
     
    367424
    368425    if (in == NULL) {
    369         psError(__func__, "Input image is NULL.");
     426        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRebin",
     427                   PS_ERR_BAD_PARAMETER_NULL, true,
     428                   PS_ERRORTEXT_psImage_IMAGE_NULL);
    370429        psFree(out);
    371430        return NULL;
     
    373432
    374433    if (scale < 1) {
    375         psError(__func__, "The scale must be positive.");
     434        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRebin",
     435                   PS_ERR_BAD_PARAMETER_VALUE, true,
     436                   PS_ERRORTEXT_psImageManip_SCALE_NOT_POSITIVE,
     437                   scale);
    376438        psFree(out);
    377439        return NULL;
     
    379441
    380442    if (stats == NULL) {
    381         psError(__func__, "The stats input can not be NULL.");
     443        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRebin",
     444                   PS_ERR_BAD_PARAMETER_NULL, true,
     445                   PS_ERRORTEXT_psImage_STAT_NULL);
    382446        psFree(out);
    383447        return NULL;
     
    385449
    386450    if (p_psGetStatValue(stats, &statVal) == false) {
    387         psError(__func__, "The stat options didn't specify a single supported statistic type.");
     451        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRebin",
     452                   PS_ERR_BAD_PARAMETER_VALUE, true,
     453                   PS_ERRORTEXT_psImage_BAD_STAT,
     454                   stats->options);
    388455        psFree(out);
    389456        return NULL;
     
    394461    if (mask != NULL) {
    395462        if (mask->type.type != PS_TYPE_MASK) {
    396             psError(__func__, "The mask datatype must be %s (%d).",
    397                     PS_TYPE_MASK_NAME,
    398                     mask->type.type);
     463            char* typeStr;
     464            PS_TYPE_NAME(typeStr,mask->type.type);
     465            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRebin",
     466                       PS_ERR_BAD_PARAMETER_TYPE, true,
     467                       PS_ERRORTEXT_psImage_IMAGE_MASK_TYPE,
     468                       typeStr, PS_TYPE_MASK_NAME);
    399469            psFree(out);
    400470            psFree(vec);
     
    462532        PS_IMAGE_REBIN_CASE(C32);
    463533        PS_IMAGE_REBIN_CASE(C64);
    464     default:
    465         psError(__func__, "Input image type not supported.");
    466         psFree(out);
    467         out = NULL;
     534
     535    default: {
     536            char* typeStr;
     537            PS_TYPE_NAME(typeStr,in->type.type);
     538            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRebin",
     539                       PS_ERR_BAD_PARAMETER_TYPE, true,
     540                       PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
     541                       typeStr);
     542            psFree(out);
     543            out = NULL;
     544        }
    468545    }
    469546
     
    484561
    485562    if (in == NULL) {
    486         psError(__func__, "Input image can not be NULL.");
     563        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageResample",
     564                   PS_ERR_BAD_PARAMETER_NULL, true,
     565                   PS_ERRORTEXT_psImage_IMAGE_NULL);
    487566        psFree(out);
    488567        return NULL;
     
    520599        PSIMAGE_RESAMPLE_CASE(C32)
    521600        PSIMAGE_RESAMPLE_CASE(C64)
    522     default:
    523         psError(__func__, "Unsupported type (%d)", in->type.type);
    524         psFree(out);
    525         return NULL;
     601    default: {
     602            char* typeStr;
     603            PS_TYPE_NAME(typeStr,in->type.type);
     604            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageResample",
     605                       PS_ERR_BAD_PARAMETER_TYPE, true,
     606                       PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
     607                       typeStr);
     608            psFree(out);
     609            out = NULL;
     610        }
    526611    }
    527612
     
    539624
    540625    if (in == NULL) {
    541         psError(__func__, "Input image can not be NULL.");
     626        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRoll",
     627                   PS_ERR_BAD_PARAMETER_NULL, true,
     628                   PS_ERRORTEXT_psImage_IMAGE_NULL);
    542629        psFree(out);
    543630        return NULL;
     
    570657            inRowNumber -= outRows;
    571658        }
    572         psU8* inRow = in->data.U8[inRowNumber]; // to
    573 
    574         // allow
    575 
    576         // byte
    577         // arithmetic,
    578 
    579         // but for all types
     659        psU8* inRow = in->data.U8[inRowNumber]; // use byte arithmetic for all types
    580660        psU8* outRow = out->data.U8[row];
    581661
     
    594674{
    595675    if (in == NULL) {
    596         psError(__func__, "The input image was NULL.");
     676        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRotate",
     677                   PS_ERR_BAD_PARAMETER_NULL, true,
     678                   PS_ERRORTEXT_psImage_IMAGE_NULL);
    597679        psFree(out);
    598680        return NULL;
     
    635717            PSIMAGE_ROTATE_LEFT_90(C32);
    636718            PSIMAGE_ROTATE_LEFT_90(C64);
    637         default:
    638             psError(__func__, "Unsupported type (%d)", type);
    639             psFree(out);
    640             return NULL;
     719        default: {
     720                char* typeStr;
     721                PS_TYPE_NAME(typeStr,type);
     722                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRotate",
     723                           PS_ERR_BAD_PARAMETER_TYPE, true,
     724                           PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
     725                           typeStr);
     726                psFree(out);
     727                return NULL;
     728            }
    641729        }
    642730    } else if (fabsf(angle - 180.0f) < FLT_EPSILON) {
     
    675763            PSIMAGE_ROTATE_180_CASE(C32);
    676764            PSIMAGE_ROTATE_180_CASE(C64);
    677         default:
    678             psError(__func__, "Unsupported type (%d)", type);
    679             psFree(out);
    680             return NULL;
     765
     766        default: {
     767                char* typeStr;
     768                PS_TYPE_NAME(typeStr,type);
     769                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRotate",
     770                           PS_ERR_BAD_PARAMETER_TYPE, true,
     771                           PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
     772                           typeStr);
     773                psFree(out);
     774                return NULL;
     775            }
    681776        }
    682777    } else if (fabsf(angle - 270.0f) < FLT_EPSILON) {
     
    714809            PSIMAGE_ROTATE_RIGHT_90(C32);
    715810            PSIMAGE_ROTATE_RIGHT_90(C64);
    716         default:
    717             psError(__func__, "Unsupported type (%d)", type);
    718             psFree(out);
    719             return NULL;
     811
     812        default: {
     813                char* typeStr;
     814                PS_TYPE_NAME(typeStr,type);
     815                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRotate",
     816                           PS_ERR_BAD_PARAMETER_TYPE, true,
     817                           PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
     818                           typeStr);
     819                psFree(out);
     820                return NULL;
     821            }
    720822        }
    721823    } else if (fabsf(angle) < FLT_EPSILON) {
     
    731833        double sinT = sinf(t);
    732834
    733         // calculate the corners of the rotated
    734         // image so we know the proper
    735         // output image size.
    736         // x' = x cos(t) + y sin(t); i.e, x' =
    737         // (x-centerX)*cosT +
    738         // (y-centerY)*sinT;
    739         // y' = y cos(t) - x sin(t); i.e. y' =
    740         // (y-centerY)*cosT -
    741         // (x-centerX)*sinT;
     835        // calculate the corners of the rotated image so we know the proper output image size.
     836        // x' = x cos(t) + y sin(t); i.e, x' = (x-centerX)*cosT + (y-centerY)*sinT;
     837        // y' = y cos(t) - x sin(t); i.e. y' = (y-centerY)*cosT - (x-centerX)*sinT;
    742838
    743839        int outCols = ceil(abs(numCols * cosT) + abs(numRows * sinT)) + 1;
     
    748844        out = psImageRecycle(out, outCols, outRows, type);
    749845
    750         /* optimized public domain rotation routine by Karl Lager float cosT,sinT; cosT = cos(t); sinT =
    751          * sin(t); for (y = min_y; y <= max_y; y++) { x' = min_x * cosT + y * sinT + x1'; y' = y * cosT -
    752          * min_x * sinT + y1'; for (x = min_x; x <= max_x; x++) { if (x', y') * * * * * * * * is in the
    753          * bounds of the bitmap, get pixel(x', y') and plot the pixel to (x, y) on screen. x' += cosT; y' -=
    754          * sinT; } } */
    755 
    756         // precalculate some figures that are
    757         // used within loop
     846        /* optimized public domain rotation routine by Karl Lager
     847         *
     848         * float cosT,sinT;
     849         * cosT = cos(t);
     850         * sinT = sin(t);
     851         * for (y = min_y; y <= max_y; y++) {
     852         *     x' = min_x * cosT + y * sinT + x1';
     853         *     y' = y * cosT - min_x * sinT + y1';
     854         *     for (x = min_x; x <= max_x; x++) {
     855         *         if (x', y') is in the bounds of the bitmap, get pixel
     856         *            (x', y') and plot the pixel to (x, y) on screen.
     857         *         x' += cosT;
     858         *         y' -= sinT;
     859         *     }
     860         * }
     861         */
     862
     863        // precalculate some figures that are used within loop
    758864        float minXTimesCosTPlusCenterX = minX * cosT + centerX;
    759865        float CenterYMinusminXTimesSinT = centerY - minX * sinT;
    760866
    761867        #define PSIMAGE_ROTATE_ARBITRARY_LOOP(TYPE,MODE) { \
    762             if (creal(unexposedValue) < PS_MIN_##TYPE || creal(unexposedValue) > PS_MAX_##TYPE || \
    763                     cimag(unexposedValue) < PS_MIN_##TYPE || cimag(unexposedValue) > PS_MAX_##TYPE) { \
    764                 psError(__func__,"The given unexposedValue (%g%+g) is outside of the " \
    765                         "image type's range (%g->%g).", \
    766                         creal(unexposedValue),cimag(unexposedValue), \
    767                         (double)PS_MIN_##TYPE,(double)PS_MAX_##TYPE); \
     868            if (creal(unexposedValue) < PS_MIN_##TYPE || \
     869                    creal(unexposedValue) > PS_MAX_##TYPE || \
     870                    cimag(unexposedValue) < PS_MIN_##TYPE || \
     871                    cimag(unexposedValue) > PS_MAX_##TYPE) { \
     872                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRotate", \
     873                           PS_ERR_BAD_PARAMETER_VALUE, true, \
     874                           PS_ERRORTEXT_psImageManip_CLIP_VALUE_INVALID, \
     875                           "unexposedValue", \
     876                           creal(unexposedValue),cimag(unexposedValue), \
     877                           PS_TYPE_##TYPE##_NAME,  \
     878                           (double)PS_MIN_##TYPE,(double)PS_MAX_##TYPE); \
    768879                psFree(out); \
    769880                out = NULL; \
     
    824935            PSIMAGE_ROTATE_ARBITRARY_LOOP(C64,MODE); \
    825936            break; \
    826         default: \
    827             psError(__func__,"Image type (%d) not supported",type); \
    828             psFree(out); \
    829             out = NULL; \
     937        default: { \
     938                char* typeStr; \
     939                PS_TYPE_NAME(typeStr,type); \
     940                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRotate", \
     941                           PS_ERR_BAD_PARAMETER_TYPE, true, \
     942                           PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED, \
     943                           typeStr); \
     944                psFree(out); \
     945                out = NULL; \
     946            } \
    830947        } \
    831948        break;
     
    835952            PSIMAGE_ROTATE_ARBITRARY_CASE(BILINEAR);
    836953        default:
    837             psError(__func__, "Unsupported interpolation mode (%d)", mode);
     954            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRotate",
     955                       PS_ERR_BAD_PARAMETER_VALUE, true,
     956                       PS_ERRORTEXT_psImageManip_INTERPOLATION_MODE_UNSUPPORTED,
     957                       mode);
    838958            psFree(out);
    839959            out = NULL;
     
    857977
    858978    if (in == NULL) {
    859         psError(__func__, "Input image can not be NULL.");
     979        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageShift",
     980                   PS_ERR_BAD_PARAMETER_NULL, true,
     981                   PS_ERRORTEXT_psImage_IMAGE_NULL);
    860982        psFree(out);
    861983        return NULL;
     
    871993    #define PSIMAGE_SHIFT_CASE(MODE,TYPE) \
    872994case PS_TYPE_##TYPE: \
    873     if (creal(unexposedValue) < PS_MIN_##TYPE || creal(unexposedValue) > PS_MAX_##TYPE || \
    874             cimag(unexposedValue) < PS_MIN_##TYPE || cimag(unexposedValue) > PS_MAX_##TYPE) { \
    875         psError(__func__,"The given unexposedValue (%g%+g) is outside of the " \
    876                 "image type's range (%g->%g).", \
    877                 creal(unexposedValue), cimag(unexposedValue), \
    878                 (double)PS_MIN_##TYPE,(double)PS_MAX_##TYPE); \
     995    if (creal(unexposedValue) < PS_MIN_##TYPE || \
     996            creal(unexposedValue) > PS_MAX_##TYPE || \
     997            cimag(unexposedValue) < PS_MIN_##TYPE || \
     998            cimag(unexposedValue) > PS_MAX_##TYPE) { \
     999        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageShift", \
     1000                   PS_ERR_BAD_PARAMETER_VALUE, true, \
     1001                   PS_ERRORTEXT_psImageManip_CLIP_VALUE_INVALID, \
     1002                   "unexposedValue", \
     1003                   creal(unexposedValue),cimag(unexposedValue), \
     1004                   PS_TYPE_##TYPE##_NAME,  \
     1005                   (double)PS_MIN_##TYPE,(double)PS_MAX_##TYPE); \
    8791006        psFree(out); \
    8801007        out = NULL; \
     
    8851012        float y = dy+(float)row; \
    8861013        for (int col=0;col<outCols;col++) { \
    887             outRow[col] = p_psImagePixelInterpolate##MODE##_##TYPE(in,dx+(float)col,y,unexposedValue); \
     1014            outRow[col] = p_psImagePixelInterpolate##MODE##_##TYPE( \
     1015                          in,dx+(float)col,y,unexposedValue); \
    8881016        } \
    8891017    } \
     
    9051033        PSIMAGE_SHIFT_CASE(MODE,C32); \
    9061034        PSIMAGE_SHIFT_CASE(MODE,C64); \
    907     default: \
    908         psError(__func__, "Image type (%d) not supported.", type); \
    909         psFree(out); \
    910         out = NULL; \
     1035        \
     1036    default: { \
     1037            char* typeStr; \
     1038            PS_TYPE_NAME(typeStr,type); \
     1039            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRotate", \
     1040                       PS_ERR_BAD_PARAMETER_TYPE, true, \
     1041                       PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED, \
     1042                       typeStr); \
     1043            psFree(out); \
     1044            out = NULL; \
     1045        } \
    9111046    } \
    9121047    break;
     
    9171052        PSIMAGE_SHIFT_ARBITRARY_CASE(BILINEAR);
    9181053    default:
    919         psError(__func__, "Unsupported interpolation mode (%d)", mode);
     1054        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageShift",
     1055                   PS_ERR_BAD_PARAMETER_VALUE, true,
     1056                   PS_ERRORTEXT_psImageManip_INTERPOLATION_MODE_UNSUPPORTED,
     1057                   mode);
    9201058        psFree(out);
    9211059        out = NULL;
Note: See TracChangeset for help on using the changeset viewer.