Index: /trunk/psLib/src/mathtypes/psImage.c
===================================================================
--- /trunk/psLib/src/mathtypes/psImage.c	(revision 7662)
+++ /trunk/psLib/src/mathtypes/psImage.c	(revision 7663)
@@ -9,6 +9,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.109 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-06-23 21:17:52 $
+ *  @version $Revision: 1.110 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-06-24 00:22:54 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -113,131 +113,4 @@
 }
 
-
-// XXX these have been moved to psRegion* in src/math/
-# if 0
-psRegion psRegionSet(float x0,
-                     float x1,
-                     float y0,
-                     float y1)
-{
-    psRegion out;
-
-    out.x0 = x0;
-    out.y0 = y0;
-    out.x1 = x1;
-    out.y1 = y1;
-
-    return out;
-}
-
-psRegion psRegionFromString(const char* region)
-{
-    psS32 col0;
-    psS32 col1;
-    psS32 row0;
-    psS32 row1;
-
-    // section should be of the form '[col0:col1,row0:row1]'
-    if (region == NULL) {
-        psError(PS_ERR_BAD_PARAMETER_NULL, true,
-                PS_ERRORTEXT_psImage_SUBSECTION_NULL);
-        return psRegionSet(NAN,NAN,NAN,NAN);
-    }
-
-    if (sscanf(region,"[%d:%d,%d:%d]",&col0,&col1,&row0,&row1) < 4) {
-        psError(PS_ERR_BAD_PARAMETER_NULL, true,
-                PS_ERRORTEXT_psImage_SUBSECTION_INVALID,
-                region);
-        return psRegionSet(NAN,NAN,NAN,NAN);
-    }
-
-    if (col0 > col1 || row0 > row1) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
-                PS_ERRORTEXT_psImage_SUBSET_RANGE_MALFORMED,
-                col0,col1,row0,row1);
-        return psRegionSet(NAN,NAN,NAN,NAN);
-    }
-
-    return psRegionSet(col0-1,col1,row0-1,row1);
-}
-
-psString psRegionToString(const psRegion region)
-{
-    char tmpText[256]; // big enough to store any region as text
-
-    snprintf(tmpText,256,"[%g:%g,%g:%g]",
-             region.x0+1, region.x1,
-             region.y0+1, region.y1);
-
-    return psStringCopy(tmpText);
-}
-
-// set actual region based on image parameters:
-// - compensate for negative upper limits
-// - force range to be on this image
-// - saturate on upper and lower limits of image
-// - flip x0,x1 if x0>x1
-// - flip y0,y1 if y0>y1
-// XXX EAM : psRegion refers to coordinates in the *parent* image
-psRegion psRegionForImage(psImage *image,
-                          psRegion in)
-{
-
-    //    if (image == NULL) {
-    //        return in;
-    //    }
-    PS_ASSERT_IMAGE_NON_NULL(image, in);
-    //if the region is [0,0,0,0], the whole image (or subimage) is to be included.
-    if (in.x0 == 0 && in.x1 == 0 && in.y0 == 0 && in.y1 == 0) {
-        in.x0 = image->col0;
-        in.x1 = image->col0 + image->numCols - 1;
-        in.y0 = image->row0;
-        in.y1 = image->row0 + image->numRows - 1;
-        return (in);
-    }
-
-    // convert non-positive upper-limits
-    // XXX note that the upper limit in these cases is defined relative to the subimage
-    // also note that truncation limits to the valid subimage pixels
-    in.x1 = (in.x1 <= 0) ? (image->col0 + image->numCols + in.x1) : in.x1;
-    in.y1 = (in.y1 <= 0) ? (image->row0 + image->numRows + in.y1) : in.y1;
-
-    // force the upper-limits to be on the subimage
-    in.x1 = PS_MIN(image->col0 + image->numCols, in.x1);
-    in.y1 = PS_MIN(image->row0 + image->numRows, in.y1);
-
-    // force the lower-limits to be on the subimage
-    in.x0 = PS_MAX(image->col0, in.x0);
-    in.y0 = PS_MAX(image->row0, in.y0);
-    in.x0 = PS_MIN(image->col0 + image->numCols, in.x0);
-    in.y0 = PS_MIN(image->row0 + image->numRows, in.y0);
-
-    // flip start and end if out of order
-    if (in.x0 > in.x1) {
-        psError (PS_ERR_BAD_PARAMETER_VALUE, true,
-                 "Invalid region in psRegionForImage.  x0 > x1.  Values have been swapped.\n");
-        PS_SWAP (in.x0, in.x1);
-    }
-    if (in.y0 > in.y1) {
-        psError (PS_ERR_BAD_PARAMETER_VALUE, true,
-                 "Invalid region in psRegionForImage.  y0 > y1.  Values have been swapped.\n");
-        PS_SWAP (in.y0, in.y1);
-    }
-
-    return (in);
-}
-
-// define a square region centered on the given coordinate
-psRegion psRegionForSquare(double x,
-                           double y,
-                           double radius)
-{
-    psRegion region;
-    region = psRegionSet (x - radius, x + radius + 1,
-                          y - radius, y + radius + 1);
-    return (region);
-}
-# endif /* commented-out psRegion functions */
-
 bool psImageInit (psImage *image,...)
 {
@@ -251,19 +124,26 @@
 
     switch (image->type.type) {
-        #define IMAGEINIT_INTCASE(TTT,NATIVETYPE) \
-    case PS_TYPE_##TTT: { \
-            NATIVETYPE temp = va_arg (argp, NATIVETYPE); \
-            if ( temp < PS_MIN_##TTT || temp > PS_MAX_##TTT ) { \
+        #define IMAGEINIT_INTCASE(TYPE,NATIVETYPE) \
+    case PS_TYPE_##TYPE: { \
+            NATIVETYPE temp = va_arg(argp, NATIVETYPE); \
+            if ( temp < PS_MIN_##TYPE || temp > PS_MAX_##TYPE ) { \
                 psError(PS_ERR_BAD_PARAMETER_VALUE, true, "Error: Value %d out of Range.\n", temp); \
                 return false; \
             } \
-            ps##TTT value = temp; \
-            for (int iy = 0; iy < image->numRows; iy++) { \
-                ps##TTT *row = image->data.TTT[iy]; \
-                for (int ix = 0; ix < image->numCols; ix++) { \
-                    row[ix] = value; \
+            ps##TYPE value = temp; \
+            if (value == 0) { \
+                size_t numBytes = image->numCols * sizeof(ps##TYPE); \
+                for (int y = 0; y < image->numRows; y++) { \
+                    memset(image->data.TYPE[y], 0, numBytes); \
+                } \
+            } else { \
+                for (int iy = 0; iy < image->numRows; iy++) { \
+                    ps##TYPE *row = image->data.TYPE[iy]; \
+                    for (int ix = 0; ix < image->numCols; ix++) { \
+                        row[ix] = value; \
+                    } \
                 } \
             } \
-            return (true); \
+            return true; \
         }
 
@@ -275,14 +155,21 @@
         IMAGEINIT_INTCASE(S32,int)
 
-        #define IMAGEINIT_LONGCASE(TTT,NATIVETYPE) \
-    case PS_TYPE_##TTT: { \
-            ps##TTT value = va_arg (argp, NATIVETYPE); \
-            for (int iy = 0; iy < image->numRows; iy++) { \
-                ps##TTT *row = image->data.TTT[iy]; \
-                for (int ix = 0; ix < image->numCols; ix++) { \
-                    row[ix] = value; \
+        #define IMAGEINIT_LONGCASE(TYPE,NATIVETYPE) \
+    case PS_TYPE_##TYPE: { \
+            ps##TYPE value = va_arg(argp, NATIVETYPE); \
+            if (value == 0) { \
+                size_t numBytes = image->numCols * sizeof(ps##TYPE); \
+                for (int y = 0; y < image->numRows; y++) { \
+                    memset(image->data.TYPE[y], 0, numBytes); \
+                } \
+            } else { \
+                for (int iy = 0; iy < image->numRows; iy++) { \
+                    ps##TYPE *row = image->data.TYPE[iy]; \
+                    for (int ix = 0; ix < image->numCols; ix++) { \
+                        row[ix] = value; \
+                    } \
                 } \
             } \
-            return (true); \
+            return true; \
         }
 
@@ -290,15 +177,21 @@
         IMAGEINIT_LONGCASE(S64,long)
 
-        #define IMAGEINIT_FLOATCASE(TTT) \
-    case PS_TYPE_##TTT: { \
-            ps##TTT value = va_arg(argp, psF64); \
-            \
-            for (int iy = 0; iy < image->numRows; iy++) { \
-                ps##TTT *row = image->data.TTT[iy]; \
-                for (int ix = 0; ix < image->numCols; ix++) { \
-                    row[ix] = value; \
+        #define IMAGEINIT_FLOATCASE(TYPE) \
+    case PS_TYPE_##TYPE: { \
+            ps##TYPE value = va_arg(argp, psF64); \
+            if (value == 0) { \
+                size_t numBytes = image->numCols * sizeof(ps##TYPE); \
+                for (int y = 0; y < image->numRows; y++) { \
+                    memset(image->data.TYPE[y], 0, numBytes); \
+                } \
+            } else { \
+                for (int iy = 0; iy < image->numRows; iy++) { \
+                    ps##TYPE *row = image->data.TYPE[iy]; \
+                    for (int ix = 0; ix < image->numCols; ix++) { \
+                        row[ix] = value; \
+                    } \
                 } \
             } \
-            return (true); \
+            return true; \
         }
 
@@ -308,5 +201,4 @@
     default:
         psError (PS_ERR_BAD_PARAMETER_TYPE, true, "datatype %d not defined in psImageInit\n", image->type);
-        return (false);
     }
     return (false);
