Index: trunk/psModules/src/imcombine/pmStack.c
===================================================================
--- trunk/psModules/src/imcombine/pmStack.c	(revision 19241)
+++ trunk/psModules/src/imcombine/pmStack.c	(revision 19243)
@@ -8,6 +8,6 @@
  *  @author GLG, MHPCC
  *
- *  @version $Revision: 1.35 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2008-08-27 22:31:03 $
+ *  @version $Revision: 1.36 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2008-08-28 00:12:12 $
  *  Copyright 2004-2007 Institute for Astronomy, University of Hawaii
  *
@@ -205,5 +205,6 @@
         return;
     }
-    data->inspect = psPixelsAdd(data->inspect, data->inspect->nalloc, x, y);
+    data->inspect = psPixelsAdd(data->inspect, data->inspect ? data->inspect->nalloc : PIXEL_LIST_BUFFER ,
+                                x, y);
     return;
 }
@@ -476,7 +477,9 @@
 // can be identified easily.
 static psArray *pixelMapGenerate(const psArray *input, // Data to stack
-                                 int numCols, int numRows // Size of (sky) images
+                                 int minCols, int maxCols, int minRows, int maxRows // Bounds of interest
     )
 {
+    int numCols = maxCols - minCols + 1, numRows = maxRows - minRows + 1; // Size of map
+
     psArray *map = psArrayAlloc(numRows); // The pixel map
     for (int y = 0; y < numRows; y++) {
@@ -492,7 +495,6 @@
         psPixels *pixels = data->reject; // The rejected pixels
         for (int j = 0; j < pixels->n; j++) {
-            int x = pixels->data[j].x, y = pixels->data[j].y; // Coordinates of interest
+            int x = pixels->data[j].x - minCols, y = pixels->data[j].y - minRows; // Coordinates of interest
             if (x < 0 || x >= numCols || y < 0 || y >= numRows) {
-                //                psWarning("Bad pixel coordinate: %d,%d --- ignored.", x, y);
                 continue;
             }
@@ -513,7 +515,12 @@
 // Query a "pixel map", by returning the list of image indices for a particular pixel.
 static psVector *pixelMapQuery(const psArray *map, // Pixel map
+                               int x0, int y0, // Offset into map
                                int x, int y // Coordinates of interest
     )
 {
+    // Adjust for offset
+    x -= x0;
+    y -= y0;
+
     assert(y >= 0 && y < map->n);
     psArray *colMap = map->data[y];     // Columns for that row
@@ -624,5 +631,6 @@
         psImage *combinedVariance = combined->weight; // Combined variance map
 
-        psArray *pixelMap = pixelMapGenerate(input, maxInputCols, maxInputRows); // Map of pixels to source
+        psArray *pixelMap = pixelMapGenerate(input, minInputCols, maxInputCols,
+                                             minInputRows, maxInputRows); // Map of pixels to source
         psPixels *pixels = NULL;            // Total list of pixels, with no duplicates
         for (int i = 0; i < num; i++) {
@@ -638,5 +646,6 @@
             for (int y = minInputRows; y < maxInputRows; y++) {
                 for (int x = minInputCols; x < maxInputCols; x++) {
-                    psVector *reject = pixelMapQuery(pixelMap, x, y); // Inspect these images closely
+                    psVector *reject = pixelMapQuery(pixelMap, minInputCols, minInputRows,
+                                                     x, y); // Reject these images
                     combinePixels(combinedImage, combinedMask, combinedVariance, input, weights, varFactors,
                                   reject, x, y, maskVal, bad, numIter, rej, useVariance, safe, buffer);
@@ -651,5 +660,6 @@
                     continue;
                 }
-                psVector *reject = pixelMapQuery(pixelMap, x, y); // Inspect these images closely
+                psVector *reject = pixelMapQuery(pixelMap, minInputCols, minInputRows,
+                                                 x, y); // Reject these images
                 combinePixels(combinedImage, combinedMask, combinedVariance, input, weights, varFactors,
                               reject, x, y, maskVal, bad, numIter, rej, useVariance, safe, buffer);
