Index: /trunk/psLib/src/image/psImage.c
===================================================================
--- /trunk/psLib/src/image/psImage.c	(revision 820)
+++ /trunk/psLib/src/image/psImage.c	(revision 821)
@@ -9,6 +9,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-06-01 20:00:08 $
+ *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-06-01 21:30:47 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -389,6 +389,6 @@
 {
     int numClipped = 0;
-    psU32 numRows;
-    psU32 numCols;
+    unsigned int numRows;
+    unsigned int numCols;
 
     if (input == NULL) {
@@ -400,11 +400,11 @@
     switch (input->type.type) {
 
-        #define psImageClipCase(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++) { \
+            for (unsigned int row = 0;row<numRows;row++) { \
                 ps##type* inputRow = input->data.type[row]; \
-                for (psU32 col = 0; col < numCols; col++) { \
+                for (unsigned int col = 0; col < numCols; col++) { \
                     if (inputRow[col] < minimum) { \
                         inputRow[col] = (ps##type)vmin; \
@@ -441,6 +441,6 @@
 {
     int numClipped = 0;
-    psU32 numRows;
-    psU32 numCols;
+    unsigned int numRows;
+    unsigned int numCols;
 
     if (input == NULL) {
@@ -453,12 +453,11 @@
 
         #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++; \
-                    } \
+    case PS_TYPE_##type: \
+        for (unsigned int row = 0;row<numRows;row++) { \
+            ps##type* inputRow = input->data.type[row]; \
+            for (unsigned int col = 0; col < numCols; col++) { \
+                if (! isfinite(inputRow[col])) { \
+                    inputRow[col] = (ps##type)value; \
+                    numClipped++; \
                 } \
             } \
@@ -478,2 +477,102 @@
     return numClipped;
 }
+
+int psImageOverlaySection(psImage* image, const psImage* overlay, int col0,
+                          int row0, const char* op)
+{
+    unsigned int imageNumRows;
+    unsigned int imageNumCols;
+    unsigned int overlayNumRows;
+    unsigned int overlayNumCols;
+    unsigned int imageRowLimit;
+    unsigned int imageColLimit;
+    psElemType  type;
+
+    if (image == NULL || overlay == NULL) {
+        psError(__func__,"one of the input images was NULL.");
+        return 1;
+    }
+
+    if (op == NULL) {
+        psError(__func__,"Operation can not be NULL.");
+        return 1;
+    }
+
+    type = image->type.type;
+
+    if (type != overlay->type.type) {
+        psError(__func__,"Image and overlay datatypes must match. (%d vs %d)",
+                type,overlay->type.type);
+        return 2;
+    }
+
+    imageNumRows = image->numRows;
+    imageNumCols = image->numCols;
+    overlayNumRows = overlay->numRows;
+    overlayNumCols = overlay->numCols;
+
+    /* check row0/col0 to see if it is within the image size */
+    if (row0 < 0 || col0 < 0 || row0 >= imageNumRows || col0 >= imageNumCols) {
+        psError(__func__, "Overlay origin of (%d,%d) is outside of the image dimensions (%d x %d).",
+                col0, row0, imageNumCols, imageNumRows);
+        return 3;
+    }
+
+    /* check if overlay is totally withing input image */
+    imageRowLimit = row0+overlayNumRows;
+    imageColLimit = col0+overlayNumCols;
+    if (imageRowLimit > imageNumRows || imageColLimit > imageNumCols) {
+        psError(__func__, "Overlay image (%d,%d -> %d,%d) is partially outside"
+                " of the input image (%d x %d).",
+                col0, row0, col0+overlayNumCols-1, row0+overlayNumRows-1,
+                imageNumCols,imageNumRows);
+        return 4;
+    }
+
+    switch (type) {
+
+        #define psImageOverlayCase(DATATYPE) \
+    case PS_TYPE_##DATATYPE: \
+        for (unsigned int row=row0;row<imageRowLimit;row++) { \
+            ps##DATATYPE* imageRow = image->data.DATATYPE[row]; \
+            ps##DATATYPE* overlayRow = overlay->data.DATATYPE[row-row0]; \
+            for (unsigned int col=col0;col<imageColLimit;col++) { \
+                switch (*op) { \
+                case '+': \
+                    imageRow[col] += overlayRow[col-col0]; \
+                    break; \
+                case '-': \
+                    imageRow[col] -= overlayRow[col-col0]; \
+                    break; \
+                case '*': \
+                    imageRow[col] *= overlayRow[col-col0]; \
+                    break; \
+                case '/': \
+                    imageRow[col] /= overlayRow[col-col0]; \
+                    break; \
+                default: \
+                    psError(__func__,"Unknown operation %s",op); \
+                    return 5; \
+                } \
+            } \
+        }
+
+        psImageOverlayCase(U8);
+        psImageOverlayCase(U16);
+        psImageOverlayCase(U32);
+        psImageOverlayCase(U64);
+        psImageOverlayCase(S8);
+        psImageOverlayCase(S16);
+        psImageOverlayCase(S32);
+        psImageOverlayCase(S64);
+        psImageOverlayCase(F32);
+        psImageOverlayCase(F64);
+        psImageOverlayCase(C32);
+        psImageOverlayCase(C64);
+
+    default:
+        psError(__func__,"Can not operate on type %d.",type);
+    }
+
+    return 0;
+}
Index: /trunk/psLib/src/mathtypes/psImage.c
===================================================================
--- /trunk/psLib/src/mathtypes/psImage.c	(revision 820)
+++ /trunk/psLib/src/mathtypes/psImage.c	(revision 821)
@@ -9,6 +9,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.21 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-06-01 20:00:08 $
+ *  @version $Revision: 1.22 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-06-01 21:30:47 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -389,6 +389,6 @@
 {
     int numClipped = 0;
-    psU32 numRows;
-    psU32 numCols;
+    unsigned int numRows;
+    unsigned int numCols;
 
     if (input == NULL) {
@@ -400,11 +400,11 @@
     switch (input->type.type) {
 
-        #define psImageClipCase(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++) { \
+            for (unsigned int row = 0;row<numRows;row++) { \
                 ps##type* inputRow = input->data.type[row]; \
-                for (psU32 col = 0; col < numCols; col++) { \
+                for (unsigned int col = 0; col < numCols; col++) { \
                     if (inputRow[col] < minimum) { \
                         inputRow[col] = (ps##type)vmin; \
@@ -441,6 +441,6 @@
 {
     int numClipped = 0;
-    psU32 numRows;
-    psU32 numCols;
+    unsigned int numRows;
+    unsigned int numCols;
 
     if (input == NULL) {
@@ -453,12 +453,11 @@
 
         #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++; \
-                    } \
+    case PS_TYPE_##type: \
+        for (unsigned int row = 0;row<numRows;row++) { \
+            ps##type* inputRow = input->data.type[row]; \
+            for (unsigned int col = 0; col < numCols; col++) { \
+                if (! isfinite(inputRow[col])) { \
+                    inputRow[col] = (ps##type)value; \
+                    numClipped++; \
                 } \
             } \
@@ -478,2 +477,102 @@
     return numClipped;
 }
+
+int psImageOverlaySection(psImage* image, const psImage* overlay, int col0,
+                          int row0, const char* op)
+{
+    unsigned int imageNumRows;
+    unsigned int imageNumCols;
+    unsigned int overlayNumRows;
+    unsigned int overlayNumCols;
+    unsigned int imageRowLimit;
+    unsigned int imageColLimit;
+    psElemType  type;
+
+    if (image == NULL || overlay == NULL) {
+        psError(__func__,"one of the input images was NULL.");
+        return 1;
+    }
+
+    if (op == NULL) {
+        psError(__func__,"Operation can not be NULL.");
+        return 1;
+    }
+
+    type = image->type.type;
+
+    if (type != overlay->type.type) {
+        psError(__func__,"Image and overlay datatypes must match. (%d vs %d)",
+                type,overlay->type.type);
+        return 2;
+    }
+
+    imageNumRows = image->numRows;
+    imageNumCols = image->numCols;
+    overlayNumRows = overlay->numRows;
+    overlayNumCols = overlay->numCols;
+
+    /* check row0/col0 to see if it is within the image size */
+    if (row0 < 0 || col0 < 0 || row0 >= imageNumRows || col0 >= imageNumCols) {
+        psError(__func__, "Overlay origin of (%d,%d) is outside of the image dimensions (%d x %d).",
+                col0, row0, imageNumCols, imageNumRows);
+        return 3;
+    }
+
+    /* check if overlay is totally withing input image */
+    imageRowLimit = row0+overlayNumRows;
+    imageColLimit = col0+overlayNumCols;
+    if (imageRowLimit > imageNumRows || imageColLimit > imageNumCols) {
+        psError(__func__, "Overlay image (%d,%d -> %d,%d) is partially outside"
+                " of the input image (%d x %d).",
+                col0, row0, col0+overlayNumCols-1, row0+overlayNumRows-1,
+                imageNumCols,imageNumRows);
+        return 4;
+    }
+
+    switch (type) {
+
+        #define psImageOverlayCase(DATATYPE) \
+    case PS_TYPE_##DATATYPE: \
+        for (unsigned int row=row0;row<imageRowLimit;row++) { \
+            ps##DATATYPE* imageRow = image->data.DATATYPE[row]; \
+            ps##DATATYPE* overlayRow = overlay->data.DATATYPE[row-row0]; \
+            for (unsigned int col=col0;col<imageColLimit;col++) { \
+                switch (*op) { \
+                case '+': \
+                    imageRow[col] += overlayRow[col-col0]; \
+                    break; \
+                case '-': \
+                    imageRow[col] -= overlayRow[col-col0]; \
+                    break; \
+                case '*': \
+                    imageRow[col] *= overlayRow[col-col0]; \
+                    break; \
+                case '/': \
+                    imageRow[col] /= overlayRow[col-col0]; \
+                    break; \
+                default: \
+                    psError(__func__,"Unknown operation %s",op); \
+                    return 5; \
+                } \
+            } \
+        }
+
+        psImageOverlayCase(U8);
+        psImageOverlayCase(U16);
+        psImageOverlayCase(U32);
+        psImageOverlayCase(U64);
+        psImageOverlayCase(S8);
+        psImageOverlayCase(S16);
+        psImageOverlayCase(S32);
+        psImageOverlayCase(S64);
+        psImageOverlayCase(F32);
+        psImageOverlayCase(F64);
+        psImageOverlayCase(C32);
+        psImageOverlayCase(C64);
+
+    default:
+        psError(__func__,"Can not operate on type %d.",type);
+    }
+
+    return 0;
+}
