Index: /trunk/psModules/src/pmReadoutCombine.c
===================================================================
--- /trunk/psModules/src/pmReadoutCombine.c	(revision 2275)
+++ /trunk/psModules/src/pmReadoutCombine.c	(revision 2276)
@@ -5,6 +5,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-11-04 02:02:10 $
+ *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-11-04 19:18:50 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -61,4 +61,6 @@
     int numInputCols = -1;
     int numInputRows = -1;
+    int minInputCols = HUGE;
+    int minInputRowss = HUGE;
     psListElem *tmpInput = NULL;
     int numInputs = 0;
@@ -68,8 +70,15 @@
     // We step through each readout in the input image list.  If any readout is
     // NULL, empty, or has the wrong type, we generate an error and return
-    // NULL.  If any readout is not the same size as any other image, we
-    // generate an error and return NULL.
+    // NULL.  We determine how big of an output image is needed to combine
+    // these input images.  We do this by taking the
+    //     max(readout->col0 + readout->numCols + image->col0 + image->numCols)
+    //     max(readout->row0 + readout->numRows + image->row0 + image->numRows)
+    // We then compare that to
+    //     output->col0 + output->numCols
+    //     output->row0 + output->numRows
+    // to determine if the output image actually stores that pixel.  A similar
+    // thing is done for the minimul row and column.
+    //
     tmpInput = (psListElem *) inputs->head;
-
     while (NULL != tmpInput) {
         tmpReadout = (psReadout *) tmpInput->data;
@@ -78,26 +87,19 @@
         PS_READOUT_CHECK_TYPE(tmpReadout, PS_TYPE_F32, output);
 
-        if (numInputCols == -1) {
-            // XXX        numInputCols = tmpReadout->image->numCols + OFFSET??;
-            numInputCols = tmpReadout->image->numCols;
-        }
-        if (numInputRows == -1) {
-            // XXX            numInputRows = tmpReadout->image->numRows + OFFSET;
-            numInputRows = tmpReadout->image->numRows;
-        }
-
-        // XXX
-        if (numInputCols != tmpReadout->image->numCols) {
-            psError(PS_ERR_UNKNOWN,true, "Image %d not same size as other input images (%d, %d)\n",
-                    tmpReadout->image->numRows, tmpReadout->image->numCols);
-            return(NULL);
-        }
-        // XXX
-        if (numInputRows != tmpReadout->image->numRows) {
-            psError(PS_ERR_UNKNOWN,true, "Image %d not same size as other input images (%d, %d)\n",
-                    tmpReadout->image->numRows, tmpReadout->image->numCols);
-            return(NULL);
-        }
-
+        minInputRows = PS_MIN(minInputRows,
+                              (tmpReadout->row0 + tmpReadout->image->row0));
+        tmpF = tmpReadout->col0 +
+               tmpReadout->numCols +
+               tmpReadout->image->col0 +
+               tmpReadout->image->numCols;
+        maxInputCols = PS_MAX(maxInputCols, tmpF);
+
+        minInputCols = PS_MIN(minInputCols,
+                              (tmpReadout->col0 + tmpReadout->image->col0));
+        tmpF = tmpReadout->row0 +
+               tmpReadout->numRows +
+               tmpReadout->image->row0 +
+               tmpReadout->image->numRows;
+        maxInputRows = PS_MAX(maxInputRows, tmpF);
         tmpInput = tmpInput->next;
         numInputs++;
@@ -105,7 +107,23 @@
 
     if (output == NULL) {
-        output = psImageAlloc(numInputCols, numInputRows, PS_TYPE_F32);
-    }
-
+        output = psImageAlloc(numInputCols-minInputCols,
+                              numInputRows-minInputRows, PS_TYPE_F32);
+        output->col0 = minInputCols;
+        output->row0 = minInputRows;
+    } else {
+        if (((output->col0 + output->numCols) < maxInputCols) ||
+                ((output->row0 + output->numRows) < maxInputRows)) {
+            psError(__func__, "Output image (%d, %d) is too small to hold combined images.\n",
+                    output->row0 + output->numRows,
+                    output->col0 + output->numCols);
+            return(NULL);
+        }
+
+        if ((output->col0 > minInputCols) ||
+                (output->row0 > minInputRows)) {
+            psError(__func__, "Output image offset is larger then input image offset.\n");
+            return(NULL);
+        }
+    }
 
     if (1 < p_psDetermineNumBits(params->stats->options)) {
@@ -127,8 +145,9 @@
     for (i = 0; i < output->numRows ; i++) {
         for (j = 0; j < output->numCols ; j++) {
+
             for (int r = 0; r < numInputs ; r++) {
-                //                if (i,j are valid for this readout) {
+                // if (i,j are valid for this readout) {
                 if (0) {
-                    //                    tmpPixels->data.F32[r] = WHATEVER;
+                    // tmpPixels->data.F32[r] = WHATEVER;
                     tmpPixelMask->data.U8[r] = 0;
                 } else {
