Index: /trunk/psLib/src/image/psImage.c
===================================================================
--- /trunk/psLib/src/image/psImage.c	(revision 699)
+++ /trunk/psLib/src/image/psImage.c	(revision 700)
@@ -7,6 +7,6 @@
  *  @author Ross Harman, MHPCC
  *   
- *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-05-15 00:14:56 $
+ *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-05-15 02:10:27 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -65,20 +65,7 @@
 void psImageFree(psImage *image)
 {
-    int i = 0;
-    int nChildren = 0;
-    psImage **children = NULL;
-
-    if(image != NULL) {
-        nChildren = image->nChildren;
-        children = image->children;
-
-        for(i=0; i<nChildren; i++) {
-            psImageFree(children[i]);
-        }
-
-        psFree(image->data.v[0]);
-        psFree(image->data.v);
-
-    }
+    psImageFreeChildren(image);
+    psImageFreePixels(image);
+    psFree(image);
 }
 
@@ -91,6 +78,6 @@
     unsigned int inputColOffset;        // offset in bytes to first subset pixel in input row
 
-    if (image == NULL) {
-        psError(__func__,"Can not subset image because input image is NULL.");
+    if (image == NULL || image->data.v == NULL) {
+        psError(__func__,"Can not subset image because input image or its pixel buffer is NULL.");
         return NULL;
     }
@@ -139,2 +126,41 @@
     return (out);
 }
+
+void psImageFreePixels(psImage *restrict image)
+{
+    if (image == NULL || image->data.v == NULL) {
+        return;
+    }
+
+    psFree(image->data.v[0]);
+    psFree(image->data.v);
+    image->data.v = NULL;
+
+    // xxx - is this proper?
+    *(unsigned int*)&image->numRows = 0;
+    *(unsigned int*)&image->numCols = 0;
+}
+
+int psImageFreeChildren(psImage* image)
+{
+    int i = 0;
+    int nChildren = 0;
+    psImage **children = NULL;
+    int numFreed = 0;
+
+    if (image == NULL) {
+        return numFreed;
+    }
+
+    nChildren = image->nChildren;
+    children = image->children;
+
+    for(i=0; i<nChildren; i++) {
+        if (children[i] != NULL) {
+            numFreed++;
+            psImageFree(children[i]);
+        }
+    }
+
+    return numFreed;
+}
Index: /trunk/psLib/src/image/psImage.h
===================================================================
--- /trunk/psLib/src/image/psImage.h	(revision 699)
+++ /trunk/psLib/src/image/psImage.h	(revision 700)
@@ -7,6 +7,6 @@
  *  @author Ross Harman, MHPCC
  *   
- *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-05-14 22:39:58 $
+ *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-05-15 02:10:27 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -99,6 +99,4 @@
  *  Uses psLib memory deallocation functions to free an image and any existing children.
  *
- * @return psImage*: Pointer to psImage.
- *
  */
 void psImageFree(
@@ -106,3 +104,23 @@
 );
 
+/** Deallocate the image buffer of a psImage.
+ *
+ *  deallocates the image buffer while preserving the psImage struct and any children.
+ *
+ */
+void psImageFreePixels(
+    psImage *restrict image             ///< psImage to free pixel memory from
+);
+
+/** Frees all children of a psImage.
+ *
+ *  return int      Number of children freed.
+ *
+ */
+int psImageFreeChildren(
+    psImage* image                      ///< psImage in which all children shall be deallocated
+);
+
+
+
 #endif
Index: /trunk/psLib/src/mathtypes/psImage.c
===================================================================
--- /trunk/psLib/src/mathtypes/psImage.c	(revision 699)
+++ /trunk/psLib/src/mathtypes/psImage.c	(revision 700)
@@ -7,6 +7,6 @@
  *  @author Ross Harman, MHPCC
  *   
- *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-05-15 00:14:56 $
+ *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-05-15 02:10:27 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -65,20 +65,7 @@
 void psImageFree(psImage *image)
 {
-    int i = 0;
-    int nChildren = 0;
-    psImage **children = NULL;
-
-    if(image != NULL) {
-        nChildren = image->nChildren;
-        children = image->children;
-
-        for(i=0; i<nChildren; i++) {
-            psImageFree(children[i]);
-        }
-
-        psFree(image->data.v[0]);
-        psFree(image->data.v);
-
-    }
+    psImageFreeChildren(image);
+    psImageFreePixels(image);
+    psFree(image);
 }
 
@@ -91,6 +78,6 @@
     unsigned int inputColOffset;        // offset in bytes to first subset pixel in input row
 
-    if (image == NULL) {
-        psError(__func__,"Can not subset image because input image is NULL.");
+    if (image == NULL || image->data.v == NULL) {
+        psError(__func__,"Can not subset image because input image or its pixel buffer is NULL.");
         return NULL;
     }
@@ -139,2 +126,41 @@
     return (out);
 }
+
+void psImageFreePixels(psImage *restrict image)
+{
+    if (image == NULL || image->data.v == NULL) {
+        return;
+    }
+
+    psFree(image->data.v[0]);
+    psFree(image->data.v);
+    image->data.v = NULL;
+
+    // xxx - is this proper?
+    *(unsigned int*)&image->numRows = 0;
+    *(unsigned int*)&image->numCols = 0;
+}
+
+int psImageFreeChildren(psImage* image)
+{
+    int i = 0;
+    int nChildren = 0;
+    psImage **children = NULL;
+    int numFreed = 0;
+
+    if (image == NULL) {
+        return numFreed;
+    }
+
+    nChildren = image->nChildren;
+    children = image->children;
+
+    for(i=0; i<nChildren; i++) {
+        if (children[i] != NULL) {
+            numFreed++;
+            psImageFree(children[i]);
+        }
+    }
+
+    return numFreed;
+}
Index: /trunk/psLib/src/mathtypes/psImage.h
===================================================================
--- /trunk/psLib/src/mathtypes/psImage.h	(revision 699)
+++ /trunk/psLib/src/mathtypes/psImage.h	(revision 700)
@@ -7,6 +7,6 @@
  *  @author Ross Harman, MHPCC
  *   
- *  @version $Revision: 1.6 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-05-14 22:39:58 $
+ *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-05-15 02:10:27 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -99,6 +99,4 @@
  *  Uses psLib memory deallocation functions to free an image and any existing children.
  *
- * @return psImage*: Pointer to psImage.
- *
  */
 void psImageFree(
@@ -106,3 +104,23 @@
 );
 
+/** Deallocate the image buffer of a psImage.
+ *
+ *  deallocates the image buffer while preserving the psImage struct and any children.
+ *
+ */
+void psImageFreePixels(
+    psImage *restrict image             ///< psImage to free pixel memory from
+);
+
+/** Frees all children of a psImage.
+ *
+ *  return int      Number of children freed.
+ *
+ */
+int psImageFreeChildren(
+    psImage* image                      ///< psImage in which all children shall be deallocated
+);
+
+
+
 #endif
