Index: trunk/psLib/src/image/psImageManip.c
===================================================================
--- trunk/psLib/src/image/psImageManip.c	(revision 1827)
+++ trunk/psLib/src/image/psImageManip.c	(revision 1840)
@@ -10,6 +10,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-17 23:57:41 $
+ *  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-21 22:30:19 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -26,4 +26,6 @@
 #include "psMemory.h"
 #include "psImageExtraction.h"
+
+#include "psImageErrors.h"
 
 int psImageClip(psImage* input,
@@ -42,5 +44,8 @@
 
     if (max < min) {
-        psError(__func__, "psImageClip can not be invoked with max < min.");
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageClip",
+                   PS_ERR_BAD_PARAMETER_VALUE, true,
+                   PS_ERRORTEXT_psImageManip_MAXMIN,
+                   (double)min,(double)max);
         return 0;
     }
@@ -51,15 +56,19 @@
     switch (input->type.type) {
 
-        #define psImageClipCase(type,typename) \
+        #define psImageClipCase(type) \
     case PS_TYPE_##type: { \
             if (vmin < PS_MIN_##type || vmin > PS_MAX_##type) { \
-                psError(__func__, "Specified vmin (%g) is outside of image's " \
-                        typename " pixel range (%g to %g)", \
-                        vmin,(psF64)PS_MIN_##type,(psF64)PS_MAX_##type); \
+                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageClip", \
+                           PS_ERR_BAD_PARAMETER_VALUE, true, \
+                           PS_ERRORTEXT_psImage_PARAMETER_OUTOF_TYPERANGE, \
+                           "vmin",vmin, PS_TYPE_##type##_NAME, \
+                           (psF64)PS_MIN_##type,(psF64)PS_MAX_##type); \
             } \
             if (vmax > PS_MAX_##type || vmax < PS_MIN_##type) { \
-                psError(__func__, "Specified vmax (%g) is outside of image's " \
-                        typename " pixel range (%g to %g)", \
-                        vmax,(psF64)PS_MIN_##type,(psF64)PS_MAX_##type); \
+                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageClip", \
+                           PS_ERR_BAD_PARAMETER_VALUE, true, \
+                           PS_ERRORTEXT_psImage_PARAMETER_OUTOF_TYPERANGE, \
+                           "vmax",vmax, PS_TYPE_##type##_NAME, \
+                           (psF64)PS_MIN_##type,(psF64)PS_MAX_##type); \
             } \
             for (unsigned int row = 0;row<numRows;row++) { \
@@ -78,15 +87,19 @@
         break;
 
-        #define psImageClipCaseComplex(type,typename,absfcn)\
+        #define psImageClipCaseComplex(type,absfcn)\
     case PS_TYPE_##type: { \
             if (vmin < PS_MIN_##type || vmin > PS_MAX_##type) { \
-                psError(__func__, "Specified vmin (%g) is outside of image's " \
-                        typename " pixel range", \
-                        vmin); \
+                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageClip", \
+                           PS_ERR_BAD_PARAMETER_VALUE, true, \
+                           PS_ERRORTEXT_psImage_PARAMETER_OUTOF_TYPERANGE, \
+                           "vmin",vmin, PS_TYPE_##type##_NAME, \
+                           (psF64)PS_MIN_##type,(psF64)PS_MAX_##type); \
             } \
             if (vmax > PS_MAX_##type || vmax < PS_MIN_##type) { \
-                psError(__func__, "Specified vmax (%g) is outside of image's " \
-                        typename " pixel range", \
-                        vmax); \
+                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageClip", \
+                           PS_ERR_BAD_PARAMETER_VALUE, true, \
+                           PS_ERRORTEXT_psImage_PARAMETER_OUTOF_TYPERANGE, \
+                           "vmax",vmax, PS_TYPE_##type##_NAME, \
+                           (psF64)PS_MIN_##type,(psF64)PS_MAX_##type); \
             } \
             for (unsigned int row = 0;row<numRows;row++) { \
@@ -105,19 +118,25 @@
         break;
 
-        psImageClipCase(S8, "psS8")
-        psImageClipCase(S16, "psS16")
-        psImageClipCase(S32, "psS32")
-        psImageClipCase(S64, "psS64")
-        psImageClipCase(U8, "psU8")
-        psImageClipCase(U16, "psU16")
-        psImageClipCase(U32, "psU32")
-        psImageClipCase(U64, "psU64")
-        psImageClipCase(F32, "psF32")
-        psImageClipCase(F64, "psF64")
-        psImageClipCaseComplex(C32, "psC32", cabsf)
-        psImageClipCaseComplex(C64, "psC64", cabs)
-
-    default:
-        psError(__func__, "psImageClip does not support the given datatype (%d)", input->type.type);
+        psImageClipCase(S8)
+        psImageClipCase(S16)
+        psImageClipCase(S32)
+        psImageClipCase(S64)
+        psImageClipCase(U8)
+        psImageClipCase(U16)
+        psImageClipCase(U32)
+        psImageClipCase(U64)
+        psImageClipCase(F32)
+        psImageClipCase(F64)
+        psImageClipCaseComplex(C32, cabsf)
+        psImageClipCaseComplex(C64, cabs)
+
+    default: {
+            char* typeStr;
+            PS_TYPE_NAME(typeStr,input->type.type);
+            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageClip",
+                       PS_ERR_BAD_PARAMETER_TYPE, true,
+                       PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
+                       typeStr);
+        }
     }
 
@@ -158,6 +177,12 @@
         psImageClipNaNCase(C64)
 
-    default:
-        psError(__func__, "psImageClip does not support the given datatype (%d)", input->type.type);
+    default: {
+            char* typeStr;
+            PS_TYPE_NAME(typeStr,input->type.type);
+            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageClipNaN",
+                       PS_ERR_BAD_PARAMETER_TYPE, true,
+                       PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
+                       typeStr);
+        }
     }
 
