Index: /trunk/psLib/src/image/psImage.c
===================================================================
--- /trunk/psLib/src/image/psImage.c	(revision 718)
+++ /trunk/psLib/src/image/psImage.c	(revision 719)
@@ -7,6 +7,6 @@
  *  @author Ross Harman, MHPCC
  *   
- *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-05-18 18:39:43 $
+ *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-05-18 23:26:26 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -70,8 +70,43 @@
 }
 
+psImage* psImageRealloc(psImage* old,unsigned int numCols, unsigned int numRows, const psElemType type)
+{
+    int elementSize = PSELEMTYPE_SIZEOF(type); // element size in bytes
+    int rowSize = numCols*elementSize;  // row size in bytes.
+
+    if (old == NULL) {
+        old = psImageAlloc(numCols,numRows,type);
+        return old;
+    }
+
+    if (old->type.dimen != PS_DIMEN_IMAGE) {
+        psError(__func__,"Can not realloc image because image is not an image.");
+        return NULL;
+    }
+
+    /* image already the right size/type? */
+    if (numCols == old->numCols && numRows == old->numRows && type == old->type.type) {
+        return old;
+    }
+
+    // Resize the image buffer
+    old->data.v[0] = psRealloc(old->data.v[0],numCols * numRows * elementSize);
+    old->data.v = (void**) psRealloc(old->data.v,numRows * sizeof(void*));
+
+    // recreate the row pointers
+    for(int i = 1; i < numRows; i++) {
+        old->data.v[i] = (void*)((int8_t*)old->data.v[i-1]+rowSize);
+    }
+
+    *(unsigned int*)&old->numCols = numCols;
+    *(unsigned int*)&old->numRows = numRows;
+    *(psElemType*)&old->type.type = type;
+
+    return old;
+}
+
 psImage *psImageSubset(psImage *out,psImage *image,unsigned int numCols,
                        unsigned int numRows, unsigned int col0, unsigned int row0)
 {
-    psElemType type;
     unsigned int elementSize;           // size of image element in bytes
     unsigned int outputRowSize;         // output row size in bytes
@@ -88,22 +123,28 @@
     }
 
+    if (numCols < 1 || numRows < 1) {
+        psError(__func__,"Can not subset image because number of rows or columns are zero (%dx%d).",
+                numCols, numRows);
+        return NULL;
+    }
+
+    if (col0 >= image->numCols || row0 >= image->numRows) {
+        psError(__func__,"Can not subset image because col0,row0 (%d,%d) is not a valid pixel "
+                "location.", col0,row0);
+        return NULL;
+    }
+
     /* validate subimage size */
     if (col0+numCols >= image->numCols || row0+numRows >= image->numRows) {
         psError(__func__,"Can not subset image outside of image boundaries (size=%dx%d, "
-                "subset=[%d:%d,%d:%d]).",image->numCols,image->numRows,image->col0,
-                image->col0+numCols, image->row0, image->row0+numRows);
-        return NULL;
-    }
-
-    type = image->type.type;
-    elementSize = PSELEMTYPE_SIZEOF(type);
-
-    if (out == NULL) {
-        out = psImageAlloc(numCols,numRows,image->type.type);
-    } else if (out->numCols != numCols || out->numRows != numRows || out->type.type != type) {
-        // sizes/type different, can't reuse the given image buffer
-        psImageFree(out);
-        out = psImageAlloc(numCols,numRows,image->type.type);
-    }
+                "subset=[%d:%d,%d:%d]).",image->numCols,image->numRows,col0,
+                col0+numCols, row0, row0+numRows);
+        return NULL;
+    }
+
+
+    elementSize = PSELEMTYPE_SIZEOF(image->type.type);
+
+    out = psImageRealloc(out,numCols,numRows,image->type.type);
 
     // set the parent information into the child output image
@@ -199,14 +240,7 @@
     }
 
