Index: trunk/psLib/src/imageops/psImageConvolve.c
===================================================================
--- trunk/psLib/src/imageops/psImageConvolve.c	(revision 17806)
+++ trunk/psLib/src/imageops/psImageConvolve.c	(revision 17807)
@@ -7,6 +7,6 @@
 /// @author Eugene Magnier, IfA
 ///
-/// @version $Revision: 1.67 $ $Name: not supported by cvs2svn $
-/// @date $Date: 2008-05-17 01:38:20 $
+/// @version $Revision: 1.68 $ $Name: not supported by cvs2svn $
+/// @date $Date: 2008-05-24 22:23:14 $
 ///
 /// Copyright 2004-2007 Institute for Astronomy, University of Hawaii
@@ -795,8 +795,6 @@
     int numCols = mask->numCols;        // Number of columns
 
-    if (!out) {
-        // Propagate the non-masked values
-        out = (psImage*)psBinaryOp(NULL, (const psPtr)mask, "&", psScalarAlloc(~maskVal, PS_TYPE_MASK));
-    }
+    // Propagate the non-masked values
+    out = (psImage*)psBinaryOp(out, (const psPtr)mask, "&", psScalarAlloc(~setVal, PS_TYPE_MASK));
 
     if (!setVal) {
@@ -804,6 +802,10 @@
     }
 
+    psImage *conv = psImageAlloc(numCols, numRows, PS_TYPE_MASK); // Temporary convolved image
+    psImageInit(conv, 0);
+
     // Dereference mask images
     psMaskType **maskData = mask->data.PS_TYPE_MASK_DATA;
+    psMaskType **convData = conv->data.PS_TYPE_MASK_DATA;
     psMaskType **outData = out->data.PS_TYPE_MASK_DATA;
 
@@ -826,7 +828,5 @@
                 min = PS_MAX(0, min);
                 max = PS_MIN(numCols - 1, max);
-                for (int i = min; i < max; i++) {
-                    outData[y][i] |= setVal;
-                }
+                memset(&convData[y][min], 0xff, (max - min + 1) * PSELEMTYPE_SIZEOF(PS_TYPE_MASK));
             }
         }
@@ -836,5 +836,5 @@
         bool masking = false;           // Currently masking?
         for (int y = 0; y < numRows; y++) {
-            if (maskData[y][x] & maskVal) {
+            if (convData[y][x]) {
                 if (!masking) {
                     masking = true;
@@ -849,5 +849,5 @@
                 min = PS_MAX(0, min);
                 max = PS_MIN(numRows - 1, max);
-                for (int i = min; i < max; i++) {
+                for (int i = min; i <= max; i++) {
                     outData[i][x] |= setVal;
                 }
@@ -856,4 +856,6 @@
     }
 
+    psFree(conv);
+
     return out;
 }
