about summary refs log tree commit diff
path: root/editor/pamthreshold.c
diff options
context:
space:
mode:
authorgiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2007-05-19 16:23:24 +0000
committergiraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8>2007-05-19 16:23:24 +0000
commite08f19e5b27ad33f42c79ea5e1a9416f38ed97e6 (patch)
tree3bdeb5eb58bb9359c7b0c0758236ab59a80c943e /editor/pamthreshold.c
parent20a8ad58c067b0c4b57419e79712f5b790c8e1c2 (diff)
downloadnetpbm-mirror-e08f19e5b27ad33f42c79ea5e1a9416f38ed97e6.tar.gz
netpbm-mirror-e08f19e5b27ad33f42c79ea5e1a9416f38ed97e6.tar.xz
netpbm-mirror-e08f19e5b27ad33f42c79ea5e1a9416f38ed97e6.zip
Add assertions
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@301 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'editor/pamthreshold.c')
-rw-r--r--editor/pamthreshold.c22
1 files changed, 22 insertions, 0 deletions
diff --git a/editor/pamthreshold.c b/editor/pamthreshold.c
index 4caaed9b..8f4587e0 100644
--- a/editor/pamthreshold.c
+++ b/editor/pamthreshold.c
@@ -48,6 +48,13 @@ struct cmdlineInfo {
 
 
 
+static __inline__ bool
+betweenZeroAndOne(float const arg) {
+    return (arg >= 0.0 && arg <= 1.0);
+}
+
+
+
 struct range {
     /* A range of sample values, normalized to [0, 1] */
     samplen min;
@@ -76,6 +83,16 @@ addToRange(struct range * const rangeP,
 
 
 
+static void
+assertRangeValid(struct range const range) {
+
+    assert(betweenZeroAndOne(range.min));
+    assert(betweenZeroAndOne(range.max));
+    assert(range.max >= range.min);
+}
+
+
+
 static float
 spread(struct range const range) {
 
@@ -416,6 +433,9 @@ computeGlobalThreshold(struct pam *         const inpamP,
     float oldthreshold;        /* stop if oldthreshold==threshold */
     unsigned int iter;         /* count of done iterations */
 
+    assert(betweenZeroAndOne(globalRange.min));
+    assert(betweenZeroAndOne(globalRange.max));
+
     /* Use middle value (halfway between min and max) as initial threshold */
     threshold = (globalRange.min + globalRange.max) / 2.0;
 
@@ -449,6 +469,8 @@ computeGlobalThreshold(struct pam *         const inpamP,
             (black * (globalRange.min + threshold) / 2.0 +
              white * (threshold + globalRange.max) / 2.0) /
             (black + white);
+        
+        assert(betweenZeroAndOne(threshold ));
     }
 
     *thresholdP = threshold;