diff --git a/src/lib/openjp2/tcd.c b/src/lib/openjp2/tcd.c index 1dd15405d..7380c4bd6 100644 --- a/src/lib/openjp2/tcd.c +++ b/src/lib/openjp2/tcd.c @@ -586,7 +586,9 @@ OPJ_BOOL opj_tcd_rateallocate(opj_tcd_t *tcd, if (distoachieved < distotarget) { hi = thresh; - stable_thresh = thresh; + if (distoachieved > DBL_EPSILON) { + stable_thresh = thresh; + } continue; } else { lo = thresh; @@ -598,7 +600,9 @@ OPJ_BOOL opj_tcd_rateallocate(opj_tcd_t *tcd, if (distoachieved < distotarget) { hi = thresh; - stable_thresh = thresh; + if (distoachieved > DBL_EPSILON) { + stable_thresh = thresh; + } continue; } lo = thresh; @@ -618,7 +622,7 @@ OPJ_BOOL opj_tcd_rateallocate(opj_tcd_t *tcd, } } - goodthresh = stable_thresh == 0 ? thresh : stable_thresh; + goodthresh = stable_thresh == 0 ? lo : stable_thresh; opj_t2_destroy(t2); } else {