-
-    if (output == NULL) {
-        output = psImageAlloc(numCols,numRows,type);
-    } else if (output->numCols != numCols || output->numRows != numRows ||
-               output->type.type != type) {        // sizes/type different, can't reuse the given image buffer
-        psImageFree(output);
-        output = psImageAlloc(numCols,numRows,type);
-    }
-
-    // cover the trival case of copy of the same type.
+    output = psImageRealloc(output,numCols,numRows,type);
+
+    // cover the trival case of copy of the same datatype.
     if (type == inDatatype) {
         memcpy(output->data.v[0],input->data.v[0],elementSize*numRows*numCols);
Index: /trunk/psLib/src/image/psImage.h
===================================================================
--- /trunk/psLib/src/image/psImage.h	(revision 718)
+++ /trunk/psLib/src/image/psImage.h	(revision 719)
@@ -7,6 +7,6 @@
  *  @author Ross Harman, MHPCC
  *   
- *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-05-18 02:33:59 $
+ *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-05-18 23:26:26 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -138,3 +138,15 @@
 );
 
+/** Resize a given image to the given size/type.
+ *
+ *  return psImage* Resized psImage.
+ *
+ */
+psImage* psImageRealloc(
+    psImage* old,                   ///< the psImage to recycle by resizing image buffer
+    unsigned int numCols,           ///< the desired number of columns in image
+    unsigned int numRows,           ///< the desired number of rows in image
+    const psElemType type           ///< the desired datatype of the image
+);
+
 #endif
Index: /trunk/psLib/src/mathtypes/psImage.c
===================================================================
--- /trunk/psLib/src/mathtypes/psImage.c	(revision 718)
+++ /trunk/psLib/src/mathtypes/psImage.c	(revision 719)
@@ -7,6 +7,6 @@
  *  @author Ross Harman, MHPCC
  *   
- *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-05-18 18:39:43 $
+ *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-05-18 23:26:26 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -70,8 +70,43 @@
 }
 
+psImage* psImageRealloc(psImage* old,unsigned int numCols, unsigned int numRows, const psElemType type)
+{
+    int elementSize = PSELEMTYPE_SIZEOF(type); // element size in bytes
+    int rowSize = numCols*elementSize;  // row size in bytes.
+
+    if (old == NULL) {
+        old = psImageAlloc(numCols,numRows,type);
+        return old;
+    }
+
+    if (old->type.dimen != PS_DIMEN_IMAGE) {
+        psError(__func__,"Can not realloc image because image is not an image.");
+        return NULL;
+    }
+
+    /* image already the right size/type? */
+    if (numCols == old->numCols && numRows == old->numRows && type == old->type.type) {
+        return old;
+    }
+
+    // Resize the image buffer
+    old->data.v[0] = psRealloc(old->data.v[0],numCols * numRows * elementSize);
+    old->data.v = (void**) psRealloc(old->data.v,numRows * sizeof(void*));
+
+    // recreate the row pointers
+    for(int i = 1; i < numRows; i++) {
+        old->data.v[i] = (void*)((int8_t*)old->data.v[i-1]+rowSize);
+    }
+
+    *(unsigned int*)&old->numCols = numCols;
+    *(unsigned int*)&old->numRows = numRows;
+    *(psElemType*)&old->type.type = type;
+
+    return old;
+}
+
 psImage *psImageSubset(psImage *out,psImage *image,unsigned int numCols,
                        unsigned int numRows, unsigned int col0, unsigned int row0)
 {
-    psElemType type;
     unsigned int elementSize;           // size of image element in bytes
     unsigned int outputRowSize;         // output row size in bytes
@@ -88,22 +123,28 @@
     }
 
