Index: trunk/pstamp/src/ppstampMakeStamp.c
===================================================================
--- trunk/pstamp/src/ppstampMakeStamp.c	(revision 25445)
+++ trunk/pstamp/src/ppstampMakeStamp.c	(revision 25446)
@@ -100,13 +100,15 @@
 // Extract pixels from an image. If part of the bounds of the region are
 // partially outside of the input those pixels are set to zero.
-psImage *extractStampOld(psImage *image, psRegion region)
-{
-    int width  = region.x1 - region.x0;
-    int height = region.y1 - region.y0;
+static psImage *extractStamp(psImage *image, psRegion region, double value)
+{
+    int width  = region.x1 - region.x0 + 0.5;
+    int height = region.y1 - region.y0 + 0.5;
 
     if (width < 0) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "negative width\n");
         return NULL;
     }
     if (height < 0) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "negative height\n");
         return NULL;
     }
@@ -132,79 +134,4 @@
 
     int copyWidth  = lastX - srcX;
-    int rightBlank = width - copyWidth - leftBlank;
-    if (copyWidth <= 0) {
-        return NULL;
-    }
-
-    psImage *output = psImageAlloc(width, height, image->type.type);
-
-    psElemType  type = image->type.type;
-    psS32       elementSize =  PSELEMTYPE_SIZEOF(type);
-    int         copySize = copyWidth * elementSize;
-
-    for (int dstY=0 ; dstY < height; srcY++, dstY++) {
-        psU8 *pdst = output->data.U8[dstY];
-
-        if ((srcY < image->row0) || (srcY >= lastY)) {
-            // zero the row
-            memset(pdst, 0, width*elementSize);
-        } else {
-            psU8 *psrc = image->data.U8[srcY]  + (srcX * elementSize);
-
-            if (leftBlank) {
-                memset(pdst, 0, leftBlank*elementSize);
-            }
-
-            // copy copyWidth pixels from srcX,srcY to dstX, dstY
-            pdst += dstX*elementSize;
-            memcpy(pdst, psrc, copySize);
-
-            if (rightBlank) {
-                pdst += copyWidth * elementSize;
-                memset(pdst, 0, rightBlank);
-            }
-        }
-    }
-
-
-    return output;
-}
-// Extract pixels from an image. If part of the bounds of the region are
-// partially outside of the input those pixels are set to zero.
-static psImage *extractStamp(psImage *image, psRegion region, double value)
-{
-    int width  = region.x1 - region.x0 + 0.5;
-    int height = region.y1 - region.y0 + 0.5;
-
-    if (width < 0) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "negative width\n");
-        return NULL;
-    }
-    if (height < 0) {
-        psError(PS_ERR_BAD_PARAMETER_VALUE, true, "negative height\n");
-        return NULL;
-    }
-
-    int srcX  = region.x0;
-    int srcY  = region.y0;
-    int lastX = region.x1;
-    int lastY = region.y1;
-    if (lastX > (image->col0 + image->numCols)) {
-        lastX = image->col0 + image->numCols;
-    }
-    if (lastY > (image->row0 + image->numRows)) {
-        lastY = image->row0 + image->numRows;
-    }
-
-    int leftBlank = 0;
-    int dstX  = 0;
-    if (srcX < image->col0) {
-        leftBlank = image->col0 - srcX;
-        dstX += leftBlank;
-        srcX = 0;
-    }
-
-    int copyWidth  = lastX - srcX;
-//    int rightBlank = width - copyWidth - leftBlank;
     if (copyWidth <= 0) {
         psError(PS_ERR_BAD_PARAMETER_VALUE, true, "copyWidth is invalid: %d\n", copyWidth);
@@ -231,5 +158,4 @@
     if (skip > 0) {
         dstY = skip;
-        height -= skip;
         srcY = image->row0;
     }
@@ -238,10 +164,9 @@
             break;
         }
-        psU8 *pdst = output->data.U8[dstY];
+        // copy copyWidth pixels from srcX,srcY to dstX, dstY
+        psU8 *pdst = output->data.U8[dstY] + (dstX * elementSize);
 
         psU8 *psrc = image->data.U8[srcY]  + (srcX * elementSize);
 
-        // copy copyWidth pixels from srcX,srcY to dstX, dstY
-        pdst += dstX*elementSize;
         memcpy(pdst, psrc, copySize);
     }
@@ -320,5 +245,5 @@
         }
 
-        outReadout->image = extractStamp(readout->image, extractRegion,  0);
+        outReadout->image = extractStamp(readout->image, extractRegion,  NAN);
         if (!outReadout->image) {
             psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp image\n");
@@ -327,5 +252,5 @@
         }
         if (readout->variance) {
-            outReadout->variance = extractStamp(readout->variance, extractRegion,  0);
+            outReadout->variance = extractStamp(readout->variance, extractRegion,  NAN);
             if (!outReadout->variance) {
                 psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp weight image\n");
