Index: trunk/psLib/src/image/psImage.c
===================================================================
--- trunk/psLib/src/image/psImage.c	(revision 816)
+++ trunk/psLib/src/image/psImage.c	(revision 820)
@@ -9,6 +9,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.20 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-05-29 01:42:12 $
+ *  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-06-01 20:00:08 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -18,5 +18,7 @@
 /*  INCLUDE FILES                                                             */
 /******************************************************************************/
+
 #include <string.h>
+#include <math.h>
 
 #include "psMemory.h"
@@ -384,2 +386,94 @@
 }
 
+int psImageClip(psImage* input,float min,float vmin,float max,float vmax)
+{
+    int numClipped = 0;
+    psU32 numRows;
+    psU32 numCols;
+
+    if (input == NULL) {
+        return 0;
+    }
+    numRows = input->numRows;
+    numCols = input->numCols;
+
+    switch (input->type.type) {
+
+        #define psImageClipCase(type) \
+    case PS_TYPE_##type: { \
+            ps##type minimum = (ps##type) min; \
+            ps##type maximum = (ps##type) max; \
+            for (psU32 row = 0;row<numRows;row++) { \
+                ps##type* inputRow = input->data.type[row]; \
+                for (psU32 col = 0; col < numCols; col++) { \
+                    if (inputRow[col] < minimum) { \
+                        inputRow[col] = (ps##type)vmin; \
+                        numClipped++; \
+                    } else if (inputRow[col] > maximum) { \
+                        inputRow[col] = (ps##type)vmax; \
+                        numClipped++; \
+                    } \
+                } \
+            } \
+        } \
+        break;
+
+        psImageClipCase(S8)
+        psImageClipCase(S16)
+        psImageClipCase(S32)
+        psImageClipCase(S64)
+        psImageClipCase(U8)
+        psImageClipCase(U16)
+        psImageClipCase(U32)
+        psImageClipCase(U64)
+        psImageClipCase(F32)
+        psImageClipCase(F64)
+
+    default:
+        psError(__func__,"psImageClip does not support the given datatype (%d)",
+                input->type.type);
+    }
+
+    return numClipped;
+}
+
+int psImageClipNaN(psImage* input,float value)
+{
+    int numClipped = 0;
+    psU32 numRows;
+    psU32 numCols;
+
+    if (input == NULL) {
+        return 0;
+    }
+    numRows = input->numRows;
+    numCols = input->numCols;
+
+    switch (input->type.type) {
+
+        #define psImageClipNaNCase(type) \
+    case PS_TYPE_##type: { \
+            for (psU32 row = 0;row<numRows;row++) { \
+                ps##type* inputRow = input->data.type[row]; \
+                for (psU32 col = 0; col < numCols; col++) { \
+                    if (! isfinite(inputRow[col])) { \
+                        inputRow[col] = (ps##type)value; \
+                        numClipped++; \
+                    } \
+                } \
+            } \
+        } \
+        break;
+
+        psImageClipNaNCase(F32)
+        psImageClipNaNCase(F64)
+        psImageClipNaNCase(C32)
+        psImageClipNaNCase(C64)
+
+    default:
+        psError(__func__,"psImageClip does not support the given datatype (%d)",
+                input->type.type);
+    }
+
+    return numClipped;
+}
