Index: trunk/psLib/src/image/psImageExtraction.c
===================================================================
--- trunk/psLib/src/image/psImageExtraction.c	(revision 1613)
+++ trunk/psLib/src/image/psImageExtraction.c	(revision 1840)
@@ -10,6 +10,6 @@
 *  @author Robert DeSonia, MHPCC
 *
-*  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-08-25 00:04:01 $
+*  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-09-21 22:30:19 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -22,4 +22,6 @@
 #include "psImageExtraction.h"
 #include "psError.h"
+
+#include "psImageErrors.h"
 
 psImage* psImageSubset(psImage* image,
@@ -34,31 +36,34 @@
 
     if (image == NULL || image->data.V == NULL) {
-        psError(__func__, "Can not subset image because input image or its pixel buffer is NULL.");
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSubset",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psImage_IMAGE_NULL);
         return NULL;
     }
 
     if (image->type.dimen != PS_DIMEN_IMAGE) {
-        psError(__func__, "Can not subset image because input image is not an image.");
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSubset",
+                   PS_ERR_BAD_PARAMETER_TYPE, true,
+                   PS_ERRORTEXT_psImage_NOT_AN_IMAGE);
         return NULL;
     }
 
     if (numCols < 1 || numRows < 1) {
-        psError(__func__,
-                "Can not subset image because number of rows or columns are zero (%dx%d).", numCols, numRows);
-        return NULL;
-    }
-
-    if (col0 >= image->numCols || row0 >= image->numRows) {
-        psError(__func__,
-                "Can not subset image because col0,row0 (%d,%d) is not a valid pixel location.", col0, row0);
-        return NULL;
-    }
-
-    /* validate subimage size */
-    if (col0 + numCols >= image->numCols || row0 + numRows >= image->numRows) {
-        psError(__func__,
-                "Can not subset image outside of image boundaries (size=%dx%d, "
-                "subset=[%d:%d,%d:%d]).",
-                image->numCols, image->numRows, col0, col0 + numCols, row0, row0 + numRows);
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSubset",
+                   PS_ERR_BAD_PARAMETER_VALUE, true,
+                   PS_ERRORTEXT_psImage_AREA_NEGATIVE,
+                   numCols,numRows);
+        return NULL;
+    }
+
+    if ( col0 >= image->numCols ||
+            row0 >= image->numRows ||
+            col0 + numCols >= image->numCols ||
+            row0 + numRows >= image->numRows ) {
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSubset",
+                   PS_ERR_BAD_PARAMETER_VALUE, true,
+                   PS_ERRORTEXT_psImage_SUBSET_RANGE_INVALID,
+                   col0, col0 + numCols, row0, row0 + numRows,
+                   image->numCols, image->numRows);
         return NULL;
     }
@@ -104,12 +109,15 @@
     // section should be of the form '[x1:x2,y1:y2]'
     if (section == NULL) {
-        psError(__func__,"The subsection string input can not be NULL.");
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSubsection",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psImage_SUBSECTION_NULL);
         return NULL;
     }
 
     if (sscanf(section,"[%d:%d,%d:%d]",&x1,&x2,&y1,&y2) < 4) {
-        psError(__func__,"The subsection string (%s) can not be parsed.  "
-                "Needs to be of the form '[x1:x2,y1:y2]'",
-                section);
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSubsection",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psImage_SUBSECTION_INVALID,
+                   section);
         return NULL;
     }
@@ -120,11 +128,14 @@
 {
     if (image == NULL || image->data.V == NULL) {
-        psError(__func__, "Can not subset image because input image or its "
-                "pixel buffer is NULL.");
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageTrim",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psImage_IMAGE_NULL);
         return NULL;
     }
 
     if (image->parent != NULL) {
-        psError(__func__, "Can not perform a trim on a child image.");
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageTrim",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psImage_NOT_PARENT);
         return NULL;
     }
@@ -134,7 +145,9 @@
             y0 >= image->numRows || y1 >= image->numRows ||
             x0 > x1 || y0 > y1 ) {
-        psError(__func__, "Can not subset image because specified region "
-                "[%d:%d,%d:%d] is not valid for image of size %dx%d.",
-                x0,x1,y0,y1,image->numCols,image->numRows);
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageTrim",
+                   PS_ERR_BAD_PARAMETER_VALUE, true,
+                   PS_ERRORTEXT_psImage_SUBSET_RANGE_INVALID,
+                   x0, x1, y0, y1,
+                   image->numCols, image->numRows);
         return NULL;
     }