+    if (numCols < 1 || numRows < 1) {
+        psError(__func__,"Can not subset image because number of rows or columns are zero (%dx%d).",
+                numCols, numRows);
+        return NULL;
+    }
+
+    if (col0 >= image->numCols || row0 >= image->numRows) {
+        psError(__func__,"Can not subset image because col0,row0 (%d,%d) is not a valid pixel "
+                "location.", col0,row0);
+        return NULL;
+    }
+
     /* validate subimage size */
     if (col0+numCols >= image->numCols || row0+numRows >= image->numRows) {
         psError(__func__,"Can not subset image outside of image boundaries (size=%dx%d, "
-                "subset=[%d:%d,%d:%d]).",image->numCols,image->numRows,image->col0,
-                image->col0+numCols, image->row0, image->row0+numRows);
-        return NULL;
-    }
-
-    type = image->type.type;
-    elementSize = PSELEMTYPE_SIZEOF(type);
-
-    if (out == NULL) {
-        out = psImageAlloc(numCols,numRows,image->type.type);
-    } else if (out->numCols != numCols || out->numRows != numRows || out->type.type != type) {
-        // sizes/type different, can't reuse the given image buffer
-        psImageFree(out);
-        out = psImageAlloc(numCols,numRows,image->type.type);
-    }
+                "subset=[%d:%d,%d:%d]).",image->numCols,image->numRows,col0,
+                col0+numCols, row0, row0+numRows);
+        return NULL;
+    }
+
+
+    elementSize = PSELEMTYPE_SIZEOF(image->type.type);
+
+    out = psImageRealloc(out,numCols,numRows,image->type.type);
 
     // set the parent information into the child output image
@@ -199,14 +240,7 @@
     }
 
-
-    if (output == NULL) {
-        output = psImageAlloc(numCols,numRows,type);
-    } else if (output->numCols != numCols || output->numRows != numRows ||
-               output->type.type != type) {        // sizes/type different, can't reuse the given image buffer
-        psImageFree(output);
-        output = psImageAlloc(numCols,numRows,type);
-    }
-
-    // cover the trival case of copy of the same type.
+    output = psImageRealloc(output,numCols,numRows,type);
+
+    // cover the trival case of copy of the same datatype.
     if (type == inDatatype) {
         memcpy(output->data.v[0],input->data.v[0],elementSize*numRows*numCols);
Index: /trunk/psLib/src/mathtypes/psImage.h
===================================================================
--- /trunk/psLib/src/mathtypes/psImage.h	(revision 718)
+++ /trunk/psLib/src/mathtypes/psImage.h	(revision 719)
@@ -7,6 +7,6 @@
  *  @author Ross Harman, MHPCC
  *   
- *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-05-18 02:33:59 $
+ *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-05-18 23:26:26 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -138,3 +138,15 @@
 );
 
+/** Resize a given image to the given size/type.
+ *
+ *  return psImage* Resized psImage.
+ *
+ */
+psImage* psImageRealloc(
+    psImage* old,                   ///< the psImage to recycle by resizing image buffer
+    unsigned int numCols,           ///< the desired number of columns in image
+    unsigned int numRows,           ///< the desired number of rows in image
+    const psElemType type           ///< the desired datatype of the image
+);
+
 #endif
Index: unk/psLib/src/psLib.h
===================================================================
--- /trunk/psLib/src/psLib.h	(revision 718)
+++ 	(revision )
@@ -1,58 +1,0 @@
-/** @file  psLib.h
- *
- *  @brief Contains the complete list of header files for pslib.
- *
- *  This header file includes all the necessary header files for a user to
- *  user all public functions within the pslib library.
- *
- *  @author Eric Van Alst, MHPCC
- *   
- *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-05-15 00:17:31 $
- *
- *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
- */
-
-#ifndef PS_LIB_H
-#define PS_LIB_H
-
-/******************************************************************************/
-/*  INCLUDE FILES                                                             */
-/******************************************************************************/
-
-// System Utilities
-#include "psMemory.h"
-#include "psLogMsg.h"
-#include "psTrace.h"
-#include "psAbort.h"
-#include "psError.h"
-#include "psString.h"
-
-// Collections
-#include "psVector.h"
-#include "psImage.h"
-#include "psBitSet.h"
-#include "psSort.h"
-#include "psHash.h"
-
-// Data Manipulation
-#include "psStats.h"
-
-/******************************************************************************/
-/*  DEFINE STATEMENTS                                                         */
-/******************************************************************************/
-
-// None
-
-/******************************************************************************/
-/*  TYPE DEFINITIONS                                                          */
-/******************************************************************************/
-
-// None
-
-/*****************************************************************************/
-/* FUNCTION PROTOTYPES                                                       */
-/*****************************************************************************/
-
-#endif
-