@@ -180,10 +205,14 @@
 
     if (image == NULL || overlay == NULL) {
-        psError(__func__, "one of the input images was NULL.");
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageOverlaySection",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psImage_IMAGE_NULL);
         return 1;
     }
 
     if (op == NULL) {
-        psError(__func__, "Operation can not be NULL.");
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageOverlaySection",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psImageManip_OPERATION_NULL);
         return 1;
     }
@@ -192,5 +221,12 @@
 
     if (type != overlay->type.type) {
-        psError(__func__, "Image and overlay datatypes must match. (%d vs %d)", type, overlay->type.type);
+        char* typeStr;
+        char* typeStrOverlay;
+        PS_TYPE_NAME(typeStr,type);
+        PS_TYPE_NAME(typeStrOverlay,overlay->type.type);
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageOverlaySection",
+                   PS_ERR_BAD_PARAMETER_TYPE, true,
+                   PS_ERRORTEXT_psImageManip_OVERLAY_TYPE_MISMATCH,
+                   typeStrOverlay, typeStr);
         return 2;
     }
@@ -200,22 +236,19 @@
     overlayNumRows = overlay->numRows;
     overlayNumCols = overlay->numCols;
-
-    /* check row0/col0 to see if it is within the image size */
-    if (row0 < 0 || col0 < 0 || row0 >= imageNumRows || col0 >= imageNumCols) {
-        psError(__func__,
-                "Overlay origin of (%d,%d) is outside of the image dimensions (%d x %d).",
-                col0, row0, imageNumCols, imageNumRows);
-        return 3;
-    }
-
-    /* check if overlay is totally withing input image */
     imageRowLimit = row0 + overlayNumRows;
     imageColLimit = col0 + overlayNumCols;
