Index: trunk/psLib/src/image/psImage.c
===================================================================
--- trunk/psLib/src/image/psImage.c	(revision 634)
+++ trunk/psLib/src/image/psImage.c	(revision 649)
@@ -7,6 +7,6 @@
  *  @author Ross Harman, MHPCC
  *   
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-05-10 22:37:04 $
+ *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-05-12 19:46:52 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -57,47 +57,91 @@
 psImage *psImageAlloc(int nCols, int nRows, psType type)
 {
-    psImage *image = NULL;
-
-    image = psAlloc(sizeof(psImage));
-    image->type = type;
+    int area = 0;
+    psElemType imageType = 0;
+    psDimen imageDim = 0;
+
+    imageType = type.type;
+    imageDim =  type.dimen;
+    area = nCols*nRows;
+
+    if(imageDim != PS_DIMEN_IMAGE) {
+        psError(__func__, " : Line %d - Image dimensionality not PS_DIMEN_IMAGE=3 . Dimensionality: %d\n",
+                __LINE__, imageDim);
+        return NULL;
+    } else if(area <= 0) {
+        psError(__func__, " : Line %d - Invalid value for number of rows or columns. nRows: %d nCols: %d \n",
+                __LINE__, nRows, nCols);
+        return NULL;
+    }
+
+    psImage *image = (psImage *)psAlloc(sizeof(psImage));
+
+    switch (type.type) {
+    case PS_TYPE_CHAR:
+        image->rows.rows_c = (char **)psAlloc(ny*sizeof(char *));
+        image->rows.rows_c[0] = (char *)psAlloc(area*sizeof(char));
+        for(int i = 1; i < ny; i++) {
+            image->rows.rows_c[i] = &image->rows.rows_c[0][i*nx];
+        }
+        break;
+    case PS_TYPE_SHORT:
+        image->rows.rows_s = (short **)psAlloc(ny*sizeof(short *));
+        image->rows.rows_s[0] = (short *)psAlloc(area*sizeof(short));
+        for(int i = 1; i < ny; i++) {
+            image->rows.rows_s[i] = &image->rows.rows_s[0][i*nx];
+        }
+        break;
+    case PS_TYPE_INT:
+        image->rows.rows_i = (int **)psAlloc(ny*sizeof(int *));
+        image->rows.rows_i[0] = (int *)psAlloc(area*sizeof(int));
+        for(int i = 1; i < ny; i++) {
+            image->rows.rows_i[i] = &image->rows.rows_i[0][i*nx];
+        }
+        break;
+    case PS_TYPE_LONG:
+        image->rows.rows_l = (long **)psAlloc(ny*sizeof(long *));
+        image->rows.rows_l[0] = (long *)psAlloc(area*sizeof(long));
+        for(int i = 1; i < ny; i++) {
+            image->rows.rows_l[i] = &image->rows.rows_l[0][i*nx];
+        }
+        break;
+    case PS_TYPE_UCHAR:
+        image->rows.rows_uc = (unsigned char **)psAlloc(ny*sizeof(unsigned char *));
+        image->rows.rows_uc[0] = (unsigned char *)psAlloc(area*sizeof(unsigned char));
+        for(int i = 1; i < ny; i++) {
+            image->rows.rows_uc[i] = &image->rows.rows_uc[0][i*nx];
+        }
+        break;
+    case PS_TYPE_USHORT:
+        image->rows.rows_us = (unsigned short **)psAlloc(ny*sizeof(unsigned short *));
+        image->rows.rows_us[0] = (unsigned short *)psAlloc(area*sizeof(unsigned short));
+        for(int i = 1; i < ny; i++) {
+            image->rows.rows_us[i] = &image->rows.rows_us[0][i*nx];
+        }
+        break;
+    case PS_TYPE_UINT:
+        image->rows.rows_ui = (unsigned int **)psAlloc(ny*sizeof(unsigned int *));
+        image->rows.rows_ui[0] = (unsigned int *)psAlloc(area*sizeof(unsigned int));
+        for(int i = 1; i < ny; i++) {
+            image->rows.rows_ui[i] = &image->rows.rows_ui[0][i*nx];
+        }
+        break;
+    case PS_TYPE_ULONG:
+        image->rows.rows_ul = (unsigned long **)psAlloc(ny*sizeof(unsigned long *));
+        image->rows.rows_ul[0] = (unsigned long *)psAlloc(area*sizeof(unsigned long));
+        for(int i = 1; i < ny; i++) {
+            image->rows.rows_ul[i] = &image->rows.rows_ul[0][i*nx];
+        }
+        break;
+    }
+
+    image->cols0 = 0;
+    image->rows0 = 0;
     image->nCols = nCols;
     image->nRows = nRows;
-    image->col0 = 0;
-    image->row0 = 0;
+    image->type = type;
     image->parent = NULL;
     image->nChildren = 0;
     image->children = NULL;
-
-    switch(type.type) {
-    case PS_TYPE_SHORT:
-        image->rows.rows_s = psAlloc(nCols*nRows*sizeof(short));
-        break;
-    case PS_TYPE_INT:
-        image->rows.rows_i = psAlloc(nCols*nRows*sizeof(int));
-        break;
-    case PS_TYPE_LONG:
-        image->rows.rows_l = psAlloc(nCols*nRows*sizeof(long));
-        break;
-    case PS_TYPE_USHORT:
-        image->rows.rows_us = psAlloc(nCols*nRows*sizeof(unsigned short));
-        break;
-    case PS_TYPE_UINT:
-        image->rows.rows_ui = psAlloc(nCols*nRows*sizeof(unsigned int));
-        break;
-    case PS_TYPE_ULONG:
-        image->rows.rows_ul = psAlloc(nCols*nRows*sizeof(unsigned long));
-        break;
-    case PS_TYPE_FLOAT:
-        image->rows.rows_f = psAlloc(nCols*nRows*sizeof(float));
-        break;
-    case PS_TYPE_DOUBLE:
-        image->rows.rows_d = psAlloc(nCols*nRows*sizeof(double));
-        break;
-    case PS_TYPE_COMPLEX:
-        image->rows.rows_cf = psAlloc(nCols*nRows*sizeof(complex float));
-        break;
-    default:
-        psError(__func__, " : Line %d - Invalid psImage type: %d\n", __LINE__, type.type);
-    }
 
     return image;
