Index: trunk/psLib/src/image/psImage.c
===================================================================
--- trunk/psLib/src/image/psImage.c	(revision 1605)
+++ trunk/psLib/src/image/psImage.c	(revision 1606)
@@ -10,6 +10,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.39 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-08-09 23:34:58 $
+ *  @version $Revision: 1.40 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-08-23 22:36:03 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -43,13 +43,6 @@
 {
     int area = 0;
-    int elementSize = PSELEMTYPE_SIZEOF(type);  // element
-
-    // size in
-    // bytes
-    int rowSize = numCols * elementSize;        // row
-
-    // size
-
-    // in bytes.
+    int elementSize = PSELEMTYPE_SIZEOF(type);  // element size in bytes
+    int rowSize = numCols * elementSize;        // row size in bytes.
 
     area = numCols * numRows;
@@ -71,12 +64,17 @@
     image->data.V = psAlloc(sizeof(void *) * numRows);
     if (image->data.V == NULL) {
+        psFree(image);
         psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);
     }
 
-    image->data.V[0] = psAlloc(area * elementSize);
-    if (image->data.V[0] == NULL) {
+    image->rawDataBuffer = psAlloc(area * elementSize);
+    if (image->rawDataBuffer == NULL) {
+        psFree(image);
+        psFree(image->data.V);
         psAbort(__func__, " : Line %d - Failed to allocate memory", __LINE__);
     }
 
+    // set the row pointers.
+    image->data.V[0] = image->rawDataBuffer;
     for (int i = 1; i < numRows; i++) {
         image->data.V[i] = (void *)((int8_t *) image->data.V[i - 1] + rowSize);
@@ -119,5 +117,5 @@
     psImageFreeChildren(image);
 
-    psFree(image->data.V[0]);
+    psFree(image->rawDataBuffer);
     psFree(image->data.V);
     image->data.V = NULL;
@@ -167,8 +165,9 @@
     }
     // Resize the image buffer
-    old->data.V[0] = psRealloc(old->data.V[0], numCols * numRows * elementSize);
+    old->rawDataBuffer = psRealloc(old->data.V[0], numCols * numRows * elementSize);
     old->data.V = (void **)psRealloc(old->data.V, numRows * sizeof(void *));
 
     // recreate the row pointers
+    old->data.V[0] = old->rawDataBuffer;
     for (int i = 1; i < numRows; i++) {
         old->data.V[i] = (void *)((int8_t *) old->data.V[i - 1] + rowSize);
Index: trunk/psLib/src/image/psImage.h
===================================================================
--- trunk/psLib/src/image/psImage.h	(revision 1605)
+++ trunk/psLib/src/image/psImage.h	(revision 1606)
@@ -12,6 +12,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-08-10 01:05:53 $
+ *  @version $Revision: 1.33 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-08-23 22:36:03 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -68,4 +68,6 @@
     int nChildren;                     ///< Number of subimages.
     struct psImage* *children;         ///< Children of this region.
+
+    void* rawDataBuffer;
 }
 psImage;
Index: trunk/psLib/src/image/psImageExtraction.c
===================================================================
--- trunk/psLib/src/image/psImageExtraction.c	(revision 1605)
+++ 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++); \
+            } \
         } \
     }
Index: trunk/psLib/src/image/psImageExtraction.h
===================================================================
--- trunk/psLib/src/image/psImageExtraction.h	(revision 1605)
+++ trunk/psLib/src/image/psImageExtraction.h	(revision 1606)
@@ -10,6 +10,6 @@
 *  @author Robert DeSonia, MHPCC
 *
-*  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
-*  @date $Date: 2004-08-09 23:40:55 $
+*  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
+*  @date $Date: 2004-08-23 22:36:03 $
 *
 *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -44,5 +44,4 @@
  */
 psImage* psImageSubset(
-    psImage* out,                      ///< image to recycle, or NULL.
     psImage* image,                    ///< Parent image.
     unsigned int numCols,              ///< Subimage width (<= image.nCols - col0).
@@ -50,4 +49,17 @@
     unsigned int col0,                 ///< Subimage col-offset (0 <= col0 < nCol).
     unsigned int row0                  ///< Subimage row-offset (0 <= row0 < nCol).
+);
+
+/** Create a subimage of the specified area.
+ *
+ * Uses psLib memory allocation functions to create an image based on a larger
+ * one.
+ *
+ * @return psImage* : Pointer to psImage.
+ *
+ */
+psImage* psImageSubsection(
+    psImage* image,                    ///< Parent image.
+    const char* section                ///< Subsection in the form '[x1:x2,y1:y2]'
 );
 
