Index: trunk/pstamp/src/ppstampMakeStamp.c
===================================================================
--- trunk/pstamp/src/ppstampMakeStamp.c	(revision 18851)
+++ trunk/pstamp/src/ppstampMakeStamp.c	(revision 18981)
@@ -101,5 +101,5 @@
 // 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 *extractStamp(psImage *image, psRegion region)
+psImage *extractStampOld(psImage *image, psRegion region)
 {
     int width  = region.x1 - region.x0;
@@ -168,4 +168,83 @@
     }
 
+
+    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;
+    int height = region.y1 - region.y0;
+
+    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);
+        return NULL;
+    }
+
+    psImage *output = psImageAlloc(width, height, image->type.type);
+    if (!output) {
+        psError(PS_ERR_UNKNOWN, false, "psImageAlloc failed\n");
+        return NULL;
+    }
+
+    if (!psImageInit(output, value)) {
+        psError(PS_ERR_UNKNOWN, false, "psInitImage failed\n");
+        return NULL;
+    }
+
+    psElemType  type = image->type.type;
+    psS32       elementSize =  PSELEMTYPE_SIZEOF(type);
+    int         copySize = copyWidth * elementSize;
+
+    int     dstY = 0;
+    psS32   skip = image->row0 - srcY;
+    if (skip > 0) {
+        dstY = skip;
+        height -= skip;
+        srcY = image->row0;
+    }
+    for ( ; dstY < height; srcY++, dstY++) {
+        if (srcY >= lastY) {
+            break;
+        }
+        psU8 *pdst = output->data.U8[dstY];
+
+        psU8 *psrc = image->data.U8[srcY]  + (srcX * elementSize);
+
+        // copy copyWidth pixels from srcX,srcY to dstX, dstY
+        pdst += dstX*elementSize;
+        memcpy(pdst, psrc, copySize);
+    }
 
     return output;
@@ -243,7 +322,7 @@
         }
 
-        outReadout->image = extractStamp(readout->image, extractRegion);
+        outReadout->image = extractStamp(readout->image, extractRegion,  0);
         if (!outReadout->image) {
-            psError(PS_ERR_UNKNOWN, false, "failed to allocate create postage stamp image\n");
+            psError(PS_ERR_UNKNOWN, false, "failed to create postage stamp image\n");
             status = false;
             break;
