Index: trunk/psModules/src/imcombine/pmReadoutCombine.c
===================================================================
--- trunk/psModules/src/imcombine/pmReadoutCombine.c	(revision 7851)
+++ trunk/psModules/src/imcombine/pmReadoutCombine.c	(revision 7868)
@@ -5,6 +5,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2006-07-08 05:35:59 $
+ *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2006-07-12 03:30:53 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -176,23 +176,4 @@
     }
 
-    // Apply scale and zero
-    if (scale || zero) {
-        for (int i = 0; i < inputs->n; i++) {
-            pmReadout *readout = inputs->data[i]; // The particular readout
-            if (zero) {
-                psBinaryOp(readout->image, readout->image, "-",
-                           psScalarAlloc(zero->data.F32[i], PS_TYPE_F32));
-            }
-            if (scale) {
-                float scaleFactor = 1.0 / scale->data.F32[i]; // Scaling
-                psBinaryOp(readout->image, readout->image, "*", psScalarAlloc(scaleFactor, PS_TYPE_F32));
-                if (haveWeights) {
-                    psBinaryOp(readout->weight, readout->weight, "*",
-                               psScalarAlloc(scaleFactor * scaleFactor, PS_TYPE_F32));
-                }
-            }
-        }
-    }
-
     // Update the origin
     if (output->image) {
@@ -291,4 +272,6 @@
     psMaskType maskVal = params->maskVal; // The mask value
 
+    #ifndef PS_NO_TRACE
+
     psTrace(__func__, 3, "Iterating output: %d --> %d, %d --> %d\n",
             minInputCols - output->col0, maxInputCols - output->col0,
@@ -302,4 +285,5 @@
         }
     }
+    #endif
 
     // Dereference output products
@@ -311,4 +295,9 @@
     }
 
+    psVector *invScale = NULL;          // Inverse scale; pre-calculated for efficiency
+    if (scale) {
+        invScale = (psVector*)psBinaryOp(NULL, psScalarAlloc(1.0, PS_TYPE_F32), "/", (const psPtr)scale);
+    }
+
     for (int i = minInputRows; i < maxInputRows; i++) {
         int yOut = i - output->row0; // y position on output readout
@@ -329,13 +318,20 @@
                 int yIn = i - readout->row0; // y position on input readout
                 int xIn = j - readout->col0; // x position on input readout
-
                 psImage *image = readout->image; // The readout image
 
+                #if 0
+                // This should have been taken care of already:
                 // Check bounds
                 if (xIn < 0 || xIn >= image->numCols || yIn < 0 || yIn >= image->numRows) {
                     continue;
                 }
-
+                #endif
                 pixelsData[r] = image->data.F32[yIn][xIn];
+                if (zero) {
+                    pixelsData[r] -= zero->data.F32[r];
+                }
+                if (scale) {
+                    pixelsData[r] *= invScale->data.F32[r];
+                }
 
                 // Check mask
@@ -398,4 +394,5 @@
     psFree(weights);
     psFree(stats);
+    psFree(invScale);
 
     // Update the "concepts"
