Index: trunk/psModules/src/pmMaskBadPixels.c
===================================================================
--- trunk/psModules/src/pmMaskBadPixels.c	(revision 1822)
+++ trunk/psModules/src/pmMaskBadPixels.c	(revision 1832)
@@ -16,8 +16,9 @@
  * pixel on the mask. In the event that the mask image is too small (i.e., pixels on the input image refer to
  * pixels outside the range of the mask image), the function shall generate an error.
+ 
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-09-17 00:49:04 $
+ *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-09-20 20:36:46 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -40,4 +41,5 @@
     int jj = 0;
     int ii = 0;
+    int rRound = 0;
     int rowMin = 0;
     int rowMax = 0;
@@ -46,5 +48,5 @@
     int totOffCol = 0;
     int totOffRow = 0;
-    float r = 0.0;
+    float r = 0.0f;
     psElemType inType;
     psElemType maskType;
@@ -63,11 +65,11 @@
 
     inImage = in->image;
-    inMask = in->mask;
     if (inImage == NULL) {
         psError(__func__, " : Line %d - Null not allowed for input image", __LINE__);
         return false;
     } else if(inMask == NULL) {
-        inMask = psImageAlloc(inImage->numCols, inImage->numRows, PS_TYPE_MASK);
+        in->mask = psImageAlloc(inImage->numCols, inImage->numRows, PS_TYPE_MASK);
     }
+    inMask = in->mask;
 
     // Check input image and its mask are not larger than mask
@@ -135,34 +137,35 @@
     // Macro for all PS types
     #define PM_BAD_PIXELS(TYPE)                                                                              \
-case PS_TYPE_##TYPE:                                                                                 \
-    for(j=totOffRow; j<inImage->numRows; j++) {                                                      \
-        for(i=totOffCol; i<inImage->numCols; i++) {                                                  \
-            if(inImage->data.TYPE[j][i] > sat) {                                                     \
-                /* Pixels with flux greater than sat shall be masked */                              \
-                inMask->data.PS_TYPE_MASK_DATA[j][i] |= PM_MASK_SAT;                                 \
-            }                                                                                        \
-            if(mask->data.PS_TYPE_MASK_DATA[j][i] & maskVal) {                                       \
-                /* Pixels in mask which satisfy maskVal shall have their pixels masked in inMask */  \
-                inMask->data.PS_TYPE_MASK_DATA[j][i] |= mask->data.PS_TYPE_MASK_DATA[j][i]|maskVal;  \
-            }                                                                                        \
-            rowMin = MAX(j-grow, 0);                                                                 \
-            rowMax = MIN(j+grow, inImage->numRows-1);                                                \
-            colMin = MAX(i-grow, 0);                                                                 \
-            colMax = MIN(i+grow, inImage->numCols-1);                                                \
-            for(jj=rowMin; jj<rowMax; jj++) {                                                        \
-                for(ii=colMin; ii<colMax; ii++) {                                                    \
-                    if(mask->data.PS_TYPE_MASK_DATA[j][i] & growVal) {                               \
-                        r = sqrtf((ii-i)*(ii-i)+(jj-j)*(jj-j));                                      \
-                        if(r <= grow) {                                                              \
-                            /* Pixels in mask which satisfy growVal shall have their corresponding   \
-                            pixels,along with all pixels within the grow radius masked */            \
-                            inMask->data.PS_TYPE_MASK_DATA[j][i] |=                                  \
-                                    mask->data.PS_TYPE_MASK_DATA[j][i]&growVal;                          \
-                        }                                                                            \
-                    }                                                                                \
-                }                                                                                    \
-            }                                                                                        \
-        }                                                                                            \
-    }                                                                                                \
+case PS_TYPE_##TYPE:                                                                                         \
+    for(j=totOffRow; j<inImage->numRows; j++) {                                                              \
+        for(i=totOffCol; i<inImage->numCols; i++) {                                                          \
+            \
+            /* Pixels with flux greater than sat shall be masked */                                          \
+            if(inImage->data.TYPE[j][i] > sat) {                                                             \
+                inMask->data.PS_TYPE_MASK_DATA[j][i] |= PM_MASK_SAT;                                         \
+            }                                                                                                \
+            \
+            /* Pixels which satisfy maskVal shall be masked */                                               \
+            inMask->data.PS_TYPE_MASK_DATA[j][i] |= (mask->data.PS_TYPE_MASK_DATA[j][i]&maskVal);            \
+            \
+            /* Pixels which satisfy growVal and within the grow radius shall be masked */                    \
+            if(mask->data.PS_TYPE_MASK_DATA[j][i] & growVal) {                                               \
+                rowMin = MAX(j-grow, 0);                                                                     \
+                rowMax = MIN(j+grow+1, inImage->numRows);                                                    \
+                colMin = MAX(i-grow, 0);                                                                     \
+                colMax = MIN(i+grow+1, inImage->numCols);                                                    \
+                for(jj=rowMin; jj<rowMax; jj++) {                                                            \
+                    for(ii=colMin; ii<colMax; ii++) {                                                        \
+                        r = sqrtf((ii-i)*(ii-i)+(jj-j)*(jj-j));                                              \
+                        rRound = r + 0.5;                                                                    \
+                        if(rRound <= grow) {                                                                 \
+                            inMask->data.PS_TYPE_MASK_DATA[jj][ii] |=                                        \
+                                    (mask->data.PS_TYPE_MASK_DATA[j][i]&growVal);                            \
+                        }                                                                                    \
+                    }                                                                                        \
+                }                                                                                            \
+            }                                                                                                \
+        }                                                                                                    \
+    }                                                                                                        \
     break;
 
