Index: /branches/eam_02_branch/psModules/src/objects/pmSource.c
===================================================================
--- /branches/eam_02_branch/psModules/src/objects/pmSource.c	(revision 13000)
+++ /branches/eam_02_branch/psModules/src/objects/pmSource.c	(revision 13001)
@@ -6,6 +6,6 @@
  *  @author EAM, IfA: significant modifications.
  *
- *  @version $Revision: 1.25.4.7 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2007-04-24 18:15:33 $
+ *  @version $Revision: 1.25.4.8 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2007-04-24 22:28:44 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -123,26 +123,29 @@
     // the original values.
     pmSource *source = pmSourceAlloc ();
-    source->peak = psMemIncrRefCounter (in->peak);
-    source->pixels = psMemIncrRefCounter (in->pixels);
-    source->weight = psMemIncrRefCounter (in->weight);
-    source->maskObj = psMemIncrRefCounter (in->maskObj);
-    source->maskView = psMemIncrRefCounter (in->maskView);
-    source->moments = psMemIncrRefCounter (in->moments);
-    source->blends = NULL;
-    source->modelPSF = NULL;
-    source->modelEXT = NULL;
-    source->modelFlux = NULL;
+
+    // this is actually the same peak as the original, is this the correct way to handle this?
+    source->peak = pmPeakAlloc (in->peak->x, in->peak->y, in->peak->value, in->peak->type);
+    source->peak->xf = in->peak->xf;
+    source->peak->yf = in->peak->yf;
+    source->peak->flux = in->peak->flux;
+    source->peak->SN = in->peak->SN;
+
+    // copy the values in the moments structure
+    source->moments  =  pmMomentsAlloc();
+    *source->moments = *in->moments;
+
+    // These images are all views to the parent.  
+    // We want a new view, but pointing at the same pixels.
+    source->pixels   = psImageCopyView (NULL, in->pixels);
+    source->weight   = psImageCopyView (NULL, in->weight);
+    source->maskView = psImageCopyView (NULL, in->maskView);
+
+    // the maskObj is a unique mask array; create a new mask image
+    if (in->maskObj) {
+	source->maskObj = psImageCopy (NULL, in->maskObj, PS_TYPE_MASK);
+    }
+
     source->type = in->type;
     source->mode = in->mode;
-    psMemSetDeallocator(source, (psFreeFunc) sourceFree);
-
-    // default values are NAN
-    source->psfMag = NAN;
-    source->extMag = NAN;
-    source->errMag = NAN;
-    source->apMag  = NAN;
-    source->sky    = NAN;
-    source->skyErr = NAN;
-    source->pixWeight = NAN;
 
     return(source);
@@ -213,9 +216,11 @@
         mySource->region   = newRegion;
 
-	// XXX how do we extend the mask?  do we need to keep the old masked pixels?
-	// the object mask is a copy, and used to define the source pixels
+	// re-copy the main mask pixels.  NOTE: the user will need to reset the object mask
+	// pixels (eg, with psImageKeepCircle)
 	mySource->maskObj = psImageCopy (mySource->maskObj, mySource->maskView, PS_TYPE_MASK);
 	
-	// XXX what about the modelFlux image?
+	// drop the old modelFlux pixels and force the user to re-create
+	psFree (mySource->modelFlux);
+	mySource->modelFlux = NULL;
     }
     return extend;
