Index: /trunk/psLib/src/image/psImage.c
===================================================================
--- /trunk/psLib/src/image/psImage.c	(revision 2104)
+++ /trunk/psLib/src/image/psImage.c	(revision 2105)
@@ -10,6 +10,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.49 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-13 00:10:50 $
+ *  @version $Revision: 1.50 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-14 01:22:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -441,6 +441,6 @@
         psF64 unexposedValue) \
 { \
-    int intX = (int) round((psF64)(x) - 0.5); \
-    int intY = (int) round((psF64)(y) - 0.5); \
+    int intX = (int) round((psF64)(x) - 0.5 + FLT_EPSILON); \
+    int intY = (int) round((psF64)(y) - 0.5 + FLT_EPSILON); \
     int lastX = input->numCols - 1; \
     int lastY = input->numRows - 1; \
Index: /trunk/psLib/src/image/psImage.h
===================================================================
--- /trunk/psLib/src/image/psImage.h	(revision 2104)
+++ /trunk/psLib/src/image/psImage.h	(revision 2105)
@@ -11,6 +11,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.40 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-13 00:10:50 $
+ *  @version $Revision: 1.41 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-14 01:22:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -31,8 +31,9 @@
  */
 typedef enum {
-    PS_INTERPOLATE_FLAT,               ///< 'flat' interpolation (nearest pixel)
+    PS_INTERPOLATE_FLAT = 1,           ///< 'flat' interpolation (nearest pixel)
     PS_INTERPOLATE_BILINEAR,           ///< bi-linear interpolation
     PS_INTERPOLATE_BICUBIC,            ///< bi-cubic interpolation
-    PS_INTERPOLATE_SINC                ///< sinc interpolation
+    PS_INTERPOLATE_SINC,               ///< sinc interpolation
+    PS_INTERPOLATE_NUM_MODES           ///< end-marker of list of modes; not a valid interpolation mode
 } psImageInterpolateMode;
 
Index: /trunk/psLib/src/image/psImageExtraction.c
===================================================================
--- /trunk/psLib/src/image/psImageExtraction.c	(revision 2104)
+++ /trunk/psLib/src/image/psImageExtraction.c	(revision 2105)
@@ -9,6 +9,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.25 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-13 23:34:57 $
+ *  @version $Revision: 1.26 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-14 01:22:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -543,4 +543,13 @@
     }
 
+    if (mode < PS_INTERPOLATE_FLAT || mode >= PS_INTERPOLATE_NUM_MODES) {
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageResample",
+                   PS_ERR_BAD_PARAMETER_VALUE, true,
+                   PS_ERRORTEXT_psImageManip_INTERPOLATION_MODE_UNSUPPORTED,
+                   mode);
+        psFree(out);
+        return NULL;
+    }
+
     if (mask != NULL) {
         if (numRows != mask->numRows || numCols != mask->numCols) {
Index: /trunk/psLib/src/image/psImageManip.c
===================================================================
--- /trunk/psLib/src/image/psImageManip.c	(revision 2104)
+++ /trunk/psLib/src/image/psImageManip.c	(revision 2105)
@@ -10,6 +10,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.27 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-02 02:08:00 $
+ *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-14 01:22:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -569,4 +569,23 @@
         return NULL;
     }
+
+    if (scale < 1) {
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageResample",
+                   PS_ERR_BAD_PARAMETER_VALUE, true,
+                   PS_ERRORTEXT_psImageManip_SCALE_NOT_POSITIVE,
+                   scale);
+        psFree(out);
+        return NULL;
+    }
+
+    if (mode < PS_INTERPOLATE_FLAT || mode >= PS_INTERPOLATE_NUM_MODES) {
+        psErrorMsg(PS_ERRORNAME_DOMAIN "psImageResample",
+                   PS_ERR_BAD_PARAMETER_VALUE, true,
+                   PS_ERRORTEXT_psImageManip_INTERPOLATION_MODE_UNSUPPORTED,
+                   mode);
+        psFree(out);
+        return NULL;
+    }
+
     // create an output image of the same size
     // and type
@@ -582,5 +601,5 @@
             float inRow = (float)row * invScale; \
             for (int col=0;col<outCols;col++) { \
-                rowData[col] = psImagePixelInterpolate(in,inRow,(float)col*invScale,NULL,0,0,mode); \
+                rowData[col] = psImagePixelInterpolate(in,(float)col*invScale,inRow,NULL,0,0,mode); \
             } \
         }  \
