Index: trunk/psLib/src/imageops/psImageMaskOps.c
===================================================================
--- trunk/psLib/src/imageops/psImageMaskOps.c	(revision 12431)
+++ trunk/psLib/src/imageops/psImageMaskOps.c	(revision 17457)
@@ -8,6 +8,6 @@
  *  @author David Robbins, MHPCC
  *
- *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-03-14 00:39:50 $
+ *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2008-04-21 18:16:58 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -44,49 +44,37 @@
         return;
     }
-    for (int j = 0; j < image->numRows; j++) {
-        for (int i = 0; i < image->numCols; i++) {
-            if ( (j + image->row0) >= region.y0 &&
-                    (j + image->row0) <= region.y1 &&
-                    (i + image->col0) >= region.x0 &&
-                    (i + image->col0) <= region.x1 ) {
-                if ( !strncmp(op, "&", 2) || !strncmp(op, "AND", 5) ) {
-                    image->data.PS_TYPE_MASK_DATA[j][i] &= maskValue;
-                } else if ( !strncmp(op, "|", 2) || !strncmp(op, "OR", 5) ) {
-                    image->data.PS_TYPE_MASK_DATA[j][i] |= maskValue;
-                } else if ( !strncmp(op, "=", 2) || !strncmp(op, "EQUAL", 5) ) {
-                    image->data.PS_TYPE_MASK_DATA[j][i] = maskValue;
-                } else if ( !strncmp(op, "^", 2) || !strncmp(op, "XOR", 5) ) {
-                    image->data.PS_TYPE_MASK_DATA[j][i] ^= maskValue;
-                } else {
-                    psError(PS_ERR_BAD_PARAMETER_VALUE,true,
-                            "The logical operation specified is incorrect\n");
-                    return;
-                }
-            }
-        }
-    }
-    /*
-        for (int iy = 0; iy < image->numRows; iy++) {
-            for (int ix = 0; ix < image->numCols; ix++) {
-                if (ix + image->col0 >=  region.x0)
-                    continue;
-                if (ix + image->col0 <= region.x1)
-                    continue;
-                if (iy + image->row0 >=  region.y0)
-                    continue;
-                if (iy + image->row0 <= region.y1)
-                    continue;
-                if ( !strncmp(op, "&", 2) || !strncmp(op, "AND", 5) ) {
-                    image->data.PS_TYPE_MASK_DATA[iy][ix] &= maskValue;
-                } else if ( !strncmp(op, "|", 2) || !strncmp(op, "OR", 5) ) {
-                    image->data.PS_TYPE_MASK_DATA[iy][ix] |= maskValue;
-                } else if ( !strncmp(op, "=", 2) || !strncmp(op, "EQUAL", 5) ) {
-                    image->data.PS_TYPE_MASK_DATA[iy][ix] = maskValue;
-                } else if ( !strncmp(op, "^", 2) || !strncmp(op, "XOR", 5) ) {
-                    image->data.PS_TYPE_MASK_DATA[iy][ix] ^= maskValue;
-                }
-            }
-        }
-    */
+
+
+# define MASK_IT(OP) \
+      for (int j = 0; j < image->numRows; j++) { \
+	if ((j + image->row0) < region.y0) continue; \
+	if ((j + image->row0) > region.y1) continue; /* is this correct (not >= ?) */ \
+	for (int i = 0; i < image->numCols; i++) { \
+	  if ((i + image->col0) < region.x0) continue; \
+	  if ((i + image->col0) > region.x1) continue; /* is this correct (not >= ?) */ \
+	  image->data.PS_TYPE_MASK_DATA[j][i] OP maskValue; \
+	} \
+      }
+
+    if ( !strncmp(op, "&", 2) || !strncmp(op, "AND", 5) ) {
+      MASK_IT (&=);
+      return;
+    }
+    if ( !strncmp(op, "|", 2) || !strncmp(op, "OR", 5) ) {
+      MASK_IT (|=);
+      return;
+    }
+    if ( !strncmp(op, "=", 2) || !strncmp(op, "EQUAL", 5) ) {
+      MASK_IT (=);
+      return;
+    }
+    if ( !strncmp(op, "^", 2) || !strncmp(op, "XOR", 5) ) {
+      MASK_IT (^=);
+      return;
+    }
+
+    psError(PS_ERR_BAD_PARAMETER_VALUE,true,
+	    "The logical operation specified is incorrect\n");
+    return;
 }
 
@@ -103,52 +91,35 @@
         return;
     }
