Index: trunk/psphot/src/psphot-utils.c
===================================================================
--- trunk/psphot/src/psphot-utils.c	(revision 4114)
+++ trunk/psphot/src/psphot-utils.c	(revision 4215)
@@ -160,4 +160,34 @@
 }
 
+// mask the area contained by the region
+void psImageMaskRegion (psImage *image, psRegion *region, int 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;
+	    image->data.U8[iy][ix] |= maskValue;
+	}
+    }
+}
+
+// mask the area not contained by the region
+void psImageKeepRegion (psImage *image, psRegion *region, int 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:
+	    image->data.U8[iy][ix] |= maskValue;
+	}
+    }
+}
+
 // create a subset of sources for the PS_SOURCE_PSFSTAR entries
 // XXX deprecated
