Index: /trunk/psLib/src/image/psImageManip.c
===================================================================
--- /trunk/psLib/src/image/psImageManip.c	(revision 2834)
+++ /trunk/psLib/src/image/psImageManip.c	(revision 2835)
@@ -10,6 +10,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-12-23 19:14:15 $
+ *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-12-28 01:42:28 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -195,9 +195,10 @@
     psU32 imageColLimit;
     psElemType type;
+    psU32 pixelsOverlaid = 0;
 
     if (image == NULL || overlay == NULL) {
         psError(PS_ERR_BAD_PARAMETER_NULL, true,
                 PS_ERRORTEXT_psImage_IMAGE_NULL);
-        return 1;
+        return pixelsOverlaid;
     }
 
@@ -205,5 +206,5 @@
         psError(PS_ERR_BAD_PARAMETER_NULL, true,
                 PS_ERRORTEXT_psImageManip_OPERATION_NULL);
-        return 1;
+        return pixelsOverlaid;
     }
 
@@ -218,5 +219,5 @@
                 PS_ERRORTEXT_psImageManip_OVERLAY_TYPE_MISMATCH,
                 typeStrOverlay, typeStr);
-        return 2;
+        return pixelsOverlaid;
     }
 
@@ -238,49 +239,54 @@
                 col0, imageColLimit, row0, imageRowLimit,
                 imageNumCols, imageNumRows);
-        return 3;
-    }
-
-    switch (type) {
-
-        #define psImageOverlayCase(DATATYPE) \
-    case PS_TYPE_##DATATYPE: \
-        for (psU32 row=row0;row<imageRowLimit;row++) { \
+        return pixelsOverlaid;
+    }
+
+
+    #define psImageOverlayLoop(DATATYPE,OP) { \
+        for (int row=row0;row<imageRowLimit;row++) { \
             ps##DATATYPE* imageRow = image->data.DATATYPE[row]; \
             ps##DATATYPE* overlayRow = overlay->data.DATATYPE[row-row0]; \
-            for (psU32 col=col0;col<imageColLimit;col++) { \
-                switch (*op) { \
-                case '+': \
-                    imageRow[col] += overlayRow[col-col0]; \
-                    break; \
-                case '-': \
-                    imageRow[col] -= overlayRow[col-col0]; \
-                    break; \
-                case '*': \
-                    imageRow[col] *= overlayRow[col-col0]; \
-                    break; \
-                case '/': \
-                    imageRow[col] /= overlayRow[col-col0]; \
-                    break; \
-                case '=': \
-                    imageRow[col] = overlayRow[col-col0]; \
-                    break; \
-                default: \
-                    psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
-                            PS_ERRORTEXT_psImageManip_OVERLAY_OPERATOR_INVALID, \
-                            op); \
-                    return 5; \
-                } \
-            } \
-        } \
-        break;
-
+            for (int col=col0;col<imageColLimit;col++) { \
+                imageRow[col] OP overlayRow[col-col0]; \
+            } \
+        } \
+        pixelsOverlaid += (imageRowLimit - row0) * (imageColLimit - col0); \
+    }
+
+    #define psImageOverlayCase(DATATYPE) \
+case PS_TYPE_##DATATYPE: \
+    switch (*op) { \
+    case '+': \
+        psImageOverlayLoop(DATATYPE,+=); \
+        break; \
+    case '-': \
+        psImageOverlayLoop(DATATYPE,-=); \
+        break; \
+    case '*': \
+        psImageOverlayLoop(DATATYPE,*=); \
+        break; \
+    case '/': \
+        psImageOverlayLoop(DATATYPE,/=); \
+        break; \
+    case '=': \
+        psImageOverlayLoop(DATATYPE,=); \
+        break; \
+    default: \
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true, \
+                PS_ERRORTEXT_psImageManip_OVERLAY_OPERATOR_INVALID, \
+                op); \
+        return pixelsOverlaid; \
+    } \
+    break;
+
+    switch (type) {
         psImageOverlayCase(U8);
         psImageOverlayCase(U16);
-        //        psImageOverlayCase(U32);       Not a requirement
-        //        psImageOverlayCase(U64);       Not a requirement
+        psImageOverlayCase(U32);       // Not a requirement
+        psImageOverlayCase(U64);       // Not a requirement
         psImageOverlayCase(S8);
         psImageOverlayCase(S16);
-        //        psImageOverlayCase(S32);       Not a requirement
-        //        psImageOverlayCase(S64);       Not a requirement
+        psImageOverlayCase(S32);       // Not a requirement
+        psImageOverlayCase(S64);       // Not a requirement
         psImageOverlayCase(F32);
         psImageOverlayCase(F64);
@@ -294,9 +300,9 @@
                     PS_ERRORTEXT_psImage_IMAGE_TYPE_UNSUPPORTED,
                     typeStr);
-            return 6;
-        }
-    }
-
-    return 0;
+            return pixelsOverlaid;
+        }
+    }
+
+    return pixelsOverlaid;
 }
 