-    for (int j = 0; j < image->numRows; j++) {
-        for (int i = 0; i < image->numCols; i++) {
-            if ( (j + image->row0) < region.y0 ||
-                    (j + image->row0) > region.y1 ||
-                    (i + image->col0) < region.x0 ||
-                    (i + image->col0) > region.x1 ) {
-                if ( !strncmp(op, "&", 2) || !strncmp(op, "AND", 5) ) {
-                    image->data.PS_TYPE_MASK_DATA[j][i] &= maskValue;
-                } else if ( !strncmp(op, "|", 2) || !strncmp(op, "OR", 5) ) {
-                    image->data.PS_TYPE_MASK_DATA[j][i] |= maskValue;
-                } else if ( !strncmp(op, "=", 2) || !strncmp(op, "EQUAL", 5) ) {
-                    image->data.PS_TYPE_MASK_DATA[j][i] = maskValue;
-                } else if ( !strncmp(op, "^", 2) || !strncmp(op, "XOR", 5) ) {
-                    image->data.PS_TYPE_MASK_DATA[j][i] ^= maskValue;
-                } else {
-                    psError(PS_ERR_BAD_PARAMETER_VALUE,true,
-                            "The logical operation specified is incorrect\n");
-                    return;
-                }
-            }
-        }
-    }
-    /*
-        for (int iy = 0; iy < image->numRows; iy++) {
-            for (int ix = 0; ix < image->numCols; ix++) {
-                if (ix + image->col0 <  region.x0)
-                    goto maskit;
-                if (ix + image->col0 > region.x1)
-                    goto maskit;
-                if (iy + image->row0 <  region.y0)
-                    goto maskit;
-                if (iy + image->row0 > region.y1)
-                    goto maskit;
-                continue;
-    maskit:
-                if ( !strncmp(op, "&", 2) || !strncmp(op, "AND", 5) ) {
-                    image->data.PS_TYPE_MASK_DATA[iy][ix] &= maskValue;
-                } else if ( !strncmp(op, "|", 2) || !strncmp(op, "OR", 5) ) {
-                    image->data.PS_TYPE_MASK_DATA[iy][ix] |= maskValue;
-                } else if ( !strncmp(op, "=", 2) || !strncmp(op, "EQUAL", 5) ) {
-                    image->data.PS_TYPE_MASK_DATA[iy][ix] = maskValue;
-                } else if ( !strncmp(op, "^", 2) || !strncmp(op, "XOR", 5) ) {
-                    image->data.PS_TYPE_MASK_DATA[iy][ix] ^= maskValue;
-                }
-            }Robert DeSonia, MHPCC
-    *  @author Ross Harman, MHPCC
-        }
-    */
+
+
+# define KEEP_IT(OP) \
+    for (int j = 0; j < image->numRows; j++) { \
+      for (int i = 0; i < image->numCols; i++) { \
+	if ((j + image->row0) < region.y0 || \
+	    (j + image->row0) > region.y1 || \
+	    (i + image->col0) < region.x0 || \
+	    (i + image->col0) > region.x1 ) { \
+	  image->data.PS_TYPE_MASK_DATA[j][i] OP maskValue; \
+	} } }
+
+    if ( !strncmp(op, "&", 2) || !strncmp(op, "AND", 5) ) {
+      KEEP_IT(&=);
+      return;
+    }
+    if ( !strncmp(op, "|", 2) || !strncmp(op, "OR", 5) ) {
+      KEEP_IT(|=);
+      return;
+    }
+    if ( !strncmp(op, "=", 2) || !strncmp(op, "EQUAL", 5) ) {
+      KEEP_IT(=);
+      return;
+    }
+    if ( !strncmp(op, "^", 2) || !strncmp(op, "XOR", 5) ) {
+      KEEP_IT(^=);
+      return;
+    }
+    psError(PS_ERR_BAD_PARAMETER_VALUE,true,
+	    "The logical operation specified is incorrect\n");
+    return;
 }
 
@@ -168,31 +139,38 @@
     }
 
-
     double dx, dy, r2, R2;
 
     R2 = PS_SQR(radius);
 
