Index: trunk/psLib/src/image/psImageManip.c
===================================================================
--- trunk/psLib/src/image/psImageManip.c	(revision 1520)
+++ trunk/psLib/src/image/psImageManip.c	(revision 1604)
@@ -11,6 +11,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.15 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-08-13 00:02:03 $
+ *  @version $Revision: 1.16 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-08-20 02:48:38 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -31,5 +31,9 @@
 #include "psImageExtraction.h"
 
-int psImageClip(psImage* input, psF64 min, psF64 vmin, psF64 max, psF64 vmax)
+int psImageClip(psImage* input,
+                psF64 min,
+                psF64 vmin,
+                psF64 max,
+                psF64 vmax)
 {
     int numClipped = 0;
@@ -125,5 +129,6 @@
 }
 
-int psImageClipNaN(psImage* input, psF64 value)
+int psImageClipNaN(psImage* input,
+                   psF64 value)
 {
     int numClipped = 0;
@@ -164,5 +169,9 @@
 }
 
-int psImageOverlaySection(psImage* image, const psImage* overlay, int col0, int row0, const char *op)
+int psImageOverlaySection(psImage* image,
+                          const psImage* overlay,
+                          int col0,
+                          int row0,
+                          const char *op)
 {
     unsigned int imageNumRows;
@@ -267,5 +276,9 @@
 }
 
-int psImageClipComplexRegion(psImage* input, psC64 min, psC64 vmin, psC64 max, psC64 vmax)
+int psImageClipComplexRegion(psImage* input,
+                             psC64 min,
+                             psC64 vmin,
+                             psC64 max,
+                             psC64 vmax)
 {
     int numClipped = 0;
@@ -340,5 +353,10 @@
 }
 
-psImage* psImageRebin(psImage* out, const psImage* in, unsigned int scale, const psStats* stats)
+psImage* psImageRebin(psImage* out,
+                      const psImage* in,
+                      const psImage* restrict mask,
+                      unsigned int maskVal,
+                      unsigned int scale,
+                      const psStats* stats)
 {
     int inRows;
@@ -346,8 +364,7 @@
     int outRows;
     int outCols;
-    psVector* vec;              // vector to hold
-
-    // the values of
-    // a single bin.
+    psVector* vec;                     // vector to hold the values of a single bin.
+    psVector* maskVec = NULL;          // vector to hold the mask of a single bin.
+    psMaskType* maskData = NULL;
     psStats* myStats;
     double statVal;
@@ -377,25 +394,36 @@
     }
 
+    vec = psVectorAlloc(scale * scale, in->type.type);
+
+    if (mask != NULL) {
+        if (mask->type.type != PS_TYPE_MASK) {
+            psError(__func__, "The mask datatype must be %s (%d).",
+                    PS_TYPE_MASK_NAME,
+                    mask->type.type);
+            psFree(out);
+            psFree(vec);
+            return NULL;
+        }
+        maskVec = psVectorAlloc(scale * scale, PS_TYPE_MASK);
+        maskData = maskVec->data.PS_TYPE_MASK_DATA;
+    }
+
     myStats = psAlloc(sizeof(psStats));
     *myStats = *stats;
-
-    vec = psVectorAlloc(scale * scale, in->type.type);
 
     // create output image.
     inRows = in->numRows;
     inCols = in->numCols;
-    outRows = (inRows + scale - 1) / scale;     // round-up
-    // for
-    // remainders
-    outCols = (inCols + scale - 1) / scale;     // round-up
-    // for
-    // remainders
+    outRows = (inRows + scale - 1) / scale;     // round-up for remainders
+    outCols = (inCols + scale - 1) / scale;     // round-up for remainders
     out = psImageRecycle(out, outCols, outRows, in->type.type);
 
     #define PS_IMAGE_REBIN_CASE(type) \
 case PS_TYPE_##type: { \
+        ps##type* outRowData; \
         ps##type* vecData = vec->data.type; \
+        psMaskType* inRowMask = NULL; \
         for (int row = 0; row < outRows; row++) { \
-            ps##type* outRowData = out->data.type[row]; \
+            outRowData = out->data.type[row]; \
             int inCurrentRow = row*scale; \
             int inNextRow = (row+1)*scale; \
@@ -406,10 +434,16 @@
                 for (int inRow = inCurrentRow; inRow < inNextRow && inRow < inRows; inRow++) { \
                     ps##type* inRowData = in->data.type[inRow]; \
+                    if (mask != NULL) { \
+                        inRowMask = mask->data.PS_TYPE_MASK_DATA[inRow]; \
+                    } \
                     for (int inCol = inCurrentCol; inCol < inNextCol && inCol < inCols; inCol++) { \
+                        if (maskData != NULL) { \
+                            maskData[n] = inRowMask[inCol]; \
+                        } \
                         vecData[n++] = inRowData[inCol]; \
                     } \
                 } \
                 vec->n = n; \
-                myStats = psVectorStats(myStats,vec,NULL,0); \
+                myStats = psVectorStats(myStats,vec,maskVec,maskVal); \
                 p_psGetStatValue(myStats,&statVal); \
                 outRowData[col] = (ps##type)statVal; \
@@ -444,5 +478,8 @@
 }
 
-psImage* psImageResample(psImage* out, const psImage* in, int scale, psImageInterpolateMode mode)
+psImage* psImageResample(psImage* out,
+                         const psImage* in,
+                         int scale,
+                         psImageInterpolateMode mode)
 {
     int outRows;
@@ -496,5 +533,8 @@
 }
 
-psImage* psImageRoll(psImage* out, const psImage* in, int dx, int dy)
+psImage* psImageRoll(psImage* out,
+                     const psImage* in,
+                     int dx,
+                     int dy)
 {
     int outRows;
@@ -808,5 +848,8 @@
 psImage* psImageShift(psImage* out,
                       const psImage* in,
-                      float dx, float dy, psF64 unexposedValue, psImageInterpolateMode mode)
+                      float dx,
+                      float dy,
+                      psF64 unexposedValue,
+                      psImageInterpolateMode mode)
 {
     int outRows;
