Index: trunk/psModules/src/camera/pmFPAExtent.c
===================================================================
--- trunk/psModules/src/camera/pmFPAExtent.c	(revision 13496)
+++ trunk/psModules/src/camera/pmFPAExtent.c	(revision 13499)
@@ -10,29 +10,24 @@
     PS_ASSERT_PTR_NON_NULL(readout, NULL);
 
-    if (readout->image) {
-        return psRegionAlloc(readout->col0, readout->image->numCols,
-                             readout->row0, readout->image->numRows);
+    psImage *image = readout->image;    // Image from which to get dimensions
+    if (!image) {
+        image = readout->mask;
     }
-    pmCell *cell = readout->parent;     // The parent cell
-    if (!cell) {
-        psError(PS_ERR_UNEXPECTED_NULL, true, "Unable to determine size of readout.\n");
-        return NULL;
-    }
-    bool mdok;                          // Status of MD lookup
-    psRegion *trimsec = psMetadataLookupPtr(&mdok, cell->concepts, "CELL.TRIMSEC"); // Trim section
-    if (!mdok || !trimsec) {
-        psError(PS_ERR_UNKNOWN, true, "Unable to find CELL.TRIMSEC.\n");
-        return NULL;
+    if (!image) {
+        image = readout->weight;
     }
 
-    // XXX: Binning?
-    // XXX this is not setting the right value for megacam spliced chip
-    trimsec->x0 = 0;
-    trimsec->y0 = 0;
-    trimsec->x1 = 2112;
-    trimsec->y1 = 4644;
+    if (!image) {
+        // Don't have anything to base the true extent on, so have to give the largest possible extent
+        int xSize = psMetadataLookupS32(NULL, readout->parent->concepts, "CELL.XSIZE");
+        int ySize = psMetadataLookupS32(NULL, readout->parent->concepts, "CELL.YSIZE");
+        return psRegionAlloc(0, xSize, 0, ySize);
+    }
 
-    return psRegionAlloc(readout->col0, trimsec->x1 - trimsec->x0,
-                         readout->row0, trimsec->y1 - trimsec->y0);
+    // Get the offset to the CCD window
+    int xWindow = psMetadataLookupS32(NULL, readout->parent->concepts, "CELL.XWINDOW");
+    int yWindow = psMetadataLookupS32(NULL, readout->parent->concepts, "CELL.YWINDOW");
+    return psRegionAlloc(xWindow, xWindow + image->numCols,
+                         yWindow, yWindow + image->numRows);
 }
 
Index: trunk/psModules/src/camera/pmFPAMosaic.c
===================================================================
--- trunk/psModules/src/camera/pmFPAMosaic.c	(revision 13496)
+++ trunk/psModules/src/camera/pmFPAMosaic.c	(revision 13499)
@@ -16,4 +16,5 @@
 #include "pmConfig.h"
 #include "pmAstrometryWCS.h"
+#include "pmFPAExtent.h"
 
 #include "pmFPAMosaic.h"
@@ -1086,4 +1087,15 @@
     pmHDU *sourcePHU = pmHDUGetHighest(source->parent, source, NULL);
 
+    // Need to update NAXIS1, NAXIS2 in the target header, so that when we write a CMF, it has the correct
+    // extent.  I'm not convinced that this is the best way to do this, but it should be, at worst, harmless,
+    // since NAXIS[12] will get overwritten for an image with the proper dimensions.
+    psRegion *naxis = pmChipExtent(target);
+    psMetadataAddS32(targetHDU->header, PS_LIST_TAIL, "NAXIS1", PS_META_REPLACE, "Size in x",
+                     naxis->x1 - naxis->x0);
+    psMetadataAddS32(targetHDU->header, PS_LIST_TAIL, "NAXIS2", PS_META_REPLACE, "Size in y",
+                     naxis->y1 - naxis->y0);
+    psFree(naxis);
+
+
     if (!targetPHU) {
         psError(PS_ERR_UNKNOWN, true, "Unable to find HDU after mosaicking.\n");
