Index: trunk/pois/src/poisStamp.c
===================================================================
--- trunk/pois/src/poisStamp.c	(revision 3836)
+++ trunk/pois/src/poisStamp.c	(revision 5717)
@@ -11,5 +11,5 @@
     stamp->matrix = NULL;
     stamp->vector = NULL;
-    psMemSetDeallocator(stamp, (psFreeFcn)poisStampFree);
+    psMemSetDeallocator(stamp, (psFreeFunc)poisStampFree);
 
     return stamp;
@@ -18,5 +18,44 @@
 void poisStampFree(poisStamp *stamp)
 {
-    psFree(stamp->matrix);
-    psFree(stamp->vector);
+    if (stamp->matrix) {
+	psFree(stamp->matrix);
+    }
+    if (stamp->vector) {
+	psFree(stamp->vector);
+    }
+    psFree(stamp);
 }
+
+
+// Return true if the stamp is OK
+bool poisCheckStamp(const psImage *image, // Image to check for threshold
+		    const psImage *mask, // Mask to check for bad pixels
+		    int x, int y,	// Pixel coordinates
+		    const poisConfig *config // Configuration
+    )
+{
+    if (x < config->footprint + config->xKernel ||
+	y < config->footprint + config->yKernel ||
+	x > config->xImage - config->footprint - config->xKernel ||
+	y > config->yImage - config->footprint - config->yKernel ||
+	image->data.F32[y][x] < config->threshold) {
+	psTrace("pois.checkStamp", 9, "Rejecting stamp at %d,%d (border/threshold)\n", x, y);
+	return false;
+    }
+
+    // Check the footprint
+    bool ok = true;			// Is the footprint OK?
+    int footprint = config->footprint;	// Footprint size
+    for (int v = y - footprint; v <= y + footprint && ok; v++) {
+	for (int u = x - footprint; u <= x + footprint && ok; u++) {
+	    if (mask->data.U8[v][u] &
+		(POIS_MASK_BAD | POIS_MASK_NEAR_BAD | POIS_MASK_STAMP)) {
+		psTrace("pois.checkStamp", 9, "Rejecting stamp at %d,%d (bad footprint)\n", x, y);
+		ok = false;
+	    }
+	}
+    }
+    
+    return ok;
+}
+
