Index: trunk/psLib/src/image/psImage.c
===================================================================
--- trunk/psLib/src/image/psImage.c	(revision 599)
+++ trunk/psLib/src/image/psImage.c	(revision 633)
@@ -7,6 +7,6 @@
  *  @author Ross Harman, MHPCC
  *   
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-05-07 02:56:52 $
+ *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-05-10 20:20:42 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -17,5 +17,7 @@
 /******************************************************************************/
 #include "psMemory.h"
+#include "psError.h"
 #include "psArray.h"
+#include "psImage.h"
 
 /******************************************************************************/
@@ -53,53 +55,103 @@
 /*****************************************************************************/
 
-psImage *psImageAlloc(int nx, int ny, psType type)
+psImage *psImageAlloc(int nCols, int nRows, psType type)
 {
     psImage *image = NULL;
 
-    psImage = psAlloc(psImage);
-    psImage->type = type;
-    psImage->nx = nx;
-    psImage->ny = ny;
-    psImage->x0 = 0;
-    psImage->y0 = 0;
-    psImage->parent = NULL;
-    psImage->nChildren = 0;
-    psImage->children = NULL;
+    image = psAlloc(sizeof(psImage));
+    image->type = type;
+    image->nCols = nCols;
+    image->nRows = nRows;
+    image->col0 = 0;
+    image->row0 = 0;
+    image->parent = NULL;
+    image->nChildren = 0;
+    image->children = NULL;
 
     switch(type.type) {
     case PS_TYPE_SHORT:
-        image->rows.rows_si = psAlloc(nx*ny*sizeof(short));
+        image->rows.rows_s = psAlloc(nCols*nRows*sizeof(short));
         break;
     case PS_TYPE_INT:
-        image->rows.rows_i = psAlloc(nx*ny*sizeof(int));
+        image->rows.rows_i = psAlloc(nCols*nRows*sizeof(int));
         break;
     case PS_TYPE_LONG:
-        image->rows.rows_li = psAlloc(nx*ny*sizeof(long));
+        image->rows.rows_l = psAlloc(nCols*nRows*sizeof(long));
         break;
     case PS_TYPE_USHORT:
-        image->rows.rows_us = psAlloc(nx*ny*sizeof(unsigned short));
+        image->rows.rows_us = psAlloc(nCols*nRows*sizeof(unsigned short));
         break;
     case PS_TYPE_UINT:
-        image->rows.rows_ui = psAlloc(nx*ny*sizeof(unsigned int));
+        image->rows.rows_ui = psAlloc(nCols*nRows*sizeof(unsigned int));
         break;
     case PS_TYPE_ULONG:
-        image->rows.rows_ul = psAlloc(nx*ny*sizeof(unsigned long));
+        image->rows.rows_ul = psAlloc(nCols*nRows*sizeof(unsigned long));
         break;
     case PS_TYPE_FLOAT:
-        image->rows.rows_f = psAlloc(nx*ny*sizeof(float));
+        image->rows.rows_f = psAlloc(nCols*nRows*sizeof(float));
         break;
     case PS_TYPE_DOUBLE:
-        image->rows.rows_d = psAlloc(nx*ny*sizeof(double));
+        image->rows.rows_d = psAlloc(nCols*nRows*sizeof(double));
         break;
     case PS_TYPE_COMPLEX:
-        image->rows.rows_cf = psAlloc(nx*ny*sizeof(complex float));
-        break;
-    case PS_TYPE_OTHER:
-        psError(__func__, " : Line %d - Invalid psBitMask binary operation: %s\n", __LINE__);
+        image->rows.rows_cf = psAlloc(nCols*nRows*sizeof(complex float));
         break;
     default:
-        psError(__func__, " : Line %d - Invalid psBitMask binary operation: %s\n", __LINE__);
+        psError(__func__, " : Line %d - Invalid psImage type: %d\n", __LINE__, type.type);
     }
 
+    return image;
+}
 
+void psImageFree(psImage *image)
+{
+    int i = 0;
+    int nChildren = 0;
+    psElemType imageType = 0;
+    psImage *children = NULL;
+
+    if(image != NULL) {
+        imageType = image->type.type;
+        nChildren = image->nChildren;
+        children = image->children;
+
+        switch(imageType) {
+        case PS_TYPE_SHORT:
+            psFree(image->rows.rows_s);
+            break;
+        case PS_TYPE_INT:
+            psFree(image->rows.rows_i);
+            break;
+        case PS_TYPE_LONG:
+            psFree(image->rows.rows_l);
+            break;
+        case PS_TYPE_USHORT:
+            psFree(image->rows.rows_us);
+            break;
+        case PS_TYPE_UINT:
+            psFree(image->rows.rows_ui);
+            break;
+        case PS_TYPE_ULONG:
+            psFree(image->rows.rows_ul);
+            break;
+        case PS_TYPE_FLOAT:
+            psFree(image->rows.rows_f);
+            break;
+        case PS_TYPE_DOUBLE:
+            psFree(image->rows.rows_d);
+            break;
+        case PS_TYPE_COMPLEX:
+            psFree(image->rows.rows_cf);
+            break;
+        case PS_TYPE_OTHER:
+            psError(__func__, " : Line %d - Can't delete images of type PS_TYPE_OTHER\n", __LINE__);
+            break;
+        default:
+            psError(__func__, " : Line %d - Invalid psImage type: %d\n", __LINE__, imageType);
+        }
+
+        for(i=0; i<nChildren; i++) {
+            psImageFree(children);
+        }
+    }
 }
