Index: /trunk/psLib/src/astro/psTime.c
===================================================================
--- /trunk/psLib/src/astro/psTime.c	(revision 5223)
+++ /trunk/psLib/src/astro/psTime.c	(revision 5224)
@@ -10,6 +10,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.73 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-10-04 01:31:40 $
+ *  @version $Revision: 1.74 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-10-05 03:51:41 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -1151,5 +1151,4 @@
         jd = time->sec / SEC_PER_DAY + time->nsec / NSEC_PER_DAY + JD_EPOCH_OFFSET;
     }
-
     return jd;
 }
@@ -1171,5 +1170,4 @@
         mjd = time->sec / SEC_PER_DAY + time->nsec / NSEC_PER_DAY + MJD_EPOCH_OFFSET;
     }
-
     return mjd;
 }
Index: /trunk/psLib/src/imageops/psImagePixelManip.c
===================================================================
--- /trunk/psLib/src/imageops/psImagePixelManip.c	(revision 5223)
+++ /trunk/psLib/src/imageops/psImagePixelManip.c	(revision 5224)
@@ -10,6 +10,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-09-16 23:56:48 $
+ *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-10-05 03:51:43 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -403,26 +403,49 @@
                        psMaskType maskValue)
 {
-
-    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.U8[iy][ix] &= maskValue;
-            } else if ( !strncmp(op, "|", 2) || !strncmp(op, "OR", 5) ) {
-                image->data.U8[iy][ix] |= maskValue;
-            } else if ( !strncmp(op, "=", 2) || !strncmp(op, "EQUAL", 5) ) {
-                image->data.U8[iy][ix] = maskValue;
-            } else if ( !strncmp(op, "^", 2) || !strncmp(op, "XOR", 5) ) {
-                image->data.U8[iy][ix] ^= maskValue;
+    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;
+                }
+            }
+        }
+    */
 }
 
@@ -434,28 +457,51 @@
                        psMaskType maskValue)
 {
-
-    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.U8[iy][ix] &= maskValue;
-            } else if ( !strncmp(op, "|", 2) || !strncmp(op, "OR", 5) ) {
-                image->data.U8[iy][ix] |= maskValue;
-            } else if ( !strncmp(op, "=", 2) || !strncmp(op, "EQUAL", 5) ) {
-                image->data.U8[iy][ix] = maskValue;
-            } else if ( !strncmp(op, "^", 2) || !strncmp(op, "XOR", 5) ) {
-                image->data.U8[iy][ix] ^= maskValue;
+    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;
+                }
+            }
+        }
+    */
 }
 
@@ -469,4 +515,10 @@
                        psMaskType maskValue)
 {
+    if (image == NULL) {
+        psError(PS_ERR_BAD_PARAMETER_NULL, true,
+                "Invalid image input.  Image is NULL.\n");
+        return;
+    }
+
 
     double dx, dy, r2, R2;
@@ -479,14 +531,18 @@
             dy = iy + image->row0 - y;
             r2 = PS_SQR(dx) + PS_SQR(dy);
-            if (r2 > R2)
-                continue;
-            if ( !strncmp(op, "&", 2) || !strncmp(op, "AND", 5) ) {
-                image->data.U8[iy][ix] &= maskValue;
-            } else if ( !strncmp(op, "|", 2) || !strncmp(op, "OR", 5) ) {
-                image->data.U8[iy][ix] |= maskValue;
-            } else if ( !strncmp(op, "=", 2) || !strncmp(op, "EQUAL", 5) ) {
-                image->data.U8[iy][ix] = maskValue;
-            } else if ( !strncmp(op, "^", 2) || !strncmp(op, "XOR", 5) ) {
-                image->data.U8[iy][ix] ^= maskValue;
+            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;
+                }
             }
         }
@@ -513,14 +569,18 @@
             dy = iy + image->row0 - y;
             r2 = PS_SQR(dx) + PS_SQR(dy);
