Index: trunk/psLib/src/math/psRegion.c
===================================================================
--- trunk/psLib/src/math/psRegion.c	(revision 10999)
+++ trunk/psLib/src/math/psRegion.c	(revision 13741)
@@ -8,4 +8,5 @@
 #include "psError.h"
 #include "psAssert.h"
+#include "psConstants.h"
 #include "psRegion.h"
 
@@ -83,4 +84,48 @@
 }
 
+psRegion psRegionAndParityFromString(int *xParity, int *yParity, const char* region)
+{
+    PS_ASSERT_PTR_NON_NULL (xParity, psRegionSet(NAN,NAN,NAN,NAN));
+    PS_ASSERT_PTR_NON_NULL (yParity, psRegionSet(NAN,NAN,NAN,NAN));
+
+    psS32 col0;
+    psS32 col1;
+    psS32 row0;
+    psS32 row1;
+
+    // unless otherwise detected
+    *xParity = +1;
+    *yParity = +1;
+
+    // section should be of the form '[col0:col1,row0:row1]'
+    if (region == NULL) {
+        return psRegionSet(0,0,0,0);
+    }
+
+    if (sscanf(region,"[%d:%d,%d:%d]",&col0,&col1,&row0,&row1) < 4) {
+        psError(PS_ERR_BAD_PARAMETER_NULL, true,
+                _("Specified subsection string, '%s', can not be parsed.  Must be in the form '[x1:x2,y1:y2]'."),
+                region);
+        return psRegionSet(NAN,NAN,NAN,NAN);
+    }
+
+    // [0:0,0:0] is complete image region
+    if ((col0 == 0) && (col1 == 0) && (row0 == 0) && (row1 == 0)) {
+        return psRegionSet(0,0,0,0);
+    }
+
+    if ((col1 > 0) && (col0 > col1)) {
+	*xParity = -1;
+	PS_SWAP (col0, col1);
+    }
+
+    if ((row1 > 0) && (row0 > row1)) {
+	*yParity = -1;
+	PS_SWAP (row0, row1);
+    }
+
+    return psRegionSet(col0-1,col1,row0-1,row1);
+}
+
 psString psRegionToString(const psRegion region)
 {