@@ -832,18 +838,18 @@
 
         /* 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++) { 
+         *
+         * 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; 
+         *            (x', y') and plot the pixel to (x, y) on screen.
+         *         x' += cosT;
+         *         y' -= sinT;
          *     }
-         * } 
+         * }
          */
 
Index: /trunk/psLib/test/image/tst_psImageManip.c
===================================================================
--- /trunk/psLib/test/image/tst_psImageManip.c	(revision 2834)
+++ /trunk/psLib/test/image/tst_psImageManip.c	(revision 2835)
@@ -6,6 +6,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-12-18 00:01:08 $
+ *  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-12-28 01:43:17 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -331,5 +331,5 @@
     1. Create a complex image with a wide range of complex values
 
-    2. call psImageClipComplexRegion with min and max where there is at least 
+    2. call psImageClipComplexRegion with min and max where there is at least
        2 pixels in the image above) that is:
         a) real(p) < real(min) && complex(p) < complex(min),
@@ -347,5 +347,5 @@
     4. verify that all pixels in case (d) are unchanged from input
 
-    5. verify that all pixels in case (e), (f), (g), (h), and (i) have the 
+    5. verify that all pixels in case (e), (f), (g), (h), and (i) have the
        value vmax
 
@@ -606,6 +606,4 @@
     */
 
-
-
     #define testOverlayTypeOP(DATATYPE,OP,OPSTRING) \
     img = psImageAlloc(c,r,PS_TYPE_##DATATYPE); \
@@ -624,6 +622,7 @@
     } \
     retVal = psImageOverlaySection(img,img2,c/4,r/4,OPSTRING); \
-    if (retVal != 0) { \
-        psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned non-zero %s op",OPSTRING); \
+    if (retVal == 0) { \
+        psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned zero with %s op", \
+                OPSTRING); \
         return 1; \
     } \
@@ -705,7 +704,7 @@
              "within image boundaries");
     retVal = psImageOverlaySection(img,img2,c/4,r/4,"+");
-    if (retVal == 0) {
-        psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned zero even though "
-                "overlay too big");
+    if (retVal != 0) {
+        psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection did not return "
+                "zero even though overlay too big");
         return 3;
     }
@@ -728,7 +727,7 @@
     psLogMsg(__func__,PS_LOG_INFO,"Following should error as overlay is NULL");
     retVal = psImageOverlaySection(img,NULL,c/4,r/4,"+");
-    if (retVal == 0) {
-        psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned zero even though "
-                "overlay too big");
+    if (retVal != 0) {
+        psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection did not return "
+                "zero even though overlay too big");
         return 5;
     }
@@ -750,6 +749,6 @@
     psLogMsg(__func__,PS_LOG_INFO,"Following should error as image input is NULL");
     retVal = psImageOverlaySection(NULL,img2,c/4,r/4,"+");
-    if (retVal == 0) {
-        psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned zero even though "
+    if (retVal != 0) {
+        psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned non-zero even though "
                 "overlay too big");
         return 7;
@@ -763,6 +762,6 @@
     psLogMsg(__func__,PS_LOG_INFO,"Following should error as operator is invalid");
     retVal = psImageOverlaySection(img,img2,0,0,"$");
-    if (retVal == 0) {
-        psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned zero even though "
+    if (retVal != 0) {
+        psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned non-zero even though "
                 "overlay operator is invalid");
         return 8;
@@ -776,6 +775,6 @@
     psLogMsg(__func__,PS_LOG_INFO,"Following should error as operator is invalid");
     retVal = psImageOverlaySection(img,img2,0,0,NULL);
-    if(retVal == 0) {
-        psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned zero even though "
+    if(retVal != 0) {
+        psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned non-zero even though "
                 "overlay operator is NULL");
         return 9;
@@ -783,5 +782,5 @@
 
     /*
-    Verify the return integer is equal to non-zero and program execution 
+    Verify the return integer is equal to non-zero and program execution
     doesn't stop, if overlay image is a different type than the input image
     */
@@ -789,21 +788,8 @@
              "a different type");
     retVal = psImageOverlaySection(img,img3,0,0,"+");
-    if(retVal == 0) {
-        psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned zero eventhough "
+    if(retVal != 0) {
+        psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned nonzero eventhough "
                 " overlay image type is different than input image.");
         return 10;
-    }
-
-    /*
-    Verify the return integer is equal to non-zero and program execution
-    doesn't stop, if invalid input and overlay images
-    */
-    psLogMsg(__func__,PS_LOG_INFO,"Following should error as overlay and "
-             "image are not valid for the psImageOverlaySection function.");
-    retVal = psImageOverlaySection(img3,img4,0,0,"+");
-    if(retVal == 0) {
-        psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned zero eventhough "
-                "overlay and image type are invalid type.");
-        return 11;
     }
 
@@ -819,6 +805,6 @@
     }
     retVal = psImageOverlaySection(img,img2,0,0,"/");