-    if (imageRowLimit > imageNumRows || imageColLimit > imageNumCols) {
-        psError(__func__,
-                "Overlay image (%d,%d -> %d,%d) is partially outside"
-                " of the input image (%d x %d).",
-                col0, row0, col0 + overlayNumCols - 1, row0 + overlayNumRows - 1, imageNumCols, imageNumRows);
-        return 4;
+
+    /* check to see if overlay is within the input image */
+    if ( row0 < 0 ||
+            col0 < 0 ||
+            imageRowLimit > imageNumRows ||
+            imageColLimit > imageNumCols) {
+
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageOverlaySection",
+                   PS_ERR_BAD_PARAMETER_VALUE, true,
+                   PS_ERRORTEXT_psImage_SUBSET_RANGE_INVALID,
+                   col0, imageColLimit, row0, imageRowLimit,
+                   imageNumCols, imageNumRows);
+        return 3;
     }
 
@@ -245,5 +278,8 @@
                     break; \
                 default: \
-                    psError(__func__,"Unknown operation %s",op); \
+                    psErrorMsg(PS_ERRORNAME_DOMAIN "psImageOverlaySection", \
+                               PS_ERR_BAD_PARAMETER_VALUE, true, \
+                               PS_ERRORTEXT_psImageManip_OVERLAY_OPERATOR_INVALID, \
+                               op); \
                     return 5; \
                 } \
@@ -265,6 +301,12 @@
         psImageOverlayCase(C64);
 
-    default:
-        psError(__func__, "Can not operate on type %d.", type);
+    default: {
+            char* typeStr;
+            PS_TYPE_NAME(typeStr,type);
+            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageOverlaySection",
+                       PS_ERR_BAD_PARAMETER_TYPE, true,
+                       PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
+                       typeStr);
+        }
     }
 
@@ -287,17 +329,22 @@
 
     if (input == NULL) {
-        psError(__func__, "Can not perform clip on NULL image");
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageClipComplexRegion",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psImage_IMAGE_NULL);
         return 0;
     }
 
     if (realMax < realMin) {
-        psError(__func__,
-                "psImageClipComplexRegion can not be invoked with " "max < min in the real image space.");
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageClipComplexRegion",
+                   PS_ERR_BAD_PARAMETER_VALUE, true,
+                   PS_ERRORTEXT_psImageManip_MAXMIN_REAL,
+                   (double)realMin, (double)realMax);
         return 0;
     }
     if (imagMax < imagMin) {
-        psError(__func__,
-                "psImageClipComplexRegion can not be invoked with "
-                "max < min in the imaginary image space.");
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageClipComplexRegion",
+                   PS_ERR_BAD_PARAMETER_VALUE, true,
+                   PS_ERRORTEXT_psImageManip_MAXMIN_IMAG,
+                   (double)imagMin, (double)imagMax);
         return 0;
     }
@@ -306,18 +353,22 @@
     numCols = input->numCols;
 
