From 5f02757eef51dc834401e2ba5500312a9edab95e Mon Sep 17 00:00:00 2001 From: mayeut Date: Thu, 10 Sep 2015 00:39:23 +0200 Subject: [PATCH 1/6] Correct lossless issue on linux x86 Update uclouvain/openjpeg#571 --- src/lib/openjp2/tcd.c | 4 ++-- tests/compare_images.c | 2 +- tests/nonregression/CMakeLists.txt | 20 ++++++++++++++++++++ 3 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/lib/openjp2/tcd.c b/src/lib/openjp2/tcd.c index 8f1c94102..df9272ff1 100644 --- a/src/lib/openjp2/tcd.c +++ b/src/lib/openjp2/tcd.c @@ -268,7 +268,7 @@ void opj_tcd_makelayer( opj_tcd_t *tcd, n = passno + 1; continue; } - if (dd / dr >= thresh) + if (dd / dr > thresh) 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; + goodthresh = min - DBL_MAX; /* do not rely on float equality for lossless transform */ } if (!success) { diff --git a/tests/compare_images.c b/tests/compare_images.c index cb1b13011..fa15d13e6 100644 --- a/tests/compare_images.c +++ b/tests/compare_images.c @@ -85,7 +85,7 @@ static void compare_images_help_display(void) fprintf(stdout,"\n"); fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline PGX/TIF/PNM image \n"); fprintf(stdout," -t \t REQUIRED \t filename to the test PGX/TIF/PNM image\n"); - fprintf(stdout," -n \t REQUIRED \t number of component of the image (used to generate correct filename)\n"); + fprintf(stdout," -n \t REQUIRED \t number of component of the image (used to generate correct filename, not used when both input files are TIF)\n"); fprintf(stdout," -m \t OPTIONAL \t list of MSE tolerances, separated by : (size must correspond to the number of component) of \n"); fprintf(stdout," -p \t OPTIONAL \t list of PEAK tolerances, separated by : (size must correspond to the number of component) \n"); fprintf(stdout," -s \t OPTIONAL \t 1 or 2 filename separator to take into account PGX/PNM image with different components, " diff --git a/tests/nonregression/CMakeLists.txt b/tests/nonregression/CMakeLists.txt index 2527f8cb5..5ce37c815 100644 --- a/tests/nonregression/CMakeLists.txt +++ b/tests/nonregression/CMakeLists.txt @@ -353,6 +353,26 @@ foreach(OPJ_TEST_CMD_LINE ${OPJ_TEST_CMD_LINE_LIST}) ) endif() endif(JPYLYZER_EXECUTABLE) + + # If lossless compression (simple test is 4 arguments), decompress & compare + list(LENGTH CMD_ARG_LIST_2 ARG_COUNT) + if (ARG_COUNT EQUAL 4) + # can we compare with the input image ? + if (${INPUT_FILENAME_NAME} MATCHES "\\.tif$") + add_test(NAME NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-lossless-decode + COMMAND opj_decompress -i ${OUTPUT_FILENAME} -o ${OUTPUT_FILENAME}.lossless.tif + ) + set_tests_properties(NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-lossless-decode PROPERTIES + DEPENDS NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-encode + ) + add_test(NAME NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-lossless-compare + COMMAND compare_images -b ${INPUT_FILENAME} -t ${OUTPUT_FILENAME}.lossless.tif -n 1 -d + ) + set_tests_properties(NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-lossless-compare PROPERTIES + DEPENDS NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-lossless-decode + ) + endif() + endif() endif() # DECODER TEST SUITE From 4cde646cd7a1dd4a364bd2b2fabaf832149728a5 Mon Sep 17 00:00:00 2001 From: mayeut Date: Thu, 10 Sep 2015 01:24:46 +0200 Subject: [PATCH 2/6] Add test for uclouvain/openjpeg#571 --- tests/nonregression/test_suite.ctest.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 6f9bba830..7e3a35a87 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -134,6 +134,9 @@ opj_compress -i @INPUT_NR_PATH@/pngsuite/ftp0n2c08.png -o @TEMP_PATH@/ftp0n2c08. opj_compress -i @INPUT_NR_PATH@/pngsuite/ftp0n3p08.png -o @TEMP_PATH@/ftp0n3p08.png.jp2 opj_compress -i @INPUT_NR_PATH@/pngsuite/ftp1n3p08.png -o @TEMP_PATH@/ftp1n3p08.png.jp2 +# issue 571 Lossless is not lossless on linux x86 +opj_compress -i @INPUT_NR_PATH@/issue571.tif -o @TEMP_PATH@/issue571.tif.j2k + # DECODER TEST SUITE opj_decompress -i @INPUT_NR_PATH@/Bretagne2.j2k -o @TEMP_PATH@/Bretagne2.j2k.pgx opj_decompress -i @INPUT_NR_PATH@/_00042.j2k -o @TEMP_PATH@/_00042.j2k.pgx From d7d9f84707a8a93a393666fafedd7b77c59eff37 Mon Sep 17 00:00:00 2001 From: mayeut Date: Thu, 10 Sep 2015 08:04:59 +0200 Subject: [PATCH 3/6] Remove invalid assert in compare_images --- tests/compare_images.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/tests/compare_images.c b/tests/compare_images.c index fa15d13e6..b28d49577 100644 --- a/tests/compare_images.c +++ b/tests/compare_images.c @@ -279,8 +279,6 @@ static opj_image_t* readImageFromFileTIF(const char* filename, int nbFilenamePGX return NULL; } - /* \postconditions */ - assert( image_read->numcomps == 1 || image_read->numcomps == 3 ); return image_read; } From ccdce606f1baa945e5c717064bc17e8218b7cb29 Mon Sep 17 00:00:00 2001 From: Matthieu Darbois Date: Thu, 10 Sep 2015 15:10:14 +0200 Subject: [PATCH 4/6] Fix threshold calculation It doesn't change the outcome of the test suite, that's weird... --- src/lib/openjp2/tcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/openjp2/tcd.c b/src/lib/openjp2/tcd.c index df9272ff1..d227e388f 100644 --- a/src/lib/openjp2/tcd.c +++ b/src/lib/openjp2/tcd.c @@ -565,7 +565,7 @@ OPJ_BOOL opj_tcd_rateallocate( opj_tcd_t *tcd, opj_t2_destroy(t2); } else { success = OPJ_TRUE; - goodthresh = min - DBL_MAX; /* do not rely on float equality for lossless transform */ + goodthresh = min - DBL_EPSILON; /* do not rely on float equality for lossless transform */ } if (!success) { From ee0f3138482fc5ef44f92e6164206bc8df34efe4 Mon Sep 17 00:00:00 2001 From: Matthieu Darbois Date: Thu, 10 Sep 2015 15:46:51 +0200 Subject: [PATCH 5/6] Update check in opj_tcd_makelayer to be robust to different float precisions --- src/lib/openjp2/tcd.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/openjp2/tcd.c b/src/lib/openjp2/tcd.c index d227e388f..32db260b1 100644 --- a/src/lib/openjp2/tcd.c +++ b/src/lib/openjp2/tcd.c @@ -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) { From bac2c9e0a37a79a35e39cbe18572ec40bcfc3f29 Mon Sep 17 00:00:00 2001 From: Matthieu Darbois Date: Fri, 11 Sep 2015 14:17:30 +0200 Subject: [PATCH 6/6] Change test in opj_tcd_makelayer Remove float equality test. Such a test has no meaning. --- src/lib/openjp2/tcd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/openjp2/tcd.c b/src/lib/openjp2/tcd.c index 32db260b1..2fccff1c9 100644 --- a/src/lib/openjp2/tcd.c +++ b/src/lib/openjp2/tcd.c @@ -268,7 +268,7 @@ void opj_tcd_makelayer( opj_tcd_t *tcd, n = passno + 1; continue; } - if (thresh - (dd / dr) <= DBL_EPSILON) /* do not rely on float equality, check with DBL_EPSILON margin */ + if (thresh - (dd / dr) < DBL_EPSILON) /* do not rely on float equality, check with DBL_EPSILON margin */ n = passno + 1; }