Index: trunk/psLib/src/image/psImage.c
===================================================================
--- trunk/psLib/src/image/psImage.c	(revision 2291)
+++ trunk/psLib/src/image/psImage.c	(revision 2375)
@@ -9,6 +9,6 @@
  *  @author Ross Harman, MHPCC
  *
- *  @version $Revision: 1.53 $ $Name: not supported by cvs2svn $
- *  @date $Date: 2004-11-06 00:44:56 $
+ *  @version $Revision: 1.54 $ $Name: not supported by cvs2svn $
+ *  @date $Date: 2004-11-16 20:00:21 $
  *
  *  Copyright 2004 Maui High Performance Computing Center, University of Hawaii
@@ -26,5 +26,34 @@
 #include "psImageErrors.h"
 
-static void imageFree(psImage* image);
+static void imageFree(psImage* image)
+{
+    if (image == NULL) {
+        return;
+    }
+
+    if (image->type.type == PS_TYPE_PTR) {
+        // 2-D array of pointers -- must dereference elements
+        psU32 oldNumRows = image->numRows;
+        psU32 oldNumCols = image->numCols;
+        psPtr* rowPtr;
+
+        for (psU32 row = 0; row < oldNumRows; row++) {
+            rowPtr = image->data.PTR[row];
+            for (psU32 col = 0; col < oldNumCols; col++) {
+                psMemDecrRefCounter(rowPtr[col]);
+            }
+        }
+    }
+
+    if (image->parent != NULL) {
+        psArrayRemove(image->parent->children,image);
+        image->parent = NULL;
+    }
+
+    psImageFreeChildren(image);
+
+    psFree(image->rawDataBuffer);
+    psFree(image->data.V);
+}
 
 psImage* psImageAlloc(psU32 numCols,
@@ -71,34 +100,52 @@
 }
 
-static void imageFree(psImage* image)
+psRegion* psRegionAlloc(double x0,
+                        double x1,
+                        double y0,
+                        double y1)
 {
-    if (image == NULL) {
-        return;
-    }
-
-    if (image->type.type == PS_TYPE_PTR) {
-        // 2-D array of pointers -- must dereference elements
-        psU32 oldNumRows = image->numRows;
-        psU32 oldNumCols = image->numCols;
-        psPtr* rowPtr;
-
-        for (psU32 row = 0; row < oldNumRows; row++) {
-            rowPtr = image->data.PTR[row];
-            for (psU32 col = 0; col < oldNumCols; col++) {
-                psMemDecrRefCounter(rowPtr[col]);
-            }
-        }
-    }
-
-    if (image->parent != NULL) {
-        psArrayRemove(image->parent->children,image);
-        image->parent = NULL;
-    }
-
-    psImageFreeChildren(image);
-
-    psFree(image->rawDataBuffer);
-    psFree(image->data.V);
-}
+    psRegion* out = psAlloc(sizeof(psRegion));
+
+    out->x0 = x0;
+    out->y0 = y0;
+    out->x1 = x1;
+    out->y1 = y1;
+
+    return out;
+}
+
+
+
+psRegion* psRegionFromString(char* region)
+{
+    psS32 col0;
+    psS32 col1;
+    psS32 row0;
+    psS32 row1;
+
+    // section should be of the form '[col0:col1,row0:row1]'
+    if (region == NULL) {
+        psError(PS_ERR_BAD_PARAMETER_NULL, true,
+                PS_ERRORTEXT_psImage_SUBSECTION_NULL);
+        return NULL;
+    }
+
+    if (sscanf(region,"[%d:%d,%d:%d]",&col0,&col1,&row0,&row1) < 4) {
+        psError(PS_ERR_BAD_PARAMETER_NULL, true,
+                PS_ERRORTEXT_psImage_SUBSECTION_INVALID,
+                region);
+        return NULL;
+    }
+
+    if (col0 > col1 || row0 > row1) {
+        psError(PS_ERR_BAD_PARAMETER_VALUE, true,
+                PS_ERRORTEXT_psImage_SUBSET_RANGE_MALFORMED,
+                col0,col1,row0,row1);
+        return NULL;
+    }
+
+    return psRegionAlloc(col0,col1,row0,row1);
+}
+
 
 psImage* psImageRecycle(psImage* old,