-    if (retVal != 0) {
-        psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned non-zero when "
+    if (retVal == 0) {
+        psError(PS_ERR_UNKNOWN, true,"psImageOverlaySection returned zero when "
                 "checking divide-by-zero.");
         return 12;
@@ -837,5 +823,5 @@
 
     /*
-    This function shall generate a rescaled version of a psImage structure 
+    This function shall generate a rescaled version of a psImage structure
     derived from a specified statistics method.
     */
@@ -852,9 +838,9 @@
 
     /*
-    Verify the returned psImage structure contains expected values, if the 
-    input parameter input contains known data, the input scale is a known 
-    value with a known statistical method specified in stats. Cases should 
-    include at least two different scales and statistical methods. Comparison 
-    of expected values should include a delta to allow testing on different 
+    Verify the returned psImage structure contains expected values, if the
+    input parameter input contains known data, the input scale is a known
+    value with a known statistical method specified in stats. Cases should
+    include at least two different scales and statistical methods. Comparison
+    of expected values should include a delta to allow testing on different
     platforms.
     */
@@ -1094,14 +1080,14 @@
 
     /*
-     The function psImageRoll shall generate a new psImage structure by 
+     The function psImageRoll shall generate a new psImage structure by
      rolling the input image the correponding number of pixels in the vertical
      and/or horizontal direction. The image output image shall be the same size
-     as the input image. Values which roll off the image are wrapped to the 
+     as the input image. Values which roll off the image are wrapped to the
      other side.
 
-     Verify the returned psImage structure contains expected values, if the 
-     input image contains known values and the roll performed is known. 
-     Cases should include no roll, vertical roll, horizontal roll and 
-     combination vertical/horizontal rolls. Positive and negative rolls 
+     Verify the returned psImage structure contains expected values, if the
+     input image contains known values and the roll performed is known.
+     Cases should include no roll, vertical roll, horizontal roll and
+     combination vertical/horizontal rolls. Positive and negative rolls
      should be performed.
     */
@@ -1274,14 +1260,14 @@
     /*
 
-    This function shall calculate a new psImage structure based upon the 
-    rotation of a given psImage structure. The center of rotation shall be the 
+    This function shall calculate a new psImage structure based upon the
+    rotation of a given psImage structure. The center of rotation shall be the
     center pixel of the input image.
 
-    The following steps of the testpoint are done manually via inspection of 
+    The following steps of the testpoint are done manually via inspection of
     temp/fOut.fits & temp/sOut.fits.
 
-        * Verify the returned psImage structure contains expected values, if 
-          the input parameter psImage contains known values. Cases should 
-          include rotations of 0, 45, 90, 135, 180, 225, 270, 315, 360 and at leat one 
+        * Verify the returned psImage structure contains expected values, if
+          the input parameter psImage contains known values. Cases should
+          include rotations of 0, 45, 90, 135, 180, 225, 270, 315, 360 and at leat one
           other arbitrary angle. Cases of the input image should include image
           with a center pixel and an image without a center pixel.
@@ -1541,17 +1527,17 @@
     /* psImageShift:
 
-       This functions shall generate a new psImage structure by shifting the 
-       input psImage structure a specified number of pixels in the horizontal 
+       This functions shall generate a new psImage structure by shifting the
+       input psImage structure a specified number of pixels in the horizontal
        and/or vertical directions.
 
-       Verify the returned psImage structure contains expected values, if the 
-       input psImage structure contains known values and a know shift in the 
-       vertical and/or horizontal directions. Cases should include no shift, 
-       vertical only(up,down), horizontal only(right, left), and combination 
-       shift. Cases should include fractional shifts. Comparison of expected 
-       values should include a delta to allow for testing on different 
+       Verify the returned psImage structure contains expected values, if the
+       input psImage structure contains known values and a know shift in the
+       vertical and/or horizontal directions. Cases should include no shift,
+       vertical only(up,down), horizontal only(right, left), and combination
+       shift. Cases should include fractional shifts. Comparison of expected
+       values should include a delta to allow for testing on different
        platforms.
 
-       Verify the returned psImage structure contains values for pixels not in 
+       Verify the returned psImage structure contains values for pixels not in
        the original image set to the input parameter exposed.
 
@@ -1590,5 +1576,5 @@
 
     /*
-       Verify the returned psImage structure pointer is equal to the input 
+       Verify the returned psImage structure pointer is equal to the input
        parameter out if provided.
     */
@@ -1603,5 +1589,5 @@
 
     /*
-       Verify the returned psImage structure pointer is null and program 
+       Verify the returned psImage structure pointer is null and program
        execution doesn't stop, if the input psImage structure pointer is null.
     */
@@ -1820,4 +1806,5 @@
     psErrorClear();
     psImage* invImage = psImageAlloc(cols,rows,PS_TYPE_PTR);
+    memset(invImage->rawDataBuffer,0,cols*rows*sizeof(psPtr)); // make sure the image is of all NULLs
     result = psImageResample(result,invImage,2,PS_INTERPOLATE_FLAT);
     if (result != NULL) {
