Index: /trunk/psModules/src/imcombine/pmReadoutCombine.c
===================================================================
--- /trunk/psModules/src/imcombine/pmReadoutCombine.c	(revision 13765)
+++ /trunk/psModules/src/imcombine/pmReadoutCombine.c	(revision 13766)
@@ -104,4 +104,9 @@
     int xSize = 0, ySize = 0;           // The size of the output image
 
+    int xMin = INT_MAX;
+    int yMin = INT_MAX;
+    int xMax = 0;
+    int yMax = 0;
+
     bool valid = false;                 // Do we have a single valid input?
     for (long i = 0; i < inputs->n; i++) {
@@ -113,7 +118,5 @@
         }
 
-// XXX the use of trimsec here to judge the output size is inconsistent with the values of
-// minInputRows,etc below
-# if (0)
+	// use the trimsec to define the max full range of the output pixels
         pmCell *cell = readout->parent; // The parent cell
         bool mdok = true;       // Status of MD lookup
@@ -124,6 +127,9 @@
             xSize = PS_MAX(xSize, trimsec->x1 - trimsec->x0);
             ySize = PS_MAX(ySize, trimsec->y1 - trimsec->y0);
-        }
-# endif
+	    xMin  = PS_MIN(xMin,  trimsec->x0);
+	    xMax  = PS_MAX(xMax,  trimsec->x1);
+	    yMin  = PS_MIN(yMin,  trimsec->y0);
+	    yMax  = PS_MAX(yMax,  trimsec->y1);
+        }
 
         if (params->weights && !readout->weight) {
@@ -136,15 +142,11 @@
 
         // Range of pixels on output image
-        minInputRows = PS_MIN(minInputRows, readout->row0);
-        maxInputRows = PS_MAX(maxInputRows, readout->row0 + readout->image->numRows);
-        minInputCols = PS_MIN(minInputCols, readout->col0);
-        maxInputCols = PS_MAX(maxInputCols, readout->col0 + readout->image->numCols);
+        minInputRows = PS_MAX (xMin, PS_MIN(minInputRows, readout->row0));
+        maxInputRows = PS_MIN (xMax, PS_MAX(maxInputRows, readout->row0 + readout->image->numRows));
+        minInputCols = PS_MAX (yMin, PS_MIN(minInputCols, readout->col0));
+        maxInputCols = PS_MIN (yMax, PS_MAX(maxInputCols, readout->col0 + readout->image->numCols));
         psTrace("psModules.imcombine", 7, "Readout %ld: offset %d,%d; size %dx%d\n", i,
                 readout->col0, readout->row0, readout->image->numCols, readout->image->numRows);
     }
-
-    // full size of the output image
-    xSize = maxInputCols - minInputCols;
-    ySize = maxInputRows - minInputRows;
 
     if (!valid) {