@@ -179,5 +192,7 @@
 
     if (input == NULL || input->data.V == NULL) {
-        psError(__func__, "Can not copy image because input image or its pixel buffer is NULL.");
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageCopy",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psImage_IMAGE_NULL);
         psFree(output);
         return NULL;
@@ -185,7 +200,7 @@
 
     if (input == output) {
-        psError(__func__,
-                "Can not copy image because given input and output "
-                "parameter reference the same psImage struct.");
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageCopy",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psImage_INPLACE_NOTSUPPORTED);
         psFree(output);
         return NULL;
@@ -193,5 +208,7 @@
 
     if (input->type.dimen != PS_DIMEN_IMAGE) {
-        psError(__func__, "Can not copy image because input image is not actually an image.");
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageCopy",
+                   PS_ERR_BAD_PARAMETER_TYPE, true,
+                   PS_ERRORTEXT_psImage_NOT_AN_IMAGE);
         psFree(output);
         return NULL;
@@ -205,5 +222,8 @@
 
     if (inDatatype == PS_TYPE_PTR || type == PS_TYPE_PTR) {
-        psError(__func__, "Can not copy image to/from a void* matrix");
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageCopy",
+                   PS_ERR_BAD_PARAMETER_TYPE, true,
+                   PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
+                   PS_TYPE_PTR_NAME);
         psFree(output);
         return NULL;
@@ -220,4 +240,5 @@
         return output;
     }
+
     #define PSIMAGE_ELEMENT_COPY(IN,INTYPE,OUT,OUTTYPE,ELEMENTS) { \
         ps##INTYPE *in; \
@@ -232,44 +253,45 @@
     }
 
-    #define PSIMAGE_COPY_CASE(OUT,OUTTYPE) \
-    switch (inDatatype) { \
-    case PS_TYPE_S8: \
-        PSIMAGE_ELEMENT_COPY(input,S8,OUT,OUTTYPE,elements); \
-        break; \
-    case PS_TYPE_S16: \
-        PSIMAGE_ELEMENT_COPY(input,S16,OUT,OUTTYPE,elements); \
-        break; \
-    case PS_TYPE_S32: \
-        PSIMAGE_ELEMENT_COPY(input,S32,OUT,OUTTYPE,elements); \
-        break; \
-    case PS_TYPE_S64: \
-        PSIMAGE_ELEMENT_COPY(input,S64,OUT,OUTTYPE,elements); \
-        break; \
-    case PS_TYPE_U8: \
-        PSIMAGE_ELEMENT_COPY(input,U8,OUT,OUTTYPE,elements); \
-        break; \
-    case PS_TYPE_U16: \
-        PSIMAGE_ELEMENT_COPY(input,U16,OUT,OUTTYPE,elements); \
-        break; \
-    case PS_TYPE_U32: \
-        PSIMAGE_ELEMENT_COPY(input,U32,OUT,OUTTYPE,elements); \
-        break; \
-    case PS_TYPE_U64: \
-        PSIMAGE_ELEMENT_COPY(input,U64,OUT,OUTTYPE,elements); \
-        break; \
-    case PS_TYPE_F32: \
-        PSIMAGE_ELEMENT_COPY(input,F32,OUT,OUTTYPE,elements); \
-        break; \
-    case PS_TYPE_F64: \
-        PSIMAGE_ELEMENT_COPY(input,F64,OUT,OUTTYPE,elements); \
-        break; \
-    case PS_TYPE_C32: \
-        PSIMAGE_ELEMENT_COPY(input,C32,OUT,OUTTYPE,elements); \
-        break; \
-    case PS_TYPE_C64: \
-        PSIMAGE_ELEMENT_COPY(input,C64,OUT,OUTTYPE,elements); \
-        break; \
-    default: \
-        break; \
+    #define PSIMAGE_COPY_CASE(OUT,OUTTYPE) { \
+        switch (inDatatype) { \
+        case PS_TYPE_S8: \
+            PSIMAGE_ELEMENT_COPY(input,S8,OUT,OUTTYPE,elements); \
+            break; \
+        case PS_TYPE_S16: \
+            PSIMAGE_ELEMENT_COPY(input,S16,OUT,OUTTYPE,elements); \
+            break; \
+        case PS_TYPE_S32: \
+            PSIMAGE_ELEMENT_COPY(input,S32,OUT,OUTTYPE,elements); \
+            break; \
+        case PS_TYPE_S64: \
+            PSIMAGE_ELEMENT_COPY(input,S64,OUT,OUTTYPE,elements); \
+            break; \
+        case PS_TYPE_U8: \
+            PSIMAGE_ELEMENT_COPY(input,U8,OUT,OUTTYPE,elements); \
+            break; \
+        case PS_TYPE_U16: \
+            PSIMAGE_ELEMENT_COPY(input,U16,OUT,OUTTYPE,elements); \
+            break; \
+        case PS_TYPE_U32: \
+            PSIMAGE_ELEMENT_COPY(input,U32,OUT,OUTTYPE,elements); \
+            break; \
+        case PS_TYPE_U64: \
+            PSIMAGE_ELEMENT_COPY(input,U64,OUT,OUTTYPE,elements); \
+            break; \
+        case PS_TYPE_F32: \
+            PSIMAGE_ELEMENT_COPY(input,F32,OUT,OUTTYPE,elements); \
+            break; \
+        case PS_TYPE_F64: \
+            PSIMAGE_ELEMENT_COPY(input,F64,OUT,OUTTYPE,elements); \
+            break; \
+        case PS_TYPE_C32: \
+            PSIMAGE_ELEMENT_COPY(input,C32,OUT,OUTTYPE,elements); \
+            break; \
+        case PS_TYPE_C64: \
+            PSIMAGE_ELEMENT_COPY(input,C64,OUT,OUTTYPE,elements); \
+            break; \
+        default: \
+            break; \
+        } \
     }
 
