Index: trunk/psLib/test/image/tst_psImageManip.c
===================================================================
--- trunk/psLib/test/image/tst_psImageManip.c	(revision 1212)
+++ trunk/psLib/test/image/tst_psImageManip.c	(revision 1217)
@@ -1,11 +1,11 @@
-/** @file  tst_psImage.c
+/** @file  tst_psImageManip.c
  *
- *  @brief Contains the tests for psImage.[ch]
+ *  @brief Contains the tests for psImageManip.[ch]
  *
  *
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.1 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-07-13 01:37:59 $
+ *  @version $Revision: 1.2 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-07-14 23:23:42 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -16,4 +16,5 @@
 #include <string.h>
 #include <stdlib.h>
+#include <string.h>                    // for memset
 
 #include "psTest.h"
@@ -24,4 +25,5 @@
 static int testImageClipNAN(void);
 static int testImageOverlay(void);
+static int testImageRebin(void);
 
 testDescription tests[] = {
@@ -29,4 +31,5 @@
                               {testImageClipNAN,572,"psImageClipNAN",0,false},
                               {testImageOverlay,573,"psImageOverlay",0,false},
+                              {testImageRebin,559,"psImageRebin",0,false},
                               {NULL}
                           };
@@ -460,2 +463,176 @@
     return 0;
 }
+
+static int testImageRebin(void)
+{
+
+    /*
+    This function shall generate a rescaled version of a psImage structure derived from a specified statistics method.
+    */
+
+    psImage* in = NULL;
+    psImage* out = NULL;
+    psImage* out2 = NULL;
+    psImage* meanTruth = NULL;
+    psImage* maxTruth = NULL;
+    psStats stats;
+
+    /*
+    Verify the returned psImage structure contains expected values, if the input parameter input contains known data, the input scale is a known value with a known statistical method specified in stats. Cases should include at least two different scales and statistical methods. Comparison of expected values should include a delta to allow testing on different platforms.
+    */
+
+    in = psImageAlloc(16,16,PS_TYPE_F32);
+    meanTruth = psImageAlloc(4,4,PS_TYPE_F32);
+    maxTruth = psImageAlloc(6,6,PS_TYPE_F32);
+    memset(meanTruth->data.F32[0],0,sizeof(psF32)*4*4);
+    memset(maxTruth->data.F32[0],0,sizeof(psF32)*6*6);
+
+    for (int row = 0; row<16; row++) {
+        psF32* inRow = in->data.F32[row];
+        psF32* meanTruthRow = meanTruth->data.F32[row/4];
+        psF32* maxTruthRow = maxTruth->data.F32[row/3];
+        for (int col = 0; col<16; col++) {
+            inRow[col] = row + col;
+            meanTruthRow[col/4] += row + col;
+            if (maxTruthRow[col/3] < row + col) {
+                maxTruthRow[col/3] = row+col;
+            }
+        }
+    }
+    for (int row = 0; row<4; row++) {
+        psF32* meanTruthRow = meanTruth->data.F32[row];
+        for (int col = 0; col<4; col++) {
+            meanTruthRow[col] /= 16;
+        }
+    }
+
+    stats.options = PS_STAT_SAMPLE_MEAN;
+    out = psImageRebin(NULL,in,4,&stats);
+
+    if (out == NULL) {
+        psError(__func__,"psImageRebin returned a NULL pointer!?");
+        return 1;
+    }
+
+    if (out->numRows != 4 || out->numCols != 4) {
+        psError(__func__,"psImageRebin didn't produce the proper size image (%d x %d).",
+                out->numCols, out->numRows);
+        return 2;
+    }
+
+    for (int row = 0; row<4; row++) {
+        psF32* outRow = out->data.F32[row];
+        psF32* truthRow = meanTruth->data.F32[row];
+        for (int col = 0; col<4; col++) {
+            if (fabsf(outRow[col]-truthRow[col]) > FLT_EPSILON) {
+                psError(__func__,"psImageRebin didn't produce the proper result at (%d,%d) [%f vs %f].",
+                        col,row,outRow[col],truthRow[col]);
+                return 3;
+            }
+        }
+    }
+
+    stats.options = PS_STAT_MAX;
+    out2 = psImageRebin(out,in,3,&stats);
+
+    // Verify the returned psImage structure is equal to the input parameter out if specified.
+    if (out != out2) {
+        psError(__func__,"psImageRebin didn't recycle a psImage properly!?");
+        return 7;
+    }
+
+    if (out == NULL) {
+        psError(__func__,"psImageRebin returned a NULL pointer!?");
+        return 4;
+    }
+
+    if (out->numRows != 6 || out->numCols != 6) {
+        psError(__func__,"psImageRebin didn't produce the proper size image (%d x %d).",
+                out->numCols, out->numRows);
+        return 5;
+    }
+
+    for (int row = 0; row<6; row++) {
+        psF32* outRow = out->data.F32[row];
+        psF32* truthRow = maxTruth->data.F32[row];
+        for (int col = 0; col<6; col++) {
+            if (fabsf(outRow[col]-truthRow[col]) > FLT_EPSILON) {
+                psError(__func__,"psImageRebin didn't produce the proper result at (%d,%d) [%f vs %f].",
+                        col,row,outRow[col],truthRow[col]);
+                return 6;
+            }
+        }
+    }
+
+    // Verify the returned psImage structure is null and program execution
+    // doesn't stop, if the input parameter input is null.
+
+    out2 = psImageRebin(NULL,NULL,1,&stats);
+
+    if (out2 != NULL) {
+        psError(__func__,"psImageRebin returned an image though the input was NULL!?");
+        return 8;
+    }
+
+    // Verify the returned psImage structure is null and program execution
+    // doesn't stop, if the input parameter scale is less than or equal to zero.
+    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");
+    out2 = psImageRebin(NULL,in,0,&stats);
+
+    if (out2 != NULL) {
+        psError(__func__,"psImageRebin returned an image though the scale was zero!?");
+        return 9;
+    }
+
+    // Verify the returned psImage structure is null and program execution
+    // doesn't stop, if the input parameter stats is null.
+    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");
+    out2 = psImageRebin(NULL,in,1,NULL);
+
+    if (out2 != NULL) {
+        psError(__func__,"psImageRebin returned an image though the stats was NULL!?");
+        return 10;
+    }
+
+    // Verify the returned psImage structure is null and program execution
+    // doesn't stop, if the input parameter psStats structure member options
+    // is zero or any value which doesn't correspond to a valid statistical
+    // method.
+    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");
+    stats.options = 0;
+    out2 = psImageRebin(NULL,in,1,&stats);
+
+    if (out2 != NULL) {
+        psError(__func__,"psImageRebin returned an image though the stats options was zero!?");
+        return 11;
+    }
+
+    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");
+    stats.options = PS_STAT_USE_RANGE;
+    out2 = psImageRebin(NULL,in,1,&stats);
+
+    if (out2 != NULL) {
+        psError(__func__,"psImageRebin returned an image though the stats options was PS_STAT_USE_RANGE!?");
+        return 12;
+    }
+
+    // Verify the returned psImage structure is null and program execution
+    // doesn't stop, if the input parameter psStats structure member options
+    // specifies more than one valid statistical method.
+    psLogMsg(__func__,PS_LOG_INFO,"Following should be an error.");
+    stats.options = PS_STAT_SAMPLE_MEAN + PS_STAT_MAX;
+    out2 = psImageRebin(NULL,in,1,&stats);
+
+    if (out2 != NULL) {
+        psError(__func__,"psImageRebin returned an image though the stats options was PS_STAT_SAMPLE_MEAN+PS_STAT_MAX!?");
+        return 13;
+    }
+
+
+    psFree(in);
+    psFree(out);
+    psFree(meanTruth);
+    psFree(maxTruth);
+
+    return 0;
+}
