Index: /trunk/psLib/psLib.kdevses
===================================================================
--- /trunk/psLib/psLib.kdevses	(revision 1192)
+++ /trunk/psLib/psLib.kdevses	(revision 1193)
@@ -3,17 +3,17 @@
 <KDevPrjSession>
  <DocsAndViews NumberOfDocuments="3" >
-  <Doc0 NumberOfViews="1" URL="file:/home/desonia/psLib/src/collections/psList.h" >
-   <View0 line="19" Type="???" >
-    <AdditionalSettings Top="1" Width="1133" Attach="1" Height="832" Left="1" MinMaxMode="0" />
+  <Doc0 NumberOfViews="1" URL="file:/home/desonia/psLib/src/collections/psImage.c" >
+   <View0 line="446" Type="???" >
+    <AdditionalSettings Top="1" Width="1180" Attach="1" Height="652" Left="1" MinMaxMode="0" />
    </View0>
   </Doc0>
   <Doc1 NumberOfViews="1" URL="file:/home/desonia/psLib/src/collections/psList.c" >
-   <View0 line="480" Type="???" >
-    <AdditionalSettings Top="1" Width="1133" Attach="1" Height="832" Left="1" MinMaxMode="0" />
+   <View0 line="106" Type="???" >
+    <AdditionalSettings Top="1" Width="1180" Attach="1" Height="652" Left="1" MinMaxMode="0" />
    </View0>
   </Doc1>
   <Doc2 NumberOfViews="1" URL="file:/home/desonia/psLib/test/collections/tst_psList.c" >
-   <View0 line="969" Type="???" >
-    <AdditionalSettings Top="1" Width="1133" Attach="1" Height="832" Left="1" MinMaxMode="0" />
+   <View0 line="311" Type="???" >
+    <AdditionalSettings Top="1" Width="1180" Attach="1" Height="652" Left="1" MinMaxMode="0" />
    </View0>
   </Doc2>
Index: /trunk/psLib/src/collections/psList.c
===================================================================
--- /trunk/psLib/src/collections/psList.c	(revision 1192)
+++ /trunk/psLib/src/collections/psList.c	(revision 1193)
@@ -6,6 +6,6 @@
  *  @author Robert Daniel DeSonia, MHPCC
  *
- *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-06-29 23:19:11 $
+ *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-07-08 01:05:00 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -80,5 +80,5 @@
 }
 
-psList* psListAdd(psList *list, void *data, int where)
+bool psListAdd(psList *list, void *data, int where)
 {
     psListElem* position;
@@ -87,22 +87,23 @@
 
     if (list == NULL) {
-        return NULL;
+        return false;
     }
 
     if (data == NULL) {
-        return list;
-    }
-    elem = psAlloc(sizeof(psListElem));
-
-    pthread_mutex_lock(&list->lock)
-    ;
+        return false;
+    }
 
     if (where <= PS_LIST_UNKNOWN) {
         /// XXX What is the better way to communicate this failure to the caller?
         psLogMsg(__func__,PS_LOG_WARN,
-                 "The given insert location (%i) for psListAdd is invalid. Adding to head instead.",
+                 "The given insert location (%i) for psListAdd is invalid.",
                  where);
-        where = PS_LIST_HEAD; // given I can't tell caller about this, should just add it somewhere???
-    }
+        return false;
+    }
+
+    elem = psAlloc(sizeof(psListElem));
+
+    pthread_mutex_lock(&list->lock)
+    ;
 
     if (where > 0 && where > list->size) {
@@ -162,12 +163,5 @@
     ;
 
-    return list;
-}
-
-/*****************************************************************************/
-
-psList *psListAppend(psList *list, void *data)
-{
-    return psListAdd(list, data, PS_LIST_TAIL);
+    return true;
 }
 
@@ -452,5 +446,5 @@
     n = arr->n;
     for (int i = 0; i < n; i++) {
-        psListAppend(list,arr->data.PTR[i]);
+        psListAdd(list,arr->data.PTR[i],PS_LIST_TAIL);
     }
 
Index: /trunk/psLib/src/collections/psList.h
===================================================================
--- /trunk/psLib/src/collections/psList.h	(revision 1192)
+++ /trunk/psLib/src/collections/psList.h	(revision 1193)
@@ -10,6 +10,6 @@
  *  @ingroup LinkedList
  *
- *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-06-29 23:19:11 $
+ *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-07-08 01:05:00 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -81,18 +81,8 @@
  *                      NULL, the return value will also be NULL.
  */
-psList* psListAdd(
+bool psListAdd(
     psList* restrict list,              ///< list to add to (if NULL, nothing is done)
     void* data,                         ///< data item to add.  If NULL, list is not modified.
     int where                           ///< index, PS_LIST_HEAD, PS_LIST_TAIL, or numbered location.
-);
-
-/** Appends an item to a psList.
- *
- *  @return psList*     The psList with added data item.  If list parameter is
- *                      NULL, the return value will also be NULL.
- */
-psList* psListAppend(
-    psList* restrict list,              ///< list to append to (if NULL, nothing is done)
-    void *data                          ///< data item to add. If NULL, list is not modified.
 );
 
Index: /trunk/psLib/src/image/psImage.c
===================================================================
--- /trunk/psLib/src/image/psImage.c	(revision 1192)
+++ /trunk/psLib/src/image/psImage.c	(revision 1193)
@@ -9,6 +9,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-07-01 00:26:37 $
+ *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-07-08 01:05:00 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -261,4 +261,6 @@
 }
 
+
+
 psImage *psImageCopy(psImage* restrict output, const psImage *input,
                      psElemType type)
@@ -266,4 +268,5 @@
     psElemType inDatatype;
     int elementSize;
+    int elements;
     int numRows;
     int numCols;
@@ -288,4 +291,5 @@
     numRows = input->numRows;
     numCols = input->numCols;
+    elements = numRows*numCols;
     elementSize = PSELEMTYPE_SIZEOF(inDatatype);
 
@@ -299,1825 +303,98 @@
     // 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);
+        memcpy(output->data.V[0],input->data.V[0],elementSize*elements);
         return output;
     }
 
-    #define PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,INTYPE,OUTTYPE) \
-    { \
-        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[col] = (ps##OUTTYPE) in[col]; \
-            } \
+    #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++); \
         } \
     }
 
-    #define PSIMAGE_ELEMENT_ASSIGN(OUT,IN,OUTTYPE) \
-    switch (IN->type.type) { \
+    #define PSIMAGE_COPY_CASE(OUT,OUTTYPE) \
+    switch (inDatatype) { \
     case PS_TYPE_S8: \
-        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,S8,OUTTYPE); \
+        PSIMAGE_ELEMENT_COPY(input,S8,OUT,OUTTYPE,elements); \
         break; \
     case PS_TYPE_S16: \
-        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,S16,OUTTYPE); \
+        PSIMAGE_ELEMENT_COPY(input,S16,OUT,OUTTYPE,elements); \
         break; \
     case PS_TYPE_S32: \
-        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,S32,OUTTYPE); \
+        PSIMAGE_ELEMENT_COPY(input,S32,OUT,OUTTYPE,elements); \
         break; \
     case PS_TYPE_S64: \
-        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,S64,OUTTYPE); \
+        PSIMAGE_ELEMENT_COPY(input,S64,OUT,OUTTYPE,elements); \
         break; \
     case PS_TYPE_U8: \
-        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,U8,OUTTYPE); \
+        PSIMAGE_ELEMENT_COPY(input,U8,OUT,OUTTYPE,elements); \
         break; \
     case PS_TYPE_U16: \
-        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,U16,OUTTYPE); \
+        PSIMAGE_ELEMENT_COPY(input,U16,OUT,OUTTYPE,elements); \
         break; \
     case PS_TYPE_U32: \
-        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,U32,OUTTYPE); \
+        PSIMAGE_ELEMENT_COPY(input,U32,OUT,OUTTYPE,elements); \
         break; \
     case PS_TYPE_U64: \
-        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,U64,OUTTYPE); \
+        PSIMAGE_ELEMENT_COPY(input,U64,OUT,OUTTYPE,elements); \
         break; \
     case PS_TYPE_F32: \
-        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,F32,OUTTYPE); \
+        PSIMAGE_ELEMENT_COPY(input,F32,OUT,OUTTYPE,elements); \
         break; \
     case PS_TYPE_F64: \
-        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,F64,OUTTYPE); \
+        PSIMAGE_ELEMENT_COPY(input,F64,OUT,OUTTYPE,elements); \
         break; \
     case PS_TYPE_C32: \
-        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,C32,OUTTYPE); \
-        break; \
-    case PS_TYPE_PTR: \
-        psError(__func__,"Can't copy image from a matrix of pointers."); \
-        psFree(output); \
-        return NULL; \
+        PSIMAGE_ELEMENT_COPY(input,C32,OUT,OUTTYPE,elements); \
+        break; \
+    case PS_TYPE_C64: \
+        PSIMAGE_ELEMENT_COPY(input,C64,OUT,OUTTYPE,elements); \
+        break; \
     default: \
         break; \
     }
 