-            if (r2 < R2)
-                continue;
-            if ( !strncmp(op, "&", 2) || !strncmp(op, "AND", 5) ) {
-                image->data.U8[iy][ix] &= maskValue;
-            } else if ( !strncmp(op, "|", 2) || !strncmp(op, "OR", 5) ) {
-                image->data.U8[iy][ix] |= maskValue;
-            } else if ( !strncmp(op, "=", 2) || !strncmp(op, "EQUAL", 5) ) {
-                image->data.U8[iy][ix] = maskValue;
-            } else if ( !strncmp(op, "^", 2) || !strncmp(op, "XOR", 5) ) {
-                image->data.U8[iy][ix] ^= maskValue;
+            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;
+                }
             }
         }
Index: /trunk/psLib/test/imageops/tst_psImagePixelManip.c
===================================================================
--- /trunk/psLib/test/imageops/tst_psImagePixelManip.c	(revision 5223)
+++ /trunk/psLib/test/imageops/tst_psImagePixelManip.c	(revision 5224)
@@ -6,6 +6,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2005-07-13 02:47:00 $
+ *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2005-10-05 03:51:43 $
  *
  *  Copyright 2004-2005 Maui High Performance Computing Center, University of Hawaii
@@ -29,4 +29,5 @@
 static psS32 testImageClipComplexRegion(void);
 static psS32 testImageOverlay(void);
+static psS32 testImageKeepMask(void);
 
 testDescription tests[] = {
@@ -35,4 +36,5 @@
                               {testImageClipComplexRegion,673,"psImageClipComplexRegion",0,false},
                               {testImageOverlay,573,"psImageOverlay",0,false},
+                              {testImageKeepMask,574,"psImageKeep and Mask",0,false},
                               {NULL}
                           };
@@ -796,2 +798,99 @@
     return 0;
 }