@@ -311,6 +333,15 @@
         PSIMAGE_COPY_CASE(output, C64);
         break;
-    default:
-        break;
+    default: {
+            char* typeStr;
+            PS_TYPE_NAME(typeStr,type);
+            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageCopy",
+                       PS_ERR_BAD_PARAMETER_TYPE, true,
+                       PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
+                       typeStr);
+            psFree(output);
+
+            break;
+        }
     }
     return output;
@@ -338,11 +369,16 @@
 
     if (in == NULL || in->data.V == NULL) {
-        psError(__func__, "Input image can not be NULL.");
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psImage_IMAGE_NULL);
         psFree(out);
         return NULL;
     }
 
-    if (numRows == 0 || numCols == 0) {
-        psError(__func__, "The specified region contains no data (%dx%d)", numCols, numRows);
+    if (numRows < 1 || numCols < 1) {
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psImage_SUBSET_ZERO_SIZE,
+                   col,col+numCols,row,row+numRows);
         psFree(out);
         return NULL;
@@ -374,26 +410,46 @@
     if (mask != NULL) {
         if (inRows != mask->numRows || inCols != mask->numCols) {
-            psError(__func__,
-                    "The mask and image dimensions did not match (%dx%d vs %dx%d)",
-                    mask->numCols, mask->numRows, in->numCols, in->numRows);
+            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice",
+                       PS_ERR_BAD_PARAMETER_VALUE, true,
+                       PS_ERRORTEXT_psImage_IMAGE_MASK_SIZE,
+                       mask->numCols,mask->numRows,
+                       inCols, inRows);
             psFree(out);
         }
         if (mask->type.type != PS_TYPE_MASK) {
-            psError(__func__, "The mask datatype (%d) must be %s.", mask->type.type, PS_TYPE_MASK_NAME);
+            char* typeStr;
+            PS_TYPE_NAME(typeStr,mask->type.type);
+            psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice",
+                       PS_ERR_BAD_PARAMETER_TYPE, true,
+                       PS_ERRORTEXT_psImage_IMAGE_MASK_TYPE,
+                       typeStr, PS_TYPE_MASK_NAME);
             psFree(out);
         }
     }
 