-    #define psImageClipComplexRegionCase(type,typename,realfcn,imagfcn) \
+    #define psImageClipComplexRegionCase(type,realfcn,imagfcn) \
 case PS_TYPE_##type: { \
         if (realfcn(vmin) < PS_MIN_##type || imagfcn(vmin) < PS_MIN_##type || \
                 realfcn(vmin) > PS_MAX_##type || imagfcn(vmin) > PS_MAX_##type ) { \
-            psError(__func__, "Specified vmin (%g%+gi) is outside of image's " \
-                    typename " pixel range", \
-                    creal(vmin),cimag(vmin)); \
+            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageClipComplexRegion", \
+                       PS_ERR_BAD_PARAMETER_VALUE, true, \
+                       PS_ERRORTEXT_psImageManip_CLIP_VALUE_INVALID, \
+                       "vmin", creal(vmin), cimag(vmin), \
+                       PS_TYPE_##type##_NAME, PS_MIN_##type, PS_MAX_##type); \
             break; \
         } \
         if (realfcn(vmax) > PS_MAX_##type || imagfcn(vmax) > PS_MAX_##type || \
                 realfcn(vmax) < PS_MIN_##type || imagfcn(vmax) < PS_MIN_##type ) { \
-            psError(__func__, "Specified vmax (%g%+gi) is outside of image's " \
-                    typename " pixel range", \
-                    creal(vmax),cimag(vmax)); \
+            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageClipComplexRegion", \
+                       PS_ERR_BAD_PARAMETER_VALUE, true, \
+                       PS_ERRORTEXT_psImageManip_CLIP_VALUE_INVALID, \
+                       "vmax", creal(vmax), cimag(vmax), \
+                       PS_TYPE_##type##_NAME, PS_MIN_##type, PS_MAX_##type); \
             break; \
         } \
@@ -339,9 +390,15 @@
     switch (input->type.type) {
 
-        psImageClipComplexRegionCase(C32, "psC32", crealf, cimagf)
-        psImageClipComplexRegionCase(C64, "psC64", creal, cimag)
-
-    default:
-        psError(__func__, "psImageClip does not support the given datatype (%d)", input->type.type);
+        psImageClipComplexRegionCase(C32, crealf, cimagf)
+        psImageClipComplexRegionCase(C64, creal, cimag)
+
+    default: {
+            char* typeStr;
+            PS_TYPE_NAME(typeStr,input->type.type);
+            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageClipComplexRegion",
+                       PS_ERR_BAD_PARAMETER_TYPE, true,
+                       PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
+                       typeStr);
+        }
     }
 
@@ -367,5 +424,7 @@
 
     if (in == NULL) {
-        psError(__func__, "Input image is NULL.");
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRebin",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psImage_IMAGE_NULL);
         psFree(out);
         return NULL;
@@ -373,5 +432,8 @@
 
     if (scale < 1) {
-        psError(__func__, "The scale must be positive.");
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRebin",
+                   PS_ERR_BAD_PARAMETER_VALUE, true,
+                   PS_ERRORTEXT_psImageManip_SCALE_NOT_POSITIVE,
+                   scale);
         psFree(out);
         return NULL;
@@ -379,5 +441,7 @@
 
     if (stats == NULL) {
-        psError(__func__, "The stats input can not be NULL.");
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRebin",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psImage_STAT_NULL);
         psFree(out);
         return NULL;
@@ -385,5 +449,8 @@
 
     if (p_psGetStatValue(stats, &statVal) == false) {
-        psError(__func__, "The stat options didn't specify a single supported statistic type.");
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRebin",
+                   PS_ERR_BAD_PARAMETER_VALUE, true,
+                   PS_ERRORTEXT_psImage_BAD_STAT,
+                   stats->options);
         psFree(out);
         return NULL;
@@ -394,7 +461,10 @@
     if (mask != NULL) {
         if (mask->type.type != PS_TYPE_MASK) {
-            psError(__func__, "The mask datatype must be %s (%d).",
-                    PS_TYPE_MASK_NAME,
-                    mask->type.type);
+            char* typeStr;
+            PS_TYPE_NAME(typeStr,mask->type.type);
+            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRebin",
+                       PS_ERR_BAD_PARAMETER_TYPE, true,
+                       PS_ERRORTEXT_psImage_IMAGE_MASK_TYPE,
+                       typeStr, PS_TYPE_MASK_NAME);
             psFree(out);
             psFree(vec);
@@ -462,8 +532,15 @@
         PS_IMAGE_REBIN_CASE(C32);
         PS_IMAGE_REBIN_CASE(C64);
-    default:
-        psError(__func__, "Input image type not supported.");
-        psFree(out);
-        out = NULL;
+
+    default: {
+            char* typeStr;
+            PS_TYPE_NAME(typeStr,in->type.type);
+            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRebin",
+                       PS_ERR_BAD_PARAMETER_TYPE, true,
+                       PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
+                       typeStr);
+            psFree(out);
+            out = NULL;
+        }
     }
 
@@ -484,5 +561,7 @@
 
     if (in == NULL) {
-        psError(__func__, "Input image can not be NULL.");
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageResample",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psImage_IMAGE_NULL);
         psFree(out);
         return NULL;
@@ -520,8 +599,14 @@
         PSIMAGE_RESAMPLE_CASE(C32)
         PSIMAGE_RESAMPLE_CASE(C64)
-    default:
-        psError(__func__, "Unsupported type (%d)", in->type.type);
-        psFree(out);
-        return NULL;
+    default: {
+            char* typeStr;
+            PS_TYPE_NAME(typeStr,in->type.type);
+            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageResample",
+                       PS_ERR_BAD_PARAMETER_TYPE, true,
+                       PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
+                       typeStr);
+            psFree(out);
+            out = NULL;
+        }
     }
 
