Index: trunk/psphot/src/psphotFindDetections.c
===================================================================
--- trunk/psphot/src/psphotFindDetections.c	(revision 17396)
+++ trunk/psphot/src/psphotFindDetections.c	(revision 17444)
@@ -1,7 +1,5 @@
 # include "psphotInternal.h"
 
-// XXX let's make a better distinction between 'pass' (used for counting intput / output
-// entries) and needing/having a PSF.  In this function, we smooth the image, then search for
-// the peaks
+// smooth the image, search for peaks, optionally define footprints based on the peaks
 pmDetections *psphotFindDetections (pmDetections *detections, pmReadout *readout, psMetadata *recipe) {
 
@@ -27,48 +25,21 @@
 
     // move the old peaks array (if it exists) to oldPeaks 
+    // XXX generically, we should be able to call this function an arbitrary number of times
     assert (detections->oldPeaks == NULL);
     detections->oldPeaks = detections->peaks;
     detections->peaks = NULL;
 
-    // if footprints are not requested, find the peaks and return them
-    if (!useFootprints) {
-	detections->peaks = psphotFindPeaks (readout, recipe, useFootprints, pass, maskVal);
-	return detections;
+    // generate the smoothed significance image
+    psImage *significance = psphotSignificanceImage (readout, recipe, pass, maskVal);
+
+    // detect the peaks in the significance image
+    detections->peaks = psphotFindPeaks (significance, readout, recipe, pass, maskVal);
+
+    // optionally merge peaks into footprints
+    if (useFootprints) {
+	psphotFindFootprints (detections, significance, readout, recipe, pass, maskVal);
     }
 
-    // psphotFindPeaks returns a different set of objects if useFootprints is true!
-    // XXX fix this by splitting psphotFindPeaks into smooth / peaks / footprint stages?
-    psArray *footprints = psphotFindPeaks (readout, recipe, useFootprints, pass, maskVal);
-
-    int growRadius = 0;
-    if (pass == 1) {
-	growRadius = psMetadataLookupS32(NULL, recipe, "FOOTPRINT_GROW_RADIUS");
-    } else {
-	growRadius = psMetadataLookupS32(NULL, recipe, "FOOTPRINT_GROW_RADIUS_2");
-    }
-
-    if (growRadius > 0) {
-	psArray *tmp = pmGrowFootprintArray(footprints, growRadius);
-	psFree(footprints);
-	footprints = tmp;
-    }
-
-    if (pass == 2) {
-	// merge in old peaks;
-	const int includePeaks = 0x0 | 0x2; // i.e. just from newFootprints
-	
-	psLogMsg ("psphot", PS_LOG_INFO, "merging %ld new footprints into %ld existing ones\n", footprints->n, detections->footprints->n);
-	psArray *mergedFootprints = pmMergeFootprintArrays(detections->footprints, footprints, includePeaks);
-	psFree(footprints);
-	psFree(detections->footprints);
-	detections->footprints = mergedFootprints;
-    } else {
-	detections->footprints = footprints;
-    }
-
-    psphotCullPeaks(readout->image, readout->weight, recipe, detections->footprints);
-    detections->peaks = pmFootprintArrayToPeaks(detections->footprints);
-    psLogMsg ("psphot", PS_LOG_INFO, "%ld peaks, %ld total footprints: %f sec\n", detections->peaks->n, detections->footprints->n, psTimerMark ("psphot"));
-
+    psFree (significance);
     return detections;
 }
