about summary refs log tree commit diff
path: root/editor/pamthreshold.c
diff options
context:
space:
mode:
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;