Update check in opj_tcd_makelayer to be robust to different float precisions
authorMatthieu Darbois <mayeut@users.noreply.github.com>
Thu, 10 Sep 2015 13:46:51 +0000 (15:46 +0200)
committerMatthieu Darbois <mayeut@users.noreply.github.com>
Thu, 10 Sep 2015 13:46:51 +0000 (15:46 +0200)
src/lib/openjp2/tcd.c

index d227e388f1e82259ba65c18606b226ceb0a257bb..32db260b124dd9856657e14000e70ea83671ee6b 100644 (file)
@@ -268,7 +268,7 @@ void opj_tcd_makelayer( opj_tcd_t *tcd,
                                                                         n = passno + 1;
                                                                 continue;
                                                         }
-                                                        if (dd / dr > thresh)
+                                                        if (thresh - (dd / dr) <= DBL_EPSILON) /* do not rely on float equality, check with DBL_EPSILON margin */
                                                                 n = passno + 1;
                                                 }
 
@@ -565,7 +565,7 @@ OPJ_BOOL opj_tcd_rateallocate(  opj_tcd_t *tcd,
                         opj_t2_destroy(t2);
                 } else {
                         success = OPJ_TRUE;
-                        goodthresh = min - DBL_EPSILON; /* do not rely on float equality for lossless transform */
+                        goodthresh = min;
                 }
 
                 if (!success) {