Index: /trunk/psLib/src/mathtypes/psImage.c
===================================================================
--- /trunk/psLib/src/mathtypes/psImage.c	(revision 2104)
+++ /trunk/psLib/src/mathtypes/psImage.c	(revision 2105)
@@ -10,6 +10,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.49 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-13 00:10:50 $
+ *  @version $Revision: 1.50 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-14 01:22:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -441,6 +441,6 @@
         psF64 unexposedValue) \
 { \
-    int intX = (int) round((psF64)(x) - 0.5); \
-    int intY = (int) round((psF64)(y) - 0.5); \
+    int intX = (int) round((psF64)(x) - 0.5 + FLT_EPSILON); \
+    int intY = (int) round((psF64)(y) - 0.5 + FLT_EPSILON); \
     int lastX = input->numCols - 1; \
     int lastY = input->numRows - 1; \
Index: /trunk/psLib/src/mathtypes/psImage.h
===================================================================
--- /trunk/psLib/src/mathtypes/psImage.h	(revision 2104)
+++ /trunk/psLib/src/mathtypes/psImage.h	(revision 2105)
@@ -11,6 +11,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.40 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-13 00:10:50 $
+ *  @version $Revision: 1.41 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-14 01:22:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -31,8 +31,9 @@
  */
 typedef enum {
-    PS_INTERPOLATE_FLAT,               ///< 'flat' interpolation (nearest pixel)
+    PS_INTERPOLATE_FLAT = 1,           ///< 'flat' interpolation (nearest pixel)
     PS_INTERPOLATE_BILINEAR,           ///< bi-linear interpolation
     PS_INTERPOLATE_BICUBIC,            ///< bi-cubic interpolation
-    PS_INTERPOLATE_SINC                ///< sinc interpolation
+    PS_INTERPOLATE_SINC,               ///< sinc interpolation
+    PS_INTERPOLATE_NUM_MODES           ///< end-marker of list of modes; not a valid interpolation mode
 } psImageInterpolateMode;
 
Index: /trunk/psLib/test/image/tst_psImageManip.c
===================================================================
--- /trunk/psLib/test/image/tst_psImageManip.c	(revision 2104)
+++ /trunk/psLib/test/image/tst_psImageManip.c	(revision 2105)
@@ -6,6 +6,6 @@
  *  @author Robert DeSonia, MHPCC
  *
- *  @version $Revision: 1.28 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-10-02 02:23:05 $
+ *  @version $Revision: 1.29 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-10-14 01:22:59 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -34,4 +34,5 @@
 static int testImageShift(void);
 static int testImageShiftCase(int cols, int rows, float colShift,float rowShift);
+static int testImageResample(void);
 
 testDescription tests[] = {
@@ -44,4 +45,5 @@
                               {testImageRotate,560,"psImageRotate",0,false},
                               {testImageShift,561,"psImageShift",0,false},
+                              {testImageResample,743,"psImageResample",0,false},
                               {NULL}
                           };
@@ -1704,2 +1706,119 @@
     return 0;
 }
+
+static int testImageResample(void)
+{
+
+    int rows = 60;
+    int cols = 80;
+    psImage* result = NULL;
+    int scale = 4;
+    psErr* err;
+
+    psImage* image = psImageAlloc(cols,rows,PS_TYPE_F32);
+    for(int row=0;row<rows;row++) {
+        psF32* imageRow = image->data.F32[row];
+        for (int col=0;col<cols;col++) {
+            imageRow[col] = row+2*col;
+        }
+    }
+    result = psImageCopy(NULL,image,PS_TYPE_F64);
+    psImage* orig = result;
+    result = psImageResample(result,image,scale,PS_INTERPOLATE_FLAT);
+
+    if (result == NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "NULL return unexpected");
+        return 1;
+    }
+
+    if (result != orig) {
+        psLogMsg(__func__,PS_LOG_ERROR,"failure to recycle image.");
+        return 2;
+    }
+
+    if (result->type.type != PS_TYPE_F32) {
+        psLogMsg(__func__,PS_LOG_ERROR,"unexpected type");
+        return 3;
+    }
+
+
+    if (result->numCols != image->numCols*scale ||
+            result->numRows != image->numRows*scale) {
+        psLogMsg(__func__,PS_LOG_ERROR,"The size of the result is %dx%d, but %dx%d was expected.",
+                 result->numCols,result->numRows,
+                 image->numCols*scale, image->numRows*scale);
+        return 4;
+    }
+
+    psF32 truthValue;
+    for(int row=0;row<result->numRows;row++) {
+        for (int col=0;col<result->numCols;col++) {
+            truthValue = psImagePixelInterpolate(image,
+                                                 (float)col/(float)scale,(float)row/(float)scale,
+                                                 NULL,0,-1,PS_INTERPOLATE_FLAT);
+            if (fabs(truthValue - result->data.F32[row][col]) > FLT_EPSILON) {
+                psLogMsg(__func__,PS_LOG_ERROR,"value bad at (%d,%d).  Got %g, expected %g.",
+                         col,row,result->data.F32[row][col], truthValue);
+                return 5;
+            }
+        }
+    }
+
+    // verify that image=null is handled properly.
+    psErrorClear();
+    result = psImageResample(result,NULL,scale,PS_INTERPOLATE_FLAT);
+
+    if (result != NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "return was not NULL, as expected.");
+        return 6;
+    }
+    err = psErrorLast();
+    if (err->code != PS_ERR_BAD_PARAMETER_NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "error message was not appropriate type.");
+        return 7;
+    }
+    psFree(err);
+
+    // verify that scale < 1 is handled properly
+    psErrorClear();
+    result = psImageResample(result,image,0,PS_INTERPOLATE_FLAT);
+
+    if (result != NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "return was not NULL, as expected.");
+        return 8;
+    }
+    err = psErrorLast();
+    if (err->code != PS_ERR_BAD_PARAMETER_VALUE) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "error message was not appropriate type.");
+        return 9;
+    }
+    psFree(err);
+
+    // verify that invalid interpolation mode is handled properly
+    psErrorClear();
+    result = psImageResample(result,image,2,0);
+
+    if (result != NULL) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "return was not NULL, as expected.");
+        return 10;
+    }
+    err = psErrorLast();
+    if (err->code != PS_ERR_BAD_PARAMETER_VALUE) {
+        psLogMsg(__func__,PS_LOG_ERROR,
+                 "error message was not appropriate type.");
+        return 11;
+    }
+    psFree(err);
+
+    psFree(image);
+    psFree(result);
+
+    return 0;
+}
+
Index: /trunk/psLib/test/image/verified/tst_psImageExtraction.stderr
===================================================================
--- /trunk/psLib/test/image/verified/tst_psImageExtraction.stderr	(revision 2104)
+++ /trunk/psLib/test/image/verified/tst_psImageExtraction.stderr	(revision 2105)
@@ -138,9 +138,9 @@
     Following should be an error.
 <DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