-    for (int iy = 0; iy < image->numRows; iy++) {
-        for (int ix = 0; ix < image->numCols; ix++) {
-            dx = ix + image->col0 - x;
-            dy = iy + image->row0 - y;
-            r2 = PS_SQR(dx) + PS_SQR(dy);
-            if (r2 <= R2) {
-                if ( !strncmp(op, "&", 2) || !strncmp(op, "AND", 5) ) {
-                    image->data.PS_TYPE_MASK_DATA[iy][ix] &= maskValue;
-                } else if ( !strncmp(op, "|", 2) || !strncmp(op, "OR", 5) ) {
-                    image->data.PS_TYPE_MASK_DATA[iy][ix] |= maskValue;
-                } else if ( !strncmp(op, "=", 2) || !strncmp(op, "EQUAL", 5) ) {
-                    image->data.PS_TYPE_MASK_DATA[iy][ix] = maskValue;
-                } else if ( !strncmp(op, "^", 2) || !strncmp(op, "XOR", 5) ) {
-                    image->data.PS_TYPE_MASK_DATA[iy][ix] ^= maskValue;
-                } else {
-                    psError(PS_ERR_BAD_PARAMETER_VALUE,true,
-                            "The logical operation specified is incorrect\n");
-                    return;
-                }
-            }
-        }
-    }
+# define MASK_IT_CIRCLE(OP) \
+    for (int iy = 0; iy < image->numRows; iy++) { \
+        for (int ix = 0; ix < image->numCols; ix++) { \
+            dx = ix + image->col0 - x; \
+            dy = iy + image->row0 - y; \
+            r2 = PS_SQR(dx) + PS_SQR(dy); \
+            if (r2 <= R2) { \
+	      image->data.PS_TYPE_MASK_DATA[iy][ix] OP maskValue; \
+            } } }
+
+    if ( !strncmp(op, "&", 2) || !strncmp(op, "AND", 5) ) {
+      MASK_IT_CIRCLE (&=);
+      return;
+    } 
+    if ( !strncmp(op, "|", 2) || !strncmp(op, "OR", 5) ) {
+      MASK_IT_CIRCLE (|=);
+      return;
+    } 
+    if ( !strncmp(op, "=", 2) || !strncmp(op, "EQUAL", 5) ) {
+      MASK_IT_CIRCLE (=);
+      return;
+    } 
+    if ( !strncmp(op, "^", 2) || !strncmp(op, "XOR", 5) ) {
+      MASK_IT_CIRCLE (^=);
+      return;
+    } 
+
+    psError(PS_ERR_BAD_PARAMETER_VALUE,true,
+	    "The logical operation specified is incorrect\n");
+    return;
 }
 
@@ -216,26 +194,34 @@
     R2 = PS_SQR(radius);
 
-    for (int iy = 0; iy < image->numRows; iy++) {
-        for (int ix = 0; ix < image->numCols; ix++) {
-            dx = ix + image->col0 - x;
-            dy = iy + image->row0 - y;
-            r2 = PS_SQR(dx) + PS_SQR(dy);
-            if (r2 > R2) {
-                if ( !strncmp(op, "&", 2) || !strncmp(op, "AND", 5) ) {
-                    image->data.PS_TYPE_MASK_DATA[iy][ix] &= maskValue;
-                } else if ( !strncmp(op, "|", 2) || !strncmp(op, "OR", 5) ) {
-                    image->data.PS_TYPE_MASK_DATA[iy][ix] |= maskValue;
-                } else if ( !strncmp(op, "=", 2) || !strncmp(op, "EQUAL", 5) ) {
-                    image->data.PS_TYPE_MASK_DATA[iy][ix] = maskValue;
-                } else if ( !strncmp(op, "^", 2) || !strncmp(op, "XOR", 5) ) {
-                    image->data.PS_TYPE_MASK_DATA[iy][ix] ^= maskValue;
-                } else {
-                    psError(PS_ERR_BAD_PARAMETER_VALUE,true,
-                            "The logical operation specified is incorrect\n");
-                    return;
-                }
-            }
-        }
-    }
+# define KEEP_IT_CIRCLE(OP) \
+    for (int iy = 0; iy < image->numRows; iy++) { \
+        for (int ix = 0; ix < image->numCols; ix++) { \
+            dx = ix + image->col0 - x; \
+            dy = iy + image->row0 - y; \
+            r2 = PS_SQR(dx) + PS_SQR(dy); \
+            if (r2 > R2) { \
+	      image->data.PS_TYPE_MASK_DATA[iy][ix] OP maskValue; \
+            } } }
+
+    if ( !strncmp(op, "&", 2) || !strncmp(op, "AND", 5) ) {
+      KEEP_IT_CIRCLE (&=);
+      return;
+    } 
+    if ( !strncmp(op, "|", 2) || !strncmp(op, "OR", 5) ) {
+      KEEP_IT_CIRCLE (|=);
+      return;
+    } 
+    if ( !strncmp(op, "=", 2) || !strncmp(op, "EQUAL", 5) ) {
+      KEEP_IT_CIRCLE (=);
+      return;
+    } 
+    if ( !strncmp(op, "^", 2) || !strncmp(op, "XOR", 5) ) {
+      KEEP_IT_CIRCLE (^=);
+      return;
+    } 
+
+    psError(PS_ERR_BAD_PARAMETER_VALUE,true,
+	    "The logical operation specified is incorrect\n");
+    return;
 }
 