+
+psS32 testImageKeepMask(void)
+{
+    //psImageMaskRegion
+    //psImageKeepRegion
+    //psImageMaskCircle
+    //psImageKeepCircle
+    psImage *in = psImageAlloc(3,3,PS_TYPE_MASK);
+    psRegion reg;
+    reg.x0 = 0;
+    reg.x1 = 1;
+    reg.y0 = 0;
+    reg.y1 = 1;
+    psMaskType mask = 2;
+    in->data.PS_TYPE_MASK_DATA[0][0] = 2;
+    in->data.PS_TYPE_MASK_DATA[0][1] = 0;
+    in->data.PS_TYPE_MASK_DATA[0][2] = 1;
+    in->data.PS_TYPE_MASK_DATA[1][0] = 4;
+    in->data.PS_TYPE_MASK_DATA[1][1] = 0;
+    in->data.PS_TYPE_MASK_DATA[1][2] = 3;
+    in->data.PS_TYPE_MASK_DATA[2][0] = 2;
+    in->data.PS_TYPE_MASK_DATA[2][1] = 1;
+    in->data.PS_TYPE_MASK_DATA[2][2] = 2;
+
+    printf("\n Mask Region------");
+    psImageMaskRegion(in, reg, "|", mask);
+    for(int i = 0; i < 3; i++) {
+        for (int j = 0; j < 3; j++) {
+            printf("\nin->data.u8 [i][j] i=%d, j=%d = %u", i, j, in->data.PS_TYPE_MASK_DATA[i][j]);
+        }
+    }
+
+    in->data.PS_TYPE_MASK_DATA[0][0] = 2;
+    in->data.PS_TYPE_MASK_DATA[0][1] = 0;
+    in->data.PS_TYPE_MASK_DATA[0][2] = 1;
+    in->data.PS_TYPE_MASK_DATA[1][0] = 4;
+    in->data.PS_TYPE_MASK_DATA[1][1] = 0;
+    in->data.PS_TYPE_MASK_DATA[1][2] = 3;
+    in->data.PS_TYPE_MASK_DATA[2][0] = 2;
+    in->data.PS_TYPE_MASK_DATA[2][1] = 1;
+    in->data.PS_TYPE_MASK_DATA[2][2] = 2;
+    psImageKeepRegion(in, reg, "AND", mask);
+    printf("\n Keep Region------");
+    for(int i = 0; i < 3; i++) {
+        for (int j = 0; j < 3; j++) {
+            printf("\nin->data.u8 [i][j] i=%d, j=%d = %u", i, j, in->data.PS_TYPE_MASK_DATA[i][j]);
+        }
+    }
+
+    //Mask Circle and Keep Circle Functions
+    in->data.PS_TYPE_MASK_DATA[0][0] = 2;
+    in->data.PS_TYPE_MASK_DATA[0][1] = 0;
+    in->data.PS_TYPE_MASK_DATA[0][2] = 1;
+    in->data.PS_TYPE_MASK_DATA[1][0] = 4;
+    in->data.PS_TYPE_MASK_DATA[1][1] = 0;
+    in->data.PS_TYPE_MASK_DATA[1][2] = 3;
+    in->data.PS_TYPE_MASK_DATA[2][0] = 2;
+    in->data.PS_TYPE_MASK_DATA[2][1] = 1;
+    in->data.PS_TYPE_MASK_DATA[2][2] = 2;
+    psImageMaskCircle(in, 1, 1, 1, "XOR", mask);
+    printf("\n Mask Circle------");
+    for(int i = 0; i < 3; i++) {
+        for (int j = 0; j < 3; j++) {
+            printf("\nin->data.u8 [i][j] i=%d, j=%d = %u", i, j, in->data.PS_TYPE_MASK_DATA[i][j]);
+        }
+    }
+
+    in->data.PS_TYPE_MASK_DATA[0][0] = 2;
+    in->data.PS_TYPE_MASK_DATA[0][1] = 0;
+    in->data.PS_TYPE_MASK_DATA[0][2] = 1;
+    in->data.PS_TYPE_MASK_DATA[1][0] = 4;
+    in->data.PS_TYPE_MASK_DATA[1][1] = 0;
+    in->data.PS_TYPE_MASK_DATA[1][2] = 3;
+    in->data.PS_TYPE_MASK_DATA[2][0] = 2;
+    in->data.PS_TYPE_MASK_DATA[2][1] = 1;
+    in->data.PS_TYPE_MASK_DATA[2][2] = 2;
+    psImageKeepCircle(in, 1, 1, 1, "=", mask);
+    printf("\n Keep Circle------");
+    for(int i = 0; i < 3; i++) {
+        for (int j = 0; j < 3; j++) {
+            printf("\nin->data.u8 [i][j] i=%d, j=%d = %u", i, j, in->data.PS_TYPE_MASK_DATA[i][j]);
+        }
+    }
+    fflush(stdout);
+
+    //Error Checks
+    //incorrect logical operation
+    printf("\n");
+    psImageKeepRegion(in, reg, "+", mask);
+    //null image
+    psImage *none = NULL;
+    psImageMaskCircle(none, 1, 1, 1, "&", mask);
+
+    psFree(in);
+    return 0;
+}
+
Index: /trunk/psLib/test/imageops/verified/tst_psImagePixelManip.stderr
===================================================================
--- /trunk/psLib/test/imageops/verified/tst_psImagePixelManip.stderr	(revision 5223)
+++ /trunk/psLib/test/imageops/verified/tst_psImagePixelManip.stderr	(revision 5224)
@@ -147,2 +147,15 @@
 ---> TESTPOINT PASSED (psImage{psImageOverlay} | tst_psImagePixelManip.c)
 
+/***************************** TESTPOINT ******************************************\
+*             TestFile: tst_psImagePixelManip.c                                    *
+*            TestPoint: psImage{psImageKeep and Mask}                              *
+*             TestType: Positive                                                   *
+\**********************************************************************************/
+
+<DATE><TIME>|<HOST>|E|psImageKeepRegion (FILE:LINENO)
+    The logical operation specified is incorrect
+<DATE><TIME>|<HOST>|E|psImageMaskCircle (FILE:LINENO)
+    Invalid image input.  Image is NULL.
+
+---> TESTPOINT PASSED (psImage{psImageKeep and Mask} | tst_psImagePixelManip.c)
+