-    Input psImage mask size, 2000x1000, does not match psImage input size, 1869636978x1635018016.
-<DATE><TIME>|<HOST>|I|testImageSlice
-    Following should be an error.
-<DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
-    Input psImage mask size, 2000x1000, does not match psImage input size, 1869636978x1635018016.
+    Input psImage mask size, 2000x1000, does not match psImage input size, 1919250543x543519841.
+<DATE><TIME>|<HOST>|I|testImageSlice
+    Following should be an error.
+<DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
+    Input psImage mask size, 2000x1000, does not match psImage input size, 1919250543x543519841.
 <DATE><TIME>|<HOST>|I|testImageSlice
     Following should be an error.
@@ -150,21 +150,21 @@
     Following should be an error.
 <DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
-    Input psImage mask size, 2000x1000, does not match psImage input size, 1869636978x1635018016.
-<DATE><TIME>|<HOST>|I|testImageSlice
-    Following should be an error.
-<DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
-    Input psImage mask size, 2000x1000, does not match psImage input size, 1869636978x1635018016.
-<DATE><TIME>|<HOST>|I|testImageSlice
-    Following should be an error.
-<DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
-    Input psImage mask size, 2000x1000, does not match psImage input size, 1869636978x1635018016.
-<DATE><TIME>|<HOST>|I|testImageSlice
-    Following should be an error.
-<DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
-    Input psImage mask size, 2000x1000, does not match psImage input size, 1869636978x1635018016.
-<DATE><TIME>|<HOST>|I|testImageSlice
-    Following should be an error.
-<DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
-    Input psImage mask size, 2000x1000, does not match psImage input size, 1869636978x1635018016.
+    Input psImage mask size, 2000x1000, does not match psImage input size, 1919250543x543519841.
+<DATE><TIME>|<HOST>|I|testImageSlice
+    Following should be an error.
+<DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
+    Input psImage mask size, 2000x1000, does not match psImage input size, 1919250543x543519841.
+<DATE><TIME>|<HOST>|I|testImageSlice
+    Following should be an error.
+<DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
+    Input psImage mask size, 2000x1000, does not match psImage input size, 1919250543x543519841.
+<DATE><TIME>|<HOST>|I|testImageSlice
+    Following should be an error.
+<DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
+    Input psImage mask size, 2000x1000, does not match psImage input size, 1919250543x543519841.
+<DATE><TIME>|<HOST>|I|testImageSlice
+    Following should be an error.
+<DATE><TIME>|<HOST>|E|psLib.image.psImageSlice
+    Input psImage mask size, 2000x1000, does not match psImage input size, 1919250543x543519841.
 <DATE><TIME>|<HOST>|I|testImageSlice
     Following should be an error mask size != image size.
Index: /trunk/psLib/test/image/verified/tst_psImageManip.stderr
===================================================================
--- /trunk/psLib/test/image/verified/tst_psImageManip.stderr	(revision 2104)
+++ /trunk/psLib/test/image/verified/tst_psImageManip.stderr	(revision 2105)
@@ -307,2 +307,17 @@
 ---> TESTPOINT PASSED (psImage{psImageShift} | tst_psImageManip.c)
 
+/***************************** TESTPOINT ******************************************\
+*             TestFile: tst_psImageManip.c                                         *
+*            TestPoint: psImage{psImageResample}                                   *
+*             TestType: Positive                                                   *
+\**********************************************************************************/
+
+<DATE><TIME>|<HOST>|E|psLib.image.psImageResample
+    Can not operate on a NULL psImage.
+<DATE><TIME>|<HOST>|E|psLib.image.psImageResample
+    Specified scale value, 0, must be a positive value.
+<DATE><TIME>|<HOST>|E|psLib.image.psImageResample
+    Specified interpolation mode, 0, is unsupported.
+
+---> TESTPOINT PASSED (psImage{psImageResample} | tst_psImageManip.c)
+