@@ -539,5 +624,7 @@
 
     if (in == NULL) {
-        psError(__func__, "Input image can not be NULL.");
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRoll",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psImage_IMAGE_NULL);
         psFree(out);
         return NULL;
@@ -570,12 +657,5 @@
             inRowNumber -= outRows;
         }
-        psU8* inRow = in->data.U8[inRowNumber]; // to
-
-        // allow
-
-        // byte
-        // arithmetic,
-
-        // but for all types
+        psU8* inRow = in->data.U8[inRowNumber]; // use byte arithmetic for all types
         psU8* outRow = out->data.U8[row];
 
@@ -594,5 +674,7 @@
 {
     if (in == NULL) {
-        psError(__func__, "The input image was NULL.");
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRotate",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psImage_IMAGE_NULL);
         psFree(out);
         return NULL;
@@ -635,8 +717,14 @@
             PSIMAGE_ROTATE_LEFT_90(C32);
             PSIMAGE_ROTATE_LEFT_90(C64);
-        default:
-            psError(__func__, "Unsupported type (%d)", type);
-            psFree(out);
-            return NULL;
+        default: {
+                char* typeStr;
+                PS_TYPE_NAME(typeStr,type);
+                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRotate",
+                           PS_ERR_BAD_PARAMETER_TYPE, true,
+                           PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
+                           typeStr);
+                psFree(out);
+                return NULL;
+            }
         }
     } else if (fabsf(angle - 180.0f) < FLT_EPSILON) {
@@ -675,8 +763,15 @@
             PSIMAGE_ROTATE_180_CASE(C32);
             PSIMAGE_ROTATE_180_CASE(C64);
-        default:
-            psError(__func__, "Unsupported type (%d)", type);
-            psFree(out);
-            return NULL;
+
+        default: {
+                char* typeStr;
+                PS_TYPE_NAME(typeStr,type);
+                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRotate",
+                           PS_ERR_BAD_PARAMETER_TYPE, true,
+                           PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
+                           typeStr);
+                psFree(out);
+                return NULL;
+            }
         }
     } else if (fabsf(angle - 270.0f) < FLT_EPSILON) {
@@ -714,8 +809,15 @@
             PSIMAGE_ROTATE_RIGHT_90(C32);
             PSIMAGE_ROTATE_RIGHT_90(C64);
-        default:
-            psError(__func__, "Unsupported type (%d)", type);
-            psFree(out);
-            return NULL;
+
+        default: {
+                char* typeStr;
+                PS_TYPE_NAME(typeStr,type);
+                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRotate",
+                           PS_ERR_BAD_PARAMETER_TYPE, true,
+                           PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
+                           typeStr);
+                psFree(out);
+                return NULL;
+            }
         }
     } else if (fabsf(angle) < FLT_EPSILON) {
@@ -731,13 +833,7 @@
         double sinT = sinf(t);
 
-        // calculate the corners of the rotated
-        // image so we know the proper
-        // output image size.
-        // x' = x cos(t) + y sin(t); i.e, x' =
-        // (x-centerX)*cosT +
-        // (y-centerY)*sinT;
-        // y' = y cos(t) - x sin(t); i.e. y' =
-        // (y-centerY)*cosT -
-        // (x-centerX)*sinT;
+        // calculate the corners of the rotated image so we know the proper output image size.
+        // x' = x cos(t) + y sin(t); i.e, x' = (x-centerX)*cosT + (y-centerY)*sinT;
+        // y' = y cos(t) - x sin(t); i.e. y' = (y-centerY)*cosT - (x-centerX)*sinT;
 
         int outCols = ceil(abs(numCols * cosT) + abs(numRows * sinT)) + 1;
@@ -748,22 +844,37 @@
         out = psImageRecycle(out, outCols, outRows, type);
 
-        /* optimized public domain rotation routine by Karl Lager float cosT,sinT; cosT = cos(t); sinT =
-         * sin(t); for (y = min_y; y <= max_y; y++) { x' = min_x * cosT + y * sinT + x1'; y' = y * cosT -
-         * min_x * sinT + y1'; for (x = min_x; x <= max_x; x++) { if (x', y') * * * * * * * * is in the
-         * bounds of the bitmap, get pixel(x', y') and plot the pixel to (x, y) on screen. x' += cosT; y' -=
-         * sinT; } } */
-
-        // precalculate some figures that are
-        // used within loop
+        /* optimized public domain rotation routine by Karl Lager
+         * 
+         * float cosT,sinT; 
+         * cosT = cos(t); 
+         * sinT = sin(t); 
+         * for (y = min_y; y <= max_y; y++) { 
+         *     x' = min_x * cosT + y * sinT + x1'; 
+         *     y' = y * cosT - min_x * sinT + y1'; 
+         *     for (x = min_x; x <= max_x; x++) { 
+         *         if (x', y') is in the bounds of the bitmap, get pixel
+         *            (x', y') and plot the pixel to (x, y) on screen. 
+         *         x' += cosT; 
+         *         y' -= sinT; 
+         *     }
+         * } 
+         */
+
+        // precalculate some figures that are used within loop
         float minXTimesCosTPlusCenterX = minX * cosT + centerX;
         float CenterYMinusminXTimesSinT = centerY - minX * sinT;
 
         #define PSIMAGE_ROTATE_ARBITRARY_LOOP(TYPE,MODE) { \
-            if (creal(unexposedValue) < PS_MIN_##TYPE || creal(unexposedValue) > PS_MAX_##TYPE || \
-                    cimag(unexposedValue) < PS_MIN_##TYPE || cimag(unexposedValue) > PS_MAX_##TYPE) { \
-                psError(__func__,"The given unexposedValue (%g%+g) is outside of the " \
-                        "image type's range (%g->%g).", \
-                        creal(unexposedValue),cimag(unexposedValue), \
-                        (double)PS_MIN_##TYPE,(double)PS_MAX_##TYPE); \
+            if (creal(unexposedValue) < PS_MIN_##TYPE || \
+                    creal(unexposedValue) > PS_MAX_##TYPE || \
+                    cimag(unexposedValue) < PS_MIN_##TYPE || \
+                    cimag(unexposedValue) > PS_MAX_##TYPE) { \
+                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRotate", \
+                           PS_ERR_BAD_PARAMETER_VALUE, true, \
+                           PS_ERRORTEXT_psImageManip_CLIP_VALUE_INVALID, \
+                           "unexposedValue", \
+                           creal(unexposedValue),cimag(unexposedValue), \
+                           PS_TYPE_##TYPE##_NAME,  \
+                           (double)PS_MIN_##TYPE,(double)PS_MAX_##TYPE); \
                 psFree(out); \
                 out = NULL; \
@@ -824,8 +935,14 @@
             PSIMAGE_ROTATE_ARBITRARY_LOOP(C64,MODE); \
             break; \
-        default: \
-            psError(__func__,"Image type (%d) not supported",type); \
-            psFree(out); \
-            out = NULL; \
+        default: { \
+                char* typeStr; \
+                PS_TYPE_NAME(typeStr,type); \
+                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRotate", \
+                           PS_ERR_BAD_PARAMETER_TYPE, true, \
+                           PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED, \
+                           typeStr); \
+                psFree(out); \
+                out = NULL; \
+            } \
         } \
         break;
@@ -835,5 +952,8 @@
             PSIMAGE_ROTATE_ARBITRARY_CASE(BILINEAR);
         default:
-            psError(__func__, "Unsupported interpolation mode (%d)", mode);
+            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRotate",
+                       PS_ERR_BAD_PARAMETER_VALUE, true,
+                       PS_ERRORTEXT_psImageManip_INTERPOLATION_MODE_UNSUPPORTED,
+                       mode);
             psFree(out);
             out = NULL;
@@ -857,5 +977,7 @@
 
     if (in == NULL) {
-        psError(__func__, "Input image can not be NULL.");
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageShift",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psImage_IMAGE_NULL);
         psFree(out);
         return NULL;
@@ -871,10 +993,15 @@
     #define PSIMAGE_SHIFT_CASE(MODE,TYPE) \
 case PS_TYPE_##TYPE: \
-    if (creal(unexposedValue) < PS_MIN_##TYPE || creal(unexposedValue) > PS_MAX_##TYPE || \
-            cimag(unexposedValue) < PS_MIN_##TYPE || cimag(unexposedValue) > PS_MAX_##TYPE) { \
-        psError(__func__,"The given unexposedValue (%g%+g) is outside of the " \
-                "image type's range (%g->%g).", \
-                creal(unexposedValue), cimag(unexposedValue), \
-                (double)PS_MIN_##TYPE,(double)PS_MAX_##TYPE); \
+    if (creal(unexposedValue) < PS_MIN_##TYPE || \
+            creal(unexposedValue) > PS_MAX_##TYPE || \
+            cimag(unexposedValue) < PS_MIN_##TYPE || \
+            cimag(unexposedValue) > PS_MAX_##TYPE) { \
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageShift", \
+                   PS_ERR_BAD_PARAMETER_VALUE, true, \
+                   PS_ERRORTEXT_psImageManip_CLIP_VALUE_INVALID, \
+                   "unexposedValue", \
+                   creal(unexposedValue),cimag(unexposedValue), \
+                   PS_TYPE_##TYPE##_NAME,  \
+                   (double)PS_MIN_##TYPE,(double)PS_MAX_##TYPE); \
         psFree(out); \
         out = NULL; \
@@ -885,5 +1012,6 @@
         float y = dy+(float)row; \
         for (int col=0;col<outCols;col++) { \
-            outRow[col] = p_psImagePixelInterpolate##MODE##_##TYPE(in,dx+(float)col,y,unexposedValue); \
+            outRow[col] = p_psImagePixelInterpolate##MODE##_##TYPE( \
+                          in,dx+(float)col,y,unexposedValue); \
         } \
     } \
@@ -905,8 +1033,15 @@
         PSIMAGE_SHIFT_CASE(MODE,C32); \
         PSIMAGE_SHIFT_CASE(MODE,C64); \
-    default: \
-        psError(__func__, "Image type (%d) not supported.", type); \
-        psFree(out); \
-        out = NULL; \
+        \
+    default: { \
+            char* typeStr; \
+            PS_TYPE_NAME(typeStr,type); \
+            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageRotate", \
+                       PS_ERR_BAD_PARAMETER_TYPE, true, \
+                       PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED, \
+                       typeStr); \
+            psFree(out); \
+            out = NULL; \
+        } \
     } \
     break;
@@ -917,5 +1052,8 @@
         PSIMAGE_SHIFT_ARBITRARY_CASE(BILINEAR);
     default:
-        psError(__func__, "Unsupported interpolation mode (%d)", mode);
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageShift",
+                   PS_ERR_BAD_PARAMETER_VALUE, true,
+                   PS_ERRORTEXT_psImageManip_INTERPOLATION_MODE_UNSUPPORTED,
+                   mode);
         psFree(out);
         out = NULL;