-    // XXX - GCC had problems with the length? of the above macro.  The original
-    // macro code here is commented out and the preprocessor output is pasted below it
-    // (effectively to the end of the function)
-    // We need to find out what is doing on here and move back to the macro version.
-    #if 0
-    switch (type)
-    {
-    case PS_TYPE_S8:
-        PSIMAGE_ELEMENT_ASSIGN(output,input,S8);
-        break;
-    case PS_TYPE_S16:
-        PSIMAGE_ELEMENT_ASSIGN(output,input,S16);
-        break;
-    case PS_TYPE_S32:
-        PSIMAGE_ELEMENT_ASSIGN(output,input,S32);
-        break;
-    case PS_TYPE_S64:
-        PSIMAGE_ELEMENT_ASSIGN(output,input,S64);
-        break;
-    case PS_TYPE_U8:
-        PSIMAGE_ELEMENT_ASSIGN(output,input,U8);
-    case PS_TYPE_U16:
-        PSIMAGE_ELEMENT_ASSIGN(output,input,U16);
-        break;
-    case PS_TYPE_U32:
-        PSIMAGE_ELEMENT_ASSIGN(output,input,U32);
-        break;
-    case PS_TYPE_U64:
-        PSIMAGE_ELEMENT_ASSIGN(output,input,U64);
-        break;
-    case PS_TYPE_F32:
-        PSIMAGE_ELEMENT_ASSIGN(output,input,F32);
-        break;
-    case PS_TYPE_F64:
-        PSIMAGE_ELEMENT_ASSIGN(output,input,F64);
-        break;
-    case PS_TYPE_C32:
-        PSIMAGE_ELEMENT_ASSIGN(output,input,C32);
-        break;
-    case PS_TYPE_C64:
-        PSIMAGE_ELEMENT_ASSIGN(output,input,C64);
-        break;
-    case PS_TYPE_PTR:
-        psError(__func__,"Can't copy image into a matrix of pointers.");
-        psFree(output);
-        return NULL;
-    }
-    #endif
-
-    #if 1
     switch (type) {
     case PS_TYPE_S8:
-        switch (input->type.type) {
-        case PS_TYPE_S8: {
-                psS8 *in;
-                psS8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S8[row];
-                    out = output->data.S8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S16: {
-                psS16 *in;
-                psS8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S16[row];
-                    out = output->data.S8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S32: {
-                psS32 *in;
-                psS8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S32[row];
-                    out = output->data.S8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S64: {
-                psS64 *in;
-                psS8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S64[row];
-                    out = output->data.S8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U8: {
-                psU8 *in;
-                psS8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U8[row];
-                    out = output->data.S8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U16: {
-                psU16 *in;
-                psS8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U16[row];
-                    out = output->data.S8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U32: {
-                psU32 *in;
-                psS8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U32[row];
-                    out = output->data.S8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U64: {
-                psU64 *in;
-                psS8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U64[row];
-                    out = output->data.S8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F32: {
-                psF32 *in;
-                psS8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F32[row];
-                    out = output->data.S8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F64: {
-                psF64 *in;
-                psS8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F64[row];
-                    out = output->data.S8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_C32: {
-                psC32 *in;
-                psS8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.C32[row];
-                    out = output->data.S8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_PTR:
-            psError (__func__, "Can't copy image from a matrix of pointers.");
-            psFree (output);
-            return ((void *) 0);
-        default:
-            break;
-        };
+        PSIMAGE_COPY_CASE(output,S8);
         break;
     case PS_TYPE_S16:
-        switch (input->type.type) {
-        case PS_TYPE_S8: {
-                psS8 *in;
-                psS16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S8[row];
-                    out = output->data.S16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S16: {
-                psS16 *in;
-                psS16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S16[row];
-                    out = output->data.S16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S32: {
-                psS32 *in;
-                psS16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S32[row];
-                    out = output->data.S16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S64: {
-                psS64 *in;
-                psS16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S64[row];
-                    out = output->data.S16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U8: {
-                psU8 *in;
-                psS16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U8[row];
-                    out = output->data.S16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U16: {
-                psU16 *in;
-                psS16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U16[row];
-                    out = output->data.S16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U32: {
-                psU32 *in;
-                psS16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U32[row];
-                    out = output->data.S16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U64: {
-                psU64 *in;
-                psS16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U64[row];
-                    out = output->data.S16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F32: {
-                psF32 *in;
-                psS16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F32[row];
-                    out = output->data.S16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F64: {
-                psF64 *in;
-                psS16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F64[row];
-                    out = output->data.S16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_C32: {
-                psC32 *in;
-                psS16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.C32[row];
-                    out = output->data.S16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_PTR:
-            psError (__func__, "Can't copy image from a matrix of pointers.");
-            psFree (output);
-            return ((void *) 0);
-        default:
-            break;
-        };
+        PSIMAGE_COPY_CASE(output,S16);
         break;
     case PS_TYPE_S32:
-        switch (input->type.type) {
-        case PS_TYPE_S8: {
-                psS8 *in;
-                psS32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S8[row];
-                    out = output->data.S32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S16: {
-                psS16 *in;
-                psS32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S16[row];
-                    out = output->data.S32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S32: {
-                psS32 *in;
-                psS32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S32[row];
-                    out = output->data.S32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S64: {
-                psS64 *in;
-                psS32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S64[row];
-                    out = output->data.S32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U8: {
-                psU8 *in;
-                psS32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U8[row];
-                    out = output->data.S32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U16: {
-                psU16 *in;
-                psS32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U16[row];
-                    out = output->data.S32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U32: {
-                psU32 *in;
-                psS32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U32[row];
-                    out = output->data.S32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U64: {
-                psU64 *in;
-                psS32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U64[row];
-                    out = output->data.S32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F32: {
-                psF32 *in;
-                psS32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F32[row];
-                    out = output->data.S32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F64: {
-                psF64 *in;
-                psS32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F64[row];
-                    out = output->data.S32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_C32: {
-                psC32 *in;
-                psS32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.C32[row];
-                    out = output->data.S32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_PTR:
-            psError (__func__, "Can't copy image from a matrix of pointers.");
-            psFree (output);
-            return ((void *) 0);
-        default:
-            break;
-        };
+        PSIMAGE_COPY_CASE(output,S32);
         break;
     case PS_TYPE_S64:
-        switch (input->type.type) {
-        case PS_TYPE_S8: {
-                psS8 *in;
-                psS64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S8[row];
-                    out = output->data.S64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S16: {
-                psS16 *in;
-                psS64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S16[row];
-                    out = output->data.S64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S32: {
-                psS32 *in;
-                psS64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S32[row];
-                    out = output->data.S64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S64: {
-                psS64 *in;
-                psS64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S64[row];
-                    out = output->data.S64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U8: {
-                psU8 *in;
-                psS64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U8[row];
-                    out = output->data.S64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U16: {
-                psU16 *in;
-                psS64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U16[row];
-                    out = output->data.S64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U32: {
-                psU32 *in;
-                psS64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U32[row];
-                    out = output->data.S64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U64: {
-                psU64 *in;
-                psS64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U64[row];
-                    out = output->data.S64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F32: {
-                psF32 *in;
-                psS64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F32[row];
-                    out = output->data.S64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F64: {
-                psF64 *in;
-                psS64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F64[row];
-                    out = output->data.S64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_C32: {
-                psC32 *in;
-                psS64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.C32[row];
-                    out = output->data.S64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_PTR:
-            psError (__func__, "Can't copy image from a matrix of pointers.");
-            psFree (output);
-            return ((void *) 0);
-        default:
-            break;
-        };
+        PSIMAGE_COPY_CASE(output,S64);
         break;
     case PS_TYPE_U8:
-        switch (input->type.type) {
-        case PS_TYPE_S8: {
-                psS8 *in;
-                psU8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S8[row];
-                    out = output->data.U8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S16: {
-                psS16 *in;
-                psU8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S16[row];
-                    out = output->data.U8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S32: {
-                psS32 *in;
-                psU8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S32[row];
-                    out = output->data.U8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S64: {
-                psS64 *in;
-                psU8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S64[row];
-                    out = output->data.U8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U8: {
-                psU8 *in;
-                psU8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U8[row];
-                    out = output->data.U8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U16: {
-                psU16 *in;
-                psU8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U16[row];
-                    out = output->data.U8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U32: {
-                psU32 *in;
-                psU8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U32[row];
-                    out = output->data.U8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U64: {
-                psU64 *in;
-                psU8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U64[row];
-                    out = output->data.U8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F32: {
-                psF32 *in;
-                psU8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F32[row];
-                    out = output->data.U8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F64: {
-                psF64 *in;
-                psU8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F64[row];
-                    out = output->data.U8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_C32: {
-                psC32 *in;
-                psU8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.C32[row];
-                    out = output->data.U8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_PTR:
-            psError (__func__, "Can't copy image from a matrix of pointers.");
-            psFree (output);
-            return ((void *) 0);
-        default:
-            break;
-        };
+        PSIMAGE_COPY_CASE(output,U8);
         break;
     case PS_TYPE_U16:
-        switch (input->type.type) {
-        case PS_TYPE_S8: {
-                psS8 *in;
-                psU16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S8[row];
-                    out = output->data.U16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S16: {
-                psS16 *in;
-                psU16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S16[row];
-                    out = output->data.U16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S32: {
-                psS32 *in;
-                psU16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S32[row];
-                    out = output->data.U16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S64: {
-                psS64 *in;
-                psU16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S64[row];
-                    out = output->data.U16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U8: {
-                psU8 *in;
-                psU16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U8[row];
-                    out = output->data.U16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U16: {
-                psU16 *in;
-                psU16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U16[row];
-                    out = output->data.U16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U32: {
-                psU32 *in;
-                psU16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U32[row];
-                    out = output->data.U16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U64: {
-                psU64 *in;
-                psU16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U64[row];
-                    out = output->data.U16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F32: {
-                psF32 *in;
-                psU16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F32[row];
-                    out = output->data.U16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F64: {
-                psF64 *in;
-                psU16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F64[row];
-                    out = output->data.U16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_C32: {
-                psC32 *in;
-                psU16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.C32[row];
-                    out = output->data.U16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_PTR:
-            psError (__func__, "Can't copy image from a matrix of pointers.");
-            psFree (output);
-            return ((void *) 0);
-        default:
-            break;
-        };
+        PSIMAGE_COPY_CASE(output,U16);
         break;
     case PS_TYPE_U32:
-        switch (input->type.type) {
-        case PS_TYPE_S8: {
-                psS8 *in;
-                psU32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S8[row];
-                    out = output->data.U32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S16: {
-                psS16 *in;
-                psU32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S16[row];
-                    out = output->data.U32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S32: {
-                psS32 *in;
-                psU32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S32[row];
-                    out = output->data.U32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S64: {
-                psS64 *in;
-                psU32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S64[row];
-                    out = output->data.U32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U8: {
-                psU8 *in;
-                psU32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U8[row];
-                    out = output->data.U32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U16: {
-                psU16 *in;
-                psU32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U16[row];
-                    out = output->data.U32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U32: {
-                psU32 *in;
-                psU32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U32[row];
-                    out = output->data.U32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U64: {
-                psU64 *in;
-                psU32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U64[row];
-                    out = output->data.U32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F32: {
-                psF32 *in;
-                psU32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F32[row];
-                    out = output->data.U32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F64: {
-                psF64 *in;
-                psU32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F64[row];
-                    out = output->data.U32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_C32: {
-                psC32 *in;
-                psU32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.C32[row];
-                    out = output->data.U32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_PTR:
-            psError (__func__, "Can't copy image from a matrix of pointers.");
-            psFree (output);
-            return ((void *) 0);
-        default:
-            break;
-        };
+        PSIMAGE_COPY_CASE(output,U32);
         break;
     case PS_TYPE_U64:
-        switch (input->type.type) {
-        case PS_TYPE_S8: {
-                psS8 *in;
-                psU64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S8[row];
-                    out = output->data.U64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S16: {
-                psS16 *in;
-                psU64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S16[row];
-                    out = output->data.U64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S32: {
-                psS32 *in;
-                psU64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S32[row];
-                    out = output->data.U64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S64: {
-                psS64 *in;
-                psU64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S64[row];
-                    out = output->data.U64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U8: {
-                psU8 *in;
-                psU64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U8[row];
-                    out = output->data.U64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U16: {
-                psU16 *in;
-                psU64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U16[row];
-                    out = output->data.U64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U32: {
-                psU32 *in;
-                psU64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U32[row];
-                    out = output->data.U64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U64: {
-                psU64 *in;
-                psU64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U64[row];
-                    out = output->data.U64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F32: {
-                psF32 *in;
-                psU64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F32[row];
-                    out = output->data.U64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F64: {
-                psF64 *in;
-                psU64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F64[row];
-                    out = output->data.U64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_C32: {
-                psC32 *in;
-                psU64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.C32[row];
-                    out = output->data.U64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_PTR:
-            psError (__func__, "Can't copy image from a matrix of pointers.");
-            psFree (output);
-            return ((void *) 0);
-        default:
-            break;
-        };
+        PSIMAGE_COPY_CASE(output,U64);
         break;
     case PS_TYPE_F32:
-        switch (input->type.type) {
-        case PS_TYPE_S8: {
-                psS8 *in;
-                psF32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S8[row];
-                    out = output->data.F32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S16: {
-                psS16 *in;
-                psF32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S16[row];
-                    out = output->data.F32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S32: {
-                psS32 *in;
-                psF32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S32[row];
-                    out = output->data.F32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S64: {
-                psS64 *in;
-                psF32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S64[row];
-                    out = output->data.F32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U8: {
-                psU8 *in;
-                psF32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U8[row];
-                    out = output->data.F32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U16: {
-                psU16 *in;
-                psF32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U16[row];
-                    out = output->data.F32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U32: {
-                psU32 *in;
-                psF32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U32[row];
-                    out = output->data.F32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U64: {
-                psU64 *in;
-                psF32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U64[row];
-                    out = output->data.F32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F32: {
-                psF32 *in;
-                psF32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F32[row];
-                    out = output->data.F32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F64: {
-                psF64 *in;
-                psF32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F64[row];
-                    out = output->data.F32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_C32: {
-                psC32 *in;
-                psF32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.C32[row];
-                    out = output->data.F32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_PTR:
-            psError (__func__, "Can't copy image from a matrix of pointers.");
-            psFree (output);
-            return ((void *) 0);
-        default:
-            break;
-        };
+        PSIMAGE_COPY_CASE(output,F32);
         break;
     case PS_TYPE_F64:
-        switch (input->type.type) {
-        case PS_TYPE_S8: {
-                psS8 *in;
-                psF64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S8[row];
-                    out = output->data.F64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S16: {
-                psS16 *in;
-                psF64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S16[row];
-                    out = output->data.F64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S32: {
-                psS32 *in;
-                psF64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S32[row];
-                    out = output->data.F64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S64: {
-                psS64 *in;
-                psF64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S64[row];
-                    out = output->data.F64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U8: {
-                psU8 *in;
-                psF64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U8[row];
-                    out = output->data.F64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U16: {
-                psU16 *in;
-                psF64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U16[row];
-                    out = output->data.F64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U32: {
-                psU32 *in;
-                psF64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U32[row];
-                    out = output->data.F64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U64: {
-                psU64 *in;
-                psF64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U64[row];
-                    out = output->data.F64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F32: {
-                psF32 *in;
-                psF64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F32[row];
-                    out = output->data.F64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F64: {
-                psF64 *in;
-                psF64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F64[row];
-                    out = output->data.F64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_C32: {
-                psC32 *in;
-                psF64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.C32[row];
-                    out = output->data.F64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_PTR:
-            psError (__func__, "Can't copy image from a matrix of pointers.");
-            psFree (output);
-            return ((void *) 0);
-        default:
-            break;
-        };
+        PSIMAGE_COPY_CASE(output,F64);
         break;
     case PS_TYPE_C32:
-        switch (input->type.type) {
-        case PS_TYPE_S8: {
-                psS8 *in;
-                psC32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S8[row];
-                    out = output->data.C32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S16: {
-                psS16 *in;
-                psC32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S16[row];
-                    out = output->data.C32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S32: {
-                psS32 *in;
-                psC32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S32[row];
-                    out = output->data.C32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S64: {
-                psS64 *in;
-                psC32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S64[row];
-                    out = output->data.C32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U8: {
-                psU8 *in;
-                psC32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U8[row];
-                    out = output->data.C32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U16: {
-                psU16 *in;
-                psC32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U16[row];
-                    out = output->data.C32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U32: {
-                psU32 *in;
-                psC32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U32[row];
-                    out = output->data.C32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U64: {
-                psU64 *in;
-                psC32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U64[row];
-                    out = output->data.C32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F32: {
-                psF32 *in;
-                psC32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F32[row];
-                    out = output->data.C32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F64: {
-                psF64 *in;
-                psC32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F64[row];
-                    out = output->data.C32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_C32: {
-                psC32 *in;
-                psC32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.C32[row];
-                    out = output->data.C32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_PTR:
-            psError (__func__, "Can't copy image from a matrix of pointers.");
-            psFree (output);
-            return ((void *) 0);
-        default:
-            break;
-        };
+        PSIMAGE_COPY_CASE(output,C32);
         break;
     case PS_TYPE_C64:
-        switch (input->type.type) {
-        case PS_TYPE_S8: {
-                psS8 *in;
-                psC64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S8[row];
-                    out = output->data.C64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S16: {
-                psS16 *in;
-                psC64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S16[row];
-                    out = output->data.C64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S32: {
-                psS32 *in;
-                psC64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S32[row];
-                    out = output->data.C64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S64: {
-                psS64 *in;
-                psC64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S64[row];
-                    out = output->data.C64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U8: {
-                psU8 *in;
-                psC64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U8[row];
-                    out = output->data.C64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U16: {
-                psU16 *in;
-                psC64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U16[row];
-                    out = output->data.C64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U32: {
-                psU32 *in;
-                psC64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U32[row];
-                    out = output->data.C64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U64: {
-                psU64 *in;
-                psC64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U64[row];
-                    out = output->data.C64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F32: {
-                psF32 *in;
-                psC64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F32[row];
-                    out = output->data.C64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F64: {
-                psF64 *in;
-                psC64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F64[row];
-                    out = output->data.C64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_C32: {
-                psC32 *in;
-                psC64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.C32[row];
-                    out = output->data.C64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_PTR:
-            psError (__func__, "Can't copy image from a matrix of pointers.");
-            psFree (output);
-            return ((void *) 0);
-        default:
-            break;
-        };
-        break;
-    case PS_TYPE_PTR:
-        psError (__func__, "Can't copy image into a matrix of pointers.");
-        psFree (output);
-        return ((void *) 0);
-    }
-
+        PSIMAGE_COPY_CASE(output,C64);
+        break;
+    default:
+        break;
+    }
     return output;
 }
@@ -2340,6 +617,4 @@
     }
 
-    #endif
-
     return 0;
 }
Index: /trunk/psLib/src/image/psImage.d
===================================================================
--- /trunk/psLib/src/image/psImage.d	(revision 1192)
+++ /trunk/psLib/src/image/psImage.d	(revision 1193)
@@ -1,2 +1,2 @@
-psImage.o psImage.d : psImage.c ../sysUtils/psMemory.h ../sysUtils/psError.h \
-  psImage.h psType.h
+psImage.o psImage.d : psImage.c ../sysUtils/psMemory.h ../sysUtils/psAbort.h \
+  ../sysUtils/psError.h psImage.h psType.h
Index: /trunk/psLib/src/mathtypes/psImage.c
===================================================================
--- /trunk/psLib/src/mathtypes/psImage.c	(revision 1192)
+++ /trunk/psLib/src/mathtypes/psImage.c	(revision 1193)
@@ -9,6 +9,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.31 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-07-01 00:26:37 $
+ *  @version $Revision: 1.32 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-07-08 01:05:00 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -261,4 +261,6 @@
 }
 
+
+
 psImage *psImageCopy(psImage* restrict output, const psImage *input,
                      psElemType type)
@@ -266,4 +268,5 @@
     psElemType inDatatype;
     int elementSize;
+    int elements;
     int numRows;
     int numCols;
@@ -288,4 +291,5 @@
     numRows = input->numRows;
     numCols = input->numCols;
+    elements = numRows*numCols;
     elementSize = PSELEMTYPE_SIZEOF(inDatatype);
 
@@ -299,1825 +303,98 @@
     // 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);
+        memcpy(output->data.V[0],input->data.V[0],elementSize*elements);
         return output;
     }
 
-    #define PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,INTYPE,OUTTYPE) \
-    { \
-        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[col] = (ps##OUTTYPE) in[col]; \
-            } \
+    #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++); \
         } \
     }
 
-    #define PSIMAGE_ELEMENT_ASSIGN(OUT,IN,OUTTYPE) \
-    switch (IN->type.type) { \
+    #define PSIMAGE_COPY_CASE(OUT,OUTTYPE) \
+    switch (inDatatype) { \
     case PS_TYPE_S8: \
-        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,S8,OUTTYPE); \
+        PSIMAGE_ELEMENT_COPY(input,S8,OUT,OUTTYPE,elements); \
         break; \
     case PS_TYPE_S16: \
-        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,S16,OUTTYPE); \
+        PSIMAGE_ELEMENT_COPY(input,S16,OUT,OUTTYPE,elements); \
         break; \
     case PS_TYPE_S32: \
-        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,S32,OUTTYPE); \
+        PSIMAGE_ELEMENT_COPY(input,S32,OUT,OUTTYPE,elements); \
         break; \
     case PS_TYPE_S64: \
-        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,S64,OUTTYPE); \
+        PSIMAGE_ELEMENT_COPY(input,S64,OUT,OUTTYPE,elements); \
         break; \
     case PS_TYPE_U8: \
-        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,U8,OUTTYPE); \
+        PSIMAGE_ELEMENT_COPY(input,U8,OUT,OUTTYPE,elements); \
         break; \
     case PS_TYPE_U16: \
-        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,U16,OUTTYPE); \
+        PSIMAGE_ELEMENT_COPY(input,U16,OUT,OUTTYPE,elements); \
         break; \
     case PS_TYPE_U32: \
-        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,U32,OUTTYPE); \
+        PSIMAGE_ELEMENT_COPY(input,U32,OUT,OUTTYPE,elements); \
         break; \
     case PS_TYPE_U64: \
-        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,U64,OUTTYPE); \
+        PSIMAGE_ELEMENT_COPY(input,U64,OUT,OUTTYPE,elements); \
         break; \
     case PS_TYPE_F32: \
-        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,F32,OUTTYPE); \
+        PSIMAGE_ELEMENT_COPY(input,F32,OUT,OUTTYPE,elements); \
         break; \
     case PS_TYPE_F64: \
-        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,F64,OUTTYPE); \
+        PSIMAGE_ELEMENT_COPY(input,F64,OUT,OUTTYPE,elements); \
         break; \
     case PS_TYPE_C32: \
-        PSIMAGE_ELEMENT_ASSIGN_LOOP(OUT,IN,C32,OUTTYPE); \
-        break; \
-    case PS_TYPE_PTR: \
-        psError(__func__,"Can't copy image from a matrix of pointers."); \
-        psFree(output); \
-        return NULL; \
+        PSIMAGE_ELEMENT_COPY(input,C32,OUT,OUTTYPE,elements); \
+        break; \
+    case PS_TYPE_C64: \
+        PSIMAGE_ELEMENT_COPY(input,C64,OUT,OUTTYPE,elements); \
+        break; \
     default: \
         break; \
     }
 
-    // XXX - GCC had problems with the length? of the above macro.  The original
-    // macro code here is commented out and the preprocessor output is pasted below it
-    // (effectively to the end of the function)
-    // We need to find out what is doing on here and move back to the macro version.
-    #if 0
-    switch (type)
-    {
-    case PS_TYPE_S8:
-        PSIMAGE_ELEMENT_ASSIGN(output,input,S8);
-        break;
-    case PS_TYPE_S16:
-        PSIMAGE_ELEMENT_ASSIGN(output,input,S16);
-        break;
-    case PS_TYPE_S32:
-        PSIMAGE_ELEMENT_ASSIGN(output,input,S32);
-        break;
-    case PS_TYPE_S64:
-        PSIMAGE_ELEMENT_ASSIGN(output,input,S64);
-        break;
-    case PS_TYPE_U8:
-        PSIMAGE_ELEMENT_ASSIGN(output,input,U8);
-    case PS_TYPE_U16:
-        PSIMAGE_ELEMENT_ASSIGN(output,input,U16);
-        break;
-    case PS_TYPE_U32:
-        PSIMAGE_ELEMENT_ASSIGN(output,input,U32);
-        break;
-    case PS_TYPE_U64:
-        PSIMAGE_ELEMENT_ASSIGN(output,input,U64);
-        break;
-    case PS_TYPE_F32:
-        PSIMAGE_ELEMENT_ASSIGN(output,input,F32);
-        break;
-    case PS_TYPE_F64:
-        PSIMAGE_ELEMENT_ASSIGN(output,input,F64);
-        break;
-    case PS_TYPE_C32:
-        PSIMAGE_ELEMENT_ASSIGN(output,input,C32);
-        break;
-    case PS_TYPE_C64:
-        PSIMAGE_ELEMENT_ASSIGN(output,input,C64);
-        break;
-    case PS_TYPE_PTR:
-        psError(__func__,"Can't copy image into a matrix of pointers.");
-        psFree(output);
-        return NULL;
-    }
-    #endif
-
-    #if 1
     switch (type) {
     case PS_TYPE_S8:
-        switch (input->type.type) {
-        case PS_TYPE_S8: {
-                psS8 *in;
-                psS8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S8[row];
-                    out = output->data.S8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S16: {
-                psS16 *in;
-                psS8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S16[row];
-                    out = output->data.S8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S32: {
-                psS32 *in;
-                psS8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S32[row];
-                    out = output->data.S8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S64: {
-                psS64 *in;
-                psS8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S64[row];
-                    out = output->data.S8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U8: {
-                psU8 *in;
-                psS8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U8[row];
-                    out = output->data.S8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U16: {
-                psU16 *in;
-                psS8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U16[row];
-                    out = output->data.S8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U32: {
-                psU32 *in;
-                psS8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U32[row];
-                    out = output->data.S8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U64: {
-                psU64 *in;
-                psS8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U64[row];
-                    out = output->data.S8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F32: {
-                psF32 *in;
-                psS8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F32[row];
-                    out = output->data.S8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F64: {
-                psF64 *in;
-                psS8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F64[row];
-                    out = output->data.S8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_C32: {
-                psC32 *in;
-                psS8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.C32[row];
-                    out = output->data.S8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_PTR:
-            psError (__func__, "Can't copy image from a matrix of pointers.");
-            psFree (output);
-            return ((void *) 0);
-        default:
-            break;
-        };
+        PSIMAGE_COPY_CASE(output,S8);
         break;
     case PS_TYPE_S16:
-        switch (input->type.type) {
-        case PS_TYPE_S8: {
-                psS8 *in;
-                psS16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S8[row];
-                    out = output->data.S16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S16: {
-                psS16 *in;
-                psS16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S16[row];
-                    out = output->data.S16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S32: {
-                psS32 *in;
-                psS16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S32[row];
-                    out = output->data.S16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S64: {
-                psS64 *in;
-                psS16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S64[row];
-                    out = output->data.S16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U8: {
-                psU8 *in;
-                psS16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U8[row];
-                    out = output->data.S16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U16: {
-                psU16 *in;
-                psS16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U16[row];
-                    out = output->data.S16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U32: {
-                psU32 *in;
-                psS16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U32[row];
-                    out = output->data.S16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U64: {
-                psU64 *in;
-                psS16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U64[row];
-                    out = output->data.S16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F32: {
-                psF32 *in;
-                psS16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F32[row];
-                    out = output->data.S16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F64: {
-                psF64 *in;
-                psS16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F64[row];
-                    out = output->data.S16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_C32: {
-                psC32 *in;
-                psS16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.C32[row];
-                    out = output->data.S16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_PTR:
-            psError (__func__, "Can't copy image from a matrix of pointers.");
-            psFree (output);
-            return ((void *) 0);
-        default:
-            break;
-        };
+        PSIMAGE_COPY_CASE(output,S16);
         break;
     case PS_TYPE_S32:
-        switch (input->type.type) {
-        case PS_TYPE_S8: {
-                psS8 *in;
-                psS32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S8[row];
-                    out = output->data.S32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S16: {
-                psS16 *in;
-                psS32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S16[row];
-                    out = output->data.S32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S32: {
-                psS32 *in;
-                psS32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S32[row];
-                    out = output->data.S32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S64: {
-                psS64 *in;
-                psS32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S64[row];
-                    out = output->data.S32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U8: {
-                psU8 *in;
-                psS32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U8[row];
-                    out = output->data.S32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U16: {
-                psU16 *in;
-                psS32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U16[row];
-                    out = output->data.S32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U32: {
-                psU32 *in;
-                psS32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U32[row];
-                    out = output->data.S32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U64: {
-                psU64 *in;
-                psS32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U64[row];
-                    out = output->data.S32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F32: {
-                psF32 *in;
-                psS32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F32[row];
-                    out = output->data.S32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F64: {
-                psF64 *in;
-                psS32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F64[row];
-                    out = output->data.S32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_C32: {
-                psC32 *in;
-                psS32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.C32[row];
-                    out = output->data.S32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_PTR:
-            psError (__func__, "Can't copy image from a matrix of pointers.");
-            psFree (output);
-            return ((void *) 0);
-        default:
-            break;
-        };
+        PSIMAGE_COPY_CASE(output,S32);
         break;
     case PS_TYPE_S64:
-        switch (input->type.type) {
-        case PS_TYPE_S8: {
-                psS8 *in;
-                psS64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S8[row];
-                    out = output->data.S64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S16: {
-                psS16 *in;
-                psS64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S16[row];
-                    out = output->data.S64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S32: {
-                psS32 *in;
-                psS64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S32[row];
-                    out = output->data.S64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S64: {
-                psS64 *in;
-                psS64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S64[row];
-                    out = output->data.S64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U8: {
-                psU8 *in;
-                psS64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U8[row];
-                    out = output->data.S64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U16: {
-                psU16 *in;
-                psS64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U16[row];
-                    out = output->data.S64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U32: {
-                psU32 *in;
-                psS64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U32[row];
-                    out = output->data.S64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U64: {
-                psU64 *in;
-                psS64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U64[row];
-                    out = output->data.S64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F32: {
-                psF32 *in;
-                psS64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F32[row];
-                    out = output->data.S64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F64: {
-                psF64 *in;
-                psS64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F64[row];
-                    out = output->data.S64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_C32: {
-                psC32 *in;
-                psS64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.C32[row];
-                    out = output->data.S64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psS64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_PTR:
-            psError (__func__, "Can't copy image from a matrix of pointers.");
-            psFree (output);
-            return ((void *) 0);
-        default:
-            break;
-        };
+        PSIMAGE_COPY_CASE(output,S64);
         break;
     case PS_TYPE_U8:
-        switch (input->type.type) {
-        case PS_TYPE_S8: {
-                psS8 *in;
-                psU8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S8[row];
-                    out = output->data.U8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S16: {
-                psS16 *in;
-                psU8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S16[row];
-                    out = output->data.U8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S32: {
-                psS32 *in;
-                psU8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S32[row];
-                    out = output->data.U8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S64: {
-                psS64 *in;
-                psU8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S64[row];
-                    out = output->data.U8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U8: {
-                psU8 *in;
-                psU8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U8[row];
-                    out = output->data.U8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U16: {
-                psU16 *in;
-                psU8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U16[row];
-                    out = output->data.U8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U32: {
-                psU32 *in;
-                psU8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U32[row];
-                    out = output->data.U8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U64: {
-                psU64 *in;
-                psU8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U64[row];
-                    out = output->data.U8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F32: {
-                psF32 *in;
-                psU8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F32[row];
-                    out = output->data.U8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F64: {
-                psF64 *in;
-                psU8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F64[row];
-                    out = output->data.U8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_C32: {
-                psC32 *in;
-                psU8 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.C32[row];
-                    out = output->data.U8[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU8) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_PTR:
-            psError (__func__, "Can't copy image from a matrix of pointers.");
-            psFree (output);
-            return ((void *) 0);
-        default:
-            break;
-        };
+        PSIMAGE_COPY_CASE(output,U8);
         break;
     case PS_TYPE_U16:
-        switch (input->type.type) {
-        case PS_TYPE_S8: {
-                psS8 *in;
-                psU16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S8[row];
-                    out = output->data.U16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S16: {
-                psS16 *in;
-                psU16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S16[row];
-                    out = output->data.U16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S32: {
-                psS32 *in;
-                psU16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S32[row];
-                    out = output->data.U16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S64: {
-                psS64 *in;
-                psU16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S64[row];
-                    out = output->data.U16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U8: {
-                psU8 *in;
-                psU16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U8[row];
-                    out = output->data.U16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U16: {
-                psU16 *in;
-                psU16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U16[row];
-                    out = output->data.U16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U32: {
-                psU32 *in;
-                psU16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U32[row];
-                    out = output->data.U16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U64: {
-                psU64 *in;
-                psU16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U64[row];
-                    out = output->data.U16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F32: {
-                psF32 *in;
-                psU16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F32[row];
-                    out = output->data.U16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F64: {
-                psF64 *in;
-                psU16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F64[row];
-                    out = output->data.U16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_C32: {
-                psC32 *in;
-                psU16 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.C32[row];
-                    out = output->data.U16[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU16) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_PTR:
-            psError (__func__, "Can't copy image from a matrix of pointers.");
-            psFree (output);
-            return ((void *) 0);
-        default:
-            break;
-        };
+        PSIMAGE_COPY_CASE(output,U16);
         break;
     case PS_TYPE_U32:
-        switch (input->type.type) {
-        case PS_TYPE_S8: {
-                psS8 *in;
-                psU32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S8[row];
-                    out = output->data.U32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S16: {
-                psS16 *in;
-                psU32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S16[row];
-                    out = output->data.U32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S32: {
-                psS32 *in;
-                psU32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S32[row];
-                    out = output->data.U32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S64: {
-                psS64 *in;
-                psU32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S64[row];
-                    out = output->data.U32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U8: {
-                psU8 *in;
-                psU32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U8[row];
-                    out = output->data.U32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U16: {
-                psU16 *in;
-                psU32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U16[row];
-                    out = output->data.U32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U32: {
-                psU32 *in;
-                psU32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U32[row];
-                    out = output->data.U32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U64: {
-                psU64 *in;
-                psU32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U64[row];
-                    out = output->data.U32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F32: {
-                psF32 *in;
-                psU32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F32[row];
-                    out = output->data.U32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F64: {
-                psF64 *in;
-                psU32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F64[row];
-                    out = output->data.U32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_C32: {
-                psC32 *in;
-                psU32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.C32[row];
-                    out = output->data.U32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_PTR:
-            psError (__func__, "Can't copy image from a matrix of pointers.");
-            psFree (output);
-            return ((void *) 0);
-        default:
-            break;
-        };
+        PSIMAGE_COPY_CASE(output,U32);
         break;
     case PS_TYPE_U64:
-        switch (input->type.type) {
-        case PS_TYPE_S8: {
-                psS8 *in;
-                psU64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S8[row];
-                    out = output->data.U64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S16: {
-                psS16 *in;
-                psU64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S16[row];
-                    out = output->data.U64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S32: {
-                psS32 *in;
-                psU64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S32[row];
-                    out = output->data.U64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S64: {
-                psS64 *in;
-                psU64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S64[row];
-                    out = output->data.U64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U8: {
-                psU8 *in;
-                psU64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U8[row];
-                    out = output->data.U64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U16: {
-                psU16 *in;
-                psU64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U16[row];
-                    out = output->data.U64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U32: {
-                psU32 *in;
-                psU64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U32[row];
-                    out = output->data.U64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U64: {
-                psU64 *in;
-                psU64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U64[row];
-                    out = output->data.U64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F32: {
-                psF32 *in;
-                psU64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F32[row];
-                    out = output->data.U64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F64: {
-                psF64 *in;
-                psU64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F64[row];
-                    out = output->data.U64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_C32: {
-                psC32 *in;
-                psU64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.C32[row];
-                    out = output->data.U64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psU64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_PTR:
-            psError (__func__, "Can't copy image from a matrix of pointers.");
-            psFree (output);
-            return ((void *) 0);
-        default:
-            break;
-        };
+        PSIMAGE_COPY_CASE(output,U64);
         break;
     case PS_TYPE_F32:
-        switch (input->type.type) {
-        case PS_TYPE_S8: {
-                psS8 *in;
-                psF32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S8[row];
-                    out = output->data.F32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S16: {
-                psS16 *in;
-                psF32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S16[row];
-                    out = output->data.F32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S32: {
-                psS32 *in;
-                psF32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S32[row];
-                    out = output->data.F32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S64: {
-                psS64 *in;
-                psF32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S64[row];
-                    out = output->data.F32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U8: {
-                psU8 *in;
-                psF32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U8[row];
-                    out = output->data.F32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U16: {
-                psU16 *in;
-                psF32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U16[row];
-                    out = output->data.F32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U32: {
-                psU32 *in;
-                psF32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U32[row];
-                    out = output->data.F32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U64: {
-                psU64 *in;
-                psF32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U64[row];
-                    out = output->data.F32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F32: {
-                psF32 *in;
-                psF32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F32[row];
-                    out = output->data.F32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F64: {
-                psF64 *in;
-                psF32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F64[row];
-                    out = output->data.F32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_C32: {
-                psC32 *in;
-                psF32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.C32[row];
-                    out = output->data.F32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_PTR:
-            psError (__func__, "Can't copy image from a matrix of pointers.");
-            psFree (output);
-            return ((void *) 0);
-        default:
-            break;
-        };
+        PSIMAGE_COPY_CASE(output,F32);
         break;
     case PS_TYPE_F64:
-        switch (input->type.type) {
-        case PS_TYPE_S8: {
-                psS8 *in;
-                psF64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S8[row];
-                    out = output->data.F64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S16: {
-                psS16 *in;
-                psF64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S16[row];
-                    out = output->data.F64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S32: {
-                psS32 *in;
-                psF64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S32[row];
-                    out = output->data.F64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S64: {
-                psS64 *in;
-                psF64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S64[row];
-                    out = output->data.F64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U8: {
-                psU8 *in;
-                psF64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U8[row];
-                    out = output->data.F64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U16: {
-                psU16 *in;
-                psF64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U16[row];
-                    out = output->data.F64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U32: {
-                psU32 *in;
-                psF64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U32[row];
-                    out = output->data.F64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U64: {
-                psU64 *in;
-                psF64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U64[row];
-                    out = output->data.F64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F32: {
-                psF32 *in;
-                psF64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F32[row];
-                    out = output->data.F64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F64: {
-                psF64 *in;
-                psF64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F64[row];
-                    out = output->data.F64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_C32: {
-                psC32 *in;
-                psF64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.C32[row];
-                    out = output->data.F64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psF64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_PTR:
-            psError (__func__, "Can't copy image from a matrix of pointers.");
-            psFree (output);
-            return ((void *) 0);
-        default:
-            break;
-        };
+        PSIMAGE_COPY_CASE(output,F64);
         break;
     case PS_TYPE_C32:
-        switch (input->type.type) {
-        case PS_TYPE_S8: {
-                psS8 *in;
-                psC32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S8[row];
-                    out = output->data.C32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S16: {
-                psS16 *in;
-                psC32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S16[row];
-                    out = output->data.C32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S32: {
-                psS32 *in;
-                psC32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S32[row];
-                    out = output->data.C32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S64: {
-                psS64 *in;
-                psC32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S64[row];
-                    out = output->data.C32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U8: {
-                psU8 *in;
-                psC32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U8[row];
-                    out = output->data.C32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U16: {
-                psU16 *in;
-                psC32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U16[row];
-                    out = output->data.C32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U32: {
-                psU32 *in;
-                psC32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U32[row];
-                    out = output->data.C32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U64: {
-                psU64 *in;
-                psC32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U64[row];
-                    out = output->data.C32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F32: {
-                psF32 *in;
-                psC32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F32[row];
-                    out = output->data.C32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F64: {
-                psF64 *in;
-                psC32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F64[row];
-                    out = output->data.C32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_C32: {
-                psC32 *in;
-                psC32 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.C32[row];
-                    out = output->data.C32[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC32) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_PTR:
-            psError (__func__, "Can't copy image from a matrix of pointers.");
-            psFree (output);
-            return ((void *) 0);
-        default:
-            break;
-        };
+        PSIMAGE_COPY_CASE(output,C32);
         break;
     case PS_TYPE_C64:
-        switch (input->type.type) {
-        case PS_TYPE_S8: {
-                psS8 *in;
-                psC64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S8[row];
-                    out = output->data.C64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S16: {
-                psS16 *in;
-                psC64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S16[row];
-                    out = output->data.C64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S32: {
-                psS32 *in;
-                psC64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S32[row];
-                    out = output->data.C64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_S64: {
-                psS64 *in;
-                psC64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.S64[row];
-                    out = output->data.C64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U8: {
-                psU8 *in;
-                psC64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U8[row];
-                    out = output->data.C64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U16: {
-                psU16 *in;
-                psC64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U16[row];
-                    out = output->data.C64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U32: {
-                psU32 *in;
-                psC64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U32[row];
-                    out = output->data.C64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_U64: {
-                psU64 *in;
-                psC64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.U64[row];
-                    out = output->data.C64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F32: {
-                psF32 *in;
-                psC64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F32[row];
-                    out = output->data.C64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_F64: {
-                psF64 *in;
-                psC64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.F64[row];
-                    out = output->data.C64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_C32: {
-                psC32 *in;
-                psC64 *out;
-                for (int row = 0; row < numRows; row++) {
-                    in = input->data.C32[row];
-                    out = output->data.C64[row];
-                    for (int col = 0; col < numCols; col++) {
-                        out[col] = (psC64) in[col];
-                    }
-                }
-            };
-            break;
-        case PS_TYPE_PTR:
-            psError (__func__, "Can't copy image from a matrix of pointers.");
-            psFree (output);
-            return ((void *) 0);
-        default:
-            break;
-        };
-        break;
-    case PS_TYPE_PTR:
-        psError (__func__, "Can't copy image into a matrix of pointers.");
-        psFree (output);
-        return ((void *) 0);
-    }
-
+        PSIMAGE_COPY_CASE(output,C64);
+        break;
+    default:
+        break;
+    }
     return output;
 }
@@ -2340,6 +617,4 @@
     }
 
-    #endif
-
     return 0;
 }
Index: /trunk/psLib/src/types/psList.c
===================================================================
--- /trunk/psLib/src/types/psList.c	(revision 1192)
+++ /trunk/psLib/src/types/psList.c	(revision 1193)
@@ -6,6 +6,6 @@
  *  @author Robert Daniel DeSonia, MHPCC
  *
- *  @version $Revision: 1.9 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-06-29 23:19:11 $
+ *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-07-08 01:05:00 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -80,5 +80,5 @@
 }
 
-psList* psListAdd(psList *list, void *data, int where)
+bool psListAdd(psList *list, void *data, int where)
 {
     psListElem* position;
@@ -87,22 +87,23 @@
 
     if (list == NULL) {
-        return NULL;
+        return false;
     }
 
     if (data == NULL) {
-        return list;
-    }
-    elem = psAlloc(sizeof(psListElem));
-
-    pthread_mutex_lock(&list->lock)
-    ;
+        return false;
+    }
 
     if (where <= PS_LIST_UNKNOWN) {
         /// XXX What is the better way to communicate this failure to the caller?
         psLogMsg(__func__,PS_LOG_WARN,
-                 "The given insert location (%i) for psListAdd is invalid. Adding to head instead.",
+                 "The given insert location (%i) for psListAdd is invalid.",
                  where);
-        where = PS_LIST_HEAD; // given I can't tell caller about this, should just add it somewhere???
-    }
+        return false;
+    }
+
+    elem = psAlloc(sizeof(psListElem));
+
+    pthread_mutex_lock(&list->lock)
+    ;
 
     if (where > 0 && where > list->size) {
@@ -162,12 +163,5 @@
     ;
 
-    return list;
-}
-
-/*****************************************************************************/
-
-psList *psListAppend(psList *list, void *data)
-{
-    return psListAdd(list, data, PS_LIST_TAIL);
+    return true;
 }
 
@@ -452,5 +446,5 @@
     n = arr->n;
     for (int i = 0; i < n; i++) {
-        psListAppend(list,arr->data.PTR[i]);
+        psListAdd(list,arr->data.PTR[i],PS_LIST_TAIL);
     }
 
Index: /trunk/psLib/src/types/psList.h
===================================================================
--- /trunk/psLib/src/types/psList.h	(revision 1192)
+++ /trunk/psLib/src/types/psList.h	(revision 1193)
@@ -10,6 +10,6 @@
  *  @ingroup LinkedList
  *
- *  @version $Revision: 1.7 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-06-29 23:19:11 $
+ *  @version $Revision: 1.8 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-07-08 01:05:00 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -81,18 +81,8 @@
  *                      NULL, the return value will also be NULL.
  */
-psList* psListAdd(
+bool psListAdd(
     psList* restrict list,              ///< list to add to (if NULL, nothing is done)
     void* data,                         ///< data item to add.  If NULL, list is not modified.
     int where                           ///< index, PS_LIST_HEAD, PS_LIST_TAIL, or numbered location.
-);
-
-/** Appends an item to a psList.
- *
- *  @return psList*     The psList with added data item.  If list parameter is
- *                      NULL, the return value will also be NULL.
- */
-psList* psListAppend(
-    psList* restrict list,              ///< list to append to (if NULL, nothing is done)
-    void *data                          ///< data item to add. If NULL, list is not modified.
 );
 
Index: /trunk/psLib/test/collections/tst_psList.c
===================================================================
--- /trunk/psLib/test/collections/tst_psList.c	(revision 1192)
+++ /trunk/psLib/test/collections/tst_psList.c	(revision 1193)
@@ -6,6 +6,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.12 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-06-29 23:18:00 $
+ *  @version $Revision: 1.13 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-07-08 01:05:01 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -28,20 +28,20 @@
 
 testDescription tests[] = {
-                              {testListAlloc,"487-testListAlloc",0},
-                              {testListAdd,"488-testListAdd",0},
-                              {testListGet,"489-testListGet",0},
-                              {testListRemove,"490-testListRemove",0},
-                              {testListConvert,"491-testListConvert",0},
-                              {testListIterator,"494-testListIterator",0},
-                              {testListFree,"627-testListFree",0},
-                              {testListSort,"624-testListSort",0},
+                              {testListAlloc,487,"psListAlloc",0,false},
+                              {testListAdd,488,"psListAdd",0,false},
+                              {testListGet,489,"psListGet",0,false},
+                              {testListRemove,490,"psListRemove",0,false},
+                              {testListConvert,491,"psListConvert",0,false},
+                              {testListIterator,494,"psListIterator",0,false},
+                              {testListFree,627,"psListFree",0,false},
+                              {testListSort,624,"psListSort",0,false},
                               {NULL}
                           };
 
-int main()
+int main(int argc, char* argv[])
 {
     psLogSetLevel(PS_LOG_INFO);
 
-    if (! runTestSuite(stderr,"psList",tests)) {
+    if (! runTestSuite(stderr,"psList",tests,argc,argv) ) {
         psError(__FILE__,"One or more tests failed");
         return 1;
@@ -138,12 +138,9 @@
 
     //  1. list is NULL (error)
-    list = psListAdd(NULL,data,PS_LIST_HEAD);
-
-    if (list != NULL) {
-        psError(__func__,"psListAdd was given a NULL list, but returned a non-NULL list.");
-        return 1;
-    }
-
-    //  2. data is NULL (error, list should not grow)
+    if (psListAdd(NULL,data,PS_LIST_HEAD)) {
+        psError(__func__,"psListAdd was given a NULL list, but returned a true/success.");
+        return 1;
+    }
+
     list = psListAlloc(data);
     psFree(data);
@@ -153,8 +150,11 @@
     }
 
-    list = psListAdd(list, NULL,PS_LIST_HEAD);
-
-    if (list->size != 1) {
-        psError(__func__,"psListAdd with a NULL data element changed the list size.");
+    //  2. data is NULL (error, list should not grow)
+    if (psListAdd(list, NULL,PS_LIST_HEAD)) {
+        psError(__func__,"psListAdd successfully added a NULL data item?");
+        return 40;
+    }
+    if ( list->size != 1) {
+        psError(__func__,"psListAdd with a NULL data element changed the list size or returned success.");
         return 3;
     }
@@ -163,5 +163,9 @@
     data = psAlloc(sizeof(int));
     *data = 2;
-    list = psListAdd(list,data,PS_LIST_HEAD);
+    if ( ! psListAdd(list,data,PS_LIST_HEAD) ) {
+        psError(__func__,"psListAdd failed to add a data item to head.");
+        return 21;
+    }
+
     if (psMemGetRefCounter(data) != 2) {
         psError(__func__,"psListAdd didn't increment the data reference count.");
@@ -169,4 +173,5 @@
     }
     psFree(data);
+
     // verify that the size incremented
     if (list->size != 2) {
@@ -183,8 +188,12 @@
     data = psAlloc(sizeof(int));
     *data = 3;
-    list = psListAdd(list,data,PS_LIST_TAIL);
+    if ( ! psListAdd(list,data,PS_LIST_TAIL) ) {
+        psError(__func__,"psListAdd failed to add a data item to tail.");
+        return 21;
+    }
+
     if (psMemGetRefCounter(data) != 2) {
         psError(__func__,"psListAdd didn't increment the data reference count.");
-        return 20;
+        return 22;
     }
     psFree(data);
@@ -211,13 +220,17 @@
     data = psAlloc(sizeof(int));
     *data = 4;
-    psLogMsg(__func__,PS_LOG_INFO,"Following should warn with invalid insert location");
-    list = psListAdd(list,data,-10);
-    if (psMemGetRefCounter(data) != 2) {
-        psError(__func__,"psListAdd didn't increment the data reference count.");
-        return 20;
-    }
-    psFree(data);
-    // verify that the size incremented
-    if (list->size != 4 || *(int*)list->head->data != 4) {
+    psLogMsg(__func__,PS_LOG_INFO,"Following should error with invalid insert location");
+
+    if ( psListAdd(list,data,-10) ) {
+        psError(__func__,"psListAdd successfully added data to a -10 position?");
+        return 30;
+    }
+    if (psMemGetRefCounter(data) != 1) {
+        psError(__func__,"psListAdd incremented the data reference count.");
+        return 24;
+    }
+    psFree(data);
+    // verify that the size wasn't incremented
+    if (list->size != 3) {
         printListInt(list);
         psError(__func__,"psListAdd didn't insert to head when where was invalid.");
@@ -228,45 +241,56 @@
     data = psAlloc(sizeof(int));
     *data = 5;
-    list = psListAdd(list,data,1);
+
+    if ( ! psListAdd(list,data,1) ) {
+        psError(__func__,"psListAdd failed to add data to 1 position.");
+        return 30;
+    }
+
     if (psMemGetRefCounter(data) != 2) {
         psError(__func__,"psListAdd didn't increment the data reference count.");
-        return 20;
+        return 25;
     }
     psFree(data);
     // verify that the size incremented
-    if (list->size != 5 || *(int*)list->head->next->data != 5) {
+    if (list->size != 4 || *(int*)list->head->next->data != 5) {
         printListInt(list);
         psError(__func__,"psListAdd didn't insert to position #1.");
-        return 9;
+        return 10;
     }
 
     data = psAlloc(sizeof(int));
     *data = 6;
-    list = psListAdd(list,data,4);
+    if ( ! psListAdd(list,data,3) ) {
+        psError(__func__,"psListAdd failed to add data to 4 position.");
+        return 31;
+    }
     if (psMemGetRefCounter(data) != 2) {
         psError(__func__,"psListAdd didn't increment the data reference count.");
-        return 20;
+        return 26;
     }
     psFree(data);
     // verify that the size incremented
-    if (list->size != 6  || *(int *)list->head->next->next->next->next->data != 6) {
+    if (list->size != 5  || *(int *)list->head->next->next->next->data != 6) {
         printListInt(list);
         psError(__func__,"psListAdd didn't insert to position #4.");
-        return 9;
+        return 50;
     }
 
     data = psAlloc(sizeof(int));
     *data = 7;
-    list = psListAdd(list,data,2);
+    if ( ! psListAdd(list,data,2) ) {
+        psError(__func__,"psListAdd failed to add data to 2 position.");
+        return 32;
+    }
     if (psMemGetRefCounter(data) != 2) {
         psError(__func__,"psListAdd didn't increment the data reference count.");
-        return 20;
+        return 28;
     }
     psFree(data);
     // verify that the size incremented
-    if (list->size != 7  || *(int *)list->head->next->next->data != 7) {
+    if (list->size != 6  || *(int *)list->head->next->next->data != 7) {
         printListInt(list);
         psError(__func__,"psListAdd didn't insert to position #2.");
-        return 9;
+        return 11;
     }
 
@@ -274,15 +298,22 @@
     *data = 7;
     psLogMsg(__func__,PS_LOG_INFO,"Following should be a warning.");
-    list = psListAdd(list,data,9);
+
+    if ( ! psListAdd(list,data,9) ) {
+        psError(__func__,"psListAdd failed to add data to a 9 position?");
+        return 30;
+    }
+
     if (psMemGetRefCounter(data) != 2) {
         psError(__func__,"psListAdd didn't increment the data reference count.");
-        return 20;
-    }
-    psFree(data);
+        return 29;
+    }
+
+    psFree(data);
+
     // verify that the size incremented
-    if (list->size != 8) {
+    if (list->size != 7) {
         printListInt(list);
         psError(__func__,"psListAdd didn't insert to position #9.");
-        return 9;
+        return 12;
     }
 
@@ -347,15 +378,15 @@
     data = psAlloc(sizeof(int));
     *data = 1;
-    list = psListAdd(list,data,PS_LIST_TAIL);
+    psListAdd(list,data,PS_LIST_TAIL);
     psFree(data);
 
     data = psAlloc(sizeof(int));
     *data = 2;
-    list = psListAdd(list,data,PS_LIST_TAIL);
+    psListAdd(list,data,PS_LIST_TAIL);
     psFree(data);
 
     data = psAlloc(sizeof(int));
     *data = 3;
-    list = psListAdd(list,data,PS_LIST_TAIL);
+    psListAdd(list,data,PS_LIST_TAIL);
     psFree(data);
 
@@ -452,5 +483,5 @@
         data = psAlloc(sizeof(int));
         *data = lcv;
-        list = psListAdd(list,data,PS_LIST_TAIL);
+        psListAdd(list,data,PS_LIST_TAIL);
         psMemDecrRefCounter(data);
     }
@@ -671,5 +702,5 @@
         data = psAlloc(sizeof(int));
         *data = lcv;
-        list = psListAdd(list,data,PS_LIST_TAIL);
+        psListAdd(list,data,PS_LIST_TAIL);
         psMemDecrRefCounter(data);
     }
@@ -809,5 +840,5 @@
         data = psAlloc(sizeof(int));
         *data = lcv;
-        list = psListAdd(list,data,PS_LIST_TAIL);
+        psListAdd(list,data,PS_LIST_TAIL);
         psFree(data);
     }
@@ -926,5 +957,5 @@
         data[lcv] = psAlloc(sizeof(int));
         *data[lcv] = lcv;
-        list = psListAdd(list,data[lcv],PS_LIST_TAIL);
+        psListAdd(list,data[lcv],PS_LIST_TAIL);
         if (psMemGetRefCounter(data[lcv]) != 2) {
             psError(__func__,"Reference counter for data was not incremented");
@@ -980,5 +1011,5 @@
             *data = lcv*2-12;
         }
-        list = psListAdd(list,data,PS_LIST_TAIL);
+        psListAdd(list,data,PS_LIST_TAIL);
         psFree(data);
 
@@ -1046,5 +1077,5 @@
             *data = lcv*2-12;
         }
-        list = psListAdd(list,data,PS_LIST_TAIL);
+        psListAdd(list,data,PS_LIST_TAIL);
         psFree(data);
 
Index: /trunk/psLib/test/dataManip/builddir/tst_psImageFFT.d
===================================================================
--- /trunk/psLib/test/dataManip/builddir/tst_psImageFFT.d	(revision 1192)
+++ /trunk/psLib/test/dataManip/builddir/tst_psImageFFT.d	(revision 1193)
@@ -3,6 +3,6 @@
   ../../include/psTrace.h ../../include/psAbort.h ../../include/psError.h \
   ../../include/psString.h ../../include/psType.h ../../include/psList.h \
-  ../../include/psVector.h ../../include/psHash.h \
-  ../../include/psScalar.h ../../include/psImage.h \
+  ../../include/psCompare.h ../../include/psVector.h \
+  ../../include/psHash.h ../../include/psScalar.h ../../include/psImage.h \
   ../../include/psBitSet.h ../../include/psSort.h ../../include/psStats.h \
   ../../include/psMatrix.h ../../include/psMatrixVectorArithmetic.h \
Index: /trunk/psLib/test/dataManip/builddir/tst_psImageIO.d
===================================================================
--- /trunk/psLib/test/dataManip/builddir/tst_psImageIO.d	(revision 1192)
+++ /trunk/psLib/test/dataManip/builddir/tst_psImageIO.d	(revision 1193)
@@ -3,6 +3,6 @@
   ../../include/psTrace.h ../../include/psAbort.h ../../include/psError.h \
   ../../include/psString.h ../../include/psType.h ../../include/psList.h \
-  ../../include/psVector.h ../../include/psHash.h \
-  ../../include/psScalar.h ../../include/psImage.h \
+  ../../include/psCompare.h ../../include/psVector.h \
+  ../../include/psHash.h ../../include/psScalar.h ../../include/psImage.h \
   ../../include/psBitSet.h ../../include/psSort.h ../../include/psStats.h \
   ../../include/psMatrix.h ../../include/psMatrixVectorArithmetic.h \
Index: /trunk/psLib/test/dataManip/builddir/tst_psVectorFFT.d
===================================================================
--- /trunk/psLib/test/dataManip/builddir/tst_psVectorFFT.d	(revision 1192)
+++ /trunk/psLib/test/dataManip/builddir/tst_psVectorFFT.d	(revision 1193)
@@ -3,6 +3,6 @@
   ../../include/psTrace.h ../../include/psAbort.h ../../include/psError.h \
   ../../include/psString.h ../../include/psType.h ../../include/psList.h \
-  ../../include/psVector.h ../../include/psHash.h \
-  ../../include/psScalar.h ../../include/psImage.h \
+  ../../include/psCompare.h ../../include/psVector.h \
+  ../../include/psHash.h ../../include/psScalar.h ../../include/psImage.h \
   ../../include/psBitSet.h ../../include/psSort.h ../../include/psStats.h \
   ../../include/psMatrix.h ../../include/psMatrixVectorArithmetic.h \
Index: /trunk/psLib/test/dataManip/tst_psVectorFFT.c
===================================================================
--- /trunk/psLib/test/dataManip/tst_psVectorFFT.c	(revision 1192)
+++ /trunk/psLib/test/dataManip/tst_psVectorFFT.c	(revision 1193)
@@ -6,6 +6,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-06-23 23:00:17 $
+ *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-07-08 01:05:01 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -34,17 +34,17 @@
 
 testDescription tests[] = {
-                              {testVectorFFT,"600-testVectorFFT",0},
-                              {testVectorRealImaginary,"601-testVectorRealImaginary",0},
-                              {testVectorComplex,"602-testVectorComplex",0},
-                              {testVectorConjugate,"603-testVectorConjugate",0},
-                              {testVectorPowerSpectrum,"604-testVectorPowerSpectrum",0},
+                              {testVectorFFT,600,"psVectorFFT",0,false},
+                              {testVectorRealImaginary,601,"psVectorRealImaginary",0,false},
+                              {testVectorComplex,602,"psVectorComplex",0,false},
+                              {testVectorConjugate,603,"psVectorConjugate",0,false},
+                              {testVectorPowerSpectrum,604,"psVectorPowerSpectrum",0,false},
                               {NULL}
                           };
 
-int main()
+int main(int argc, char* argv[])
 {
     psLogSetLevel(PS_LOG_INFO);
 
-    if (! runTestSuite(stderr,"psFFT",tests)) {
+    if (! runTestSuite(stderr,"psFFT",tests,argc,argv) ) {
         psAbort(__FILE__,"One or more tests failed");
     }
Index: /trunk/psLib/test/image/tst_psImage.c
===================================================================
--- /trunk/psLib/test/image/tst_psImage.c	(revision 1192)
+++ /trunk/psLib/test/image/tst_psImage.c	(revision 1193)
@@ -6,6 +6,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-06-23 23:00:15 $
+ *  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-07-08 01:05:01 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -29,18 +29,20 @@
 
 testDescription tests[] = {
-                              {testImageAlloc,"546/548-testImageAlloc/Free",0},
-                              {testImageSubset,"547/550-testImageSubset",0},
-                              {testImageCopy,"551-testImageCopy",0},
-                              {testImageClip,"571-testImageClip",0},
-                              {testImageClipNAN,"572-testImageClipNAN",0},
-                              {testImageOverlay,"573-testImageOverlay",0},
+                              {testImageAlloc,546,"psImageAlloc",0,false},
+                              {testImageAlloc,548,"psImageFree",0,true},
+                              {testImageSubset,547,"psImageSubset",0,false},
+                              {testImageSubset,550,"psImageSubset",0,true},
+                              {testImageCopy,551,"psImageCopy",0,false},
+                              {testImageClip,571,"psImageClip",0,false},
+                              {testImageClipNAN,572,"psImageClipNAN",0,false},
+                              {testImageOverlay,573,"psImageOverlay",0,false},
                               {NULL}
                           };
 
-int main()
+int main(int argc, char* argv[])
 {
     psLogSetLevel(PS_LOG_INFO);
-    testImageOverlay();
-    if (! runTestSuite(stderr,"psImage",tests)) {
+
+    if (! runTestSuite(stderr,"psImage",tests,argc,argv)) {
         psError(__FILE__,"One or more tests failed");
         return 1;
@@ -572,20 +574,36 @@
 
     #define testImageCopyTypes(IN) \
+    printf("to psF32\n"); \
+    testImageCopyType(IN,F32);\
+    printf("to psF64\n"); \
+    testImageCopyType(IN,F64); \
+    printf("to psU8\n"); \
     testImageCopyType(IN,U8); \
+    printf("to psU16\n"); \
     testImageCopyType(IN,U16); \
+    printf("to psU32\n"); \
     testImageCopyType(IN,U32); \
+    printf("to psS8\n"); \
     testImageCopyType(IN,S8);\
+    printf("to psS16\n"); \
     testImageCopyType(IN,S16);\
-    testImageCopyType(IN,S32);\
-    testImageCopyType(IN,F32);\
-    testImageCopyType(IN,F64);
-
+    printf("to psS32\n"); \
+    testImageCopyType(IN,S32);
+
+    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psU8");
     testImageCopyTypes(U8);
+    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psU16");
     testImageCopyTypes(U16);
+    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psU32");
     testImageCopyTypes(U32);
+    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psS8");
     testImageCopyTypes(S8);
+    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psS16");
     testImageCopyTypes(S16);
+    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psS32");
     testImageCopyTypes(S32);
+    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psF32");
     testImageCopyTypes(F32);
+    psLogMsg(__func__,PS_LOG_INFO,"Image Copy Test for psF64");
     testImageCopyTypes(F64);
 
Index: /trunk/psLib/test/image/tst_psImageFFT.c
===================================================================
--- /trunk/psLib/test/image/tst_psImageFFT.c	(revision 1192)
+++ /trunk/psLib/test/image/tst_psImageFFT.c	(revision 1193)
@@ -6,6 +6,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.3 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-06-23 23:00:17 $
+ *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-07-08 01:05:01 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -34,17 +34,17 @@
 
 testDescription tests[] = {
-                              {testImageFFT,"600-testImageFFT",0},
-                              {testImageRealImaginary,"601-testImageRealImaginary",0},
-                              {testImageComplex,"602-testImageComplex",0},
-                              {testImageConjugate,"603-testImageConjugate",0},
-                              {testImagePowerSpectrum,"604-testImagePowerSpectrum",0},
+                              {testImageFFT,600,"psImageFFT",0,false},
+                              {testImageRealImaginary,601,"psImageRealImaginary",0,false},
+                              {testImageComplex,602,"psImageComplex",0,false},
+                              {testImageConjugate,603,"psImageConjugate",0,false},
+                              {testImagePowerSpectrum,604,"psImagePowerSpectrum",0,false},
                               {NULL}
                           };
 
-int main()
+int main(int argc, char* argv[])
 {
     psLogSetLevel(PS_LOG_INFO);
 
-    if (! runTestSuite(stderr,"psFFT",tests)) {
+    if (! runTestSuite(stderr,"psFFT",tests,argc,argv) ) {
         psAbort(__FILE__,"One or more tests failed");
     }
Index: /trunk/psLib/test/image/tst_psImageIO.c
===================================================================
--- /trunk/psLib/test/image/tst_psImageIO.c	(revision 1192)
+++ /trunk/psLib/test/image/tst_psImageIO.c	(revision 1193)
@@ -6,6 +6,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.4 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-06-23 23:00:17 $
+ *  @version $Revision: 1.5 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-07-08 01:05:01 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -35,16 +35,14 @@
 
 testDescription tests[] = {
-                              {testImageRead,"567-testImageRead",0},
-                              {testImageWrite,"569-testImageWrite",0},
+                              {testImageRead,567,"psImageReadSection",0,false},
+                              {testImageWrite,569,"psImageWriteSection",0,false},
                               {NULL}
                           };
 
-int main()
+int main(int argc, char* argv[])
 {
     psLogSetLevel(PS_LOG_INFO);
 
-    testImageRead();
-
-    if (! runTestSuite(stderr,"psImage",tests)) {
+    if (! runTestSuite(stderr,"psImage",tests,argc,argv)) {
         psAbort(__FILE__,"One or more tests failed");
     }
Index: /trunk/psLib/test/psTest.c
===================================================================
--- /trunk/psLib/test/psTest.c	(revision 1192)
+++ /trunk/psLib/test/psTest.c	(revision 1193)
@@ -15,4 +15,6 @@
 #include <unistd.h>
 #include <sys/wait.h>
+#include <stdbool.h>
+#include <string.h>
 
 #include "psTest.h"
@@ -25,11 +27,103 @@
 #define HEADER_BOTTOM "\\**********************************************************************************/\n\n"
 
-bool p_runTestSuite(FILE *fp, const char* testPointFile, const char* packageName, testDescription tests[])
+bool p_runTestSuite(FILE *fp, const char* testPointFile, const char* packageName,
+                    testDescription tests[], int argc, char * const argv[])
 {
     bool success = true;
-
-    for (int index=0; tests[index].fcn != NULL; index++) {
-        success = p_runTest(fp,testPointFile,packageName,tests[index].testPointName,
-                            tests[index].fcn,tests[index].expectedReturn) && success;
+    bool runAll = true;
+    bool useFork = true;
+    bool found;
+    int c;
+    int n;
+    extern char *optarg;
+
+    if (argc > 0) {
+        while ( (c=getopt(argc,argv,"lhn:dt:")) != -1) {
+            switch (c) {
+            case 'h':
+                printf("Usage: %s [-l] [-d] [-h] [-n=Testpoint#] [-t=TestpointName]\n"
+                       "    where:\n"
+                       "           -l  : lists the testpoints contained in this test driver executable\n"
+                       "           -d  : turns on debugger-friendly mode (no forking, aborts/signals are not handled)\n"
+                       "           -h  : prints this help\n"
+                       "           -n  : specifies a particular testpoint by number to run\n"
+                       "           -t  : specifies a particular testpoint by name to run\n"
+                       "    (if no -l, -n or -t options are given, all testpoints are run)\n",
+                       argv[0]);
+                runAll = false;
+                break;
+            case 'd':
+                useFork = false;
+                break;
+            case 'l':
+                printf("Test Driver:  %s\n",testPointFile);
+                printf("Package Name: %s\n",packageName);
+                printf("Testpoints:\n");
+                runAll = false;
+                for (int index=0; tests[index].fcn != NULL; index++) {
+                    printf("    %6d - %s \n",tests[index].testPointNumber,
+                           tests[index].testPointName);
+                }
+                printf("\n");
+                break;
+            case 't':
+                runAll = false;
+                for (int index=0; tests[index].fcn != NULL; index++) {
+                    if (strcmp(optarg,tests[index].testPointName) == 0) {
+                        success = p_runTest(fp,
+                                            testPointFile,
+                                            packageName,
+                                            tests[index].testPointName,
+                                            tests[index].fcn,
+                                            tests[index].expectedReturn,
+                                            useFork) && success;
+                    }
+                }
+                break;
+            case 'n':
+                runAll = false;
+                if (sscanf(optarg,"%i",&n) != 1) {
+                    psError(__func__,"Failed to parse the testpoint number (%s).",
+                            optarg);
+                    break;
+                }
+                found = false;
+                for (int index=0; tests[index].fcn != NULL; index++) {
+                    if (n==tests[index].testPointNumber) {
+                        found = true;
+                        success = p_runTest(fp,
+                                            testPointFile,
+                                            packageName,
+                                            tests[index].testPointName,
+                                            tests[index].fcn,
+                                            tests[index].expectedReturn,
+                                            useFork) && success;
+                    }
+                }
+                if (! found) {
+                    psError(__func__,"The specified testpoint number (%d) doesn't exist in this test driver.",
+                            n);
+                    break;
+                }
+                break;
+            case '?':
+                psError(__func__,"Option %s is not recognized and is ignored.",optarg);
+                break;
+            }
+        }
+    }
+
+    if (runAll) {
+        for (int index=0; tests[index].fcn != NULL; index++) {
+            if (! tests[index].isDuplicateEntry) {
+                success = p_runTest(fp,
+                                    testPointFile,
+                                    packageName,
+                                    tests[index].testPointName,
+                                    tests[index].fcn,
+                                    tests[index].expectedReturn,
+                                    useFork) && success;
+            }
+        }
     }
     return success;
@@ -37,5 +131,5 @@
 
 bool p_runTest(FILE *fp, const char* testPointFile, const char* packageName, const char* testPointName,
-               testFcn fcn, int expectedReturn)
+               testFcn fcn, int expectedReturn, bool useFork)
 {
     int childReturn = 0;
@@ -44,28 +138,41 @@
     p_printPositiveTestHeader(fp,testPointFile,packageName,testPointName);
 
-    child = fork();
-    if (child == 0) {                   // I am the child process, run the test
+    if (useFork) {
+        child = fork();
+        if (child == 0) {                   // I am the child process, run the test
+            int currentId = psMemGetId();
+            int retVal = fcn();
+            if (retVal == 0) { // only bother checking memory if test executed to end.
+                if (psMemCheckLeaks(currentId,NULL,stderr) != 0) {
+                    psError(__func__,"Memory Leaks Detected");
+                    retVal = 64;
+                }
+                psMemCheckCorruption(1);
+            }
+            exit(retVal);
+        } else if (child < 0) {
+            fprintf(fp,"Couldn't fork a process to run a negative test (%s|%s)",
+                    packageName, testPointName);
+            abort();
+        }
+
+        waitpid(child,&childReturn,0);
+        if (WIFSIGNALED(childReturn)) {
+            childReturn =  -WTERMSIG(childReturn);
+        } else {
+            childReturn = WEXITSTATUS(childReturn);
+        }
+    } else {
         int currentId = psMemGetId();
-        int retVal = fcn();
-        if (retVal == 0) { // only bother checking memory if test executed to end.
+        childReturn = fcn();
+        if (childReturn == 0) { // only bother checking memory if test executed to end.
             if (psMemCheckLeaks(currentId,NULL,stderr) != 0) {
                 psError(__func__,"Memory Leaks Detected");
-                retVal = 64;
+                childReturn = 64;
             }
             psMemCheckCorruption(1);
         }
-        exit(retVal);
-    } else if (child < 0) {
-        fprintf(fp,"Couldn't fork a process to run a negative test (%s|%s)",
-                packageName, testPointName);
-        abort();
-    }
-
-    waitpid(child,&childReturn,0);
-    if (WIFSIGNALED(childReturn)) {
-        childReturn =  -WTERMSIG(childReturn);
-    } else {
-        childReturn = WEXITSTATUS(childReturn);
-    }
+    }
+
 
     if (childReturn != expectedReturn) {
Index: /trunk/psLib/test/psTest.h
===================================================================
--- /trunk/psLib/test/psTest.h	(revision 1192)
+++ /trunk/psLib/test/psTest.h	(revision 1193)
@@ -20,31 +20,62 @@
 {
     testFcn     fcn;
+    int         testPointNumber;
     const char* testPointName;
     int         expectedReturn;
+    bool        isDuplicateEntry;
 }
 testDescription;
 
-#define runTest(filePtr, packageName, testPointName, fcn, expectedReturn) \
-p_runTest(filePtr, __FILE__, packageName, testPointName, fcn, expectedReturn)
+#define runTest(filePtr, packageName, testPointName, fcn, expectedReturn, useFork) \
+p_runTest(filePtr, __FILE__, packageName, testPointName, fcn, expectedReturn, useFork)
 
-#define runTestSuite(filePtr, packageName, tests) \
-p_runTestSuite(filePtr, __FILE__, packageName, tests)
+#define runTestSuite(filePtr, packageName, tests, argc, argv) \
+p_runTestSuite(filePtr, __FILE__, packageName, tests, argc, argv)
 
 
 /////////////////////////// PRIVATE FUNCTIONS //////////////////////////////
 
-bool p_runTest(FILE *fp, const char* testPointFile, const char* packageName, const char* testPointName,
-               testFcn fcn, int expectedReturn);
+bool p_runTest(
+    FILE *fp,
+    const char* testPointFile,
+    const char* packageName,
+    const char* testPointName,
+    testFcn fcn,
+    int expectedReturn,
+    bool useFork
+);
 
-bool p_runTestSuite(FILE *fp, const char* testPointFile, const char* packageName, testDescription tests[]);
+bool p_runTestSuite(
+    FILE *fp,
+    const char* testPointFile,
+    const char* packageName,
+    testDescription tests[],
+    int argc,
+    char * const argv[]
+);
 
-void p_printPositiveTestHeader(FILE *fp, const char* testPointFile, const char* packageName,
-                               const char* testPointName);
+void p_printPositiveTestHeader(
+    FILE *fp,
+    const char* testPointFile,
+    const char* packageName,
+    const char* testPointName
+);
 
-void p_printNegativeTestHeader(FILE *fp, const char* testPointFile, const char* packageName,
-                               const char* testPointName,const char* expectedError, int exitValue);
+void p_printNegativeTestHeader(
+    FILE *fp,
+    const char* testPointFile,
+    const char* packageName,
+    const char* testPointName,
+    const char* expectedError,
+    int exitValue
+);
 
-void p_printFooter(FILE *fp, const char* testPointFile, const char* packageName, const char* testPointName,
-                   bool success);
+void p_printFooter(
+    FILE *fp,
+    const char* testPointFile,
+    const char* packageName,
+    const char* testPointName,
+    bool success
+);
 
 #endif
Index: /trunk/psLib/test/sysUtils/builddir/tst_psMemory.d
===================================================================
--- /trunk/psLib/test/sysUtils/builddir/tst_psMemory.d	(revision 1192)
+++ /trunk/psLib/test/sysUtils/builddir/tst_psMemory.d	(revision 1193)
@@ -3,6 +3,6 @@
   ../../include/psTrace.h ../../include/psAbort.h ../../include/psError.h \
   ../../include/psString.h ../../include/psType.h ../../include/psList.h \
-  ../../include/psVector.h ../../include/psHash.h \
-  ../../include/psScalar.h ../../include/psImage.h \
+  ../../include/psCompare.h ../../include/psVector.h \
+  ../../include/psHash.h ../../include/psScalar.h ../../include/psImage.h \
   ../../include/psBitSet.h ../../include/psSort.h ../../include/psStats.h \
   ../../include/psMatrix.h ../../include/psMatrixVectorArithmetic.h \
Index: /trunk/psLib/test/sysUtils/tst_psMemory.c
===================================================================
--- /trunk/psLib/test/sysUtils/tst_psMemory.c	(revision 1192)
+++ /trunk/psLib/test/sysUtils/tst_psMemory.c	(revision 1193)
@@ -6,6 +6,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.18 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-06-25 21:51:46 $
+ *  @version $Revision: 1.19 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-07-08 01:05:01 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -45,20 +45,21 @@
 
 testDescription tests[] = {
-                              {TPCheckBufferPositive,"449-TPCheckBufferPositive",0},
-                              {TPOutOfMemory,"450-TPOutOfMemory",-6},
-                              {TPReallocOutOfMemory,"562-TPReallocOutOfMemory",-6},
-                              {TPrealloc,"451-TPrealloc",0},
-                              {TPallocCallback,"452/453-TPallocCallback",0},
-                              {TPcheckLeaks,"454-TPcheckLeaks",0},
-                              {TPmemCorruption,"455-TPmemCorruption",0},
-                              {TPFreeReferencedMemory,"456-TPFreeReferencedMemory",0},
+                              {TPCheckBufferPositive,449,"checkBufferPositive",0,false},
+                              {TPOutOfMemory,450,"outOfMemory",-6,false},
+                              {TPReallocOutOfMemory,562,"reallocOutOfMemory",-6,false},
+                              {TPrealloc,451,"psRealloc",0,false},
+                              {TPallocCallback,452,"allocCallback",0,false},
+                              {TPallocCallback,453,"allocCallback2",0,true},
+                              {TPcheckLeaks,454,"checkLeaks",0,false},
+                              {TPmemCorruption,455,"psMemCorruption",0,false},
+                              {TPFreeReferencedMemory,456,"freeReferencedMemory",0,false},
                               {NULL}
                           };
 
-int main()
+int main(int argc, char* argv[])
 {
     psLogSetLevel(PS_LOG_INFO);
 
-    if (! runTestSuite(stderr,"psMemory",tests)) {
+    if (! runTestSuite(stderr,"psMemory",tests,argc,argv) ) {
         psError(__FILE__,"One or more tests failed");
         return 1;
