Index: trunk/psLib/test/image/tst_psImage.c
===================================================================
--- trunk/psLib/test/image/tst_psImage.c	(revision 856)
+++ trunk/psLib/test/image/tst_psImage.c	(revision 938)
@@ -6,6 +6,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.10 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-06-04 03:12:11 $
+ *  @version $Revision: 1.11 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-06-08 23:57:00 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -24,4 +24,5 @@
 static int testImageSubset(void);
 static int testImageCopy(void);
+static int testImageClip(void);
 
 testDescription tests[] = {
@@ -29,4 +30,5 @@
                               {testImageSubset,"547/550-testImageSubset",0},
                               {testImageCopy,"551-testImageCopy",0},
+                              {testImageClip,"571-testImageClip",0},
                               {NULL}
                           };
@@ -618,2 +620,115 @@
     return 0;
 }
+
+int testImageClip(void)
+{
+    psImage* img = NULL;
+    unsigned int c = 128;
+    unsigned int r = 256;
+    psF32 min;
+    psF32 max;
+    int currentId = psMemGetId();
+    int numClipped = 0;
+    int retVal;
+
+    psLogMsg(__func__,PS_LOG_INFO,
+             "psImageClip shall limit the minimum and maximum data value within a psImage structure");
+
+    /*
+
+        psImageClip shall limit the minimum and maximum data value within a
+        psImage structure to a specified min and max value.
+
+        Verify the returned integer is equal to the number of pixels clipped,
+        if the input psImage structure contains known values and input parameters
+        min and max have know values.
+
+        Verify the psImage structure specified by the input parameter input is
+        modified to contain the expected values, if the input psImage structure
+        contains known values, min and max are specified and vmin and vmax
+        parameters are known.
+
+        Verify the retuned integer is zero, psImage structure input is unmodified
+        and program executions doesn't stop, if input parameter psImage structure
+        pointer is null.
+
+        Verify the retuned integer is zero, psImage structure input is unmodified
+        and program executions doesn't stop, if input parameter min is larger than max.
+    */
+
+    // create image
+    #define testImageClipByType(datatype) \
+    img = psImageAlloc(c,r,PS_TYPE_##datatype); \
+    for (unsigned row=0;row<r;row++) { \
+        ps##datatype* imgRow = img->data.datatype[row]; \
+        for (unsigned col=0;col<c;col++) { \
+            imgRow[col] = (ps##datatype)(row+col); \
+        } \
+    } \
+    min = (float)r/2.0f; \
+    max = (float)r; \
+    \
+    retVal = psImageClip(img,min,-1.0f,max,-2.0f); \
+    \
+    numClipped = 0; \
+    for (unsigned row=0;row<r;row++) { \
+        ps##datatype* imgRow = img->data.datatype[row]; \
+        for (unsigned col=0;col<c;col++) { \
+            ps##datatype value = (ps##datatype)(row+col); \
+            if (value < (ps##datatype)min) { \
+                numClipped++; \
+                value = -1; \
+            } else if (value > (ps##datatype)max) { \
+                numClipped++; \
+                value = -2; \
+            } \
+            if (fabsf(imgRow[col]-value) > FLT_EPSILON) { \
+                psError(__func__,"Pixel value is not as expected (%d vs %d) at %d,%d", \
+                        imgRow[col],value,col,row); \
+                return 1; \
+            } \
+        } \
+    } \
+    if (retVal != numClipped) { \
+        psError(__func__,"Expected %d clips, but got %d", \
+                numClipped,retVal); \
+        return 2; \
+    } \
+    psImageFree(img);
+
+    testImageClipByType(F64);
+    testImageClipByType(F32);
+    testImageClipByType(S64);
+    testImageClipByType(S32);
+    testImageClipByType(S16);
+    testImageClipByType(S8);
+    testImageClipByType(U64);
+    testImageClipByType(U32);
+    testImageClipByType(U16);
+    testImageClipByType(U8);
+
+    // Verify the retuned integer is zero, psImage structure input is unmodified
+    // and program executions doesn't stop, if input parameter psImage structure
+    // pointer is null.
+    retVal = psImageClip(NULL,min,-1.0f,max,-2.0f);
+    if (retVal != 0) {
+        psError(__func__,"Expected zero return for clips of a NULL image.");
+        return 3;
+    }
+
+    // Verify the retuned integer is zero, psImage structure input is unmodified
+    // and program executions doesn't stop, if input parameter min is larger than max.
+    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error (max<min)");
+    retVal = psImageClip(img,max,-1.0f,min,-2.0f);
+    if (retVal != 0) {
+        psError(__func__,"Expected zero return for clips when max < min.");
+        return 4;
+    }
+
+    if (psMemCheckLeaks(currentId,NULL,NULL) != 0) {
+        psAbort(__func__,"Memory Leaks!");
+    }
+    psMemCheckCorruption(1);
+
+    return 0;
+}