-    if (row >= inRows || col >= inCols || col + numCols > in->numCols || row + numRows > in->numRows) {
-        psError(__func__,
-                "The specified image region (%d,%d to %d,%d) is outside of image area (0,0 to %d,%d).",
-                col, row, col + numCols - 1, row + numRows - 1, in->numCols - 1, in->numRows - 1);
+    if (row >= inRows || col >= inCols || col + numCols > inCols || row + numRows > inRows) {
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice",
+                   PS_ERR_BAD_PARAMETER_VALUE, true,
+                   PS_ERRORTEXT_psImage_SUBSET_RANGE_INVALID,
+                   col, row, col+numCols, row+numRows,
+                   inCols, inRows);
         psFree(out);
         return NULL;
     }
+
+    if (stats == NULL) {
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice",
+                   PS_ERR_BAD_PARAMETER_NULL, true,
+                   PS_ERRORTEXT_psImage_STAT_NULL);
+        psFree(out);
+        return NULL;
+    }
+
     // verify that the stats struct specifies a
     // single stats operation
-    if (stats == NULL || p_psGetStatValue(stats, &statVal) == false) {
-        psError(__func__, "The stat options didn't specify a single supported statistic type.");
+    if (p_psGetStatValue(stats, &statVal) == false) {
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice",
+                   PS_ERR_BAD_PARAMETER_VALUE, false,
+                   PS_ERRORTEXT_psImage_BAD_STAT);
         psFree(out);
         return NULL;
@@ -410,8 +466,6 @@
         psU32* outPosition = NULL;
 
-        // recycle output to make a proper
-        // sized/type output structure
-        // n.b. type is double as that is the
-        // type given for all stats in
+        // recycle output to make a proper sized/type output structure
+        // n.b. type is double as that is the type given for all stats is
         // psStats.
         out = psVectorRecycle(out, numCols, PS_TYPE_F64);
@@ -474,24 +528,19 @@
             PSIMAGE_CUT_VERTICAL(C32);
             PSIMAGE_CUT_VERTICAL(C64);
-        default:
-            psError(__func__, "Unsupported datatype (%d)", type);
-            psFree(out);
-            out = NULL;
+        default: {
+                char* typeStr;
+                PS_TYPE_NAME(typeStr,type);
+                psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice",
+                           PS_ERR_BAD_PARAMETER_TYPE, true,
+                           PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
+                           typeStr);
+                psFree(out);
+                out = NULL;
+            }
         }
         psFree(imgVec);
         psFree(maskVec);
-    } else if (direction == PS_CUT_Y_POS || direction == PS_CUT_Y_NEG) {        // Cut
-        //
-        //
-        //
-        //
-        //
-        //
-        //
-        //
-        //
-        // in
-        // Y
-        // direction
+    } else if (direction == PS_CUT_Y_POS || direction == PS_CUT_Y_NEG) {
+        // Cut in Y direction
         psVector* imgVec = NULL;
         psVector* maskVec = NULL;
@@ -509,8 +558,6 @@
             maskVec->n = maskVec->nalloc = numCols;
         }
-        // recycle output to make a proper
-        // sized/type output structure
-        // n.b. type is double as that is the
-        // type given for all stats in
+        // recycle output to make a proper sized/type output structure
+        // n.b. type is double as that is the type given for all stats in
         // psStats.
         out = psVectorRecycle(out, numRows, PS_TYPE_F64);
@@ -535,10 +582,5 @@
             }
             myStats = psVectorStats(myStats, imgVec, maskVec, maskVal);
-            (void)p_psGetStatValue(myStats, &statVal);  // we
-            // know
-            // it
-            // works
-            // cause we tested it
-            // above
+            (void)p_psGetStatValue(myStats, &statVal);  // we know it works cause we tested it above
             *outData = statVal;
             if (outPosition != NULL) {
@@ -551,12 +593,9 @@
         psFree(imgVec);
         psFree(maskVec);
-    } else {                               // don't
-        // know
-        // what
-        // the
-        // direction
-        // flag
-        // is
-        psError(__func__, "Invalid direction flag (%d)", direction);
+    } else { // don't know what the direction flag is
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageSlice",
+                   PS_ERR_BAD_PARAMETER_VALUE, true,
+                   PS_ERRORTEXT_psImage_SLICE_DIRECTION_INVALID,
+                   direction);
         psFree(out);
         out = NULL;
