Index: trunk/psLib/src/image/psImageExtraction.c
===================================================================
--- trunk/psLib/src/image/psImageExtraction.c	(revision 1603)
+++ trunk/psLib/src/image/psImageExtraction.c	(revision 1606)
@@ -10,6 +10,6 @@
 *  @author Robert DeSonia, MHPCC
 *
-*  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-08-20 01:10:54 $
+*  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-08-23 22:36:03 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -23,6 +23,5 @@
 #include "psError.h"
 
-psImage* psImageSubset(psImage* out,
-                       psImage* image,
+psImage* psImageSubset(psImage* image,
                        unsigned int numCols,
                        unsigned int numRows,
@@ -30,20 +29,7 @@
                        unsigned int row0)
 {
-    unsigned int elementSize;   // size of image
-
-    // element in
-    // bytes
-    unsigned int outputRowSize; // output row
-
-    // size in bytes
-    unsigned int inputColOffset;        // offset
-
-    // in
-    // bytes
-    // to
-    // first
-    // subset
-
-    // pixel in input row
+    psImage* out;
+    unsigned int elementSize;          // size of image element in bytes
+    unsigned int inputColOffset;       // offset in bytes to first subset pixel in input row
 
     if (image == NULL || image->data.V == NULL) {
@@ -80,24 +66,29 @@
     elementSize = PSELEMTYPE_SIZEOF(image->type.type);
 
-    out = psImageRecycle(out, numCols, numRows, image->type.type);
-
-    // set the parent information into the child
-    // output image
-    *(int *)&out->row0 = row0;
-    *(int *)&out->col0 = col0;
-    *(psImage* *) & out->parent = (psImage* ) image;
+    out = psAlloc(sizeof(psImage));
+    *(psType*)&out->type = image->type;
+    *(unsigned int*)&out->numCols = numCols;
+    *(unsigned int*)&out->numRows = numRows;
+    *(int*)&out->row0 = row0;
+    *(int*)&out->col0 = col0;
+    out->parent = image;
+    out->nChildren = 0;
+    out->children = NULL;
+    out->rawDataBuffer = psMemIncrRefCounter(image->rawDataBuffer);
+    out->data.V = psAlloc(sizeof(void*)*numRows);
+
+    // set the new psImage's deallocator to the same as the input image
+    p_psMemSetDeallocator(out,p_psMemGetDeallocator(image));
+
+    inputColOffset = elementSize * col0;
+    for (int row = 0; row < numRows; row++) {
+        out->data.V[row] = image->data.U8[row0 + row] + inputColOffset;
+    }
 
     // add output image as a child of the input
     // image.
     image->nChildren++;
-    image->children = (psImage* *) psRealloc(image->children, image->nChildren * sizeof(psImage* ));
+    image->children = (psImage**) psRealloc(image->children, image->nChildren * sizeof(psImage* ));
     image->children[image->nChildren - 1] = out;
-
-    inputColOffset = elementSize * col0;
-    outputRowSize = elementSize * numCols;
-
-    for (int row = 0; row < numRows; row++) {
-        memcpy(out->data.V[row], image->data.U8[row0 + row] + inputColOffset, outputRowSize);
-    }
 
     return (out);
@@ -151,12 +142,18 @@
     // datatype.
     if (type == inDatatype) {
-        memcpy(output->data.V[0], input->data.V[0], elementSize * elements);
+        for (int row=0;row<numRows;row++) {
+            memcpy(output->data.V[row], input->data.V[row], elementSize * numCols);
+        }
         return output;
     }
     #define PSIMAGE_ELEMENT_COPY(IN,INTYPE,OUT,OUTTYPE,ELEMENTS) { \
-        ps##INTYPE *in = IN->data.INTYPE[0]; \
-        ps##OUTTYPE *out = OUT->data.OUTTYPE[0]; \
-        for (int e=0;e<ELEMENTS;e++) { \
-            *(out++) = *(in++); \
+        ps##INTYPE *in; \
+        ps##OUTTYPE *out; \
+        for(int row=0;row<numRows;row++) { \
+            in = IN->data.INTYPE[row]; \
+            out = OUT->data.OUTTYPE[row]; \
+            for (int col=0;col<numCols;col++) { \
+                *(out++) = *(in++); \
+            } \
         } \
     }
