Index: trunk/psLib/src/imageops/psImagePixelManip.c
===================================================================
--- trunk/psLib/src/imageops/psImagePixelManip.c	(revision 34800)
+++ trunk/psLib/src/imageops/psImagePixelManip.c	(revision 40045)
@@ -216,4 +216,5 @@
     }
 
+    // this function is only called for float-type values
 #define psImageOverlayLoopClean(DATATYPE,OP) {	 \
       for (int row=y0;row<imageRowLimit;row++) {	    \
@@ -235,18 +236,25 @@
     }
 
-#define psImageOverlayLoopMask(DATATYPE) {		    \
-      for (int row=y0;row<imageRowLimit;row++) {	    \
-	ps##DATATYPE* imageRow = image->data.DATATYPE[row];	   \
-	ps##DATATYPE* overlayRow = overlay->data.DATATYPE[row-y0]; \
-	for (int col=x0;col<imageColLimit;col++) {		   \
-	  if (!isfinite(imageRow[col])) {			   \
-	    imageRow[col] = overlayRow[col-x0];		   \
-	  }							   \
-	  else if (!isfinite(overlayRow[col-x0])) {		   \
-	    imageRow[col] = imageRow[col];			   \
-	  }							   \
-	  else {						   \
-	    imageRow[col] &= overlayRow[col-x0];		   \
-	  }								\
+#define psImageOverlayLoopCleanInt(DATATYPE,OP) {			\
+      for (int row=y0;row<imageRowLimit;row++) {			\
+	ps##DATATYPE* imageRow = image->data.DATATYPE[row];		\
+	ps##DATATYPE* overlayRow = overlay->data.DATATYPE[row-y0];	\
+	for (int col=x0;col<imageColLimit;col++) {			\
+	  imageRow[col] = overlayRow[col-x0];				\
+	}								\
+      }									\
+      pixelsOverlaid += (imageRowLimit - y0) * (imageColLimit - x0);	\
+    }
+
+    // test for int type (but compiler does not allow int type to go to isfinit)
+    //	bool isFloatType = ((PS_TYPE_##DATATYPE == PS_TYPE_F32) || (PS_TYPE_##DATATYPE == PS_TYPE_F64)); 
+
+    // this function is only called for int type data, so we cannot test for isfinite
+#define psImageOverlayLoopMask(DATATYPE) {				\
+      for (int row=y0;row<imageRowLimit;row++) {			\
+	ps##DATATYPE* imageRow = image->data.DATATYPE[row];		\
+	ps##DATATYPE* overlayRow = overlay->data.DATATYPE[row-y0];	\
+	for (int col=x0;col<imageColLimit;col++) {			\
+	  imageRow[col] &= overlayRow[col-x0];				\
 	}								\
       }									\
@@ -328,4 +336,6 @@
     } \
     break;
+
+    // this function is only called for Int type data
     #define psImageOverlayCaseInt(DATATYPE,BADVALUE) \
 case PS_TYPE_##DATATYPE: \
@@ -341,5 +351,5 @@
         break; \
     case 'E': \
-      psImageOverlayLoopClean(DATATYPE,=); \
+      psImageOverlayLoopCleanInt(DATATYPE,=); \
       break;				   \
     case 'M':				   \
