From f14da66ce544632aa605ee739d542491cc6f0efb Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Mon, 26 Nov 2012 13:37:33 +0000 Subject: [PATCH 001/333] [trunk] update test suite with issue 191 to 194 and update patch for 191 which should fail properly --- src/lib/openjp2/j2k.c | 4 ++-- tests/nonregression/test_suite.ctest.in | 9 ++++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 05bd3452..2fda7385 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -7883,8 +7883,8 @@ OPJ_BOOL opj_j2k_read_SPCod_SPCoc( opj_j2k_t *p_j2k, ++l_tccp->numresolutions; /* tccp->numresolutions = read() + 1 */ if (l_tccp->numresolutions > OPJ_J2K_MAXRLVLS) { opj_event_msg(p_manager, EVT_ERROR, - "Invalid value for numresolutions : %d\n", - l_tccp->numresolutions); + "Invalid value for numresolutions : %d, max value is set in openjpeg.h at %d\n", + l_tccp->numresolutions, OPJ_J2K_MAXRLVLS); return OPJ_FALSE; } ++l_current_ptr; diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 7ffa0485..0fa89de7 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -74,7 +74,14 @@ opj_decompress -i @INPUT_NR_PATH@/issue104_jpxstream.jp2 -o @TEMP_PATH@/issue10 opj_decompress -i @INPUT_NR_PATH@/mem-b2ace68c-1381.jp2 -o @TEMP_PATH@/mem-b2ace68c-1381.jp2.pgx # File which produced weird output with kakadu and not supoprter by openjpeg (problem with value of TPSot) opj_decompress -i @INPUT_NR_PATH@/mem-b2b86b74-2753.jp2 -o @TEMP_PATH@/mem-b2b86b74-2753.jp2.pgx - +# issue 191 raised by the gdal fuzzer test (should properly failed) +!opj_decompress -i @INPUT_NR_PATH@/gdal_fuzzer_unchecked_numresolutions.jp2 -o @TEMP_PATH@/gdal_fuzzer_unchecked_numresolutions.pgx +# issue 192 raised by the gdal fuzzer test (should properly failed) +opj_decompress -i @INPUT_NR_PATH@/gdal_fuzzer_assert_in_opj_j2k_read_SQcd_SQcc.patch.jp2 -o @TEMP_PATH@/gdal_fuzzer_assert_in_opj_j2k_read_SQcd_SQcc.patch.pgx +# issue 193 raised by the gdal fuzzer test (should properly failed) +opj_decompress -i @INPUT_NR_PATH@/gdal_fuzzer_check_number_of_tiles.jp2 -o @TEMP_PATH@/gdal_fuzzer_check_number_of_tiles.pgx +# issue 194 raised by the gdal fuzzer test (should properly failed) +opj_decompress -i @INPUT_NR_PATH@/gdal_fuzzer_check_comp_dx_dy.jp2 -o @TEMP_PATH@/gdal_fuzzer_check_comp_dx_dy.pgx # decode with specific area # prec=12; nb_c=1 From 48e0d167aa7a9343c7861e38970dbcf57b6bcb54 Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Mon, 26 Nov 2012 15:58:14 +0000 Subject: [PATCH 002/333] [trunk] check the index of the component in read_qcc (thanks Even). fixes issue 192 --- src/lib/openjp2/j2k.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 2fda7385..dccab6de 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -2823,6 +2823,13 @@ static OPJ_BOOL opj_j2k_read_qcc( opj_j2k_t *p_j2k, }; #endif /* USE_JPWL */ + if (l_comp_no >= p_j2k->m_private_image->numcomps) { + opj_event_msg(p_manager, EVT_ERROR, + "Invalid component number: %d, regarding the number of components %d\n", + l_comp_no, p_j2k->m_private_image->numcomps); + return OPJ_FALSE; + } + if (! opj_j2k_read_SQcd_SQcc(p_j2k,l_comp_no,p_header_data,&p_header_size,p_manager)) { opj_event_msg(p_manager, EVT_ERROR, "Error reading QCC marker\n"); return OPJ_FALSE; From 999a84c77a8b4f36021ccb0193128bf61ee5776c Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Mon, 26 Nov 2012 16:03:35 +0000 Subject: [PATCH 003/333] [trunk] test about issue 192 should nicely fail --- tests/nonregression/test_suite.ctest.in | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 0fa89de7..3f2067f6 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -76,8 +76,8 @@ opj_decompress -i @INPUT_NR_PATH@/mem-b2ace68c-1381.jp2 -o @TEMP_PATH@/mem-b2ac opj_decompress -i @INPUT_NR_PATH@/mem-b2b86b74-2753.jp2 -o @TEMP_PATH@/mem-b2b86b74-2753.jp2.pgx # issue 191 raised by the gdal fuzzer test (should properly failed) !opj_decompress -i @INPUT_NR_PATH@/gdal_fuzzer_unchecked_numresolutions.jp2 -o @TEMP_PATH@/gdal_fuzzer_unchecked_numresolutions.pgx -# issue 192 raised by the gdal fuzzer test (should properly failed) -opj_decompress -i @INPUT_NR_PATH@/gdal_fuzzer_assert_in_opj_j2k_read_SQcd_SQcc.patch.jp2 -o @TEMP_PATH@/gdal_fuzzer_assert_in_opj_j2k_read_SQcd_SQcc.patch.pgx +# issue 192 raised by the gdal fuzzer test (should nicely failed) +! opj_decompress -i @INPUT_NR_PATH@/gdal_fuzzer_assert_in_opj_j2k_read_SQcd_SQcc.patch.jp2 -o @TEMP_PATH@/gdal_fuzzer_assert_in_opj_j2k_read_SQcd_SQcc.patch.pgx # issue 193 raised by the gdal fuzzer test (should properly failed) opj_decompress -i @INPUT_NR_PATH@/gdal_fuzzer_check_number_of_tiles.jp2 -o @TEMP_PATH@/gdal_fuzzer_check_number_of_tiles.pgx # issue 194 raised by the gdal fuzzer test (should properly failed) From 1ad85ac9eeb7c0b037e5209c6d3f10e80802790b Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Mon, 26 Nov 2012 16:13:32 +0000 Subject: [PATCH 004/333] [trunk] check if the number of tiles is not incorrect regarding the JPEG2000 norm (thanks Even). Test associated to this issue should nicely fail. Fixes issue 163 --- src/lib/openjp2/j2k.c | 8 ++++++++ tests/nonregression/test_suite.ctest.in | 4 ++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index dccab6de..0c0fb102 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -2034,6 +2034,14 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, /* Compute the number of tiles */ l_cp->tw = opj_int_ceildiv(l_image->x1 - l_cp->tx0, l_cp->tdx); l_cp->th = opj_int_ceildiv(l_image->y1 - l_cp->ty0, l_cp->tdy); + + /* Check that the number of tiles is valid */ + if (l_cp->tw == 0 || l_cp->th == 0 || l_cp->tw > 65535 / l_cp->th) { + opj_event_msg( p_manager, EVT_ERROR, + "Invalid number of tiles : %u x %u (maximum fixed by jpeg2000 norm is 65535 tiles)\n", + l_cp->tw, l_cp->th); + return OPJ_FALSE; + } l_nb_tiles = l_cp->tw * l_cp->th; /* Define the tiles which will be decoded */ diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 3f2067f6..2396a474 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -78,8 +78,8 @@ opj_decompress -i @INPUT_NR_PATH@/mem-b2b86b74-2753.jp2 -o @TEMP_PATH@/mem-b2b8 !opj_decompress -i @INPUT_NR_PATH@/gdal_fuzzer_unchecked_numresolutions.jp2 -o @TEMP_PATH@/gdal_fuzzer_unchecked_numresolutions.pgx # issue 192 raised by the gdal fuzzer test (should nicely failed) ! opj_decompress -i @INPUT_NR_PATH@/gdal_fuzzer_assert_in_opj_j2k_read_SQcd_SQcc.patch.jp2 -o @TEMP_PATH@/gdal_fuzzer_assert_in_opj_j2k_read_SQcd_SQcc.patch.pgx -# issue 193 raised by the gdal fuzzer test (should properly failed) -opj_decompress -i @INPUT_NR_PATH@/gdal_fuzzer_check_number_of_tiles.jp2 -o @TEMP_PATH@/gdal_fuzzer_check_number_of_tiles.pgx +# issue 193 raised by the gdal fuzzer test (should nicely failed) +!opj_decompress -i @INPUT_NR_PATH@/gdal_fuzzer_check_number_of_tiles.jp2 -o @TEMP_PATH@/gdal_fuzzer_check_number_of_tiles.pgx # issue 194 raised by the gdal fuzzer test (should properly failed) opj_decompress -i @INPUT_NR_PATH@/gdal_fuzzer_check_comp_dx_dy.jp2 -o @TEMP_PATH@/gdal_fuzzer_check_comp_dx_dy.pgx From 59582bafa39fc2e0e20e10c0538dbc59d3948deb Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Mon, 26 Nov 2012 16:24:29 +0000 Subject: [PATCH 005/333] [trun[trunk] check if the dx and dy steps are not incorrect according to the JPEG2000 norm (thanks Even). Test associated to this issue should nicely fail. Fixes issue 194 --- src/lib/openjp2/j2k.c | 7 +++++++ tests/nonregression/test_suite.ctest.in | 4 ++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 0c0fb102..3b439fc7 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -1998,6 +1998,13 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, opj_read_bytes(p_header_data,&tmp,1); /* YRsiz_i */ ++p_header_data; l_img_comp->dy = (OPJ_INT32)tmp; /* should be between 1 and 255 */ + if( l_img_comp->dx < 1 || l_img_comp->dx > 255 || + l_img_comp->dy < 1 || l_img_comp->dy > 255 ) { + opj_event_msg(p_manager, EVT_ERROR, + "Invalid values for comp = %d : dx=%u dy=%u\n (should be between 1 and 255 according the JPEG2000 norm)", + i, l_img_comp->dx, l_img_comp->dy); + return OPJ_FALSE; + } #ifdef USE_JPWL if (l_cp->correct) { diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 2396a474..3fc52fe8 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -80,8 +80,8 @@ opj_decompress -i @INPUT_NR_PATH@/mem-b2b86b74-2753.jp2 -o @TEMP_PATH@/mem-b2b8 ! opj_decompress -i @INPUT_NR_PATH@/gdal_fuzzer_assert_in_opj_j2k_read_SQcd_SQcc.patch.jp2 -o @TEMP_PATH@/gdal_fuzzer_assert_in_opj_j2k_read_SQcd_SQcc.patch.pgx # issue 193 raised by the gdal fuzzer test (should nicely failed) !opj_decompress -i @INPUT_NR_PATH@/gdal_fuzzer_check_number_of_tiles.jp2 -o @TEMP_PATH@/gdal_fuzzer_check_number_of_tiles.pgx -# issue 194 raised by the gdal fuzzer test (should properly failed) -opj_decompress -i @INPUT_NR_PATH@/gdal_fuzzer_check_comp_dx_dy.jp2 -o @TEMP_PATH@/gdal_fuzzer_check_comp_dx_dy.pgx +# issue 194 raised by the gdal fuzzer test (should nicely failed) +! opj_decompress -i @INPUT_NR_PATH@/gdal_fuzzer_check_comp_dx_dy.jp2 -o @TEMP_PATH@/gdal_fuzzer_check_comp_dx_dy.pgx # decode with specific area # prec=12; nb_c=1 From ee9d777d69c4e94eab09b15ec6eac1d050750e02 Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Tue, 27 Nov 2012 09:11:16 +0000 Subject: [PATCH 006/333] [trunk] add empty test about the issue 197. Updates issue 197 --- tests/unit/CMakeLists.txt | 4 ++++ tests/unit/testempty0.c | 3 +++ 2 files changed, 7 insertions(+) create mode 100644 tests/unit/testempty0.c diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index 984cedc3..d6bca7ad 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -5,10 +5,14 @@ include_directories( ${OPENJPEG_SOURCE_DIR}/src/lib/openjp2 ) +add_executable(testempty0 testempty0.c) add_executable(testempty1 testempty1.c) add_executable(testempty2 testempty2.c) + +target_link_libraries(testempty0 openjp2) target_link_libraries(testempty1 openjp2) target_link_libraries(testempty2 openjp2) +add_test(testempty0 ${EXECUTABLE_OUTPUT_PATH}/testempty0) add_test(testempty1 ${EXECUTABLE_OUTPUT_PATH}/testempty1) add_test(testempty2 ${EXECUTABLE_OUTPUT_PATH}/testempty2) diff --git a/tests/unit/testempty0.c b/tests/unit/testempty0.c new file mode 100644 index 00000000..32d6f266 --- /dev/null +++ b/tests/unit/testempty0.c @@ -0,0 +1,3 @@ +#include + +int main(int argc, char **argv) { return 0; } From d29c5760bd6649f52813a5f97f0be08f2c957ce7 Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Tue, 27 Nov 2012 09:24:24 +0000 Subject: [PATCH 007/333] [test] update the list of files which will be gracefully rejected when they are dump --- tests/nonregression/CMakeLists.txt | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/nonregression/CMakeLists.txt b/tests/nonregression/CMakeLists.txt index 053233b8..d03eb6aa 100644 --- a/tests/nonregression/CMakeLists.txt +++ b/tests/nonregression/CMakeLists.txt @@ -24,6 +24,10 @@ set(BLACKLIST_JPEG2000 broken2.jp2 broken3.jp2 broken4.jp2 + gdal_fuzzer_assert_in_opj_j2k_read_SQcd_SQcc.patch.jp2 + gdal_fuzzer_check_comp_dx_dy.jp2 + gdal_fuzzer_check_number_of_tiles.jp2 + gdal_fuzzer_unchecked_numresolutions.jp2 ) file(GLOB_RECURSE OPJ_DATA_NR_LIST From 650c5878752869fe794b7115126a3781055fcdeb Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 28 Nov 2012 10:54:33 +0000 Subject: [PATCH 008/333] [trunk] Fix compilation issue where size_t would be undefined --- tests/unit/testempty0.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/unit/testempty0.c b/tests/unit/testempty0.c index 32d6f266..7fbb9d44 100644 --- a/tests/unit/testempty0.c +++ b/tests/unit/testempty0.c @@ -1,3 +1,5 @@ -#include +#include + +#include "openjpeg.h" int main(int argc, char **argv) { return 0; } From be3a1da14a2f81129c59d40b8b69425b670d1575 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 28 Nov 2012 11:46:16 +0000 Subject: [PATCH 009/333] [trunk] Fix issue with ITU-T T.809 (05/2011) - ZSI is now known as NSI (FF54) - NSI now stores Ndim (=3) - CAP extended marker was not set properly --- src/bin/jp3d/opj_jp3d_decompress.c | 3 ++- src/lib/openjp3d/jp3d.c | 33 +++++++++++++++++++++--------- src/lib/openjp3d/jp3d.h | 2 +- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/bin/jp3d/opj_jp3d_decompress.c b/src/bin/jp3d/opj_jp3d_decompress.c index 0a58b678..c2cdb321 100755 --- a/src/bin/jp3d/opj_jp3d_decompress.c +++ b/src/bin/jp3d/opj_jp3d_decompress.c @@ -518,7 +518,8 @@ int main(int argc, char **argv) { fprintf(stdout, "[RESULT] Volume: %d x %d x %d (x %d bpv)\n ", (volume->comps[0].w >> volume->comps[0].factor[0]), (volume->comps[0].h >> volume->comps[0].factor[1]), - (volume->comps[0].l >> volume->comps[0].factor[2]),volume->comps[0].prec); + (volume->comps[0].l >> volume->comps[0].factor[2]), + volume->comps[0].prec); if(original){ psnr = calc_PSNR(original,volume); diff --git a/src/lib/openjp3d/jp3d.c b/src/lib/openjp3d/jp3d.c index 593cda82..95e6ff3b 100755 --- a/src/lib/openjp3d/jp3d.c +++ b/src/lib/openjp3d/jp3d.c @@ -58,15 +58,15 @@ Read the SIZ marker (2D volume and tile size) */ static void j3d_read_siz(opj_j3d_t *j3d); /** -Write the ZSI marker (3rd volume and tile size) +Write the NSI marker (3rd volume and tile size) @param j3d J3D handle */ -static void j3d_write_zsi(opj_j3d_t *j3d); +static void j3d_write_nsi(opj_j3d_t *j3d); /** -Read the ZSI marker (3rd volume and tile size) +Read the NSI marker (3rd volume and tile size) @param j3d J3D handle */ -static void j3d_read_zsi(opj_j3d_t *j3d); +static void j3d_read_nsi(opj_j3d_t *j3d); /** Write the COM marker (comment) @param j3d J3D handle @@ -418,6 +418,10 @@ static void j3d_write_cap(opj_j3d_t *j3d){ lenp = cio_tell(cio); cio_skip(cio, 2); cio_write(cio,J3D_CAP_10, 4); + if( J3D_CAP_10 ) + { + cio_write(cio, 0x0, 2); + } len = cio_tell(cio) - lenp; cio_seek(cio, lenp); cio_write(cio, len, 2); /* Lsiz */ @@ -430,18 +434,24 @@ static void j3d_read_cap(opj_j3d_t *j3d){ /*cio_read(cio, 2); CAP */ len = cio_read(cio, 2); Cap = cio_read(cio, 4); + if(Cap) { + cio_read(cio, 2); + } + assert( len == 2 + 4 + 2 ); } -static void j3d_write_zsi(opj_j3d_t *j3d) { +static void j3d_write_nsi(opj_j3d_t *j3d) { int i; int lenp, len; + int ndim = 3; opj_cio_t *cio = j3d->cio; opj_volume_t *volume = j3d->volume; opj_cp_t *cp = j3d->cp; - cio_write(cio, J3D_MS_ZSI, 2); /* ZSI */ + cio_write(cio, J3D_MS_NSI, 2); /* NSI */ lenp = cio_tell(cio); cio_skip(cio, 2); + cio_write(cio, ndim, 1); /* Ndim */ cio_write(cio, volume->z1, 4); /* Zsiz */ cio_write(cio, volume->z0, 4); /* Z0siz */ cio_write(cio, cp->tdz, 4); /* ZTsiz */ @@ -455,14 +465,17 @@ static void j3d_write_zsi(opj_j3d_t *j3d) { cio_seek(cio, lenp + len); } -static void j3d_read_zsi(opj_j3d_t *j3d) { +static void j3d_read_nsi(opj_j3d_t *j3d) { + int ndim; int len, i; opj_cio_t *cio = j3d->cio; opj_volume_t *volume = j3d->volume; opj_cp_t *cp = j3d->cp; - len = cio_read(cio, 2); /* Lsiz */ + len = cio_read(cio, 2); /* Lnsi */ + ndim = cio_read(cio, 1); /* Ndim */ + assert( ndim == 3 ); volume->z1 = cio_read(cio, 4); /* Zsiz */ volume->z0 = cio_read(cio, 4); /* Z0siz */ cp->tdz = cio_read(cio, 4); /* ZTsiz */ @@ -1545,7 +1558,7 @@ opj_dec_mstabent_t j3d_dec_mstab[] = { {J3D_MS_EOC, J3D_STATE_TPHSOT, j3d_read_eoc}, {J3D_MS_CAP, J3D_STATE_MHSIZ, j3d_read_cap}, {J3D_MS_SIZ, J3D_STATE_MHSIZ, j3d_read_siz}, - {J3D_MS_ZSI, J3D_STATE_MHSIZ, j3d_read_zsi}, + {J3D_MS_NSI, J3D_STATE_MHSIZ, j3d_read_nsi}, {J3D_MS_COD, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_cod}, {J3D_MS_COC, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_coc}, {J3D_MS_RGN, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_rgn}, @@ -2243,7 +2256,7 @@ bool j3d_encode(opj_j3d_t *j3d, opj_cio_t *cio, opj_volume_t *volume, char *inde j3d_write_siz(j3d); if (j3d->cinfo->codec_format == CODEC_J3D) { j3d_write_cap(j3d); - j3d_write_zsi(j3d); + j3d_write_nsi(j3d); } j3d_write_cod(j3d); j3d_write_qcd(j3d); diff --git a/src/lib/openjp3d/jp3d.h b/src/lib/openjp3d/jp3d.h index e9ecf131..edd27a1a 100755 --- a/src/lib/openjp3d/jp3d.h +++ b/src/lib/openjp3d/jp3d.h @@ -65,7 +65,7 @@ The functions in J3D.C have for goal to read/write the several parts of the code #define J3D_MS_EOC 0xffd9 /**< EOC marker value */ #define J3D_MS_CAP 0xff50 /**< CAP marker value */ #define J3D_MS_SIZ 0xff51 /**< SIZ marker value */ -#define J3D_MS_ZSI 0xff54 /**< ZSI marker value */ +#define J3D_MS_NSI 0xff54 /**< NSI marker value */ #define J3D_MS_COD 0xff52 /**< COD marker value */ #define J3D_MS_COC 0xff53 /**< COC marker value */ #define J3D_MS_RGN 0xff5e /**< RGN marker value */ From cab86a0deb03b223bb21dcafb3fd7632714f0e6f Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 28 Nov 2012 12:04:40 +0000 Subject: [PATCH 010/333] [trunk] jp3d: fix command line parsing for subsampling --- src/bin/jp3d/opj_jp3d_compress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/jp3d/opj_jp3d_compress.c b/src/bin/jp3d/opj_jp3d_compress.c index 066de350..b774e149 100755 --- a/src/bin/jp3d/opj_jp3d_compress.c +++ b/src/bin/jp3d/opj_jp3d_compress.c @@ -488,7 +488,7 @@ int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters) case 's': /* subsampling factor */ { - if (sscanf(opj_optarg, "%d,%d,%d", ¶meters->subsampling_dx, ¶meters->subsampling_dy, ¶meters->subsampling_dz) != 2) { + if (sscanf(opj_optarg, "%d,%d,%d", ¶meters->subsampling_dx, ¶meters->subsampling_dy, ¶meters->subsampling_dz) != 3) { fprintf(stdout, "[ERROR] '-s' sub-sampling argument error ! [-s dx,dy,dz]\n"); return 1; } From 7980115412141a82795f37ada12f4eb49d8e81fb Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 28 Nov 2012 12:18:17 +0000 Subject: [PATCH 011/333] [trunk] JP3D fix issue with Registration value in COM marker. Move COM marker just before COD. --- src/lib/openjp3d/jp3d.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/lib/openjp3d/jp3d.c b/src/lib/openjp3d/jp3d.c index 95e6ff3b..e54617b0 100755 --- a/src/lib/openjp3d/jp3d.c +++ b/src/lib/openjp3d/jp3d.c @@ -780,9 +780,7 @@ static void j3d_write_com(opj_j3d_t *j3d) { cio_write(cio, J3D_MS_COM, 2); lenp = cio_tell(cio); cio_skip(cio, 2); - /*cio_write(cio, 0, 2);*/ - cio_write(cio, j3d->cp->transform_format,1); - cio_write(cio, j3d->cp->encoding_format,1); + cio_write(cio, 0, 2); /*opj_event_msg(j3d->cinfo, EVT_INFO, "TRF %D ENCOD %d\n",j3d->cp->transform_format,j3d->cp->encoding_format);*/ if (j3d->cp->comment != NULL) { char *comment = j3d->cp->comment; @@ -2258,6 +2256,10 @@ bool j3d_encode(opj_j3d_t *j3d, opj_cio_t *cio, opj_volume_t *volume, char *inde j3d_write_cap(j3d); j3d_write_nsi(j3d); } + + /*if (j3d->cp->transform_format != TRF_2D_DWT || j3d->cp->encoding_format != ENCOD_2EB)*/ + j3d_write_com(j3d); + j3d_write_cod(j3d); j3d_write_qcd(j3d); for (compno = 0; compno < volume->numcomps; compno++) { @@ -2271,9 +2273,6 @@ bool j3d_encode(opj_j3d_t *j3d, opj_cio_t *cio, opj_volume_t *volume, char *inde if (j3d->volume->comps[0].dcoffset != 0) j3d_write_dco(j3d); - if (j3d->cp->transform_format != TRF_2D_DWT || j3d->cp->encoding_format != ENCOD_2EB) - j3d_write_com(j3d); - /* INDEX >> */ if(volume_info && volume_info->index_on) { volume_info->main_head_end = cio_tell(cio) - 1; From be5e6941bfa341f95fdb10ae5aca4292a50f8767 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 28 Nov 2012 12:21:51 +0000 Subject: [PATCH 012/333] [trunk] JP3D: this is safe to write comment using Registration: ISO-8859-15 --- src/lib/openjp3d/jp3d.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/openjp3d/jp3d.c b/src/lib/openjp3d/jp3d.c index e54617b0..c21d7442 100755 --- a/src/lib/openjp3d/jp3d.c +++ b/src/lib/openjp3d/jp3d.c @@ -780,7 +780,7 @@ static void j3d_write_com(opj_j3d_t *j3d) { cio_write(cio, J3D_MS_COM, 2); lenp = cio_tell(cio); cio_skip(cio, 2); - cio_write(cio, 0, 2); + cio_write(cio, 1, 2); /*opj_event_msg(j3d->cinfo, EVT_INFO, "TRF %D ENCOD %d\n",j3d->cp->transform_format,j3d->cp->encoding_format);*/ if (j3d->cp->comment != NULL) { char *comment = j3d->cp->comment; From 863fdafcd5311db5f5a3de8e26b988f5f9111e5b Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 28 Nov 2012 13:06:02 +0000 Subject: [PATCH 013/333] [trunk] As per T.809 code block are not shifted in JP3D MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Table A.7 3D code-block width, height and depth exponent values xcb = value, ycb = value or zcb = value. NOTE – This redefines Rec. ITU-T T.800 | ISO/IEC 15444-1 significantly! The 3D code-block width, height and depth are limited to powers of two with the minimum size being 20 and the maximum being 210. Further, the 3D code-block size is restricted so that 4 ≤ xcb+ycb+zcb ≤ 18. --- src/lib/openjp3d/jp3d.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/lib/openjp3d/jp3d.c b/src/lib/openjp3d/jp3d.c index c21d7442..de4b2266 100755 --- a/src/lib/openjp3d/jp3d.c +++ b/src/lib/openjp3d/jp3d.c @@ -809,6 +809,7 @@ static void j3d_read_com(opj_j3d_t *j3d) { static void j3d_write_cox(opj_j3d_t *j3d, int compno) { int i; + int shift = 2; opj_cp_t *cp = j3d->cp; opj_tcp_t *tcp = &cp->tcps[j3d->curtileno]; @@ -820,11 +821,15 @@ static void j3d_write_cox(opj_j3d_t *j3d, int compno) { cio_write(cio, tccp->numresolution[1] - 1, 1); /* SPcox (E) No of decomposition levels in y-axis*/ cio_write(cio, tccp->numresolution[2] - 1, 1); /* SPcox (F) No of decomposition levels in z-axis*/ } - /* (cblkw - 2) + (cblkh - 2) + (cblkl - 2) <= 18*/ - cio_write(cio, tccp->cblk[0] - 2, 1); /* SPcox (G) Cblk width entre 10 y 2 (8 y 0)*/ - cio_write(cio, tccp->cblk[1] - 2, 1); /* SPcox (H) Cblk height*/ if (j3d->cinfo->codec_format == CODEC_J3D) { - cio_write(cio, tccp->cblk[2] - 2, 1); /* SPcox (I) Cblk depth*/ + /* Table A.7 */ + shift = 0; + } + /* (cblkw - 2) + (cblkh - 2) + (cblkl - 2) <= 18*/ + cio_write(cio, tccp->cblk[0] - shift, 1); /* SPcox (G) Cblk width entre 10 y 2 (8 y 0)*/ + cio_write(cio, tccp->cblk[1] - shift, 1); /* SPcox (H) Cblk height*/ + if (j3d->cinfo->codec_format == CODEC_J3D) { + cio_write(cio, tccp->cblk[2] - shift, 1); /* SPcox (I) Cblk depth*/ } cio_write(cio, tccp->cblksty, 1); /* SPcox (J) Cblk style*/ cio_write(cio, tccp->dwtid[0], 1); /* SPcox (K) WT in x-axis 15444-2 Table A10*/ @@ -847,6 +852,7 @@ static void j3d_write_cox(opj_j3d_t *j3d, int compno) { static void j3d_read_cox(opj_j3d_t *j3d, int compno) { int i; + int shift = 2; opj_cp_t *cp = j3d->cp; opj_tcp_t *tcp = j3d->state == J3D_STATE_TPH ? &cp->tcps[j3d->curtileno] : j3d->default_tcp; @@ -866,10 +872,14 @@ static void j3d_read_cox(opj_j3d_t *j3d, int compno) { cp->reduce[1] = int_min((tccp->numresolution[1])-1, cp->reduce[1]); cp->reduce[2] = int_min((tccp->numresolution[2])-1, cp->reduce[2]); - tccp->cblk[0] = cio_read(cio, 1) + 2; /* SPcox (G) */ - tccp->cblk[1] = cio_read(cio, 1) + 2; /* SPcox (H) */ + if (j3d->cinfo->codec_format == CODEC_J3D) { + /* Table A.7 */ + shift = 0; + } + tccp->cblk[0] = cio_read(cio, 1) + shift; /* SPcox (G) */ + tccp->cblk[1] = cio_read(cio, 1) + shift; /* SPcox (H) */ if (j3d->cinfo->codec_format == CODEC_J3D) - tccp->cblk[2] = cio_read(cio, 1) + 2; /* SPcox (I) */ + tccp->cblk[2] = cio_read(cio, 1) + shift; /* SPcox (I) */ else tccp->cblk[2] = tccp->cblk[0]; From ba630816bc08c6d8a78817cb9763d6e84cc51dd9 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 28 Nov 2012 13:37:50 +0000 Subject: [PATCH 014/333] [trunk] JP3D codec was trying to pull information from the registration parameter in COM. This is non-standard. --- src/lib/openjp3d/jp3d.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib/openjp3d/jp3d.c b/src/lib/openjp3d/jp3d.c index de4b2266..bbdf0dc5 100755 --- a/src/lib/openjp3d/jp3d.c +++ b/src/lib/openjp3d/jp3d.c @@ -799,9 +799,8 @@ static void j3d_read_com(opj_j3d_t *j3d) { opj_cio_t *cio = j3d->cio; len = cio_read(cio, 2); + cio_read(cio, 2); // read registration - j3d->cp->transform_format = (OPJ_TRANSFORM) cio_read(cio, 1); - j3d->cp->encoding_format = (OPJ_ENTROPY_CODING) cio_read(cio, 1); /*opj_event_msg(j3d->cinfo, EVT_INFO, "TRF %D ENCOD %d\n",j3d->cp->transform_format,j3d->cp->encoding_format);*/ cio_skip(cio, len - 4); /*posible comments*/ @@ -1685,11 +1684,12 @@ void j3d_setup_decoder(opj_j3d_t *j3d, opj_dparameters_t *parameters) { cp->reduce[2] = parameters->cp_reduce[2]; cp->layer = parameters->cp_layer; cp->bigendian = parameters->bigendian; - - - cp->encoding_format = ENCOD_2EB; + + /* MM: Settings of the following two member variables would take + place during j3d_read_com. FIXME */ + cp->encoding_format = ENCOD_3EB; cp->transform_format = TRF_2D_DWT; - + /* keep a link to cp so that we can destroy it later in j3d_destroy_decompress */ j3d->cp = cp; } From 87e09a09da6493b9e25193173091fd56c2063136 Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Mon, 3 Dec 2012 12:21:48 +0000 Subject: [PATCH 015/333] [trunk]add the pkgconfig support for openjp2 (thanks Winfried) --- CMakeLists.txt | 11 +++++++++++ src/lib/openjp2/libopenjp2.pc.cmake.in | 13 +++++++++++++ 2 files changed, 24 insertions(+) create mode 100644 src/lib/openjp2/libopenjp2.pc.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index a2d58789..9b55c02a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -287,3 +287,14 @@ endif() install(FILES LICENSE DESTINATION ${OPENJPEG_INSTALL_DOC_DIR}) include (cmake/OpenJPEGCPack.cmake) + +#----------------------------------------------------------------------------- +# pkgconfig support +if(UNIX) + # install in lib and not share (see multi-arch note above) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/libopenjp2.pc.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc @ONLY) + install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc DESTINATION + ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig ) +endif() +#----------------------------------------------------------------------------- \ No newline at end of file diff --git a/src/lib/openjp2/libopenjp2.pc.cmake.in b/src/lib/openjp2/libopenjp2.pc.cmake.in new file mode 100644 index 00000000..42f33d0c --- /dev/null +++ b/src/lib/openjp2/libopenjp2.pc.cmake.in @@ -0,0 +1,13 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +bindir=${prefix}/@OPENJPEG_INSTALL_BIN_DIR@ +mandir=${prefix}/@OPENJPEG_INSTALL_MAN_DIR@ +docdir=${prefix}/@OPENJPEG_INSTALL_DOC_DIR@ +libdir=${prefix}/@OPENJPEG_INSTALL_LIB_DIR@ +includedir=${prefix}/@OPENJPEG_INSTALL_INCLUDE_DIR@ + +Name: openjp2 +Description: JPEG2000 library (Part 1 and 2) +URL: http://www.openjpeg.org/ +Version: @OPENJPEG_VERSION@ +Libs: -L${libdir} -lopenjp2 +Cflags: -I${includedir} From 0adb43f06e9c1517f1f72a4e596a247a5817d048 Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Mon, 3 Dec 2012 13:04:43 +0000 Subject: [PATCH 016/333] [trunk] correct the encoding of colr box information (thanks Winfried) --- src/lib/openjp2/jp2.c | 53 ++++++++++++++++++++++++------------------- 1 file changed, 30 insertions(+), 23 deletions(-) diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c index 2d4acc29..9fd78592 100644 --- a/src/lib/openjp2/jp2.c +++ b/src/lib/openjp2/jp2.c @@ -682,13 +682,15 @@ OPJ_BYTE * opj_jp2_write_colr( opj_jp2_t *jp2, /* preconditions */ assert(jp2 != 00); assert(p_nb_bytes_written != 00); + assert(jp2->meth == 1 || jp2->meth == 2); - switch (jp2->meth) { + switch (jp2->meth) { case 1 : - l_colr_size += 4; + l_colr_size += 4; /* EnumCS */ break; case 2 : - ++l_colr_size; + assert(jp2->color.icc_profile_len); /* ICC profile */ + l_colr_size += jp2->color.icc_profile_len; break; default : return 00; @@ -717,11 +719,16 @@ OPJ_BYTE * opj_jp2_write_colr( opj_jp2_t *jp2, opj_write_bytes(l_current_colr_ptr, jp2->approx,1); /* APPROX */ ++l_current_colr_ptr; - if (jp2->meth == 1) { - opj_write_bytes(l_current_colr_ptr, jp2->enumcs,4); /* EnumCS */ - } - else { - opj_write_bytes(l_current_colr_ptr, 0, 1); /* PROFILE (??) */ + if (jp2->meth == 1) { /* Meth value is restricted to 1 or 2 (Table I.9 of part 1) */ + opj_write_bytes(l_current_colr_ptr, jp2->enumcs,4); } /* EnumCS */ + else { + if (jp2->meth == 2) { /* ICC profile */ + OPJ_UINT32 i; + for(i = 0; i < jp2->color.icc_profile_len; ++i) { + opj_write_bytes(l_current_colr_ptr, jp2->color.icc_profile_buf[i], 1); + ++l_current_colr_ptr; + } + } } *p_nb_bytes_written = l_colr_size; @@ -1472,21 +1479,21 @@ void opj_jp2_setup_encoder( opj_jp2_t *jp2, } /* Colour Specification box */ - if ((image->numcomps == 1 || image->numcomps == 3) && (jp2->bpc != 255)) { - jp2->meth = 1; /* METH: Enumerated colourspace */ - } else { - jp2->meth = 2; /* METH: Restricted ICC profile */ - } - if (jp2->meth == 1) { - if (image->color_space == 1) - jp2->enumcs = 16; /* sRGB as defined by IEC 61966-2-1 */ - else if (image->color_space == 2) - jp2->enumcs = 17; /* greyscale */ - else if (image->color_space == 3) - jp2->enumcs = 18; /* YUV */ - } else { - jp2->enumcs = 0; /* PROFILE (??) */ - } + if(image->icc_profile_len) { + jp2->meth = 2; + jp2->enumcs = 0; + } + else { + jp2->meth = 1; + if (image->color_space == 1) + jp2->enumcs = 16; /* sRGB as defined by IEC 61966-2-1 */ + else if (image->color_space == 2) + jp2->enumcs = 17; /* greyscale */ + else if (image->color_space == 3) + jp2->enumcs = 18; /* YUV */ + } + + jp2->precedence = 0; /* PRECEDENCE */ jp2->approx = 0; /* APPROX */ From 59aa37fe2bfed224e465382e84a9170d9d73377a Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Mon, 3 Dec 2012 13:26:30 +0000 Subject: [PATCH 017/333] [trunk] move typedef from opj_stdint.h to openjpeg.h and add an include of stdio.h in openjpeg.h. Fixes issue 197 --- CMakeLists.txt | 1 + src/lib/openjp2/openjpeg.h | 7 ++++++- src/lib/openjp2/opj_stdint.h | 4 ---- tests/unit/testempty0.c | 2 -- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 9b55c02a..946a76e4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -187,6 +187,7 @@ CHECK_INCLUDE_FILE("inttypes.h" HAVE_INTTYPES_H) CHECK_INCLUDE_FILE("memory.h" HAVE_MEMORY_H) CHECK_INCLUDE_FILE("stdint.h" HAVE_STDINT_H) CHECK_INCLUDE_FILE("stdlib.h" HAVE_STDLIB_H) +CHECK_INCLUDE_FILE("stdio.h" HAVE_STDIO_H) CHECK_INCLUDE_FILE("string.h" HAVE_STRING_H) CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H) CHECK_INCLUDE_FILE("sys/types.h" HAVE_SYS_TYPES_H) diff --git a/src/lib/openjp2/openjpeg.h b/src/lib/openjp2/openjpeg.h index e5104316..9a2f1073 100644 --- a/src/lib/openjp2/openjpeg.h +++ b/src/lib/openjp2/openjpeg.h @@ -80,7 +80,7 @@ defined with this macro as being exported. #endif /* OPJ_EXPORTS */ #endif /* !OPJ_STATIC || !_WIN32 */ -typedef int OPJ_BOOL; /*FIXME it should be to follow the name of others OPJ_TYPE -> OPJ_BOOL*/ +typedef int OPJ_BOOL; #define OPJ_TRUE 1 #define OPJ_FALSE 0 @@ -100,6 +100,11 @@ typedef uint32_t OPJ_UINT32; typedef int64_t OPJ_INT64; typedef uint64_t OPJ_UINT64; +typedef int64_t OPJ_OFF_T; /* 64-bit file offset type */ + +#include +typedef size_t OPJ_SIZE_T; + /* Avoid compile-time warning because parameter is not used */ #define OPJ_ARG_NOT_USED(x) (void)(x) diff --git a/src/lib/openjp2/opj_stdint.h b/src/lib/openjp2/opj_stdint.h index 3dd2ec2b..fde17759 100644 --- a/src/lib/openjp2/opj_stdint.h +++ b/src/lib/openjp2/opj_stdint.h @@ -43,10 +43,6 @@ typedef unsigned __int64 uint64_t; #error unsupported platform #endif #endif -typedef size_t OPJ_SIZE_T; - -/* 64-bit file offset type */ -typedef int64_t OPJ_OFF_T; #ifndef HAVE_SSIZE_T #if defined(_WIN32) diff --git a/tests/unit/testempty0.c b/tests/unit/testempty0.c index 7fbb9d44..8edd2a6c 100644 --- a/tests/unit/testempty0.c +++ b/tests/unit/testempty0.c @@ -1,5 +1,3 @@ -#include - #include "openjpeg.h" int main(int argc, char **argv) { return 0; } From 82dad8e629356907121f9b91fcc2826fc8066ec2 Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Tue, 4 Dec 2012 12:20:30 +0000 Subject: [PATCH 018/333] [trunk] add openjpeg.h in some files of openjpip to use some opj type (thanks winfried) --- src/lib/openjpip/boxheader_manager.h | 1 + src/lib/openjpip/byte_manager.h | 1 + 2 files changed, 2 insertions(+) diff --git a/src/lib/openjpip/boxheader_manager.h b/src/lib/openjpip/boxheader_manager.h index 91092df9..d12d0732 100644 --- a/src/lib/openjpip/boxheader_manager.h +++ b/src/lib/openjpip/boxheader_manager.h @@ -31,6 +31,7 @@ #ifndef BOXHEADER_MANAGER_H_ # define BOXHEADER_MANAGER_H_ +#include "openjpeg.h" #include "byte_manager.h" #include "box_manager.h" diff --git a/src/lib/openjpip/byte_manager.h b/src/lib/openjpip/byte_manager.h index 696c1f69..62aea8b4 100644 --- a/src/lib/openjpip/byte_manager.h +++ b/src/lib/openjpip/byte_manager.h @@ -32,6 +32,7 @@ #define BYTE_MANAGER_H_ #include +#include "openjpeg.h" #include "opj_stdint.h" typedef uint8_t Byte_t; typedef uint16_t Byte2_t; From f5429e4ce82d88ac86dab7d50f1776207e4c0bed Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Tue, 4 Dec 2012 12:51:00 +0000 Subject: [PATCH 019/333] [trunk] remove SSIZE which is unused in openjpeg and rename HAVE_STDINT_H to OPJ_HAVE_STDINT_H --- CMakeLists.txt | 3 --- src/lib/openjp2/opj_config.h.cmake.in | 4 ++-- src/lib/openjp2/opj_stdint.h | 11 +---------- 3 files changed, 3 insertions(+), 15 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 946a76e4..926a6ac1 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -192,9 +192,6 @@ CHECK_INCLUDE_FILE("string.h" HAVE_STRING_H) CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H) CHECK_INCLUDE_FILE("sys/types.h" HAVE_SYS_TYPES_H) CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H) -# ssize_t -include(CheckTypeSize) -CHECK_TYPE_SIZE(ssize_t SSIZE_T) # Enable Large file support include(TestLargeFiles) diff --git a/src/lib/openjp2/opj_config.h.cmake.in b/src/lib/openjp2/opj_config.h.cmake.in index e5ac38e4..91772ef9 100644 --- a/src/lib/openjp2/opj_config.h.cmake.in +++ b/src/lib/openjp2/opj_config.h.cmake.in @@ -1,9 +1,10 @@ /* create config.h for CMake */ +#cmakedefine OPJ_HAVE_STDINT_H @HAVE_STDINT_H@ + #define OPJ_PACKAGE_VERSION "@PACKAGE_VERSION@" #cmakedefine HAVE_INTTYPES_H @HAVE_INTTYPES_H@ #cmakedefine HAVE_MEMORY_H @HAVE_MEMORY_H@ -#cmakedefine HAVE_STDINT_H @HAVE_STDINT_H@ #cmakedefine HAVE_STDLIB_H @HAVE_STDLIB_H@ #cmakedefine HAVE_STRINGS_H @HAVE_STRINGS_H@ #cmakedefine HAVE_STRING_H @HAVE_STRING_H@ @@ -14,7 +15,6 @@ #cmakedefine HAVE_PNG_H @HAVE_PNG_H@ #cmakedefine HAVE_LIBTIFF @HAVE_LIBTIFF@ #cmakedefine HAVE_TIFF_H @HAVE_TIFF_H@ -#cmakedefine HAVE_SSIZE_T @HAVE_SSIZE_T@ #cmakedefine _LARGEFILE_SOURCE #cmakedefine _LARGE_FILES diff --git a/src/lib/openjp2/opj_stdint.h b/src/lib/openjp2/opj_stdint.h index fde17759..2d121803 100644 --- a/src/lib/openjp2/opj_stdint.h +++ b/src/lib/openjp2/opj_stdint.h @@ -27,7 +27,7 @@ #define OPJ_STDINT_H #include "opj_config.h" -#ifdef HAVE_STDINT_H +#ifdef OPJ_HAVE_STDINT_H #include #else #if defined(_WIN32) @@ -44,13 +44,4 @@ typedef unsigned __int64 uint64_t; #endif #endif -#ifndef HAVE_SSIZE_T -#if defined(_WIN32) -#include -typedef SSIZE_T ssize_t; -#else -#error SSIZE_T is undefined -#endif /* _WIN32 */ -#endif - #endif /* OPJ_STDINT_H */ From b42cf317d64e817f635c88e15da1a9134ef5e49e Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Tue, 4 Dec 2012 13:13:50 +0000 Subject: [PATCH 020/333] [trunk] correct the new name of OPJ_HAVE_STDINT_H everywhere --- CMakeLists.txt | 2 +- src/lib/openjp2/opj_config.h.cmake.in | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 926a6ac1..4c7c825c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -185,7 +185,7 @@ include (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake) CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H) CHECK_INCLUDE_FILE("inttypes.h" HAVE_INTTYPES_H) CHECK_INCLUDE_FILE("memory.h" HAVE_MEMORY_H) -CHECK_INCLUDE_FILE("stdint.h" HAVE_STDINT_H) +CHECK_INCLUDE_FILE("stdint.h" OPJ_HAVE_STDINT_H) CHECK_INCLUDE_FILE("stdlib.h" HAVE_STDLIB_H) CHECK_INCLUDE_FILE("stdio.h" HAVE_STDIO_H) CHECK_INCLUDE_FILE("string.h" HAVE_STRING_H) diff --git a/src/lib/openjp2/opj_config.h.cmake.in b/src/lib/openjp2/opj_config.h.cmake.in index 91772ef9..6bc268ef 100644 --- a/src/lib/openjp2/opj_config.h.cmake.in +++ b/src/lib/openjp2/opj_config.h.cmake.in @@ -1,5 +1,5 @@ /* create config.h for CMake */ -#cmakedefine OPJ_HAVE_STDINT_H @HAVE_STDINT_H@ +#cmakedefine OPJ_HAVE_STDINT_H @OPJ_HAVE_STDINT_H@ #define OPJ_PACKAGE_VERSION "@PACKAGE_VERSION@" From c075742bc8353fb4f4115a3e62db3d9cd3147e5e Mon Sep 17 00:00:00 2001 From: Rex Dieter Date: Fri, 7 Dec 2012 15:07:50 +0000 Subject: [PATCH 021/333] Doxyfile: HTML_TIMESTAMP = NO helps when comparing the output of multiple runs, and distros will appreciate avoiding multilib conflicts. --- doc/Doxyfile.dox.cmake.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/Doxyfile.dox.cmake.in b/doc/Doxyfile.dox.cmake.in index 548c2012..8c2398ee 100644 --- a/doc/Doxyfile.dox.cmake.in +++ b/doc/Doxyfile.dox.cmake.in @@ -145,7 +145,7 @@ HTML_STYLESHEET = HTML_COLORSTYLE_HUE = 220 HTML_COLORSTYLE_SAT = 100 HTML_COLORSTYLE_GAMMA = 80 -HTML_TIMESTAMP = YES +HTML_TIMESTAMP = NO HTML_ALIGN_MEMBERS = YES HTML_DYNAMIC_SECTIONS = NO GENERATE_DOCSET = NO From 8c9151c86b5250693f8247d58c75d1c3ef6ea54a Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 11 Dec 2012 14:09:24 +0000 Subject: [PATCH 022/333] [trunk] JP3D: completely redo the opj_tgt_create function. Take as input the initial opj_tgt_create as found in openjpeg 1.5, and extend with the 3rd dimension. --- src/lib/openjp3d/tgt.c | 45 +++++++++++++++++++----------------------- 1 file changed, 20 insertions(+), 25 deletions(-) diff --git a/src/lib/openjp3d/tgt.c b/src/lib/openjp3d/tgt.c index 77a751a6..c86cfe6d 100755 --- a/src/lib/openjp3d/tgt.c +++ b/src/lib/openjp3d/tgt.c @@ -68,6 +68,7 @@ opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv, int numleafsz) { opj_tgt_node_t *node = NULL; opj_tgt_node_t *parentnode = NULL; opj_tgt_node_t *parentnode0 = NULL; + opj_tgt_node_t *parentnode1 = NULL; opj_tgt_tree_t *tree = NULL; int i, j, k, p, p0; int numlvls; @@ -108,38 +109,32 @@ opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv, int numleafsz) { node = tree->nodes; parentnode = &tree->nodes[tree->numleafsh * tree->numleafsv * tree->numleafsz]; parentnode0 = parentnode; - - p = tree->numleafsh * tree->numleafsv * tree->numleafsz; - p0 = p; - n = 0; + parentnode1 = parentnode; /*fprintf(stdout,"\nH %d V %d Z %d numlvls %d nodes %d\n",tree->numleafsh,tree->numleafsv,tree->numleafsz,numlvls,tree->numnodes);*/ for (i = 0; i < numlvls - 1; ++i) { - for (j = 0; j < nplv[i]; ++j) { - k = nplh[i]*nplz[i]; - while (--k >= 0) { - node->parent = parentnode; /*fprintf(stdout,"node[%d].parent = node[%d]\n",n,p);*/ - ++node; ++n; - if (--k >= 0 && n < p) { - node->parent = parentnode; /*fprintf(stdout,"node[%d].parent = node[%d]\n",n,p);*/ - ++node; ++n; - } - if (nplz[i] != 1){ /*2D operation vs 3D operation*/ - if (--k >= 0 && n < p) { + for (z = 0; z < nplz[i]; ++z) { + for (j = 0; j < nplv[i]; ++j) { + k = nplh[i]; + while(--k >= 0) { + node->parent = parentnode; /*fprintf(stdout,"node[%d].parent = node[%d]\n",n,p);*/ + ++node; + if(--k >= 0) { node->parent = parentnode; /*fprintf(stdout,"node[%d].parent = node[%d]\n",n,p);*/ - ++node; ++n; - } - if (--k >= 0 && n < p) { - node->parent = parentnode; /*fprintf(stdout,"node[%d].parent = node[%d]\n",n,p);*/ - ++node; ++n; + ++node; } + ++parentnode; + } + if((j & 1) || j == nplv[i] - 1) { + parentnode0 = parentnode; + } else { + parentnode = parentnode0; } - ++parentnode; ++p; } - if ((j & 1) || j == nplv[i] - 1) { - parentnode0 = parentnode; p0 = p; /*fprintf(stdout,"parent = node[%d] \n",p);*/ + if ((z & 1) || z == nplz[i] - 1) { + parentnode1 = parentnode; } else { - parentnode = parentnode0; p = p0; /*fprintf(stdout,"parent = node[%d] \n",p);*/ - parentnode0 += nplh[i]*nplz[i]; p0 += nplh[i]*nplz[i]; + parentnode0 = parentnode1; + parentnode = parentnode1; } } } From 4c02acb728a0204684cd622007b8366ed373295c Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 11 Dec 2012 14:15:46 +0000 Subject: [PATCH 023/333] [trunk] remove left over from v2 transition --- src/lib/openjp2/tgt.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/openjp2/tgt.c b/src/lib/openjp2/tgt.c index 06930d49..6fd85587 100644 --- a/src/lib/openjp2/tgt.c +++ b/src/lib/openjp2/tgt.c @@ -53,7 +53,7 @@ opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv) { tree = (opj_tgt_tree_t *) opj_malloc(sizeof(opj_tgt_tree_t)); if(!tree) { - fprintf(stderr, "ERROR in tgt_create_v2 while allocating tree\n"); + fprintf(stderr, "ERROR in tgt_create while allocating tree\n"); return 00; } memset(tree,0,sizeof(opj_tgt_tree_t)); @@ -76,13 +76,13 @@ opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv) { /* ADD */ if (tree->numnodes == 0) { opj_free(tree); - fprintf(stderr, "WARNING in tgt_create_v2 tree->numnodes == 0, no tree created.\n"); + fprintf(stderr, "WARNING in tgt_create tree->numnodes == 0, no tree created.\n"); return 00; } tree->nodes = (opj_tgt_node_t*) opj_calloc(tree->numnodes, sizeof(opj_tgt_node_t)); if(!tree->nodes) { - fprintf(stderr, "ERROR in tgt_create_v2 while allocating node of the tree\n"); + fprintf(stderr, "ERROR in tgt_create while allocating node of the tree\n"); opj_free(tree); return 00; } @@ -119,7 +119,7 @@ opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv) { } /** - * Reinitialises a tag-tree from an exixting one. (V2 framevork) + * Reinitialises a tag-tree from an existing one. * * @param p_tree the tree to reinitialize. * @param p_num_leafs_h the width of the array of leafs of the tree From b65bf4836933355df88a9eb5ce5696dcf3c324ba Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Tue, 18 Dec 2012 17:46:33 +0000 Subject: [PATCH 024/333] [trunk] merge from branch 1.5 a correction about large code-block data (decoding part) and add tests about issue 5 and issue 62 --- src/lib/openjp2/j2k.h | 2 ++ src/lib/openjp2/t2.c | 34 +++++++++++++++---------- src/lib/openjp2/tcd.c | 10 ++++---- src/lib/openjp2/tcd.h | 5 ++-- tests/nonregression/test_suite.ctest.in | 4 +++ 5 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/lib/openjp2/j2k.h b/src/lib/openjp2/j2k.h index be341724..22d38762 100644 --- a/src/lib/openjp2/j2k.h +++ b/src/lib/openjp2/j2k.h @@ -59,6 +59,8 @@ The functions in J2K.C have for goal to read/write the several parts of the code #define J2K_CCP_QNTSTY_SIQNT 1 #define J2K_CCP_QNTSTY_SEQNT 2 +#define OPJ_J2K_DEFAULT_CBLK_DATA_SIZE 8192 + /* ----------------------------------------------------------------------- */ #define J2K_MS_SOC 0xff4f /**< SOC marker value */ diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c index f48847b8..a3cf75d9 100644 --- a/src/lib/openjp2/t2.c +++ b/src/lib/openjp2/t2.c @@ -524,12 +524,12 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, opj_codestream_info_t *cstr_info) { OPJ_UINT32 bandno, cblkno; - OPJ_BYTE *c = dest; + OPJ_BYTE* c = dest; OPJ_UINT32 l_nb_bytes; - OPJ_UINT32 compno = pi->compno; /* component value */ - OPJ_UINT32 resno = pi->resno; /* resolution level value */ - OPJ_UINT32 precno = pi->precno; /* precinct value */ - OPJ_UINT32 layno = pi->layno; /* quality layer value */ + OPJ_UINT32 compno = pi->compno; /* component value */ + OPJ_UINT32 resno = pi->resno; /* resolution level value */ + OPJ_UINT32 precno = pi->precno; /* precinct value */ + OPJ_UINT32 layno = pi->layno; /* quality layer value */ OPJ_UINT32 l_nb_blocks; opj_tcd_band_t *band = 00; opj_tcd_cblk_enc_t* cblk = 00; @@ -1076,7 +1076,7 @@ OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2, if (!l_cblk->numsegs) { l_seg = l_cblk->segs; ++l_cblk->numsegs; - l_cblk->len = 0; + l_cblk->data_current_size = 0; } else { l_seg = &l_cblk->segs[l_cblk->numsegs - 1]; @@ -1111,16 +1111,24 @@ OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2, }; #endif /* USE_JPWL */ - - if ((l_cblk->len + l_seg->newlen) > 8192) { + /* Check if the cblk->data have allocated enough memory */ + if ((l_cblk->data_current_size + l_seg->newlen) > l_cblk->data_max_size) { + OPJ_BYTE* new_cblk_data = (OPJ_BYTE*) opj_realloc(l_cblk->data, l_cblk->data_current_size + l_seg->newlen); + if(! new_cblk_data) { + opj_free(l_cblk->data); + l_cblk->data_max_size = 0; + /* opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to realloc code block cata!\n"); */ return OPJ_FALSE; + } + l_cblk->data_max_size = l_cblk->data_current_size + l_seg->newlen; + l_cblk->data = new_cblk_data; } - memcpy(l_cblk->data + l_cblk->len, l_current_data, l_seg->newlen); + memcpy(l_cblk->data + l_cblk->data_current_size, l_current_data, l_seg->newlen); if (l_seg->numpasses == 0) { l_seg->data = &l_cblk->data; - l_seg->dataindex = l_cblk->len; + l_seg->dataindex = l_cblk->data_current_size; } l_current_data += l_seg->newlen; @@ -1128,7 +1136,7 @@ OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2, l_cblk->numnewpasses -= l_seg->numnewpasses; l_seg->real_num_passes = l_seg->numpasses; - l_cblk->len += l_seg->newlen; + l_cblk->data_current_size += l_seg->newlen; l_seg->len += l_seg->newlen; if (l_cblk->numnewpasses > 0) { @@ -1139,7 +1147,7 @@ OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2, l_cblk->real_num_segs = l_cblk->numsegs; ++l_cblk; - } + } /* next code_block */ ++l_band; } @@ -1191,7 +1199,7 @@ OPJ_BOOL opj_t2_skip_packet_data( opj_t2_t* p_t2, if (!l_cblk->numsegs) { l_seg = l_cblk->segs; ++l_cblk->numsegs; - l_cblk->len = 0; + l_cblk->data_current_size = 0; } else { l_seg = &l_cblk->segs[l_cblk->numsegs - 1]; diff --git a/src/lib/openjp2/tcd.c b/src/lib/openjp2/tcd.c index 18ebd077..88372e23 100644 --- a/src/lib/openjp2/tcd.c +++ b/src/lib/openjp2/tcd.c @@ -1001,7 +1001,7 @@ OPJ_BOOL opj_tcd_code_block_enc_allocate (opj_tcd_cblk_enc_t * p_code_block) { if (! p_code_block->data) { - p_code_block->data = (OPJ_BYTE*) opj_malloc(8192+1); + p_code_block->data = (OPJ_BYTE*) opj_malloc(OPJ_J2K_DEFAULT_CBLK_DATA_SIZE); //why +1 ? if(! p_code_block->data) { return OPJ_FALSE; } @@ -1036,10 +1036,11 @@ OPJ_BOOL opj_tcd_code_block_dec_allocate (opj_tcd_cblk_dec_t * p_code_block) if (! p_code_block->data) { - p_code_block->data = (OPJ_BYTE*) opj_malloc(8192); + p_code_block->data = (OPJ_BYTE*) opj_malloc(OPJ_J2K_DEFAULT_CBLK_DATA_SIZE); if (! p_code_block->data) { return OPJ_FALSE; } + p_code_block->data_max_size = OPJ_J2K_DEFAULT_CBLK_DATA_SIZE; /*fprintf(stderr, "Allocate 8192 elements of code_block->data\n");*/ l_seg_size = OPJ_J2K_DEFAULT_NB_SEGS * sizeof(opj_tcd_seg_t); @@ -1213,8 +1214,7 @@ OPJ_BOOL opj_tcd_decode_tile( opj_tcd_t *p_tcd, /*--------------TIER2------------------*/ /* FIXME _ProfStart(PGROUP_T2); */ l_data_read = 0; - if - (! opj_tcd_t2_decode(p_tcd, p_src, &l_data_read, p_max_length, p_cstr_index)) + if (! opj_tcd_t2_decode(p_tcd, p_src, &l_data_read, p_max_length, p_cstr_index)) { return OPJ_FALSE; } @@ -1746,7 +1746,7 @@ void opj_tcd_code_block_enc_deallocate (opj_tcd_precinct_t * p_precinct) for (cblkno = 0; cblkno < l_nb_code_blocks; ++cblkno) { if (l_code_block->data) { - opj_free(l_code_block->data-1); + opj_free(l_code_block->data); l_code_block->data = 00; } diff --git a/src/lib/openjp2/tcd.h b/src/lib/openjp2/tcd.h index 0a540453..11aec81b 100644 --- a/src/lib/openjp2/tcd.h +++ b/src/lib/openjp2/tcd.h @@ -96,10 +96,11 @@ typedef struct opj_tcd_cblk_enc { typedef struct opj_tcd_cblk_dec { OPJ_BYTE * data; /* Data */ opj_tcd_seg_t* segs; /* segments information */ - OPJ_INT32 x0, y0, x1, y1; /* dimension of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */ + OPJ_INT32 x0, y0, x1, y1; /* position of the code-blocks : left upper corner (x0, y0) right low corner (x1,y1) */ OPJ_UINT32 numbps; OPJ_UINT32 numlenbits; - OPJ_UINT32 len; /* length */ + OPJ_UINT32 data_max_size; /* Size of allocated data buffer */ + OPJ_UINT32 data_current_size; /* Size of used data buffer */ OPJ_UINT32 numnewpasses; /* number of pass added to the code-blocks */ OPJ_UINT32 numsegs; /* number of segments */ OPJ_UINT32 real_num_segs; diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 3fc52fe8..dc6fec52 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -27,6 +27,10 @@ opj_compress -i @INPUT_NR_PATH@/Bretagne2.ppm -o @TEMP_PATH@/Bretagne2_4.j2k -d opj_compress -i @INPUT_NR_PATH@/Cevennes1.bmp -o @TEMP_PATH@/Cevennes1.j2k -r 10 opj_compress -i @INPUT_NR_PATH@/Cevennes2.ppm -o @TEMP_PATH@/Cevennes2.jp2 -r 50 opj_compress -i @INPUT_NR_PATH@/Rome.bmp -o @TEMP_PATH@/Rome.jp2 -q 30,35,50 -p LRCP -n 3 +# related to issue 5 +opj_compress -i @INPUT_NR_PATH@/random.tif -o @TEMP_PATH@/random.tif.j2k +# related to issue 62 +opj_compress -i @INPUT_NR_PATH@/tmp.raw -o @TEMP_PATH@/tmp.raw.j2k -F 512,512,1,16,u opj_compress -i @INPUT_NR_PATH@/X_4_2K_24_185_CBR_WB_000.tif -o @TEMP_PATH@/X_4_2K_24_185_CBR_WB_000.j2k -cinema2K 24 opj_compress -i @INPUT_NR_PATH@/X_5_2K_24_235_CBR_STEM24_000.tif -o @TEMP_PATH@/X_5_2K_24_235_CBR_STEM24_000.j2k -cinema2K 24 opj_compress -i @INPUT_NR_PATH@/X_6_2K_24_FULL_CBR_CIRCLE_000.tif -o @TEMP_PATH@/X_6_2K_24_FULL_CBR_CIRCLE_000.j2k -cinema2K 24 From df47fae2872d726e7d8ca7b2ef4df0fbcc25cffc Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 2 Jan 2013 18:16:14 +0000 Subject: [PATCH 025/333] [trunk] JP3D: remove exe bit from source files --- src/lib/openjp3d/bio.c | 0 src/lib/openjp3d/bio.h | 0 src/lib/openjp3d/cio.c | 0 src/lib/openjp3d/cio.h | 0 src/lib/openjp3d/dwt.c | 0 src/lib/openjp3d/dwt.h | 0 src/lib/openjp3d/event.c | 0 src/lib/openjp3d/event.h | 0 src/lib/openjp3d/fix.h | 0 src/lib/openjp3d/int.h | 0 src/lib/openjp3d/jp3d.c | 0 src/lib/openjp3d/jp3d.h | 0 src/lib/openjp3d/jp3d_lib.c | 0 src/lib/openjp3d/jp3d_lib.h | 0 src/lib/openjp3d/mct.c | 0 src/lib/openjp3d/mct.h | 0 src/lib/openjp3d/mqc.c | 0 src/lib/openjp3d/mqc.h | 0 src/lib/openjp3d/openjp3d.c | 0 src/lib/openjp3d/openjp3d.h | 0 src/lib/openjp3d/opj_includes.h | 0 src/lib/openjp3d/pi.c | 0 src/lib/openjp3d/pi.h | 0 src/lib/openjp3d/raw.c | 0 src/lib/openjp3d/raw.h | 0 src/lib/openjp3d/t1.c | 0 src/lib/openjp3d/t1.h | 0 src/lib/openjp3d/t1_3d.c | 0 src/lib/openjp3d/t1_3d.h | 0 src/lib/openjp3d/t2.c | 0 src/lib/openjp3d/t2.h | 0 src/lib/openjp3d/tcd.c | 0 src/lib/openjp3d/tcd.h | 0 src/lib/openjp3d/tgt.c | 0 src/lib/openjp3d/tgt.h | 0 src/lib/openjp3d/volume.c | 0 src/lib/openjp3d/volume.h | 0 37 files changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 src/lib/openjp3d/bio.c mode change 100755 => 100644 src/lib/openjp3d/bio.h mode change 100755 => 100644 src/lib/openjp3d/cio.c mode change 100755 => 100644 src/lib/openjp3d/cio.h mode change 100755 => 100644 src/lib/openjp3d/dwt.c mode change 100755 => 100644 src/lib/openjp3d/dwt.h mode change 100755 => 100644 src/lib/openjp3d/event.c mode change 100755 => 100644 src/lib/openjp3d/event.h mode change 100755 => 100644 src/lib/openjp3d/fix.h mode change 100755 => 100644 src/lib/openjp3d/int.h mode change 100755 => 100644 src/lib/openjp3d/jp3d.c mode change 100755 => 100644 src/lib/openjp3d/jp3d.h mode change 100755 => 100644 src/lib/openjp3d/jp3d_lib.c mode change 100755 => 100644 src/lib/openjp3d/jp3d_lib.h mode change 100755 => 100644 src/lib/openjp3d/mct.c mode change 100755 => 100644 src/lib/openjp3d/mct.h mode change 100755 => 100644 src/lib/openjp3d/mqc.c mode change 100755 => 100644 src/lib/openjp3d/mqc.h mode change 100755 => 100644 src/lib/openjp3d/openjp3d.c mode change 100755 => 100644 src/lib/openjp3d/openjp3d.h mode change 100755 => 100644 src/lib/openjp3d/opj_includes.h mode change 100755 => 100644 src/lib/openjp3d/pi.c mode change 100755 => 100644 src/lib/openjp3d/pi.h mode change 100755 => 100644 src/lib/openjp3d/raw.c mode change 100755 => 100644 src/lib/openjp3d/raw.h mode change 100755 => 100644 src/lib/openjp3d/t1.c mode change 100755 => 100644 src/lib/openjp3d/t1.h mode change 100755 => 100644 src/lib/openjp3d/t1_3d.c mode change 100755 => 100644 src/lib/openjp3d/t1_3d.h mode change 100755 => 100644 src/lib/openjp3d/t2.c mode change 100755 => 100644 src/lib/openjp3d/t2.h mode change 100755 => 100644 src/lib/openjp3d/tcd.c mode change 100755 => 100644 src/lib/openjp3d/tcd.h mode change 100755 => 100644 src/lib/openjp3d/tgt.c mode change 100755 => 100644 src/lib/openjp3d/tgt.h mode change 100755 => 100644 src/lib/openjp3d/volume.c mode change 100755 => 100644 src/lib/openjp3d/volume.h diff --git a/src/lib/openjp3d/bio.c b/src/lib/openjp3d/bio.c old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/bio.h b/src/lib/openjp3d/bio.h old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/cio.c b/src/lib/openjp3d/cio.c old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/cio.h b/src/lib/openjp3d/cio.h old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/dwt.c b/src/lib/openjp3d/dwt.c old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/dwt.h b/src/lib/openjp3d/dwt.h old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/event.c b/src/lib/openjp3d/event.c old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/event.h b/src/lib/openjp3d/event.h old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/fix.h b/src/lib/openjp3d/fix.h old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/int.h b/src/lib/openjp3d/int.h old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/jp3d.c b/src/lib/openjp3d/jp3d.c old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/jp3d.h b/src/lib/openjp3d/jp3d.h old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/jp3d_lib.c b/src/lib/openjp3d/jp3d_lib.c old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/jp3d_lib.h b/src/lib/openjp3d/jp3d_lib.h old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/mct.c b/src/lib/openjp3d/mct.c old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/mct.h b/src/lib/openjp3d/mct.h old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/mqc.c b/src/lib/openjp3d/mqc.c old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/mqc.h b/src/lib/openjp3d/mqc.h old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/openjp3d.c b/src/lib/openjp3d/openjp3d.c old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/openjp3d.h b/src/lib/openjp3d/openjp3d.h old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/opj_includes.h b/src/lib/openjp3d/opj_includes.h old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/pi.c b/src/lib/openjp3d/pi.c old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/pi.h b/src/lib/openjp3d/pi.h old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/raw.c b/src/lib/openjp3d/raw.c old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/raw.h b/src/lib/openjp3d/raw.h old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/t1.c b/src/lib/openjp3d/t1.c old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/t1.h b/src/lib/openjp3d/t1.h old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/t1_3d.c b/src/lib/openjp3d/t1_3d.c old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/t1_3d.h b/src/lib/openjp3d/t1_3d.h old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/t2.c b/src/lib/openjp3d/t2.c old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/t2.h b/src/lib/openjp3d/t2.h old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/tcd.c b/src/lib/openjp3d/tcd.c old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/tcd.h b/src/lib/openjp3d/tcd.h old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/tgt.c b/src/lib/openjp3d/tgt.c old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/tgt.h b/src/lib/openjp3d/tgt.h old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/volume.c b/src/lib/openjp3d/volume.c old mode 100755 new mode 100644 diff --git a/src/lib/openjp3d/volume.h b/src/lib/openjp3d/volume.h old mode 100755 new mode 100644 From caaec3bb05b3ecaa4cf6bc8b59b7abd401faa42c Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 2 Jan 2013 18:19:56 +0000 Subject: [PATCH 026/333] [trunk] JP3D: convert from DOS to UNIX eol --- src/lib/openjp3d/bio.c | 378 +-- src/lib/openjp3d/bio.h | 264 +- src/lib/openjp3d/cio.c | 434 ++-- src/lib/openjp3d/cio.h | 200 +- src/lib/openjp3d/dwt.h | 202 +- src/lib/openjp3d/event.c | 362 +-- src/lib/openjp3d/event.h | 116 +- src/lib/openjp3d/jp3d.c | 4710 +++++++++++++++++------------------ src/lib/openjp3d/jp3d.h | 1036 ++++---- src/lib/openjp3d/jp3d_lib.c | 152 +- src/lib/openjp3d/jp3d_lib.h | 150 +- src/lib/openjp3d/mct.c | 262 +- src/lib/openjp3d/mct.h | 194 +- src/lib/openjp3d/mqc.c | 1096 ++++---- src/lib/openjp3d/mqc.h | 402 +-- src/lib/openjp3d/openjp3d.c | 416 ++-- src/lib/openjp3d/openjp3d.h | 1442 +++++------ src/lib/openjp3d/pi.c | 1260 +++++----- src/lib/openjp3d/pi.h | 290 +-- src/lib/openjp3d/raw.c | 172 +- src/lib/openjp3d/raw.h | 198 +- src/lib/openjp3d/t1.c | 2362 +++++++++--------- src/lib/openjp3d/t1.h | 346 +-- src/lib/openjp3d/t1_3d.c | 2460 +++++++++--------- src/lib/openjp3d/t1_3d.h | 346 +-- src/lib/openjp3d/t2.c | 1350 +++++----- src/lib/openjp3d/t2.h | 202 +- src/lib/openjp3d/tcd.c | 3478 +++++++++++++------------- src/lib/openjp3d/tgt.c | 502 ++-- src/lib/openjp3d/tgt.h | 250 +- src/lib/openjp3d/volume.c | 182 +- src/lib/openjp3d/volume.h | 86 +- 32 files changed, 12650 insertions(+), 12650 deletions(-) diff --git a/src/lib/openjp3d/bio.c b/src/lib/openjp3d/bio.c index bc3b1138..57e909b9 100644 --- a/src/lib/openjp3d/bio.c +++ b/src/lib/openjp3d/bio.c @@ -1,189 +1,189 @@ -/* - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "opj_includes.h" - -/** @defgroup BIO BIO - Individual bit input-output stream */ -/*@{*/ - -/** @name Local static functions */ -/*@{*/ - -/** -Write a bit -@param bio BIO handle -@param b Bit to write (0 or 1) -*/ -static void bio_putbit(opj_bio_t *bio, int b); -/** -Read a bit -@param bio BIO handle -@return Returns the read bit -*/ -static int bio_getbit(opj_bio_t *bio); -/** -Write a byte -@param bio BIO handle -@return Returns 0 if successful, returns 1 otherwise -*/ -static int bio_byteout(opj_bio_t *bio); -/** -Read a byte -@param bio BIO handle -@return Returns 0 if successful, returns 1 otherwise -*/ -static int bio_bytein(opj_bio_t *bio); - -/*@}*/ - -/*@}*/ - - -/* -========================================================== - local functions -========================================================== -*/ - -static int bio_byteout(opj_bio_t *bio) { - bio->buf = (bio->buf << 8) & 0xffff; - bio->ct = bio->buf == 0xff00 ? 7 : 8; - if (bio->bp >= bio->end) { - return 1; - } - *bio->bp++ = bio->buf >> 8; - return 0; -} - -static int bio_bytein(opj_bio_t *bio) { - bio->buf = (bio->buf << 8) & 0xffff; - bio->ct = bio->buf == 0xff00 ? 7 : 8; - if (bio->bp >= bio->end) { - return 1; - } - bio->buf |= *bio->bp++; - return 0; -} - -static void bio_putbit(opj_bio_t *bio, int b) { - if (bio->ct == 0) { - bio_byteout(bio); - } - bio->ct--; - bio->buf |= b << bio->ct; -} - -/* MOD antonin */ -static int bio_getbit(opj_bio_t *bio) { -/* DOM */ - if (bio->ct == 0) { - bio_bytein(bio); - } - bio->ct--; - return (bio->buf >> bio->ct) & 1; -} - -/* -========================================================== - Bit Input/Output interface -========================================================== -*/ - -opj_bio_t* bio_create() { - opj_bio_t *bio = (opj_bio_t*)opj_malloc(sizeof(opj_bio_t)); - return bio; -} - -void bio_destroy(opj_bio_t *bio) { - if(bio) { - opj_free(bio); - } -} - -int bio_numbytes(opj_bio_t *bio) { - return (bio->bp - bio->start); -} - -void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len) { - bio->start = bp; - bio->end = bp + len; - bio->bp = bp; - bio->buf = 0; - bio->ct = 8; -} - -void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len) { - bio->start = bp; - bio->end = bp + len; - bio->bp = bp; - bio->buf = 0; - bio->ct = 0; -} - -void bio_write(opj_bio_t *bio, int v, int n) { - int i; - for (i = n - 1; i >= 0; i--) { - bio_putbit(bio, (v >> i) & 1); - } -} - -int bio_read(opj_bio_t *bio, int n) { - int i, v; - v = 0; - for (i = n - 1; i >= 0; i--) { - v += bio_getbit(bio) << i; - } - return v; -} - -int bio_flush(opj_bio_t *bio) { - bio->ct = 0; - if (bio_byteout(bio)) { - return 1; - } - if (bio->ct == 7) { - bio->ct = 0; - if (bio_byteout(bio)) { - return 1; - } - } - return 0; -} - -int bio_inalign(opj_bio_t *bio) { - bio->ct = 0; - if ((bio->buf & 0xff) == 0xff) { - if (bio_bytein(bio)) { - return 1; - } - bio->ct = 0; - } - return 0; -} +/* + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opj_includes.h" + +/** @defgroup BIO BIO - Individual bit input-output stream */ +/*@{*/ + +/** @name Local static functions */ +/*@{*/ + +/** +Write a bit +@param bio BIO handle +@param b Bit to write (0 or 1) +*/ +static void bio_putbit(opj_bio_t *bio, int b); +/** +Read a bit +@param bio BIO handle +@return Returns the read bit +*/ +static int bio_getbit(opj_bio_t *bio); +/** +Write a byte +@param bio BIO handle +@return Returns 0 if successful, returns 1 otherwise +*/ +static int bio_byteout(opj_bio_t *bio); +/** +Read a byte +@param bio BIO handle +@return Returns 0 if successful, returns 1 otherwise +*/ +static int bio_bytein(opj_bio_t *bio); + +/*@}*/ + +/*@}*/ + + +/* +========================================================== + local functions +========================================================== +*/ + +static int bio_byteout(opj_bio_t *bio) { + bio->buf = (bio->buf << 8) & 0xffff; + bio->ct = bio->buf == 0xff00 ? 7 : 8; + if (bio->bp >= bio->end) { + return 1; + } + *bio->bp++ = bio->buf >> 8; + return 0; +} + +static int bio_bytein(opj_bio_t *bio) { + bio->buf = (bio->buf << 8) & 0xffff; + bio->ct = bio->buf == 0xff00 ? 7 : 8; + if (bio->bp >= bio->end) { + return 1; + } + bio->buf |= *bio->bp++; + return 0; +} + +static void bio_putbit(opj_bio_t *bio, int b) { + if (bio->ct == 0) { + bio_byteout(bio); + } + bio->ct--; + bio->buf |= b << bio->ct; +} + +/* MOD antonin */ +static int bio_getbit(opj_bio_t *bio) { +/* DOM */ + if (bio->ct == 0) { + bio_bytein(bio); + } + bio->ct--; + return (bio->buf >> bio->ct) & 1; +} + +/* +========================================================== + Bit Input/Output interface +========================================================== +*/ + +opj_bio_t* bio_create() { + opj_bio_t *bio = (opj_bio_t*)opj_malloc(sizeof(opj_bio_t)); + return bio; +} + +void bio_destroy(opj_bio_t *bio) { + if(bio) { + opj_free(bio); + } +} + +int bio_numbytes(opj_bio_t *bio) { + return (bio->bp - bio->start); +} + +void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len) { + bio->start = bp; + bio->end = bp + len; + bio->bp = bp; + bio->buf = 0; + bio->ct = 8; +} + +void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len) { + bio->start = bp; + bio->end = bp + len; + bio->bp = bp; + bio->buf = 0; + bio->ct = 0; +} + +void bio_write(opj_bio_t *bio, int v, int n) { + int i; + for (i = n - 1; i >= 0; i--) { + bio_putbit(bio, (v >> i) & 1); + } +} + +int bio_read(opj_bio_t *bio, int n) { + int i, v; + v = 0; + for (i = n - 1; i >= 0; i--) { + v += bio_getbit(bio) << i; + } + return v; +} + +int bio_flush(opj_bio_t *bio) { + bio->ct = 0; + if (bio_byteout(bio)) { + return 1; + } + if (bio->ct == 7) { + bio->ct = 0; + if (bio_byteout(bio)) { + return 1; + } + } + return 0; +} + +int bio_inalign(opj_bio_t *bio) { + bio->ct = 0; + if ((bio->buf & 0xff) == 0xff) { + if (bio_bytein(bio)) { + return 1; + } + bio->ct = 0; + } + return 0; +} diff --git a/src/lib/openjp3d/bio.h b/src/lib/openjp3d/bio.h index 2c91342f..183eb0a1 100644 --- a/src/lib/openjp3d/bio.h +++ b/src/lib/openjp3d/bio.h @@ -1,132 +1,132 @@ -/* - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __BIO_H -#define __BIO_H -/** -@file bio.h -@brief Implementation of an individual bit input-output (BIO) - -The functions in BIO.C have for goal to realize an individual bit input - output. -*/ - -/** @defgroup BIO BIO - Individual bit input-output stream */ -/*@{*/ - -/** -Individual bit input-output stream (BIO) -*/ -typedef struct opj_bio { -/** pointer to the start of the buffer */ - unsigned char *start; -/** pointer to the end of the buffer */ - unsigned char *end; -/** pointer to the present position in the buffer */ - unsigned char *bp; -/** temporary place where each byte is read or written */ - unsigned int buf; -/** coder : number of bits free to write. decoder : number of bits read */ - int ct; -} opj_bio_t; - -/** @name Funciones generales */ -/*@{*/ -/* ----------------------------------------------------------------------- */ -/** -Create a new BIO handle -@return Returns a new BIO handle if successful, returns NULL otherwise -*/ -opj_bio_t* bio_create(void); -/** -Destroy a previously created BIO handle -@param bio BIO handle to destroy -*/ -void bio_destroy(opj_bio_t *bio); -/** -Number of bytes written. -@param bio BIO handle -@return Returns the number of bytes written -*/ -int bio_numbytes(opj_bio_t *bio); -/** -Init encoder -@param bio BIO handle -@param bp Output buffer -@param len Output buffer length -*/ -void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len); -/** -Init decoder -@param bio BIO handle -@param bp Input buffer -@param len Input buffer length -*/ -void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len); -/** -Write bits -@param bio BIO handle -@param v Value of bits -@param n Number of bits to write -*/ -void bio_write(opj_bio_t *bio, int v, int n); -/** -Read bits -@param bio BIO handle -@param n Number of bits to read -@return Returns the corresponding read number -*/ -int bio_read(opj_bio_t *bio, int n); -/** -Flush bits -@param bio BIO handle -@return Returns 1 if successful, returns 0 otherwise -*/ -int bio_flush(opj_bio_t *bio); -/** -Passes the ending bits (coming from flushing) -@param bio BIO handle -@return Returns 1 if successful, returns 0 otherwise -*/ -int bio_inalign(opj_bio_t *bio); -/** -Read a bit -@param bio BIO handle -@return Returns the read bit -*/ -/* MOD antonin */ -/*int bio_getbit(opj_bio_t *bio);*/ -/* DOM */ -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __BIO_H */ - +/* + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __BIO_H +#define __BIO_H +/** +@file bio.h +@brief Implementation of an individual bit input-output (BIO) + +The functions in BIO.C have for goal to realize an individual bit input - output. +*/ + +/** @defgroup BIO BIO - Individual bit input-output stream */ +/*@{*/ + +/** +Individual bit input-output stream (BIO) +*/ +typedef struct opj_bio { +/** pointer to the start of the buffer */ + unsigned char *start; +/** pointer to the end of the buffer */ + unsigned char *end; +/** pointer to the present position in the buffer */ + unsigned char *bp; +/** temporary place where each byte is read or written */ + unsigned int buf; +/** coder : number of bits free to write. decoder : number of bits read */ + int ct; +} opj_bio_t; + +/** @name Funciones generales */ +/*@{*/ +/* ----------------------------------------------------------------------- */ +/** +Create a new BIO handle +@return Returns a new BIO handle if successful, returns NULL otherwise +*/ +opj_bio_t* bio_create(void); +/** +Destroy a previously created BIO handle +@param bio BIO handle to destroy +*/ +void bio_destroy(opj_bio_t *bio); +/** +Number of bytes written. +@param bio BIO handle +@return Returns the number of bytes written +*/ +int bio_numbytes(opj_bio_t *bio); +/** +Init encoder +@param bio BIO handle +@param bp Output buffer +@param len Output buffer length +*/ +void bio_init_enc(opj_bio_t *bio, unsigned char *bp, int len); +/** +Init decoder +@param bio BIO handle +@param bp Input buffer +@param len Input buffer length +*/ +void bio_init_dec(opj_bio_t *bio, unsigned char *bp, int len); +/** +Write bits +@param bio BIO handle +@param v Value of bits +@param n Number of bits to write +*/ +void bio_write(opj_bio_t *bio, int v, int n); +/** +Read bits +@param bio BIO handle +@param n Number of bits to read +@return Returns the corresponding read number +*/ +int bio_read(opj_bio_t *bio, int n); +/** +Flush bits +@param bio BIO handle +@return Returns 1 if successful, returns 0 otherwise +*/ +int bio_flush(opj_bio_t *bio); +/** +Passes the ending bits (coming from flushing) +@param bio BIO handle +@return Returns 1 if successful, returns 0 otherwise +*/ +int bio_inalign(opj_bio_t *bio); +/** +Read a bit +@param bio BIO handle +@return Returns the read bit +*/ +/* MOD antonin */ +/*int bio_getbit(opj_bio_t *bio);*/ +/* DOM */ +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __BIO_H */ + diff --git a/src/lib/openjp3d/cio.c b/src/lib/openjp3d/cio.c index 4e99c847..10bd2af3 100644 --- a/src/lib/openjp3d/cio.c +++ b/src/lib/openjp3d/cio.c @@ -1,217 +1,217 @@ -/* - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "opj_includes.h" - -/* ----------------------------------------------------------------------- */ - -opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length) { - opj_cp_t *cp = NULL; - opj_cio_t *cio = (opj_cio_t*)opj_malloc(sizeof(opj_cio_t)); - if(!cio) return NULL; - cio->cinfo = cinfo; - if(buffer && length) { - /* wrap a user buffer containing the encoded image */ - cio->openmode = OPJ_STREAM_READ; - cio->buffer = buffer; - cio->length = length; - } - else if(!buffer && !length && cinfo) { - /* allocate a buffer for the encoded image */ - cio->openmode = OPJ_STREAM_WRITE; - switch(cinfo->codec_format) { - case CODEC_J3D: - case CODEC_J2K: - cp = ((opj_j3d_t*)cinfo->j3d_handle)->cp; - break; - default: - opj_free(cio); - return NULL; - } - cio->length = cp->tdx * cp->tdy * cp->tdz * cp->tw * cp->th * cp->tl * 4; - cio->buffer = (unsigned char *)opj_malloc(cio->length); - if(!cio->buffer) { - opj_free(cio); - return NULL; - } - } - else { - opj_free(cio); - return NULL; - } - - /* Initialize byte IO */ - cio->start = cio->buffer; - cio->end = cio->buffer + cio->length; - cio->bp = cio->buffer; - - return cio; -} - -void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio) { - if(cio) { - if(cio->openmode == OPJ_STREAM_WRITE) { - /* destroy the allocated buffer */ - opj_free(cio->buffer); - } - /* destroy the cio */ - opj_free(cio); - } -} - - -/* ----------------------------------------------------------------------- */ - -/* - * Get position in byte stream. - */ -int OPJ_CALLCONV cio_tell(opj_cio_t *cio) { - return cio->bp - cio->start; -} - -/* - * Set position in byte stream. - * - * pos : position, in number of bytes, from the beginning of the stream - */ -void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos) { - cio->bp = cio->start + pos; -} - -/* - * Number of bytes left before the end of the stream. - */ -int cio_numbytesleft(opj_cio_t *cio) { - return cio->end - cio->bp; -} - -/* - * Get pointer to the current position in the stream. - */ -unsigned char *cio_getbp(opj_cio_t *cio) { - return cio->bp; -} - -/* - * Write a byte. - */ -static bool cio_byteout(opj_cio_t *cio, unsigned char v) { - if (cio->bp >= cio->end) { - opj_event_msg(cio->cinfo, EVT_ERROR, "write error\n"); - return false; - } - *cio->bp++ = v; - return true; -} - -/* - * Read a byte. - */ -static unsigned char cio_bytein(opj_cio_t *cio) { - if (cio->bp >= cio->end) { - opj_event_msg(cio->cinfo, EVT_ERROR, "read error\n"); - return 0; - } - return *cio->bp++; -} - -/* - * Write some bytes. - * - * v : value to write - * n : number of bytes to write - */ -unsigned int cio_write(opj_cio_t *cio, unsigned int v, int n) { - int i; - for (i = n - 1; i >= 0; i--) { - if( !cio_byteout(cio, (unsigned char) ((v >> (i << 3)) & 0xff)) ) - return 0; - } - return n; -} - -/* - * Read some bytes. - * - * n : number of bytes to read - * - * return : value of the n bytes read - */ -unsigned int cio_read(opj_cio_t *cio, int n) { - int i; - unsigned int v; - v = 0; - for (i = n - 1; i >= 0; i--) { - v += cio_bytein(cio) << (i << 3); - } - return v; -} - -/* - * Skip some bytes. - * - * n : number of bytes to skip - */ -void cio_skip(opj_cio_t *cio, int n) { - cio->bp += n; -} - -/* - * Write some bytes. - * - * v : value to write - * n : number of bytes to write - */ -int cio_write_int(opj_cio_t *cio, int v, int n) { - int i; - for (i = n - 1; i >= 0; i--) { - if( !cio_byteout(cio, (char) ((v >> (i << 3)) & 0xff)) ) - return 0; - } - return n; -} - -/* - * Read some bytes. - * - * n : number of bytes to read - * - * return : value of the n bytes read - */ -int cio_read_int(opj_cio_t *cio, int n) { - int i; - int v; - v = 0; - for (i = n - 1; i >= 0; i--) { - v += cio_bytein(cio) << (i << 3); - } - return v; -} - +/* + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opj_includes.h" + +/* ----------------------------------------------------------------------- */ + +opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length) { + opj_cp_t *cp = NULL; + opj_cio_t *cio = (opj_cio_t*)opj_malloc(sizeof(opj_cio_t)); + if(!cio) return NULL; + cio->cinfo = cinfo; + if(buffer && length) { + /* wrap a user buffer containing the encoded image */ + cio->openmode = OPJ_STREAM_READ; + cio->buffer = buffer; + cio->length = length; + } + else if(!buffer && !length && cinfo) { + /* allocate a buffer for the encoded image */ + cio->openmode = OPJ_STREAM_WRITE; + switch(cinfo->codec_format) { + case CODEC_J3D: + case CODEC_J2K: + cp = ((opj_j3d_t*)cinfo->j3d_handle)->cp; + break; + default: + opj_free(cio); + return NULL; + } + cio->length = cp->tdx * cp->tdy * cp->tdz * cp->tw * cp->th * cp->tl * 4; + cio->buffer = (unsigned char *)opj_malloc(cio->length); + if(!cio->buffer) { + opj_free(cio); + return NULL; + } + } + else { + opj_free(cio); + return NULL; + } + + /* Initialize byte IO */ + cio->start = cio->buffer; + cio->end = cio->buffer + cio->length; + cio->bp = cio->buffer; + + return cio; +} + +void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio) { + if(cio) { + if(cio->openmode == OPJ_STREAM_WRITE) { + /* destroy the allocated buffer */ + opj_free(cio->buffer); + } + /* destroy the cio */ + opj_free(cio); + } +} + + +/* ----------------------------------------------------------------------- */ + +/* + * Get position in byte stream. + */ +int OPJ_CALLCONV cio_tell(opj_cio_t *cio) { + return cio->bp - cio->start; +} + +/* + * Set position in byte stream. + * + * pos : position, in number of bytes, from the beginning of the stream + */ +void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos) { + cio->bp = cio->start + pos; +} + +/* + * Number of bytes left before the end of the stream. + */ +int cio_numbytesleft(opj_cio_t *cio) { + return cio->end - cio->bp; +} + +/* + * Get pointer to the current position in the stream. + */ +unsigned char *cio_getbp(opj_cio_t *cio) { + return cio->bp; +} + +/* + * Write a byte. + */ +static bool cio_byteout(opj_cio_t *cio, unsigned char v) { + if (cio->bp >= cio->end) { + opj_event_msg(cio->cinfo, EVT_ERROR, "write error\n"); + return false; + } + *cio->bp++ = v; + return true; +} + +/* + * Read a byte. + */ +static unsigned char cio_bytein(opj_cio_t *cio) { + if (cio->bp >= cio->end) { + opj_event_msg(cio->cinfo, EVT_ERROR, "read error\n"); + return 0; + } + return *cio->bp++; +} + +/* + * Write some bytes. + * + * v : value to write + * n : number of bytes to write + */ +unsigned int cio_write(opj_cio_t *cio, unsigned int v, int n) { + int i; + for (i = n - 1; i >= 0; i--) { + if( !cio_byteout(cio, (unsigned char) ((v >> (i << 3)) & 0xff)) ) + return 0; + } + return n; +} + +/* + * Read some bytes. + * + * n : number of bytes to read + * + * return : value of the n bytes read + */ +unsigned int cio_read(opj_cio_t *cio, int n) { + int i; + unsigned int v; + v = 0; + for (i = n - 1; i >= 0; i--) { + v += cio_bytein(cio) << (i << 3); + } + return v; +} + +/* + * Skip some bytes. + * + * n : number of bytes to skip + */ +void cio_skip(opj_cio_t *cio, int n) { + cio->bp += n; +} + +/* + * Write some bytes. + * + * v : value to write + * n : number of bytes to write + */ +int cio_write_int(opj_cio_t *cio, int v, int n) { + int i; + for (i = n - 1; i >= 0; i--) { + if( !cio_byteout(cio, (char) ((v >> (i << 3)) & 0xff)) ) + return 0; + } + return n; +} + +/* + * Read some bytes. + * + * n : number of bytes to read + * + * return : value of the n bytes read + */ +int cio_read_int(opj_cio_t *cio, int n) { + int i; + int v; + v = 0; + for (i = n - 1; i >= 0; i--) { + v += cio_bytein(cio) << (i << 3); + } + return v; +} + diff --git a/src/lib/openjp3d/cio.h b/src/lib/openjp3d/cio.h index b7b0c416..aee5b330 100644 --- a/src/lib/openjp3d/cio.h +++ b/src/lib/openjp3d/cio.h @@ -1,100 +1,100 @@ -/* - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __CIO_H -#define __CIO_H -/** -@file cio.h -@brief Implementation of a byte input-output process (CIO) - -The functions in CIO.C have for goal to realize a byte input / output process. -*/ - -/** @defgroup CIO CIO - byte input-output stream */ -/*@{*/ - -/** @name Funciones generales (see also openjp3d.h) */ -/*@{*/ -/* ----------------------------------------------------------------------- */ -/** -Number of bytes left before the end of the stream -@param cio CIO handle -@return Returns the number of bytes before the end of the stream -*/ -int cio_numbytesleft(opj_cio_t *cio); -/** -Get pointer to the current position in the stream -@param cio CIO handle -@return Returns a pointer to the current position -*/ -unsigned char *cio_getbp(opj_cio_t *cio); -/** -Write some bytes -@param cio CIO handle -@param v Value to write -@param n Number of bytes to write -@return Returns the number of bytes written or 0 if an error occured -*/ -unsigned int cio_write(opj_cio_t *cio, unsigned int v, int n); -/** -Read some bytes -@param cio CIO handle -@param n Number of bytes to read -@return Returns the value of the n bytes read -*/ -unsigned int cio_read(opj_cio_t *cio, int n); -/** -Skip some bytes -@param cio CIO handle -@param n Number of bytes to skip -*/ -void cio_skip(opj_cio_t *cio, int n); -/** -Write some bytes -@param cio CIO handle -@param v Signed integer value to write -@param n Number of bytes to write -@return Returns the number of bytes written or 0 if an error occured -*/ -int cio_write_int(opj_cio_t *cio, int v, int n); -/** -Read some bytes -@param cio CIO handle -@param n Number of bytes to read -@return Returns the value of the n bytes read -*/ -int cio_read_int(opj_cio_t *cio, int n); -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __CIO_H */ - +/* + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __CIO_H +#define __CIO_H +/** +@file cio.h +@brief Implementation of a byte input-output process (CIO) + +The functions in CIO.C have for goal to realize a byte input / output process. +*/ + +/** @defgroup CIO CIO - byte input-output stream */ +/*@{*/ + +/** @name Funciones generales (see also openjp3d.h) */ +/*@{*/ +/* ----------------------------------------------------------------------- */ +/** +Number of bytes left before the end of the stream +@param cio CIO handle +@return Returns the number of bytes before the end of the stream +*/ +int cio_numbytesleft(opj_cio_t *cio); +/** +Get pointer to the current position in the stream +@param cio CIO handle +@return Returns a pointer to the current position +*/ +unsigned char *cio_getbp(opj_cio_t *cio); +/** +Write some bytes +@param cio CIO handle +@param v Value to write +@param n Number of bytes to write +@return Returns the number of bytes written or 0 if an error occured +*/ +unsigned int cio_write(opj_cio_t *cio, unsigned int v, int n); +/** +Read some bytes +@param cio CIO handle +@param n Number of bytes to read +@return Returns the value of the n bytes read +*/ +unsigned int cio_read(opj_cio_t *cio, int n); +/** +Skip some bytes +@param cio CIO handle +@param n Number of bytes to skip +*/ +void cio_skip(opj_cio_t *cio, int n); +/** +Write some bytes +@param cio CIO handle +@param v Signed integer value to write +@param n Number of bytes to write +@return Returns the number of bytes written or 0 if an error occured +*/ +int cio_write_int(opj_cio_t *cio, int v, int n); +/** +Read some bytes +@param cio CIO handle +@param n Number of bytes to read +@return Returns the value of the n bytes read +*/ +int cio_read_int(opj_cio_t *cio, int n); +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __CIO_H */ + diff --git a/src/lib/openjp3d/dwt.h b/src/lib/openjp3d/dwt.h index 3fa781b1..9ad6237c 100644 --- a/src/lib/openjp3d/dwt.h +++ b/src/lib/openjp3d/dwt.h @@ -1,101 +1,101 @@ -/* - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium - * Copyrigth (c) 2006, Mónica Díez, LPI-UVA, Spain - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __DWT_H -#define __DWT_H -/** -@file dwt.h -@brief Implementation of a discrete wavelet transform (DWT) - -The functions in DWT.C have for goal to realize forward and inverse discret wavelet -transform with filter 5-3 (reversible) and filter 9-7 (irreversible). The functions in -DWT.C are used by some function in TCD.C. -*/ - -/** @defgroup DWT DWT - Implementation of a discrete wavelet transform */ -/*@{*/ - -/** -DCCS-LIWT properties -*/ - - -typedef struct opj_wtfilt { - double *LPS; - int lenLPS; - double *HPS; - int lenHPS; -} opj_wtfilt_t; -/** @name Funciones generales */ -/*@{*/ -/* ----------------------------------------------------------------------- */ -/** -Forward 5-3 wavelet tranform in 3-D. -Apply a reversible DWT transform to a component of an volume. -@param tilec Tile component information (current tile) -@param dwtid Number of identification of wavelet kernel(s) used in DWT in each direction -*/ -void dwt_encode(opj_tcd_tilecomp_t * tilec, int dwtid[3]); -/** -Inverse 5-3 wavelet tranform in 3-D. -Apply a reversible inverse DWT transform to a component of an volume. -@param tilec Tile component information (current tile) -@param stops Number of decoded resolution levels in each dimension -@param dwtid Number of identification of wavelet kernel(s) used in DWT in each dimension -*/ -void dwt_decode(opj_tcd_tilecomp_t * tilec, int stops[3], int dwtid[3]); -/* ----------------------------------------------------------------------- */ -/** -Get the gain of a subband for the reversible 3-D DWT. -@param orient Number that identifies the subband (0->LLL, 1->HLL, 2->LHL, 3->HHL, 4->LLH, 5->HLH, 6->LHH, 7->HHH) -@param reversible Wavelet transformation type -@return Returns 0 if orient = 0, returns 1 if orient = 1,2 or 4, returns 2 if orient = 3,5 or 6, returns 3 otherwise -*/ -int dwt_getgain(int orient, int reversible); -/** -Get the norm of a wavelet function of a subband at a specified level for the reversible 5-3 DWT or irreversible 9-7 in 3-D. -@param orient Band of the wavelet function -@param level Levels of the wavelet function in X,Y,Z axis -@param dwtid Wavelet transformation identifier -@return Returns the norm of the wavelet function -*/ -double dwt_getnorm(int orient, int level[3], int dwtid[3]); -/* ----------------------------------------------------------------------- */ -/** -Calcula el valor del escalón de cuantificación correspondiente a cada subbanda. -@param tccp Tile component coding parameters -@param prec Precision of data -*/ -void dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, int prec); -/*@}*/ -/*@}*/ - -#endif /* __DWT_H */ +/* + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * Copyrigth (c) 2006, Mónica Díez, LPI-UVA, Spain + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __DWT_H +#define __DWT_H +/** +@file dwt.h +@brief Implementation of a discrete wavelet transform (DWT) + +The functions in DWT.C have for goal to realize forward and inverse discret wavelet +transform with filter 5-3 (reversible) and filter 9-7 (irreversible). The functions in +DWT.C are used by some function in TCD.C. +*/ + +/** @defgroup DWT DWT - Implementation of a discrete wavelet transform */ +/*@{*/ + +/** +DCCS-LIWT properties +*/ + + +typedef struct opj_wtfilt { + double *LPS; + int lenLPS; + double *HPS; + int lenHPS; +} opj_wtfilt_t; +/** @name Funciones generales */ +/*@{*/ +/* ----------------------------------------------------------------------- */ +/** +Forward 5-3 wavelet tranform in 3-D. +Apply a reversible DWT transform to a component of an volume. +@param tilec Tile component information (current tile) +@param dwtid Number of identification of wavelet kernel(s) used in DWT in each direction +*/ +void dwt_encode(opj_tcd_tilecomp_t * tilec, int dwtid[3]); +/** +Inverse 5-3 wavelet tranform in 3-D. +Apply a reversible inverse DWT transform to a component of an volume. +@param tilec Tile component information (current tile) +@param stops Number of decoded resolution levels in each dimension +@param dwtid Number of identification of wavelet kernel(s) used in DWT in each dimension +*/ +void dwt_decode(opj_tcd_tilecomp_t * tilec, int stops[3], int dwtid[3]); +/* ----------------------------------------------------------------------- */ +/** +Get the gain of a subband for the reversible 3-D DWT. +@param orient Number that identifies the subband (0->LLL, 1->HLL, 2->LHL, 3->HHL, 4->LLH, 5->HLH, 6->LHH, 7->HHH) +@param reversible Wavelet transformation type +@return Returns 0 if orient = 0, returns 1 if orient = 1,2 or 4, returns 2 if orient = 3,5 or 6, returns 3 otherwise +*/ +int dwt_getgain(int orient, int reversible); +/** +Get the norm of a wavelet function of a subband at a specified level for the reversible 5-3 DWT or irreversible 9-7 in 3-D. +@param orient Band of the wavelet function +@param level Levels of the wavelet function in X,Y,Z axis +@param dwtid Wavelet transformation identifier +@return Returns the norm of the wavelet function +*/ +double dwt_getnorm(int orient, int level[3], int dwtid[3]); +/* ----------------------------------------------------------------------- */ +/** +Calcula el valor del escalón de cuantificación correspondiente a cada subbanda. +@param tccp Tile component coding parameters +@param prec Precision of data +*/ +void dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, int prec); +/*@}*/ +/*@}*/ + +#endif /* __DWT_H */ diff --git a/src/lib/openjp3d/event.c b/src/lib/openjp3d/event.c index 4c86c332..f9e4da0e 100644 --- a/src/lib/openjp3d/event.c +++ b/src/lib/openjp3d/event.c @@ -1,181 +1,181 @@ -/* - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "opj_includes.h" - -/* ========================================================== -// Utility functions -// ==========================================================*/ - -#ifndef _WIN32 -static char* -i2a(unsigned i, char *a, unsigned r) { - if (i/r > 0) a = i2a(i/r,a,r); - *a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r]; - return a+1; -} - -/** - Transforms integer i into an ascii string and stores the result in a; - string is encoded in the base indicated by r. - @param i Number to be converted - @param a String result - @param r Base of value; must be in the range 2 - 36 - @return Returns a -*/ -static char * -_itoa(int i, char *a, int r) { - r = ((r < 2) || (r > 36)) ? 10 : r; - if(i < 0) { - *a = '-'; - *i2a(-i, a+1, r) = 0; - } - else *i2a(i, a, r) = 0; - return a; -} - -#endif /* !_WIN32 */ - -/* ----------------------------------------------------------------------- */ - -opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context) { - if(cinfo) { - opj_event_mgr_t *previous = cinfo->event_mgr; - cinfo->event_mgr = event_mgr; - cinfo->client_data = context; - return previous; - } - - return NULL; -} - -bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...) { -#define MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */ - opj_msg_callback msg_handler = NULL; - - opj_event_mgr_t *event_mgr = cinfo->event_mgr; - if(event_mgr != NULL) { - switch(event_type) { - case EVT_ERROR: - msg_handler = event_mgr->error_handler; - break; - case EVT_WARNING: - msg_handler = event_mgr->warning_handler; - break; - case EVT_INFO: - msg_handler = event_mgr->info_handler; - break; - default: - break; - } - if(msg_handler == NULL) { - return false; - } - } else { - return false; - } - - if ((fmt != NULL) && (event_mgr != NULL)) { - va_list arg; - int str_length, i, j; - char message[MSG_SIZE]; - memset(message, 0, MSG_SIZE); - /* initialize the optional parameter list */ - va_start(arg, fmt); - /* check the length of the format string */ - str_length = (strlen(fmt) > MSG_SIZE) ? MSG_SIZE : strlen(fmt); - /* parse the format string and put the result in 'message' */ - for (i = 0, j = 0; i < str_length; ++i) { - if (fmt[i] == '%') { - if (i + 1 < str_length) { - switch(tolower(fmt[i + 1])) { - case '%' : - message[j++] = '%'; - break; - case 'o' : /* octal numbers */ - { - char tmp[16]; - _itoa(va_arg(arg, int), tmp, 8); - strcat(message, tmp); - j += strlen(tmp); - ++i; - break; - } - case 'i' : /* decimal numbers */ - case 'd' : - { - char tmp[16]; - _itoa(va_arg(arg, int), tmp, 10); - strcat(message, tmp); - j += strlen(tmp); - ++i; - break; - } - case 'x' : /* hexadecimal numbers */ - { - char tmp[16]; - _itoa(va_arg(arg, int), tmp, 16); - strcat(message, tmp); - j += strlen(tmp); - ++i; - break; - } - case 's' : /* strings */ - { - char *tmp = va_arg(arg, char*); - strcat(message, tmp); - j += strlen(tmp); - ++i; - break; - } - case 'f' : /* floats */ - { - char tmp[16]; - double value = va_arg(arg, double); - sprintf(tmp, "%f", value); - strcat(message, tmp); - j += strlen(tmp); - ++i; - break; - } - }; - } else { - message[j++] = fmt[i]; - } - } else { - message[j++] = fmt[i]; - }; - } - /* deinitialize the optional parameter list */ - va_end(arg); - - /* output the message to the user program */ - msg_handler(message, cinfo->client_data); - } - - return true; -} - +/* + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opj_includes.h" + +/* ========================================================== +// Utility functions +// ==========================================================*/ + +#ifndef _WIN32 +static char* +i2a(unsigned i, char *a, unsigned r) { + if (i/r > 0) a = i2a(i/r,a,r); + *a = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[i%r]; + return a+1; +} + +/** + Transforms integer i into an ascii string and stores the result in a; + string is encoded in the base indicated by r. + @param i Number to be converted + @param a String result + @param r Base of value; must be in the range 2 - 36 + @return Returns a +*/ +static char * +_itoa(int i, char *a, int r) { + r = ((r < 2) || (r > 36)) ? 10 : r; + if(i < 0) { + *a = '-'; + *i2a(-i, a+1, r) = 0; + } + else *i2a(i, a, r) = 0; + return a; +} + +#endif /* !_WIN32 */ + +/* ----------------------------------------------------------------------- */ + +opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context) { + if(cinfo) { + opj_event_mgr_t *previous = cinfo->event_mgr; + cinfo->event_mgr = event_mgr; + cinfo->client_data = context; + return previous; + } + + return NULL; +} + +bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...) { +#define MSG_SIZE 512 /* 512 bytes should be more than enough for a short message */ + opj_msg_callback msg_handler = NULL; + + opj_event_mgr_t *event_mgr = cinfo->event_mgr; + if(event_mgr != NULL) { + switch(event_type) { + case EVT_ERROR: + msg_handler = event_mgr->error_handler; + break; + case EVT_WARNING: + msg_handler = event_mgr->warning_handler; + break; + case EVT_INFO: + msg_handler = event_mgr->info_handler; + break; + default: + break; + } + if(msg_handler == NULL) { + return false; + } + } else { + return false; + } + + if ((fmt != NULL) && (event_mgr != NULL)) { + va_list arg; + int str_length, i, j; + char message[MSG_SIZE]; + memset(message, 0, MSG_SIZE); + /* initialize the optional parameter list */ + va_start(arg, fmt); + /* check the length of the format string */ + str_length = (strlen(fmt) > MSG_SIZE) ? MSG_SIZE : strlen(fmt); + /* parse the format string and put the result in 'message' */ + for (i = 0, j = 0; i < str_length; ++i) { + if (fmt[i] == '%') { + if (i + 1 < str_length) { + switch(tolower(fmt[i + 1])) { + case '%' : + message[j++] = '%'; + break; + case 'o' : /* octal numbers */ + { + char tmp[16]; + _itoa(va_arg(arg, int), tmp, 8); + strcat(message, tmp); + j += strlen(tmp); + ++i; + break; + } + case 'i' : /* decimal numbers */ + case 'd' : + { + char tmp[16]; + _itoa(va_arg(arg, int), tmp, 10); + strcat(message, tmp); + j += strlen(tmp); + ++i; + break; + } + case 'x' : /* hexadecimal numbers */ + { + char tmp[16]; + _itoa(va_arg(arg, int), tmp, 16); + strcat(message, tmp); + j += strlen(tmp); + ++i; + break; + } + case 's' : /* strings */ + { + char *tmp = va_arg(arg, char*); + strcat(message, tmp); + j += strlen(tmp); + ++i; + break; + } + case 'f' : /* floats */ + { + char tmp[16]; + double value = va_arg(arg, double); + sprintf(tmp, "%f", value); + strcat(message, tmp); + j += strlen(tmp); + ++i; + break; + } + }; + } else { + message[j++] = fmt[i]; + } + } else { + message[j++] = fmt[i]; + }; + } + /* deinitialize the optional parameter list */ + va_end(arg); + + /* output the message to the user program */ + msg_handler(message, cinfo->client_data); + } + + return true; +} + diff --git a/src/lib/openjp3d/event.h b/src/lib/openjp3d/event.h index 8f45452b..4b803b56 100644 --- a/src/lib/openjp3d/event.h +++ b/src/lib/openjp3d/event.h @@ -1,58 +1,58 @@ -/* - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef __EVENT_H -#define __EVENT_H -/** -@file event.h -@brief Implementation of a event callback system - -The functions in EVENT.C have for goal to send output messages (errors, warnings, debug) to the user. -*/ - -#define EVT_ERROR 1 /**< Error event type */ -#define EVT_WARNING 2 /**< Warning event type */ -#define EVT_INFO 4 /**< Debug event type */ - -/** @defgroup EVENT EVENT - Implementation of a event callback system */ -/*@{*/ - -/** @name Funciones generales (see also openjp3d.h) */ -/*@{*/ -/* ----------------------------------------------------------------------- */ -/** -Write formatted data to a string and send the string to a user callback. -@param cinfo Codec context info -@param event_type Event type or callback to use to send the message -@param fmt Format-control string (plus optionnal arguments) -@return Returns true if successful, returns false otherwise -*/ -bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...); -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __EVENT_H */ +/* + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __EVENT_H +#define __EVENT_H +/** +@file event.h +@brief Implementation of a event callback system + +The functions in EVENT.C have for goal to send output messages (errors, warnings, debug) to the user. +*/ + +#define EVT_ERROR 1 /**< Error event type */ +#define EVT_WARNING 2 /**< Warning event type */ +#define EVT_INFO 4 /**< Debug event type */ + +/** @defgroup EVENT EVENT - Implementation of a event callback system */ +/*@{*/ + +/** @name Funciones generales (see also openjp3d.h) */ +/*@{*/ +/* ----------------------------------------------------------------------- */ +/** +Write formatted data to a string and send the string to a user callback. +@param cinfo Codec context info +@param event_type Event type or callback to use to send the message +@param fmt Format-control string (plus optionnal arguments) +@return Returns true if successful, returns false otherwise +*/ +bool opj_event_msg(opj_common_ptr cinfo, int event_type, const char *fmt, ...); +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __EVENT_H */ diff --git a/src/lib/openjp3d/jp3d.c b/src/lib/openjp3d/jp3d.c index bbdf0dc5..1b940e70 100644 --- a/src/lib/openjp3d/jp3d.c +++ b/src/lib/openjp3d/jp3d.c @@ -1,2355 +1,2355 @@ -/* - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium - * Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "opj_includes.h" - -/** @defgroup J3D J3D - JPEG-2000 PART 10 codestream reader/writer */ -/*@{*/ - -/** @name Funciones locales */ -/*@{*/ - -/** -Write the SOC marker (Start Of Codestream) -@param j3d J3D handle -*/ -static void j3d_write_soc(opj_j3d_t *j3d); -/** -Read the SOC marker (Start of Codestream) -@param j3d J3D handle -*/ -static void j3d_read_soc(opj_j3d_t *j3d); -/** -Write the SIZ marker (2D volume and tile size) -@param j3d J3D handle -*/ -static void j3d_write_siz(opj_j3d_t *j3d); -/** -Read the SIZ marker (2D volume and tile size) -@param j3d J3D handle -*/ -static void j3d_read_siz(opj_j3d_t *j3d); -/** -Write the NSI marker (3rd volume and tile size) -@param j3d J3D handle -*/ -static void j3d_write_nsi(opj_j3d_t *j3d); -/** -Read the NSI marker (3rd volume and tile size) -@param j3d J3D handle -*/ -static void j3d_read_nsi(opj_j3d_t *j3d); -/** -Write the COM marker (comment) -@param j3d J3D handle -*/ -static void j3d_write_com(opj_j3d_t *j3d); -/** -Read the COM marker (comment) -@param j3d J3D handle -*/ -static void j3d_read_com(opj_j3d_t *j3d); -/** -Write the value concerning the specified component in the marker COD and COC -@param j3d J3D handle -@param compno Number of the component concerned by the information written -*/ -static void j3d_write_cox(opj_j3d_t *j3d, int compno); -/** -Read the value concerning the specified component in the marker COD and COC -@param j3d J3D handle -@param compno Number of the component concerned by the information read -*/ -static void j3d_read_cox(opj_j3d_t *j3d, int compno); -/** -Write the COD marker (coding style default) -@param j3d J3D handle -*/ -static void j3d_write_cod(opj_j3d_t *j3d); -/** -Read the COD marker (coding style default) -@param j3d J3D handle -*/ -static void j3d_read_cod(opj_j3d_t *j3d); -/** -Write the COC marker (coding style component) -@param j3d J3D handle -@param compno Number of the component concerned by the information written -*/ -static void j3d_write_coc(opj_j3d_t *j3d, int compno); -/** -Read the COC marker (coding style component) -@param j3d J3D handle -*/ -static void j3d_read_coc(opj_j3d_t *j3d); -/** -Write the value concerning the specified component in the marker QCD and QCC -@param j3d J3D handle -@param compno Number of the component concerned by the information written -*/ -static void j3d_write_qcx(opj_j3d_t *j3d, int compno); -/** -Read the value concerning the specified component in the marker QCD and QCC -@param j3d J3D handle -@param compno Number of the component concern by the information read -@param len Length of the information in the QCX part of the marker QCD/QCC -*/ -static void j3d_read_qcx(opj_j3d_t *j3d, int compno, int len); -/** -Write the QCD marker (quantization default) -@param j3d J3D handle -*/ -static void j3d_write_qcd(opj_j3d_t *j3d); -/** -Read the QCD marker (quantization default) -@param j3d J3D handle -*/ -static void j3d_read_qcd(opj_j3d_t *j3d); -/** -Write the QCC marker (quantization component) -@param j3d J3D handle -@param compno Number of the component concerned by the information written -*/ -static void j3d_write_qcc(opj_j3d_t *j3d, int compno); -/** -Read the QCC marker (quantization component) -@param j3d J3D handle -*/ -static void j3d_read_qcc(opj_j3d_t *j3d); -/** -Write the POC marker (progression order change) -@param j3d J3D handle -*/ -static void j3d_write_poc(opj_j3d_t *j3d); -/** -Read the POC marker (progression order change) -@param j3d J3D handle -*/ -static void j3d_read_poc(opj_j3d_t *j3d); -/** -Read the CRG marker (component registration) -@param j3d J3D handle -*/ -static void j3d_read_crg(opj_j3d_t *j3d); -/** -Read the TLM marker (tile-part lengths) -@param j3d J3D handle -*/ -static void j3d_read_tlm(opj_j3d_t *j3d); -/** -Read the PLM marker (packet length, main header) -@param j3d J3D handle -*/ -static void j3d_read_plm(opj_j3d_t *j3d); -/** -Read the PLT marker (packet length, tile-part header) -@param j3d J3D handle -*/ -static void j3d_read_plt(opj_j3d_t *j3d); -/** -Read the PPM marker (packet packet headers, main header) -@param j3d J3D handle -*/ -static void j3d_read_ppm(opj_j3d_t *j3d); -/** -Read the PPT marker (packet packet headers, tile-part header) -@param j3d J3D handle -*/ -static void j3d_read_ppt(opj_j3d_t *j3d); -/** -Write the SOT marker (start of tile-part) -@param j3d J3D handle -*/ -static void j3d_write_sot(opj_j3d_t *j3d); -/** -Read the SOT marker (start of tile-part) -@param j3d J3D handle -*/ -static void j3d_read_sot(opj_j3d_t *j3d); -/** -Write the SOD marker (start of data) -@param j3d J3D handle -@param tile_coder Pointer to a TCD handle -*/ -static void j3d_write_sod(opj_j3d_t *j3d, void *tile_coder); -/** -Read the SOD marker (start of data) -@param j3d J3D handle -*/ -static void j3d_read_sod(opj_j3d_t *j3d); -/** -Write the RGN marker (region-of-interest) -@param j3d J3D handle -@param compno Number of the component concerned by the information written -@param tileno Number of the tile concerned by the information written -*/ -static void j3d_write_rgn(opj_j3d_t *j3d, int compno, int tileno); -/** -Read the RGN marker (region-of-interest) -@param j3d J3D handle -*/ -static void j3d_read_rgn(opj_j3d_t *j3d); -/** -Write the EOC marker (end of codestream) -@param j3d J3D handle -*/ -static void j3d_write_eoc(opj_j3d_t *j3d); -/** -Read the EOC marker (end of codestream) -@param j3d J3D handle -*/ -static void j3d_read_eoc(opj_j3d_t *j3d); -/** -Read an unknown marker -@param j3d J3D handle -*/ -static void j3d_read_unk(opj_j3d_t *j3d); -/** -Write the CAP marker (extended capabilities) -@param j3d J3D handle -*/ -static void j3d_write_cap(opj_j3d_t *j3d); -/** -Read the CAP marker (extended capabilities) -@param j3d J3D handle -*/ -static void j3d_read_cap(opj_j3d_t *j3d); -/** -Write the DCO marker (Variable DC offset) -@param j3d J3D handle -*/ -static void j3d_write_dco(opj_j3d_t *j3d); -/** -Read the DCO marker (Variable DC offset) -@param j3d J3D handle -*/ -static void j3d_read_dco(opj_j3d_t *j3d); -/** -Write the ATK marker (arbitrary transformation kernel) -@param j3d J3D handle -*/ -static void j3d_write_atk(opj_j3d_t *j3d); -/** -Read the ATK marker (arbitrary transformation kernel) -@param j3d J3D handle -*/ -static void j3d_read_atk(opj_j3d_t *j3d); -/** -Write the CBD marker (component bit depth definition) -@param j3d J3D handle -*/ -static void j3d_write_cbd(opj_j3d_t *j3d); -/** -Read the CBD marker (component bit depth definition) -@param j3d J3D handle -*/ -static void j3d_read_cbd(opj_j3d_t *j3d); -/** -Write the MCT marker (multiple component transfomation definition) -@param j3d J3D handle -*/ -static void j3d_write_mct(opj_j3d_t *j3d); -/** -Read the MCT marker (multiple component transfomation definition) -@param j3d J3D handle -*/ -static void j3d_read_mct(opj_j3d_t *j3d); -/** -Write the MCC marker (multiple component transfomation collection) -@param j3d J3D handle -*/ -static void j3d_write_mcc(opj_j3d_t *j3d); -/** -Read the MCC marker (multiple component transfomation collection) -@param j3d J3D handle -*/ -static void j3d_read_mcc(opj_j3d_t *j3d); -/** -Write the MCO marker (multiple component transfomation ordering) -@param j3d J3D handle -*/ -static void j3d_write_mco(opj_j3d_t *j3d); -/** -Read the MCO marker (multiple component transfomation ordering) -@param j3d J3D handle -*/ -static void j3d_read_mco(opj_j3d_t *j3d); -/** -Write the NLT marker (non-linearity point transformation) -@param j3d J3D handle -*/ -static void j3d_write_nlt(opj_j3d_t *j3d); -/** -Read the NLT marker (non-linearity point transformation) -@param j3d J3D handle -*/ -static void j3d_read_nlt(opj_j3d_t *j3d); -/*@}*/ - -/* ----------------------------------------------------------------------- */ - -static void j3d_dump_volume(FILE *fd, opj_volume_t * vol) { - int compno; - fprintf(fd, "volume {\n"); - fprintf(fd, " x0=%d, y0=%d, z0=%d, x1=%d, y1=%d, z1=%d\n", vol->x0, vol->y0, vol->z0,vol->x1, vol->y1, vol->z1); - fprintf(fd, " numcomps=%d\n", vol->numcomps); - for (compno = 0; compno < vol->numcomps; compno++) { - opj_volume_comp_t *comp = &vol->comps[compno]; - fprintf(fd, " comp %d {\n", compno); - fprintf(fd, " dx=%d, dy=%d, dz=%d\n", comp->dx, comp->dy, comp->dz); - fprintf(fd, " prec=%d\n", comp->prec); - fprintf(fd, " sgnd=%d\n", comp->sgnd); - fprintf(fd, " }\n"); - } - fprintf(fd, "}\n"); -} - -static void j3d_dump_cp(FILE *fd, opj_volume_t * vol, opj_cp_t * cp) { - int tileno, compno, layno, bandno, resno, numbands; - fprintf(fd, "coding parameters {\n"); - fprintf(fd, " tx0=%d, ty0=%d, tz0=%d\n", cp->tx0, cp->ty0, cp->tz0); - fprintf(fd, " tdx=%d, tdy=%d, tdz=%d\n", cp->tdx, cp->tdy, cp->tdz); - fprintf(fd, " tw=%d, th=%d, tl=%d\n", cp->tw, cp->th, cp->tl); - fprintf(fd, " transform format: %d\n", cp->transform_format); - fprintf(fd, " encoding format: %d\n", cp->encoding_format); - for (tileno = 0; tileno < cp->tw * cp->th * cp->tl; tileno++) { - opj_tcp_t *tcp = &cp->tcps[tileno]; - fprintf(fd, " tile %d {\n", tileno); - fprintf(fd, " csty=%x\n", tcp->csty); - fprintf(fd, " prg=%d\n", tcp->prg); - fprintf(fd, " numlayers=%d\n", tcp->numlayers); - fprintf(fd, " mct=%d\n", tcp->mct); - fprintf(fd, " rates="); - for (layno = 0; layno < tcp->numlayers; layno++) { - fprintf(fd, "%f ", tcp->rates[layno]); - } - fprintf(fd, "\n"); - fprintf(fd, " first=%d\n", tcp->first); - for (compno = 0; compno < vol->numcomps; compno++) { - opj_tccp_t *tccp = &tcp->tccps[compno]; - fprintf(fd, " comp %d {\n", compno); - fprintf(fd, " csty=%x\n", tccp->csty); - fprintf(fd, " numresx=%d, numresy=%d, numresz=%d\n", tccp->numresolution[0], tccp->numresolution[1], tccp->numresolution[2]); - fprintf(fd, " cblkw=%d, cblkh=%d, cblkl=%d\n", tccp->cblk[0], tccp->cblk[1], tccp->cblk[2]); - fprintf(fd, " cblksty=%x\n", tccp->cblksty); - fprintf(fd, " qntsty=%d\n", tccp->qntsty); - fprintf(fd, " numgbits=%d\n", tccp->numgbits); - fprintf(fd, " roishift=%d\n", tccp->roishift); - fprintf(fd, " reversible=%d\n", tccp->reversible); - fprintf(fd, " dwtidx=%d dwtidy=%d dwtidz=%d\n", tccp->dwtid[0], tccp->dwtid[1], tccp->dwtid[2]); - if (tccp->atk != NULL) { - fprintf(fd, " atk.index=%d\n", tccp->atk->index); - fprintf(fd, " atk.coeff_typ=%d\n", tccp->atk->coeff_typ); - fprintf(fd, " atk.filt_cat=%d\n", tccp->atk->filt_cat); - fprintf(fd, " atk.exten=%d\n", tccp->atk->exten); - fprintf(fd, " atk.minit=%d\n", tccp->atk->minit); - fprintf(fd, " atk.wt_typ=%d\n", tccp->atk->wt_typ); - } - fprintf(fd, " stepsizes of bands="); - numbands = (tccp->qntsty == J3D_CCP_QNTSTY_SIQNT) ? 1 : - ( (cp->transform_format == TRF_2D_DWT) ? (tccp->numresolution[0] * 3 - 2) : - (tccp->numresolution[0] * 7 - 6) - 4 *(tccp->numresolution[0] - tccp->numresolution[2]) ); - for (bandno = 0; bandno < numbands; bandno++) { - fprintf(fd, "(%d,%d) ", tccp->stepsizes[bandno].mant,tccp->stepsizes[bandno].expn); - } - fprintf(fd, "\n"); - - if (tccp->csty & J3D_CCP_CSTY_PRT) { - fprintf(fd, " prcw="); - for (resno = 0; resno < tccp->numresolution[0]; resno++) { - fprintf(fd, "%d ", tccp->prctsiz[0][resno]); - } - fprintf(fd, "\n"); - fprintf(fd, " prch="); - for (resno = 0; resno < tccp->numresolution[0]; resno++) { - fprintf(fd, "%d ", tccp->prctsiz[1][resno]); - } - fprintf(fd, "\n"); - fprintf(fd, " prcl="); - for (resno = 0; resno < tccp->numresolution[0]; resno++) { - fprintf(fd, "%d ", tccp->prctsiz[2][resno]); - } - fprintf(fd, "\n"); - } - fprintf(fd, " }\n"); - } - fprintf(fd, " }\n"); - } - fprintf(fd, "}\n"); -} - -/* ----------------------------------------------------------------------- -Extended capabilities -------------------------------------------------------------------------*/ - -static void j3d_write_cap(opj_j3d_t *j3d){ - int len,lenp; - - opj_cio_t *cio = j3d->cio; - cio_write(cio, J3D_MS_CAP, 2); /* CAP */ - lenp = cio_tell(cio); - cio_skip(cio, 2); - cio_write(cio,J3D_CAP_10, 4); - if( J3D_CAP_10 ) - { - cio_write(cio, 0x0, 2); - } - len = cio_tell(cio) - lenp; - cio_seek(cio, lenp); - cio_write(cio, len, 2); /* Lsiz */ - cio_seek(cio, lenp + len); - -} -static void j3d_read_cap(opj_j3d_t *j3d){ - int len, Cap; - opj_cio_t *cio = j3d->cio; - /*cio_read(cio, 2); CAP */ - len = cio_read(cio, 2); - Cap = cio_read(cio, 4); - if(Cap) { - cio_read(cio, 2); - } - assert( len == 2 + 4 + 2 ); -} -static void j3d_write_nsi(opj_j3d_t *j3d) { - int i; - int lenp, len; - int ndim = 3; - - opj_cio_t *cio = j3d->cio; - opj_volume_t *volume = j3d->volume; - opj_cp_t *cp = j3d->cp; - - cio_write(cio, J3D_MS_NSI, 2); /* NSI */ - lenp = cio_tell(cio); - cio_skip(cio, 2); - cio_write(cio, ndim, 1); /* Ndim */ - cio_write(cio, volume->z1, 4); /* Zsiz */ - cio_write(cio, volume->z0, 4); /* Z0siz */ - cio_write(cio, cp->tdz, 4); /* ZTsiz */ - cio_write(cio, cp->tz0, 4); /* ZT0siz */ - for (i = 0; i < volume->numcomps; i++) { - cio_write(cio, volume->comps[i].dz, 1); /* ZRsiz_i */ - } - len = cio_tell(cio) - lenp; - cio_seek(cio, lenp); - cio_write(cio, len, 2); /* Lsiz */ - cio_seek(cio, lenp + len); -} - -static void j3d_read_nsi(opj_j3d_t *j3d) { - int ndim; - int len, i; - - opj_cio_t *cio = j3d->cio; - opj_volume_t *volume = j3d->volume; - opj_cp_t *cp = j3d->cp; - - len = cio_read(cio, 2); /* Lnsi */ - ndim = cio_read(cio, 1); /* Ndim */ - assert( ndim == 3 ); - volume->z1 = cio_read(cio, 4); /* Zsiz */ - volume->z0 = cio_read(cio, 4); /* Z0siz */ - cp->tdz = cio_read(cio, 4); /* ZTsiz */ - cp->tz0 = cio_read(cio, 4); /* ZT0siz */ - for (i = 0; i < volume->numcomps; i++) { - volume->comps[i].dz = cio_read(cio, 1); /* ZRsiz_i */ - } - - /*Initialization of volume*/ - cp->tw = int_ceildiv(volume->x1 - cp->tx0, cp->tdx); - cp->th = int_ceildiv(volume->y1 - cp->ty0, cp->tdy); - cp->tl = int_ceildiv(volume->z1 - cp->tz0, cp->tdz); - cp->tcps = (opj_tcp_t *) opj_malloc(cp->tw * cp->th * cp->tl * sizeof(opj_tcp_t)); - cp->tileno = (int *) opj_malloc(cp->tw * cp->th * cp->tl * sizeof(int)); - cp->tileno_size = 0; - - for (i = 0; i < cp->tw * cp->th * cp->tl ; i++) { - cp->tcps[i].POC = 0; - cp->tcps[i].numpocs = 0; - cp->tcps[i].first = 1; - } - - /* Initialization for PPM marker (Packets header)*/ - cp->ppm = 0; - cp->ppm_data = NULL; - cp->ppm_data_first = NULL; - cp->ppm_previous = 0; - cp->ppm_store = 0; - - j3d->default_tcp->tccps = (opj_tccp_t *) opj_malloc(sizeof(opj_tccp_t) * volume->numcomps); - for (i = 0; i < cp->tw * cp->th * cp->tl ; i++) { - cp->tcps[i].tccps = (opj_tccp_t *) opj_malloc(sizeof(opj_tccp_t) * volume->numcomps); - } - j3d->tile_data = (unsigned char **) opj_malloc(cp->tw * cp->th * cp->tl * sizeof(unsigned char *)); - j3d->tile_len = (int *) opj_malloc(cp->tw * cp->th * cp->tl * sizeof(int)); - j3d->state = J3D_STATE_MH; - -} -static void j3d_write_dco(opj_j3d_t *j3d){ - int lenp, len, i; - int dcotype; - - opj_cio_t *cio = j3d->cio; - opj_volume_t *volume = j3d->volume; - opj_cp_t *cp = j3d->cp; - - dcotype = 1; /* Offsets are 16bit signed integers Table A21 15444-2 */ - cio_write(cio, J3D_MS_DCO, 2); /* DCO */ - lenp = cio_tell(cio); - cio_skip(cio, 2); - cio_write(cio, dcotype, 1); - if (dcotype == 0) { - for (i = 0; i < volume->numcomps; i++) - cio_write(cio, volume->comps[i].dcoffset, 1); /* SPdco_i */ - } else if (dcotype == 1) { - for (i = 0; i < volume->numcomps; i++){ - cio_write(cio, volume->comps[i].dcoffset, 1); /* SPdco_i */ - opj_event_msg(j3d->cinfo, EVT_INFO, "dcotype %d DCO %d \n",dcotype,volume->comps[i].dcoffset); - } - } - len = cio_tell(cio) - lenp; - cio_seek(cio, lenp); - cio_write(cio, len, 2); /* Ldco */ - cio_seek(cio, lenp + len); - -} -static void j3d_read_dco(opj_j3d_t *j3d){ - int len, i; - int dcotype; - - opj_cio_t *cio = j3d->cio; - opj_volume_t *volume = j3d->volume; - opj_cp_t *cp = j3d->cp; - - len = cio_read(cio, 2); /* Lsiz */ - dcotype = cio_read(cio, 1); /*offset 8bit unsigned / 16bit signed integers*/ - if (dcotype == 0) { - for (i = 0; i < volume->numcomps; i++) { - volume->comps[i].dcoffset = cio_read(cio, 1); - if (volume->comps[i].dcoffset > 128) - volume->comps[i].dcoffset = volume->comps[i].dcoffset - 256; - } - } else if (dcotype == 1) { - for (i = 0; i < volume->numcomps; i++) { - volume->comps[i].dcoffset = cio_read(cio, 1); - if (volume->comps[i].dcoffset > 128) - volume->comps[i].dcoffset = volume->comps[i].dcoffset - 256; - } - } - -} -static void j3d_write_atk(opj_j3d_t *j3d){ - int lenp, len, s, k; - - opj_cio_t *cio = j3d->cio; - opj_volume_t *volume = j3d->volume; - opj_atk_t *atk = j3d->cp->tcps->tccps->atk; - - cio_write(cio, J3D_MS_ATK, 2); /* ATK */ - lenp = cio_tell(cio); - cio_skip(cio, 2); - cio_write(cio, atk->index + (atk->coeff_typ << 8) + (atk->filt_cat << 11) - + (atk->wt_typ << 12) + (atk->minit << 13) + (atk->exten << 14), 2); /* Satk */ - if (atk->wt_typ == J3D_ATK_IRR) - cio_write(cio,(unsigned int) (atk->Katk * 8192.0), 1 << atk->coeff_typ); - cio_write(cio, atk->Natk, 1); - for (s = 0; s < atk->Natk; s++){ - if (atk->filt_cat == J3D_ATK_ARB) - cio_write(cio, atk->Oatk[s], 1); - if (atk->wt_typ == J3D_ATK_REV){ - cio_write(cio, atk->Eatk[s], 1); - cio_write(cio, atk->Batk[s], 1); - } - cio_write(cio, atk->LCatk[s], 1); - for (k = 0; k < atk->LCatk[s]; k++) - cio_write(cio,(unsigned int) (atk->Aatk[s][k] * 8192.0), 1 << atk->coeff_typ); - } - len = cio_tell(cio) - lenp; - cio_seek(cio, lenp); - cio_write(cio, len, 2); /* Latk */ - cio_seek(cio, lenp + len); -} -static void j3d_read_atk(opj_j3d_t *j3d){ - int len, i, Satk, k; - - opj_cio_t *cio = j3d->cio; - opj_volume_t *volume = j3d->volume; - opj_cp_t *cp = j3d->cp; - opj_atk_t *atk = cp->tcps->tccps->atk; - - len = cio_read(cio, 2); /* Latk */ - Satk = cio_read(cio, 2); - atk->index = Satk & 0x00ff; - atk->coeff_typ = Satk >> 8 & 0x0007; - atk->filt_cat = Satk >> 11 & 0x0001; - atk->wt_typ = Satk >> 12 & 0x0001; - atk->minit = Satk >> 13 & 0x0001; - atk->exten = Satk >> 14 & 0x0001; - if (atk->wt_typ == J3D_ATK_IRR) - atk->Katk = ((double) cio_read(cio, 1 << atk->coeff_typ) / 8192.0); - atk->Natk = cio_read(cio, 1); - for (i = 0; i < atk->Natk; i++) { - if (atk->filt_cat == J3D_ATK_ARB) - atk->Oatk[i] = cio_read(cio, 1); - if (atk->wt_typ == J3D_ATK_REV){ - atk->Eatk[i] = cio_read(cio, 1); - atk->Batk[i] = cio_read(cio, 1); - } - atk->LCatk[i] = cio_read(cio, 1); - for (k = 0; k < atk->LCatk[i]; k++) - atk->Aatk[i][k] = ((double) cio_read(cio, 1 << atk->coeff_typ) / 8192.0); - } -} -static void j3d_write_cbd(opj_j3d_t *j3d){ -} -static void j3d_read_cbd(opj_j3d_t *j3d){ -} -static void j3d_write_mct(opj_j3d_t *j3d){ -} -static void j3d_read_mct(opj_j3d_t *j3d){ -} -static void j3d_write_mcc(opj_j3d_t *j3d){ -} -static void j3d_read_mcc(opj_j3d_t *j3d){ -} -static void j3d_write_mco(opj_j3d_t *j3d){ -} -static void j3d_read_mco(opj_j3d_t *j3d){ -} -static void j3d_write_nlt(opj_j3d_t *j3d){ -} -static void j3d_read_nlt(opj_j3d_t *j3d){ -} -/* ----------------------------------------------------------------------- -15444-1 codestream syntax -------------------------------------------------------------------------*/ -static void j3d_write_soc(opj_j3d_t *j3d) { - opj_cio_t *cio = j3d->cio; - cio_write(cio, J3D_MS_SOC, 2); -} - -static void j3d_read_soc(opj_j3d_t *j3d) { - j3d->state = J3D_STATE_MHSIZ; -} - -static void j3d_write_siz(opj_j3d_t *j3d) { - int i; - int lenp, len; - int Rsiz; - - opj_cio_t *cio = j3d->cio; - opj_volume_t *volume = j3d->volume; - opj_cp_t *cp = j3d->cp; - - cio_write(cio, J3D_MS_SIZ, 2); /* SIZ */ - lenp = cio_tell(cio); - cio_skip(cio, 2); - /*cio_write(cio, 0, 2);*/ /* Rsiz (capabilities of 15444-1 only) */ - Rsiz = J3D_RSIZ_DCO | J3D_RSIZ_ATK; /** | J3D_RSIZ_MCT | J3D_RSIZ_NONLT (not implemented yet)*/ - cio_write(cio, Rsiz, 2); /* capabilities of WDv5.2*/ - cio_write(cio, volume->x1, 4); /* Xsiz */ - cio_write(cio, volume->y1, 4); /* Ysiz */ - cio_write(cio, volume->x0, 4); /* X0siz */ - cio_write(cio, volume->y0, 4); /* Y0siz */ - cio_write(cio, cp->tdx, 4); /* XTsiz */ - cio_write(cio, cp->tdy, 4); /* YTsiz */ - cio_write(cio, cp->tx0, 4); /* XT0siz */ - cio_write(cio, cp->ty0, 4); /* YT0siz */ - cio_write(cio, volume->numcomps, 2); /* Csiz */ - for (i = 0; i < volume->numcomps; i++) { - cio_write(cio, volume->comps[i].prec - 1 + (volume->comps[i].sgnd << 7), 1); /* Ssiz_i */ - cio_write(cio, volume->comps[i].dx, 1); /* XRsiz_i */ - cio_write(cio, volume->comps[i].dy, 1); /* YRsiz_i */ - } - len = cio_tell(cio) - lenp; - cio_seek(cio, lenp); - cio_write(cio, len, 2); /* Lsiz */ - cio_seek(cio, lenp + len); -} - -static void j3d_read_siz(opj_j3d_t *j3d) { - int len, i; - - opj_cio_t *cio = j3d->cio; - opj_volume_t *volume = j3d->volume; - opj_cp_t *cp = j3d->cp; - - len = cio_read(cio, 2); /* Lsiz */ - cp->rsiz = cio_read(cio, 2); /* Rsiz (capabilities) */ - volume->x1 = cio_read(cio, 4); /* Xsiz */ - volume->y1 = cio_read(cio, 4); /* Ysiz */ - volume->x0 = cio_read(cio, 4); /* X0siz */ - volume->y0 = cio_read(cio, 4); /* Y0siz */ - cp->tdx = cio_read(cio, 4); /* XTsiz */ - cp->tdy = cio_read(cio, 4); /* YTsiz */ - cp->tx0 = cio_read(cio, 4); /* XT0siz */ - cp->ty0 = cio_read(cio, 4); /* YT0siz */ - - volume->numcomps = cio_read(cio, 2); /* Csiz */ - volume->comps = (opj_volume_comp_t *) opj_malloc(volume->numcomps * sizeof(opj_volume_comp_t)); - for (i = 0; i < volume->numcomps; i++) { - int tmp, j; - tmp = cio_read(cio, 1); /* Ssiz_i */ - volume->comps[i].prec = (tmp & 0x7f) + 1; - volume->comps[i].sgnd = tmp >> 7; - volume->comps[i].dx = cio_read(cio, 1); /* XRsiz_i */ - volume->comps[i].dy = cio_read(cio, 1); /* YRsiz_i */ - for (j = 0; j < 3; j++) { - volume->comps[i].resno_decoded[j] = 0; /* number of resolution decoded */ - volume->comps[i].factor[j] = 0; /* reducing factor per component */ - } - } - - if (j3d->cinfo->codec_format == CODEC_J2K){ - volume->z1 = 1; - volume->z0 = 0; - volume->numslices = 1; - cp->tdz = 1; - cp->tz0 = 0; - for (i = 0; i < volume->numcomps; i++) - volume->comps[i].dz = 1; - - /*Initialization of volume*/ - cp->tw = int_ceildiv(volume->x1 - cp->tx0, cp->tdx); - cp->th = int_ceildiv(volume->y1 - cp->ty0, cp->tdy); - cp->tl = int_ceildiv(volume->z1 - cp->tz0, cp->tdz); - cp->tcps = (opj_tcp_t *) opj_malloc(cp->tw * cp->th * cp->tl * sizeof(opj_tcp_t)); - cp->tileno = (int *) opj_malloc(cp->tw * cp->th * cp->tl * sizeof(int)); - cp->tileno_size = 0; - - for (i = 0; i < cp->tw * cp->th * cp->tl ; i++) { - cp->tcps[i].POC = 0; - cp->tcps[i].numpocs = 0; - cp->tcps[i].first = 1; - } - - /* Initialization for PPM marker (Packets header)*/ - cp->ppm = 0; - cp->ppm_data = NULL; - cp->ppm_data_first = NULL; - cp->ppm_previous = 0; - cp->ppm_store = 0; - - j3d->default_tcp->tccps = (opj_tccp_t *) opj_malloc(sizeof(opj_tccp_t) * volume->numcomps); - for (i = 0; i < cp->tw * cp->th * cp->tl ; i++) { - cp->tcps[i].tccps = (opj_tccp_t *) opj_malloc(sizeof(opj_tccp_t) * volume->numcomps); - } - j3d->tile_data = (unsigned char **) opj_malloc(cp->tw * cp->th * cp->tl * sizeof(unsigned char *)); - j3d->tile_len = (int *) opj_malloc(cp->tw * cp->th * cp->tl * sizeof(int)); - j3d->state = J3D_STATE_MH; - } -} - - - -static void j3d_write_com(opj_j3d_t *j3d) { - unsigned int i; - int lenp, len; - - opj_cio_t *cio = j3d->cio; - - cio_write(cio, J3D_MS_COM, 2); - lenp = cio_tell(cio); - cio_skip(cio, 2); - cio_write(cio, 1, 2); - /*opj_event_msg(j3d->cinfo, EVT_INFO, "TRF %D ENCOD %d\n",j3d->cp->transform_format,j3d->cp->encoding_format);*/ - if (j3d->cp->comment != NULL) { - char *comment = j3d->cp->comment; - for (i = 0; i < strlen(comment); i++) { - cio_write(cio, comment[i], 1); - } - } - len = cio_tell(cio) - lenp; - cio_seek(cio, lenp); - cio_write(cio, len, 2); - cio_seek(cio, lenp + len); -} - -static void j3d_read_com(opj_j3d_t *j3d) { - int len; - opj_cio_t *cio = j3d->cio; - - len = cio_read(cio, 2); - cio_read(cio, 2); // read registration - - /*opj_event_msg(j3d->cinfo, EVT_INFO, "TRF %D ENCOD %d\n",j3d->cp->transform_format,j3d->cp->encoding_format);*/ - - cio_skip(cio, len - 4); /*posible comments*/ -} - -static void j3d_write_cox(opj_j3d_t *j3d, int compno) { - int i; - int shift = 2; - - opj_cp_t *cp = j3d->cp; - opj_tcp_t *tcp = &cp->tcps[j3d->curtileno]; - opj_tccp_t *tccp = &tcp->tccps[compno]; - opj_cio_t *cio = j3d->cio; - - cio_write(cio, tccp->numresolution[0] - 1, 1); /* SPcox (D) No of decomposition levels in x-axis*/ - if (j3d->cinfo->codec_format == CODEC_J3D) { - cio_write(cio, tccp->numresolution[1] - 1, 1); /* SPcox (E) No of decomposition levels in y-axis*/ - cio_write(cio, tccp->numresolution[2] - 1, 1); /* SPcox (F) No of decomposition levels in z-axis*/ - } - if (j3d->cinfo->codec_format == CODEC_J3D) { - /* Table A.7 */ - shift = 0; - } - /* (cblkw - 2) + (cblkh - 2) + (cblkl - 2) <= 18*/ - cio_write(cio, tccp->cblk[0] - shift, 1); /* SPcox (G) Cblk width entre 10 y 2 (8 y 0)*/ - cio_write(cio, tccp->cblk[1] - shift, 1); /* SPcox (H) Cblk height*/ - if (j3d->cinfo->codec_format == CODEC_J3D) { - cio_write(cio, tccp->cblk[2] - shift, 1); /* SPcox (I) Cblk depth*/ - } - cio_write(cio, tccp->cblksty, 1); /* SPcox (J) Cblk style*/ - cio_write(cio, tccp->dwtid[0], 1); /* SPcox (K) WT in x-axis 15444-2 Table A10*/ - if (j3d->cinfo->codec_format == CODEC_J3D) { - cio_write(cio, tccp->dwtid[1], 1); /* SPcox (L) WT in y-axis 15444-2 Table A10*/ - cio_write(cio, tccp->dwtid[2], 1); /* SPcox (M) WT in z-axis 15444-2 Table A10*/ - } - - if (tccp->csty & J3D_CCP_CSTY_PRT) { - for (i = 0; i < tccp->numresolution[0]; i++) { - if (i < tccp->numresolution[2]) - cio_write(cio, tccp->prctsiz[0][i] + (tccp->prctsiz[1][i] << 4) + (tccp->prctsiz[2][i] << 8), 2); /* SPcox (N_i) Table A9*/ - else - if (j3d->cinfo->codec_format == CODEC_J3D) - cio_write(cio, tccp->prctsiz[0][i] + (tccp->prctsiz[1][i] << 4), 2); /* SPcox (N_i) Table A9*/ - else - cio_write(cio, tccp->prctsiz[0][i] + (tccp->prctsiz[1][i] << 4), 1); /* SPcox (N_i) Table A9*/ } - } -} - -static void j3d_read_cox(opj_j3d_t *j3d, int compno) { - int i; - int shift = 2; - - opj_cp_t *cp = j3d->cp; - opj_tcp_t *tcp = j3d->state == J3D_STATE_TPH ? &cp->tcps[j3d->curtileno] : j3d->default_tcp; - opj_tccp_t *tccp = &tcp->tccps[compno]; - opj_cio_t *cio = j3d->cio; - - tccp->numresolution[0] = cio_read(cio, 1) + 1; /* SPcox (D) No of decomposition levels in x-axis*/ - if (j3d->cinfo->codec_format == CODEC_J3D) { - tccp->numresolution[1] = cio_read(cio, 1) + 1; /* SPcox (E) No of decomposition levels in y-axis*/ - tccp->numresolution[2] = cio_read(cio, 1) + 1; /* SPcox (F) No of decomposition levels in z-axis*/ - }else if (j3d->cinfo->codec_format == CODEC_J2K) { - tccp->numresolution[1] = tccp->numresolution[0]; - tccp->numresolution[2] = 1; - } - /* check the reduce value */ - cp->reduce[0] = int_min((tccp->numresolution[0])-1, cp->reduce[0]); - cp->reduce[1] = int_min((tccp->numresolution[1])-1, cp->reduce[1]); - cp->reduce[2] = int_min((tccp->numresolution[2])-1, cp->reduce[2]); - - if (j3d->cinfo->codec_format == CODEC_J3D) { - /* Table A.7 */ - shift = 0; - } - tccp->cblk[0] = cio_read(cio, 1) + shift; /* SPcox (G) */ - tccp->cblk[1] = cio_read(cio, 1) + shift; /* SPcox (H) */ - if (j3d->cinfo->codec_format == CODEC_J3D) - tccp->cblk[2] = cio_read(cio, 1) + shift; /* SPcox (I) */ - else - tccp->cblk[2] = tccp->cblk[0]; - - tccp->cblksty = cio_read(cio, 1); /* SPcox (J) */ - tccp->dwtid[0] = cio_read(cio, 1); /* SPcox (K) */ - if (j3d->cinfo->codec_format == CODEC_J3D) { - tccp->dwtid[1] = cio_read(cio, 1); /* SPcox (L) */ - tccp->dwtid[2] = cio_read(cio, 1); /* SPcox (M) */ - }else{ - tccp->dwtid[1] = tccp->dwtid[0]; /* SPcox (L) */ - tccp->dwtid[2] = tccp->dwtid[0]; /* SPcox (M) */ - } - tccp->reversible = (tccp->dwtid[0]>=1 && tccp->dwtid[1]>=1 && tccp->dwtid[2]>=1); /*TODO: only valid for irreversible 9x7 WTs*/ - if (tccp->csty & J3D_CP_CSTY_PRT) { - for (i = 0; i < tccp->numresolution[0]; i++) { - int tmp = cio_read(cio, 2); /* SPcox (N_i) */ - tccp->prctsiz[0][i] = tmp & 0xf; - tccp->prctsiz[1][i] = tmp >> 4; - tccp->prctsiz[2][i] = tmp >> 8; - } - } -} - -static void j3d_write_cod(opj_j3d_t *j3d) { - opj_cp_t *cp = NULL; - opj_tcp_t *tcp = NULL; - int lenp, len; - - opj_cio_t *cio = j3d->cio; - - cio_write(cio, J3D_MS_COD, 2); /* COD */ - - lenp = cio_tell(cio); - cio_skip(cio, 2); - - cp = j3d->cp; - tcp = &cp->tcps[j3d->curtileno]; - - /* Scod : Table A-4*/ - cio_write(cio, tcp->csty, 1); /* Scod : Coding style parameters */ - /* SGcod : Table A-5*/ - cio_write(cio, tcp->prg, 1); /* SGcod (A) : Progression order */ - cio_write(cio, tcp->numlayers, 2); /* SGcod (B) : No of layers */ - cio_write(cio, tcp->mct, 1); /* SGcod (C) : Multiple component transformation usage */ - /* SPcod : Table A-6*/ - j3d_write_cox(j3d, 0); - len = cio_tell(cio) - lenp; - cio_seek(cio, lenp); - cio_write(cio, len, 2); /* Lcod */ - cio_seek(cio, lenp + len); -} - -static void j3d_read_cod(opj_j3d_t *j3d) { - int len, i, pos; - - opj_cio_t *cio = j3d->cio; - opj_cp_t *cp = j3d->cp; - opj_tcp_t *tcp = j3d->state == J3D_STATE_TPH ? &cp->tcps[j3d->curtileno] : j3d->default_tcp; - opj_volume_t *volume = j3d->volume; - - /* Lcod */ - len = cio_read(cio, 2); - /* Scod : Table A-4*/ - tcp->csty = cio_read(cio, 1); - /* SGcod : Table A-5*/ - tcp->prg = (OPJ_PROG_ORDER)cio_read(cio, 1); - tcp->numlayers = cio_read(cio, 2); - tcp->mct = cio_read(cio, 1); - - pos = cio_tell(cio); - for (i = 0; i < volume->numcomps; i++) { - tcp->tccps[i].csty = tcp->csty & J3D_CP_CSTY_PRT; - cio_seek(cio, pos); - j3d_read_cox(j3d, i); - } -} - -static void j3d_write_coc(opj_j3d_t *j3d, int compno) { - int lenp, len; - - opj_cp_t *cp = j3d->cp; - opj_tcp_t *tcp = &cp->tcps[j3d->curtileno]; - opj_volume_t *volume = j3d->volume; - opj_cio_t *cio = j3d->cio; - - cio_write(cio, J3D_MS_COC, 2); /* COC */ - lenp = cio_tell(cio); - cio_skip(cio, 2); - cio_write(cio, compno, volume->numcomps <= 256 ? 1 : 2); /* Ccoc */ - cio_write(cio, tcp->tccps[compno].csty, 1); /* Scoc */ - - j3d_write_cox(j3d, compno); - - len = cio_tell(cio) - lenp; - cio_seek(cio, lenp); - cio_write(cio, len, 2); /* Lcoc */ - cio_seek(cio, lenp + len); -} - -static void j3d_read_coc(opj_j3d_t *j3d) { - int len, compno; - - opj_cp_t *cp = j3d->cp; - opj_tcp_t *tcp = j3d->state == J3D_STATE_TPH ? &cp->tcps[j3d->curtileno] : j3d->default_tcp; - opj_volume_t *volume = j3d->volume; - opj_cio_t *cio = j3d->cio; - - len = cio_read(cio, 2); /* Lcoc */ - compno = cio_read(cio, volume->numcomps <= 256 ? 1 : 2); /* Ccoc */ - tcp->tccps[compno].csty = cio_read(cio, 1); /* Scoc */ - j3d_read_cox(j3d, compno); -} - -static void j3d_write_qcx(opj_j3d_t *j3d, int compno) { - int bandno, numbands; - int expn, mant; - - opj_cp_t *cp = j3d->cp; - opj_tcp_t *tcp = &cp->tcps[j3d->curtileno]; - opj_tccp_t *tccp = &tcp->tccps[compno]; - opj_cio_t *cio = j3d->cio; - - cio_write(cio, tccp->qntsty + (tccp->numgbits << 5), 1); /* Sqcx : Table A28 de 15444-1*/ - - if (j3d->cinfo->codec_format == CODEC_J2K) - numbands = tccp->qntsty == J3D_CCP_QNTSTY_SIQNT ? 1 : tccp->numresolution[0] * 3 - 2; - else if (j3d->cinfo->codec_format == CODEC_J3D) { - int diff = tccp->numresolution[0] - tccp->numresolution[2]; - numbands = (tccp->qntsty == J3D_CCP_QNTSTY_SIQNT) ? 1 : (tccp->numresolution[0] * 7 - 6) - 4 *diff; /* SIQNT vs. SEQNT */ - } - - for (bandno = 0; bandno < numbands; bandno++) { - expn = tccp->stepsizes[bandno].expn; - mant = tccp->stepsizes[bandno].mant; - - if (tccp->qntsty == J3D_CCP_QNTSTY_NOQNT) { - cio_write(cio, expn << 3, 1); /* SPqcx_i */ - } else { - cio_write(cio, (expn << 11) + mant, 2); /* SPqcx_i */ - } - } -} - -static void j3d_read_qcx(opj_j3d_t *j3d, int compno, int len) { - int tmp; - int bandno, numbands; - - opj_cp_t *cp = j3d->cp; - opj_tcp_t *tcp = j3d->state == J3D_STATE_TPH ? &cp->tcps[j3d->curtileno] : j3d->default_tcp; - opj_tccp_t *tccp = &tcp->tccps[compno]; - opj_cio_t *cio = j3d->cio; - - tmp = cio_read(cio, 1); /* Sqcx */ - tccp->qntsty = tmp & 0x1f; - tccp->numgbits = tmp >> 5; - - /*Numbands = 1 si SIQNT - len - 1 si NOQNT - (len - 1) / 2 si SEQNT */ - numbands = tccp->qntsty == J3D_CCP_QNTSTY_SIQNT ? 1 : ((tccp->qntsty == J3D_CCP_QNTSTY_NOQNT) ? len - 1 : (len - 1) / 2); - - for (bandno = 0; bandno < numbands; bandno++) { - int expn, mant; - if (tccp->qntsty == J3D_CCP_QNTSTY_NOQNT) { - expn = cio_read(cio, 1) >> 3; /* SPqcx_i */ - mant = 0; - } else { - tmp = cio_read(cio, 2); /* SPqcx_i */ - expn = tmp >> 11; - mant = tmp & 0x7ff; - } - tccp->stepsizes[bandno].expn = expn; - tccp->stepsizes[bandno].mant = mant; - } - - /* Add Antonin : if scalar_derived -> compute other stepsizes */ - if (tccp->qntsty == J3D_CCP_QNTSTY_SIQNT) { - for (bandno = 1; bandno < J3D_MAXBANDS; bandno++) { - int numbands = (cp->transform_format==TRF_2D_DWT) ? 3 : 7; - tccp->stepsizes[bandno].expn = tccp->stepsizes[0].expn - ((bandno - 1) / numbands); - tccp->stepsizes[bandno].mant = tccp->stepsizes[0].mant; - } - } - /* ddA */ -} - -static void j3d_write_qcd(opj_j3d_t *j3d) { - int lenp, len; - - opj_cio_t *cio = j3d->cio; - - cio_write(cio, J3D_MS_QCD, 2); /* QCD */ - lenp = cio_tell(cio); - cio_skip(cio, 2); - j3d_write_qcx(j3d, 0); /* Sqcd*/ - len = cio_tell(cio) - lenp; - cio_seek(cio, lenp); - cio_write(cio, len, 2); /* Lqcd */ - cio_seek(cio, lenp + len); -} - -static void j3d_read_qcd(opj_j3d_t *j3d) { - int len, i, pos; - - opj_cio_t *cio = j3d->cio; - opj_volume_t *volume = j3d->volume; - - len = cio_read(cio, 2); /* Lqcd */ - pos = cio_tell(cio); - for (i = 0; i < volume->numcomps; i++) { - cio_seek(cio, pos); - j3d_read_qcx(j3d, i, len - 2); - } -} - -static void j3d_write_qcc(opj_j3d_t *j3d, int compno) { - int lenp, len; - - opj_cio_t *cio = j3d->cio; - - cio_write(cio, J3D_MS_QCC, 2); /* QCC */ - lenp = cio_tell(cio); - cio_skip(cio, 2); - cio_write(cio, compno, j3d->volume->numcomps <= 256 ? 1 : 2); /* Cqcc */ - j3d_write_qcx(j3d, compno); - len = cio_tell(cio) - lenp; - cio_seek(cio, lenp); - cio_write(cio, len, 2); /* Lqcc */ - cio_seek(cio, lenp + len); -} - -static void j3d_read_qcc(opj_j3d_t *j3d) { - int len, compno; - int numcomp = j3d->volume->numcomps; - opj_cio_t *cio = j3d->cio; - - len = cio_read(cio, 2); /* Lqcc */ - compno = cio_read(cio, numcomp <= 256 ? 1 : 2); /* Cqcc */ - j3d_read_qcx(j3d, compno, len - 2 - (numcomp <= 256 ? 1 : 2)); -} - -static void j3d_write_poc(opj_j3d_t *j3d) { - int len, numpchgs, i; - - int numcomps = j3d->volume->numcomps; - - opj_cp_t *cp = j3d->cp; - opj_tcp_t *tcp = &cp->tcps[j3d->curtileno]; - opj_tccp_t *tccp = &tcp->tccps[0]; - opj_cio_t *cio = j3d->cio; - - numpchgs = tcp->numpocs; - cio_write(cio, J3D_MS_POC, 2); /* POC */ - len = 2 + (5 + 2 * (numcomps <= 256 ? 1 : 2)) * numpchgs; - cio_write(cio, len, 2); /* Lpoc */ - for (i = 0; i < numpchgs; i++) { - opj_poc_t *poc = &tcp->pocs[i]; - cio_write(cio, poc->resno0, 1); /* RSpoc_i */ - cio_write(cio, poc->compno0, (numcomps <= 256 ? 1 : 2)); /* CSpoc_i */ - cio_write(cio, poc->layno1, 2); /* LYEpoc_i */ - poc->layno1 = int_min(poc->layno1, tcp->numlayers); - cio_write(cio, poc->resno1, 1); /* REpoc_i */ - poc->resno1 = int_min(poc->resno1, tccp->numresolution[0]); - cio_write(cio, poc->compno1, (numcomps <= 256 ? 1 : 2)); /* CEpoc_i */ - poc->compno1 = int_min(poc->compno1, numcomps); - cio_write(cio, poc->prg, 1); /* Ppoc_i */ - } -} - -static void j3d_read_poc(opj_j3d_t *j3d) { - int len, numpchgs, i, old_poc; - - int numcomps = j3d->volume->numcomps; - - opj_cp_t *cp = j3d->cp; - opj_tcp_t *tcp = j3d->state == J3D_STATE_TPH ? &cp->tcps[j3d->curtileno] : j3d->default_tcp; - opj_tccp_t *tccp = &tcp->tccps[0]; - opj_cio_t *cio = j3d->cio; - - old_poc = tcp->POC ? tcp->numpocs + 1 : 0; - tcp->POC = 1; - len = cio_read(cio, 2); /* Lpoc */ - numpchgs = (len - 2) / (5 + 2 * (numcomps <= 256 ? 1 : 2)); - - for (i = old_poc; i < numpchgs + old_poc; i++) { - opj_poc_t *poc; - poc = &tcp->pocs[i]; - poc->resno0 = cio_read(cio, 1); /* RSpoc_i */ - poc->compno0 = cio_read(cio, numcomps <= 256 ? 1 : 2); /* CSpoc_i */ - poc->layno1 = int_min(cio_read(cio, 2), (unsigned int) tcp->numlayers); /* LYEpoc_i */ - poc->resno1 = int_min(cio_read(cio, 1), (unsigned int) tccp->numresolution[0]); /* REpoc_i */ - poc->compno1 = int_min( - cio_read(cio, numcomps <= 256 ? 1 : 2), (unsigned int) numcomps); /* CEpoc_i */ - poc->prg = (OPJ_PROG_ORDER)cio_read(cio, 1); /* Ppoc_i */ - } - - tcp->numpocs = numpchgs + old_poc - 1; -} - -static void j3d_read_crg(opj_j3d_t *j3d) { - int len, i, Xcrg_i, Ycrg_i, Zcrg_i; - - opj_cio_t *cio = j3d->cio; - int numcomps = j3d->volume->numcomps; - - len = cio_read(cio, 2); /* Lcrg */ - for (i = 0; i < numcomps; i++) { - Xcrg_i = cio_read(cio, 2); /* Xcrg_i */ - Ycrg_i = cio_read(cio, 2); /* Ycrg_i */ - Zcrg_i = cio_read(cio, 2); /* Zcrg_i */ - } -} - -static void j3d_read_tlm(opj_j3d_t *j3d) { - int len, Ztlm, Stlm, ST, SP, tile_tlm, i; - long int Ttlm_i, Ptlm_i; - - opj_cio_t *cio = j3d->cio; - - len = cio_read(cio, 2); /* Ltlm */ - Ztlm = cio_read(cio, 1); /* Ztlm */ - Stlm = cio_read(cio, 1); /* Stlm */ - ST = ((Stlm >> 4) & 0x01) + ((Stlm >> 4) & 0x02); - SP = (Stlm >> 6) & 0x01; - tile_tlm = (len - 4) / ((SP + 1) * 2 + ST); - for (i = 0; i < tile_tlm; i++) { - Ttlm_i = cio_read(cio, ST); /* Ttlm_i */ - Ptlm_i = cio_read(cio, SP ? 4 : 2); /* Ptlm_i */ - } -} - -static void j3d_read_plm(opj_j3d_t *j3d) { - int len, i, Zplm, Nplm, add, packet_len = 0; - - opj_cio_t *cio = j3d->cio; - - len = cio_read(cio, 2); /* Lplm */ - Zplm = cio_read(cio, 1); /* Zplm */ - len -= 3; - while (len > 0) { - Nplm = cio_read(cio, 4); /* Nplm */ - len -= 4; - for (i = Nplm; i > 0; i--) { - add = cio_read(cio, 1); - len--; - packet_len = (packet_len << 7) + add; /* Iplm_ij */ - if ((add & 0x80) == 0) { - /* New packet */ - packet_len = 0; - } - if (len <= 0) - break; - } - } -} - -static void j3d_read_plt(opj_j3d_t *j3d) { - int len, i, Zplt, packet_len = 0, add; - - opj_cio_t *cio = j3d->cio; - - len = cio_read(cio, 2); /* Lplt */ - Zplt = cio_read(cio, 1); /* Zplt */ - for (i = len - 3; i > 0; i--) { - add = cio_read(cio, 1); - packet_len = (packet_len << 7) + add; /* Iplt_i */ - if ((add & 0x80) == 0) { - /* New packet */ - packet_len = 0; - } - } -} - -static void j3d_read_ppm(opj_j3d_t *j3d) { - int len, Z_ppm, i, j; - int N_ppm; - - opj_cp_t *cp = j3d->cp; - opj_cio_t *cio = j3d->cio; - - len = cio_read(cio, 2); - cp->ppm = 1; - - Z_ppm = cio_read(cio, 1); /* Z_ppm */ - len -= 3; - while (len > 0) { - if (cp->ppm_previous == 0) { - N_ppm = cio_read(cio, 4); /* N_ppm */ - len -= 4; - } else { - N_ppm = cp->ppm_previous; - } - j = cp->ppm_store; - if (Z_ppm == 0) { /* First PPM marker */ - cp->ppm_data = (unsigned char *) opj_malloc(N_ppm * sizeof(unsigned char)); - cp->ppm_data_first = cp->ppm_data; - cp->ppm_len = N_ppm; - } else { /* NON-first PPM marker */ - cp->ppm_data = (unsigned char *) opj_realloc(cp->ppm_data, (N_ppm + cp->ppm_store) * sizeof(unsigned char)); - cp->ppm_data_first = cp->ppm_data; - cp->ppm_len = N_ppm + cp->ppm_store; - } - for (i = N_ppm; i > 0; i--) { /* Read packet header */ - cp->ppm_data[j] = cio_read(cio, 1); - j++; - len--; - if (len == 0) - break; /* Case of non-finished packet header in present marker but finished in next one */ - } - cp->ppm_previous = i - 1; - cp->ppm_store = j; - } -} - -static void j3d_read_ppt(opj_j3d_t *j3d) { - int len, Z_ppt, i, j = 0; - - opj_cp_t *cp = j3d->cp; - opj_tcp_t *tcp = cp->tcps + j3d->curtileno; - opj_cio_t *cio = j3d->cio; - - len = cio_read(cio, 2); - Z_ppt = cio_read(cio, 1); - tcp->ppt = 1; - if (Z_ppt == 0) { /* First PPT marker */ - tcp->ppt_data = (unsigned char *) opj_malloc((len - 3) * sizeof(unsigned char)); - tcp->ppt_data_first = tcp->ppt_data; - tcp->ppt_store = 0; - tcp->ppt_len = len - 3; - } else { /* NON-first PPT marker */ - tcp->ppt_data = (unsigned char *) opj_realloc(tcp->ppt_data, (len - 3 + tcp->ppt_store) * sizeof(unsigned char)); - tcp->ppt_data_first = tcp->ppt_data; - tcp->ppt_len = len - 3 + tcp->ppt_store; - } - j = tcp->ppt_store; - for (i = len - 3; i > 0; i--) { - tcp->ppt_data[j] = cio_read(cio, 1); - j++; - } - tcp->ppt_store = j; -} - -static void j3d_write_sot(opj_j3d_t *j3d) { - int lenp, len; - - opj_cio_t *cio = j3d->cio; - - j3d->sot_start = cio_tell(cio); - cio_write(cio, J3D_MS_SOT, 2); /* SOT */ - lenp = cio_tell(cio); - cio_skip(cio, 2); /* Lsot (further) */ - cio_write(cio, j3d->curtileno, 2); /* Isot */ - cio_skip(cio, 4); /* Psot (further in j3d_write_sod) */ - cio_write(cio, 0, 1); /* TPsot */ - cio_write(cio, 1, 1); /* TNsot (no of tile-parts of this tile in this codestream)*/ - len = cio_tell(cio) - lenp; - cio_seek(cio, lenp); - cio_write(cio, len, 2); /* Lsot */ - cio_seek(cio, lenp + len); -} - -static void j3d_read_sot(opj_j3d_t *j3d) { - int len, tileno, totlen, partno, numparts, i; - opj_tcp_t *tcp = NULL; - char status = 0; - - opj_cp_t *cp = j3d->cp; - opj_cio_t *cio = j3d->cio; - - len = cio_read(cio, 2); - tileno = cio_read(cio, 2); - - if (cp->tileno_size == 0) { - cp->tileno[cp->tileno_size] = tileno; - cp->tileno_size++; - } else { - i = 0; - while (i < cp->tileno_size && status == 0) { - status = cp->tileno[i] == tileno ? 1 : 0; - i++; - } - if (status == 0) { - cp->tileno[cp->tileno_size] = tileno; - cp->tileno_size++; - } - } - - totlen = cio_read(cio, 4); - if (!totlen) - totlen = cio_numbytesleft(cio) + 8; - - partno = cio_read(cio, 1); - numparts = cio_read(cio, 1); - - j3d->curtileno = tileno; - j3d->eot = cio_getbp(cio) - 12 + totlen; - j3d->state = J3D_STATE_TPH; - tcp = &cp->tcps[j3d->curtileno]; - - if (tcp->first == 1) { - - /* Initialization PPT */ - opj_tccp_t *tmp = tcp->tccps; - memcpy(tcp, j3d->default_tcp, sizeof(opj_tcp_t)); - tcp->ppt = 0; - tcp->ppt_data = NULL; - tcp->ppt_data_first = NULL; - tcp->tccps = tmp; - - for (i = 0; i < j3d->volume->numcomps; i++) { - tcp->tccps[i] = j3d->default_tcp->tccps[i]; - } - cp->tcps[j3d->curtileno].first = 0; - } -} - -static void j3d_write_sod(opj_j3d_t *j3d, void *tile_coder) { - int l, layno; - int totlen; - opj_tcp_t *tcp = NULL; - opj_volume_info_t *volume_info = NULL; - - opj_tcd_t *tcd = (opj_tcd_t*)tile_coder; /* cast is needed because of conflicts in header inclusions */ - opj_cp_t *cp = j3d->cp; - opj_cio_t *cio = j3d->cio; - - cio_write(cio, J3D_MS_SOD, 2); - if (j3d->curtileno == 0) { - j3d->sod_start = cio_tell(cio) + j3d->pos_correction; - } - - /* INDEX >> */ - volume_info = j3d->volume_info; - if (volume_info && volume_info->index_on) { - volume_info->tile[j3d->curtileno].end_header = cio_tell(cio) + j3d->pos_correction - 1; - } - /* << INDEX */ - - tcp = &cp->tcps[j3d->curtileno]; - for (layno = 0; layno < tcp->numlayers; layno++) { - tcp->rates[layno] -= tcp->rates[layno] ? (j3d->sod_start / (cp->th * cp->tw * cp->tl)) : 0; - } - - if(volume_info) { - volume_info->num = 0; - } - - l = tcd_encode_tile(tcd, j3d->curtileno, cio_getbp(cio), cio_numbytesleft(cio) - 2, volume_info); - - /* Writing Psot in SOT marker */ - totlen = cio_tell(cio) + l - j3d->sot_start; - cio_seek(cio, j3d->sot_start + 6); - cio_write(cio, totlen, 4); - cio_seek(cio, j3d->sot_start + totlen); -} - -static void j3d_read_sod(opj_j3d_t *j3d) { - int len, truncate = 0, i; - unsigned char *data = NULL, *data_ptr = NULL; - - opj_cio_t *cio = j3d->cio; - int curtileno = j3d->curtileno; - - len = int_min(j3d->eot - cio_getbp(cio), cio_numbytesleft(cio) + 1); - - if (len == cio_numbytesleft(cio) + 1) { - truncate = 1; /* Case of a truncate codestream */ - } - - data = (unsigned char *) opj_malloc((j3d->tile_len[curtileno] + len) * sizeof(unsigned char)); - - for (i = 0; i < j3d->tile_len[curtileno]; i++) { - data[i] = j3d->tile_data[curtileno][i]; - } - - data_ptr = data + j3d->tile_len[curtileno]; - for (i = 0; i < len; i++) { - data_ptr[i] = cio_read(cio, 1); - } - - j3d->tile_len[curtileno] += len; - opj_free(j3d->tile_data[curtileno]); - j3d->tile_data[curtileno] = data; - - if (!truncate) { - j3d->state = J3D_STATE_TPHSOT; - } else { - j3d->state = J3D_STATE_NEOC; /* RAJOUTE !! */ - } -} - -static void j3d_write_rgn(opj_j3d_t *j3d, int compno, int tileno) { - - opj_cp_t *cp = j3d->cp; - opj_tcp_t *tcp = &cp->tcps[tileno]; - opj_cio_t *cio = j3d->cio; - int numcomps = j3d->volume->numcomps; - - cio_write(cio, J3D_MS_RGN, 2); /* RGN */ - cio_write(cio, numcomps <= 256 ? 5 : 6, 2); /* Lrgn */ - cio_write(cio, compno, numcomps <= 256 ? 1 : 2); /* Crgn */ - cio_write(cio, 0, 1); /* Srgn */ - cio_write(cio, tcp->tccps[compno].roishift, 1); /* SPrgn */ -} - -static void j3d_read_rgn(opj_j3d_t *j3d) { - int len, compno, roisty; - - opj_cp_t *cp = j3d->cp; - opj_tcp_t *tcp = j3d->state == J3D_STATE_TPH ? &cp->tcps[j3d->curtileno] : j3d->default_tcp; - opj_cio_t *cio = j3d->cio; - int numcomps = j3d->volume->numcomps; - - len = cio_read(cio, 2); /* Lrgn */ - compno = cio_read(cio, numcomps <= 256 ? 1 : 2); /* Crgn */ - roisty = cio_read(cio, 1); /* Srgn */ - tcp->tccps[compno].roishift = cio_read(cio, 1); /* SPrgn */ -} - -static void j3d_write_eoc(opj_j3d_t *j3d) { - opj_cio_t *cio = j3d->cio; - /* opj_event_msg(j3d->cinfo, "%.8x: EOC\n", cio_tell(cio) + j3d->pos_correction); */ - cio_write(cio, J3D_MS_EOC, 2); -} - -static void j3d_read_eoc(opj_j3d_t *j3d) { - int i, tileno; - -#ifndef NO_PACKETS_DECODING - opj_tcd_t *tcd = tcd_create(j3d->cinfo); - tcd_malloc_decode(tcd, j3d->volume, j3d->cp); - /*j3d_dump_volume(stdout, tcd->volume); - j3d_dump_cp(stdout, tcd->volume, tcd->cp);*/ - for (i = 0; i < j3d->cp->tileno_size; i++) { - tileno = j3d->cp->tileno[i]; - /*opj_event_msg(j3d->cinfo, EVT_INFO, "tcd_decode_tile \n");*/ - tcd_decode_tile(tcd, j3d->tile_data[tileno], j3d->tile_len[tileno], tileno); - opj_free(j3d->tile_data[tileno]); - j3d->tile_data[tileno] = NULL; - } - tcd_free_decode(tcd); - tcd_destroy(tcd); -#else - for (i = 0; i < j3d->cp->tileno_size; i++) { - tileno = j3d->cp->tileno[i]; - opj_free(j3d->tile_data[tileno]); - j3d->tile_data[tileno] = NULL; - } -#endif - - j3d->state = J3D_STATE_MT; -} - -static void j3d_read_unk(opj_j3d_t *j3d) { - opj_event_msg(j3d->cinfo, EVT_WARNING, "Unknown marker\n"); -} - -static opj_atk_t atk_info_wt[] = { - {0, 1, J3D_ATK_WS, J3D_ATK_IRR, 0, J3D_ATK_WS, 1.230174104, 4, {0}, {0}, {0}, {1,1,1,1}, {-1.586134342059924, -0.052980118572961, 0.882911075530934, 0.443506852043971}},/* WT 9-7 IRR*/ - {1, 0, J3D_ATK_WS, J3D_ATK_REV, 0, J3D_ATK_WS, 0, 2, {0}, {1,2}, {1,2}, {1,1}, {-1.0,1.0}},/* WT 5-3 REV*/ - {2, 0, J3D_ATK_ARB, J3D_ATK_REV, 0, J3D_ATK_CON, 0, 2, {0,0}, {0,1}, {0,1}, {1,1}, {{-1.0},{1.0}}}, /* WT 2-2 REV*/ - {3, 0, J3D_ATK_ARB, J3D_ATK_REV, 1, J3D_ATK_CON, 0, 3, {0,0,-1}, {0,1,2}, {0,1,2}, {1,1,3}, {{-1.0},{1.0},{1.0,0.0,-1.0}}}, /* WT 2-6 REV*/ - {4, 0, J3D_ATK_ARB, J3D_ATK_REV, 1, J3D_ATK_CON, 0, 3, {0,0,-2}, {0,1,6}, {0,1,32}, {1,1,5}, {{-1},{1},{-3.0,22.0,0.0,-22.0,3.0}}}, /* WT 2-10 REV*/ - {5, 1, J3D_ATK_ARB, J3D_ATK_IRR, 1, J3D_ATK_WS, 1, 7, {0}, {0}, {0}, {1,1,2,1,2,1,3},{{-1},{1.58613434206},{-0.460348209828, 0.460348209828},{0.25},{0.374213867768,-0.374213867768},{-1.33613434206},{0.29306717103,0,-0.29306717103}}}, /* WT 6-10 IRR*/ - {6, 1, J3D_ATK_ARB, J3D_ATK_IRR, 0, J3D_ATK_WS, 1, 11, {0}, {0}, {0}, {1,1,2,1,2,1,2,1,2,1,5},{{-1},{0,99715069105},{-1.00573127827, 1.00573127827},{-0.27040357631},{2.20509972343, -2.20509972343},{0.08059995736}, - {-1.62682532350, 1.62682532350},{0.52040357631},{0.60404664250, -0.60404664250},{-0.82775064841},{-0.06615812964, 0.29402137720, 0, -0.29402137720, 0.06615812964}}}, /* WT 10-18 IRR*/ - {7, 1, J3D_ATK_WS, J3D_ATK_IRR, 0, J3D_ATK_WS, 1, 2, {0}, {0}, {0}, {1,1}, {-0.5, 0.25}}, /* WT 5-3 IRR*/ - {8, 0, J3D_ATK_WS, J3D_ATK_REV, 0, J3D_ATK_WS, 0, 2, {0}, {4,4}, {8,8}, {2,2}, {{-9,1},{5,-1}}} /* WT 13-7 REV*/ -}; - -typedef struct opj_dec_mstabent { - /** marker value */ - int id; - /** value of the state when the marker can appear */ - int states; - /** action linked to the marker */ - void (*handler) (opj_j3d_t *j3d); -} opj_dec_mstabent_t; - -opj_dec_mstabent_t j3d_dec_mstab[] = { - {J3D_MS_SOC, J3D_STATE_MHSOC, j3d_read_soc}, - {J3D_MS_SOT, J3D_STATE_MH | J3D_STATE_TPHSOT, j3d_read_sot}, - {J3D_MS_SOD, J3D_STATE_TPH, j3d_read_sod}, - {J3D_MS_EOC, J3D_STATE_TPHSOT, j3d_read_eoc}, - {J3D_MS_CAP, J3D_STATE_MHSIZ, j3d_read_cap}, - {J3D_MS_SIZ, J3D_STATE_MHSIZ, j3d_read_siz}, - {J3D_MS_NSI, J3D_STATE_MHSIZ, j3d_read_nsi}, - {J3D_MS_COD, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_cod}, - {J3D_MS_COC, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_coc}, - {J3D_MS_RGN, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_rgn}, - {J3D_MS_QCD, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_qcd}, - {J3D_MS_QCC, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_qcc}, - {J3D_MS_POC, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_poc}, - {J3D_MS_TLM, J3D_STATE_MH, j3d_read_tlm}, - {J3D_MS_PLM, J3D_STATE_MH, j3d_read_plm}, - {J3D_MS_PLT, J3D_STATE_TPH, j3d_read_plt}, - {J3D_MS_PPM, J3D_STATE_MH, j3d_read_ppm}, - {J3D_MS_PPT, J3D_STATE_TPH, j3d_read_ppt}, - {J3D_MS_SOP, 0, 0}, - {J3D_MS_CRG, J3D_STATE_MH, j3d_read_crg}, - {J3D_MS_COM, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_com}, - {J3D_MS_DCO, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_dco}, - {J3D_MS_ATK, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_atk}, - {0, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_unk} - /*, -->must define the j3d_read functions - {J3D_MS_CBD, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_cbd}, - {J3D_MS_MCT, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_mct}, - {J3D_MS_MCC, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_mcc}, - {J3D_MS_MCO, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_mco}, - {J3D_MS_NLT, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_nlt}, - {J3D_MS_VMS, J3D_STATE_MH, j3d_read_vms}, - {J3D_MS_DFS, J3D_STATE_MH, j3d_read_dfs}, - {J3D_MS_ADS, J3D_STATE_MH, j3d_read_ads}, - {J3D_MS_QPD, J3D_STATE_MH, j3d_read_qpd}, - {J3D_MS_QPC, J3D_STATE_TPH, j3d_read_qpc}*/ -}; - -/** -Read the lookup table containing all the marker, status and action -@param id Marker value -*/ -static opj_dec_mstabent_t *j3d_dec_mstab_lookup(int id) { - opj_dec_mstabent_t *e; - for (e = j3d_dec_mstab; e->id != 0; e++) { - if (e->id == id) { - break; - } - } - return e; -} - -/* ----------------------------------------------------------------------- */ -/* J3D / JPT decoder interface */ -/* ----------------------------------------------------------------------- */ - -opj_j3d_t* j3d_create_decompress(opj_common_ptr cinfo) { - opj_j3d_t *j3d = (opj_j3d_t*)opj_malloc(sizeof(opj_j3d_t)); - if(j3d) { - j3d->cinfo = cinfo; - j3d->default_tcp = (opj_tcp_t*)opj_malloc(sizeof(opj_tcp_t)); - if(!j3d->default_tcp) { - opj_free(j3d); - return NULL; - } - } - return j3d; -} - -void j3d_destroy_decompress(opj_j3d_t *j3d) { - int i = 0; - - if(j3d->tile_len != NULL) { - opj_free(j3d->tile_len); - } - if(j3d->tile_data != NULL) { - opj_free(j3d->tile_data); - } - if(j3d->default_tcp != NULL) { - opj_tcp_t *default_tcp = j3d->default_tcp; - if(default_tcp->ppt_data_first != NULL) { - opj_free(default_tcp->ppt_data_first); - } - if(j3d->default_tcp->tccps != NULL) { - opj_free(j3d->default_tcp->tccps); - } - opj_free(j3d->default_tcp); - } - if(j3d->cp != NULL) { - opj_cp_t *cp = j3d->cp; - if(cp->tcps != NULL) { - for(i = 0; i < cp->tw * cp->th * cp->tl; i++) { - if(cp->tcps[i].ppt_data_first != NULL) { - opj_free(cp->tcps[i].ppt_data_first); - } - if(cp->tcps[i].tccps != NULL) { - opj_free(cp->tcps[i].tccps); - } - } - opj_free(cp->tcps); - } - if(cp->ppm_data_first != NULL) { - opj_free(cp->ppm_data_first); - } - if(cp->tileno != NULL) { - opj_free(cp->tileno); - } - if(cp->comment != NULL) { - opj_free(cp->comment); - } - - opj_free(cp); - } - - opj_free(j3d); -} - -void j3d_setup_decoder(opj_j3d_t *j3d, opj_dparameters_t *parameters) { - if(j3d && parameters) { - /* create and initialize the coding parameters structure */ - opj_cp_t *cp = (opj_cp_t*)opj_malloc(sizeof(opj_cp_t)); - cp->reduce[0] = parameters->cp_reduce[0]; - cp->reduce[1] = parameters->cp_reduce[1]; - cp->reduce[2] = parameters->cp_reduce[2]; - cp->layer = parameters->cp_layer; - cp->bigendian = parameters->bigendian; - - /* MM: Settings of the following two member variables would take - place during j3d_read_com. FIXME */ - cp->encoding_format = ENCOD_3EB; - cp->transform_format = TRF_2D_DWT; - - /* keep a link to cp so that we can destroy it later in j3d_destroy_decompress */ - j3d->cp = cp; - } -} - -opj_volume_t* j3d_decode(opj_j3d_t *j3d, opj_cio_t *cio) { - opj_volume_t *volume = NULL; - - opj_common_ptr cinfo = j3d->cinfo; - - j3d->cio = cio; - - /* create an empty volume */ - volume = (opj_volume_t*)opj_malloc(sizeof(opj_volume_t)); - j3d->volume = volume; - - j3d->state = J3D_STATE_MHSOC; - - for (;;) { - opj_dec_mstabent_t *e; - int id = cio_read(cio, 2); - if (id >> 8 != 0xff) { - opj_volume_destroy(volume); - opj_event_msg(cinfo, EVT_ERROR, "%.8x: expected a marker instead of %x\n", cio_tell(cio) - 2, id); - return 0; - } - e = j3d_dec_mstab_lookup(id); - /*opj_event_msg(cinfo, EVT_INFO, "MARKER %x PREVSTATE %d E->STATE %d\n",e->id,j3d->state,e->states);*/ - if (!(j3d->state & e->states)) { - opj_volume_destroy(volume); - opj_event_msg(cinfo, EVT_ERROR, "%.8x: unexpected marker %x\n", cio_tell(cio) - 2, id); - return 0; - } - if (e->handler) { - (*e->handler)(j3d); - } - /*opj_event_msg(cinfo, EVT_INFO, "POSTSTATE %d\n",j3d->state);*/ - if (j3d->state == J3D_STATE_MT) { - break; - } - if (j3d->state == J3D_STATE_NEOC) { - break; - } - } - if (j3d->state == J3D_STATE_NEOC) { - j3d_read_eoc(j3d); - } - - if (j3d->state != J3D_STATE_MT) { - opj_event_msg(cinfo, EVT_WARNING, "Incomplete bitstream\n"); - } - - return volume; -} - -/* ----------------------------------------------------------------------- */ -/* J3D encoder interface */ -/* ----------------------------------------------------------------------- */ - -opj_j3d_t* j3d_create_compress(opj_common_ptr cinfo) { - opj_j3d_t *j3d = (opj_j3d_t*)opj_malloc(sizeof(opj_j3d_t)); - if(j3d) { - j3d->cinfo = cinfo; - } - return j3d; -} - -void j3d_destroy_compress(opj_j3d_t *j3d) { - int tileno; - - if(!j3d) return; - - if(j3d->volume_info != NULL) { - opj_volume_info_t *volume_info = j3d->volume_info; - if (volume_info->index_on && j3d->cp) { - opj_cp_t *cp = j3d->cp; - for (tileno = 0; tileno < cp->tw * cp->th; tileno++) { - opj_tile_info_t *tile_info = &volume_info->tile[tileno]; - opj_free(tile_info->thresh); - opj_free(tile_info->packet); - } - opj_free(volume_info->tile); - } - opj_free(volume_info); - } - if(j3d->cp != NULL) { - opj_cp_t *cp = j3d->cp; - - if(cp->comment) { - opj_free(cp->comment); - } - if(cp->matrice) { - opj_free(cp->matrice); - } - for (tileno = 0; tileno < cp->tw * cp->th; tileno++) { - opj_free(cp->tcps[tileno].tccps); - } - opj_free(cp->tcps); - opj_free(cp); - } - - opj_free(j3d); -} - -void j3d_setup_encoder(opj_j3d_t *j3d, opj_cparameters_t *parameters, opj_volume_t *volume) { - int i, j, tileno, numpocs_tile; - opj_cp_t *cp = NULL; - - if(!j3d || !parameters || ! volume) { - return; - } - - /* create and initialize the coding parameters structure */ - cp = (opj_cp_t*)opj_malloc(sizeof(opj_cp_t)); - - /* keep a link to cp so that we can destroy it later in j3d_destroy_compress */ - j3d->cp = cp; - - /* set default values for cp */ - cp->tw = 1; - cp->th = 1; - cp->tl = 1; - - /* copy user encoding parameters */ - cp->disto_alloc = parameters->cp_disto_alloc; - cp->fixed_alloc = parameters->cp_fixed_alloc; - cp->fixed_quality = parameters->cp_fixed_quality; - - /* transform and coding method */ - cp->transform_format = parameters->transform_format; - cp->encoding_format = parameters->encoding_format; - - /* mod fixed_quality */ - if(parameters->cp_matrice) { - size_t array_size = parameters->tcp_numlayers * 3 * parameters->numresolution[0] * sizeof(int); - cp->matrice = (int *) opj_malloc(array_size); - memcpy(cp->matrice, parameters->cp_matrice, array_size); - } - - /* creation of an index file ? */ - cp->index_on = parameters->index_on; - if(cp->index_on) { - j3d->volume_info = (opj_volume_info_t*)opj_malloc(sizeof(opj_volume_info_t)); - } - - /* tiles */ - cp->tdx = parameters->cp_tdx; - cp->tdy = parameters->cp_tdy; - cp->tdz = parameters->cp_tdz; - /* tile offset */ - cp->tx0 = parameters->cp_tx0; - cp->ty0 = parameters->cp_ty0; - cp->tz0 = parameters->cp_tz0; - /* comment string */ - if(parameters->cp_comment) { - cp->comment = (char*)opj_malloc(strlen(parameters->cp_comment) + 1); - if(cp->comment) { - strcpy(cp->comment, parameters->cp_comment); - } - } - - /*calculate other encoding parameters*/ - if (parameters->tile_size_on) { - cp->tw = int_ceildiv(volume->x1 - cp->tx0, cp->tdx); - cp->th = int_ceildiv(volume->y1 - cp->ty0, cp->tdy); - cp->tl = int_ceildiv(volume->z1 - cp->tz0, cp->tdz); - } else { - cp->tdx = volume->x1 - cp->tx0; - cp->tdy = volume->y1 - cp->ty0; - cp->tdz = volume->z1 - cp->tz0; - } - - /* initialize the multiple tiles */ - /* ---------------------------- */ - cp->tcps = (opj_tcp_t *) opj_malloc(cp->tw * cp->th * cp->tl * sizeof(opj_tcp_t)); - - for (tileno = 0; tileno < cp->tw * cp->th * cp->tl; tileno++) { - opj_tcp_t *tcp = &cp->tcps[tileno]; - tcp->numlayers = parameters->tcp_numlayers; - for (j = 0; j < tcp->numlayers; j++) { - if (cp->fixed_quality) { /* add fixed_quality */ - tcp->distoratio[j] = parameters->tcp_distoratio[j]; - } else { - tcp->rates[j] = parameters->tcp_rates[j]; - } - } - tcp->csty = parameters->csty; - tcp->prg = parameters->prog_order; - tcp->mct = volume->numcomps == 3 ? 1 : 0; - - numpocs_tile = 0; - tcp->POC = 0; - if (parameters->numpocs) { - /* initialisation of POC */ - tcp->POC = 1; - for (i = 0; i < parameters->numpocs; i++) { - if((tileno == parameters->POC[i].tile - 1) || (parameters->POC[i].tile == -1)) { - opj_poc_t *tcp_poc = &tcp->pocs[numpocs_tile]; - tcp_poc->resno0 = parameters->POC[numpocs_tile].resno0; - tcp_poc->compno0 = parameters->POC[numpocs_tile].compno0; - tcp_poc->layno1 = parameters->POC[numpocs_tile].layno1; - tcp_poc->resno1 = parameters->POC[numpocs_tile].resno1; - tcp_poc->compno1 = parameters->POC[numpocs_tile].compno1; - tcp_poc->prg = parameters->POC[numpocs_tile].prg; - tcp_poc->tile = parameters->POC[numpocs_tile].tile; - numpocs_tile++; - } - } - } - tcp->numpocs = numpocs_tile; - - tcp->tccps = (opj_tccp_t *) opj_malloc(volume->numcomps * sizeof(opj_tccp_t)); - - for (i = 0; i < volume->numcomps; i++) { - opj_tccp_t *tccp = &tcp->tccps[i]; - tccp->csty = parameters->csty & J3D_CCP_CSTY_PRT; /* 0 => standard precint || 1 => custom-defined precinct */ - tccp->numresolution[0] = parameters->numresolution[0]; - tccp->numresolution[1] = parameters->numresolution[1]; - tccp->numresolution[2] = parameters->numresolution[2]; - assert (parameters->cblock_init[0] <= T1_MAXCBLKW); - assert (parameters->cblock_init[0] >= T1_MINCBLKW); - assert (parameters->cblock_init[1] <= T1_MAXCBLKH); - assert (parameters->cblock_init[1] >= T1_MINCBLKH); - assert (parameters->cblock_init[2] <= T1_MAXCBLKD); - assert (parameters->cblock_init[2] >= T1_MINCBLKD); - tccp->cblk[0] = int_floorlog2(parameters->cblock_init[0]); - tccp->cblk[1] = int_floorlog2(parameters->cblock_init[1]); - tccp->cblk[2] = int_floorlog2(parameters->cblock_init[2]); - assert (tccp->cblk[0]+tccp->cblk[1]+tccp->cblk[1] <= T1_MAXWHD); - tccp->cblksty = parameters->mode; /*Codeblock style --> Table A.19 (default 0)*/ - - /*ATK / transform */ - tccp->reversible = parameters->irreversible ? 0 : 1; /* 0 => DWT 9-7 || 1 => DWT 5-3 */ - for (j = 0; j < 3; j++) { - tccp->dwtid[j] = parameters->irreversible ? 0 : 1; /* 0 => DWT 9-7 || 1 => DWT 5-3 */ - } - - /* Quantification: SEQNT (Scalar Expounded, value for each subband) / NOQNT (no quant)*/ - tccp->qntsty = parameters->irreversible ? J3D_CCP_QNTSTY_SEQNT : J3D_CCP_QNTSTY_NOQNT; - tccp->numgbits = 2; - if (i == parameters->roi_compno) { - tccp->roishift = parameters->roi_shift; - } else { - tccp->roishift = 0; - } - /* Custom defined precints */ - if (parameters->csty & J3D_CCP_CSTY_PRT) { - int k; - for (k = 0; k < 3; k++) { - int p = 0; - for (j = tccp->numresolution[k] - 1; j >= 0; j--) { - if (p < parameters->res_spec) {/* p < number of precinct size specifications */ - if (parameters->prct_init[k][p] < 1) { - tccp->prctsiz[k][j] = 1; - } else { - tccp->prctsiz[k][j] = int_floorlog2(parameters->prct_init[k][p]); - } - } else { - int res_spec = parameters->res_spec; - int size_prct = parameters->prct_init[k][res_spec - 1] >> (p - (res_spec - 1)); - if (size_prct < 1) { - tccp->prctsiz[k][j] = 1; - } else { - tccp->prctsiz[k][j] = int_floorlog2(size_prct); - } - } - } - p++; - } - } else { - int k; - for (k = 0; k < 3; k++) { - for (j = 0; j < tccp->numresolution[k]; j++) { - tccp->prctsiz[k][j] = 15; - } - } - } - /*Calcular stepsize for each subband (if NOQNT -->stepsize = 1.0)*/ - dwt_calc_explicit_stepsizes(tccp, volume->comps[i].prec); - } - } -} - -/** -Create an index file -@param j3d -@param cio -@param volume_info -@param index Index filename -@return Returns 1 if successful, returns 0 otherwise -*/ -static int j3d_create_index(opj_j3d_t *j3d, opj_cio_t *cio, opj_volume_info_t *volume_info, char *index) { - - int tileno, compno, layno, resno, precno, pack_nb, x, y, z; - FILE *stream = NULL; - double total_disto = 0; - - volume_info->codestream_size = cio_tell(cio) + j3d->pos_correction; /* Correction 14/4/03 suite rmq de Patrick */ - - stream = fopen(index, "w"); - if (!stream) { - opj_event_msg(j3d->cinfo, EVT_ERROR, "failed to open %s for writing\n", index); - return 0; - } - - fprintf(stream, "w %d\t h %d\t l %d\n", volume_info->volume_w, volume_info->volume_h, volume_info->volume_l); - fprintf(stream, "TRASNFORM\t%d\n", volume_info->transform_format); - fprintf(stream, "ENTROPY CODING\t%d\n", volume_info->encoding_format); - fprintf(stream, "PROG\t%d\n", volume_info->prog); - fprintf(stream, "TILE\tx %d y %d z %d\n", volume_info->tile_x, volume_info->tile_y, volume_info->tile_z); - fprintf(stream, "NOTILE\tx %d y %d z %d\n", volume_info->tw, volume_info->th, volume_info->tl); - fprintf(stream, "COMPONENTS\t%d\n", volume_info->comp); - fprintf(stream, "LAYER\t%d\n", volume_info->layer); - fprintf(stream, "RESOLUTIONS\tx %d y %d z %d\n", volume_info->decomposition[0], volume_info->decomposition[1], volume_info->decomposition[2]); - - fprintf(stream, "Precint sizes for each resolution:\n"); - for (resno = volume_info->decomposition[0]; resno >= 0; resno--) { - fprintf(stream, "Resno %d \t [%d,%d,%d] \n", resno, - (1 << volume_info->tile[0].prctsiz[0][resno]), (1 << volume_info->tile[0].prctsiz[0][resno]), (1 << volume_info->tile[0].prctsiz[2][resno])); /* based on tile 0 */ - } - fprintf(stream, "HEADER_END\t%d\n", volume_info->main_head_end); - fprintf(stream, "CODESTREAM\t%d\n", volume_info->codestream_size); - fprintf(stream, "Num_tile Start_pos End_header End_pos Distotile Nbpix Ratio\n"); - for (tileno = 0; tileno < (volume_info->tw * volume_info->th * volume_info->tl); tileno++) { - fprintf(stream, "%4d\t%9d\t%9d\t%9d\t%9e\t%9d\t%9e\n", - volume_info->tile[tileno].num_tile, - volume_info->tile[tileno].start_pos, - volume_info->tile[tileno].end_header, - volume_info->tile[tileno].end_pos, - volume_info->tile[tileno].distotile, volume_info->tile[tileno].nbpix, - volume_info->tile[tileno].distotile / volume_info->tile[tileno].nbpix); - } - - for (tileno = 0; tileno < (volume_info->tw * volume_info->th * volume_info->tl); tileno++) { - int start_pos, end_pos; - double disto = 0; - pack_nb = 0; - if (volume_info->prog == LRCP) { /* LRCP */ - fprintf(stream, "pack_nb tileno layno resno compno precno start_pos end_pos disto\n"); - for (layno = 0; layno < volume_info->layer; layno++) { - for (resno = 0; resno < volume_info->decomposition[0] + 1; resno++) { - for (compno = 0; compno < volume_info->comp; compno++) { - int prec_max = volume_info->tile[tileno].prctno[0][resno] * volume_info->tile[tileno].prctno[1][resno] * volume_info->tile[tileno].prctno[2][resno]; - for (precno = 0; precno < prec_max; precno++) { - start_pos = volume_info->tile[tileno].packet[pack_nb].start_pos; - end_pos = volume_info->tile[tileno].packet[pack_nb].end_pos; - disto = volume_info->tile[tileno].packet[pack_nb].disto; - fprintf(stream, "%4d %6d %7d %5d %6d %6d %9d %9d %8e\n",pack_nb, tileno, layno, resno, compno, precno, start_pos, end_pos, disto); - total_disto += disto; - pack_nb++; - } - } - } - } - } /* LRCP */ - else if (volume_info->prog == RLCP) { /* RLCP */ - /* - fprintf(stream, "pack_nb tileno resno layno compno precno start_pos end_pos disto"); - */ - for (resno = 0; resno < volume_info->decomposition[0] + 1; resno++) { - for (layno = 0; layno < volume_info->layer; layno++) { - for (compno = 0; compno < volume_info->comp; compno++) { - int prec_max = volume_info->tile[tileno].prctno[0][resno] * volume_info->tile[tileno].prctno[1][resno]* volume_info->tile[tileno].prctno[2][resno]; - for (precno = 0; precno < prec_max; precno++) { - start_pos = volume_info->tile[tileno].packet[pack_nb].start_pos; - end_pos = volume_info->tile[tileno].packet[pack_nb].end_pos; - disto = volume_info->tile[tileno].packet[pack_nb].disto; - fprintf(stream, "%4d %6d %5d %7d %6d %6d %9d %9d %8e\n", - pack_nb, tileno, resno, layno, compno, precno, start_pos, end_pos, disto); - total_disto += disto; - pack_nb++; - } - } - } - } - } /* RLCP */ - else if (volume_info->prog == RPCL) { /* RPCL */ - /* - fprintf(stream, "\npack_nb tileno resno precno compno layno start_pos end_pos disto\n"); - */ - for (resno = 0; resno < volume_info->decomposition[0] + 1; resno++) { - /* I suppose components have same XRsiz, YRsiz */ - /*int x0 = volume_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)volume_info->tw ) * volume_info->tw * volume_info->tile_x;*/ - /*int y0 = volume_info->tile_Ox + (int)floor( (float)tileno/(float)volume_info->tw ) * volume_info->tile_y;*/ - int x0 = volume_info->tile_Ox + (int)floor( (float)tileno/(float)volume_info->tw ) * volume_info->tile_x; - int y0 = volume_info->tile_Oy + (int)floor( (float)tileno/(float)volume_info->th ) * volume_info->tile_y; - int z0 = volume_info->tile_Ox + (int)floor( (float)tileno/(float)volume_info->tl ) * volume_info->tile_z; - int x1 = x0 + volume_info->tile_x; - int y1 = y0 + volume_info->tile_y; - int z1 = z0 + volume_info->tile_z; - for(z = z0; z < z1; z++) { - for(y = y0; y < y1; y++) { - for(x = x0; x < x1; x++) { - for (compno = 0; compno < volume_info->comp; compno++) { - int prec_max = volume_info->tile[tileno].prctno[0][resno] * volume_info->tile[tileno].prctno[1][resno] * volume_info->tile[tileno].prctno[2][resno]; - for (precno = 0; precno < prec_max; precno++) { - int pcnx = volume_info->tile[tileno].prctno[0][resno]; - int pcx = (int) pow( 2, volume_info->tile[tileno].prctsiz[0][resno] + volume_info->decomposition[0] - resno ); - int pcy = (int) pow( 2, volume_info->tile[tileno].prctsiz[1][resno] + volume_info->decomposition[1] - resno ); - int pcz = (int) pow( 2, volume_info->tile[tileno].prctsiz[2][resno] + volume_info->decomposition[2] - resno ); - int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; - int precno_y = (int) floor( (float)precno/(float)pcnx ); - if (precno_y*pcy == y ) { - if (precno_x*pcx == x ) { - for (layno = 0; layno < volume_info->layer; layno++) { - start_pos = volume_info->tile[tileno].packet[pack_nb].start_pos; - end_pos = volume_info->tile[tileno].packet[pack_nb].end_pos; - disto = volume_info->tile[tileno].packet[pack_nb].disto; - fprintf(stream, "%4d %6d %5d %6d %6d %7d %9d %9d %8e\n", - pack_nb, tileno, resno, precno, compno, layno, start_pos, end_pos, disto); - total_disto += disto; - pack_nb++; - } - } - } - } /* precno */ - } /* compno */ - } /* x = x0..x1 */ - } /* y = y0..y1 */ - } /* z = z0..z1 */ - } /* resno */ - } /* RPCL */ - else if (volume_info->prog == PCRL) { /* PCRL */ - /* I suppose components have same XRsiz, YRsiz */ - int x0 = volume_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)volume_info->tw ) * volume_info->tw * volume_info->tile_x; - int y0 = volume_info->tile_Ox + (int)floor( (float)tileno/(float)volume_info->tw ) * volume_info->tile_y; - int z0 = volume_info->tile_Oz + (int)floor( (float)tileno/(float)volume_info->tw ) * volume_info->tile_z; - int x1 = x0 + volume_info->tile_x; - int y1 = y0 + volume_info->tile_y; - int z1 = z0 + volume_info->tile_z; - /* - fprintf(stream, "\npack_nb tileno precno compno resno layno start_pos end_pos disto\n"); - */ - for(z = z0; z < z1; z++) { - for(y = y0; y < y1; y++) { - for(x = x0; x < x1; x++) { - for (compno = 0; compno < volume_info->comp; compno++) { - for (resno = 0; resno < volume_info->decomposition[0] + 1; resno++) { - int prec_max = volume_info->tile[tileno].prctno[0][resno] * volume_info->tile[tileno].prctno[1][resno]; - for (precno = 0; precno < prec_max; precno++) { - int pcnx = volume_info->tile[tileno].prctno[0][resno]; - int pcx = (int) pow( 2, volume_info->tile[tileno].prctsiz[0][resno] + volume_info->decomposition[0] - resno ); - int pcy = (int) pow( 2, volume_info->tile[tileno].prctsiz[1][resno] + volume_info->decomposition[1] - resno ); - int pcz = (int) pow( 2, volume_info->tile[tileno].prctsiz[2][resno] + volume_info->decomposition[2] - resno ); - int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; - int precno_y = (int) floor( (float)precno/(float)pcnx ); - int precno_z = (int) floor( (float)precno/(float)pcnx ); - if (precno_z*pcz == z ) { - if (precno_y*pcy == y ) { - if (precno_x*pcx == x ) { - for (layno = 0; layno < volume_info->layer; layno++) { - start_pos = volume_info->tile[tileno].packet[pack_nb].start_pos; - end_pos = volume_info->tile[tileno].packet[pack_nb].end_pos; - disto = volume_info->tile[tileno].packet[pack_nb].disto; - fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d %9d %8e\n", - pack_nb, tileno, precno, compno, resno, layno, start_pos, end_pos, disto); - total_disto += disto; - pack_nb++; - } - } - } - } - } /* precno */ - } /* resno */ - } /* compno */ - } /* x = x0..x1 */ - } /* y = y0..y1 */ - } - } /* PCRL */ - else { /* CPRL */ - /* - fprintf(stream, "\npack_nb tileno compno precno resno layno start_pos end_pos disto\n"); - */ - for (compno = 0; compno < volume_info->comp; compno++) { - /* I suppose components have same XRsiz, YRsiz */ - int x0 = volume_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)volume_info->tw ) * volume_info->tw * volume_info->tile_x; - int y0 = volume_info->tile_Ox + (int)floor( (float)tileno/(float)volume_info->tw ) * volume_info->tile_y; - int z0 = volume_info->tile_Oz + (int)floor( (float)tileno/(float)volume_info->tw ) * volume_info->tile_z; - int x1 = x0 + volume_info->tile_x; - int y1 = y0 + volume_info->tile_y; - int z1 = z0 + volume_info->tile_z; - for(z = z0; z < z1; z++) { - for(y = y0; y < y1; y++) { - for(x = x0; x < x1; x++) { - for (resno = 0; resno < volume_info->decomposition[0] + 1; resno++) { - int prec_max = volume_info->tile[tileno].prctno[0][resno] * volume_info->tile[tileno].prctno[1][resno] * volume_info->tile[tileno].prctno[2][resno]; - for (precno = 0; precno < prec_max; precno++) { - int pcnx = volume_info->tile[tileno].prctno[0][resno]; - int pcny = volume_info->tile[tileno].prctno[1][resno]; - int pcx = (int) pow( 2, volume_info->tile[tileno].prctsiz[0][resno] + volume_info->decomposition[0] - resno ); - int pcy = (int) pow( 2, volume_info->tile[tileno].prctsiz[1][resno] + volume_info->decomposition[1] - resno ); - int pcz = (int) pow( 2, volume_info->tile[tileno].prctsiz[2][resno] + volume_info->decomposition[2] - resno ); - int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; - int precno_y = (int) floor( (float)precno/(float)pcnx ); - int precno_z = 0; /*???*/ - if (precno_z*pcz == z ) { - if (precno_y*pcy == y ) { - if (precno_x*pcx == x ) { - for (layno = 0; layno < volume_info->layer; layno++) { - start_pos = volume_info->tile[tileno].packet[pack_nb].start_pos; - end_pos = volume_info->tile[tileno].packet[pack_nb].end_pos; - disto = volume_info->tile[tileno].packet[pack_nb].disto; - fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d %9d %8e\n", - pack_nb, tileno, compno, precno, resno, layno, start_pos, end_pos, disto); - total_disto += disto; - pack_nb++; - } - } - } - } - } /* precno */ - } /* resno */ - } /* x = x0..x1 */ - } /* y = y0..y1 */ - } /* z = z0..z1 */ - } /* comno */ - } /* CPRL */ - } /* tileno */ - - fprintf(stream, "SE_MAX\t%8e\n", volume_info->D_max); /* SE max */ - fprintf(stream, "SE_TOTAL\t%.8e\n", total_disto); /* SE totale */ - - - fclose(stream); - - return 1; -} - -bool j3d_encode(opj_j3d_t *j3d, opj_cio_t *cio, opj_volume_t *volume, char *index) { - int tileno, compno; - opj_volume_info_t *volume_info = NULL; - opj_cp_t *cp = NULL; - opj_tcd_t *tcd = NULL; /* TCD component */ - - j3d->cio = cio; - j3d->volume = volume; - cp = j3d->cp; - - /*j3d_dump_volume(stdout, volume); - j3d_dump_cp(stdout, volume, cp);*/ - - /* INDEX >> */ - volume_info = j3d->volume_info; - if (volume_info && cp->index_on) { - volume_info->index_on = cp->index_on; - volume_info->tile = (opj_tile_info_t *) opj_malloc(cp->tw * cp->th * cp->tl * sizeof(opj_tile_info_t)); - volume_info->volume_w = volume->x1 - volume->x0; - volume_info->volume_h = volume->y1 - volume->y0; - volume_info->volume_l = volume->z1 - volume->z0; - volume_info->prog = (&cp->tcps[0])->prg; - volume_info->tw = cp->tw; - volume_info->th = cp->th; - volume_info->tl = cp->tl; - volume_info->tile_x = cp->tdx; /* new version parser */ - volume_info->tile_y = cp->tdy; /* new version parser */ - volume_info->tile_z = cp->tdz; /* new version parser */ - volume_info->tile_Ox = cp->tx0; /* new version parser */ - volume_info->tile_Oy = cp->ty0; /* new version parser */ - volume_info->tile_Oz = cp->tz0; /* new version parser */ - volume_info->transform_format = cp->transform_format; - volume_info->encoding_format = cp->encoding_format; - volume_info->comp = volume->numcomps; - volume_info->layer = (&cp->tcps[0])->numlayers; - volume_info->decomposition[0] = (&cp->tcps[0])->tccps->numresolution[0] - 1; - volume_info->decomposition[1] = (&cp->tcps[0])->tccps->numresolution[1] - 1; - volume_info->decomposition[2] = (&cp->tcps[0])->tccps->numresolution[2] - 1; - volume_info->D_max = 0; /* ADD Marcela */ - } - /* << INDEX */ - - j3d_write_soc(j3d); - j3d_write_siz(j3d); - if (j3d->cinfo->codec_format == CODEC_J3D) { - j3d_write_cap(j3d); - j3d_write_nsi(j3d); - } - - /*if (j3d->cp->transform_format != TRF_2D_DWT || j3d->cp->encoding_format != ENCOD_2EB)*/ - j3d_write_com(j3d); - - j3d_write_cod(j3d); - j3d_write_qcd(j3d); - for (compno = 0; compno < volume->numcomps; compno++) { - opj_tcp_t *tcp = &cp->tcps[0]; - if (tcp->tccps[compno].roishift) - j3d_write_rgn(j3d, compno, 0); - } - /*Optional 15444-2 markers*/ - if (j3d->cp->tcps->tccps[0].atk != NULL) - j3d_write_atk(j3d); - if (j3d->volume->comps[0].dcoffset != 0) - j3d_write_dco(j3d); - - /* INDEX >> */ - if(volume_info && volume_info->index_on) { - volume_info->main_head_end = cio_tell(cio) - 1; - } - /* << INDEX */ - - /* create the tile encoder */ - tcd = tcd_create(j3d->cinfo); - - /* encode each tile */ - for (tileno = 0; tileno < cp->tw * cp->th * cp->tl; tileno++) { - opj_event_msg(j3d->cinfo, EVT_INFO, "tile number %d / %d\n", tileno + 1, cp->tw * cp->th * cp->tl); - - j3d->curtileno = tileno; - - /* initialisation before tile encoding */ - if (tileno == 0) { - tcd_malloc_encode(tcd, volume, cp, j3d->curtileno); - } else { - tcd_init_encode(tcd, volume, cp, j3d->curtileno); - } - - /* INDEX >> */ - if(volume_info && volume_info->index_on) { - volume_info->tile[j3d->curtileno].num_tile = j3d->curtileno; - volume_info->tile[j3d->curtileno].start_pos = cio_tell(cio) + j3d->pos_correction; - } - /* << INDEX */ - - j3d_write_sot(j3d); - - for (compno = 1; compno < volume->numcomps; compno++) { - j3d_write_coc(j3d, compno); - j3d_write_qcc(j3d, compno); - } - - if (cp->tcps[tileno].numpocs) { - j3d_write_poc(j3d); - } - j3d_write_sod(j3d, tcd); /*--> tcd_encode_tile*/ - - /* INDEX >> */ - if(volume_info && volume_info->index_on) { - volume_info->tile[j3d->curtileno].end_pos = cio_tell(cio) + j3d->pos_correction - 1; - } - /* << INDEX */ - } - - /* destroy the tile encoder */ - tcd_free_encode(tcd); - tcd_destroy(tcd); - - j3d_write_eoc(j3d); - - /* Creation of the index file */ - if(volume_info && volume_info->index_on) { - if(!j3d_create_index(j3d, cio, volume_info, index)) { - opj_event_msg(j3d->cinfo, EVT_ERROR, "failed to create index file %s\n", index); - return false; - } - } - - return true; -} - -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - +/* + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opj_includes.h" + +/** @defgroup J3D J3D - JPEG-2000 PART 10 codestream reader/writer */ +/*@{*/ + +/** @name Funciones locales */ +/*@{*/ + +/** +Write the SOC marker (Start Of Codestream) +@param j3d J3D handle +*/ +static void j3d_write_soc(opj_j3d_t *j3d); +/** +Read the SOC marker (Start of Codestream) +@param j3d J3D handle +*/ +static void j3d_read_soc(opj_j3d_t *j3d); +/** +Write the SIZ marker (2D volume and tile size) +@param j3d J3D handle +*/ +static void j3d_write_siz(opj_j3d_t *j3d); +/** +Read the SIZ marker (2D volume and tile size) +@param j3d J3D handle +*/ +static void j3d_read_siz(opj_j3d_t *j3d); +/** +Write the NSI marker (3rd volume and tile size) +@param j3d J3D handle +*/ +static void j3d_write_nsi(opj_j3d_t *j3d); +/** +Read the NSI marker (3rd volume and tile size) +@param j3d J3D handle +*/ +static void j3d_read_nsi(opj_j3d_t *j3d); +/** +Write the COM marker (comment) +@param j3d J3D handle +*/ +static void j3d_write_com(opj_j3d_t *j3d); +/** +Read the COM marker (comment) +@param j3d J3D handle +*/ +static void j3d_read_com(opj_j3d_t *j3d); +/** +Write the value concerning the specified component in the marker COD and COC +@param j3d J3D handle +@param compno Number of the component concerned by the information written +*/ +static void j3d_write_cox(opj_j3d_t *j3d, int compno); +/** +Read the value concerning the specified component in the marker COD and COC +@param j3d J3D handle +@param compno Number of the component concerned by the information read +*/ +static void j3d_read_cox(opj_j3d_t *j3d, int compno); +/** +Write the COD marker (coding style default) +@param j3d J3D handle +*/ +static void j3d_write_cod(opj_j3d_t *j3d); +/** +Read the COD marker (coding style default) +@param j3d J3D handle +*/ +static void j3d_read_cod(opj_j3d_t *j3d); +/** +Write the COC marker (coding style component) +@param j3d J3D handle +@param compno Number of the component concerned by the information written +*/ +static void j3d_write_coc(opj_j3d_t *j3d, int compno); +/** +Read the COC marker (coding style component) +@param j3d J3D handle +*/ +static void j3d_read_coc(opj_j3d_t *j3d); +/** +Write the value concerning the specified component in the marker QCD and QCC +@param j3d J3D handle +@param compno Number of the component concerned by the information written +*/ +static void j3d_write_qcx(opj_j3d_t *j3d, int compno); +/** +Read the value concerning the specified component in the marker QCD and QCC +@param j3d J3D handle +@param compno Number of the component concern by the information read +@param len Length of the information in the QCX part of the marker QCD/QCC +*/ +static void j3d_read_qcx(opj_j3d_t *j3d, int compno, int len); +/** +Write the QCD marker (quantization default) +@param j3d J3D handle +*/ +static void j3d_write_qcd(opj_j3d_t *j3d); +/** +Read the QCD marker (quantization default) +@param j3d J3D handle +*/ +static void j3d_read_qcd(opj_j3d_t *j3d); +/** +Write the QCC marker (quantization component) +@param j3d J3D handle +@param compno Number of the component concerned by the information written +*/ +static void j3d_write_qcc(opj_j3d_t *j3d, int compno); +/** +Read the QCC marker (quantization component) +@param j3d J3D handle +*/ +static void j3d_read_qcc(opj_j3d_t *j3d); +/** +Write the POC marker (progression order change) +@param j3d J3D handle +*/ +static void j3d_write_poc(opj_j3d_t *j3d); +/** +Read the POC marker (progression order change) +@param j3d J3D handle +*/ +static void j3d_read_poc(opj_j3d_t *j3d); +/** +Read the CRG marker (component registration) +@param j3d J3D handle +*/ +static void j3d_read_crg(opj_j3d_t *j3d); +/** +Read the TLM marker (tile-part lengths) +@param j3d J3D handle +*/ +static void j3d_read_tlm(opj_j3d_t *j3d); +/** +Read the PLM marker (packet length, main header) +@param j3d J3D handle +*/ +static void j3d_read_plm(opj_j3d_t *j3d); +/** +Read the PLT marker (packet length, tile-part header) +@param j3d J3D handle +*/ +static void j3d_read_plt(opj_j3d_t *j3d); +/** +Read the PPM marker (packet packet headers, main header) +@param j3d J3D handle +*/ +static void j3d_read_ppm(opj_j3d_t *j3d); +/** +Read the PPT marker (packet packet headers, tile-part header) +@param j3d J3D handle +*/ +static void j3d_read_ppt(opj_j3d_t *j3d); +/** +Write the SOT marker (start of tile-part) +@param j3d J3D handle +*/ +static void j3d_write_sot(opj_j3d_t *j3d); +/** +Read the SOT marker (start of tile-part) +@param j3d J3D handle +*/ +static void j3d_read_sot(opj_j3d_t *j3d); +/** +Write the SOD marker (start of data) +@param j3d J3D handle +@param tile_coder Pointer to a TCD handle +*/ +static void j3d_write_sod(opj_j3d_t *j3d, void *tile_coder); +/** +Read the SOD marker (start of data) +@param j3d J3D handle +*/ +static void j3d_read_sod(opj_j3d_t *j3d); +/** +Write the RGN marker (region-of-interest) +@param j3d J3D handle +@param compno Number of the component concerned by the information written +@param tileno Number of the tile concerned by the information written +*/ +static void j3d_write_rgn(opj_j3d_t *j3d, int compno, int tileno); +/** +Read the RGN marker (region-of-interest) +@param j3d J3D handle +*/ +static void j3d_read_rgn(opj_j3d_t *j3d); +/** +Write the EOC marker (end of codestream) +@param j3d J3D handle +*/ +static void j3d_write_eoc(opj_j3d_t *j3d); +/** +Read the EOC marker (end of codestream) +@param j3d J3D handle +*/ +static void j3d_read_eoc(opj_j3d_t *j3d); +/** +Read an unknown marker +@param j3d J3D handle +*/ +static void j3d_read_unk(opj_j3d_t *j3d); +/** +Write the CAP marker (extended capabilities) +@param j3d J3D handle +*/ +static void j3d_write_cap(opj_j3d_t *j3d); +/** +Read the CAP marker (extended capabilities) +@param j3d J3D handle +*/ +static void j3d_read_cap(opj_j3d_t *j3d); +/** +Write the DCO marker (Variable DC offset) +@param j3d J3D handle +*/ +static void j3d_write_dco(opj_j3d_t *j3d); +/** +Read the DCO marker (Variable DC offset) +@param j3d J3D handle +*/ +static void j3d_read_dco(opj_j3d_t *j3d); +/** +Write the ATK marker (arbitrary transformation kernel) +@param j3d J3D handle +*/ +static void j3d_write_atk(opj_j3d_t *j3d); +/** +Read the ATK marker (arbitrary transformation kernel) +@param j3d J3D handle +*/ +static void j3d_read_atk(opj_j3d_t *j3d); +/** +Write the CBD marker (component bit depth definition) +@param j3d J3D handle +*/ +static void j3d_write_cbd(opj_j3d_t *j3d); +/** +Read the CBD marker (component bit depth definition) +@param j3d J3D handle +*/ +static void j3d_read_cbd(opj_j3d_t *j3d); +/** +Write the MCT marker (multiple component transfomation definition) +@param j3d J3D handle +*/ +static void j3d_write_mct(opj_j3d_t *j3d); +/** +Read the MCT marker (multiple component transfomation definition) +@param j3d J3D handle +*/ +static void j3d_read_mct(opj_j3d_t *j3d); +/** +Write the MCC marker (multiple component transfomation collection) +@param j3d J3D handle +*/ +static void j3d_write_mcc(opj_j3d_t *j3d); +/** +Read the MCC marker (multiple component transfomation collection) +@param j3d J3D handle +*/ +static void j3d_read_mcc(opj_j3d_t *j3d); +/** +Write the MCO marker (multiple component transfomation ordering) +@param j3d J3D handle +*/ +static void j3d_write_mco(opj_j3d_t *j3d); +/** +Read the MCO marker (multiple component transfomation ordering) +@param j3d J3D handle +*/ +static void j3d_read_mco(opj_j3d_t *j3d); +/** +Write the NLT marker (non-linearity point transformation) +@param j3d J3D handle +*/ +static void j3d_write_nlt(opj_j3d_t *j3d); +/** +Read the NLT marker (non-linearity point transformation) +@param j3d J3D handle +*/ +static void j3d_read_nlt(opj_j3d_t *j3d); +/*@}*/ + +/* ----------------------------------------------------------------------- */ + +static void j3d_dump_volume(FILE *fd, opj_volume_t * vol) { + int compno; + fprintf(fd, "volume {\n"); + fprintf(fd, " x0=%d, y0=%d, z0=%d, x1=%d, y1=%d, z1=%d\n", vol->x0, vol->y0, vol->z0,vol->x1, vol->y1, vol->z1); + fprintf(fd, " numcomps=%d\n", vol->numcomps); + for (compno = 0; compno < vol->numcomps; compno++) { + opj_volume_comp_t *comp = &vol->comps[compno]; + fprintf(fd, " comp %d {\n", compno); + fprintf(fd, " dx=%d, dy=%d, dz=%d\n", comp->dx, comp->dy, comp->dz); + fprintf(fd, " prec=%d\n", comp->prec); + fprintf(fd, " sgnd=%d\n", comp->sgnd); + fprintf(fd, " }\n"); + } + fprintf(fd, "}\n"); +} + +static void j3d_dump_cp(FILE *fd, opj_volume_t * vol, opj_cp_t * cp) { + int tileno, compno, layno, bandno, resno, numbands; + fprintf(fd, "coding parameters {\n"); + fprintf(fd, " tx0=%d, ty0=%d, tz0=%d\n", cp->tx0, cp->ty0, cp->tz0); + fprintf(fd, " tdx=%d, tdy=%d, tdz=%d\n", cp->tdx, cp->tdy, cp->tdz); + fprintf(fd, " tw=%d, th=%d, tl=%d\n", cp->tw, cp->th, cp->tl); + fprintf(fd, " transform format: %d\n", cp->transform_format); + fprintf(fd, " encoding format: %d\n", cp->encoding_format); + for (tileno = 0; tileno < cp->tw * cp->th * cp->tl; tileno++) { + opj_tcp_t *tcp = &cp->tcps[tileno]; + fprintf(fd, " tile %d {\n", tileno); + fprintf(fd, " csty=%x\n", tcp->csty); + fprintf(fd, " prg=%d\n", tcp->prg); + fprintf(fd, " numlayers=%d\n", tcp->numlayers); + fprintf(fd, " mct=%d\n", tcp->mct); + fprintf(fd, " rates="); + for (layno = 0; layno < tcp->numlayers; layno++) { + fprintf(fd, "%f ", tcp->rates[layno]); + } + fprintf(fd, "\n"); + fprintf(fd, " first=%d\n", tcp->first); + for (compno = 0; compno < vol->numcomps; compno++) { + opj_tccp_t *tccp = &tcp->tccps[compno]; + fprintf(fd, " comp %d {\n", compno); + fprintf(fd, " csty=%x\n", tccp->csty); + fprintf(fd, " numresx=%d, numresy=%d, numresz=%d\n", tccp->numresolution[0], tccp->numresolution[1], tccp->numresolution[2]); + fprintf(fd, " cblkw=%d, cblkh=%d, cblkl=%d\n", tccp->cblk[0], tccp->cblk[1], tccp->cblk[2]); + fprintf(fd, " cblksty=%x\n", tccp->cblksty); + fprintf(fd, " qntsty=%d\n", tccp->qntsty); + fprintf(fd, " numgbits=%d\n", tccp->numgbits); + fprintf(fd, " roishift=%d\n", tccp->roishift); + fprintf(fd, " reversible=%d\n", tccp->reversible); + fprintf(fd, " dwtidx=%d dwtidy=%d dwtidz=%d\n", tccp->dwtid[0], tccp->dwtid[1], tccp->dwtid[2]); + if (tccp->atk != NULL) { + fprintf(fd, " atk.index=%d\n", tccp->atk->index); + fprintf(fd, " atk.coeff_typ=%d\n", tccp->atk->coeff_typ); + fprintf(fd, " atk.filt_cat=%d\n", tccp->atk->filt_cat); + fprintf(fd, " atk.exten=%d\n", tccp->atk->exten); + fprintf(fd, " atk.minit=%d\n", tccp->atk->minit); + fprintf(fd, " atk.wt_typ=%d\n", tccp->atk->wt_typ); + } + fprintf(fd, " stepsizes of bands="); + numbands = (tccp->qntsty == J3D_CCP_QNTSTY_SIQNT) ? 1 : + ( (cp->transform_format == TRF_2D_DWT) ? (tccp->numresolution[0] * 3 - 2) : + (tccp->numresolution[0] * 7 - 6) - 4 *(tccp->numresolution[0] - tccp->numresolution[2]) ); + for (bandno = 0; bandno < numbands; bandno++) { + fprintf(fd, "(%d,%d) ", tccp->stepsizes[bandno].mant,tccp->stepsizes[bandno].expn); + } + fprintf(fd, "\n"); + + if (tccp->csty & J3D_CCP_CSTY_PRT) { + fprintf(fd, " prcw="); + for (resno = 0; resno < tccp->numresolution[0]; resno++) { + fprintf(fd, "%d ", tccp->prctsiz[0][resno]); + } + fprintf(fd, "\n"); + fprintf(fd, " prch="); + for (resno = 0; resno < tccp->numresolution[0]; resno++) { + fprintf(fd, "%d ", tccp->prctsiz[1][resno]); + } + fprintf(fd, "\n"); + fprintf(fd, " prcl="); + for (resno = 0; resno < tccp->numresolution[0]; resno++) { + fprintf(fd, "%d ", tccp->prctsiz[2][resno]); + } + fprintf(fd, "\n"); + } + fprintf(fd, " }\n"); + } + fprintf(fd, " }\n"); + } + fprintf(fd, "}\n"); +} + +/* ----------------------------------------------------------------------- +Extended capabilities +------------------------------------------------------------------------*/ + +static void j3d_write_cap(opj_j3d_t *j3d){ + int len,lenp; + + opj_cio_t *cio = j3d->cio; + cio_write(cio, J3D_MS_CAP, 2); /* CAP */ + lenp = cio_tell(cio); + cio_skip(cio, 2); + cio_write(cio,J3D_CAP_10, 4); + if( J3D_CAP_10 ) + { + cio_write(cio, 0x0, 2); + } + len = cio_tell(cio) - lenp; + cio_seek(cio, lenp); + cio_write(cio, len, 2); /* Lsiz */ + cio_seek(cio, lenp + len); + +} +static void j3d_read_cap(opj_j3d_t *j3d){ + int len, Cap; + opj_cio_t *cio = j3d->cio; + /*cio_read(cio, 2); CAP */ + len = cio_read(cio, 2); + Cap = cio_read(cio, 4); + if(Cap) { + cio_read(cio, 2); + } + assert( len == 2 + 4 + 2 ); +} +static void j3d_write_nsi(opj_j3d_t *j3d) { + int i; + int lenp, len; + int ndim = 3; + + opj_cio_t *cio = j3d->cio; + opj_volume_t *volume = j3d->volume; + opj_cp_t *cp = j3d->cp; + + cio_write(cio, J3D_MS_NSI, 2); /* NSI */ + lenp = cio_tell(cio); + cio_skip(cio, 2); + cio_write(cio, ndim, 1); /* Ndim */ + cio_write(cio, volume->z1, 4); /* Zsiz */ + cio_write(cio, volume->z0, 4); /* Z0siz */ + cio_write(cio, cp->tdz, 4); /* ZTsiz */ + cio_write(cio, cp->tz0, 4); /* ZT0siz */ + for (i = 0; i < volume->numcomps; i++) { + cio_write(cio, volume->comps[i].dz, 1); /* ZRsiz_i */ + } + len = cio_tell(cio) - lenp; + cio_seek(cio, lenp); + cio_write(cio, len, 2); /* Lsiz */ + cio_seek(cio, lenp + len); +} + +static void j3d_read_nsi(opj_j3d_t *j3d) { + int ndim; + int len, i; + + opj_cio_t *cio = j3d->cio; + opj_volume_t *volume = j3d->volume; + opj_cp_t *cp = j3d->cp; + + len = cio_read(cio, 2); /* Lnsi */ + ndim = cio_read(cio, 1); /* Ndim */ + assert( ndim == 3 ); + volume->z1 = cio_read(cio, 4); /* Zsiz */ + volume->z0 = cio_read(cio, 4); /* Z0siz */ + cp->tdz = cio_read(cio, 4); /* ZTsiz */ + cp->tz0 = cio_read(cio, 4); /* ZT0siz */ + for (i = 0; i < volume->numcomps; i++) { + volume->comps[i].dz = cio_read(cio, 1); /* ZRsiz_i */ + } + + /*Initialization of volume*/ + cp->tw = int_ceildiv(volume->x1 - cp->tx0, cp->tdx); + cp->th = int_ceildiv(volume->y1 - cp->ty0, cp->tdy); + cp->tl = int_ceildiv(volume->z1 - cp->tz0, cp->tdz); + cp->tcps = (opj_tcp_t *) opj_malloc(cp->tw * cp->th * cp->tl * sizeof(opj_tcp_t)); + cp->tileno = (int *) opj_malloc(cp->tw * cp->th * cp->tl * sizeof(int)); + cp->tileno_size = 0; + + for (i = 0; i < cp->tw * cp->th * cp->tl ; i++) { + cp->tcps[i].POC = 0; + cp->tcps[i].numpocs = 0; + cp->tcps[i].first = 1; + } + + /* Initialization for PPM marker (Packets header)*/ + cp->ppm = 0; + cp->ppm_data = NULL; + cp->ppm_data_first = NULL; + cp->ppm_previous = 0; + cp->ppm_store = 0; + + j3d->default_tcp->tccps = (opj_tccp_t *) opj_malloc(sizeof(opj_tccp_t) * volume->numcomps); + for (i = 0; i < cp->tw * cp->th * cp->tl ; i++) { + cp->tcps[i].tccps = (opj_tccp_t *) opj_malloc(sizeof(opj_tccp_t) * volume->numcomps); + } + j3d->tile_data = (unsigned char **) opj_malloc(cp->tw * cp->th * cp->tl * sizeof(unsigned char *)); + j3d->tile_len = (int *) opj_malloc(cp->tw * cp->th * cp->tl * sizeof(int)); + j3d->state = J3D_STATE_MH; + +} +static void j3d_write_dco(opj_j3d_t *j3d){ + int lenp, len, i; + int dcotype; + + opj_cio_t *cio = j3d->cio; + opj_volume_t *volume = j3d->volume; + opj_cp_t *cp = j3d->cp; + + dcotype = 1; /* Offsets are 16bit signed integers Table A21 15444-2 */ + cio_write(cio, J3D_MS_DCO, 2); /* DCO */ + lenp = cio_tell(cio); + cio_skip(cio, 2); + cio_write(cio, dcotype, 1); + if (dcotype == 0) { + for (i = 0; i < volume->numcomps; i++) + cio_write(cio, volume->comps[i].dcoffset, 1); /* SPdco_i */ + } else if (dcotype == 1) { + for (i = 0; i < volume->numcomps; i++){ + cio_write(cio, volume->comps[i].dcoffset, 1); /* SPdco_i */ + opj_event_msg(j3d->cinfo, EVT_INFO, "dcotype %d DCO %d \n",dcotype,volume->comps[i].dcoffset); + } + } + len = cio_tell(cio) - lenp; + cio_seek(cio, lenp); + cio_write(cio, len, 2); /* Ldco */ + cio_seek(cio, lenp + len); + +} +static void j3d_read_dco(opj_j3d_t *j3d){ + int len, i; + int dcotype; + + opj_cio_t *cio = j3d->cio; + opj_volume_t *volume = j3d->volume; + opj_cp_t *cp = j3d->cp; + + len = cio_read(cio, 2); /* Lsiz */ + dcotype = cio_read(cio, 1); /*offset 8bit unsigned / 16bit signed integers*/ + if (dcotype == 0) { + for (i = 0; i < volume->numcomps; i++) { + volume->comps[i].dcoffset = cio_read(cio, 1); + if (volume->comps[i].dcoffset > 128) + volume->comps[i].dcoffset = volume->comps[i].dcoffset - 256; + } + } else if (dcotype == 1) { + for (i = 0; i < volume->numcomps; i++) { + volume->comps[i].dcoffset = cio_read(cio, 1); + if (volume->comps[i].dcoffset > 128) + volume->comps[i].dcoffset = volume->comps[i].dcoffset - 256; + } + } + +} +static void j3d_write_atk(opj_j3d_t *j3d){ + int lenp, len, s, k; + + opj_cio_t *cio = j3d->cio; + opj_volume_t *volume = j3d->volume; + opj_atk_t *atk = j3d->cp->tcps->tccps->atk; + + cio_write(cio, J3D_MS_ATK, 2); /* ATK */ + lenp = cio_tell(cio); + cio_skip(cio, 2); + cio_write(cio, atk->index + (atk->coeff_typ << 8) + (atk->filt_cat << 11) + + (atk->wt_typ << 12) + (atk->minit << 13) + (atk->exten << 14), 2); /* Satk */ + if (atk->wt_typ == J3D_ATK_IRR) + cio_write(cio,(unsigned int) (atk->Katk * 8192.0), 1 << atk->coeff_typ); + cio_write(cio, atk->Natk, 1); + for (s = 0; s < atk->Natk; s++){ + if (atk->filt_cat == J3D_ATK_ARB) + cio_write(cio, atk->Oatk[s], 1); + if (atk->wt_typ == J3D_ATK_REV){ + cio_write(cio, atk->Eatk[s], 1); + cio_write(cio, atk->Batk[s], 1); + } + cio_write(cio, atk->LCatk[s], 1); + for (k = 0; k < atk->LCatk[s]; k++) + cio_write(cio,(unsigned int) (atk->Aatk[s][k] * 8192.0), 1 << atk->coeff_typ); + } + len = cio_tell(cio) - lenp; + cio_seek(cio, lenp); + cio_write(cio, len, 2); /* Latk */ + cio_seek(cio, lenp + len); +} +static void j3d_read_atk(opj_j3d_t *j3d){ + int len, i, Satk, k; + + opj_cio_t *cio = j3d->cio; + opj_volume_t *volume = j3d->volume; + opj_cp_t *cp = j3d->cp; + opj_atk_t *atk = cp->tcps->tccps->atk; + + len = cio_read(cio, 2); /* Latk */ + Satk = cio_read(cio, 2); + atk->index = Satk & 0x00ff; + atk->coeff_typ = Satk >> 8 & 0x0007; + atk->filt_cat = Satk >> 11 & 0x0001; + atk->wt_typ = Satk >> 12 & 0x0001; + atk->minit = Satk >> 13 & 0x0001; + atk->exten = Satk >> 14 & 0x0001; + if (atk->wt_typ == J3D_ATK_IRR) + atk->Katk = ((double) cio_read(cio, 1 << atk->coeff_typ) / 8192.0); + atk->Natk = cio_read(cio, 1); + for (i = 0; i < atk->Natk; i++) { + if (atk->filt_cat == J3D_ATK_ARB) + atk->Oatk[i] = cio_read(cio, 1); + if (atk->wt_typ == J3D_ATK_REV){ + atk->Eatk[i] = cio_read(cio, 1); + atk->Batk[i] = cio_read(cio, 1); + } + atk->LCatk[i] = cio_read(cio, 1); + for (k = 0; k < atk->LCatk[i]; k++) + atk->Aatk[i][k] = ((double) cio_read(cio, 1 << atk->coeff_typ) / 8192.0); + } +} +static void j3d_write_cbd(opj_j3d_t *j3d){ +} +static void j3d_read_cbd(opj_j3d_t *j3d){ +} +static void j3d_write_mct(opj_j3d_t *j3d){ +} +static void j3d_read_mct(opj_j3d_t *j3d){ +} +static void j3d_write_mcc(opj_j3d_t *j3d){ +} +static void j3d_read_mcc(opj_j3d_t *j3d){ +} +static void j3d_write_mco(opj_j3d_t *j3d){ +} +static void j3d_read_mco(opj_j3d_t *j3d){ +} +static void j3d_write_nlt(opj_j3d_t *j3d){ +} +static void j3d_read_nlt(opj_j3d_t *j3d){ +} +/* ----------------------------------------------------------------------- +15444-1 codestream syntax +------------------------------------------------------------------------*/ +static void j3d_write_soc(opj_j3d_t *j3d) { + opj_cio_t *cio = j3d->cio; + cio_write(cio, J3D_MS_SOC, 2); +} + +static void j3d_read_soc(opj_j3d_t *j3d) { + j3d->state = J3D_STATE_MHSIZ; +} + +static void j3d_write_siz(opj_j3d_t *j3d) { + int i; + int lenp, len; + int Rsiz; + + opj_cio_t *cio = j3d->cio; + opj_volume_t *volume = j3d->volume; + opj_cp_t *cp = j3d->cp; + + cio_write(cio, J3D_MS_SIZ, 2); /* SIZ */ + lenp = cio_tell(cio); + cio_skip(cio, 2); + /*cio_write(cio, 0, 2);*/ /* Rsiz (capabilities of 15444-1 only) */ + Rsiz = J3D_RSIZ_DCO | J3D_RSIZ_ATK; /** | J3D_RSIZ_MCT | J3D_RSIZ_NONLT (not implemented yet)*/ + cio_write(cio, Rsiz, 2); /* capabilities of WDv5.2*/ + cio_write(cio, volume->x1, 4); /* Xsiz */ + cio_write(cio, volume->y1, 4); /* Ysiz */ + cio_write(cio, volume->x0, 4); /* X0siz */ + cio_write(cio, volume->y0, 4); /* Y0siz */ + cio_write(cio, cp->tdx, 4); /* XTsiz */ + cio_write(cio, cp->tdy, 4); /* YTsiz */ + cio_write(cio, cp->tx0, 4); /* XT0siz */ + cio_write(cio, cp->ty0, 4); /* YT0siz */ + cio_write(cio, volume->numcomps, 2); /* Csiz */ + for (i = 0; i < volume->numcomps; i++) { + cio_write(cio, volume->comps[i].prec - 1 + (volume->comps[i].sgnd << 7), 1); /* Ssiz_i */ + cio_write(cio, volume->comps[i].dx, 1); /* XRsiz_i */ + cio_write(cio, volume->comps[i].dy, 1); /* YRsiz_i */ + } + len = cio_tell(cio) - lenp; + cio_seek(cio, lenp); + cio_write(cio, len, 2); /* Lsiz */ + cio_seek(cio, lenp + len); +} + +static void j3d_read_siz(opj_j3d_t *j3d) { + int len, i; + + opj_cio_t *cio = j3d->cio; + opj_volume_t *volume = j3d->volume; + opj_cp_t *cp = j3d->cp; + + len = cio_read(cio, 2); /* Lsiz */ + cp->rsiz = cio_read(cio, 2); /* Rsiz (capabilities) */ + volume->x1 = cio_read(cio, 4); /* Xsiz */ + volume->y1 = cio_read(cio, 4); /* Ysiz */ + volume->x0 = cio_read(cio, 4); /* X0siz */ + volume->y0 = cio_read(cio, 4); /* Y0siz */ + cp->tdx = cio_read(cio, 4); /* XTsiz */ + cp->tdy = cio_read(cio, 4); /* YTsiz */ + cp->tx0 = cio_read(cio, 4); /* XT0siz */ + cp->ty0 = cio_read(cio, 4); /* YT0siz */ + + volume->numcomps = cio_read(cio, 2); /* Csiz */ + volume->comps = (opj_volume_comp_t *) opj_malloc(volume->numcomps * sizeof(opj_volume_comp_t)); + for (i = 0; i < volume->numcomps; i++) { + int tmp, j; + tmp = cio_read(cio, 1); /* Ssiz_i */ + volume->comps[i].prec = (tmp & 0x7f) + 1; + volume->comps[i].sgnd = tmp >> 7; + volume->comps[i].dx = cio_read(cio, 1); /* XRsiz_i */ + volume->comps[i].dy = cio_read(cio, 1); /* YRsiz_i */ + for (j = 0; j < 3; j++) { + volume->comps[i].resno_decoded[j] = 0; /* number of resolution decoded */ + volume->comps[i].factor[j] = 0; /* reducing factor per component */ + } + } + + if (j3d->cinfo->codec_format == CODEC_J2K){ + volume->z1 = 1; + volume->z0 = 0; + volume->numslices = 1; + cp->tdz = 1; + cp->tz0 = 0; + for (i = 0; i < volume->numcomps; i++) + volume->comps[i].dz = 1; + + /*Initialization of volume*/ + cp->tw = int_ceildiv(volume->x1 - cp->tx0, cp->tdx); + cp->th = int_ceildiv(volume->y1 - cp->ty0, cp->tdy); + cp->tl = int_ceildiv(volume->z1 - cp->tz0, cp->tdz); + cp->tcps = (opj_tcp_t *) opj_malloc(cp->tw * cp->th * cp->tl * sizeof(opj_tcp_t)); + cp->tileno = (int *) opj_malloc(cp->tw * cp->th * cp->tl * sizeof(int)); + cp->tileno_size = 0; + + for (i = 0; i < cp->tw * cp->th * cp->tl ; i++) { + cp->tcps[i].POC = 0; + cp->tcps[i].numpocs = 0; + cp->tcps[i].first = 1; + } + + /* Initialization for PPM marker (Packets header)*/ + cp->ppm = 0; + cp->ppm_data = NULL; + cp->ppm_data_first = NULL; + cp->ppm_previous = 0; + cp->ppm_store = 0; + + j3d->default_tcp->tccps = (opj_tccp_t *) opj_malloc(sizeof(opj_tccp_t) * volume->numcomps); + for (i = 0; i < cp->tw * cp->th * cp->tl ; i++) { + cp->tcps[i].tccps = (opj_tccp_t *) opj_malloc(sizeof(opj_tccp_t) * volume->numcomps); + } + j3d->tile_data = (unsigned char **) opj_malloc(cp->tw * cp->th * cp->tl * sizeof(unsigned char *)); + j3d->tile_len = (int *) opj_malloc(cp->tw * cp->th * cp->tl * sizeof(int)); + j3d->state = J3D_STATE_MH; + } +} + + + +static void j3d_write_com(opj_j3d_t *j3d) { + unsigned int i; + int lenp, len; + + opj_cio_t *cio = j3d->cio; + + cio_write(cio, J3D_MS_COM, 2); + lenp = cio_tell(cio); + cio_skip(cio, 2); + cio_write(cio, 1, 2); + /*opj_event_msg(j3d->cinfo, EVT_INFO, "TRF %D ENCOD %d\n",j3d->cp->transform_format,j3d->cp->encoding_format);*/ + if (j3d->cp->comment != NULL) { + char *comment = j3d->cp->comment; + for (i = 0; i < strlen(comment); i++) { + cio_write(cio, comment[i], 1); + } + } + len = cio_tell(cio) - lenp; + cio_seek(cio, lenp); + cio_write(cio, len, 2); + cio_seek(cio, lenp + len); +} + +static void j3d_read_com(opj_j3d_t *j3d) { + int len; + opj_cio_t *cio = j3d->cio; + + len = cio_read(cio, 2); + cio_read(cio, 2); // read registration + + /*opj_event_msg(j3d->cinfo, EVT_INFO, "TRF %D ENCOD %d\n",j3d->cp->transform_format,j3d->cp->encoding_format);*/ + + cio_skip(cio, len - 4); /*posible comments*/ +} + +static void j3d_write_cox(opj_j3d_t *j3d, int compno) { + int i; + int shift = 2; + + opj_cp_t *cp = j3d->cp; + opj_tcp_t *tcp = &cp->tcps[j3d->curtileno]; + opj_tccp_t *tccp = &tcp->tccps[compno]; + opj_cio_t *cio = j3d->cio; + + cio_write(cio, tccp->numresolution[0] - 1, 1); /* SPcox (D) No of decomposition levels in x-axis*/ + if (j3d->cinfo->codec_format == CODEC_J3D) { + cio_write(cio, tccp->numresolution[1] - 1, 1); /* SPcox (E) No of decomposition levels in y-axis*/ + cio_write(cio, tccp->numresolution[2] - 1, 1); /* SPcox (F) No of decomposition levels in z-axis*/ + } + if (j3d->cinfo->codec_format == CODEC_J3D) { + /* Table A.7 */ + shift = 0; + } + /* (cblkw - 2) + (cblkh - 2) + (cblkl - 2) <= 18*/ + cio_write(cio, tccp->cblk[0] - shift, 1); /* SPcox (G) Cblk width entre 10 y 2 (8 y 0)*/ + cio_write(cio, tccp->cblk[1] - shift, 1); /* SPcox (H) Cblk height*/ + if (j3d->cinfo->codec_format == CODEC_J3D) { + cio_write(cio, tccp->cblk[2] - shift, 1); /* SPcox (I) Cblk depth*/ + } + cio_write(cio, tccp->cblksty, 1); /* SPcox (J) Cblk style*/ + cio_write(cio, tccp->dwtid[0], 1); /* SPcox (K) WT in x-axis 15444-2 Table A10*/ + if (j3d->cinfo->codec_format == CODEC_J3D) { + cio_write(cio, tccp->dwtid[1], 1); /* SPcox (L) WT in y-axis 15444-2 Table A10*/ + cio_write(cio, tccp->dwtid[2], 1); /* SPcox (M) WT in z-axis 15444-2 Table A10*/ + } + + if (tccp->csty & J3D_CCP_CSTY_PRT) { + for (i = 0; i < tccp->numresolution[0]; i++) { + if (i < tccp->numresolution[2]) + cio_write(cio, tccp->prctsiz[0][i] + (tccp->prctsiz[1][i] << 4) + (tccp->prctsiz[2][i] << 8), 2); /* SPcox (N_i) Table A9*/ + else + if (j3d->cinfo->codec_format == CODEC_J3D) + cio_write(cio, tccp->prctsiz[0][i] + (tccp->prctsiz[1][i] << 4), 2); /* SPcox (N_i) Table A9*/ + else + cio_write(cio, tccp->prctsiz[0][i] + (tccp->prctsiz[1][i] << 4), 1); /* SPcox (N_i) Table A9*/ } + } +} + +static void j3d_read_cox(opj_j3d_t *j3d, int compno) { + int i; + int shift = 2; + + opj_cp_t *cp = j3d->cp; + opj_tcp_t *tcp = j3d->state == J3D_STATE_TPH ? &cp->tcps[j3d->curtileno] : j3d->default_tcp; + opj_tccp_t *tccp = &tcp->tccps[compno]; + opj_cio_t *cio = j3d->cio; + + tccp->numresolution[0] = cio_read(cio, 1) + 1; /* SPcox (D) No of decomposition levels in x-axis*/ + if (j3d->cinfo->codec_format == CODEC_J3D) { + tccp->numresolution[1] = cio_read(cio, 1) + 1; /* SPcox (E) No of decomposition levels in y-axis*/ + tccp->numresolution[2] = cio_read(cio, 1) + 1; /* SPcox (F) No of decomposition levels in z-axis*/ + }else if (j3d->cinfo->codec_format == CODEC_J2K) { + tccp->numresolution[1] = tccp->numresolution[0]; + tccp->numresolution[2] = 1; + } + /* check the reduce value */ + cp->reduce[0] = int_min((tccp->numresolution[0])-1, cp->reduce[0]); + cp->reduce[1] = int_min((tccp->numresolution[1])-1, cp->reduce[1]); + cp->reduce[2] = int_min((tccp->numresolution[2])-1, cp->reduce[2]); + + if (j3d->cinfo->codec_format == CODEC_J3D) { + /* Table A.7 */ + shift = 0; + } + tccp->cblk[0] = cio_read(cio, 1) + shift; /* SPcox (G) */ + tccp->cblk[1] = cio_read(cio, 1) + shift; /* SPcox (H) */ + if (j3d->cinfo->codec_format == CODEC_J3D) + tccp->cblk[2] = cio_read(cio, 1) + shift; /* SPcox (I) */ + else + tccp->cblk[2] = tccp->cblk[0]; + + tccp->cblksty = cio_read(cio, 1); /* SPcox (J) */ + tccp->dwtid[0] = cio_read(cio, 1); /* SPcox (K) */ + if (j3d->cinfo->codec_format == CODEC_J3D) { + tccp->dwtid[1] = cio_read(cio, 1); /* SPcox (L) */ + tccp->dwtid[2] = cio_read(cio, 1); /* SPcox (M) */ + }else{ + tccp->dwtid[1] = tccp->dwtid[0]; /* SPcox (L) */ + tccp->dwtid[2] = tccp->dwtid[0]; /* SPcox (M) */ + } + tccp->reversible = (tccp->dwtid[0]>=1 && tccp->dwtid[1]>=1 && tccp->dwtid[2]>=1); /*TODO: only valid for irreversible 9x7 WTs*/ + if (tccp->csty & J3D_CP_CSTY_PRT) { + for (i = 0; i < tccp->numresolution[0]; i++) { + int tmp = cio_read(cio, 2); /* SPcox (N_i) */ + tccp->prctsiz[0][i] = tmp & 0xf; + tccp->prctsiz[1][i] = tmp >> 4; + tccp->prctsiz[2][i] = tmp >> 8; + } + } +} + +static void j3d_write_cod(opj_j3d_t *j3d) { + opj_cp_t *cp = NULL; + opj_tcp_t *tcp = NULL; + int lenp, len; + + opj_cio_t *cio = j3d->cio; + + cio_write(cio, J3D_MS_COD, 2); /* COD */ + + lenp = cio_tell(cio); + cio_skip(cio, 2); + + cp = j3d->cp; + tcp = &cp->tcps[j3d->curtileno]; + + /* Scod : Table A-4*/ + cio_write(cio, tcp->csty, 1); /* Scod : Coding style parameters */ + /* SGcod : Table A-5*/ + cio_write(cio, tcp->prg, 1); /* SGcod (A) : Progression order */ + cio_write(cio, tcp->numlayers, 2); /* SGcod (B) : No of layers */ + cio_write(cio, tcp->mct, 1); /* SGcod (C) : Multiple component transformation usage */ + /* SPcod : Table A-6*/ + j3d_write_cox(j3d, 0); + len = cio_tell(cio) - lenp; + cio_seek(cio, lenp); + cio_write(cio, len, 2); /* Lcod */ + cio_seek(cio, lenp + len); +} + +static void j3d_read_cod(opj_j3d_t *j3d) { + int len, i, pos; + + opj_cio_t *cio = j3d->cio; + opj_cp_t *cp = j3d->cp; + opj_tcp_t *tcp = j3d->state == J3D_STATE_TPH ? &cp->tcps[j3d->curtileno] : j3d->default_tcp; + opj_volume_t *volume = j3d->volume; + + /* Lcod */ + len = cio_read(cio, 2); + /* Scod : Table A-4*/ + tcp->csty = cio_read(cio, 1); + /* SGcod : Table A-5*/ + tcp->prg = (OPJ_PROG_ORDER)cio_read(cio, 1); + tcp->numlayers = cio_read(cio, 2); + tcp->mct = cio_read(cio, 1); + + pos = cio_tell(cio); + for (i = 0; i < volume->numcomps; i++) { + tcp->tccps[i].csty = tcp->csty & J3D_CP_CSTY_PRT; + cio_seek(cio, pos); + j3d_read_cox(j3d, i); + } +} + +static void j3d_write_coc(opj_j3d_t *j3d, int compno) { + int lenp, len; + + opj_cp_t *cp = j3d->cp; + opj_tcp_t *tcp = &cp->tcps[j3d->curtileno]; + opj_volume_t *volume = j3d->volume; + opj_cio_t *cio = j3d->cio; + + cio_write(cio, J3D_MS_COC, 2); /* COC */ + lenp = cio_tell(cio); + cio_skip(cio, 2); + cio_write(cio, compno, volume->numcomps <= 256 ? 1 : 2); /* Ccoc */ + cio_write(cio, tcp->tccps[compno].csty, 1); /* Scoc */ + + j3d_write_cox(j3d, compno); + + len = cio_tell(cio) - lenp; + cio_seek(cio, lenp); + cio_write(cio, len, 2); /* Lcoc */ + cio_seek(cio, lenp + len); +} + +static void j3d_read_coc(opj_j3d_t *j3d) { + int len, compno; + + opj_cp_t *cp = j3d->cp; + opj_tcp_t *tcp = j3d->state == J3D_STATE_TPH ? &cp->tcps[j3d->curtileno] : j3d->default_tcp; + opj_volume_t *volume = j3d->volume; + opj_cio_t *cio = j3d->cio; + + len = cio_read(cio, 2); /* Lcoc */ + compno = cio_read(cio, volume->numcomps <= 256 ? 1 : 2); /* Ccoc */ + tcp->tccps[compno].csty = cio_read(cio, 1); /* Scoc */ + j3d_read_cox(j3d, compno); +} + +static void j3d_write_qcx(opj_j3d_t *j3d, int compno) { + int bandno, numbands; + int expn, mant; + + opj_cp_t *cp = j3d->cp; + opj_tcp_t *tcp = &cp->tcps[j3d->curtileno]; + opj_tccp_t *tccp = &tcp->tccps[compno]; + opj_cio_t *cio = j3d->cio; + + cio_write(cio, tccp->qntsty + (tccp->numgbits << 5), 1); /* Sqcx : Table A28 de 15444-1*/ + + if (j3d->cinfo->codec_format == CODEC_J2K) + numbands = tccp->qntsty == J3D_CCP_QNTSTY_SIQNT ? 1 : tccp->numresolution[0] * 3 - 2; + else if (j3d->cinfo->codec_format == CODEC_J3D) { + int diff = tccp->numresolution[0] - tccp->numresolution[2]; + numbands = (tccp->qntsty == J3D_CCP_QNTSTY_SIQNT) ? 1 : (tccp->numresolution[0] * 7 - 6) - 4 *diff; /* SIQNT vs. SEQNT */ + } + + for (bandno = 0; bandno < numbands; bandno++) { + expn = tccp->stepsizes[bandno].expn; + mant = tccp->stepsizes[bandno].mant; + + if (tccp->qntsty == J3D_CCP_QNTSTY_NOQNT) { + cio_write(cio, expn << 3, 1); /* SPqcx_i */ + } else { + cio_write(cio, (expn << 11) + mant, 2); /* SPqcx_i */ + } + } +} + +static void j3d_read_qcx(opj_j3d_t *j3d, int compno, int len) { + int tmp; + int bandno, numbands; + + opj_cp_t *cp = j3d->cp; + opj_tcp_t *tcp = j3d->state == J3D_STATE_TPH ? &cp->tcps[j3d->curtileno] : j3d->default_tcp; + opj_tccp_t *tccp = &tcp->tccps[compno]; + opj_cio_t *cio = j3d->cio; + + tmp = cio_read(cio, 1); /* Sqcx */ + tccp->qntsty = tmp & 0x1f; + tccp->numgbits = tmp >> 5; + + /*Numbands = 1 si SIQNT + len - 1 si NOQNT + (len - 1) / 2 si SEQNT */ + numbands = tccp->qntsty == J3D_CCP_QNTSTY_SIQNT ? 1 : ((tccp->qntsty == J3D_CCP_QNTSTY_NOQNT) ? len - 1 : (len - 1) / 2); + + for (bandno = 0; bandno < numbands; bandno++) { + int expn, mant; + if (tccp->qntsty == J3D_CCP_QNTSTY_NOQNT) { + expn = cio_read(cio, 1) >> 3; /* SPqcx_i */ + mant = 0; + } else { + tmp = cio_read(cio, 2); /* SPqcx_i */ + expn = tmp >> 11; + mant = tmp & 0x7ff; + } + tccp->stepsizes[bandno].expn = expn; + tccp->stepsizes[bandno].mant = mant; + } + + /* Add Antonin : if scalar_derived -> compute other stepsizes */ + if (tccp->qntsty == J3D_CCP_QNTSTY_SIQNT) { + for (bandno = 1; bandno < J3D_MAXBANDS; bandno++) { + int numbands = (cp->transform_format==TRF_2D_DWT) ? 3 : 7; + tccp->stepsizes[bandno].expn = tccp->stepsizes[0].expn - ((bandno - 1) / numbands); + tccp->stepsizes[bandno].mant = tccp->stepsizes[0].mant; + } + } + /* ddA */ +} + +static void j3d_write_qcd(opj_j3d_t *j3d) { + int lenp, len; + + opj_cio_t *cio = j3d->cio; + + cio_write(cio, J3D_MS_QCD, 2); /* QCD */ + lenp = cio_tell(cio); + cio_skip(cio, 2); + j3d_write_qcx(j3d, 0); /* Sqcd*/ + len = cio_tell(cio) - lenp; + cio_seek(cio, lenp); + cio_write(cio, len, 2); /* Lqcd */ + cio_seek(cio, lenp + len); +} + +static void j3d_read_qcd(opj_j3d_t *j3d) { + int len, i, pos; + + opj_cio_t *cio = j3d->cio; + opj_volume_t *volume = j3d->volume; + + len = cio_read(cio, 2); /* Lqcd */ + pos = cio_tell(cio); + for (i = 0; i < volume->numcomps; i++) { + cio_seek(cio, pos); + j3d_read_qcx(j3d, i, len - 2); + } +} + +static void j3d_write_qcc(opj_j3d_t *j3d, int compno) { + int lenp, len; + + opj_cio_t *cio = j3d->cio; + + cio_write(cio, J3D_MS_QCC, 2); /* QCC */ + lenp = cio_tell(cio); + cio_skip(cio, 2); + cio_write(cio, compno, j3d->volume->numcomps <= 256 ? 1 : 2); /* Cqcc */ + j3d_write_qcx(j3d, compno); + len = cio_tell(cio) - lenp; + cio_seek(cio, lenp); + cio_write(cio, len, 2); /* Lqcc */ + cio_seek(cio, lenp + len); +} + +static void j3d_read_qcc(opj_j3d_t *j3d) { + int len, compno; + int numcomp = j3d->volume->numcomps; + opj_cio_t *cio = j3d->cio; + + len = cio_read(cio, 2); /* Lqcc */ + compno = cio_read(cio, numcomp <= 256 ? 1 : 2); /* Cqcc */ + j3d_read_qcx(j3d, compno, len - 2 - (numcomp <= 256 ? 1 : 2)); +} + +static void j3d_write_poc(opj_j3d_t *j3d) { + int len, numpchgs, i; + + int numcomps = j3d->volume->numcomps; + + opj_cp_t *cp = j3d->cp; + opj_tcp_t *tcp = &cp->tcps[j3d->curtileno]; + opj_tccp_t *tccp = &tcp->tccps[0]; + opj_cio_t *cio = j3d->cio; + + numpchgs = tcp->numpocs; + cio_write(cio, J3D_MS_POC, 2); /* POC */ + len = 2 + (5 + 2 * (numcomps <= 256 ? 1 : 2)) * numpchgs; + cio_write(cio, len, 2); /* Lpoc */ + for (i = 0; i < numpchgs; i++) { + opj_poc_t *poc = &tcp->pocs[i]; + cio_write(cio, poc->resno0, 1); /* RSpoc_i */ + cio_write(cio, poc->compno0, (numcomps <= 256 ? 1 : 2)); /* CSpoc_i */ + cio_write(cio, poc->layno1, 2); /* LYEpoc_i */ + poc->layno1 = int_min(poc->layno1, tcp->numlayers); + cio_write(cio, poc->resno1, 1); /* REpoc_i */ + poc->resno1 = int_min(poc->resno1, tccp->numresolution[0]); + cio_write(cio, poc->compno1, (numcomps <= 256 ? 1 : 2)); /* CEpoc_i */ + poc->compno1 = int_min(poc->compno1, numcomps); + cio_write(cio, poc->prg, 1); /* Ppoc_i */ + } +} + +static void j3d_read_poc(opj_j3d_t *j3d) { + int len, numpchgs, i, old_poc; + + int numcomps = j3d->volume->numcomps; + + opj_cp_t *cp = j3d->cp; + opj_tcp_t *tcp = j3d->state == J3D_STATE_TPH ? &cp->tcps[j3d->curtileno] : j3d->default_tcp; + opj_tccp_t *tccp = &tcp->tccps[0]; + opj_cio_t *cio = j3d->cio; + + old_poc = tcp->POC ? tcp->numpocs + 1 : 0; + tcp->POC = 1; + len = cio_read(cio, 2); /* Lpoc */ + numpchgs = (len - 2) / (5 + 2 * (numcomps <= 256 ? 1 : 2)); + + for (i = old_poc; i < numpchgs + old_poc; i++) { + opj_poc_t *poc; + poc = &tcp->pocs[i]; + poc->resno0 = cio_read(cio, 1); /* RSpoc_i */ + poc->compno0 = cio_read(cio, numcomps <= 256 ? 1 : 2); /* CSpoc_i */ + poc->layno1 = int_min(cio_read(cio, 2), (unsigned int) tcp->numlayers); /* LYEpoc_i */ + poc->resno1 = int_min(cio_read(cio, 1), (unsigned int) tccp->numresolution[0]); /* REpoc_i */ + poc->compno1 = int_min( + cio_read(cio, numcomps <= 256 ? 1 : 2), (unsigned int) numcomps); /* CEpoc_i */ + poc->prg = (OPJ_PROG_ORDER)cio_read(cio, 1); /* Ppoc_i */ + } + + tcp->numpocs = numpchgs + old_poc - 1; +} + +static void j3d_read_crg(opj_j3d_t *j3d) { + int len, i, Xcrg_i, Ycrg_i, Zcrg_i; + + opj_cio_t *cio = j3d->cio; + int numcomps = j3d->volume->numcomps; + + len = cio_read(cio, 2); /* Lcrg */ + for (i = 0; i < numcomps; i++) { + Xcrg_i = cio_read(cio, 2); /* Xcrg_i */ + Ycrg_i = cio_read(cio, 2); /* Ycrg_i */ + Zcrg_i = cio_read(cio, 2); /* Zcrg_i */ + } +} + +static void j3d_read_tlm(opj_j3d_t *j3d) { + int len, Ztlm, Stlm, ST, SP, tile_tlm, i; + long int Ttlm_i, Ptlm_i; + + opj_cio_t *cio = j3d->cio; + + len = cio_read(cio, 2); /* Ltlm */ + Ztlm = cio_read(cio, 1); /* Ztlm */ + Stlm = cio_read(cio, 1); /* Stlm */ + ST = ((Stlm >> 4) & 0x01) + ((Stlm >> 4) & 0x02); + SP = (Stlm >> 6) & 0x01; + tile_tlm = (len - 4) / ((SP + 1) * 2 + ST); + for (i = 0; i < tile_tlm; i++) { + Ttlm_i = cio_read(cio, ST); /* Ttlm_i */ + Ptlm_i = cio_read(cio, SP ? 4 : 2); /* Ptlm_i */ + } +} + +static void j3d_read_plm(opj_j3d_t *j3d) { + int len, i, Zplm, Nplm, add, packet_len = 0; + + opj_cio_t *cio = j3d->cio; + + len = cio_read(cio, 2); /* Lplm */ + Zplm = cio_read(cio, 1); /* Zplm */ + len -= 3; + while (len > 0) { + Nplm = cio_read(cio, 4); /* Nplm */ + len -= 4; + for (i = Nplm; i > 0; i--) { + add = cio_read(cio, 1); + len--; + packet_len = (packet_len << 7) + add; /* Iplm_ij */ + if ((add & 0x80) == 0) { + /* New packet */ + packet_len = 0; + } + if (len <= 0) + break; + } + } +} + +static void j3d_read_plt(opj_j3d_t *j3d) { + int len, i, Zplt, packet_len = 0, add; + + opj_cio_t *cio = j3d->cio; + + len = cio_read(cio, 2); /* Lplt */ + Zplt = cio_read(cio, 1); /* Zplt */ + for (i = len - 3; i > 0; i--) { + add = cio_read(cio, 1); + packet_len = (packet_len << 7) + add; /* Iplt_i */ + if ((add & 0x80) == 0) { + /* New packet */ + packet_len = 0; + } + } +} + +static void j3d_read_ppm(opj_j3d_t *j3d) { + int len, Z_ppm, i, j; + int N_ppm; + + opj_cp_t *cp = j3d->cp; + opj_cio_t *cio = j3d->cio; + + len = cio_read(cio, 2); + cp->ppm = 1; + + Z_ppm = cio_read(cio, 1); /* Z_ppm */ + len -= 3; + while (len > 0) { + if (cp->ppm_previous == 0) { + N_ppm = cio_read(cio, 4); /* N_ppm */ + len -= 4; + } else { + N_ppm = cp->ppm_previous; + } + j = cp->ppm_store; + if (Z_ppm == 0) { /* First PPM marker */ + cp->ppm_data = (unsigned char *) opj_malloc(N_ppm * sizeof(unsigned char)); + cp->ppm_data_first = cp->ppm_data; + cp->ppm_len = N_ppm; + } else { /* NON-first PPM marker */ + cp->ppm_data = (unsigned char *) opj_realloc(cp->ppm_data, (N_ppm + cp->ppm_store) * sizeof(unsigned char)); + cp->ppm_data_first = cp->ppm_data; + cp->ppm_len = N_ppm + cp->ppm_store; + } + for (i = N_ppm; i > 0; i--) { /* Read packet header */ + cp->ppm_data[j] = cio_read(cio, 1); + j++; + len--; + if (len == 0) + break; /* Case of non-finished packet header in present marker but finished in next one */ + } + cp->ppm_previous = i - 1; + cp->ppm_store = j; + } +} + +static void j3d_read_ppt(opj_j3d_t *j3d) { + int len, Z_ppt, i, j = 0; + + opj_cp_t *cp = j3d->cp; + opj_tcp_t *tcp = cp->tcps + j3d->curtileno; + opj_cio_t *cio = j3d->cio; + + len = cio_read(cio, 2); + Z_ppt = cio_read(cio, 1); + tcp->ppt = 1; + if (Z_ppt == 0) { /* First PPT marker */ + tcp->ppt_data = (unsigned char *) opj_malloc((len - 3) * sizeof(unsigned char)); + tcp->ppt_data_first = tcp->ppt_data; + tcp->ppt_store = 0; + tcp->ppt_len = len - 3; + } else { /* NON-first PPT marker */ + tcp->ppt_data = (unsigned char *) opj_realloc(tcp->ppt_data, (len - 3 + tcp->ppt_store) * sizeof(unsigned char)); + tcp->ppt_data_first = tcp->ppt_data; + tcp->ppt_len = len - 3 + tcp->ppt_store; + } + j = tcp->ppt_store; + for (i = len - 3; i > 0; i--) { + tcp->ppt_data[j] = cio_read(cio, 1); + j++; + } + tcp->ppt_store = j; +} + +static void j3d_write_sot(opj_j3d_t *j3d) { + int lenp, len; + + opj_cio_t *cio = j3d->cio; + + j3d->sot_start = cio_tell(cio); + cio_write(cio, J3D_MS_SOT, 2); /* SOT */ + lenp = cio_tell(cio); + cio_skip(cio, 2); /* Lsot (further) */ + cio_write(cio, j3d->curtileno, 2); /* Isot */ + cio_skip(cio, 4); /* Psot (further in j3d_write_sod) */ + cio_write(cio, 0, 1); /* TPsot */ + cio_write(cio, 1, 1); /* TNsot (no of tile-parts of this tile in this codestream)*/ + len = cio_tell(cio) - lenp; + cio_seek(cio, lenp); + cio_write(cio, len, 2); /* Lsot */ + cio_seek(cio, lenp + len); +} + +static void j3d_read_sot(opj_j3d_t *j3d) { + int len, tileno, totlen, partno, numparts, i; + opj_tcp_t *tcp = NULL; + char status = 0; + + opj_cp_t *cp = j3d->cp; + opj_cio_t *cio = j3d->cio; + + len = cio_read(cio, 2); + tileno = cio_read(cio, 2); + + if (cp->tileno_size == 0) { + cp->tileno[cp->tileno_size] = tileno; + cp->tileno_size++; + } else { + i = 0; + while (i < cp->tileno_size && status == 0) { + status = cp->tileno[i] == tileno ? 1 : 0; + i++; + } + if (status == 0) { + cp->tileno[cp->tileno_size] = tileno; + cp->tileno_size++; + } + } + + totlen = cio_read(cio, 4); + if (!totlen) + totlen = cio_numbytesleft(cio) + 8; + + partno = cio_read(cio, 1); + numparts = cio_read(cio, 1); + + j3d->curtileno = tileno; + j3d->eot = cio_getbp(cio) - 12 + totlen; + j3d->state = J3D_STATE_TPH; + tcp = &cp->tcps[j3d->curtileno]; + + if (tcp->first == 1) { + + /* Initialization PPT */ + opj_tccp_t *tmp = tcp->tccps; + memcpy(tcp, j3d->default_tcp, sizeof(opj_tcp_t)); + tcp->ppt = 0; + tcp->ppt_data = NULL; + tcp->ppt_data_first = NULL; + tcp->tccps = tmp; + + for (i = 0; i < j3d->volume->numcomps; i++) { + tcp->tccps[i] = j3d->default_tcp->tccps[i]; + } + cp->tcps[j3d->curtileno].first = 0; + } +} + +static void j3d_write_sod(opj_j3d_t *j3d, void *tile_coder) { + int l, layno; + int totlen; + opj_tcp_t *tcp = NULL; + opj_volume_info_t *volume_info = NULL; + + opj_tcd_t *tcd = (opj_tcd_t*)tile_coder; /* cast is needed because of conflicts in header inclusions */ + opj_cp_t *cp = j3d->cp; + opj_cio_t *cio = j3d->cio; + + cio_write(cio, J3D_MS_SOD, 2); + if (j3d->curtileno == 0) { + j3d->sod_start = cio_tell(cio) + j3d->pos_correction; + } + + /* INDEX >> */ + volume_info = j3d->volume_info; + if (volume_info && volume_info->index_on) { + volume_info->tile[j3d->curtileno].end_header = cio_tell(cio) + j3d->pos_correction - 1; + } + /* << INDEX */ + + tcp = &cp->tcps[j3d->curtileno]; + for (layno = 0; layno < tcp->numlayers; layno++) { + tcp->rates[layno] -= tcp->rates[layno] ? (j3d->sod_start / (cp->th * cp->tw * cp->tl)) : 0; + } + + if(volume_info) { + volume_info->num = 0; + } + + l = tcd_encode_tile(tcd, j3d->curtileno, cio_getbp(cio), cio_numbytesleft(cio) - 2, volume_info); + + /* Writing Psot in SOT marker */ + totlen = cio_tell(cio) + l - j3d->sot_start; + cio_seek(cio, j3d->sot_start + 6); + cio_write(cio, totlen, 4); + cio_seek(cio, j3d->sot_start + totlen); +} + +static void j3d_read_sod(opj_j3d_t *j3d) { + int len, truncate = 0, i; + unsigned char *data = NULL, *data_ptr = NULL; + + opj_cio_t *cio = j3d->cio; + int curtileno = j3d->curtileno; + + len = int_min(j3d->eot - cio_getbp(cio), cio_numbytesleft(cio) + 1); + + if (len == cio_numbytesleft(cio) + 1) { + truncate = 1; /* Case of a truncate codestream */ + } + + data = (unsigned char *) opj_malloc((j3d->tile_len[curtileno] + len) * sizeof(unsigned char)); + + for (i = 0; i < j3d->tile_len[curtileno]; i++) { + data[i] = j3d->tile_data[curtileno][i]; + } + + data_ptr = data + j3d->tile_len[curtileno]; + for (i = 0; i < len; i++) { + data_ptr[i] = cio_read(cio, 1); + } + + j3d->tile_len[curtileno] += len; + opj_free(j3d->tile_data[curtileno]); + j3d->tile_data[curtileno] = data; + + if (!truncate) { + j3d->state = J3D_STATE_TPHSOT; + } else { + j3d->state = J3D_STATE_NEOC; /* RAJOUTE !! */ + } +} + +static void j3d_write_rgn(opj_j3d_t *j3d, int compno, int tileno) { + + opj_cp_t *cp = j3d->cp; + opj_tcp_t *tcp = &cp->tcps[tileno]; + opj_cio_t *cio = j3d->cio; + int numcomps = j3d->volume->numcomps; + + cio_write(cio, J3D_MS_RGN, 2); /* RGN */ + cio_write(cio, numcomps <= 256 ? 5 : 6, 2); /* Lrgn */ + cio_write(cio, compno, numcomps <= 256 ? 1 : 2); /* Crgn */ + cio_write(cio, 0, 1); /* Srgn */ + cio_write(cio, tcp->tccps[compno].roishift, 1); /* SPrgn */ +} + +static void j3d_read_rgn(opj_j3d_t *j3d) { + int len, compno, roisty; + + opj_cp_t *cp = j3d->cp; + opj_tcp_t *tcp = j3d->state == J3D_STATE_TPH ? &cp->tcps[j3d->curtileno] : j3d->default_tcp; + opj_cio_t *cio = j3d->cio; + int numcomps = j3d->volume->numcomps; + + len = cio_read(cio, 2); /* Lrgn */ + compno = cio_read(cio, numcomps <= 256 ? 1 : 2); /* Crgn */ + roisty = cio_read(cio, 1); /* Srgn */ + tcp->tccps[compno].roishift = cio_read(cio, 1); /* SPrgn */ +} + +static void j3d_write_eoc(opj_j3d_t *j3d) { + opj_cio_t *cio = j3d->cio; + /* opj_event_msg(j3d->cinfo, "%.8x: EOC\n", cio_tell(cio) + j3d->pos_correction); */ + cio_write(cio, J3D_MS_EOC, 2); +} + +static void j3d_read_eoc(opj_j3d_t *j3d) { + int i, tileno; + +#ifndef NO_PACKETS_DECODING + opj_tcd_t *tcd = tcd_create(j3d->cinfo); + tcd_malloc_decode(tcd, j3d->volume, j3d->cp); + /*j3d_dump_volume(stdout, tcd->volume); + j3d_dump_cp(stdout, tcd->volume, tcd->cp);*/ + for (i = 0; i < j3d->cp->tileno_size; i++) { + tileno = j3d->cp->tileno[i]; + /*opj_event_msg(j3d->cinfo, EVT_INFO, "tcd_decode_tile \n");*/ + tcd_decode_tile(tcd, j3d->tile_data[tileno], j3d->tile_len[tileno], tileno); + opj_free(j3d->tile_data[tileno]); + j3d->tile_data[tileno] = NULL; + } + tcd_free_decode(tcd); + tcd_destroy(tcd); +#else + for (i = 0; i < j3d->cp->tileno_size; i++) { + tileno = j3d->cp->tileno[i]; + opj_free(j3d->tile_data[tileno]); + j3d->tile_data[tileno] = NULL; + } +#endif + + j3d->state = J3D_STATE_MT; +} + +static void j3d_read_unk(opj_j3d_t *j3d) { + opj_event_msg(j3d->cinfo, EVT_WARNING, "Unknown marker\n"); +} + +static opj_atk_t atk_info_wt[] = { + {0, 1, J3D_ATK_WS, J3D_ATK_IRR, 0, J3D_ATK_WS, 1.230174104, 4, {0}, {0}, {0}, {1,1,1,1}, {-1.586134342059924, -0.052980118572961, 0.882911075530934, 0.443506852043971}},/* WT 9-7 IRR*/ + {1, 0, J3D_ATK_WS, J3D_ATK_REV, 0, J3D_ATK_WS, 0, 2, {0}, {1,2}, {1,2}, {1,1}, {-1.0,1.0}},/* WT 5-3 REV*/ + {2, 0, J3D_ATK_ARB, J3D_ATK_REV, 0, J3D_ATK_CON, 0, 2, {0,0}, {0,1}, {0,1}, {1,1}, {{-1.0},{1.0}}}, /* WT 2-2 REV*/ + {3, 0, J3D_ATK_ARB, J3D_ATK_REV, 1, J3D_ATK_CON, 0, 3, {0,0,-1}, {0,1,2}, {0,1,2}, {1,1,3}, {{-1.0},{1.0},{1.0,0.0,-1.0}}}, /* WT 2-6 REV*/ + {4, 0, J3D_ATK_ARB, J3D_ATK_REV, 1, J3D_ATK_CON, 0, 3, {0,0,-2}, {0,1,6}, {0,1,32}, {1,1,5}, {{-1},{1},{-3.0,22.0,0.0,-22.0,3.0}}}, /* WT 2-10 REV*/ + {5, 1, J3D_ATK_ARB, J3D_ATK_IRR, 1, J3D_ATK_WS, 1, 7, {0}, {0}, {0}, {1,1,2,1,2,1,3},{{-1},{1.58613434206},{-0.460348209828, 0.460348209828},{0.25},{0.374213867768,-0.374213867768},{-1.33613434206},{0.29306717103,0,-0.29306717103}}}, /* WT 6-10 IRR*/ + {6, 1, J3D_ATK_ARB, J3D_ATK_IRR, 0, J3D_ATK_WS, 1, 11, {0}, {0}, {0}, {1,1,2,1,2,1,2,1,2,1,5},{{-1},{0,99715069105},{-1.00573127827, 1.00573127827},{-0.27040357631},{2.20509972343, -2.20509972343},{0.08059995736}, + {-1.62682532350, 1.62682532350},{0.52040357631},{0.60404664250, -0.60404664250},{-0.82775064841},{-0.06615812964, 0.29402137720, 0, -0.29402137720, 0.06615812964}}}, /* WT 10-18 IRR*/ + {7, 1, J3D_ATK_WS, J3D_ATK_IRR, 0, J3D_ATK_WS, 1, 2, {0}, {0}, {0}, {1,1}, {-0.5, 0.25}}, /* WT 5-3 IRR*/ + {8, 0, J3D_ATK_WS, J3D_ATK_REV, 0, J3D_ATK_WS, 0, 2, {0}, {4,4}, {8,8}, {2,2}, {{-9,1},{5,-1}}} /* WT 13-7 REV*/ +}; + +typedef struct opj_dec_mstabent { + /** marker value */ + int id; + /** value of the state when the marker can appear */ + int states; + /** action linked to the marker */ + void (*handler) (opj_j3d_t *j3d); +} opj_dec_mstabent_t; + +opj_dec_mstabent_t j3d_dec_mstab[] = { + {J3D_MS_SOC, J3D_STATE_MHSOC, j3d_read_soc}, + {J3D_MS_SOT, J3D_STATE_MH | J3D_STATE_TPHSOT, j3d_read_sot}, + {J3D_MS_SOD, J3D_STATE_TPH, j3d_read_sod}, + {J3D_MS_EOC, J3D_STATE_TPHSOT, j3d_read_eoc}, + {J3D_MS_CAP, J3D_STATE_MHSIZ, j3d_read_cap}, + {J3D_MS_SIZ, J3D_STATE_MHSIZ, j3d_read_siz}, + {J3D_MS_NSI, J3D_STATE_MHSIZ, j3d_read_nsi}, + {J3D_MS_COD, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_cod}, + {J3D_MS_COC, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_coc}, + {J3D_MS_RGN, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_rgn}, + {J3D_MS_QCD, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_qcd}, + {J3D_MS_QCC, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_qcc}, + {J3D_MS_POC, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_poc}, + {J3D_MS_TLM, J3D_STATE_MH, j3d_read_tlm}, + {J3D_MS_PLM, J3D_STATE_MH, j3d_read_plm}, + {J3D_MS_PLT, J3D_STATE_TPH, j3d_read_plt}, + {J3D_MS_PPM, J3D_STATE_MH, j3d_read_ppm}, + {J3D_MS_PPT, J3D_STATE_TPH, j3d_read_ppt}, + {J3D_MS_SOP, 0, 0}, + {J3D_MS_CRG, J3D_STATE_MH, j3d_read_crg}, + {J3D_MS_COM, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_com}, + {J3D_MS_DCO, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_dco}, + {J3D_MS_ATK, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_atk}, + {0, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_unk} + /*, -->must define the j3d_read functions + {J3D_MS_CBD, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_cbd}, + {J3D_MS_MCT, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_mct}, + {J3D_MS_MCC, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_mcc}, + {J3D_MS_MCO, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_mco}, + {J3D_MS_NLT, J3D_STATE_MH | J3D_STATE_TPH, j3d_read_nlt}, + {J3D_MS_VMS, J3D_STATE_MH, j3d_read_vms}, + {J3D_MS_DFS, J3D_STATE_MH, j3d_read_dfs}, + {J3D_MS_ADS, J3D_STATE_MH, j3d_read_ads}, + {J3D_MS_QPD, J3D_STATE_MH, j3d_read_qpd}, + {J3D_MS_QPC, J3D_STATE_TPH, j3d_read_qpc}*/ +}; + +/** +Read the lookup table containing all the marker, status and action +@param id Marker value +*/ +static opj_dec_mstabent_t *j3d_dec_mstab_lookup(int id) { + opj_dec_mstabent_t *e; + for (e = j3d_dec_mstab; e->id != 0; e++) { + if (e->id == id) { + break; + } + } + return e; +} + +/* ----------------------------------------------------------------------- */ +/* J3D / JPT decoder interface */ +/* ----------------------------------------------------------------------- */ + +opj_j3d_t* j3d_create_decompress(opj_common_ptr cinfo) { + opj_j3d_t *j3d = (opj_j3d_t*)opj_malloc(sizeof(opj_j3d_t)); + if(j3d) { + j3d->cinfo = cinfo; + j3d->default_tcp = (opj_tcp_t*)opj_malloc(sizeof(opj_tcp_t)); + if(!j3d->default_tcp) { + opj_free(j3d); + return NULL; + } + } + return j3d; +} + +void j3d_destroy_decompress(opj_j3d_t *j3d) { + int i = 0; + + if(j3d->tile_len != NULL) { + opj_free(j3d->tile_len); + } + if(j3d->tile_data != NULL) { + opj_free(j3d->tile_data); + } + if(j3d->default_tcp != NULL) { + opj_tcp_t *default_tcp = j3d->default_tcp; + if(default_tcp->ppt_data_first != NULL) { + opj_free(default_tcp->ppt_data_first); + } + if(j3d->default_tcp->tccps != NULL) { + opj_free(j3d->default_tcp->tccps); + } + opj_free(j3d->default_tcp); + } + if(j3d->cp != NULL) { + opj_cp_t *cp = j3d->cp; + if(cp->tcps != NULL) { + for(i = 0; i < cp->tw * cp->th * cp->tl; i++) { + if(cp->tcps[i].ppt_data_first != NULL) { + opj_free(cp->tcps[i].ppt_data_first); + } + if(cp->tcps[i].tccps != NULL) { + opj_free(cp->tcps[i].tccps); + } + } + opj_free(cp->tcps); + } + if(cp->ppm_data_first != NULL) { + opj_free(cp->ppm_data_first); + } + if(cp->tileno != NULL) { + opj_free(cp->tileno); + } + if(cp->comment != NULL) { + opj_free(cp->comment); + } + + opj_free(cp); + } + + opj_free(j3d); +} + +void j3d_setup_decoder(opj_j3d_t *j3d, opj_dparameters_t *parameters) { + if(j3d && parameters) { + /* create and initialize the coding parameters structure */ + opj_cp_t *cp = (opj_cp_t*)opj_malloc(sizeof(opj_cp_t)); + cp->reduce[0] = parameters->cp_reduce[0]; + cp->reduce[1] = parameters->cp_reduce[1]; + cp->reduce[2] = parameters->cp_reduce[2]; + cp->layer = parameters->cp_layer; + cp->bigendian = parameters->bigendian; + + /* MM: Settings of the following two member variables would take + place during j3d_read_com. FIXME */ + cp->encoding_format = ENCOD_3EB; + cp->transform_format = TRF_2D_DWT; + + /* keep a link to cp so that we can destroy it later in j3d_destroy_decompress */ + j3d->cp = cp; + } +} + +opj_volume_t* j3d_decode(opj_j3d_t *j3d, opj_cio_t *cio) { + opj_volume_t *volume = NULL; + + opj_common_ptr cinfo = j3d->cinfo; + + j3d->cio = cio; + + /* create an empty volume */ + volume = (opj_volume_t*)opj_malloc(sizeof(opj_volume_t)); + j3d->volume = volume; + + j3d->state = J3D_STATE_MHSOC; + + for (;;) { + opj_dec_mstabent_t *e; + int id = cio_read(cio, 2); + if (id >> 8 != 0xff) { + opj_volume_destroy(volume); + opj_event_msg(cinfo, EVT_ERROR, "%.8x: expected a marker instead of %x\n", cio_tell(cio) - 2, id); + return 0; + } + e = j3d_dec_mstab_lookup(id); + /*opj_event_msg(cinfo, EVT_INFO, "MARKER %x PREVSTATE %d E->STATE %d\n",e->id,j3d->state,e->states);*/ + if (!(j3d->state & e->states)) { + opj_volume_destroy(volume); + opj_event_msg(cinfo, EVT_ERROR, "%.8x: unexpected marker %x\n", cio_tell(cio) - 2, id); + return 0; + } + if (e->handler) { + (*e->handler)(j3d); + } + /*opj_event_msg(cinfo, EVT_INFO, "POSTSTATE %d\n",j3d->state);*/ + if (j3d->state == J3D_STATE_MT) { + break; + } + if (j3d->state == J3D_STATE_NEOC) { + break; + } + } + if (j3d->state == J3D_STATE_NEOC) { + j3d_read_eoc(j3d); + } + + if (j3d->state != J3D_STATE_MT) { + opj_event_msg(cinfo, EVT_WARNING, "Incomplete bitstream\n"); + } + + return volume; +} + +/* ----------------------------------------------------------------------- */ +/* J3D encoder interface */ +/* ----------------------------------------------------------------------- */ + +opj_j3d_t* j3d_create_compress(opj_common_ptr cinfo) { + opj_j3d_t *j3d = (opj_j3d_t*)opj_malloc(sizeof(opj_j3d_t)); + if(j3d) { + j3d->cinfo = cinfo; + } + return j3d; +} + +void j3d_destroy_compress(opj_j3d_t *j3d) { + int tileno; + + if(!j3d) return; + + if(j3d->volume_info != NULL) { + opj_volume_info_t *volume_info = j3d->volume_info; + if (volume_info->index_on && j3d->cp) { + opj_cp_t *cp = j3d->cp; + for (tileno = 0; tileno < cp->tw * cp->th; tileno++) { + opj_tile_info_t *tile_info = &volume_info->tile[tileno]; + opj_free(tile_info->thresh); + opj_free(tile_info->packet); + } + opj_free(volume_info->tile); + } + opj_free(volume_info); + } + if(j3d->cp != NULL) { + opj_cp_t *cp = j3d->cp; + + if(cp->comment) { + opj_free(cp->comment); + } + if(cp->matrice) { + opj_free(cp->matrice); + } + for (tileno = 0; tileno < cp->tw * cp->th; tileno++) { + opj_free(cp->tcps[tileno].tccps); + } + opj_free(cp->tcps); + opj_free(cp); + } + + opj_free(j3d); +} + +void j3d_setup_encoder(opj_j3d_t *j3d, opj_cparameters_t *parameters, opj_volume_t *volume) { + int i, j, tileno, numpocs_tile; + opj_cp_t *cp = NULL; + + if(!j3d || !parameters || ! volume) { + return; + } + + /* create and initialize the coding parameters structure */ + cp = (opj_cp_t*)opj_malloc(sizeof(opj_cp_t)); + + /* keep a link to cp so that we can destroy it later in j3d_destroy_compress */ + j3d->cp = cp; + + /* set default values for cp */ + cp->tw = 1; + cp->th = 1; + cp->tl = 1; + + /* copy user encoding parameters */ + cp->disto_alloc = parameters->cp_disto_alloc; + cp->fixed_alloc = parameters->cp_fixed_alloc; + cp->fixed_quality = parameters->cp_fixed_quality; + + /* transform and coding method */ + cp->transform_format = parameters->transform_format; + cp->encoding_format = parameters->encoding_format; + + /* mod fixed_quality */ + if(parameters->cp_matrice) { + size_t array_size = parameters->tcp_numlayers * 3 * parameters->numresolution[0] * sizeof(int); + cp->matrice = (int *) opj_malloc(array_size); + memcpy(cp->matrice, parameters->cp_matrice, array_size); + } + + /* creation of an index file ? */ + cp->index_on = parameters->index_on; + if(cp->index_on) { + j3d->volume_info = (opj_volume_info_t*)opj_malloc(sizeof(opj_volume_info_t)); + } + + /* tiles */ + cp->tdx = parameters->cp_tdx; + cp->tdy = parameters->cp_tdy; + cp->tdz = parameters->cp_tdz; + /* tile offset */ + cp->tx0 = parameters->cp_tx0; + cp->ty0 = parameters->cp_ty0; + cp->tz0 = parameters->cp_tz0; + /* comment string */ + if(parameters->cp_comment) { + cp->comment = (char*)opj_malloc(strlen(parameters->cp_comment) + 1); + if(cp->comment) { + strcpy(cp->comment, parameters->cp_comment); + } + } + + /*calculate other encoding parameters*/ + if (parameters->tile_size_on) { + cp->tw = int_ceildiv(volume->x1 - cp->tx0, cp->tdx); + cp->th = int_ceildiv(volume->y1 - cp->ty0, cp->tdy); + cp->tl = int_ceildiv(volume->z1 - cp->tz0, cp->tdz); + } else { + cp->tdx = volume->x1 - cp->tx0; + cp->tdy = volume->y1 - cp->ty0; + cp->tdz = volume->z1 - cp->tz0; + } + + /* initialize the multiple tiles */ + /* ---------------------------- */ + cp->tcps = (opj_tcp_t *) opj_malloc(cp->tw * cp->th * cp->tl * sizeof(opj_tcp_t)); + + for (tileno = 0; tileno < cp->tw * cp->th * cp->tl; tileno++) { + opj_tcp_t *tcp = &cp->tcps[tileno]; + tcp->numlayers = parameters->tcp_numlayers; + for (j = 0; j < tcp->numlayers; j++) { + if (cp->fixed_quality) { /* add fixed_quality */ + tcp->distoratio[j] = parameters->tcp_distoratio[j]; + } else { + tcp->rates[j] = parameters->tcp_rates[j]; + } + } + tcp->csty = parameters->csty; + tcp->prg = parameters->prog_order; + tcp->mct = volume->numcomps == 3 ? 1 : 0; + + numpocs_tile = 0; + tcp->POC = 0; + if (parameters->numpocs) { + /* initialisation of POC */ + tcp->POC = 1; + for (i = 0; i < parameters->numpocs; i++) { + if((tileno == parameters->POC[i].tile - 1) || (parameters->POC[i].tile == -1)) { + opj_poc_t *tcp_poc = &tcp->pocs[numpocs_tile]; + tcp_poc->resno0 = parameters->POC[numpocs_tile].resno0; + tcp_poc->compno0 = parameters->POC[numpocs_tile].compno0; + tcp_poc->layno1 = parameters->POC[numpocs_tile].layno1; + tcp_poc->resno1 = parameters->POC[numpocs_tile].resno1; + tcp_poc->compno1 = parameters->POC[numpocs_tile].compno1; + tcp_poc->prg = parameters->POC[numpocs_tile].prg; + tcp_poc->tile = parameters->POC[numpocs_tile].tile; + numpocs_tile++; + } + } + } + tcp->numpocs = numpocs_tile; + + tcp->tccps = (opj_tccp_t *) opj_malloc(volume->numcomps * sizeof(opj_tccp_t)); + + for (i = 0; i < volume->numcomps; i++) { + opj_tccp_t *tccp = &tcp->tccps[i]; + tccp->csty = parameters->csty & J3D_CCP_CSTY_PRT; /* 0 => standard precint || 1 => custom-defined precinct */ + tccp->numresolution[0] = parameters->numresolution[0]; + tccp->numresolution[1] = parameters->numresolution[1]; + tccp->numresolution[2] = parameters->numresolution[2]; + assert (parameters->cblock_init[0] <= T1_MAXCBLKW); + assert (parameters->cblock_init[0] >= T1_MINCBLKW); + assert (parameters->cblock_init[1] <= T1_MAXCBLKH); + assert (parameters->cblock_init[1] >= T1_MINCBLKH); + assert (parameters->cblock_init[2] <= T1_MAXCBLKD); + assert (parameters->cblock_init[2] >= T1_MINCBLKD); + tccp->cblk[0] = int_floorlog2(parameters->cblock_init[0]); + tccp->cblk[1] = int_floorlog2(parameters->cblock_init[1]); + tccp->cblk[2] = int_floorlog2(parameters->cblock_init[2]); + assert (tccp->cblk[0]+tccp->cblk[1]+tccp->cblk[1] <= T1_MAXWHD); + tccp->cblksty = parameters->mode; /*Codeblock style --> Table A.19 (default 0)*/ + + /*ATK / transform */ + tccp->reversible = parameters->irreversible ? 0 : 1; /* 0 => DWT 9-7 || 1 => DWT 5-3 */ + for (j = 0; j < 3; j++) { + tccp->dwtid[j] = parameters->irreversible ? 0 : 1; /* 0 => DWT 9-7 || 1 => DWT 5-3 */ + } + + /* Quantification: SEQNT (Scalar Expounded, value for each subband) / NOQNT (no quant)*/ + tccp->qntsty = parameters->irreversible ? J3D_CCP_QNTSTY_SEQNT : J3D_CCP_QNTSTY_NOQNT; + tccp->numgbits = 2; + if (i == parameters->roi_compno) { + tccp->roishift = parameters->roi_shift; + } else { + tccp->roishift = 0; + } + /* Custom defined precints */ + if (parameters->csty & J3D_CCP_CSTY_PRT) { + int k; + for (k = 0; k < 3; k++) { + int p = 0; + for (j = tccp->numresolution[k] - 1; j >= 0; j--) { + if (p < parameters->res_spec) {/* p < number of precinct size specifications */ + if (parameters->prct_init[k][p] < 1) { + tccp->prctsiz[k][j] = 1; + } else { + tccp->prctsiz[k][j] = int_floorlog2(parameters->prct_init[k][p]); + } + } else { + int res_spec = parameters->res_spec; + int size_prct = parameters->prct_init[k][res_spec - 1] >> (p - (res_spec - 1)); + if (size_prct < 1) { + tccp->prctsiz[k][j] = 1; + } else { + tccp->prctsiz[k][j] = int_floorlog2(size_prct); + } + } + } + p++; + } + } else { + int k; + for (k = 0; k < 3; k++) { + for (j = 0; j < tccp->numresolution[k]; j++) { + tccp->prctsiz[k][j] = 15; + } + } + } + /*Calcular stepsize for each subband (if NOQNT -->stepsize = 1.0)*/ + dwt_calc_explicit_stepsizes(tccp, volume->comps[i].prec); + } + } +} + +/** +Create an index file +@param j3d +@param cio +@param volume_info +@param index Index filename +@return Returns 1 if successful, returns 0 otherwise +*/ +static int j3d_create_index(opj_j3d_t *j3d, opj_cio_t *cio, opj_volume_info_t *volume_info, char *index) { + + int tileno, compno, layno, resno, precno, pack_nb, x, y, z; + FILE *stream = NULL; + double total_disto = 0; + + volume_info->codestream_size = cio_tell(cio) + j3d->pos_correction; /* Correction 14/4/03 suite rmq de Patrick */ + + stream = fopen(index, "w"); + if (!stream) { + opj_event_msg(j3d->cinfo, EVT_ERROR, "failed to open %s for writing\n", index); + return 0; + } + + fprintf(stream, "w %d\t h %d\t l %d\n", volume_info->volume_w, volume_info->volume_h, volume_info->volume_l); + fprintf(stream, "TRASNFORM\t%d\n", volume_info->transform_format); + fprintf(stream, "ENTROPY CODING\t%d\n", volume_info->encoding_format); + fprintf(stream, "PROG\t%d\n", volume_info->prog); + fprintf(stream, "TILE\tx %d y %d z %d\n", volume_info->tile_x, volume_info->tile_y, volume_info->tile_z); + fprintf(stream, "NOTILE\tx %d y %d z %d\n", volume_info->tw, volume_info->th, volume_info->tl); + fprintf(stream, "COMPONENTS\t%d\n", volume_info->comp); + fprintf(stream, "LAYER\t%d\n", volume_info->layer); + fprintf(stream, "RESOLUTIONS\tx %d y %d z %d\n", volume_info->decomposition[0], volume_info->decomposition[1], volume_info->decomposition[2]); + + fprintf(stream, "Precint sizes for each resolution:\n"); + for (resno = volume_info->decomposition[0]; resno >= 0; resno--) { + fprintf(stream, "Resno %d \t [%d,%d,%d] \n", resno, + (1 << volume_info->tile[0].prctsiz[0][resno]), (1 << volume_info->tile[0].prctsiz[0][resno]), (1 << volume_info->tile[0].prctsiz[2][resno])); /* based on tile 0 */ + } + fprintf(stream, "HEADER_END\t%d\n", volume_info->main_head_end); + fprintf(stream, "CODESTREAM\t%d\n", volume_info->codestream_size); + fprintf(stream, "Num_tile Start_pos End_header End_pos Distotile Nbpix Ratio\n"); + for (tileno = 0; tileno < (volume_info->tw * volume_info->th * volume_info->tl); tileno++) { + fprintf(stream, "%4d\t%9d\t%9d\t%9d\t%9e\t%9d\t%9e\n", + volume_info->tile[tileno].num_tile, + volume_info->tile[tileno].start_pos, + volume_info->tile[tileno].end_header, + volume_info->tile[tileno].end_pos, + volume_info->tile[tileno].distotile, volume_info->tile[tileno].nbpix, + volume_info->tile[tileno].distotile / volume_info->tile[tileno].nbpix); + } + + for (tileno = 0; tileno < (volume_info->tw * volume_info->th * volume_info->tl); tileno++) { + int start_pos, end_pos; + double disto = 0; + pack_nb = 0; + if (volume_info->prog == LRCP) { /* LRCP */ + fprintf(stream, "pack_nb tileno layno resno compno precno start_pos end_pos disto\n"); + for (layno = 0; layno < volume_info->layer; layno++) { + for (resno = 0; resno < volume_info->decomposition[0] + 1; resno++) { + for (compno = 0; compno < volume_info->comp; compno++) { + int prec_max = volume_info->tile[tileno].prctno[0][resno] * volume_info->tile[tileno].prctno[1][resno] * volume_info->tile[tileno].prctno[2][resno]; + for (precno = 0; precno < prec_max; precno++) { + start_pos = volume_info->tile[tileno].packet[pack_nb].start_pos; + end_pos = volume_info->tile[tileno].packet[pack_nb].end_pos; + disto = volume_info->tile[tileno].packet[pack_nb].disto; + fprintf(stream, "%4d %6d %7d %5d %6d %6d %9d %9d %8e\n",pack_nb, tileno, layno, resno, compno, precno, start_pos, end_pos, disto); + total_disto += disto; + pack_nb++; + } + } + } + } + } /* LRCP */ + else if (volume_info->prog == RLCP) { /* RLCP */ + /* + fprintf(stream, "pack_nb tileno resno layno compno precno start_pos end_pos disto"); + */ + for (resno = 0; resno < volume_info->decomposition[0] + 1; resno++) { + for (layno = 0; layno < volume_info->layer; layno++) { + for (compno = 0; compno < volume_info->comp; compno++) { + int prec_max = volume_info->tile[tileno].prctno[0][resno] * volume_info->tile[tileno].prctno[1][resno]* volume_info->tile[tileno].prctno[2][resno]; + for (precno = 0; precno < prec_max; precno++) { + start_pos = volume_info->tile[tileno].packet[pack_nb].start_pos; + end_pos = volume_info->tile[tileno].packet[pack_nb].end_pos; + disto = volume_info->tile[tileno].packet[pack_nb].disto; + fprintf(stream, "%4d %6d %5d %7d %6d %6d %9d %9d %8e\n", + pack_nb, tileno, resno, layno, compno, precno, start_pos, end_pos, disto); + total_disto += disto; + pack_nb++; + } + } + } + } + } /* RLCP */ + else if (volume_info->prog == RPCL) { /* RPCL */ + /* + fprintf(stream, "\npack_nb tileno resno precno compno layno start_pos end_pos disto\n"); + */ + for (resno = 0; resno < volume_info->decomposition[0] + 1; resno++) { + /* I suppose components have same XRsiz, YRsiz */ + /*int x0 = volume_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)volume_info->tw ) * volume_info->tw * volume_info->tile_x;*/ + /*int y0 = volume_info->tile_Ox + (int)floor( (float)tileno/(float)volume_info->tw ) * volume_info->tile_y;*/ + int x0 = volume_info->tile_Ox + (int)floor( (float)tileno/(float)volume_info->tw ) * volume_info->tile_x; + int y0 = volume_info->tile_Oy + (int)floor( (float)tileno/(float)volume_info->th ) * volume_info->tile_y; + int z0 = volume_info->tile_Ox + (int)floor( (float)tileno/(float)volume_info->tl ) * volume_info->tile_z; + int x1 = x0 + volume_info->tile_x; + int y1 = y0 + volume_info->tile_y; + int z1 = z0 + volume_info->tile_z; + for(z = z0; z < z1; z++) { + for(y = y0; y < y1; y++) { + for(x = x0; x < x1; x++) { + for (compno = 0; compno < volume_info->comp; compno++) { + int prec_max = volume_info->tile[tileno].prctno[0][resno] * volume_info->tile[tileno].prctno[1][resno] * volume_info->tile[tileno].prctno[2][resno]; + for (precno = 0; precno < prec_max; precno++) { + int pcnx = volume_info->tile[tileno].prctno[0][resno]; + int pcx = (int) pow( 2, volume_info->tile[tileno].prctsiz[0][resno] + volume_info->decomposition[0] - resno ); + int pcy = (int) pow( 2, volume_info->tile[tileno].prctsiz[1][resno] + volume_info->decomposition[1] - resno ); + int pcz = (int) pow( 2, volume_info->tile[tileno].prctsiz[2][resno] + volume_info->decomposition[2] - resno ); + int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; + int precno_y = (int) floor( (float)precno/(float)pcnx ); + if (precno_y*pcy == y ) { + if (precno_x*pcx == x ) { + for (layno = 0; layno < volume_info->layer; layno++) { + start_pos = volume_info->tile[tileno].packet[pack_nb].start_pos; + end_pos = volume_info->tile[tileno].packet[pack_nb].end_pos; + disto = volume_info->tile[tileno].packet[pack_nb].disto; + fprintf(stream, "%4d %6d %5d %6d %6d %7d %9d %9d %8e\n", + pack_nb, tileno, resno, precno, compno, layno, start_pos, end_pos, disto); + total_disto += disto; + pack_nb++; + } + } + } + } /* precno */ + } /* compno */ + } /* x = x0..x1 */ + } /* y = y0..y1 */ + } /* z = z0..z1 */ + } /* resno */ + } /* RPCL */ + else if (volume_info->prog == PCRL) { /* PCRL */ + /* I suppose components have same XRsiz, YRsiz */ + int x0 = volume_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)volume_info->tw ) * volume_info->tw * volume_info->tile_x; + int y0 = volume_info->tile_Ox + (int)floor( (float)tileno/(float)volume_info->tw ) * volume_info->tile_y; + int z0 = volume_info->tile_Oz + (int)floor( (float)tileno/(float)volume_info->tw ) * volume_info->tile_z; + int x1 = x0 + volume_info->tile_x; + int y1 = y0 + volume_info->tile_y; + int z1 = z0 + volume_info->tile_z; + /* + fprintf(stream, "\npack_nb tileno precno compno resno layno start_pos end_pos disto\n"); + */ + for(z = z0; z < z1; z++) { + for(y = y0; y < y1; y++) { + for(x = x0; x < x1; x++) { + for (compno = 0; compno < volume_info->comp; compno++) { + for (resno = 0; resno < volume_info->decomposition[0] + 1; resno++) { + int prec_max = volume_info->tile[tileno].prctno[0][resno] * volume_info->tile[tileno].prctno[1][resno]; + for (precno = 0; precno < prec_max; precno++) { + int pcnx = volume_info->tile[tileno].prctno[0][resno]; + int pcx = (int) pow( 2, volume_info->tile[tileno].prctsiz[0][resno] + volume_info->decomposition[0] - resno ); + int pcy = (int) pow( 2, volume_info->tile[tileno].prctsiz[1][resno] + volume_info->decomposition[1] - resno ); + int pcz = (int) pow( 2, volume_info->tile[tileno].prctsiz[2][resno] + volume_info->decomposition[2] - resno ); + int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; + int precno_y = (int) floor( (float)precno/(float)pcnx ); + int precno_z = (int) floor( (float)precno/(float)pcnx ); + if (precno_z*pcz == z ) { + if (precno_y*pcy == y ) { + if (precno_x*pcx == x ) { + for (layno = 0; layno < volume_info->layer; layno++) { + start_pos = volume_info->tile[tileno].packet[pack_nb].start_pos; + end_pos = volume_info->tile[tileno].packet[pack_nb].end_pos; + disto = volume_info->tile[tileno].packet[pack_nb].disto; + fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d %9d %8e\n", + pack_nb, tileno, precno, compno, resno, layno, start_pos, end_pos, disto); + total_disto += disto; + pack_nb++; + } + } + } + } + } /* precno */ + } /* resno */ + } /* compno */ + } /* x = x0..x1 */ + } /* y = y0..y1 */ + } + } /* PCRL */ + else { /* CPRL */ + /* + fprintf(stream, "\npack_nb tileno compno precno resno layno start_pos end_pos disto\n"); + */ + for (compno = 0; compno < volume_info->comp; compno++) { + /* I suppose components have same XRsiz, YRsiz */ + int x0 = volume_info->tile_Ox + tileno - (int)floor( (float)tileno/(float)volume_info->tw ) * volume_info->tw * volume_info->tile_x; + int y0 = volume_info->tile_Ox + (int)floor( (float)tileno/(float)volume_info->tw ) * volume_info->tile_y; + int z0 = volume_info->tile_Oz + (int)floor( (float)tileno/(float)volume_info->tw ) * volume_info->tile_z; + int x1 = x0 + volume_info->tile_x; + int y1 = y0 + volume_info->tile_y; + int z1 = z0 + volume_info->tile_z; + for(z = z0; z < z1; z++) { + for(y = y0; y < y1; y++) { + for(x = x0; x < x1; x++) { + for (resno = 0; resno < volume_info->decomposition[0] + 1; resno++) { + int prec_max = volume_info->tile[tileno].prctno[0][resno] * volume_info->tile[tileno].prctno[1][resno] * volume_info->tile[tileno].prctno[2][resno]; + for (precno = 0; precno < prec_max; precno++) { + int pcnx = volume_info->tile[tileno].prctno[0][resno]; + int pcny = volume_info->tile[tileno].prctno[1][resno]; + int pcx = (int) pow( 2, volume_info->tile[tileno].prctsiz[0][resno] + volume_info->decomposition[0] - resno ); + int pcy = (int) pow( 2, volume_info->tile[tileno].prctsiz[1][resno] + volume_info->decomposition[1] - resno ); + int pcz = (int) pow( 2, volume_info->tile[tileno].prctsiz[2][resno] + volume_info->decomposition[2] - resno ); + int precno_x = precno - (int) floor( (float)precno/(float)pcnx ) * pcnx; + int precno_y = (int) floor( (float)precno/(float)pcnx ); + int precno_z = 0; /*???*/ + if (precno_z*pcz == z ) { + if (precno_y*pcy == y ) { + if (precno_x*pcx == x ) { + for (layno = 0; layno < volume_info->layer; layno++) { + start_pos = volume_info->tile[tileno].packet[pack_nb].start_pos; + end_pos = volume_info->tile[tileno].packet[pack_nb].end_pos; + disto = volume_info->tile[tileno].packet[pack_nb].disto; + fprintf(stream, "%4d %6d %6d %6d %5d %7d %9d %9d %8e\n", + pack_nb, tileno, compno, precno, resno, layno, start_pos, end_pos, disto); + total_disto += disto; + pack_nb++; + } + } + } + } + } /* precno */ + } /* resno */ + } /* x = x0..x1 */ + } /* y = y0..y1 */ + } /* z = z0..z1 */ + } /* comno */ + } /* CPRL */ + } /* tileno */ + + fprintf(stream, "SE_MAX\t%8e\n", volume_info->D_max); /* SE max */ + fprintf(stream, "SE_TOTAL\t%.8e\n", total_disto); /* SE totale */ + + + fclose(stream); + + return 1; +} + +bool j3d_encode(opj_j3d_t *j3d, opj_cio_t *cio, opj_volume_t *volume, char *index) { + int tileno, compno; + opj_volume_info_t *volume_info = NULL; + opj_cp_t *cp = NULL; + opj_tcd_t *tcd = NULL; /* TCD component */ + + j3d->cio = cio; + j3d->volume = volume; + cp = j3d->cp; + + /*j3d_dump_volume(stdout, volume); + j3d_dump_cp(stdout, volume, cp);*/ + + /* INDEX >> */ + volume_info = j3d->volume_info; + if (volume_info && cp->index_on) { + volume_info->index_on = cp->index_on; + volume_info->tile = (opj_tile_info_t *) opj_malloc(cp->tw * cp->th * cp->tl * sizeof(opj_tile_info_t)); + volume_info->volume_w = volume->x1 - volume->x0; + volume_info->volume_h = volume->y1 - volume->y0; + volume_info->volume_l = volume->z1 - volume->z0; + volume_info->prog = (&cp->tcps[0])->prg; + volume_info->tw = cp->tw; + volume_info->th = cp->th; + volume_info->tl = cp->tl; + volume_info->tile_x = cp->tdx; /* new version parser */ + volume_info->tile_y = cp->tdy; /* new version parser */ + volume_info->tile_z = cp->tdz; /* new version parser */ + volume_info->tile_Ox = cp->tx0; /* new version parser */ + volume_info->tile_Oy = cp->ty0; /* new version parser */ + volume_info->tile_Oz = cp->tz0; /* new version parser */ + volume_info->transform_format = cp->transform_format; + volume_info->encoding_format = cp->encoding_format; + volume_info->comp = volume->numcomps; + volume_info->layer = (&cp->tcps[0])->numlayers; + volume_info->decomposition[0] = (&cp->tcps[0])->tccps->numresolution[0] - 1; + volume_info->decomposition[1] = (&cp->tcps[0])->tccps->numresolution[1] - 1; + volume_info->decomposition[2] = (&cp->tcps[0])->tccps->numresolution[2] - 1; + volume_info->D_max = 0; /* ADD Marcela */ + } + /* << INDEX */ + + j3d_write_soc(j3d); + j3d_write_siz(j3d); + if (j3d->cinfo->codec_format == CODEC_J3D) { + j3d_write_cap(j3d); + j3d_write_nsi(j3d); + } + + /*if (j3d->cp->transform_format != TRF_2D_DWT || j3d->cp->encoding_format != ENCOD_2EB)*/ + j3d_write_com(j3d); + + j3d_write_cod(j3d); + j3d_write_qcd(j3d); + for (compno = 0; compno < volume->numcomps; compno++) { + opj_tcp_t *tcp = &cp->tcps[0]; + if (tcp->tccps[compno].roishift) + j3d_write_rgn(j3d, compno, 0); + } + /*Optional 15444-2 markers*/ + if (j3d->cp->tcps->tccps[0].atk != NULL) + j3d_write_atk(j3d); + if (j3d->volume->comps[0].dcoffset != 0) + j3d_write_dco(j3d); + + /* INDEX >> */ + if(volume_info && volume_info->index_on) { + volume_info->main_head_end = cio_tell(cio) - 1; + } + /* << INDEX */ + + /* create the tile encoder */ + tcd = tcd_create(j3d->cinfo); + + /* encode each tile */ + for (tileno = 0; tileno < cp->tw * cp->th * cp->tl; tileno++) { + opj_event_msg(j3d->cinfo, EVT_INFO, "tile number %d / %d\n", tileno + 1, cp->tw * cp->th * cp->tl); + + j3d->curtileno = tileno; + + /* initialisation before tile encoding */ + if (tileno == 0) { + tcd_malloc_encode(tcd, volume, cp, j3d->curtileno); + } else { + tcd_init_encode(tcd, volume, cp, j3d->curtileno); + } + + /* INDEX >> */ + if(volume_info && volume_info->index_on) { + volume_info->tile[j3d->curtileno].num_tile = j3d->curtileno; + volume_info->tile[j3d->curtileno].start_pos = cio_tell(cio) + j3d->pos_correction; + } + /* << INDEX */ + + j3d_write_sot(j3d); + + for (compno = 1; compno < volume->numcomps; compno++) { + j3d_write_coc(j3d, compno); + j3d_write_qcc(j3d, compno); + } + + if (cp->tcps[tileno].numpocs) { + j3d_write_poc(j3d); + } + j3d_write_sod(j3d, tcd); /*--> tcd_encode_tile*/ + + /* INDEX >> */ + if(volume_info && volume_info->index_on) { + volume_info->tile[j3d->curtileno].end_pos = cio_tell(cio) + j3d->pos_correction - 1; + } + /* << INDEX */ + } + + /* destroy the tile encoder */ + tcd_free_encode(tcd); + tcd_destroy(tcd); + + j3d_write_eoc(j3d); + + /* Creation of the index file */ + if(volume_info && volume_info->index_on) { + if(!j3d_create_index(j3d, cio, volume_info, index)) { + opj_event_msg(j3d->cinfo, EVT_ERROR, "failed to create index file %s\n", index); + return false; + } + } + + return true; +} + +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + diff --git a/src/lib/openjp3d/jp3d.h b/src/lib/openjp3d/jp3d.h index edd27a1a..d54e21dc 100644 --- a/src/lib/openjp3d/jp3d.h +++ b/src/lib/openjp3d/jp3d.h @@ -1,518 +1,518 @@ -/* - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium - * Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef __J3D_H -#define __J3D_H -/** -@file jp3d.h -@brief The JPEG-2000 Codestream Reader/Writer (J3D) - -The functions in J3D.C have for goal to read/write the several parts of the codestream: markers and data. -*/ - -/** @defgroup J3D J3D - JPEG-2000 PART 10 codestream reader/writer */ -/*@{*/ - -#define J3D_CP_CSTY_PRT 0x01 -#define J3D_CP_CSTY_SOP 0x02 -#define J3D_CP_CSTY_EPH 0x04 -#define J3D_CCP_CSTY_PRT 0x01 -/** Table A-8 */ -#define J3D_CCP_CBLKSTY_LAZY 0x01 /* Selective arithmetic coding bypass */ -#define J3D_CCP_CBLKSTY_RESET 0x02 /* Reset context probabilities on coding pass boundaries */ -#define J3D_CCP_CBLKSTY_TERMALL 0x04 /* Termination on each coding pass */ -#define J3D_CCP_CBLKSTY_VSC 0x08 /* Vertically causal context, add also hook for switching off and on 3D context models */ -#define J3D_CCP_CBLKSTY_PTERM 0x10 /* Predictable termination */ -#define J3D_CCP_CBLKSTY_SEGSYM 0x20 /* Segmentation symbols are used */ -#define J3D_CCP_CBLKSTY_3DCTXT 0x40 /* 3D context models (3D-EBCOT) vs 2D context models */ - -#define J3D_CCP_QNTSTY_NOQNT 0 /* Quantization style : no quantization */ -#define J3D_CCP_QNTSTY_SIQNT 1 /* Quantization style : scalar derived (values signalled only in LLL subband) */ -#define J3D_CCP_QNTSTY_SEQNT 2 /* Quantization style : scalar expounded (values signalled for each subband) */ - -/* ----------------------------------------------------------------------- */ - -#define J3D_MS_SOC 0xff4f /**< SOC marker value */ -#define J3D_MS_SOT 0xff90 /**< SOT marker value */ -#define J3D_MS_SOD 0xff93 /**< SOD marker value */ -#define J3D_MS_EOC 0xffd9 /**< EOC marker value */ -#define J3D_MS_CAP 0xff50 /**< CAP marker value */ -#define J3D_MS_SIZ 0xff51 /**< SIZ marker value */ -#define J3D_MS_NSI 0xff54 /**< NSI marker value */ -#define J3D_MS_COD 0xff52 /**< COD marker value */ -#define J3D_MS_COC 0xff53 /**< COC marker value */ -#define J3D_MS_RGN 0xff5e /**< RGN marker value */ -#define J3D_MS_QCD 0xff5c /**< QCD marker value */ -#define J3D_MS_QCC 0xff5d /**< QCC marker value */ -#define J3D_MS_POC 0xff5f /**< POC marker value */ -#define J3D_MS_TLM 0xff55 /**< TLM marker value */ -#define J3D_MS_PLM 0xff57 /**< PLM marker value */ -#define J3D_MS_PLT 0xff58 /**< PLT marker value */ -#define J3D_MS_PPM 0xff60 /**< PPM marker value */ -#define J3D_MS_PPT 0xff61 /**< PPT marker value */ -#define J3D_MS_SOP 0xff91 /**< SOP marker value */ -#define J3D_MS_EPH 0xff92 /**< EPH marker value */ -#define J3D_MS_CRG 0xff63 /**< CRG marker value */ -#define J3D_MS_COM 0xff64 /**< COM marker value */ -/*15444-2*/ -#define J3D_MS_DCO 0xff70 /**< DCO marker value */ -#define J3D_MS_VMS 0xff71 /**< VMS marker value */ -#define J3D_MS_DFS 0xff72 /**< DFS marker value */ -#define J3D_MS_ADS 0xff73 /**< ADS marker value */ -#define J3D_MS_ATK 0xff79 /**< ATK marker value */ -#define J3D_MS_CBD 0xff78 /**< CBD marker value */ -#define J3D_MS_MCT 0xff74 /**< MCT marker value */ -#define J3D_MS_MCC 0xff75 /**< MCC marker value */ -#define J3D_MS_MCO 0xff77 /**< MCO marker value */ -#define J3D_MS_NLT 0xff76 /**< NLT marker value */ -#define J3D_MS_QPD 0xff5a /**< QPD marker value */ -#define J3D_MS_QPC 0xff5b /**< QPC marker value */ - -/* ----------------------------------------------------------------------- */ -/* Capability RSIZ parameter, extended */ -#define J3D_RSIZ_BASIC 0x0000 - -#define J3D_RSIZ_DCO 0x8001 /* Required */ -#define J3D_RSIZ_VSQNT 0x8002 -#define J3D_RSIZ_TCQNT 0x8004 -#define J3D_RSIZ_VMASK 0x8008 -#define J3D_RSIZ_SSOVL 0x8010 -#define J3D_RSIZ_ADECS 0x8020 -#define J3D_RSIZ_ATK 0x8040 /*Required*/ -#define J3D_RSIZ_SSYMK 0x8080 -#define J3D_RSIZ_MCT 0x8100 /*Not compatible with DCO*/ -#define J3D_RSIZ_NLT 0x8200 /*Required*/ -#define J3D_RSIZ_ASHAP 0x8400 -#define J3D_RSIZ_PRQNT 0x8800 - -#define J3D_CAP_10 0x00400000 -/* Arbitrary transformation kernel, 15444-2 */ -#define J3D_ATK_IRR 0 -#define J3D_ATK_REV 1 -#define J3D_ATK_ARB 0 -#define J3D_ATK_WS 1 -#define J3D_ATK_CON 0 -/* ----------------------------------------------------------------------- */ - -/** -Values that specify the status of the decoding process when decoding the main header. -These values may be combined with a | operator. -*/ -typedef enum J3D_STATUS { - /**< a SOC marker is expected */ - J3D_STATE_MHSOC = 0x0001, - /**< a SIZ marker is expected */ - J3D_STATE_MHSIZ = 0x0002, - /**< the decoding process is in the main header */ - J3D_STATE_MH = 0x0004, - /**< the decoding process is in a tile part header and expects a SOT marker */ - J3D_STATE_TPHSOT = 0x0008, - /**< the decoding process is in a tile part header */ - J3D_STATE_TPH = 0x0010, - /**< the EOC marker has just been read */ - J3D_STATE_MT = 0x0020, - /**< the decoding process must not expect a EOC marker because the codestream is truncated */ - J3D_STATE_NEOC = 0x0040 -} J3D_STATUS; - - - -/** -Arbitrary transformation kernel -*/ -typedef struct opj_atk { -/** index of wavelet kernel */ - int index; -/** Numerical type of scaling factor and lifting step parameters */ - int coeff_typ; -/** Wavelet filter category */ - int filt_cat; -/** Wavelet transformation type (REV/IRR) */ - int wt_typ; -/** Initial odd/even subsequence */ - int minit; -/** Boundary extension method (constant CON / whole-sample symmetric WS) */ - int exten; -/** Scaling factor. Only for wt_typ=IRR */ - double Katk; -/** Number of lifting steps */ - int Natk; -/** Offset for lifting step s. Only for filt_cat=ARB */ - int Oatk[256]; -/** Base 2 scaling exponent for lifting step s. Only for wt_typ=REV */ - int Eatk[256]; -/** Additive residue for lifting step s. Only for wt_typ=REV */ - int Batk[256]; -/** Number of lifting coefficients signaled for lifting step s */ - int LCatk[256]; -/** Lifting coefficient k for lifting step s */ - double Aatk[256][256]; -} opj_atk_t; - - -/** -Quantization stepsize -*/ -typedef struct opj_stepsize { -/** exponent */ - int expn; -/** mantissa */ - int mant; -} opj_stepsize_t; - -/** -Tile-component coding parameters -*/ -typedef struct opj_tccp { - /** coding style */ - int csty; - /** number of resolutions of x, y and z-axis */ - int numresolution[3]; - /** code-blocks width height & depth*/ - int cblk[3]; - /** code-block coding style */ - int cblksty; - /** 0: no ATK (only 9-7 or 5-3) 1: ATK defined WT*/ - int atk_wt[3]; - /** Arbitrary transformation kernel (15444-2)*/ - opj_atk_t *atk; - /** DWT identifier for x, y and z-axis (0:WT9-7 1:WT5-3 >1:WT-atk->index) */ - int dwtid[3]; - /** reversible/irreversible wavelet transfomation (0:irrev 1:reversible)*/ - int reversible; - /** quantisation style */ - int qntsty; - /** stepsizes used for quantization */ - opj_stepsize_t stepsizes[J3D_MAXBANDS]; - /** number of guard bits. Table A28 de 15444-1*/ - int numgbits; - /** Region Of Interest shift */ - int roishift; - /** precinct width heigth & depth*/ - int prctsiz[3][J3D_MAXRLVLS]; -} opj_tccp_t; - -/** -Tile coding parameters : coding/decoding parameters common to all tiles -(information like COD, COC in main header) -*/ -typedef struct opj_tcp { -/** 1 : first part-tile of a tile */ - int first; - /** coding style */ - int csty; - /** progression order */ - OPJ_PROG_ORDER prg; - /** number of layers */ - int numlayers; - /** multi-component transform identifier */ - int mct; - /** rates of layers */ - float rates[100]; - /** number of progression order changes */ - int numpocs; - /** indicates if a POC marker has been used O:NO, 1:YES */ - int POC; - /** progression order changes */ - opj_poc_t pocs[J3D_MAXRLVLS - 1]; - /** add fixed_quality */ - float distoratio[100]; - /** tile-component coding parameters */ - opj_tccp_t *tccps; -/** packet header store there for futur use in t2_decode_packet */ - unsigned char *ppt_data; - /** pointer remaining on the first byte of the first header if ppt is used */ - unsigned char *ppt_data_first; - /** If ppt == 1 --> there was a PPT marker for the present tile */ - int ppt; - /** used in case of multiple marker PPT (number of info already stored) */ - int ppt_store; - int ppt_len; -} opj_tcp_t; - -/** -Coding parameters -*/ -typedef struct opj_cp { -/** transform format 0: 2DWT, 1: 2D1P, 2: 3DWT, 3: 3RLS */ - OPJ_TRANSFORM transform_format; - /** entropy coding format 0: 2EB, 1: 3EB, 2: 2GR, 3: 3GR, 4: GRI*/ - OPJ_ENTROPY_CODING encoding_format; - /** allocation by rate/distortion */ - int disto_alloc; - /** allocation by fixed layer */ - int fixed_alloc; - /** add fixed_quality */ - int fixed_quality; - /** Rsiz: capabilities */ - int rsiz; - /** if != 0, then original dimension divided by 2^(reduce); if == 0 or not used, volume is decoded to the full resolution */ - int reduce[3]; - /** if != 0, then only the first "layer" layers are decoded; if == 0 or not used, all the quality layers are decoded */ - int layer; - /** 0 = no index || 1 = index */ - int index_on; - /** Big-Endian/Little-endian order */ - int bigendian; - /** XTOsiz */ - int tx0; - /** YTOsiz */ - int ty0; - /** ZTOsiz */ - int tz0; - /** XTsiz */ - int tdx; - /** YTsiz */ - int tdy; - /** ZTsiz */ - int tdz; - /** comment for coding */ - char *comment; - /** number of tiles in width, heigth and depth */ - int tw; - int th; - int tl; - /** ID number of the tiles present in the codestream */ - int *tileno; - /** size of the vector tileno */ - int tileno_size; - /** tile coding parameters */ - opj_tcp_t *tcps; - /** fixed layer */ - int *matrice; - - /** packet header store there for futur use in t2_decode_packet */ - unsigned char *ppm_data; - /** pointer remaining on the first byte of the first header if ppm is used */ - unsigned char *ppm_data_first; - /** if ppm == 1 --> there was a PPM marker for the present tile */ - int ppm; - /** use in case of multiple marker PPM (number of info already store) */ - int ppm_store; - /** use in case of multiple marker PPM (case on non-finished previous info) */ - int ppm_previous; - int ppm_len; -} opj_cp_t; - -/** -Information concerning a packet inside tile -*/ -typedef struct opj_packet_info { - /** start position */ - int start_pos; - /** end position */ - int end_pos; - /** distorsion introduced */ - double disto; -} opj_packet_info_t; - -/** -Index structure : information regarding tiles inside volume -*/ -typedef struct opj_tile_info { - /** value of thresh for each layer by tile cfr. Marcela */ - double *thresh; - /** number of tile */ - int num_tile; - /** start position */ - int start_pos; - /** end position of the header */ - int end_header; - /** end position */ - int end_pos; - /** precinct number for each resolution level (width, heigth and depth) */ - int prctno[3][J3D_MAXRLVLS]; - /** precinct size (in power of 2), in X for each resolution level */ - int prctsiz[3][J3D_MAXRLVLS]; - /** information concerning packets inside tile */ - opj_packet_info_t *packet; - - /** add fixed_quality */ - int nbpix; - /** add fixed_quality */ - double distotile; -} opj_tile_info_t; - -/** -Index structure -*/ -typedef struct opj_volume_info { - - /** transform format 0: 2DWT, 1: 2D1P, 2: 3DWT, 3: 3RLS */ - OPJ_TRANSFORM transform_format; - /** output file format 0: 2EB, 1: 3EB, 2: 2GR, 3: 3GR, 4: GRI*/ - OPJ_ENTROPY_CODING encoding_format; /** 0 = no index || 1 = index */ - int index_on; - /** 0 = wt 9-7 || 1 = wt 5-3 || >=2 wt atk defined */ - int dwtid[3]; - /** maximum distortion reduction on the whole volume (add for Marcela) */ - double D_max; - /** packet number */ - int num; - /** writing the packet in the index with t2_encode_packets */ - int index_write; - /** volume width, height and depth */ - int volume_w; - int volume_h; - int volume_l; - /** progression order */ - OPJ_PROG_ORDER prog; - /** tile size in x, y and z */ - int tile_x; - int tile_y; - int tile_z; - /** tile origin in x, y and z */ - int tile_Ox; - int tile_Oy; - int tile_Oz; - /** number of tiles in X, Y and Z */ - int tw; - int th; - int tl; - /** component numbers */ - int comp; - /** number of layer */ - int layer; - /** number of decomposition in X, Y and Z*/ - int decomposition[3]; - /** DC offset (15444-2) */ - int dcoffset; - /** main header position */ - int main_head_end; - /** codestream's size */ - int codestream_size; - /** information regarding tiles inside volume */ - opj_tile_info_t *tile; -} opj_volume_info_t; - -/** -JPEG-2000 codestream reader/writer -*/ -typedef struct opj_j3d { - /** codec context */ - opj_common_ptr cinfo; - /** locate in which part of the codestream the decoder is (main header, tile header, end) */ - int state; - /** number of the tile curently concern by coding/decoding */ - int curtileno; - /** locate the position of the end of the tile in the codestream, used to detect a truncated codestream (in j3d_read_sod) */ - unsigned char *eot; - /** locate the start position of the SOT marker of the current coded tile: */ - int sot_start; - /* after encoding the tile, a jump (in j3d_write_sod) is done to the SOT marker to store the value of its length. */ - int sod_start; - /** as the J3D-file is written in several parts during encoding, it enables to make the right correction in position return by cio_tell */ - int pos_correction; - /** array used to store the data of each tile */ - unsigned char **tile_data; - /** array used to store the length of each tile */ - int *tile_len; - - /** decompression only : store decoding parameters common to all tiles */ - opj_tcp_t *default_tcp; - /** pointer to the encoded / decoded volume */ - opj_volume_t *volume; - /** pointer to the coding parameters */ - opj_cp_t *cp; - /** helper used to write the index file */ - opj_volume_info_t *volume_info; - /** pointer to the byte i/o stream */ - opj_cio_t *cio; -} opj_j3d_t; - -/** @name Funciones generales */ -/*@{*/ -/* ----------------------------------------------------------------------- */ -/** -Creates a J3D decompression structure -@param cinfo Codec context info -@return Returns a handle to a J3D decompressor if successful, returns NULL otherwise -*/ -opj_j3d_t* j3d_create_decompress(opj_common_ptr cinfo); -/** -Destroy a J3D decompressor handle -@param j3d J3D decompressor handle to destroy -*/ -void j3d_destroy_decompress(opj_j3d_t *j3d); -/** -Setup the decoder decoding parameters using user parameters. -Decoding parameters are returned in j3d->cp. -@param j3d J3D decompressor handle -@param parameters decompression parameters -*/ -void j3d_setup_decoder(opj_j3d_t *j3d, opj_dparameters_t *parameters); -/** -Decode an volume from a JPEG-2000 codestream -@param j3d J3D decompressor handle -@param cio Input buffer stream -@return Returns a decoded volume if successful, returns NULL otherwise -*/ -opj_volume_t* j3d_decode(opj_j3d_t *j3d, opj_cio_t *cio); -/** -Decode an volume form a JPT-stream (JPEG 2000, JPIP) -@param j3d J3D decompressor handle -@param cio Input buffer stream -@return Returns a decoded volume if successful, returns NULL otherwise -*/ -opj_volume_t* j3d_decode_jpt_stream(opj_j3d_t *j3d, opj_cio_t *cio); -/** -Creates a J3D compression structure -@param cinfo Codec context info -@return Returns a handle to a J3D compressor if successful, returns NULL otherwise -*/ -opj_j3d_t* j3d_create_compress(opj_common_ptr cinfo); -/** -Destroy a J3D compressor handle -@param j3d J3D compressor handle to destroy -*/ -void j3d_destroy_compress(opj_j3d_t *j3d); -/** -Setup the encoder parameters using the current volume and using user parameters. -Coding parameters are returned in j3d->cp. -@param j3d J3D compressor handle -@param parameters compression parameters -@param volume input filled volume -*/ -void j3d_setup_encoder(opj_j3d_t *j3d, opj_cparameters_t *parameters, opj_volume_t *volume); -/** -Encode an volume into a JPEG-2000 codestream -@param j3d J3D compressor handle -@param cio Output buffer stream -@param volume Volume to encode -@param index Name of the index file if required, NULL otherwise -@return Returns true if successful, returns false otherwise -*/ -bool j3d_encode(opj_j3d_t *j3d, opj_cio_t *cio, opj_volume_t *volume, char *index); -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __J3D_H */ +/* + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __J3D_H +#define __J3D_H +/** +@file jp3d.h +@brief The JPEG-2000 Codestream Reader/Writer (J3D) + +The functions in J3D.C have for goal to read/write the several parts of the codestream: markers and data. +*/ + +/** @defgroup J3D J3D - JPEG-2000 PART 10 codestream reader/writer */ +/*@{*/ + +#define J3D_CP_CSTY_PRT 0x01 +#define J3D_CP_CSTY_SOP 0x02 +#define J3D_CP_CSTY_EPH 0x04 +#define J3D_CCP_CSTY_PRT 0x01 +/** Table A-8 */ +#define J3D_CCP_CBLKSTY_LAZY 0x01 /* Selective arithmetic coding bypass */ +#define J3D_CCP_CBLKSTY_RESET 0x02 /* Reset context probabilities on coding pass boundaries */ +#define J3D_CCP_CBLKSTY_TERMALL 0x04 /* Termination on each coding pass */ +#define J3D_CCP_CBLKSTY_VSC 0x08 /* Vertically causal context, add also hook for switching off and on 3D context models */ +#define J3D_CCP_CBLKSTY_PTERM 0x10 /* Predictable termination */ +#define J3D_CCP_CBLKSTY_SEGSYM 0x20 /* Segmentation symbols are used */ +#define J3D_CCP_CBLKSTY_3DCTXT 0x40 /* 3D context models (3D-EBCOT) vs 2D context models */ + +#define J3D_CCP_QNTSTY_NOQNT 0 /* Quantization style : no quantization */ +#define J3D_CCP_QNTSTY_SIQNT 1 /* Quantization style : scalar derived (values signalled only in LLL subband) */ +#define J3D_CCP_QNTSTY_SEQNT 2 /* Quantization style : scalar expounded (values signalled for each subband) */ + +/* ----------------------------------------------------------------------- */ + +#define J3D_MS_SOC 0xff4f /**< SOC marker value */ +#define J3D_MS_SOT 0xff90 /**< SOT marker value */ +#define J3D_MS_SOD 0xff93 /**< SOD marker value */ +#define J3D_MS_EOC 0xffd9 /**< EOC marker value */ +#define J3D_MS_CAP 0xff50 /**< CAP marker value */ +#define J3D_MS_SIZ 0xff51 /**< SIZ marker value */ +#define J3D_MS_NSI 0xff54 /**< NSI marker value */ +#define J3D_MS_COD 0xff52 /**< COD marker value */ +#define J3D_MS_COC 0xff53 /**< COC marker value */ +#define J3D_MS_RGN 0xff5e /**< RGN marker value */ +#define J3D_MS_QCD 0xff5c /**< QCD marker value */ +#define J3D_MS_QCC 0xff5d /**< QCC marker value */ +#define J3D_MS_POC 0xff5f /**< POC marker value */ +#define J3D_MS_TLM 0xff55 /**< TLM marker value */ +#define J3D_MS_PLM 0xff57 /**< PLM marker value */ +#define J3D_MS_PLT 0xff58 /**< PLT marker value */ +#define J3D_MS_PPM 0xff60 /**< PPM marker value */ +#define J3D_MS_PPT 0xff61 /**< PPT marker value */ +#define J3D_MS_SOP 0xff91 /**< SOP marker value */ +#define J3D_MS_EPH 0xff92 /**< EPH marker value */ +#define J3D_MS_CRG 0xff63 /**< CRG marker value */ +#define J3D_MS_COM 0xff64 /**< COM marker value */ +/*15444-2*/ +#define J3D_MS_DCO 0xff70 /**< DCO marker value */ +#define J3D_MS_VMS 0xff71 /**< VMS marker value */ +#define J3D_MS_DFS 0xff72 /**< DFS marker value */ +#define J3D_MS_ADS 0xff73 /**< ADS marker value */ +#define J3D_MS_ATK 0xff79 /**< ATK marker value */ +#define J3D_MS_CBD 0xff78 /**< CBD marker value */ +#define J3D_MS_MCT 0xff74 /**< MCT marker value */ +#define J3D_MS_MCC 0xff75 /**< MCC marker value */ +#define J3D_MS_MCO 0xff77 /**< MCO marker value */ +#define J3D_MS_NLT 0xff76 /**< NLT marker value */ +#define J3D_MS_QPD 0xff5a /**< QPD marker value */ +#define J3D_MS_QPC 0xff5b /**< QPC marker value */ + +/* ----------------------------------------------------------------------- */ +/* Capability RSIZ parameter, extended */ +#define J3D_RSIZ_BASIC 0x0000 + +#define J3D_RSIZ_DCO 0x8001 /* Required */ +#define J3D_RSIZ_VSQNT 0x8002 +#define J3D_RSIZ_TCQNT 0x8004 +#define J3D_RSIZ_VMASK 0x8008 +#define J3D_RSIZ_SSOVL 0x8010 +#define J3D_RSIZ_ADECS 0x8020 +#define J3D_RSIZ_ATK 0x8040 /*Required*/ +#define J3D_RSIZ_SSYMK 0x8080 +#define J3D_RSIZ_MCT 0x8100 /*Not compatible with DCO*/ +#define J3D_RSIZ_NLT 0x8200 /*Required*/ +#define J3D_RSIZ_ASHAP 0x8400 +#define J3D_RSIZ_PRQNT 0x8800 + +#define J3D_CAP_10 0x00400000 +/* Arbitrary transformation kernel, 15444-2 */ +#define J3D_ATK_IRR 0 +#define J3D_ATK_REV 1 +#define J3D_ATK_ARB 0 +#define J3D_ATK_WS 1 +#define J3D_ATK_CON 0 +/* ----------------------------------------------------------------------- */ + +/** +Values that specify the status of the decoding process when decoding the main header. +These values may be combined with a | operator. +*/ +typedef enum J3D_STATUS { + /**< a SOC marker is expected */ + J3D_STATE_MHSOC = 0x0001, + /**< a SIZ marker is expected */ + J3D_STATE_MHSIZ = 0x0002, + /**< the decoding process is in the main header */ + J3D_STATE_MH = 0x0004, + /**< the decoding process is in a tile part header and expects a SOT marker */ + J3D_STATE_TPHSOT = 0x0008, + /**< the decoding process is in a tile part header */ + J3D_STATE_TPH = 0x0010, + /**< the EOC marker has just been read */ + J3D_STATE_MT = 0x0020, + /**< the decoding process must not expect a EOC marker because the codestream is truncated */ + J3D_STATE_NEOC = 0x0040 +} J3D_STATUS; + + + +/** +Arbitrary transformation kernel +*/ +typedef struct opj_atk { +/** index of wavelet kernel */ + int index; +/** Numerical type of scaling factor and lifting step parameters */ + int coeff_typ; +/** Wavelet filter category */ + int filt_cat; +/** Wavelet transformation type (REV/IRR) */ + int wt_typ; +/** Initial odd/even subsequence */ + int minit; +/** Boundary extension method (constant CON / whole-sample symmetric WS) */ + int exten; +/** Scaling factor. Only for wt_typ=IRR */ + double Katk; +/** Number of lifting steps */ + int Natk; +/** Offset for lifting step s. Only for filt_cat=ARB */ + int Oatk[256]; +/** Base 2 scaling exponent for lifting step s. Only for wt_typ=REV */ + int Eatk[256]; +/** Additive residue for lifting step s. Only for wt_typ=REV */ + int Batk[256]; +/** Number of lifting coefficients signaled for lifting step s */ + int LCatk[256]; +/** Lifting coefficient k for lifting step s */ + double Aatk[256][256]; +} opj_atk_t; + + +/** +Quantization stepsize +*/ +typedef struct opj_stepsize { +/** exponent */ + int expn; +/** mantissa */ + int mant; +} opj_stepsize_t; + +/** +Tile-component coding parameters +*/ +typedef struct opj_tccp { + /** coding style */ + int csty; + /** number of resolutions of x, y and z-axis */ + int numresolution[3]; + /** code-blocks width height & depth*/ + int cblk[3]; + /** code-block coding style */ + int cblksty; + /** 0: no ATK (only 9-7 or 5-3) 1: ATK defined WT*/ + int atk_wt[3]; + /** Arbitrary transformation kernel (15444-2)*/ + opj_atk_t *atk; + /** DWT identifier for x, y and z-axis (0:WT9-7 1:WT5-3 >1:WT-atk->index) */ + int dwtid[3]; + /** reversible/irreversible wavelet transfomation (0:irrev 1:reversible)*/ + int reversible; + /** quantisation style */ + int qntsty; + /** stepsizes used for quantization */ + opj_stepsize_t stepsizes[J3D_MAXBANDS]; + /** number of guard bits. Table A28 de 15444-1*/ + int numgbits; + /** Region Of Interest shift */ + int roishift; + /** precinct width heigth & depth*/ + int prctsiz[3][J3D_MAXRLVLS]; +} opj_tccp_t; + +/** +Tile coding parameters : coding/decoding parameters common to all tiles +(information like COD, COC in main header) +*/ +typedef struct opj_tcp { +/** 1 : first part-tile of a tile */ + int first; + /** coding style */ + int csty; + /** progression order */ + OPJ_PROG_ORDER prg; + /** number of layers */ + int numlayers; + /** multi-component transform identifier */ + int mct; + /** rates of layers */ + float rates[100]; + /** number of progression order changes */ + int numpocs; + /** indicates if a POC marker has been used O:NO, 1:YES */ + int POC; + /** progression order changes */ + opj_poc_t pocs[J3D_MAXRLVLS - 1]; + /** add fixed_quality */ + float distoratio[100]; + /** tile-component coding parameters */ + opj_tccp_t *tccps; +/** packet header store there for futur use in t2_decode_packet */ + unsigned char *ppt_data; + /** pointer remaining on the first byte of the first header if ppt is used */ + unsigned char *ppt_data_first; + /** If ppt == 1 --> there was a PPT marker for the present tile */ + int ppt; + /** used in case of multiple marker PPT (number of info already stored) */ + int ppt_store; + int ppt_len; +} opj_tcp_t; + +/** +Coding parameters +*/ +typedef struct opj_cp { +/** transform format 0: 2DWT, 1: 2D1P, 2: 3DWT, 3: 3RLS */ + OPJ_TRANSFORM transform_format; + /** entropy coding format 0: 2EB, 1: 3EB, 2: 2GR, 3: 3GR, 4: GRI*/ + OPJ_ENTROPY_CODING encoding_format; + /** allocation by rate/distortion */ + int disto_alloc; + /** allocation by fixed layer */ + int fixed_alloc; + /** add fixed_quality */ + int fixed_quality; + /** Rsiz: capabilities */ + int rsiz; + /** if != 0, then original dimension divided by 2^(reduce); if == 0 or not used, volume is decoded to the full resolution */ + int reduce[3]; + /** if != 0, then only the first "layer" layers are decoded; if == 0 or not used, all the quality layers are decoded */ + int layer; + /** 0 = no index || 1 = index */ + int index_on; + /** Big-Endian/Little-endian order */ + int bigendian; + /** XTOsiz */ + int tx0; + /** YTOsiz */ + int ty0; + /** ZTOsiz */ + int tz0; + /** XTsiz */ + int tdx; + /** YTsiz */ + int tdy; + /** ZTsiz */ + int tdz; + /** comment for coding */ + char *comment; + /** number of tiles in width, heigth and depth */ + int tw; + int th; + int tl; + /** ID number of the tiles present in the codestream */ + int *tileno; + /** size of the vector tileno */ + int tileno_size; + /** tile coding parameters */ + opj_tcp_t *tcps; + /** fixed layer */ + int *matrice; + + /** packet header store there for futur use in t2_decode_packet */ + unsigned char *ppm_data; + /** pointer remaining on the first byte of the first header if ppm is used */ + unsigned char *ppm_data_first; + /** if ppm == 1 --> there was a PPM marker for the present tile */ + int ppm; + /** use in case of multiple marker PPM (number of info already store) */ + int ppm_store; + /** use in case of multiple marker PPM (case on non-finished previous info) */ + int ppm_previous; + int ppm_len; +} opj_cp_t; + +/** +Information concerning a packet inside tile +*/ +typedef struct opj_packet_info { + /** start position */ + int start_pos; + /** end position */ + int end_pos; + /** distorsion introduced */ + double disto; +} opj_packet_info_t; + +/** +Index structure : information regarding tiles inside volume +*/ +typedef struct opj_tile_info { + /** value of thresh for each layer by tile cfr. Marcela */ + double *thresh; + /** number of tile */ + int num_tile; + /** start position */ + int start_pos; + /** end position of the header */ + int end_header; + /** end position */ + int end_pos; + /** precinct number for each resolution level (width, heigth and depth) */ + int prctno[3][J3D_MAXRLVLS]; + /** precinct size (in power of 2), in X for each resolution level */ + int prctsiz[3][J3D_MAXRLVLS]; + /** information concerning packets inside tile */ + opj_packet_info_t *packet; + + /** add fixed_quality */ + int nbpix; + /** add fixed_quality */ + double distotile; +} opj_tile_info_t; + +/** +Index structure +*/ +typedef struct opj_volume_info { + + /** transform format 0: 2DWT, 1: 2D1P, 2: 3DWT, 3: 3RLS */ + OPJ_TRANSFORM transform_format; + /** output file format 0: 2EB, 1: 3EB, 2: 2GR, 3: 3GR, 4: GRI*/ + OPJ_ENTROPY_CODING encoding_format; /** 0 = no index || 1 = index */ + int index_on; + /** 0 = wt 9-7 || 1 = wt 5-3 || >=2 wt atk defined */ + int dwtid[3]; + /** maximum distortion reduction on the whole volume (add for Marcela) */ + double D_max; + /** packet number */ + int num; + /** writing the packet in the index with t2_encode_packets */ + int index_write; + /** volume width, height and depth */ + int volume_w; + int volume_h; + int volume_l; + /** progression order */ + OPJ_PROG_ORDER prog; + /** tile size in x, y and z */ + int tile_x; + int tile_y; + int tile_z; + /** tile origin in x, y and z */ + int tile_Ox; + int tile_Oy; + int tile_Oz; + /** number of tiles in X, Y and Z */ + int tw; + int th; + int tl; + /** component numbers */ + int comp; + /** number of layer */ + int layer; + /** number of decomposition in X, Y and Z*/ + int decomposition[3]; + /** DC offset (15444-2) */ + int dcoffset; + /** main header position */ + int main_head_end; + /** codestream's size */ + int codestream_size; + /** information regarding tiles inside volume */ + opj_tile_info_t *tile; +} opj_volume_info_t; + +/** +JPEG-2000 codestream reader/writer +*/ +typedef struct opj_j3d { + /** codec context */ + opj_common_ptr cinfo; + /** locate in which part of the codestream the decoder is (main header, tile header, end) */ + int state; + /** number of the tile curently concern by coding/decoding */ + int curtileno; + /** locate the position of the end of the tile in the codestream, used to detect a truncated codestream (in j3d_read_sod) */ + unsigned char *eot; + /** locate the start position of the SOT marker of the current coded tile: */ + int sot_start; + /* after encoding the tile, a jump (in j3d_write_sod) is done to the SOT marker to store the value of its length. */ + int sod_start; + /** as the J3D-file is written in several parts during encoding, it enables to make the right correction in position return by cio_tell */ + int pos_correction; + /** array used to store the data of each tile */ + unsigned char **tile_data; + /** array used to store the length of each tile */ + int *tile_len; + + /** decompression only : store decoding parameters common to all tiles */ + opj_tcp_t *default_tcp; + /** pointer to the encoded / decoded volume */ + opj_volume_t *volume; + /** pointer to the coding parameters */ + opj_cp_t *cp; + /** helper used to write the index file */ + opj_volume_info_t *volume_info; + /** pointer to the byte i/o stream */ + opj_cio_t *cio; +} opj_j3d_t; + +/** @name Funciones generales */ +/*@{*/ +/* ----------------------------------------------------------------------- */ +/** +Creates a J3D decompression structure +@param cinfo Codec context info +@return Returns a handle to a J3D decompressor if successful, returns NULL otherwise +*/ +opj_j3d_t* j3d_create_decompress(opj_common_ptr cinfo); +/** +Destroy a J3D decompressor handle +@param j3d J3D decompressor handle to destroy +*/ +void j3d_destroy_decompress(opj_j3d_t *j3d); +/** +Setup the decoder decoding parameters using user parameters. +Decoding parameters are returned in j3d->cp. +@param j3d J3D decompressor handle +@param parameters decompression parameters +*/ +void j3d_setup_decoder(opj_j3d_t *j3d, opj_dparameters_t *parameters); +/** +Decode an volume from a JPEG-2000 codestream +@param j3d J3D decompressor handle +@param cio Input buffer stream +@return Returns a decoded volume if successful, returns NULL otherwise +*/ +opj_volume_t* j3d_decode(opj_j3d_t *j3d, opj_cio_t *cio); +/** +Decode an volume form a JPT-stream (JPEG 2000, JPIP) +@param j3d J3D decompressor handle +@param cio Input buffer stream +@return Returns a decoded volume if successful, returns NULL otherwise +*/ +opj_volume_t* j3d_decode_jpt_stream(opj_j3d_t *j3d, opj_cio_t *cio); +/** +Creates a J3D compression structure +@param cinfo Codec context info +@return Returns a handle to a J3D compressor if successful, returns NULL otherwise +*/ +opj_j3d_t* j3d_create_compress(opj_common_ptr cinfo); +/** +Destroy a J3D compressor handle +@param j3d J3D compressor handle to destroy +*/ +void j3d_destroy_compress(opj_j3d_t *j3d); +/** +Setup the encoder parameters using the current volume and using user parameters. +Coding parameters are returned in j3d->cp. +@param j3d J3D compressor handle +@param parameters compression parameters +@param volume input filled volume +*/ +void j3d_setup_encoder(opj_j3d_t *j3d, opj_cparameters_t *parameters, opj_volume_t *volume); +/** +Encode an volume into a JPEG-2000 codestream +@param j3d J3D compressor handle +@param cio Output buffer stream +@param volume Volume to encode +@param index Name of the index file if required, NULL otherwise +@return Returns true if successful, returns false otherwise +*/ +bool j3d_encode(opj_j3d_t *j3d, opj_cio_t *cio, opj_volume_t *volume, char *index); +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __J3D_H */ diff --git a/src/lib/openjp3d/jp3d_lib.c b/src/lib/openjp3d/jp3d_lib.c index 4445e859..d63a9b0d 100644 --- a/src/lib/openjp3d/jp3d_lib.c +++ b/src/lib/openjp3d/jp3d_lib.c @@ -1,76 +1,76 @@ -/* - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef _WIN32 -#include -#else -#include -#include -#include -#endif /* _WIN32 */ -#include "opj_includes.h" - -double opj_clock() { -#ifdef _WIN32 - /* WIN32: use QueryPerformance (very accurate) */ - LARGE_INTEGER freq , t ; - /* freq is the clock speed of the CPU */ - QueryPerformanceFrequency(&freq) ; - /* cout << "freq = " << ((double) freq.QuadPart) << endl; */ - /* t is the high resolution performance counter (see MSDN) */ - QueryPerformanceCounter ( & t ) ; - return ( t.QuadPart /(double) freq.QuadPart ) ; -#else - /* Unix or Linux: use resource usage */ - struct rusage t; - double procTime; - /* (1) Get the rusage data structure at this moment (man getrusage) */ - getrusage(0,&t); - /* (2) What is the elapsed time ? - CPU time = User time + System time */ - /* (2a) Get the seconds */ - procTime = t.ru_utime.tv_sec + t.ru_stime.tv_sec; - /* (2b) More precisely! Get the microseconds part ! */ - return ( procTime + (t.ru_utime.tv_usec + t.ru_stime.tv_usec) * 1e-6 ) ; -#endif /* _WIN32 */ -} - -void* opj_malloc( size_t size ) { - void *memblock = malloc(size); - if(memblock) { - memset(memblock, 0, size); - } - return memblock; -} - -void* opj_realloc( void *memblock, size_t size ) { - return realloc(memblock, size); -} - -void opj_free( void *memblock ) { - free(memblock); -} - - +/* + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifdef _WIN32 +#include +#else +#include +#include +#include +#endif /* _WIN32 */ +#include "opj_includes.h" + +double opj_clock() { +#ifdef _WIN32 + /* WIN32: use QueryPerformance (very accurate) */ + LARGE_INTEGER freq , t ; + /* freq is the clock speed of the CPU */ + QueryPerformanceFrequency(&freq) ; + /* cout << "freq = " << ((double) freq.QuadPart) << endl; */ + /* t is the high resolution performance counter (see MSDN) */ + QueryPerformanceCounter ( & t ) ; + return ( t.QuadPart /(double) freq.QuadPart ) ; +#else + /* Unix or Linux: use resource usage */ + struct rusage t; + double procTime; + /* (1) Get the rusage data structure at this moment (man getrusage) */ + getrusage(0,&t); + /* (2) What is the elapsed time ? - CPU time = User time + System time */ + /* (2a) Get the seconds */ + procTime = t.ru_utime.tv_sec + t.ru_stime.tv_sec; + /* (2b) More precisely! Get the microseconds part ! */ + return ( procTime + (t.ru_utime.tv_usec + t.ru_stime.tv_usec) * 1e-6 ) ; +#endif /* _WIN32 */ +} + +void* opj_malloc( size_t size ) { + void *memblock = malloc(size); + if(memblock) { + memset(memblock, 0, size); + } + return memblock; +} + +void* opj_realloc( void *memblock, size_t size ) { + return realloc(memblock, size); +} + +void opj_free( void *memblock ) { + free(memblock); +} + + diff --git a/src/lib/openjp3d/jp3d_lib.h b/src/lib/openjp3d/jp3d_lib.h index dae43275..1b910ae3 100644 --- a/src/lib/openjp3d/jp3d_lib.h +++ b/src/lib/openjp3d/jp3d_lib.h @@ -1,75 +1,75 @@ -/* - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef __J3D_LIB_H -#define __J3D_LIB_H -/** -@file jp3d_lib.h -@brief Internal functions - -The functions in JP3D_LIB.C are internal utilities mainly used for memory management. -*/ - -/** @defgroup MISC MISC - Miscellaneous internal functions */ -/*@{*/ - -/** @name Funciones generales */ -/*@{*/ -/* ----------------------------------------------------------------------- */ - -/** -Difference in successive opj_clock() calls tells you the elapsed time -@return Returns time in seconds -*/ -double opj_clock(void); - -/** -Allocate a memory block with elements initialized to 0 -@param size Bytes to allocate -@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available -*/ -void* opj_malloc( size_t size ); - -/** -Reallocate memory blocks. -@param memblock Pointer to previously allocated memory block -@param size New size in bytes -@return Returns a void pointer to the reallocated (and possibly moved) memory block -*/ -void* opj_realloc( void *memblock, size_t size ); - -/** -Deallocates or frees a memory block. -@param memblock Previously allocated memory block to be freed -*/ -void opj_free( void *memblock ); - -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __J3D_LIB_H */ - +/* + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __J3D_LIB_H +#define __J3D_LIB_H +/** +@file jp3d_lib.h +@brief Internal functions + +The functions in JP3D_LIB.C are internal utilities mainly used for memory management. +*/ + +/** @defgroup MISC MISC - Miscellaneous internal functions */ +/*@{*/ + +/** @name Funciones generales */ +/*@{*/ +/* ----------------------------------------------------------------------- */ + +/** +Difference in successive opj_clock() calls tells you the elapsed time +@return Returns time in seconds +*/ +double opj_clock(void); + +/** +Allocate a memory block with elements initialized to 0 +@param size Bytes to allocate +@return Returns a void pointer to the allocated space, or NULL if there is insufficient memory available +*/ +void* opj_malloc( size_t size ); + +/** +Reallocate memory blocks. +@param memblock Pointer to previously allocated memory block +@param size New size in bytes +@return Returns a void pointer to the reallocated (and possibly moved) memory block +*/ +void* opj_realloc( void *memblock, size_t size ); + +/** +Deallocates or frees a memory block. +@param memblock Previously allocated memory block to be freed +*/ +void opj_free( void *memblock ); + +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __J3D_LIB_H */ + diff --git a/src/lib/openjp3d/mct.c b/src/lib/openjp3d/mct.c index e915e390..ccccdbc4 100644 --- a/src/lib/openjp3d/mct.c +++ b/src/lib/openjp3d/mct.c @@ -1,131 +1,131 @@ -/* - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "opj_includes.h" - -/* */ -/* This table contains the norms of the basis function of the reversible MCT. */ -/* */ -static const double mct_norms[3] = { 1.732, .8292, .8292 }; - -/* */ -/* This table contains the norms of the basis function of the irreversible MCT. */ -/* */ -static const double mct_norms_real[3] = { 1.732, 1.805, 1.573 }; - -/* */ -/* Foward reversible MCT. */ -/* */ -void mct_encode(int *c0, int *c1, int *c2, int n) { - int i; - for (i = 0; i < n; i++) { - int r, g, b, y, u, v; - r = c0[i]; - g = c1[i]; - b = c2[i]; - y = (r + (g << 1) + b) >> 2; - u = b - g; - v = r - g; - c0[i] = y; - c1[i] = u; - c2[i] = v; - } -} - -/* */ -/* Inverse reversible MCT. */ -/* */ -void mct_decode(int *c0, int *c1, int *c2, int n) { - int i; - for (i = 0; i < n; i++) { - int y, u, v, r, g, b; - y = c0[i]; - u = c1[i]; - v = c2[i]; - g = y - ((u + v) >> 2); - r = v + g; - b = u + g; - c0[i] = r; - c1[i] = g; - c2[i] = b; - } -} - -/* */ -/* Get norm of basis function of reversible MCT. */ -/* */ -double mct_getnorm(int compno) { - return mct_norms[compno]; -} - -/* */ -/* Foward irreversible MCT. */ -/* */ -void mct_encode_real(int *c0, int *c1, int *c2, int n) { - int i; - for (i = 0; i < n; i++) { - int r, g, b, y, u, v; - r = c0[i]; - g = c1[i]; - b = c2[i]; - y = fix_mul(r, 2449) + fix_mul(g, 4809) + fix_mul(b, 934); - u = -fix_mul(r, 1382) - fix_mul(g, 2714) + fix_mul(b, 4096); - v = fix_mul(r, 4096) - fix_mul(g, 3430) - fix_mul(b, 666); - c0[i] = y; - c1[i] = u; - c2[i] = v; - } -} - -/* */ -/* Inverse irreversible MCT. */ -/* */ -void mct_decode_real(int *c0, int *c1, int *c2, int n) { - int i; - for (i = 0; i < n; i++) { - int y, u, v, r, g, b; - y = c0[i]; - u = c1[i]; - v = c2[i]; - r = y + fix_mul(v, 11485); - g = y - fix_mul(u, 2819) - fix_mul(v, 5850); - b = y + fix_mul(u, 14516); - c0[i] = r; - c1[i] = g; - c2[i] = b; - } -} - -/* */ -/* Get norm of basis function of irreversible MCT. */ -/* */ -double mct_getnorm_real(int compno) { - return mct_norms_real[compno]; -} +/* + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opj_includes.h" + +/* */ +/* This table contains the norms of the basis function of the reversible MCT. */ +/* */ +static const double mct_norms[3] = { 1.732, .8292, .8292 }; + +/* */ +/* This table contains the norms of the basis function of the irreversible MCT. */ +/* */ +static const double mct_norms_real[3] = { 1.732, 1.805, 1.573 }; + +/* */ +/* Foward reversible MCT. */ +/* */ +void mct_encode(int *c0, int *c1, int *c2, int n) { + int i; + for (i = 0; i < n; i++) { + int r, g, b, y, u, v; + r = c0[i]; + g = c1[i]; + b = c2[i]; + y = (r + (g << 1) + b) >> 2; + u = b - g; + v = r - g; + c0[i] = y; + c1[i] = u; + c2[i] = v; + } +} + +/* */ +/* Inverse reversible MCT. */ +/* */ +void mct_decode(int *c0, int *c1, int *c2, int n) { + int i; + for (i = 0; i < n; i++) { + int y, u, v, r, g, b; + y = c0[i]; + u = c1[i]; + v = c2[i]; + g = y - ((u + v) >> 2); + r = v + g; + b = u + g; + c0[i] = r; + c1[i] = g; + c2[i] = b; + } +} + +/* */ +/* Get norm of basis function of reversible MCT. */ +/* */ +double mct_getnorm(int compno) { + return mct_norms[compno]; +} + +/* */ +/* Foward irreversible MCT. */ +/* */ +void mct_encode_real(int *c0, int *c1, int *c2, int n) { + int i; + for (i = 0; i < n; i++) { + int r, g, b, y, u, v; + r = c0[i]; + g = c1[i]; + b = c2[i]; + y = fix_mul(r, 2449) + fix_mul(g, 4809) + fix_mul(b, 934); + u = -fix_mul(r, 1382) - fix_mul(g, 2714) + fix_mul(b, 4096); + v = fix_mul(r, 4096) - fix_mul(g, 3430) - fix_mul(b, 666); + c0[i] = y; + c1[i] = u; + c2[i] = v; + } +} + +/* */ +/* Inverse irreversible MCT. */ +/* */ +void mct_decode_real(int *c0, int *c1, int *c2, int n) { + int i; + for (i = 0; i < n; i++) { + int y, u, v, r, g, b; + y = c0[i]; + u = c1[i]; + v = c2[i]; + r = y + fix_mul(v, 11485); + g = y - fix_mul(u, 2819) - fix_mul(v, 5850); + b = y + fix_mul(u, 14516); + c0[i] = r; + c1[i] = g; + c2[i] = b; + } +} + +/* */ +/* Get norm of basis function of irreversible MCT. */ +/* */ +double mct_getnorm_real(int compno) { + return mct_norms_real[compno]; +} diff --git a/src/lib/openjp3d/mct.h b/src/lib/openjp3d/mct.h index 0b8edb7b..e843aec9 100644 --- a/src/lib/openjp3d/mct.h +++ b/src/lib/openjp3d/mct.h @@ -1,97 +1,97 @@ -/* - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __MCT_H -#define __MCT_H -/** -@file mct.h -@brief Implementation of a multi-component transforms (MCT) - -The functions in MCT.C have for goal to realize reversible and irreversible multicomponent -transform. The functions in MCT.C are used by some function in TCD.C. -*/ - -/** @defgroup MCT MCT - Implementation of a multi-component transform */ -/*@{*/ - -/** @name Funciones generales */ -/*@{*/ -/* ----------------------------------------------------------------------- */ -/** -Apply a reversible multi-component transform to an image -@param c0 Samples for red component -@param c1 Samples for green component -@param c2 Samples blue component -@param n Number of samples for each component -*/ -void mct_encode(int *c0, int *c1, int *c2, int n); -/** -Apply a reversible multi-component inverse transform to an image -@param c0 Samples for luminance component -@param c1 Samples for red chrominance component -@param c2 Samples for blue chrominance component -@param n Number of samples for each component -*/ -void mct_decode(int *c0, int *c1, int *c2, int n); -/** -Get norm of the basis function used for the reversible multi-component transform -@param compno Number of the component (0->Y, 1->U, 2->V) -@return -*/ -double mct_getnorm(int compno); - -/** -Apply an irreversible multi-component transform to an image -@param c0 Samples for red component -@param c1 Samples for green component -@param c2 Samples blue component -@param n Number of samples for each component -*/ -void mct_encode_real(int *c0, int *c1, int *c2, int n); -/** -Apply an irreversible multi-component inverse transform to an image -@param c0 Samples for luminance component -@param c1 Samples for red chrominance component -@param c2 Samples for blue chrominance component -@param n Number of samples for each component -*/ -void mct_decode_real(int *c0, int *c1, int *c2, int n); -/** -Get norm of the basis function used for the irreversible multi-component transform -@param compno Number of the component (0->Y, 1->U, 2->V) -@return -*/ -double mct_getnorm_real(int compno); -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __MCT_H */ +/* + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __MCT_H +#define __MCT_H +/** +@file mct.h +@brief Implementation of a multi-component transforms (MCT) + +The functions in MCT.C have for goal to realize reversible and irreversible multicomponent +transform. The functions in MCT.C are used by some function in TCD.C. +*/ + +/** @defgroup MCT MCT - Implementation of a multi-component transform */ +/*@{*/ + +/** @name Funciones generales */ +/*@{*/ +/* ----------------------------------------------------------------------- */ +/** +Apply a reversible multi-component transform to an image +@param c0 Samples for red component +@param c1 Samples for green component +@param c2 Samples blue component +@param n Number of samples for each component +*/ +void mct_encode(int *c0, int *c1, int *c2, int n); +/** +Apply a reversible multi-component inverse transform to an image +@param c0 Samples for luminance component +@param c1 Samples for red chrominance component +@param c2 Samples for blue chrominance component +@param n Number of samples for each component +*/ +void mct_decode(int *c0, int *c1, int *c2, int n); +/** +Get norm of the basis function used for the reversible multi-component transform +@param compno Number of the component (0->Y, 1->U, 2->V) +@return +*/ +double mct_getnorm(int compno); + +/** +Apply an irreversible multi-component transform to an image +@param c0 Samples for red component +@param c1 Samples for green component +@param c2 Samples blue component +@param n Number of samples for each component +*/ +void mct_encode_real(int *c0, int *c1, int *c2, int n); +/** +Apply an irreversible multi-component inverse transform to an image +@param c0 Samples for luminance component +@param c1 Samples for red chrominance component +@param c2 Samples for blue chrominance component +@param n Number of samples for each component +*/ +void mct_decode_real(int *c0, int *c1, int *c2, int n); +/** +Get norm of the basis function used for the irreversible multi-component transform +@param compno Number of the component (0->Y, 1->U, 2->V) +@return +*/ +double mct_getnorm_real(int compno); +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __MCT_H */ diff --git a/src/lib/openjp3d/mqc.c b/src/lib/openjp3d/mqc.c index 12ac90d6..874b7340 100644 --- a/src/lib/openjp3d/mqc.c +++ b/src/lib/openjp3d/mqc.c @@ -1,548 +1,548 @@ -/* - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "opj_includes.h" - -/** @defgroup MQC MQC - Implementation of an MQ-Coder */ -/*@{*/ - -/** @name Local static functions */ -/*@{*/ - -/** -Output a byte, doing bit-stuffing if necessary. -After a 0xff byte, the next byte must be smaller than 0x90. -@param mqc MQC handle -*/ -static void mqc_byteout(opj_mqc_t *mqc); -/** -Renormalize mqc->a and mqc->c while encoding, so that mqc->a stays between 0x8000 and 0x10000 -@param mqc MQC handle -*/ -static void mqc_renorme(opj_mqc_t *mqc); -/** -Encode the most probable symbol -@param mqc MQC handle -*/ -static void mqc_codemps(opj_mqc_t *mqc); -/** -Encode the most least symbol -@param mqc MQC handle -*/ -static void mqc_codelps(opj_mqc_t *mqc); -/** -Fill mqc->c with 1's for flushing -@param mqc MQC handle -*/ -static void mqc_setbits(opj_mqc_t *mqc); -/** -Exchange MPS with LPS -@param mqc MQC handle -@return -*/ -static int mqc_mpsexchange(opj_mqc_t *mqc); -/** -Exchange LPS with MPS -@param mqc MQC handle -@return -*/ -static int mqc_lpsexchange(opj_mqc_t *mqc); -/** -Input a byte -@param mqc MQC handle -*/ -static void mqc_bytein(opj_mqc_t *mqc); -/** -Renormalize mqc->a and mqc->c while decoding -@param mqc MQC handle -*/ -static void mqc_renormd(opj_mqc_t *mqc); - -/*@}*/ - -/*@}*/ - -/* */ -/* This array defines all the possible states for a context. */ -/* */ -static opj_mqc_state_t mqc_states[47 * 2] = { - {0x5601, 0, &mqc_states[2], &mqc_states[3]}, - {0x5601, 1, &mqc_states[3], &mqc_states[2]}, - {0x3401, 0, &mqc_states[4], &mqc_states[12]}, - {0x3401, 1, &mqc_states[5], &mqc_states[13]}, - {0x1801, 0, &mqc_states[6], &mqc_states[18]}, - {0x1801, 1, &mqc_states[7], &mqc_states[19]}, - {0x0ac1, 0, &mqc_states[8], &mqc_states[24]}, - {0x0ac1, 1, &mqc_states[9], &mqc_states[25]}, - {0x0521, 0, &mqc_states[10], &mqc_states[58]}, - {0x0521, 1, &mqc_states[11], &mqc_states[59]}, - {0x0221, 0, &mqc_states[76], &mqc_states[66]}, - {0x0221, 1, &mqc_states[77], &mqc_states[67]}, - {0x5601, 0, &mqc_states[14], &mqc_states[13]}, - {0x5601, 1, &mqc_states[15], &mqc_states[12]}, - {0x5401, 0, &mqc_states[16], &mqc_states[28]}, - {0x5401, 1, &mqc_states[17], &mqc_states[29]}, - {0x4801, 0, &mqc_states[18], &mqc_states[28]}, - {0x4801, 1, &mqc_states[19], &mqc_states[29]}, - {0x3801, 0, &mqc_states[20], &mqc_states[28]}, - {0x3801, 1, &mqc_states[21], &mqc_states[29]}, - {0x3001, 0, &mqc_states[22], &mqc_states[34]}, - {0x3001, 1, &mqc_states[23], &mqc_states[35]}, - {0x2401, 0, &mqc_states[24], &mqc_states[36]}, - {0x2401, 1, &mqc_states[25], &mqc_states[37]}, - {0x1c01, 0, &mqc_states[26], &mqc_states[40]}, - {0x1c01, 1, &mqc_states[27], &mqc_states[41]}, - {0x1601, 0, &mqc_states[58], &mqc_states[42]}, - {0x1601, 1, &mqc_states[59], &mqc_states[43]}, - {0x5601, 0, &mqc_states[30], &mqc_states[29]}, - {0x5601, 1, &mqc_states[31], &mqc_states[28]}, - {0x5401, 0, &mqc_states[32], &mqc_states[28]}, - {0x5401, 1, &mqc_states[33], &mqc_states[29]}, - {0x5101, 0, &mqc_states[34], &mqc_states[30]}, - {0x5101, 1, &mqc_states[35], &mqc_states[31]}, - {0x4801, 0, &mqc_states[36], &mqc_states[32]}, - {0x4801, 1, &mqc_states[37], &mqc_states[33]}, - {0x3801, 0, &mqc_states[38], &mqc_states[34]}, - {0x3801, 1, &mqc_states[39], &mqc_states[35]}, - {0x3401, 0, &mqc_states[40], &mqc_states[36]}, - {0x3401, 1, &mqc_states[41], &mqc_states[37]}, - {0x3001, 0, &mqc_states[42], &mqc_states[38]}, - {0x3001, 1, &mqc_states[43], &mqc_states[39]}, - {0x2801, 0, &mqc_states[44], &mqc_states[38]}, - {0x2801, 1, &mqc_states[45], &mqc_states[39]}, - {0x2401, 0, &mqc_states[46], &mqc_states[40]}, - {0x2401, 1, &mqc_states[47], &mqc_states[41]}, - {0x2201, 0, &mqc_states[48], &mqc_states[42]}, - {0x2201, 1, &mqc_states[49], &mqc_states[43]}, - {0x1c01, 0, &mqc_states[50], &mqc_states[44]}, - {0x1c01, 1, &mqc_states[51], &mqc_states[45]}, - {0x1801, 0, &mqc_states[52], &mqc_states[46]}, - {0x1801, 1, &mqc_states[53], &mqc_states[47]}, - {0x1601, 0, &mqc_states[54], &mqc_states[48]}, - {0x1601, 1, &mqc_states[55], &mqc_states[49]}, - {0x1401, 0, &mqc_states[56], &mqc_states[50]}, - {0x1401, 1, &mqc_states[57], &mqc_states[51]}, - {0x1201, 0, &mqc_states[58], &mqc_states[52]}, - {0x1201, 1, &mqc_states[59], &mqc_states[53]}, - {0x1101, 0, &mqc_states[60], &mqc_states[54]}, - {0x1101, 1, &mqc_states[61], &mqc_states[55]}, - {0x0ac1, 0, &mqc_states[62], &mqc_states[56]}, - {0x0ac1, 1, &mqc_states[63], &mqc_states[57]}, - {0x09c1, 0, &mqc_states[64], &mqc_states[58]}, - {0x09c1, 1, &mqc_states[65], &mqc_states[59]}, - {0x08a1, 0, &mqc_states[66], &mqc_states[60]}, - {0x08a1, 1, &mqc_states[67], &mqc_states[61]}, - {0x0521, 0, &mqc_states[68], &mqc_states[62]}, - {0x0521, 1, &mqc_states[69], &mqc_states[63]}, - {0x0441, 0, &mqc_states[70], &mqc_states[64]}, - {0x0441, 1, &mqc_states[71], &mqc_states[65]}, - {0x02a1, 0, &mqc_states[72], &mqc_states[66]}, - {0x02a1, 1, &mqc_states[73], &mqc_states[67]}, - {0x0221, 0, &mqc_states[74], &mqc_states[68]}, - {0x0221, 1, &mqc_states[75], &mqc_states[69]}, - {0x0141, 0, &mqc_states[76], &mqc_states[70]}, - {0x0141, 1, &mqc_states[77], &mqc_states[71]}, - {0x0111, 0, &mqc_states[78], &mqc_states[72]}, - {0x0111, 1, &mqc_states[79], &mqc_states[73]}, - {0x0085, 0, &mqc_states[80], &mqc_states[74]}, - {0x0085, 1, &mqc_states[81], &mqc_states[75]}, - {0x0049, 0, &mqc_states[82], &mqc_states[76]}, - {0x0049, 1, &mqc_states[83], &mqc_states[77]}, - {0x0025, 0, &mqc_states[84], &mqc_states[78]}, - {0x0025, 1, &mqc_states[85], &mqc_states[79]}, - {0x0015, 0, &mqc_states[86], &mqc_states[80]}, - {0x0015, 1, &mqc_states[87], &mqc_states[81]}, - {0x0009, 0, &mqc_states[88], &mqc_states[82]}, - {0x0009, 1, &mqc_states[89], &mqc_states[83]}, - {0x0005, 0, &mqc_states[90], &mqc_states[84]}, - {0x0005, 1, &mqc_states[91], &mqc_states[85]}, - {0x0001, 0, &mqc_states[90], &mqc_states[86]}, - {0x0001, 1, &mqc_states[91], &mqc_states[87]}, - {0x5601, 0, &mqc_states[92], &mqc_states[92]}, - {0x5601, 1, &mqc_states[93], &mqc_states[93]}, -}; - -/* -========================================================== - local functions -========================================================== -*/ - -static void mqc_byteout(opj_mqc_t *mqc) { - if (*mqc->bp == 0xff) { - mqc->bp++; - *mqc->bp = mqc->c >> 20; - mqc->c &= 0xfffff; - mqc->ct = 7; - } else { - if ((mqc->c & 0x8000000) == 0) { /* ((mqc->c&0x8000000)==0) CHANGE */ - mqc->bp++; - *mqc->bp = mqc->c >> 19; - mqc->c &= 0x7ffff; - mqc->ct = 8; - } else { - (*mqc->bp)++; - if (*mqc->bp == 0xff) { - mqc->c &= 0x7ffffff; - mqc->bp++; - *mqc->bp = mqc->c >> 20; - mqc->c &= 0xfffff; - mqc->ct = 7; - } else { - mqc->bp++; - *mqc->bp = mqc->c >> 19; - mqc->c &= 0x7ffff; - mqc->ct = 8; - } - } - } -} - -static void mqc_renorme(opj_mqc_t *mqc) { - do { - mqc->a <<= 1; - mqc->c <<= 1; - mqc->ct--; - if (mqc->ct == 0) { - mqc_byteout(mqc); - } - } while ((mqc->a & 0x8000) == 0); -} - -static void mqc_codemps(opj_mqc_t *mqc) { - mqc->a -= (*mqc->curctx)->qeval; - if ((mqc->a & 0x8000) == 0) { - if (mqc->a < (*mqc->curctx)->qeval) { - mqc->a = (*mqc->curctx)->qeval; - } else { - mqc->c += (*mqc->curctx)->qeval; - } - *mqc->curctx = (*mqc->curctx)->nmps; - mqc_renorme(mqc); - } else { - mqc->c += (*mqc->curctx)->qeval; - } -} - -static void mqc_codelps(opj_mqc_t *mqc) { - mqc->a -= (*mqc->curctx)->qeval; - if (mqc->a < (*mqc->curctx)->qeval) { - mqc->c += (*mqc->curctx)->qeval; - } else { - mqc->a = (*mqc->curctx)->qeval; - } - *mqc->curctx = (*mqc->curctx)->nlps; - mqc_renorme(mqc); -} - -static void mqc_setbits(opj_mqc_t *mqc) { - unsigned int tempc = mqc->c + mqc->a; - mqc->c |= 0xffff; - if (mqc->c >= tempc) { - mqc->c -= 0x8000; - } -} - -static int mqc_mpsexchange(opj_mqc_t *mqc) { - int d; - if (mqc->a < (*mqc->curctx)->qeval) { - d = 1 - (*mqc->curctx)->mps; - *mqc->curctx = (*mqc->curctx)->nlps; - } else { - d = (*mqc->curctx)->mps; - *mqc->curctx = (*mqc->curctx)->nmps; - } - - return d; -} - -static int mqc_lpsexchange(opj_mqc_t *mqc) { - int d; - if (mqc->a < (*mqc->curctx)->qeval) { - mqc->a = (*mqc->curctx)->qeval; - d = (*mqc->curctx)->mps; - *mqc->curctx = (*mqc->curctx)->nmps; - } else { - mqc->a = (*mqc->curctx)->qeval; - d = 1 - (*mqc->curctx)->mps; - *mqc->curctx = (*mqc->curctx)->nlps; - } - - return d; -} - -static void mqc_bytein(opj_mqc_t *mqc) { - if (mqc->bp != mqc->end) { - unsigned int c; - if (mqc->bp + 1 != mqc->end) { - c = *(mqc->bp + 1); - } else { - c = 0xff; - } - if (*mqc->bp == 0xff) { - if (c > 0x8f) { - mqc->c += 0xff00; - mqc->ct = 8; - } else { - mqc->bp++; - mqc->c += c << 9; - mqc->ct = 7; - } - } else { - mqc->bp++; - mqc->c += c << 8; - mqc->ct = 8; - } - } else { - mqc->c += 0xff00; - mqc->ct = 8; - } -} - -static void mqc_renormd(opj_mqc_t *mqc) { - do { - if (mqc->ct == 0) { - mqc_bytein(mqc); - } - mqc->a <<= 1; - mqc->c <<= 1; - mqc->ct--; - } while (mqc->a < 0x8000); -} - -/* -========================================================== - MQ-Coder interface -========================================================== -*/ - -opj_mqc_t* mqc_create() { - opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t)); - return mqc; -} - -void mqc_destroy(opj_mqc_t *mqc) { - if(mqc) { - opj_free(mqc); - } -} - -int mqc_numbytes(opj_mqc_t *mqc) { - return mqc->bp - mqc->start; -} - -void mqc_init_enc(opj_mqc_t *mqc, unsigned char *bp) { - mqc_setcurctx(mqc, 0); - mqc->a = 0x8000; - mqc->c = 0; - mqc->bp = bp - 1; - mqc->ct = 12; - if (*mqc->bp == 0xff) { - mqc->ct = 13; - } - mqc->start = bp; -} - -void mqc_setcurctx(opj_mqc_t *mqc, int ctxno) { - mqc->curctx = &mqc->ctxs[ctxno]; -} - -void mqc_encode(opj_mqc_t *mqc, int d) { - if ((*mqc->curctx)->mps == d) { - mqc_codemps(mqc); - } else { - mqc_codelps(mqc); - } -} - -void mqc_flush(opj_mqc_t *mqc) { - mqc_setbits(mqc); - mqc->c <<= mqc->ct; - mqc_byteout(mqc); - mqc->c <<= mqc->ct; - mqc_byteout(mqc); - - if (*mqc->bp != 0xff) { - mqc->bp++; - } -} - -void mqc_bypass_init_enc(opj_mqc_t *mqc) { - mqc->c = 0; - mqc->ct = 8; - /*if (*mqc->bp == 0xff) { - mqc->ct = 7; - } */ -} - -void mqc_bypass_enc(opj_mqc_t *mqc, int d) { - mqc->ct--; - mqc->c = mqc->c + (d << mqc->ct); - if (mqc->ct == 0) { - mqc->bp++; - *mqc->bp = mqc->c; - mqc->ct = 8; - if (*mqc->bp == 0xff) { - mqc->ct = 7; - } - mqc->c = 0; - } -} - -int mqc_bypass_flush_enc(opj_mqc_t *mqc) { - unsigned char bit_padding; - - bit_padding = 0; - - if (mqc->ct != 0) { - while (mqc->ct > 0) { - mqc->ct--; - mqc->c += bit_padding << mqc->ct; - bit_padding = (bit_padding + 1) & 0x01; - } - mqc->bp++; - *mqc->bp = mqc->c; - mqc->ct = 8; - mqc->c = 0; - } - - return 1; -} - -void mqc_reset_enc(opj_mqc_t *mqc) { - mqc_resetstates(mqc); - mqc_setstate(mqc, 18, 0, 46); - mqc_setstate(mqc, 0, 0, 3); - mqc_setstate(mqc, 1, 0, 4); -} - -void mqc_reset_enc_3(opj_mqc_t *mqc) { - mqc_resetstates(mqc); - mqc_setstate(mqc, T1_3D_CTXNO_UNI, 0, 46); - mqc_setstate(mqc, T1_3D_CTXNO_AGG, 0, 3); - mqc_setstate(mqc, T1_3D_CTXNO_ZC, 0, 4); -} - -int mqc_restart_enc(opj_mqc_t *mqc) { - int correction = 1; - - /* */ - int n = 27 - 15 - mqc->ct; - mqc->c <<= mqc->ct; - while (n > 0) { - mqc_byteout(mqc); - n -= mqc->ct; - mqc->c <<= mqc->ct; - } - mqc_byteout(mqc); - - return correction; -} - -void mqc_restart_init_enc(opj_mqc_t *mqc) { - /* */ - mqc_setcurctx(mqc, 0); - mqc->a = 0x8000; - mqc->c = 0; - mqc->ct = 12; - mqc->bp--; - if (*mqc->bp == 0xff) { - mqc->ct = 13; - } -} - -void mqc_erterm_enc(opj_mqc_t *mqc) { - int k = 11 - mqc->ct + 1; - - while (k > 0) { - mqc->c <<= mqc->ct; - mqc->ct = 0; - mqc_byteout(mqc); - k -= mqc->ct; - } - - if (*mqc->bp != 0xff) { - mqc_byteout(mqc); - } -} - -void mqc_segmark_enc(opj_mqc_t *mqc) { - int i; - mqc_setcurctx(mqc, 18); - - for (i = 1; i < 5; i++) { - mqc_encode(mqc, i % 2); - } -} - -void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len) { - mqc_setcurctx(mqc, 0); - mqc->start = bp; - mqc->end = bp + len; - mqc->bp = bp; - if (len==0) mqc->c = 0xff << 16; - else mqc->c = *mqc->bp << 16; - mqc_bytein(mqc); - mqc->c <<= 7; - mqc->ct -= 7; - mqc->a = 0x8000; -} - -int mqc_decode(opj_mqc_t *mqc) { - int d; - mqc->a -= (*mqc->curctx)->qeval; - if ((mqc->c >> 16) < (*mqc->curctx)->qeval) { - d = mqc_lpsexchange(mqc); - mqc_renormd(mqc); - } else { - mqc->c -= (*mqc->curctx)->qeval << 16; - if ((mqc->a & 0x8000) == 0) { - d = mqc_mpsexchange(mqc); - mqc_renormd(mqc); - } else { - d = (*mqc->curctx)->mps; - } - } - - return d; -} - -void mqc_resetstates(opj_mqc_t *mqc) { - int i; - for (i = 0; i < MQC_NUMCTXS; i++) { - mqc->ctxs[i] = mqc_states; - } -} - -void mqc_setstate(opj_mqc_t *mqc, int ctxno, int msb, int prob) { - mqc->ctxs[ctxno] = &mqc_states[msb + (prob << 1)]; -} - - +/* + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opj_includes.h" + +/** @defgroup MQC MQC - Implementation of an MQ-Coder */ +/*@{*/ + +/** @name Local static functions */ +/*@{*/ + +/** +Output a byte, doing bit-stuffing if necessary. +After a 0xff byte, the next byte must be smaller than 0x90. +@param mqc MQC handle +*/ +static void mqc_byteout(opj_mqc_t *mqc); +/** +Renormalize mqc->a and mqc->c while encoding, so that mqc->a stays between 0x8000 and 0x10000 +@param mqc MQC handle +*/ +static void mqc_renorme(opj_mqc_t *mqc); +/** +Encode the most probable symbol +@param mqc MQC handle +*/ +static void mqc_codemps(opj_mqc_t *mqc); +/** +Encode the most least symbol +@param mqc MQC handle +*/ +static void mqc_codelps(opj_mqc_t *mqc); +/** +Fill mqc->c with 1's for flushing +@param mqc MQC handle +*/ +static void mqc_setbits(opj_mqc_t *mqc); +/** +Exchange MPS with LPS +@param mqc MQC handle +@return +*/ +static int mqc_mpsexchange(opj_mqc_t *mqc); +/** +Exchange LPS with MPS +@param mqc MQC handle +@return +*/ +static int mqc_lpsexchange(opj_mqc_t *mqc); +/** +Input a byte +@param mqc MQC handle +*/ +static void mqc_bytein(opj_mqc_t *mqc); +/** +Renormalize mqc->a and mqc->c while decoding +@param mqc MQC handle +*/ +static void mqc_renormd(opj_mqc_t *mqc); + +/*@}*/ + +/*@}*/ + +/* */ +/* This array defines all the possible states for a context. */ +/* */ +static opj_mqc_state_t mqc_states[47 * 2] = { + {0x5601, 0, &mqc_states[2], &mqc_states[3]}, + {0x5601, 1, &mqc_states[3], &mqc_states[2]}, + {0x3401, 0, &mqc_states[4], &mqc_states[12]}, + {0x3401, 1, &mqc_states[5], &mqc_states[13]}, + {0x1801, 0, &mqc_states[6], &mqc_states[18]}, + {0x1801, 1, &mqc_states[7], &mqc_states[19]}, + {0x0ac1, 0, &mqc_states[8], &mqc_states[24]}, + {0x0ac1, 1, &mqc_states[9], &mqc_states[25]}, + {0x0521, 0, &mqc_states[10], &mqc_states[58]}, + {0x0521, 1, &mqc_states[11], &mqc_states[59]}, + {0x0221, 0, &mqc_states[76], &mqc_states[66]}, + {0x0221, 1, &mqc_states[77], &mqc_states[67]}, + {0x5601, 0, &mqc_states[14], &mqc_states[13]}, + {0x5601, 1, &mqc_states[15], &mqc_states[12]}, + {0x5401, 0, &mqc_states[16], &mqc_states[28]}, + {0x5401, 1, &mqc_states[17], &mqc_states[29]}, + {0x4801, 0, &mqc_states[18], &mqc_states[28]}, + {0x4801, 1, &mqc_states[19], &mqc_states[29]}, + {0x3801, 0, &mqc_states[20], &mqc_states[28]}, + {0x3801, 1, &mqc_states[21], &mqc_states[29]}, + {0x3001, 0, &mqc_states[22], &mqc_states[34]}, + {0x3001, 1, &mqc_states[23], &mqc_states[35]}, + {0x2401, 0, &mqc_states[24], &mqc_states[36]}, + {0x2401, 1, &mqc_states[25], &mqc_states[37]}, + {0x1c01, 0, &mqc_states[26], &mqc_states[40]}, + {0x1c01, 1, &mqc_states[27], &mqc_states[41]}, + {0x1601, 0, &mqc_states[58], &mqc_states[42]}, + {0x1601, 1, &mqc_states[59], &mqc_states[43]}, + {0x5601, 0, &mqc_states[30], &mqc_states[29]}, + {0x5601, 1, &mqc_states[31], &mqc_states[28]}, + {0x5401, 0, &mqc_states[32], &mqc_states[28]}, + {0x5401, 1, &mqc_states[33], &mqc_states[29]}, + {0x5101, 0, &mqc_states[34], &mqc_states[30]}, + {0x5101, 1, &mqc_states[35], &mqc_states[31]}, + {0x4801, 0, &mqc_states[36], &mqc_states[32]}, + {0x4801, 1, &mqc_states[37], &mqc_states[33]}, + {0x3801, 0, &mqc_states[38], &mqc_states[34]}, + {0x3801, 1, &mqc_states[39], &mqc_states[35]}, + {0x3401, 0, &mqc_states[40], &mqc_states[36]}, + {0x3401, 1, &mqc_states[41], &mqc_states[37]}, + {0x3001, 0, &mqc_states[42], &mqc_states[38]}, + {0x3001, 1, &mqc_states[43], &mqc_states[39]}, + {0x2801, 0, &mqc_states[44], &mqc_states[38]}, + {0x2801, 1, &mqc_states[45], &mqc_states[39]}, + {0x2401, 0, &mqc_states[46], &mqc_states[40]}, + {0x2401, 1, &mqc_states[47], &mqc_states[41]}, + {0x2201, 0, &mqc_states[48], &mqc_states[42]}, + {0x2201, 1, &mqc_states[49], &mqc_states[43]}, + {0x1c01, 0, &mqc_states[50], &mqc_states[44]}, + {0x1c01, 1, &mqc_states[51], &mqc_states[45]}, + {0x1801, 0, &mqc_states[52], &mqc_states[46]}, + {0x1801, 1, &mqc_states[53], &mqc_states[47]}, + {0x1601, 0, &mqc_states[54], &mqc_states[48]}, + {0x1601, 1, &mqc_states[55], &mqc_states[49]}, + {0x1401, 0, &mqc_states[56], &mqc_states[50]}, + {0x1401, 1, &mqc_states[57], &mqc_states[51]}, + {0x1201, 0, &mqc_states[58], &mqc_states[52]}, + {0x1201, 1, &mqc_states[59], &mqc_states[53]}, + {0x1101, 0, &mqc_states[60], &mqc_states[54]}, + {0x1101, 1, &mqc_states[61], &mqc_states[55]}, + {0x0ac1, 0, &mqc_states[62], &mqc_states[56]}, + {0x0ac1, 1, &mqc_states[63], &mqc_states[57]}, + {0x09c1, 0, &mqc_states[64], &mqc_states[58]}, + {0x09c1, 1, &mqc_states[65], &mqc_states[59]}, + {0x08a1, 0, &mqc_states[66], &mqc_states[60]}, + {0x08a1, 1, &mqc_states[67], &mqc_states[61]}, + {0x0521, 0, &mqc_states[68], &mqc_states[62]}, + {0x0521, 1, &mqc_states[69], &mqc_states[63]}, + {0x0441, 0, &mqc_states[70], &mqc_states[64]}, + {0x0441, 1, &mqc_states[71], &mqc_states[65]}, + {0x02a1, 0, &mqc_states[72], &mqc_states[66]}, + {0x02a1, 1, &mqc_states[73], &mqc_states[67]}, + {0x0221, 0, &mqc_states[74], &mqc_states[68]}, + {0x0221, 1, &mqc_states[75], &mqc_states[69]}, + {0x0141, 0, &mqc_states[76], &mqc_states[70]}, + {0x0141, 1, &mqc_states[77], &mqc_states[71]}, + {0x0111, 0, &mqc_states[78], &mqc_states[72]}, + {0x0111, 1, &mqc_states[79], &mqc_states[73]}, + {0x0085, 0, &mqc_states[80], &mqc_states[74]}, + {0x0085, 1, &mqc_states[81], &mqc_states[75]}, + {0x0049, 0, &mqc_states[82], &mqc_states[76]}, + {0x0049, 1, &mqc_states[83], &mqc_states[77]}, + {0x0025, 0, &mqc_states[84], &mqc_states[78]}, + {0x0025, 1, &mqc_states[85], &mqc_states[79]}, + {0x0015, 0, &mqc_states[86], &mqc_states[80]}, + {0x0015, 1, &mqc_states[87], &mqc_states[81]}, + {0x0009, 0, &mqc_states[88], &mqc_states[82]}, + {0x0009, 1, &mqc_states[89], &mqc_states[83]}, + {0x0005, 0, &mqc_states[90], &mqc_states[84]}, + {0x0005, 1, &mqc_states[91], &mqc_states[85]}, + {0x0001, 0, &mqc_states[90], &mqc_states[86]}, + {0x0001, 1, &mqc_states[91], &mqc_states[87]}, + {0x5601, 0, &mqc_states[92], &mqc_states[92]}, + {0x5601, 1, &mqc_states[93], &mqc_states[93]}, +}; + +/* +========================================================== + local functions +========================================================== +*/ + +static void mqc_byteout(opj_mqc_t *mqc) { + if (*mqc->bp == 0xff) { + mqc->bp++; + *mqc->bp = mqc->c >> 20; + mqc->c &= 0xfffff; + mqc->ct = 7; + } else { + if ((mqc->c & 0x8000000) == 0) { /* ((mqc->c&0x8000000)==0) CHANGE */ + mqc->bp++; + *mqc->bp = mqc->c >> 19; + mqc->c &= 0x7ffff; + mqc->ct = 8; + } else { + (*mqc->bp)++; + if (*mqc->bp == 0xff) { + mqc->c &= 0x7ffffff; + mqc->bp++; + *mqc->bp = mqc->c >> 20; + mqc->c &= 0xfffff; + mqc->ct = 7; + } else { + mqc->bp++; + *mqc->bp = mqc->c >> 19; + mqc->c &= 0x7ffff; + mqc->ct = 8; + } + } + } +} + +static void mqc_renorme(opj_mqc_t *mqc) { + do { + mqc->a <<= 1; + mqc->c <<= 1; + mqc->ct--; + if (mqc->ct == 0) { + mqc_byteout(mqc); + } + } while ((mqc->a & 0x8000) == 0); +} + +static void mqc_codemps(opj_mqc_t *mqc) { + mqc->a -= (*mqc->curctx)->qeval; + if ((mqc->a & 0x8000) == 0) { + if (mqc->a < (*mqc->curctx)->qeval) { + mqc->a = (*mqc->curctx)->qeval; + } else { + mqc->c += (*mqc->curctx)->qeval; + } + *mqc->curctx = (*mqc->curctx)->nmps; + mqc_renorme(mqc); + } else { + mqc->c += (*mqc->curctx)->qeval; + } +} + +static void mqc_codelps(opj_mqc_t *mqc) { + mqc->a -= (*mqc->curctx)->qeval; + if (mqc->a < (*mqc->curctx)->qeval) { + mqc->c += (*mqc->curctx)->qeval; + } else { + mqc->a = (*mqc->curctx)->qeval; + } + *mqc->curctx = (*mqc->curctx)->nlps; + mqc_renorme(mqc); +} + +static void mqc_setbits(opj_mqc_t *mqc) { + unsigned int tempc = mqc->c + mqc->a; + mqc->c |= 0xffff; + if (mqc->c >= tempc) { + mqc->c -= 0x8000; + } +} + +static int mqc_mpsexchange(opj_mqc_t *mqc) { + int d; + if (mqc->a < (*mqc->curctx)->qeval) { + d = 1 - (*mqc->curctx)->mps; + *mqc->curctx = (*mqc->curctx)->nlps; + } else { + d = (*mqc->curctx)->mps; + *mqc->curctx = (*mqc->curctx)->nmps; + } + + return d; +} + +static int mqc_lpsexchange(opj_mqc_t *mqc) { + int d; + if (mqc->a < (*mqc->curctx)->qeval) { + mqc->a = (*mqc->curctx)->qeval; + d = (*mqc->curctx)->mps; + *mqc->curctx = (*mqc->curctx)->nmps; + } else { + mqc->a = (*mqc->curctx)->qeval; + d = 1 - (*mqc->curctx)->mps; + *mqc->curctx = (*mqc->curctx)->nlps; + } + + return d; +} + +static void mqc_bytein(opj_mqc_t *mqc) { + if (mqc->bp != mqc->end) { + unsigned int c; + if (mqc->bp + 1 != mqc->end) { + c = *(mqc->bp + 1); + } else { + c = 0xff; + } + if (*mqc->bp == 0xff) { + if (c > 0x8f) { + mqc->c += 0xff00; + mqc->ct = 8; + } else { + mqc->bp++; + mqc->c += c << 9; + mqc->ct = 7; + } + } else { + mqc->bp++; + mqc->c += c << 8; + mqc->ct = 8; + } + } else { + mqc->c += 0xff00; + mqc->ct = 8; + } +} + +static void mqc_renormd(opj_mqc_t *mqc) { + do { + if (mqc->ct == 0) { + mqc_bytein(mqc); + } + mqc->a <<= 1; + mqc->c <<= 1; + mqc->ct--; + } while (mqc->a < 0x8000); +} + +/* +========================================================== + MQ-Coder interface +========================================================== +*/ + +opj_mqc_t* mqc_create() { + opj_mqc_t *mqc = (opj_mqc_t*)opj_malloc(sizeof(opj_mqc_t)); + return mqc; +} + +void mqc_destroy(opj_mqc_t *mqc) { + if(mqc) { + opj_free(mqc); + } +} + +int mqc_numbytes(opj_mqc_t *mqc) { + return mqc->bp - mqc->start; +} + +void mqc_init_enc(opj_mqc_t *mqc, unsigned char *bp) { + mqc_setcurctx(mqc, 0); + mqc->a = 0x8000; + mqc->c = 0; + mqc->bp = bp - 1; + mqc->ct = 12; + if (*mqc->bp == 0xff) { + mqc->ct = 13; + } + mqc->start = bp; +} + +void mqc_setcurctx(opj_mqc_t *mqc, int ctxno) { + mqc->curctx = &mqc->ctxs[ctxno]; +} + +void mqc_encode(opj_mqc_t *mqc, int d) { + if ((*mqc->curctx)->mps == d) { + mqc_codemps(mqc); + } else { + mqc_codelps(mqc); + } +} + +void mqc_flush(opj_mqc_t *mqc) { + mqc_setbits(mqc); + mqc->c <<= mqc->ct; + mqc_byteout(mqc); + mqc->c <<= mqc->ct; + mqc_byteout(mqc); + + if (*mqc->bp != 0xff) { + mqc->bp++; + } +} + +void mqc_bypass_init_enc(opj_mqc_t *mqc) { + mqc->c = 0; + mqc->ct = 8; + /*if (*mqc->bp == 0xff) { + mqc->ct = 7; + } */ +} + +void mqc_bypass_enc(opj_mqc_t *mqc, int d) { + mqc->ct--; + mqc->c = mqc->c + (d << mqc->ct); + if (mqc->ct == 0) { + mqc->bp++; + *mqc->bp = mqc->c; + mqc->ct = 8; + if (*mqc->bp == 0xff) { + mqc->ct = 7; + } + mqc->c = 0; + } +} + +int mqc_bypass_flush_enc(opj_mqc_t *mqc) { + unsigned char bit_padding; + + bit_padding = 0; + + if (mqc->ct != 0) { + while (mqc->ct > 0) { + mqc->ct--; + mqc->c += bit_padding << mqc->ct; + bit_padding = (bit_padding + 1) & 0x01; + } + mqc->bp++; + *mqc->bp = mqc->c; + mqc->ct = 8; + mqc->c = 0; + } + + return 1; +} + +void mqc_reset_enc(opj_mqc_t *mqc) { + mqc_resetstates(mqc); + mqc_setstate(mqc, 18, 0, 46); + mqc_setstate(mqc, 0, 0, 3); + mqc_setstate(mqc, 1, 0, 4); +} + +void mqc_reset_enc_3(opj_mqc_t *mqc) { + mqc_resetstates(mqc); + mqc_setstate(mqc, T1_3D_CTXNO_UNI, 0, 46); + mqc_setstate(mqc, T1_3D_CTXNO_AGG, 0, 3); + mqc_setstate(mqc, T1_3D_CTXNO_ZC, 0, 4); +} + +int mqc_restart_enc(opj_mqc_t *mqc) { + int correction = 1; + + /* */ + int n = 27 - 15 - mqc->ct; + mqc->c <<= mqc->ct; + while (n > 0) { + mqc_byteout(mqc); + n -= mqc->ct; + mqc->c <<= mqc->ct; + } + mqc_byteout(mqc); + + return correction; +} + +void mqc_restart_init_enc(opj_mqc_t *mqc) { + /* */ + mqc_setcurctx(mqc, 0); + mqc->a = 0x8000; + mqc->c = 0; + mqc->ct = 12; + mqc->bp--; + if (*mqc->bp == 0xff) { + mqc->ct = 13; + } +} + +void mqc_erterm_enc(opj_mqc_t *mqc) { + int k = 11 - mqc->ct + 1; + + while (k > 0) { + mqc->c <<= mqc->ct; + mqc->ct = 0; + mqc_byteout(mqc); + k -= mqc->ct; + } + + if (*mqc->bp != 0xff) { + mqc_byteout(mqc); + } +} + +void mqc_segmark_enc(opj_mqc_t *mqc) { + int i; + mqc_setcurctx(mqc, 18); + + for (i = 1; i < 5; i++) { + mqc_encode(mqc, i % 2); + } +} + +void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len) { + mqc_setcurctx(mqc, 0); + mqc->start = bp; + mqc->end = bp + len; + mqc->bp = bp; + if (len==0) mqc->c = 0xff << 16; + else mqc->c = *mqc->bp << 16; + mqc_bytein(mqc); + mqc->c <<= 7; + mqc->ct -= 7; + mqc->a = 0x8000; +} + +int mqc_decode(opj_mqc_t *mqc) { + int d; + mqc->a -= (*mqc->curctx)->qeval; + if ((mqc->c >> 16) < (*mqc->curctx)->qeval) { + d = mqc_lpsexchange(mqc); + mqc_renormd(mqc); + } else { + mqc->c -= (*mqc->curctx)->qeval << 16; + if ((mqc->a & 0x8000) == 0) { + d = mqc_mpsexchange(mqc); + mqc_renormd(mqc); + } else { + d = (*mqc->curctx)->mps; + } + } + + return d; +} + +void mqc_resetstates(opj_mqc_t *mqc) { + int i; + for (i = 0; i < MQC_NUMCTXS; i++) { + mqc->ctxs[i] = mqc_states; + } +} + +void mqc_setstate(opj_mqc_t *mqc, int ctxno, int msb, int prob) { + mqc->ctxs[ctxno] = &mqc_states[msb + (prob << 1)]; +} + + diff --git a/src/lib/openjp3d/mqc.h b/src/lib/openjp3d/mqc.h index 023bf415..57bfc9f8 100644 --- a/src/lib/openjp3d/mqc.h +++ b/src/lib/openjp3d/mqc.h @@ -1,201 +1,201 @@ -/* - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __MQC_H -#define __MQC_H -/** -@file mqc.h -@brief Implementation of an MQ-Coder (MQC) - -The functions in MQC.C have for goal to realize the MQ-coder operations. The functions -in MQC.C are used by some function in T1.C. -*/ - -/** @defgroup MQC MQC - Implementation of an MQ-Coder */ -/*@{*/ - -/** -This struct defines the state of a context. -*/ -typedef struct opj_mqc_state { - /** the probability of the Least Probable Symbol (0.75->0x8000, 1.5->0xffff) */ - unsigned int qeval; - /** the Most Probable Symbol (0 or 1) */ - int mps; - /** next state if the next encoded symbol is the MPS */ - struct opj_mqc_state *nmps; - /** next state if the next encoded symbol is the LPS */ - struct opj_mqc_state *nlps; -} opj_mqc_state_t; - -#define MQC_NUMCTXS 32 - -/** -MQ coder -*/ -typedef struct opj_mqc { - unsigned int c; - unsigned int a; - unsigned int ct; - unsigned char *bp; - unsigned char *start; - unsigned char *end; - opj_mqc_state_t *ctxs[MQC_NUMCTXS]; - opj_mqc_state_t **curctx; -} opj_mqc_t; - -/** @name Exported functions */ -/*@{*/ -/* ----------------------------------------------------------------------- */ -/** -Create a new MQC handle -@return Returns a new MQC handle if successful, returns NULL otherwise -*/ -opj_mqc_t* mqc_create(void); -/** -Destroy a previously created MQC handle -@param mqc MQC handle to destroy -*/ -void mqc_destroy(opj_mqc_t *mqc); -/** -Return the number of bytes written/read since initialisation -@param mqc MQC handle -@return Returns the number of bytes already encoded -*/ -int mqc_numbytes(opj_mqc_t *mqc); -/** -Reset the states of all the context of the coder/decoder -(each context is set to a state where 0 and 1 are more or less equiprobable) -@param mqc MQC handle -*/ -void mqc_resetstates(opj_mqc_t *mqc); -/** -Set the state of a particular context -@param mqc MQC handle -@param ctxno Number that identifies the context -@param msb The MSB of the new state of the context -@param prob Number that identifies the probability of the symbols for the new state of the context -*/ -void mqc_setstate(opj_mqc_t *mqc, int ctxno, int msb, int prob); -/** -Initialize the encoder -@param mqc MQC handle -@param bp Pointer to the start of the buffer where the bytes will be written -*/ -void mqc_init_enc(opj_mqc_t *mqc, unsigned char *bp); -/** -Set the current context used for coding/decoding -@param mqc MQC handle -@param ctxno Number that identifies the context -*/ -void mqc_setcurctx(opj_mqc_t *mqc, int ctxno); -/** -Encode a symbol using the MQ-coder -@param mqc MQC handle -@param d The symbol to be encoded (0 or 1) -*/ -void mqc_encode(opj_mqc_t *mqc, int d); -/** -Flush the encoder, so that all remaining data is written -@param mqc MQC handle -*/ -void mqc_flush(opj_mqc_t *mqc); -/** -BYPASS mode switch, initialization operation. -JPEG 2000 p 505. -

Not fully implemented and tested !!

-@param mqc MQC handle -*/ -void mqc_bypass_init_enc(opj_mqc_t *mqc); -/** -BYPASS mode switch, coding operation. -JPEG 2000 p 505. -

Not fully implemented and tested !!

-@param mqc MQC handle -@param d The symbol to be encoded (0 or 1) -*/ -void mqc_bypass_enc(opj_mqc_t *mqc, int d); -/** -BYPASS mode switch, flush operation -

Not fully implemented and tested !!

-@param mqc MQC handle -@return Returns 1 (always) -*/ -int mqc_bypass_flush_enc(opj_mqc_t *mqc); -/** -RESET mode switch -@param mqc MQC handle -*/ -void mqc_reset_enc(opj_mqc_t *mqc); -/** -RESET mode switch -@param mqc MQC handle -*/ -void mqc_reset_enc_3(opj_mqc_t *mqc); -/** -RESTART mode switch (TERMALL) -@param mqc MQC handle -@return Returns 1 (always) -*/ -int mqc_restart_enc(opj_mqc_t *mqc); -/** -RESTART mode switch (TERMALL) reinitialisation -@param mqc MQC handle -*/ -void mqc_restart_init_enc(opj_mqc_t *mqc); -/** -ERTERM mode switch (PTERM) -@param mqc MQC handle -*/ -void mqc_erterm_enc(opj_mqc_t *mqc); -/** -SEGMARK mode switch (SEGSYM) -@param mqc MQC handle -*/ -void mqc_segmark_enc(opj_mqc_t *mqc); -/** -Initialize the decoder -@param mqc MQC handle -@param bp Pointer to the start of the buffer from which the bytes will be read -@param len Length of the input buffer -*/ -void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len); -/** -Decode a symbol -@param mqc MQC handle -@return Returns the decoded symbol (0 or 1) -*/ -int mqc_decode(opj_mqc_t *mqc); -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __MQC_H */ +/* + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __MQC_H +#define __MQC_H +/** +@file mqc.h +@brief Implementation of an MQ-Coder (MQC) + +The functions in MQC.C have for goal to realize the MQ-coder operations. The functions +in MQC.C are used by some function in T1.C. +*/ + +/** @defgroup MQC MQC - Implementation of an MQ-Coder */ +/*@{*/ + +/** +This struct defines the state of a context. +*/ +typedef struct opj_mqc_state { + /** the probability of the Least Probable Symbol (0.75->0x8000, 1.5->0xffff) */ + unsigned int qeval; + /** the Most Probable Symbol (0 or 1) */ + int mps; + /** next state if the next encoded symbol is the MPS */ + struct opj_mqc_state *nmps; + /** next state if the next encoded symbol is the LPS */ + struct opj_mqc_state *nlps; +} opj_mqc_state_t; + +#define MQC_NUMCTXS 32 + +/** +MQ coder +*/ +typedef struct opj_mqc { + unsigned int c; + unsigned int a; + unsigned int ct; + unsigned char *bp; + unsigned char *start; + unsigned char *end; + opj_mqc_state_t *ctxs[MQC_NUMCTXS]; + opj_mqc_state_t **curctx; +} opj_mqc_t; + +/** @name Exported functions */ +/*@{*/ +/* ----------------------------------------------------------------------- */ +/** +Create a new MQC handle +@return Returns a new MQC handle if successful, returns NULL otherwise +*/ +opj_mqc_t* mqc_create(void); +/** +Destroy a previously created MQC handle +@param mqc MQC handle to destroy +*/ +void mqc_destroy(opj_mqc_t *mqc); +/** +Return the number of bytes written/read since initialisation +@param mqc MQC handle +@return Returns the number of bytes already encoded +*/ +int mqc_numbytes(opj_mqc_t *mqc); +/** +Reset the states of all the context of the coder/decoder +(each context is set to a state where 0 and 1 are more or less equiprobable) +@param mqc MQC handle +*/ +void mqc_resetstates(opj_mqc_t *mqc); +/** +Set the state of a particular context +@param mqc MQC handle +@param ctxno Number that identifies the context +@param msb The MSB of the new state of the context +@param prob Number that identifies the probability of the symbols for the new state of the context +*/ +void mqc_setstate(opj_mqc_t *mqc, int ctxno, int msb, int prob); +/** +Initialize the encoder +@param mqc MQC handle +@param bp Pointer to the start of the buffer where the bytes will be written +*/ +void mqc_init_enc(opj_mqc_t *mqc, unsigned char *bp); +/** +Set the current context used for coding/decoding +@param mqc MQC handle +@param ctxno Number that identifies the context +*/ +void mqc_setcurctx(opj_mqc_t *mqc, int ctxno); +/** +Encode a symbol using the MQ-coder +@param mqc MQC handle +@param d The symbol to be encoded (0 or 1) +*/ +void mqc_encode(opj_mqc_t *mqc, int d); +/** +Flush the encoder, so that all remaining data is written +@param mqc MQC handle +*/ +void mqc_flush(opj_mqc_t *mqc); +/** +BYPASS mode switch, initialization operation. +JPEG 2000 p 505. +

Not fully implemented and tested !!

+@param mqc MQC handle +*/ +void mqc_bypass_init_enc(opj_mqc_t *mqc); +/** +BYPASS mode switch, coding operation. +JPEG 2000 p 505. +

Not fully implemented and tested !!

+@param mqc MQC handle +@param d The symbol to be encoded (0 or 1) +*/ +void mqc_bypass_enc(opj_mqc_t *mqc, int d); +/** +BYPASS mode switch, flush operation +

Not fully implemented and tested !!

+@param mqc MQC handle +@return Returns 1 (always) +*/ +int mqc_bypass_flush_enc(opj_mqc_t *mqc); +/** +RESET mode switch +@param mqc MQC handle +*/ +void mqc_reset_enc(opj_mqc_t *mqc); +/** +RESET mode switch +@param mqc MQC handle +*/ +void mqc_reset_enc_3(opj_mqc_t *mqc); +/** +RESTART mode switch (TERMALL) +@param mqc MQC handle +@return Returns 1 (always) +*/ +int mqc_restart_enc(opj_mqc_t *mqc); +/** +RESTART mode switch (TERMALL) reinitialisation +@param mqc MQC handle +*/ +void mqc_restart_init_enc(opj_mqc_t *mqc); +/** +ERTERM mode switch (PTERM) +@param mqc MQC handle +*/ +void mqc_erterm_enc(opj_mqc_t *mqc); +/** +SEGMARK mode switch (SEGSYM) +@param mqc MQC handle +*/ +void mqc_segmark_enc(opj_mqc_t *mqc); +/** +Initialize the decoder +@param mqc MQC handle +@param bp Pointer to the start of the buffer from which the bytes will be read +@param len Length of the input buffer +*/ +void mqc_init_dec(opj_mqc_t *mqc, unsigned char *bp, int len); +/** +Decode a symbol +@param mqc MQC handle +@return Returns the decoded symbol (0 or 1) +*/ +int mqc_decode(opj_mqc_t *mqc); +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __MQC_H */ diff --git a/src/lib/openjp3d/openjp3d.c b/src/lib/openjp3d/openjp3d.c index c1f3c44f..7adfbea0 100644 --- a/src/lib/openjp3d/openjp3d.c +++ b/src/lib/openjp3d/openjp3d.c @@ -1,208 +1,208 @@ -/* - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifdef _WIN32 -#include -#endif /* _WIN32 */ - -#include "opj_includes.h" -#include "openjp3d.h" -#define JP3D_VERSION "1.3.0" -/* ---------------------------------------------------------------------- */ -#ifdef _WIN32 -#ifndef OPJ_STATIC -BOOL APIENTRY -DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { - switch (ul_reason_for_call) { - case DLL_PROCESS_ATTACH : - break; - case DLL_PROCESS_DETACH : - break; - case DLL_THREAD_ATTACH : - case DLL_THREAD_DETACH : - break; - } - - return TRUE; -} -#endif /* OPJ_STATIC */ -#endif /* _WIN32 */ - -/* ---------------------------------------------------------------------- */ - -const char* OPJ_CALLCONV opj_version() { - return JP3D_VERSION; -} -opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) { - opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_malloc(sizeof(opj_dinfo_t)); - if(!dinfo) return NULL; - dinfo->is_decompressor = true; - switch(format) { - case CODEC_J3D: - case CODEC_J2K: - /* get a J3D decoder handle */ - dinfo->j3d_handle = (void*)j3d_create_decompress((opj_common_ptr)dinfo); - if(!dinfo->j3d_handle) { - opj_free(dinfo); - return NULL; - } - break; - default: - opj_free(dinfo); - return NULL; - } - - dinfo->codec_format = format; - - return dinfo; -} - -void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo) { - if(dinfo) { - /* destroy the codec */ - if(dinfo->codec_format != CODEC_UNKNOWN) { - j3d_destroy_decompress((opj_j3d_t*)dinfo->j3d_handle); - } - /* destroy the decompressor */ - opj_free(dinfo); - } -} - -void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters) { - if(parameters) { - memset(parameters, 0, sizeof(opj_dparameters_t)); - /* default decoding parameters */ - parameters->cp_layer = 0; - parameters->cp_reduce[0] = 0; - parameters->cp_reduce[1] = 0; - parameters->cp_reduce[2] = 0; - parameters->bigendian = 0; - - parameters->decod_format = -1; - parameters->cod_format = -1; - } -} - -void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters) { - if(dinfo && parameters) { - if (dinfo->codec_format != CODEC_UNKNOWN) { - j3d_setup_decoder((opj_j3d_t*)dinfo->j3d_handle, parameters); - } - } -} - -opj_volume_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) { - if(dinfo && cio) { - if (dinfo->codec_format != CODEC_UNKNOWN) { - return j3d_decode((opj_j3d_t*)dinfo->j3d_handle, cio); - } - } - - return NULL; -} - -opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format) { - opj_cinfo_t *cinfo = (opj_cinfo_t*)opj_malloc(sizeof(opj_cinfo_t)); - if(!cinfo) return NULL; - cinfo->is_decompressor = false; - switch(format) { - case CODEC_J3D: - case CODEC_J2K: - /* get a J3D coder handle */ - cinfo->j3d_handle = (void*)j3d_create_compress((opj_common_ptr)cinfo); - if(!cinfo->j3d_handle) { - opj_free(cinfo); - return NULL; - } - break; - default: - opj_free(cinfo); - return NULL; - } - - cinfo->codec_format = format; - - return cinfo; -} - -void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo) { - if(cinfo) { - /* destroy the codec */ - if (cinfo->codec_format != CODEC_UNKNOWN) { - j3d_destroy_compress((opj_j3d_t*)cinfo->j3d_handle); - } - /* destroy the decompressor */ - opj_free(cinfo); - } -} - -void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters) { - if(parameters) { - memset(parameters, 0, sizeof(opj_cparameters_t)); - /* default coding parameters */ - parameters->numresolution[0] = 3; - parameters->numresolution[1] = 3; - parameters->numresolution[2] = 1; - parameters->cblock_init[0] = 64; - parameters->cblock_init[1] = 64; - parameters->cblock_init[2] = 64; - parameters->prog_order = LRCP; - parameters->roi_compno = -1; /* no ROI */ - parameters->atk_wt[0] = 1; /* 5-3 WT */ - parameters->atk_wt[1] = 1; /* 5-3 WT */ - parameters->atk_wt[2] = 1; /* 5-3 WT */ - parameters->irreversible = 0; - parameters->subsampling_dx = 1; - parameters->subsampling_dy = 1; - parameters->subsampling_dz = 1; - - parameters->decod_format = -1; - parameters->cod_format = -1; - parameters->encoding_format = ENCOD_2EB; - parameters->transform_format = TRF_2D_DWT; - } -} - -void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_volume_t *volume) { - if(cinfo && parameters && volume) { - if (cinfo->codec_format != CODEC_UNKNOWN) { - j3d_setup_encoder((opj_j3d_t*)cinfo->j3d_handle, parameters, volume); - } - } -} - -bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_volume_t *volume, char *index) { - if(cinfo && cio && volume) { - if (cinfo->codec_format != CODEC_UNKNOWN) { - return j3d_encode((opj_j3d_t*)cinfo->j3d_handle, cio, volume, index); - } - } - - return false; -} - - +/* + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifdef _WIN32 +#include +#endif /* _WIN32 */ + +#include "opj_includes.h" +#include "openjp3d.h" +#define JP3D_VERSION "1.3.0" +/* ---------------------------------------------------------------------- */ +#ifdef _WIN32 +#ifndef OPJ_STATIC +BOOL APIENTRY +DllMain(HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved) { + switch (ul_reason_for_call) { + case DLL_PROCESS_ATTACH : + break; + case DLL_PROCESS_DETACH : + break; + case DLL_THREAD_ATTACH : + case DLL_THREAD_DETACH : + break; + } + + return TRUE; +} +#endif /* OPJ_STATIC */ +#endif /* _WIN32 */ + +/* ---------------------------------------------------------------------- */ + +const char* OPJ_CALLCONV opj_version() { + return JP3D_VERSION; +} +opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) { + opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_malloc(sizeof(opj_dinfo_t)); + if(!dinfo) return NULL; + dinfo->is_decompressor = true; + switch(format) { + case CODEC_J3D: + case CODEC_J2K: + /* get a J3D decoder handle */ + dinfo->j3d_handle = (void*)j3d_create_decompress((opj_common_ptr)dinfo); + if(!dinfo->j3d_handle) { + opj_free(dinfo); + return NULL; + } + break; + default: + opj_free(dinfo); + return NULL; + } + + dinfo->codec_format = format; + + return dinfo; +} + +void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo) { + if(dinfo) { + /* destroy the codec */ + if(dinfo->codec_format != CODEC_UNKNOWN) { + j3d_destroy_decompress((opj_j3d_t*)dinfo->j3d_handle); + } + /* destroy the decompressor */ + opj_free(dinfo); + } +} + +void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters) { + if(parameters) { + memset(parameters, 0, sizeof(opj_dparameters_t)); + /* default decoding parameters */ + parameters->cp_layer = 0; + parameters->cp_reduce[0] = 0; + parameters->cp_reduce[1] = 0; + parameters->cp_reduce[2] = 0; + parameters->bigendian = 0; + + parameters->decod_format = -1; + parameters->cod_format = -1; + } +} + +void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters) { + if(dinfo && parameters) { + if (dinfo->codec_format != CODEC_UNKNOWN) { + j3d_setup_decoder((opj_j3d_t*)dinfo->j3d_handle, parameters); + } + } +} + +opj_volume_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) { + if(dinfo && cio) { + if (dinfo->codec_format != CODEC_UNKNOWN) { + return j3d_decode((opj_j3d_t*)dinfo->j3d_handle, cio); + } + } + + return NULL; +} + +opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format) { + opj_cinfo_t *cinfo = (opj_cinfo_t*)opj_malloc(sizeof(opj_cinfo_t)); + if(!cinfo) return NULL; + cinfo->is_decompressor = false; + switch(format) { + case CODEC_J3D: + case CODEC_J2K: + /* get a J3D coder handle */ + cinfo->j3d_handle = (void*)j3d_create_compress((opj_common_ptr)cinfo); + if(!cinfo->j3d_handle) { + opj_free(cinfo); + return NULL; + } + break; + default: + opj_free(cinfo); + return NULL; + } + + cinfo->codec_format = format; + + return cinfo; +} + +void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo) { + if(cinfo) { + /* destroy the codec */ + if (cinfo->codec_format != CODEC_UNKNOWN) { + j3d_destroy_compress((opj_j3d_t*)cinfo->j3d_handle); + } + /* destroy the decompressor */ + opj_free(cinfo); + } +} + +void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters) { + if(parameters) { + memset(parameters, 0, sizeof(opj_cparameters_t)); + /* default coding parameters */ + parameters->numresolution[0] = 3; + parameters->numresolution[1] = 3; + parameters->numresolution[2] = 1; + parameters->cblock_init[0] = 64; + parameters->cblock_init[1] = 64; + parameters->cblock_init[2] = 64; + parameters->prog_order = LRCP; + parameters->roi_compno = -1; /* no ROI */ + parameters->atk_wt[0] = 1; /* 5-3 WT */ + parameters->atk_wt[1] = 1; /* 5-3 WT */ + parameters->atk_wt[2] = 1; /* 5-3 WT */ + parameters->irreversible = 0; + parameters->subsampling_dx = 1; + parameters->subsampling_dy = 1; + parameters->subsampling_dz = 1; + + parameters->decod_format = -1; + parameters->cod_format = -1; + parameters->encoding_format = ENCOD_2EB; + parameters->transform_format = TRF_2D_DWT; + } +} + +void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_volume_t *volume) { + if(cinfo && parameters && volume) { + if (cinfo->codec_format != CODEC_UNKNOWN) { + j3d_setup_encoder((opj_j3d_t*)cinfo->j3d_handle, parameters, volume); + } + } +} + +bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_volume_t *volume, char *index) { + if(cinfo && cio && volume) { + if (cinfo->codec_format != CODEC_UNKNOWN) { + return j3d_encode((opj_j3d_t*)cinfo->j3d_handle, cio, volume, index); + } + } + + return false; +} + + diff --git a/src/lib/openjp3d/openjp3d.h b/src/lib/openjp3d/openjp3d.h index 44fe1f70..3657f92b 100644 --- a/src/lib/openjp3d/openjp3d.h +++ b/src/lib/openjp3d/openjp3d.h @@ -1,721 +1,721 @@ -/* - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium - * Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef OPENJPEG_H -#define OPENJPEG_H - -/* -========================================================== - Compiler directives -========================================================== -*/ - -#if defined(OPJ_STATIC) || !defined(_WIN32) -/* http://gcc.gnu.org/wiki/Visibility */ -#if __GNUC__ >= 4 -#define OPJ_API __attribute__ ((visibility ("default"))) -#define OPJ_LOCAL __attribute__ ((visibility ("hidden"))) -#else -#define OPJ_API -#define OPJ_LOCAL -#endif -#define OPJ_CALLCONV -#else -#define OPJ_CALLCONV __stdcall - -/* -The following ifdef block is the standard way of creating macros which make exporting -from a DLL simpler. All files within this DLL are compiled with the OPJ_EXPORTS -symbol defined on the command line. this symbol should not be defined on any project -that uses this DLL. This way any other project whose source files include this file see -OPJ_API functions as being imported from a DLL, wheras this DLL sees symbols -defined with this macro as being exported. -*/ -#if defined(OPJ_EXPORTS) || defined(DLL_EXPORT) -#define OPJ_API __declspec(dllexport) -#else -#define OPJ_API __declspec(dllimport) -#endif /* OPJ_EXPORTS */ -#endif /* !OPJ_STATIC || !WIN32 */ - -#ifndef __cplusplus -#if defined(HAVE_STDBOOL_H) -/* -The C language implementation does correctly provide the standard header -file "stdbool.h". - */ -#include -#else -/* -The C language implementation does not provide the standard header file -"stdbool.h" as required by ISO/IEC 9899:1999. Try to compensate for this -braindamage below. -*/ -#if !defined(bool) -#define bool int -#endif -#if !defined(true) -#define true 1 -#endif -#if !defined(false) -#define false 0 -#endif -#endif -#endif /* __cplusplus */ - -/* -========================================================== - Useful constant definitions -========================================================== -*/ -#ifndef MAX_SLICES -#define MAX_SLICES 300 /**< Maximum allowed size for slices */ -#endif /* MAX_PATH */ - -#ifndef MAX_PATH -#define MAX_PATH 260 /**< Maximum allowed size for filenames */ -#endif /* MAX_PATH */ - -#define J3D_MAXRLVLS 32 /**< Number of maximum resolution level authorized */ -#define J3D_MAXBANDS (7*J3D_MAXRLVLS + 1) /**< Number of maximum sub-band linked to number of resolution level */ - -#define TINY 1.0E-20 -/* -========================================================== - enum definitions -========================================================== -*/ - -#define J2K_CFMT 0 -#define J3D_CFMT 1 -#define LSE_CFMT 2 - -#define BIN_DFMT 0 -#define PGX_DFMT 1 -#define IMG_DFMT 2 -/* ----------------------------------------------------------------------- */ - -/** Progression order */ -typedef enum PROG_ORDER { -/**< place-holder */ - PROG_UNKNOWN = -1, -/**< layer-resolution-component-precinct order */ - LRCP = 0, -/**< resolution-layer-component-precinct order */ - RLCP = 1, -/**< resolution-precinct-component-layer order */ - RPCL = 2, -/**< precinct-component-resolution-layer order */ - PCRL = 3, -/**< component-precinct-resolution-layer order */ - CPRL = 4 -} OPJ_PROG_ORDER; - -/** -Supported volume color spaces -*/ -typedef enum COLOR_SPACE { -/**< place-holder */ - CLRSPC_UNKNOWN = -1, -/**< sRGB */ - CLRSPC_SRGB = 1, -/**< grayscale */ - CLRSPC_GRAY = 2, -/**< YUV */ - CLRSPC_SYCC = 3 -} OPJ_COLOR_SPACE; - -/** -Supported codec -*/ -typedef enum CODEC_FORMAT { - /**< place-holder */ - CODEC_UNKNOWN = -1, -/**< JPEG-2000 codestream : read/write */ - CODEC_J2K = 0, -/**< JPEG-2000 Part 10 file format : read/write */ - CODEC_J3D = 1 -} OPJ_CODEC_FORMAT; - -/** -Supported entropy coding algorithms -*/ -typedef enum ENTROPY_CODING { -/**< place-holder */ - ENCOD_UNKNOWN = -1, -/**< 2D EBCOT encoding */ - ENCOD_2EB = 0, -/**< 3D EBCOT encoding */ - ENCOD_3EB = 1, -/**< Golomb-Rice coding with 2D context */ - ENCOD_2GR = 2, -/**< Golomb-Rice coding with 3D context */ - ENCOD_3GR = 3 -} OPJ_ENTROPY_CODING; - -/** -Supported transforms -*/ -typedef enum TRANSFORM { -/**< place-holder */ - TRF_UNKNOWN = -1, -/**< 2D DWT, no transform in axial dim */ - TRF_2D_DWT = 0, -/**< 3D DWT */ - TRF_3D_DWT = 1, -/**< 3D prediction*/ - TRF_3D_RLS = 2, - TRF_3D_LSE = 3 -} OPJ_TRANSFORM; -/* -========================================================== - event manager typedef definitions -========================================================== -*/ - -/** -Callback function prototype for events -@param msg Event message -@param client_data -*/ -typedef void (*opj_msg_callback) (const char *msg, void *client_data); - -/** -Message handler object -used for -
    -
  • Error messages -
  • Warning messages -
  • Debugging messages -
-*/ -typedef struct opj_event_mgr { - /** Error message callback if available, NULL otherwise */ - opj_msg_callback error_handler; - /** Warning message callback if available, NULL otherwise */ - opj_msg_callback warning_handler; - /** Debug message callback if available, NULL otherwise */ - opj_msg_callback info_handler; -} opj_event_mgr_t; - - -/* -========================================================== - codec typedef definitions -========================================================== -*/ - -/** -Progression order changes -*/ -typedef struct opj_poc { - int resno0, compno0; - int layno1, resno1, compno1; - OPJ_PROG_ORDER prg; - int tile; - char progorder[4]; -} opj_poc_t; - - -/** -Compression parameters -*/ -typedef struct opj_cparameters { -/** size of tile: tile_size_on = false (not in argument) or = true (in argument) */ - bool tile_size_on; -/** XTOsiz */ - int cp_tx0; -/** YTOsiz */ - int cp_ty0; -/** ZTOsiz */ - int cp_tz0; - -/** XTsiz */ - int cp_tdx; -/** YTsiz */ - int cp_tdy; -/** ZTsiz */ - int cp_tdz; - -/** allocation by rate/distortion */ - int cp_disto_alloc; -/** allocation by fixed layer */ - int cp_fixed_alloc; -/** add fixed_quality */ - int cp_fixed_quality; -/** fixed layer */ - int *cp_matrice; -/** number of layers */ - int tcp_numlayers; -/** rates for successive layers */ - float tcp_rates[100]; -/** psnr's for successive layers */ - float tcp_distoratio[100]; -/** comment for coding */ - char *cp_comment; -/** csty : coding style */ - int csty; -/** DC offset (DCO) */ - int dcoffset; -/** progression order (default LRCP) */ - OPJ_PROG_ORDER prog_order; -/** progression order changes */ - opj_poc_t POC[J3D_MAXRLVLS-1]; -/** number of progression order changes (POC), default to 0 */ - int numpocs; - -/** number of resolutions */ - int numresolution[3]; -/** initial code block width, height and depth, default to 64 */ - int cblock_init[3]; -/** mode switch (1=BYPASS(LAZY) 2=RESET 4=RESTART(TERMALL) 8=VSC 16=ERTERM(SEGTERM) 32=SEGMARK(SEGSYM)) */ - int mode; - -/** 1 : use the irreversible DWT 9-7, 0 : use lossless compression (default) */ - int irreversible; -/** WT from ATK, default to 0 (false), no of atk used */ - int atk_wt[3]; -/** region of interest: affected component in [0..3], -1 means no ROI */ - int roi_compno; -/** region of interest: upshift value */ - int roi_shift; - -/* number of precinct size specifications */ - int res_spec; -/** initial precinct width */ - int prct_init[3][J3D_MAXRLVLS]; - -/** transform format 0: 0: 2DWT, 1: 2D1P, 2: 3DWT, 3: 3RLS */ - OPJ_TRANSFORM transform_format; -/** output file format 0: 2EB, 1: 3EB, 2: 2GR, 3: 3GR, 4: GRI */ - OPJ_ENTROPY_CODING encoding_format; - - /**@name command line encoder parameters (not used inside the library) */ - /*@{*/ - char infile[MAX_PATH]; /** input file name */ - char outfile[MAX_PATH]; /** output file name */ - char imgfile[MAX_PATH]; /** IMG file name for BIN volumes*/ - int index_on; /** creation of an index file, default to 0 (false) */ - char index[MAX_PATH]; /** index file name */ - - int volume_offset_x0; /** subvolume encoding: origin volume offset in x, y and z direction */ - int volume_offset_y0; - int volume_offset_z0; - - int subsampling_dx; /** subsampling value for dx */ - int subsampling_dy; - int subsampling_dz; - - int decod_format; /** input file format 0: BIN, 1: PGX */ - int cod_format; /** output file format 0: JP3D */ - /*@}*/ -} opj_cparameters_t; - -/** -Decompression parameters -*/ -typedef struct opj_dparameters { -/** Set the number of highest resolution levels to be discarded. if != 0, then original dimension divided by 2^(reduce); if == 0 or not used, volume is decoded to the full resolution */ - int cp_reduce[3]; -/** Set the maximum number of quality layers to decode. if != 0, then only the first "layer" layers are decoded; if == 0 or not used, all the quality layers are decoded */ - int cp_layer; - int bigendian; - - /**@name command line encoder parameters (not used inside the library) */ - /*@{*/ -/** input file name */ - char infile[MAX_PATH]; -/** output file name */ - char outfile[MAX_PATH]; -/** IMG file name for BIN volumes*/ - char imgfile[MAX_PATH]; -/** Original file name for PSNR measures*/ - char original[MAX_PATH]; -/** input file format 0: J2K, 1: JP3D */ - int decod_format; -/** input file format 0: BIN, 1: PGM */ - int cod_format; -/** original file format 0: BIN, 1: PGM */ - int orig_format; - /*@}*/ -} opj_dparameters_t; - -/** Common fields between JPEG-2000 compression and decompression master structs. */ -#define opj_common_fields \ - opj_event_mgr_t *event_mgr; /**< pointer to the event manager */\ - void * client_data; /**< Available for use by application */\ - bool is_decompressor; /**< So common code can tell which is which */\ - OPJ_CODEC_FORMAT codec_format; /**< selected codec */\ - OPJ_ENTROPY_CODING encoding_format; /**< selected entropy coding */\ - OPJ_TRANSFORM transform_format; /**< selected transform */\ - void *j3d_handle /**< pointer to the J3D codec */ - -/* Routines that are to be used by both halves of the library are declared - * to receive a pointer to this structure. There are no actual instances of - * opj_common_struct_t, only of opj_cinfo_t and opj_dinfo_t. - */ -typedef struct opj_common_struct { - opj_common_fields; /* Fields common to both master struct types */ - /* Additional fields follow in an actual opj_cinfo_t or - * opj_dinfo_t. All three structs must agree on these - * initial fields! (This would be a lot cleaner in C++.) - */ -} opj_common_struct_t; - -typedef opj_common_struct_t * opj_common_ptr; - -/** -Compression context info -*/ -typedef struct opj_cinfo { - /** Fields shared with opj_dinfo_t */ - opj_common_fields; - /* other specific fields go here */ -} opj_cinfo_t; - -/** -Decompression context info -*/ -typedef struct opj_dinfo { - /** Fields shared with opj_cinfo_t */ - opj_common_fields; - /* other specific fields go here */ -} opj_dinfo_t; - -/* -========================================================== - I/O stream typedef definitions -========================================================== -*/ - -/* - * Stream open flags. - */ -/** The stream was opened for reading. */ -#define OPJ_STREAM_READ 0x0001 -/** The stream was opened for writing. */ -#define OPJ_STREAM_WRITE 0x0002 - -/** -Byte input-output stream (CIO) -*/ -typedef struct opj_cio { -/** codec context */ - opj_common_ptr cinfo; -/** open mode (read/write) either OPJ_STREAM_READ or OPJ_STREAM_WRITE */ - int openmode; -/** pointer to the start of the buffer */ - unsigned char *buffer; -/** buffer size in bytes */ - int length; -/** pointer to the start of the stream */ - unsigned char *start; -/** pointer to the end of the stream */ - unsigned char *end; -/** pointer to the current position */ - unsigned char *bp; -} opj_cio_t; - -/* -========================================================== - volume typedef definitions -========================================================== -*/ - -/** -Defines a single volume component -*/ -typedef struct opj_volume_comp { -/** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */ - int dx; -/** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */ - int dy; -/** ZRsiz: vertical separation of a sample of ith component with respect to the reference grid */ - int dz; -/** data width */ - int w; - /** data height */ - int h; - /** data length : no of slices */ - int l; - /** x component offset compared to the whole volume */ - int x0; - /** y component offset compared to the whole volume */ - int y0; - /** z component offset compared to the whole volume */ - int z0; - /** precision */ - int prec; - /** volume depth in bits */ - int bpp; - /** DC offset (15444-2) */ - int dcoffset; - /** signed (1) / unsigned (0) */ - int sgnd; - /** BE byte order (1) / LE byte order (0) */ - int bigendian; - /** number of decoded resolution */ - int resno_decoded[3]; - /** number of division by 2 of the out volume compared to the original size of volume */ - int factor[3]; - /** volume component data */ - int *data; -} opj_volume_comp_t; - -/** -Defines volume data and characteristics -*/ -typedef struct opj_volume { -/** XOsiz: horizontal offset from the origin of the reference grid to the left side of the volume area */ - int x0; -/** YOsiz: vertical offset from the origin of the reference grid to the top side of the volume area */ - int y0; -/** ZOsiz: vertical offset from the origin of the reference grid to the top side of the volume area */ - int z0; -/** Xsiz: width of the reference grid */ - int x1; -/** Ysiz: height of the reference grid */ - int y1; -/** Zsiz: length of the reference grid */ - int z1; -/** number of components in the volume */ - int numcomps; -/** number of slices in the volume */ - int numslices; -/** color space: sRGB, Greyscale or YUV */ - OPJ_COLOR_SPACE color_space; -/** volume components */ - opj_volume_comp_t *comps; -} opj_volume_t; - -/** -Component parameters structure used by the opj_volume_create function -*/ -typedef struct opj_volume_comptparm { - /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */ - int dx; - /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */ - int dy; - /** ZRsiz: axial separation of a sample of ith component with respect to the reference grid */ - int dz; - /** data width */ - int w; - /** data height */ - int h; - /** data length */ - int l; - /** x component offset compared to the whole volume */ - int x0; - /** y component offset compared to the whole volume */ - int y0; - /** z component offset compared to the whole volume */ - int z0; - /** precision */ - int prec; - /** volume depth in bits */ - int bpp; - /** signed (1) / unsigned (0) */ - int sgnd; - /** DC offset*/ - int dcoffset; - /** BE byte order (1) / LE byte order (0) */ - int bigendian; -} opj_volume_cmptparm_t; - -#ifdef __cplusplus -extern "C" { -#endif - - -/* -========================================================== - openjpeg version -========================================================== -*/ - -OPJ_API const char * OPJ_CALLCONV opj_version(void); - -/* -========================================================== - volume functions definitions -========================================================== -*/ - -/** -Create an volume -@param numcmpts number of components -@param cmptparms components parameters -@param clrspc volume color space -@return returns a new volume structure if successful, returns NULL otherwise -*/ -OPJ_API opj_volume_t* OPJ_CALLCONV opj_volume_create(int numcmpts, opj_volume_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc); - -/** -Deallocate any resources associated with an volume -@param volume volume to be destroyed -*/ -OPJ_API void OPJ_CALLCONV opj_volume_destroy(opj_volume_t *volume); - -/* -========================================================== - stream functions definitions -========================================================== -*/ - -/** -Open and allocate a memory stream for read / write. -On reading, the user must provide a buffer containing encoded data. The buffer will be -wrapped by the returned CIO handle. -On writing, buffer parameters must be set to 0: a buffer will be allocated by the library -to contain encoded data. -@param cinfo Codec context info -@param buffer Reading: buffer address. Writing: NULL -@param length Reading: buffer length. Writing: 0 -@return Returns a CIO handle if successful, returns NULL otherwise -*/ -OPJ_API opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length); - -/** -Close and free a CIO handle -@param cio CIO handle to free -*/ -OPJ_API void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio); - -/** -Get position in byte stream -@param cio CIO handle -@return Returns the position in bytes -*/ -OPJ_API int OPJ_CALLCONV cio_tell(opj_cio_t *cio); -/** -Set position in byte stream -@param cio CIO handle -@param pos Position, in number of bytes, from the beginning of the stream -*/ -OPJ_API void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos); - -/* -========================================================== - event manager functions definitions -========================================================== -*/ - -OPJ_API opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context); - -/* -========================================================== - codec functions definitions -========================================================== -*/ -/** -Creates a J3D decompression structure -@param format Decoder to select -@return Returns a handle to a decompressor if successful, returns NULL otherwise -*/ -OPJ_API opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format); -/** -Destroy a decompressor handle -@param dinfo decompressor handle to destroy -*/ -OPJ_API void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo); -/** -Set decoding parameters to default values -@param parameters Decompression parameters -*/ -OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters); -/** -Setup the decoder decoding parameters using user parameters. -Decoding parameters are returned in j3d->cp. -@param dinfo decompressor handle -@param parameters decompression parameters -*/ -OPJ_API void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters); -/** -Decode an volume from a JPEG-2000 codestream -@param dinfo decompressor handle -@param cio Input buffer stream -@return Returns a decoded volume if successful, returns NULL otherwise -*/ -OPJ_API opj_volume_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio); -/** -Creates a J3D/JP2 compression structure -@param format Coder to select -@return Returns a handle to a compressor if successful, returns NULL otherwise -*/ -OPJ_API opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format); -/** -Destroy a compressor handle -@param cinfo compressor handle to destroy -*/ -OPJ_API void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo); -/** -Set encoding parameters to default values, that means : -
    -
  • Lossless -
  • 1 tile -
  • Size of precinct : 2^15 x 2^15 (means 1 precinct) -
  • Size of code-block : 64 x 64 -
  • Number of resolutions: 6 -
  • No SOP marker in the codestream -
  • No EPH marker in the codestream -
  • No sub-sampling in x or y direction -
  • No mode switch activated -
  • Progression order: LRCP -
  • No index file -
  • No ROI upshifted -
  • No offset of the origin of the volume -
  • No offset of the origin of the tiles -
  • Reversible DWT 5-3 -
-@param parameters Compression parameters -*/ -OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters); -/** -Setup the encoder parameters using the current volume and using user parameters. -@param cinfo compressor handle -@param parameters compression parameters -@param volume input filled volume -*/ -OPJ_API void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_volume_t *volume); -/** -Encode an volume into a JPEG-2000 codestream -@param cinfo compressor handle -@param cio Output buffer stream -@param volume Volume to encode -@param index Name of the index file if required, NULL otherwise -@return Returns true if successful, returns false otherwise -*/ -OPJ_API bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_volume_t *volume, char *index); - -#ifdef __cplusplus -} -#endif - -#endif /* OPENJPEG_H */ +/* + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef OPENJPEG_H +#define OPENJPEG_H + +/* +========================================================== + Compiler directives +========================================================== +*/ + +#if defined(OPJ_STATIC) || !defined(_WIN32) +/* http://gcc.gnu.org/wiki/Visibility */ +#if __GNUC__ >= 4 +#define OPJ_API __attribute__ ((visibility ("default"))) +#define OPJ_LOCAL __attribute__ ((visibility ("hidden"))) +#else +#define OPJ_API +#define OPJ_LOCAL +#endif +#define OPJ_CALLCONV +#else +#define OPJ_CALLCONV __stdcall + +/* +The following ifdef block is the standard way of creating macros which make exporting +from a DLL simpler. All files within this DLL are compiled with the OPJ_EXPORTS +symbol defined on the command line. this symbol should not be defined on any project +that uses this DLL. This way any other project whose source files include this file see +OPJ_API functions as being imported from a DLL, wheras this DLL sees symbols +defined with this macro as being exported. +*/ +#if defined(OPJ_EXPORTS) || defined(DLL_EXPORT) +#define OPJ_API __declspec(dllexport) +#else +#define OPJ_API __declspec(dllimport) +#endif /* OPJ_EXPORTS */ +#endif /* !OPJ_STATIC || !WIN32 */ + +#ifndef __cplusplus +#if defined(HAVE_STDBOOL_H) +/* +The C language implementation does correctly provide the standard header +file "stdbool.h". + */ +#include +#else +/* +The C language implementation does not provide the standard header file +"stdbool.h" as required by ISO/IEC 9899:1999. Try to compensate for this +braindamage below. +*/ +#if !defined(bool) +#define bool int +#endif +#if !defined(true) +#define true 1 +#endif +#if !defined(false) +#define false 0 +#endif +#endif +#endif /* __cplusplus */ + +/* +========================================================== + Useful constant definitions +========================================================== +*/ +#ifndef MAX_SLICES +#define MAX_SLICES 300 /**< Maximum allowed size for slices */ +#endif /* MAX_PATH */ + +#ifndef MAX_PATH +#define MAX_PATH 260 /**< Maximum allowed size for filenames */ +#endif /* MAX_PATH */ + +#define J3D_MAXRLVLS 32 /**< Number of maximum resolution level authorized */ +#define J3D_MAXBANDS (7*J3D_MAXRLVLS + 1) /**< Number of maximum sub-band linked to number of resolution level */ + +#define TINY 1.0E-20 +/* +========================================================== + enum definitions +========================================================== +*/ + +#define J2K_CFMT 0 +#define J3D_CFMT 1 +#define LSE_CFMT 2 + +#define BIN_DFMT 0 +#define PGX_DFMT 1 +#define IMG_DFMT 2 +/* ----------------------------------------------------------------------- */ + +/** Progression order */ +typedef enum PROG_ORDER { +/**< place-holder */ + PROG_UNKNOWN = -1, +/**< layer-resolution-component-precinct order */ + LRCP = 0, +/**< resolution-layer-component-precinct order */ + RLCP = 1, +/**< resolution-precinct-component-layer order */ + RPCL = 2, +/**< precinct-component-resolution-layer order */ + PCRL = 3, +/**< component-precinct-resolution-layer order */ + CPRL = 4 +} OPJ_PROG_ORDER; + +/** +Supported volume color spaces +*/ +typedef enum COLOR_SPACE { +/**< place-holder */ + CLRSPC_UNKNOWN = -1, +/**< sRGB */ + CLRSPC_SRGB = 1, +/**< grayscale */ + CLRSPC_GRAY = 2, +/**< YUV */ + CLRSPC_SYCC = 3 +} OPJ_COLOR_SPACE; + +/** +Supported codec +*/ +typedef enum CODEC_FORMAT { + /**< place-holder */ + CODEC_UNKNOWN = -1, +/**< JPEG-2000 codestream : read/write */ + CODEC_J2K = 0, +/**< JPEG-2000 Part 10 file format : read/write */ + CODEC_J3D = 1 +} OPJ_CODEC_FORMAT; + +/** +Supported entropy coding algorithms +*/ +typedef enum ENTROPY_CODING { +/**< place-holder */ + ENCOD_UNKNOWN = -1, +/**< 2D EBCOT encoding */ + ENCOD_2EB = 0, +/**< 3D EBCOT encoding */ + ENCOD_3EB = 1, +/**< Golomb-Rice coding with 2D context */ + ENCOD_2GR = 2, +/**< Golomb-Rice coding with 3D context */ + ENCOD_3GR = 3 +} OPJ_ENTROPY_CODING; + +/** +Supported transforms +*/ +typedef enum TRANSFORM { +/**< place-holder */ + TRF_UNKNOWN = -1, +/**< 2D DWT, no transform in axial dim */ + TRF_2D_DWT = 0, +/**< 3D DWT */ + TRF_3D_DWT = 1, +/**< 3D prediction*/ + TRF_3D_RLS = 2, + TRF_3D_LSE = 3 +} OPJ_TRANSFORM; +/* +========================================================== + event manager typedef definitions +========================================================== +*/ + +/** +Callback function prototype for events +@param msg Event message +@param client_data +*/ +typedef void (*opj_msg_callback) (const char *msg, void *client_data); + +/** +Message handler object +used for +
    +
  • Error messages +
  • Warning messages +
  • Debugging messages +
+*/ +typedef struct opj_event_mgr { + /** Error message callback if available, NULL otherwise */ + opj_msg_callback error_handler; + /** Warning message callback if available, NULL otherwise */ + opj_msg_callback warning_handler; + /** Debug message callback if available, NULL otherwise */ + opj_msg_callback info_handler; +} opj_event_mgr_t; + + +/* +========================================================== + codec typedef definitions +========================================================== +*/ + +/** +Progression order changes +*/ +typedef struct opj_poc { + int resno0, compno0; + int layno1, resno1, compno1; + OPJ_PROG_ORDER prg; + int tile; + char progorder[4]; +} opj_poc_t; + + +/** +Compression parameters +*/ +typedef struct opj_cparameters { +/** size of tile: tile_size_on = false (not in argument) or = true (in argument) */ + bool tile_size_on; +/** XTOsiz */ + int cp_tx0; +/** YTOsiz */ + int cp_ty0; +/** ZTOsiz */ + int cp_tz0; + +/** XTsiz */ + int cp_tdx; +/** YTsiz */ + int cp_tdy; +/** ZTsiz */ + int cp_tdz; + +/** allocation by rate/distortion */ + int cp_disto_alloc; +/** allocation by fixed layer */ + int cp_fixed_alloc; +/** add fixed_quality */ + int cp_fixed_quality; +/** fixed layer */ + int *cp_matrice; +/** number of layers */ + int tcp_numlayers; +/** rates for successive layers */ + float tcp_rates[100]; +/** psnr's for successive layers */ + float tcp_distoratio[100]; +/** comment for coding */ + char *cp_comment; +/** csty : coding style */ + int csty; +/** DC offset (DCO) */ + int dcoffset; +/** progression order (default LRCP) */ + OPJ_PROG_ORDER prog_order; +/** progression order changes */ + opj_poc_t POC[J3D_MAXRLVLS-1]; +/** number of progression order changes (POC), default to 0 */ + int numpocs; + +/** number of resolutions */ + int numresolution[3]; +/** initial code block width, height and depth, default to 64 */ + int cblock_init[3]; +/** mode switch (1=BYPASS(LAZY) 2=RESET 4=RESTART(TERMALL) 8=VSC 16=ERTERM(SEGTERM) 32=SEGMARK(SEGSYM)) */ + int mode; + +/** 1 : use the irreversible DWT 9-7, 0 : use lossless compression (default) */ + int irreversible; +/** WT from ATK, default to 0 (false), no of atk used */ + int atk_wt[3]; +/** region of interest: affected component in [0..3], -1 means no ROI */ + int roi_compno; +/** region of interest: upshift value */ + int roi_shift; + +/* number of precinct size specifications */ + int res_spec; +/** initial precinct width */ + int prct_init[3][J3D_MAXRLVLS]; + +/** transform format 0: 0: 2DWT, 1: 2D1P, 2: 3DWT, 3: 3RLS */ + OPJ_TRANSFORM transform_format; +/** output file format 0: 2EB, 1: 3EB, 2: 2GR, 3: 3GR, 4: GRI */ + OPJ_ENTROPY_CODING encoding_format; + + /**@name command line encoder parameters (not used inside the library) */ + /*@{*/ + char infile[MAX_PATH]; /** input file name */ + char outfile[MAX_PATH]; /** output file name */ + char imgfile[MAX_PATH]; /** IMG file name for BIN volumes*/ + int index_on; /** creation of an index file, default to 0 (false) */ + char index[MAX_PATH]; /** index file name */ + + int volume_offset_x0; /** subvolume encoding: origin volume offset in x, y and z direction */ + int volume_offset_y0; + int volume_offset_z0; + + int subsampling_dx; /** subsampling value for dx */ + int subsampling_dy; + int subsampling_dz; + + int decod_format; /** input file format 0: BIN, 1: PGX */ + int cod_format; /** output file format 0: JP3D */ + /*@}*/ +} opj_cparameters_t; + +/** +Decompression parameters +*/ +typedef struct opj_dparameters { +/** Set the number of highest resolution levels to be discarded. if != 0, then original dimension divided by 2^(reduce); if == 0 or not used, volume is decoded to the full resolution */ + int cp_reduce[3]; +/** Set the maximum number of quality layers to decode. if != 0, then only the first "layer" layers are decoded; if == 0 or not used, all the quality layers are decoded */ + int cp_layer; + int bigendian; + + /**@name command line encoder parameters (not used inside the library) */ + /*@{*/ +/** input file name */ + char infile[MAX_PATH]; +/** output file name */ + char outfile[MAX_PATH]; +/** IMG file name for BIN volumes*/ + char imgfile[MAX_PATH]; +/** Original file name for PSNR measures*/ + char original[MAX_PATH]; +/** input file format 0: J2K, 1: JP3D */ + int decod_format; +/** input file format 0: BIN, 1: PGM */ + int cod_format; +/** original file format 0: BIN, 1: PGM */ + int orig_format; + /*@}*/ +} opj_dparameters_t; + +/** Common fields between JPEG-2000 compression and decompression master structs. */ +#define opj_common_fields \ + opj_event_mgr_t *event_mgr; /**< pointer to the event manager */\ + void * client_data; /**< Available for use by application */\ + bool is_decompressor; /**< So common code can tell which is which */\ + OPJ_CODEC_FORMAT codec_format; /**< selected codec */\ + OPJ_ENTROPY_CODING encoding_format; /**< selected entropy coding */\ + OPJ_TRANSFORM transform_format; /**< selected transform */\ + void *j3d_handle /**< pointer to the J3D codec */ + +/* Routines that are to be used by both halves of the library are declared + * to receive a pointer to this structure. There are no actual instances of + * opj_common_struct_t, only of opj_cinfo_t and opj_dinfo_t. + */ +typedef struct opj_common_struct { + opj_common_fields; /* Fields common to both master struct types */ + /* Additional fields follow in an actual opj_cinfo_t or + * opj_dinfo_t. All three structs must agree on these + * initial fields! (This would be a lot cleaner in C++.) + */ +} opj_common_struct_t; + +typedef opj_common_struct_t * opj_common_ptr; + +/** +Compression context info +*/ +typedef struct opj_cinfo { + /** Fields shared with opj_dinfo_t */ + opj_common_fields; + /* other specific fields go here */ +} opj_cinfo_t; + +/** +Decompression context info +*/ +typedef struct opj_dinfo { + /** Fields shared with opj_cinfo_t */ + opj_common_fields; + /* other specific fields go here */ +} opj_dinfo_t; + +/* +========================================================== + I/O stream typedef definitions +========================================================== +*/ + +/* + * Stream open flags. + */ +/** The stream was opened for reading. */ +#define OPJ_STREAM_READ 0x0001 +/** The stream was opened for writing. */ +#define OPJ_STREAM_WRITE 0x0002 + +/** +Byte input-output stream (CIO) +*/ +typedef struct opj_cio { +/** codec context */ + opj_common_ptr cinfo; +/** open mode (read/write) either OPJ_STREAM_READ or OPJ_STREAM_WRITE */ + int openmode; +/** pointer to the start of the buffer */ + unsigned char *buffer; +/** buffer size in bytes */ + int length; +/** pointer to the start of the stream */ + unsigned char *start; +/** pointer to the end of the stream */ + unsigned char *end; +/** pointer to the current position */ + unsigned char *bp; +} opj_cio_t; + +/* +========================================================== + volume typedef definitions +========================================================== +*/ + +/** +Defines a single volume component +*/ +typedef struct opj_volume_comp { +/** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */ + int dx; +/** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */ + int dy; +/** ZRsiz: vertical separation of a sample of ith component with respect to the reference grid */ + int dz; +/** data width */ + int w; + /** data height */ + int h; + /** data length : no of slices */ + int l; + /** x component offset compared to the whole volume */ + int x0; + /** y component offset compared to the whole volume */ + int y0; + /** z component offset compared to the whole volume */ + int z0; + /** precision */ + int prec; + /** volume depth in bits */ + int bpp; + /** DC offset (15444-2) */ + int dcoffset; + /** signed (1) / unsigned (0) */ + int sgnd; + /** BE byte order (1) / LE byte order (0) */ + int bigendian; + /** number of decoded resolution */ + int resno_decoded[3]; + /** number of division by 2 of the out volume compared to the original size of volume */ + int factor[3]; + /** volume component data */ + int *data; +} opj_volume_comp_t; + +/** +Defines volume data and characteristics +*/ +typedef struct opj_volume { +/** XOsiz: horizontal offset from the origin of the reference grid to the left side of the volume area */ + int x0; +/** YOsiz: vertical offset from the origin of the reference grid to the top side of the volume area */ + int y0; +/** ZOsiz: vertical offset from the origin of the reference grid to the top side of the volume area */ + int z0; +/** Xsiz: width of the reference grid */ + int x1; +/** Ysiz: height of the reference grid */ + int y1; +/** Zsiz: length of the reference grid */ + int z1; +/** number of components in the volume */ + int numcomps; +/** number of slices in the volume */ + int numslices; +/** color space: sRGB, Greyscale or YUV */ + OPJ_COLOR_SPACE color_space; +/** volume components */ + opj_volume_comp_t *comps; +} opj_volume_t; + +/** +Component parameters structure used by the opj_volume_create function +*/ +typedef struct opj_volume_comptparm { + /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */ + int dx; + /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */ + int dy; + /** ZRsiz: axial separation of a sample of ith component with respect to the reference grid */ + int dz; + /** data width */ + int w; + /** data height */ + int h; + /** data length */ + int l; + /** x component offset compared to the whole volume */ + int x0; + /** y component offset compared to the whole volume */ + int y0; + /** z component offset compared to the whole volume */ + int z0; + /** precision */ + int prec; + /** volume depth in bits */ + int bpp; + /** signed (1) / unsigned (0) */ + int sgnd; + /** DC offset*/ + int dcoffset; + /** BE byte order (1) / LE byte order (0) */ + int bigendian; +} opj_volume_cmptparm_t; + +#ifdef __cplusplus +extern "C" { +#endif + + +/* +========================================================== + openjpeg version +========================================================== +*/ + +OPJ_API const char * OPJ_CALLCONV opj_version(void); + +/* +========================================================== + volume functions definitions +========================================================== +*/ + +/** +Create an volume +@param numcmpts number of components +@param cmptparms components parameters +@param clrspc volume color space +@return returns a new volume structure if successful, returns NULL otherwise +*/ +OPJ_API opj_volume_t* OPJ_CALLCONV opj_volume_create(int numcmpts, opj_volume_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc); + +/** +Deallocate any resources associated with an volume +@param volume volume to be destroyed +*/ +OPJ_API void OPJ_CALLCONV opj_volume_destroy(opj_volume_t *volume); + +/* +========================================================== + stream functions definitions +========================================================== +*/ + +/** +Open and allocate a memory stream for read / write. +On reading, the user must provide a buffer containing encoded data. The buffer will be +wrapped by the returned CIO handle. +On writing, buffer parameters must be set to 0: a buffer will be allocated by the library +to contain encoded data. +@param cinfo Codec context info +@param buffer Reading: buffer address. Writing: NULL +@param length Reading: buffer length. Writing: 0 +@return Returns a CIO handle if successful, returns NULL otherwise +*/ +OPJ_API opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer, int length); + +/** +Close and free a CIO handle +@param cio CIO handle to free +*/ +OPJ_API void OPJ_CALLCONV opj_cio_close(opj_cio_t *cio); + +/** +Get position in byte stream +@param cio CIO handle +@return Returns the position in bytes +*/ +OPJ_API int OPJ_CALLCONV cio_tell(opj_cio_t *cio); +/** +Set position in byte stream +@param cio CIO handle +@param pos Position, in number of bytes, from the beginning of the stream +*/ +OPJ_API void OPJ_CALLCONV cio_seek(opj_cio_t *cio, int pos); + +/* +========================================================== + event manager functions definitions +========================================================== +*/ + +OPJ_API opj_event_mgr_t* OPJ_CALLCONV opj_set_event_mgr(opj_common_ptr cinfo, opj_event_mgr_t *event_mgr, void *context); + +/* +========================================================== + codec functions definitions +========================================================== +*/ +/** +Creates a J3D decompression structure +@param format Decoder to select +@return Returns a handle to a decompressor if successful, returns NULL otherwise +*/ +OPJ_API opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format); +/** +Destroy a decompressor handle +@param dinfo decompressor handle to destroy +*/ +OPJ_API void OPJ_CALLCONV opj_destroy_decompress(opj_dinfo_t *dinfo); +/** +Set decoding parameters to default values +@param parameters Decompression parameters +*/ +OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters); +/** +Setup the decoder decoding parameters using user parameters. +Decoding parameters are returned in j3d->cp. +@param dinfo decompressor handle +@param parameters decompression parameters +*/ +OPJ_API void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *parameters); +/** +Decode an volume from a JPEG-2000 codestream +@param dinfo decompressor handle +@param cio Input buffer stream +@return Returns a decoded volume if successful, returns NULL otherwise +*/ +OPJ_API opj_volume_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio); +/** +Creates a J3D/JP2 compression structure +@param format Coder to select +@return Returns a handle to a compressor if successful, returns NULL otherwise +*/ +OPJ_API opj_cinfo_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format); +/** +Destroy a compressor handle +@param cinfo compressor handle to destroy +*/ +OPJ_API void OPJ_CALLCONV opj_destroy_compress(opj_cinfo_t *cinfo); +/** +Set encoding parameters to default values, that means : +
    +
  • Lossless +
  • 1 tile +
  • Size of precinct : 2^15 x 2^15 (means 1 precinct) +
  • Size of code-block : 64 x 64 +
  • Number of resolutions: 6 +
  • No SOP marker in the codestream +
  • No EPH marker in the codestream +
  • No sub-sampling in x or y direction +
  • No mode switch activated +
  • Progression order: LRCP +
  • No index file +
  • No ROI upshifted +
  • No offset of the origin of the volume +
  • No offset of the origin of the tiles +
  • Reversible DWT 5-3 +
+@param parameters Compression parameters +*/ +OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters); +/** +Setup the encoder parameters using the current volume and using user parameters. +@param cinfo compressor handle +@param parameters compression parameters +@param volume input filled volume +*/ +OPJ_API void OPJ_CALLCONV opj_setup_encoder(opj_cinfo_t *cinfo, opj_cparameters_t *parameters, opj_volume_t *volume); +/** +Encode an volume into a JPEG-2000 codestream +@param cinfo compressor handle +@param cio Output buffer stream +@param volume Volume to encode +@param index Name of the index file if required, NULL otherwise +@return Returns true if successful, returns false otherwise +*/ +OPJ_API bool OPJ_CALLCONV opj_encode(opj_cinfo_t *cinfo, opj_cio_t *cio, opj_volume_t *volume, char *index); + +#ifdef __cplusplus +} +#endif + +#endif /* OPENJPEG_H */ diff --git a/src/lib/openjp3d/pi.c b/src/lib/openjp3d/pi.c index 960c1d84..185d2620 100644 --- a/src/lib/openjp3d/pi.c +++ b/src/lib/openjp3d/pi.c @@ -1,630 +1,630 @@ -/* - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium - * Copyright (c) 2006, Mónica Díez, LPI-UVA, Spain - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "opj_includes.h" - -/** @defgroup PI PI - Implementation of a packet iterator */ -/*@{*/ - -/** @name Funciones locales */ -/*@{*/ - -/** -Get next packet in layer-resolution-component-precinct order. -@param pi packet iterator to modify -@return returns false if pi pointed to the last packet or else returns true -*/ -static bool pi_next_lrcp(opj_pi_iterator_t * pi); -/** -Get next packet in resolution-layer-component-precinct order. -@param pi packet iterator to modify -@return returns false if pi pointed to the last packet or else returns true -*/ -static bool pi_next_rlcp(opj_pi_iterator_t * pi); -/** -Get next packet in resolution-precinct-component-layer order. -@param pi packet iterator to modify -@return returns false if pi pointed to the last packet or else returns true -*/ -static bool pi_next_rpcl(opj_pi_iterator_t * pi); -/** -Get next packet in precinct-component-resolution-layer order. -@param pi packet iterator to modify -@return returns false if pi pointed to the last packet or else returns true -*/ -static bool pi_next_pcrl(opj_pi_iterator_t * pi); -/** -Get next packet in component-precinct-resolution-layer order. -@param pi packet iterator to modify -@return returns false if pi pointed to the last packet or else returns true -*/ -static bool pi_next_cprl(opj_pi_iterator_t * pi); - -/*@}*/ - -/*@}*/ - -/* -========================================================== - local functions -========================================================== -*/ - -static bool pi_next_lrcp(opj_pi_iterator_t * pi) { - opj_pi_comp_t *comp = NULL; - opj_pi_resolution_t *res = NULL; - long index = 0; - - if (!pi->first) { - comp = &pi->comps[pi->compno]; - res = &comp->resolutions[pi->resno]; - goto LABEL_SKIP; - } else { - pi->first = 0; - } - - for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) { - for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) { - for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { - comp = &pi->comps[pi->compno]; - if (pi->resno >= comp->numresolution[0]) { - continue; - } - res = &comp->resolutions[pi->resno]; - /*for (pi->precno = 0; pi->precno < (res->prctno[0] * res->prctno[1]); pi->precno++) {*/ - for (pi->precno = 0; pi->precno < (res->prctno[0] * res->prctno[1] * res->prctno[2]); pi->precno++) { - index = pi->layno * pi->step_l - + pi->resno * pi->step_r - + pi->compno * pi->step_c - + pi->precno * pi->step_p; - if (!pi->include[index]) { - pi->include[index] = 1; - return true; - } -LABEL_SKIP:; - - } - } - } - } - - return false; -} - -static bool pi_next_rlcp(opj_pi_iterator_t * pi) { - opj_pi_comp_t *comp = NULL; - opj_pi_resolution_t *res = NULL; - long index = 0; - - if (!pi->first) { - comp = &pi->comps[pi->compno]; - res = &comp->resolutions[pi->resno]; - goto LABEL_SKIP; - } else { - pi->first = 0; - } - - for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) { - for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) { - for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { - comp = &pi->comps[pi->compno]; - if (pi->resno >= comp->numresolution[0]) { - continue; - } - res = &comp->resolutions[pi->resno]; - /*for (pi->precno = 0; pi->precno < (res->prctno[0] * res->prctno[1]); pi->precno++) {*/ - for (pi->precno = 0; pi->precno < (res->prctno[0] * res->prctno[1] * res->prctno[2]); pi->precno++) { - index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; - if (!pi->include[index]) { - pi->include[index] = 1; - return true; - } -LABEL_SKIP:; - } - } - } - } - - return false; -} - -static bool pi_next_rpcl(opj_pi_iterator_t * pi) { - opj_pi_comp_t *comp = NULL; - opj_pi_resolution_t *res = NULL; - long index = 0; - - if (!pi->first) { - goto LABEL_SKIP; - } else { - int compno, resno; - pi->first = 0; - pi->dx = 0; - pi->dy = 0; - for (compno = 0; compno < pi->numcomps; compno++) { - comp = &pi->comps[compno]; - for (resno = 0; resno < comp->numresolution[0]; resno++) { - int dx, dy,dz; - res = &comp->resolutions[resno]; - dx = comp->dx * (1 << (res->pdx + comp->numresolution[0] - 1 - resno)); - dy = comp->dy * (1 << (res->pdy + comp->numresolution[1] - 1 - resno)); - dz = comp->dz * (1 << (res->pdz + comp->numresolution[2] - 1 - resno)); - pi->dx = !pi->dx ? dx : int_min(pi->dx, dx); - pi->dy = !pi->dy ? dy : int_min(pi->dy, dy); - pi->dz = !pi->dz ? dz : int_min(pi->dz, dz); - } - } - } - - for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) { - for (pi->z = pi->tz0; pi->z < pi->tz1; pi->z += pi->dz - (pi->z % pi->dz)) { - for (pi->y = pi->ty0; pi->y < pi->ty1; pi->y += pi->dy - (pi->y % pi->dy)) { - for (pi->x = pi->tx0; pi->x < pi->tx1; pi->x += pi->dx - (pi->x % pi->dx)) { - for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { - int levelnox, levelnoy, levelnoz; - int trx0, try0, trz0; - int trx1, try1, trz1; - int rpx, rpy, rpz; - int prci, prcj, prck; - comp = &pi->comps[pi->compno]; - if (pi->resno >= comp->numresolution[0]) { - continue; - } - res = &comp->resolutions[pi->resno]; - levelnox = comp->numresolution[0] - 1 - pi->resno; - levelnoy = comp->numresolution[1] - 1 - pi->resno; - levelnoz = comp->numresolution[2] - 1 - pi->resno; - trx0 = int_ceildiv(pi->tx0, comp->dx << levelnox); - try0 = int_ceildiv(pi->ty0, comp->dy << levelnoy); - trz0 = int_ceildiv(pi->tz0, comp->dz << levelnoz); - trx1 = int_ceildiv(pi->tx1, comp->dx << levelnox); - try1 = int_ceildiv(pi->ty1, comp->dy << levelnoy); - trz1 = int_ceildiv(pi->tz1, comp->dz << levelnoz); - rpx = res->pdx + levelnox; - rpy = res->pdy + levelnoy; - rpz = res->pdz + levelnoz; - if ((!(pi->x % (comp->dx << rpx) == 0) || (pi->x == pi->tx0 && (trx0 << levelnox) % (1 << rpx)))) { - continue; - } - if ((!(pi->y % (comp->dy << rpy) == 0) || (pi->y == pi->ty0 && (try0 << levelnoy) % (1 << rpx)))) { - continue; - } - if ((!(pi->z % (comp->dz << rpz) == 0) || (pi->z == pi->tz0 && (trz0 << levelnoz) % (1 << rpx)))) { - continue; - } - if ((res->prctno[0]==0)||(res->prctno[1]==0)||(res->prctno[2]==0)) continue; - - if ((trx0==trx1)||(try0==try1)||(trz0==trz1)) continue; - - prci = int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelnox), res->pdx) - - int_floordivpow2(trx0, res->pdx); - prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelnoy), res->pdy) - - int_floordivpow2(try0, res->pdy); - prck = int_floordivpow2(int_ceildiv(pi->z, comp->dz << levelnoz), res->pdz) - - int_floordivpow2(trz0, res->pdz); - pi->precno = prci + prcj * res->prctno[0] + prck * res->prctno[0] * res->prctno[1]; - for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) { - index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; - if (!pi->include[index]) { - pi->include[index] = 1; - return true; - } - LABEL_SKIP:; - } - } - } - } - } - } - - return false; -} - -static bool pi_next_pcrl(opj_pi_iterator_t * pi) { - opj_pi_comp_t *comp = NULL; - opj_pi_resolution_t *res = NULL; - long index = 0; - - if (!pi->first) { - comp = &pi->comps[pi->compno]; - goto LABEL_SKIP; - } else { - int compno, resno; - pi->first = 0; - pi->dx = 0; - pi->dy = 0; - pi->dz = 0; - for (compno = 0; compno < pi->numcomps; compno++) { - comp = &pi->comps[compno]; - for (resno = 0; resno < comp->numresolution[0]; resno++) { - int dx, dy, dz; - res = &comp->resolutions[resno]; - dx = comp->dx * (1 << (res->pdx + comp->numresolution[0] - 1 - resno)); - dy = comp->dy * (1 << (res->pdy + comp->numresolution[1] - 1 - resno)); - dz = comp->dz * (1 << (res->pdy + comp->numresolution[2] - 1 - resno)); - pi->dx = !pi->dx ? dx : int_min(pi->dx, dx); - pi->dy = !pi->dy ? dy : int_min(pi->dy, dy); - pi->dz = !pi->dz ? dz : int_min(pi->dz, dz); - } - } - } - -for (pi->z = pi->tz0; pi->z < pi->tz1; pi->z += pi->dz - (pi->z % pi->dz)) { - for (pi->y = pi->ty0; pi->y < pi->ty1; pi->y += pi->dy - (pi->y % pi->dy)) { - for (pi->x = pi->tx0; pi->x < pi->tx1; pi->x += pi->dx - (pi->x % pi->dx)) { - for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { - comp = &pi->comps[pi->compno]; - for (pi->resno = pi->poc.resno0; pi->resno < int_min(pi->poc.resno1, comp->numresolution[0]); pi->resno++) { - int levelnox, levelnoy, levelnoz; - int trx0, try0, trz0; - int trx1, try1, trz1; - int rpx, rpy, rpz; - int prci, prcj, prck; - comp = &pi->comps[pi->compno]; - if (pi->resno >= comp->numresolution[0]) { - continue; - } - res = &comp->resolutions[pi->resno]; - levelnox = comp->numresolution[0] - 1 - pi->resno; - levelnoy = comp->numresolution[1] - 1 - pi->resno; - levelnoz = comp->numresolution[2] - 1 - pi->resno; - trx0 = int_ceildiv(pi->tx0, comp->dx << levelnox); - try0 = int_ceildiv(pi->ty0, comp->dy << levelnoy); - trz0 = int_ceildiv(pi->tz0, comp->dz << levelnoz); - trx1 = int_ceildiv(pi->tx1, comp->dx << levelnox); - try1 = int_ceildiv(pi->ty1, comp->dy << levelnoy); - trz1 = int_ceildiv(pi->tz1, comp->dz << levelnoz); - rpx = res->pdx + levelnox; - rpy = res->pdy + levelnoy; - rpz = res->pdz + levelnoz; - if ((!(pi->x % (comp->dx << rpx) == 0) || (pi->x == pi->tx0 && (trx0 << levelnox) % (1 << rpx)))) { - continue; - } - if ((!(pi->y % (comp->dy << rpy) == 0) || (pi->y == pi->ty0 && (try0 << levelnoy) % (1 << rpx)))) { - continue; - } - if ((!(pi->z % (comp->dz << rpz) == 0) || (pi->z == pi->tz0 && (trz0 << levelnoz) % (1 << rpx)))) { - continue; - } - if ((res->prctno[0]==0)||(res->prctno[1]==0)||(res->prctno[2]==0)) continue; - - if ((trx0==trx1)||(try0==try1)||(trz0==trz1)) continue; - - prci = int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelnox), res->pdx) - - int_floordivpow2(trx0, res->pdx); - prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelnoy), res->pdy) - - int_floordivpow2(try0, res->pdy); - prck = int_floordivpow2(int_ceildiv(pi->z, comp->dz << levelnoz), res->pdz) - - int_floordivpow2(trz0, res->pdz); - pi->precno = prci + prcj * res->prctno[0] + prck * res->prctno[0] * res->prctno[1]; - for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) { - index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; - if (!pi->include[index]) { - pi->include[index] = 1; - return true; - } -LABEL_SKIP:; - } - } - } - } - } -} - - return false; -} - -static bool pi_next_cprl(opj_pi_iterator_t * pi) { - opj_pi_comp_t *comp = NULL; - opj_pi_resolution_t *res = NULL; - long index = 0; - - if (!pi->first) { - comp = &pi->comps[pi->compno]; - goto LABEL_SKIP; - } else { - pi->first = 0; - } - - for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { - int resno; - comp = &pi->comps[pi->compno]; - pi->dx = 0; - pi->dy = 0; - for (resno = 0; resno < comp->numresolution[0]; resno++) { - int dx, dy; - res = &comp->resolutions[resno]; - dx = comp->dx * (1 << (res->pdx + comp->numresolution[0] - 1 - resno)); - dy = comp->dy * (1 << (res->pdy + comp->numresolution[0] - 1 - resno)); - pi->dx = !pi->dx ? dx : int_min(pi->dx, dx); - pi->dy = !pi->dy ? dy : int_min(pi->dy, dy); - } - for (pi->z = pi->tz0; pi->z < pi->tz1; pi->z += pi->dz - (pi->z % pi->dz)) { - for (pi->y = pi->ty0; pi->y < pi->ty1; pi->y += pi->dy - (pi->y % pi->dy)) { - for (pi->x = pi->tx0; pi->x < pi->tx1; pi->x += pi->dx - (pi->x % pi->dx)) { - for (pi->resno = pi->poc.resno0; pi->resno < int_min(pi->poc.resno1, comp->numresolution[0]); pi->resno++) { - int levelnox, levelnoy, levelnoz; - int trx0, try0, trz0; - int trx1, try1, trz1; - int rpx, rpy, rpz; - int prci, prcj, prck; - comp = &pi->comps[pi->compno]; - if (pi->resno >= comp->numresolution[0]) { - continue; - } - res = &comp->resolutions[pi->resno]; - levelnox = comp->numresolution[0] - 1 - pi->resno; - levelnoy = comp->numresolution[1] - 1 - pi->resno; - levelnoz = comp->numresolution[2] - 1 - pi->resno; - trx0 = int_ceildiv(pi->tx0, comp->dx << levelnox); - try0 = int_ceildiv(pi->ty0, comp->dy << levelnoy); - trz0 = int_ceildiv(pi->tz0, comp->dz << levelnoz); - trx1 = int_ceildiv(pi->tx1, comp->dx << levelnox); - try1 = int_ceildiv(pi->ty1, comp->dy << levelnoy); - trz1 = int_ceildiv(pi->tz1, comp->dz << levelnoz); - rpx = res->pdx + levelnox; - rpy = res->pdy + levelnoy; - rpz = res->pdz + levelnoz; - if ((!(pi->x % (comp->dx << rpx) == 0) || (pi->x == pi->tx0 && (trx0 << levelnox) % (1 << rpx)))) { - continue; - } - if ((!(pi->y % (comp->dy << rpy) == 0) || (pi->y == pi->ty0 && (try0 << levelnoy) % (1 << rpx)))) { - continue; - } - if ((!(pi->z % (comp->dz << rpz) == 0) || (pi->z == pi->tz0 && (trz0 << levelnoz) % (1 << rpx)))) { - continue; - } - if ((res->prctno[0]==0)||(res->prctno[1]==0)||(res->prctno[2]==0)) continue; - - if ((trx0==trx1)||(try0==try1)||(trz0==trz1)) continue; - - prci = int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelnox), res->pdx) - - int_floordivpow2(trx0, res->pdx); - prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelnoy), res->pdy) - - int_floordivpow2(try0, res->pdy); - prck = int_floordivpow2(int_ceildiv(pi->z, comp->dz << levelnoz), res->pdz) - - int_floordivpow2(trz0, res->pdz); - pi->precno = prci + prcj * res->prctno[0] + prck * res->prctno[0] * res->prctno[1]; - for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) { - index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; - if (!pi->include[index]) { - pi->include[index] = 1; - return true; - } - LABEL_SKIP:; - } - } - } - } - } - } - - return false; -} - -/* -========================================================== - Packet iterator interface -========================================================== -*/ - -opj_pi_iterator_t *pi_create(opj_volume_t *volume, opj_cp_t *cp, int tileno) { - int p, q, r; - int compno, resno, pino; - opj_pi_iterator_t *pi = NULL; - opj_tcp_t *tcp = NULL; - opj_tccp_t *tccp = NULL; - size_t array_size; - - tcp = &cp->tcps[tileno]; - - array_size = (tcp->numpocs + 1) * sizeof(opj_pi_iterator_t); - pi = (opj_pi_iterator_t *) opj_malloc(array_size); - if(!pi) { - fprintf(stdout,"[ERROR] Malloc of opj_pi_iterator failed \n"); - return NULL; - } - - for (pino = 0; pino < tcp->numpocs + 1; pino++) { /* change */ - int maxres = 0; - int maxprec = 0; - p = tileno % cp->tw; - q = tileno / cp->tw; - r = tileno / (cp->tw * cp->th); - - pi[pino].tx0 = int_max(cp->tx0 + p * cp->tdx, volume->x0); - pi[pino].ty0 = int_max(cp->ty0 + q * cp->tdy, volume->y0); - pi[pino].tz0 = int_max(cp->tz0 + r * cp->tdz, volume->z0); - pi[pino].tx1 = int_min(cp->tx0 + (p + 1) * cp->tdx, volume->x1); - pi[pino].ty1 = int_min(cp->ty0 + (q + 1) * cp->tdy, volume->y1); - pi[pino].tz1 = int_min(cp->tz0 + (r + 1) * cp->tdz, volume->z1); - pi[pino].numcomps = volume->numcomps; - - array_size = volume->numcomps * sizeof(opj_pi_comp_t); - pi[pino].comps = (opj_pi_comp_t *) opj_malloc(array_size); - if(!pi[pino].comps) { - fprintf(stdout,"[ERROR] Malloc of opj_pi_comp failed \n"); - pi_destroy(pi, cp, tileno); - return NULL; - } - memset(pi[pino].comps, 0, array_size); - - for (compno = 0; compno < pi->numcomps; compno++) { - int tcx0, tcx1, tcy0, tcy1, tcz0, tcz1; - int i; - opj_pi_comp_t *comp = &pi[pino].comps[compno]; - tccp = &tcp->tccps[compno]; - - comp->dx = volume->comps[compno].dx; - comp->dy = volume->comps[compno].dy; - comp->dz = volume->comps[compno].dz; - for (i = 0; i < 3; i++) { - comp->numresolution[i] = tccp->numresolution[i]; - if (comp->numresolution[i] > maxres) { - maxres = comp->numresolution[i]; - } - } - array_size = comp->numresolution[0] * sizeof(opj_pi_resolution_t); - comp->resolutions = (opj_pi_resolution_t *) opj_malloc(array_size); - if(!comp->resolutions) { - fprintf(stdout,"[ERROR] Malloc of opj_pi_resolution failed \n"); - pi_destroy(pi, cp, tileno); - return NULL; - } - - tcx0 = int_ceildiv(pi->tx0, comp->dx); - tcy0 = int_ceildiv(pi->ty0, comp->dy); - tcz0 = int_ceildiv(pi->tz0, comp->dz); - tcx1 = int_ceildiv(pi->tx1, comp->dx); - tcy1 = int_ceildiv(pi->ty1, comp->dy); - tcz1 = int_ceildiv(pi->tz1, comp->dz); - - for (resno = 0; resno < comp->numresolution[0]; resno++) { - int levelnox, levelnoy, levelnoz, diff; - int rx0, ry0, rz0, rx1, ry1, rz1; - int px0, py0, pz0, px1, py1, pz1; - opj_pi_resolution_t *res = &comp->resolutions[resno]; - if (tccp->csty & J3D_CCP_CSTY_PRT) { - res->pdx = tccp->prctsiz[0][resno]; - res->pdy = tccp->prctsiz[1][resno]; - res->pdz = tccp->prctsiz[2][resno]; - } else { - res->pdx = 15; - res->pdy = 15; - res->pdz = 15; - } - levelnox = comp->numresolution[0] - 1 - resno; - levelnoy = comp->numresolution[1] - 1 - resno; - levelnoz = comp->numresolution[2] - 1 - resno; - if (levelnoz < 0) levelnoz = 0; - diff = comp->numresolution[0] - comp->numresolution[2]; - - rx0 = int_ceildivpow2(tcx0, levelnox); - ry0 = int_ceildivpow2(tcy0, levelnoy); - rz0 = int_ceildivpow2(tcz0, levelnoz); - rx1 = int_ceildivpow2(tcx1, levelnox); - ry1 = int_ceildivpow2(tcy1, levelnoy); - rz1 = int_ceildivpow2(tcz1, levelnoz); - px0 = int_floordivpow2(rx0, res->pdx) << res->pdx; - py0 = int_floordivpow2(ry0, res->pdy) << res->pdy; - pz0 = int_floordivpow2(rz0, res->pdz) << res->pdz; - px1 = int_ceildivpow2(rx1, res->pdx) << res->pdx; - py1 = int_ceildivpow2(ry1, res->pdy) << res->pdy; - pz1 = int_ceildivpow2(rz1, res->pdz) << res->pdz; - res->prctno[0] = (rx0==rx1)? 0 : ((px1 - px0) >> res->pdx); - res->prctno[1] = (ry0==ry1)? 0 : ((py1 - py0) >> res->pdy); - res->prctno[2] = (rz0==rz1)? 0 : ((pz1 - pz0) >> res->pdz); - - if (res->prctno[0]*res->prctno[1]*res->prctno[2] > maxprec) { - maxprec = res->prctno[0]*res->prctno[1]*res->prctno[2]; - } - } - } - - tccp = &tcp->tccps[0]; - pi[pino].step_p = 1; - pi[pino].step_c = maxprec * pi[pino].step_p; - pi[pino].step_r = volume->numcomps * pi[pino].step_c; - pi[pino].step_l = maxres * pi[pino].step_r; - - if (pino == 0) { - array_size = volume->numcomps * maxres * tcp->numlayers * maxprec * sizeof(short int); - pi[pino].include = (short int *) opj_malloc(array_size); - if(!pi[pino].include) { - fprintf(stdout,"[ERROR] Malloc of pi[pino].include failed \n"); - pi_destroy(pi, cp, tileno); - return NULL; - } - } - else { - pi[pino].include = pi[pino - 1].include; - } - - if (tcp->POC == 0) { - pi[pino].first = 1; - pi[pino].poc.resno0 = 0; - pi[pino].poc.compno0 = 0; - pi[pino].poc.layno1 = tcp->numlayers; - pi[pino].poc.resno1 = maxres; - pi[pino].poc.compno1 = volume->numcomps; - pi[pino].poc.prg = tcp->prg; - } else { - pi[pino].first = 1; - pi[pino].poc.resno0 = tcp->pocs[pino].resno0; - pi[pino].poc.compno0 = tcp->pocs[pino].compno0; - pi[pino].poc.layno1 = tcp->pocs[pino].layno1; - pi[pino].poc.resno1 = tcp->pocs[pino].resno1; - pi[pino].poc.compno1 = tcp->pocs[pino].compno1; - pi[pino].poc.prg = tcp->pocs[pino].prg; - } - } - - return pi; -} - -void pi_destroy(opj_pi_iterator_t *pi, opj_cp_t *cp, int tileno) { - int compno, pino; - opj_tcp_t *tcp = &cp->tcps[tileno]; - if(pi) { - for (pino = 0; pino < tcp->numpocs + 1; pino++) { - if(pi[pino].comps) { - for (compno = 0; compno < pi->numcomps; compno++) { - opj_pi_comp_t *comp = &pi[pino].comps[compno]; - if(comp->resolutions) { - opj_free(comp->resolutions); - } - } - opj_free(pi[pino].comps); - } - } - if(pi->include) { - opj_free(pi->include); - } - opj_free(pi); - } -} - -bool pi_next(opj_pi_iterator_t * pi) { - switch (pi->poc.prg) { - case LRCP: - return pi_next_lrcp(pi); - case RLCP: - return pi_next_rlcp(pi); - case RPCL: - return pi_next_rpcl(pi); - case PCRL: - return pi_next_pcrl(pi); - case CPRL: - return pi_next_cprl(pi); - } - - return false; -} - +/* + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * Copyright (c) 2006, Mónica Díez, LPI-UVA, Spain + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opj_includes.h" + +/** @defgroup PI PI - Implementation of a packet iterator */ +/*@{*/ + +/** @name Funciones locales */ +/*@{*/ + +/** +Get next packet in layer-resolution-component-precinct order. +@param pi packet iterator to modify +@return returns false if pi pointed to the last packet or else returns true +*/ +static bool pi_next_lrcp(opj_pi_iterator_t * pi); +/** +Get next packet in resolution-layer-component-precinct order. +@param pi packet iterator to modify +@return returns false if pi pointed to the last packet or else returns true +*/ +static bool pi_next_rlcp(opj_pi_iterator_t * pi); +/** +Get next packet in resolution-precinct-component-layer order. +@param pi packet iterator to modify +@return returns false if pi pointed to the last packet or else returns true +*/ +static bool pi_next_rpcl(opj_pi_iterator_t * pi); +/** +Get next packet in precinct-component-resolution-layer order. +@param pi packet iterator to modify +@return returns false if pi pointed to the last packet or else returns true +*/ +static bool pi_next_pcrl(opj_pi_iterator_t * pi); +/** +Get next packet in component-precinct-resolution-layer order. +@param pi packet iterator to modify +@return returns false if pi pointed to the last packet or else returns true +*/ +static bool pi_next_cprl(opj_pi_iterator_t * pi); + +/*@}*/ + +/*@}*/ + +/* +========================================================== + local functions +========================================================== +*/ + +static bool pi_next_lrcp(opj_pi_iterator_t * pi) { + opj_pi_comp_t *comp = NULL; + opj_pi_resolution_t *res = NULL; + long index = 0; + + if (!pi->first) { + comp = &pi->comps[pi->compno]; + res = &comp->resolutions[pi->resno]; + goto LABEL_SKIP; + } else { + pi->first = 0; + } + + for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) { + for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) { + for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { + comp = &pi->comps[pi->compno]; + if (pi->resno >= comp->numresolution[0]) { + continue; + } + res = &comp->resolutions[pi->resno]; + /*for (pi->precno = 0; pi->precno < (res->prctno[0] * res->prctno[1]); pi->precno++) {*/ + for (pi->precno = 0; pi->precno < (res->prctno[0] * res->prctno[1] * res->prctno[2]); pi->precno++) { + index = pi->layno * pi->step_l + + pi->resno * pi->step_r + + pi->compno * pi->step_c + + pi->precno * pi->step_p; + if (!pi->include[index]) { + pi->include[index] = 1; + return true; + } +LABEL_SKIP:; + + } + } + } + } + + return false; +} + +static bool pi_next_rlcp(opj_pi_iterator_t * pi) { + opj_pi_comp_t *comp = NULL; + opj_pi_resolution_t *res = NULL; + long index = 0; + + if (!pi->first) { + comp = &pi->comps[pi->compno]; + res = &comp->resolutions[pi->resno]; + goto LABEL_SKIP; + } else { + pi->first = 0; + } + + for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) { + for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) { + for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { + comp = &pi->comps[pi->compno]; + if (pi->resno >= comp->numresolution[0]) { + continue; + } + res = &comp->resolutions[pi->resno]; + /*for (pi->precno = 0; pi->precno < (res->prctno[0] * res->prctno[1]); pi->precno++) {*/ + for (pi->precno = 0; pi->precno < (res->prctno[0] * res->prctno[1] * res->prctno[2]); pi->precno++) { + index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; + if (!pi->include[index]) { + pi->include[index] = 1; + return true; + } +LABEL_SKIP:; + } + } + } + } + + return false; +} + +static bool pi_next_rpcl(opj_pi_iterator_t * pi) { + opj_pi_comp_t *comp = NULL; + opj_pi_resolution_t *res = NULL; + long index = 0; + + if (!pi->first) { + goto LABEL_SKIP; + } else { + int compno, resno; + pi->first = 0; + pi->dx = 0; + pi->dy = 0; + for (compno = 0; compno < pi->numcomps; compno++) { + comp = &pi->comps[compno]; + for (resno = 0; resno < comp->numresolution[0]; resno++) { + int dx, dy,dz; + res = &comp->resolutions[resno]; + dx = comp->dx * (1 << (res->pdx + comp->numresolution[0] - 1 - resno)); + dy = comp->dy * (1 << (res->pdy + comp->numresolution[1] - 1 - resno)); + dz = comp->dz * (1 << (res->pdz + comp->numresolution[2] - 1 - resno)); + pi->dx = !pi->dx ? dx : int_min(pi->dx, dx); + pi->dy = !pi->dy ? dy : int_min(pi->dy, dy); + pi->dz = !pi->dz ? dz : int_min(pi->dz, dz); + } + } + } + + for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) { + for (pi->z = pi->tz0; pi->z < pi->tz1; pi->z += pi->dz - (pi->z % pi->dz)) { + for (pi->y = pi->ty0; pi->y < pi->ty1; pi->y += pi->dy - (pi->y % pi->dy)) { + for (pi->x = pi->tx0; pi->x < pi->tx1; pi->x += pi->dx - (pi->x % pi->dx)) { + for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { + int levelnox, levelnoy, levelnoz; + int trx0, try0, trz0; + int trx1, try1, trz1; + int rpx, rpy, rpz; + int prci, prcj, prck; + comp = &pi->comps[pi->compno]; + if (pi->resno >= comp->numresolution[0]) { + continue; + } + res = &comp->resolutions[pi->resno]; + levelnox = comp->numresolution[0] - 1 - pi->resno; + levelnoy = comp->numresolution[1] - 1 - pi->resno; + levelnoz = comp->numresolution[2] - 1 - pi->resno; + trx0 = int_ceildiv(pi->tx0, comp->dx << levelnox); + try0 = int_ceildiv(pi->ty0, comp->dy << levelnoy); + trz0 = int_ceildiv(pi->tz0, comp->dz << levelnoz); + trx1 = int_ceildiv(pi->tx1, comp->dx << levelnox); + try1 = int_ceildiv(pi->ty1, comp->dy << levelnoy); + trz1 = int_ceildiv(pi->tz1, comp->dz << levelnoz); + rpx = res->pdx + levelnox; + rpy = res->pdy + levelnoy; + rpz = res->pdz + levelnoz; + if ((!(pi->x % (comp->dx << rpx) == 0) || (pi->x == pi->tx0 && (trx0 << levelnox) % (1 << rpx)))) { + continue; + } + if ((!(pi->y % (comp->dy << rpy) == 0) || (pi->y == pi->ty0 && (try0 << levelnoy) % (1 << rpx)))) { + continue; + } + if ((!(pi->z % (comp->dz << rpz) == 0) || (pi->z == pi->tz0 && (trz0 << levelnoz) % (1 << rpx)))) { + continue; + } + if ((res->prctno[0]==0)||(res->prctno[1]==0)||(res->prctno[2]==0)) continue; + + if ((trx0==trx1)||(try0==try1)||(trz0==trz1)) continue; + + prci = int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelnox), res->pdx) + - int_floordivpow2(trx0, res->pdx); + prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelnoy), res->pdy) + - int_floordivpow2(try0, res->pdy); + prck = int_floordivpow2(int_ceildiv(pi->z, comp->dz << levelnoz), res->pdz) + - int_floordivpow2(trz0, res->pdz); + pi->precno = prci + prcj * res->prctno[0] + prck * res->prctno[0] * res->prctno[1]; + for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) { + index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; + if (!pi->include[index]) { + pi->include[index] = 1; + return true; + } + LABEL_SKIP:; + } + } + } + } + } + } + + return false; +} + +static bool pi_next_pcrl(opj_pi_iterator_t * pi) { + opj_pi_comp_t *comp = NULL; + opj_pi_resolution_t *res = NULL; + long index = 0; + + if (!pi->first) { + comp = &pi->comps[pi->compno]; + goto LABEL_SKIP; + } else { + int compno, resno; + pi->first = 0; + pi->dx = 0; + pi->dy = 0; + pi->dz = 0; + for (compno = 0; compno < pi->numcomps; compno++) { + comp = &pi->comps[compno]; + for (resno = 0; resno < comp->numresolution[0]; resno++) { + int dx, dy, dz; + res = &comp->resolutions[resno]; + dx = comp->dx * (1 << (res->pdx + comp->numresolution[0] - 1 - resno)); + dy = comp->dy * (1 << (res->pdy + comp->numresolution[1] - 1 - resno)); + dz = comp->dz * (1 << (res->pdy + comp->numresolution[2] - 1 - resno)); + pi->dx = !pi->dx ? dx : int_min(pi->dx, dx); + pi->dy = !pi->dy ? dy : int_min(pi->dy, dy); + pi->dz = !pi->dz ? dz : int_min(pi->dz, dz); + } + } + } + +for (pi->z = pi->tz0; pi->z < pi->tz1; pi->z += pi->dz - (pi->z % pi->dz)) { + for (pi->y = pi->ty0; pi->y < pi->ty1; pi->y += pi->dy - (pi->y % pi->dy)) { + for (pi->x = pi->tx0; pi->x < pi->tx1; pi->x += pi->dx - (pi->x % pi->dx)) { + for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { + comp = &pi->comps[pi->compno]; + for (pi->resno = pi->poc.resno0; pi->resno < int_min(pi->poc.resno1, comp->numresolution[0]); pi->resno++) { + int levelnox, levelnoy, levelnoz; + int trx0, try0, trz0; + int trx1, try1, trz1; + int rpx, rpy, rpz; + int prci, prcj, prck; + comp = &pi->comps[pi->compno]; + if (pi->resno >= comp->numresolution[0]) { + continue; + } + res = &comp->resolutions[pi->resno]; + levelnox = comp->numresolution[0] - 1 - pi->resno; + levelnoy = comp->numresolution[1] - 1 - pi->resno; + levelnoz = comp->numresolution[2] - 1 - pi->resno; + trx0 = int_ceildiv(pi->tx0, comp->dx << levelnox); + try0 = int_ceildiv(pi->ty0, comp->dy << levelnoy); + trz0 = int_ceildiv(pi->tz0, comp->dz << levelnoz); + trx1 = int_ceildiv(pi->tx1, comp->dx << levelnox); + try1 = int_ceildiv(pi->ty1, comp->dy << levelnoy); + trz1 = int_ceildiv(pi->tz1, comp->dz << levelnoz); + rpx = res->pdx + levelnox; + rpy = res->pdy + levelnoy; + rpz = res->pdz + levelnoz; + if ((!(pi->x % (comp->dx << rpx) == 0) || (pi->x == pi->tx0 && (trx0 << levelnox) % (1 << rpx)))) { + continue; + } + if ((!(pi->y % (comp->dy << rpy) == 0) || (pi->y == pi->ty0 && (try0 << levelnoy) % (1 << rpx)))) { + continue; + } + if ((!(pi->z % (comp->dz << rpz) == 0) || (pi->z == pi->tz0 && (trz0 << levelnoz) % (1 << rpx)))) { + continue; + } + if ((res->prctno[0]==0)||(res->prctno[1]==0)||(res->prctno[2]==0)) continue; + + if ((trx0==trx1)||(try0==try1)||(trz0==trz1)) continue; + + prci = int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelnox), res->pdx) + - int_floordivpow2(trx0, res->pdx); + prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelnoy), res->pdy) + - int_floordivpow2(try0, res->pdy); + prck = int_floordivpow2(int_ceildiv(pi->z, comp->dz << levelnoz), res->pdz) + - int_floordivpow2(trz0, res->pdz); + pi->precno = prci + prcj * res->prctno[0] + prck * res->prctno[0] * res->prctno[1]; + for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) { + index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; + if (!pi->include[index]) { + pi->include[index] = 1; + return true; + } +LABEL_SKIP:; + } + } + } + } + } +} + + return false; +} + +static bool pi_next_cprl(opj_pi_iterator_t * pi) { + opj_pi_comp_t *comp = NULL; + opj_pi_resolution_t *res = NULL; + long index = 0; + + if (!pi->first) { + comp = &pi->comps[pi->compno]; + goto LABEL_SKIP; + } else { + pi->first = 0; + } + + for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { + int resno; + comp = &pi->comps[pi->compno]; + pi->dx = 0; + pi->dy = 0; + for (resno = 0; resno < comp->numresolution[0]; resno++) { + int dx, dy; + res = &comp->resolutions[resno]; + dx = comp->dx * (1 << (res->pdx + comp->numresolution[0] - 1 - resno)); + dy = comp->dy * (1 << (res->pdy + comp->numresolution[0] - 1 - resno)); + pi->dx = !pi->dx ? dx : int_min(pi->dx, dx); + pi->dy = !pi->dy ? dy : int_min(pi->dy, dy); + } + for (pi->z = pi->tz0; pi->z < pi->tz1; pi->z += pi->dz - (pi->z % pi->dz)) { + for (pi->y = pi->ty0; pi->y < pi->ty1; pi->y += pi->dy - (pi->y % pi->dy)) { + for (pi->x = pi->tx0; pi->x < pi->tx1; pi->x += pi->dx - (pi->x % pi->dx)) { + for (pi->resno = pi->poc.resno0; pi->resno < int_min(pi->poc.resno1, comp->numresolution[0]); pi->resno++) { + int levelnox, levelnoy, levelnoz; + int trx0, try0, trz0; + int trx1, try1, trz1; + int rpx, rpy, rpz; + int prci, prcj, prck; + comp = &pi->comps[pi->compno]; + if (pi->resno >= comp->numresolution[0]) { + continue; + } + res = &comp->resolutions[pi->resno]; + levelnox = comp->numresolution[0] - 1 - pi->resno; + levelnoy = comp->numresolution[1] - 1 - pi->resno; + levelnoz = comp->numresolution[2] - 1 - pi->resno; + trx0 = int_ceildiv(pi->tx0, comp->dx << levelnox); + try0 = int_ceildiv(pi->ty0, comp->dy << levelnoy); + trz0 = int_ceildiv(pi->tz0, comp->dz << levelnoz); + trx1 = int_ceildiv(pi->tx1, comp->dx << levelnox); + try1 = int_ceildiv(pi->ty1, comp->dy << levelnoy); + trz1 = int_ceildiv(pi->tz1, comp->dz << levelnoz); + rpx = res->pdx + levelnox; + rpy = res->pdy + levelnoy; + rpz = res->pdz + levelnoz; + if ((!(pi->x % (comp->dx << rpx) == 0) || (pi->x == pi->tx0 && (trx0 << levelnox) % (1 << rpx)))) { + continue; + } + if ((!(pi->y % (comp->dy << rpy) == 0) || (pi->y == pi->ty0 && (try0 << levelnoy) % (1 << rpx)))) { + continue; + } + if ((!(pi->z % (comp->dz << rpz) == 0) || (pi->z == pi->tz0 && (trz0 << levelnoz) % (1 << rpx)))) { + continue; + } + if ((res->prctno[0]==0)||(res->prctno[1]==0)||(res->prctno[2]==0)) continue; + + if ((trx0==trx1)||(try0==try1)||(trz0==trz1)) continue; + + prci = int_floordivpow2(int_ceildiv(pi->x, comp->dx << levelnox), res->pdx) + - int_floordivpow2(trx0, res->pdx); + prcj = int_floordivpow2(int_ceildiv(pi->y, comp->dy << levelnoy), res->pdy) + - int_floordivpow2(try0, res->pdy); + prck = int_floordivpow2(int_ceildiv(pi->z, comp->dz << levelnoz), res->pdz) + - int_floordivpow2(trz0, res->pdz); + pi->precno = prci + prcj * res->prctno[0] + prck * res->prctno[0] * res->prctno[1]; + for (pi->layno = 0; pi->layno < pi->poc.layno1; pi->layno++) { + index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; + if (!pi->include[index]) { + pi->include[index] = 1; + return true; + } + LABEL_SKIP:; + } + } + } + } + } + } + + return false; +} + +/* +========================================================== + Packet iterator interface +========================================================== +*/ + +opj_pi_iterator_t *pi_create(opj_volume_t *volume, opj_cp_t *cp, int tileno) { + int p, q, r; + int compno, resno, pino; + opj_pi_iterator_t *pi = NULL; + opj_tcp_t *tcp = NULL; + opj_tccp_t *tccp = NULL; + size_t array_size; + + tcp = &cp->tcps[tileno]; + + array_size = (tcp->numpocs + 1) * sizeof(opj_pi_iterator_t); + pi = (opj_pi_iterator_t *) opj_malloc(array_size); + if(!pi) { + fprintf(stdout,"[ERROR] Malloc of opj_pi_iterator failed \n"); + return NULL; + } + + for (pino = 0; pino < tcp->numpocs + 1; pino++) { /* change */ + int maxres = 0; + int maxprec = 0; + p = tileno % cp->tw; + q = tileno / cp->tw; + r = tileno / (cp->tw * cp->th); + + pi[pino].tx0 = int_max(cp->tx0 + p * cp->tdx, volume->x0); + pi[pino].ty0 = int_max(cp->ty0 + q * cp->tdy, volume->y0); + pi[pino].tz0 = int_max(cp->tz0 + r * cp->tdz, volume->z0); + pi[pino].tx1 = int_min(cp->tx0 + (p + 1) * cp->tdx, volume->x1); + pi[pino].ty1 = int_min(cp->ty0 + (q + 1) * cp->tdy, volume->y1); + pi[pino].tz1 = int_min(cp->tz0 + (r + 1) * cp->tdz, volume->z1); + pi[pino].numcomps = volume->numcomps; + + array_size = volume->numcomps * sizeof(opj_pi_comp_t); + pi[pino].comps = (opj_pi_comp_t *) opj_malloc(array_size); + if(!pi[pino].comps) { + fprintf(stdout,"[ERROR] Malloc of opj_pi_comp failed \n"); + pi_destroy(pi, cp, tileno); + return NULL; + } + memset(pi[pino].comps, 0, array_size); + + for (compno = 0; compno < pi->numcomps; compno++) { + int tcx0, tcx1, tcy0, tcy1, tcz0, tcz1; + int i; + opj_pi_comp_t *comp = &pi[pino].comps[compno]; + tccp = &tcp->tccps[compno]; + + comp->dx = volume->comps[compno].dx; + comp->dy = volume->comps[compno].dy; + comp->dz = volume->comps[compno].dz; + for (i = 0; i < 3; i++) { + comp->numresolution[i] = tccp->numresolution[i]; + if (comp->numresolution[i] > maxres) { + maxres = comp->numresolution[i]; + } + } + array_size = comp->numresolution[0] * sizeof(opj_pi_resolution_t); + comp->resolutions = (opj_pi_resolution_t *) opj_malloc(array_size); + if(!comp->resolutions) { + fprintf(stdout,"[ERROR] Malloc of opj_pi_resolution failed \n"); + pi_destroy(pi, cp, tileno); + return NULL; + } + + tcx0 = int_ceildiv(pi->tx0, comp->dx); + tcy0 = int_ceildiv(pi->ty0, comp->dy); + tcz0 = int_ceildiv(pi->tz0, comp->dz); + tcx1 = int_ceildiv(pi->tx1, comp->dx); + tcy1 = int_ceildiv(pi->ty1, comp->dy); + tcz1 = int_ceildiv(pi->tz1, comp->dz); + + for (resno = 0; resno < comp->numresolution[0]; resno++) { + int levelnox, levelnoy, levelnoz, diff; + int rx0, ry0, rz0, rx1, ry1, rz1; + int px0, py0, pz0, px1, py1, pz1; + opj_pi_resolution_t *res = &comp->resolutions[resno]; + if (tccp->csty & J3D_CCP_CSTY_PRT) { + res->pdx = tccp->prctsiz[0][resno]; + res->pdy = tccp->prctsiz[1][resno]; + res->pdz = tccp->prctsiz[2][resno]; + } else { + res->pdx = 15; + res->pdy = 15; + res->pdz = 15; + } + levelnox = comp->numresolution[0] - 1 - resno; + levelnoy = comp->numresolution[1] - 1 - resno; + levelnoz = comp->numresolution[2] - 1 - resno; + if (levelnoz < 0) levelnoz = 0; + diff = comp->numresolution[0] - comp->numresolution[2]; + + rx0 = int_ceildivpow2(tcx0, levelnox); + ry0 = int_ceildivpow2(tcy0, levelnoy); + rz0 = int_ceildivpow2(tcz0, levelnoz); + rx1 = int_ceildivpow2(tcx1, levelnox); + ry1 = int_ceildivpow2(tcy1, levelnoy); + rz1 = int_ceildivpow2(tcz1, levelnoz); + px0 = int_floordivpow2(rx0, res->pdx) << res->pdx; + py0 = int_floordivpow2(ry0, res->pdy) << res->pdy; + pz0 = int_floordivpow2(rz0, res->pdz) << res->pdz; + px1 = int_ceildivpow2(rx1, res->pdx) << res->pdx; + py1 = int_ceildivpow2(ry1, res->pdy) << res->pdy; + pz1 = int_ceildivpow2(rz1, res->pdz) << res->pdz; + res->prctno[0] = (rx0==rx1)? 0 : ((px1 - px0) >> res->pdx); + res->prctno[1] = (ry0==ry1)? 0 : ((py1 - py0) >> res->pdy); + res->prctno[2] = (rz0==rz1)? 0 : ((pz1 - pz0) >> res->pdz); + + if (res->prctno[0]*res->prctno[1]*res->prctno[2] > maxprec) { + maxprec = res->prctno[0]*res->prctno[1]*res->prctno[2]; + } + } + } + + tccp = &tcp->tccps[0]; + pi[pino].step_p = 1; + pi[pino].step_c = maxprec * pi[pino].step_p; + pi[pino].step_r = volume->numcomps * pi[pino].step_c; + pi[pino].step_l = maxres * pi[pino].step_r; + + if (pino == 0) { + array_size = volume->numcomps * maxres * tcp->numlayers * maxprec * sizeof(short int); + pi[pino].include = (short int *) opj_malloc(array_size); + if(!pi[pino].include) { + fprintf(stdout,"[ERROR] Malloc of pi[pino].include failed \n"); + pi_destroy(pi, cp, tileno); + return NULL; + } + } + else { + pi[pino].include = pi[pino - 1].include; + } + + if (tcp->POC == 0) { + pi[pino].first = 1; + pi[pino].poc.resno0 = 0; + pi[pino].poc.compno0 = 0; + pi[pino].poc.layno1 = tcp->numlayers; + pi[pino].poc.resno1 = maxres; + pi[pino].poc.compno1 = volume->numcomps; + pi[pino].poc.prg = tcp->prg; + } else { + pi[pino].first = 1; + pi[pino].poc.resno0 = tcp->pocs[pino].resno0; + pi[pino].poc.compno0 = tcp->pocs[pino].compno0; + pi[pino].poc.layno1 = tcp->pocs[pino].layno1; + pi[pino].poc.resno1 = tcp->pocs[pino].resno1; + pi[pino].poc.compno1 = tcp->pocs[pino].compno1; + pi[pino].poc.prg = tcp->pocs[pino].prg; + } + } + + return pi; +} + +void pi_destroy(opj_pi_iterator_t *pi, opj_cp_t *cp, int tileno) { + int compno, pino; + opj_tcp_t *tcp = &cp->tcps[tileno]; + if(pi) { + for (pino = 0; pino < tcp->numpocs + 1; pino++) { + if(pi[pino].comps) { + for (compno = 0; compno < pi->numcomps; compno++) { + opj_pi_comp_t *comp = &pi[pino].comps[compno]; + if(comp->resolutions) { + opj_free(comp->resolutions); + } + } + opj_free(pi[pino].comps); + } + } + if(pi->include) { + opj_free(pi->include); + } + opj_free(pi); + } +} + +bool pi_next(opj_pi_iterator_t * pi) { + switch (pi->poc.prg) { + case LRCP: + return pi_next_lrcp(pi); + case RLCP: + return pi_next_rlcp(pi); + case RPCL: + return pi_next_rpcl(pi); + case PCRL: + return pi_next_pcrl(pi); + case CPRL: + return pi_next_cprl(pi); + } + + return false; +} + diff --git a/src/lib/openjp3d/pi.h b/src/lib/openjp3d/pi.h index 1edcc5fc..4274f4e6 100644 --- a/src/lib/openjp3d/pi.h +++ b/src/lib/openjp3d/pi.h @@ -1,145 +1,145 @@ -/* - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium - * Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __PI_H -#define __PI_H -/** -@file pi.h -@brief Implementation of a packet iterator (PI) - -The functions in PI.C have for goal to realize a packet iterator that permits to get the next -packet following the progression order and change of it. The functions in PI.C are used -by some function in T2.C. -*/ - -/** @defgroup PI PI - Implementation of a packet iterator */ -/*@{*/ - -/** -Packet iterator : resolution level information -*/ -typedef struct opj_pi_resolution { -/** Size of precints in horizontal axis */ - int pdx; -/** Size of precints in vertical axis */ - int pdy; -/** Size of precints in axial axis */ - int pdz; -/** Number of precints in each axis */ - int prctno[3]; -} opj_pi_resolution_t; - -/** -Packet iterator : component information -*/ -typedef struct opj_pi_comp { -/** Size in horizontal axis */ - int dx; -/** Size in vertical axis */ - int dy; -/** Size in axial axis */ - int dz; -/** Number of resolution levels */ - int numresolution[3]; -/** Packet iterator : resolution level information */ - opj_pi_resolution_t *resolutions; -} opj_pi_comp_t; - -/** -Packet iterator -*/ -typedef struct opj_pi_iterator { -/** precise if the packet has been already used (usefull for progression order change) */ - short int *include; -/** layer step used to localize the packet in the include vector */ - int step_l; -/** resolution step used to localize the packet in the include vector */ - int step_r; -/** component step used to localize the packet in the include vector */ - int step_c; -/** precinct step used to localize the packet in the include vector */ - int step_p; -/** component that identify the packet */ - int compno; -/** resolution that identify the packet */ - int resno; -/** precinct that identify the packet */ - int precno; -/** layer that identify the packet */ - int layno; -/** 0 if the first packet */ - int first; -/** progression order change information */ - opj_poc_t poc; -/** Packet iterator : component information */ -opj_pi_comp_t *comps; - - int numcomps; - int tx0, ty0, tz0; - int tx1, ty1, tz1; - int x, y, z; - int dx, dy, dz; -} opj_pi_iterator_t; - -/** @name Funciones generales */ -/*@{*/ -/* ----------------------------------------------------------------------- */ -/** -Create a packet iterator -@param volume Raw volume for which the packets will be listed -@param cp Coding parameters -@param tileno Number that identifies the tile for which to list the packets -@return Returns a packet iterator that points to the first packet of the tile -@see pi_destroy -*/ -opj_pi_iterator_t *pi_create(opj_volume_t * volume, opj_cp_t * cp, int tileno); - -/** -Destroy a packet iterator -@param pi Previously created packet iterator -@param cp Coding parameters -@param tileno Number that identifies the tile for which the packets were listed -@see pi_create -*/ -void pi_destroy(opj_pi_iterator_t *pi, opj_cp_t *cp, int tileno); - -/** -Modify the packet iterator to point to the next packet -@param pi Packet iterator to modify -@return Returns false if pi pointed to the last packet or else returns true -*/ -bool pi_next(opj_pi_iterator_t * pi); -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __PI_H */ +/* + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __PI_H +#define __PI_H +/** +@file pi.h +@brief Implementation of a packet iterator (PI) + +The functions in PI.C have for goal to realize a packet iterator that permits to get the next +packet following the progression order and change of it. The functions in PI.C are used +by some function in T2.C. +*/ + +/** @defgroup PI PI - Implementation of a packet iterator */ +/*@{*/ + +/** +Packet iterator : resolution level information +*/ +typedef struct opj_pi_resolution { +/** Size of precints in horizontal axis */ + int pdx; +/** Size of precints in vertical axis */ + int pdy; +/** Size of precints in axial axis */ + int pdz; +/** Number of precints in each axis */ + int prctno[3]; +} opj_pi_resolution_t; + +/** +Packet iterator : component information +*/ +typedef struct opj_pi_comp { +/** Size in horizontal axis */ + int dx; +/** Size in vertical axis */ + int dy; +/** Size in axial axis */ + int dz; +/** Number of resolution levels */ + int numresolution[3]; +/** Packet iterator : resolution level information */ + opj_pi_resolution_t *resolutions; +} opj_pi_comp_t; + +/** +Packet iterator +*/ +typedef struct opj_pi_iterator { +/** precise if the packet has been already used (usefull for progression order change) */ + short int *include; +/** layer step used to localize the packet in the include vector */ + int step_l; +/** resolution step used to localize the packet in the include vector */ + int step_r; +/** component step used to localize the packet in the include vector */ + int step_c; +/** precinct step used to localize the packet in the include vector */ + int step_p; +/** component that identify the packet */ + int compno; +/** resolution that identify the packet */ + int resno; +/** precinct that identify the packet */ + int precno; +/** layer that identify the packet */ + int layno; +/** 0 if the first packet */ + int first; +/** progression order change information */ + opj_poc_t poc; +/** Packet iterator : component information */ +opj_pi_comp_t *comps; + + int numcomps; + int tx0, ty0, tz0; + int tx1, ty1, tz1; + int x, y, z; + int dx, dy, dz; +} opj_pi_iterator_t; + +/** @name Funciones generales */ +/*@{*/ +/* ----------------------------------------------------------------------- */ +/** +Create a packet iterator +@param volume Raw volume for which the packets will be listed +@param cp Coding parameters +@param tileno Number that identifies the tile for which to list the packets +@return Returns a packet iterator that points to the first packet of the tile +@see pi_destroy +*/ +opj_pi_iterator_t *pi_create(opj_volume_t * volume, opj_cp_t * cp, int tileno); + +/** +Destroy a packet iterator +@param pi Previously created packet iterator +@param cp Coding parameters +@param tileno Number that identifies the tile for which the packets were listed +@see pi_create +*/ +void pi_destroy(opj_pi_iterator_t *pi, opj_cp_t *cp, int tileno); + +/** +Modify the packet iterator to point to the next packet +@param pi Packet iterator to modify +@return Returns false if pi pointed to the last packet or else returns true +*/ +bool pi_next(opj_pi_iterator_t * pi); +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __PI_H */ diff --git a/src/lib/openjp3d/raw.c b/src/lib/openjp3d/raw.c index b6a58106..1457a66b 100644 --- a/src/lib/openjp3d/raw.c +++ b/src/lib/openjp3d/raw.c @@ -1,86 +1,86 @@ -/* - * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "opj_includes.h" - -/* -========================================================== - local functions -========================================================== -*/ - - -/* -========================================================== - RAW encoding interface -========================================================== -*/ - -opj_raw_t* raw_create() { - opj_raw_t *raw = (opj_raw_t*)opj_malloc(sizeof(opj_raw_t)); - return raw; -} - -void raw_destroy(opj_raw_t *raw) { - if(raw) { - opj_free(raw); - } -} - -int raw_numbytes(opj_raw_t *raw) { - return raw->bp - raw->start; -} - -void raw_init_dec(opj_raw_t *raw, unsigned char *bp, int len) { - raw->start = bp; - raw->lenmax = len; - raw->len = 0; - raw->c = 0; - raw->ct = 0; -} - -int raw_decode(opj_raw_t *raw) { - int d; - if (raw->ct == 0) { - raw->ct = 8; - if (raw->len == raw->lenmax) { - raw->c = 0xff; - } else { - if (raw->c == 0xff) { - raw->ct = 7; - } - raw->c = *(raw->start + raw->len); - raw->len++; - } - } - raw->ct--; - d = (raw->c >> raw->ct) & 0x01; - - return d; -} - +/* + * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opj_includes.h" + +/* +========================================================== + local functions +========================================================== +*/ + + +/* +========================================================== + RAW encoding interface +========================================================== +*/ + +opj_raw_t* raw_create() { + opj_raw_t *raw = (opj_raw_t*)opj_malloc(sizeof(opj_raw_t)); + return raw; +} + +void raw_destroy(opj_raw_t *raw) { + if(raw) { + opj_free(raw); + } +} + +int raw_numbytes(opj_raw_t *raw) { + return raw->bp - raw->start; +} + +void raw_init_dec(opj_raw_t *raw, unsigned char *bp, int len) { + raw->start = bp; + raw->lenmax = len; + raw->len = 0; + raw->c = 0; + raw->ct = 0; +} + +int raw_decode(opj_raw_t *raw) { + int d; + if (raw->ct == 0) { + raw->ct = 8; + if (raw->len == raw->lenmax) { + raw->c = 0xff; + } else { + if (raw->c == 0xff) { + raw->ct = 7; + } + raw->c = *(raw->start + raw->len); + raw->len++; + } + } + raw->ct--; + d = (raw->c >> raw->ct) & 0x01; + + return d; +} + diff --git a/src/lib/openjp3d/raw.h b/src/lib/openjp3d/raw.h index 55e889da..c452804d 100644 --- a/src/lib/openjp3d/raw.h +++ b/src/lib/openjp3d/raw.h @@ -1,99 +1,99 @@ -/* - * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __RAW_H -#define __RAW_H -/** -@file raw.h -@brief Implementation of operations for raw encoding (RAW) - -The functions in RAW.C have for goal to realize the operation of raw encoding linked -with the corresponding mode switch. -*/ - -/** @defgroup RAW RAW - Implementation of operations for raw encoding */ -/*@{*/ - -/** -RAW encoding operations -*/ -typedef struct opj_raw { -/** Temporary buffer where bits are coded or decoded */ - unsigned char c; -/** Number of bits already read or free to write */ - unsigned int ct; -/** Maximum length to decode */ - unsigned int lenmax; -/** Length decoded */ - unsigned int len; -/** Pointer to the current position in the buffer */ - unsigned char *bp; -/** Pointer to the start of the buffer */ - unsigned char *start; -/** Pointer to the end of the buffer */ - unsigned char *end; -} opj_raw_t; - -/** @name Funciones generales */ -/*@{*/ -/* ----------------------------------------------------------------------- */ -/** -Create a new RAW handle -@return Returns a new RAW handle if successful, returns NULL otherwise -*/ -opj_raw_t* raw_create(void); -/** -Destroy a previously created RAW handle -@param raw RAW handle to destroy -*/ -void raw_destroy(opj_raw_t *raw); -/** -Return the number of bytes written/read since initialisation -@param raw RAW handle to destroy -@return Returns the number of bytes already encoded -*/ -int raw_numbytes(opj_raw_t *raw); -/** -Initialize the decoder -@param raw RAW handle -@param bp Pointer to the start of the buffer from which the bytes will be read -@param len Length of the input buffer -*/ -void raw_init_dec(opj_raw_t *raw, unsigned char *bp, int len); -/** -Decode a symbol using raw-decoder. Cfr p.506 TAUBMAN -@param raw RAW handle -@return Returns the decoded symbol (0 or 1) -*/ -int raw_decode(opj_raw_t *raw); -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __RAW_H */ +/* + * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __RAW_H +#define __RAW_H +/** +@file raw.h +@brief Implementation of operations for raw encoding (RAW) + +The functions in RAW.C have for goal to realize the operation of raw encoding linked +with the corresponding mode switch. +*/ + +/** @defgroup RAW RAW - Implementation of operations for raw encoding */ +/*@{*/ + +/** +RAW encoding operations +*/ +typedef struct opj_raw { +/** Temporary buffer where bits are coded or decoded */ + unsigned char c; +/** Number of bits already read or free to write */ + unsigned int ct; +/** Maximum length to decode */ + unsigned int lenmax; +/** Length decoded */ + unsigned int len; +/** Pointer to the current position in the buffer */ + unsigned char *bp; +/** Pointer to the start of the buffer */ + unsigned char *start; +/** Pointer to the end of the buffer */ + unsigned char *end; +} opj_raw_t; + +/** @name Funciones generales */ +/*@{*/ +/* ----------------------------------------------------------------------- */ +/** +Create a new RAW handle +@return Returns a new RAW handle if successful, returns NULL otherwise +*/ +opj_raw_t* raw_create(void); +/** +Destroy a previously created RAW handle +@param raw RAW handle to destroy +*/ +void raw_destroy(opj_raw_t *raw); +/** +Return the number of bytes written/read since initialisation +@param raw RAW handle to destroy +@return Returns the number of bytes already encoded +*/ +int raw_numbytes(opj_raw_t *raw); +/** +Initialize the decoder +@param raw RAW handle +@param bp Pointer to the start of the buffer from which the bytes will be read +@param len Length of the input buffer +*/ +void raw_init_dec(opj_raw_t *raw, unsigned char *bp, int len); +/** +Decode a symbol using raw-decoder. Cfr p.506 TAUBMAN +@param raw RAW handle +@return Returns the decoded symbol (0 or 1) +*/ +int raw_decode(opj_raw_t *raw); +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __RAW_H */ diff --git a/src/lib/openjp3d/t1.c b/src/lib/openjp3d/t1.c index 6a389864..8ba8ee5e 100644 --- a/src/lib/openjp3d/t1.c +++ b/src/lib/openjp3d/t1.c @@ -1,1181 +1,1181 @@ -/* - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "opj_includes.h" - -/** @defgroup T1 T1 - Implementation of the tier-1 coding */ -/*@{*/ - -/** @name Local static functions */ -/*@{*/ - -static int t1_getctxno_zc(opj_t1_t *t1, int f, int orient); -static int t1_getctxno_sc(opj_t1_t *t1, int f); -static int t1_getctxno_mag(opj_t1_t *t1, int f); -static int t1_getspb(opj_t1_t *t1, int f); -static int t1_getnmsedec_sig(opj_t1_t *t1, int x, int bitpos); -static int t1_getnmsedec_ref(opj_t1_t *t1, int x, int bitpos); -static void t1_updateflags(int *fp, int s); -/** -Encode significant pass -*/ -static void t1_enc_sigpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int bpno, int one, int *nmsedec, char type, int vsc); -/** -Decode significant pass -*/ -static void t1_dec_sigpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int oneplushalf, char type, int vsc); -/** -Encode significant pass -*/ -static void t1_enc_sigpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, char type, int cblksty); -/** -Decode significant pass -*/ -static void t1_dec_sigpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, char type, int cblksty); -/** -Encode refinement pass -*/ -static void t1_enc_refpass_step(opj_t1_t *t1, int *fp, int *dp, int bpno, int one, int *nmsedec, char type, int vsc); -/** -Decode refinement pass -*/ -static void t1_dec_refpass_step(opj_t1_t *t1, int *fp, int *dp, int poshalf, int neghalf, char type, int vsc); -/** -Encode refinement pass -*/ -static void t1_enc_refpass(opj_t1_t *t1, int w, int h, int l, int bpno, int *nmsedec, char type, int cblksty); -/** -Decode refinement pass -*/ -static void t1_dec_refpass(opj_t1_t *t1, int w, int h, int l, int bpno, char type, int cblksty); -/** -Encode clean-up pass -*/ -static void t1_enc_clnpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int bpno, int one, int *nmsedec, int partial, int vsc); -/** -Decode clean-up pass -*/ -static void t1_dec_clnpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int oneplushalf, int partial, int vsc); -/** -Encode clean-up pass -*/ -static void t1_enc_clnpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, int cblksty); -/** -Decode clean-up pass -*/ -static void t1_dec_clnpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, int cblksty); -/** -Encode 1 code-block -@param t1 T1 handle -@param cblk Code-block coding parameters -@param orient -@param compno Component number -@param level -@param dwtid -@param stepsize -@param cblksty Code-block style -@param numcomps -@param tile -*/ -static void t1_encode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int compno, int level[3], int dwtid[3], double stepsize, int cblksty, int numcomps, opj_tcd_tile_t * tile); -/** -Decode 1 code-block -@param t1 T1 handle -@param cblk Code-block coding parameters -@param orient -@param roishift Region of interest shifting value -@param cblksty Code-block style -*/ -static void t1_decode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int roishift, int cblksty); - -static int t1_init_ctxno_zc(int f, int orient); -static int t1_init_ctxno_sc(int f); -static int t1_init_ctxno_mag(int f); -static int t1_init_spb(int f); -/** -Initialize the look-up tables of the Tier-1 coder/decoder -@param t1 T1 handle -*/ -static void t1_init_luts(opj_t1_t *t1); - -/*@}*/ - -/*@}*/ - -/* ----------------------------------------------------------------------- */ - -static int t1_getctxno_zc(opj_t1_t *t1, int f, int orient) { - return t1->lut_ctxno_zc[(orient << 8) | (f & T1_SIG_OTH)]; -} - -static int t1_getctxno_sc(opj_t1_t *t1, int f) { - return t1->lut_ctxno_sc[(f & (T1_SIG_PRIM | T1_SGN)) >> 4]; -} - -static int t1_getctxno_mag(opj_t1_t *t1, int f) { - return t1->lut_ctxno_mag[(f & T1_SIG_OTH) | (((f & T1_REFINE) != 0) << 11)]; -} - -static int t1_getspb(opj_t1_t *t1, int f) { - return t1->lut_spb[(f & (T1_SIG_PRIM | T1_SGN)) >> 4]; -} - -static int t1_getnmsedec_sig(opj_t1_t *t1, int x, int bitpos) { - if (bitpos > T1_NMSEDEC_FRACBITS) { - return t1->lut_nmsedec_sig[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)]; - } - - return t1->lut_nmsedec_sig0[x & ((1 << T1_NMSEDEC_BITS) - 1)]; -} - -static int t1_getnmsedec_ref(opj_t1_t *t1, int x, int bitpos) { - if (bitpos > T1_NMSEDEC_FRACBITS) { - return t1->lut_nmsedec_ref[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)]; - } - - return t1->lut_nmsedec_ref0[x & ((1 << T1_NMSEDEC_BITS) - 1)]; -} - -static void t1_updateflags(int *fp, int s) { - int *np = fp - (T1_MAXCBLKW + 2); - int *sp = fp + (T1_MAXCBLKW + 2); - np[-1] |= T1_SIG_SE; - np[1] |= T1_SIG_SW; - sp[-1] |= T1_SIG_NE; - sp[1] |= T1_SIG_NW; - *np |= T1_SIG_S; - *sp |= T1_SIG_N; - fp[-1] |= T1_SIG_E; - fp[1] |= T1_SIG_W; - if (s) { - *np |= T1_SGN_S; - *sp |= T1_SGN_N; - fp[-1] |= T1_SGN_E; - fp[1] |= T1_SGN_W; - } -} - -static void t1_enc_sigpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int bpno, int one, int *nmsedec, char type, int vsc) { - int v, flag; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - flag = vsc ? ((*fp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*fp); - if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) { - v = int_abs(*dp) & one ? 1 : 0; - if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ - mqc_setcurctx(mqc, t1_getctxno_zc(t1, flag, orient)); /* ESSAI */ - mqc_bypass_enc(mqc, v); - } else { - mqc_setcurctx(mqc, t1_getctxno_zc(t1, flag, orient)); - mqc_encode(mqc, v); - } - if (v) { - v = *dp < 0 ? 1 : 0; - *nmsedec += t1_getnmsedec_sig(t1, int_abs(*dp), bpno + T1_NMSEDEC_FRACBITS); - if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ - mqc_setcurctx(mqc, t1_getctxno_sc(t1, flag)); /* ESSAI */ - mqc_bypass_enc(mqc, v); - } else { - mqc_setcurctx(mqc, t1_getctxno_sc(t1, flag)); - mqc_encode(mqc, v ^ t1_getspb(t1, flag)); - } - t1_updateflags(fp, v); - *fp |= T1_SIG; - } - *fp |= T1_VISIT; - } -} - -static void t1_dec_sigpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int oneplushalf, char type, int vsc) { - int v, flag; - - opj_raw_t *raw = t1->raw; /* RAW component */ - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - flag = vsc ? ((*fp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*fp); - if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) { - if (type == T1_TYPE_RAW) { - if (raw_decode(raw)) { - v = raw_decode(raw); /* ESSAI */ - *dp = v ? -oneplushalf : oneplushalf; - t1_updateflags(fp, v); - *fp |= T1_SIG; - } - } else { - mqc_setcurctx(mqc, t1_getctxno_zc(t1, flag, orient)); - if (mqc_decode(mqc)) { - mqc_setcurctx(mqc, t1_getctxno_sc(t1, flag)); - v = mqc_decode(mqc) ^ t1_getspb(t1, flag); - *dp = v ? -oneplushalf : oneplushalf; - t1_updateflags(fp, v); - *fp |= T1_SIG; - } - } - *fp |= T1_VISIT; - } -} /* VSC and BYPASS by Antonin */ - -static void t1_enc_sigpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, char type, int cblksty) { - int i, j, k, m, one, vsc; - *nmsedec = 0; - one = 1 << (bpno + T1_NMSEDEC_FRACBITS); - for (m = 0; m < l; m++) { - for (k = 0; k < h; k += 4) { - for (i = 0; i < w; i++) { - for (j = k; j < k + 4 && j < h; j++) { - vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; - t1_enc_sigpass_step(t1, &t1->flags[1 + m][1 + j][1 + i], &t1->data[m][j][i], orient, bpno, one, nmsedec, type, vsc); - } - } - } - } -} - -static void t1_dec_sigpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, char type, int cblksty) { - int i, j, k, m, one, half, oneplushalf, vsc; - one = 1 << bpno; - half = one >> 1; - oneplushalf = one | half; - for (m = 0; m < l; m++) { - for (k = 0; k < h; k += 4) { - for (i = 0; i < w; i++) { - for (j = k; j < k + 4 && j < h; j++) { - vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; - t1_dec_sigpass_step(t1, &t1->flags[1 + m][1 + j][1 + i], &t1->data[m][j][i], orient, oneplushalf, type, vsc); - } - } - } - } -} /* VSC and BYPASS by Antonin */ - -static void t1_enc_refpass_step(opj_t1_t *t1, int *fp, int *dp, int bpno, int one, int *nmsedec, char type, int vsc) { - int v, flag; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - flag = vsc ? ((*fp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*fp); - if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) { - *nmsedec += t1_getnmsedec_ref(t1, int_abs(*dp), bpno + T1_NMSEDEC_FRACBITS); - v = int_abs(*dp) & one ? 1 : 0; - if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ - mqc_setcurctx(mqc, t1_getctxno_mag(t1, flag)); /* ESSAI */ - mqc_bypass_enc(mqc, v); - } else { - mqc_setcurctx(mqc, t1_getctxno_mag(t1, flag)); - mqc_encode(mqc, v); - } - *fp |= T1_REFINE; - } -} - -static void t1_dec_refpass_step(opj_t1_t *t1, int *fp, int *dp, int poshalf, int neghalf, char type, int vsc) { - int v, t, flag; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - opj_raw_t *raw = t1->raw; /* RAW component */ - - flag = vsc ? ((*fp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*fp); - if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) { - if (type == T1_TYPE_RAW) { - mqc_setcurctx(mqc, t1_getctxno_mag(t1, flag)); /* ESSAI */ - v = raw_decode(raw); - } else { - mqc_setcurctx(mqc, t1_getctxno_mag(t1, flag)); - v = mqc_decode(mqc); - } - t = v ? poshalf : neghalf; - *dp += *dp < 0 ? -t : t; - *fp |= T1_REFINE; - } -} /* VSC and BYPASS by Antonin */ - -static void t1_enc_refpass(opj_t1_t *t1, int w, int h, int l, int bpno, int *nmsedec, char type, int cblksty) { - int i, j, k, m, one, vsc; - *nmsedec = 0; - one = 1 << (bpno + T1_NMSEDEC_FRACBITS); - for (m = 0; m < l; m++) { - for (k = 0; k < h; k += 4) { - for (i = 0; i < w; i++) { - for (j = k; j < k + 4 && j < h; j++) { - vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; - t1_enc_refpass_step(t1, &t1->flags[1 + m][1 + j][1 + i], &t1->data[m][j][i], bpno, one, nmsedec, type, vsc); - } - } - } - } -} - -static void t1_dec_refpass(opj_t1_t *t1, int w, int h, int l, int bpno, char type, int cblksty) { - int i, j, k, m, one, poshalf, neghalf; - int vsc; - one = 1 << bpno; - poshalf = one >> 1; - neghalf = bpno > 0 ? -poshalf : -1; - for (m = 0; m < l; m++) { - for (k = 0; k < h; k += 4) { - for (i = 0; i < w; i++) { - for (j = k; j < k + 4 && j < h; j++) { - vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; - t1_dec_refpass_step(t1, &t1->flags[1 + m][1 + j][1 + i], &t1->data[m][j][i], poshalf, neghalf, type, vsc); - } - } - } - } -} /* VSC and BYPASS by Antonin */ - -static void t1_enc_clnpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int bpno, int one, int *nmsedec, int partial, int vsc) { - int v, flag; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - flag = vsc ? ((*fp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*fp); - if (partial) { - goto LABEL_PARTIAL; - } - if (!(*fp & (T1_SIG | T1_VISIT))) { - mqc_setcurctx(mqc, t1_getctxno_zc(t1, flag, orient)); - v = int_abs(*dp) & one ? 1 : 0; - mqc_encode(mqc, v); - if (v) { -LABEL_PARTIAL: - *nmsedec += t1_getnmsedec_sig(t1, int_abs(*dp), bpno + T1_NMSEDEC_FRACBITS); - mqc_setcurctx(mqc, t1_getctxno_sc(t1, flag)); - v = *dp < 0 ? 1 : 0; - mqc_encode(mqc, v ^ t1_getspb(t1, flag)); - t1_updateflags(fp, v); - *fp |= T1_SIG; - } - } - *fp &= ~T1_VISIT; -} - -static void t1_dec_clnpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int oneplushalf, int partial, int vsc) { - int v, flag; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - flag = vsc ? ((*fp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*fp); - if (partial) { - goto LABEL_PARTIAL; - } - if (!(flag & (T1_SIG | T1_VISIT))) { - mqc_setcurctx(mqc, t1_getctxno_zc(t1, flag, orient)); - if (mqc_decode(mqc)) { -LABEL_PARTIAL: - mqc_setcurctx(mqc, t1_getctxno_sc(t1, flag)); - v = mqc_decode(mqc) ^ t1_getspb(t1, flag); - *dp = v ? -oneplushalf : oneplushalf; - t1_updateflags(fp, v); - *fp |= T1_SIG; - } - } - *fp &= ~T1_VISIT; -} /* VSC and BYPASS by Antonin */ - -static void t1_enc_clnpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, int cblksty) { - int i, j, k, m, one, agg, runlen, vsc; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - *nmsedec = 0; - one = 1 << (bpno + T1_NMSEDEC_FRACBITS); - for (m = 0; m < l; m++) { - for (k = 0; k < h; k += 4) { - for (i = 0; i < w; i++) { - if (k + 3 < h) { - if (cblksty & J3D_CCP_CBLKSTY_VSC) { - agg = !(t1->flags[1 + m][1 + k][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) - || t1->flags[1 + m][1 + k + 1][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) - || t1->flags[1 + m][1 + k + 2][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) - || (t1->flags[1 + m][1 + k + 3][1 + i] - & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) & (T1_SIG | T1_VISIT | T1_SIG_OTH)); - } else { - agg = !(t1->flags[1 + m][1 + k][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) - || t1->flags[1 + m][1 + k + 1][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) - || t1->flags[1 + m][1 + k + 2][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) - || t1->flags[1 + m][1 + k + 3][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH)); - } - } else { - agg = 0; - } - if (agg) { - for (runlen = 0; runlen < 4; runlen++) { - if (int_abs(t1->data[m][k + runlen][i]) & one) - break; - } - mqc_setcurctx(mqc, T1_CTXNO_AGG); - mqc_encode(mqc, runlen != 4); - if (runlen == 4) { - continue; - } - mqc_setcurctx(mqc, T1_CTXNO_UNI); - mqc_encode(mqc, runlen >> 1); - mqc_encode(mqc, runlen & 1); - } else { - runlen = 0; - } - for (j = k + runlen; j < k + 4 && j < h; j++) { - vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; - t1_enc_clnpass_step(t1, &(t1->flags[1 + m][1 + j][1 + i]), &(t1->data[m][j][i]), orient, bpno, one, nmsedec, agg && (j == k + runlen), vsc); - } - } - } - } -} - -static void t1_dec_clnpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, int cblksty) { - int i, j, k, m, one, half, oneplushalf, agg, runlen, vsc; - int segsym = cblksty & J3D_CCP_CBLKSTY_SEGSYM; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - one = 1 << bpno; - half = one >> 1; - oneplushalf = one | half; - for (m = 0; m < l; m++) { - for (k = 0; k < h; k += 4) { - for (i = 0; i < w; i++) { - if (k + 3 < h) { - if (cblksty & J3D_CCP_CBLKSTY_VSC) { - agg = !(t1->flags[1 + m][1 + k][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) - || t1->flags[1 + m][1 + k + 1][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) - || t1->flags[1 + m][1 + k + 2][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) - || (t1->flags[1 + m][1 + k + 3][1 + i] - & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) & (T1_SIG | T1_VISIT | T1_SIG_OTH)); - } else { - agg = !(t1->flags[1 + m][1 + k][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) - || t1->flags[1 + m][1 + k + 1][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) - || t1->flags[1 + m][1 + k + 2][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) - || t1->flags[1 + m][1 + k + 3][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH)); - } - } else { - agg = 0; - } - if (agg) { - mqc_setcurctx(mqc, T1_CTXNO_AGG); - if (!mqc_decode(mqc)) { - continue; - } - mqc_setcurctx(mqc, T1_CTXNO_UNI); - runlen = mqc_decode(mqc); - runlen = (runlen << 1) | mqc_decode(mqc); - } else { - runlen = 0; - } - for (j = k + runlen; j < k + 4 && j < h; j++) { - vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; - t1_dec_clnpass_step(t1, &t1->flags[1 + m][1 + j][1 + i], &t1->data[m][j][i], orient, oneplushalf, agg && (j == k + runlen), vsc); - } - } - } - } - if (segsym) { - int v = 0; - mqc_setcurctx(mqc, T1_CTXNO_UNI); - v = mqc_decode(mqc); - v = (v << 1) | mqc_decode(mqc); - v = (v << 1) | mqc_decode(mqc); - v = (v << 1) | mqc_decode(mqc); - /* - if (v!=0xa) { - opj_event_msg(t1->cinfo, EVT_WARNING, "Bad segmentation symbol %x\n", v); - } - */ - } -} /* VSC and BYPASS by Antonin */ - - -static void t1_encode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int compno, int level[3], int dwtid[3], double stepsize, int cblksty, int numcomps, opj_tcd_tile_t * tile) { - int i, j, k; - int w, h, l; - int passno; - int bpno, passtype; - int max; - int nmsedec = 0; - double cumwmsedec = 0; - char type = T1_TYPE_MQ; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - w = cblk->x1 - cblk->x0; - h = cblk->y1 - cblk->y0; - l = cblk->z1 - cblk->z0; - - max = 0; - for (k = 0; k < l; k++) { - for (j = 0; j < h; j++) { - for (i = 0; i < w; i++) { - max = int_max(max, int_abs(t1->data[k][j][i])); - } - } - } - for (k = 0; k <= l; k++) { - for (j = 0; j <= h; j++) { - for (i = 0; i <= w; i++) { - t1->flags[k][j][i] = 0; - } - } - } - - cblk->numbps = max ? (int_floorlog2(max) + 1) - T1_NMSEDEC_FRACBITS : 0; - - bpno = cblk->numbps - 1; - passtype = 2; - - mqc_reset_enc(mqc); - mqc_init_enc(mqc, cblk->data); - - for (passno = 0; bpno >= 0; passno++) { - opj_tcd_pass_t *pass = &cblk->passes[passno]; - int correction = 3; - double tmpwmsedec; - type = ((bpno < (cblk->numbps - 4)) && (passtype < 2) && (cblksty & J3D_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ; - /*fprintf(stdout,"passno %d passtype %d w %d h %d l %d bpno %d orient %d type %d cblksty %d\n",passno,passtype,w,h,l,bpno,orient,type,cblksty);*/ - - switch (passtype) { - case 0: - t1_enc_sigpass(t1, w, h, l, bpno, orient, &nmsedec, type, cblksty); - break; - case 1: - t1_enc_refpass(t1, w, h, l, bpno, &nmsedec, type, cblksty); - break; - case 2: - /*fprintf(stdout,"w %d h %d l %d bpno %d orient %d \n",w,h,l,bpno,orient);*/ - t1_enc_clnpass(t1, w, h, l, bpno, orient, &nmsedec, cblksty); - /* code switch SEGMARK (i.e. SEGSYM) */ - if (cblksty & J3D_CCP_CBLKSTY_SEGSYM) - mqc_segmark_enc(mqc); - break; - } - - /* fixed_quality */ - tmpwmsedec = t1_getwmsedec(nmsedec, compno, level, orient, bpno, stepsize, numcomps, dwtid); - cumwmsedec += tmpwmsedec; - tile->distotile += tmpwmsedec; - - /* Code switch "RESTART" (i.e. TERMALL) */ - if ((cblksty & J3D_CCP_CBLKSTY_TERMALL) && !((passtype == 2) && (bpno - 1 < 0))) { - if (type == T1_TYPE_RAW) { - mqc_flush(mqc); - correction = 1; - /* correction = mqc_bypass_flush_enc(); */ - } else { /* correction = mqc_restart_enc(); */ - mqc_flush(mqc); - correction = 1; - } - pass->term = 1; - } else { - if (((bpno < (cblk->numbps - 4) && (passtype > 0)) - || ((bpno == (cblk->numbps - 4)) && (passtype == 2))) && (cblksty & J3D_CCP_CBLKSTY_LAZY)) { - if (type == T1_TYPE_RAW) { - mqc_flush(mqc); - correction = 1; - /* correction = mqc_bypass_flush_enc(); */ - } else { /* correction = mqc_restart_enc(); */ - mqc_flush(mqc); - correction = 1; - } - pass->term = 1; - } else { - pass->term = 0; - } - } - - if (++passtype == 3) { - passtype = 0; - bpno--; - } - - if (pass->term && bpno > 0) { - type = ((bpno < (cblk->numbps - 4)) && (passtype < 2) && (cblksty & J3D_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ; - if (type == T1_TYPE_RAW) - mqc_bypass_init_enc(mqc); - else - mqc_restart_init_enc(mqc); - } - - pass->distortiondec = cumwmsedec; - pass->rate = mqc_numbytes(mqc) + correction; /* FIXME */ - pass->len = pass->rate - (passno == 0 ? 0 : cblk->passes[passno - 1].rate); - - /* Code-switch "RESET" */ - if (cblksty & J3D_CCP_CBLKSTY_RESET) - mqc_reset_enc(mqc); - } - - /* Code switch "ERTERM" (i.e. PTERM) */ - if (cblksty & J3D_CCP_CBLKSTY_PTERM) - mqc_erterm_enc(mqc); - else /* Default coding */ if (!(cblksty & J3D_CCP_CBLKSTY_LAZY)) - mqc_flush(mqc); - - cblk->totalpasses = passno; -} - -static void t1_decode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int roishift, int cblksty) { - int i, j, k, w, h, l; - int bpno, passtype; - int segno, passno; - char type = T1_TYPE_MQ; /* BYPASS mode */ - - opj_raw_t *raw = t1->raw; /* RAW component */ - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - w = cblk->x1 - cblk->x0; - h = cblk->y1 - cblk->y0; - l = cblk->z1 - cblk->z0; - - for (k = 0; k < l; k++) { - for (j = 0; j < h; j++) { - for (i = 0; i < w; i++) { - t1->data[k][j][i] = 0; - } - } - } - - for (k = 0; k <= l; k++) { - for (j = 0; j <= h; j++) { - for (i = 0; i <= w; i++) { - t1->flags[k][j][i] = 0; - } - } - } - - bpno = roishift + cblk->numbps - 1; - passtype = 2; - - mqc_reset_enc(mqc); - - for (segno = 0; segno < cblk->numsegs; segno++) { - opj_tcd_seg_t *seg = &cblk->segs[segno]; - - /* BYPASS mode */ - type = ((bpno <= (cblk->numbps - 1) - 4) && (passtype < 2) && (cblksty & J3D_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ; - if (type == T1_TYPE_RAW) { - raw_init_dec(raw, seg->data, seg->len); - } else { - mqc_init_dec(mqc, seg->data, seg->len); - } - - for (passno = 0; passno < seg->numpasses; passno++) { - switch (passtype) { - case 0: - t1_dec_sigpass(t1, w, h, l, bpno+1, orient, type, cblksty); - break; - case 1: - t1_dec_refpass(t1, w, h, l, bpno+1, type, cblksty); - break; - case 2: - t1_dec_clnpass(t1, w, h, l, bpno+1, orient, cblksty); - break; - } - - if ((cblksty & J3D_CCP_CBLKSTY_RESET) && type == T1_TYPE_MQ) { - mqc_reset_enc(mqc); - } - if (++passtype == 3) { - passtype = 0; - bpno--; - } - } - } -} - -static int t1_init_ctxno_zc(int f, int orient) { - int h, v, d, n, t, hv; - n = 0; - h = ((f & T1_SIG_W) != 0) + ((f & T1_SIG_E) != 0); - v = ((f & T1_SIG_N) != 0) + ((f & T1_SIG_S) != 0); - d = ((f & T1_SIG_NW) != 0) + ((f & T1_SIG_NE) != 0) + ((f & T1_SIG_SE) != 0) + ((f & T1_SIG_SW) != 0); - - switch (orient) { - case 2: - t = h; - h = v; - v = t; - case 0: - case 1: - if (!h) { - if (!v) { - if (!d) - n = 0; - else if (d == 1) - n = 1; - else - n = 2; - } else if (v == 1) { - n = 3; - } else { - n = 4; - } - } else if (h == 1) { - if (!v) { - if (!d) - n = 5; - else - n = 6; - } else { - n = 7; - } - } else - n = 8; - break; - case 3: - hv = h + v; - if (!d) { - if (!hv) { - n = 0; - } else if (hv == 1) { - n = 1; - } else { - n = 2; - } - } else if (d == 1) { - if (!hv) { - n = 3; - } else if (hv == 1) { - n = 4; - } else { - n = 5; - } - } else if (d == 2) { - if (!hv) { - n = 6; - } else { - n = 7; - } - } else { - n = 8; - } - break; - } - - return (T1_CTXNO_ZC + n); -} - -static int t1_init_ctxno_sc(int f) { - int hc, vc, n; - n = 0; - - hc = int_min(((f & (T1_SIG_E | T1_SGN_E)) == - T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W), - 1) - int_min(((f & (T1_SIG_E | T1_SGN_E)) == - (T1_SIG_E | T1_SGN_E)) + - ((f & (T1_SIG_W | T1_SGN_W)) == - (T1_SIG_W | T1_SGN_W)), 1); - - vc = int_min(((f & (T1_SIG_N | T1_SGN_N)) == - T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S), - 1) - int_min(((f & (T1_SIG_N | T1_SGN_N)) == - (T1_SIG_N | T1_SGN_N)) + - ((f & (T1_SIG_S | T1_SGN_S)) == - (T1_SIG_S | T1_SGN_S)), 1); - - if (hc < 0) { - hc = -hc; - vc = -vc; - } - if (!hc) { - if (vc == -1) - n = 1; - else if (!vc) - n = 0; - else - n = 1; - } else if (hc == 1) { - if (vc == -1) - n = 2; - else if (!vc) - n = 3; - else - n = 4; - } - - return (T1_CTXNO_SC + n); -} - -static int t1_init_ctxno_mag(int f) { - int n; - if (!(f & T1_REFINE)) - n = (f & (T1_SIG_OTH)) ? 1 : 0; - else - n = 2; - - return (T1_CTXNO_MAG + n); -} - -static int t1_init_spb(int f) { - int hc, vc, n; - - hc = int_min(((f & (T1_SIG_E | T1_SGN_E)) == - T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W), - 1) - int_min(((f & (T1_SIG_E | T1_SGN_E)) == - (T1_SIG_E | T1_SGN_E)) + - ((f & (T1_SIG_W | T1_SGN_W)) == - (T1_SIG_W | T1_SGN_W)), 1); - - vc = int_min(((f & (T1_SIG_N | T1_SGN_N)) == - T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S), - 1) - int_min(((f & (T1_SIG_N | T1_SGN_N)) == - (T1_SIG_N | T1_SGN_N)) + - ((f & (T1_SIG_S | T1_SGN_S)) == - (T1_SIG_S | T1_SGN_S)), 1); - - if (!hc && !vc) - n = 0; - else - n = (!(hc > 0 || (!hc && vc > 0))); - - return n; -} - -static void t1_init_luts(opj_t1_t *t1) { - int i, j; - double u, v, t; - for (j = 0; j < 4; j++) { - for (i = 0; i < 256; ++i) { - t1->lut_ctxno_zc[(j << 8) | i] = t1_init_ctxno_zc(i, j); - } - } - for (i = 0; i < 256; i++) { - t1->lut_ctxno_sc[i] = t1_init_ctxno_sc(i << 4); - } - for (j = 0; j < 2; j++) { - for (i = 0; i < 2048; ++i) { - t1->lut_ctxno_mag[(j << 11) + i] = t1_init_ctxno_mag((j ? T1_REFINE : 0) | i); - } - } - for (i = 0; i < 256; ++i) { - t1->lut_spb[i] = t1_init_spb(i << 4); - } - /* FIXME FIXME FIXME */ - /* fprintf(stdout,"nmsedec luts:\n"); */ - for (i = 0; i < (1 << T1_NMSEDEC_BITS); i++) { - t = i / pow(2, T1_NMSEDEC_FRACBITS); - u = t; - v = t - 1.5; - t1->lut_nmsedec_sig[i] = - int_max(0, - (int) (floor((u * u - v * v) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0)); - t1->lut_nmsedec_sig0[i] = - int_max(0, - (int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0)); - u = t - 1.0; - if (i & (1 << (T1_NMSEDEC_BITS - 1))) { - v = t - 1.5; - } else { - v = t - 0.5; - } - t1->lut_nmsedec_ref[i] = - int_max(0, - (int) (floor((u * u - v * v) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0)); - t1->lut_nmsedec_ref0[i] = - int_max(0, - (int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0)); - } -} - -/* ----------------------------------------------------------------------- */ - -opj_t1_t* t1_create(opj_common_ptr cinfo) { - opj_t1_t *t1 = (opj_t1_t*)opj_malloc(sizeof(opj_t1_t)); - if(t1) { - t1->cinfo = cinfo; - /* create MQC and RAW handles */ - t1->mqc = mqc_create(); - t1->raw = raw_create(); - /* initialize the look-up tables of the Tier-1 coder/decoder */ - t1_init_luts(t1); - } - return t1; -} - -void t1_destroy(opj_t1_t *t1) { - if(t1) { - /* destroy MQC and RAW handles */ - mqc_destroy(t1->mqc); - raw_destroy(t1->raw); - /*opj_free(t1->data);*/ - /*opj_free(t1->flags);*/ - opj_free(t1); - } -} - -void t1_encode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) { - int compno, resno, bandno, precno, cblkno; - int x, y, z, i, j, k, orient; - int n=0; - int level[3]; - FILE *fid = NULL; -/* char filename[10];*/ - tile->distotile = 0; /* fixed_quality */ - - for (compno = 0; compno < tile->numcomps; compno++) { - opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; - - for (resno = 0; resno < tilec->numresolution[0]; resno++) { - opj_tcd_resolution_t *res = &tilec->resolutions[resno]; - - /* Weighted first order entropy - sprintf(filename,"res%d.txt",resno); - if ((fid = fopen(filename,"w")) == 0){ - fprintf(stdout,"Error while opening %s\n", filename); - exit(1); - } - */ - for (bandno = 0; bandno < res->numbands; bandno++) { - opj_tcd_band_t *band = &res->bands[bandno]; - for (precno = 0; precno < res->prctno[0] * res->prctno[1] * res->prctno[2]; precno++) { - opj_tcd_precinct_t *prc = &band->precincts[precno]; - - for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { - opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; - - /*fprintf(stdout,"Precno %d Cblkno %d \n",precno,cblkno);*/ - if (band->bandno == 0) { - x = cblk->x0 - band->x0; - y = cblk->y0 - band->y0; - z = cblk->z0 - band->z0; - } else if (band->bandno == 1) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = pres->x1 - pres->x0 + cblk->x0 - band->x0; - y = cblk->y0 - band->y0; - z = cblk->z0 - band->z0; - } else if (band->bandno == 2) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = cblk->x0 - band->x0; - y = pres->y1 - pres->y0 + cblk->y0 - band->y0; - z = cblk->z0 - band->z0; - } else if (band->bandno == 3) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = pres->x1 - pres->x0 + cblk->x0 - band->x0; - y = pres->y1 - pres->y0 + cblk->y0 - band->y0; - z = cblk->z0 - band->z0; - } else if (band->bandno == 4) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = cblk->x0 - band->x0; - y = cblk->y0 - band->y0; - z = pres->z1 - pres->z0 + cblk->z0 - band->z0; - } else if (band->bandno == 5) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = pres->x1 - pres->x0 + cblk->x0 - band->x0; - y = cblk->y0 - band->y0; - z = pres->z1 - pres->z0 + cblk->z0 - band->z0; - } else if (band->bandno == 6) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = cblk->x0 - band->x0; - y = pres->y1 - pres->y0 + cblk->y0 - band->y0; - z = pres->z1 - pres->z0 + cblk->z0 - band->z0; - } else if (band->bandno == 7) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = pres->x1 - pres->x0 + cblk->x0 - band->x0; - y = pres->y1 - pres->y0 + cblk->y0 - band->y0; - z = pres->z1 - pres->z0 + cblk->z0 - band->z0; - } - - if (tcp->tccps[compno].reversible == 1) { - for (k = 0; k < cblk->z1 - cblk->z0; k++) { - for (j = 0; j < cblk->y1 - cblk->y0; j++) { - for (i = 0; i < cblk->x1 - cblk->x0; i++) { - t1->data[k][j][i] = - tilec->data[(x + i) + (y + j) * (tilec->x1 - tilec->x0) + (z + k) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)] << T1_NMSEDEC_FRACBITS; -/*fprintf(fid," %d",t1->data[k][j][i]);*/ - } - } - } - } else if (tcp->tccps[compno].reversible == 0) { - for (k = 0; k < cblk->z1 - cblk->z0; k++) { - for (j = 0; j < cblk->y1 - cblk->y0; j++) { - for (i = 0; i < cblk->x1 - cblk->x0; i++) { - t1->data[k][j][i] = fix_mul( - tilec->data[(x + i) + (y + j) * (tilec->x1 - tilec->x0) + (z + k) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)], - 8192 * 8192 / ((int) floor(band->stepsize * 8192))) >> (13 - T1_NMSEDEC_FRACBITS); - } - } - } - } - - orient = band->bandno; /* FIXME */ - if (orient == 2) { - orient = 1; - } else if (orient == 1) { - orient = 2; - } - for (i = 0; i < 3; i++) - level[i] = tilec->numresolution[i] - 1 - resno; - /*fprintf(stdout,"t1_encode_cblk(t1, cblk, %d, %d, %d %d %d, %d, %f, %d, %d, tile);\n", orient, compno, level[0], level[1], level[2], tcp->tccps[compno].reversible, band->stepsize, tcp->tccps[compno].cblksty, tile->numcomps);*/ - t1_encode_cblk(t1, cblk, orient, compno, level, tcp->tccps[compno].dwtid, band->stepsize, tcp->tccps[compno].cblksty, tile->numcomps, tile); - - } /* cblkno */ - } /* precno */ -/*fprintf(fid,"\n");*/ - } /* bandno */ -/*fclose(fid);*/ - } /* resno */ - } /* compno */ -} - -void t1_decode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) { - int compno, resno, bandno, precno, cblkno; - - for (compno = 0; compno < tile->numcomps; compno++) { - opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; - - for (resno = 0; resno < tilec->numresolution[0]; resno++) { - opj_tcd_resolution_t *res = &tilec->resolutions[resno]; - - for (bandno = 0; bandno < res->numbands; bandno++) { - opj_tcd_band_t *band = &res->bands[bandno]; - - for (precno = 0; precno < res->prctno[0] * res->prctno[1] * res->prctno[2]; precno++) { - opj_tcd_precinct_t *prc = &band->precincts[precno]; - - for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { - int x, y, k, i, j, z, orient; - opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; - - orient = band->bandno; /* FIXME */ - if (orient == 2) { - orient = 1; - } else if (orient == 1) { - orient = 2; - } - - t1_decode_cblk(t1, cblk, orient, tcp->tccps[compno].roishift, tcp->tccps[compno].cblksty); - - if (band->bandno == 0) { - x = cblk->x0 - band->x0; - y = cblk->y0 - band->y0; - z = cblk->z0 - band->z0; - } else if (band->bandno == 1) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = pres->x1 - pres->x0 + cblk->x0 - band->x0; - y = cblk->y0 - band->y0; - z = cblk->z0 - band->z0; - } else if (band->bandno == 2) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = cblk->x0 - band->x0; - y = pres->y1 - pres->y0 + cblk->y0 - band->y0; - z = cblk->z0 - band->z0; - } else if (band->bandno == 3) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = pres->x1 - pres->x0 + cblk->x0 - band->x0; - y = pres->y1 - pres->y0 + cblk->y0 - band->y0; - z = cblk->z0 - band->z0; - } else if (band->bandno == 4) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = cblk->x0 - band->x0; - y = cblk->y0 - band->y0; - z = pres->z1 - pres->z0 + cblk->z0 - band->z0; - } else if (band->bandno == 5) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = pres->x1 - pres->x0 + cblk->x0 - band->x0; - y = cblk->y0 - band->y0; - z = pres->z1 - pres->z0 + cblk->z0 - band->z0; - } else if (band->bandno == 6) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = cblk->x0 - band->x0; - y = pres->y1 - pres->y0 + cblk->y0 - band->y0; - z = pres->z1 - pres->z0 + cblk->z0 - band->z0; - } else if (band->bandno == 7) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = pres->x1 - pres->x0 + cblk->x0 - band->x0; - y = pres->y1 - pres->y0 + cblk->y0 - band->y0; - z = pres->z1 - pres->z0 + cblk->z0 - band->z0; - } - - if (tcp->tccps[compno].roishift) { - int thresh, val, mag; - thresh = 1 << tcp->tccps[compno].roishift; - for (k = 0; k < cblk->z1 - cblk->z0; k++) { - for (j = 0; j < cblk->y1 - cblk->y0; j++) { - for (i = 0; i < cblk->x1 - cblk->x0; i++) { - val = t1->data[k][j][i]; - mag = int_abs(val); - if (mag >= thresh) { - mag >>= tcp->tccps[compno].roishift; - t1->data[k][j][i] = val < 0 ? -mag : mag; - } - } - } - } - } - - if (tcp->tccps[compno].reversible == 1) { - for (k = 0; k < cblk->z1 - cblk->z0; k++) { - for (j = 0; j < cblk->y1 - cblk->y0; j++) { - for (i = 0; i < cblk->x1 - cblk->x0; i++) { - int tmp = t1->data[k][j][i]; - tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0) + (z + k) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)] = tmp/2; - } - } - } - } else { /* if (tcp->tccps[compno].reversible == 0) */ - for (k = 0; k < cblk->z1 - cblk->z0; k++) { - for (j = 0; j < cblk->y1 - cblk->y0; j++) { - for (i = 0; i < cblk->x1 - cblk->x0; i++) { - double tmp = (double)(t1->data[k][j][i] * band->stepsize * 4096.0); - if (t1->data[k][j][i] >> 1 == 0) { - tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0) + (z + k) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)] = 0; - } else { - int tmp2 = ((int) (floor(fabs(tmp)))) + ((int) floor(fabs(tmp*2))%2); - tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0) + (z + k) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)] = ((tmp<0)?-tmp2:tmp2); - } - } - } - } - } - } /* cblkno */ - } /* precno */ - } /* bandno */ - } /* resno */ - } /* compno */ -} - - -/** mod fixed_quality */ -double t1_getwmsedec(int nmsedec, int compno, int level[3], int orient, int bpno, double stepsize, int numcomps, int dwtid[3]) { - double w1, w2, wmsedec; - - if (dwtid[0] == 1 || dwtid[1] == 1 || dwtid[2] == 1) { - w1 = (numcomps > 1) ? mct_getnorm_real(compno) : 1; - } else { - w1 = (numcomps > 1) ? mct_getnorm(compno) : 1; - } - w2 = dwt_getnorm(orient, level, dwtid); - - /*fprintf(stdout,"nmsedec %d level %d %d %d orient %d bpno %d stepsize %f \n",nmsedec ,level[0],level[1],level[2],orient,bpno,stepsize);*/ - wmsedec = w1 * w2 * stepsize * (1 << bpno); - wmsedec *= wmsedec * nmsedec / 8192.0; - - return wmsedec; -} -/** mod fixed_quality */ +/* + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opj_includes.h" + +/** @defgroup T1 T1 - Implementation of the tier-1 coding */ +/*@{*/ + +/** @name Local static functions */ +/*@{*/ + +static int t1_getctxno_zc(opj_t1_t *t1, int f, int orient); +static int t1_getctxno_sc(opj_t1_t *t1, int f); +static int t1_getctxno_mag(opj_t1_t *t1, int f); +static int t1_getspb(opj_t1_t *t1, int f); +static int t1_getnmsedec_sig(opj_t1_t *t1, int x, int bitpos); +static int t1_getnmsedec_ref(opj_t1_t *t1, int x, int bitpos); +static void t1_updateflags(int *fp, int s); +/** +Encode significant pass +*/ +static void t1_enc_sigpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int bpno, int one, int *nmsedec, char type, int vsc); +/** +Decode significant pass +*/ +static void t1_dec_sigpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int oneplushalf, char type, int vsc); +/** +Encode significant pass +*/ +static void t1_enc_sigpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, char type, int cblksty); +/** +Decode significant pass +*/ +static void t1_dec_sigpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, char type, int cblksty); +/** +Encode refinement pass +*/ +static void t1_enc_refpass_step(opj_t1_t *t1, int *fp, int *dp, int bpno, int one, int *nmsedec, char type, int vsc); +/** +Decode refinement pass +*/ +static void t1_dec_refpass_step(opj_t1_t *t1, int *fp, int *dp, int poshalf, int neghalf, char type, int vsc); +/** +Encode refinement pass +*/ +static void t1_enc_refpass(opj_t1_t *t1, int w, int h, int l, int bpno, int *nmsedec, char type, int cblksty); +/** +Decode refinement pass +*/ +static void t1_dec_refpass(opj_t1_t *t1, int w, int h, int l, int bpno, char type, int cblksty); +/** +Encode clean-up pass +*/ +static void t1_enc_clnpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int bpno, int one, int *nmsedec, int partial, int vsc); +/** +Decode clean-up pass +*/ +static void t1_dec_clnpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int oneplushalf, int partial, int vsc); +/** +Encode clean-up pass +*/ +static void t1_enc_clnpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, int cblksty); +/** +Decode clean-up pass +*/ +static void t1_dec_clnpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, int cblksty); +/** +Encode 1 code-block +@param t1 T1 handle +@param cblk Code-block coding parameters +@param orient +@param compno Component number +@param level +@param dwtid +@param stepsize +@param cblksty Code-block style +@param numcomps +@param tile +*/ +static void t1_encode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int compno, int level[3], int dwtid[3], double stepsize, int cblksty, int numcomps, opj_tcd_tile_t * tile); +/** +Decode 1 code-block +@param t1 T1 handle +@param cblk Code-block coding parameters +@param orient +@param roishift Region of interest shifting value +@param cblksty Code-block style +*/ +static void t1_decode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int roishift, int cblksty); + +static int t1_init_ctxno_zc(int f, int orient); +static int t1_init_ctxno_sc(int f); +static int t1_init_ctxno_mag(int f); +static int t1_init_spb(int f); +/** +Initialize the look-up tables of the Tier-1 coder/decoder +@param t1 T1 handle +*/ +static void t1_init_luts(opj_t1_t *t1); + +/*@}*/ + +/*@}*/ + +/* ----------------------------------------------------------------------- */ + +static int t1_getctxno_zc(opj_t1_t *t1, int f, int orient) { + return t1->lut_ctxno_zc[(orient << 8) | (f & T1_SIG_OTH)]; +} + +static int t1_getctxno_sc(opj_t1_t *t1, int f) { + return t1->lut_ctxno_sc[(f & (T1_SIG_PRIM | T1_SGN)) >> 4]; +} + +static int t1_getctxno_mag(opj_t1_t *t1, int f) { + return t1->lut_ctxno_mag[(f & T1_SIG_OTH) | (((f & T1_REFINE) != 0) << 11)]; +} + +static int t1_getspb(opj_t1_t *t1, int f) { + return t1->lut_spb[(f & (T1_SIG_PRIM | T1_SGN)) >> 4]; +} + +static int t1_getnmsedec_sig(opj_t1_t *t1, int x, int bitpos) { + if (bitpos > T1_NMSEDEC_FRACBITS) { + return t1->lut_nmsedec_sig[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)]; + } + + return t1->lut_nmsedec_sig0[x & ((1 << T1_NMSEDEC_BITS) - 1)]; +} + +static int t1_getnmsedec_ref(opj_t1_t *t1, int x, int bitpos) { + if (bitpos > T1_NMSEDEC_FRACBITS) { + return t1->lut_nmsedec_ref[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)]; + } + + return t1->lut_nmsedec_ref0[x & ((1 << T1_NMSEDEC_BITS) - 1)]; +} + +static void t1_updateflags(int *fp, int s) { + int *np = fp - (T1_MAXCBLKW + 2); + int *sp = fp + (T1_MAXCBLKW + 2); + np[-1] |= T1_SIG_SE; + np[1] |= T1_SIG_SW; + sp[-1] |= T1_SIG_NE; + sp[1] |= T1_SIG_NW; + *np |= T1_SIG_S; + *sp |= T1_SIG_N; + fp[-1] |= T1_SIG_E; + fp[1] |= T1_SIG_W; + if (s) { + *np |= T1_SGN_S; + *sp |= T1_SGN_N; + fp[-1] |= T1_SGN_E; + fp[1] |= T1_SGN_W; + } +} + +static void t1_enc_sigpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int bpno, int one, int *nmsedec, char type, int vsc) { + int v, flag; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + flag = vsc ? ((*fp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*fp); + if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) { + v = int_abs(*dp) & one ? 1 : 0; + if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ + mqc_setcurctx(mqc, t1_getctxno_zc(t1, flag, orient)); /* ESSAI */ + mqc_bypass_enc(mqc, v); + } else { + mqc_setcurctx(mqc, t1_getctxno_zc(t1, flag, orient)); + mqc_encode(mqc, v); + } + if (v) { + v = *dp < 0 ? 1 : 0; + *nmsedec += t1_getnmsedec_sig(t1, int_abs(*dp), bpno + T1_NMSEDEC_FRACBITS); + if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ + mqc_setcurctx(mqc, t1_getctxno_sc(t1, flag)); /* ESSAI */ + mqc_bypass_enc(mqc, v); + } else { + mqc_setcurctx(mqc, t1_getctxno_sc(t1, flag)); + mqc_encode(mqc, v ^ t1_getspb(t1, flag)); + } + t1_updateflags(fp, v); + *fp |= T1_SIG; + } + *fp |= T1_VISIT; + } +} + +static void t1_dec_sigpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int oneplushalf, char type, int vsc) { + int v, flag; + + opj_raw_t *raw = t1->raw; /* RAW component */ + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + flag = vsc ? ((*fp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*fp); + if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) { + if (type == T1_TYPE_RAW) { + if (raw_decode(raw)) { + v = raw_decode(raw); /* ESSAI */ + *dp = v ? -oneplushalf : oneplushalf; + t1_updateflags(fp, v); + *fp |= T1_SIG; + } + } else { + mqc_setcurctx(mqc, t1_getctxno_zc(t1, flag, orient)); + if (mqc_decode(mqc)) { + mqc_setcurctx(mqc, t1_getctxno_sc(t1, flag)); + v = mqc_decode(mqc) ^ t1_getspb(t1, flag); + *dp = v ? -oneplushalf : oneplushalf; + t1_updateflags(fp, v); + *fp |= T1_SIG; + } + } + *fp |= T1_VISIT; + } +} /* VSC and BYPASS by Antonin */ + +static void t1_enc_sigpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, char type, int cblksty) { + int i, j, k, m, one, vsc; + *nmsedec = 0; + one = 1 << (bpno + T1_NMSEDEC_FRACBITS); + for (m = 0; m < l; m++) { + for (k = 0; k < h; k += 4) { + for (i = 0; i < w; i++) { + for (j = k; j < k + 4 && j < h; j++) { + vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; + t1_enc_sigpass_step(t1, &t1->flags[1 + m][1 + j][1 + i], &t1->data[m][j][i], orient, bpno, one, nmsedec, type, vsc); + } + } + } + } +} + +static void t1_dec_sigpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, char type, int cblksty) { + int i, j, k, m, one, half, oneplushalf, vsc; + one = 1 << bpno; + half = one >> 1; + oneplushalf = one | half; + for (m = 0; m < l; m++) { + for (k = 0; k < h; k += 4) { + for (i = 0; i < w; i++) { + for (j = k; j < k + 4 && j < h; j++) { + vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; + t1_dec_sigpass_step(t1, &t1->flags[1 + m][1 + j][1 + i], &t1->data[m][j][i], orient, oneplushalf, type, vsc); + } + } + } + } +} /* VSC and BYPASS by Antonin */ + +static void t1_enc_refpass_step(opj_t1_t *t1, int *fp, int *dp, int bpno, int one, int *nmsedec, char type, int vsc) { + int v, flag; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + flag = vsc ? ((*fp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*fp); + if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) { + *nmsedec += t1_getnmsedec_ref(t1, int_abs(*dp), bpno + T1_NMSEDEC_FRACBITS); + v = int_abs(*dp) & one ? 1 : 0; + if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ + mqc_setcurctx(mqc, t1_getctxno_mag(t1, flag)); /* ESSAI */ + mqc_bypass_enc(mqc, v); + } else { + mqc_setcurctx(mqc, t1_getctxno_mag(t1, flag)); + mqc_encode(mqc, v); + } + *fp |= T1_REFINE; + } +} + +static void t1_dec_refpass_step(opj_t1_t *t1, int *fp, int *dp, int poshalf, int neghalf, char type, int vsc) { + int v, t, flag; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + opj_raw_t *raw = t1->raw; /* RAW component */ + + flag = vsc ? ((*fp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*fp); + if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) { + if (type == T1_TYPE_RAW) { + mqc_setcurctx(mqc, t1_getctxno_mag(t1, flag)); /* ESSAI */ + v = raw_decode(raw); + } else { + mqc_setcurctx(mqc, t1_getctxno_mag(t1, flag)); + v = mqc_decode(mqc); + } + t = v ? poshalf : neghalf; + *dp += *dp < 0 ? -t : t; + *fp |= T1_REFINE; + } +} /* VSC and BYPASS by Antonin */ + +static void t1_enc_refpass(opj_t1_t *t1, int w, int h, int l, int bpno, int *nmsedec, char type, int cblksty) { + int i, j, k, m, one, vsc; + *nmsedec = 0; + one = 1 << (bpno + T1_NMSEDEC_FRACBITS); + for (m = 0; m < l; m++) { + for (k = 0; k < h; k += 4) { + for (i = 0; i < w; i++) { + for (j = k; j < k + 4 && j < h; j++) { + vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; + t1_enc_refpass_step(t1, &t1->flags[1 + m][1 + j][1 + i], &t1->data[m][j][i], bpno, one, nmsedec, type, vsc); + } + } + } + } +} + +static void t1_dec_refpass(opj_t1_t *t1, int w, int h, int l, int bpno, char type, int cblksty) { + int i, j, k, m, one, poshalf, neghalf; + int vsc; + one = 1 << bpno; + poshalf = one >> 1; + neghalf = bpno > 0 ? -poshalf : -1; + for (m = 0; m < l; m++) { + for (k = 0; k < h; k += 4) { + for (i = 0; i < w; i++) { + for (j = k; j < k + 4 && j < h; j++) { + vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; + t1_dec_refpass_step(t1, &t1->flags[1 + m][1 + j][1 + i], &t1->data[m][j][i], poshalf, neghalf, type, vsc); + } + } + } + } +} /* VSC and BYPASS by Antonin */ + +static void t1_enc_clnpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int bpno, int one, int *nmsedec, int partial, int vsc) { + int v, flag; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + flag = vsc ? ((*fp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*fp); + if (partial) { + goto LABEL_PARTIAL; + } + if (!(*fp & (T1_SIG | T1_VISIT))) { + mqc_setcurctx(mqc, t1_getctxno_zc(t1, flag, orient)); + v = int_abs(*dp) & one ? 1 : 0; + mqc_encode(mqc, v); + if (v) { +LABEL_PARTIAL: + *nmsedec += t1_getnmsedec_sig(t1, int_abs(*dp), bpno + T1_NMSEDEC_FRACBITS); + mqc_setcurctx(mqc, t1_getctxno_sc(t1, flag)); + v = *dp < 0 ? 1 : 0; + mqc_encode(mqc, v ^ t1_getspb(t1, flag)); + t1_updateflags(fp, v); + *fp |= T1_SIG; + } + } + *fp &= ~T1_VISIT; +} + +static void t1_dec_clnpass_step(opj_t1_t *t1, int *fp, int *dp, int orient, int oneplushalf, int partial, int vsc) { + int v, flag; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + flag = vsc ? ((*fp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*fp); + if (partial) { + goto LABEL_PARTIAL; + } + if (!(flag & (T1_SIG | T1_VISIT))) { + mqc_setcurctx(mqc, t1_getctxno_zc(t1, flag, orient)); + if (mqc_decode(mqc)) { +LABEL_PARTIAL: + mqc_setcurctx(mqc, t1_getctxno_sc(t1, flag)); + v = mqc_decode(mqc) ^ t1_getspb(t1, flag); + *dp = v ? -oneplushalf : oneplushalf; + t1_updateflags(fp, v); + *fp |= T1_SIG; + } + } + *fp &= ~T1_VISIT; +} /* VSC and BYPASS by Antonin */ + +static void t1_enc_clnpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, int cblksty) { + int i, j, k, m, one, agg, runlen, vsc; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + *nmsedec = 0; + one = 1 << (bpno + T1_NMSEDEC_FRACBITS); + for (m = 0; m < l; m++) { + for (k = 0; k < h; k += 4) { + for (i = 0; i < w; i++) { + if (k + 3 < h) { + if (cblksty & J3D_CCP_CBLKSTY_VSC) { + agg = !(t1->flags[1 + m][1 + k][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) + || t1->flags[1 + m][1 + k + 1][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) + || t1->flags[1 + m][1 + k + 2][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) + || (t1->flags[1 + m][1 + k + 3][1 + i] + & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) & (T1_SIG | T1_VISIT | T1_SIG_OTH)); + } else { + agg = !(t1->flags[1 + m][1 + k][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) + || t1->flags[1 + m][1 + k + 1][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) + || t1->flags[1 + m][1 + k + 2][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) + || t1->flags[1 + m][1 + k + 3][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH)); + } + } else { + agg = 0; + } + if (agg) { + for (runlen = 0; runlen < 4; runlen++) { + if (int_abs(t1->data[m][k + runlen][i]) & one) + break; + } + mqc_setcurctx(mqc, T1_CTXNO_AGG); + mqc_encode(mqc, runlen != 4); + if (runlen == 4) { + continue; + } + mqc_setcurctx(mqc, T1_CTXNO_UNI); + mqc_encode(mqc, runlen >> 1); + mqc_encode(mqc, runlen & 1); + } else { + runlen = 0; + } + for (j = k + runlen; j < k + 4 && j < h; j++) { + vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; + t1_enc_clnpass_step(t1, &(t1->flags[1 + m][1 + j][1 + i]), &(t1->data[m][j][i]), orient, bpno, one, nmsedec, agg && (j == k + runlen), vsc); + } + } + } + } +} + +static void t1_dec_clnpass(opj_t1_t *t1, int w, int h, int l, int bpno, int orient, int cblksty) { + int i, j, k, m, one, half, oneplushalf, agg, runlen, vsc; + int segsym = cblksty & J3D_CCP_CBLKSTY_SEGSYM; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + one = 1 << bpno; + half = one >> 1; + oneplushalf = one | half; + for (m = 0; m < l; m++) { + for (k = 0; k < h; k += 4) { + for (i = 0; i < w; i++) { + if (k + 3 < h) { + if (cblksty & J3D_CCP_CBLKSTY_VSC) { + agg = !(t1->flags[1 + m][1 + k][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) + || t1->flags[1 + m][1 + k + 1][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) + || t1->flags[1 + m][1 + k + 2][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) + || (t1->flags[1 + m][1 + k + 3][1 + i] + & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) & (T1_SIG | T1_VISIT | T1_SIG_OTH)); + } else { + agg = !(t1->flags[1 + m][1 + k][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) + || t1->flags[1 + m][1 + k + 1][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) + || t1->flags[1 + m][1 + k + 2][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH) + || t1->flags[1 + m][1 + k + 3][1 + i] & (T1_SIG | T1_VISIT | T1_SIG_OTH)); + } + } else { + agg = 0; + } + if (agg) { + mqc_setcurctx(mqc, T1_CTXNO_AGG); + if (!mqc_decode(mqc)) { + continue; + } + mqc_setcurctx(mqc, T1_CTXNO_UNI); + runlen = mqc_decode(mqc); + runlen = (runlen << 1) | mqc_decode(mqc); + } else { + runlen = 0; + } + for (j = k + runlen; j < k + 4 && j < h; j++) { + vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; + t1_dec_clnpass_step(t1, &t1->flags[1 + m][1 + j][1 + i], &t1->data[m][j][i], orient, oneplushalf, agg && (j == k + runlen), vsc); + } + } + } + } + if (segsym) { + int v = 0; + mqc_setcurctx(mqc, T1_CTXNO_UNI); + v = mqc_decode(mqc); + v = (v << 1) | mqc_decode(mqc); + v = (v << 1) | mqc_decode(mqc); + v = (v << 1) | mqc_decode(mqc); + /* + if (v!=0xa) { + opj_event_msg(t1->cinfo, EVT_WARNING, "Bad segmentation symbol %x\n", v); + } + */ + } +} /* VSC and BYPASS by Antonin */ + + +static void t1_encode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int compno, int level[3], int dwtid[3], double stepsize, int cblksty, int numcomps, opj_tcd_tile_t * tile) { + int i, j, k; + int w, h, l; + int passno; + int bpno, passtype; + int max; + int nmsedec = 0; + double cumwmsedec = 0; + char type = T1_TYPE_MQ; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + w = cblk->x1 - cblk->x0; + h = cblk->y1 - cblk->y0; + l = cblk->z1 - cblk->z0; + + max = 0; + for (k = 0; k < l; k++) { + for (j = 0; j < h; j++) { + for (i = 0; i < w; i++) { + max = int_max(max, int_abs(t1->data[k][j][i])); + } + } + } + for (k = 0; k <= l; k++) { + for (j = 0; j <= h; j++) { + for (i = 0; i <= w; i++) { + t1->flags[k][j][i] = 0; + } + } + } + + cblk->numbps = max ? (int_floorlog2(max) + 1) - T1_NMSEDEC_FRACBITS : 0; + + bpno = cblk->numbps - 1; + passtype = 2; + + mqc_reset_enc(mqc); + mqc_init_enc(mqc, cblk->data); + + for (passno = 0; bpno >= 0; passno++) { + opj_tcd_pass_t *pass = &cblk->passes[passno]; + int correction = 3; + double tmpwmsedec; + type = ((bpno < (cblk->numbps - 4)) && (passtype < 2) && (cblksty & J3D_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ; + /*fprintf(stdout,"passno %d passtype %d w %d h %d l %d bpno %d orient %d type %d cblksty %d\n",passno,passtype,w,h,l,bpno,orient,type,cblksty);*/ + + switch (passtype) { + case 0: + t1_enc_sigpass(t1, w, h, l, bpno, orient, &nmsedec, type, cblksty); + break; + case 1: + t1_enc_refpass(t1, w, h, l, bpno, &nmsedec, type, cblksty); + break; + case 2: + /*fprintf(stdout,"w %d h %d l %d bpno %d orient %d \n",w,h,l,bpno,orient);*/ + t1_enc_clnpass(t1, w, h, l, bpno, orient, &nmsedec, cblksty); + /* code switch SEGMARK (i.e. SEGSYM) */ + if (cblksty & J3D_CCP_CBLKSTY_SEGSYM) + mqc_segmark_enc(mqc); + break; + } + + /* fixed_quality */ + tmpwmsedec = t1_getwmsedec(nmsedec, compno, level, orient, bpno, stepsize, numcomps, dwtid); + cumwmsedec += tmpwmsedec; + tile->distotile += tmpwmsedec; + + /* Code switch "RESTART" (i.e. TERMALL) */ + if ((cblksty & J3D_CCP_CBLKSTY_TERMALL) && !((passtype == 2) && (bpno - 1 < 0))) { + if (type == T1_TYPE_RAW) { + mqc_flush(mqc); + correction = 1; + /* correction = mqc_bypass_flush_enc(); */ + } else { /* correction = mqc_restart_enc(); */ + mqc_flush(mqc); + correction = 1; + } + pass->term = 1; + } else { + if (((bpno < (cblk->numbps - 4) && (passtype > 0)) + || ((bpno == (cblk->numbps - 4)) && (passtype == 2))) && (cblksty & J3D_CCP_CBLKSTY_LAZY)) { + if (type == T1_TYPE_RAW) { + mqc_flush(mqc); + correction = 1; + /* correction = mqc_bypass_flush_enc(); */ + } else { /* correction = mqc_restart_enc(); */ + mqc_flush(mqc); + correction = 1; + } + pass->term = 1; + } else { + pass->term = 0; + } + } + + if (++passtype == 3) { + passtype = 0; + bpno--; + } + + if (pass->term && bpno > 0) { + type = ((bpno < (cblk->numbps - 4)) && (passtype < 2) && (cblksty & J3D_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ; + if (type == T1_TYPE_RAW) + mqc_bypass_init_enc(mqc); + else + mqc_restart_init_enc(mqc); + } + + pass->distortiondec = cumwmsedec; + pass->rate = mqc_numbytes(mqc) + correction; /* FIXME */ + pass->len = pass->rate - (passno == 0 ? 0 : cblk->passes[passno - 1].rate); + + /* Code-switch "RESET" */ + if (cblksty & J3D_CCP_CBLKSTY_RESET) + mqc_reset_enc(mqc); + } + + /* Code switch "ERTERM" (i.e. PTERM) */ + if (cblksty & J3D_CCP_CBLKSTY_PTERM) + mqc_erterm_enc(mqc); + else /* Default coding */ if (!(cblksty & J3D_CCP_CBLKSTY_LAZY)) + mqc_flush(mqc); + + cblk->totalpasses = passno; +} + +static void t1_decode_cblk(opj_t1_t *t1, opj_tcd_cblk_t * cblk, int orient, int roishift, int cblksty) { + int i, j, k, w, h, l; + int bpno, passtype; + int segno, passno; + char type = T1_TYPE_MQ; /* BYPASS mode */ + + opj_raw_t *raw = t1->raw; /* RAW component */ + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + w = cblk->x1 - cblk->x0; + h = cblk->y1 - cblk->y0; + l = cblk->z1 - cblk->z0; + + for (k = 0; k < l; k++) { + for (j = 0; j < h; j++) { + for (i = 0; i < w; i++) { + t1->data[k][j][i] = 0; + } + } + } + + for (k = 0; k <= l; k++) { + for (j = 0; j <= h; j++) { + for (i = 0; i <= w; i++) { + t1->flags[k][j][i] = 0; + } + } + } + + bpno = roishift + cblk->numbps - 1; + passtype = 2; + + mqc_reset_enc(mqc); + + for (segno = 0; segno < cblk->numsegs; segno++) { + opj_tcd_seg_t *seg = &cblk->segs[segno]; + + /* BYPASS mode */ + type = ((bpno <= (cblk->numbps - 1) - 4) && (passtype < 2) && (cblksty & J3D_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ; + if (type == T1_TYPE_RAW) { + raw_init_dec(raw, seg->data, seg->len); + } else { + mqc_init_dec(mqc, seg->data, seg->len); + } + + for (passno = 0; passno < seg->numpasses; passno++) { + switch (passtype) { + case 0: + t1_dec_sigpass(t1, w, h, l, bpno+1, orient, type, cblksty); + break; + case 1: + t1_dec_refpass(t1, w, h, l, bpno+1, type, cblksty); + break; + case 2: + t1_dec_clnpass(t1, w, h, l, bpno+1, orient, cblksty); + break; + } + + if ((cblksty & J3D_CCP_CBLKSTY_RESET) && type == T1_TYPE_MQ) { + mqc_reset_enc(mqc); + } + if (++passtype == 3) { + passtype = 0; + bpno--; + } + } + } +} + +static int t1_init_ctxno_zc(int f, int orient) { + int h, v, d, n, t, hv; + n = 0; + h = ((f & T1_SIG_W) != 0) + ((f & T1_SIG_E) != 0); + v = ((f & T1_SIG_N) != 0) + ((f & T1_SIG_S) != 0); + d = ((f & T1_SIG_NW) != 0) + ((f & T1_SIG_NE) != 0) + ((f & T1_SIG_SE) != 0) + ((f & T1_SIG_SW) != 0); + + switch (orient) { + case 2: + t = h; + h = v; + v = t; + case 0: + case 1: + if (!h) { + if (!v) { + if (!d) + n = 0; + else if (d == 1) + n = 1; + else + n = 2; + } else if (v == 1) { + n = 3; + } else { + n = 4; + } + } else if (h == 1) { + if (!v) { + if (!d) + n = 5; + else + n = 6; + } else { + n = 7; + } + } else + n = 8; + break; + case 3: + hv = h + v; + if (!d) { + if (!hv) { + n = 0; + } else if (hv == 1) { + n = 1; + } else { + n = 2; + } + } else if (d == 1) { + if (!hv) { + n = 3; + } else if (hv == 1) { + n = 4; + } else { + n = 5; + } + } else if (d == 2) { + if (!hv) { + n = 6; + } else { + n = 7; + } + } else { + n = 8; + } + break; + } + + return (T1_CTXNO_ZC + n); +} + +static int t1_init_ctxno_sc(int f) { + int hc, vc, n; + n = 0; + + hc = int_min(((f & (T1_SIG_E | T1_SGN_E)) == + T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W), + 1) - int_min(((f & (T1_SIG_E | T1_SGN_E)) == + (T1_SIG_E | T1_SGN_E)) + + ((f & (T1_SIG_W | T1_SGN_W)) == + (T1_SIG_W | T1_SGN_W)), 1); + + vc = int_min(((f & (T1_SIG_N | T1_SGN_N)) == + T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S), + 1) - int_min(((f & (T1_SIG_N | T1_SGN_N)) == + (T1_SIG_N | T1_SGN_N)) + + ((f & (T1_SIG_S | T1_SGN_S)) == + (T1_SIG_S | T1_SGN_S)), 1); + + if (hc < 0) { + hc = -hc; + vc = -vc; + } + if (!hc) { + if (vc == -1) + n = 1; + else if (!vc) + n = 0; + else + n = 1; + } else if (hc == 1) { + if (vc == -1) + n = 2; + else if (!vc) + n = 3; + else + n = 4; + } + + return (T1_CTXNO_SC + n); +} + +static int t1_init_ctxno_mag(int f) { + int n; + if (!(f & T1_REFINE)) + n = (f & (T1_SIG_OTH)) ? 1 : 0; + else + n = 2; + + return (T1_CTXNO_MAG + n); +} + +static int t1_init_spb(int f) { + int hc, vc, n; + + hc = int_min(((f & (T1_SIG_E | T1_SGN_E)) == + T1_SIG_E) + ((f & (T1_SIG_W | T1_SGN_W)) == T1_SIG_W), + 1) - int_min(((f & (T1_SIG_E | T1_SGN_E)) == + (T1_SIG_E | T1_SGN_E)) + + ((f & (T1_SIG_W | T1_SGN_W)) == + (T1_SIG_W | T1_SGN_W)), 1); + + vc = int_min(((f & (T1_SIG_N | T1_SGN_N)) == + T1_SIG_N) + ((f & (T1_SIG_S | T1_SGN_S)) == T1_SIG_S), + 1) - int_min(((f & (T1_SIG_N | T1_SGN_N)) == + (T1_SIG_N | T1_SGN_N)) + + ((f & (T1_SIG_S | T1_SGN_S)) == + (T1_SIG_S | T1_SGN_S)), 1); + + if (!hc && !vc) + n = 0; + else + n = (!(hc > 0 || (!hc && vc > 0))); + + return n; +} + +static void t1_init_luts(opj_t1_t *t1) { + int i, j; + double u, v, t; + for (j = 0; j < 4; j++) { + for (i = 0; i < 256; ++i) { + t1->lut_ctxno_zc[(j << 8) | i] = t1_init_ctxno_zc(i, j); + } + } + for (i = 0; i < 256; i++) { + t1->lut_ctxno_sc[i] = t1_init_ctxno_sc(i << 4); + } + for (j = 0; j < 2; j++) { + for (i = 0; i < 2048; ++i) { + t1->lut_ctxno_mag[(j << 11) + i] = t1_init_ctxno_mag((j ? T1_REFINE : 0) | i); + } + } + for (i = 0; i < 256; ++i) { + t1->lut_spb[i] = t1_init_spb(i << 4); + } + /* FIXME FIXME FIXME */ + /* fprintf(stdout,"nmsedec luts:\n"); */ + for (i = 0; i < (1 << T1_NMSEDEC_BITS); i++) { + t = i / pow(2, T1_NMSEDEC_FRACBITS); + u = t; + v = t - 1.5; + t1->lut_nmsedec_sig[i] = + int_max(0, + (int) (floor((u * u - v * v) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0)); + t1->lut_nmsedec_sig0[i] = + int_max(0, + (int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0)); + u = t - 1.0; + if (i & (1 << (T1_NMSEDEC_BITS - 1))) { + v = t - 1.5; + } else { + v = t - 0.5; + } + t1->lut_nmsedec_ref[i] = + int_max(0, + (int) (floor((u * u - v * v) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0)); + t1->lut_nmsedec_ref0[i] = + int_max(0, + (int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0)); + } +} + +/* ----------------------------------------------------------------------- */ + +opj_t1_t* t1_create(opj_common_ptr cinfo) { + opj_t1_t *t1 = (opj_t1_t*)opj_malloc(sizeof(opj_t1_t)); + if(t1) { + t1->cinfo = cinfo; + /* create MQC and RAW handles */ + t1->mqc = mqc_create(); + t1->raw = raw_create(); + /* initialize the look-up tables of the Tier-1 coder/decoder */ + t1_init_luts(t1); + } + return t1; +} + +void t1_destroy(opj_t1_t *t1) { + if(t1) { + /* destroy MQC and RAW handles */ + mqc_destroy(t1->mqc); + raw_destroy(t1->raw); + /*opj_free(t1->data);*/ + /*opj_free(t1->flags);*/ + opj_free(t1); + } +} + +void t1_encode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) { + int compno, resno, bandno, precno, cblkno; + int x, y, z, i, j, k, orient; + int n=0; + int level[3]; + FILE *fid = NULL; +/* char filename[10];*/ + tile->distotile = 0; /* fixed_quality */ + + for (compno = 0; compno < tile->numcomps; compno++) { + opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; + + for (resno = 0; resno < tilec->numresolution[0]; resno++) { + opj_tcd_resolution_t *res = &tilec->resolutions[resno]; + + /* Weighted first order entropy + sprintf(filename,"res%d.txt",resno); + if ((fid = fopen(filename,"w")) == 0){ + fprintf(stdout,"Error while opening %s\n", filename); + exit(1); + } + */ + for (bandno = 0; bandno < res->numbands; bandno++) { + opj_tcd_band_t *band = &res->bands[bandno]; + for (precno = 0; precno < res->prctno[0] * res->prctno[1] * res->prctno[2]; precno++) { + opj_tcd_precinct_t *prc = &band->precincts[precno]; + + for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { + opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; + + /*fprintf(stdout,"Precno %d Cblkno %d \n",precno,cblkno);*/ + if (band->bandno == 0) { + x = cblk->x0 - band->x0; + y = cblk->y0 - band->y0; + z = cblk->z0 - band->z0; + } else if (band->bandno == 1) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = pres->x1 - pres->x0 + cblk->x0 - band->x0; + y = cblk->y0 - band->y0; + z = cblk->z0 - band->z0; + } else if (band->bandno == 2) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = cblk->x0 - band->x0; + y = pres->y1 - pres->y0 + cblk->y0 - band->y0; + z = cblk->z0 - band->z0; + } else if (band->bandno == 3) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = pres->x1 - pres->x0 + cblk->x0 - band->x0; + y = pres->y1 - pres->y0 + cblk->y0 - band->y0; + z = cblk->z0 - band->z0; + } else if (band->bandno == 4) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = cblk->x0 - band->x0; + y = cblk->y0 - band->y0; + z = pres->z1 - pres->z0 + cblk->z0 - band->z0; + } else if (band->bandno == 5) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = pres->x1 - pres->x0 + cblk->x0 - band->x0; + y = cblk->y0 - band->y0; + z = pres->z1 - pres->z0 + cblk->z0 - band->z0; + } else if (band->bandno == 6) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = cblk->x0 - band->x0; + y = pres->y1 - pres->y0 + cblk->y0 - band->y0; + z = pres->z1 - pres->z0 + cblk->z0 - band->z0; + } else if (band->bandno == 7) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = pres->x1 - pres->x0 + cblk->x0 - band->x0; + y = pres->y1 - pres->y0 + cblk->y0 - band->y0; + z = pres->z1 - pres->z0 + cblk->z0 - band->z0; + } + + if (tcp->tccps[compno].reversible == 1) { + for (k = 0; k < cblk->z1 - cblk->z0; k++) { + for (j = 0; j < cblk->y1 - cblk->y0; j++) { + for (i = 0; i < cblk->x1 - cblk->x0; i++) { + t1->data[k][j][i] = + tilec->data[(x + i) + (y + j) * (tilec->x1 - tilec->x0) + (z + k) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)] << T1_NMSEDEC_FRACBITS; +/*fprintf(fid," %d",t1->data[k][j][i]);*/ + } + } + } + } else if (tcp->tccps[compno].reversible == 0) { + for (k = 0; k < cblk->z1 - cblk->z0; k++) { + for (j = 0; j < cblk->y1 - cblk->y0; j++) { + for (i = 0; i < cblk->x1 - cblk->x0; i++) { + t1->data[k][j][i] = fix_mul( + tilec->data[(x + i) + (y + j) * (tilec->x1 - tilec->x0) + (z + k) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)], + 8192 * 8192 / ((int) floor(band->stepsize * 8192))) >> (13 - T1_NMSEDEC_FRACBITS); + } + } + } + } + + orient = band->bandno; /* FIXME */ + if (orient == 2) { + orient = 1; + } else if (orient == 1) { + orient = 2; + } + for (i = 0; i < 3; i++) + level[i] = tilec->numresolution[i] - 1 - resno; + /*fprintf(stdout,"t1_encode_cblk(t1, cblk, %d, %d, %d %d %d, %d, %f, %d, %d, tile);\n", orient, compno, level[0], level[1], level[2], tcp->tccps[compno].reversible, band->stepsize, tcp->tccps[compno].cblksty, tile->numcomps);*/ + t1_encode_cblk(t1, cblk, orient, compno, level, tcp->tccps[compno].dwtid, band->stepsize, tcp->tccps[compno].cblksty, tile->numcomps, tile); + + } /* cblkno */ + } /* precno */ +/*fprintf(fid,"\n");*/ + } /* bandno */ +/*fclose(fid);*/ + } /* resno */ + } /* compno */ +} + +void t1_decode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) { + int compno, resno, bandno, precno, cblkno; + + for (compno = 0; compno < tile->numcomps; compno++) { + opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; + + for (resno = 0; resno < tilec->numresolution[0]; resno++) { + opj_tcd_resolution_t *res = &tilec->resolutions[resno]; + + for (bandno = 0; bandno < res->numbands; bandno++) { + opj_tcd_band_t *band = &res->bands[bandno]; + + for (precno = 0; precno < res->prctno[0] * res->prctno[1] * res->prctno[2]; precno++) { + opj_tcd_precinct_t *prc = &band->precincts[precno]; + + for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { + int x, y, k, i, j, z, orient; + opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; + + orient = band->bandno; /* FIXME */ + if (orient == 2) { + orient = 1; + } else if (orient == 1) { + orient = 2; + } + + t1_decode_cblk(t1, cblk, orient, tcp->tccps[compno].roishift, tcp->tccps[compno].cblksty); + + if (band->bandno == 0) { + x = cblk->x0 - band->x0; + y = cblk->y0 - band->y0; + z = cblk->z0 - band->z0; + } else if (band->bandno == 1) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = pres->x1 - pres->x0 + cblk->x0 - band->x0; + y = cblk->y0 - band->y0; + z = cblk->z0 - band->z0; + } else if (band->bandno == 2) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = cblk->x0 - band->x0; + y = pres->y1 - pres->y0 + cblk->y0 - band->y0; + z = cblk->z0 - band->z0; + } else if (band->bandno == 3) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = pres->x1 - pres->x0 + cblk->x0 - band->x0; + y = pres->y1 - pres->y0 + cblk->y0 - band->y0; + z = cblk->z0 - band->z0; + } else if (band->bandno == 4) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = cblk->x0 - band->x0; + y = cblk->y0 - band->y0; + z = pres->z1 - pres->z0 + cblk->z0 - band->z0; + } else if (band->bandno == 5) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = pres->x1 - pres->x0 + cblk->x0 - band->x0; + y = cblk->y0 - band->y0; + z = pres->z1 - pres->z0 + cblk->z0 - band->z0; + } else if (band->bandno == 6) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = cblk->x0 - band->x0; + y = pres->y1 - pres->y0 + cblk->y0 - band->y0; + z = pres->z1 - pres->z0 + cblk->z0 - band->z0; + } else if (band->bandno == 7) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = pres->x1 - pres->x0 + cblk->x0 - band->x0; + y = pres->y1 - pres->y0 + cblk->y0 - band->y0; + z = pres->z1 - pres->z0 + cblk->z0 - band->z0; + } + + if (tcp->tccps[compno].roishift) { + int thresh, val, mag; + thresh = 1 << tcp->tccps[compno].roishift; + for (k = 0; k < cblk->z1 - cblk->z0; k++) { + for (j = 0; j < cblk->y1 - cblk->y0; j++) { + for (i = 0; i < cblk->x1 - cblk->x0; i++) { + val = t1->data[k][j][i]; + mag = int_abs(val); + if (mag >= thresh) { + mag >>= tcp->tccps[compno].roishift; + t1->data[k][j][i] = val < 0 ? -mag : mag; + } + } + } + } + } + + if (tcp->tccps[compno].reversible == 1) { + for (k = 0; k < cblk->z1 - cblk->z0; k++) { + for (j = 0; j < cblk->y1 - cblk->y0; j++) { + for (i = 0; i < cblk->x1 - cblk->x0; i++) { + int tmp = t1->data[k][j][i]; + tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0) + (z + k) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)] = tmp/2; + } + } + } + } else { /* if (tcp->tccps[compno].reversible == 0) */ + for (k = 0; k < cblk->z1 - cblk->z0; k++) { + for (j = 0; j < cblk->y1 - cblk->y0; j++) { + for (i = 0; i < cblk->x1 - cblk->x0; i++) { + double tmp = (double)(t1->data[k][j][i] * band->stepsize * 4096.0); + if (t1->data[k][j][i] >> 1 == 0) { + tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0) + (z + k) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)] = 0; + } else { + int tmp2 = ((int) (floor(fabs(tmp)))) + ((int) floor(fabs(tmp*2))%2); + tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0) + (z + k) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)] = ((tmp<0)?-tmp2:tmp2); + } + } + } + } + } + } /* cblkno */ + } /* precno */ + } /* bandno */ + } /* resno */ + } /* compno */ +} + + +/** mod fixed_quality */ +double t1_getwmsedec(int nmsedec, int compno, int level[3], int orient, int bpno, double stepsize, int numcomps, int dwtid[3]) { + double w1, w2, wmsedec; + + if (dwtid[0] == 1 || dwtid[1] == 1 || dwtid[2] == 1) { + w1 = (numcomps > 1) ? mct_getnorm_real(compno) : 1; + } else { + w1 = (numcomps > 1) ? mct_getnorm(compno) : 1; + } + w2 = dwt_getnorm(orient, level, dwtid); + + /*fprintf(stdout,"nmsedec %d level %d %d %d orient %d bpno %d stepsize %f \n",nmsedec ,level[0],level[1],level[2],orient,bpno,stepsize);*/ + wmsedec = w1 * w2 * stepsize * (1 << bpno); + wmsedec *= wmsedec * nmsedec / 8192.0; + + return wmsedec; +} +/** mod fixed_quality */ diff --git a/src/lib/openjp3d/t1.h b/src/lib/openjp3d/t1.h index 1863484c..138f04c7 100644 --- a/src/lib/openjp3d/t1.h +++ b/src/lib/openjp3d/t1.h @@ -1,173 +1,173 @@ -/* - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef __T1_H -#define __T1_H -/** -@file t1.h -@brief Implementation of the tier-1 coding (coding of code-block coefficients) (T1) - -The functions in T1.C have for goal to realize the tier-1 coding operation. The functions -in T1.C are used by some function in TCD.C. -*/ - -/** @defgroup T1 T1 - Implementation of the tier-1 coding */ -/*@{*/ - -/* ----------------------------------------------------------------------- */ -#define T1_NMSEDEC_BITS 7 - -#define T1_MAXCBLKW 256 /*< Maximum size of code-block (width) */ -#define T1_MAXCBLKH 256 /*< Maximum size of code-block (heigth) */ -#define T1_MAXCBLKD 256 /*< Maximum size of code-block (depth) */ -#define T1_MINCBLKW 4 /*< Minimum size of code-block (width) */ -#define T1_MINCBLKH 4 /*< Minimum size of code-block (heigth) */ -#define T1_MINCBLKD 4 /*< Minimum size of code-block (depth) */ -#define T1_MAXWHD 18 -#define T1_CBLKW 256 -#define T1_CBLKH 256 -#define T1_CBLKD 256 - -#define T1_SIG_NE 0x0001 /*< Context orientation : North-East direction */ -#define T1_SIG_SE 0x0002 /*< Context orientation : South-East direction */ -#define T1_SIG_SW 0x0004 /*< Context orientation : South-West direction */ -#define T1_SIG_NW 0x0008 /*< Context orientation : North-West direction */ -#define T1_SIG_N 0x0010 /*< Context orientation : North direction */ -#define T1_SIG_E 0x0020 /*< Context orientation : East direction */ -#define T1_SIG_S 0x0040 /*< Context orientation : South direction */ -#define T1_SIG_W 0x0080 /*< Context orientation : West direction */ -#define T1_SIG_OTH (T1_SIG_N|T1_SIG_NE|T1_SIG_E|T1_SIG_SE|T1_SIG_S|T1_SIG_SW|T1_SIG_W|T1_SIG_NW) -#define T1_SIG_PRIM (T1_SIG_N|T1_SIG_E|T1_SIG_S|T1_SIG_W) - -#define T1_SGN_N 0x0100 -#define T1_SGN_E 0x0200 -#define T1_SGN_S 0x0400 -#define T1_SGN_W 0x0800 -#define T1_SGN (T1_SGN_N|T1_SGN_E|T1_SGN_S|T1_SGN_W) - -#define T1_SIG 0x1000 -#define T1_REFINE 0x2000 -#define T1_VISIT 0x4000 - -#define T1_NUMCTXS_AGG 1 -#define T1_NUMCTXS_ZC 9 -#define T1_NUMCTXS_MAG 3 -#define T1_NUMCTXS_SC 5 -#define T1_NUMCTXS_UNI 1 - -#define T1_CTXNO_AGG 0 -#define T1_CTXNO_ZC (T1_CTXNO_AGG+T1_NUMCTXS_AGG) -#define T1_CTXNO_MAG (T1_CTXNO_ZC+T1_NUMCTXS_ZC) -#define T1_CTXNO_SC (T1_CTXNO_MAG+T1_NUMCTXS_MAG) -#define T1_CTXNO_UNI (T1_CTXNO_SC+T1_NUMCTXS_SC) -#define T1_NUMCTXS (T1_CTXNO_UNI+T1_NUMCTXS_UNI) - -#define T1_NMSEDEC_FRACBITS (T1_NMSEDEC_BITS-1) - -#define T1_TYPE_MQ 0 /*< Normal coding using entropy coder */ -#define T1_TYPE_RAW 1 /*< No encoding the information is store under raw format in codestream (mode switch RAW)*/ - -/* ----------------------------------------------------------------------- */ - -/** -Tier-1 coding (coding of code-block coefficients) -*/ -typedef struct opj_t1 { - /** codec context */ - opj_common_ptr cinfo; - - /** MQC component */ - opj_mqc_t *mqc; - /** RAW component */ - opj_raw_t *raw; - /** LUTs for context-based coding */ - int lut_ctxno_zc[1024]; - int lut_ctxno_sc[256]; - int lut_ctxno_mag[4096]; - int lut_spb[256]; - /** LUTs for decoding normalised MSE */ - int lut_nmsedec_sig[1 << T1_NMSEDEC_BITS]; - int lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS]; - int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS]; - int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS]; - /** Codeblock data */ - int data[T1_CBLKD][T1_CBLKH][T1_CBLKW];/*int ***data;*/ - /** Context information for each voxel in codeblock */ - int flags[T1_CBLKD + 2][T1_CBLKH + 2][T1_CBLKH + 2];/*int ***flags;*/ -} opj_t1_t; - -/** @name Exported functions */ -/*@{*/ -/* ----------------------------------------------------------------------- */ -/** -Create a new T1 handle -and initialize the look-up tables of the Tier-1 coder/decoder -@return Returns a new T1 handle if successful, returns NULL otherwise -@see t1_init_luts -*/ -opj_t1_t* t1_create(opj_common_ptr cinfo); -/** -Destroy a previously created T1 handle -@param t1 T1 handle to destroy -*/ -void t1_destroy(opj_t1_t *t1); -/** -Encode the code-blocks of a tile -@param t1 T1 handle -@param tile The tile to encode -@param tcp Tile coding parameters -*/ -void t1_encode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp); -/** -Decode the code-blocks of a tile -@param t1 T1 handle -@param tile The tile to decode -@param tcp Tile coding parameters -*/ -void t1_decode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp); -/** -Get weigths of MSE decoding -@param nmsedec The normalized MSE reduction -@param compno -@param level -@param orient -@param bpno -@param stepsize -@param numcomps -@param dwtid -returns MSE associated to decoding pass -*/ -double t1_getwmsedec(int nmsedec, int compno, int level[3], int orient, int bpno, double stepsize, int numcomps, int dwtid[3]); - -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __T1_H */ +/* + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __T1_H +#define __T1_H +/** +@file t1.h +@brief Implementation of the tier-1 coding (coding of code-block coefficients) (T1) + +The functions in T1.C have for goal to realize the tier-1 coding operation. The functions +in T1.C are used by some function in TCD.C. +*/ + +/** @defgroup T1 T1 - Implementation of the tier-1 coding */ +/*@{*/ + +/* ----------------------------------------------------------------------- */ +#define T1_NMSEDEC_BITS 7 + +#define T1_MAXCBLKW 256 /*< Maximum size of code-block (width) */ +#define T1_MAXCBLKH 256 /*< Maximum size of code-block (heigth) */ +#define T1_MAXCBLKD 256 /*< Maximum size of code-block (depth) */ +#define T1_MINCBLKW 4 /*< Minimum size of code-block (width) */ +#define T1_MINCBLKH 4 /*< Minimum size of code-block (heigth) */ +#define T1_MINCBLKD 4 /*< Minimum size of code-block (depth) */ +#define T1_MAXWHD 18 +#define T1_CBLKW 256 +#define T1_CBLKH 256 +#define T1_CBLKD 256 + +#define T1_SIG_NE 0x0001 /*< Context orientation : North-East direction */ +#define T1_SIG_SE 0x0002 /*< Context orientation : South-East direction */ +#define T1_SIG_SW 0x0004 /*< Context orientation : South-West direction */ +#define T1_SIG_NW 0x0008 /*< Context orientation : North-West direction */ +#define T1_SIG_N 0x0010 /*< Context orientation : North direction */ +#define T1_SIG_E 0x0020 /*< Context orientation : East direction */ +#define T1_SIG_S 0x0040 /*< Context orientation : South direction */ +#define T1_SIG_W 0x0080 /*< Context orientation : West direction */ +#define T1_SIG_OTH (T1_SIG_N|T1_SIG_NE|T1_SIG_E|T1_SIG_SE|T1_SIG_S|T1_SIG_SW|T1_SIG_W|T1_SIG_NW) +#define T1_SIG_PRIM (T1_SIG_N|T1_SIG_E|T1_SIG_S|T1_SIG_W) + +#define T1_SGN_N 0x0100 +#define T1_SGN_E 0x0200 +#define T1_SGN_S 0x0400 +#define T1_SGN_W 0x0800 +#define T1_SGN (T1_SGN_N|T1_SGN_E|T1_SGN_S|T1_SGN_W) + +#define T1_SIG 0x1000 +#define T1_REFINE 0x2000 +#define T1_VISIT 0x4000 + +#define T1_NUMCTXS_AGG 1 +#define T1_NUMCTXS_ZC 9 +#define T1_NUMCTXS_MAG 3 +#define T1_NUMCTXS_SC 5 +#define T1_NUMCTXS_UNI 1 + +#define T1_CTXNO_AGG 0 +#define T1_CTXNO_ZC (T1_CTXNO_AGG+T1_NUMCTXS_AGG) +#define T1_CTXNO_MAG (T1_CTXNO_ZC+T1_NUMCTXS_ZC) +#define T1_CTXNO_SC (T1_CTXNO_MAG+T1_NUMCTXS_MAG) +#define T1_CTXNO_UNI (T1_CTXNO_SC+T1_NUMCTXS_SC) +#define T1_NUMCTXS (T1_CTXNO_UNI+T1_NUMCTXS_UNI) + +#define T1_NMSEDEC_FRACBITS (T1_NMSEDEC_BITS-1) + +#define T1_TYPE_MQ 0 /*< Normal coding using entropy coder */ +#define T1_TYPE_RAW 1 /*< No encoding the information is store under raw format in codestream (mode switch RAW)*/ + +/* ----------------------------------------------------------------------- */ + +/** +Tier-1 coding (coding of code-block coefficients) +*/ +typedef struct opj_t1 { + /** codec context */ + opj_common_ptr cinfo; + + /** MQC component */ + opj_mqc_t *mqc; + /** RAW component */ + opj_raw_t *raw; + /** LUTs for context-based coding */ + int lut_ctxno_zc[1024]; + int lut_ctxno_sc[256]; + int lut_ctxno_mag[4096]; + int lut_spb[256]; + /** LUTs for decoding normalised MSE */ + int lut_nmsedec_sig[1 << T1_NMSEDEC_BITS]; + int lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS]; + int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS]; + int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS]; + /** Codeblock data */ + int data[T1_CBLKD][T1_CBLKH][T1_CBLKW];/*int ***data;*/ + /** Context information for each voxel in codeblock */ + int flags[T1_CBLKD + 2][T1_CBLKH + 2][T1_CBLKH + 2];/*int ***flags;*/ +} opj_t1_t; + +/** @name Exported functions */ +/*@{*/ +/* ----------------------------------------------------------------------- */ +/** +Create a new T1 handle +and initialize the look-up tables of the Tier-1 coder/decoder +@return Returns a new T1 handle if successful, returns NULL otherwise +@see t1_init_luts +*/ +opj_t1_t* t1_create(opj_common_ptr cinfo); +/** +Destroy a previously created T1 handle +@param t1 T1 handle to destroy +*/ +void t1_destroy(opj_t1_t *t1); +/** +Encode the code-blocks of a tile +@param t1 T1 handle +@param tile The tile to encode +@param tcp Tile coding parameters +*/ +void t1_encode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp); +/** +Decode the code-blocks of a tile +@param t1 T1 handle +@param tile The tile to decode +@param tcp Tile coding parameters +*/ +void t1_decode_cblks(opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp); +/** +Get weigths of MSE decoding +@param nmsedec The normalized MSE reduction +@param compno +@param level +@param orient +@param bpno +@param stepsize +@param numcomps +@param dwtid +returns MSE associated to decoding pass +*/ +double t1_getwmsedec(int nmsedec, int compno, int level[3], int orient, int bpno, double stepsize, int numcomps, int dwtid[3]); + +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __T1_H */ diff --git a/src/lib/openjp3d/t1_3d.c b/src/lib/openjp3d/t1_3d.c index 24038242..63332d21 100644 --- a/src/lib/openjp3d/t1_3d.c +++ b/src/lib/openjp3d/t1_3d.c @@ -1,1230 +1,1230 @@ -/* - * Copyrigth (c) 2006, Mónica Díez, LPI-UVA, Spain - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "opj_includes.h" - -/** @defgroup T1_3D T1_3D - Implementation of the tier-1 coding */ -/*@{*/ - -/** @name Local static functions */ -/*@{*/ - -static int t1_3d_getctxno_zc(unsigned int f, int orient); -static int t1_3d_getctxno_sc(unsigned int f); -static int t1_3d_getctxno_mag(unsigned int f, int fsvr); -static int t1_3d_getspb(unsigned int f); -static int t1_3d_getnmsedec_sig(opj_t1_3d_t *t1, int x, int bitpos); -static int t1_3d_getnmsedec_ref(opj_t1_3d_t *t1, int x, int bitpos); -static void t1_3d_updateflags(unsigned int *fp, int s); -/** -Encode significant pass -*/ -static void t1_3d_enc_sigpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int orient, int bpno, int one, int *nmsedec, char type, int vsc); -/** -Decode significant pass -*/ -static void t1_3d_dec_sigpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int orient, int oneplushalf, char type, int vsc); -/** -Encode significant pass -*/ -static void t1_3d_enc_sigpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, char type, int cblksty); -/** -Decode significant pass -*/ -static void t1_3d_dec_sigpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int orient, char type, int cblksty); -/** -Encode refinement pass -*/ -static void t1_3d_enc_refpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int bpno, int one, int *nmsedec, char type, int vsc); -/** -Decode refinement pass -*/ -static void t1_3d_dec_refpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int poshalf, int neghalf, char type, int vsc); -/** -Encode refinement pass -*/ -static void t1_3d_enc_refpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int *nmsedec, char type, int cblksty); -/** -Decode refinement pass -*/ -static void t1_3d_dec_refpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, char type, int cblksty); -/** -Encode clean-up pass -*/ -static void t1_3d_enc_clnpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int orient, int bpno, int one, int *nmsedec, int partial, int vsc); -/** -Decode clean-up pass -*/ -static void t1_3d_dec_clnpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int orient, int oneplushalf, int partial, int vsc); -/** -Encode clean-up pass -*/ -static void t1_3d_enc_clnpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, int cblksty); -/** -Decode clean-up pass -*/ -static void t1_3d_dec_clnpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int orient, int cblksty); -/** -Encode 1 code-block -@param t1 T1 handle -@param cblk Code-block coding parameters -@param orient -@param compno Component number -@param level[3] -@param dwtid[3] -@param stepsize -@param cblksty Code-block style -@param numcomps -@param tile -*/ -static void t1_3d_encode_cblk(opj_t1_3d_t *t1, opj_tcd_cblk_t * cblk, int orient, int compno, int level[3], int dwtid[3], double stepsize, int cblksty, int numcomps, opj_tcd_tile_t * tile); -/** -Decode 1 code-block -@param t1 T1 handle -@param cblk Code-block coding parameters -@param orient -@param roishift Region of interest shifting value -@param cblksty Code-block style -*/ -static void t1_3d_decode_cblk(opj_t1_3d_t *t1, opj_tcd_cblk_t * cblk, int orient, int roishift, int cblksty); -static int t1_3d_init_ctxno_zc(unsigned int f, int orient); -static int t1_3d_init_ctxno_sc(unsigned int f); -static int t1_3d_init_ctxno_mag(unsigned int f, int f2); -static int t1_3d_init_spb(unsigned int f); -/** -Initialize the look-up tables of the Tier-1 coder/decoder -@param t1 T1 handle -*/ -static void t1_3d_init_luts(opj_t1_3d_t *t1); - -/*@}*/ - -/*@}*/ - -/* ----------------------------------------------------------------------- */ - -static int t1_3d_getctxno_zc(unsigned int f, int orient) { - return t1_3d_init_ctxno_zc((f & T1_3D_SIG_OTH), orient); -} - -static int t1_3d_getctxno_sc(unsigned int f) { - return t1_3d_init_ctxno_sc((f & T1_3D_SIG_PRIM) | ((f >> 16) & T1_3D_SGN)); - /*return t1->lut_ctxno_sc[((f & T1_3D_SIG_PRIM) | ((f >> 16) & T1_3D_SGN)) >> 4];*/ -} - -static int t1_3d_getctxno_mag(unsigned int f, int fsvr) { - return t1_3d_init_ctxno_mag((f & T1_3D_SIG_OTH), fsvr); -} - -static int t1_3d_getspb(unsigned int f) { - return t1_3d_init_spb((f & T1_3D_SIG_PRIM) | ((f >> 16) & T1_3D_SGN)); - /*return t1->lut_spb[((f & T1_3D_SIG_PRIM) | ((f >> 16) & T1_3D_SGN)) >> 4];*/ -} - -static int t1_3d_getnmsedec_sig(opj_t1_3d_t *t1, int x, int bitpos) { - if (bitpos > T1_NMSEDEC_FRACBITS) { - return t1->lut_nmsedec_sig[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)]; - } - - return t1->lut_nmsedec_sig0[x & ((1 << T1_NMSEDEC_BITS) - 1)]; -} - -static int t1_3d_getnmsedec_ref(opj_t1_3d_t *t1, int x, int bitpos) { - if (bitpos > T1_NMSEDEC_FRACBITS) { - return t1->lut_nmsedec_ref[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)]; - } - - return t1->lut_nmsedec_ref0[x & ((1 << T1_NMSEDEC_BITS) - 1)]; -} - -static void t1_3d_updateflags(unsigned int *fp, int s) { - unsigned int *np = fp - (T1_MAXCBLKW + 2); - unsigned int *sp = fp + (T1_MAXCBLKW + 2); - - unsigned int *bwp = fp + ((T1_MAXCBLKW + 2)*(T1_MAXCBLKH +2)); - unsigned int *bnp = bwp - (T1_MAXCBLKW + 2); - unsigned int *bsp = bwp + (T1_MAXCBLKW + 2); - - unsigned int *fwp = fp - ((T1_MAXCBLKW + 2)*(T1_MAXCBLKH +2)); - unsigned int *fnp = fwp - (T1_MAXCBLKW + 2); - unsigned int *fsp = fwp + (T1_MAXCBLKW + 2); - - np[-1] |= T1_3D_SIG_SE; - np[1] |= T1_3D_SIG_SW; - sp[-1] |= T1_3D_SIG_NE; - sp[1] |= T1_3D_SIG_NW; - *np |= T1_3D_SIG_S; - *sp |= T1_3D_SIG_N; - fp[-1] |= T1_3D_SIG_E; - fp[1] |= T1_3D_SIG_W; - - *fwp |= T1_3D_SIG_FC; - *bwp |= T1_3D_SIG_BC; - - fnp[-1] |= T1_3D_SIG_FSE; - fnp[1] |= T1_3D_SIG_FSW; - fsp[-1] |= T1_3D_SIG_FNE; - fsp[1] |= T1_3D_SIG_FNW; - *fnp |= T1_3D_SIG_FS; - *fsp |= T1_3D_SIG_FN; - fwp[-1] |= T1_3D_SIG_FE; - fwp[1] |= T1_3D_SIG_FW; - - bnp[-1] |= T1_3D_SIG_BSE; - bnp[1] |= T1_3D_SIG_BSW; - bsp[-1] |= T1_3D_SIG_BNE; - bsp[1] |= T1_3D_SIG_BNW; - *bnp |= T1_3D_SIG_BS; - *bsp |= T1_3D_SIG_BN; - bwp[-1] |= T1_3D_SIG_BE; - bwp[1] |= T1_3D_SIG_BW; - - if (s) { - *np |= (T1_3D_SGN_S << 16); - *sp |= (T1_3D_SGN_N << 16); - fp[-1] |= (T1_3D_SGN_E << 16); - fp[1] |= (T1_3D_SGN_W << 16); - *fwp |= (T1_3D_SGN_F << 16); - *bwp |= (T1_3D_SGN_B << 16); - } -} - -static void t1_3d_enc_sigpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int orient, int bpno, int one, int *nmsedec, char type, int vsc) { - int v, flagsvr; - unsigned int flag; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - flag = vsc ? ((*fp) & (~(T1_3D_SIG_S | T1_3D_SIG_SE | T1_3D_SIG_SW | (T1_3D_SGN_S << 16)))) : (*fp); - flagsvr = (*fsvr); - if ((flag & T1_3D_SIG_OTH) && !(flagsvr & (T1_3D_SIG | T1_3D_VISIT))) { - v = int_abs(*dp) & one ? 1 : 0; - if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ - mqc_setcurctx(mqc, t1_3d_getctxno_zc(flag, orient)); /* ESSAI */ - mqc_bypass_enc(mqc, v); - } else { - mqc_setcurctx(mqc, t1_3d_getctxno_zc(flag, orient)); - mqc_encode(mqc, v); - } - if (v) { - v = *dp < 0 ? 1 : 0; - *nmsedec += t1_3d_getnmsedec_sig(t1, int_abs(*dp), bpno + T1_NMSEDEC_FRACBITS); - if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ - mqc_setcurctx(mqc, t1_3d_getctxno_sc(flag)); /* ESSAI */ - mqc_bypass_enc(mqc, v); - } else { - mqc_setcurctx(mqc, t1_3d_getctxno_sc(flag)); - mqc_encode(mqc, v ^ t1_3d_getspb(flag)); - } - t1_3d_updateflags(fp, v); - *fsvr |= T1_3D_SIG; - } - *fsvr |= T1_3D_VISIT; - } -} - -static void t1_3d_dec_sigpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int orient, int oneplushalf, char type, int vsc) { - int v, flagsvr; - unsigned int flag; - - opj_raw_t *raw = t1->raw; /* RAW component */ - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - flag = vsc ? ((*fp) & (~(T1_3D_SIG_S | T1_3D_SIG_SE | T1_3D_SIG_SW | (T1_3D_SGN_S << 16)))) : (*fp); - flagsvr = (*fsvr); - if ((flag & T1_3D_SIG_OTH) && !(flagsvr & (T1_3D_SIG | T1_3D_VISIT))) { - if (type == T1_TYPE_RAW) { - if (raw_decode(raw)) { - v = raw_decode(raw); /* ESSAI */ - *dp = v ? -oneplushalf : oneplushalf; - t1_3d_updateflags(fp, v); - *fsvr |= T1_3D_SIG; - } - } else { - mqc_setcurctx(mqc, t1_3d_getctxno_zc(flag, orient)); - if (mqc_decode(mqc)) { - mqc_setcurctx(mqc, t1_3d_getctxno_sc(flag)); - v = mqc_decode(mqc) ^ t1_3d_getspb(flag); - *dp = v ? -oneplushalf : oneplushalf; - t1_3d_updateflags(fp, v); - *fsvr |= T1_3D_SIG; - } - } - *fsvr |= T1_3D_VISIT; - } -} /* VSC and BYPASS by Antonin */ - -static void t1_3d_enc_sigpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, char type, int cblksty) { - int i, j, k, m, one, vsc; - *nmsedec = 0; - one = 1 << (bpno + T1_NMSEDEC_FRACBITS); - for (m = 0; m < l; m++) { - for (k = 0; k < h; k += 4) { - for (i = 0; i < w; i++) { - for (j = k; j < k + 4 && j < h; j++) { - vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; - t1_3d_enc_sigpass_step(t1, &t1->flags[1 + m][1 + j][1 + i], &t1->flagSVR[1 + m][1 + j][1 + i], &t1->data[m][j][i], orient, bpno, one, nmsedec, type, vsc); - } - } - } - } -} - -static void t1_3d_dec_sigpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int orient, char type, int cblksty) { - int i, j, k, m, one, half, oneplushalf, vsc; - one = 1 << bpno; - half = one >> 1; - oneplushalf = one | half; - for (m = 0; m < l; m++) { - for (k = 0; k < h; k += 4) { - for (i = 0; i < w; i++) { - for (j = k; j < k + 4 && j < h; j++) { - vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; - t1_3d_dec_sigpass_step(t1, &t1->flags[1 + m][1 + j][1 + i], &t1->flagSVR[1 + m][1 + j][1 + i], &t1->data[m][j][i], orient, oneplushalf, type, vsc); - } - } - } - } -} /* VSC and BYPASS by Antonin */ - -static void t1_3d_enc_refpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int bpno, int one, int *nmsedec, char type, int vsc) { - int v, flagsvr; - unsigned int flag; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - flag = vsc ? ((*fp) & (~(T1_3D_SIG_S | T1_3D_SIG_SE | T1_3D_SIG_SW | (T1_3D_SGN_S << 16)))) : (*fp); - flagsvr = (*fsvr); - if ((flagsvr & (T1_3D_SIG | T1_3D_VISIT)) == T1_3D_SIG) { - *nmsedec += t1_3d_getnmsedec_ref(t1, int_abs(*dp), bpno + T1_NMSEDEC_FRACBITS); - v = int_abs(*dp) & one ? 1 : 0; - if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ - mqc_setcurctx(mqc, t1_3d_getctxno_mag(flag, flagsvr)); /* ESSAI */ - mqc_bypass_enc(mqc, v); - } else { - mqc_setcurctx(mqc, t1_3d_getctxno_mag(flag, flagsvr)); - mqc_encode(mqc, v); - } - *fsvr |= T1_3D_REFINE; - } -} - -static void t1_3d_dec_refpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int poshalf, int neghalf, char type, int vsc) { - int v, t, flagsvr; - unsigned int flag; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - opj_raw_t *raw = t1->raw; /* RAW component */ - - flag = vsc ? ((*fp) & (~(T1_3D_SIG_S | T1_3D_SIG_SE | T1_3D_SIG_SW | (T1_3D_SGN_S << 16)))) : (*fp); - flagsvr = (*fsvr); - if ((flagsvr & (T1_3D_SIG | T1_3D_VISIT)) == T1_3D_SIG) { - if (type == T1_TYPE_RAW) { - mqc_setcurctx(mqc, t1_3d_getctxno_mag(flag, flagsvr)); /* ESSAI */ - v = raw_decode(raw); - } else { - mqc_setcurctx(mqc, t1_3d_getctxno_mag(flag, flagsvr)); - v = mqc_decode(mqc); - } - t = v ? poshalf : neghalf; - *dp += *dp < 0 ? -t : t; - *fsvr |= T1_3D_REFINE; - } -} /* VSC and BYPASS by Antonin */ - -static void t1_3d_enc_refpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int *nmsedec, char type, int cblksty) { - int i, j, k, m, one, vsc; - *nmsedec = 0; - one = 1 << (bpno + T1_NMSEDEC_FRACBITS); - for (m = 0; m < l; m++){ - for (k = 0; k < h; k += 4) { - for (i = 0; i < w; i++) { - for (j = k; j < k + 4 && j < h; j++) { - vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; - t1_3d_enc_refpass_step(t1, &t1->flags[1 + m][1 + j][1 + i], &t1->flagSVR[1 + m][1 + j][1 + i], &t1->data[m][j][i], bpno, one, nmsedec, type, vsc); - } - } - } - } -} - -static void t1_3d_dec_refpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, char type, int cblksty) { - int i, j, k, m, one, poshalf, neghalf; - int vsc; - one = 1 << bpno; - poshalf = one >> 1; - neghalf = bpno > 0 ? -poshalf : -1; - for (m = 0; m < l; m++) { - for (k = 0; k < h; k += 4) { - for (i = 0; i < w; i++) { - for (j = k; j < k + 4 && j < h; j++) { - vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; - t1_3d_dec_refpass_step(t1, &t1->flags[1 + m][1 + j][1 + i], &t1->flagSVR[1 + m][1 + j][1 + i], &t1->data[m][j][i], poshalf, neghalf, type, vsc); - } - } - } - } -} /* VSC and BYPASS by Antonin */ - -static void t1_3d_enc_clnpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int orient, int bpno, int one, int *nmsedec, int partial, int vsc) { - int v, flagsvr; - unsigned int flag; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - flag = vsc ? ((*fp) & (~(T1_3D_SIG_S | T1_3D_SIG_SE | T1_3D_SIG_SW | (T1_3D_SGN_S << 16)))) : (*fp); - flagsvr = (*fsvr); - if (partial) { - goto LABEL_PARTIAL; - } - if (!(*fsvr & (T1_3D_SIG | T1_3D_VISIT))) { - mqc_setcurctx(mqc, t1_3d_getctxno_zc(flag, orient)); - v = int_abs(*dp) & one ? 1 : 0; - mqc_encode(mqc, v); - if (v) { -LABEL_PARTIAL: - *nmsedec += t1_3d_getnmsedec_sig(t1, int_abs(*dp), bpno + T1_NMSEDEC_FRACBITS); - mqc_setcurctx(mqc, t1_3d_getctxno_sc(flag)); - v = *dp < 0 ? 1 : 0; - mqc_encode(mqc, v ^ t1_3d_getspb(flag)); - t1_3d_updateflags(fp, v); - *fsvr |= T1_3D_SIG; - } - } - *fsvr &= ~T1_3D_VISIT; -} - -static void t1_3d_dec_clnpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int orient, int oneplushalf, int partial, int vsc) { - int v, flagsvr; - unsigned int flag; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - flag = vsc ? ((*fp) & (~(T1_3D_SIG_S | T1_3D_SIG_SE | T1_3D_SIG_SW | (T1_3D_SGN_S << 16)))) : (*fp); - flagsvr = (*fsvr); - if (partial) { - goto LABEL_PARTIAL; - } - if (!(flagsvr & (T1_3D_SIG | T1_3D_VISIT))) { - mqc_setcurctx(mqc, t1_3d_getctxno_zc(flag, orient)); - if (mqc_decode(mqc)) { -LABEL_PARTIAL: - mqc_setcurctx(mqc, t1_3d_getctxno_sc(flag)); - v = mqc_decode(mqc) ^ t1_3d_getspb(flag); - *dp = v ? -oneplushalf : oneplushalf; - t1_3d_updateflags(fp, v); - *fsvr |= T1_3D_SIG; - } - } - *fsvr &= ~T1_3D_VISIT; -} /* VSC and BYPASS by Antonin */ - -static void t1_3d_enc_clnpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, int cblksty) { - int i, j, k, m, one, agg, runlen, vsc; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - *nmsedec = 0; - one = 1 << (bpno + T1_NMSEDEC_FRACBITS); - for (m = 0; m < l; m++) { - for (k = 0; k < h; k += 4) { - for (i = 0; i < w; i++) { - if (k + 3 < h) { - if (cblksty & J3D_CCP_CBLKSTY_VSC) { - agg = !( ((t1->flagSVR[1 + m][1 + k][1 + i] | (T1_3D_SIG | T1_3D_VISIT)) & (t1->flags[1 + m][1 + k][1 + i] & T1_3D_SIG_OTH)) - || ((t1->flagSVR[1 + m][1 + k + 1][1 + i] | (T1_3D_SIG | T1_3D_VISIT)) & (t1->flags[1 + m][1 + k + 1][1 + i] & T1_3D_SIG_OTH)) - || ((t1->flagSVR[1 + m][1 + k + 2][1 + i] | (T1_3D_SIG | T1_3D_VISIT)) & (t1->flags[1 + m][1 + k + 2][1 + i] & T1_3D_SIG_OTH)) - || ((t1->flagSVR[1 + m][1 + k + 3][1 + i] | (T1_3D_SIG | T1_3D_VISIT)) & ((t1->flags[1 + m][1 + k + 3][1 + i] & (~(T1_3D_SIG_S | T1_3D_SIG_SE | T1_3D_SIG_SW | (T1_3D_SGN_S << 16)))) & (T1_3D_SIG_OTH))) - ); - } else { - agg = !( - ((t1->flagSVR[1 + m][1 + k][1 + i] & (T1_3D_SIG | T1_3D_VISIT)) | (t1->flags[1 + m][1 + k][1 + i] & T1_3D_SIG_OTH)) - || ((t1->flagSVR[1 + m][1 + k + 1][1 + i] & (T1_3D_SIG | T1_3D_VISIT)) | (t1->flags[1 + m][1 + k + 1][1 + i] & T1_3D_SIG_OTH)) - || ((t1->flagSVR[1 + m][1 + k + 2][1 + i] & (T1_3D_SIG | T1_3D_VISIT)) | (t1->flags[1 + m][1 + k + 2][1 + i] & T1_3D_SIG_OTH)) - || ((t1->flagSVR[1 + m][1 + k + 3][1 + i] & (T1_3D_SIG | T1_3D_VISIT)) | (t1->flags[1 + m][1 + k + 3][1 + i] & T1_3D_SIG_OTH)) - ); - } - } else { - agg = 0; - } - if (agg) { - for (runlen = 0; runlen < 4; runlen++) { - if (int_abs(t1->data[m][k + runlen][i]) & one) - break; - } - mqc_setcurctx(mqc, T1_CTXNO_AGG); - mqc_encode(mqc, runlen != 4); - if (runlen == 4) { - continue; - } - mqc_setcurctx(mqc, T1_CTXNO_UNI); - mqc_encode(mqc, runlen >> 1); - mqc_encode(mqc, runlen & 1); - } else { - runlen = 0; - } - for (j = k + runlen; j < k + 4 && j < h; j++) { - vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; - t1_3d_enc_clnpass_step(t1, &t1->flags[1 + m][1 + j][1 + i], &t1->flagSVR[1 + m][1 + j][1 + i], &t1->data[m][j][i], orient, bpno, one, nmsedec, agg && (j == k + runlen), vsc); - } - } - } - } -} - -static void t1_3d_dec_clnpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int orient, int cblksty) { - int i, j, k, m, one, half, oneplushalf, agg, runlen, vsc; - int segsym = cblksty & J3D_CCP_CBLKSTY_SEGSYM; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - one = 1 << bpno; - half = one >> 1; - oneplushalf = one | half; - for (m = 0; m < l; m++) { - for (k = 0; k < h; k += 4) { - for (i = 0; i < w; i++) { - if (k + 3 < h) { - if (cblksty & J3D_CCP_CBLKSTY_VSC) { - agg = !( - ((t1->flagSVR[1 + m][1 + k][1 + i] & (T1_3D_SIG | T1_3D_VISIT)) | (t1->flags[1 + m][1 + k][1 + i] & T1_3D_SIG_OTH)) - || ((t1->flagSVR[1 + m][1 + k + 1][1 + i] & (T1_3D_SIG | T1_3D_VISIT)) | (t1->flags[1 + m][1 + k + 1][1 + i] & T1_3D_SIG_OTH)) - || ((t1->flagSVR[1 + m][1 + k + 2][1 + i] & (T1_3D_SIG | T1_3D_VISIT)) | (t1->flags[1 + m][1 + k + 2][1 + i] & T1_3D_SIG_OTH)) - || ((t1->flagSVR[1 + m][1 + k + 3][1 + i] & (T1_3D_SIG | T1_3D_VISIT)) | ((t1->flags[1 + m][1 + k + 3][1 + i] & (~(T1_3D_SIG_S | T1_3D_SIG_SE | T1_3D_SIG_SW | (T1_3D_SGN_S << 16)))) & (T1_3D_SIG_OTH))) - ); - } else { - agg = !( - ((t1->flagSVR[1 + m][1 + k][1 + i] & (T1_3D_SIG | T1_3D_VISIT)) | (t1->flags[1 + m][1 + k][1 + i] & T1_3D_SIG_OTH)) - || ((t1->flagSVR[1 + m][1 + k + 1][1 + i] & (T1_3D_SIG | T1_3D_VISIT)) | (t1->flags[1 + m][1 + k + 1][1 + i] & T1_3D_SIG_OTH)) - || ((t1->flagSVR[1 + m][1 + k + 2][1 + i] & (T1_3D_SIG | T1_3D_VISIT)) | (t1->flags[1 + m][1 + k + 2][1 + i] & T1_3D_SIG_OTH)) - || ((t1->flagSVR[1 + m][1 + k + 3][1 + i] & (T1_3D_SIG | T1_3D_VISIT)) | (t1->flags[1 + m][1 + k + 3][1 + i] & T1_3D_SIG_OTH)) - ); - } - } else { - agg = 0; - } - if (agg) { - mqc_setcurctx(mqc, T1_CTXNO_AGG); - if (!mqc_decode(mqc)) { - continue; - } - mqc_setcurctx(mqc, T1_CTXNO_UNI); - runlen = mqc_decode(mqc); - runlen = (runlen << 1) | mqc_decode(mqc); - } else { - runlen = 0; - } - for (j = k + runlen; j < k + 4 && j < h; j++) { - vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; - t1_3d_dec_clnpass_step(t1, &t1->flags[1 + m][1 + j][1 + i], &t1->flagSVR[1 + m][1 + j][1 + i], &t1->data[m][j][i], orient, oneplushalf, agg && (j == k + runlen), vsc); - } - } - } - } - if (segsym) { - int v = 0; - mqc_setcurctx(mqc, T1_CTXNO_UNI); - v = mqc_decode(mqc); - v = (v << 1) | mqc_decode(mqc); - v = (v << 1) | mqc_decode(mqc); - v = (v << 1) | mqc_decode(mqc); - /* - if (v!=0xa) { - opj_event_msg(t1->cinfo, EVT_WARNING, "Bad segmentation symbol %x\n", v); - } - */ - } -} /* VSC and BYPASS by Antonin */ - - -static void t1_3d_encode_cblk(opj_t1_3d_t *t1, opj_tcd_cblk_t * cblk, int orient, int compno, int level[3], int dwtid[3], double stepsize, int cblksty, int numcomps, opj_tcd_tile_t * tile) { - int i, j, k; - int w, h, l; - int passno; - int bpno, passtype; - int max; - int nmsedec = 0; - double cumwmsedec = 0; - char type = T1_TYPE_MQ; - - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - w = cblk->x1 - cblk->x0; - h = cblk->y1 - cblk->y0; - l = cblk->z1 - cblk->z0; - - max = 0; - for (k = 0; k < l; k++) { - for (j = 0; j < h; j++) { - for (i = 0; i < w; i++) { - max = int_max(max, int_abs(t1->data[k][j][i])); - } - } - } - for (k = 0; k <= l; k++) { - for (j = 0; j <= h; j++) { - for (i = 0; i <= w; i++) { - t1->flags[k][j][i] = 0; - t1->flagSVR[k][j][i] = 0; - } - } - } - - cblk->numbps = max ? (int_floorlog2(max) + 1) - T1_NMSEDEC_FRACBITS : 0; - - bpno = cblk->numbps - 1; - passtype = 2; - - mqc_reset_enc(mqc); - mqc_init_enc(mqc, cblk->data); - - for (passno = 0; bpno >= 0; passno++) { - opj_tcd_pass_t *pass = &cblk->passes[passno]; - int correction = 3; - double tmpwmsedec; - type = ((bpno < (cblk->numbps - 4)) && (passtype < 2) && (cblksty & J3D_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ; - - switch (passtype) { - case 0: - t1_3d_enc_sigpass(t1, w, h, l, bpno, orient, &nmsedec, type, cblksty); - break; - case 1: - t1_3d_enc_refpass(t1, w, h, l, bpno, &nmsedec, type, cblksty); - break; - case 2: - t1_3d_enc_clnpass(t1, w, h, l, bpno, orient, &nmsedec, cblksty); - /* code switch SEGMARK (i.e. SEGSYM) */ - if (cblksty & J3D_CCP_CBLKSTY_SEGSYM) - mqc_segmark_enc(mqc); - break; - } - - /* fixed_quality */ - tmpwmsedec = t1_getwmsedec(nmsedec, compno, level, orient, bpno, stepsize, numcomps, dwtid); - cumwmsedec += tmpwmsedec; - tile->distotile += tmpwmsedec; - - /* Code switch "RESTART" (i.e. TERMALL) */ - if ((cblksty & J3D_CCP_CBLKSTY_TERMALL) && !((passtype == 2) && (bpno - 1 < 0))) { - if (type == T1_TYPE_RAW) { - mqc_flush(mqc); - correction = 1; - /* correction = mqc_bypass_flush_enc(); */ - } else { /* correction = mqc_restart_enc(); */ - mqc_flush(mqc); - correction = 1; - } - pass->term = 1; - } else { - if (((bpno < (cblk->numbps - 4) && (passtype > 0)) - || ((bpno == (cblk->numbps - 4)) && (passtype == 2))) && (cblksty & J3D_CCP_CBLKSTY_LAZY)) { - if (type == T1_TYPE_RAW) { - mqc_flush(mqc); - correction = 1; - } else { - mqc_flush(mqc); - correction = 1; - } - pass->term = 1; - } else { - pass->term = 0; - } - } - - if (++passtype == 3) { - passtype = 0; - bpno--; - } - - if (pass->term && bpno > 0) { - type = ((bpno < (cblk->numbps - 4)) && (passtype < 2) && (cblksty & J3D_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ; - if (type == T1_TYPE_RAW) - mqc_bypass_init_enc(mqc); - else - mqc_restart_init_enc(mqc); - } - - pass->distortiondec = cumwmsedec; - pass->rate = mqc_numbytes(mqc) + correction; /* FIXME */ - pass->len = pass->rate - (passno == 0 ? 0 : cblk->passes[passno - 1].rate); - - /* Code-switch "RESET" */ - if (cblksty & J3D_CCP_CBLKSTY_RESET) - mqc_reset_enc(mqc); - } - - /* Code switch "ERTERM" (i.e. PTERM) */ - if (cblksty & J3D_CCP_CBLKSTY_PTERM) - mqc_erterm_enc(mqc); - else /* Default coding */ if (!(cblksty & J3D_CCP_CBLKSTY_LAZY)) - mqc_flush(mqc); - - cblk->totalpasses = passno; -} - -static void t1_3d_decode_cblk(opj_t1_3d_t *t1, opj_tcd_cblk_t * cblk, int orient, int roishift, int cblksty) { - int i, j, k; - int w, h, l; - int bpno, passtype; - int segno, passno; - char type = T1_TYPE_MQ; /* BYPASS mode */ - opj_raw_t *raw = t1->raw; /* RAW component */ - opj_mqc_t *mqc = t1->mqc; /* MQC component */ - - w = cblk->x1 - cblk->x0; - h = cblk->y1 - cblk->y0; - l = cblk->z1 - cblk->z0; - - for (k = 0; k < l; k++) { - for (j = 0; j < h; j++) { - for (i = 0; i < w; i++) { - t1->data[k][j][i] = 0; - } - } - } - - for (k = 0; k <= l; k++) { - for (j = 0; j <= h; j++) { - for (i = 0; i <= w; i++) { - t1->flags[k][j][i] = 0; - t1->flagSVR[k][j][i] = 0; - } - } - } - - - bpno = roishift + cblk->numbps - 1; - passtype = 2; - - mqc_reset_enc(mqc); - - for (segno = 0; segno < cblk->numsegs; segno++) { - opj_tcd_seg_t *seg = &cblk->segs[segno]; - - /* BYPASS mode */ - type = ((bpno <= (cblk->numbps - 1) - 4) && (passtype < 2) && (cblksty & J3D_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ; - if (type == T1_TYPE_RAW) { - raw_init_dec(raw, seg->data, seg->len); - } else { - mqc_init_dec(mqc, seg->data, seg->len); - } - - for (passno = 0; passno < seg->numpasses; passno++) { - switch (passtype) { - case 0: - t1_3d_dec_sigpass(t1, w, h, l, bpno+1, orient, type, cblksty); - break; - case 1: - t1_3d_dec_refpass(t1, w, h, l, bpno+1, type, cblksty); - break; - case 2: - t1_3d_dec_clnpass(t1, w, h, l, bpno+1, orient, cblksty); - break; - } - - if ((cblksty & J3D_CCP_CBLKSTY_RESET) && type == T1_TYPE_MQ) { - mqc_reset_enc(mqc); - } - if (++passtype == 3) { - passtype = 0; - bpno--; - } - - } - } -} - -static int t1_3d_init_ctxno_zc(unsigned int f, int orient) { - unsigned int h, v, c; - unsigned int d2xy, d2xz, d2yz, d3; - int n; - unsigned int hvc, hc, d2, d2xy2yz, d2xy2xz; - n = 0; - h = ((f & T1_3D_SIG_W) != 0) + ((f & T1_3D_SIG_E) != 0); - v = ((f & T1_3D_SIG_N) != 0) + ((f & T1_3D_SIG_S) != 0); - c = ((f & T1_3D_SIG_FC) != 0) + ((f & T1_3D_SIG_BC) != 0); - d2xy = ((f & T1_3D_SIG_NW) != 0) + ((f & T1_3D_SIG_NE) != 0) + ((f & T1_3D_SIG_SE) != 0) + ((f & T1_3D_SIG_SW) != 0); - d2xz = ((f & T1_3D_SIG_FW) != 0) + ((f & T1_3D_SIG_BW) != 0) + ((f & T1_3D_SIG_FE) != 0) + ((f & T1_3D_SIG_BE) != 0); - d2yz = ((f & T1_3D_SIG_FN) != 0) + ((f & T1_3D_SIG_FS) != 0) + ((f & T1_3D_SIG_BN) != 0) + ((f & T1_3D_SIG_BS) != 0); - d3 = ((f & T1_3D_SIG_FNW) != 0) + ((f & T1_3D_SIG_FNE) != 0) + ((f & T1_3D_SIG_FSE) != 0) + ((f & T1_3D_SIG_FSW) != 0) - + ((f & T1_3D_SIG_BNW) != 0) + ((f & T1_3D_SIG_BNE) != 0) + ((f & T1_3D_SIG_BSE) != 0) + ((f & T1_3D_SIG_BSW) != 0); - - switch (orient) { - case 0: /*LLL*/ - case 7: /*HHH*/ - hvc = h + v + c; - d2 = d2xy + d2xz + d2yz; - if (!hvc) { - if (!d2) { - n = (!d3) ? 0 : 1; - } else if (d2 == 1) { - n = (!d3) ? 2 : 3; - } else { - n = (!d3) ? 4 : 5; - } - } else if (hvc == 1) { - if (!d2) { - n = (!d3) ? 6 : 7; - } else if (d2 == 1) { - n = (!d3) ? 8 : 9; - } else { - n = 10; - } - } else if (hvc == 2) { - if (!d2) { - n = (!d3) ? 11 : 12; - } else { - n = 13; - } - } else if (hvc == 3) { - n = 14; - } else { - n = 15; - } - break; - /*LHL, HLL, LLH*/ - case 1: - case 2: - case 4: - hc = h + c; - d2xy2yz = d2xy + d2yz; - if (!hc) { - if (!v) { - if (!d2xy) { - n = (!d2xy2yz) ? ((!d3) ? 0 : 1) : ((!d3) ? 2 : 3); - } else if (d2xy == 1) { - n = (!d2xy2yz) ? ((!d3) ? 4 : 5) : 6; - } else { /*>=2*/ - n = 7; - } - } else { - n = (v == 1) ? 8 : 9; /* =1 or =2*/ - } - } else if (hc == 1) { - n = (!v) ? ( (!d2xy) ? ( (!d2xy2yz) ? ( (!d3) ? 10 : 11) : (12) ) : (13) ) : (14); - } else { /*if (hc >= 2)*/ - n = 15; - } - break; - /*HLH, HHL, LHH*/ - case 3: - case 5: - case 6: - hc = h + c; - d2xy2xz = d2xy + d2xz; - if (!v) { - if (!d2xz) { - if (!hc && !d2xy2xz) { - n = (!d3) ? 0 : 1; - } else if (hc == 1) { - n = (!d2xy2xz) ? 2 : 3; - } else { /*if >= 2*/ - n = 4; - } - } else if ( d2xz>=1 && !hc ) { - n = 5; - } else if ( hc>=1 ) { - n = (d2xz==1) ? 6 : 7; - } - } else if (v == 1) { - if (!d2xz) { - n = (!hc) ? 8 : 9; - } else if (d2xz == 1) { - n = (!hc) ? 10 : 11; - } else if (d2xz == 2) { - n = (!hc) ? 12 : 13; - } else { /* if (d2xz >= 3) {*/ - n = 14; - } - } else if (v == 2) { - n = 15; - } - break; - } - - return (T1_3D_CTXNO_ZC + n); -} - -static int t1_3d_init_ctxno_sc(unsigned int f) { - int hc, vc, cc; - int n = 0; - - hc = int_min( ( (f & (T1_3D_SIG_E | T1_3D_SGN_E)) == T1_3D_SIG_E ) - + ( (f & (T1_3D_SIG_W | T1_3D_SGN_W)) == T1_3D_SIG_W ) , 1) - - int_min( ( (f & (T1_3D_SIG_E | T1_3D_SGN_E)) == (T1_3D_SIG_E | T1_3D_SGN_E) ) - + ( (f & (T1_3D_SIG_W | T1_3D_SGN_W) ) == (T1_3D_SIG_W | T1_3D_SGN_W)), 1); - - vc = int_min(((f & (T1_3D_SIG_N | T1_3D_SGN_N)) == T1_3D_SIG_N) - + ((f & (T1_3D_SIG_S | T1_3D_SGN_S)) == T1_3D_SIG_S), 1) - - int_min(((f & (T1_3D_SIG_N | T1_3D_SGN_N)) == (T1_3D_SIG_N | T1_3D_SGN_N)) - + ((f & (T1_3D_SIG_S | T1_3D_SGN_S)) == (T1_3D_SIG_S | T1_3D_SGN_S)), 1); - - cc = int_min(((f & (T1_3D_SIG_FC | T1_3D_SGN_F)) == T1_3D_SIG_FC) - + ((f & (T1_3D_SIG_BC | T1_3D_SGN_B)) == T1_3D_SIG_BC), 1) - - int_min(((f & (T1_3D_SIG_FC | T1_3D_SGN_F)) == (T1_3D_SIG_FC | T1_3D_SGN_F)) - + ((f & (T1_3D_SIG_BC | T1_3D_SGN_B)) == (T1_3D_SIG_BC | T1_3D_SGN_B)), 1); - if (hc < 0) { - hc = -hc; - vc = -vc; - cc = -cc; - } - - if (!hc) { - if (!vc) - n = (!cc) ? 0 : 1; - else if (vc == -1) - n = (!cc) ? 1 : ( (cc>0) ? 2 : 4); - else if (vc == 1) - n = (!cc) ? 1 : ( (cc<0) ? 2 : 4); - } else if (hc == 1) { - if (!vc) - n = (!cc) ? 1 : ( (cc<0) ? 2 : 4); - else if (vc == 1) - n = (!cc) ? 4 : ( (cc>0) ? 5 : 3); - else if (vc == -1) - n = (!cc) ? 2 : 3; - } else if (hc == -1) { - if (!vc) - n = (!cc) ? 1 : ( (cc>0) ? 2 : 4); - else if (vc == 1) - n = (!cc) ? 2 : 3; - else if (vc == -1) - n = (!cc) ? 4 : ( (cc<0) ? 5 : 3); - } - - return (T1_3D_CTXNO_SC + n); -} - -static int t1_3d_init_ctxno_mag(unsigned int f, int f2) { - int n; - if (!(f2 & T1_3D_REFINE)) /*First refinement for this coefficient (no previous refinement)*/ - n = (f & (T1_3D_SIG_PRIM)) ? 1 : 0; - else - n = 2; - - return (T1_3D_CTXNO_MAG + n); -} - -static int t1_3d_init_spb(unsigned int f) { - int hc, vc, cc; - int n = 0; - - hc = int_min( ( (f & (T1_3D_SIG_E | T1_3D_SGN_E)) == T1_3D_SIG_E ) - + ( (f & (T1_3D_SIG_W | T1_3D_SGN_W)) == T1_3D_SIG_W ) , 1) - - int_min( ( (f & (T1_3D_SIG_E | T1_3D_SGN_E)) == (T1_3D_SIG_E | T1_3D_SGN_E) ) - + ( (f & (T1_3D_SIG_W | T1_3D_SGN_W) ) == (T1_3D_SIG_W | T1_3D_SGN_W)), 1); - - vc = int_min(((f & (T1_3D_SIG_N | T1_3D_SGN_N)) == T1_3D_SIG_N) - + ((f & (T1_3D_SIG_S | T1_3D_SGN_S)) == T1_3D_SIG_S), 1) - - int_min(((f & (T1_3D_SIG_N | T1_3D_SGN_N)) == (T1_3D_SIG_N | T1_3D_SGN_N)) - + ((f & (T1_3D_SIG_S | T1_3D_SGN_S)) == (T1_3D_SIG_S | T1_3D_SGN_S)), 1); - - cc = int_min(((f & (T1_3D_SIG_FC | T1_3D_SGN_F)) == T1_3D_SIG_FC) - + ((f & (T1_3D_SIG_BC | T1_3D_SGN_B)) == T1_3D_SIG_BC), 1) - - int_min(((f & (T1_3D_SIG_FC | T1_3D_SGN_F)) == (T1_3D_SIG_FC | T1_3D_SGN_F)) - + ((f & (T1_3D_SIG_BC | T1_3D_SGN_B)) == (T1_3D_SIG_BC | T1_3D_SGN_B)), 1); - - n = ((hc + vc + cc) < 0); - - return n; -} - -static void t1_3d_init_luts(opj_t1_3d_t *t1) { - int i; - double u, v, t; - /*for (j = 0; j < 4; j++) { - for (i = 0; i < 256; ++i) { - t1->lut_ctxno_zc[(j << 8) | i] = t1_3d_init_ctxno_zc(i, j); - } - } - for (i = 0; i < 4096; i++) { - t1->lut_ctxno_sc[i] = t1_3d_init_ctxno_sc(i << 4); - } - for (j = 0; j < 2; j++) { - for (i = 0; i < 2048; ++i) { - t1->lut_ctxno_mag[(j << 11) + i] = t1_3d_init_ctxno_mag((j ? T1_3D_REFINE : 0) | i); - } - } - for (i = 0; i < 4096; ++i) { - t1->lut_spb[i] = t1_3d_init_spb(i << 4); - }*/ - /* FIXME FIXME FIXME */ - for (i = 0; i < (1 << T1_NMSEDEC_BITS); i++) { - t = i / pow(2, T1_NMSEDEC_FRACBITS); - u = t; - v = t - 1.5; - t1->lut_nmsedec_sig[i] = - int_max(0, - (int) (floor((u * u - v * v) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0)); - t1->lut_nmsedec_sig0[i] = - int_max(0, - (int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0)); - u = t - 1.0; - if (i & (1 << (T1_NMSEDEC_BITS - 1))) { - v = t - 1.5; - } else { - v = t - 0.5; - } - t1->lut_nmsedec_ref[i] = - int_max(0, - (int) (floor((u * u - v * v) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0)); - t1->lut_nmsedec_ref0[i] = - int_max(0, - (int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0)); - } -} - -/* ----------------------------------------------------------------------- */ - -opj_t1_3d_t* t1_3d_create(opj_common_ptr cinfo) { - opj_t1_3d_t *t1 = (opj_t1_3d_t*)opj_malloc(sizeof(opj_t1_3d_t)); - if(t1) { - t1->cinfo = cinfo; - /* create MQC and RAW handles */ - t1->mqc = mqc_create(); - t1->raw = raw_create(); - /* initialize the look-up tables of the Tier-1 coder/decoder */ - t1_3d_init_luts(t1); - } - return t1; -} - -void t1_3d_destroy(opj_t1_3d_t *t1) { - if(t1) { - /* destroy MQC and RAW handles */ - mqc_destroy(t1->mqc); - raw_destroy(t1->raw); - opj_free(t1); - } -} - -void t1_3d_encode_cblks(opj_t1_3d_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) { - int compno, resno, bandno, precno, cblkno; - int x, y, z, i, j, k, orient; - int level[3]; - tile->distotile = 0; /* fixed_quality */ - - for (compno = 0; compno < tile->numcomps; compno++) { - opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; - - for (resno = 0; resno < tilec->numresolution[0]; resno++) { - opj_tcd_resolution_t *res = &tilec->resolutions[resno]; - - for (bandno = 0; bandno < res->numbands; bandno++) { - opj_tcd_band_t *band = &res->bands[bandno]; - - for (precno = 0; precno < res->prctno[0] * res->prctno[1] * res->prctno[2]; precno++) { - opj_tcd_precinct_t *prc = &band->precincts[precno]; - - for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { - opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; - - if (band->bandno == 0) { - x = cblk->x0 - band->x0; - y = cblk->y0 - band->y0; - z = cblk->z0 - band->z0; - } else if (band->bandno == 1) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = pres->x1 - pres->x0 + cblk->x0 - band->x0; - y = cblk->y0 - band->y0; - z = cblk->z0 - band->z0; - } else if (band->bandno == 2) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = cblk->x0 - band->x0; - y = pres->y1 - pres->y0 + cblk->y0 - band->y0; - z = cblk->z0 - band->z0; - } else if (band->bandno == 3) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = pres->x1 - pres->x0 + cblk->x0 - band->x0; - y = pres->y1 - pres->y0 + cblk->y0 - band->y0; - z = cblk->z0 - band->z0; - } else if (band->bandno == 4) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = cblk->x0 - band->x0; - y = cblk->y0 - band->y0; - z = pres->z1 - pres->z0 + cblk->z0 - band->z0; - } else if (band->bandno == 5) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = pres->x1 - pres->x0 + cblk->x0 - band->x0; - y = cblk->y0 - band->y0; - z = pres->z1 - pres->z0 + cblk->z0 - band->z0; - } else if (band->bandno == 6) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = cblk->x0 - band->x0; - y = pres->y1 - pres->y0 + cblk->y0 - band->y0; - z = pres->z1 - pres->z0 + cblk->z0 - band->z0; - } else if (band->bandno == 7) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = pres->x1 - pres->x0 + cblk->x0 - band->x0; - y = pres->y1 - pres->y0 + cblk->y0 - band->y0; - z = pres->z1 - pres->z0 + cblk->z0 - band->z0; - } - - if (tcp->tccps[compno].reversible == 1) { - for (k = 0; k < cblk->z1 - cblk->z0; k++) { - for (j = 0; j < cblk->y1 - cblk->y0; j++) { - for (i = 0; i < cblk->x1 - cblk->x0; i++) { - t1->data[k][j][i] = - tilec->data[(x + i) + (y + j) * (tilec->x1 - tilec->x0) + (z + k) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)] << T1_NMSEDEC_FRACBITS; - } - } - } - } else if (tcp->tccps[compno].reversible == 0) { - for (k = 0; k < cblk->z1 - cblk->z0; k++) { - for (j = 0; j < cblk->y1 - cblk->y0; j++) { - for (i = 0; i < cblk->x1 - cblk->x0; i++) { - t1->data[k][j][i] = fix_mul( - tilec->data[(x + i) + (y + j) * (tilec->x1 - tilec->x0) + (z + k) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)], - 8192 * 8192 / ((int) floor(band->stepsize * 8192))) >> (13 - T1_NMSEDEC_FRACBITS); - } - } - } - } - orient = band->bandno; /* FIXME */ - for (i = 0; i < 3; i++) - level[i] = tilec->numresolution[i] - 1 - resno; - - t1_3d_encode_cblk(t1, cblk, orient, compno, level, tcp->tccps[compno].dwtid, band->stepsize, tcp->tccps[compno].cblksty, tile->numcomps, tile); - - } /* cblkno */ - } /* precno */ - } /* bandno */ - } /* resno */ - } /* compno */ -} - -void t1_3d_decode_cblks(opj_t1_3d_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) { - int compno, resno, bandno, precno, cblkno; - - for (compno = 0; compno < tile->numcomps; compno++) { - opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; - - for (resno = 0; resno < tilec->numresolution[0]; resno++) { - opj_tcd_resolution_t *res = &tilec->resolutions[resno]; - - for (bandno = 0; bandno < res->numbands; bandno++) { - opj_tcd_band_t *band = &res->bands[bandno]; - - for (precno = 0; precno < res->prctno[0] * res->prctno[1] * res->prctno[2]; precno++) { - opj_tcd_precinct_t *prc = &band->precincts[precno]; - - for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { - int x, y, z, i, j, k, orient; - opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; - - orient = band->bandno; /* FIXME */ - - /*fprintf(stdout,"[INFO] t1_3d_decode_cblk(t1, cblk, orient(%d), tcp->tccps[compno].roishift (%d), tcp->tccps[compno].cblksty (%d));\n",orient,tcp->tccps[compno].roishift, tcp->tccps[compno].cblksty);*/ - t1_3d_decode_cblk(t1, cblk, orient, tcp->tccps[compno].roishift, tcp->tccps[compno].cblksty); - - if (band->bandno == 0) { - x = cblk->x0 - band->x0; - y = cblk->y0 - band->y0; - z = cblk->z0 - band->z0; - } else if (band->bandno == 1) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = pres->x1 - pres->x0 + cblk->x0 - band->x0; - y = cblk->y0 - band->y0; - z = cblk->z0 - band->z0; - } else if (band->bandno == 2) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = cblk->x0 - band->x0; - y = pres->y1 - pres->y0 + cblk->y0 - band->y0; - z = cblk->z0 - band->z0; - } else if (band->bandno == 3) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = pres->x1 - pres->x0 + cblk->x0 - band->x0; - y = pres->y1 - pres->y0 + cblk->y0 - band->y0; - z = cblk->z0 - band->z0; - } else if (band->bandno == 4) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = cblk->x0 - band->x0; - y = cblk->y0 - band->y0; - z = pres->z1 - pres->z0 + cblk->z0 - band->z0; - } else if (band->bandno == 5) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = pres->x1 - pres->x0 + cblk->x0 - band->x0; - y = cblk->y0 - band->y0; - z = pres->z1 - pres->z0 + cblk->z0 - band->z0; - } else if (band->bandno == 6) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = cblk->x0 - band->x0; - y = pres->y1 - pres->y0 + cblk->y0 - band->y0; - z = pres->z1 - pres->z0 + cblk->z0 - band->z0; - } else if (band->bandno == 7) { - opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; - x = pres->x1 - pres->x0 + cblk->x0 - band->x0; - y = pres->y1 - pres->y0 + cblk->y0 - band->y0; - z = pres->z1 - pres->z0 + cblk->z0 - band->z0; - } - - if (tcp->tccps[compno].roishift) { - int thresh, val, mag; - thresh = 1 << tcp->tccps[compno].roishift; - for (k = 0; k < cblk->z1 - cblk->z0; k++) { - for (j = 0; j < cblk->y1 - cblk->y0; j++) { - for (i = 0; i < cblk->x1 - cblk->x0; i++) { - val = t1->data[k][j][i]; - mag = int_abs(val); - if (mag >= thresh) { - mag >>= tcp->tccps[compno].roishift; - t1->data[k][j][i] = val < 0 ? -mag : mag; - } - } - } - } - } - - if (tcp->tccps[compno].reversible == 1) { - for (k = 0; k < cblk->z1 - cblk->z0; k++) { - for (j = 0; j < cblk->y1 - cblk->y0; j++) { - for (i = 0; i < cblk->x1 - cblk->x0; i++) { - int tmp = t1->data[k][j][i]; - tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0) + (z + k) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)] = tmp/2; - } - } - } - } else { /* if (tcp->tccps[compno].reversible == 0) */ - for (k = 0; k < cblk->z1 - cblk->z0; k++) { - for (j = 0; j < cblk->y1 - cblk->y0; j++) { - for (i = 0; i < cblk->x1 - cblk->x0; i++) { - double tmp = (double)(t1->data[k][j][i] * band->stepsize * 4096.0); - if (t1->data[k][j][i] >> 1 == 0) { - tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0) + (z + k) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)] = 0; - } else { - int tmp2 = ((int) (floor(fabs(tmp)))) + ((int) floor(fabs(tmp*2))%2); - tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0) + (z + k) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)] = ((tmp<0)?-tmp2:tmp2); - } - } - } - } - } - } /* cblkno */ - } /* precno */ - } /* bandno */ - } /* resno */ - } /* compno */ -} +/* + * Copyrigth (c) 2006, Mónica Díez, LPI-UVA, Spain + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opj_includes.h" + +/** @defgroup T1_3D T1_3D - Implementation of the tier-1 coding */ +/*@{*/ + +/** @name Local static functions */ +/*@{*/ + +static int t1_3d_getctxno_zc(unsigned int f, int orient); +static int t1_3d_getctxno_sc(unsigned int f); +static int t1_3d_getctxno_mag(unsigned int f, int fsvr); +static int t1_3d_getspb(unsigned int f); +static int t1_3d_getnmsedec_sig(opj_t1_3d_t *t1, int x, int bitpos); +static int t1_3d_getnmsedec_ref(opj_t1_3d_t *t1, int x, int bitpos); +static void t1_3d_updateflags(unsigned int *fp, int s); +/** +Encode significant pass +*/ +static void t1_3d_enc_sigpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int orient, int bpno, int one, int *nmsedec, char type, int vsc); +/** +Decode significant pass +*/ +static void t1_3d_dec_sigpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int orient, int oneplushalf, char type, int vsc); +/** +Encode significant pass +*/ +static void t1_3d_enc_sigpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, char type, int cblksty); +/** +Decode significant pass +*/ +static void t1_3d_dec_sigpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int orient, char type, int cblksty); +/** +Encode refinement pass +*/ +static void t1_3d_enc_refpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int bpno, int one, int *nmsedec, char type, int vsc); +/** +Decode refinement pass +*/ +static void t1_3d_dec_refpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int poshalf, int neghalf, char type, int vsc); +/** +Encode refinement pass +*/ +static void t1_3d_enc_refpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int *nmsedec, char type, int cblksty); +/** +Decode refinement pass +*/ +static void t1_3d_dec_refpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, char type, int cblksty); +/** +Encode clean-up pass +*/ +static void t1_3d_enc_clnpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int orient, int bpno, int one, int *nmsedec, int partial, int vsc); +/** +Decode clean-up pass +*/ +static void t1_3d_dec_clnpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int orient, int oneplushalf, int partial, int vsc); +/** +Encode clean-up pass +*/ +static void t1_3d_enc_clnpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, int cblksty); +/** +Decode clean-up pass +*/ +static void t1_3d_dec_clnpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int orient, int cblksty); +/** +Encode 1 code-block +@param t1 T1 handle +@param cblk Code-block coding parameters +@param orient +@param compno Component number +@param level[3] +@param dwtid[3] +@param stepsize +@param cblksty Code-block style +@param numcomps +@param tile +*/ +static void t1_3d_encode_cblk(opj_t1_3d_t *t1, opj_tcd_cblk_t * cblk, int orient, int compno, int level[3], int dwtid[3], double stepsize, int cblksty, int numcomps, opj_tcd_tile_t * tile); +/** +Decode 1 code-block +@param t1 T1 handle +@param cblk Code-block coding parameters +@param orient +@param roishift Region of interest shifting value +@param cblksty Code-block style +*/ +static void t1_3d_decode_cblk(opj_t1_3d_t *t1, opj_tcd_cblk_t * cblk, int orient, int roishift, int cblksty); +static int t1_3d_init_ctxno_zc(unsigned int f, int orient); +static int t1_3d_init_ctxno_sc(unsigned int f); +static int t1_3d_init_ctxno_mag(unsigned int f, int f2); +static int t1_3d_init_spb(unsigned int f); +/** +Initialize the look-up tables of the Tier-1 coder/decoder +@param t1 T1 handle +*/ +static void t1_3d_init_luts(opj_t1_3d_t *t1); + +/*@}*/ + +/*@}*/ + +/* ----------------------------------------------------------------------- */ + +static int t1_3d_getctxno_zc(unsigned int f, int orient) { + return t1_3d_init_ctxno_zc((f & T1_3D_SIG_OTH), orient); +} + +static int t1_3d_getctxno_sc(unsigned int f) { + return t1_3d_init_ctxno_sc((f & T1_3D_SIG_PRIM) | ((f >> 16) & T1_3D_SGN)); + /*return t1->lut_ctxno_sc[((f & T1_3D_SIG_PRIM) | ((f >> 16) & T1_3D_SGN)) >> 4];*/ +} + +static int t1_3d_getctxno_mag(unsigned int f, int fsvr) { + return t1_3d_init_ctxno_mag((f & T1_3D_SIG_OTH), fsvr); +} + +static int t1_3d_getspb(unsigned int f) { + return t1_3d_init_spb((f & T1_3D_SIG_PRIM) | ((f >> 16) & T1_3D_SGN)); + /*return t1->lut_spb[((f & T1_3D_SIG_PRIM) | ((f >> 16) & T1_3D_SGN)) >> 4];*/ +} + +static int t1_3d_getnmsedec_sig(opj_t1_3d_t *t1, int x, int bitpos) { + if (bitpos > T1_NMSEDEC_FRACBITS) { + return t1->lut_nmsedec_sig[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)]; + } + + return t1->lut_nmsedec_sig0[x & ((1 << T1_NMSEDEC_BITS) - 1)]; +} + +static int t1_3d_getnmsedec_ref(opj_t1_3d_t *t1, int x, int bitpos) { + if (bitpos > T1_NMSEDEC_FRACBITS) { + return t1->lut_nmsedec_ref[(x >> (bitpos - T1_NMSEDEC_FRACBITS)) & ((1 << T1_NMSEDEC_BITS) - 1)]; + } + + return t1->lut_nmsedec_ref0[x & ((1 << T1_NMSEDEC_BITS) - 1)]; +} + +static void t1_3d_updateflags(unsigned int *fp, int s) { + unsigned int *np = fp - (T1_MAXCBLKW + 2); + unsigned int *sp = fp + (T1_MAXCBLKW + 2); + + unsigned int *bwp = fp + ((T1_MAXCBLKW + 2)*(T1_MAXCBLKH +2)); + unsigned int *bnp = bwp - (T1_MAXCBLKW + 2); + unsigned int *bsp = bwp + (T1_MAXCBLKW + 2); + + unsigned int *fwp = fp - ((T1_MAXCBLKW + 2)*(T1_MAXCBLKH +2)); + unsigned int *fnp = fwp - (T1_MAXCBLKW + 2); + unsigned int *fsp = fwp + (T1_MAXCBLKW + 2); + + np[-1] |= T1_3D_SIG_SE; + np[1] |= T1_3D_SIG_SW; + sp[-1] |= T1_3D_SIG_NE; + sp[1] |= T1_3D_SIG_NW; + *np |= T1_3D_SIG_S; + *sp |= T1_3D_SIG_N; + fp[-1] |= T1_3D_SIG_E; + fp[1] |= T1_3D_SIG_W; + + *fwp |= T1_3D_SIG_FC; + *bwp |= T1_3D_SIG_BC; + + fnp[-1] |= T1_3D_SIG_FSE; + fnp[1] |= T1_3D_SIG_FSW; + fsp[-1] |= T1_3D_SIG_FNE; + fsp[1] |= T1_3D_SIG_FNW; + *fnp |= T1_3D_SIG_FS; + *fsp |= T1_3D_SIG_FN; + fwp[-1] |= T1_3D_SIG_FE; + fwp[1] |= T1_3D_SIG_FW; + + bnp[-1] |= T1_3D_SIG_BSE; + bnp[1] |= T1_3D_SIG_BSW; + bsp[-1] |= T1_3D_SIG_BNE; + bsp[1] |= T1_3D_SIG_BNW; + *bnp |= T1_3D_SIG_BS; + *bsp |= T1_3D_SIG_BN; + bwp[-1] |= T1_3D_SIG_BE; + bwp[1] |= T1_3D_SIG_BW; + + if (s) { + *np |= (T1_3D_SGN_S << 16); + *sp |= (T1_3D_SGN_N << 16); + fp[-1] |= (T1_3D_SGN_E << 16); + fp[1] |= (T1_3D_SGN_W << 16); + *fwp |= (T1_3D_SGN_F << 16); + *bwp |= (T1_3D_SGN_B << 16); + } +} + +static void t1_3d_enc_sigpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int orient, int bpno, int one, int *nmsedec, char type, int vsc) { + int v, flagsvr; + unsigned int flag; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + flag = vsc ? ((*fp) & (~(T1_3D_SIG_S | T1_3D_SIG_SE | T1_3D_SIG_SW | (T1_3D_SGN_S << 16)))) : (*fp); + flagsvr = (*fsvr); + if ((flag & T1_3D_SIG_OTH) && !(flagsvr & (T1_3D_SIG | T1_3D_VISIT))) { + v = int_abs(*dp) & one ? 1 : 0; + if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ + mqc_setcurctx(mqc, t1_3d_getctxno_zc(flag, orient)); /* ESSAI */ + mqc_bypass_enc(mqc, v); + } else { + mqc_setcurctx(mqc, t1_3d_getctxno_zc(flag, orient)); + mqc_encode(mqc, v); + } + if (v) { + v = *dp < 0 ? 1 : 0; + *nmsedec += t1_3d_getnmsedec_sig(t1, int_abs(*dp), bpno + T1_NMSEDEC_FRACBITS); + if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ + mqc_setcurctx(mqc, t1_3d_getctxno_sc(flag)); /* ESSAI */ + mqc_bypass_enc(mqc, v); + } else { + mqc_setcurctx(mqc, t1_3d_getctxno_sc(flag)); + mqc_encode(mqc, v ^ t1_3d_getspb(flag)); + } + t1_3d_updateflags(fp, v); + *fsvr |= T1_3D_SIG; + } + *fsvr |= T1_3D_VISIT; + } +} + +static void t1_3d_dec_sigpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int orient, int oneplushalf, char type, int vsc) { + int v, flagsvr; + unsigned int flag; + + opj_raw_t *raw = t1->raw; /* RAW component */ + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + flag = vsc ? ((*fp) & (~(T1_3D_SIG_S | T1_3D_SIG_SE | T1_3D_SIG_SW | (T1_3D_SGN_S << 16)))) : (*fp); + flagsvr = (*fsvr); + if ((flag & T1_3D_SIG_OTH) && !(flagsvr & (T1_3D_SIG | T1_3D_VISIT))) { + if (type == T1_TYPE_RAW) { + if (raw_decode(raw)) { + v = raw_decode(raw); /* ESSAI */ + *dp = v ? -oneplushalf : oneplushalf; + t1_3d_updateflags(fp, v); + *fsvr |= T1_3D_SIG; + } + } else { + mqc_setcurctx(mqc, t1_3d_getctxno_zc(flag, orient)); + if (mqc_decode(mqc)) { + mqc_setcurctx(mqc, t1_3d_getctxno_sc(flag)); + v = mqc_decode(mqc) ^ t1_3d_getspb(flag); + *dp = v ? -oneplushalf : oneplushalf; + t1_3d_updateflags(fp, v); + *fsvr |= T1_3D_SIG; + } + } + *fsvr |= T1_3D_VISIT; + } +} /* VSC and BYPASS by Antonin */ + +static void t1_3d_enc_sigpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, char type, int cblksty) { + int i, j, k, m, one, vsc; + *nmsedec = 0; + one = 1 << (bpno + T1_NMSEDEC_FRACBITS); + for (m = 0; m < l; m++) { + for (k = 0; k < h; k += 4) { + for (i = 0; i < w; i++) { + for (j = k; j < k + 4 && j < h; j++) { + vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; + t1_3d_enc_sigpass_step(t1, &t1->flags[1 + m][1 + j][1 + i], &t1->flagSVR[1 + m][1 + j][1 + i], &t1->data[m][j][i], orient, bpno, one, nmsedec, type, vsc); + } + } + } + } +} + +static void t1_3d_dec_sigpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int orient, char type, int cblksty) { + int i, j, k, m, one, half, oneplushalf, vsc; + one = 1 << bpno; + half = one >> 1; + oneplushalf = one | half; + for (m = 0; m < l; m++) { + for (k = 0; k < h; k += 4) { + for (i = 0; i < w; i++) { + for (j = k; j < k + 4 && j < h; j++) { + vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; + t1_3d_dec_sigpass_step(t1, &t1->flags[1 + m][1 + j][1 + i], &t1->flagSVR[1 + m][1 + j][1 + i], &t1->data[m][j][i], orient, oneplushalf, type, vsc); + } + } + } + } +} /* VSC and BYPASS by Antonin */ + +static void t1_3d_enc_refpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int bpno, int one, int *nmsedec, char type, int vsc) { + int v, flagsvr; + unsigned int flag; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + flag = vsc ? ((*fp) & (~(T1_3D_SIG_S | T1_3D_SIG_SE | T1_3D_SIG_SW | (T1_3D_SGN_S << 16)))) : (*fp); + flagsvr = (*fsvr); + if ((flagsvr & (T1_3D_SIG | T1_3D_VISIT)) == T1_3D_SIG) { + *nmsedec += t1_3d_getnmsedec_ref(t1, int_abs(*dp), bpno + T1_NMSEDEC_FRACBITS); + v = int_abs(*dp) & one ? 1 : 0; + if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ + mqc_setcurctx(mqc, t1_3d_getctxno_mag(flag, flagsvr)); /* ESSAI */ + mqc_bypass_enc(mqc, v); + } else { + mqc_setcurctx(mqc, t1_3d_getctxno_mag(flag, flagsvr)); + mqc_encode(mqc, v); + } + *fsvr |= T1_3D_REFINE; + } +} + +static void t1_3d_dec_refpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int poshalf, int neghalf, char type, int vsc) { + int v, t, flagsvr; + unsigned int flag; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + opj_raw_t *raw = t1->raw; /* RAW component */ + + flag = vsc ? ((*fp) & (~(T1_3D_SIG_S | T1_3D_SIG_SE | T1_3D_SIG_SW | (T1_3D_SGN_S << 16)))) : (*fp); + flagsvr = (*fsvr); + if ((flagsvr & (T1_3D_SIG | T1_3D_VISIT)) == T1_3D_SIG) { + if (type == T1_TYPE_RAW) { + mqc_setcurctx(mqc, t1_3d_getctxno_mag(flag, flagsvr)); /* ESSAI */ + v = raw_decode(raw); + } else { + mqc_setcurctx(mqc, t1_3d_getctxno_mag(flag, flagsvr)); + v = mqc_decode(mqc); + } + t = v ? poshalf : neghalf; + *dp += *dp < 0 ? -t : t; + *fsvr |= T1_3D_REFINE; + } +} /* VSC and BYPASS by Antonin */ + +static void t1_3d_enc_refpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int *nmsedec, char type, int cblksty) { + int i, j, k, m, one, vsc; + *nmsedec = 0; + one = 1 << (bpno + T1_NMSEDEC_FRACBITS); + for (m = 0; m < l; m++){ + for (k = 0; k < h; k += 4) { + for (i = 0; i < w; i++) { + for (j = k; j < k + 4 && j < h; j++) { + vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; + t1_3d_enc_refpass_step(t1, &t1->flags[1 + m][1 + j][1 + i], &t1->flagSVR[1 + m][1 + j][1 + i], &t1->data[m][j][i], bpno, one, nmsedec, type, vsc); + } + } + } + } +} + +static void t1_3d_dec_refpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, char type, int cblksty) { + int i, j, k, m, one, poshalf, neghalf; + int vsc; + one = 1 << bpno; + poshalf = one >> 1; + neghalf = bpno > 0 ? -poshalf : -1; + for (m = 0; m < l; m++) { + for (k = 0; k < h; k += 4) { + for (i = 0; i < w; i++) { + for (j = k; j < k + 4 && j < h; j++) { + vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; + t1_3d_dec_refpass_step(t1, &t1->flags[1 + m][1 + j][1 + i], &t1->flagSVR[1 + m][1 + j][1 + i], &t1->data[m][j][i], poshalf, neghalf, type, vsc); + } + } + } + } +} /* VSC and BYPASS by Antonin */ + +static void t1_3d_enc_clnpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int orient, int bpno, int one, int *nmsedec, int partial, int vsc) { + int v, flagsvr; + unsigned int flag; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + flag = vsc ? ((*fp) & (~(T1_3D_SIG_S | T1_3D_SIG_SE | T1_3D_SIG_SW | (T1_3D_SGN_S << 16)))) : (*fp); + flagsvr = (*fsvr); + if (partial) { + goto LABEL_PARTIAL; + } + if (!(*fsvr & (T1_3D_SIG | T1_3D_VISIT))) { + mqc_setcurctx(mqc, t1_3d_getctxno_zc(flag, orient)); + v = int_abs(*dp) & one ? 1 : 0; + mqc_encode(mqc, v); + if (v) { +LABEL_PARTIAL: + *nmsedec += t1_3d_getnmsedec_sig(t1, int_abs(*dp), bpno + T1_NMSEDEC_FRACBITS); + mqc_setcurctx(mqc, t1_3d_getctxno_sc(flag)); + v = *dp < 0 ? 1 : 0; + mqc_encode(mqc, v ^ t1_3d_getspb(flag)); + t1_3d_updateflags(fp, v); + *fsvr |= T1_3D_SIG; + } + } + *fsvr &= ~T1_3D_VISIT; +} + +static void t1_3d_dec_clnpass_step(opj_t1_3d_t *t1, unsigned int *fp, int *fsvr, int *dp, int orient, int oneplushalf, int partial, int vsc) { + int v, flagsvr; + unsigned int flag; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + flag = vsc ? ((*fp) & (~(T1_3D_SIG_S | T1_3D_SIG_SE | T1_3D_SIG_SW | (T1_3D_SGN_S << 16)))) : (*fp); + flagsvr = (*fsvr); + if (partial) { + goto LABEL_PARTIAL; + } + if (!(flagsvr & (T1_3D_SIG | T1_3D_VISIT))) { + mqc_setcurctx(mqc, t1_3d_getctxno_zc(flag, orient)); + if (mqc_decode(mqc)) { +LABEL_PARTIAL: + mqc_setcurctx(mqc, t1_3d_getctxno_sc(flag)); + v = mqc_decode(mqc) ^ t1_3d_getspb(flag); + *dp = v ? -oneplushalf : oneplushalf; + t1_3d_updateflags(fp, v); + *fsvr |= T1_3D_SIG; + } + } + *fsvr &= ~T1_3D_VISIT; +} /* VSC and BYPASS by Antonin */ + +static void t1_3d_enc_clnpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int orient, int *nmsedec, int cblksty) { + int i, j, k, m, one, agg, runlen, vsc; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + *nmsedec = 0; + one = 1 << (bpno + T1_NMSEDEC_FRACBITS); + for (m = 0; m < l; m++) { + for (k = 0; k < h; k += 4) { + for (i = 0; i < w; i++) { + if (k + 3 < h) { + if (cblksty & J3D_CCP_CBLKSTY_VSC) { + agg = !( ((t1->flagSVR[1 + m][1 + k][1 + i] | (T1_3D_SIG | T1_3D_VISIT)) & (t1->flags[1 + m][1 + k][1 + i] & T1_3D_SIG_OTH)) + || ((t1->flagSVR[1 + m][1 + k + 1][1 + i] | (T1_3D_SIG | T1_3D_VISIT)) & (t1->flags[1 + m][1 + k + 1][1 + i] & T1_3D_SIG_OTH)) + || ((t1->flagSVR[1 + m][1 + k + 2][1 + i] | (T1_3D_SIG | T1_3D_VISIT)) & (t1->flags[1 + m][1 + k + 2][1 + i] & T1_3D_SIG_OTH)) + || ((t1->flagSVR[1 + m][1 + k + 3][1 + i] | (T1_3D_SIG | T1_3D_VISIT)) & ((t1->flags[1 + m][1 + k + 3][1 + i] & (~(T1_3D_SIG_S | T1_3D_SIG_SE | T1_3D_SIG_SW | (T1_3D_SGN_S << 16)))) & (T1_3D_SIG_OTH))) + ); + } else { + agg = !( + ((t1->flagSVR[1 + m][1 + k][1 + i] & (T1_3D_SIG | T1_3D_VISIT)) | (t1->flags[1 + m][1 + k][1 + i] & T1_3D_SIG_OTH)) + || ((t1->flagSVR[1 + m][1 + k + 1][1 + i] & (T1_3D_SIG | T1_3D_VISIT)) | (t1->flags[1 + m][1 + k + 1][1 + i] & T1_3D_SIG_OTH)) + || ((t1->flagSVR[1 + m][1 + k + 2][1 + i] & (T1_3D_SIG | T1_3D_VISIT)) | (t1->flags[1 + m][1 + k + 2][1 + i] & T1_3D_SIG_OTH)) + || ((t1->flagSVR[1 + m][1 + k + 3][1 + i] & (T1_3D_SIG | T1_3D_VISIT)) | (t1->flags[1 + m][1 + k + 3][1 + i] & T1_3D_SIG_OTH)) + ); + } + } else { + agg = 0; + } + if (agg) { + for (runlen = 0; runlen < 4; runlen++) { + if (int_abs(t1->data[m][k + runlen][i]) & one) + break; + } + mqc_setcurctx(mqc, T1_CTXNO_AGG); + mqc_encode(mqc, runlen != 4); + if (runlen == 4) { + continue; + } + mqc_setcurctx(mqc, T1_CTXNO_UNI); + mqc_encode(mqc, runlen >> 1); + mqc_encode(mqc, runlen & 1); + } else { + runlen = 0; + } + for (j = k + runlen; j < k + 4 && j < h; j++) { + vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; + t1_3d_enc_clnpass_step(t1, &t1->flags[1 + m][1 + j][1 + i], &t1->flagSVR[1 + m][1 + j][1 + i], &t1->data[m][j][i], orient, bpno, one, nmsedec, agg && (j == k + runlen), vsc); + } + } + } + } +} + +static void t1_3d_dec_clnpass(opj_t1_3d_t *t1, int w, int h, int l, int bpno, int orient, int cblksty) { + int i, j, k, m, one, half, oneplushalf, agg, runlen, vsc; + int segsym = cblksty & J3D_CCP_CBLKSTY_SEGSYM; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + one = 1 << bpno; + half = one >> 1; + oneplushalf = one | half; + for (m = 0; m < l; m++) { + for (k = 0; k < h; k += 4) { + for (i = 0; i < w; i++) { + if (k + 3 < h) { + if (cblksty & J3D_CCP_CBLKSTY_VSC) { + agg = !( + ((t1->flagSVR[1 + m][1 + k][1 + i] & (T1_3D_SIG | T1_3D_VISIT)) | (t1->flags[1 + m][1 + k][1 + i] & T1_3D_SIG_OTH)) + || ((t1->flagSVR[1 + m][1 + k + 1][1 + i] & (T1_3D_SIG | T1_3D_VISIT)) | (t1->flags[1 + m][1 + k + 1][1 + i] & T1_3D_SIG_OTH)) + || ((t1->flagSVR[1 + m][1 + k + 2][1 + i] & (T1_3D_SIG | T1_3D_VISIT)) | (t1->flags[1 + m][1 + k + 2][1 + i] & T1_3D_SIG_OTH)) + || ((t1->flagSVR[1 + m][1 + k + 3][1 + i] & (T1_3D_SIG | T1_3D_VISIT)) | ((t1->flags[1 + m][1 + k + 3][1 + i] & (~(T1_3D_SIG_S | T1_3D_SIG_SE | T1_3D_SIG_SW | (T1_3D_SGN_S << 16)))) & (T1_3D_SIG_OTH))) + ); + } else { + agg = !( + ((t1->flagSVR[1 + m][1 + k][1 + i] & (T1_3D_SIG | T1_3D_VISIT)) | (t1->flags[1 + m][1 + k][1 + i] & T1_3D_SIG_OTH)) + || ((t1->flagSVR[1 + m][1 + k + 1][1 + i] & (T1_3D_SIG | T1_3D_VISIT)) | (t1->flags[1 + m][1 + k + 1][1 + i] & T1_3D_SIG_OTH)) + || ((t1->flagSVR[1 + m][1 + k + 2][1 + i] & (T1_3D_SIG | T1_3D_VISIT)) | (t1->flags[1 + m][1 + k + 2][1 + i] & T1_3D_SIG_OTH)) + || ((t1->flagSVR[1 + m][1 + k + 3][1 + i] & (T1_3D_SIG | T1_3D_VISIT)) | (t1->flags[1 + m][1 + k + 3][1 + i] & T1_3D_SIG_OTH)) + ); + } + } else { + agg = 0; + } + if (agg) { + mqc_setcurctx(mqc, T1_CTXNO_AGG); + if (!mqc_decode(mqc)) { + continue; + } + mqc_setcurctx(mqc, T1_CTXNO_UNI); + runlen = mqc_decode(mqc); + runlen = (runlen << 1) | mqc_decode(mqc); + } else { + runlen = 0; + } + for (j = k + runlen; j < k + 4 && j < h; j++) { + vsc = ((cblksty & J3D_CCP_CBLKSTY_VSC) && (j == k + 3 || j == h - 1)) ? 1 : 0; + t1_3d_dec_clnpass_step(t1, &t1->flags[1 + m][1 + j][1 + i], &t1->flagSVR[1 + m][1 + j][1 + i], &t1->data[m][j][i], orient, oneplushalf, agg && (j == k + runlen), vsc); + } + } + } + } + if (segsym) { + int v = 0; + mqc_setcurctx(mqc, T1_CTXNO_UNI); + v = mqc_decode(mqc); + v = (v << 1) | mqc_decode(mqc); + v = (v << 1) | mqc_decode(mqc); + v = (v << 1) | mqc_decode(mqc); + /* + if (v!=0xa) { + opj_event_msg(t1->cinfo, EVT_WARNING, "Bad segmentation symbol %x\n", v); + } + */ + } +} /* VSC and BYPASS by Antonin */ + + +static void t1_3d_encode_cblk(opj_t1_3d_t *t1, opj_tcd_cblk_t * cblk, int orient, int compno, int level[3], int dwtid[3], double stepsize, int cblksty, int numcomps, opj_tcd_tile_t * tile) { + int i, j, k; + int w, h, l; + int passno; + int bpno, passtype; + int max; + int nmsedec = 0; + double cumwmsedec = 0; + char type = T1_TYPE_MQ; + + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + w = cblk->x1 - cblk->x0; + h = cblk->y1 - cblk->y0; + l = cblk->z1 - cblk->z0; + + max = 0; + for (k = 0; k < l; k++) { + for (j = 0; j < h; j++) { + for (i = 0; i < w; i++) { + max = int_max(max, int_abs(t1->data[k][j][i])); + } + } + } + for (k = 0; k <= l; k++) { + for (j = 0; j <= h; j++) { + for (i = 0; i <= w; i++) { + t1->flags[k][j][i] = 0; + t1->flagSVR[k][j][i] = 0; + } + } + } + + cblk->numbps = max ? (int_floorlog2(max) + 1) - T1_NMSEDEC_FRACBITS : 0; + + bpno = cblk->numbps - 1; + passtype = 2; + + mqc_reset_enc(mqc); + mqc_init_enc(mqc, cblk->data); + + for (passno = 0; bpno >= 0; passno++) { + opj_tcd_pass_t *pass = &cblk->passes[passno]; + int correction = 3; + double tmpwmsedec; + type = ((bpno < (cblk->numbps - 4)) && (passtype < 2) && (cblksty & J3D_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ; + + switch (passtype) { + case 0: + t1_3d_enc_sigpass(t1, w, h, l, bpno, orient, &nmsedec, type, cblksty); + break; + case 1: + t1_3d_enc_refpass(t1, w, h, l, bpno, &nmsedec, type, cblksty); + break; + case 2: + t1_3d_enc_clnpass(t1, w, h, l, bpno, orient, &nmsedec, cblksty); + /* code switch SEGMARK (i.e. SEGSYM) */ + if (cblksty & J3D_CCP_CBLKSTY_SEGSYM) + mqc_segmark_enc(mqc); + break; + } + + /* fixed_quality */ + tmpwmsedec = t1_getwmsedec(nmsedec, compno, level, orient, bpno, stepsize, numcomps, dwtid); + cumwmsedec += tmpwmsedec; + tile->distotile += tmpwmsedec; + + /* Code switch "RESTART" (i.e. TERMALL) */ + if ((cblksty & J3D_CCP_CBLKSTY_TERMALL) && !((passtype == 2) && (bpno - 1 < 0))) { + if (type == T1_TYPE_RAW) { + mqc_flush(mqc); + correction = 1; + /* correction = mqc_bypass_flush_enc(); */ + } else { /* correction = mqc_restart_enc(); */ + mqc_flush(mqc); + correction = 1; + } + pass->term = 1; + } else { + if (((bpno < (cblk->numbps - 4) && (passtype > 0)) + || ((bpno == (cblk->numbps - 4)) && (passtype == 2))) && (cblksty & J3D_CCP_CBLKSTY_LAZY)) { + if (type == T1_TYPE_RAW) { + mqc_flush(mqc); + correction = 1; + } else { + mqc_flush(mqc); + correction = 1; + } + pass->term = 1; + } else { + pass->term = 0; + } + } + + if (++passtype == 3) { + passtype = 0; + bpno--; + } + + if (pass->term && bpno > 0) { + type = ((bpno < (cblk->numbps - 4)) && (passtype < 2) && (cblksty & J3D_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ; + if (type == T1_TYPE_RAW) + mqc_bypass_init_enc(mqc); + else + mqc_restart_init_enc(mqc); + } + + pass->distortiondec = cumwmsedec; + pass->rate = mqc_numbytes(mqc) + correction; /* FIXME */ + pass->len = pass->rate - (passno == 0 ? 0 : cblk->passes[passno - 1].rate); + + /* Code-switch "RESET" */ + if (cblksty & J3D_CCP_CBLKSTY_RESET) + mqc_reset_enc(mqc); + } + + /* Code switch "ERTERM" (i.e. PTERM) */ + if (cblksty & J3D_CCP_CBLKSTY_PTERM) + mqc_erterm_enc(mqc); + else /* Default coding */ if (!(cblksty & J3D_CCP_CBLKSTY_LAZY)) + mqc_flush(mqc); + + cblk->totalpasses = passno; +} + +static void t1_3d_decode_cblk(opj_t1_3d_t *t1, opj_tcd_cblk_t * cblk, int orient, int roishift, int cblksty) { + int i, j, k; + int w, h, l; + int bpno, passtype; + int segno, passno; + char type = T1_TYPE_MQ; /* BYPASS mode */ + opj_raw_t *raw = t1->raw; /* RAW component */ + opj_mqc_t *mqc = t1->mqc; /* MQC component */ + + w = cblk->x1 - cblk->x0; + h = cblk->y1 - cblk->y0; + l = cblk->z1 - cblk->z0; + + for (k = 0; k < l; k++) { + for (j = 0; j < h; j++) { + for (i = 0; i < w; i++) { + t1->data[k][j][i] = 0; + } + } + } + + for (k = 0; k <= l; k++) { + for (j = 0; j <= h; j++) { + for (i = 0; i <= w; i++) { + t1->flags[k][j][i] = 0; + t1->flagSVR[k][j][i] = 0; + } + } + } + + + bpno = roishift + cblk->numbps - 1; + passtype = 2; + + mqc_reset_enc(mqc); + + for (segno = 0; segno < cblk->numsegs; segno++) { + opj_tcd_seg_t *seg = &cblk->segs[segno]; + + /* BYPASS mode */ + type = ((bpno <= (cblk->numbps - 1) - 4) && (passtype < 2) && (cblksty & J3D_CCP_CBLKSTY_LAZY)) ? T1_TYPE_RAW : T1_TYPE_MQ; + if (type == T1_TYPE_RAW) { + raw_init_dec(raw, seg->data, seg->len); + } else { + mqc_init_dec(mqc, seg->data, seg->len); + } + + for (passno = 0; passno < seg->numpasses; passno++) { + switch (passtype) { + case 0: + t1_3d_dec_sigpass(t1, w, h, l, bpno+1, orient, type, cblksty); + break; + case 1: + t1_3d_dec_refpass(t1, w, h, l, bpno+1, type, cblksty); + break; + case 2: + t1_3d_dec_clnpass(t1, w, h, l, bpno+1, orient, cblksty); + break; + } + + if ((cblksty & J3D_CCP_CBLKSTY_RESET) && type == T1_TYPE_MQ) { + mqc_reset_enc(mqc); + } + if (++passtype == 3) { + passtype = 0; + bpno--; + } + + } + } +} + +static int t1_3d_init_ctxno_zc(unsigned int f, int orient) { + unsigned int h, v, c; + unsigned int d2xy, d2xz, d2yz, d3; + int n; + unsigned int hvc, hc, d2, d2xy2yz, d2xy2xz; + n = 0; + h = ((f & T1_3D_SIG_W) != 0) + ((f & T1_3D_SIG_E) != 0); + v = ((f & T1_3D_SIG_N) != 0) + ((f & T1_3D_SIG_S) != 0); + c = ((f & T1_3D_SIG_FC) != 0) + ((f & T1_3D_SIG_BC) != 0); + d2xy = ((f & T1_3D_SIG_NW) != 0) + ((f & T1_3D_SIG_NE) != 0) + ((f & T1_3D_SIG_SE) != 0) + ((f & T1_3D_SIG_SW) != 0); + d2xz = ((f & T1_3D_SIG_FW) != 0) + ((f & T1_3D_SIG_BW) != 0) + ((f & T1_3D_SIG_FE) != 0) + ((f & T1_3D_SIG_BE) != 0); + d2yz = ((f & T1_3D_SIG_FN) != 0) + ((f & T1_3D_SIG_FS) != 0) + ((f & T1_3D_SIG_BN) != 0) + ((f & T1_3D_SIG_BS) != 0); + d3 = ((f & T1_3D_SIG_FNW) != 0) + ((f & T1_3D_SIG_FNE) != 0) + ((f & T1_3D_SIG_FSE) != 0) + ((f & T1_3D_SIG_FSW) != 0) + + ((f & T1_3D_SIG_BNW) != 0) + ((f & T1_3D_SIG_BNE) != 0) + ((f & T1_3D_SIG_BSE) != 0) + ((f & T1_3D_SIG_BSW) != 0); + + switch (orient) { + case 0: /*LLL*/ + case 7: /*HHH*/ + hvc = h + v + c; + d2 = d2xy + d2xz + d2yz; + if (!hvc) { + if (!d2) { + n = (!d3) ? 0 : 1; + } else if (d2 == 1) { + n = (!d3) ? 2 : 3; + } else { + n = (!d3) ? 4 : 5; + } + } else if (hvc == 1) { + if (!d2) { + n = (!d3) ? 6 : 7; + } else if (d2 == 1) { + n = (!d3) ? 8 : 9; + } else { + n = 10; + } + } else if (hvc == 2) { + if (!d2) { + n = (!d3) ? 11 : 12; + } else { + n = 13; + } + } else if (hvc == 3) { + n = 14; + } else { + n = 15; + } + break; + /*LHL, HLL, LLH*/ + case 1: + case 2: + case 4: + hc = h + c; + d2xy2yz = d2xy + d2yz; + if (!hc) { + if (!v) { + if (!d2xy) { + n = (!d2xy2yz) ? ((!d3) ? 0 : 1) : ((!d3) ? 2 : 3); + } else if (d2xy == 1) { + n = (!d2xy2yz) ? ((!d3) ? 4 : 5) : 6; + } else { /*>=2*/ + n = 7; + } + } else { + n = (v == 1) ? 8 : 9; /* =1 or =2*/ + } + } else if (hc == 1) { + n = (!v) ? ( (!d2xy) ? ( (!d2xy2yz) ? ( (!d3) ? 10 : 11) : (12) ) : (13) ) : (14); + } else { /*if (hc >= 2)*/ + n = 15; + } + break; + /*HLH, HHL, LHH*/ + case 3: + case 5: + case 6: + hc = h + c; + d2xy2xz = d2xy + d2xz; + if (!v) { + if (!d2xz) { + if (!hc && !d2xy2xz) { + n = (!d3) ? 0 : 1; + } else if (hc == 1) { + n = (!d2xy2xz) ? 2 : 3; + } else { /*if >= 2*/ + n = 4; + } + } else if ( d2xz>=1 && !hc ) { + n = 5; + } else if ( hc>=1 ) { + n = (d2xz==1) ? 6 : 7; + } + } else if (v == 1) { + if (!d2xz) { + n = (!hc) ? 8 : 9; + } else if (d2xz == 1) { + n = (!hc) ? 10 : 11; + } else if (d2xz == 2) { + n = (!hc) ? 12 : 13; + } else { /* if (d2xz >= 3) {*/ + n = 14; + } + } else if (v == 2) { + n = 15; + } + break; + } + + return (T1_3D_CTXNO_ZC + n); +} + +static int t1_3d_init_ctxno_sc(unsigned int f) { + int hc, vc, cc; + int n = 0; + + hc = int_min( ( (f & (T1_3D_SIG_E | T1_3D_SGN_E)) == T1_3D_SIG_E ) + + ( (f & (T1_3D_SIG_W | T1_3D_SGN_W)) == T1_3D_SIG_W ) , 1) + - int_min( ( (f & (T1_3D_SIG_E | T1_3D_SGN_E)) == (T1_3D_SIG_E | T1_3D_SGN_E) ) + + ( (f & (T1_3D_SIG_W | T1_3D_SGN_W) ) == (T1_3D_SIG_W | T1_3D_SGN_W)), 1); + + vc = int_min(((f & (T1_3D_SIG_N | T1_3D_SGN_N)) == T1_3D_SIG_N) + + ((f & (T1_3D_SIG_S | T1_3D_SGN_S)) == T1_3D_SIG_S), 1) + - int_min(((f & (T1_3D_SIG_N | T1_3D_SGN_N)) == (T1_3D_SIG_N | T1_3D_SGN_N)) + + ((f & (T1_3D_SIG_S | T1_3D_SGN_S)) == (T1_3D_SIG_S | T1_3D_SGN_S)), 1); + + cc = int_min(((f & (T1_3D_SIG_FC | T1_3D_SGN_F)) == T1_3D_SIG_FC) + + ((f & (T1_3D_SIG_BC | T1_3D_SGN_B)) == T1_3D_SIG_BC), 1) + - int_min(((f & (T1_3D_SIG_FC | T1_3D_SGN_F)) == (T1_3D_SIG_FC | T1_3D_SGN_F)) + + ((f & (T1_3D_SIG_BC | T1_3D_SGN_B)) == (T1_3D_SIG_BC | T1_3D_SGN_B)), 1); + if (hc < 0) { + hc = -hc; + vc = -vc; + cc = -cc; + } + + if (!hc) { + if (!vc) + n = (!cc) ? 0 : 1; + else if (vc == -1) + n = (!cc) ? 1 : ( (cc>0) ? 2 : 4); + else if (vc == 1) + n = (!cc) ? 1 : ( (cc<0) ? 2 : 4); + } else if (hc == 1) { + if (!vc) + n = (!cc) ? 1 : ( (cc<0) ? 2 : 4); + else if (vc == 1) + n = (!cc) ? 4 : ( (cc>0) ? 5 : 3); + else if (vc == -1) + n = (!cc) ? 2 : 3; + } else if (hc == -1) { + if (!vc) + n = (!cc) ? 1 : ( (cc>0) ? 2 : 4); + else if (vc == 1) + n = (!cc) ? 2 : 3; + else if (vc == -1) + n = (!cc) ? 4 : ( (cc<0) ? 5 : 3); + } + + return (T1_3D_CTXNO_SC + n); +} + +static int t1_3d_init_ctxno_mag(unsigned int f, int f2) { + int n; + if (!(f2 & T1_3D_REFINE)) /*First refinement for this coefficient (no previous refinement)*/ + n = (f & (T1_3D_SIG_PRIM)) ? 1 : 0; + else + n = 2; + + return (T1_3D_CTXNO_MAG + n); +} + +static int t1_3d_init_spb(unsigned int f) { + int hc, vc, cc; + int n = 0; + + hc = int_min( ( (f & (T1_3D_SIG_E | T1_3D_SGN_E)) == T1_3D_SIG_E ) + + ( (f & (T1_3D_SIG_W | T1_3D_SGN_W)) == T1_3D_SIG_W ) , 1) + - int_min( ( (f & (T1_3D_SIG_E | T1_3D_SGN_E)) == (T1_3D_SIG_E | T1_3D_SGN_E) ) + + ( (f & (T1_3D_SIG_W | T1_3D_SGN_W) ) == (T1_3D_SIG_W | T1_3D_SGN_W)), 1); + + vc = int_min(((f & (T1_3D_SIG_N | T1_3D_SGN_N)) == T1_3D_SIG_N) + + ((f & (T1_3D_SIG_S | T1_3D_SGN_S)) == T1_3D_SIG_S), 1) + - int_min(((f & (T1_3D_SIG_N | T1_3D_SGN_N)) == (T1_3D_SIG_N | T1_3D_SGN_N)) + + ((f & (T1_3D_SIG_S | T1_3D_SGN_S)) == (T1_3D_SIG_S | T1_3D_SGN_S)), 1); + + cc = int_min(((f & (T1_3D_SIG_FC | T1_3D_SGN_F)) == T1_3D_SIG_FC) + + ((f & (T1_3D_SIG_BC | T1_3D_SGN_B)) == T1_3D_SIG_BC), 1) + - int_min(((f & (T1_3D_SIG_FC | T1_3D_SGN_F)) == (T1_3D_SIG_FC | T1_3D_SGN_F)) + + ((f & (T1_3D_SIG_BC | T1_3D_SGN_B)) == (T1_3D_SIG_BC | T1_3D_SGN_B)), 1); + + n = ((hc + vc + cc) < 0); + + return n; +} + +static void t1_3d_init_luts(opj_t1_3d_t *t1) { + int i; + double u, v, t; + /*for (j = 0; j < 4; j++) { + for (i = 0; i < 256; ++i) { + t1->lut_ctxno_zc[(j << 8) | i] = t1_3d_init_ctxno_zc(i, j); + } + } + for (i = 0; i < 4096; i++) { + t1->lut_ctxno_sc[i] = t1_3d_init_ctxno_sc(i << 4); + } + for (j = 0; j < 2; j++) { + for (i = 0; i < 2048; ++i) { + t1->lut_ctxno_mag[(j << 11) + i] = t1_3d_init_ctxno_mag((j ? T1_3D_REFINE : 0) | i); + } + } + for (i = 0; i < 4096; ++i) { + t1->lut_spb[i] = t1_3d_init_spb(i << 4); + }*/ + /* FIXME FIXME FIXME */ + for (i = 0; i < (1 << T1_NMSEDEC_BITS); i++) { + t = i / pow(2, T1_NMSEDEC_FRACBITS); + u = t; + v = t - 1.5; + t1->lut_nmsedec_sig[i] = + int_max(0, + (int) (floor((u * u - v * v) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0)); + t1->lut_nmsedec_sig0[i] = + int_max(0, + (int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0)); + u = t - 1.0; + if (i & (1 << (T1_NMSEDEC_BITS - 1))) { + v = t - 1.5; + } else { + v = t - 0.5; + } + t1->lut_nmsedec_ref[i] = + int_max(0, + (int) (floor((u * u - v * v) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0)); + t1->lut_nmsedec_ref0[i] = + int_max(0, + (int) (floor((u * u) * pow(2, T1_NMSEDEC_FRACBITS) + 0.5) / pow(2, T1_NMSEDEC_FRACBITS) * 8192.0)); + } +} + +/* ----------------------------------------------------------------------- */ + +opj_t1_3d_t* t1_3d_create(opj_common_ptr cinfo) { + opj_t1_3d_t *t1 = (opj_t1_3d_t*)opj_malloc(sizeof(opj_t1_3d_t)); + if(t1) { + t1->cinfo = cinfo; + /* create MQC and RAW handles */ + t1->mqc = mqc_create(); + t1->raw = raw_create(); + /* initialize the look-up tables of the Tier-1 coder/decoder */ + t1_3d_init_luts(t1); + } + return t1; +} + +void t1_3d_destroy(opj_t1_3d_t *t1) { + if(t1) { + /* destroy MQC and RAW handles */ + mqc_destroy(t1->mqc); + raw_destroy(t1->raw); + opj_free(t1); + } +} + +void t1_3d_encode_cblks(opj_t1_3d_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) { + int compno, resno, bandno, precno, cblkno; + int x, y, z, i, j, k, orient; + int level[3]; + tile->distotile = 0; /* fixed_quality */ + + for (compno = 0; compno < tile->numcomps; compno++) { + opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; + + for (resno = 0; resno < tilec->numresolution[0]; resno++) { + opj_tcd_resolution_t *res = &tilec->resolutions[resno]; + + for (bandno = 0; bandno < res->numbands; bandno++) { + opj_tcd_band_t *band = &res->bands[bandno]; + + for (precno = 0; precno < res->prctno[0] * res->prctno[1] * res->prctno[2]; precno++) { + opj_tcd_precinct_t *prc = &band->precincts[precno]; + + for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { + opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; + + if (band->bandno == 0) { + x = cblk->x0 - band->x0; + y = cblk->y0 - band->y0; + z = cblk->z0 - band->z0; + } else if (band->bandno == 1) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = pres->x1 - pres->x0 + cblk->x0 - band->x0; + y = cblk->y0 - band->y0; + z = cblk->z0 - band->z0; + } else if (band->bandno == 2) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = cblk->x0 - band->x0; + y = pres->y1 - pres->y0 + cblk->y0 - band->y0; + z = cblk->z0 - band->z0; + } else if (band->bandno == 3) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = pres->x1 - pres->x0 + cblk->x0 - band->x0; + y = pres->y1 - pres->y0 + cblk->y0 - band->y0; + z = cblk->z0 - band->z0; + } else if (band->bandno == 4) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = cblk->x0 - band->x0; + y = cblk->y0 - band->y0; + z = pres->z1 - pres->z0 + cblk->z0 - band->z0; + } else if (band->bandno == 5) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = pres->x1 - pres->x0 + cblk->x0 - band->x0; + y = cblk->y0 - band->y0; + z = pres->z1 - pres->z0 + cblk->z0 - band->z0; + } else if (band->bandno == 6) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = cblk->x0 - band->x0; + y = pres->y1 - pres->y0 + cblk->y0 - band->y0; + z = pres->z1 - pres->z0 + cblk->z0 - band->z0; + } else if (band->bandno == 7) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = pres->x1 - pres->x0 + cblk->x0 - band->x0; + y = pres->y1 - pres->y0 + cblk->y0 - band->y0; + z = pres->z1 - pres->z0 + cblk->z0 - band->z0; + } + + if (tcp->tccps[compno].reversible == 1) { + for (k = 0; k < cblk->z1 - cblk->z0; k++) { + for (j = 0; j < cblk->y1 - cblk->y0; j++) { + for (i = 0; i < cblk->x1 - cblk->x0; i++) { + t1->data[k][j][i] = + tilec->data[(x + i) + (y + j) * (tilec->x1 - tilec->x0) + (z + k) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)] << T1_NMSEDEC_FRACBITS; + } + } + } + } else if (tcp->tccps[compno].reversible == 0) { + for (k = 0; k < cblk->z1 - cblk->z0; k++) { + for (j = 0; j < cblk->y1 - cblk->y0; j++) { + for (i = 0; i < cblk->x1 - cblk->x0; i++) { + t1->data[k][j][i] = fix_mul( + tilec->data[(x + i) + (y + j) * (tilec->x1 - tilec->x0) + (z + k) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)], + 8192 * 8192 / ((int) floor(band->stepsize * 8192))) >> (13 - T1_NMSEDEC_FRACBITS); + } + } + } + } + orient = band->bandno; /* FIXME */ + for (i = 0; i < 3; i++) + level[i] = tilec->numresolution[i] - 1 - resno; + + t1_3d_encode_cblk(t1, cblk, orient, compno, level, tcp->tccps[compno].dwtid, band->stepsize, tcp->tccps[compno].cblksty, tile->numcomps, tile); + + } /* cblkno */ + } /* precno */ + } /* bandno */ + } /* resno */ + } /* compno */ +} + +void t1_3d_decode_cblks(opj_t1_3d_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp) { + int compno, resno, bandno, precno, cblkno; + + for (compno = 0; compno < tile->numcomps; compno++) { + opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; + + for (resno = 0; resno < tilec->numresolution[0]; resno++) { + opj_tcd_resolution_t *res = &tilec->resolutions[resno]; + + for (bandno = 0; bandno < res->numbands; bandno++) { + opj_tcd_band_t *band = &res->bands[bandno]; + + for (precno = 0; precno < res->prctno[0] * res->prctno[1] * res->prctno[2]; precno++) { + opj_tcd_precinct_t *prc = &band->precincts[precno]; + + for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { + int x, y, z, i, j, k, orient; + opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; + + orient = band->bandno; /* FIXME */ + + /*fprintf(stdout,"[INFO] t1_3d_decode_cblk(t1, cblk, orient(%d), tcp->tccps[compno].roishift (%d), tcp->tccps[compno].cblksty (%d));\n",orient,tcp->tccps[compno].roishift, tcp->tccps[compno].cblksty);*/ + t1_3d_decode_cblk(t1, cblk, orient, tcp->tccps[compno].roishift, tcp->tccps[compno].cblksty); + + if (band->bandno == 0) { + x = cblk->x0 - band->x0; + y = cblk->y0 - band->y0; + z = cblk->z0 - band->z0; + } else if (band->bandno == 1) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = pres->x1 - pres->x0 + cblk->x0 - band->x0; + y = cblk->y0 - band->y0; + z = cblk->z0 - band->z0; + } else if (band->bandno == 2) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = cblk->x0 - band->x0; + y = pres->y1 - pres->y0 + cblk->y0 - band->y0; + z = cblk->z0 - band->z0; + } else if (band->bandno == 3) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = pres->x1 - pres->x0 + cblk->x0 - band->x0; + y = pres->y1 - pres->y0 + cblk->y0 - band->y0; + z = cblk->z0 - band->z0; + } else if (band->bandno == 4) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = cblk->x0 - band->x0; + y = cblk->y0 - band->y0; + z = pres->z1 - pres->z0 + cblk->z0 - band->z0; + } else if (band->bandno == 5) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = pres->x1 - pres->x0 + cblk->x0 - band->x0; + y = cblk->y0 - band->y0; + z = pres->z1 - pres->z0 + cblk->z0 - band->z0; + } else if (band->bandno == 6) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = cblk->x0 - band->x0; + y = pres->y1 - pres->y0 + cblk->y0 - band->y0; + z = pres->z1 - pres->z0 + cblk->z0 - band->z0; + } else if (band->bandno == 7) { + opj_tcd_resolution_t *pres = &tilec->resolutions[resno - 1]; + x = pres->x1 - pres->x0 + cblk->x0 - band->x0; + y = pres->y1 - pres->y0 + cblk->y0 - band->y0; + z = pres->z1 - pres->z0 + cblk->z0 - band->z0; + } + + if (tcp->tccps[compno].roishift) { + int thresh, val, mag; + thresh = 1 << tcp->tccps[compno].roishift; + for (k = 0; k < cblk->z1 - cblk->z0; k++) { + for (j = 0; j < cblk->y1 - cblk->y0; j++) { + for (i = 0; i < cblk->x1 - cblk->x0; i++) { + val = t1->data[k][j][i]; + mag = int_abs(val); + if (mag >= thresh) { + mag >>= tcp->tccps[compno].roishift; + t1->data[k][j][i] = val < 0 ? -mag : mag; + } + } + } + } + } + + if (tcp->tccps[compno].reversible == 1) { + for (k = 0; k < cblk->z1 - cblk->z0; k++) { + for (j = 0; j < cblk->y1 - cblk->y0; j++) { + for (i = 0; i < cblk->x1 - cblk->x0; i++) { + int tmp = t1->data[k][j][i]; + tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0) + (z + k) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)] = tmp/2; + } + } + } + } else { /* if (tcp->tccps[compno].reversible == 0) */ + for (k = 0; k < cblk->z1 - cblk->z0; k++) { + for (j = 0; j < cblk->y1 - cblk->y0; j++) { + for (i = 0; i < cblk->x1 - cblk->x0; i++) { + double tmp = (double)(t1->data[k][j][i] * band->stepsize * 4096.0); + if (t1->data[k][j][i] >> 1 == 0) { + tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0) + (z + k) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)] = 0; + } else { + int tmp2 = ((int) (floor(fabs(tmp)))) + ((int) floor(fabs(tmp*2))%2); + tilec->data[x + i + (y + j) * (tilec->x1 - tilec->x0) + (z + k) * (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)] = ((tmp<0)?-tmp2:tmp2); + } + } + } + } + } + } /* cblkno */ + } /* precno */ + } /* bandno */ + } /* resno */ + } /* compno */ +} diff --git a/src/lib/openjp3d/t1_3d.h b/src/lib/openjp3d/t1_3d.h index 6410bd5a..2974781f 100644 --- a/src/lib/openjp3d/t1_3d.h +++ b/src/lib/openjp3d/t1_3d.h @@ -1,173 +1,173 @@ -/* - * Copyrigth (c) 2006, Mónica Díez, LPI-UVA, Spain - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef __T1_3D_H -#define __T1_3D_H -/** -@file t1_3d.h -@brief Implementation of the tier-1 coding (coding of code-block coefficients) (T1) - -The functions in T1_3D.C have for goal to realize the tier-1 coding operation of 3D-EBCOT. -The functions in T1_3D.C are used by some function in TCD.C. -*/ - -/** @defgroup T1_3D T1_3D - Implementation of the tier-1 coding */ -/*@{*/ - -/* ----------------------------------------------------------------------- */ - -/* Neighbourhood of 3D EBCOT (Significance context)*/ -#define T1_3D_SIG_NE 0x00000001 /*< Context orientation : North-East direction */ -#define T1_3D_SIG_SE 0x00000002 /*< Context orientation : South-East direction */ -#define T1_3D_SIG_SW 0x00000004 /*< Context orientation : South-West direction */ -#define T1_3D_SIG_NW 0x00000008 /* Context orientation : North-West direction */ -#define T1_3D_SIG_N 0x00000010 /*< Context orientation : North direction */ -#define T1_3D_SIG_E 0x00000020 /*< Context orientation : East direction */ -#define T1_3D_SIG_S 0x00000040 /*< Context orientation : South direction */ -#define T1_3D_SIG_W 0x00000080 /*< Context orientation : West direction */ -#define T1_3D_SIG_FC 0x00000100 /*< Context orientation : Forward Central direction */ -#define T1_3D_SIG_BC 0x00000200 /*< Context orientation : Backward Central direction */ -#define T1_3D_SIG_FNE 0x00000400 /*< Context orientation : Forward North-East direction */ -#define T1_3D_SIG_FSE 0x00000800 /*< Context orientation : Forward South-East direction */ -#define T1_3D_SIG_FSW 0x00001000 /*< Context orientation : Forward South-West direction */ -#define T1_3D_SIG_FNW 0x00002000 /*< Context orientation : Forward North-West direction */ -#define T1_3D_SIG_FN 0x00004000 /*< Context orientation : Forward North direction */ -#define T1_3D_SIG_FE 0x00008000 /*< Context orientation : Forward East direction */ -#define T1_3D_SIG_FS 0x00010000 /*< Context orientation : Forward South direction */ -#define T1_3D_SIG_FW 0x00020000 /*< Context orientation : Forward West direction */ -#define T1_3D_SIG_BNE 0x00040000 /*< Context orientation : Backward North-East direction */ -#define T1_3D_SIG_BSE 0x00080000 /*< Context orientation : Backward South-East direction */ -#define T1_3D_SIG_BSW 0x00100000 /*< Context orientation : Backward South-West direction */ -#define T1_3D_SIG_BNW 0x00200000 /*< Context orientation : Backward North-West direction */ -#define T1_3D_SIG_BN 0x00400000 /*< Context orientation : Backward North direction */ -#define T1_3D_SIG_BE 0x00800000 /*< Context orientation : Backward East direction */ -#define T1_3D_SIG_BS 0x01000000 /*< Context orientation : Backward South direction */ -#define T1_3D_SIG_BW 0x02000000 /*< Context orientation : Backward West direction */ -#define T1_3D_SIG_COTH (T1_3D_SIG_N|T1_3D_SIG_NE|T1_3D_SIG_E|T1_3D_SIG_SE|T1_3D_SIG_S|T1_3D_SIG_SW|T1_3D_SIG_W|T1_3D_SIG_NW) -#define T1_3D_SIG_BOTH (T1_3D_SIG_BN|T1_3D_SIG_BNE|T1_3D_SIG_BE|T1_3D_SIG_BSE|T1_3D_SIG_BS|T1_3D_SIG_BSW|T1_3D_SIG_BW|T1_3D_SIG_BNW|T1_3D_SIG_BC) -#define T1_3D_SIG_FOTH (T1_3D_SIG_FN|T1_3D_SIG_FNE|T1_3D_SIG_FE|T1_3D_SIG_FSE|T1_3D_SIG_FS|T1_3D_SIG_FSW|T1_3D_SIG_FW|T1_3D_SIG_FNW|T1_3D_SIG_FC) -#define T1_3D_SIG_OTH (T1_3D_SIG_FOTH|T1_3D_SIG_BOTH|T1_3D_SIG_COTH) -#define T1_3D_SIG_PRIM (T1_3D_SIG_N|T1_3D_SIG_E|T1_3D_SIG_S|T1_3D_SIG_W|T1_3D_SIG_FC|T1_3D_SIG_BC) - -#define T1_3D_SGN_N 0x0400 -#define T1_3D_SGN_E 0x0800 -#define T1_3D_SGN_S 0x1000 -#define T1_3D_SGN_W 0x2000 -#define T1_3D_SGN_F 0x4000 -#define T1_3D_SGN_B 0x8000 -#define T1_3D_SGN (T1_3D_SGN_N|T1_3D_SGN_E|T1_3D_SGN_S|T1_3D_SGN_W|T1_3D_SGN_F|T1_3D_SGN_B) - -#define T1_3D_SIG 0x0001 /*Significance state*/ -#define T1_3D_REFINE 0x0002 /*Delayed significance*/ -#define T1_3D_VISIT 0x0004 /*First-pass membership*/ - -#define T1_3D_NUMCTXS_AGG 1 -#define T1_3D_NUMCTXS_ZC 16 -#define T1_3D_NUMCTXS_MAG 3 -#define T1_3D_NUMCTXS_SC 6 -#define T1_3D_NUMCTXS_UNI 1 - -#define T1_3D_CTXNO_AGG 0 -#define T1_3D_CTXNO_ZC (T1_3D_CTXNO_AGG+T1_3D_NUMCTXS_AGG) /*1*/ -#define T1_3D_CTXNO_MAG (T1_3D_CTXNO_ZC+T1_3D_NUMCTXS_ZC) /*17*/ -#define T1_3D_CTXNO_SC (T1_3D_CTXNO_MAG+T1_3D_NUMCTXS_MAG) /*20*/ -#define T1_3D_CTXNO_UNI (T1_3D_CTXNO_SC+T1_3D_NUMCTXS_SC) /*26*/ -#define T1_3D_NUMCTXS (T1_3D_CTXNO_UNI+T1_3D_NUMCTXS_UNI) /*27*/ - - -/* ----------------------------------------------------------------------- */ - -/** -Tier-1 coding (coding of code-block coefficients) -*/ -typedef struct opj_t1_3d { - /** Codec context */ - opj_common_ptr cinfo; - /** MQC component */ - opj_mqc_t *mqc; - /** RAW component */ - opj_raw_t *raw; - /** LUTs for decoding normalised MSE */ - int lut_nmsedec_sig[1 << T1_NMSEDEC_BITS]; - int lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS]; - int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS]; - int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS]; - /** Codeblock data */ - int data[T1_CBLKD][T1_CBLKH][T1_CBLKW]; - /** Context information for each voxel in codeblock */ - unsigned int flags[T1_CBLKD + 2][T1_CBLKH + 2][T1_CBLKH + 2]; - /** Voxel information (significance/visited/refined) */ - int flagSVR[T1_CBLKD + 2][T1_CBLKH + 2][T1_CBLKH + 2]; -} opj_t1_3d_t; - -/** @name Exported functions */ -/*@{*/ -/* ----------------------------------------------------------------------- */ -/** -Create a new T1_3D handle -and initialize the look-up tables of the Tier-1 coder/decoder -@return Returns a new T1 handle if successful, returns NULL otherwise -@see t1_init_luts -*/ -opj_t1_3d_t* t1_3d_create(opj_common_ptr cinfo); -/** -Destroy a previously created T1_3D handle -@param t1 T1_3D handle to destroy -*/ -void t1_3d_destroy(opj_t1_3d_t *t1); -/** -Encode the code-blocks of a tile -@param t1 T1_3D handle -@param tile The tile to encode -@param tcp Tile coding parameters -*/ -void t1_3d_encode_cblks(opj_t1_3d_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp); -/** -Decode the code-blocks of a tile -@param t1 T1_3D handle -@param tile The tile to decode -@param tcp Tile coding parameters -*/ -void t1_3d_decode_cblks(opj_t1_3d_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp); -/** -Get weigths of MSE decoding -@param nmsedec The normalized MSE reduction -@param compno -@param level -@param orient -@param bpno -@param reversible -@param stepsize -@param numcomps -@param dwtid -returns MSE associated to decoding pass -double t1_3d_getwmsedec(int nmsedec, int compno, int levelxy, int levelz, int orient, int bpno, int reversible, double stepsize, int numcomps, int dwtid); -*/ -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __T1_H */ +/* + * Copyrigth (c) 2006, Mónica Díez, LPI-UVA, Spain + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __T1_3D_H +#define __T1_3D_H +/** +@file t1_3d.h +@brief Implementation of the tier-1 coding (coding of code-block coefficients) (T1) + +The functions in T1_3D.C have for goal to realize the tier-1 coding operation of 3D-EBCOT. +The functions in T1_3D.C are used by some function in TCD.C. +*/ + +/** @defgroup T1_3D T1_3D - Implementation of the tier-1 coding */ +/*@{*/ + +/* ----------------------------------------------------------------------- */ + +/* Neighbourhood of 3D EBCOT (Significance context)*/ +#define T1_3D_SIG_NE 0x00000001 /*< Context orientation : North-East direction */ +#define T1_3D_SIG_SE 0x00000002 /*< Context orientation : South-East direction */ +#define T1_3D_SIG_SW 0x00000004 /*< Context orientation : South-West direction */ +#define T1_3D_SIG_NW 0x00000008 /* Context orientation : North-West direction */ +#define T1_3D_SIG_N 0x00000010 /*< Context orientation : North direction */ +#define T1_3D_SIG_E 0x00000020 /*< Context orientation : East direction */ +#define T1_3D_SIG_S 0x00000040 /*< Context orientation : South direction */ +#define T1_3D_SIG_W 0x00000080 /*< Context orientation : West direction */ +#define T1_3D_SIG_FC 0x00000100 /*< Context orientation : Forward Central direction */ +#define T1_3D_SIG_BC 0x00000200 /*< Context orientation : Backward Central direction */ +#define T1_3D_SIG_FNE 0x00000400 /*< Context orientation : Forward North-East direction */ +#define T1_3D_SIG_FSE 0x00000800 /*< Context orientation : Forward South-East direction */ +#define T1_3D_SIG_FSW 0x00001000 /*< Context orientation : Forward South-West direction */ +#define T1_3D_SIG_FNW 0x00002000 /*< Context orientation : Forward North-West direction */ +#define T1_3D_SIG_FN 0x00004000 /*< Context orientation : Forward North direction */ +#define T1_3D_SIG_FE 0x00008000 /*< Context orientation : Forward East direction */ +#define T1_3D_SIG_FS 0x00010000 /*< Context orientation : Forward South direction */ +#define T1_3D_SIG_FW 0x00020000 /*< Context orientation : Forward West direction */ +#define T1_3D_SIG_BNE 0x00040000 /*< Context orientation : Backward North-East direction */ +#define T1_3D_SIG_BSE 0x00080000 /*< Context orientation : Backward South-East direction */ +#define T1_3D_SIG_BSW 0x00100000 /*< Context orientation : Backward South-West direction */ +#define T1_3D_SIG_BNW 0x00200000 /*< Context orientation : Backward North-West direction */ +#define T1_3D_SIG_BN 0x00400000 /*< Context orientation : Backward North direction */ +#define T1_3D_SIG_BE 0x00800000 /*< Context orientation : Backward East direction */ +#define T1_3D_SIG_BS 0x01000000 /*< Context orientation : Backward South direction */ +#define T1_3D_SIG_BW 0x02000000 /*< Context orientation : Backward West direction */ +#define T1_3D_SIG_COTH (T1_3D_SIG_N|T1_3D_SIG_NE|T1_3D_SIG_E|T1_3D_SIG_SE|T1_3D_SIG_S|T1_3D_SIG_SW|T1_3D_SIG_W|T1_3D_SIG_NW) +#define T1_3D_SIG_BOTH (T1_3D_SIG_BN|T1_3D_SIG_BNE|T1_3D_SIG_BE|T1_3D_SIG_BSE|T1_3D_SIG_BS|T1_3D_SIG_BSW|T1_3D_SIG_BW|T1_3D_SIG_BNW|T1_3D_SIG_BC) +#define T1_3D_SIG_FOTH (T1_3D_SIG_FN|T1_3D_SIG_FNE|T1_3D_SIG_FE|T1_3D_SIG_FSE|T1_3D_SIG_FS|T1_3D_SIG_FSW|T1_3D_SIG_FW|T1_3D_SIG_FNW|T1_3D_SIG_FC) +#define T1_3D_SIG_OTH (T1_3D_SIG_FOTH|T1_3D_SIG_BOTH|T1_3D_SIG_COTH) +#define T1_3D_SIG_PRIM (T1_3D_SIG_N|T1_3D_SIG_E|T1_3D_SIG_S|T1_3D_SIG_W|T1_3D_SIG_FC|T1_3D_SIG_BC) + +#define T1_3D_SGN_N 0x0400 +#define T1_3D_SGN_E 0x0800 +#define T1_3D_SGN_S 0x1000 +#define T1_3D_SGN_W 0x2000 +#define T1_3D_SGN_F 0x4000 +#define T1_3D_SGN_B 0x8000 +#define T1_3D_SGN (T1_3D_SGN_N|T1_3D_SGN_E|T1_3D_SGN_S|T1_3D_SGN_W|T1_3D_SGN_F|T1_3D_SGN_B) + +#define T1_3D_SIG 0x0001 /*Significance state*/ +#define T1_3D_REFINE 0x0002 /*Delayed significance*/ +#define T1_3D_VISIT 0x0004 /*First-pass membership*/ + +#define T1_3D_NUMCTXS_AGG 1 +#define T1_3D_NUMCTXS_ZC 16 +#define T1_3D_NUMCTXS_MAG 3 +#define T1_3D_NUMCTXS_SC 6 +#define T1_3D_NUMCTXS_UNI 1 + +#define T1_3D_CTXNO_AGG 0 +#define T1_3D_CTXNO_ZC (T1_3D_CTXNO_AGG+T1_3D_NUMCTXS_AGG) /*1*/ +#define T1_3D_CTXNO_MAG (T1_3D_CTXNO_ZC+T1_3D_NUMCTXS_ZC) /*17*/ +#define T1_3D_CTXNO_SC (T1_3D_CTXNO_MAG+T1_3D_NUMCTXS_MAG) /*20*/ +#define T1_3D_CTXNO_UNI (T1_3D_CTXNO_SC+T1_3D_NUMCTXS_SC) /*26*/ +#define T1_3D_NUMCTXS (T1_3D_CTXNO_UNI+T1_3D_NUMCTXS_UNI) /*27*/ + + +/* ----------------------------------------------------------------------- */ + +/** +Tier-1 coding (coding of code-block coefficients) +*/ +typedef struct opj_t1_3d { + /** Codec context */ + opj_common_ptr cinfo; + /** MQC component */ + opj_mqc_t *mqc; + /** RAW component */ + opj_raw_t *raw; + /** LUTs for decoding normalised MSE */ + int lut_nmsedec_sig[1 << T1_NMSEDEC_BITS]; + int lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS]; + int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS]; + int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS]; + /** Codeblock data */ + int data[T1_CBLKD][T1_CBLKH][T1_CBLKW]; + /** Context information for each voxel in codeblock */ + unsigned int flags[T1_CBLKD + 2][T1_CBLKH + 2][T1_CBLKH + 2]; + /** Voxel information (significance/visited/refined) */ + int flagSVR[T1_CBLKD + 2][T1_CBLKH + 2][T1_CBLKH + 2]; +} opj_t1_3d_t; + +/** @name Exported functions */ +/*@{*/ +/* ----------------------------------------------------------------------- */ +/** +Create a new T1_3D handle +and initialize the look-up tables of the Tier-1 coder/decoder +@return Returns a new T1 handle if successful, returns NULL otherwise +@see t1_init_luts +*/ +opj_t1_3d_t* t1_3d_create(opj_common_ptr cinfo); +/** +Destroy a previously created T1_3D handle +@param t1 T1_3D handle to destroy +*/ +void t1_3d_destroy(opj_t1_3d_t *t1); +/** +Encode the code-blocks of a tile +@param t1 T1_3D handle +@param tile The tile to encode +@param tcp Tile coding parameters +*/ +void t1_3d_encode_cblks(opj_t1_3d_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp); +/** +Decode the code-blocks of a tile +@param t1 T1_3D handle +@param tile The tile to decode +@param tcp Tile coding parameters +*/ +void t1_3d_decode_cblks(opj_t1_3d_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp); +/** +Get weigths of MSE decoding +@param nmsedec The normalized MSE reduction +@param compno +@param level +@param orient +@param bpno +@param reversible +@param stepsize +@param numcomps +@param dwtid +returns MSE associated to decoding pass +double t1_3d_getwmsedec(int nmsedec, int compno, int levelxy, int levelz, int orient, int bpno, int reversible, double stepsize, int numcomps, int dwtid); +*/ +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __T1_H */ diff --git a/src/lib/openjp3d/t2.c b/src/lib/openjp3d/t2.c index e902d60d..7fd551e5 100644 --- a/src/lib/openjp3d/t2.c +++ b/src/lib/openjp3d/t2.c @@ -1,675 +1,675 @@ -/* - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "opj_includes.h" - -/** @defgroup T2 T2 - Implementation of a tier-2 coding */ -/*@{*/ - -/** @name Local static functions */ -/*@{*/ - -static void t2_putcommacode(opj_bio_t *bio, int n); -static int t2_getcommacode(opj_bio_t *bio); -/** -Variable length code for signalling delta Zil (truncation point) -@param bio Bit Input/Output component -@param n delta Zil -*/ -static void t2_putnumpasses(opj_bio_t *bio, int n); -static int t2_getnumpasses(opj_bio_t *bio); -/** -Encode a packet of a tile to a destination buffer -@param tile Tile for which to write the packets -@param tcp Tile coding parameters -@param pi Packet identity -@param dest Destination buffer -@param len Length of the destination buffer -@param volume_info Structure to create an index file -@param tileno Number of the tile encoded -@param cp Coding parameters -@return Number of bytes encoded from the packet -*/ -static int t2_encode_packet(opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi, unsigned char *dest, int len, opj_volume_info_t *volume_info, int tileno, opj_cp_t *cp); -/** -Initialize the segment decoder -@param seg Segment instance -@param cblksty Codeblock style -@param first Is first segment -*/ -static void t2_init_seg(opj_tcd_seg_t *seg, int cblksty, int first); -/** -Decode a packet of a tile from a source buffer -@param t2 T2 handle -@param src Source buffer -@param len Length of the source buffer -@param tile Tile for which to write the packets -@param tcp Tile coding parameters -@param pi Packet identity -@return Number of bytes decoded from the packet -*/ -int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi); - -/*@}*/ - -/*@}*/ - -/* ----------------------------------------------------------------------- */ - -/* #define RESTART 0x04 */ -static void t2_putcommacode(opj_bio_t *bio, int n) { - while (--n >= 0) { - bio_write(bio, 1, 1); - } - bio_write(bio, 0, 1); -} - -static int t2_getcommacode(opj_bio_t *bio) { - int n; - for (n = 0; bio_read(bio, 1); n++) { - ; - } - return n; -} - -static void t2_putnumpasses(opj_bio_t *bio, int n) { - if (n == 1) { - bio_write(bio, 0, 1); - } else if (n == 2) { - bio_write(bio, 2, 2); - } else if (n <= 5) { - bio_write(bio, 0xc | (n - 3), 4); - } else if (n <= 36) { - bio_write(bio, 0x1e0 | (n - 6), 9); - } else if (n <= 164) { - bio_write(bio, 0xff80 | (n - 37), 16); - } -} - -static int t2_getnumpasses(opj_bio_t *bio) { - int n; - if (!bio_read(bio, 1)) - return 1; - if (!bio_read(bio, 1)) - return 2; - if ((n = bio_read(bio, 2)) != 3) - return (3 + n); - if ((n = bio_read(bio, 5)) != 31) - return (6 + n); - return (37 + bio_read(bio, 7)); -} - -static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_iterator_t *pi, unsigned char *dest, int len, opj_volume_info_t * volume_info, int tileno, opj_cp_t *cp) { - int bandno, cblkno; - unsigned char *sop = 0, *eph = 0; - unsigned char *c = dest; - - int compno = pi->compno; /* component value */ - int resno = pi->resno; /* resolution level value */ - int precno = pi->precno; /* precinct value */ - int layno = pi->layno; /* quality layer value */ - - opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; - opj_tcd_resolution_t *res = &tilec->resolutions[resno]; - - opj_bio_t *bio = NULL; /* BIO component */ - - /* */ - if ((tcp->csty & J3D_CP_CSTY_SOP)) { - sop = (unsigned char *) opj_malloc(6 * sizeof(unsigned char)); - sop[0] = 255; - sop[1] = 145; - sop[2] = 0; - sop[3] = 4; - sop[4] = (volume_info) ? (volume_info->num % 65536) / 256 : (0 % 65536) / 256 ; - sop[5] = (volume_info) ? (volume_info->num % 65536) % 256 : (0 % 65536) % 256 ; - memcpy(c, sop, 6); - opj_free(sop); - c += 6; - } - /* */ - - if (!layno) { - for (bandno = 0; bandno < res->numbands; bandno++) { - opj_tcd_band_t *band = &res->bands[bandno]; - opj_tcd_precinct_t *prc = &band->precincts[precno]; - tgt_reset(prc->incltree); - tgt_reset(prc->imsbtree); - for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { - opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; - cblk->numpasses = 0; - tgt_setvalue(prc->imsbtree, cblkno, band->numbps - cblk->numbps); - } - } - } - - bio = bio_create(); - bio_init_enc(bio, c, len); - bio_write(bio, 1, 1); /* Empty header bit */ - - /* Writing Packet header */ - for (bandno = 0; bandno < res->numbands; bandno++) { - opj_tcd_band_t *band = &res->bands[bandno]; - opj_tcd_precinct_t *prc = &band->precincts[precno]; - for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { - opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; - opj_tcd_layer_t *layer = &cblk->layers[layno]; - if (!cblk->numpasses && layer->numpasses) { - tgt_setvalue(prc->incltree, cblkno, layno); - } - } - - for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { - opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; - opj_tcd_layer_t *layer = &cblk->layers[layno]; - int increment = 0; - int nump = 0; - int len = 0, passno; - /* cblk inclusion bits */ - if (!cblk->numpasses) { - tgt_encode(bio, prc->incltree, cblkno, layno + 1); - } else { - bio_write(bio, layer->numpasses != 0, 1); - } - /* if cblk not included, go to the next cblk */ - if (!layer->numpasses) { - continue; - } - /* if first instance of cblk --> zero bit-planes information */ - if (!cblk->numpasses) { - cblk->numlenbits = 3; - tgt_encode(bio, prc->imsbtree, cblkno, 999); - } - /* number of coding passes included */ - t2_putnumpasses(bio, layer->numpasses); - - /* computation of the increase of the length indicator and insertion in the header */ - for (passno = cblk->numpasses; passno < cblk->numpasses + layer->numpasses; passno++) { - opj_tcd_pass_t *pass = &cblk->passes[passno]; - nump++; - len += pass->len; - if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) { - increment = int_max(increment, int_floorlog2(len) + 1 - (cblk->numlenbits + int_floorlog2(nump))); - len = 0; - nump = 0; - } - } - t2_putcommacode(bio, increment); - - /* computation of the new Length indicator */ - cblk->numlenbits += increment; - - /* insertion of the codeword segment length */ - for (passno = cblk->numpasses; passno < cblk->numpasses + layer->numpasses; passno++) { - opj_tcd_pass_t *pass = &cblk->passes[passno]; - nump++; - len += pass->len; - if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) { - bio_write(bio, len, cblk->numlenbits + int_floorlog2(nump)); - len = 0; - nump = 0; - } - } - - } - } - - - if (bio_flush(bio)) { - return -999; /* modified to eliminate longjmp !! */ - } - - c += bio_numbytes(bio); - - bio_destroy(bio); - - /* */ - if (tcp->csty & J3D_CP_CSTY_EPH) { - eph = (unsigned char *) opj_malloc(2 * sizeof(unsigned char)); - eph[0] = 255; - eph[1] = 146; - memcpy(c, eph, 2); - opj_free(eph); - c += 2; - } - /* */ - - /* Writing the packet body */ - - for (bandno = 0; bandno < res->numbands; bandno++) { - opj_tcd_band_t *band = &res->bands[bandno]; - opj_tcd_precinct_t *prc = &band->precincts[precno]; - for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { - opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; - opj_tcd_layer_t *layer = &cblk->layers[layno]; - if (!layer->numpasses) { - continue; - } - if (c + layer->len > dest + len) { - return -999; - } - - memcpy(c, layer->data, layer->len); - cblk->numpasses += layer->numpasses; - c += layer->len; - /* ADD for index Cfr. Marcela --> delta disto by packet */ - if(volume_info && volume_info->index_write && volume_info->index_on) { - opj_tile_info_t *info_TL = &volume_info->tile[tileno]; - opj_packet_info_t *info_PK = &info_TL->packet[volume_info->num]; - info_PK->disto += layer->disto; - if (volume_info->D_max < info_PK->disto) { - volume_info->D_max = info_PK->disto; - } - } - /* */ - } - } - - return (c - dest); -} - -static void t2_init_seg(opj_tcd_seg_t * seg, int cblksty, int first) { - seg->numpasses = 0; - seg->len = 0; - if (cblksty & J3D_CCP_CBLKSTY_TERMALL) { - seg->maxpasses = 1; - } - else if (cblksty & J3D_CCP_CBLKSTY_LAZY) { - if (first) { - seg->maxpasses = 10; - } else { - seg->maxpasses = (((seg - 1)->maxpasses == 1) || ((seg - 1)->maxpasses == 10)) ? 2 : 1; - } - } else { - seg->maxpasses = 109; - } -} - -int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi) { - int bandno, cblkno; - unsigned char *c = src; - - opj_cp_t *cp = t2->cp; - - int compno = pi->compno; /* component value */ - int resno = pi->resno; /* resolution level value */ - int precno = pi->precno; /* precinct value */ - int layno = pi->layno; /* quality layer value */ - - opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; - opj_tcd_resolution_t *res = &tilec->resolutions[resno]; - - unsigned char *hd = NULL; - int present; - - opj_bio_t *bio = NULL; /* BIO component */ - - if (layno == 0) { - for (bandno = 0; bandno < res->numbands; bandno++) { - opj_tcd_band_t *band = &res->bands[bandno]; - opj_tcd_precinct_t *prc = &band->precincts[precno]; - - if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)||(band->z1-band->z0 == 0)) continue; - - tgt_reset(prc->incltree); - tgt_reset(prc->imsbtree); - for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { - opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; - cblk->numsegs = 0; - } - } - } - - /* SOP markers */ - - if (tcp->csty & J3D_CP_CSTY_SOP) { - if ((*c) != 0xff || (*(c + 1) != 0x91)) { - opj_event_msg(t2->cinfo, EVT_WARNING, "Expected SOP marker\n"); - } else { - c += 6; - } - - /** TODO : check the Nsop value */ - } - - /* - When the marker PPT/PPM is used the packet header are store in PPT/PPM marker - This part deal with this caracteristic - step 1: Read packet header in the saved structure - step 2: Return to codestream for decoding - */ - - bio = bio_create(); - - if (cp->ppm == 1) { /* PPM */ - hd = cp->ppm_data; - bio_init_dec(bio, hd, cp->ppm_len); - } else if (tcp->ppt == 1) { /* PPT */ - hd = tcp->ppt_data; - bio_init_dec(bio, hd, tcp->ppt_len); - } else { /* Normal Case */ - hd = c; - bio_init_dec(bio, hd, src+len-hd); - } - - present = bio_read(bio, 1); - - if (!present) { - bio_inalign(bio); - hd += bio_numbytes(bio); - bio_destroy(bio); - - /* EPH markers */ - - if (tcp->csty & J3D_CP_CSTY_EPH) { - if ((*hd) != 0xff || (*(hd + 1) != 0x92)) { - printf("Error : expected EPH marker\n"); - } else { - hd += 2; - } - } - - if (cp->ppm == 1) { /* PPM case */ - cp->ppm_len += cp->ppm_data-hd; - cp->ppm_data = hd; - return (c - src); - } - if (tcp->ppt == 1) { /* PPT case */ - tcp->ppt_len+=tcp->ppt_data-hd; - tcp->ppt_data = hd; - return (c - src); - } - - return (hd - src); - } - - for (bandno = 0; bandno < res->numbands; bandno++) { - opj_tcd_band_t *band = &res->bands[bandno]; - opj_tcd_precinct_t *prc = &band->precincts[precno]; - - if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)||(band->z1-band->z0 == 0)) continue; - - for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { - int included, increment, n; - opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; - opj_tcd_seg_t *seg = NULL; - /* if cblk not yet included before --> inclusion tagtree */ - if (!cblk->numsegs) { - included = tgt_decode(bio, prc->incltree, cblkno, layno + 1); - /* else one bit */ - } else { - included = bio_read(bio, 1); - } - /* if cblk not included */ - if (!included) { - cblk->numnewpasses = 0; - continue; - } - /* if cblk not yet included --> zero-bitplane tagtree */ - if (!cblk->numsegs) { - int i, numimsbs; - for (i = 0; !tgt_decode(bio, prc->imsbtree, cblkno, i); i++); - numimsbs = i - 1; - cblk->numbps = band->numbps - numimsbs; - cblk->numlenbits = 3; - } - /* number of coding passes */ - cblk->numnewpasses = t2_getnumpasses(bio); - increment = t2_getcommacode(bio); - /* length indicator increment */ - cblk->numlenbits += increment; - if (!cblk->numsegs) { - seg = &cblk->segs[0]; - t2_init_seg(seg, tcp->tccps[compno].cblksty, 1); - } else { - seg = &cblk->segs[cblk->numsegs - 1]; - if (seg->numpasses == seg->maxpasses) { - t2_init_seg(++seg, tcp->tccps[compno].cblksty, 0); - } - } - n = cblk->numnewpasses; - - do { - seg->numnewpasses = int_min(seg->maxpasses - seg->numpasses, n); - seg->newlen = bio_read(bio, cblk->numlenbits + int_floorlog2(seg->numnewpasses)); - n -= seg->numnewpasses; - if (n > 0) { - t2_init_seg(++seg, tcp->tccps[compno].cblksty, 0); - } - } while (n > 0); - } - } - - if (bio_inalign(bio)) { - bio_destroy(bio); - return -999; - } - - hd += bio_numbytes(bio); - bio_destroy(bio); - - /* EPH markers */ - if (tcp->csty & J3D_CP_CSTY_EPH) { - if ((*hd) != 0xff || (*(hd + 1) != 0x92)) { - opj_event_msg(t2->cinfo, EVT_ERROR, "Expected EPH marker\n"); - } else { - hd += 2; - } - } - - if (cp->ppm==1) { - cp->ppm_len+=cp->ppm_data-hd; - cp->ppm_data = hd; - } else if (tcp->ppt == 1) { - tcp->ppt_len+=tcp->ppt_data-hd; - tcp->ppt_data = hd; - } else { - c=hd; - } - - for (bandno = 0; bandno < res->numbands; bandno++) { - opj_tcd_band_t *band = &res->bands[bandno]; - opj_tcd_precinct_t *prc = &band->precincts[precno]; - - if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)||(band->z1-band->z0 == 0)) continue; - - for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { - opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; - opj_tcd_seg_t *seg = NULL; - if (!cblk->numnewpasses) - continue; - if (!cblk->numsegs) { - seg = &cblk->segs[0]; - cblk->numsegs++; - cblk->len = 0; - } else { - seg = &cblk->segs[cblk->numsegs - 1]; - if (seg->numpasses == seg->maxpasses) { - seg++; - cblk->numsegs++; - } - } - - do { - if (c + seg->newlen > src + len) { - return -999; - } - - memcpy(cblk->data + cblk->len, c, seg->newlen); - if (seg->numpasses == 0) { - seg->data = cblk->data + cblk->len; - } - c += seg->newlen; - cblk->len += seg->newlen; - seg->len += seg->newlen; - seg->numpasses += seg->numnewpasses; - cblk->numnewpasses -= seg->numnewpasses; - if (cblk->numnewpasses > 0) { - seg++; - cblk->numsegs++; - } - } while (cblk->numnewpasses > 0); - } - } - - return (c - src); -} - -/* ----------------------------------------------------------------------- */ - -int t2_encode_packets(opj_t2_t* t2, int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_volume_info_t *volume_info) { - unsigned char *c = dest; - int e = 0; - opj_pi_iterator_t *pi = NULL; - int pino; - - opj_volume_t *volume = t2->volume; - opj_cp_t *cp = t2->cp; - - /* create a packet iterator */ - pi = pi_create(volume, cp, tileno); - if(!pi) { - fprintf(stdout,"[ERROR] Failed to create a pi structure\n"); - return -999; - } - - if(volume_info) { - volume_info->num = 0; - } - - for (pino = 0; pino <= cp->tcps[tileno].numpocs; pino++) { - while (pi_next(&pi[pino])) { - if (pi[pino].layno < maxlayers) { - e = t2_encode_packet(tile, &cp->tcps[tileno], &pi[pino], c, dest + len - c, volume_info, tileno, cp); - /*opj_event_msg(t2->cinfo, EVT_INFO, " t2_encode_packet: %d bytes coded\n",e);*/ - if (e == -999) { - break; - } else { - c += e; - } - - /* INDEX >> */ - if(volume_info && volume_info->index_on) { - if(volume_info->index_write) { - opj_tile_info_t *info_TL = &volume_info->tile[tileno]; - opj_packet_info_t *info_PK = &info_TL->packet[volume_info->num]; - if (!volume_info->num) { - info_PK->start_pos = info_TL->end_header + 1; - } else { - info_PK->start_pos = info_TL->packet[volume_info->num - 1].end_pos + 1; - } - info_PK->end_pos = info_PK->start_pos + e - 1; - } - - volume_info->num++; - } - /* << INDEX */ - } - } - } - - /* don't forget to release pi */ - pi_destroy(pi, cp, tileno); - - if (e == -999) { - return e; - } - - return (c - dest); -} - -int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj_tcd_tile_t *tile) { - unsigned char *c = src; - opj_pi_iterator_t *pi; - int pino, e = 0; - int n = 0,i; - - opj_volume_t *volume = t2->volume; - opj_cp_t *cp = t2->cp; - - /* create a packet iterator */ - pi = pi_create(volume, cp, tileno); - if(!pi) { - /* TODO: throw an error */ - return -999; - } - - for (pino = 0; pino <= cp->tcps[tileno].numpocs; pino++) { - while (pi_next(&pi[pino])) { - if ((cp->layer==0) || (cp->layer>=((pi[pino].layno)+1))) { - e = t2_decode_packet(t2, c, src + len - c, tile, &cp->tcps[tileno], &pi[pino]); - } else { - e = 0; - } - - /* progression in resolution */ - for (i = 0; i < 3; i++){ - volume->comps[pi[pino].compno].resno_decoded[i] = (e > 0) ? int_max(pi[pino].resno, volume->comps[pi[pino].compno].resno_decoded[i]) : volume->comps[pi[pino].compno].resno_decoded[i]; - } - n++; - - if (e == -999) { /* ADD */ - break; - } else { - opj_event_msg(t2->cinfo, EVT_INFO, " t2_decode_packet: %d bytes decoded\n",e); - c += e; - } - } - } - - /* don't forget to release pi */ - pi_destroy(pi, cp, tileno); - - if (e == -999) { - return e; - } - - return (c - src); -} - -/* ----------------------------------------------------------------------- */ - -opj_t2_t* t2_create(opj_common_ptr cinfo, opj_volume_t *volume, opj_cp_t *cp) { - /* create the tcd structure */ - opj_t2_t *t2 = (opj_t2_t*)opj_malloc(sizeof(opj_t2_t)); - if(!t2) return NULL; - t2->cinfo = cinfo; - t2->volume = volume; - t2->cp = cp; - - return t2; -} - -void t2_destroy(opj_t2_t *t2) { - if(t2) { - opj_free(t2); - } -} - +/* + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opj_includes.h" + +/** @defgroup T2 T2 - Implementation of a tier-2 coding */ +/*@{*/ + +/** @name Local static functions */ +/*@{*/ + +static void t2_putcommacode(opj_bio_t *bio, int n); +static int t2_getcommacode(opj_bio_t *bio); +/** +Variable length code for signalling delta Zil (truncation point) +@param bio Bit Input/Output component +@param n delta Zil +*/ +static void t2_putnumpasses(opj_bio_t *bio, int n); +static int t2_getnumpasses(opj_bio_t *bio); +/** +Encode a packet of a tile to a destination buffer +@param tile Tile for which to write the packets +@param tcp Tile coding parameters +@param pi Packet identity +@param dest Destination buffer +@param len Length of the destination buffer +@param volume_info Structure to create an index file +@param tileno Number of the tile encoded +@param cp Coding parameters +@return Number of bytes encoded from the packet +*/ +static int t2_encode_packet(opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi, unsigned char *dest, int len, opj_volume_info_t *volume_info, int tileno, opj_cp_t *cp); +/** +Initialize the segment decoder +@param seg Segment instance +@param cblksty Codeblock style +@param first Is first segment +*/ +static void t2_init_seg(opj_tcd_seg_t *seg, int cblksty, int first); +/** +Decode a packet of a tile from a source buffer +@param t2 T2 handle +@param src Source buffer +@param len Length of the source buffer +@param tile Tile for which to write the packets +@param tcp Tile coding parameters +@param pi Packet identity +@return Number of bytes decoded from the packet +*/ +int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi); + +/*@}*/ + +/*@}*/ + +/* ----------------------------------------------------------------------- */ + +/* #define RESTART 0x04 */ +static void t2_putcommacode(opj_bio_t *bio, int n) { + while (--n >= 0) { + bio_write(bio, 1, 1); + } + bio_write(bio, 0, 1); +} + +static int t2_getcommacode(opj_bio_t *bio) { + int n; + for (n = 0; bio_read(bio, 1); n++) { + ; + } + return n; +} + +static void t2_putnumpasses(opj_bio_t *bio, int n) { + if (n == 1) { + bio_write(bio, 0, 1); + } else if (n == 2) { + bio_write(bio, 2, 2); + } else if (n <= 5) { + bio_write(bio, 0xc | (n - 3), 4); + } else if (n <= 36) { + bio_write(bio, 0x1e0 | (n - 6), 9); + } else if (n <= 164) { + bio_write(bio, 0xff80 | (n - 37), 16); + } +} + +static int t2_getnumpasses(opj_bio_t *bio) { + int n; + if (!bio_read(bio, 1)) + return 1; + if (!bio_read(bio, 1)) + return 2; + if ((n = bio_read(bio, 2)) != 3) + return (3 + n); + if ((n = bio_read(bio, 5)) != 31) + return (6 + n); + return (37 + bio_read(bio, 7)); +} + +static int t2_encode_packet(opj_tcd_tile_t * tile, opj_tcp_t * tcp, opj_pi_iterator_t *pi, unsigned char *dest, int len, opj_volume_info_t * volume_info, int tileno, opj_cp_t *cp) { + int bandno, cblkno; + unsigned char *sop = 0, *eph = 0; + unsigned char *c = dest; + + int compno = pi->compno; /* component value */ + int resno = pi->resno; /* resolution level value */ + int precno = pi->precno; /* precinct value */ + int layno = pi->layno; /* quality layer value */ + + opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; + opj_tcd_resolution_t *res = &tilec->resolutions[resno]; + + opj_bio_t *bio = NULL; /* BIO component */ + + /* */ + if ((tcp->csty & J3D_CP_CSTY_SOP)) { + sop = (unsigned char *) opj_malloc(6 * sizeof(unsigned char)); + sop[0] = 255; + sop[1] = 145; + sop[2] = 0; + sop[3] = 4; + sop[4] = (volume_info) ? (volume_info->num % 65536) / 256 : (0 % 65536) / 256 ; + sop[5] = (volume_info) ? (volume_info->num % 65536) % 256 : (0 % 65536) % 256 ; + memcpy(c, sop, 6); + opj_free(sop); + c += 6; + } + /* */ + + if (!layno) { + for (bandno = 0; bandno < res->numbands; bandno++) { + opj_tcd_band_t *band = &res->bands[bandno]; + opj_tcd_precinct_t *prc = &band->precincts[precno]; + tgt_reset(prc->incltree); + tgt_reset(prc->imsbtree); + for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { + opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; + cblk->numpasses = 0; + tgt_setvalue(prc->imsbtree, cblkno, band->numbps - cblk->numbps); + } + } + } + + bio = bio_create(); + bio_init_enc(bio, c, len); + bio_write(bio, 1, 1); /* Empty header bit */ + + /* Writing Packet header */ + for (bandno = 0; bandno < res->numbands; bandno++) { + opj_tcd_band_t *band = &res->bands[bandno]; + opj_tcd_precinct_t *prc = &band->precincts[precno]; + for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { + opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; + opj_tcd_layer_t *layer = &cblk->layers[layno]; + if (!cblk->numpasses && layer->numpasses) { + tgt_setvalue(prc->incltree, cblkno, layno); + } + } + + for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { + opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; + opj_tcd_layer_t *layer = &cblk->layers[layno]; + int increment = 0; + int nump = 0; + int len = 0, passno; + /* cblk inclusion bits */ + if (!cblk->numpasses) { + tgt_encode(bio, prc->incltree, cblkno, layno + 1); + } else { + bio_write(bio, layer->numpasses != 0, 1); + } + /* if cblk not included, go to the next cblk */ + if (!layer->numpasses) { + continue; + } + /* if first instance of cblk --> zero bit-planes information */ + if (!cblk->numpasses) { + cblk->numlenbits = 3; + tgt_encode(bio, prc->imsbtree, cblkno, 999); + } + /* number of coding passes included */ + t2_putnumpasses(bio, layer->numpasses); + + /* computation of the increase of the length indicator and insertion in the header */ + for (passno = cblk->numpasses; passno < cblk->numpasses + layer->numpasses; passno++) { + opj_tcd_pass_t *pass = &cblk->passes[passno]; + nump++; + len += pass->len; + if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) { + increment = int_max(increment, int_floorlog2(len) + 1 - (cblk->numlenbits + int_floorlog2(nump))); + len = 0; + nump = 0; + } + } + t2_putcommacode(bio, increment); + + /* computation of the new Length indicator */ + cblk->numlenbits += increment; + + /* insertion of the codeword segment length */ + for (passno = cblk->numpasses; passno < cblk->numpasses + layer->numpasses; passno++) { + opj_tcd_pass_t *pass = &cblk->passes[passno]; + nump++; + len += pass->len; + if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) { + bio_write(bio, len, cblk->numlenbits + int_floorlog2(nump)); + len = 0; + nump = 0; + } + } + + } + } + + + if (bio_flush(bio)) { + return -999; /* modified to eliminate longjmp !! */ + } + + c += bio_numbytes(bio); + + bio_destroy(bio); + + /* */ + if (tcp->csty & J3D_CP_CSTY_EPH) { + eph = (unsigned char *) opj_malloc(2 * sizeof(unsigned char)); + eph[0] = 255; + eph[1] = 146; + memcpy(c, eph, 2); + opj_free(eph); + c += 2; + } + /* */ + + /* Writing the packet body */ + + for (bandno = 0; bandno < res->numbands; bandno++) { + opj_tcd_band_t *band = &res->bands[bandno]; + opj_tcd_precinct_t *prc = &band->precincts[precno]; + for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { + opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; + opj_tcd_layer_t *layer = &cblk->layers[layno]; + if (!layer->numpasses) { + continue; + } + if (c + layer->len > dest + len) { + return -999; + } + + memcpy(c, layer->data, layer->len); + cblk->numpasses += layer->numpasses; + c += layer->len; + /* ADD for index Cfr. Marcela --> delta disto by packet */ + if(volume_info && volume_info->index_write && volume_info->index_on) { + opj_tile_info_t *info_TL = &volume_info->tile[tileno]; + opj_packet_info_t *info_PK = &info_TL->packet[volume_info->num]; + info_PK->disto += layer->disto; + if (volume_info->D_max < info_PK->disto) { + volume_info->D_max = info_PK->disto; + } + } + /* */ + } + } + + return (c - dest); +} + +static void t2_init_seg(opj_tcd_seg_t * seg, int cblksty, int first) { + seg->numpasses = 0; + seg->len = 0; + if (cblksty & J3D_CCP_CBLKSTY_TERMALL) { + seg->maxpasses = 1; + } + else if (cblksty & J3D_CCP_CBLKSTY_LAZY) { + if (first) { + seg->maxpasses = 10; + } else { + seg->maxpasses = (((seg - 1)->maxpasses == 1) || ((seg - 1)->maxpasses == 10)) ? 2 : 1; + } + } else { + seg->maxpasses = 109; + } +} + +int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t *tile, opj_tcp_t *tcp, opj_pi_iterator_t *pi) { + int bandno, cblkno; + unsigned char *c = src; + + opj_cp_t *cp = t2->cp; + + int compno = pi->compno; /* component value */ + int resno = pi->resno; /* resolution level value */ + int precno = pi->precno; /* precinct value */ + int layno = pi->layno; /* quality layer value */ + + opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; + opj_tcd_resolution_t *res = &tilec->resolutions[resno]; + + unsigned char *hd = NULL; + int present; + + opj_bio_t *bio = NULL; /* BIO component */ + + if (layno == 0) { + for (bandno = 0; bandno < res->numbands; bandno++) { + opj_tcd_band_t *band = &res->bands[bandno]; + opj_tcd_precinct_t *prc = &band->precincts[precno]; + + if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)||(band->z1-band->z0 == 0)) continue; + + tgt_reset(prc->incltree); + tgt_reset(prc->imsbtree); + for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { + opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; + cblk->numsegs = 0; + } + } + } + + /* SOP markers */ + + if (tcp->csty & J3D_CP_CSTY_SOP) { + if ((*c) != 0xff || (*(c + 1) != 0x91)) { + opj_event_msg(t2->cinfo, EVT_WARNING, "Expected SOP marker\n"); + } else { + c += 6; + } + + /** TODO : check the Nsop value */ + } + + /* + When the marker PPT/PPM is used the packet header are store in PPT/PPM marker + This part deal with this caracteristic + step 1: Read packet header in the saved structure + step 2: Return to codestream for decoding + */ + + bio = bio_create(); + + if (cp->ppm == 1) { /* PPM */ + hd = cp->ppm_data; + bio_init_dec(bio, hd, cp->ppm_len); + } else if (tcp->ppt == 1) { /* PPT */ + hd = tcp->ppt_data; + bio_init_dec(bio, hd, tcp->ppt_len); + } else { /* Normal Case */ + hd = c; + bio_init_dec(bio, hd, src+len-hd); + } + + present = bio_read(bio, 1); + + if (!present) { + bio_inalign(bio); + hd += bio_numbytes(bio); + bio_destroy(bio); + + /* EPH markers */ + + if (tcp->csty & J3D_CP_CSTY_EPH) { + if ((*hd) != 0xff || (*(hd + 1) != 0x92)) { + printf("Error : expected EPH marker\n"); + } else { + hd += 2; + } + } + + if (cp->ppm == 1) { /* PPM case */ + cp->ppm_len += cp->ppm_data-hd; + cp->ppm_data = hd; + return (c - src); + } + if (tcp->ppt == 1) { /* PPT case */ + tcp->ppt_len+=tcp->ppt_data-hd; + tcp->ppt_data = hd; + return (c - src); + } + + return (hd - src); + } + + for (bandno = 0; bandno < res->numbands; bandno++) { + opj_tcd_band_t *band = &res->bands[bandno]; + opj_tcd_precinct_t *prc = &band->precincts[precno]; + + if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)||(band->z1-band->z0 == 0)) continue; + + for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { + int included, increment, n; + opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; + opj_tcd_seg_t *seg = NULL; + /* if cblk not yet included before --> inclusion tagtree */ + if (!cblk->numsegs) { + included = tgt_decode(bio, prc->incltree, cblkno, layno + 1); + /* else one bit */ + } else { + included = bio_read(bio, 1); + } + /* if cblk not included */ + if (!included) { + cblk->numnewpasses = 0; + continue; + } + /* if cblk not yet included --> zero-bitplane tagtree */ + if (!cblk->numsegs) { + int i, numimsbs; + for (i = 0; !tgt_decode(bio, prc->imsbtree, cblkno, i); i++); + numimsbs = i - 1; + cblk->numbps = band->numbps - numimsbs; + cblk->numlenbits = 3; + } + /* number of coding passes */ + cblk->numnewpasses = t2_getnumpasses(bio); + increment = t2_getcommacode(bio); + /* length indicator increment */ + cblk->numlenbits += increment; + if (!cblk->numsegs) { + seg = &cblk->segs[0]; + t2_init_seg(seg, tcp->tccps[compno].cblksty, 1); + } else { + seg = &cblk->segs[cblk->numsegs - 1]; + if (seg->numpasses == seg->maxpasses) { + t2_init_seg(++seg, tcp->tccps[compno].cblksty, 0); + } + } + n = cblk->numnewpasses; + + do { + seg->numnewpasses = int_min(seg->maxpasses - seg->numpasses, n); + seg->newlen = bio_read(bio, cblk->numlenbits + int_floorlog2(seg->numnewpasses)); + n -= seg->numnewpasses; + if (n > 0) { + t2_init_seg(++seg, tcp->tccps[compno].cblksty, 0); + } + } while (n > 0); + } + } + + if (bio_inalign(bio)) { + bio_destroy(bio); + return -999; + } + + hd += bio_numbytes(bio); + bio_destroy(bio); + + /* EPH markers */ + if (tcp->csty & J3D_CP_CSTY_EPH) { + if ((*hd) != 0xff || (*(hd + 1) != 0x92)) { + opj_event_msg(t2->cinfo, EVT_ERROR, "Expected EPH marker\n"); + } else { + hd += 2; + } + } + + if (cp->ppm==1) { + cp->ppm_len+=cp->ppm_data-hd; + cp->ppm_data = hd; + } else if (tcp->ppt == 1) { + tcp->ppt_len+=tcp->ppt_data-hd; + tcp->ppt_data = hd; + } else { + c=hd; + } + + for (bandno = 0; bandno < res->numbands; bandno++) { + opj_tcd_band_t *band = &res->bands[bandno]; + opj_tcd_precinct_t *prc = &band->precincts[precno]; + + if ((band->x1-band->x0 == 0)||(band->y1-band->y0 == 0)||(band->z1-band->z0 == 0)) continue; + + for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { + opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; + opj_tcd_seg_t *seg = NULL; + if (!cblk->numnewpasses) + continue; + if (!cblk->numsegs) { + seg = &cblk->segs[0]; + cblk->numsegs++; + cblk->len = 0; + } else { + seg = &cblk->segs[cblk->numsegs - 1]; + if (seg->numpasses == seg->maxpasses) { + seg++; + cblk->numsegs++; + } + } + + do { + if (c + seg->newlen > src + len) { + return -999; + } + + memcpy(cblk->data + cblk->len, c, seg->newlen); + if (seg->numpasses == 0) { + seg->data = cblk->data + cblk->len; + } + c += seg->newlen; + cblk->len += seg->newlen; + seg->len += seg->newlen; + seg->numpasses += seg->numnewpasses; + cblk->numnewpasses -= seg->numnewpasses; + if (cblk->numnewpasses > 0) { + seg++; + cblk->numsegs++; + } + } while (cblk->numnewpasses > 0); + } + } + + return (c - src); +} + +/* ----------------------------------------------------------------------- */ + +int t2_encode_packets(opj_t2_t* t2, int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_volume_info_t *volume_info) { + unsigned char *c = dest; + int e = 0; + opj_pi_iterator_t *pi = NULL; + int pino; + + opj_volume_t *volume = t2->volume; + opj_cp_t *cp = t2->cp; + + /* create a packet iterator */ + pi = pi_create(volume, cp, tileno); + if(!pi) { + fprintf(stdout,"[ERROR] Failed to create a pi structure\n"); + return -999; + } + + if(volume_info) { + volume_info->num = 0; + } + + for (pino = 0; pino <= cp->tcps[tileno].numpocs; pino++) { + while (pi_next(&pi[pino])) { + if (pi[pino].layno < maxlayers) { + e = t2_encode_packet(tile, &cp->tcps[tileno], &pi[pino], c, dest + len - c, volume_info, tileno, cp); + /*opj_event_msg(t2->cinfo, EVT_INFO, " t2_encode_packet: %d bytes coded\n",e);*/ + if (e == -999) { + break; + } else { + c += e; + } + + /* INDEX >> */ + if(volume_info && volume_info->index_on) { + if(volume_info->index_write) { + opj_tile_info_t *info_TL = &volume_info->tile[tileno]; + opj_packet_info_t *info_PK = &info_TL->packet[volume_info->num]; + if (!volume_info->num) { + info_PK->start_pos = info_TL->end_header + 1; + } else { + info_PK->start_pos = info_TL->packet[volume_info->num - 1].end_pos + 1; + } + info_PK->end_pos = info_PK->start_pos + e - 1; + } + + volume_info->num++; + } + /* << INDEX */ + } + } + } + + /* don't forget to release pi */ + pi_destroy(pi, cp, tileno); + + if (e == -999) { + return e; + } + + return (c - dest); +} + +int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj_tcd_tile_t *tile) { + unsigned char *c = src; + opj_pi_iterator_t *pi; + int pino, e = 0; + int n = 0,i; + + opj_volume_t *volume = t2->volume; + opj_cp_t *cp = t2->cp; + + /* create a packet iterator */ + pi = pi_create(volume, cp, tileno); + if(!pi) { + /* TODO: throw an error */ + return -999; + } + + for (pino = 0; pino <= cp->tcps[tileno].numpocs; pino++) { + while (pi_next(&pi[pino])) { + if ((cp->layer==0) || (cp->layer>=((pi[pino].layno)+1))) { + e = t2_decode_packet(t2, c, src + len - c, tile, &cp->tcps[tileno], &pi[pino]); + } else { + e = 0; + } + + /* progression in resolution */ + for (i = 0; i < 3; i++){ + volume->comps[pi[pino].compno].resno_decoded[i] = (e > 0) ? int_max(pi[pino].resno, volume->comps[pi[pino].compno].resno_decoded[i]) : volume->comps[pi[pino].compno].resno_decoded[i]; + } + n++; + + if (e == -999) { /* ADD */ + break; + } else { + opj_event_msg(t2->cinfo, EVT_INFO, " t2_decode_packet: %d bytes decoded\n",e); + c += e; + } + } + } + + /* don't forget to release pi */ + pi_destroy(pi, cp, tileno); + + if (e == -999) { + return e; + } + + return (c - src); +} + +/* ----------------------------------------------------------------------- */ + +opj_t2_t* t2_create(opj_common_ptr cinfo, opj_volume_t *volume, opj_cp_t *cp) { + /* create the tcd structure */ + opj_t2_t *t2 = (opj_t2_t*)opj_malloc(sizeof(opj_t2_t)); + if(!t2) return NULL; + t2->cinfo = cinfo; + t2->volume = volume; + t2->cp = cp; + + return t2; +} + +void t2_destroy(opj_t2_t *t2) { + if(t2) { + opj_free(t2); + } +} + diff --git a/src/lib/openjp3d/t2.h b/src/lib/openjp3d/t2.h index b937290b..9aaecb14 100644 --- a/src/lib/openjp3d/t2.h +++ b/src/lib/openjp3d/t2.h @@ -1,101 +1,101 @@ -/* - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium - * Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef __T2_H -#define __T2_H -/** -@file t2.h -@brief Implementation of a tier-2 coding (packetization of code-block data) (T2) - -*/ - -/** @defgroup T2 T2 - Implementation of a tier-2 coding */ -/*@{*/ - -/** -Tier-2 coding -*/ -typedef struct opj_t2 { -/** Codec context */ - opj_common_ptr cinfo; -/** Encoding: pointer to the src volume. Decoding: pointer to the dst volume. */ - opj_volume_t *volume; -/** Pointer to the volume coding parameters */ - opj_cp_t *cp; -} opj_t2_t; - -/** @name Funciones generales */ -/*@{*/ -/* ----------------------------------------------------------------------- */ - -/** -Encode the packets of a tile to a destination buffer -@param t2 T2 handle -@param tileno number of the tile encoded -@param tile the tile for which to write the packets -@param maxlayers maximum number of layers -@param dest the destination buffer -@param len the length of the destination buffer -@param volume_info structure to create an index file -@return Number of bytes written from packets -*/ -int t2_encode_packets(opj_t2_t* t2, int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_volume_info_t *volume_info); - -/** -Decode the packets of a tile from a source buffer -@param t2 T2 handle -@param src the source buffer -@param len length of the source buffer -@param tileno number that identifies the tile for which to decode the packets -@param tile tile for which to decode the packets -@return Number of bytes read from packets - */ -int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj_tcd_tile_t *tile); - -/** -Create a T2 handle -@param cinfo Codec context info -@param volume Source or destination volume -@param cp Volume coding parameters -@return Returns a new T2 handle if successful, returns NULL otherwise -*/ -opj_t2_t* t2_create(opj_common_ptr cinfo, opj_volume_t *volume, opj_cp_t *cp); -/** -Destroy a T2 handle -@param t2 T2 handle to destroy -*/ -void t2_destroy(opj_t2_t *t2); - -/* ----------------------------------------------------------------------- */ -/*@}*/ - -/*@}*/ - -#endif /* __T2_H */ +/* + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __T2_H +#define __T2_H +/** +@file t2.h +@brief Implementation of a tier-2 coding (packetization of code-block data) (T2) + +*/ + +/** @defgroup T2 T2 - Implementation of a tier-2 coding */ +/*@{*/ + +/** +Tier-2 coding +*/ +typedef struct opj_t2 { +/** Codec context */ + opj_common_ptr cinfo; +/** Encoding: pointer to the src volume. Decoding: pointer to the dst volume. */ + opj_volume_t *volume; +/** Pointer to the volume coding parameters */ + opj_cp_t *cp; +} opj_t2_t; + +/** @name Funciones generales */ +/*@{*/ +/* ----------------------------------------------------------------------- */ + +/** +Encode the packets of a tile to a destination buffer +@param t2 T2 handle +@param tileno number of the tile encoded +@param tile the tile for which to write the packets +@param maxlayers maximum number of layers +@param dest the destination buffer +@param len the length of the destination buffer +@param volume_info structure to create an index file +@return Number of bytes written from packets +*/ +int t2_encode_packets(opj_t2_t* t2, int tileno, opj_tcd_tile_t *tile, int maxlayers, unsigned char *dest, int len, opj_volume_info_t *volume_info); + +/** +Decode the packets of a tile from a source buffer +@param t2 T2 handle +@param src the source buffer +@param len length of the source buffer +@param tileno number that identifies the tile for which to decode the packets +@param tile tile for which to decode the packets +@return Number of bytes read from packets + */ +int t2_decode_packets(opj_t2_t *t2, unsigned char *src, int len, int tileno, opj_tcd_tile_t *tile); + +/** +Create a T2 handle +@param cinfo Codec context info +@param volume Source or destination volume +@param cp Volume coding parameters +@return Returns a new T2 handle if successful, returns NULL otherwise +*/ +opj_t2_t* t2_create(opj_common_ptr cinfo, opj_volume_t *volume, opj_cp_t *cp); +/** +Destroy a T2 handle +@param t2 T2 handle to destroy +*/ +void t2_destroy(opj_t2_t *t2); + +/* ----------------------------------------------------------------------- */ +/*@}*/ + +/*@}*/ + +#endif /* __T2_H */ diff --git a/src/lib/openjp3d/tcd.c b/src/lib/openjp3d/tcd.c index 84c1ed1e..e13a4af6 100644 --- a/src/lib/openjp3d/tcd.c +++ b/src/lib/openjp3d/tcd.c @@ -1,1739 +1,1739 @@ -/* - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium - * Copyright (c) 2006, Mónica Díez, LPI-UVA, Spain - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "opj_includes.h" - -void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_volume_t * vol) { - int tileno, compno, resno, bandno, precno, cblkno; - - fprintf(fd, "volume {\n"); - fprintf(fd, " tw=%d, th=%d, tl=%d, x0=%d x1=%d y0=%d y1=%d z0=%d z1=%d\n", - vol->tw, vol->th, vol->tl, tcd->volume->x0, tcd->volume->x1, tcd->volume->y0, tcd->volume->y1, tcd->volume->z0, tcd->volume->z1); - - for (tileno = 0; tileno < vol->th * vol->tw * vol->tl; tileno++) { - opj_tcd_tile_t *tile = &tcd->tcd_volume->tiles[tileno]; - fprintf(fd, " tile {\n"); - fprintf(fd, " x0=%d, y0=%d, z0=%d, x1=%d, y1=%d, z1=%d, numcomps=%d\n", - tile->x0, tile->y0, tile->z0, tile->x1, tile->y1, tile->z1, tile->numcomps); - for (compno = 0; compno < tile->numcomps; compno++) { - opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; - fprintf(fd, " tilecomp %d {\n",compno); - fprintf(fd, " x0=%d, y0=%d, z0=%d, x1=%d, y1=%d, z1=%d, numresx=%d, numresy=%d, numresz=%d\n", - tilec->x0, tilec->y0, tilec->z0, tilec->x1, tilec->y1, tilec->z1, tilec->numresolution[0], tilec->numresolution[1], tilec->numresolution[2]); - for (resno = 0; resno < tilec->numresolution[0]; resno++) { - opj_tcd_resolution_t *res = &tilec->resolutions[resno]; - fprintf(fd, " res %d{\n",resno); - fprintf(fd," x0=%d, y0=%d, z0=%d, x1=%d, y1=%d, z1=%d, pw=%d, ph=%d, pl=%d, numbands=%d\n", - res->x0, res->y0, res->z0, res->x1, res->y1, res->z1, res->prctno[0], res->prctno[1], res->prctno[2], res->numbands); - for (bandno = 0; bandno < res->numbands; bandno++) { - opj_tcd_band_t *band = &res->bands[bandno]; - fprintf(fd, " band %d{\n", bandno); - fprintf(fd, " x0=%d, y0=%d, z0=%d, x1=%d, y1=%d, z1=%d, stepsize=%f, numbps=%d\n", - band->x0, band->y0, band->z0, band->x1, band->y1, band->z1, band->stepsize, band->numbps); - for (precno = 0; precno < (res->prctno[0] * res->prctno[1] * res->prctno[2]); precno++) { - opj_tcd_precinct_t *prec = &band->precincts[precno]; - fprintf(fd, " prec %d{\n",precno); - fprintf(fd, " x0=%d, y0=%d, z0=%d, x1=%d, y1=%d, z1=%d, cw=%d, ch=%d, cl=%d,\n", - prec->x0, prec->y0, prec->z0, prec->x1, prec->y1, prec->z1, prec->cblkno[0], prec->cblkno[1], prec->cblkno[2]); - for (cblkno = 0; cblkno < (prec->cblkno[0] * prec->cblkno[1] * prec->cblkno[2]); cblkno++) { - opj_tcd_cblk_t *cblk = &prec->cblks[cblkno]; - fprintf(fd, " cblk %d{\n",cblkno); - fprintf(fd, " x0=%d, y0=%d, z0=%d, x1=%d, y1=%d, z1=%d\n", cblk->x0, cblk->y0, cblk->z0, cblk->x1, cblk->y1, cblk->z1); - fprintf(fd, " }\n"); - } - fprintf(fd, " }\n"); - } - fprintf(fd, " }\n"); - } - fprintf(fd, " }\n"); - } - fprintf(fd, " }\n"); - } - fprintf(fd, " }\n"); - } - fprintf(fd, "}\n"); -} - -static void tilec_dump(FILE *fd, opj_tcd_tilecomp_t *tilec) { - - int i=0,k; - int datalen; - int *a; - - fprintf(fd, " tilecomp{\n"); - fprintf(fd, " x0=%d, y0=%d, z0=%d, x1=%d, y1=%d, z1=%d, numresx=%d, numresy=%d, numresz=%d\n", - tilec->x0, tilec->y0, tilec->z0, tilec->x1, tilec->y1, tilec->z1, tilec->numresolution[0], tilec->numresolution[1], tilec->numresolution[2]); - fprintf(fd, " data {\n"); - datalen = (tilec->z1 - tilec->z0) * (tilec->y1 - tilec->y0) * (tilec->x1 - tilec->x0); - a = tilec->data; - for (k = 0; k < datalen; k++) { - if (!(k % tilec->x1)){ - fprintf(fd, "\n"); - } - if (!(k % (tilec->y1 * tilec->x1))){ - fprintf(fd, "Slice %d\n",i++); - } - fprintf(fd," %d",a[k]); - - - } - fprintf(fd, " }\n"); - /*i=0; - fprintf(fd, "Slice %d\n"); - if (tilec->prediction->prederr) { - fprintf(fd, " prederror {\n"); - a = tilec->prediction->prederr; - for (k = 0; k < datalen; k++) { - fprintf(fd," %d",*(a++)); - if (!(k % (tilec->y1 - tilec->y0) * (tilec->x1 - tilec->x0))){ - fprintf(fd, "\n");fprintf(fd, "Slice %d\n",i++); - } - if (!(k % (tilec->x1 - tilec->x0))){ - fprintf(fd, "\n"); - } - } - } - fprintf(fd, " }\n");*/ - fprintf(fd, "}\n"); -} - -/* ----------------------------------------------------------------------- */ - -/** -Create a new TCD handle -*/ -opj_tcd_t* tcd_create(opj_common_ptr cinfo) { - /* create the tcd structure */ - opj_tcd_t *tcd = (opj_tcd_t*)opj_malloc(sizeof(opj_tcd_t)); - if(!tcd) return NULL; - tcd->cinfo = cinfo; - tcd->tcd_volume = (opj_tcd_volume_t*)opj_malloc(sizeof(opj_tcd_volume_t)); - if(!tcd->tcd_volume) { - opj_free(tcd); - return NULL; - } - - return tcd; -} - -/** -Destroy a previously created TCD handle -*/ -void tcd_destroy(opj_tcd_t *tcd) { - if(tcd) { - opj_free(tcd->tcd_volume); - opj_free(tcd); - } -} - -/* ----------------------------------------------------------------------- */ -void tcd_malloc_encode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp, int curtileno) { - int compno, resno, bandno, precno, cblkno, i, j;/*, k;*/ - - opj_tcd_tile_t *tile = NULL; /* pointer to tcd->tile */ - opj_tcd_tilecomp_t *tilec = NULL; /* pointer to tcd->tilec */ - opj_tcd_resolution_t *res = NULL; /* pointer to tcd->res */ - opj_tcd_band_t *band = NULL; /* pointer to tcd->band */ - opj_tcd_precinct_t *prc = NULL; /* pointer to tcd->prc */ - opj_tcd_cblk_t *cblk = NULL; /* pointer to tcd->cblk */ - opj_tcp_t *tcp = &cp->tcps[curtileno]; - int p,q,r; - - tcd->volume = volume; - tcd->cp = cp; - tcd->tcd_volume->tw = cp->tw; - tcd->tcd_volume->th = cp->th; - tcd->tcd_volume->tl = cp->tl; - tcd->tcd_volume->tiles = (opj_tcd_tile_t *) opj_malloc(sizeof(opj_tcd_tile_t)); - tcd->tile = tcd->tcd_volume->tiles; - tile = tcd->tile; - - - /* p61 ISO/IEC IS15444-1 : 2002 */ - /* curtileno --> raster scanned index of tiles */ - /* p,q,r --> matricial index of tiles */ - p = curtileno % cp->tw; - q = curtileno / cp->tw; - r = curtileno / (cp->tw * cp->th); /* extension to 3-D */ - - /* 4 borders of the tile rescale on the volume if necessary (B.3)*/ - tile->x0 = int_max(cp->tx0 + p * cp->tdx, volume->x0); - tile->y0 = int_max(cp->ty0 + q * cp->tdy, volume->y0); - tile->z0 = int_max(cp->tz0 + r * cp->tdz, volume->z0); - tile->x1 = int_min(cp->tx0 + (p + 1) * cp->tdx, volume->x1); - tile->y1 = int_min(cp->ty0 + (q + 1) * cp->tdy, volume->y1); - tile->z1 = int_min(cp->tz0 + (r + 1) * cp->tdz, volume->z1); - tile->numcomps = volume->numcomps; - - /* Modification of the RATE >> */ - for (j = 0; j < tcp->numlayers; j++) { - if (tcp->rates[j] <= 1) { - tcp->rates[j] = 0; - } else { - float num = (float) (tile->numcomps * (tile->x1 - tile->x0) * (tile->y1 - tile->y0) * (tile->z1 - tile->z0) * volume->comps[0].prec); - float den = (float) (8 * volume->comps[0].dx * volume->comps[0].dy * volume->comps[0].dz); - den = tcp->rates[j] * den; - tcp->rates[j] = (num + den - 1) / den; - } - /*tcp->rates[j] = tcp->rates[j] ? int_ceildiv( - tile->numcomps * (tile->x1 - tile->x0) * (tile->y1 - tile->y0) * (tile->z1 - tile->z0) * volume->comps[0].prec, - (tcp->rates[j] * 8 * volume->comps[0].dx * volume->comps[0].dy * volume->comps[0].dz)) : 0;*/ - if (tcp->rates[j]) { - if (j && tcp->rates[j] < tcp->rates[j - 1] + 10) { - tcp->rates[j] = tcp->rates[j - 1] + 20; - } else if (!j && tcp->rates[j] < 30){ - tcp->rates[j] = 30; - } - } - } - /* << Modification of the RATE */ - - tile->comps = (opj_tcd_tilecomp_t *) opj_malloc(volume->numcomps * sizeof(opj_tcd_tilecomp_t)); - for (compno = 0; compno < tile->numcomps; compno++) { - opj_tccp_t *tccp = &tcp->tccps[compno]; - int res_max; - int prevnumbands = 0; - - /* opj_tcd_tilecomp_t *tilec=&tile->comps[compno]; */ - tcd->tilec = &tile->comps[compno]; - tilec = tcd->tilec; - - /* border of each tile component (global) (B.3) */ - tilec->x0 = int_ceildiv(tile->x0, volume->comps[compno].dx); - tilec->y0 = int_ceildiv(tile->y0, volume->comps[compno].dy); - tilec->z0 = int_ceildiv(tile->z0, volume->comps[compno].dz); - tilec->x1 = int_ceildiv(tile->x1, volume->comps[compno].dx); - tilec->y1 = int_ceildiv(tile->y1, volume->comps[compno].dy); - tilec->z1 = int_ceildiv(tile->z1, volume->comps[compno].dz); - - tilec->data = (int *) opj_malloc((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0) * (tilec->z1 - tilec->z0) * sizeof(int)); - - res_max = 0; - for (i = 0;i < 3; i++){ - tilec->numresolution[i] = tccp->numresolution[i]; - /*Greater of 3 resolutions contains all information*/ - res_max = (tilec->numresolution[i] > res_max) ? tilec->numresolution[i] : res_max; - } - - - tilec->resolutions = (opj_tcd_resolution_t *) opj_malloc(res_max * sizeof(opj_tcd_resolution_t)); - for (resno = 0; resno < res_max; resno++) { - - int pdx, pdy, pdz; - int tlprcxstart, tlprcystart, tlprczstart; - int brprcxend, brprcyend, brprczend; - int tlcbgxstart, tlcbgystart, tlcbgzstart; - int brcbgxend, brcbgyend, brcbgzend; - int cbgwidthexpn, cbgheightexpn, cbglengthexpn; - int cblkwidthexpn, cblkheightexpn, cblklengthexpn; - - int diff = tccp->numresolution[0] - tccp->numresolution[2]; - int levelnox = tilec->numresolution[0] - 1 - resno; - int levelnoy = tilec->numresolution[1] - 1 - resno; - int levelnoz = tilec->numresolution[2] - 1 - ((resno <= diff) ? 0 : (resno - diff)); - if (levelnoz < 0) levelnoz = 0; - - /* opj_tcd_resolution_t *res=&tilec->resolutions[resno]; */ - tcd->res = &tilec->resolutions[resno]; - res = tcd->res; - - /* border for each resolution level (global) (B.14)*/ - res->x0 = int_ceildivpow2(tilec->x0, levelnox); - res->y0 = int_ceildivpow2(tilec->y0, levelnoy); - res->z0 = int_ceildivpow2(tilec->z0, levelnoz); - res->x1 = int_ceildivpow2(tilec->x1, levelnox); - res->y1 = int_ceildivpow2(tilec->y1, levelnoy); - res->z1 = int_ceildivpow2(tilec->z1, levelnoz); - /*if (res->z1 < 0)fprintf(stdout,"Res: %d %d/%d --> %d\n",resno,tilec->z1, levelnoz, int_ceildivpow2(tilec->z1, levelnoz));*/ - - res->numbands = (resno == 0) ? 1 : (resno <= diff) ? 3 : 7; /* --> 3D */ - - /* p. 30, table A-13, ISO/IEC IS154444-1 : 2002 */ - if (tccp->csty & J3D_CCP_CSTY_PRT) { - pdx = tccp->prctsiz[0][resno]; - pdy = tccp->prctsiz[1][resno]; - pdz = tccp->prctsiz[2][resno]; - } else { - pdx = 15; - pdy = 15; - pdz = 15; - } - - /* p. 66, B.16, ISO/IEC IS15444-1 : 2002 */ - tlprcxstart = int_floordivpow2(res->x0, pdx) << pdx; - tlprcystart = int_floordivpow2(res->y0, pdy) << pdy; - tlprczstart = int_floordivpow2(res->z0, pdz) << pdz; - brprcxend = int_ceildivpow2(res->x1, pdx) << pdx; - brprcyend = int_ceildivpow2(res->y1, pdy) << pdy; - brprczend = int_ceildivpow2(res->z1, pdz) << pdz; - - res->prctno[0] = (brprcxend - tlprcxstart) >> pdx; - res->prctno[1] = (brprcyend - tlprcystart) >> pdy; - res->prctno[2] = (brprczend - tlprczstart) >> pdz; - if (res->prctno[2] == 0) res->prctno[2] = 1; - - /* p. 67, B.17 & B.18, ISO/IEC IS15444-1 : 2002 */ - if (resno == 0) { - tlcbgxstart = tlprcxstart; - tlcbgystart = tlprcystart; - tlcbgzstart = tlprczstart; - brcbgxend = brprcxend; - brcbgyend = brprcyend; - brcbgzend = brprczend; - cbgwidthexpn = pdx; - cbgheightexpn = pdy; - cbglengthexpn = pdz; - } else { - tlcbgxstart = int_ceildivpow2(tlprcxstart, 1); - tlcbgystart = int_ceildivpow2(tlprcystart, 1); - tlcbgzstart = int_ceildivpow2(tlprczstart, 1); - brcbgxend = int_ceildivpow2(brprcxend, 1); - brcbgyend = int_ceildivpow2(brprcyend, 1); - brcbgzend = int_ceildivpow2(brprczend, 1); - cbgwidthexpn = pdx - 1; - cbgheightexpn = pdy - 1; - cbglengthexpn = pdz - 1; - } - - cblkwidthexpn = int_min(tccp->cblk[0], cbgwidthexpn); /*6*/ - cblkheightexpn = int_min(tccp->cblk[1], cbgheightexpn); /*6*/ - cblklengthexpn = int_min(tccp->cblk[2], cbglengthexpn); /*6*/ - - res->bands = (opj_tcd_band_t *) opj_malloc(res->numbands * sizeof(opj_tcd_band_t)); - for (bandno = 0; bandno < res->numbands; bandno++) { - int x0b, y0b, z0b, i; - int gain, numbps; - opj_stepsize_t *ss = NULL; - - tcd->band = &res->bands[bandno]; - band = tcd->band; - - band->bandno = (resno == 0) ? 0 : bandno + 1; - /* Bandno: 0 - LLL 2 - LHL - 1 - HLL 3 - HHL - 4 - LLH 6 - LHH - 5 - HLH 7 - HHH */ - x0b = (band->bandno == 1) || (band->bandno == 3) || (band->bandno == 5 ) || (band->bandno == 7 ) ? 1 : 0; - y0b = (band->bandno == 2) || (band->bandno == 3) || (band->bandno == 6 ) || (band->bandno == 7 ) ? 1 : 0; - z0b = (band->bandno == 4) || (band->bandno == 5) || (band->bandno == 6 ) || (band->bandno == 7 ) ? 1 : 0; - - /* p. 65, B.15, ISO/IEC IS15444-1 : 2002 */ - if (band->bandno == 0) { - /* band border (global) */ - band->x0 = int_ceildivpow2(tilec->x0, levelnox); - band->y0 = int_ceildivpow2(tilec->y0, levelnoy); - band->z0 = int_ceildivpow2(tilec->z0, levelnoz); - band->x1 = int_ceildivpow2(tilec->x1, levelnox); - band->y1 = int_ceildivpow2(tilec->y1, levelnoy); - band->z1 = int_ceildivpow2(tilec->z1, levelnoz); - } else { - band->x0 = int_ceildivpow2(tilec->x0 - (1 << levelnox) * x0b, levelnox + 1); - band->y0 = int_ceildivpow2(tilec->y0 - (1 << levelnoy) * y0b, levelnoy + 1); - band->z0 = int_ceildivpow2(tilec->z0 - (1 << levelnoz) * z0b, (resno <= diff) ? levelnoz : levelnoz + 1); - band->x1 = int_ceildivpow2(tilec->x1 - (1 << levelnox) * x0b, levelnox + 1); - band->y1 = int_ceildivpow2(tilec->y1 - (1 << levelnoy) * y0b, levelnoy + 1); - band->z1 = int_ceildivpow2(tilec->z1 - (1 << levelnoz) * z0b, (resno <= diff) ? levelnoz : levelnoz + 1); - } - - ss = &tccp->stepsizes[(resno == 0) ? 0 : (prevnumbands + bandno + 1)]; - if (bandno == (res->numbands - 1)) - prevnumbands += (resno == 0) ? 0 : res->numbands; - gain = dwt_getgain(band->bandno,tccp->reversible); - numbps = volume->comps[compno].prec + gain; - band->stepsize = (float)((1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn)); - band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */ - - band->precincts = (opj_tcd_precinct_t *) opj_malloc((res->prctno[0] * res->prctno[1] * res->prctno[2]) * sizeof(opj_tcd_precinct_t)); - - for (i = 0; i < (res->prctno[0] * res->prctno[1] * res->prctno[2]); i++) { - band->precincts[i].imsbtree = NULL; - band->precincts[i].incltree = NULL; - } - - for (precno = 0; precno < (res->prctno[0] * res->prctno[1] * res->prctno[2]); precno++) { - int tlcblkxstart, tlcblkystart, tlcblkzstart, brcblkxend, brcblkyend, brcblkzend; - int cbgxstart, cbgystart, cbgzstart, cbgxend, cbgyend, cbgzend; - - cbgxstart = tlcbgxstart + (precno % res->prctno[0]) * (1 << cbgwidthexpn); - cbgystart = tlcbgystart + ((precno % (res->prctno[0] * res->prctno[1])) / res->prctno[0]) * (1 << cbgheightexpn); - cbgzstart = tlcbgzstart + (precno / (res->prctno[0] * res->prctno[1])) * (1 << cbglengthexpn); - cbgxend = cbgxstart + (1 << cbgwidthexpn); - cbgyend = cbgystart + (1 << cbgheightexpn); - cbgzend = cbgzstart + (1 << cbglengthexpn); - - tcd->prc = &band->precincts[precno]; - prc = tcd->prc; - - /* precinct size (global) */ - prc->x0 = int_max(cbgxstart, band->x0); - prc->y0 = int_max(cbgystart, band->y0); - prc->z0 = int_max(cbgzstart, band->z0); - prc->x1 = int_min(cbgxend, band->x1); - prc->y1 = int_min(cbgyend, band->y1); - prc->z1 = int_min(cbgzend, band->z1); - - tlcblkxstart = int_floordivpow2(prc->x0, cblkwidthexpn) << cblkwidthexpn; - tlcblkystart = int_floordivpow2(prc->y0, cblkheightexpn) << cblkheightexpn; - tlcblkzstart = int_floordivpow2(prc->z0, cblklengthexpn) << cblklengthexpn; - brcblkxend = int_ceildivpow2(prc->x1, cblkwidthexpn) << cblkwidthexpn; - brcblkyend = int_ceildivpow2(prc->y1, cblkheightexpn) << cblkheightexpn; - brcblkzend = int_ceildivpow2(prc->z1, cblklengthexpn) << cblklengthexpn; - prc->cblkno[0] = (brcblkxend - tlcblkxstart) >> cblkwidthexpn; - prc->cblkno[1] = (brcblkyend - tlcblkystart) >> cblkheightexpn; - prc->cblkno[2] = (brcblkzend - tlcblkzstart) >> cblklengthexpn; - prc->cblkno[2] = (prc->cblkno[2] == 0) ? 1 : prc->cblkno[2]; - - prc->cblks = (opj_tcd_cblk_t *) opj_malloc((prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]) * sizeof(opj_tcd_cblk_t)); - prc->incltree = tgt_create(prc->cblkno[0], prc->cblkno[1], prc->cblkno[2]); - prc->imsbtree = tgt_create(prc->cblkno[0], prc->cblkno[1], prc->cblkno[2]); - /*tgt_tree_dump(stdout,prc->incltree);*/ - for (cblkno = 0; cblkno < (prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]); cblkno++) { - int cblkxstart = tlcblkxstart + (cblkno % prc->cblkno[0]) * (1 << cblkwidthexpn); - int cblkystart = tlcblkystart + ((cblkno % (prc->cblkno[0] * prc->cblkno[1])) / prc->cblkno[0]) * (1 << cblkheightexpn); - int cblkzstart = tlcblkzstart + (cblkno / (prc->cblkno[0] * prc->cblkno[1])) * (1 << cblklengthexpn); - int cblkxend = cblkxstart + (1 << cblkwidthexpn); - int cblkyend = cblkystart + (1 << cblkheightexpn); - int cblkzend = cblkzstart + (1 << cblklengthexpn); - int prec = ((tilec->bpp > 16) ? 3 : ((tilec->bpp > 8) ? 2 : 1)); - - tcd->cblk = &prc->cblks[cblkno]; - cblk = tcd->cblk; - - /* code-block size (global) */ - cblk->x0 = int_max(cblkxstart, prc->x0); - cblk->y0 = int_max(cblkystart, prc->y0); - cblk->z0 = int_max(cblkzstart, prc->z0); - cblk->x1 = int_min(cblkxend, prc->x1); - cblk->y1 = int_min(cblkyend, prc->y1); - cblk->z1 = int_min(cblkzend, prc->z1); - } - } - } - } - } - /*tcd_dump(stdout, tcd, tcd->tcd_volume);*/ - -} -void tcd_init_encode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp, int curtileno) { - int compno, resno, bandno, precno, cblkno; - int j, p, q, r; - - opj_tcd_tile_t *tile = NULL; /* pointer to tcd->tile */ - opj_tcd_tilecomp_t *tilec = NULL; /* pointer to tcd->tilec */ - opj_tcd_resolution_t *res = NULL; /* pointer to tcd->res */ - opj_tcd_band_t *band = NULL; /* pointer to tcd->band */ - opj_tcd_precinct_t *prc = NULL; /* pointer to tcd->prc */ - opj_tcd_cblk_t *cblk = NULL; /* pointer to tcd->cblk */ - opj_tcp_t *tcp = &cp->tcps[curtileno]; - - tcd->tile = tcd->tcd_volume->tiles; - tile = tcd->tile; - - /* p61 ISO/IEC IS15444-1 : 2002 */ - /* curtileno --> raster scanned index of tiles */ - /* p,q,r --> matricial index of tiles */ - p = curtileno % cp->tw; - q = curtileno / cp->tw; - r = curtileno / (cp->tw * cp->th); /* extension to 3-D */ - - /* 4 borders of the tile rescale on the volume if necessary (B.3)*/ - tile->x0 = int_max(cp->tx0 + p * cp->tdx, volume->x0); - tile->y0 = int_max(cp->ty0 + q * cp->tdy, volume->y0); - tile->z0 = int_max(cp->tz0 + r * cp->tdz, volume->z0); - tile->x1 = int_min(cp->tx0 + (p + 1) * cp->tdx, volume->x1); - tile->y1 = int_min(cp->ty0 + (q + 1) * cp->tdy, volume->y1); - tile->z1 = int_min(cp->tz0 + (r + 1) * cp->tdz, volume->z1); - tile->numcomps = volume->numcomps; - - /* Modification of the RATE >> */ - for (j = 0; j < tcp->numlayers; j++) { - if (tcp->rates[j] <= 1) { - tcp->rates[j] = 0; - } else { - float num = (float) (tile->numcomps * (tile->x1 - tile->x0) * (tile->y1 - tile->y0) * (tile->z1 - tile->z0) * volume->comps[0].prec); - float den = (float) (8 * volume->comps[0].dx * volume->comps[0].dy * volume->comps[0].dz); - den = tcp->rates[j] * den; - tcp->rates[j] = (num + den - 1) / den; - } - /*tcp->rates[j] = tcp->rates[j] ? int_ceildiv( - tile->numcomps * (tile->x1 - tile->x0) * (tile->y1 - tile->y0) * (tile->z1 - tile->z0) * volume->comps[0].prec, - (tcp->rates[j] * 8 * volume->comps[0].dx * volume->comps[0].dy * volume->comps[0].dz)) : 0;*/ - if (tcp->rates[j]) { - if (j && tcp->rates[j] < tcp->rates[j - 1] + 10) { - tcp->rates[j] = tcp->rates[j - 1] + 20; - } else if (!j && tcp->rates[j] < 30){ - tcp->rates[j] = 30; - } - } - } - /* << Modification of the RATE */ - - for (compno = 0; compno < tile->numcomps; compno++) { - opj_tccp_t *tccp = &tcp->tccps[compno]; - int res_max, i; - int prevnumbands = 0; - - /* opj_tcd_tilecomp_t *tilec=&tile->comps[compno]; */ - tcd->tilec = &tile->comps[compno]; - tilec = tcd->tilec; - - /* border of each tile component (global) (B.3) */ - tilec->x0 = int_ceildiv(tile->x0, volume->comps[compno].dx); - tilec->y0 = int_ceildiv(tile->y0, volume->comps[compno].dy); - tilec->z0 = int_ceildiv(tile->z0, volume->comps[compno].dz); - tilec->x1 = int_ceildiv(tile->x1, volume->comps[compno].dx); - tilec->y1 = int_ceildiv(tile->y1, volume->comps[compno].dy); - tilec->z1 = int_ceildiv(tile->z1, volume->comps[compno].dz); - - tilec->data = (int *) opj_malloc((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0) * (tilec->z1 - tilec->z0) * sizeof(int)); - - res_max = 0; - for (i = 0;i < 3; i++){ - tilec->numresolution[i] = tccp->numresolution[i]; - /*Greater of 3 resolutions contains all information*/ - res_max = (tilec->numresolution[i] > res_max) ? tilec->numresolution[i] : res_max; - } - - tilec->resolutions = (opj_tcd_resolution_t *) opj_malloc(res_max * sizeof(opj_tcd_resolution_t)); - for (resno = 0; resno < res_max; resno++) { - int pdx, pdy, pdz; - int tlprcxstart, tlprcystart, tlprczstart, brprcxend, brprcyend, brprczend; - int tlcbgxstart, tlcbgystart, tlcbgzstart, brcbgxend, brcbgyend, brcbgzend; - int cbgwidthexpn, cbgheightexpn, cbglengthexpn; - int cblkwidthexpn, cblkheightexpn, cblklengthexpn; - - int levelnox = tilec->numresolution[0] - 1 - resno; - int levelnoy = tilec->numresolution[1] - 1 - resno; - int diff = tccp->numresolution[0] - tccp->numresolution[2]; - int levelnoz = tilec->numresolution[2] - 1 - ((resno <= diff) ? 0 : (resno - diff)); - if (levelnoz < 0) levelnoz = 0; - - tcd->res = &tilec->resolutions[resno]; - res = tcd->res; - - /* border for each resolution level (global) (B.14)*/ - res->x0 = int_ceildivpow2(tilec->x0, levelnox); - res->y0 = int_ceildivpow2(tilec->y0, levelnoy); - res->z0 = int_ceildivpow2(tilec->z0, levelnoz); - res->x1 = int_ceildivpow2(tilec->x1, levelnox); - res->y1 = int_ceildivpow2(tilec->y1, levelnoy); - res->z1 = int_ceildivpow2(tilec->z1, levelnoz); - - /* res->numbands = resno == 0 ? 1 : 3; *//* --> 2D */ - - res->numbands = (resno == 0) ? 1 : (resno <= diff) ? 3 : 7; /* --> 3D */ - - /* p. 30, table A-13, ISO/IEC IS154444-1 : 2002 */ - if (tccp->csty & J3D_CCP_CSTY_PRT) { - pdx = tccp->prctsiz[0][resno]; - pdy = tccp->prctsiz[1][resno]; - pdz = tccp->prctsiz[2][resno]; - } else { - pdx = 15; - pdy = 15; - pdz = 15; - } - /* p. 66, B.16, ISO/IEC IS15444-1 : 2002 */ - tlprcxstart = int_floordivpow2(res->x0, pdx) << pdx; - tlprcystart = int_floordivpow2(res->y0, pdy) << pdy; - tlprczstart = int_floordivpow2(res->z0, pdz) << pdz; - brprcxend = int_ceildivpow2(res->x1, pdx) << pdx; - brprcyend = int_ceildivpow2(res->y1, pdy) << pdy; - brprczend = int_ceildivpow2(res->z1, pdz) << pdz; - - res->prctno[0] = (brprcxend - tlprcxstart) >> pdx; - res->prctno[1] = (brprcyend - tlprcystart) >> pdy; - res->prctno[2] = (brprczend - tlprczstart) >> pdz; - if (res->prctno[2] == 0) res->prctno[2] = 1; - - /* p. 67, B.17 & B.18, ISO/IEC IS15444-1 : 2002 */ - if (resno == 0) { - tlcbgxstart = tlprcxstart; - tlcbgystart = tlprcystart; - tlcbgzstart = tlprczstart; - brcbgxend = brprcxend; - brcbgyend = brprcyend; - brcbgzend = brprczend; - cbgwidthexpn = pdx; - cbgheightexpn = pdy; - cbglengthexpn = pdz; - } else { - tlcbgxstart = int_ceildivpow2(tlprcxstart, 1); - tlcbgystart = int_ceildivpow2(tlprcystart, 1); - tlcbgzstart = int_ceildivpow2(tlprczstart, 1); - brcbgxend = int_ceildivpow2(brprcxend, 1); - brcbgyend = int_ceildivpow2(brprcyend, 1); - brcbgzend = int_ceildivpow2(brprczend, 1); - cbgwidthexpn = pdx - 1; - cbgheightexpn = pdy - 1; - cbglengthexpn = pdz - 1; - } - - cblkwidthexpn = int_min(tccp->cblk[0], cbgwidthexpn); - cblkheightexpn = int_min(tccp->cblk[1], cbgheightexpn); - cblklengthexpn = int_min(tccp->cblk[2], cbglengthexpn); - - res->bands = (opj_tcd_band_t *) opj_malloc(res->numbands * sizeof(opj_tcd_band_t)); - for (bandno = 0; bandno < res->numbands; bandno++) { - int x0b, y0b, z0b; - int gain, numbps; - opj_stepsize_t *ss = NULL; - - tcd->band = &res->bands[bandno]; - band = tcd->band; - - band->bandno = resno == 0 ? 0 : bandno + 1; - /* Bandno: 0 - LLL 2 - LHL - 1 - HLL 3 - HHL - 4 - LLH 6 - LHH - 5 - HLH 7 - HHH */ - x0b = (band->bandno == 1) || (band->bandno == 3) || (band->bandno == 5 ) || (band->bandno == 7 ) ? 1 : 0; - y0b = (band->bandno == 2) || (band->bandno == 3) || (band->bandno == 6 ) || (band->bandno == 7 ) ? 1 : 0; - z0b = (band->bandno == 4) || (band->bandno == 5) || (band->bandno == 6 ) || (band->bandno == 7 ) ? 1 : 0; - - /* p. 65, B.15, ISO/IEC IS15444-1 : 2002 */ - if (band->bandno == 0) { - /* band border (global) */ - band->x0 = int_ceildivpow2(tilec->x0, levelnox); - band->y0 = int_ceildivpow2(tilec->y0, levelnoy); - band->z0 = int_ceildivpow2(tilec->z0, levelnoz); - band->x1 = int_ceildivpow2(tilec->x1, levelnox); - band->y1 = int_ceildivpow2(tilec->y1, levelnoy); - band->z1 = int_ceildivpow2(tilec->z1, levelnoz); - } else { - band->x0 = int_ceildivpow2(tilec->x0 - (1 << levelnox) * x0b, levelnox + 1); - band->y0 = int_ceildivpow2(tilec->y0 - (1 << levelnoy) * y0b, levelnoy + 1); - band->z0 = int_ceildivpow2(tilec->z0 - (1 << levelnoz) * z0b, (resno <= diff) ? levelnoz : levelnoz + 1); - band->x1 = int_ceildivpow2(tilec->x1 - (1 << levelnox) * x0b, levelnox + 1); - band->y1 = int_ceildivpow2(tilec->y1 - (1 << levelnoy) * y0b, levelnoy + 1); - band->z1 = int_ceildivpow2(tilec->z1 - (1 << levelnoz) * z0b, (resno <= diff) ? levelnoz : levelnoz + 1); - } - - ss = &tccp->stepsizes[(resno == 0) ? 0 : (prevnumbands + bandno + 1)]; - if (bandno == (res->numbands - 1)) - prevnumbands += (resno == 0) ? 0 : res->numbands; - gain = dwt_getgain(band->bandno,tccp->reversible); - numbps = volume->comps[compno].prec + gain; - - band->stepsize = (float)((1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn)); - band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */ - - for (precno = 0; precno < res->prctno[0] * res->prctno[1] * res->prctno[2]; precno++) { - int tlcblkxstart, tlcblkystart, tlcblkzstart, brcblkxend, brcblkyend, brcblkzend; - - int cbgxstart = tlcbgxstart + (precno % res->prctno[0]) * (1 << cbgwidthexpn); - int cbgystart = tlcbgystart + ((precno / (res->prctno[0] * res->prctno[1])) / res->prctno[0]) * (1 << cbgheightexpn); - int cbgzstart = tlcbgzstart + (precno / (res->prctno[0] * res->prctno[1])) * (1 << cbglengthexpn); - int cbgxend = cbgxstart + (1 << cbgwidthexpn); - int cbgyend = cbgystart + (1 << cbgheightexpn); - int cbgzend = cbgzstart + (1 << cbglengthexpn); - - /* opj_tcd_precinct_t *prc=&band->precincts[precno]; */ - tcd->prc = &band->precincts[precno]; - prc = tcd->prc; - - /* precinct size (global) */ - prc->x0 = int_max(cbgxstart, band->x0); - prc->y0 = int_max(cbgystart, band->y0); - prc->z0 = int_max(cbgzstart, band->z0); - prc->x1 = int_min(cbgxend, band->x1); - prc->y1 = int_min(cbgyend, band->y1); - prc->z1 = int_min(cbgzend, band->z1); - - tlcblkxstart = int_floordivpow2(prc->x0, cblkwidthexpn) << cblkwidthexpn; - tlcblkystart = int_floordivpow2(prc->y0, cblkheightexpn) << cblkheightexpn; - tlcblkzstart = int_floordivpow2(prc->z0, cblklengthexpn) << cblklengthexpn; - brcblkxend = int_ceildivpow2(prc->x1, cblkwidthexpn) << cblkwidthexpn; - brcblkyend = int_ceildivpow2(prc->y1, cblkheightexpn) << cblkheightexpn; - brcblkzend = int_ceildivpow2(prc->z1, cblklengthexpn) << cblklengthexpn; - prc->cblkno[0] = (brcblkxend - tlcblkxstart) >> cblkwidthexpn; - prc->cblkno[1] = (brcblkyend - tlcblkystart) >> cblkheightexpn; - prc->cblkno[2] = (brcblkzend - tlcblkzstart) >> cblklengthexpn; - prc->cblkno[2] = (prc->cblkno[2] == 0) ? 1 : prc->cblkno[2]; - - opj_free(prc->cblks); - prc->cblks = (opj_tcd_cblk_t *) opj_malloc((prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]) * sizeof(opj_tcd_cblk_t)); - prc->incltree = tgt_create(prc->cblkno[0], prc->cblkno[1], prc->cblkno[2]); - prc->imsbtree = tgt_create(prc->cblkno[0], prc->cblkno[1], prc->cblkno[2]); - - for (cblkno = 0; cblkno < (prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]); cblkno++) { - int cblkxstart = tlcblkxstart + (cblkno % prc->cblkno[0]) * (1 << cblkwidthexpn); - int cblkystart = tlcblkystart + ((cblkno % (prc->cblkno[0] * prc->cblkno[1])) / prc->cblkno[0]) * (1 << cblkheightexpn); - int cblkzstart = tlcblkzstart + (cblkno / (prc->cblkno[0] * prc->cblkno[1])) * (1 << cblklengthexpn); - int cblkxend = cblkxstart + (1 << cblkwidthexpn); - int cblkyend = cblkystart + (1 << cblkheightexpn); - int cblkzend = cblkzstart + (1 << cblklengthexpn); - int prec = ((tilec->bpp > 16) ? 3 : ((tilec->bpp > 8) ? 2 : 1)); - - tcd->cblk = &prc->cblks[cblkno]; - cblk = tcd->cblk; - - /* code-block size (global) */ - cblk->x0 = int_max(cblkxstart, prc->x0); - cblk->y0 = int_max(cblkystart, prc->y0); - cblk->z0 = int_max(cblkzstart, prc->z0); - cblk->x1 = int_min(cblkxend, prc->x1); - cblk->y1 = int_min(cblkyend, prc->y1); - cblk->z1 = int_min(cblkzend, prc->z1); - } - } /* precno */ - } /* bandno */ - } /* resno */ - } /* compno */ - /*tcd_dump(stdout, tcd, tcd->tcd_volume);*/ -} - - -void tcd_free_encode(opj_tcd_t *tcd) { - int tileno, compno, resno, bandno, precno; - - opj_tcd_tile_t *tile = NULL; /* pointer to tcd->tile */ -/* opj_tcd_slice_t *slice = NULL; */ /* pointer to tcd->slice */ - opj_tcd_tilecomp_t *tilec = NULL; /* pointer to tcd->tilec */ - opj_tcd_resolution_t *res = NULL; /* pointer to tcd->res */ - opj_tcd_band_t *band = NULL; /* pointer to tcd->band */ - opj_tcd_precinct_t *prc = NULL; /* pointer to tcd->prc */ - - for (tileno = 0; tileno < 1; tileno++) { - tcd->tile = tcd->tcd_volume->tiles; - tile = tcd->tile; - - for (compno = 0; compno < tile->numcomps; compno++) { - tcd->tilec = &tile->comps[compno]; - tilec = tcd->tilec; - - for (resno = 0; resno < tilec->numresolution[0]; resno++) { - tcd->res = &tilec->resolutions[resno]; - res = tcd->res; - - for (bandno = 0; bandno < res->numbands; bandno++) { - tcd->band = &res->bands[bandno]; - band = tcd->band; - - for (precno = 0; precno < res->prctno[0] * res->prctno[1] * res->prctno[2]; precno++) { - tcd->prc = &band->precincts[precno]; - prc = tcd->prc; - - if (prc->incltree != NULL) { - tgt_destroy(prc->incltree); - prc->incltree = NULL; - } - if (prc->imsbtree != NULL) { - tgt_destroy(prc->imsbtree); - prc->imsbtree = NULL; - } - opj_free(prc->cblks); - prc->cblks = NULL; - } /* for (precno */ - opj_free(band->precincts); - band->precincts = NULL; - } /* for (bandno */ - } /* for (resno */ - opj_free(tilec->resolutions); - tilec->resolutions = NULL; - } /* for (compno */ - opj_free(tile->comps); - tile->comps = NULL; - } /* for (tileno */ - opj_free(tcd->tcd_volume->tiles); - tcd->tcd_volume->tiles = NULL; -} - -/* ----------------------------------------------------------------------- */ -void tcd_malloc_decode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp) { - int tileno, compno, resno, bandno, precno, cblkno, res_max, - i, j, p, q, r; - unsigned int x0 = 0, y0 = 0, z0 = 0, - x1 = 0, y1 = 0, z1 = 0, - w, h, l; - - tcd->volume = volume; - tcd->cp = cp; - tcd->tcd_volume->tw = cp->tw; - tcd->tcd_volume->th = cp->th; - tcd->tcd_volume->tl = cp->tl; - tcd->tcd_volume->tiles = (opj_tcd_tile_t *) opj_malloc(cp->tw * cp->th * cp->tl * sizeof(opj_tcd_tile_t)); - - for (i = 0; i < cp->tileno_size; i++) { - opj_tcp_t *tcp = &(cp->tcps[cp->tileno[i]]); - opj_tcd_tile_t *tile = &(tcd->tcd_volume->tiles[cp->tileno[i]]); - - /* p61 ISO/IEC IS15444-1 : 2002 */ - /* curtileno --> raster scanned index of tiles */ - /* p,q,r --> matricial index of tiles */ - tileno = cp->tileno[i]; - p = tileno % cp->tw; - q = tileno / cp->tw; - r = tileno / (cp->tw * cp->th); /* extension to 3-D */ - - /* 4 borders of the tile rescale on the volume if necessary (B.3)*/ - tile->x0 = int_max(cp->tx0 + p * cp->tdx, volume->x0); - tile->y0 = int_max(cp->ty0 + q * cp->tdy, volume->y0); - tile->z0 = int_max(cp->tz0 + r * cp->tdz, volume->z0); - tile->x1 = int_min(cp->tx0 + (p + 1) * cp->tdx, volume->x1); - tile->y1 = int_min(cp->ty0 + (q + 1) * cp->tdy, volume->y1); - tile->z1 = int_min(cp->tz0 + (r + 1) * cp->tdz, volume->z1); - tile->numcomps = volume->numcomps; - - tile->comps = (opj_tcd_tilecomp_t *) opj_malloc(volume->numcomps * sizeof(opj_tcd_tilecomp_t)); - for (compno = 0; compno < tile->numcomps; compno++) { - opj_tccp_t *tccp = &tcp->tccps[compno]; - opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; - int prevnumbands = 0; - - /* border of each tile component (global) */ - tilec->x0 = int_ceildiv(tile->x0, volume->comps[compno].dx); - tilec->y0 = int_ceildiv(tile->y0, volume->comps[compno].dy); - tilec->z0 = int_ceildiv(tile->z0, volume->comps[compno].dz); - tilec->x1 = int_ceildiv(tile->x1, volume->comps[compno].dx); - tilec->y1 = int_ceildiv(tile->y1, volume->comps[compno].dy); - tilec->z1 = int_ceildiv(tile->z1, volume->comps[compno].dz); - - tilec->data = (int *) opj_malloc((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0) * (tilec->z1 - tilec->z0) * sizeof(int)); - - res_max = 0; - for (i = 0;i < 3; i++){ - tilec->numresolution[i] = tccp->numresolution[i]; - /*Greater of 3 resolutions contains all information*/ - res_max = (tilec->numresolution[i] > res_max) ? tilec->numresolution[i] : res_max; - } - - tilec->resolutions = (opj_tcd_resolution_t *) opj_malloc(res_max * sizeof(opj_tcd_resolution_t)); - - for (resno = 0; resno < res_max; resno++) { - opj_tcd_resolution_t *res = &tilec->resolutions[resno]; - int pdx, pdy, pdz; - int tlprcxstart, tlprcystart, tlprczstart, brprcxend, brprcyend, brprczend; - int tlcbgxstart, tlcbgystart, tlcbgzstart, brcbgxend, brcbgyend, brcbgzend; - int cbgwidthexpn, cbgheightexpn, cbglengthexpn; - int cblkwidthexpn, cblkheightexpn, cblklengthexpn; - int levelnox = tilec->numresolution[0] - 1 - resno; - int levelnoy = tilec->numresolution[1] - 1 - resno; - int diff = tccp->numresolution[0] - tccp->numresolution[2]; - int levelnoz = tilec->numresolution[2] - 1 - ((resno <= diff) ? 0 : (resno - diff)); - if (levelnoz < 0) levelnoz = 0; - - /* border for each resolution level (global) */ - res->x0 = int_ceildivpow2(tilec->x0, levelnox); - res->y0 = int_ceildivpow2(tilec->y0, levelnoy); - res->z0 = int_ceildivpow2(tilec->z0, levelnoz); - res->x1 = int_ceildivpow2(tilec->x1, levelnox); - res->y1 = int_ceildivpow2(tilec->y1, levelnoy); - res->z1 = int_ceildivpow2(tilec->z1, levelnoz); - res->numbands = (resno == 0) ? 1 : (resno <= diff) ? 3 : 7; /* --> 3D */ - - /* p. 30, table A-13, ISO/IEC IS154444-1 : 2002 */ - if (tccp->csty & J3D_CCP_CSTY_PRT) { - pdx = tccp->prctsiz[0][resno]; - pdy = tccp->prctsiz[1][resno]; - pdz = tccp->prctsiz[2][resno]; - } else { - pdx = 15; - pdy = 15; - pdz = 15; - } - - /* p. 66, B.16, ISO/IEC IS15444-1 : 2002 */ - tlprcxstart = int_floordivpow2(res->x0, pdx) << pdx; - tlprcystart = int_floordivpow2(res->y0, pdy) << pdy; - tlprczstart = int_floordivpow2(res->z0, pdz) << pdz; - brprcxend = int_ceildivpow2(res->x1, pdx) << pdx; - brprcyend = int_ceildivpow2(res->y1, pdy) << pdy; - brprczend = int_ceildivpow2(res->z1, pdz) << pdz; - - res->prctno[0] = (brprcxend - tlprcxstart) >> pdx; - res->prctno[1] = (brprcyend - tlprcystart) >> pdy; - res->prctno[2] = (brprczend - tlprczstart) >> pdz; - - /* p. 67, B.17 & B.18, ISO/IEC IS15444-1 : 2002 */ - if (resno == 0) { - tlcbgxstart = tlprcxstart;/*0*/ - tlcbgystart = tlprcystart; - tlcbgzstart = tlprczstart; - brcbgxend = brprcxend;/*1*/ - brcbgyend = brprcyend; - brcbgzend = brprczend; - cbgwidthexpn = pdx; /*15*/ - cbgheightexpn = pdy; - cbglengthexpn = pdz; - } else { - tlcbgxstart = int_ceildivpow2(tlprcxstart, 1); - tlcbgystart = int_ceildivpow2(tlprcystart, 1); - tlcbgzstart = int_ceildivpow2(tlprczstart, 1); - brcbgxend = int_ceildivpow2(brprcxend, 1); - brcbgyend = int_ceildivpow2(brprcyend, 1); - brcbgzend = int_ceildivpow2(brprczend, 1); - cbgwidthexpn = pdx - 1; - cbgheightexpn = pdy - 1; - cbglengthexpn = pdz - 1; - } - - cblkwidthexpn = int_min(tccp->cblk[0], cbgwidthexpn); /*6*/ - cblkheightexpn = int_min(tccp->cblk[1], cbgheightexpn); /*6*/ - cblklengthexpn = int_min(tccp->cblk[2], cbglengthexpn); /*6*/ - - res->bands = (opj_tcd_band_t *) opj_malloc(res->numbands * sizeof(opj_tcd_band_t)); - for (bandno = 0; bandno < res->numbands; bandno++) { - int x0b, y0b, z0b; - int gain, numbps; - opj_stepsize_t *ss = NULL; - - opj_tcd_band_t *band = &res->bands[bandno]; - band->bandno = resno == 0 ? 0 : bandno + 1; - /* Bandno: 0 - LLL 2 - LHL - 1 - HLL 3 - HHL - 4 - LLH 6 - LHH - 5 - HLH 7 - HHH */ - x0b = (band->bandno == 1) || (band->bandno == 3) || (band->bandno == 5 ) || (band->bandno == 7 ) ? 1 : 0; - y0b = (band->bandno == 2) || (band->bandno == 3) || (band->bandno == 6 ) || (band->bandno == 7 ) ? 1 : 0; - z0b = (band->bandno == 4) || (band->bandno == 5) || (band->bandno == 6 ) || (band->bandno == 7 ) ? 1 : 0; - - /* p. 65, B.15, ISO/IEC IS15444-1 : 2002 */ - if (band->bandno == 0) { - /* band border (global) */ - band->x0 = int_ceildivpow2(tilec->x0, levelnox); - band->y0 = int_ceildivpow2(tilec->y0, levelnoy); - band->z0 = int_ceildivpow2(tilec->z0, levelnoz); - band->x1 = int_ceildivpow2(tilec->x1, levelnox); - band->y1 = int_ceildivpow2(tilec->y1, levelnoy); - band->z1 = int_ceildivpow2(tilec->z1, levelnoz); - } else { - band->x0 = int_ceildivpow2(tilec->x0 - (1 << levelnox) * x0b, levelnox + 1); - band->y0 = int_ceildivpow2(tilec->y0 - (1 << levelnoy) * y0b, levelnoy + 1); - band->z0 = int_ceildivpow2(tilec->z0 - (1 << levelnoz) * z0b, (resno <= diff) ? levelnoz : levelnoz + 1); - band->x1 = int_ceildivpow2(tilec->x1 - (1 << levelnox) * x0b, levelnox + 1); - band->y1 = int_ceildivpow2(tilec->y1 - (1 << levelnoy) * y0b, levelnoy + 1); - band->z1 = int_ceildivpow2(tilec->z1 - (1 << levelnoz) * z0b, (resno <= diff) ? levelnoz : levelnoz + 1); - } - - ss = &tccp->stepsizes[(resno == 0) ? 0 : (prevnumbands + bandno + 1)]; - if (bandno == (res->numbands - 1)) - prevnumbands += (resno == 0) ? 0 : res->numbands; - gain = dwt_getgain(band->bandno,tccp->reversible); - numbps = volume->comps[compno].prec + gain; - - band->stepsize = (float)((1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn)); - band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */ - - band->precincts = (opj_tcd_precinct_t *) opj_malloc(res->prctno[0] * res->prctno[1] * res->prctno[2] * sizeof(opj_tcd_precinct_t)); - - for (precno = 0; precno < res->prctno[0] * res->prctno[1] * res->prctno[2]; precno++) { - int tlcblkxstart, tlcblkystart, tlcblkzstart, brcblkxend, brcblkyend, brcblkzend; - - int cbgxstart = tlcbgxstart + (precno % res->prctno[0]) * (1 << cbgwidthexpn); - int cbgystart = tlcbgystart + (precno / res->prctno[0]) * (1 << cbgheightexpn); - int cbgzstart = tlcbgzstart + (precno / (res->prctno[0] * res->prctno[1])) * (1 << cbglengthexpn); - int cbgxend = cbgxstart + (1 << cbgwidthexpn); - int cbgyend = cbgystart + (1 << cbgheightexpn); - int cbgzend = cbgzstart + (1 << cbglengthexpn); - - opj_tcd_precinct_t *prc = &band->precincts[precno]; - /* precinct size (global) */ - prc->x0 = int_max(cbgxstart, band->x0); - prc->y0 = int_max(cbgystart, band->y0); - prc->z0 = int_max(cbgzstart, band->z0); - prc->x1 = int_min(cbgxend, band->x1); - prc->y1 = int_min(cbgyend, band->y1); - prc->z1 = int_min(cbgzend, band->z1); - - tlcblkxstart = int_floordivpow2(prc->x0, cblkwidthexpn) << cblkwidthexpn; - tlcblkystart = int_floordivpow2(prc->y0, cblkheightexpn) << cblkheightexpn; - tlcblkzstart = int_floordivpow2(prc->z0, cblklengthexpn) << cblklengthexpn; - brcblkxend = int_ceildivpow2(prc->x1, cblkwidthexpn) << cblkwidthexpn; - brcblkyend = int_ceildivpow2(prc->y1, cblkheightexpn) << cblkheightexpn; - brcblkzend = int_ceildivpow2(prc->z1, cblklengthexpn) << cblklengthexpn; - prc->cblkno[0] = (brcblkxend - tlcblkxstart) >> cblkwidthexpn; - prc->cblkno[1] = (brcblkyend - tlcblkystart) >> cblkheightexpn; - prc->cblkno[2] = (brcblkzend - tlcblkzstart) >> cblklengthexpn; - prc->cblkno[2] = (prc->cblkno[2] == 0) ? 1 : prc->cblkno[2]; - - prc->cblks = (opj_tcd_cblk_t *) opj_malloc((prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]) * sizeof(opj_tcd_cblk_t)); - prc->incltree = tgt_create(prc->cblkno[0], prc->cblkno[1], prc->cblkno[2]); - prc->imsbtree = tgt_create(prc->cblkno[0], prc->cblkno[1], prc->cblkno[2]); - - for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { - int cblkxstart = tlcblkxstart + (cblkno % prc->cblkno[0]) * (1 << cblkwidthexpn); - int cblkystart = tlcblkystart + ((cblkno % (prc->cblkno[0] * prc->cblkno[1])) / prc->cblkno[0]) * (1 << cblkheightexpn); - int cblkzstart = tlcblkzstart + (cblkno / (prc->cblkno[0] * prc->cblkno[1])) * (1 << cblklengthexpn); - int cblkxend = cblkxstart + (1 << cblkwidthexpn); - int cblkyend = cblkystart + (1 << cblkheightexpn); - int cblkzend = cblkzstart + (1 << cblklengthexpn); - int prec = ((tilec->bpp > 16) ? 3 : ((tilec->bpp > 8) ? 2 : 1)); - /* code-block size (global) */ - opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; - - /* code-block size (global) */ - cblk->x0 = int_max(cblkxstart, prc->x0); - cblk->y0 = int_max(cblkystart, prc->y0); - cblk->z0 = int_max(cblkzstart, prc->z0); - cblk->x1 = int_min(cblkxend, prc->x1); - cblk->y1 = int_min(cblkyend, prc->y1); - cblk->z1 = int_min(cblkzend, prc->z1); - } - } /* precno */ - } /* bandno */ - } /* resno */ - } /* compno */ - } /* i = 0..cp->tileno_size */ - - /*tcd_dump(stdout, tcd, tcd->tcd_volume);*/ - - /* - Allocate place to store the decoded data = final volume - Place limited by the tile really present in the codestream - */ - - for (i = 0; i < volume->numcomps; i++) { - for (j = 0; j < cp->tileno_size; j++) { - tileno = cp->tileno[j]; - x0 = (j == 0) ? tcd->tcd_volume->tiles[tileno].comps[i].x0 : int_min(x0,(unsigned int) tcd->tcd_volume->tiles[tileno].comps[i].x0); - y0 = (j == 0) ? tcd->tcd_volume->tiles[tileno].comps[i].y0 : int_min(y0,(unsigned int) tcd->tcd_volume->tiles[tileno].comps[i].y0); - z0 = (j == 0) ? tcd->tcd_volume->tiles[tileno].comps[i].z0 : int_min(z0,(unsigned int) tcd->tcd_volume->tiles[tileno].comps[i].z0); - x1 = (j == 0) ? tcd->tcd_volume->tiles[tileno].comps[i].x1 : int_max(x1,(unsigned int) tcd->tcd_volume->tiles[tileno].comps[i].x1); - y1 = (j == 0) ? tcd->tcd_volume->tiles[tileno].comps[i].y1 : int_max(y1,(unsigned int) tcd->tcd_volume->tiles[tileno].comps[i].y1); - z1 = (j == 0) ? tcd->tcd_volume->tiles[tileno].comps[i].z1 : int_max(z1,(unsigned int) tcd->tcd_volume->tiles[tileno].comps[i].z1); - } - - w = x1 - x0; - h = y1 - y0; - l = z1 - z0; - - volume->comps[i].data = (int *) opj_malloc(w * h * l * sizeof(int)); - volume->comps[i].w = w; - volume->comps[i].h = h; - volume->comps[i].l = l; - volume->comps[i].x0 = x0; - volume->comps[i].y0 = y0; - volume->comps[i].z0 = z0; - volume->comps[i].bigendian = cp->bigendian; - } -} - -void tcd_free_decode(opj_tcd_t *tcd) { - int tileno,compno,resno,bandno,precno; - - opj_tcd_volume_t *tcd_volume = tcd->tcd_volume; - - for (tileno = 0; tileno < tcd_volume->tw * tcd_volume->th * tcd_volume->tl; tileno++) { - opj_tcd_tile_t *tile = &tcd_volume->tiles[tileno]; - for (compno = 0; compno < tile->numcomps; compno++) { - opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; - for (resno = 0; resno < tilec->numresolution[0]; resno++) { - opj_tcd_resolution_t *res = &tilec->resolutions[resno]; - for (bandno = 0; bandno < res->numbands; bandno++) { - opj_tcd_band_t *band = &res->bands[bandno]; - for (precno = 0; precno < res->prctno[1] * res->prctno[0] * res->prctno[2]; precno++) { - opj_tcd_precinct_t *prec = &band->precincts[precno]; - if (prec->cblks != NULL) opj_free(prec->cblks); - if (prec->imsbtree != NULL) tgt_destroy(prec->imsbtree); - if (prec->incltree != NULL) tgt_destroy(prec->incltree); - /*for (treeno = 0; treeno < prec->numtrees; treeno++){ - if (prec->imsbtree[treeno] != NULL) tgt_destroy(prec->imsbtree[treeno]); - if (prec->incltree[treeno] != NULL) tgt_destroy(prec->incltree[treeno]); - }*/ - } - if (band->precincts != NULL) opj_free(band->precincts); - } - } - if (tilec->resolutions != NULL) opj_free(tilec->resolutions); - } - if (tile->comps != NULL) opj_free(tile->comps); - } - - if (tcd_volume->tiles != NULL) opj_free(tcd_volume->tiles); -} - - - -/* ----------------------------------------------------------------------- */ -void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final) { - int compno, resno, bandno, precno, cblkno; - int value; /*, matrice[tcd_tcp->numlayers][tcd_tile->comps[0].numresolution[0]][3]; */ - int matrice[10][10][3]; - int i, j, k; - - opj_cp_t *cp = tcd->cp; - opj_tcd_tile_t *tcd_tile = tcd->tcd_tile; - opj_tcp_t *tcd_tcp = tcd->tcp; - - /*matrice=(int*)opj_malloc(tcd_tcp->numlayers*tcd_tile->comps[0].numresolution[0]*3*sizeof(int)); */ - - for (compno = 0; compno < tcd_tile->numcomps; compno++) { - opj_tcd_tilecomp_t *tilec = &tcd_tile->comps[compno]; - for (i = 0; i < tcd_tcp->numlayers; i++) { - for (j = 0; j < tilec->numresolution[0]; j++) { - for (k = 0; k < 3; k++) { - matrice[i][j][k] = - (int) (cp->matrice[i * tilec->numresolution[0] * 3 + j * 3 + k] - * (float) (tcd->volume->comps[compno].prec / 16.0)); - } - } - } - - for (resno = 0; resno < tilec->numresolution[0]; resno++) { - opj_tcd_resolution_t *res = &tilec->resolutions[resno]; - for (bandno = 0; bandno < res->numbands; bandno++) { - opj_tcd_band_t *band = &res->bands[bandno]; - for (precno = 0; precno < res->prctno[0] * res->prctno[1] * res->prctno[2]; precno++) { - opj_tcd_precinct_t *prc = &band->precincts[precno]; - for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { - opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; - opj_tcd_layer_t *layer = &cblk->layers[layno]; - int n; - int imsb = tcd->volume->comps[compno].prec - cblk->numbps; /* number of bit-plan equal to zero */ - /* Correction of the matrix of coefficient to include the IMSB information */ - if (layno == 0) { - value = matrice[layno][resno][bandno]; - if (imsb >= value) { - value = 0; - } else { - value -= imsb; - } - } else { - value = matrice[layno][resno][bandno] - matrice[layno - 1][resno][bandno]; - if (imsb >= matrice[layno - 1][resno][bandno]) { - value -= (imsb - matrice[layno - 1][resno][bandno]); - if (value < 0) { - value = 0; - } - } - } - - if (layno == 0) { - cblk->numpassesinlayers = 0; - } - - n = cblk->numpassesinlayers; - if (cblk->numpassesinlayers == 0) { - if (value != 0) { - n = 3 * value - 2 + cblk->numpassesinlayers; - } else { - n = cblk->numpassesinlayers; - } - } else { - n = 3 * value + cblk->numpassesinlayers; - } - - layer->numpasses = n - cblk->numpassesinlayers; - - if (!layer->numpasses) - continue; - - if (cblk->numpassesinlayers == 0) { - layer->len = cblk->passes[n - 1].rate; - layer->data = cblk->data; - } else { - layer->len = cblk->passes[n - 1].rate - cblk->passes[cblk->numpassesinlayers - 1].rate; - layer->data = cblk->data + cblk->passes[cblk->numpassesinlayers - 1].rate; - } - if (final) - cblk->numpassesinlayers = n; - } - } - } - } - } -} - -void tcd_rateallocate_fixed(opj_tcd_t *tcd) { - int layno; - for (layno = 0; layno < tcd->tcp->numlayers; layno++) { - tcd_makelayer_fixed(tcd, layno, 1); - } -} - -void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final) { - int compno, resno, bandno, precno, cblkno, passno; - - opj_tcd_tile_t *tcd_tile = tcd->tcd_tile; - - tcd_tile->distolayer[layno] = 0; /* fixed_quality */ - - for (compno = 0; compno < tcd_tile->numcomps; compno++) { - opj_tcd_tilecomp_t *tilec = &tcd_tile->comps[compno]; - for (resno = 0; resno < tilec->numresolution[0]; resno++) { - opj_tcd_resolution_t *res = &tilec->resolutions[resno]; - for (bandno = 0; bandno < res->numbands; bandno++) { - opj_tcd_band_t *band = &res->bands[bandno]; - for (precno = 0; precno < res->prctno[0] * res->prctno[1] * res->prctno[2]; precno++) { - opj_tcd_precinct_t *prc = &band->precincts[precno]; - for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { - opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; - opj_tcd_layer_t *layer = &cblk->layers[layno]; - - int n; - if (layno == 0) { - cblk->numpassesinlayers = 0; - } - n = cblk->numpassesinlayers; - for (passno = cblk->numpassesinlayers; passno < cblk->totalpasses; passno++) { - int dr; - double dd; - opj_tcd_pass_t *pass = &cblk->passes[passno]; - if (n == 0) { - dr = pass->rate; - dd = pass->distortiondec; - } else { - dr = pass->rate - cblk->passes[n - 1].rate; - dd = pass->distortiondec - cblk->passes[n - 1].distortiondec; - } - if (!dr) { - if (dd) - n = passno + 1; - continue; - } - if (dd / dr >= thresh){ - n = passno + 1; - } - } - layer->numpasses = n - cblk->numpassesinlayers; - - if (!layer->numpasses) { - layer->disto = 0; - continue; - } - if (cblk->numpassesinlayers == 0) { - layer->len = cblk->passes[n - 1].rate; - layer->data = cblk->data; - layer->disto = cblk->passes[n - 1].distortiondec; - } else { - layer->len = cblk->passes[n - 1].rate - cblk->passes[cblk->numpassesinlayers - 1].rate; - layer->data = cblk->data + cblk->passes[cblk->numpassesinlayers - 1].rate; - layer->disto = cblk->passes[n - 1].distortiondec - cblk->passes[cblk->numpassesinlayers - 1].distortiondec; - } - - tcd_tile->distolayer[layno] += layer->disto; /* fixed_quality */ - - if (final) - cblk->numpassesinlayers = n; - - /* fprintf(stdout,"MakeLayer : %d %f %d %d \n",layer->len, layer->disto, layer->numpasses, n);*/ - } - } - } - } - } -} - -bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_volume_info_t * volume_info) { - int compno, resno, bandno, precno, cblkno, passno, layno; - double min, max; - double cumdisto[100]; /* fixed_quality */ - const double K = 1; /* 1.1; // fixed_quality */ - double maxSE = 0; - - opj_cp_t *cp = tcd->cp; - opj_tcd_tile_t *tcd_tile = tcd->tcd_tile; - opj_tcp_t *tcd_tcp = tcd->tcp; - - min = DBL_MAX; - max = 0; - - tcd_tile->nbpix = 0; /* fixed_quality */ - - for (compno = 0; compno < tcd_tile->numcomps; compno++) { - opj_tcd_tilecomp_t *tilec = &tcd_tile->comps[compno]; - tilec->nbpix = 0; - for (resno = 0; resno < tilec->numresolution[0]; resno++) { - opj_tcd_resolution_t *res = &tilec->resolutions[resno]; - for (bandno = 0; bandno < res->numbands; bandno++) { - opj_tcd_band_t *band = &res->bands[bandno]; - for (precno = 0; precno < res->prctno[0] * res->prctno[1] * res->prctno[2]; precno++) { - opj_tcd_precinct_t *prc = &band->precincts[precno]; - for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { - opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; - for (passno = 0; passno < cblk->totalpasses; passno++) { - opj_tcd_pass_t *pass = &cblk->passes[passno]; - int dr; - double dd, rdslope; - if (passno == 0) { - dr = pass->rate; - dd = pass->distortiondec; - } else { - dr = pass->rate - cblk->passes[passno - 1].rate; - dd = pass->distortiondec - cblk->passes[passno - 1].distortiondec; - } - if (dr == 0) { - continue; - } - rdslope = dd / dr; - if (rdslope < min) { - min = rdslope; - } - if (rdslope > max) { - max = rdslope; - } - - } /* passno */ - - /* fixed_quality */ - tcd_tile->nbpix += ((cblk->x1 - cblk->x0) * (cblk->y1 - cblk->y0) * (cblk->z1 - cblk->z0)); - tilec->nbpix += ((cblk->x1 - cblk->x0) * (cblk->y1 - cblk->y0) * (cblk->z1 - cblk->z0)); - } /* cbklno */ - } /* precno */ - } /* bandno */ - } /* resno */ - - maxSE += (((double)(1 << tcd->volume->comps[compno].prec) - 1.0) - * ((double)(1 << tcd->volume->comps[compno].prec) -1.0)) - * ((double)(tilec->nbpix)); - } /* compno */ - - /* add antonin index */ - if(volume_info && volume_info->index_on) { - opj_tile_info_t *info_TL = &volume_info->tile[tcd->tcd_tileno]; - info_TL->nbpix = tcd_tile->nbpix; - info_TL->distotile = tcd_tile->distotile; - info_TL->thresh = (double *) opj_malloc(tcd_tcp->numlayers * sizeof(double)); - } - /* dda */ - - for (layno = 0; layno < tcd_tcp->numlayers; layno++) { - double lo = min; - double hi = max; - int success = 0; - int maxlen = tcd_tcp->rates[layno] ? int_min(((int) tcd_tcp->rates[layno]), len) : len; - double goodthresh; - double distotarget; /* fixed_quality */ - int i = 0; - - /* fixed_quality */ - distotarget = tcd_tile->distotile - ((K * maxSE) / pow((float)10, tcd_tcp->distoratio[layno] / 10)); - - if ((tcd_tcp->rates[layno]) || (cp->disto_alloc==0)) { - opj_t2_t *t2 = t2_create(tcd->cinfo, tcd->volume, cp); - int oldl = 0, oldoldl = 0; - for (i = 0; i < 128; i++) { - double thresh = (lo + hi) / 2; - int l = 0; - double distoachieved = 0; /* fixed_quality -q */ - - tcd_makelayer(tcd, layno, thresh, 0); - - if (cp->fixed_quality) { /* fixed_quality -q */ - distoachieved = (layno == 0) ? tcd_tile->distolayer[0] : cumdisto[layno - 1] + tcd_tile->distolayer[layno]; - if (distoachieved < distotarget) { - hi = thresh; - continue; - } - lo = thresh; - } else { /* disto_alloc -r, fixed_alloc -f */ - l = t2_encode_packets(t2, tcd->tcd_tileno, tcd_tile, layno + 1, dest, maxlen, volume_info); - /*fprintf(stdout, "layno %d i %d len=%d max=%d \n",layno,i,l,maxlen);*/ - if (l == -999) { - lo = thresh; - continue; - } else if (l == oldl && oldl == oldoldl && tcd_tile->distolayer[layno] > 0.0 && i>32) - break; - hi = thresh; - oldoldl = oldl; - oldl = l; - } - success = 1; - goodthresh = thresh; - } - t2_destroy(t2); - } else { - success = 1; - goodthresh = min; - } - if (!success) { - return false; - } - - if(volume_info && volume_info->index_on) { /* Threshold for Marcela Index */ - volume_info->tile[tcd->tcd_tileno].thresh[layno] = goodthresh; - } - tcd_makelayer(tcd, layno, goodthresh, 1); - - /* fixed_quality */ - cumdisto[layno] = (layno == 0) ? tcd_tile->distolayer[0] : cumdisto[layno - 1] + tcd_tile->distolayer[layno]; - } - - return true; -} - -/* ----------------------------------------------------------------------- */ -int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_volume_info_t * volume_info) { - int compno; - int l, i, npck = 0; - double encoding_time; - - opj_tcd_tile_t *tile = NULL; - opj_tcp_t *tcd_tcp = NULL; - opj_cp_t *cp = NULL; - - opj_tcp_t *tcp = &tcd->cp->tcps[0]; - opj_tccp_t *tccp = &tcp->tccps[0]; - opj_volume_t *volume = tcd->volume; - opj_t2_t *t2 = NULL; /* T2 component */ - - tcd->tcd_tileno = tileno; /* current encoded/decoded tile */ - - tcd->tcd_tile = tcd->tcd_volume->tiles; /* tile information */ - tile = tcd->tcd_tile; - - tcd->tcp = &tcd->cp->tcps[tileno]; /* coding/decoding params of tileno */ - tcd_tcp = tcd->tcp; - - cp = tcd->cp; /* coding parameters */ - - /* INDEX >> */ - if(volume_info && volume_info->index_on) { - opj_tcd_tilecomp_t *tilec_idx = &tile->comps[0]; /* based on component 0 */ - for (i = 0; i < tilec_idx->numresolution[0]; i++) { - opj_tcd_resolution_t *res_idx = &tilec_idx->resolutions[i]; - - volume_info->tile[tileno].prctno[0][i] = res_idx->prctno[0]; - volume_info->tile[tileno].prctno[1][i] = res_idx->prctno[1]; - volume_info->tile[tileno].prctno[2][i] = res_idx->prctno[2]; - - npck += res_idx->prctno[0] * res_idx->prctno[1] * res_idx->prctno[2]; - - volume_info->tile[tileno].prctsiz[0][i] = tccp->prctsiz[0][i]; - volume_info->tile[tileno].prctsiz[1][i] = tccp->prctsiz[1][i]; - volume_info->tile[tileno].prctsiz[2][i] = tccp->prctsiz[2][i]; - } - volume_info->tile[tileno].packet = (opj_packet_info_t *) opj_malloc(volume_info->comp * volume_info->layer * npck * sizeof(opj_packet_info_t)); - } - /* << INDEX */ - - /*---------------TILE-------------------*/ - encoding_time = opj_clock(); /* time needed to encode a tile */ - - for (compno = 0; compno < tile->numcomps; compno++) { - int x, y, z; - opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; - - int adjust; - int offset_x = int_ceildiv(volume->x0, volume->comps[compno].dx); /*ceil(x0 / subsampling_dx)*/ - int offset_y = int_ceildiv(volume->y0, volume->comps[compno].dy); - int offset_z = int_ceildiv(volume->z0, volume->comps[compno].dz); - - int tw = tilec->x1 - tilec->x0; - int w = int_ceildiv(volume->x1 - volume->x0, volume->comps[compno].dx); - int th = tilec->y1 - tilec->y0; - int h = int_ceildiv(volume->y1 - volume->y0, volume->comps[compno].dy); - int tl = tilec->z1 - tilec->z0; - int l = int_ceildiv(volume->z1 - volume->z0, volume->comps[compno].dz); - - - - /* extract tile data from volume.comps[0].data to tile.comps[0].data */ - /*fprintf(stdout,"[INFO] Extract tile data\n");*/ - if (tcd->cp->transform_format == TRF_3D_RLS || tcd->cp->transform_format == TRF_3D_LSE) { - adjust = 0; - } else { - adjust = volume->comps[compno].sgnd ? 0 : 1 << (volume->comps[compno].prec - 1); /*sign=='+' --> 2^(prec-1)*/ - if (volume->comps[compno].dcoffset != 0){ - adjust += volume->comps[compno].dcoffset; - fprintf(stdout,"[INFO] DC Offset applied: DCO = %d -> adjust = %d\n",volume->comps[compno].dcoffset,adjust); - } - } - - if (tcd_tcp->tccps[compno].reversible == 1) { /*IF perfect reconstruction (DWT.5-3)*/ - for (z = tilec->z0; z < tilec->z1; z++) { - for (y = tilec->y0; y < tilec->y1; y++) { - /* start of the src tile scanline */ - int *data = &volume->comps[compno].data[(tilec->x0 - offset_x) + (y - offset_y) * w + (z - offset_z) * w * h]; - /* start of the dst tile scanline */ - int *tile_data = &tilec->data[(y - tilec->y0) * tw + (z - tilec->z0) * tw * th]; - for (x = tilec->x0; x < tilec->x1; x++) { - *tile_data++ = *data++ - adjust; - } - } - } - } else if (tcd_tcp->tccps[compno].reversible == 0) { /*IF not (DWT.9-7)*/ - for (z = tilec->z0; z < tilec->z1; z++) { - for (y = tilec->y0; y < tilec->y1; y++) { - /* start of the src tile scanline */ - int *data = &volume->comps[compno].data[(tilec->x0 - offset_x) + (y - offset_y) * w + (z - offset_z) * w * h]; - /* start of the dst tile scanline */ - int *tile_data = &tilec->data[(y - tilec->y0) * tw + (z - tilec->z0) * tw * th]; - for (x = tilec->x0; x < tilec->x1; x++) { - *tile_data++ = (*data++ - adjust) << 13; - } - } - } - } - - } - - /*----------------MCT-------------------*/ - if (tcd_tcp->mct) { - int samples = (tile->comps[0].x1 - tile->comps[0].x0) * (tile->comps[0].y1 - tile->comps[0].y0) * (tile->comps[0].z1 - tile->comps[0].z0); - fprintf(stdout,"[INFO] Tcd_encode_tile: mct\n"); - if (tcd_tcp->tccps[0].reversible == 0) { - mct_encode_real(tile->comps[0].data, tile->comps[1].data, tile->comps[2].data, samples); - } else { - mct_encode(tile->comps[0].data, tile->comps[1].data, tile->comps[2].data, samples); - } - } - /*----------------TRANSFORM---------------------------------*/ - fprintf(stdout,"[INFO] Tcd_encode_tile: Transform\n"); - for (compno = 0; compno < tile->numcomps; compno++) { - opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; - dwt_encode(tilec, tcd_tcp->tccps[compno].dwtid); - } - - /*-------------------ENTROPY CODING-----------------------------*/ - fprintf(stdout,"[INFO] Tcd_encode_tile: Entropy coding\n"); - if ((cp->encoding_format == ENCOD_2EB)||(cp->encoding_format == ENCOD_3EB)) - { - if (cp->encoding_format == ENCOD_2EB) { - opj_t1_t *t1 = NULL; - t1 = t1_create(tcd->cinfo); - t1_encode_cblks(t1, tile, tcd_tcp); - t1_destroy(t1); - } else if (cp->encoding_format == ENCOD_3EB) { - opj_t1_3d_t *t1 = NULL; - t1 = t1_3d_create(tcd->cinfo); - t1_3d_encode_cblks(t1, tile, tcd_tcp); - t1_3d_destroy(t1); - } - /*-----------RATE-ALLOCATE------------------*/ - /* INDEX */ - if(volume_info) { - volume_info->index_write = 0; - } - if (cp->disto_alloc || cp->fixed_quality) { - fprintf(stdout,"[INFO] Tcd_encode_tile: Rate-allocate\n"); - tcd_rateallocate(tcd, dest, len, volume_info); /* Normal Rate/distortion allocation */ - } else {/* fixed_alloc */ - fprintf(stdout,"[INFO] Tcd_encode_tile: Rate-allocate fixed\n"); - tcd_rateallocate_fixed(tcd); /* Fixed layer allocation */ - } - - /*--------------TIER2------------------*/ - /* INDEX */ - if(volume_info) { - volume_info->index_write = 1; - } - fprintf(stdout,"[INFO] Tcd_encode_tile: Tier - 2\n"); - t2 = t2_create(tcd->cinfo, volume, cp); - l = t2_encode_packets(t2, tileno, tile, tcd_tcp->numlayers, dest, len, volume_info); - t2_destroy(t2); - } else if ((cp->encoding_format == ENCOD_2GR)||(cp->encoding_format == ENCOD_3GR)) { - /*if(volume_info) { - volume_info->index_write = 1; - } - gr = golomb_create(tcd->cinfo, volume, cp); - l = golomb_encode(gr, tileno, tile, dest, len, volume_info); - golomb_destroy(gr);*/ - } - - - /*---------------CLEAN-------------------*/ - fprintf(stdout,"[INFO] Tcd_encode_tile: %d bytes coded\n",l); - encoding_time = opj_clock() - encoding_time; - opj_event_msg(tcd->cinfo, EVT_INFO, "- tile encoded in %f s\n", encoding_time); - - /* cleaning memory */ - for (compno = 0; compno < tile->numcomps; compno++) { - tcd->tilec = &tile->comps[compno]; - opj_free(tcd->tilec->data); - } - - if (l == -999){ - fprintf(stdout,"[ERROR] Unable to perform T2 tier. Return -999.\n"); - return 0; - } - - return l; -} - - -bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno) { - int l, i; - int compno, eof = 0; - double tile_time, t1_time, dwt_time; - - opj_tcd_tile_t *tile = NULL; - opj_t2_t *t2 = NULL; /* T2 component */ - - tcd->tcd_tileno = tileno; - tcd->tcd_tile = &(tcd->tcd_volume->tiles[tileno]); - tcd->tcp = &(tcd->cp->tcps[tileno]); - tile = tcd->tcd_tile; - - tile_time = opj_clock(); /* time needed to decode a tile */ - opj_event_msg(tcd->cinfo, EVT_INFO, "tile %d / %d\n", tileno + 1, tcd->cp->tw * tcd->cp->th * tcd->cp->tl); - - if ((tcd->cp->encoding_format == ENCOD_2EB) || (tcd->cp->encoding_format == ENCOD_3EB)) { - /*--------------TIER2------------------*/ - t2 = t2_create(tcd->cinfo, tcd->volume, tcd->cp); - l = t2_decode_packets(t2, src, len, tileno, tile); - t2_destroy(t2); - opj_event_msg(tcd->cinfo, EVT_INFO, "Tcd_decode_tile: %d bytes decoded\n",l); - - if (l == -999) { - eof = 1; - opj_event_msg(tcd->cinfo, EVT_ERROR, "Tcd_decode_tile: incomplete bistream\n"); - } - - /*------------------TIER1-----------------*/ - opj_event_msg(tcd->cinfo, EVT_INFO, "Tcd_decode_tile: Entropy decoding %d \n",tcd->cp->encoding_format); - t1_time = opj_clock(); /* time needed to decode a tile */ - if (tcd->cp->encoding_format == ENCOD_2EB) { - opj_t1_t *t1 = NULL; /* T1 component */ - t1 = t1_create(tcd->cinfo); - t1_decode_cblks(t1, tile, tcd->tcp); - t1_destroy(t1); - }else if (tcd->cp->encoding_format == ENCOD_3EB) { - opj_t1_3d_t *t1 = NULL; /* T1 component */ - t1 = t1_3d_create(tcd->cinfo); - t1_3d_decode_cblks(t1, tile, tcd->tcp); - t1_3d_destroy(t1); - } - - t1_time = opj_clock() - t1_time; - #ifdef VERBOSE - opj_event_msg(tcd->cinfo, EVT_INFO, "- tier-1 took %f s\n", t1_time); - #endif - } else if ((tcd->cp->encoding_format == ENCOD_2GR)||(tcd->cp->encoding_format == ENCOD_3GR)) { - opj_event_msg(tcd->cinfo, EVT_INFO, "Tcd_decode_tile: Entropy decoding -- Does nothing :-D\n"); - /* - gr = golomb_create(tcd->cinfo, tcd->volume, tcd->cp); - l = golomb_decode(gr, tileno, tile, src, len); - golomb_destroy(gr); - if (l == -999) { - eof = 1; - opj_event_msg(tcd->cinfo, EVT_ERROR, "Tcd_decode_tile: incomplete bistream\n"); - } - */ - } - - /*----------------DWT---------------------*/ - fprintf(stdout,"[INFO] Tcd_decode_tile: Inverse DWT\n"); - dwt_time = opj_clock(); /* time needed to decode a tile */ - for (compno = 0; compno < tile->numcomps; compno++) { - opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; - int stops[3], dwtid[3]; - - for (i = 0; i < 3; i++) { - if (tcd->cp->reduce[i] != 0) - tcd->volume->comps[compno].resno_decoded[i] = tile->comps[compno].numresolution[i] - tcd->cp->reduce[i] - 1; - stops[i] = tilec->numresolution[i] - 1 - tcd->volume->comps[compno].resno_decoded[i]; - if (stops[i] < 0) stops[i]=0; - dwtid[i] = tcd->cp->tcps->tccps[compno].dwtid[i]; - } - - dwt_decode(tilec, stops, dwtid); - - for (i = 0; i < 3; i++) { - if (tile->comps[compno].numresolution[i] > 0) { - tcd->volume->comps[compno].factor[i] = tile->comps[compno].numresolution[i] - (tcd->volume->comps[compno].resno_decoded[i] + 1); - if ( (tcd->volume->comps[compno].factor[i]) < 0 ) - tcd->volume->comps[compno].factor[i] = 0; - } - } - } - dwt_time = opj_clock() - dwt_time; - #ifdef VERBOSE - opj_event_msg(tcd->cinfo, EVT_INFO, "- dwt took %f s\n", dwt_time); - #endif - - /*----------------MCT-------------------*/ - - if (tcd->tcp->mct) { - if (tcd->tcp->tccps[0].reversible == 1) { - mct_decode(tile->comps[0].data, tile->comps[1].data, tile->comps[2].data, - (tile->comps[0].x1 - tile->comps[0].x0) * (tile->comps[0].y1 - tile->comps[0].y0) * (tile->comps[0].z1 - tile->comps[0].z0)); - } else { - mct_decode_real(tile->comps[0].data, tile->comps[1].data, tile->comps[2].data, - (tile->comps[0].x1 - tile->comps[0].x0) * (tile->comps[0].y1 - tile->comps[0].y0)* (tile->comps[0].z1 - tile->comps[0].z0)); - } - } - - /*---------------TILE-------------------*/ - - for (compno = 0; compno < tile->numcomps; compno++) { - opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; - opj_tcd_resolution_t *res = &tilec->resolutions[tcd->volume->comps[compno].resno_decoded[0]]; - int adjust; - int minval = tcd->volume->comps[compno].sgnd ? -(1 << (tcd->volume->comps[compno].prec - 1)) : 0; - int maxval = tcd->volume->comps[compno].sgnd ? (1 << (tcd->volume->comps[compno].prec - 1)) - 1 : (1 << tcd->volume->comps[compno].prec) - 1; - - int tw = tilec->x1 - tilec->x0; - int w = tcd->volume->comps[compno].w; - int th = tilec->y1 - tilec->y0; - int h = tcd->volume->comps[compno].h; - - int i, j, k; - int offset_x = int_ceildivpow2(tcd->volume->comps[compno].x0, tcd->volume->comps[compno].factor[0]); - int offset_y = int_ceildivpow2(tcd->volume->comps[compno].y0, tcd->volume->comps[compno].factor[1]); - int offset_z = int_ceildivpow2(tcd->volume->comps[compno].z0, tcd->volume->comps[compno].factor[2]); - - if (tcd->cp->transform_format == TRF_3D_RLS || tcd->cp->transform_format == TRF_3D_LSE) { - adjust = 0; - } else { - adjust = tcd->volume->comps[compno].sgnd ? 0 : 1 << (tcd->volume->comps[compno].prec - 1); /*sign=='+' --> 2^(prec-1)*/ - if (tcd->volume->comps[compno].dcoffset != 0){ - adjust += tcd->volume->comps[compno].dcoffset; - fprintf(stdout,"[INFO] DC Offset applied: DCO = %d -> adjust = %d\n",tcd->volume->comps[compno].dcoffset,adjust); - } - } - - for (k = res->z0; k < res->z1; k++) { - for (j = res->y0; j < res->y1; j++) { - for (i = res->x0; i < res->x1; i++) { - int v; - float tmp = (float)((tilec->data[i - res->x0 + (j - res->y0) * tw + (k - res->z0) * tw * th]) / 8192.0); - - if (tcd->tcp->tccps[compno].reversible == 1) { - v = tilec->data[i - res->x0 + (j - res->y0) * tw + (k - res->z0) * tw * th]; - } else { - int tmp2 = ((int) (floor(fabs(tmp)))) + ((int) floor(fabs(tmp*2))%2); - v = ((tmp < 0) ? -tmp2:tmp2); - } - v += adjust; - - tcd->volume->comps[compno].data[(i - offset_x) + (j - offset_y) * w + (k - offset_z) * w * h] = int_clamp(v, minval, maxval); - } - } - } - } - - tile_time = opj_clock() - tile_time; /* time needed to decode a tile */ - opj_event_msg(tcd->cinfo, EVT_INFO, "- tile decoded in %f s\n", tile_time); - - for (compno = 0; compno < tile->numcomps; compno++) { - opj_free(tcd->tcd_volume->tiles[tileno].comps[compno].data); - tcd->tcd_volume->tiles[tileno].comps[compno].data = NULL; - } - - if (eof) { - return false; - } - - return true; -} - +/* + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * Copyright (c) 2006, Mónica Díez, LPI-UVA, Spain + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opj_includes.h" + +void tcd_dump(FILE *fd, opj_tcd_t *tcd, opj_tcd_volume_t * vol) { + int tileno, compno, resno, bandno, precno, cblkno; + + fprintf(fd, "volume {\n"); + fprintf(fd, " tw=%d, th=%d, tl=%d, x0=%d x1=%d y0=%d y1=%d z0=%d z1=%d\n", + vol->tw, vol->th, vol->tl, tcd->volume->x0, tcd->volume->x1, tcd->volume->y0, tcd->volume->y1, tcd->volume->z0, tcd->volume->z1); + + for (tileno = 0; tileno < vol->th * vol->tw * vol->tl; tileno++) { + opj_tcd_tile_t *tile = &tcd->tcd_volume->tiles[tileno]; + fprintf(fd, " tile {\n"); + fprintf(fd, " x0=%d, y0=%d, z0=%d, x1=%d, y1=%d, z1=%d, numcomps=%d\n", + tile->x0, tile->y0, tile->z0, tile->x1, tile->y1, tile->z1, tile->numcomps); + for (compno = 0; compno < tile->numcomps; compno++) { + opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; + fprintf(fd, " tilecomp %d {\n",compno); + fprintf(fd, " x0=%d, y0=%d, z0=%d, x1=%d, y1=%d, z1=%d, numresx=%d, numresy=%d, numresz=%d\n", + tilec->x0, tilec->y0, tilec->z0, tilec->x1, tilec->y1, tilec->z1, tilec->numresolution[0], tilec->numresolution[1], tilec->numresolution[2]); + for (resno = 0; resno < tilec->numresolution[0]; resno++) { + opj_tcd_resolution_t *res = &tilec->resolutions[resno]; + fprintf(fd, " res %d{\n",resno); + fprintf(fd," x0=%d, y0=%d, z0=%d, x1=%d, y1=%d, z1=%d, pw=%d, ph=%d, pl=%d, numbands=%d\n", + res->x0, res->y0, res->z0, res->x1, res->y1, res->z1, res->prctno[0], res->prctno[1], res->prctno[2], res->numbands); + for (bandno = 0; bandno < res->numbands; bandno++) { + opj_tcd_band_t *band = &res->bands[bandno]; + fprintf(fd, " band %d{\n", bandno); + fprintf(fd, " x0=%d, y0=%d, z0=%d, x1=%d, y1=%d, z1=%d, stepsize=%f, numbps=%d\n", + band->x0, band->y0, band->z0, band->x1, band->y1, band->z1, band->stepsize, band->numbps); + for (precno = 0; precno < (res->prctno[0] * res->prctno[1] * res->prctno[2]); precno++) { + opj_tcd_precinct_t *prec = &band->precincts[precno]; + fprintf(fd, " prec %d{\n",precno); + fprintf(fd, " x0=%d, y0=%d, z0=%d, x1=%d, y1=%d, z1=%d, cw=%d, ch=%d, cl=%d,\n", + prec->x0, prec->y0, prec->z0, prec->x1, prec->y1, prec->z1, prec->cblkno[0], prec->cblkno[1], prec->cblkno[2]); + for (cblkno = 0; cblkno < (prec->cblkno[0] * prec->cblkno[1] * prec->cblkno[2]); cblkno++) { + opj_tcd_cblk_t *cblk = &prec->cblks[cblkno]; + fprintf(fd, " cblk %d{\n",cblkno); + fprintf(fd, " x0=%d, y0=%d, z0=%d, x1=%d, y1=%d, z1=%d\n", cblk->x0, cblk->y0, cblk->z0, cblk->x1, cblk->y1, cblk->z1); + fprintf(fd, " }\n"); + } + fprintf(fd, " }\n"); + } + fprintf(fd, " }\n"); + } + fprintf(fd, " }\n"); + } + fprintf(fd, " }\n"); + } + fprintf(fd, " }\n"); + } + fprintf(fd, "}\n"); +} + +static void tilec_dump(FILE *fd, opj_tcd_tilecomp_t *tilec) { + + int i=0,k; + int datalen; + int *a; + + fprintf(fd, " tilecomp{\n"); + fprintf(fd, " x0=%d, y0=%d, z0=%d, x1=%d, y1=%d, z1=%d, numresx=%d, numresy=%d, numresz=%d\n", + tilec->x0, tilec->y0, tilec->z0, tilec->x1, tilec->y1, tilec->z1, tilec->numresolution[0], tilec->numresolution[1], tilec->numresolution[2]); + fprintf(fd, " data {\n"); + datalen = (tilec->z1 - tilec->z0) * (tilec->y1 - tilec->y0) * (tilec->x1 - tilec->x0); + a = tilec->data; + for (k = 0; k < datalen; k++) { + if (!(k % tilec->x1)){ + fprintf(fd, "\n"); + } + if (!(k % (tilec->y1 * tilec->x1))){ + fprintf(fd, "Slice %d\n",i++); + } + fprintf(fd," %d",a[k]); + + + } + fprintf(fd, " }\n"); + /*i=0; + fprintf(fd, "Slice %d\n"); + if (tilec->prediction->prederr) { + fprintf(fd, " prederror {\n"); + a = tilec->prediction->prederr; + for (k = 0; k < datalen; k++) { + fprintf(fd," %d",*(a++)); + if (!(k % (tilec->y1 - tilec->y0) * (tilec->x1 - tilec->x0))){ + fprintf(fd, "\n");fprintf(fd, "Slice %d\n",i++); + } + if (!(k % (tilec->x1 - tilec->x0))){ + fprintf(fd, "\n"); + } + } + } + fprintf(fd, " }\n");*/ + fprintf(fd, "}\n"); +} + +/* ----------------------------------------------------------------------- */ + +/** +Create a new TCD handle +*/ +opj_tcd_t* tcd_create(opj_common_ptr cinfo) { + /* create the tcd structure */ + opj_tcd_t *tcd = (opj_tcd_t*)opj_malloc(sizeof(opj_tcd_t)); + if(!tcd) return NULL; + tcd->cinfo = cinfo; + tcd->tcd_volume = (opj_tcd_volume_t*)opj_malloc(sizeof(opj_tcd_volume_t)); + if(!tcd->tcd_volume) { + opj_free(tcd); + return NULL; + } + + return tcd; +} + +/** +Destroy a previously created TCD handle +*/ +void tcd_destroy(opj_tcd_t *tcd) { + if(tcd) { + opj_free(tcd->tcd_volume); + opj_free(tcd); + } +} + +/* ----------------------------------------------------------------------- */ +void tcd_malloc_encode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp, int curtileno) { + int compno, resno, bandno, precno, cblkno, i, j;/*, k;*/ + + opj_tcd_tile_t *tile = NULL; /* pointer to tcd->tile */ + opj_tcd_tilecomp_t *tilec = NULL; /* pointer to tcd->tilec */ + opj_tcd_resolution_t *res = NULL; /* pointer to tcd->res */ + opj_tcd_band_t *band = NULL; /* pointer to tcd->band */ + opj_tcd_precinct_t *prc = NULL; /* pointer to tcd->prc */ + opj_tcd_cblk_t *cblk = NULL; /* pointer to tcd->cblk */ + opj_tcp_t *tcp = &cp->tcps[curtileno]; + int p,q,r; + + tcd->volume = volume; + tcd->cp = cp; + tcd->tcd_volume->tw = cp->tw; + tcd->tcd_volume->th = cp->th; + tcd->tcd_volume->tl = cp->tl; + tcd->tcd_volume->tiles = (opj_tcd_tile_t *) opj_malloc(sizeof(opj_tcd_tile_t)); + tcd->tile = tcd->tcd_volume->tiles; + tile = tcd->tile; + + + /* p61 ISO/IEC IS15444-1 : 2002 */ + /* curtileno --> raster scanned index of tiles */ + /* p,q,r --> matricial index of tiles */ + p = curtileno % cp->tw; + q = curtileno / cp->tw; + r = curtileno / (cp->tw * cp->th); /* extension to 3-D */ + + /* 4 borders of the tile rescale on the volume if necessary (B.3)*/ + tile->x0 = int_max(cp->tx0 + p * cp->tdx, volume->x0); + tile->y0 = int_max(cp->ty0 + q * cp->tdy, volume->y0); + tile->z0 = int_max(cp->tz0 + r * cp->tdz, volume->z0); + tile->x1 = int_min(cp->tx0 + (p + 1) * cp->tdx, volume->x1); + tile->y1 = int_min(cp->ty0 + (q + 1) * cp->tdy, volume->y1); + tile->z1 = int_min(cp->tz0 + (r + 1) * cp->tdz, volume->z1); + tile->numcomps = volume->numcomps; + + /* Modification of the RATE >> */ + for (j = 0; j < tcp->numlayers; j++) { + if (tcp->rates[j] <= 1) { + tcp->rates[j] = 0; + } else { + float num = (float) (tile->numcomps * (tile->x1 - tile->x0) * (tile->y1 - tile->y0) * (tile->z1 - tile->z0) * volume->comps[0].prec); + float den = (float) (8 * volume->comps[0].dx * volume->comps[0].dy * volume->comps[0].dz); + den = tcp->rates[j] * den; + tcp->rates[j] = (num + den - 1) / den; + } + /*tcp->rates[j] = tcp->rates[j] ? int_ceildiv( + tile->numcomps * (tile->x1 - tile->x0) * (tile->y1 - tile->y0) * (tile->z1 - tile->z0) * volume->comps[0].prec, + (tcp->rates[j] * 8 * volume->comps[0].dx * volume->comps[0].dy * volume->comps[0].dz)) : 0;*/ + if (tcp->rates[j]) { + if (j && tcp->rates[j] < tcp->rates[j - 1] + 10) { + tcp->rates[j] = tcp->rates[j - 1] + 20; + } else if (!j && tcp->rates[j] < 30){ + tcp->rates[j] = 30; + } + } + } + /* << Modification of the RATE */ + + tile->comps = (opj_tcd_tilecomp_t *) opj_malloc(volume->numcomps * sizeof(opj_tcd_tilecomp_t)); + for (compno = 0; compno < tile->numcomps; compno++) { + opj_tccp_t *tccp = &tcp->tccps[compno]; + int res_max; + int prevnumbands = 0; + + /* opj_tcd_tilecomp_t *tilec=&tile->comps[compno]; */ + tcd->tilec = &tile->comps[compno]; + tilec = tcd->tilec; + + /* border of each tile component (global) (B.3) */ + tilec->x0 = int_ceildiv(tile->x0, volume->comps[compno].dx); + tilec->y0 = int_ceildiv(tile->y0, volume->comps[compno].dy); + tilec->z0 = int_ceildiv(tile->z0, volume->comps[compno].dz); + tilec->x1 = int_ceildiv(tile->x1, volume->comps[compno].dx); + tilec->y1 = int_ceildiv(tile->y1, volume->comps[compno].dy); + tilec->z1 = int_ceildiv(tile->z1, volume->comps[compno].dz); + + tilec->data = (int *) opj_malloc((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0) * (tilec->z1 - tilec->z0) * sizeof(int)); + + res_max = 0; + for (i = 0;i < 3; i++){ + tilec->numresolution[i] = tccp->numresolution[i]; + /*Greater of 3 resolutions contains all information*/ + res_max = (tilec->numresolution[i] > res_max) ? tilec->numresolution[i] : res_max; + } + + + tilec->resolutions = (opj_tcd_resolution_t *) opj_malloc(res_max * sizeof(opj_tcd_resolution_t)); + for (resno = 0; resno < res_max; resno++) { + + int pdx, pdy, pdz; + int tlprcxstart, tlprcystart, tlprczstart; + int brprcxend, brprcyend, brprczend; + int tlcbgxstart, tlcbgystart, tlcbgzstart; + int brcbgxend, brcbgyend, brcbgzend; + int cbgwidthexpn, cbgheightexpn, cbglengthexpn; + int cblkwidthexpn, cblkheightexpn, cblklengthexpn; + + int diff = tccp->numresolution[0] - tccp->numresolution[2]; + int levelnox = tilec->numresolution[0] - 1 - resno; + int levelnoy = tilec->numresolution[1] - 1 - resno; + int levelnoz = tilec->numresolution[2] - 1 - ((resno <= diff) ? 0 : (resno - diff)); + if (levelnoz < 0) levelnoz = 0; + + /* opj_tcd_resolution_t *res=&tilec->resolutions[resno]; */ + tcd->res = &tilec->resolutions[resno]; + res = tcd->res; + + /* border for each resolution level (global) (B.14)*/ + res->x0 = int_ceildivpow2(tilec->x0, levelnox); + res->y0 = int_ceildivpow2(tilec->y0, levelnoy); + res->z0 = int_ceildivpow2(tilec->z0, levelnoz); + res->x1 = int_ceildivpow2(tilec->x1, levelnox); + res->y1 = int_ceildivpow2(tilec->y1, levelnoy); + res->z1 = int_ceildivpow2(tilec->z1, levelnoz); + /*if (res->z1 < 0)fprintf(stdout,"Res: %d %d/%d --> %d\n",resno,tilec->z1, levelnoz, int_ceildivpow2(tilec->z1, levelnoz));*/ + + res->numbands = (resno == 0) ? 1 : (resno <= diff) ? 3 : 7; /* --> 3D */ + + /* p. 30, table A-13, ISO/IEC IS154444-1 : 2002 */ + if (tccp->csty & J3D_CCP_CSTY_PRT) { + pdx = tccp->prctsiz[0][resno]; + pdy = tccp->prctsiz[1][resno]; + pdz = tccp->prctsiz[2][resno]; + } else { + pdx = 15; + pdy = 15; + pdz = 15; + } + + /* p. 66, B.16, ISO/IEC IS15444-1 : 2002 */ + tlprcxstart = int_floordivpow2(res->x0, pdx) << pdx; + tlprcystart = int_floordivpow2(res->y0, pdy) << pdy; + tlprczstart = int_floordivpow2(res->z0, pdz) << pdz; + brprcxend = int_ceildivpow2(res->x1, pdx) << pdx; + brprcyend = int_ceildivpow2(res->y1, pdy) << pdy; + brprczend = int_ceildivpow2(res->z1, pdz) << pdz; + + res->prctno[0] = (brprcxend - tlprcxstart) >> pdx; + res->prctno[1] = (brprcyend - tlprcystart) >> pdy; + res->prctno[2] = (brprczend - tlprczstart) >> pdz; + if (res->prctno[2] == 0) res->prctno[2] = 1; + + /* p. 67, B.17 & B.18, ISO/IEC IS15444-1 : 2002 */ + if (resno == 0) { + tlcbgxstart = tlprcxstart; + tlcbgystart = tlprcystart; + tlcbgzstart = tlprczstart; + brcbgxend = brprcxend; + brcbgyend = brprcyend; + brcbgzend = brprczend; + cbgwidthexpn = pdx; + cbgheightexpn = pdy; + cbglengthexpn = pdz; + } else { + tlcbgxstart = int_ceildivpow2(tlprcxstart, 1); + tlcbgystart = int_ceildivpow2(tlprcystart, 1); + tlcbgzstart = int_ceildivpow2(tlprczstart, 1); + brcbgxend = int_ceildivpow2(brprcxend, 1); + brcbgyend = int_ceildivpow2(brprcyend, 1); + brcbgzend = int_ceildivpow2(brprczend, 1); + cbgwidthexpn = pdx - 1; + cbgheightexpn = pdy - 1; + cbglengthexpn = pdz - 1; + } + + cblkwidthexpn = int_min(tccp->cblk[0], cbgwidthexpn); /*6*/ + cblkheightexpn = int_min(tccp->cblk[1], cbgheightexpn); /*6*/ + cblklengthexpn = int_min(tccp->cblk[2], cbglengthexpn); /*6*/ + + res->bands = (opj_tcd_band_t *) opj_malloc(res->numbands * sizeof(opj_tcd_band_t)); + for (bandno = 0; bandno < res->numbands; bandno++) { + int x0b, y0b, z0b, i; + int gain, numbps; + opj_stepsize_t *ss = NULL; + + tcd->band = &res->bands[bandno]; + band = tcd->band; + + band->bandno = (resno == 0) ? 0 : bandno + 1; + /* Bandno: 0 - LLL 2 - LHL + 1 - HLL 3 - HHL + 4 - LLH 6 - LHH + 5 - HLH 7 - HHH */ + x0b = (band->bandno == 1) || (band->bandno == 3) || (band->bandno == 5 ) || (band->bandno == 7 ) ? 1 : 0; + y0b = (band->bandno == 2) || (band->bandno == 3) || (band->bandno == 6 ) || (band->bandno == 7 ) ? 1 : 0; + z0b = (band->bandno == 4) || (band->bandno == 5) || (band->bandno == 6 ) || (band->bandno == 7 ) ? 1 : 0; + + /* p. 65, B.15, ISO/IEC IS15444-1 : 2002 */ + if (band->bandno == 0) { + /* band border (global) */ + band->x0 = int_ceildivpow2(tilec->x0, levelnox); + band->y0 = int_ceildivpow2(tilec->y0, levelnoy); + band->z0 = int_ceildivpow2(tilec->z0, levelnoz); + band->x1 = int_ceildivpow2(tilec->x1, levelnox); + band->y1 = int_ceildivpow2(tilec->y1, levelnoy); + band->z1 = int_ceildivpow2(tilec->z1, levelnoz); + } else { + band->x0 = int_ceildivpow2(tilec->x0 - (1 << levelnox) * x0b, levelnox + 1); + band->y0 = int_ceildivpow2(tilec->y0 - (1 << levelnoy) * y0b, levelnoy + 1); + band->z0 = int_ceildivpow2(tilec->z0 - (1 << levelnoz) * z0b, (resno <= diff) ? levelnoz : levelnoz + 1); + band->x1 = int_ceildivpow2(tilec->x1 - (1 << levelnox) * x0b, levelnox + 1); + band->y1 = int_ceildivpow2(tilec->y1 - (1 << levelnoy) * y0b, levelnoy + 1); + band->z1 = int_ceildivpow2(tilec->z1 - (1 << levelnoz) * z0b, (resno <= diff) ? levelnoz : levelnoz + 1); + } + + ss = &tccp->stepsizes[(resno == 0) ? 0 : (prevnumbands + bandno + 1)]; + if (bandno == (res->numbands - 1)) + prevnumbands += (resno == 0) ? 0 : res->numbands; + gain = dwt_getgain(band->bandno,tccp->reversible); + numbps = volume->comps[compno].prec + gain; + band->stepsize = (float)((1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn)); + band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */ + + band->precincts = (opj_tcd_precinct_t *) opj_malloc((res->prctno[0] * res->prctno[1] * res->prctno[2]) * sizeof(opj_tcd_precinct_t)); + + for (i = 0; i < (res->prctno[0] * res->prctno[1] * res->prctno[2]); i++) { + band->precincts[i].imsbtree = NULL; + band->precincts[i].incltree = NULL; + } + + for (precno = 0; precno < (res->prctno[0] * res->prctno[1] * res->prctno[2]); precno++) { + int tlcblkxstart, tlcblkystart, tlcblkzstart, brcblkxend, brcblkyend, brcblkzend; + int cbgxstart, cbgystart, cbgzstart, cbgxend, cbgyend, cbgzend; + + cbgxstart = tlcbgxstart + (precno % res->prctno[0]) * (1 << cbgwidthexpn); + cbgystart = tlcbgystart + ((precno % (res->prctno[0] * res->prctno[1])) / res->prctno[0]) * (1 << cbgheightexpn); + cbgzstart = tlcbgzstart + (precno / (res->prctno[0] * res->prctno[1])) * (1 << cbglengthexpn); + cbgxend = cbgxstart + (1 << cbgwidthexpn); + cbgyend = cbgystart + (1 << cbgheightexpn); + cbgzend = cbgzstart + (1 << cbglengthexpn); + + tcd->prc = &band->precincts[precno]; + prc = tcd->prc; + + /* precinct size (global) */ + prc->x0 = int_max(cbgxstart, band->x0); + prc->y0 = int_max(cbgystart, band->y0); + prc->z0 = int_max(cbgzstart, band->z0); + prc->x1 = int_min(cbgxend, band->x1); + prc->y1 = int_min(cbgyend, band->y1); + prc->z1 = int_min(cbgzend, band->z1); + + tlcblkxstart = int_floordivpow2(prc->x0, cblkwidthexpn) << cblkwidthexpn; + tlcblkystart = int_floordivpow2(prc->y0, cblkheightexpn) << cblkheightexpn; + tlcblkzstart = int_floordivpow2(prc->z0, cblklengthexpn) << cblklengthexpn; + brcblkxend = int_ceildivpow2(prc->x1, cblkwidthexpn) << cblkwidthexpn; + brcblkyend = int_ceildivpow2(prc->y1, cblkheightexpn) << cblkheightexpn; + brcblkzend = int_ceildivpow2(prc->z1, cblklengthexpn) << cblklengthexpn; + prc->cblkno[0] = (brcblkxend - tlcblkxstart) >> cblkwidthexpn; + prc->cblkno[1] = (brcblkyend - tlcblkystart) >> cblkheightexpn; + prc->cblkno[2] = (brcblkzend - tlcblkzstart) >> cblklengthexpn; + prc->cblkno[2] = (prc->cblkno[2] == 0) ? 1 : prc->cblkno[2]; + + prc->cblks = (opj_tcd_cblk_t *) opj_malloc((prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]) * sizeof(opj_tcd_cblk_t)); + prc->incltree = tgt_create(prc->cblkno[0], prc->cblkno[1], prc->cblkno[2]); + prc->imsbtree = tgt_create(prc->cblkno[0], prc->cblkno[1], prc->cblkno[2]); + /*tgt_tree_dump(stdout,prc->incltree);*/ + for (cblkno = 0; cblkno < (prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]); cblkno++) { + int cblkxstart = tlcblkxstart + (cblkno % prc->cblkno[0]) * (1 << cblkwidthexpn); + int cblkystart = tlcblkystart + ((cblkno % (prc->cblkno[0] * prc->cblkno[1])) / prc->cblkno[0]) * (1 << cblkheightexpn); + int cblkzstart = tlcblkzstart + (cblkno / (prc->cblkno[0] * prc->cblkno[1])) * (1 << cblklengthexpn); + int cblkxend = cblkxstart + (1 << cblkwidthexpn); + int cblkyend = cblkystart + (1 << cblkheightexpn); + int cblkzend = cblkzstart + (1 << cblklengthexpn); + int prec = ((tilec->bpp > 16) ? 3 : ((tilec->bpp > 8) ? 2 : 1)); + + tcd->cblk = &prc->cblks[cblkno]; + cblk = tcd->cblk; + + /* code-block size (global) */ + cblk->x0 = int_max(cblkxstart, prc->x0); + cblk->y0 = int_max(cblkystart, prc->y0); + cblk->z0 = int_max(cblkzstart, prc->z0); + cblk->x1 = int_min(cblkxend, prc->x1); + cblk->y1 = int_min(cblkyend, prc->y1); + cblk->z1 = int_min(cblkzend, prc->z1); + } + } + } + } + } + /*tcd_dump(stdout, tcd, tcd->tcd_volume);*/ + +} +void tcd_init_encode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp, int curtileno) { + int compno, resno, bandno, precno, cblkno; + int j, p, q, r; + + opj_tcd_tile_t *tile = NULL; /* pointer to tcd->tile */ + opj_tcd_tilecomp_t *tilec = NULL; /* pointer to tcd->tilec */ + opj_tcd_resolution_t *res = NULL; /* pointer to tcd->res */ + opj_tcd_band_t *band = NULL; /* pointer to tcd->band */ + opj_tcd_precinct_t *prc = NULL; /* pointer to tcd->prc */ + opj_tcd_cblk_t *cblk = NULL; /* pointer to tcd->cblk */ + opj_tcp_t *tcp = &cp->tcps[curtileno]; + + tcd->tile = tcd->tcd_volume->tiles; + tile = tcd->tile; + + /* p61 ISO/IEC IS15444-1 : 2002 */ + /* curtileno --> raster scanned index of tiles */ + /* p,q,r --> matricial index of tiles */ + p = curtileno % cp->tw; + q = curtileno / cp->tw; + r = curtileno / (cp->tw * cp->th); /* extension to 3-D */ + + /* 4 borders of the tile rescale on the volume if necessary (B.3)*/ + tile->x0 = int_max(cp->tx0 + p * cp->tdx, volume->x0); + tile->y0 = int_max(cp->ty0 + q * cp->tdy, volume->y0); + tile->z0 = int_max(cp->tz0 + r * cp->tdz, volume->z0); + tile->x1 = int_min(cp->tx0 + (p + 1) * cp->tdx, volume->x1); + tile->y1 = int_min(cp->ty0 + (q + 1) * cp->tdy, volume->y1); + tile->z1 = int_min(cp->tz0 + (r + 1) * cp->tdz, volume->z1); + tile->numcomps = volume->numcomps; + + /* Modification of the RATE >> */ + for (j = 0; j < tcp->numlayers; j++) { + if (tcp->rates[j] <= 1) { + tcp->rates[j] = 0; + } else { + float num = (float) (tile->numcomps * (tile->x1 - tile->x0) * (tile->y1 - tile->y0) * (tile->z1 - tile->z0) * volume->comps[0].prec); + float den = (float) (8 * volume->comps[0].dx * volume->comps[0].dy * volume->comps[0].dz); + den = tcp->rates[j] * den; + tcp->rates[j] = (num + den - 1) / den; + } + /*tcp->rates[j] = tcp->rates[j] ? int_ceildiv( + tile->numcomps * (tile->x1 - tile->x0) * (tile->y1 - tile->y0) * (tile->z1 - tile->z0) * volume->comps[0].prec, + (tcp->rates[j] * 8 * volume->comps[0].dx * volume->comps[0].dy * volume->comps[0].dz)) : 0;*/ + if (tcp->rates[j]) { + if (j && tcp->rates[j] < tcp->rates[j - 1] + 10) { + tcp->rates[j] = tcp->rates[j - 1] + 20; + } else if (!j && tcp->rates[j] < 30){ + tcp->rates[j] = 30; + } + } + } + /* << Modification of the RATE */ + + for (compno = 0; compno < tile->numcomps; compno++) { + opj_tccp_t *tccp = &tcp->tccps[compno]; + int res_max, i; + int prevnumbands = 0; + + /* opj_tcd_tilecomp_t *tilec=&tile->comps[compno]; */ + tcd->tilec = &tile->comps[compno]; + tilec = tcd->tilec; + + /* border of each tile component (global) (B.3) */ + tilec->x0 = int_ceildiv(tile->x0, volume->comps[compno].dx); + tilec->y0 = int_ceildiv(tile->y0, volume->comps[compno].dy); + tilec->z0 = int_ceildiv(tile->z0, volume->comps[compno].dz); + tilec->x1 = int_ceildiv(tile->x1, volume->comps[compno].dx); + tilec->y1 = int_ceildiv(tile->y1, volume->comps[compno].dy); + tilec->z1 = int_ceildiv(tile->z1, volume->comps[compno].dz); + + tilec->data = (int *) opj_malloc((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0) * (tilec->z1 - tilec->z0) * sizeof(int)); + + res_max = 0; + for (i = 0;i < 3; i++){ + tilec->numresolution[i] = tccp->numresolution[i]; + /*Greater of 3 resolutions contains all information*/ + res_max = (tilec->numresolution[i] > res_max) ? tilec->numresolution[i] : res_max; + } + + tilec->resolutions = (opj_tcd_resolution_t *) opj_malloc(res_max * sizeof(opj_tcd_resolution_t)); + for (resno = 0; resno < res_max; resno++) { + int pdx, pdy, pdz; + int tlprcxstart, tlprcystart, tlprczstart, brprcxend, brprcyend, brprczend; + int tlcbgxstart, tlcbgystart, tlcbgzstart, brcbgxend, brcbgyend, brcbgzend; + int cbgwidthexpn, cbgheightexpn, cbglengthexpn; + int cblkwidthexpn, cblkheightexpn, cblklengthexpn; + + int levelnox = tilec->numresolution[0] - 1 - resno; + int levelnoy = tilec->numresolution[1] - 1 - resno; + int diff = tccp->numresolution[0] - tccp->numresolution[2]; + int levelnoz = tilec->numresolution[2] - 1 - ((resno <= diff) ? 0 : (resno - diff)); + if (levelnoz < 0) levelnoz = 0; + + tcd->res = &tilec->resolutions[resno]; + res = tcd->res; + + /* border for each resolution level (global) (B.14)*/ + res->x0 = int_ceildivpow2(tilec->x0, levelnox); + res->y0 = int_ceildivpow2(tilec->y0, levelnoy); + res->z0 = int_ceildivpow2(tilec->z0, levelnoz); + res->x1 = int_ceildivpow2(tilec->x1, levelnox); + res->y1 = int_ceildivpow2(tilec->y1, levelnoy); + res->z1 = int_ceildivpow2(tilec->z1, levelnoz); + + /* res->numbands = resno == 0 ? 1 : 3; *//* --> 2D */ + + res->numbands = (resno == 0) ? 1 : (resno <= diff) ? 3 : 7; /* --> 3D */ + + /* p. 30, table A-13, ISO/IEC IS154444-1 : 2002 */ + if (tccp->csty & J3D_CCP_CSTY_PRT) { + pdx = tccp->prctsiz[0][resno]; + pdy = tccp->prctsiz[1][resno]; + pdz = tccp->prctsiz[2][resno]; + } else { + pdx = 15; + pdy = 15; + pdz = 15; + } + /* p. 66, B.16, ISO/IEC IS15444-1 : 2002 */ + tlprcxstart = int_floordivpow2(res->x0, pdx) << pdx; + tlprcystart = int_floordivpow2(res->y0, pdy) << pdy; + tlprczstart = int_floordivpow2(res->z0, pdz) << pdz; + brprcxend = int_ceildivpow2(res->x1, pdx) << pdx; + brprcyend = int_ceildivpow2(res->y1, pdy) << pdy; + brprczend = int_ceildivpow2(res->z1, pdz) << pdz; + + res->prctno[0] = (brprcxend - tlprcxstart) >> pdx; + res->prctno[1] = (brprcyend - tlprcystart) >> pdy; + res->prctno[2] = (brprczend - tlprczstart) >> pdz; + if (res->prctno[2] == 0) res->prctno[2] = 1; + + /* p. 67, B.17 & B.18, ISO/IEC IS15444-1 : 2002 */ + if (resno == 0) { + tlcbgxstart = tlprcxstart; + tlcbgystart = tlprcystart; + tlcbgzstart = tlprczstart; + brcbgxend = brprcxend; + brcbgyend = brprcyend; + brcbgzend = brprczend; + cbgwidthexpn = pdx; + cbgheightexpn = pdy; + cbglengthexpn = pdz; + } else { + tlcbgxstart = int_ceildivpow2(tlprcxstart, 1); + tlcbgystart = int_ceildivpow2(tlprcystart, 1); + tlcbgzstart = int_ceildivpow2(tlprczstart, 1); + brcbgxend = int_ceildivpow2(brprcxend, 1); + brcbgyend = int_ceildivpow2(brprcyend, 1); + brcbgzend = int_ceildivpow2(brprczend, 1); + cbgwidthexpn = pdx - 1; + cbgheightexpn = pdy - 1; + cbglengthexpn = pdz - 1; + } + + cblkwidthexpn = int_min(tccp->cblk[0], cbgwidthexpn); + cblkheightexpn = int_min(tccp->cblk[1], cbgheightexpn); + cblklengthexpn = int_min(tccp->cblk[2], cbglengthexpn); + + res->bands = (opj_tcd_band_t *) opj_malloc(res->numbands * sizeof(opj_tcd_band_t)); + for (bandno = 0; bandno < res->numbands; bandno++) { + int x0b, y0b, z0b; + int gain, numbps; + opj_stepsize_t *ss = NULL; + + tcd->band = &res->bands[bandno]; + band = tcd->band; + + band->bandno = resno == 0 ? 0 : bandno + 1; + /* Bandno: 0 - LLL 2 - LHL + 1 - HLL 3 - HHL + 4 - LLH 6 - LHH + 5 - HLH 7 - HHH */ + x0b = (band->bandno == 1) || (band->bandno == 3) || (band->bandno == 5 ) || (band->bandno == 7 ) ? 1 : 0; + y0b = (band->bandno == 2) || (band->bandno == 3) || (band->bandno == 6 ) || (band->bandno == 7 ) ? 1 : 0; + z0b = (band->bandno == 4) || (band->bandno == 5) || (band->bandno == 6 ) || (band->bandno == 7 ) ? 1 : 0; + + /* p. 65, B.15, ISO/IEC IS15444-1 : 2002 */ + if (band->bandno == 0) { + /* band border (global) */ + band->x0 = int_ceildivpow2(tilec->x0, levelnox); + band->y0 = int_ceildivpow2(tilec->y0, levelnoy); + band->z0 = int_ceildivpow2(tilec->z0, levelnoz); + band->x1 = int_ceildivpow2(tilec->x1, levelnox); + band->y1 = int_ceildivpow2(tilec->y1, levelnoy); + band->z1 = int_ceildivpow2(tilec->z1, levelnoz); + } else { + band->x0 = int_ceildivpow2(tilec->x0 - (1 << levelnox) * x0b, levelnox + 1); + band->y0 = int_ceildivpow2(tilec->y0 - (1 << levelnoy) * y0b, levelnoy + 1); + band->z0 = int_ceildivpow2(tilec->z0 - (1 << levelnoz) * z0b, (resno <= diff) ? levelnoz : levelnoz + 1); + band->x1 = int_ceildivpow2(tilec->x1 - (1 << levelnox) * x0b, levelnox + 1); + band->y1 = int_ceildivpow2(tilec->y1 - (1 << levelnoy) * y0b, levelnoy + 1); + band->z1 = int_ceildivpow2(tilec->z1 - (1 << levelnoz) * z0b, (resno <= diff) ? levelnoz : levelnoz + 1); + } + + ss = &tccp->stepsizes[(resno == 0) ? 0 : (prevnumbands + bandno + 1)]; + if (bandno == (res->numbands - 1)) + prevnumbands += (resno == 0) ? 0 : res->numbands; + gain = dwt_getgain(band->bandno,tccp->reversible); + numbps = volume->comps[compno].prec + gain; + + band->stepsize = (float)((1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn)); + band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */ + + for (precno = 0; precno < res->prctno[0] * res->prctno[1] * res->prctno[2]; precno++) { + int tlcblkxstart, tlcblkystart, tlcblkzstart, brcblkxend, brcblkyend, brcblkzend; + + int cbgxstart = tlcbgxstart + (precno % res->prctno[0]) * (1 << cbgwidthexpn); + int cbgystart = tlcbgystart + ((precno / (res->prctno[0] * res->prctno[1])) / res->prctno[0]) * (1 << cbgheightexpn); + int cbgzstart = tlcbgzstart + (precno / (res->prctno[0] * res->prctno[1])) * (1 << cbglengthexpn); + int cbgxend = cbgxstart + (1 << cbgwidthexpn); + int cbgyend = cbgystart + (1 << cbgheightexpn); + int cbgzend = cbgzstart + (1 << cbglengthexpn); + + /* opj_tcd_precinct_t *prc=&band->precincts[precno]; */ + tcd->prc = &band->precincts[precno]; + prc = tcd->prc; + + /* precinct size (global) */ + prc->x0 = int_max(cbgxstart, band->x0); + prc->y0 = int_max(cbgystart, band->y0); + prc->z0 = int_max(cbgzstart, band->z0); + prc->x1 = int_min(cbgxend, band->x1); + prc->y1 = int_min(cbgyend, band->y1); + prc->z1 = int_min(cbgzend, band->z1); + + tlcblkxstart = int_floordivpow2(prc->x0, cblkwidthexpn) << cblkwidthexpn; + tlcblkystart = int_floordivpow2(prc->y0, cblkheightexpn) << cblkheightexpn; + tlcblkzstart = int_floordivpow2(prc->z0, cblklengthexpn) << cblklengthexpn; + brcblkxend = int_ceildivpow2(prc->x1, cblkwidthexpn) << cblkwidthexpn; + brcblkyend = int_ceildivpow2(prc->y1, cblkheightexpn) << cblkheightexpn; + brcblkzend = int_ceildivpow2(prc->z1, cblklengthexpn) << cblklengthexpn; + prc->cblkno[0] = (brcblkxend - tlcblkxstart) >> cblkwidthexpn; + prc->cblkno[1] = (brcblkyend - tlcblkystart) >> cblkheightexpn; + prc->cblkno[2] = (brcblkzend - tlcblkzstart) >> cblklengthexpn; + prc->cblkno[2] = (prc->cblkno[2] == 0) ? 1 : prc->cblkno[2]; + + opj_free(prc->cblks); + prc->cblks = (opj_tcd_cblk_t *) opj_malloc((prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]) * sizeof(opj_tcd_cblk_t)); + prc->incltree = tgt_create(prc->cblkno[0], prc->cblkno[1], prc->cblkno[2]); + prc->imsbtree = tgt_create(prc->cblkno[0], prc->cblkno[1], prc->cblkno[2]); + + for (cblkno = 0; cblkno < (prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]); cblkno++) { + int cblkxstart = tlcblkxstart + (cblkno % prc->cblkno[0]) * (1 << cblkwidthexpn); + int cblkystart = tlcblkystart + ((cblkno % (prc->cblkno[0] * prc->cblkno[1])) / prc->cblkno[0]) * (1 << cblkheightexpn); + int cblkzstart = tlcblkzstart + (cblkno / (prc->cblkno[0] * prc->cblkno[1])) * (1 << cblklengthexpn); + int cblkxend = cblkxstart + (1 << cblkwidthexpn); + int cblkyend = cblkystart + (1 << cblkheightexpn); + int cblkzend = cblkzstart + (1 << cblklengthexpn); + int prec = ((tilec->bpp > 16) ? 3 : ((tilec->bpp > 8) ? 2 : 1)); + + tcd->cblk = &prc->cblks[cblkno]; + cblk = tcd->cblk; + + /* code-block size (global) */ + cblk->x0 = int_max(cblkxstart, prc->x0); + cblk->y0 = int_max(cblkystart, prc->y0); + cblk->z0 = int_max(cblkzstart, prc->z0); + cblk->x1 = int_min(cblkxend, prc->x1); + cblk->y1 = int_min(cblkyend, prc->y1); + cblk->z1 = int_min(cblkzend, prc->z1); + } + } /* precno */ + } /* bandno */ + } /* resno */ + } /* compno */ + /*tcd_dump(stdout, tcd, tcd->tcd_volume);*/ +} + + +void tcd_free_encode(opj_tcd_t *tcd) { + int tileno, compno, resno, bandno, precno; + + opj_tcd_tile_t *tile = NULL; /* pointer to tcd->tile */ +/* opj_tcd_slice_t *slice = NULL; */ /* pointer to tcd->slice */ + opj_tcd_tilecomp_t *tilec = NULL; /* pointer to tcd->tilec */ + opj_tcd_resolution_t *res = NULL; /* pointer to tcd->res */ + opj_tcd_band_t *band = NULL; /* pointer to tcd->band */ + opj_tcd_precinct_t *prc = NULL; /* pointer to tcd->prc */ + + for (tileno = 0; tileno < 1; tileno++) { + tcd->tile = tcd->tcd_volume->tiles; + tile = tcd->tile; + + for (compno = 0; compno < tile->numcomps; compno++) { + tcd->tilec = &tile->comps[compno]; + tilec = tcd->tilec; + + for (resno = 0; resno < tilec->numresolution[0]; resno++) { + tcd->res = &tilec->resolutions[resno]; + res = tcd->res; + + for (bandno = 0; bandno < res->numbands; bandno++) { + tcd->band = &res->bands[bandno]; + band = tcd->band; + + for (precno = 0; precno < res->prctno[0] * res->prctno[1] * res->prctno[2]; precno++) { + tcd->prc = &band->precincts[precno]; + prc = tcd->prc; + + if (prc->incltree != NULL) { + tgt_destroy(prc->incltree); + prc->incltree = NULL; + } + if (prc->imsbtree != NULL) { + tgt_destroy(prc->imsbtree); + prc->imsbtree = NULL; + } + opj_free(prc->cblks); + prc->cblks = NULL; + } /* for (precno */ + opj_free(band->precincts); + band->precincts = NULL; + } /* for (bandno */ + } /* for (resno */ + opj_free(tilec->resolutions); + tilec->resolutions = NULL; + } /* for (compno */ + opj_free(tile->comps); + tile->comps = NULL; + } /* for (tileno */ + opj_free(tcd->tcd_volume->tiles); + tcd->tcd_volume->tiles = NULL; +} + +/* ----------------------------------------------------------------------- */ +void tcd_malloc_decode(opj_tcd_t *tcd, opj_volume_t * volume, opj_cp_t * cp) { + int tileno, compno, resno, bandno, precno, cblkno, res_max, + i, j, p, q, r; + unsigned int x0 = 0, y0 = 0, z0 = 0, + x1 = 0, y1 = 0, z1 = 0, + w, h, l; + + tcd->volume = volume; + tcd->cp = cp; + tcd->tcd_volume->tw = cp->tw; + tcd->tcd_volume->th = cp->th; + tcd->tcd_volume->tl = cp->tl; + tcd->tcd_volume->tiles = (opj_tcd_tile_t *) opj_malloc(cp->tw * cp->th * cp->tl * sizeof(opj_tcd_tile_t)); + + for (i = 0; i < cp->tileno_size; i++) { + opj_tcp_t *tcp = &(cp->tcps[cp->tileno[i]]); + opj_tcd_tile_t *tile = &(tcd->tcd_volume->tiles[cp->tileno[i]]); + + /* p61 ISO/IEC IS15444-1 : 2002 */ + /* curtileno --> raster scanned index of tiles */ + /* p,q,r --> matricial index of tiles */ + tileno = cp->tileno[i]; + p = tileno % cp->tw; + q = tileno / cp->tw; + r = tileno / (cp->tw * cp->th); /* extension to 3-D */ + + /* 4 borders of the tile rescale on the volume if necessary (B.3)*/ + tile->x0 = int_max(cp->tx0 + p * cp->tdx, volume->x0); + tile->y0 = int_max(cp->ty0 + q * cp->tdy, volume->y0); + tile->z0 = int_max(cp->tz0 + r * cp->tdz, volume->z0); + tile->x1 = int_min(cp->tx0 + (p + 1) * cp->tdx, volume->x1); + tile->y1 = int_min(cp->ty0 + (q + 1) * cp->tdy, volume->y1); + tile->z1 = int_min(cp->tz0 + (r + 1) * cp->tdz, volume->z1); + tile->numcomps = volume->numcomps; + + tile->comps = (opj_tcd_tilecomp_t *) opj_malloc(volume->numcomps * sizeof(opj_tcd_tilecomp_t)); + for (compno = 0; compno < tile->numcomps; compno++) { + opj_tccp_t *tccp = &tcp->tccps[compno]; + opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; + int prevnumbands = 0; + + /* border of each tile component (global) */ + tilec->x0 = int_ceildiv(tile->x0, volume->comps[compno].dx); + tilec->y0 = int_ceildiv(tile->y0, volume->comps[compno].dy); + tilec->z0 = int_ceildiv(tile->z0, volume->comps[compno].dz); + tilec->x1 = int_ceildiv(tile->x1, volume->comps[compno].dx); + tilec->y1 = int_ceildiv(tile->y1, volume->comps[compno].dy); + tilec->z1 = int_ceildiv(tile->z1, volume->comps[compno].dz); + + tilec->data = (int *) opj_malloc((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0) * (tilec->z1 - tilec->z0) * sizeof(int)); + + res_max = 0; + for (i = 0;i < 3; i++){ + tilec->numresolution[i] = tccp->numresolution[i]; + /*Greater of 3 resolutions contains all information*/ + res_max = (tilec->numresolution[i] > res_max) ? tilec->numresolution[i] : res_max; + } + + tilec->resolutions = (opj_tcd_resolution_t *) opj_malloc(res_max * sizeof(opj_tcd_resolution_t)); + + for (resno = 0; resno < res_max; resno++) { + opj_tcd_resolution_t *res = &tilec->resolutions[resno]; + int pdx, pdy, pdz; + int tlprcxstart, tlprcystart, tlprczstart, brprcxend, brprcyend, brprczend; + int tlcbgxstart, tlcbgystart, tlcbgzstart, brcbgxend, brcbgyend, brcbgzend; + int cbgwidthexpn, cbgheightexpn, cbglengthexpn; + int cblkwidthexpn, cblkheightexpn, cblklengthexpn; + int levelnox = tilec->numresolution[0] - 1 - resno; + int levelnoy = tilec->numresolution[1] - 1 - resno; + int diff = tccp->numresolution[0] - tccp->numresolution[2]; + int levelnoz = tilec->numresolution[2] - 1 - ((resno <= diff) ? 0 : (resno - diff)); + if (levelnoz < 0) levelnoz = 0; + + /* border for each resolution level (global) */ + res->x0 = int_ceildivpow2(tilec->x0, levelnox); + res->y0 = int_ceildivpow2(tilec->y0, levelnoy); + res->z0 = int_ceildivpow2(tilec->z0, levelnoz); + res->x1 = int_ceildivpow2(tilec->x1, levelnox); + res->y1 = int_ceildivpow2(tilec->y1, levelnoy); + res->z1 = int_ceildivpow2(tilec->z1, levelnoz); + res->numbands = (resno == 0) ? 1 : (resno <= diff) ? 3 : 7; /* --> 3D */ + + /* p. 30, table A-13, ISO/IEC IS154444-1 : 2002 */ + if (tccp->csty & J3D_CCP_CSTY_PRT) { + pdx = tccp->prctsiz[0][resno]; + pdy = tccp->prctsiz[1][resno]; + pdz = tccp->prctsiz[2][resno]; + } else { + pdx = 15; + pdy = 15; + pdz = 15; + } + + /* p. 66, B.16, ISO/IEC IS15444-1 : 2002 */ + tlprcxstart = int_floordivpow2(res->x0, pdx) << pdx; + tlprcystart = int_floordivpow2(res->y0, pdy) << pdy; + tlprczstart = int_floordivpow2(res->z0, pdz) << pdz; + brprcxend = int_ceildivpow2(res->x1, pdx) << pdx; + brprcyend = int_ceildivpow2(res->y1, pdy) << pdy; + brprczend = int_ceildivpow2(res->z1, pdz) << pdz; + + res->prctno[0] = (brprcxend - tlprcxstart) >> pdx; + res->prctno[1] = (brprcyend - tlprcystart) >> pdy; + res->prctno[2] = (brprczend - tlprczstart) >> pdz; + + /* p. 67, B.17 & B.18, ISO/IEC IS15444-1 : 2002 */ + if (resno == 0) { + tlcbgxstart = tlprcxstart;/*0*/ + tlcbgystart = tlprcystart; + tlcbgzstart = tlprczstart; + brcbgxend = brprcxend;/*1*/ + brcbgyend = brprcyend; + brcbgzend = brprczend; + cbgwidthexpn = pdx; /*15*/ + cbgheightexpn = pdy; + cbglengthexpn = pdz; + } else { + tlcbgxstart = int_ceildivpow2(tlprcxstart, 1); + tlcbgystart = int_ceildivpow2(tlprcystart, 1); + tlcbgzstart = int_ceildivpow2(tlprczstart, 1); + brcbgxend = int_ceildivpow2(brprcxend, 1); + brcbgyend = int_ceildivpow2(brprcyend, 1); + brcbgzend = int_ceildivpow2(brprczend, 1); + cbgwidthexpn = pdx - 1; + cbgheightexpn = pdy - 1; + cbglengthexpn = pdz - 1; + } + + cblkwidthexpn = int_min(tccp->cblk[0], cbgwidthexpn); /*6*/ + cblkheightexpn = int_min(tccp->cblk[1], cbgheightexpn); /*6*/ + cblklengthexpn = int_min(tccp->cblk[2], cbglengthexpn); /*6*/ + + res->bands = (opj_tcd_band_t *) opj_malloc(res->numbands * sizeof(opj_tcd_band_t)); + for (bandno = 0; bandno < res->numbands; bandno++) { + int x0b, y0b, z0b; + int gain, numbps; + opj_stepsize_t *ss = NULL; + + opj_tcd_band_t *band = &res->bands[bandno]; + band->bandno = resno == 0 ? 0 : bandno + 1; + /* Bandno: 0 - LLL 2 - LHL + 1 - HLL 3 - HHL + 4 - LLH 6 - LHH + 5 - HLH 7 - HHH */ + x0b = (band->bandno == 1) || (band->bandno == 3) || (band->bandno == 5 ) || (band->bandno == 7 ) ? 1 : 0; + y0b = (band->bandno == 2) || (band->bandno == 3) || (band->bandno == 6 ) || (band->bandno == 7 ) ? 1 : 0; + z0b = (band->bandno == 4) || (band->bandno == 5) || (band->bandno == 6 ) || (band->bandno == 7 ) ? 1 : 0; + + /* p. 65, B.15, ISO/IEC IS15444-1 : 2002 */ + if (band->bandno == 0) { + /* band border (global) */ + band->x0 = int_ceildivpow2(tilec->x0, levelnox); + band->y0 = int_ceildivpow2(tilec->y0, levelnoy); + band->z0 = int_ceildivpow2(tilec->z0, levelnoz); + band->x1 = int_ceildivpow2(tilec->x1, levelnox); + band->y1 = int_ceildivpow2(tilec->y1, levelnoy); + band->z1 = int_ceildivpow2(tilec->z1, levelnoz); + } else { + band->x0 = int_ceildivpow2(tilec->x0 - (1 << levelnox) * x0b, levelnox + 1); + band->y0 = int_ceildivpow2(tilec->y0 - (1 << levelnoy) * y0b, levelnoy + 1); + band->z0 = int_ceildivpow2(tilec->z0 - (1 << levelnoz) * z0b, (resno <= diff) ? levelnoz : levelnoz + 1); + band->x1 = int_ceildivpow2(tilec->x1 - (1 << levelnox) * x0b, levelnox + 1); + band->y1 = int_ceildivpow2(tilec->y1 - (1 << levelnoy) * y0b, levelnoy + 1); + band->z1 = int_ceildivpow2(tilec->z1 - (1 << levelnoz) * z0b, (resno <= diff) ? levelnoz : levelnoz + 1); + } + + ss = &tccp->stepsizes[(resno == 0) ? 0 : (prevnumbands + bandno + 1)]; + if (bandno == (res->numbands - 1)) + prevnumbands += (resno == 0) ? 0 : res->numbands; + gain = dwt_getgain(band->bandno,tccp->reversible); + numbps = volume->comps[compno].prec + gain; + + band->stepsize = (float)((1.0 + ss->mant / 2048.0) * pow(2.0, numbps - ss->expn)); + band->numbps = ss->expn + tccp->numgbits - 1; /* WHY -1 ? */ + + band->precincts = (opj_tcd_precinct_t *) opj_malloc(res->prctno[0] * res->prctno[1] * res->prctno[2] * sizeof(opj_tcd_precinct_t)); + + for (precno = 0; precno < res->prctno[0] * res->prctno[1] * res->prctno[2]; precno++) { + int tlcblkxstart, tlcblkystart, tlcblkzstart, brcblkxend, brcblkyend, brcblkzend; + + int cbgxstart = tlcbgxstart + (precno % res->prctno[0]) * (1 << cbgwidthexpn); + int cbgystart = tlcbgystart + (precno / res->prctno[0]) * (1 << cbgheightexpn); + int cbgzstart = tlcbgzstart + (precno / (res->prctno[0] * res->prctno[1])) * (1 << cbglengthexpn); + int cbgxend = cbgxstart + (1 << cbgwidthexpn); + int cbgyend = cbgystart + (1 << cbgheightexpn); + int cbgzend = cbgzstart + (1 << cbglengthexpn); + + opj_tcd_precinct_t *prc = &band->precincts[precno]; + /* precinct size (global) */ + prc->x0 = int_max(cbgxstart, band->x0); + prc->y0 = int_max(cbgystart, band->y0); + prc->z0 = int_max(cbgzstart, band->z0); + prc->x1 = int_min(cbgxend, band->x1); + prc->y1 = int_min(cbgyend, band->y1); + prc->z1 = int_min(cbgzend, band->z1); + + tlcblkxstart = int_floordivpow2(prc->x0, cblkwidthexpn) << cblkwidthexpn; + tlcblkystart = int_floordivpow2(prc->y0, cblkheightexpn) << cblkheightexpn; + tlcblkzstart = int_floordivpow2(prc->z0, cblklengthexpn) << cblklengthexpn; + brcblkxend = int_ceildivpow2(prc->x1, cblkwidthexpn) << cblkwidthexpn; + brcblkyend = int_ceildivpow2(prc->y1, cblkheightexpn) << cblkheightexpn; + brcblkzend = int_ceildivpow2(prc->z1, cblklengthexpn) << cblklengthexpn; + prc->cblkno[0] = (brcblkxend - tlcblkxstart) >> cblkwidthexpn; + prc->cblkno[1] = (brcblkyend - tlcblkystart) >> cblkheightexpn; + prc->cblkno[2] = (brcblkzend - tlcblkzstart) >> cblklengthexpn; + prc->cblkno[2] = (prc->cblkno[2] == 0) ? 1 : prc->cblkno[2]; + + prc->cblks = (opj_tcd_cblk_t *) opj_malloc((prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]) * sizeof(opj_tcd_cblk_t)); + prc->incltree = tgt_create(prc->cblkno[0], prc->cblkno[1], prc->cblkno[2]); + prc->imsbtree = tgt_create(prc->cblkno[0], prc->cblkno[1], prc->cblkno[2]); + + for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { + int cblkxstart = tlcblkxstart + (cblkno % prc->cblkno[0]) * (1 << cblkwidthexpn); + int cblkystart = tlcblkystart + ((cblkno % (prc->cblkno[0] * prc->cblkno[1])) / prc->cblkno[0]) * (1 << cblkheightexpn); + int cblkzstart = tlcblkzstart + (cblkno / (prc->cblkno[0] * prc->cblkno[1])) * (1 << cblklengthexpn); + int cblkxend = cblkxstart + (1 << cblkwidthexpn); + int cblkyend = cblkystart + (1 << cblkheightexpn); + int cblkzend = cblkzstart + (1 << cblklengthexpn); + int prec = ((tilec->bpp > 16) ? 3 : ((tilec->bpp > 8) ? 2 : 1)); + /* code-block size (global) */ + opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; + + /* code-block size (global) */ + cblk->x0 = int_max(cblkxstart, prc->x0); + cblk->y0 = int_max(cblkystart, prc->y0); + cblk->z0 = int_max(cblkzstart, prc->z0); + cblk->x1 = int_min(cblkxend, prc->x1); + cblk->y1 = int_min(cblkyend, prc->y1); + cblk->z1 = int_min(cblkzend, prc->z1); + } + } /* precno */ + } /* bandno */ + } /* resno */ + } /* compno */ + } /* i = 0..cp->tileno_size */ + + /*tcd_dump(stdout, tcd, tcd->tcd_volume);*/ + + /* + Allocate place to store the decoded data = final volume + Place limited by the tile really present in the codestream + */ + + for (i = 0; i < volume->numcomps; i++) { + for (j = 0; j < cp->tileno_size; j++) { + tileno = cp->tileno[j]; + x0 = (j == 0) ? tcd->tcd_volume->tiles[tileno].comps[i].x0 : int_min(x0,(unsigned int) tcd->tcd_volume->tiles[tileno].comps[i].x0); + y0 = (j == 0) ? tcd->tcd_volume->tiles[tileno].comps[i].y0 : int_min(y0,(unsigned int) tcd->tcd_volume->tiles[tileno].comps[i].y0); + z0 = (j == 0) ? tcd->tcd_volume->tiles[tileno].comps[i].z0 : int_min(z0,(unsigned int) tcd->tcd_volume->tiles[tileno].comps[i].z0); + x1 = (j == 0) ? tcd->tcd_volume->tiles[tileno].comps[i].x1 : int_max(x1,(unsigned int) tcd->tcd_volume->tiles[tileno].comps[i].x1); + y1 = (j == 0) ? tcd->tcd_volume->tiles[tileno].comps[i].y1 : int_max(y1,(unsigned int) tcd->tcd_volume->tiles[tileno].comps[i].y1); + z1 = (j == 0) ? tcd->tcd_volume->tiles[tileno].comps[i].z1 : int_max(z1,(unsigned int) tcd->tcd_volume->tiles[tileno].comps[i].z1); + } + + w = x1 - x0; + h = y1 - y0; + l = z1 - z0; + + volume->comps[i].data = (int *) opj_malloc(w * h * l * sizeof(int)); + volume->comps[i].w = w; + volume->comps[i].h = h; + volume->comps[i].l = l; + volume->comps[i].x0 = x0; + volume->comps[i].y0 = y0; + volume->comps[i].z0 = z0; + volume->comps[i].bigendian = cp->bigendian; + } +} + +void tcd_free_decode(opj_tcd_t *tcd) { + int tileno,compno,resno,bandno,precno; + + opj_tcd_volume_t *tcd_volume = tcd->tcd_volume; + + for (tileno = 0; tileno < tcd_volume->tw * tcd_volume->th * tcd_volume->tl; tileno++) { + opj_tcd_tile_t *tile = &tcd_volume->tiles[tileno]; + for (compno = 0; compno < tile->numcomps; compno++) { + opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; + for (resno = 0; resno < tilec->numresolution[0]; resno++) { + opj_tcd_resolution_t *res = &tilec->resolutions[resno]; + for (bandno = 0; bandno < res->numbands; bandno++) { + opj_tcd_band_t *band = &res->bands[bandno]; + for (precno = 0; precno < res->prctno[1] * res->prctno[0] * res->prctno[2]; precno++) { + opj_tcd_precinct_t *prec = &band->precincts[precno]; + if (prec->cblks != NULL) opj_free(prec->cblks); + if (prec->imsbtree != NULL) tgt_destroy(prec->imsbtree); + if (prec->incltree != NULL) tgt_destroy(prec->incltree); + /*for (treeno = 0; treeno < prec->numtrees; treeno++){ + if (prec->imsbtree[treeno] != NULL) tgt_destroy(prec->imsbtree[treeno]); + if (prec->incltree[treeno] != NULL) tgt_destroy(prec->incltree[treeno]); + }*/ + } + if (band->precincts != NULL) opj_free(band->precincts); + } + } + if (tilec->resolutions != NULL) opj_free(tilec->resolutions); + } + if (tile->comps != NULL) opj_free(tile->comps); + } + + if (tcd_volume->tiles != NULL) opj_free(tcd_volume->tiles); +} + + + +/* ----------------------------------------------------------------------- */ +void tcd_makelayer_fixed(opj_tcd_t *tcd, int layno, int final) { + int compno, resno, bandno, precno, cblkno; + int value; /*, matrice[tcd_tcp->numlayers][tcd_tile->comps[0].numresolution[0]][3]; */ + int matrice[10][10][3]; + int i, j, k; + + opj_cp_t *cp = tcd->cp; + opj_tcd_tile_t *tcd_tile = tcd->tcd_tile; + opj_tcp_t *tcd_tcp = tcd->tcp; + + /*matrice=(int*)opj_malloc(tcd_tcp->numlayers*tcd_tile->comps[0].numresolution[0]*3*sizeof(int)); */ + + for (compno = 0; compno < tcd_tile->numcomps; compno++) { + opj_tcd_tilecomp_t *tilec = &tcd_tile->comps[compno]; + for (i = 0; i < tcd_tcp->numlayers; i++) { + for (j = 0; j < tilec->numresolution[0]; j++) { + for (k = 0; k < 3; k++) { + matrice[i][j][k] = + (int) (cp->matrice[i * tilec->numresolution[0] * 3 + j * 3 + k] + * (float) (tcd->volume->comps[compno].prec / 16.0)); + } + } + } + + for (resno = 0; resno < tilec->numresolution[0]; resno++) { + opj_tcd_resolution_t *res = &tilec->resolutions[resno]; + for (bandno = 0; bandno < res->numbands; bandno++) { + opj_tcd_band_t *band = &res->bands[bandno]; + for (precno = 0; precno < res->prctno[0] * res->prctno[1] * res->prctno[2]; precno++) { + opj_tcd_precinct_t *prc = &band->precincts[precno]; + for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { + opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; + opj_tcd_layer_t *layer = &cblk->layers[layno]; + int n; + int imsb = tcd->volume->comps[compno].prec - cblk->numbps; /* number of bit-plan equal to zero */ + /* Correction of the matrix of coefficient to include the IMSB information */ + if (layno == 0) { + value = matrice[layno][resno][bandno]; + if (imsb >= value) { + value = 0; + } else { + value -= imsb; + } + } else { + value = matrice[layno][resno][bandno] - matrice[layno - 1][resno][bandno]; + if (imsb >= matrice[layno - 1][resno][bandno]) { + value -= (imsb - matrice[layno - 1][resno][bandno]); + if (value < 0) { + value = 0; + } + } + } + + if (layno == 0) { + cblk->numpassesinlayers = 0; + } + + n = cblk->numpassesinlayers; + if (cblk->numpassesinlayers == 0) { + if (value != 0) { + n = 3 * value - 2 + cblk->numpassesinlayers; + } else { + n = cblk->numpassesinlayers; + } + } else { + n = 3 * value + cblk->numpassesinlayers; + } + + layer->numpasses = n - cblk->numpassesinlayers; + + if (!layer->numpasses) + continue; + + if (cblk->numpassesinlayers == 0) { + layer->len = cblk->passes[n - 1].rate; + layer->data = cblk->data; + } else { + layer->len = cblk->passes[n - 1].rate - cblk->passes[cblk->numpassesinlayers - 1].rate; + layer->data = cblk->data + cblk->passes[cblk->numpassesinlayers - 1].rate; + } + if (final) + cblk->numpassesinlayers = n; + } + } + } + } + } +} + +void tcd_rateallocate_fixed(opj_tcd_t *tcd) { + int layno; + for (layno = 0; layno < tcd->tcp->numlayers; layno++) { + tcd_makelayer_fixed(tcd, layno, 1); + } +} + +void tcd_makelayer(opj_tcd_t *tcd, int layno, double thresh, int final) { + int compno, resno, bandno, precno, cblkno, passno; + + opj_tcd_tile_t *tcd_tile = tcd->tcd_tile; + + tcd_tile->distolayer[layno] = 0; /* fixed_quality */ + + for (compno = 0; compno < tcd_tile->numcomps; compno++) { + opj_tcd_tilecomp_t *tilec = &tcd_tile->comps[compno]; + for (resno = 0; resno < tilec->numresolution[0]; resno++) { + opj_tcd_resolution_t *res = &tilec->resolutions[resno]; + for (bandno = 0; bandno < res->numbands; bandno++) { + opj_tcd_band_t *band = &res->bands[bandno]; + for (precno = 0; precno < res->prctno[0] * res->prctno[1] * res->prctno[2]; precno++) { + opj_tcd_precinct_t *prc = &band->precincts[precno]; + for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { + opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; + opj_tcd_layer_t *layer = &cblk->layers[layno]; + + int n; + if (layno == 0) { + cblk->numpassesinlayers = 0; + } + n = cblk->numpassesinlayers; + for (passno = cblk->numpassesinlayers; passno < cblk->totalpasses; passno++) { + int dr; + double dd; + opj_tcd_pass_t *pass = &cblk->passes[passno]; + if (n == 0) { + dr = pass->rate; + dd = pass->distortiondec; + } else { + dr = pass->rate - cblk->passes[n - 1].rate; + dd = pass->distortiondec - cblk->passes[n - 1].distortiondec; + } + if (!dr) { + if (dd) + n = passno + 1; + continue; + } + if (dd / dr >= thresh){ + n = passno + 1; + } + } + layer->numpasses = n - cblk->numpassesinlayers; + + if (!layer->numpasses) { + layer->disto = 0; + continue; + } + if (cblk->numpassesinlayers == 0) { + layer->len = cblk->passes[n - 1].rate; + layer->data = cblk->data; + layer->disto = cblk->passes[n - 1].distortiondec; + } else { + layer->len = cblk->passes[n - 1].rate - cblk->passes[cblk->numpassesinlayers - 1].rate; + layer->data = cblk->data + cblk->passes[cblk->numpassesinlayers - 1].rate; + layer->disto = cblk->passes[n - 1].distortiondec - cblk->passes[cblk->numpassesinlayers - 1].distortiondec; + } + + tcd_tile->distolayer[layno] += layer->disto; /* fixed_quality */ + + if (final) + cblk->numpassesinlayers = n; + + /* fprintf(stdout,"MakeLayer : %d %f %d %d \n",layer->len, layer->disto, layer->numpasses, n);*/ + } + } + } + } + } +} + +bool tcd_rateallocate(opj_tcd_t *tcd, unsigned char *dest, int len, opj_volume_info_t * volume_info) { + int compno, resno, bandno, precno, cblkno, passno, layno; + double min, max; + double cumdisto[100]; /* fixed_quality */ + const double K = 1; /* 1.1; // fixed_quality */ + double maxSE = 0; + + opj_cp_t *cp = tcd->cp; + opj_tcd_tile_t *tcd_tile = tcd->tcd_tile; + opj_tcp_t *tcd_tcp = tcd->tcp; + + min = DBL_MAX; + max = 0; + + tcd_tile->nbpix = 0; /* fixed_quality */ + + for (compno = 0; compno < tcd_tile->numcomps; compno++) { + opj_tcd_tilecomp_t *tilec = &tcd_tile->comps[compno]; + tilec->nbpix = 0; + for (resno = 0; resno < tilec->numresolution[0]; resno++) { + opj_tcd_resolution_t *res = &tilec->resolutions[resno]; + for (bandno = 0; bandno < res->numbands; bandno++) { + opj_tcd_band_t *band = &res->bands[bandno]; + for (precno = 0; precno < res->prctno[0] * res->prctno[1] * res->prctno[2]; precno++) { + opj_tcd_precinct_t *prc = &band->precincts[precno]; + for (cblkno = 0; cblkno < prc->cblkno[0] * prc->cblkno[1] * prc->cblkno[2]; cblkno++) { + opj_tcd_cblk_t *cblk = &prc->cblks[cblkno]; + for (passno = 0; passno < cblk->totalpasses; passno++) { + opj_tcd_pass_t *pass = &cblk->passes[passno]; + int dr; + double dd, rdslope; + if (passno == 0) { + dr = pass->rate; + dd = pass->distortiondec; + } else { + dr = pass->rate - cblk->passes[passno - 1].rate; + dd = pass->distortiondec - cblk->passes[passno - 1].distortiondec; + } + if (dr == 0) { + continue; + } + rdslope = dd / dr; + if (rdslope < min) { + min = rdslope; + } + if (rdslope > max) { + max = rdslope; + } + + } /* passno */ + + /* fixed_quality */ + tcd_tile->nbpix += ((cblk->x1 - cblk->x0) * (cblk->y1 - cblk->y0) * (cblk->z1 - cblk->z0)); + tilec->nbpix += ((cblk->x1 - cblk->x0) * (cblk->y1 - cblk->y0) * (cblk->z1 - cblk->z0)); + } /* cbklno */ + } /* precno */ + } /* bandno */ + } /* resno */ + + maxSE += (((double)(1 << tcd->volume->comps[compno].prec) - 1.0) + * ((double)(1 << tcd->volume->comps[compno].prec) -1.0)) + * ((double)(tilec->nbpix)); + } /* compno */ + + /* add antonin index */ + if(volume_info && volume_info->index_on) { + opj_tile_info_t *info_TL = &volume_info->tile[tcd->tcd_tileno]; + info_TL->nbpix = tcd_tile->nbpix; + info_TL->distotile = tcd_tile->distotile; + info_TL->thresh = (double *) opj_malloc(tcd_tcp->numlayers * sizeof(double)); + } + /* dda */ + + for (layno = 0; layno < tcd_tcp->numlayers; layno++) { + double lo = min; + double hi = max; + int success = 0; + int maxlen = tcd_tcp->rates[layno] ? int_min(((int) tcd_tcp->rates[layno]), len) : len; + double goodthresh; + double distotarget; /* fixed_quality */ + int i = 0; + + /* fixed_quality */ + distotarget = tcd_tile->distotile - ((K * maxSE) / pow((float)10, tcd_tcp->distoratio[layno] / 10)); + + if ((tcd_tcp->rates[layno]) || (cp->disto_alloc==0)) { + opj_t2_t *t2 = t2_create(tcd->cinfo, tcd->volume, cp); + int oldl = 0, oldoldl = 0; + for (i = 0; i < 128; i++) { + double thresh = (lo + hi) / 2; + int l = 0; + double distoachieved = 0; /* fixed_quality -q */ + + tcd_makelayer(tcd, layno, thresh, 0); + + if (cp->fixed_quality) { /* fixed_quality -q */ + distoachieved = (layno == 0) ? tcd_tile->distolayer[0] : cumdisto[layno - 1] + tcd_tile->distolayer[layno]; + if (distoachieved < distotarget) { + hi = thresh; + continue; + } + lo = thresh; + } else { /* disto_alloc -r, fixed_alloc -f */ + l = t2_encode_packets(t2, tcd->tcd_tileno, tcd_tile, layno + 1, dest, maxlen, volume_info); + /*fprintf(stdout, "layno %d i %d len=%d max=%d \n",layno,i,l,maxlen);*/ + if (l == -999) { + lo = thresh; + continue; + } else if (l == oldl && oldl == oldoldl && tcd_tile->distolayer[layno] > 0.0 && i>32) + break; + hi = thresh; + oldoldl = oldl; + oldl = l; + } + success = 1; + goodthresh = thresh; + } + t2_destroy(t2); + } else { + success = 1; + goodthresh = min; + } + if (!success) { + return false; + } + + if(volume_info && volume_info->index_on) { /* Threshold for Marcela Index */ + volume_info->tile[tcd->tcd_tileno].thresh[layno] = goodthresh; + } + tcd_makelayer(tcd, layno, goodthresh, 1); + + /* fixed_quality */ + cumdisto[layno] = (layno == 0) ? tcd_tile->distolayer[0] : cumdisto[layno - 1] + tcd_tile->distolayer[layno]; + } + + return true; +} + +/* ----------------------------------------------------------------------- */ +int tcd_encode_tile(opj_tcd_t *tcd, int tileno, unsigned char *dest, int len, opj_volume_info_t * volume_info) { + int compno; + int l, i, npck = 0; + double encoding_time; + + opj_tcd_tile_t *tile = NULL; + opj_tcp_t *tcd_tcp = NULL; + opj_cp_t *cp = NULL; + + opj_tcp_t *tcp = &tcd->cp->tcps[0]; + opj_tccp_t *tccp = &tcp->tccps[0]; + opj_volume_t *volume = tcd->volume; + opj_t2_t *t2 = NULL; /* T2 component */ + + tcd->tcd_tileno = tileno; /* current encoded/decoded tile */ + + tcd->tcd_tile = tcd->tcd_volume->tiles; /* tile information */ + tile = tcd->tcd_tile; + + tcd->tcp = &tcd->cp->tcps[tileno]; /* coding/decoding params of tileno */ + tcd_tcp = tcd->tcp; + + cp = tcd->cp; /* coding parameters */ + + /* INDEX >> */ + if(volume_info && volume_info->index_on) { + opj_tcd_tilecomp_t *tilec_idx = &tile->comps[0]; /* based on component 0 */ + for (i = 0; i < tilec_idx->numresolution[0]; i++) { + opj_tcd_resolution_t *res_idx = &tilec_idx->resolutions[i]; + + volume_info->tile[tileno].prctno[0][i] = res_idx->prctno[0]; + volume_info->tile[tileno].prctno[1][i] = res_idx->prctno[1]; + volume_info->tile[tileno].prctno[2][i] = res_idx->prctno[2]; + + npck += res_idx->prctno[0] * res_idx->prctno[1] * res_idx->prctno[2]; + + volume_info->tile[tileno].prctsiz[0][i] = tccp->prctsiz[0][i]; + volume_info->tile[tileno].prctsiz[1][i] = tccp->prctsiz[1][i]; + volume_info->tile[tileno].prctsiz[2][i] = tccp->prctsiz[2][i]; + } + volume_info->tile[tileno].packet = (opj_packet_info_t *) opj_malloc(volume_info->comp * volume_info->layer * npck * sizeof(opj_packet_info_t)); + } + /* << INDEX */ + + /*---------------TILE-------------------*/ + encoding_time = opj_clock(); /* time needed to encode a tile */ + + for (compno = 0; compno < tile->numcomps; compno++) { + int x, y, z; + opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; + + int adjust; + int offset_x = int_ceildiv(volume->x0, volume->comps[compno].dx); /*ceil(x0 / subsampling_dx)*/ + int offset_y = int_ceildiv(volume->y0, volume->comps[compno].dy); + int offset_z = int_ceildiv(volume->z0, volume->comps[compno].dz); + + int tw = tilec->x1 - tilec->x0; + int w = int_ceildiv(volume->x1 - volume->x0, volume->comps[compno].dx); + int th = tilec->y1 - tilec->y0; + int h = int_ceildiv(volume->y1 - volume->y0, volume->comps[compno].dy); + int tl = tilec->z1 - tilec->z0; + int l = int_ceildiv(volume->z1 - volume->z0, volume->comps[compno].dz); + + + + /* extract tile data from volume.comps[0].data to tile.comps[0].data */ + /*fprintf(stdout,"[INFO] Extract tile data\n");*/ + if (tcd->cp->transform_format == TRF_3D_RLS || tcd->cp->transform_format == TRF_3D_LSE) { + adjust = 0; + } else { + adjust = volume->comps[compno].sgnd ? 0 : 1 << (volume->comps[compno].prec - 1); /*sign=='+' --> 2^(prec-1)*/ + if (volume->comps[compno].dcoffset != 0){ + adjust += volume->comps[compno].dcoffset; + fprintf(stdout,"[INFO] DC Offset applied: DCO = %d -> adjust = %d\n",volume->comps[compno].dcoffset,adjust); + } + } + + if (tcd_tcp->tccps[compno].reversible == 1) { /*IF perfect reconstruction (DWT.5-3)*/ + for (z = tilec->z0; z < tilec->z1; z++) { + for (y = tilec->y0; y < tilec->y1; y++) { + /* start of the src tile scanline */ + int *data = &volume->comps[compno].data[(tilec->x0 - offset_x) + (y - offset_y) * w + (z - offset_z) * w * h]; + /* start of the dst tile scanline */ + int *tile_data = &tilec->data[(y - tilec->y0) * tw + (z - tilec->z0) * tw * th]; + for (x = tilec->x0; x < tilec->x1; x++) { + *tile_data++ = *data++ - adjust; + } + } + } + } else if (tcd_tcp->tccps[compno].reversible == 0) { /*IF not (DWT.9-7)*/ + for (z = tilec->z0; z < tilec->z1; z++) { + for (y = tilec->y0; y < tilec->y1; y++) { + /* start of the src tile scanline */ + int *data = &volume->comps[compno].data[(tilec->x0 - offset_x) + (y - offset_y) * w + (z - offset_z) * w * h]; + /* start of the dst tile scanline */ + int *tile_data = &tilec->data[(y - tilec->y0) * tw + (z - tilec->z0) * tw * th]; + for (x = tilec->x0; x < tilec->x1; x++) { + *tile_data++ = (*data++ - adjust) << 13; + } + } + } + } + + } + + /*----------------MCT-------------------*/ + if (tcd_tcp->mct) { + int samples = (tile->comps[0].x1 - tile->comps[0].x0) * (tile->comps[0].y1 - tile->comps[0].y0) * (tile->comps[0].z1 - tile->comps[0].z0); + fprintf(stdout,"[INFO] Tcd_encode_tile: mct\n"); + if (tcd_tcp->tccps[0].reversible == 0) { + mct_encode_real(tile->comps[0].data, tile->comps[1].data, tile->comps[2].data, samples); + } else { + mct_encode(tile->comps[0].data, tile->comps[1].data, tile->comps[2].data, samples); + } + } + /*----------------TRANSFORM---------------------------------*/ + fprintf(stdout,"[INFO] Tcd_encode_tile: Transform\n"); + for (compno = 0; compno < tile->numcomps; compno++) { + opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; + dwt_encode(tilec, tcd_tcp->tccps[compno].dwtid); + } + + /*-------------------ENTROPY CODING-----------------------------*/ + fprintf(stdout,"[INFO] Tcd_encode_tile: Entropy coding\n"); + if ((cp->encoding_format == ENCOD_2EB)||(cp->encoding_format == ENCOD_3EB)) + { + if (cp->encoding_format == ENCOD_2EB) { + opj_t1_t *t1 = NULL; + t1 = t1_create(tcd->cinfo); + t1_encode_cblks(t1, tile, tcd_tcp); + t1_destroy(t1); + } else if (cp->encoding_format == ENCOD_3EB) { + opj_t1_3d_t *t1 = NULL; + t1 = t1_3d_create(tcd->cinfo); + t1_3d_encode_cblks(t1, tile, tcd_tcp); + t1_3d_destroy(t1); + } + /*-----------RATE-ALLOCATE------------------*/ + /* INDEX */ + if(volume_info) { + volume_info->index_write = 0; + } + if (cp->disto_alloc || cp->fixed_quality) { + fprintf(stdout,"[INFO] Tcd_encode_tile: Rate-allocate\n"); + tcd_rateallocate(tcd, dest, len, volume_info); /* Normal Rate/distortion allocation */ + } else {/* fixed_alloc */ + fprintf(stdout,"[INFO] Tcd_encode_tile: Rate-allocate fixed\n"); + tcd_rateallocate_fixed(tcd); /* Fixed layer allocation */ + } + + /*--------------TIER2------------------*/ + /* INDEX */ + if(volume_info) { + volume_info->index_write = 1; + } + fprintf(stdout,"[INFO] Tcd_encode_tile: Tier - 2\n"); + t2 = t2_create(tcd->cinfo, volume, cp); + l = t2_encode_packets(t2, tileno, tile, tcd_tcp->numlayers, dest, len, volume_info); + t2_destroy(t2); + } else if ((cp->encoding_format == ENCOD_2GR)||(cp->encoding_format == ENCOD_3GR)) { + /*if(volume_info) { + volume_info->index_write = 1; + } + gr = golomb_create(tcd->cinfo, volume, cp); + l = golomb_encode(gr, tileno, tile, dest, len, volume_info); + golomb_destroy(gr);*/ + } + + + /*---------------CLEAN-------------------*/ + fprintf(stdout,"[INFO] Tcd_encode_tile: %d bytes coded\n",l); + encoding_time = opj_clock() - encoding_time; + opj_event_msg(tcd->cinfo, EVT_INFO, "- tile encoded in %f s\n", encoding_time); + + /* cleaning memory */ + for (compno = 0; compno < tile->numcomps; compno++) { + tcd->tilec = &tile->comps[compno]; + opj_free(tcd->tilec->data); + } + + if (l == -999){ + fprintf(stdout,"[ERROR] Unable to perform T2 tier. Return -999.\n"); + return 0; + } + + return l; +} + + +bool tcd_decode_tile(opj_tcd_t *tcd, unsigned char *src, int len, int tileno) { + int l, i; + int compno, eof = 0; + double tile_time, t1_time, dwt_time; + + opj_tcd_tile_t *tile = NULL; + opj_t2_t *t2 = NULL; /* T2 component */ + + tcd->tcd_tileno = tileno; + tcd->tcd_tile = &(tcd->tcd_volume->tiles[tileno]); + tcd->tcp = &(tcd->cp->tcps[tileno]); + tile = tcd->tcd_tile; + + tile_time = opj_clock(); /* time needed to decode a tile */ + opj_event_msg(tcd->cinfo, EVT_INFO, "tile %d / %d\n", tileno + 1, tcd->cp->tw * tcd->cp->th * tcd->cp->tl); + + if ((tcd->cp->encoding_format == ENCOD_2EB) || (tcd->cp->encoding_format == ENCOD_3EB)) { + /*--------------TIER2------------------*/ + t2 = t2_create(tcd->cinfo, tcd->volume, tcd->cp); + l = t2_decode_packets(t2, src, len, tileno, tile); + t2_destroy(t2); + opj_event_msg(tcd->cinfo, EVT_INFO, "Tcd_decode_tile: %d bytes decoded\n",l); + + if (l == -999) { + eof = 1; + opj_event_msg(tcd->cinfo, EVT_ERROR, "Tcd_decode_tile: incomplete bistream\n"); + } + + /*------------------TIER1-----------------*/ + opj_event_msg(tcd->cinfo, EVT_INFO, "Tcd_decode_tile: Entropy decoding %d \n",tcd->cp->encoding_format); + t1_time = opj_clock(); /* time needed to decode a tile */ + if (tcd->cp->encoding_format == ENCOD_2EB) { + opj_t1_t *t1 = NULL; /* T1 component */ + t1 = t1_create(tcd->cinfo); + t1_decode_cblks(t1, tile, tcd->tcp); + t1_destroy(t1); + }else if (tcd->cp->encoding_format == ENCOD_3EB) { + opj_t1_3d_t *t1 = NULL; /* T1 component */ + t1 = t1_3d_create(tcd->cinfo); + t1_3d_decode_cblks(t1, tile, tcd->tcp); + t1_3d_destroy(t1); + } + + t1_time = opj_clock() - t1_time; + #ifdef VERBOSE + opj_event_msg(tcd->cinfo, EVT_INFO, "- tier-1 took %f s\n", t1_time); + #endif + } else if ((tcd->cp->encoding_format == ENCOD_2GR)||(tcd->cp->encoding_format == ENCOD_3GR)) { + opj_event_msg(tcd->cinfo, EVT_INFO, "Tcd_decode_tile: Entropy decoding -- Does nothing :-D\n"); + /* + gr = golomb_create(tcd->cinfo, tcd->volume, tcd->cp); + l = golomb_decode(gr, tileno, tile, src, len); + golomb_destroy(gr); + if (l == -999) { + eof = 1; + opj_event_msg(tcd->cinfo, EVT_ERROR, "Tcd_decode_tile: incomplete bistream\n"); + } + */ + } + + /*----------------DWT---------------------*/ + fprintf(stdout,"[INFO] Tcd_decode_tile: Inverse DWT\n"); + dwt_time = opj_clock(); /* time needed to decode a tile */ + for (compno = 0; compno < tile->numcomps; compno++) { + opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; + int stops[3], dwtid[3]; + + for (i = 0; i < 3; i++) { + if (tcd->cp->reduce[i] != 0) + tcd->volume->comps[compno].resno_decoded[i] = tile->comps[compno].numresolution[i] - tcd->cp->reduce[i] - 1; + stops[i] = tilec->numresolution[i] - 1 - tcd->volume->comps[compno].resno_decoded[i]; + if (stops[i] < 0) stops[i]=0; + dwtid[i] = tcd->cp->tcps->tccps[compno].dwtid[i]; + } + + dwt_decode(tilec, stops, dwtid); + + for (i = 0; i < 3; i++) { + if (tile->comps[compno].numresolution[i] > 0) { + tcd->volume->comps[compno].factor[i] = tile->comps[compno].numresolution[i] - (tcd->volume->comps[compno].resno_decoded[i] + 1); + if ( (tcd->volume->comps[compno].factor[i]) < 0 ) + tcd->volume->comps[compno].factor[i] = 0; + } + } + } + dwt_time = opj_clock() - dwt_time; + #ifdef VERBOSE + opj_event_msg(tcd->cinfo, EVT_INFO, "- dwt took %f s\n", dwt_time); + #endif + + /*----------------MCT-------------------*/ + + if (tcd->tcp->mct) { + if (tcd->tcp->tccps[0].reversible == 1) { + mct_decode(tile->comps[0].data, tile->comps[1].data, tile->comps[2].data, + (tile->comps[0].x1 - tile->comps[0].x0) * (tile->comps[0].y1 - tile->comps[0].y0) * (tile->comps[0].z1 - tile->comps[0].z0)); + } else { + mct_decode_real(tile->comps[0].data, tile->comps[1].data, tile->comps[2].data, + (tile->comps[0].x1 - tile->comps[0].x0) * (tile->comps[0].y1 - tile->comps[0].y0)* (tile->comps[0].z1 - tile->comps[0].z0)); + } + } + + /*---------------TILE-------------------*/ + + for (compno = 0; compno < tile->numcomps; compno++) { + opj_tcd_tilecomp_t *tilec = &tile->comps[compno]; + opj_tcd_resolution_t *res = &tilec->resolutions[tcd->volume->comps[compno].resno_decoded[0]]; + int adjust; + int minval = tcd->volume->comps[compno].sgnd ? -(1 << (tcd->volume->comps[compno].prec - 1)) : 0; + int maxval = tcd->volume->comps[compno].sgnd ? (1 << (tcd->volume->comps[compno].prec - 1)) - 1 : (1 << tcd->volume->comps[compno].prec) - 1; + + int tw = tilec->x1 - tilec->x0; + int w = tcd->volume->comps[compno].w; + int th = tilec->y1 - tilec->y0; + int h = tcd->volume->comps[compno].h; + + int i, j, k; + int offset_x = int_ceildivpow2(tcd->volume->comps[compno].x0, tcd->volume->comps[compno].factor[0]); + int offset_y = int_ceildivpow2(tcd->volume->comps[compno].y0, tcd->volume->comps[compno].factor[1]); + int offset_z = int_ceildivpow2(tcd->volume->comps[compno].z0, tcd->volume->comps[compno].factor[2]); + + if (tcd->cp->transform_format == TRF_3D_RLS || tcd->cp->transform_format == TRF_3D_LSE) { + adjust = 0; + } else { + adjust = tcd->volume->comps[compno].sgnd ? 0 : 1 << (tcd->volume->comps[compno].prec - 1); /*sign=='+' --> 2^(prec-1)*/ + if (tcd->volume->comps[compno].dcoffset != 0){ + adjust += tcd->volume->comps[compno].dcoffset; + fprintf(stdout,"[INFO] DC Offset applied: DCO = %d -> adjust = %d\n",tcd->volume->comps[compno].dcoffset,adjust); + } + } + + for (k = res->z0; k < res->z1; k++) { + for (j = res->y0; j < res->y1; j++) { + for (i = res->x0; i < res->x1; i++) { + int v; + float tmp = (float)((tilec->data[i - res->x0 + (j - res->y0) * tw + (k - res->z0) * tw * th]) / 8192.0); + + if (tcd->tcp->tccps[compno].reversible == 1) { + v = tilec->data[i - res->x0 + (j - res->y0) * tw + (k - res->z0) * tw * th]; + } else { + int tmp2 = ((int) (floor(fabs(tmp)))) + ((int) floor(fabs(tmp*2))%2); + v = ((tmp < 0) ? -tmp2:tmp2); + } + v += adjust; + + tcd->volume->comps[compno].data[(i - offset_x) + (j - offset_y) * w + (k - offset_z) * w * h] = int_clamp(v, minval, maxval); + } + } + } + } + + tile_time = opj_clock() - tile_time; /* time needed to decode a tile */ + opj_event_msg(tcd->cinfo, EVT_INFO, "- tile decoded in %f s\n", tile_time); + + for (compno = 0; compno < tile->numcomps; compno++) { + opj_free(tcd->tcd_volume->tiles[tileno].comps[compno].data); + tcd->tcd_volume->tiles[tileno].comps[compno].data = NULL; + } + + if (eof) { + return false; + } + + return true; +} + diff --git a/src/lib/openjp3d/tgt.c b/src/lib/openjp3d/tgt.c index c86cfe6d..8792995e 100644 --- a/src/lib/openjp3d/tgt.c +++ b/src/lib/openjp3d/tgt.c @@ -1,251 +1,251 @@ -/* - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "opj_includes.h" - -/* -========================================================== - Tag-tree coder interface -========================================================== -*/ -void tgt_tree_dump (FILE *fd, opj_tgt_tree_t * tree){ - int nodesno; - - fprintf(fd, "TGT_TREE {\n"); - fprintf(fd, " numnodes: %d \n", tree->numnodes); - fprintf(fd, " numleafsh: %d, numleafsv: %d, numleafsz: %d,\n", tree->numleafsh, tree->numleafsv, tree->numleafsz); - - for (nodesno = 0; nodesno < tree->numnodes; nodesno++) { - fprintf(fd, "tgt_node %d {\n", nodesno); - fprintf(fd, " value: %d \n", tree->nodes[nodesno].value); - fprintf(fd, " low: %d \n", tree->nodes[nodesno].low); - fprintf(fd, " known: %d \n", tree->nodes[nodesno].known); - if (tree->nodes[nodesno].parent) { - fprintf(fd, " parent.value: %d \n", tree->nodes[nodesno].parent->value); - fprintf(fd, " parent.low: %d \n", tree->nodes[nodesno].parent->low); - fprintf(fd, " parent.known: %d \n", tree->nodes[nodesno].parent->known); - } - fprintf(fd, "}\n"); - - } - fprintf(fd, "}\n"); - -} - - -opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv, int numleafsz) { - - int nplh[32]; - int nplv[32]; - int nplz[32]; - opj_tgt_node_t *node = NULL; - opj_tgt_node_t *parentnode = NULL; - opj_tgt_node_t *parentnode0 = NULL; - opj_tgt_node_t *parentnode1 = NULL; - opj_tgt_tree_t *tree = NULL; - int i, j, k, p, p0; - int numlvls; - int n, z = 0; - - tree = (opj_tgt_tree_t *) opj_malloc(sizeof(opj_tgt_tree_t)); - if(!tree) - return NULL; - tree->numleafsh = numleafsh; - tree->numleafsv = numleafsv; - tree->numleafsz = numleafsz; - - numlvls = 0; - nplh[0] = numleafsh; - nplv[0] = numleafsv; - nplz[0] = numleafsz; - tree->numnodes = 0; - do { - n = nplh[numlvls] * nplv[numlvls] * nplz[numlvls]; - nplh[numlvls + 1] = (nplh[numlvls] + 1) / 2; - nplv[numlvls + 1] = (nplv[numlvls] + 1) / 2; - nplz[numlvls + 1] = (nplz[numlvls] + 1) / 2; - tree->numnodes += n; - ++numlvls; - } while (n > 1); - - if (tree->numnodes == 0) { - opj_free(tree); - return NULL; - } - - tree->nodes = (opj_tgt_node_t *) opj_malloc(tree->numnodes * sizeof(opj_tgt_node_t)); - if(!tree->nodes) { - opj_free(tree); - return NULL; - } - - node = tree->nodes; - parentnode = &tree->nodes[tree->numleafsh * tree->numleafsv * tree->numleafsz]; - parentnode0 = parentnode; - parentnode1 = parentnode; - /*fprintf(stdout,"\nH %d V %d Z %d numlvls %d nodes %d\n",tree->numleafsh,tree->numleafsv,tree->numleafsz,numlvls,tree->numnodes);*/ - for (i = 0; i < numlvls - 1; ++i) { - for (z = 0; z < nplz[i]; ++z) { - for (j = 0; j < nplv[i]; ++j) { - k = nplh[i]; - while(--k >= 0) { - node->parent = parentnode; /*fprintf(stdout,"node[%d].parent = node[%d]\n",n,p);*/ - ++node; - if(--k >= 0) { - node->parent = parentnode; /*fprintf(stdout,"node[%d].parent = node[%d]\n",n,p);*/ - ++node; - } - ++parentnode; - } - if((j & 1) || j == nplv[i] - 1) { - parentnode0 = parentnode; - } else { - parentnode = parentnode0; - } - } - if ((z & 1) || z == nplz[i] - 1) { - parentnode1 = parentnode; - } else { - parentnode0 = parentnode1; - parentnode = parentnode1; - } - } - } - node->parent = 0; - - - tgt_reset(tree); - - return tree; -} - -void tgt_destroy(opj_tgt_tree_t *tree) { - opj_free(tree->nodes); - opj_free(tree); -} - -void tgt_reset(opj_tgt_tree_t *tree) { - int i; - - if (NULL == tree) - return; - - for (i = 0; i < tree->numnodes; i++) { - tree->nodes[i].value = 999; - tree->nodes[i].low = 0; - tree->nodes[i].known = 0; - } -} - -void tgt_setvalue(opj_tgt_tree_t *tree, int leafno, int value) { - opj_tgt_node_t *node; - node = &tree->nodes[leafno]; - while (node && node->value > value) { - node->value = value; - node = node->parent; - } -} - -void tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold) { - opj_tgt_node_t *stk[31]; - opj_tgt_node_t **stkptr; - opj_tgt_node_t *node; - int low; - - stkptr = stk; - node = &tree->nodes[leafno]; - while (node->parent) { - *stkptr++ = node; - node = node->parent; - } - - low = 0; - for (;;) { - if (low > node->low) { - node->low = low; - } else { - low = node->low; - } - - while (low < threshold) { - if (low >= node->value) { - if (!node->known) { - bio_write(bio, 1, 1); - node->known = 1; - } - break; - } - bio_write(bio, 0, 1); - ++low; - } - - node->low = low; - if (stkptr == stk) - break; - node = *--stkptr; - } -} - -int tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold) { - opj_tgt_node_t *stk[31]; - opj_tgt_node_t **stkptr; - opj_tgt_node_t *node; - int low; - - stkptr = stk; - node = &tree->nodes[leafno]; - while (node->parent) { - *stkptr++ = node; - node = node->parent; - } - - low = 0; - for (;;) { - if (low > node->low) { - node->low = low; - } else { - low = node->low; - } - while (low < threshold && low < node->value) { - if (bio_read(bio, 1)) { - node->value = low; - } else { - ++low; - } - } - node->low = low; - if (stkptr == stk) { - break; - } - node = *--stkptr; - } - - return (node->value < threshold) ? 1 : 0; -} +/* + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opj_includes.h" + +/* +========================================================== + Tag-tree coder interface +========================================================== +*/ +void tgt_tree_dump (FILE *fd, opj_tgt_tree_t * tree){ + int nodesno; + + fprintf(fd, "TGT_TREE {\n"); + fprintf(fd, " numnodes: %d \n", tree->numnodes); + fprintf(fd, " numleafsh: %d, numleafsv: %d, numleafsz: %d,\n", tree->numleafsh, tree->numleafsv, tree->numleafsz); + + for (nodesno = 0; nodesno < tree->numnodes; nodesno++) { + fprintf(fd, "tgt_node %d {\n", nodesno); + fprintf(fd, " value: %d \n", tree->nodes[nodesno].value); + fprintf(fd, " low: %d \n", tree->nodes[nodesno].low); + fprintf(fd, " known: %d \n", tree->nodes[nodesno].known); + if (tree->nodes[nodesno].parent) { + fprintf(fd, " parent.value: %d \n", tree->nodes[nodesno].parent->value); + fprintf(fd, " parent.low: %d \n", tree->nodes[nodesno].parent->low); + fprintf(fd, " parent.known: %d \n", tree->nodes[nodesno].parent->known); + } + fprintf(fd, "}\n"); + + } + fprintf(fd, "}\n"); + +} + + +opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv, int numleafsz) { + + int nplh[32]; + int nplv[32]; + int nplz[32]; + opj_tgt_node_t *node = NULL; + opj_tgt_node_t *parentnode = NULL; + opj_tgt_node_t *parentnode0 = NULL; + opj_tgt_node_t *parentnode1 = NULL; + opj_tgt_tree_t *tree = NULL; + int i, j, k, p, p0; + int numlvls; + int n, z = 0; + + tree = (opj_tgt_tree_t *) opj_malloc(sizeof(opj_tgt_tree_t)); + if(!tree) + return NULL; + tree->numleafsh = numleafsh; + tree->numleafsv = numleafsv; + tree->numleafsz = numleafsz; + + numlvls = 0; + nplh[0] = numleafsh; + nplv[0] = numleafsv; + nplz[0] = numleafsz; + tree->numnodes = 0; + do { + n = nplh[numlvls] * nplv[numlvls] * nplz[numlvls]; + nplh[numlvls + 1] = (nplh[numlvls] + 1) / 2; + nplv[numlvls + 1] = (nplv[numlvls] + 1) / 2; + nplz[numlvls + 1] = (nplz[numlvls] + 1) / 2; + tree->numnodes += n; + ++numlvls; + } while (n > 1); + + if (tree->numnodes == 0) { + opj_free(tree); + return NULL; + } + + tree->nodes = (opj_tgt_node_t *) opj_malloc(tree->numnodes * sizeof(opj_tgt_node_t)); + if(!tree->nodes) { + opj_free(tree); + return NULL; + } + + node = tree->nodes; + parentnode = &tree->nodes[tree->numleafsh * tree->numleafsv * tree->numleafsz]; + parentnode0 = parentnode; + parentnode1 = parentnode; + /*fprintf(stdout,"\nH %d V %d Z %d numlvls %d nodes %d\n",tree->numleafsh,tree->numleafsv,tree->numleafsz,numlvls,tree->numnodes);*/ + for (i = 0; i < numlvls - 1; ++i) { + for (z = 0; z < nplz[i]; ++z) { + for (j = 0; j < nplv[i]; ++j) { + k = nplh[i]; + while(--k >= 0) { + node->parent = parentnode; /*fprintf(stdout,"node[%d].parent = node[%d]\n",n,p);*/ + ++node; + if(--k >= 0) { + node->parent = parentnode; /*fprintf(stdout,"node[%d].parent = node[%d]\n",n,p);*/ + ++node; + } + ++parentnode; + } + if((j & 1) || j == nplv[i] - 1) { + parentnode0 = parentnode; + } else { + parentnode = parentnode0; + } + } + if ((z & 1) || z == nplz[i] - 1) { + parentnode1 = parentnode; + } else { + parentnode0 = parentnode1; + parentnode = parentnode1; + } + } + } + node->parent = 0; + + + tgt_reset(tree); + + return tree; +} + +void tgt_destroy(opj_tgt_tree_t *tree) { + opj_free(tree->nodes); + opj_free(tree); +} + +void tgt_reset(opj_tgt_tree_t *tree) { + int i; + + if (NULL == tree) + return; + + for (i = 0; i < tree->numnodes; i++) { + tree->nodes[i].value = 999; + tree->nodes[i].low = 0; + tree->nodes[i].known = 0; + } +} + +void tgt_setvalue(opj_tgt_tree_t *tree, int leafno, int value) { + opj_tgt_node_t *node; + node = &tree->nodes[leafno]; + while (node && node->value > value) { + node->value = value; + node = node->parent; + } +} + +void tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold) { + opj_tgt_node_t *stk[31]; + opj_tgt_node_t **stkptr; + opj_tgt_node_t *node; + int low; + + stkptr = stk; + node = &tree->nodes[leafno]; + while (node->parent) { + *stkptr++ = node; + node = node->parent; + } + + low = 0; + for (;;) { + if (low > node->low) { + node->low = low; + } else { + low = node->low; + } + + while (low < threshold) { + if (low >= node->value) { + if (!node->known) { + bio_write(bio, 1, 1); + node->known = 1; + } + break; + } + bio_write(bio, 0, 1); + ++low; + } + + node->low = low; + if (stkptr == stk) + break; + node = *--stkptr; + } +} + +int tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold) { + opj_tgt_node_t *stk[31]; + opj_tgt_node_t **stkptr; + opj_tgt_node_t *node; + int low; + + stkptr = stk; + node = &tree->nodes[leafno]; + while (node->parent) { + *stkptr++ = node; + node = node->parent; + } + + low = 0; + for (;;) { + if (low > node->low) { + node->low = low; + } else { + low = node->low; + } + while (low < threshold && low < node->value) { + if (bio_read(bio, 1)) { + node->value = low; + } else { + ++low; + } + } + node->low = low; + if (stkptr == stk) { + break; + } + node = *--stkptr; + } + + return (node->value < threshold) ? 1 : 0; +} diff --git a/src/lib/openjp3d/tgt.h b/src/lib/openjp3d/tgt.h index 2b54baf9..4565ad22 100644 --- a/src/lib/openjp3d/tgt.h +++ b/src/lib/openjp3d/tgt.h @@ -1,125 +1,125 @@ -/* - * Copyright (c) 2001-2003, David Janssens - * Copyright (c) 2002-2003, Yannick Verschueren - * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __TGT_H -#define __TGT_H -/** -@file tgt.h -@brief Implementation of a tag-tree coder (TGT) - -The functions in TGT.C have for goal to realize a tag-tree coder. The functions in TGT.C -are used by some function in T2.C. -*/ - -/** @defgroup TGT TGT - Implementation of a tag-tree coder */ -/*@{*/ - -/** -Tag node -*/ -typedef struct opj_tgt_node { -/** Node parent reference */ - struct opj_tgt_node *parent; -/** */ - int value; -/** */ - int low; -/** */ - int known; -} opj_tgt_node_t; - -/** -Tag tree -*/ -typedef struct opj_tgt_tree { -/** Number of leaves from horizontal axis */ - int numleafsh; -/** Number of leaves from vertical axis */ - int numleafsv; -/** Number of leaves from axial axis */ - int numleafsz; -/** Number of nodes */ - int numnodes; -/** Reference to each node instance */ - opj_tgt_node_t *nodes; -} opj_tgt_tree_t; - -/** @name Funciones generales */ -/*@{*/ -/* ----------------------------------------------------------------------- */ -/** -Create a tag-tree -@param numleafsh Width of the array of leafs of the tree -@param numleafsv Height of the array of leafs of the tree -@param numleafsz Depth of the array of leafs of the tree -@return Returns a new tag-tree if successful, returns NULL otherwise -*/ -opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv, int numleafsz); -/** -Destroy a tag-tree, liberating memory -@param tree Tag-tree to destroy -*/ -void tgt_destroy(opj_tgt_tree_t *tree); -/** -Reset a tag-tree (set all leaves to 0) -@param tree Tag-tree to reset -*/ -void tgt_reset(opj_tgt_tree_t *tree); -/** -Set the value of a leaf of a tag-tree -@param tree Tag-tree to modify -@param leafno Number that identifies the leaf to modify -@param value New value of the leaf -*/ -void tgt_setvalue(opj_tgt_tree_t *tree, int leafno, int value); -/** -Encode the value of a leaf of the tag-tree up to a given threshold -@param bio Pointer to a BIO handle -@param tree Tag-tree to modify -@param leafno Number that identifies the leaf to encode -@param threshold Threshold to use when encoding value of the leaf -*/ -void tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold); -/** -Decode the value of a leaf of the tag-tree up to a given threshold -@param bio Pointer to a BIO handle -@param tree Tag-tree to decode -@param leafno Number that identifies the leaf to decode -@param threshold Threshold to use when decoding value of the leaf -@return Returns 1 if the node's value < threshold, returns 0 otherwise -*/ -int tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold); - -/*@}*/ -/* ----------------------------------------------------------------------- */ -void tgt_tree_dump (FILE *fd, opj_tgt_tree_t * tree); -/*@}*/ - -#endif /* __TGT_H */ +/* + * Copyright (c) 2001-2003, David Janssens + * Copyright (c) 2002-2003, Yannick Verschueren + * Copyright (c) 2003-2005, Francois Devaux and Antonin Descampe + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2002-2005, Communications and remote sensing Laboratory, Universite catholique de Louvain, Belgium + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef __TGT_H +#define __TGT_H +/** +@file tgt.h +@brief Implementation of a tag-tree coder (TGT) + +The functions in TGT.C have for goal to realize a tag-tree coder. The functions in TGT.C +are used by some function in T2.C. +*/ + +/** @defgroup TGT TGT - Implementation of a tag-tree coder */ +/*@{*/ + +/** +Tag node +*/ +typedef struct opj_tgt_node { +/** Node parent reference */ + struct opj_tgt_node *parent; +/** */ + int value; +/** */ + int low; +/** */ + int known; +} opj_tgt_node_t; + +/** +Tag tree +*/ +typedef struct opj_tgt_tree { +/** Number of leaves from horizontal axis */ + int numleafsh; +/** Number of leaves from vertical axis */ + int numleafsv; +/** Number of leaves from axial axis */ + int numleafsz; +/** Number of nodes */ + int numnodes; +/** Reference to each node instance */ + opj_tgt_node_t *nodes; +} opj_tgt_tree_t; + +/** @name Funciones generales */ +/*@{*/ +/* ----------------------------------------------------------------------- */ +/** +Create a tag-tree +@param numleafsh Width of the array of leafs of the tree +@param numleafsv Height of the array of leafs of the tree +@param numleafsz Depth of the array of leafs of the tree +@return Returns a new tag-tree if successful, returns NULL otherwise +*/ +opj_tgt_tree_t *tgt_create(int numleafsh, int numleafsv, int numleafsz); +/** +Destroy a tag-tree, liberating memory +@param tree Tag-tree to destroy +*/ +void tgt_destroy(opj_tgt_tree_t *tree); +/** +Reset a tag-tree (set all leaves to 0) +@param tree Tag-tree to reset +*/ +void tgt_reset(opj_tgt_tree_t *tree); +/** +Set the value of a leaf of a tag-tree +@param tree Tag-tree to modify +@param leafno Number that identifies the leaf to modify +@param value New value of the leaf +*/ +void tgt_setvalue(opj_tgt_tree_t *tree, int leafno, int value); +/** +Encode the value of a leaf of the tag-tree up to a given threshold +@param bio Pointer to a BIO handle +@param tree Tag-tree to modify +@param leafno Number that identifies the leaf to encode +@param threshold Threshold to use when encoding value of the leaf +*/ +void tgt_encode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold); +/** +Decode the value of a leaf of the tag-tree up to a given threshold +@param bio Pointer to a BIO handle +@param tree Tag-tree to decode +@param leafno Number that identifies the leaf to decode +@param threshold Threshold to use when decoding value of the leaf +@return Returns 1 if the node's value < threshold, returns 0 otherwise +*/ +int tgt_decode(opj_bio_t *bio, opj_tgt_tree_t *tree, int leafno, int threshold); + +/*@}*/ +/* ----------------------------------------------------------------------- */ +void tgt_tree_dump (FILE *fd, opj_tgt_tree_t * tree); +/*@}*/ + +#endif /* __TGT_H */ diff --git a/src/lib/openjp3d/volume.c b/src/lib/openjp3d/volume.c index 065a7a34..669b613b 100644 --- a/src/lib/openjp3d/volume.c +++ b/src/lib/openjp3d/volume.c @@ -1,91 +1,91 @@ -/* - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ - -#include "opj_includes.h" -#include "volume.h" -#include "openjp3d.h" - -opj_volume_t* OPJ_CALLCONV opj_volume_create(int numcmpts, opj_volume_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) { - int compno; - opj_volume_t *volume = NULL; - - volume = (opj_volume_t*)opj_malloc(sizeof(opj_volume_t)); - if(volume) { - volume->color_space = clrspc; - volume->numcomps = numcmpts; - /* allocate memory for the per-component information */ - volume->comps = (opj_volume_comp_t*)opj_malloc(volume->numcomps * sizeof(opj_volume_comp_t)); - if(!volume->comps) { - opj_volume_destroy(volume); - return NULL; - } - /* create the individual volume components */ - for(compno = 0; compno < numcmpts; compno++) { - opj_volume_comp_t *comp = &volume->comps[compno]; - comp->dx = cmptparms[compno].dx; - comp->dy = cmptparms[compno].dy; - comp->dz = cmptparms[compno].dz; - comp->w = cmptparms[compno].w; - comp->h = cmptparms[compno].h; - comp->l = cmptparms[compno].l; - comp->x0 = cmptparms[compno].x0; - comp->y0 = cmptparms[compno].y0; - comp->z0 = cmptparms[compno].z0; - comp->prec = cmptparms[compno].prec; - comp->bpp = cmptparms[compno].bpp; - comp->sgnd = cmptparms[compno].sgnd; - comp->bigendian = cmptparms[compno].bigendian; - comp->dcoffset = cmptparms[compno].dcoffset; - comp->data = (int*)opj_malloc(comp->w * comp->h * comp->l * sizeof(int)); - if(!comp->data) { - fprintf(stdout,"Unable to malloc comp->data (%d x %d x %d x bytes)",comp->w,comp->h,comp->l); - opj_volume_destroy(volume); - return NULL; - } - /*fprintf(stdout,"%d %d %d %d %d %d %d %d %d", comp->w,comp->h, comp->l, comp->dx, comp->dy, comp->dz, comp->prec, comp->bpp, comp->sgnd);*/ - } - } - - return volume; -} - -void OPJ_CALLCONV opj_volume_destroy(opj_volume_t *volume) { - int i; - if(volume) { - if(volume->comps) { - /* volume components */ - for(i = 0; i < volume->numcomps; i++) { - opj_volume_comp_t *volume_comp = &volume->comps[i]; - if(volume_comp->data) { - opj_free(volume_comp->data); - } - } - opj_free(volume->comps); - } - opj_free(volume); - } -} - +/* + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include "opj_includes.h" +#include "volume.h" +#include "openjp3d.h" + +opj_volume_t* OPJ_CALLCONV opj_volume_create(int numcmpts, opj_volume_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc) { + int compno; + opj_volume_t *volume = NULL; + + volume = (opj_volume_t*)opj_malloc(sizeof(opj_volume_t)); + if(volume) { + volume->color_space = clrspc; + volume->numcomps = numcmpts; + /* allocate memory for the per-component information */ + volume->comps = (opj_volume_comp_t*)opj_malloc(volume->numcomps * sizeof(opj_volume_comp_t)); + if(!volume->comps) { + opj_volume_destroy(volume); + return NULL; + } + /* create the individual volume components */ + for(compno = 0; compno < numcmpts; compno++) { + opj_volume_comp_t *comp = &volume->comps[compno]; + comp->dx = cmptparms[compno].dx; + comp->dy = cmptparms[compno].dy; + comp->dz = cmptparms[compno].dz; + comp->w = cmptparms[compno].w; + comp->h = cmptparms[compno].h; + comp->l = cmptparms[compno].l; + comp->x0 = cmptparms[compno].x0; + comp->y0 = cmptparms[compno].y0; + comp->z0 = cmptparms[compno].z0; + comp->prec = cmptparms[compno].prec; + comp->bpp = cmptparms[compno].bpp; + comp->sgnd = cmptparms[compno].sgnd; + comp->bigendian = cmptparms[compno].bigendian; + comp->dcoffset = cmptparms[compno].dcoffset; + comp->data = (int*)opj_malloc(comp->w * comp->h * comp->l * sizeof(int)); + if(!comp->data) { + fprintf(stdout,"Unable to malloc comp->data (%d x %d x %d x bytes)",comp->w,comp->h,comp->l); + opj_volume_destroy(volume); + return NULL; + } + /*fprintf(stdout,"%d %d %d %d %d %d %d %d %d", comp->w,comp->h, comp->l, comp->dx, comp->dy, comp->dz, comp->prec, comp->bpp, comp->sgnd);*/ + } + } + + return volume; +} + +void OPJ_CALLCONV opj_volume_destroy(opj_volume_t *volume) { + int i; + if(volume) { + if(volume->comps) { + /* volume components */ + for(i = 0; i < volume->numcomps; i++) { + opj_volume_comp_t *volume_comp = &volume->comps[i]; + if(volume_comp->data) { + opj_free(volume_comp->data); + } + } + opj_free(volume->comps); + } + opj_free(volume); + } +} + diff --git a/src/lib/openjp3d/volume.h b/src/lib/openjp3d/volume.h index 02f28d2a..a0cad370 100644 --- a/src/lib/openjp3d/volume.h +++ b/src/lib/openjp3d/volume.h @@ -1,43 +1,43 @@ -/* - * Copyright (c) 2005, Herve Drolon, FreeImage Team - * Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' - * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE - * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR - * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF - * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS - * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN - * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE - * POSSIBILITY OF SUCH DAMAGE. - */ -#ifndef __VOLUME_H -#define __VOLUME_H -/** -@file volume.h -@brief Implementation of operations on volumes (VOLUME) - -The functions in VOLUME.C have for goal to realize operations on volumes. -*/ - -/** @defgroup VOLUME VOLUME - Implementation of operations on volumes */ -/*@{*/ - - -/*@}*/ - -#endif /* __VOLUME_H */ - +/* + * Copyright (c) 2005, Herve Drolon, FreeImage Team + * Copyright (c) 2006, Mónica Díez García, Image Processing Laboratory, University of Valladolid, Spain + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __VOLUME_H +#define __VOLUME_H +/** +@file volume.h +@brief Implementation of operations on volumes (VOLUME) + +The functions in VOLUME.C have for goal to realize operations on volumes. +*/ + +/** @defgroup VOLUME VOLUME - Implementation of operations on volumes */ +/*@{*/ + + +/*@}*/ + +#endif /* __VOLUME_H */ + From ad1532ed57305368a85efcff0a4e6f17782b048d Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 3 Jan 2013 14:22:34 +0000 Subject: [PATCH 027/333] [trunk] JP3D: remove old debug --- src/lib/openjp3d/dwt.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/openjp3d/dwt.c b/src/lib/openjp3d/dwt.c index 6078ec1a..3d15d893 100644 --- a/src/lib/openjp3d/dwt.c +++ b/src/lib/openjp3d/dwt.c @@ -58,7 +58,7 @@ /** @name Local static functions */ /*@{*/ -unsigned int ops; +/*unsigned int ops;*/ /** Forward lazy transform (horizontal) */ @@ -668,7 +668,7 @@ void dwt_encode(opj_tcd_tilecomp_t * tilec, int dwtid[3]) { int *bj = NULL; int *cj = NULL; - ops = 0; + /*ops = 0;*/ memset(flagnorm,0,8000*sizeof(int)); w = tilec->x1-tilec->x0; From 44fb38949bfce15ec44f53b5cc2e057d48f94563 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 3 Jan 2013 14:25:49 +0000 Subject: [PATCH 028/333] [trunk] JP3D: Handles errors properly --- src/lib/openjp3d/cio.c | 1 + src/lib/openjp3d/t2.c | 1 + 2 files changed, 2 insertions(+) diff --git a/src/lib/openjp3d/cio.c b/src/lib/openjp3d/cio.c index 10bd2af3..7b2c5e4e 100644 --- a/src/lib/openjp3d/cio.c +++ b/src/lib/openjp3d/cio.c @@ -58,6 +58,7 @@ opj_cio_t* OPJ_CALLCONV opj_cio_open(opj_common_ptr cinfo, unsigned char *buffer cio->length = cp->tdx * cp->tdy * cp->tdz * cp->tw * cp->th * cp->tl * 4; cio->buffer = (unsigned char *)opj_malloc(cio->length); if(!cio->buffer) { + opj_event_msg(cio->cinfo, EVT_ERROR, "Error allocating memory for compressed bitstream\n"); opj_free(cio); return NULL; } diff --git a/src/lib/openjp3d/t2.c b/src/lib/openjp3d/t2.c index 7fd551e5..65d98c13 100644 --- a/src/lib/openjp3d/t2.c +++ b/src/lib/openjp3d/t2.c @@ -479,6 +479,7 @@ int t2_decode_packet(opj_t2_t* t2, unsigned char *src, int len, opj_tcd_tile_t * if (tcp->csty & J3D_CP_CSTY_EPH) { if ((*hd) != 0xff || (*(hd + 1) != 0x92)) { opj_event_msg(t2->cinfo, EVT_ERROR, "Expected EPH marker\n"); + return -999; } else { hd += 2; } From ccd448d626dcc8dde01053d7a98b4a28f76dd0c1 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 3 Jan 2013 14:26:38 +0000 Subject: [PATCH 029/333] [trunk] JP3D: Fix issue with Z handling in packet iterator --- src/lib/openjp3d/pi.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lib/openjp3d/pi.c b/src/lib/openjp3d/pi.c index 185d2620..44c7c529 100644 --- a/src/lib/openjp3d/pi.c +++ b/src/lib/openjp3d/pi.c @@ -358,13 +358,16 @@ static bool pi_next_cprl(opj_pi_iterator_t * pi) { comp = &pi->comps[pi->compno]; pi->dx = 0; pi->dy = 0; + pi->dz = 0; for (resno = 0; resno < comp->numresolution[0]; resno++) { - int dx, dy; + int dx, dy, dz; res = &comp->resolutions[resno]; dx = comp->dx * (1 << (res->pdx + comp->numresolution[0] - 1 - resno)); - dy = comp->dy * (1 << (res->pdy + comp->numresolution[0] - 1 - resno)); + dy = comp->dy * (1 << (res->pdy + comp->numresolution[1] - 1 - resno)); + dz = comp->dz * (1 << (res->pdz + comp->numresolution[2] - 1 - resno)); pi->dx = !pi->dx ? dx : int_min(pi->dx, dx); pi->dy = !pi->dy ? dy : int_min(pi->dy, dy); + pi->dz = !pi->dz ? dz : int_min(pi->dz, dz); } for (pi->z = pi->tz0; pi->z < pi->tz1; pi->z += pi->dz - (pi->z % pi->dz)) { for (pi->y = pi->ty0; pi->y < pi->ty1; pi->y += pi->dy - (pi->y % pi->dy)) { @@ -522,7 +525,7 @@ opj_pi_iterator_t *pi_create(opj_volume_t *volume, opj_cp_t *cp, int tileno) { } levelnox = comp->numresolution[0] - 1 - resno; levelnoy = comp->numresolution[1] - 1 - resno; - levelnoz = comp->numresolution[2] - 1 - resno; + levelnoz = comp->numresolution[2] - 1 - resno; if (levelnoz < 0) levelnoz = 0; diff = comp->numresolution[0] - comp->numresolution[2]; From 8b36a11f2b7dbfce859edba5d8b5cded15c5ed70 Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Sun, 3 Feb 2013 09:07:23 +0000 Subject: [PATCH 030/333] [trunk] backout one part of the rev 2266 --- 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 88372e23..fc77b5e4 100644 --- a/src/lib/openjp2/tcd.c +++ b/src/lib/openjp2/tcd.c @@ -1746,7 +1746,7 @@ void opj_tcd_code_block_enc_deallocate (opj_tcd_precinct_t * p_precinct) for (cblkno = 0; cblkno < l_nb_code_blocks; ++cblkno) { if (l_code_block->data) { - opj_free(l_code_block->data); + opj_free(l_code_block->data - 1); l_code_block->data = 00; } From 752e978d5670aced4ad2441f037450587b98b409 Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Sun, 3 Feb 2013 09:55:31 +0000 Subject: [PATCH 031/333] [trunk] update test suite for issue 5 and 62 --- tests/nonregression/test_suite.ctest.in | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index dc6fec52..b442050d 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -28,9 +28,10 @@ opj_compress -i @INPUT_NR_PATH@/Cevennes1.bmp -o @TEMP_PATH@/Cevennes1.j2k -r 10 opj_compress -i @INPUT_NR_PATH@/Cevennes2.ppm -o @TEMP_PATH@/Cevennes2.jp2 -r 50 opj_compress -i @INPUT_NR_PATH@/Rome.bmp -o @TEMP_PATH@/Rome.jp2 -q 30,35,50 -p LRCP -n 3 # related to issue 5 -opj_compress -i @INPUT_NR_PATH@/random.tif -o @TEMP_PATH@/random.tif.j2k +opj_compress -i @INPUT_NR_PATH@/random-issue-0005.tif -o @TEMP_PATH@/random-issue-0005.tif.j2k # related to issue 62 -opj_compress -i @INPUT_NR_PATH@/tmp.raw -o @TEMP_PATH@/tmp.raw.j2k -F 512,512,1,16,u +opj_compress -i @INPUT_NR_PATH@/tmp-issue-0062.raw -o @TEMP_PATH@/tmp-issue-0062-u.raw.j2k -F 512,512,1,16,u +opj_compress -i @INPUT_NR_PATH@/tmp-issue-0062.raw -o @TEMP_PATH@/tmp-issue-0062-s.raw.j2k -F 512,512,1,16,s opj_compress -i @INPUT_NR_PATH@/X_4_2K_24_185_CBR_WB_000.tif -o @TEMP_PATH@/X_4_2K_24_185_CBR_WB_000.j2k -cinema2K 24 opj_compress -i @INPUT_NR_PATH@/X_5_2K_24_235_CBR_STEM24_000.tif -o @TEMP_PATH@/X_5_2K_24_235_CBR_STEM24_000.j2k -cinema2K 24 opj_compress -i @INPUT_NR_PATH@/X_6_2K_24_FULL_CBR_CIRCLE_000.tif -o @TEMP_PATH@/X_6_2K_24_FULL_CBR_CIRCLE_000.j2k -cinema2K 24 From 0109b39f58e01918cdced718acc0ad0b1aa5bc0b Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Sun, 3 Feb 2013 10:18:10 +0000 Subject: [PATCH 032/333] [trunk] update convert about png writing with additional metadata (thanks winfried) --- src/bin/jp2/convert.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index dad3f8b0..98d900ad 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -3408,6 +3408,9 @@ int imagetopng(opj_image_t * image, const char *write_idf) color_type, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); + + png_set_gamma(png, 2.2, 1./2.2); + png_set_sRGB(png, info, PNG_sRGB_INTENT_PERCEPTUAL); /*=============================*/ png_write_info(png, info); /*=============================*/ @@ -3524,6 +3527,9 @@ int imagetopng(opj_image_t * image, const char *write_idf) PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); png_set_sBIT(png, info, &sig_bit); + + png_set_gamma(png, 2.2, 1./2.2); + png_set_sRGB(png, info, PNG_sRGB_INTENT_PERCEPTUAL); /*=============================*/ png_write_info(png, info); /*=============================*/ From a2aeafe85b9a39edb5ef4b74a486e8c162a69921 Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Mon, 4 Feb 2013 13:22:56 +0000 Subject: [PATCH 033/333] [trunk] add a test related to issue 202 --- tests/nonregression/test_suite.ctest.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index b442050d..13f66f45 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -87,6 +87,8 @@ opj_decompress -i @INPUT_NR_PATH@/mem-b2b86b74-2753.jp2 -o @TEMP_PATH@/mem-b2b8 !opj_decompress -i @INPUT_NR_PATH@/gdal_fuzzer_check_number_of_tiles.jp2 -o @TEMP_PATH@/gdal_fuzzer_check_number_of_tiles.pgx # issue 194 raised by the gdal fuzzer test (should nicely failed) ! opj_decompress -i @INPUT_NR_PATH@/gdal_fuzzer_check_comp_dx_dy.jp2 -o @TEMP_PATH@/gdal_fuzzer_check_comp_dx_dy.pgx +# issue 202 +opj_decompress -i @INPUT_NR_PATH@/file409752.jp2 -o @TEMP_PATH@/file409752.png # decode with specific area # prec=12; nb_c=1 From d5884afcf36c567a713fc0ee33e905e5361f6eaf Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Sat, 16 Feb 2013 17:20:55 +0000 Subject: [PATCH 034/333] [trunk] add functions to avoid to use FILE* into the API (thanks winfried). Update issue 120 and update issue 198 --- src/lib/openjp2/cio.c | 15 ++++++++++ src/lib/openjp2/openjpeg.c | 58 ++++++++++++++++++++++++++++++++------ src/lib/openjp2/openjpeg.h | 21 ++++++++++---- 3 files changed, 80 insertions(+), 14 deletions(-) diff --git a/src/lib/openjp2/cio.c b/src/lib/openjp2/cio.c index e6ba8362..8fce9812 100644 --- a/src/lib/openjp2/cio.c +++ b/src/lib/openjp2/cio.c @@ -195,6 +195,21 @@ void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream) } } +void OPJ_CALLCONV opj_stream_destroy_v3(opj_stream_t* p_stream) +{ + opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; + + if (l_stream) { + FILE *fp = (FILE*)l_stream->m_user_data; + if(fp) + fclose(fp); + + opj_free(l_stream->m_stored_data); + l_stream->m_stored_data = 00; + opj_free(l_stream); + } +} + void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, opj_stream_read_fn p_function) { opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; diff --git a/src/lib/openjp2/openjpeg.c b/src/lib/openjp2/openjpeg.c index 0ed7e67a..ec9746f7 100644 --- a/src/lib/openjp2/openjpeg.c +++ b/src/lib/openjp2/openjpeg.c @@ -1037,6 +1037,11 @@ opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file, return opj_stream_create_file_stream(p_file,OPJ_J2K_STREAM_CHUNK_SIZE,p_is_read_stream); } +opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream_v3 (const char *fname, OPJ_BOOL p_is_read_stream) +{ + return opj_stream_create_file_stream_v3(fname, OPJ_J2K_STREAM_CHUNK_SIZE, p_is_read_stream); +} + opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream ( FILE * p_file, OPJ_SIZE_T p_size, OPJ_BOOL p_is_read_stream) @@ -1052,12 +1057,49 @@ opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream ( FILE * p_file, return NULL; } - opj_stream_set_user_data(l_stream, p_file); - opj_stream_set_user_data_length(l_stream, opj_get_data_length_from_file(p_file)); - opj_stream_set_read_function(l_stream, (opj_stream_read_fn) opj_read_from_file); - opj_stream_set_write_function(l_stream, (opj_stream_write_fn) opj_write_from_file); - opj_stream_set_skip_function(l_stream, (opj_stream_skip_fn) opj_skip_from_file); - opj_stream_set_seek_function(l_stream, (opj_stream_seek_fn) opj_seek_from_file); - - return l_stream; + opj_stream_set_user_data(l_stream, p_file); + opj_stream_set_user_data_length(l_stream, opj_get_data_length_from_file(p_file)); + opj_stream_set_read_function(l_stream, (opj_stream_read_fn) opj_read_from_file); + opj_stream_set_write_function(l_stream, (opj_stream_write_fn) opj_write_from_file); + opj_stream_set_skip_function(l_stream, (opj_stream_skip_fn) opj_skip_from_file); + opj_stream_set_seek_function(l_stream, (opj_stream_seek_fn) opj_seek_from_file); + + return l_stream; +} + +opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream_v3 ( + const char *fname, + OPJ_SIZE_T p_size, + OPJ_BOOL p_is_read_stream) +{ + opj_stream_t* l_stream = 00; + FILE *p_file; + const char *mode; + + if (! fname) { + return NULL; + } + + if(p_is_read_stream) mode = "rb"; else mode = "wb"; + + p_file = fopen(fname, mode); + + if (! p_file) { + return NULL; + } + + l_stream = opj_stream_create(p_size,p_is_read_stream); + if (! l_stream) { + fclose(p_file); + return NULL; + } + + opj_stream_set_user_data(l_stream, p_file); + opj_stream_set_user_data_length(l_stream, opj_get_data_length_from_file(p_file)); + opj_stream_set_read_function(l_stream, (opj_stream_read_fn) opj_read_from_file); + opj_stream_set_write_function(l_stream, (opj_stream_write_fn) opj_write_from_file); + opj_stream_set_skip_function(l_stream, (opj_stream_skip_fn) opj_skip_from_file); + opj_stream_set_seek_function(l_stream, (opj_stream_seek_fn) opj_seek_from_file); + + return l_stream; } diff --git a/src/lib/openjp2/openjpeg.h b/src/lib/openjp2/openjpeg.h index 9a2f1073..e2657ae4 100644 --- a/src/lib/openjp2/openjpeg.h +++ b/src/lib/openjp2/openjpeg.h @@ -387,7 +387,8 @@ typedef struct opj_cparameters { char tcp_mct; /** Enable JPIP indexing*/ OPJ_BOOL jpip_on; - /** Naive implementation of MCT restricted to a single reversible array based encoding without offset concerning all the components. */ + /** Naive implementation of MCT restricted to a single reversible array based + encoding without offset concerning all the components. */ void * mct_data; } opj_cparameters_t; @@ -1004,7 +1005,8 @@ OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size, O * @param p_stream the stream to destroy. */ OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream); - +OPJ_API void OPJ_CALLCONV opj_stream_destroy_v3(opj_stream_t* p_stream); + /** * Sets the given function to be used as a read function. * @param p_stream the stream to modify @@ -1055,15 +1057,21 @@ OPJ_API void OPJ_CALLCONV opj_stream_set_user_data_length(opj_stream_t* p_stream * @param p_is_read_stream whether the stream is a read stream (true) or not (false) */ OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file, OPJ_BOOL p_is_read_stream); - +OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream_v3 (const char *fname, OPJ_BOOL p_is_read_stream); + /** * FIXME DOC * @param p_file the file stream to operate on * @param p_buffer_size size of the chunk used to stream * @param p_is_read_stream whether the stream is a read stream (true) or not (false) */ -OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (FILE * p_file, OPJ_SIZE_T p_buffer_size, OPJ_BOOL p_is_read_stream); - +OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (FILE * p_file, + OPJ_SIZE_T p_buffer_size, + OPJ_BOOL p_is_read_stream); +OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream_v3 (const char *fname, + OPJ_SIZE_T p_buffer_size, + OPJ_BOOL p_is_read_stream); + /* ========================================================== event manager functions definitions @@ -1217,7 +1225,8 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_decoded_resolution_factor(opj_codec_t *p_c * @param p_codec the jpeg2000 codec. * @param p_tile_index the index of the tile to write. At the moment, the tiles must be written from 0 to n-1 in sequence. * @param p_data pointer to the data to write. Data is arranged in sequence, data_comp0, then data_comp1, then ... NO INTERLEAVING should be set. - * @param p_data_size this value os used to make sure the data being written is correct. The size must be equal to the sum for each component of tile_width * tile_height * component_size. component_size can be 1,2 or 4 bytes, depending on the precision of the given component. + * @param p_data_size this value os used to make sure the data being written is correct. The size must be equal to the sum for each component of + * tile_width * tile_height * component_size. component_size can be 1,2 or 4 bytes, depending on the precision of the given component. * @param p_stream the stream to write data to. * * @return true if the data could be written. From c03ca9c73c15b893d5e952207224e3e339b5bbd6 Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Sat, 16 Feb 2013 17:31:22 +0000 Subject: [PATCH 035/333] [trunk] rename deprecated macro with opj_ prefix and use it for opj_stream_destroy function --- src/lib/openjp2/openjpeg.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/openjp2/openjpeg.h b/src/lib/openjp2/openjpeg.h index e2657ae4..2b6c4518 100644 --- a/src/lib/openjp2/openjpeg.h +++ b/src/lib/openjp2/openjpeg.h @@ -47,10 +47,10 @@ #ifdef __GNUC__ #define DEPRECATED(func) func __attribute__ ((deprecated)) #elif defined(_MSC_VER) - #define DEPRECATED(func) __declspec(deprecated) func + #define OPJ_DEPRECATED(func) __declspec(deprecated) func #else #pragma message("WARNING: You need to implement DEPRECATED for this compiler") - #define DEPRECATED(func) func + #define OPJ_DEPRECATED(func) func #endif #if defined(OPJ_STATIC) || !defined(_WIN32) @@ -1004,7 +1004,7 @@ OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size, O * * @param p_stream the stream to destroy. */ -OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream); +OPJ_DEPRECATED(OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream)); OPJ_API void OPJ_CALLCONV opj_stream_destroy_v3(opj_stream_t* p_stream); /** From 4bf4a7668eaeaa4b02051afe06b8ec3e0d805de3 Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Sat, 16 Feb 2013 17:39:23 +0000 Subject: [PATCH 036/333] [trunk] move to the new API for function opj_stream_destroy. Use now opj_stream_destroy_v3 (WIP) --- src/bin/jp2/opj_compress.c | 10 +++++----- src/bin/jp2/opj_decompress.c | 16 ++++++++-------- src/bin/jp2/opj_dump.c | 8 ++++---- tests/j2k_random_tile_access.c | 10 +++++----- tests/test_tile_decoder.c | 18 +++++++++--------- tests/test_tile_encoder.c | 8 ++++---- tests/unit/testempty1.c | 8 ++++---- tests/unit/testempty2.c | 10 +++++----- 8 files changed, 44 insertions(+), 44 deletions(-) diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index 9c957502..5101d841 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -1806,7 +1806,7 @@ int main(int argc, char **argv) { } default: fprintf(stderr, "skipping file..\n"); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); continue; } @@ -1828,7 +1828,7 @@ int main(int argc, char **argv) { fout = fopen(parameters.outfile, "wb"); if (! fout) { fprintf(stderr, "Not enable to create output file!\n"); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); return 1; } @@ -1852,7 +1852,7 @@ int main(int argc, char **argv) { for (i=0;i test_tile_encoder: failed to write the tile %d!\n",i); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); fclose(fout); opj_destroy_codec(l_codec); opj_image_destroy(image); @@ -1873,7 +1873,7 @@ int main(int argc, char **argv) { } if (!bSuccess) { - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); fclose(fout); opj_destroy_codec(l_codec); opj_image_destroy(image); @@ -1883,7 +1883,7 @@ int main(int argc, char **argv) { fprintf(stderr,"Generated outfile %s\n",parameters.outfile); /* close and free the byte stream */ - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); fclose(fout); /* free remaining compression structures */ diff --git a/src/bin/jp2/opj_decompress.c b/src/bin/jp2/opj_decompress.c index df2978db..e462fb5e 100644 --- a/src/bin/jp2/opj_decompress.c +++ b/src/bin/jp2/opj_decompress.c @@ -783,7 +783,7 @@ int main(int argc, char **argv) } default: fprintf(stderr, "skipping file..\n"); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); continue; } @@ -795,7 +795,7 @@ int main(int argc, char **argv) /* Setup the decoder decoding parameters using user parameters */ if ( !opj_setup_decoder(l_codec, ¶meters) ){ fprintf(stderr, "ERROR -> j2k_dump: failed to setup the decoder\n"); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); fclose(fsrc); opj_destroy_codec(l_codec); return EXIT_FAILURE; @@ -805,7 +805,7 @@ int main(int argc, char **argv) /* Read the main header of the codestream and if necessary the JP2 boxes*/ if(! opj_read_header(l_stream, l_codec, &image)){ fprintf(stderr, "ERROR -> opj_decompress: failed to read the header\n"); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); fclose(fsrc); opj_destroy_codec(l_codec); opj_image_destroy(image); @@ -817,7 +817,7 @@ int main(int argc, char **argv) if (!opj_set_decode_area(l_codec, image, parameters.DA_x0, parameters.DA_y0, parameters.DA_x1, parameters.DA_y1)){ fprintf(stderr, "ERROR -> opj_decompress: failed to set the decoded area\n"); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); opj_destroy_codec(l_codec); opj_image_destroy(image); fclose(fsrc); @@ -828,7 +828,7 @@ int main(int argc, char **argv) if (!(opj_decode(l_codec, l_stream, image) && opj_end_decompress(l_codec, l_stream))) { fprintf(stderr,"ERROR -> opj_decompress: failed to decode image!\n"); opj_destroy_codec(l_codec); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); opj_image_destroy(image); fclose(fsrc); return EXIT_FAILURE; @@ -840,7 +840,7 @@ int main(int argc, char **argv) /*if (!opj_set_decoded_resolution_factor(l_codec, 5)) { fprintf(stderr, "ERROR -> opj_decompress: failed to set the resolution factor tile!\n"); opj_destroy_codec(l_codec); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); opj_image_destroy(image); fclose(fsrc); return EXIT_FAILURE; @@ -849,7 +849,7 @@ int main(int argc, char **argv) if (!opj_get_decoded_tile(l_codec, l_stream, image, parameters.tile_index)) { fprintf(stderr, "ERROR -> opj_decompress: failed to decode tile!\n"); opj_destroy_codec(l_codec); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); opj_image_destroy(image); fclose(fsrc); return EXIT_FAILURE; @@ -858,7 +858,7 @@ int main(int argc, char **argv) } /* Close the byte stream */ - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); fclose(fsrc); if(image->color_space == OPJ_CLRSPC_SYCC){ diff --git a/src/bin/jp2/opj_dump.c b/src/bin/jp2/opj_dump.c index 2bc1893a..0fb5d117 100644 --- a/src/bin/jp2/opj_dump.c +++ b/src/bin/jp2/opj_dump.c @@ -523,7 +523,7 @@ int main(int argc, char *argv[]) } default: fprintf(stderr, "skipping file..\n"); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); continue; } @@ -535,7 +535,7 @@ int main(int argc, char *argv[]) /* Setup the decoder decoding parameters using user parameters */ if ( !opj_setup_decoder(l_codec, ¶meters) ){ fprintf(stderr, "ERROR -> opj_dump: failed to setup the decoder\n"); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); fclose(fsrc); opj_destroy_codec(l_codec); fclose(fout); @@ -545,7 +545,7 @@ int main(int argc, char *argv[]) /* Read the main header of the codestream and if necessary the JP2 boxes*/ if(! opj_read_header(l_stream, l_codec, &image)){ fprintf(stderr, "ERROR -> opj_dump: failed to read the header\n"); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); fclose(fsrc); opj_destroy_codec(l_codec); opj_image_destroy(image); @@ -560,7 +560,7 @@ int main(int argc, char *argv[]) cstr_index = opj_get_cstr_index(l_codec); /* close the byte stream */ - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); fclose(fsrc); /* free remaining structures */ diff --git a/tests/j2k_random_tile_access.c b/tests/j2k_random_tile_access.c index afe4bd41..065a955c 100644 --- a/tests/j2k_random_tile_access.c +++ b/tests/j2k_random_tile_access.c @@ -228,7 +228,7 @@ int main(int argc, char **argv) /* Setup the decoder decoding parameters using user parameters */ if ( !opj_setup_decoder(l_codec, ¶meters) ){ fprintf(stderr, "ERROR -> j2k_dump: failed to setup the decoder\n"); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); fclose(fsrc); opj_destroy_codec(l_codec); return EXIT_FAILURE; @@ -237,7 +237,7 @@ int main(int argc, char **argv) /* Read the main header of the codestream and if necessary the JP2 boxes*/ if(! opj_read_header(l_stream, l_codec, &image)){ fprintf(stderr, "ERROR -> j2k_to_image: failed to read the header\n"); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); fclose(fsrc); opj_destroy_codec(l_codec); opj_image_destroy(image); @@ -258,7 +258,7 @@ int main(int argc, char **argv) fprintf(stdout, "Decoding tile %d ...\n", tile_index); \ if(!opj_get_decoded_tile(l_codec, l_stream, image, tile_index )){ \ fprintf(stderr, "ERROR -> j2k_to_image: failed to decode tile %d\n", tile_index); \ - opj_stream_destroy(l_stream); \ + opj_stream_destroy_v3(l_stream); \ opj_destroy_cstr_info(&cstr_info); \ opj_destroy_codec(l_codec); \ opj_image_destroy(image); \ @@ -268,7 +268,7 @@ int main(int argc, char **argv) for(index = 0; index < image->numcomps; ++index) { \ if( image->comps[index].data == NULL ){ \ fprintf(stderr, "ERROR -> j2k_to_image: failed to decode tile %d\n", tile_index); \ - opj_stream_destroy(l_stream); \ + opj_stream_destroy_v3(l_stream); \ opj_destroy_cstr_info(&cstr_info); \ opj_destroy_codec(l_codec); \ opj_image_destroy(image); \ @@ -286,7 +286,7 @@ int main(int argc, char **argv) TEST_TILE(tile_lr) /* Close the byte stream */ - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); /* Destroy code stream info */ opj_destroy_cstr_info(&cstr_info); diff --git a/tests/test_tile_decoder.c b/tests/test_tile_decoder.c index 81f791cb..1dd3382f 100644 --- a/tests/test_tile_decoder.c +++ b/tests/test_tile_decoder.c @@ -270,7 +270,7 @@ int main (int argc, char *argv[]) fprintf(stderr, "ERROR -> Not a valid JPEG2000 file!\n"); fclose(l_file); free(l_data); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); return EXIT_FAILURE; } } @@ -286,7 +286,7 @@ int main (int argc, char *argv[]) fprintf(stderr, "ERROR -> j2k_dump: failed to setup the decoder\n"); fclose(l_file); free(l_data); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); opj_destroy_codec(l_codec); return EXIT_FAILURE; } @@ -297,7 +297,7 @@ int main (int argc, char *argv[]) fprintf(stderr, "ERROR -> j2k_to_image: failed to read the header\n"); fclose(l_file); free(l_data); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); opj_destroy_codec(l_codec); return EXIT_FAILURE; } @@ -306,7 +306,7 @@ int main (int argc, char *argv[]) fprintf(stderr, "ERROR -> j2k_to_image: failed to set the decoded area\n"); fclose(l_file); free(l_data); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); opj_destroy_codec(l_codec); opj_image_destroy(l_image); return EXIT_FAILURE; @@ -328,7 +328,7 @@ int main (int argc, char *argv[]) { fclose(l_file); free(l_data); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); opj_destroy_codec(l_codec); opj_image_destroy(l_image); return EXIT_FAILURE; @@ -343,7 +343,7 @@ int main (int argc, char *argv[]) { fclose(l_file); free(l_new_data); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); opj_destroy_codec(l_codec); opj_image_destroy(l_image); return EXIT_FAILURE; @@ -356,7 +356,7 @@ int main (int argc, char *argv[]) { fclose(l_file); free(l_data); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); opj_destroy_codec(l_codec); opj_image_destroy(l_image); return EXIT_FAILURE; @@ -369,7 +369,7 @@ int main (int argc, char *argv[]) { fclose(l_file); free(l_data); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); opj_destroy_codec(l_codec); opj_image_destroy(l_image); return EXIT_FAILURE; @@ -378,7 +378,7 @@ int main (int argc, char *argv[]) /* Free memory */ fclose(l_file); free(l_data); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); opj_destroy_codec(l_codec); opj_image_destroy(l_image); diff --git a/tests/test_tile_encoder.c b/tests/test_tile_encoder.c index 22ecb348..54710369 100644 --- a/tests/test_tile_encoder.c +++ b/tests/test_tile_encoder.c @@ -290,7 +290,7 @@ int main (int argc, char *argv[]) if (! opj_start_compress(l_codec,l_image,l_stream)) { fprintf(stderr, "ERROR -> test_tile_encoder: failed to start compress!\n"); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); fclose(l_file); opj_destroy_codec(l_codec); opj_image_destroy(l_image); @@ -300,7 +300,7 @@ int main (int argc, char *argv[]) for (i=0;i test_tile_encoder: failed to write the tile %d!\n",i); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); fclose(l_file); opj_destroy_codec(l_codec); opj_image_destroy(l_image); @@ -310,14 +310,14 @@ int main (int argc, char *argv[]) if (! opj_end_compress(l_codec,l_stream)) { fprintf(stderr, "ERROR -> test_tile_encoder: failed to end compress!\n"); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); fclose(l_file); opj_destroy_codec(l_codec); opj_image_destroy(l_image); return 1; } - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); fclose(l_file); opj_destroy_codec(l_codec); opj_image_destroy(l_image); diff --git a/tests/unit/testempty1.c b/tests/unit/testempty1.c index add522a6..32736485 100644 --- a/tests/unit/testempty1.c +++ b/tests/unit/testempty1.c @@ -99,9 +99,9 @@ int main(int argc, char *argv[]) } } - /* catch events using our callbacks and give a local context */ - opj_set_info_handler(l_codec, info_callback,00); - opj_set_warning_handler(l_codec, warning_callback,00); + /* catch events using our callbacks and give a local context */ + opj_set_info_handler(l_codec, info_callback,00); + opj_set_warning_handler(l_codec, warning_callback,00); opj_set_error_handler(l_codec, error_callback,00); l_codec = opj_create_compress(OPJ_CODEC_J2K); @@ -125,7 +125,7 @@ int main(int argc, char *argv[]) bSuccess = opj_end_compress(l_codec, l_stream); assert( bSuccess ); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); fclose(f); opj_destroy_codec(l_codec); diff --git a/tests/unit/testempty2.c b/tests/unit/testempty2.c index 47ef4cc2..3b0952b2 100644 --- a/tests/unit/testempty2.c +++ b/tests/unit/testempty2.c @@ -101,9 +101,9 @@ int main(int argc, char *argv[]) } } - /* catch events using our callbacks and give a local context */ - opj_set_info_handler(l_codec, info_callback,00); - opj_set_warning_handler(l_codec, warning_callback,00); + /* catch events using our callbacks and give a local context */ + opj_set_info_handler(l_codec, info_callback,00); + opj_set_warning_handler(l_codec, warning_callback,00); opj_set_error_handler(l_codec, error_callback,00); l_codec = opj_create_compress(OPJ_CODEC_J2K); @@ -127,7 +127,7 @@ int main(int argc, char *argv[]) bSuccess = opj_end_compress(l_codec, l_stream); assert( bSuccess ); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); fclose(f); opj_destroy_codec(l_codec); @@ -161,7 +161,7 @@ int main(int argc, char *argv[]) bSuccess = opj_end_decompress(l_codec, l_stream); assert( bSuccess ); - opj_stream_destroy(l_stream); + opj_stream_destroy_v3(l_stream); fclose(fsrc); opj_destroy_codec(d_codec); From af58e8e8f9d08c1e276a9ba070eb4d44a6ca4950 Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Sun, 17 Feb 2013 10:34:31 +0000 Subject: [PATCH 037/333] [trunk] move to the new API for function opj_stream_create_default_file_stream. Use now opj_stream_create_default_file_stream_v3 (WIP) --- src/bin/jp2/opj_compress.c | 14 +------------- src/bin/jp2/opj_decompress.c | 18 ++---------------- src/bin/jp2/opj_dump.c | 15 +++------------ tests/j2k_random_tile_access.c | 23 +++-------------------- tests/test_tile_decoder.c | 21 +-------------------- tests/test_tile_encoder.c | 13 +++---------- tests/unit/testempty1.c | 8 +------- tests/unit/testempty2.c | 14 +++----------- 8 files changed, 17 insertions(+), 109 deletions(-) diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index 5101d841..24217aa3 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -1588,7 +1588,6 @@ static void info_callback(const char *msg, void *client_data) { */ /* -------------------------------------------------------------------------- */ int main(int argc, char **argv) { - FILE *fout = NULL; opj_cparameters_t parameters; /* compression parameters */ @@ -1824,16 +1823,8 @@ int main(int argc, char **argv) { } opj_setup_encoder(l_codec, ¶meters, image); - /* Open the output file*/ - fout = fopen(parameters.outfile, "wb"); - if (! fout) { - fprintf(stderr, "Not enable to create output file!\n"); - opj_stream_destroy_v3(l_stream); - return 1; - } - /* open a byte stream for writing and allocate memory for all tiles */ - l_stream = opj_stream_create_default_file_stream(fout,OPJ_FALSE); + l_stream = opj_stream_create_default_file_stream_v3(parameters.outfile,OPJ_FALSE); if (! l_stream){ return 1; } @@ -1853,7 +1844,6 @@ int main(int argc, char **argv) { if (! opj_write_tile(l_codec,i,l_data,l_data_size,l_stream)) { fprintf(stderr, "ERROR -> test_tile_encoder: failed to write the tile %d!\n",i); opj_stream_destroy_v3(l_stream); - fclose(fout); opj_destroy_codec(l_codec); opj_image_destroy(image); return 1; @@ -1874,7 +1864,6 @@ int main(int argc, char **argv) { if (!bSuccess) { opj_stream_destroy_v3(l_stream); - fclose(fout); opj_destroy_codec(l_codec); opj_image_destroy(image); fprintf(stderr, "failed to encode image\n"); @@ -1884,7 +1873,6 @@ int main(int argc, char **argv) { fprintf(stderr,"Generated outfile %s\n",parameters.outfile); /* close and free the byte stream */ opj_stream_destroy_v3(l_stream); - fclose(fout); /* free remaining compression structures */ opj_destroy_codec(l_codec); diff --git a/src/bin/jp2/opj_decompress.c b/src/bin/jp2/opj_decompress.c index e462fb5e..9e4f3103 100644 --- a/src/bin/jp2/opj_decompress.c +++ b/src/bin/jp2/opj_decompress.c @@ -676,7 +676,6 @@ static void info_callback(const char *msg, void *client_data) { /* -------------------------------------------------------------------------- */ int main(int argc, char **argv) { - FILE *fsrc = NULL; opj_dparameters_t parameters; /* decompression parameters */ opj_image_t* image = NULL; @@ -746,16 +745,10 @@ int main(int argc, char **argv) /* read the input file and put it in memory */ /* ---------------------------------------- */ - fsrc = fopen(parameters.infile, "rb"); - if (!fsrc) { - fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.infile); - return EXIT_FAILURE; - } - l_stream = opj_stream_create_default_file_stream(fsrc,1); + l_stream = opj_stream_create_default_file_stream_v3(parameters.infile,1); if (!l_stream){ - fclose(fsrc); - fprintf(stderr, "ERROR -> failed to create the stream from the file\n"); + fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n", parameters.infile); return EXIT_FAILURE; } @@ -796,7 +789,6 @@ int main(int argc, char **argv) if ( !opj_setup_decoder(l_codec, ¶meters) ){ fprintf(stderr, "ERROR -> j2k_dump: failed to setup the decoder\n"); opj_stream_destroy_v3(l_stream); - fclose(fsrc); opj_destroy_codec(l_codec); return EXIT_FAILURE; } @@ -806,7 +798,6 @@ int main(int argc, char **argv) if(! opj_read_header(l_stream, l_codec, &image)){ fprintf(stderr, "ERROR -> opj_decompress: failed to read the header\n"); opj_stream_destroy_v3(l_stream); - fclose(fsrc); opj_destroy_codec(l_codec); opj_image_destroy(image); return EXIT_FAILURE; @@ -820,7 +811,6 @@ int main(int argc, char **argv) opj_stream_destroy_v3(l_stream); opj_destroy_codec(l_codec); opj_image_destroy(image); - fclose(fsrc); return EXIT_FAILURE; } @@ -830,7 +820,6 @@ int main(int argc, char **argv) opj_destroy_codec(l_codec); opj_stream_destroy_v3(l_stream); opj_image_destroy(image); - fclose(fsrc); return EXIT_FAILURE; } } @@ -842,7 +831,6 @@ int main(int argc, char **argv) opj_destroy_codec(l_codec); opj_stream_destroy_v3(l_stream); opj_image_destroy(image); - fclose(fsrc); return EXIT_FAILURE; }*/ @@ -851,7 +839,6 @@ int main(int argc, char **argv) opj_destroy_codec(l_codec); opj_stream_destroy_v3(l_stream); opj_image_destroy(image); - fclose(fsrc); return EXIT_FAILURE; } fprintf(stdout, "tile %d is decoded!\n\n", parameters.tile_index); @@ -859,7 +846,6 @@ int main(int argc, char **argv) /* Close the byte stream */ opj_stream_destroy_v3(l_stream); - fclose(fsrc); if(image->color_space == OPJ_CLRSPC_SYCC){ color_sycc_to_rgb(image); /* FIXME */ diff --git a/src/bin/jp2/opj_dump.c b/src/bin/jp2/opj_dump.c index 0fb5d117..23913899 100644 --- a/src/bin/jp2/opj_dump.c +++ b/src/bin/jp2/opj_dump.c @@ -401,7 +401,7 @@ static void info_callback(const char *msg, void *client_data) { /* -------------------------------------------------------------------------- */ int main(int argc, char *argv[]) { - FILE *fsrc = NULL, *fout = NULL; + FILE *fout = NULL; opj_dparameters_t parameters; /* Decompression parameters */ opj_image_t* image = NULL; /* Image structure */ @@ -486,16 +486,10 @@ int main(int argc, char *argv[]) /* Read the input file and put it in memory */ /* ---------------------------------------- */ - fsrc = fopen(parameters.infile, "rb"); - if (!fsrc) { - fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.infile); - return EXIT_FAILURE; - } - l_stream = opj_stream_create_default_file_stream(fsrc,1); + l_stream = opj_stream_create_default_file_stream_v3(parameters.infile,1); if (!l_stream){ - fclose(fsrc); - fprintf(stderr, "ERROR -> failed to create the stream from the file\n"); + fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n",parameters.infile); return EXIT_FAILURE; } @@ -536,7 +530,6 @@ int main(int argc, char *argv[]) if ( !opj_setup_decoder(l_codec, ¶meters) ){ fprintf(stderr, "ERROR -> opj_dump: failed to setup the decoder\n"); opj_stream_destroy_v3(l_stream); - fclose(fsrc); opj_destroy_codec(l_codec); fclose(fout); return EXIT_FAILURE; @@ -546,7 +539,6 @@ int main(int argc, char *argv[]) if(! opj_read_header(l_stream, l_codec, &image)){ fprintf(stderr, "ERROR -> opj_dump: failed to read the header\n"); opj_stream_destroy_v3(l_stream); - fclose(fsrc); opj_destroy_codec(l_codec); opj_image_destroy(image); fclose(fout); @@ -561,7 +553,6 @@ int main(int argc, char *argv[]) /* close the byte stream */ opj_stream_destroy_v3(l_stream); - fclose(fsrc); /* free remaining structures */ if (l_codec) { diff --git a/tests/j2k_random_tile_access.c b/tests/j2k_random_tile_access.c index 065a955c..b76bf359 100644 --- a/tests/j2k_random_tile_access.c +++ b/tests/j2k_random_tile_access.c @@ -150,9 +150,7 @@ static int infile_format(const char *fname) /* -------------------------------------------------------------------------- */ int main(int argc, char **argv) { - FILE *fsrc = NULL; - - OPJ_UINT32 index; + OPJ_UINT32 index; opj_dparameters_t parameters; /* decompression parameters */ opj_image_t* image = NULL; opj_stream_t *l_stream = NULL; /* Stream */ @@ -175,13 +173,6 @@ int main(int argc, char **argv) strncpy(parameters.infile, argv[1], OPJ_PATH_LEN - 1); - /* read the input file */ - /* ------------------- */ - fsrc = fopen(parameters.infile, "rb"); - if (!fsrc) { - fprintf(stderr, "ERROR -> failed to open %s for reading\n", parameters.infile); - return EXIT_FAILURE; - } /* decode the JPEG2000 stream */ /* -------------------------- */ @@ -218,10 +209,9 @@ int main(int argc, char **argv) opj_set_warning_handler(l_codec, warning_callback,00); opj_set_error_handler(l_codec, error_callback,00); - l_stream = opj_stream_create_default_file_stream(fsrc,1); + l_stream = opj_stream_create_default_file_stream_v3(parameters.infile,1); if (!l_stream){ - fclose(fsrc); - fprintf(stderr, "ERROR -> failed to create the stream from the file\n"); + fprintf(stderr, "ERROR -> failed to create the stream from the file %s\n", parameters.infile); return EXIT_FAILURE; } @@ -229,7 +219,6 @@ int main(int argc, char **argv) if ( !opj_setup_decoder(l_codec, ¶meters) ){ fprintf(stderr, "ERROR -> j2k_dump: failed to setup the decoder\n"); opj_stream_destroy_v3(l_stream); - fclose(fsrc); opj_destroy_codec(l_codec); return EXIT_FAILURE; } @@ -238,7 +227,6 @@ int main(int argc, char **argv) if(! opj_read_header(l_stream, l_codec, &image)){ fprintf(stderr, "ERROR -> j2k_to_image: failed to read the header\n"); opj_stream_destroy_v3(l_stream); - fclose(fsrc); opj_destroy_codec(l_codec); opj_image_destroy(image); return EXIT_FAILURE; @@ -262,7 +250,6 @@ int main(int argc, char **argv) opj_destroy_cstr_info(&cstr_info); \ opj_destroy_codec(l_codec); \ opj_image_destroy(image); \ - fclose(fsrc); \ return EXIT_FAILURE; \ } \ for(index = 0; index < image->numcomps; ++index) { \ @@ -272,7 +259,6 @@ int main(int argc, char **argv) opj_destroy_cstr_info(&cstr_info); \ opj_destroy_codec(l_codec); \ opj_image_destroy(image); \ - fclose(fsrc); \ return EXIT_FAILURE; \ } \ } \ @@ -297,9 +283,6 @@ int main(int argc, char **argv) /* Free image data structure */ opj_image_destroy(image); - /* Close the input file */ - fclose(fsrc); - return EXIT_SUCCESS; } /*end main*/ diff --git a/tests/test_tile_decoder.c b/tests/test_tile_decoder.c index 1dd3382f..5a53beea 100644 --- a/tests/test_tile_decoder.c +++ b/tests/test_tile_decoder.c @@ -179,7 +179,6 @@ int main (int argc, char *argv[]) opj_dparameters_t l_param; opj_codec_t * l_codec; opj_image_t * l_image; - FILE * l_file; opj_stream_t * l_stream; OPJ_UINT32 l_data_size; OPJ_UINT32 l_max_data_size = 1000; @@ -219,17 +218,8 @@ int main (int argc, char *argv[]) return EXIT_FAILURE; } - l_file = fopen(input_file,"rb"); - if (! l_file) - { - fprintf(stdout, "ERROR while opening input file\n"); - free(l_data); - return EXIT_FAILURE; - } - - l_stream = opj_stream_create_default_file_stream(l_file,OPJ_TRUE); + l_stream = opj_stream_create_default_file_stream_v3(input_file,OPJ_TRUE); if (!l_stream){ - fclose(l_file); free(l_data); fprintf(stderr, "ERROR -> failed to create the stream from the file\n"); return EXIT_FAILURE; @@ -268,7 +258,6 @@ int main (int argc, char *argv[]) default: { fprintf(stderr, "ERROR -> Not a valid JPEG2000 file!\n"); - fclose(l_file); free(l_data); opj_stream_destroy_v3(l_stream); return EXIT_FAILURE; @@ -284,7 +273,6 @@ int main (int argc, char *argv[]) if (! opj_setup_decoder(l_codec, &l_param)) { fprintf(stderr, "ERROR -> j2k_dump: failed to setup the decoder\n"); - fclose(l_file); free(l_data); opj_stream_destroy_v3(l_stream); opj_destroy_codec(l_codec); @@ -295,7 +283,6 @@ int main (int argc, char *argv[]) if (! opj_read_header(l_stream, l_codec, &l_image)) { fprintf(stderr, "ERROR -> j2k_to_image: failed to read the header\n"); - fclose(l_file); free(l_data); opj_stream_destroy_v3(l_stream); opj_destroy_codec(l_codec); @@ -304,7 +291,6 @@ int main (int argc, char *argv[]) if (!opj_set_decode_area(l_codec, l_image, da_x0, da_y0,da_x1, da_y1)){ fprintf(stderr, "ERROR -> j2k_to_image: failed to set the decoded area\n"); - fclose(l_file); free(l_data); opj_stream_destroy_v3(l_stream); opj_destroy_codec(l_codec); @@ -326,7 +312,6 @@ int main (int argc, char *argv[]) &l_nb_comps, &l_go_on)) { - fclose(l_file); free(l_data); opj_stream_destroy_v3(l_stream); opj_destroy_codec(l_codec); @@ -341,7 +326,6 @@ int main (int argc, char *argv[]) OPJ_BYTE *l_new_data = (OPJ_BYTE *) realloc(l_data, l_data_size); if (! l_new_data) { - fclose(l_file); free(l_new_data); opj_stream_destroy_v3(l_stream); opj_destroy_codec(l_codec); @@ -354,7 +338,6 @@ int main (int argc, char *argv[]) if (! opj_decode_tile_data(l_codec,l_tile_index,l_data,l_data_size,l_stream)) { - fclose(l_file); free(l_data); opj_stream_destroy_v3(l_stream); opj_destroy_codec(l_codec); @@ -367,7 +350,6 @@ int main (int argc, char *argv[]) if (! opj_end_decompress(l_codec,l_stream)) { - fclose(l_file); free(l_data); opj_stream_destroy_v3(l_stream); opj_destroy_codec(l_codec); @@ -376,7 +358,6 @@ int main (int argc, char *argv[]) } /* Free memory */ - fclose(l_file); free(l_data); opj_stream_destroy_v3(l_stream); opj_destroy_codec(l_codec); diff --git a/tests/test_tile_encoder.c b/tests/test_tile_encoder.c index 54710369..dbc3f037 100644 --- a/tests/test_tile_encoder.c +++ b/tests/test_tile_encoder.c @@ -80,7 +80,6 @@ int main (int argc, char *argv[]) opj_codec_t * l_codec; opj_image_t * l_image; opj_image_cmptparm_t l_params [NUM_COMPS_MAX]; - FILE * l_file; opj_stream_t * l_stream; OPJ_UINT32 l_nb_tiles; OPJ_UINT32 l_data_size; @@ -278,20 +277,17 @@ int main (int argc, char *argv[]) return 1; } - l_file = fopen(output_file,"wb"); - if (! l_file) { - fprintf(stderr, "ERROR -> test_tile_encoder: failed to create the output file!\n"); + l_stream = opj_stream_create_default_file_stream_v3(output_file, OPJ_FALSE); + if (! l_stream) { + fprintf(stderr, "ERROR -> test_tile_encoder: failed to create the stream from the output file %s !\n",output_file ); opj_destroy_codec(l_codec); opj_image_destroy(l_image); return 1; } - l_stream = opj_stream_create_default_file_stream(l_file, OPJ_FALSE); - if (! opj_start_compress(l_codec,l_image,l_stream)) { fprintf(stderr, "ERROR -> test_tile_encoder: failed to start compress!\n"); opj_stream_destroy_v3(l_stream); - fclose(l_file); opj_destroy_codec(l_codec); opj_image_destroy(l_image); return 1; @@ -301,7 +297,6 @@ int main (int argc, char *argv[]) if (! opj_write_tile(l_codec,i,l_data,l_data_size,l_stream)) { fprintf(stderr, "ERROR -> test_tile_encoder: failed to write the tile %d!\n",i); opj_stream_destroy_v3(l_stream); - fclose(l_file); opj_destroy_codec(l_codec); opj_image_destroy(l_image); return 1; @@ -311,14 +306,12 @@ int main (int argc, char *argv[]) if (! opj_end_compress(l_codec,l_stream)) { fprintf(stderr, "ERROR -> test_tile_encoder: failed to end compress!\n"); opj_stream_destroy_v3(l_stream); - fclose(l_file); opj_destroy_codec(l_codec); opj_image_destroy(l_image); return 1; } opj_stream_destroy_v3(l_stream); - fclose(l_file); opj_destroy_codec(l_codec); opj_image_destroy(l_image); diff --git a/tests/unit/testempty1.c b/tests/unit/testempty1.c index 32736485..17d16a17 100644 --- a/tests/unit/testempty1.c +++ b/tests/unit/testempty1.c @@ -71,7 +71,6 @@ int main(int argc, char *argv[]) opj_image_t *image; opj_codec_t* l_codec = 00; OPJ_BOOL bSuccess; - FILE *f; opj_stream_t *l_stream = 00; (void)argc; (void)argv; @@ -111,11 +110,7 @@ int main(int argc, char *argv[]) opj_setup_encoder(l_codec, ¶meters, image); - strcpy(parameters.outfile, "testempty1.j2k"); - f = fopen(parameters.outfile, "wb"); - assert( f ); - - l_stream = opj_stream_create_default_file_stream(f,OPJ_FALSE); + l_stream = opj_stream_create_default_file_stream_v3("testempty1.j2k",OPJ_FALSE); assert(l_stream); bSuccess = opj_start_compress(l_codec,image,l_stream); @@ -126,7 +121,6 @@ int main(int argc, char *argv[]) assert( bSuccess ); opj_stream_destroy_v3(l_stream); - fclose(f); opj_destroy_codec(l_codec); opj_image_destroy(image); diff --git a/tests/unit/testempty2.c b/tests/unit/testempty2.c index 3b0952b2..8d9bc282 100644 --- a/tests/unit/testempty2.c +++ b/tests/unit/testempty2.c @@ -73,7 +73,6 @@ int main(int argc, char *argv[]) opj_image_t *image; opj_codec_t* l_codec = 00; OPJ_BOOL bSuccess; - FILE *f; opj_stream_t *l_stream = 00; (void)argc; (void)argv; @@ -113,11 +112,7 @@ int main(int argc, char *argv[]) opj_setup_encoder(l_codec, ¶meters, image); - strcpy(parameters.outfile, outputfile); - f = fopen(parameters.outfile, "wb"); - assert( f ); - - l_stream = opj_stream_create_default_file_stream(f,OPJ_FALSE); + l_stream = opj_stream_create_default_file_stream_v3(parameters.outfile,OPJ_FALSE); assert(l_stream); bSuccess = opj_start_compress(l_codec,image,l_stream); @@ -128,7 +123,6 @@ int main(int argc, char *argv[]) assert( bSuccess ); opj_stream_destroy_v3(l_stream); - fclose(f); opj_destroy_codec(l_codec); opj_image_destroy(image); @@ -136,10 +130,8 @@ int main(int argc, char *argv[]) /* read back the generated file */ { - FILE *fsrc = fopen(outputfile, "rb"); opj_codec_t* d_codec = 00; opj_dparameters_t dparameters; - assert( fsrc ); d_codec = opj_create_decompress(OPJ_CODEC_J2K); opj_set_info_handler(d_codec, info_callback,00); @@ -149,7 +141,7 @@ int main(int argc, char *argv[]) bSuccess = opj_setup_decoder(d_codec, &dparameters); assert( bSuccess ); - l_stream = opj_stream_create_default_file_stream(fsrc,1); + l_stream = opj_stream_create_default_file_stream_v3(outputfile,1); assert( l_stream ); bSuccess = opj_read_header(l_stream, d_codec, &image); @@ -162,7 +154,7 @@ int main(int argc, char *argv[]) assert( bSuccess ); opj_stream_destroy_v3(l_stream); - fclose(fsrc); + opj_destroy_codec(d_codec); opj_image_destroy(image); From 42bd417acfc8ac694a4c8c6782b62135b6c505fd Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Sun, 17 Feb 2013 22:57:14 +0000 Subject: [PATCH 038/333] [trunk] update documentation of new functions _v3 and mark deprecated related functions --- src/lib/openjp2/openjpeg.h | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/lib/openjp2/openjpeg.h b/src/lib/openjp2/openjpeg.h index 2b6c4518..531c9f01 100644 --- a/src/lib/openjp2/openjpeg.h +++ b/src/lib/openjp2/openjpeg.h @@ -1005,6 +1005,13 @@ OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size, O * @param p_stream the stream to destroy. */ OPJ_DEPRECATED(OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream)); + +/** + * Destroys a stream created by opj_create_stream. This function does NOT close the abstract stream. + * If needed the user must close its own implementation of the stream. + * + * @param p_stream the stream to destroy. + */ OPJ_API void OPJ_CALLCONV opj_stream_destroy_v3(opj_stream_t* p_stream); /** @@ -1056,7 +1063,13 @@ OPJ_API void OPJ_CALLCONV opj_stream_set_user_data_length(opj_stream_t* p_stream * @param p_file the file stream to operate on * @param p_is_read_stream whether the stream is a read stream (true) or not (false) */ -OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file, OPJ_BOOL p_is_read_stream); +OPJ_DEPRECATED(OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file, OPJ_BOOL p_is_read_stream)); + +/** + * Create a stream from a file identified with its filename with default parameters (helper function) + * @param fname the filename of the file to stream + * @param p_is_read_stream whether the stream is a read stream (true) or not (false) +*/ OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream_v3 (const char *fname, OPJ_BOOL p_is_read_stream); /** @@ -1065,9 +1078,15 @@ OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream_v3 (con * @param p_buffer_size size of the chunk used to stream * @param p_is_read_stream whether the stream is a read stream (true) or not (false) */ -OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (FILE * p_file, +OPJ_DEPRECATED(OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (FILE * p_file, OPJ_SIZE_T p_buffer_size, - OPJ_BOOL p_is_read_stream); + OPJ_BOOL p_is_read_stream)); + +/** Create a stream from a file identified with its filename with a specific buffer size + * @param fname the filename of the file to stream + * @param p_buffer_size size of the chunk used to stream + * @param p_is_read_stream whether the stream is a read stream (true) or not (false) +*/ OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream_v3 (const char *fname, OPJ_SIZE_T p_buffer_size, OPJ_BOOL p_is_read_stream); From efaefa21fc6840df42894d746f314a6df899e3e1 Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Mon, 18 Feb 2013 13:19:52 +0000 Subject: [PATCH 039/333] [trunk] add the prefix opj_ to deprecated everywhere --- src/lib/openjp2/openjpeg.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/openjp2/openjpeg.h b/src/lib/openjp2/openjpeg.h index 531c9f01..bbc74577 100644 --- a/src/lib/openjp2/openjpeg.h +++ b/src/lib/openjp2/openjpeg.h @@ -45,7 +45,7 @@ /* deprecated attribute */ #ifdef __GNUC__ - #define DEPRECATED(func) func __attribute__ ((deprecated)) + #define OPJ_DEPRECATED(func) func __attribute__ ((deprecated)) #elif defined(_MSC_VER) #define OPJ_DEPRECATED(func) __declspec(deprecated) func #else From e7bc30b409fc864d7bcfec60254c4404a0c69c72 Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Sun, 3 Mar 2013 17:55:35 +0000 Subject: [PATCH 040/333] [trunk] split into two config files config options related to the lib and to the application. --- CMakeLists.txt | 16 +++++++--------- src/bin/common/CMakeLists.txt | 7 +++++++ src/bin/common/color.c | 6 +++--- src/bin/common/opj_apps_config.h.cmake.in | 13 +++++++++++++ src/bin/jp2/CMakeLists.txt | 1 + src/bin/jp2/convert.c | 18 +++++++++--------- src/bin/jp2/opj_compress.c | 12 ++++++------ src/bin/jp2/opj_decompress.c | 12 ++++++------ src/lib/openjp2/opj_config.h.cmake.in | 8 -------- tests/CMakeLists.txt | 1 + tests/comparePGXimages.c | 8 ++++---- 11 files changed, 57 insertions(+), 45 deletions(-) create mode 100644 src/bin/common/opj_apps_config.h.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 4c7c825c..483cc242 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -180,7 +180,7 @@ if(CMAKE_COMPILER_IS_GNUCC) endif() #----------------------------------------------------------------------------- -# opj_config.h generation (1/2) +# opj_config.h generation include (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake) CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H) CHECK_INCLUDE_FILE("inttypes.h" HAVE_INTTYPES_H) @@ -197,6 +197,12 @@ CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H) include(TestLargeFiles) OPJ_TEST_LARGE_FILES(OPJ_HAVE_LARGEFILES) +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config.h.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config.h + @ONLY + ) + #----------------------------------------------------------------------------- # Build Library add_subdirectory(src) @@ -226,14 +232,6 @@ if(BUILD_CODEC OR BUILD_MJ2) endif () add_subdirectory(wrapping) -#----------------------------------------------------------------------------- -# opj_config.h generation (2/2) -configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config.h.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config.h - @ONLY - ) - #----------------------------------------------------------------------------- # Build DOCUMENTATION (not in ALL target and only if Doxygen is found) option(BUILD_DOC "Build the HTML documentation (with doxygen if available)." OFF) diff --git a/src/bin/common/CMakeLists.txt b/src/bin/common/CMakeLists.txt index e69de29b..bb07ba7c 100644 --- a/src/bin/common/CMakeLists.txt +++ b/src/bin/common/CMakeLists.txt @@ -0,0 +1,7 @@ +#----------------------------------------------------------------------------- +# opj_apps_config.h generation +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/opj_apps_config.h.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/opj_apps_config.h + @ONLY + ) \ No newline at end of file diff --git a/src/bin/common/color.c b/src/bin/common/color.c index a71b7410..ce9ccde3 100644 --- a/src/bin/common/color.c +++ b/src/bin/common/color.c @@ -34,14 +34,14 @@ #include #include -#include "opj_config.h" +#include "opj_apps_config.h" #include "openjpeg.h" #include "color.h" -#ifdef HAVE_LIBLCMS2 +#ifdef OPJ_HAVE_LIBLCMS2 #include #endif -#ifdef HAVE_LIBLCMS1 +#ifdef OPJ_HAVE_LIBLCMS1 #include #endif diff --git a/src/bin/common/opj_apps_config.h.cmake.in b/src/bin/common/opj_apps_config.h.cmake.in new file mode 100644 index 00000000..4ea1efa3 --- /dev/null +++ b/src/bin/common/opj_apps_config.h.cmake.in @@ -0,0 +1,13 @@ +/* create opj_apps_config.h for CMake */ + +#cmakedefine OPJ_HAVE_LIBPNG @HAVE_LIBPNG@ +#cmakedefine OPJ_HAVE_PNG_H @HAVE_PNG_H@ +#cmakedefine OPJ_HAVE_LIBTIFF @HAVE_LIBTIFF@ +#cmakedefine OPJ_HAVE_TIFF_H @HAVE_TIFF_H@ + +#cmakedefine OPJ_HAVE_LIBLCMS1 +#cmakedefine OPJ_HAVE_LIBLCMS2 +#cmakedefine OPJ_HAVE_LCMS1_H +#cmakedefine OPJ_HAVE_LCMS2_H + + diff --git a/src/bin/jp2/CMakeLists.txt b/src/bin/jp2/CMakeLists.txt index aee330a5..43746317 100644 --- a/src/bin/jp2/CMakeLists.txt +++ b/src/bin/jp2/CMakeLists.txt @@ -11,6 +11,7 @@ set(common_SRCS # Headers file are located here: include_directories( ${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h + ${OPENJPEG_BINARY_DIR}/src/bin/common # opj_apps_config.h ${OPENJPEG_SOURCE_DIR}/src/lib/openjp2 ${OPENJPEG_SOURCE_DIR}/src/bin/common ${LCMS_INCLUDE_DIRNAME} diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index 98d900ad..1b6e688b 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -29,21 +29,21 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#include "opj_config.h" +#include "opj_apps_config.h" #include #include #include #include -#ifdef HAVE_LIBTIFF +#ifdef OPJ_HAVE_LIBTIFF #include -#endif /* HAVE_LIBTIFF */ +#endif /* OPJ_HAVE_LIBTIFF */ -#ifdef HAVE_LIBPNG +#ifdef OPJ_HAVE_LIBPNG #include #include -#endif /* HAVE_LIBPNG */ +#endif /* OPJ_HAVE_LIBPNG */ #include "openjpeg.h" #include "convert.h" @@ -2074,7 +2074,7 @@ int imagetopnm(opj_image_t * image, const char *outfile) return 0; }/* imagetopnm() */ -#ifdef HAVE_LIBTIFF +#ifdef OPJ_HAVE_LIBTIFF /* -->> -->> -->> -->> TIFF IMAGE FORMAT @@ -2795,7 +2795,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) }/* tiftoimage() */ -#endif /* HAVE_LIBTIFF */ +#endif /* OPJ_HAVE_LIBTIFF */ /* -->> -->> -->> -->> @@ -3085,7 +3085,7 @@ int imagetorawl(opj_image_t * image, const char *outfile) return imagetoraw_common(image, outfile, OPJ_FALSE); } -#ifdef HAVE_LIBPNG +#ifdef OPJ_HAVE_LIBPNG #define PNG_MAGIC "\x89PNG\x0d\x0a\x1a\x0a" #define MAGIC_SIZE 8 @@ -3624,4 +3624,4 @@ fin: return fails; }/* imagetopng() */ -#endif /* HAVE_LIBPNG */ +#endif /* OPJ_HAVE_LIBPNG */ diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index 24217aa3..71e767b5 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -53,7 +53,7 @@ #include #endif /* _WIN32 */ -#include "opj_config.h" +#include "opj_apps_config.h" #include "openjpeg.h" #include "opj_getopt.h" #include "convert.h" @@ -1727,7 +1727,7 @@ int main(int argc, char **argv) { } break; -#ifdef HAVE_LIBTIFF +#ifdef OPJ_HAVE_LIBTIFF case TIF_DFMT: image = tiftoimage(parameters.infile, ¶meters); if (!image) { @@ -1735,7 +1735,7 @@ int main(int argc, char **argv) { return 1; } break; -#endif /* HAVE_LIBTIFF */ +#endif /* OPJ_HAVE_LIBTIFF */ case RAW_DFMT: image = rawtoimage(parameters.infile, ¶meters, &raw_cp); @@ -1761,7 +1761,7 @@ int main(int argc, char **argv) { } break; -#ifdef HAVE_LIBPNG +#ifdef OPJ_HAVE_LIBPNG case PNG_DFMT: image = pngtoimage(parameters.infile, ¶meters); if (!image) { @@ -1769,11 +1769,11 @@ int main(int argc, char **argv) { return 1; } break; -#endif /* HAVE_LIBPNG */ +#endif /* OPJ_HAVE_LIBPNG */ } /* Can happen if input file is TIFF or PNG - * and HAVE_LIBTIF or HAVE_LIBPNG is undefined + * and HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined */ if( !image) { fprintf(stderr, "Unable to load file: got no image\n"); diff --git a/src/bin/jp2/opj_decompress.c b/src/bin/jp2/opj_decompress.c index 9e4f3103..3fced21d 100644 --- a/src/bin/jp2/opj_decompress.c +++ b/src/bin/jp2/opj_decompress.c @@ -31,7 +31,7 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#include "opj_config.h" +#include "opj_apps_config.h" #include #include @@ -888,7 +888,7 @@ int main(int argc, char **argv) fprintf(stdout,"Generated Outfile %s\n",parameters.outfile); } break; -#ifdef HAVE_LIBTIFF +#ifdef OPJ_HAVE_LIBTIFF case TIF_DFMT: /* TIFF */ if(imagetotif(image, parameters.outfile)){ fprintf(stdout,"Outfile %s not generated\n",parameters.outfile); @@ -897,7 +897,7 @@ int main(int argc, char **argv) fprintf(stdout,"Generated Outfile %s\n",parameters.outfile); } break; -#endif /* HAVE_LIBTIFF */ +#endif /* OPJ_HAVE_LIBTIFF */ case RAW_DFMT: /* RAW */ if(imagetoraw(image, parameters.outfile)){ fprintf(stdout,"Error generating raw file. Outfile %s not generated\n",parameters.outfile); @@ -924,7 +924,7 @@ int main(int argc, char **argv) fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile); } break; -#ifdef HAVE_LIBPNG +#ifdef OPJ_HAVE_LIBPNG case PNG_DFMT: /* PNG */ if(imagetopng(image, parameters.outfile)){ fprintf(stdout,"Error generating png file. Outfile %s not generated\n",parameters.outfile); @@ -933,9 +933,9 @@ int main(int argc, char **argv) fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile); } break; -#endif /* HAVE_LIBPNG */ +#endif /* OPJ_HAVE_LIBPNG */ /* Can happen if output file is TIFF or PNG - * and HAVE_LIBTIF or HAVE_LIBPNG is undefined + * and HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined */ default: fprintf(stderr,"Outfile %s not generated\n",parameters.outfile); diff --git a/src/lib/openjp2/opj_config.h.cmake.in b/src/lib/openjp2/opj_config.h.cmake.in index 6bc268ef..83f7009c 100644 --- a/src/lib/openjp2/opj_config.h.cmake.in +++ b/src/lib/openjp2/opj_config.h.cmake.in @@ -11,20 +11,12 @@ #cmakedefine HAVE_SYS_STAT_H @HAVE_SYS_STAT_H@ #cmakedefine HAVE_SYS_TYPES_H @HAVE_SYS_TYPES_H@ #cmakedefine HAVE_UNISTD_H @HAVE_UNISTD_H@ -#cmakedefine HAVE_LIBPNG @HAVE_LIBPNG@ -#cmakedefine HAVE_PNG_H @HAVE_PNG_H@ -#cmakedefine HAVE_LIBTIFF @HAVE_LIBTIFF@ -#cmakedefine HAVE_TIFF_H @HAVE_TIFF_H@ #cmakedefine _LARGEFILE_SOURCE #cmakedefine _LARGE_FILES #cmakedefine _FILE_OFFSET_BITS @_FILE_OFFSET_BITS@ #cmakedefine HAVE_FSEEKO @HAVE_FSEEKO@ -#cmakedefine HAVE_LIBLCMS1 -#cmakedefine HAVE_LIBLCMS2 -#cmakedefine HAVE_LCMS1_H -#cmakedefine HAVE_LCMS2_H /* Byte order. */ /* All compilers that support Mac OS X define either __BIG_ENDIAN__ or diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 7184d681..5d4f5454 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -1,6 +1,7 @@ # Tests include_directories( ${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h + ${OPENJPEG_BINARY_DIR}/src/bin/common # opj_apps_config.h ${OPENJPEG_SOURCE_DIR}/src/lib/openjp2 ${OPENJPEG_SOURCE_DIR}/src/bin/jp2 ${OPENJPEG_SOURCE_DIR}/src/bin/common diff --git a/tests/comparePGXimages.c b/tests/comparePGXimages.c index 7a6d4ae7..29300d51 100644 --- a/tests/comparePGXimages.c +++ b/tests/comparePGXimages.c @@ -37,7 +37,7 @@ #include #include -#include "opj_config.h" +#include "opj_apps_config.h" #include "opj_getopt.h" #include "openjpeg.h" @@ -47,7 +47,7 @@ double* parseToleranceValues( char* inArg, const int nbcomp); void comparePGXimages_help_display(void); opj_image_t* readImageFromFilePGX(char* filename, int nbFilenamePGX, char *separator); -#ifdef HAVE_LIBPNG +#ifdef OPJ_HAVE_LIBPNG int imageToPNG(const opj_image_t* image, const char* filename, int num_comp_select); #endif @@ -464,7 +464,7 @@ opj_image_t* readImageFromFilePGX(char* filename, int nbFilenamePGX, char *separ /******************************************************************************* * *******************************************************************************/ -#ifdef HAVE_LIBPNG +#ifdef OPJ_HAVE_LIBPNG int imageToPNG(const opj_image_t* image, const char* filename, int num_comp_select) { opj_image_cmptparm_t param_image_write; @@ -756,7 +756,7 @@ int main(int argc, char **argv) printf(" %d \n", it_comp, nbPixelDiff); printf(" %f \n", it_comp, sumDiff); -#ifdef HAVE_LIBPNG +#ifdef OPJ_HAVE_LIBPNG sprintf(it_compc, "_%i", it_comp); strcat(it_compc,".png"); strcat(filenamePNGbase_it_comp, it_compc); From a8c33ae2197f934ce6be79887f467f09add714a8 Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Sun, 3 Mar 2013 18:06:27 +0000 Subject: [PATCH 041/333] [trunk] remove some unused variable from opj_config and rename other one with opj_ prefix --- cmake/TestLargeFiles.cmake | 6 +++--- src/lib/openjp2/opj_config.h.cmake.in | 19 ++++++++++--------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/cmake/TestLargeFiles.cmake b/cmake/TestLargeFiles.cmake index ffef84f5..7960e52c 100644 --- a/cmake/TestLargeFiles.cmake +++ b/cmake/TestLargeFiles.cmake @@ -7,7 +7,7 @@ # _LARGE_FILES # _LARGEFILE_SOURCE # _FILE_OFFSET_BITS 64 -# HAVE_FSEEKO +# OPJ_HAVE_FSEEKO # # However, it is YOUR job to make sure these defines are set in a #cmakedefine so they # end up in a config.h file that is included in your source if necessary! @@ -113,10 +113,10 @@ macro(OPJ_TEST_LARGE_FILES VARIABLE) endif() if(FSEEKO_COMPILE_OK) - set(HAVE_FSEEKO ON CACHE INTERNAL "Result of test for fseeko/ftello") + set(OPJ_HAVE_FSEEKO ON CACHE INTERNAL "Result of test for fseeko/ftello") else() message(STATUS "Checking for fseeko/ftello - not found") - set(HAVE_FSEEKO OFF CACHE INTERNAL "Result of test for fseeko/ftello") + set(OPJ_HAVE_FSEEKO OFF CACHE INTERNAL "Result of test for fseeko/ftello") endif() if(FILE64_OK AND FSEEKO_COMPILE_OK) diff --git a/src/lib/openjp2/opj_config.h.cmake.in b/src/lib/openjp2/opj_config.h.cmake.in index 83f7009c..aed6dbc5 100644 --- a/src/lib/openjp2/opj_config.h.cmake.in +++ b/src/lib/openjp2/opj_config.h.cmake.in @@ -3,19 +3,20 @@ #define OPJ_PACKAGE_VERSION "@PACKAGE_VERSION@" -#cmakedefine HAVE_INTTYPES_H @HAVE_INTTYPES_H@ -#cmakedefine HAVE_MEMORY_H @HAVE_MEMORY_H@ -#cmakedefine HAVE_STDLIB_H @HAVE_STDLIB_H@ -#cmakedefine HAVE_STRINGS_H @HAVE_STRINGS_H@ -#cmakedefine HAVE_STRING_H @HAVE_STRING_H@ -#cmakedefine HAVE_SYS_STAT_H @HAVE_SYS_STAT_H@ -#cmakedefine HAVE_SYS_TYPES_H @HAVE_SYS_TYPES_H@ -#cmakedefine HAVE_UNISTD_H @HAVE_UNISTD_H@ +/* Not used by openjp2*/ +/*#cmakedefine HAVE_INTTYPES_H @HAVE_INTTYPES_H@*/ +/*#cmakedefine HAVE_MEMORY_H @HAVE_MEMORY_H@*/ +/*#cmakedefine HAVE_STDLIB_H @HAVE_STDLIB_H@*/ +/*#cmakedefine HAVE_STRINGS_H @HAVE_STRINGS_H@*/ +/*#cmakedefine HAVE_STRING_H @HAVE_STRING_H@*/ +/*#cmakedefine HAVE_SYS_STAT_H @HAVE_SYS_STAT_H@*/ +/*#cmakedefine HAVE_SYS_TYPES_H @HAVE_SYS_TYPES_H@ */ +/*#cmakedefine HAVE_UNISTD_H @HAVE_UNISTD_H@*/ #cmakedefine _LARGEFILE_SOURCE #cmakedefine _LARGE_FILES #cmakedefine _FILE_OFFSET_BITS @_FILE_OFFSET_BITS@ -#cmakedefine HAVE_FSEEKO @HAVE_FSEEKO@ +#cmakedefine OPJ_HAVE_FSEEKO @OPJ_HAVE_FSEEKO@ /* Byte order. */ From 92b1e038c16be50d9b67d2bb72bb473ab8d2d753 Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Wed, 13 Mar 2013 10:18:04 +0000 Subject: [PATCH 042/333] [trunk] correct missing variable in openjpeg config file --- CMakeLists.txt | 7 ++++--- src/lib/openjp2/opj_config.h.cmake.in | 4 ++-- src/lib/openjp2/opj_inttypes.h | 2 +- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 483cc242..49da7c46 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -182,10 +182,11 @@ endif() #----------------------------------------------------------------------------- # opj_config.h generation include (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake) -CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H) -CHECK_INCLUDE_FILE("inttypes.h" HAVE_INTTYPES_H) -CHECK_INCLUDE_FILE("memory.h" HAVE_MEMORY_H) CHECK_INCLUDE_FILE("stdint.h" OPJ_HAVE_STDINT_H) +CHECK_INCLUDE_FILE("inttypes.h" OPJ_HAVE_INTTYPES_H) + +CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H) +CHECK_INCLUDE_FILE("memory.h" HAVE_MEMORY_H) CHECK_INCLUDE_FILE("stdlib.h" HAVE_STDLIB_H) CHECK_INCLUDE_FILE("stdio.h" HAVE_STDIO_H) CHECK_INCLUDE_FILE("string.h" HAVE_STRING_H) diff --git a/src/lib/openjp2/opj_config.h.cmake.in b/src/lib/openjp2/opj_config.h.cmake.in index aed6dbc5..d922d116 100644 --- a/src/lib/openjp2/opj_config.h.cmake.in +++ b/src/lib/openjp2/opj_config.h.cmake.in @@ -1,10 +1,10 @@ /* create config.h for CMake */ -#cmakedefine OPJ_HAVE_STDINT_H @OPJ_HAVE_STDINT_H@ +#cmakedefine OPJ_HAVE_STDINT_H @OPJ_HAVE_STDINT_H@ +#cmakedefine OPJ_HAVE_INTTYPES_H @OPJ_HAVE_INTTYPES_H@ #define OPJ_PACKAGE_VERSION "@PACKAGE_VERSION@" /* Not used by openjp2*/ -/*#cmakedefine HAVE_INTTYPES_H @HAVE_INTTYPES_H@*/ /*#cmakedefine HAVE_MEMORY_H @HAVE_MEMORY_H@*/ /*#cmakedefine HAVE_STDLIB_H @HAVE_STDLIB_H@*/ /*#cmakedefine HAVE_STRINGS_H @HAVE_STRINGS_H@*/ diff --git a/src/lib/openjp2/opj_inttypes.h b/src/lib/openjp2/opj_inttypes.h index d6a29263..f94f648b 100644 --- a/src/lib/openjp2/opj_inttypes.h +++ b/src/lib/openjp2/opj_inttypes.h @@ -27,7 +27,7 @@ #define OPJ_INTTYPES_H #include "opj_config.h" -#ifdef HAVE_INTTYPES_H +#ifdef OPJ_HAVE_INTTYPES_H #include #else #if defined(_WIN32) From 021e25528220d25a1d933bcc0eea1bf5abac87e9 Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Wed, 13 Mar 2013 15:17:35 +0000 Subject: [PATCH 043/333] [trunk] use the opj_ prefix for the HAVE_FSEEKO variable --- src/lib/openjp2/opj_includes.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/openjp2/opj_includes.h b/src/lib/openjp2/opj_includes.h index 4397149a..82cc9c19 100644 --- a/src/lib/openjp2/opj_includes.h +++ b/src/lib/openjp2/opj_includes.h @@ -56,7 +56,7 @@ ftello() only on systems with special LFS support since some systems (e.g. FreeBSD) support a 64-bit off_t by default. */ -#if defined(HAVE_FSEEKO) +#if defined(OPJ_HAVE_FSEEKO) # define fseek fseeko # define ftell ftello #endif From 6de2271e2a3a5489399302c992b53ab2a0f01a8c Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Wed, 13 Mar 2013 15:21:20 +0000 Subject: [PATCH 044/333] [trunk] use the home made macro to ensure the existence of some include file --- CMakeLists.txt | 27 ++++++++++++++++++++------- cmake/EnsureFileInclude.cmake | 26 ++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 7 deletions(-) create mode 100644 cmake/EnsureFileInclude.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 49da7c46..1c56f081 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -181,15 +181,28 @@ endif() #----------------------------------------------------------------------------- # opj_config.h generation -include (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake) -CHECK_INCLUDE_FILE("stdint.h" OPJ_HAVE_STDINT_H) -CHECK_INCLUDE_FILE("inttypes.h" OPJ_HAVE_INTTYPES_H) +# Check if some include files are provided by the system +include(EnsureFileInclude) +# These files are mandatory +ensure_file_include("string.h" HAVE_STRING_H YES) +ensure_file_include("memory.h" HAVE_MEMORY_H YES) +ensure_file_include("stdlib.h" HAVE_STDLIB_H YES) +ensure_file_include("stdio.h" HAVE_STDIO_H YES) +ensure_file_include("math.h" HAVE_MATH_H YES) +ensure_file_include("float.h" HAVE_FLOAT_H YES) +ensure_file_include("time.h" HAVE_TIME_H YES) +ensure_file_include("stdarg.h" HAVE_STDARG_H YES) +ensure_file_include("ctype.h" HAVE_CTYPE_H YES) +ensure_file_include("assert.h" HAVE_ASSERT_H YES) + +# For the following files, we provide an alternative, they are not mandatory +ensure_file_include("stdint.h" OPJ_HAVE_STDINT_H NO) +ensure_file_include("inttypes.h" OPJ_HAVE_INTTYPES_H NO) + +# why check this one ? for openjpip ? +include (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake) CHECK_INCLUDE_FILE("strings.h" HAVE_STRINGS_H) -CHECK_INCLUDE_FILE("memory.h" HAVE_MEMORY_H) -CHECK_INCLUDE_FILE("stdlib.h" HAVE_STDLIB_H) -CHECK_INCLUDE_FILE("stdio.h" HAVE_STDIO_H) -CHECK_INCLUDE_FILE("string.h" HAVE_STRING_H) CHECK_INCLUDE_FILE("sys/stat.h" HAVE_SYS_STAT_H) CHECK_INCLUDE_FILE("sys/types.h" HAVE_SYS_TYPES_H) CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H) diff --git a/cmake/EnsureFileInclude.cmake b/cmake/EnsureFileInclude.cmake new file mode 100644 index 00000000..e173ea1a --- /dev/null +++ b/cmake/EnsureFileInclude.cmake @@ -0,0 +1,26 @@ +# Ensure that an include file is provided by the system +# Add the check about the mandatory status to the check_include_file macro +# provided by cmake + +include (${CMAKE_ROOT}/Modules/CheckIncludeFile.cmake) + +macro(ensure_file_include INCLUDE_FILENAME VARIABLE_NAME MANDATORY_STATUS) + +#message(WARNING "INCLUDE_FILENAME=${INCLUDE_FILENAME} \n" +# "VARIABLE_NAME=${VARIABLE_NAME} \n" +# "MANDATORY_STATUS=${MANDATORY_STATUS}") + +CHECK_INCLUDE_FILE(${INCLUDE_FILENAME} ${VARIABLE_NAME}) + +#message(WARNING "INCLUDE_FILENAME=${INCLUDE_FILENAME} \n" +# "VARIABLE_NAME=${VARIABLE_NAME} \n" +# "VARIABLE_NAME_VALUE=${${VARIABLE_NAME}} \n" +# "MANDATORY_STATUS=${MANDATORY_STATUS}") + +if (NOT ${${VARIABLE_NAME}}) + if (${MANDATORY_STATUS}) + message(FATAL_ERROR "The file ${INCLUDE_FILENAME} is mandatory but not found on your system") + endif() +endif() + +endmacro() \ No newline at end of file From a13e4a77e022be5978284b6ed6d6156d4af1378c Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Sun, 17 Mar 2013 17:03:00 +0000 Subject: [PATCH 045/333] [trunk] use everywhere the new opj_ prefix for HAVE variables and use the opj_apps_config file (thanks to winfried) --- CMakeLists.txt | 16 +++++++---- src/bin/common/color.c | 14 +++++----- src/bin/jp2/opj_compress.c | 2 +- src/bin/jp2/opj_decompress.c | 8 +++--- src/bin/jpwl/convert.c | 18 ++++++------ src/bin/jpwl/opj_jpwl_compress.c | 12 ++++---- src/bin/jpwl/opj_jpwl_decompress.c | 18 ++++++------ src/bin/mj2/opj_mj2_compress.c | 2 +- src/bin/mj2/opj_mj2_decompress.c | 8 +++--- thirdparty/CMakeLists.txt | 44 +++++++++++++++--------------- 10 files changed, 73 insertions(+), 69 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 1c56f081..6bb62e61 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -180,7 +180,7 @@ if(CMAKE_COMPILER_IS_GNUCC) endif() #----------------------------------------------------------------------------- -# opj_config.h generation +# opj_config.h generation (1/2) # Check if some include files are provided by the system include(EnsureFileInclude) @@ -211,11 +211,7 @@ CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H) include(TestLargeFiles) OPJ_TEST_LARGE_FILES(OPJ_HAVE_LARGEFILES) -configure_file( - ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config.h.cmake.in - ${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config.h - @ONLY - ) + #----------------------------------------------------------------------------- # Build Library @@ -246,6 +242,14 @@ if(BUILD_CODEC OR BUILD_MJ2) endif () add_subdirectory(wrapping) +#----------------------------------------------------------------------------- +# opj_config.h generation (2/2) +configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config.h.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config.h + @ONLY + ) + #----------------------------------------------------------------------------- # Build DOCUMENTATION (not in ALL target and only if Doxygen is found) option(BUILD_DOC "Build the HTML documentation (with doxygen if available)." OFF) diff --git a/src/bin/common/color.c b/src/bin/common/color.c index ce9ccde3..f18eb801 100644 --- a/src/bin/common/color.c +++ b/src/bin/common/color.c @@ -265,8 +265,8 @@ void color_sycc_to_rgb(opj_image_t *img) }/* color_sycc_to_rgb() */ -#if defined(HAVE_LIBLCMS2) || defined(HAVE_LIBLCMS1) -#ifdef HAVE_LIBLCMS1 +#if defined(OPJ_HAVE_LIBLCMS2) || defined(OPJ_HAVE_LIBLCMS1) +#ifdef OPJ_HAVE_LIBLCMS1 /* Bob Friesenhahn proposed:*/ #define cmsSigXYZData icSigXYZData #define cmsSigLabData icSigLabData @@ -280,7 +280,7 @@ void color_sycc_to_rgb(opj_image_t *img) #define cmsColorSpaceSignature icColorSpaceSignature #define cmsGetHeaderRenderingIntent cmsTakeRenderingIntent -#endif /* HAVE_LIBLCMS1 */ +#endif /* OPJ_HAVE_LIBLCMS1 */ void color_apply_icc_profile(opj_image_t *image) { @@ -365,7 +365,7 @@ in_type,out_type transform = cmsCreateTransform(in_prof, in_type, out_prof, out_type, intent, 0); -#ifdef HAVE_LIBLCMS2 +#ifdef OPJ_HAVE_LIBLCMS2 /* Possible for: LCMS_VERSION >= 2000 :*/ cmsCloseProfile(in_prof); cmsCloseProfile(out_prof); @@ -378,7 +378,7 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. " "ICC Profile ignored.\n",__FILE__,__LINE__); #endif image->color_space = oldspace; -#ifdef HAVE_LIBLCMS1 +#ifdef OPJ_HAVE_LIBLCMS1 cmsCloseProfile(in_prof); cmsCloseProfile(out_prof); #endif @@ -461,11 +461,11 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. " cmsDeleteTransform(transform); -#ifdef HAVE_LIBLCMS1 +#ifdef OPJ_HAVE_LIBLCMS1 cmsCloseProfile(in_prof); cmsCloseProfile(out_prof); #endif }/* color_apply_icc_profile() */ -#endif /* HAVE_LIBLCMS2 || HAVE_LIBLCMS1 */ +#endif /* OPJ_HAVE_LIBLCMS2 || OPJ_HAVE_LIBLCMS1 */ diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index 71e767b5..9b79e999 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -1773,7 +1773,7 @@ int main(int argc, char **argv) { } /* Can happen if input file is TIFF or PNG - * and HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined + * and OPJ_HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined */ if( !image) { fprintf(stderr, "Unable to load file: got no image\n"); diff --git a/src/bin/jp2/opj_decompress.c b/src/bin/jp2/opj_decompress.c index 3fced21d..0c65d852 100644 --- a/src/bin/jp2/opj_decompress.c +++ b/src/bin/jp2/opj_decompress.c @@ -57,10 +57,10 @@ #include "convert.h" #include "index.h" -#ifdef HAVE_LIBLCMS2 +#ifdef OPJ_HAVE_LIBLCMS2 #include #endif -#ifdef HAVE_LIBLCMS1 +#ifdef OPJ_HAVE_LIBLCMS1 #include #endif #include "color.h" @@ -852,7 +852,7 @@ int main(int argc, char **argv) } if(image->icc_profile_buf) { -#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) +#if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2) color_apply_icc_profile(image); /* FIXME */ #endif free(image->icc_profile_buf); @@ -935,7 +935,7 @@ int main(int argc, char **argv) break; #endif /* OPJ_HAVE_LIBPNG */ /* Can happen if output file is TIFF or PNG - * and HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined + * and OPJ_HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined */ default: fprintf(stderr,"Outfile %s not generated\n",parameters.outfile); diff --git a/src/bin/jpwl/convert.c b/src/bin/jpwl/convert.c index 11e89f7b..98f3c62c 100644 --- a/src/bin/jpwl/convert.c +++ b/src/bin/jpwl/convert.c @@ -29,21 +29,21 @@ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */ -#include "opj_config.h" +#include "opj_apps_config.h" #include #include #include #include -#ifdef HAVE_LIBTIFF +#ifdef OPJ_HAVE_LIBTIFF #include -#endif /* HAVE_LIBTIFF */ +#endif /* OPJ_HAVE_LIBTIFF */ -#ifdef HAVE_LIBPNG +#ifdef OPJ_HAVE_LIBPNG #include #include -#endif /* HAVE_LIBPNG */ +#endif /* OPJ_HAVE_LIBPNG */ #include "openjpeg.h" #include "convert.h" @@ -2074,7 +2074,7 @@ int imagetopnm(opj_image_t * image, const char *outfile) return 0; }/* imagetopnm() */ -#ifdef HAVE_LIBTIFF +#ifdef OPJ_HAVE_LIBTIFF /* -->> -->> -->> -->> TIFF IMAGE FORMAT @@ -2781,7 +2781,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) }/* tiftoimage() */ -#endif /* HAVE_LIBTIFF */ +#endif /* OPJ_HAVE_LIBTIFF */ /* -->> -->> -->> -->> @@ -3027,7 +3027,7 @@ int imagetoraw(opj_image_t * image, const char *outfile) return 0; } -#ifdef HAVE_LIBPNG +#ifdef OPJ_HAVE_LIBPNG #define PNG_MAGIC "\x89PNG\x0d\x0a\x1a\x0a" #define MAGIC_SIZE 8 @@ -3560,4 +3560,4 @@ fin: return fails; }/* imagetopng() */ -#endif /* HAVE_LIBPNG */ +#endif /* OPJ_HAVE_LIBPNG */ diff --git a/src/bin/jpwl/opj_jpwl_compress.c b/src/bin/jpwl/opj_jpwl_compress.c index c98eea17..b5bfc05b 100644 --- a/src/bin/jpwl/opj_jpwl_compress.c +++ b/src/bin/jpwl/opj_jpwl_compress.c @@ -49,7 +49,7 @@ #include #endif /* _WIN32 */ -#include "opj_config.h" +#include "opj_apps_config.h" #include "openjpeg.h" #include "opj_getopt.h" #include "convert.h" @@ -1627,7 +1627,7 @@ int main(int argc, char **argv) { return 1; } break; -#ifdef HAVE_LIBTIFF +#ifdef OPJ_HAVE_LIBTIFF case TIF_DFMT: image = tiftoimage(parameters.infile, ¶meters); if (!image) { @@ -1635,7 +1635,7 @@ int main(int argc, char **argv) { return 1; } break; -#endif /* HAVE_LIBTIFF */ +#endif /* OPJ_HAVE_LIBTIFF */ case RAW_DFMT: image = rawtoimage(parameters.infile, ¶meters, &raw_cp); if (!image) { @@ -1651,7 +1651,7 @@ int main(int argc, char **argv) { return 1; } break; -#ifdef HAVE_LIBPNG +#ifdef OPJ_HAVE_LIBPNG case PNG_DFMT: image = pngtoimage(parameters.infile, ¶meters); if (!image) { @@ -1659,10 +1659,10 @@ int main(int argc, char **argv) { return 1; } break; -#endif /* HAVE_LIBPNG */ +#endif /* OPJ_HAVE_LIBPNG */ } /* Can happen if input file is TIFF or PNG - * and HAVE_LIBTIF or HAVE_LIBPNG is undefined + * and OPJ_HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined */ if( !image) { diff --git a/src/bin/jpwl/opj_jpwl_decompress.c b/src/bin/jpwl/opj_jpwl_decompress.c index 36967b27..860c078c 100644 --- a/src/bin/jpwl/opj_jpwl_decompress.c +++ b/src/bin/jpwl/opj_jpwl_decompress.c @@ -49,16 +49,16 @@ #define _strnicmp strncasecmp #endif /* _WIN32 */ -#include "opj_config.h" +#include "opj_apps_config.h" #include "openjpeg.h" #include "opj_getopt.h" #include "convert.h" #include "index.h" -#ifdef HAVE_LIBLCMS2 +#ifdef OPJ_HAVE_LIBLCMS2 #include #endif -#ifdef HAVE_LIBLCMS1 +#ifdef OPJ_HAVE_LIBLCMS1 #include #endif #include "color.h" @@ -753,7 +753,7 @@ int main(int argc, char **argv) { if(image->icc_profile_buf) { -#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) +#if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2) color_apply_icc_profile(image); #endif @@ -790,7 +790,7 @@ int main(int argc, char **argv) { fprintf(stdout,"Generated Outfile %s\n",parameters.outfile); } break; -#ifdef HAVE_LIBTIFF +#ifdef OPJ_HAVE_LIBTIFF case TIF_DFMT: /* TIFF */ if(imagetotif(image, parameters.outfile)){ fprintf(stdout,"Outfile %s not generated\n",parameters.outfile); @@ -799,7 +799,7 @@ int main(int argc, char **argv) { fprintf(stdout,"Generated Outfile %s\n",parameters.outfile); } break; -#endif /* HAVE_LIBTIFF */ +#endif /* OPJ_HAVE_LIBTIFF */ case RAW_DFMT: /* RAW */ if(imagetoraw(image, parameters.outfile)){ fprintf(stdout,"Error generating raw file. Outfile %s not generated\n",parameters.outfile); @@ -817,7 +817,7 @@ int main(int argc, char **argv) { fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile); } break; -#ifdef HAVE_LIBPNG +#ifdef OPJ_HAVE_LIBPNG case PNG_DFMT: /* PNG */ if(imagetopng(image, parameters.outfile)){ fprintf(stdout,"Error generating png file. Outfile %s not generated\n",parameters.outfile); @@ -826,9 +826,9 @@ int main(int argc, char **argv) { fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile); } break; -#endif /* HAVE_LIBPNG */ +#endif /* OPJ_HAVE_LIBPNG */ /* Can happen if output file is TIFF or PNG - * and HAVE_LIBTIF or HAVE_LIBPNG is undefined + * and OPJ_HAVE_LIBTIF or OPJ_HAVE_LIBPNG is undefined */ default: fprintf(stderr,"Outfile %s not generated\n",parameters.outfile); diff --git a/src/bin/mj2/opj_mj2_compress.c b/src/bin/mj2/opj_mj2_compress.c index 73ddcbe8..c8f6642b 100644 --- a/src/bin/mj2/opj_mj2_compress.c +++ b/src/bin/mj2/opj_mj2_compress.c @@ -29,7 +29,7 @@ #include #include -#include "opj_config.h" +#include "opj_apps_config.h" #include "openjpeg.h" #include "j2k_lib.h" #include "cio.h" diff --git a/src/bin/mj2/opj_mj2_decompress.c b/src/bin/mj2/opj_mj2_decompress.c index ee312f61..e9278a50 100644 --- a/src/bin/mj2/opj_mj2_decompress.c +++ b/src/bin/mj2/opj_mj2_decompress.c @@ -29,7 +29,7 @@ #include #include -#include "opj_config.h" +#include "opj_apps_config.h" #include "openjpeg.h" #include "j2k_lib.h" #include "cio.h" @@ -38,10 +38,10 @@ #include "mj2.h" #include "mj2_convert.h" -#ifdef HAVE_LIBLCMS2 +#ifdef OPJ_HAVE_LIBLCMS2 #include #endif -#ifdef HAVE_LIBLCMS1 +#ifdef OPJ_HAVE_LIBLCMS1 #include #endif #include "color.h" @@ -188,7 +188,7 @@ int main(int argc, char *argv[]) { if(img->icc_profile_buf) { -#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2) +#if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2) color_apply_icc_profile(img); #endif diff --git a/thirdparty/CMakeLists.txt b/thirdparty/CMakeLists.txt index 844d1831..089ce149 100644 --- a/thirdparty/CMakeLists.txt +++ b/thirdparty/CMakeLists.txt @@ -29,8 +29,8 @@ IF(BUILD_THIRDPARTY) # Try to build it message(STATUS "We will build PNG lib from thirdparty") ADD_SUBDIRECTORY(libpng) - SET(HAVE_PNG_H 1 PARENT_SCOPE) - SET(HAVE_LIBPNG 1 PARENT_SCOPE) + SET(OPJ_HAVE_PNG_H 1 PARENT_SCOPE) + SET(OPJ_HAVE_LIBPNG 1 PARENT_SCOPE) SET(PNG_LIBNAME png PARENT_SCOPE) SET(PNG_INCLUDE_DIRNAME ${OPENJPEG_SOURCE_DIR}/thirdparty/libpng PARENT_SCOPE) ELSE (BUILD_THIRDPARTY) @@ -38,13 +38,13 @@ ELSE (BUILD_THIRDPARTY) FIND_PACKAGE(PNG) IF(PNG_FOUND) message(STATUS "Your system seems to have a PNG lib available, we will use it") - SET(HAVE_PNG_H 1 PARENT_SCOPE) - SET(HAVE_LIBPNG 1 PARENT_SCOPE) + SET(OPJ_HAVE_PNG_H 1 PARENT_SCOPE) + SET(OPJ_HAVE_LIBPNG 1 PARENT_SCOPE) SET(PNG_LIBNAME ${PNG_LIBRARIES} PARENT_SCOPE) SET(PNG_INCLUDE_DIRNAME ${PNG_PNG_INCLUDE_DIR} PARENT_SCOPE) ELSE(PNG_FOUND) # not found - SET(HAVE_PNG_H 0 PARENT_SCOPE) - SET(HAVE_LIBPNG 0 PARENT_SCOPE) + SET(OPJ_HAVE_PNG_H 0 PARENT_SCOPE) + SET(OPJ_HAVE_LIBPNG 0 PARENT_SCOPE) message(STATUS "PNG lib not found, activate BUILD_THIRDPARTY if you want build it") ENDIF(PNG_FOUND) ENDIF (ZLIB_FOUND) @@ -62,27 +62,27 @@ IF(BUILD_THIRDPARTY) ${OPENJPEG_SOURCE_DIR}/thirdparty/libtiff ${OPENJPEG_BINARY_DIR}/thirdparty/libtiff PARENT_SCOPE) - SET(HAVE_TIFF_H 1 PARENT_SCOPE) - SET(HAVE_LIBTIFF 1 PARENT_SCOPE) + SET(OPJ_HAVE_TIFF_H 1 PARENT_SCOPE) + SET(OPJ_HAVE_LIBTIFF 1 PARENT_SCOPE) ELSE (BUILD_THIRDPARTY) FIND_PACKAGE(TIFF) IF(TIFF_FOUND) message(STATUS "Your system seems to have a TIFF lib available, we will use it") - SET(HAVE_TIFF_H 1 PARENT_SCOPE) - SET(HAVE_LIBTIFF 1 PARENT_SCOPE) + SET(OPJ_HAVE_TIFF_H 1 PARENT_SCOPE) + SET(OPJ_HAVE_LIBTIFF 1 PARENT_SCOPE) SET(TIFF_LIBNAME ${TIFF_LIBRARIES} PARENT_SCOPE) SET(TIFF_INCLUDE_DIRNAME ${TIFF_INCLUDE_DIR} PARENT_SCOPE) ELSE (TIFF_FOUND) # not found - SET(HAVE_TIFF_H 0 PARENT_SCOPE) - SET(HAVE_LIBTIFF 0 PARENT_SCOPE) + SET(OPJ_HAVE_TIFF_H 0 PARENT_SCOPE) + SET(OPJ_HAVE_LIBTIFF 0 PARENT_SCOPE) message(STATUS "TIFF lib not found, activate BUILD_THIRDPARTY if you want build it") ENDIF(TIFF_FOUND) ENDIF(BUILD_THIRDPARTY) #------------ # Try to find lib LCMS2 (or by default LCMS) -SET(HAVE_LCMS_H 0 PARENT_SCOPE) -SET(HAVE_LIBLCMS 0 PARENT_SCOPE) +SET(OPJ_HAVE_LCMS_H 0 PARENT_SCOPE) +SET(OPJ_HAVE_LIBLCMS 0 PARENT_SCOPE) IF( BUILD_THIRDPARTY) # Try to build lcms2 @@ -90,14 +90,14 @@ IF( BUILD_THIRDPARTY) ADD_SUBDIRECTORY(liblcms2) SET(LCMS_LIBNAME lcms2 PARENT_SCOPE) SET(LCMS_INCLUDE_DIRNAME ${OPENJPEG_SOURCE_DIR}/thirdparty/liblcms2/include PARENT_SCOPE) # - SET(HAVE_LCMS2_H 1 PARENT_SCOPE) - SET(HAVE_LIBLCMS2 1 PARENT_SCOPE) + SET(OPJ_HAVE_LCMS2_H 1 PARENT_SCOPE) + SET(OPJ_HAVE_LIBLCMS2 1 PARENT_SCOPE) ELSE (BUILD_THIRDPARTY) FIND_PACKAGE(LCMS2) IF(LCMS2_FOUND) message(STATUS "Your system seems to have a LCMS2 lib available, we will use it") - SET(HAVE_LCMS2_H 1 PARENT_SCOPE) - SET(HAVE_LIBLCMS2 1 PARENT_SCOPE) + SET(OPJ_HAVE_LCMS2_H 1 PARENT_SCOPE) + SET(OPJ_HAVE_LIBLCMS2 1 PARENT_SCOPE) SET(LCMS_LIBNAME ${LCMS2_LIBRARIES} PARENT_SCOPE) SET(LCMS_INCLUDE_DIRNAME ${LCMS2_INCLUDE_DIRS} PARENT_SCOPE) ELSE (LCMS2_FOUND) # not found lcms2 @@ -105,13 +105,13 @@ ELSE (BUILD_THIRDPARTY) FIND_PACKAGE(LCMS) IF(LCMS_FOUND) message(STATUS "Your system seems to have a LCMS lib available, we will use it") - SET(HAVE_LCMS_H 1 PARENT_SCOPE) - SET(HAVE_LIBLCMS 1 PARENT_SCOPE) + SET(OPJ_HAVE_LCMS_H 1 PARENT_SCOPE) + SET(OPJ_HAVE_LIBLCMS 1 PARENT_SCOPE) SET(LCMS_LIBNAME ${LCMS_LIBRARIES} PARENT_SCOPE) SET(LCMS_INCLUDE_DIRNAME ${LCMS_INCLUDE_DIRS} PARENT_SCOPE) ELSE (LCMS_FOUND) # not found lcms - SET(HAVE_LCMS2_H 0 PARENT_SCOPE) - SET(HAVE_LIBLCMS2 0 PARENT_SCOPE) + SET(OPJ_HAVE_LCMS2_H 0 PARENT_SCOPE) + SET(OPJ_HAVE_LIBLCMS2 0 PARENT_SCOPE) message(STATUS "LCMS2 or LCMS lib not found, activate BUILD_THIRDPARTY if you want build it") ENDIF (LCMS_FOUND) ENDIF(LCMS2_FOUND) From 0abf4f8fbb1e63f96c4f0c78ae007011cef2f363 Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Sun, 17 Mar 2013 17:06:30 +0000 Subject: [PATCH 046/333] [trunk]remove wrong code in mj2 library detected by winfried (thanks to you) --- src/lib/openmj2/j2k.c | 18 ------------------ 1 file changed, 18 deletions(-) diff --git a/src/lib/openmj2/j2k.c b/src/lib/openmj2/j2k.c index c9293730..7c22ca7c 100644 --- a/src/lib/openmj2/j2k.c +++ b/src/lib/openmj2/j2k.c @@ -1538,24 +1538,6 @@ static void j2k_read_sod(opj_j2k_t *j2k) { truncate = 1; /* Case of a truncate codestream */ } - {/* chop padding bytes: */ - unsigned char *s, *e; - - s = cio_getbp(cio); - e = s + len; - - if(len > 8) s = e - 8; - - if(e[-2] == 0x00 && e[-1] == 0x00) /* padding bytes */ - { - while(e > s) - { - if(e[-2] == 0xff && e[-1] == 0xd9) break; - --len; --e; truncate = 1; - } - } - } - data = j2k->tile_data[curtileno]; data = (unsigned char*) opj_realloc(data, (j2k->tile_len[curtileno] + len) * sizeof(unsigned char)); From 07e6994be1b903b0481008f1cee01b4ad530bb31 Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Sun, 17 Mar 2013 17:08:12 +0000 Subject: [PATCH 047/333] [trunk] use OPJ_ prefix on HAVE variable also for tests --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5d4f5454..74555dc7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -80,7 +80,7 @@ add_test(rta5 ${EXECUTABLE_OUTPUT_PATH}/j2k_random_tile_access tte5.j2k) set_property(TEST rta5 APPEND PROPERTY DEPENDS tte5) # No image send to the dashboard if lib PNG is not available. -if(NOT HAVE_LIBPNG) +if(NOT OPJ_HAVE_LIBPNG) message(WARNING "Lib PNG seems to be not available: if you want run the non-regression tests with images reported to the dashboard, you need it (try BUILD_THIRDPARTY)") endif() From 1e414c8f37e0f392bf1867b614023e9a2ed09d3a Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Sun, 17 Mar 2013 18:16:03 +0000 Subject: [PATCH 048/333] [trunk] correct issue 188 (thanks winfried) and add test about it. Fixes issue 188 --- src/lib/openjp2/jp2.c | 19 ++++++++++++------- tests/nonregression/test_suite.ctest.in | 2 ++ 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c index 9fd78592..5f2390f3 100644 --- a/src/lib/openjp2/jp2.c +++ b/src/lib/openjp2/jp2.c @@ -428,12 +428,10 @@ static void opj_jp2_setup_decoding_validation (opj_jp2_t *jp2); static void opj_jp2_setup_header_reading (opj_jp2_t *jp2); /* ----------------------------------------------------------------------- */ - OPJ_BOOL opj_jp2_read_boxhdr(opj_jp2_box_t *box, - OPJ_UINT32 * p_number_bytes_read, - opj_stream_private_t *cio, - opj_event_mgr_t * p_manager - ) + OPJ_UINT32 * p_number_bytes_read, + opj_stream_private_t *cio, + opj_event_mgr_t * p_manager ) { /* read header from file */ OPJ_BYTE l_data_header [8]; @@ -452,6 +450,12 @@ static void opj_jp2_setup_header_reading (opj_jp2_t *jp2); /* process read data */ opj_read_bytes(l_data_header,&(box->length), 4); opj_read_bytes(l_data_header+4,&(box->type), 4); + + if(box->length == 0)/* last box */ + { + box->length = opj_stream_get_number_byte_left(cio); + return OPJ_TRUE; + } /* do we have a "special very large box ?" */ /* read then the XLBox */ @@ -467,14 +471,15 @@ static void opj_jp2_setup_header_reading (opj_jp2_t *jp2); return OPJ_FALSE; } + *p_number_bytes_read = 16; opj_read_bytes(l_data_header,&l_xl_part_size, 4); if (l_xl_part_size != 0) { opj_event_msg(p_manager, EVT_ERROR, "Cannot handle box sizes higher than 2^32\n"); return OPJ_FALSE; } - opj_read_bytes(l_data_header,&(box->length), 4); + opj_read_bytes(l_data_header+4,&(box->length), 4); } - return OPJ_TRUE; + return OPJ_TRUE; } #if 0 diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 13f66f45..dad81d77 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -89,6 +89,8 @@ opj_decompress -i @INPUT_NR_PATH@/mem-b2b86b74-2753.jp2 -o @TEMP_PATH@/mem-b2b8 ! opj_decompress -i @INPUT_NR_PATH@/gdal_fuzzer_check_comp_dx_dy.jp2 -o @TEMP_PATH@/gdal_fuzzer_check_comp_dx_dy.pgx # issue 202 opj_decompress -i @INPUT_NR_PATH@/file409752.jp2 -o @TEMP_PATH@/file409752.png +# issue 188 +opj_decompress -i @INPUT_NR_PATH@/issue188_beach_64bitsbox.jp2 -o @TEMP_PATH@/issue188_beach_64bitsbox.jp2.tif # decode with specific area # prec=12; nb_c=1 From f769d5e27f890ea1bb33b70e1d72b28b551d49f6 Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Sun, 17 Mar 2013 18:27:41 +0000 Subject: [PATCH 049/333] [trunk] manage correctly the case where meth value is not correct (thanks winfried) --- src/lib/openjp2/jp2.c | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c index 5f2390f3..77df1529 100644 --- a/src/lib/openjp2/jp2.c +++ b/src/lib/openjp2/jp2.c @@ -1103,6 +1103,8 @@ OPJ_BOOL opj_jp2_read_colr( opj_jp2_t *jp2, } opj_read_bytes(p_colr_header_data,&jp2->enumcs ,4); /* EnumCS */ + + jp2->color.jp2_has_colr = 1; } else if (jp2->meth == 2) { /* ICC profile */ @@ -1124,14 +1126,17 @@ OPJ_BOOL opj_jp2_read_colr( opj_jp2_t *jp2, ++p_colr_header_data; jp2->color.icc_profile_buf[it_icc_value] = (OPJ_BYTE) l_value; } - + + jp2->color.jp2_has_colr = 1; } - else - opj_event_msg(p_manager, EVT_INFO, "COLR BOX meth value is not a regular value (%d), so we will skip the fields following the approx field.\n", jp2->meth); - - jp2->color.jp2_has_colr = 1; - - return OPJ_TRUE; + else if (jp2->meth > 2) + { + /* ISO/IEC 15444-1:2004 (E), Table I.9 ­ Legal METH values: + conforming JP2 reader shall ignore the entire Colour Specification box.*/ + opj_event_msg(p_manager, EVT_INFO, "COLR BOX meth value is not a regular value (%d), " + "so we will ignore the entire Colour Specification box. \n", jp2->meth); + } + return OPJ_TRUE; } OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2, From ecb93d97a561dadd3fe422a3d7c7b0d3f024b914 Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Sun, 17 Mar 2013 22:22:11 +0000 Subject: [PATCH 050/333] [trunk] add access to opj_apps_config.h to old applications --- src/bin/jpwl/CMakeLists.txt | 1 + src/bin/mj2/CMakeLists.txt | 1 + 2 files changed, 2 insertions(+) diff --git a/src/bin/jpwl/CMakeLists.txt b/src/bin/jpwl/CMakeLists.txt index 7bb0b496..5df225de 100644 --- a/src/bin/jpwl/CMakeLists.txt +++ b/src/bin/jpwl/CMakeLists.txt @@ -11,6 +11,7 @@ set(common_SRCS # Headers file are located here: include_directories( ${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h + ${OPENJPEG_BINARY_DIR}/src/bin/common # opj_apps_config.h ${OPENJPEG_SOURCE_DIR}/src/lib/openmj2 ${OPENJPEG_SOURCE_DIR}/src/bin/common ${LCMS_INCLUDE_DIRNAME} diff --git a/src/bin/mj2/CMakeLists.txt b/src/bin/mj2/CMakeLists.txt index a270829f..e6b005b6 100644 --- a/src/bin/mj2/CMakeLists.txt +++ b/src/bin/mj2/CMakeLists.txt @@ -13,6 +13,7 @@ endif() # Headers file are located here: include_directories( ${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h + ${OPENJPEG_BINARY_DIR}/src/bin/common # opj_apps_config.h ${OPENJPEG_SOURCE_DIR}/src/lib/openmj2 ${OPENJPEG_SOURCE_DIR}/src/bin/common ${LCMS_INCLUDE_DIRNAME} From 07ae149955db833fea2a785c9655153252751bc1 Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Sun, 24 Mar 2013 22:50:46 +0000 Subject: [PATCH 051/333] [trunk] managed nicely the case where TPSot value is incorrect (thanks winfried). Update the test suite to check this case. Updates issue 202. Updates issue 206. Update issue 208 --- src/lib/openjp2/j2k.c | 27 ++++++++++++++++++++++++- tests/nonregression/test_suite.ctest.in | 8 +++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 3b439fc7..4657ba99 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -7033,6 +7033,12 @@ OPJ_BOOL opj_j2k_read_tile_header( opj_j2k_t * p_j2k, /* Try to read until the Start Of Data is detected */ while (l_current_marker != J2K_MS_SOD) { + + if(opj_stream_get_number_byte_left(p_stream) == 0) + { + p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_NEOC; + break; + } /* Try to read 2 bytes (the marker size) from stream and copy them into the buffer */ if (opj_stream_read_data(p_stream,p_j2k->m_specific_param.m_decoder.m_header_data,2,p_manager) != 2) { @@ -7127,6 +7133,9 @@ OPJ_BOOL opj_j2k_read_tile_header( opj_j2k_t * p_j2k, opj_read_bytes(p_j2k->m_specific_param.m_decoder.m_header_data,&l_current_marker,2); } } + if(opj_stream_get_number_byte_left(p_stream) == 0 + && p_j2k->m_specific_param.m_decoder.m_state == J2K_STATE_NEOC) + break; /* If we didn't skip data before, we need to read the SOD marker*/ if (! p_j2k->m_specific_param.m_decoder.m_skip_data) { @@ -7260,6 +7269,11 @@ OPJ_BOOL opj_j2k_decode_tile ( opj_j2k_t * p_j2k, p_j2k->m_specific_param.m_decoder.m_can_decode = 0; p_j2k->m_specific_param.m_decoder.m_state &= (~ (0x0080));/* FIXME J2K_DEC_STATE_DATA);*/ + if(opj_stream_get_number_byte_left(p_stream) == 0 + && p_j2k->m_specific_param.m_decoder.m_state == J2K_STATE_NEOC){ + return OPJ_TRUE; + } + if (p_j2k->m_specific_param.m_decoder.m_state != 0x0100){ /*FIXME J2K_DEC_STATE_EOC)*/ if (opj_stream_read_data(p_stream,l_data,2,p_manager) != 2) { opj_event_msg(p_manager, EVT_ERROR, "Stream too short\n"); @@ -7275,6 +7289,11 @@ OPJ_BOOL opj_j2k_decode_tile ( opj_j2k_t * p_j2k, else if (l_current_marker != J2K_MS_SOT) { opj_event_msg(p_manager, EVT_ERROR, "Stream too short, expected SOT\n"); + + if(opj_stream_get_number_byte_left(p_stream) == 0) { + p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_NEOC; + return OPJ_TRUE; + } return OPJ_FALSE; } } @@ -8691,6 +8710,7 @@ OPJ_BOOL opj_j2k_decode_tiles ( opj_j2k_t *p_j2k, OPJ_INT32 l_tile_x0,l_tile_y0,l_tile_x1,l_tile_y1; OPJ_UINT32 l_nb_comps; OPJ_BYTE * l_current_data; + OPJ_UINT32 nr_tiles = 0; l_current_data = (OPJ_BYTE*)opj_malloc(1000); if (! l_current_data) { @@ -8739,7 +8759,12 @@ OPJ_BOOL opj_j2k_decode_tiles ( opj_j2k_t *p_j2k, return OPJ_FALSE; } opj_event_msg(p_manager, EVT_INFO, "Image data has been updated with tile %d.\n\n", l_current_tile_no + 1); - + + if(opj_stream_get_number_byte_left(p_stream) == 0 + && p_j2k->m_specific_param.m_decoder.m_state == J2K_STATE_NEOC) + break; + if(++nr_tiles == p_j2k->m_cp.th * p_j2k->m_cp.tw) + break; } opj_free(l_current_data); diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index dad81d77..c414e4ca 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -66,8 +66,8 @@ opj_decompress -i @INPUT_NR_PATH@/orb-blue10-win-j2k.j2k -o @TEMP_PATH@/orb-blu opj_decompress -i @INPUT_NR_PATH@/orb-blue10-win-jp2.jp2 -o @TEMP_PATH@/orb-blue10-win-jp2.jp2.pgx opj_decompress -i @INPUT_NR_PATH@/relax.jp2 -o @TEMP_PATH@/relax.jp2.pgx opj_decompress -i @INPUT_NR_PATH@/test_lossless.j2k -o @TEMP_PATH@/test_lossless.j2k.pgx -# text_GBR.jp2 file exhibt a error about a tile part with a index > of the number of tile-part in this tile. -!opj_decompress -i @INPUT_NR_PATH@/text_GBR.jp2 -o @TEMP_PATH@/text_GBR.jp2.pgx +# text_GBR.jp2 file exhibt a error about a tile part with a index > of the number of tile-part in this tile (related to issue 202, 206, 208) +opj_decompress -i @INPUT_NR_PATH@/text_GBR.jp2 -o @TEMP_PATH@/text_GBR.jp2.pgx # pacs.ge file should throw an error but finally it seems work with v2 opj_decompress -i @INPUT_NR_PATH@/pacs.ge.j2k -o @TEMP_PATH@/pacs.ge.j2k.pgx # related to issue 135 @@ -77,7 +77,7 @@ opj_decompress -i @INPUT_NR_PATH@/kodak_2layers_lrcp.j2c -o @TEMP_PATH@/kodak_2 opj_decompress -i @INPUT_NR_PATH@/issue104_jpxstream.jp2 -o @TEMP_PATH@/issue104_jpxstream.jp2.pgx # File not supported by kakadu (Malformed PCLR box) and not supoprter by openjpeg (problem with value of TPSot) opj_decompress -i @INPUT_NR_PATH@/mem-b2ace68c-1381.jp2 -o @TEMP_PATH@/mem-b2ace68c-1381.jp2.pgx -# File which produced weird output with kakadu and not supoprter by openjpeg (problem with value of TPSot) +# File which produced weird output with kakadu and not supoprter by openjpeg (problem with value of TPSot, issue 202, 206, 208) opj_decompress -i @INPUT_NR_PATH@/mem-b2b86b74-2753.jp2 -o @TEMP_PATH@/mem-b2b86b74-2753.jp2.pgx # issue 191 raised by the gdal fuzzer test (should properly failed) !opj_decompress -i @INPUT_NR_PATH@/gdal_fuzzer_unchecked_numresolutions.jp2 -o @TEMP_PATH@/gdal_fuzzer_unchecked_numresolutions.pgx @@ -91,6 +91,8 @@ opj_decompress -i @INPUT_NR_PATH@/mem-b2b86b74-2753.jp2 -o @TEMP_PATH@/mem-b2b8 opj_decompress -i @INPUT_NR_PATH@/file409752.jp2 -o @TEMP_PATH@/file409752.png # issue 188 opj_decompress -i @INPUT_NR_PATH@/issue188_beach_64bitsbox.jp2 -o @TEMP_PATH@/issue188_beach_64bitsbox.jp2.tif +# issue 206 +opj_decompress -i @INPUT_NR_PATH@/issue206_image-000.jp2 -o @TEMP_PATH@/issue206_image-000.jp2.png # decode with specific area # prec=12; nb_c=1 From bf0fa4089fa33a4447054ff883acc92da604de52 Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Sun, 24 Mar 2013 23:12:41 +0000 Subject: [PATCH 052/333] [trunk] enhance the support of sYCC into opj_decompress application (thanks winfried). --- src/bin/jp2/opj_decompress.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/bin/jp2/opj_decompress.c b/src/bin/jp2/opj_decompress.c index 0c65d852..b2e4e83c 100644 --- a/src/bin/jp2/opj_decompress.c +++ b/src/bin/jp2/opj_decompress.c @@ -850,6 +850,13 @@ int main(int argc, char **argv) if(image->color_space == OPJ_CLRSPC_SYCC){ color_sycc_to_rgb(image); /* FIXME */ } + + if( image->color_space != OPJ_CLRSPC_SYCC + && image->numcomps == 3 && image->comps[0].dx == image->comps[0].dy + && image->comps[1].dx != 1 ) + image->color_space = OPJ_CLRSPC_SYCC; + else if (image->numcomps <= 2) + image->color_space = OPJ_CLRSPC_GRAY; if(image->icc_profile_buf) { #if defined(OPJ_HAVE_LIBLCMS1) || defined(OPJ_HAVE_LIBLCMS2) From 8ee74f6bff65ebfadaa728aa00cdb9005246d902 Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Mon, 25 Mar 2013 09:54:15 +0000 Subject: [PATCH 053/333] [trunk] update test suite because now illegalcolortransform.j2k could be decoded --- tests/nonregression/test_suite.ctest.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index c414e4ca..86d10576 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -51,7 +51,7 @@ opj_decompress -i @INPUT_NR_PATH@/buxR.j2k -o @TEMP_PATH@/buxR.j2k.pgx opj_decompress -i @INPUT_NR_PATH@/Cannotreaddatawithnosizeknown.j2k -o @TEMP_PATH@/Cannotreaddatawithnosizeknown.j2k.pgx opj_decompress -i @INPUT_NR_PATH@/cthead1.j2k -o @TEMP_PATH@/cthead1.j2k.pgx opj_decompress -i @INPUT_NR_PATH@/CT_Phillips_JPEG2K_Decompr_Problem.j2k -o @TEMP_PATH@/CT_Phillips_JPEG2K_Decompr_Problem.j2k.pgx -!opj_decompress -i @INPUT_NR_PATH@/illegalcolortransform.j2k -o @TEMP_PATH@/illegalcolortransform.j2k.pgx +opj_decompress -i @INPUT_NR_PATH@/illegalcolortransform.j2k -o @TEMP_PATH@/illegalcolortransform.j2k.pgx opj_decompress -i @INPUT_NR_PATH@/j2k32.j2k -o @TEMP_PATH@/j2k32.j2k.pgx opj_decompress -i @INPUT_NR_PATH@/kakadu_v4-4_openjpegv2_broken.j2k -o @TEMP_PATH@/kakadu_v4-4_openjpegv2_broken.j2k.pgx opj_decompress -i @INPUT_NR_PATH@/MarkerIsNotCompliant.j2k -o @TEMP_PATH@/MarkerIsNotCompliant.j2k.pgx From 68415d040f73ec4e6a0c091bc0652b7825a6e82b Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Mon, 25 Mar 2013 12:43:27 +0000 Subject: [PATCH 054/333] [trunk] separate the opj_config file between public and private part to avoid expose unused variables into the public API. --- CMakeLists.txt | 8 +++-- src/lib/openjp2/CMakeLists.txt | 2 +- src/lib/openjp2/openjpeg.c | 1 - src/lib/openjp2/opj_config.h.cmake.in | 34 +------------------ src/lib/openjp2/opj_config_private.h.cmake.in | 31 +++++++++++++++++ src/lib/openjp2/opj_includes.h | 2 +- 6 files changed, 40 insertions(+), 38 deletions(-) create mode 100644 src/lib/openjp2/opj_config_private.h.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index 6bb62e61..c55f46f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -211,8 +211,6 @@ CHECK_INCLUDE_FILE("unistd.h" HAVE_UNISTD_H) include(TestLargeFiles) OPJ_TEST_LARGE_FILES(OPJ_HAVE_LARGEFILES) - - #----------------------------------------------------------------------------- # Build Library add_subdirectory(src) @@ -249,6 +247,12 @@ configure_file( ${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config.h @ONLY ) + + configure_file( + ${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp2/opj_config_private.h.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/src/lib/openjp2/opj_config_private.h + @ONLY + ) #----------------------------------------------------------------------------- # Build DOCUMENTATION (not in ALL target and only if Doxygen is found) diff --git a/src/lib/openjp2/CMakeLists.txt b/src/lib/openjp2/CMakeLists.txt index a6359890..5c87f297 100644 --- a/src/lib/openjp2/CMakeLists.txt +++ b/src/lib/openjp2/CMakeLists.txt @@ -5,7 +5,7 @@ install( FILES ${CMAKE_CURRENT_BINARY_DIR}/opj_config.h DESTINATION ${OPENJPEG_INSTALL_INCLUDE_DIR} COMPONENT Headers) include_directories( - ${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h + ${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h and opj_config_private.h ) # Defines the source code for the library set(OPENJPEG_SRCS diff --git a/src/lib/openjp2/openjpeg.c b/src/lib/openjp2/openjpeg.c index ec9746f7..e7ca5f80 100644 --- a/src/lib/openjp2/openjpeg.c +++ b/src/lib/openjp2/openjpeg.c @@ -30,7 +30,6 @@ #include #endif /* _WIN32 */ -#include "opj_config.h" #include "opj_includes.h" /** diff --git a/src/lib/openjp2/opj_config.h.cmake.in b/src/lib/openjp2/opj_config.h.cmake.in index d922d116..2f5311b8 100644 --- a/src/lib/openjp2/opj_config.h.cmake.in +++ b/src/lib/openjp2/opj_config.h.cmake.in @@ -1,34 +1,2 @@ -/* create config.h for CMake */ +/* create opj_config.h for CMake */ #cmakedefine OPJ_HAVE_STDINT_H @OPJ_HAVE_STDINT_H@ -#cmakedefine OPJ_HAVE_INTTYPES_H @OPJ_HAVE_INTTYPES_H@ - -#define OPJ_PACKAGE_VERSION "@PACKAGE_VERSION@" - -/* Not used by openjp2*/ -/*#cmakedefine HAVE_MEMORY_H @HAVE_MEMORY_H@*/ -/*#cmakedefine HAVE_STDLIB_H @HAVE_STDLIB_H@*/ -/*#cmakedefine HAVE_STRINGS_H @HAVE_STRINGS_H@*/ -/*#cmakedefine HAVE_STRING_H @HAVE_STRING_H@*/ -/*#cmakedefine HAVE_SYS_STAT_H @HAVE_SYS_STAT_H@*/ -/*#cmakedefine HAVE_SYS_TYPES_H @HAVE_SYS_TYPES_H@ */ -/*#cmakedefine HAVE_UNISTD_H @HAVE_UNISTD_H@*/ - -#cmakedefine _LARGEFILE_SOURCE -#cmakedefine _LARGE_FILES -#cmakedefine _FILE_OFFSET_BITS @_FILE_OFFSET_BITS@ -#cmakedefine OPJ_HAVE_FSEEKO @OPJ_HAVE_FSEEKO@ - - -/* Byte order. */ -/* All compilers that support Mac OS X define either __BIG_ENDIAN__ or -__LITTLE_ENDIAN__ to match the endianness of the architecture being -compiled for. This is not necessarily the same as the architecture of the -machine doing the building. In order to support Universal Binaries on -Mac OS X, we prefer those defines to decide the endianness. -On other platforms we use the result of the TRY_RUN. */ -#if !defined(__APPLE__) -#cmakedefine OPJ_BIG_ENDIAN -#elif defined(__BIG_ENDIAN__) -# define OPJ_BIG_ENDIAN -#endif - diff --git a/src/lib/openjp2/opj_config_private.h.cmake.in b/src/lib/openjp2/opj_config_private.h.cmake.in new file mode 100644 index 00000000..8a02c79d --- /dev/null +++ b/src/lib/openjp2/opj_config_private.h.cmake.in @@ -0,0 +1,31 @@ +/* create opj_config_private.h for CMake */ +#cmakedefine OPJ_HAVE_INTTYPES_H @OPJ_HAVE_INTTYPES_H@ + +#define OPJ_PACKAGE_VERSION "@PACKAGE_VERSION@" + +/* Not used by openjp2*/ +/*#cmakedefine HAVE_MEMORY_H @HAVE_MEMORY_H@*/ +/*#cmakedefine HAVE_STDLIB_H @HAVE_STDLIB_H@*/ +/*#cmakedefine HAVE_STRINGS_H @HAVE_STRINGS_H@*/ +/*#cmakedefine HAVE_STRING_H @HAVE_STRING_H@*/ +/*#cmakedefine HAVE_SYS_STAT_H @HAVE_SYS_STAT_H@*/ +/*#cmakedefine HAVE_SYS_TYPES_H @HAVE_SYS_TYPES_H@ */ +/*#cmakedefine HAVE_UNISTD_H @HAVE_UNISTD_H@*/ + +#cmakedefine _LARGEFILE_SOURCE +#cmakedefine _LARGE_FILES +#cmakedefine _FILE_OFFSET_BITS @_FILE_OFFSET_BITS@ +#cmakedefine OPJ_HAVE_FSEEKO @OPJ_HAVE_FSEEKO@ + +/* Byte order. */ +/* All compilers that support Mac OS X define either __BIG_ENDIAN__ or +__LITTLE_ENDIAN__ to match the endianness of the architecture being +compiled for. This is not necessarily the same as the architecture of the +machine doing the building. In order to support Universal Binaries on +Mac OS X, we prefer those defines to decide the endianness. +On other platforms we use the result of the TRY_RUN. */ +#if !defined(__APPLE__) +#cmakedefine OPJ_BIG_ENDIAN +#elif defined(__BIG_ENDIAN__) +# define OPJ_BIG_ENDIAN +#endif \ No newline at end of file diff --git a/src/lib/openjp2/opj_includes.h b/src/lib/openjp2/opj_includes.h index 82cc9c19..9d74e470 100644 --- a/src/lib/openjp2/opj_includes.h +++ b/src/lib/openjp2/opj_includes.h @@ -32,7 +32,7 @@ * This must be included before any system headers, * since they can react to macro defined there */ -#include "opj_config.h" +#include "opj_config_private.h" /* ========================================================== From 7fbf6df09ec66202e75f998cc0ee98b81561c758 Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Mon, 25 Mar 2013 13:36:26 +0000 Subject: [PATCH 055/333] [trunk] use opj_config_private.h into the opj_inttypes.h --- src/lib/openjp2/opj_inttypes.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/openjp2/opj_inttypes.h b/src/lib/openjp2/opj_inttypes.h index f94f648b..61215137 100644 --- a/src/lib/openjp2/opj_inttypes.h +++ b/src/lib/openjp2/opj_inttypes.h @@ -26,7 +26,7 @@ #ifndef OPJ_INTTYPES_H #define OPJ_INTTYPES_H -#include "opj_config.h" +#include "opj_config_private.h" #ifdef OPJ_HAVE_INTTYPES_H #include #else From da4bd9b110674dc77140190f32faf4685b609b32 Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Mon, 25 Mar 2013 13:43:14 +0000 Subject: [PATCH 056/333] [trunk] use the private version of opj_config to avoid compilation error into mj2 --- src/lib/openmj2/openjpeg.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/openmj2/openjpeg.c b/src/lib/openmj2/openjpeg.c index b9fb0743..ab53472e 100644 --- a/src/lib/openmj2/openjpeg.c +++ b/src/lib/openmj2/openjpeg.c @@ -28,7 +28,7 @@ #include #endif /* _WIN32 */ -#include "opj_config.h" +#include "opj_config_private.h" #include "opj_includes.h" /* ---------------------------------------------------------------------- */ From 34fd4935128751aa84e8cfc0db5a9aec680ba5e7 Mon Sep 17 00:00:00 2001 From: Antonin Descampe Date: Thu, 11 Jul 2013 16:48:49 +0000 Subject: [PATCH 057/333] test: modified class-0 conformance testing to comply with constraints --- tests/conformance/CMakeLists.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/conformance/CMakeLists.txt b/tests/conformance/CMakeLists.txt index 9af8d059..77b14c3b 100644 --- a/tests/conformance/CMakeLists.txt +++ b/tests/conformance/CMakeLists.txt @@ -40,7 +40,9 @@ foreach(numFileC0P0 RANGE 1 16) # Get corresponding tests parameters list(GET C0P0_ResFactor_list ${numFileC0P0} ResFactor) - list(GET CP0_nbC_list ${numFileC0P0} nbComponents) + #For Class-0 testing, we always focus on the first component only + #list(GET CP0_nbC_list ${numFileC0P0} nbComponents) + set( nbComponents "1") list(GET C0P0_PEAK_list ${numFileC0P0} PEAK_limit) list(GET C0P0_MSE_list ${numFileC0P0} MSE_limit) @@ -177,7 +179,9 @@ foreach(numFileC0P1 RANGE 1 7) # Get corresponding tests parameters list(GET C0P1_ResFactor_list ${numFileC0P1} ResFactor) - list(GET CP1_nbC_list ${numFileC0P1} nbComponents) + #For Class-0 testing, we always focus on the first component only + #list(GET CP0_nbC_list ${numFileC0P0} nbComponents) + set( nbComponents "1") list(GET C0P1_PEAK_list ${numFileC0P1} PEAK_limit) list(GET C0P1_MSE_list ${numFileC0P1} MSE_limit) From 5855da5a156443f470a0c446e1740ab8aaf09230 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 26 Sep 2013 09:28:47 +0000 Subject: [PATCH 058/333] [trunk] Import patch from bug #241 --- src/lib/openjp2/image.c | 2 +- src/lib/openjp2/openjpeg.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/lib/openjp2/image.c b/src/lib/openjp2/image.c index 7e48de1a..1b14f685 100644 --- a/src/lib/openjp2/image.c +++ b/src/lib/openjp2/image.c @@ -40,7 +40,7 @@ opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_cmptpa image->color_space = clrspc; image->numcomps = numcmpts; /* allocate memory for the per-component information */ - image->comps = (opj_image_comp_t*)opj_malloc(image->numcomps * sizeof(opj_image_comp_t)); + image->comps = (opj_image_comp_t*)opj_calloc(1,image->numcomps * sizeof(opj_image_comp_t)); if(!image->comps) { fprintf(stderr,"Unable to allocate memory for image.\n"); opj_image_destroy(image); diff --git a/src/lib/openjp2/openjpeg.c b/src/lib/openjp2/openjpeg.c index e7ca5f80..78b5a564 100644 --- a/src/lib/openjp2/openjpeg.c +++ b/src/lib/openjp2/openjpeg.c @@ -850,10 +850,9 @@ OPJ_BOOL OPJ_CALLCONV opj_encode(opj_codec_t *p_info, opj_stream_t *p_stream) opj_stream_private_t * l_stream = (opj_stream_private_t *) p_stream; if (! l_codec->is_decompressor) { - l_codec->m_codec_data.m_compression.opj_encode( l_codec->m_codec, + return l_codec->m_codec_data.m_compression.opj_encode( l_codec->m_codec, l_stream, &(l_codec->m_event_mgr)); - return OPJ_TRUE; } } From 4d7b6374c8723fcf8aa219473e21a5c891fda298 Mon Sep 17 00:00:00 2001 From: Rex Dieter Date: Tue, 15 Oct 2013 19:17:51 +0000 Subject: [PATCH 059/333] complete openjpeg2 pkgconfig support, bug #68 --- CMakeLists.txt | 27 +++++++++++++++++++++++- src/lib/openjp3d/libopenjp3d.pc.cmake.in | 14 ++++++++++++ src/lib/openjpip/libopenjpip.pc.cmake.in | 15 +++++++++++++ src/lib/openjpwl/libopenjpwl.pc.cmake.in | 15 +++++++++++++ 4 files changed, 70 insertions(+), 1 deletion(-) create mode 100644 src/lib/openjp3d/libopenjp3d.pc.cmake.in create mode 100644 src/lib/openjpip/libopenjpip.pc.cmake.in create mode 100644 src/lib/openjpwl/libopenjpwl.pc.cmake.in diff --git a/CMakeLists.txt b/CMakeLists.txt index c55f46f8..3b86f061 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -314,5 +314,30 @@ if(UNIX) ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc @ONLY) install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjp2.pc DESTINATION ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig ) +# + if(BUILD_JPWL) + # install in lib and not share (see multi-arch note above) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjpwl/libopenjpwl.pc.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/libopenjpwl.pc @ONLY) + install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjpwl.pc DESTINATION + ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig ) + endif() +# + if(BUILD_JPIP) + # install in lib and not share (see multi-arch note above) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjpip/libopenjpip.pc.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc @ONLY) + install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjpip.pc DESTINATION + ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig ) + endif() +# + if(BUILD_JP3D) + # install in lib and not share (see multi-arch note above) + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/lib/openjp3d/libopenjp3d.pc.cmake.in + ${CMAKE_CURRENT_BINARY_DIR}/libopenjp3d.pc @ONLY) + install( FILES ${CMAKE_CURRENT_BINARY_DIR}/libopenjp3d.pc DESTINATION + ${OPENJPEG_INSTALL_LIB_DIR}/pkgconfig ) + endif() endif() -#----------------------------------------------------------------------------- \ No newline at end of file + +#----------------------------------------------------------------------------- diff --git a/src/lib/openjp3d/libopenjp3d.pc.cmake.in b/src/lib/openjp3d/libopenjp3d.pc.cmake.in new file mode 100644 index 00000000..e9b6c404 --- /dev/null +++ b/src/lib/openjp3d/libopenjp3d.pc.cmake.in @@ -0,0 +1,14 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +bindir=${prefix}/@OPENJPEG_INSTALL_BIN_DIR@ +mandir=${prefix}/@OPENJPEG_INSTALL_MAN_DIR@ +docdir=${prefix}/@OPENJPEG_INSTALL_DOC_DIR@ +libdir=${prefix}/@OPENJPEG_INSTALL_LIB_DIR@ +includedir=${prefix}/@OPENJPEG_INSTALL_INCLUDE_DIR@ + +Name: openjp3d +Description: JPEG2000 Extensions for three-dimensional data (Part 10) +URL: http://www.openjpeg.org/ +Version: @OPENJPEG_VERSION@ +Libs: -L${libdir} -lopenjp3d +Libs.private: -lm +Cflags: -I${includedir} diff --git a/src/lib/openjpip/libopenjpip.pc.cmake.in b/src/lib/openjpip/libopenjpip.pc.cmake.in new file mode 100644 index 00000000..da950a8f --- /dev/null +++ b/src/lib/openjpip/libopenjpip.pc.cmake.in @@ -0,0 +1,15 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +bindir=${prefix}/@OPENJPEG_INSTALL_BIN_DIR@ +mandir=${prefix}/@OPENJPEG_INSTALL_MAN_DIR@ +docdir=${prefix}/@OPENJPEG_INSTALL_DOC_DIR@ +libdir=${prefix}/@OPENJPEG_INSTALL_LIB_DIR@ +includedir=${prefix}/@OPENJPEG_INSTALL_INCLUDE_DIR@ + +Name: openjpip +Description: JPEG2000 Interactivity tools, APIs and protocols (Part 9) +URL: http://www.openjpeg.org/ +Version: @OPENJPEG_VERSION@ +Requires: openjp2 +Libs: -L${libdir} -lopenjpip +Libs.private: -lm -lcurl -lfcgi -lpthread +Cflags: -I${includedir} diff --git a/src/lib/openjpwl/libopenjpwl.pc.cmake.in b/src/lib/openjpwl/libopenjpwl.pc.cmake.in new file mode 100644 index 00000000..a6e6ab26 --- /dev/null +++ b/src/lib/openjpwl/libopenjpwl.pc.cmake.in @@ -0,0 +1,15 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +bindir=${prefix}/@OPENJPEG_INSTALL_BIN_DIR@ +mandir=${prefix}/@OPENJPEG_INSTALL_MAN_DIR@ +docdir=${prefix}/@OPENJPEG_INSTALL_DOC_DIR@ +libdir=${prefix}/@OPENJPEG_INSTALL_LIB_DIR@ +includedir=${prefix}/@OPENJPEG_INSTALL_INCLUDE_DIR@ + +Name: openjpwl +Description: JPEG2000 Wireless library (Part 11) +URL: http://www.openjpeg.org/ +Version: @OPENJPEG_VERSION@ +Requires: openjp2 +Libs: -L${libdir} -lopenjpwl +Libs.private: -lm +Cflags: -I${includedir} From 7294cdef3e5a050846745fb61e98e3af948ff1e6 Mon Sep 17 00:00:00 2001 From: Antonin Descampe Date: Mon, 28 Oct 2013 23:31:55 +0000 Subject: [PATCH 060/333] trunk: disabling class-0 conformance tests for now (bad implentation of tests) --- tests/conformance/CMakeLists.txt | 470 +++++++++++++++---------------- 1 file changed, 235 insertions(+), 235 deletions(-) diff --git a/tests/conformance/CMakeLists.txt b/tests/conformance/CMakeLists.txt index 77b14c3b..14c5471a 100644 --- a/tests/conformance/CMakeLists.txt +++ b/tests/conformance/CMakeLists.txt @@ -16,288 +16,288 @@ set( CP1_nbC_list "not_used;1;3;4;1;3;3;2") set(COMMENTCODEVAR FALSE) -#-------------------------------------------------------------------------- -# Tests about class 0 profile 0 -# try to decode -# compare to ref file provided by the Executable Test Suite -# non regression comparison +##-------------------------------------------------------------------------- +## Tests about class 0 profile 0 +## try to decode +## compare to ref file provided by the Executable Test Suite +## non regression comparison -# Parameters and tolerances given by Table C.1 -set( C0P0_ResFactor_list "not_used;0;0;0;3;3;3;0;5;2;0;0;0;0;2;0;0") -set( C0P0_PEAK_list "not_used;0;0;0;33;54;109;10;7;4;10;0;0;0;0;0;0") -set( C0P0_MSE_list "not_used;0;0;0;55.8;68;743;0.34;6.72;1.47;2.84;0;0;0;0;0;0") +## Parameters and tolerances given by Table C.1 +#set( C0P0_ResFactor_list "not_used;0;0;0;3;3;3;0;5;2;0;0;0;0;2;0;0") +#set( C0P0_PEAK_list "not_used;0;0;0;33;54;109;10;7;4;10;0;0;0;0;0;0") +#set( C0P0_MSE_list "not_used;0;0;0;55.8;68;743;0.34;6.72;1.47;2.84;0;0;0;0;0;0") -foreach(numFileC0P0 RANGE 1 16) +#foreach(numFileC0P0 RANGE 1 16) - # Build filenames - if(${numFileC0P0} LESS 10) - set( filenameInput p0_0${numFileC0P0}.j2k ) - set( filenameRef c0p0_0${numFileC0P0}.pgx ) - else() - set( filenameInput p0_${numFileC0P0}.j2k ) - set( filenameRef c0p0_${numFileC0P0}.pgx ) - endif() +# # Build filenames +# if(${numFileC0P0} LESS 10) +# set( filenameInput p0_0${numFileC0P0}.j2k ) +# set( filenameRef c0p0_0${numFileC0P0}.pgx ) +# else() +# set( filenameInput p0_${numFileC0P0}.j2k ) +# set( filenameRef c0p0_${numFileC0P0}.pgx ) +# endif() - # Get corresponding tests parameters - list(GET C0P0_ResFactor_list ${numFileC0P0} ResFactor) - #For Class-0 testing, we always focus on the first component only - #list(GET CP0_nbC_list ${numFileC0P0} nbComponents) - set( nbComponents "1") - list(GET C0P0_PEAK_list ${numFileC0P0} PEAK_limit) - list(GET C0P0_MSE_list ${numFileC0P0} MSE_limit) +# # Get corresponding tests parameters +# list(GET C0P0_ResFactor_list ${numFileC0P0} ResFactor) +# #For Class-0 testing, we always focus on the first component only +# #list(GET CP0_nbC_list ${numFileC0P0} nbComponents) +# set( nbComponents "1") +# list(GET C0P0_PEAK_list ${numFileC0P0} PEAK_limit) +# list(GET C0P0_MSE_list ${numFileC0P0} MSE_limit) - # Manage cases which need to try different resolution reduction - if (numFileC0P0 EQUAL 3 OR numFileC0P0 EQUAL 15) - get_filename_component(filenameRefSub ${filenameRef} NAME_WE) - #r = 0 +# # Manage cases which need to try different resolution reduction +# if (numFileC0P0 EQUAL 3 OR numFileC0P0 EQUAL 15) +# get_filename_component(filenameRefSub ${filenameRef} NAME_WE) +# #r = 0 - add_test(ETS-C0P0-${filenameInput}-r0-decode - ${EXECUTABLE_OUTPUT_PATH}/opj_decompress - -i ${INPUT_CONF}/${filenameInput} - -o ${TEMP}/c0${filenameInput}-r0.pgx - -r 0 - ) +# add_test(ETS-C0P0-${filenameInput}-r0-decode +# ${EXECUTABLE_OUTPUT_PATH}/opj_decompress +# -i ${INPUT_CONF}/${filenameInput} +# -o ${TEMP}/c0${filenameInput}-r0.pgx +# -r 0 +# ) - add_test(ETS-C0P0-${filenameInput}-r0-compare2ref - ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages - -b ${BASELINE_CONF}/${filenameRefSub}r0.pgx - -t ${TEMP}/c0${filenameInput}-r0.pgx - -n ${nbComponents} - -p ${PEAK_limit} - -m ${MSE_limit} - -s t_ - ) +# add_test(ETS-C0P0-${filenameInput}-r0-compare2ref +# ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages +# -b ${BASELINE_CONF}/${filenameRefSub}r0.pgx +# -t ${TEMP}/c0${filenameInput}-r0.pgx +# -n ${nbComponents} +# -p ${PEAK_limit} +# -m ${MSE_limit} +# -s t_ +# ) - set_tests_properties(ETS-C0P0-${filenameInput}-r0-compare2ref - PROPERTIES DEPENDS - ETS-C0P0-${filenameInput}-r0-decode) +# set_tests_properties(ETS-C0P0-${filenameInput}-r0-compare2ref +# PROPERTIES DEPENDS +# ETS-C0P0-${filenameInput}-r0-decode) - add_test(NR-C0P0-${filenameInput}-r0-compare2base - ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages - -b ${BASELINE_NR}/opj_${filenameRefSub}-r0.pgx - -t ${TEMP}/c0${filenameInput}-r0.pgx - -n ${nbComponents} - -d - -s b_t_ - ) +# add_test(NR-C0P0-${filenameInput}-r0-compare2base +# ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages +# -b ${BASELINE_NR}/opj_${filenameRefSub}-r0.pgx +# -t ${TEMP}/c0${filenameInput}-r0.pgx +# -n ${nbComponents} +# -d +# -s b_t_ +# ) - set_tests_properties(NR-C0P0-${filenameInput}-r0-compare2base - PROPERTIES DEPENDS - ETS-C0P0-${filenameInput}-r0-decode) +# set_tests_properties(NR-C0P0-${filenameInput}-r0-compare2base +# PROPERTIES DEPENDS +# ETS-C0P0-${filenameInput}-r0-decode) - #r = 1 - add_test(ETS-C0P0-${filenameInput}-r1-decode - ${EXECUTABLE_OUTPUT_PATH}/opj_decompress - -i ${INPUT_CONF}/${filenameInput} - -o ${TEMP}/c0${filenameInput}-r1.pgx - -r 1 - ) +# #r = 1 +# add_test(ETS-C0P0-${filenameInput}-r1-decode +# ${EXECUTABLE_OUTPUT_PATH}/opj_decompress +# -i ${INPUT_CONF}/${filenameInput} +# -o ${TEMP}/c0${filenameInput}-r1.pgx +# -r 1 +# ) - add_test(ETS-C0P0-${filenameInput}-r1-compare2ref - ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages - -b ${BASELINE_CONF}/${filenameRefSub}r1.pgx - -t ${TEMP}/c0${filenameInput}-r1.pgx - -n ${nbComponents} - -p ${PEAK_limit} - -m ${MSE_limit} - -s t_ - ) +# add_test(ETS-C0P0-${filenameInput}-r1-compare2ref +# ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages +# -b ${BASELINE_CONF}/${filenameRefSub}r1.pgx +# -t ${TEMP}/c0${filenameInput}-r1.pgx +# -n ${nbComponents} +# -p ${PEAK_limit} +# -m ${MSE_limit} +# -s t_ +# ) - set_tests_properties(ETS-C0P0-${filenameInput}-r1-compare2ref - PROPERTIES DEPENDS - ETS-C0P0-${filenameInput}-r1-decode) +# set_tests_properties(ETS-C0P0-${filenameInput}-r1-compare2ref +# PROPERTIES DEPENDS +# ETS-C0P0-${filenameInput}-r1-decode) - add_test(NR-C0P0-${filenameInput}-r1-compare2base - ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages - -b ${BASELINE_NR}/opj_${filenameRefSub}-r1.pgx - -t ${TEMP}/c0${filenameInput}-r1.pgx - -n ${nbComponents} - -d - -s b_t_ - ) +# add_test(NR-C0P0-${filenameInput}-r1-compare2base +# ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages +# -b ${BASELINE_NR}/opj_${filenameRefSub}-r1.pgx +# -t ${TEMP}/c0${filenameInput}-r1.pgx +# -n ${nbComponents} +# -d +# -s b_t_ +# ) - set_tests_properties(NR-C0P0-${filenameInput}-r1-compare2base - PROPERTIES DEPENDS - ETS-C0P0-${filenameInput}-r1-decode) +# set_tests_properties(NR-C0P0-${filenameInput}-r1-compare2base +# PROPERTIES DEPENDS +# ETS-C0P0-${filenameInput}-r1-decode) - else() +# else() - add_test(ETS-C0P0-${filenameInput}-decode - ${EXECUTABLE_OUTPUT_PATH}/opj_decompress - -i ${INPUT_CONF}/${filenameInput} - -o ${TEMP}/c0${filenameInput}.pgx - -r ${ResFactor} - ) +# add_test(ETS-C0P0-${filenameInput}-decode +# ${EXECUTABLE_OUTPUT_PATH}/opj_decompress +# -i ${INPUT_CONF}/${filenameInput} +# -o ${TEMP}/c0${filenameInput}.pgx +# -r ${ResFactor} +# ) - add_test(ETS-C0P0-${filenameInput}-compare2ref - ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages - -b ${BASELINE_CONF}/${filenameRef} - -t ${TEMP}/c0${filenameInput}.pgx - -n ${nbComponents} - -p ${PEAK_limit} - -m ${MSE_limit} - -s t_ - ) +# add_test(ETS-C0P0-${filenameInput}-compare2ref +# ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages +# -b ${BASELINE_CONF}/${filenameRef} +# -t ${TEMP}/c0${filenameInput}.pgx +# -n ${nbComponents} +# -p ${PEAK_limit} +# -m ${MSE_limit} +# -s t_ +# ) - set_tests_properties(ETS-C0P0-${filenameInput}-compare2ref - PROPERTIES DEPENDS - ETS-C0P0-${filenameInput}-decode) +# set_tests_properties(ETS-C0P0-${filenameInput}-compare2ref +# PROPERTIES DEPENDS +# ETS-C0P0-${filenameInput}-decode) - add_test(NR-C0P0-${filenameInput}-compare2base - ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages - -b ${BASELINE_NR}/opj_${filenameRef} - -t ${TEMP}/c0${filenameInput}.pgx - -n ${nbComponents} - -d - -s b_t_ - ) +# add_test(NR-C0P0-${filenameInput}-compare2base +# ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages +# -b ${BASELINE_NR}/opj_${filenameRef} +# -t ${TEMP}/c0${filenameInput}.pgx +# -n ${nbComponents} +# -d +# -s b_t_ +# ) - set_tests_properties(NR-C0P0-${filenameInput}-compare2base - PROPERTIES DEPENDS - ETS-C0P0-${filenameInput}-decode) +# set_tests_properties(NR-C0P0-${filenameInput}-compare2base +# PROPERTIES DEPENDS +# ETS-C0P0-${filenameInput}-decode) - endif() +# endif() -endforeach() +#endforeach() -#-------------------------------------------------------------------------- -# Tests about class 0 profile 1 -# try to decode -# compare to ref file -# non regression comparison +##-------------------------------------------------------------------------- +## Tests about class 0 profile 1 +## try to decode +## compare to ref file +## non regression comparison -# Parameters and tolerances given by Table C.4 -set( C0P1_ResFactor_list "not_used;0;3;3;0;4;1;0") -set( C0P1_PEAK_list "not_used;0;35;28;2;128;128;0") -set( C0P1_MSE_list "not_used;0;74;18.8;0.550;16384;16384;0") +## Parameters and tolerances given by Table C.4 +#set( C0P1_ResFactor_list "not_used;0;3;3;0;4;1;0") +#set( C0P1_PEAK_list "not_used;0;35;28;2;128;128;0") +#set( C0P1_MSE_list "not_used;0;74;18.8;0.550;16384;16384;0") -foreach(numFileC0P1 RANGE 1 7) +#foreach(numFileC0P1 RANGE 1 7) - # Build filenames - set( filenameInput p1_0${numFileC0P1}.j2k ) - set( filenameRef c0p1_0${numFileC0P1}.pgx ) +# # Build filenames +# set( filenameInput p1_0${numFileC0P1}.j2k ) +# set( filenameRef c0p1_0${numFileC0P1}.pgx ) - # Get corresponding tests parameters - list(GET C0P1_ResFactor_list ${numFileC0P1} ResFactor) - #For Class-0 testing, we always focus on the first component only - #list(GET CP0_nbC_list ${numFileC0P0} nbComponents) - set( nbComponents "1") - list(GET C0P1_PEAK_list ${numFileC0P1} PEAK_limit) - list(GET C0P1_MSE_list ${numFileC0P1} MSE_limit) +# # Get corresponding tests parameters +# list(GET C0P1_ResFactor_list ${numFileC0P1} ResFactor) +# #For Class-0 testing, we always focus on the first component only +# #list(GET CP0_nbC_list ${numFileC0P0} nbComponents) +# set( nbComponents "1") +# list(GET C0P1_PEAK_list ${numFileC0P1} PEAK_limit) +# list(GET C0P1_MSE_list ${numFileC0P1} MSE_limit) - # Manage cases which need to try different resolution reduction - if (numFileC0P1 EQUAL 4 ) - get_filename_component(filenameRefSub ${filenameRef} NAME_WE) +# # Manage cases which need to try different resolution reduction +# if (numFileC0P1 EQUAL 4 ) +# get_filename_component(filenameRefSub ${filenameRef} NAME_WE) - #r = 0 - add_test(ETS-C0P1-${filenameInput}-r0-decode - ${EXECUTABLE_OUTPUT_PATH}/opj_decompress - -i ${INPUT_CONF}/${filenameInput} - -o ${TEMP}/c0${filenameInput}-r0.pgx - -r 0 - ) +# #r = 0 +# add_test(ETS-C0P1-${filenameInput}-r0-decode +# ${EXECUTABLE_OUTPUT_PATH}/opj_decompress +# -i ${INPUT_CONF}/${filenameInput} +# -o ${TEMP}/c0${filenameInput}-r0.pgx +# -r 0 +# ) - add_test(ETS-C0P1-${filenameInput}-r0-compare2ref - ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages - -b ${BASELINE_CONF}/${filenameRefSub}r0.pgx - -t ${TEMP}/c0${filenameInput}-r0.pgx - -n ${nbComponents} - -p ${PEAK_limit} - -m ${MSE_limit} - -s t_ - ) +# add_test(ETS-C0P1-${filenameInput}-r0-compare2ref +# ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages +# -b ${BASELINE_CONF}/${filenameRefSub}r0.pgx +# -t ${TEMP}/c0${filenameInput}-r0.pgx +# -n ${nbComponents} +# -p ${PEAK_limit} +# -m ${MSE_limit} +# -s t_ +# ) - set_tests_properties(ETS-C0P1-${filenameInput}-r0-compare2ref - PROPERTIES DEPENDS - ETS-C0P1-${filenameInput}-r0-decode) +# set_tests_properties(ETS-C0P1-${filenameInput}-r0-compare2ref +# PROPERTIES DEPENDS +# ETS-C0P1-${filenameInput}-r0-decode) - add_test(NR-C0P1-${filenameInput}-r0-compare2base - ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages - -b ${BASELINE_NR}/opj_${filenameRefSub}-r0.pgx - -t ${TEMP}/c0${filenameInput}-r0.pgx - -n ${nbComponents} - -d - -s b_t_ - ) +# add_test(NR-C0P1-${filenameInput}-r0-compare2base +# ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages +# -b ${BASELINE_NR}/opj_${filenameRefSub}-r0.pgx +# -t ${TEMP}/c0${filenameInput}-r0.pgx +# -n ${nbComponents} +# -d +# -s b_t_ +# ) - set_tests_properties(NR-C0P1-${filenameInput}-r0-compare2base - PROPERTIES DEPENDS - ETS-C0P1-${filenameInput}-r0-decode) +# set_tests_properties(NR-C0P1-${filenameInput}-r0-compare2base +# PROPERTIES DEPENDS +# ETS-C0P1-${filenameInput}-r0-decode) - #r = 3 - add_test(ETS-C0P1-${filenameInput}-r3-decode - ${EXECUTABLE_OUTPUT_PATH}/opj_decompress - -i ${INPUT_CONF}/${filenameInput} - -o ${TEMP}/c0${filenameInput}-r3.pgx - -r 3 - ) +# #r = 3 +# add_test(ETS-C0P1-${filenameInput}-r3-decode +# ${EXECUTABLE_OUTPUT_PATH}/opj_decompress +# -i ${INPUT_CONF}/${filenameInput} +# -o ${TEMP}/c0${filenameInput}-r3.pgx +# -r 3 +# ) - add_test(ETS-C0P1-${filenameInput}-r3-compare2ref - ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages - -b ${BASELINE_CONF}/${filenameRefSub}r3.pgx - -t ${TEMP}/c0${filenameInput}-r3.pgx - -n ${nbComponents} - -p ${PEAK_limit} - -m ${MSE_limit} - -s t_ - ) +# add_test(ETS-C0P1-${filenameInput}-r3-compare2ref +# ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages +# -b ${BASELINE_CONF}/${filenameRefSub}r3.pgx +# -t ${TEMP}/c0${filenameInput}-r3.pgx +# -n ${nbComponents} +# -p ${PEAK_limit} +# -m ${MSE_limit} +# -s t_ +# ) - set_tests_properties(ETS-C0P1-${filenameInput}-r3-compare2ref - PROPERTIES DEPENDS - ETS-C0P1-${filenameInput}-r3-decode) +# set_tests_properties(ETS-C0P1-${filenameInput}-r3-compare2ref +# PROPERTIES DEPENDS +# ETS-C0P1-${filenameInput}-r3-decode) - add_test(NR-C0P1-${filenameInput}-r3-compare2base - ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages - -b ${BASELINE_NR}/opj_${filenameRefSub}-r3.pgx - -t ${TEMP}/c0${filenameInput}-r3.pgx - -n ${nbComponents} - -d - -s b_t_ - ) +# add_test(NR-C0P1-${filenameInput}-r3-compare2base +# ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages +# -b ${BASELINE_NR}/opj_${filenameRefSub}-r3.pgx +# -t ${TEMP}/c0${filenameInput}-r3.pgx +# -n ${nbComponents} +# -d +# -s b_t_ +# ) - set_tests_properties(NR-C0P1-${filenameInput}-r3-compare2base - PROPERTIES DEPENDS - ETS-C0P1-${filenameInput}-r3-decode) +# set_tests_properties(NR-C0P1-${filenameInput}-r3-compare2base +# PROPERTIES DEPENDS +# ETS-C0P1-${filenameInput}-r3-decode) - else() +# else() - add_test(ETS-C0P1-${filenameInput}-decode - ${EXECUTABLE_OUTPUT_PATH}/opj_decompress - -i ${INPUT_CONF}/${filenameInput} - -o ${TEMP}/c0${filenameInput}.pgx - -r ${ResFactor} - ) +# add_test(ETS-C0P1-${filenameInput}-decode +# ${EXECUTABLE_OUTPUT_PATH}/opj_decompress +# -i ${INPUT_CONF}/${filenameInput} +# -o ${TEMP}/c0${filenameInput}.pgx +# -r ${ResFactor} +# ) - add_test(ETS-C0P1-${filenameInput}-compare2ref - ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages - -b ${BASELINE_CONF}/${filenameRef} - -t ${TEMP}/c0${filenameInput}.pgx - -n ${nbComponents} - -p ${PEAK_limit} - -m ${MSE_limit} - -s t_ - ) +# add_test(ETS-C0P1-${filenameInput}-compare2ref +# ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages +# -b ${BASELINE_CONF}/${filenameRef} +# -t ${TEMP}/c0${filenameInput}.pgx +# -n ${nbComponents} +# -p ${PEAK_limit} +# -m ${MSE_limit} +# -s t_ +# ) - set_tests_properties(ETS-C0P1-${filenameInput}-compare2ref - PROPERTIES DEPENDS - ETS-C0P1-${filenameInput}-decode) +# set_tests_properties(ETS-C0P1-${filenameInput}-compare2ref +# PROPERTIES DEPENDS +# ETS-C0P1-${filenameInput}-decode) - add_test(NR-C0P1-${filenameInput}-compare2base - ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages - -b ${BASELINE_NR}/opj_${filenameRef} - -t ${TEMP}/c0${filenameInput}.pgx - -n ${nbComponents} - -d - -s b_t_ - ) +# add_test(NR-C0P1-${filenameInput}-compare2base +# ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages +# -b ${BASELINE_NR}/opj_${filenameRef} +# -t ${TEMP}/c0${filenameInput}.pgx +# -n ${nbComponents} +# -d +# -s b_t_ +# ) - set_tests_properties(NR-C0P1-${filenameInput}-compare2base - PROPERTIES DEPENDS - ETS-C0P1-${filenameInput}-decode) +# set_tests_properties(NR-C0P1-${filenameInput}-compare2base +# PROPERTIES DEPENDS +# ETS-C0P1-${filenameInput}-decode) - endif() +# endif() -endforeach() +#endforeach() #-------------------------------------------------------------------------- # Tests about class 1 profile 0 From bd8c91b37dc1b9345130d63582a063b59628b227 Mon Sep 17 00:00:00 2001 From: Antonin Descampe Date: Wed, 30 Oct 2013 08:57:18 +0000 Subject: [PATCH 061/333] trunk: fixed cmake config so as to be able to link opj_jpip_server with FCGI. --- src/bin/jpip/opj_server.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bin/jpip/opj_server.c b/src/bin/jpip/opj_server.c index 3534ad42..9ef9a5f2 100644 --- a/src/bin/jpip/opj_server.c +++ b/src/bin/jpip/opj_server.c @@ -48,6 +48,7 @@ #include #include #include +#include "fcgi_stdio.h" #include "openjpip.h" #ifndef QUIT_SIGNAL From 05f796d2fabd08dd1ab575dca6f59ca6bf18b70c Mon Sep 17 00:00:00 2001 From: Antonin Descampe Date: Wed, 30 Oct 2013 08:59:23 +0000 Subject: [PATCH 062/333] trunk: fixed cmake config so as to be able to link opj_jpip_server with FCGI. --- CMakeLists.txt | 10 +++++++++- src/CMakeLists.txt | 18 +++++++++--------- src/bin/jpip/CMakeLists.txt | 2 +- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3b86f061..72f985f6 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -213,7 +213,15 @@ OPJ_TEST_LARGE_FILES(OPJ_HAVE_LARGEFILES) #----------------------------------------------------------------------------- # Build Library -add_subdirectory(src) +if(BUILD_JPIP_SERVER) + find_package(CURL REQUIRED) + find_package(FCGI REQUIRED) + find_package(Threads REQUIRED) + if(NOT CMAKE_USE_PTHREADS_INIT) + message(FATAL_ERROR "Only pthread are supported") + endif() +endif() +add_subdirectory(src/lib) #----------------------------------------------------------------------------- # Build Applications diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 673843ec..87526cfc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,12 +1,12 @@ # required dep for server: -if(BUILD_JPIP_SERVER) - find_package(CURL REQUIRED) - find_package(FCGI REQUIRED) - find_package(Threads REQUIRED) - if(NOT CMAKE_USE_PTHREADS_INIT) - message(FATAL_ERROR "Only pthread are supported") - endif() -endif() +#if(BUILD_JPIP_SERVER) +# find_package(CURL REQUIRED) +# find_package(FCGI REQUIRED) +# find_package(Threads REQUIRED) +# if(NOT CMAKE_USE_PTHREADS_INIT) +# message(FATAL_ERROR "Only pthread are supported") +# endif() +#endif() -add_subdirectory(lib) +#add_subdirectory(lib) #add_subdirectory(bin) diff --git a/src/bin/jpip/CMakeLists.txt b/src/bin/jpip/CMakeLists.txt index 45f0007b..9404c111 100644 --- a/src/bin/jpip/CMakeLists.txt +++ b/src/bin/jpip/CMakeLists.txt @@ -23,7 +23,7 @@ if(BUILD_JPIP_SERVER) # Build executable add_executable(opj_server ${OPJ_SERVER_SRCS}) - target_link_libraries(opj_server openjpip_server) + target_link_libraries(opj_server ${FCGI_LIBRARIES} openjpip_server) set_property( TARGET opj_server APPEND PROPERTY From 7b14cf8558085773f106fe2a996d8e4768394459 Mon Sep 17 00:00:00 2001 From: Antonin Descampe Date: Thu, 16 Jan 2014 12:55:14 +0000 Subject: [PATCH 063/333] [trunk] fixed DCI-compliant codestream generation (-cinema2K and - --- src/lib/openjp2/j2k.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 4657ba99..6f62ee2e 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -2692,7 +2692,8 @@ OPJ_BOOL opj_j2k_write_qcc( opj_j2k_t *p_j2k, assert(p_manager != 00); assert(p_stream != 00); - l_qcc_size = 6 + opj_j2k_get_SQcd_SQcc_size(p_j2k,p_j2k->m_current_tile_number,p_comp_no); + l_qcc_size = 5 + opj_j2k_get_SQcd_SQcc_size(p_j2k,p_j2k->m_current_tile_number,p_comp_no); + l_qcc_size += p_j2k->m_private_image->numcomps <= 256 ? 0:1; l_remaining_size = l_qcc_size; if (l_qcc_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) { @@ -9540,6 +9541,8 @@ OPJ_BOOL opj_j2k_write_all_tile_parts( opj_j2k_t *p_j2k, /*Get number of tile parts*/ tot_num_tp = opj_j2k_get_num_tp(l_cp,0,p_j2k->m_current_tile_number); + /* start writing remaining tile parts */ + ++p_j2k->m_specific_param.m_encoder.m_current_tile_part_number; for (tilepartno = 1; tilepartno < tot_num_tp ; ++tilepartno) { p_j2k->m_specific_param.m_encoder.m_current_poc_tile_part_number = tilepartno; l_current_nb_bytes_written = 0; @@ -9553,7 +9556,7 @@ OPJ_BOOL opj_j2k_write_all_tile_parts( opj_j2k_t *p_j2k, l_nb_bytes_written += l_current_nb_bytes_written; p_data += l_current_nb_bytes_written; p_total_data_size -= l_current_nb_bytes_written; - l_part_tile_size += l_nb_bytes_written; + l_part_tile_size += l_current_nb_bytes_written; l_current_nb_bytes_written = 0; if (! opj_j2k_write_sod(p_j2k,l_tcd,p_data,&l_current_nb_bytes_written,p_total_data_size,p_stream,p_manager)) { @@ -9563,7 +9566,7 @@ OPJ_BOOL opj_j2k_write_all_tile_parts( opj_j2k_t *p_j2k, p_data += l_current_nb_bytes_written; l_nb_bytes_written += l_current_nb_bytes_written; p_total_data_size -= l_current_nb_bytes_written; - l_part_tile_size += l_nb_bytes_written; + l_part_tile_size += l_current_nb_bytes_written; /* Writing Psot in SOT marker */ opj_write_bytes(l_begin_data + 6,l_part_tile_size,4); /* PSOT */ From c59124dfe2fa5497790189e50411e8a627437866 Mon Sep 17 00:00:00 2001 From: Antonin Descampe Date: Thu, 16 Jan 2014 14:21:14 +0000 Subject: [PATCH 064/333] [trunk] fixed indentation in opj_compress.c, renamed 2 internal functions, added some comments --- src/bin/jp2/opj_compress.c | 3366 ++++++++++++++++++------------------ 1 file changed, 1692 insertions(+), 1674 deletions(-) diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index 9b79e999..e62a0fad 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -7,7 +7,7 @@ * Copyright (c) 2005, Herve Drolon, FreeImage Team * Copyright (c) 2006-2007, Parvatha Elangovan * Copyright (c) 2008, Jerome Fimes, Communications & Systemes - * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France + * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France * Copyright (c) 2012, CS Systemes d'Information, France * All rights reserved. * @@ -67,1473 +67,1491 @@ #define COMP_48_CS 520833 /*Maximum size per color component for 2K @ 48fps*/ typedef struct dircnt{ - /** Buffer for holding images read from Directory*/ - char *filename_buf; - /** Pointer to the buffer*/ - char **filename; + /** Buffer for holding images read from Directory*/ + char *filename_buf; + /** Pointer to the buffer*/ + char **filename; }dircnt_t; typedef struct img_folder{ - /** The directory path of the folder containing input images*/ - char *imgdirpath; - /** Output format*/ - char *out_format; - /** Enable option*/ - char set_imgdir; - /** Enable Cod Format for output*/ - char set_out_format; - /** User specified rate stored in case of cinema option*/ - float *rates; + /** The directory path of the folder containing input images*/ + char *imgdirpath; + /** Output format*/ + char *out_format; + /** Enable option*/ + char set_imgdir; + /** Enable Cod Format for output*/ + char set_out_format; + /** User specified rate stored in case of cinema option*/ + float *rates; }img_fol_t; static void encode_help_display(void) { - fprintf(stdout,"HELP for opj_compress\n----\n\n"); - fprintf(stdout,"- the -h option displays this help information on screen\n\n"); + fprintf(stdout,"HELP for opj_compress\n----\n\n"); + fprintf(stdout,"- the -h option displays this help information on screen\n\n"); -/* UniPG>> */ - fprintf(stdout,"List of parameters for the JPEG 2000 " + /* UniPG>> */ + fprintf(stdout,"List of parameters for the JPEG 2000 " + #ifdef USE_JPWL + "+ JPWL " + #endif /* USE_JPWL */ + "encoder:\n"); + /* <> */ #ifdef USE_JPWL - "+ JPWL " + fprintf(stdout," * No JPWL protection\n"); #endif /* USE_JPWL */ - "encoder:\n"); -/* <> */ + /* < \n"); + fprintf(stdout," Currently accepts PBM, PGM, PPM, PNM, PAM, PGX, PNG, BMP, TIF, RAW, RAWL and TGA formats\n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-i : source file (-i source.pnm also *pbm, *.pgm, *.ppm, *.pam, *.pgx, *png, *.bmp, *.tif, *.raw, *.tga) \n"); + fprintf(stdout," When using this option -o must be used\n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-o : destination file (-o dest.j2k or .jp2) \n"); + fprintf(stdout,"\n"); + fprintf(stdout,"Optional Parameters:\n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-h : display the help information \n "); + fprintf(stdout,"\n"); + fprintf(stdout,"-cinema2K : Digital Cinema 2K profile compliant codestream for 2K resolution.(-CINEMA2K 24 or 48) \n"); + fprintf(stdout," Need to specify the frames per second for a 2K resolution. Only 24 or 48 fps is allowed\n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-cinema4K : Digital Cinema 4K profile compliant codestream for 4K resolution \n"); + fprintf(stdout," Frames per second not required. Default value is 24fps\n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-r : different compression ratios for successive layers (-r 20,10,5)\n "); + fprintf(stdout," - The rate specified for each quality level is the desired \n"); + fprintf(stdout," compression factor.\n"); + fprintf(stdout," Example: -r 20,10,1 means quality 1: compress 20x, \n"); + fprintf(stdout," quality 2: compress 10x and quality 3: compress lossless\n"); + fprintf(stdout,"\n"); + fprintf(stdout," (options -r and -q cannot be used together)\n "); + fprintf(stdout,"\n"); + + fprintf(stdout,"-q : different psnr for successive layers (-q 30,40,50) \n "); + + fprintf(stdout," (options -r and -q cannot be used together)\n "); + + fprintf(stdout,"\n"); + fprintf(stdout,"-n : number of resolutions (-n 3) \n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-b : size of code block (-b 32,32) \n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-c : size of precinct (-c 128,128) \n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-t : size of tile (-t 512,512) \n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-p : progression order (-p LRCP) [LRCP, RLCP, RPCL, PCRL, CPRL] \n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-s : subsampling factor (-s 2,2) [-s X,Y] \n"); + fprintf(stdout," Remark: subsampling bigger than 2 can produce error\n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-POC : Progression order change (-POC T1=0,0,1,5,3,CPRL/T1=5,0,1,6,3,CPRL) \n"); + fprintf(stdout," Example: T1=0,0,1,5,3,CPRL \n"); + fprintf(stdout," : Ttilenumber=Resolution num start,Component num start,Layer num end,Resolution num end,Component num end,Progression order\n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-SOP : write SOP marker before each packet \n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-EPH : write EPH marker after each header packet \n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-M : mode switch (-M 3) [1=BYPASS(LAZY) 2=RESET 4=RESTART(TERMALL)\n"); + fprintf(stdout," 8=VSC 16=ERTERM(SEGTERM) 32=SEGMARK(SEGSYM)] \n"); + fprintf(stdout," Indicate multiple modes by adding their values. \n"); + fprintf(stdout," ex: RESTART(4) + RESET(2) + SEGMARK(32) = -M 38\n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-TP : devide packets of every tile into tile-parts (-TP R) [R, L, C]\n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-x : create an index file *.Idx (-x index_name.Idx) \n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-ROI : c=%%d,U=%%d : quantization indices upshifted \n"); + fprintf(stdout," for component c=%%d [%%d = 0,1,2]\n"); + fprintf(stdout," with a value of U=%%d [0 <= %%d <= 37] (i.e. -ROI c=0,U=25) \n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-d : offset of the origin of the image (-d 150,300) \n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-T : offset of the origin of the tiles (-T 100,75) \n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-I : use the irreversible DWT 9-7 (-I) \n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-F : characteristics of the raw input image\n"); + fprintf(stdout," -F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n"); + fprintf(stdout," Example: -i lena.raw -o lena.j2k -F 512,512,3,8,u\n"); + fprintf(stdout,"\n"); + fprintf(stdout,"-m : use array-based MCT, values are coma separated, line by line\n"); + fprintf(stdout," no specific separators between lines, no space allowed between values\n"); + fprintf(stdout,"-jpip : write jpip codestream index box in JP2 output file\n"); + fprintf(stdout," NOTICE: currently supports only RPCL order\n"); + fprintf(stdout,"\n"); + /* UniPG>> */ #ifdef USE_JPWL - fprintf(stdout," * No JPWL protection\n"); + fprintf(stdout,"-W : adoption of JPWL (Part 11) capabilities (-W params)\n"); + fprintf(stdout," The parameters can be written and repeated in any order:\n"); + fprintf(stdout," [h<=type>,s<=method>,a=,...\n"); + fprintf(stdout," ...,z=,g=,p<=type>]\n"); + fprintf(stdout,"\n"); + fprintf(stdout," h selects the header error protection (EPB): 'type' can be\n"); + fprintf(stdout," [0=none 1,absent=predefined 16=CRC-16 32=CRC-32 37-128=RS]\n"); + fprintf(stdout," if 'tilepart' is absent, it is for main and tile headers\n"); + fprintf(stdout," if 'tilepart' is present, it applies from that tile\n"); + fprintf(stdout," onwards, up to the next h<> spec, or to the last tilepart\n"); + fprintf(stdout," in the codestream (max. %d specs)\n", JPWL_MAX_NO_TILESPECS); + fprintf(stdout,"\n"); + fprintf(stdout," p selects the packet error protection (EEP/UEP with EPBs)\n"); + fprintf(stdout," to be applied to raw data: 'type' can be\n"); + fprintf(stdout," [0=none 1,absent=predefined 16=CRC-16 32=CRC-32 37-128=RS]\n"); + fprintf(stdout," if 'tilepart:pack' is absent, it is from tile 0, packet 0\n"); + fprintf(stdout," if 'tilepart:pack' is present, it applies from that tile\n"); + fprintf(stdout," and that packet onwards, up to the next packet spec\n"); + fprintf(stdout," or to the last packet in the last tilepart in the stream\n"); + fprintf(stdout," (max. %d specs)\n", JPWL_MAX_NO_PACKSPECS); + fprintf(stdout,"\n"); + fprintf(stdout," s enables sensitivity data insertion (ESD): 'method' can be\n"); + fprintf(stdout," [-1=NO ESD 0=RELATIVE ERROR 1=MSE 2=MSE REDUCTION 3=PSNR\n"); + fprintf(stdout," 4=PSNR INCREMENT 5=MAXERR 6=TSE 7=RESERVED]\n"); + fprintf(stdout," if 'tilepart' is absent, it is for main header only\n"); + fprintf(stdout," if 'tilepart' is present, it applies from that tile\n"); + fprintf(stdout," onwards, up to the next s<> spec, or to the last tilepart\n"); + fprintf(stdout," in the codestream (max. %d specs)\n", JPWL_MAX_NO_TILESPECS); + fprintf(stdout,"\n"); + fprintf(stdout," g determines the addressing mode: can be\n"); + fprintf(stdout," [0=PACKET 1=BYTE RANGE 2=PACKET RANGE]\n"); + fprintf(stdout,"\n"); + fprintf(stdout," a determines the size of data addressing: can be\n"); + fprintf(stdout," 2/4 bytes (small/large codestreams). If not set, auto-mode\n"); + fprintf(stdout,"\n"); + fprintf(stdout," z determines the size of sensitivity values: can be\n"); + fprintf(stdout," 1/2 bytes, for the transformed pseudo-floating point value\n"); + fprintf(stdout,"\n"); + fprintf(stdout," ex.:\n"); + fprintf(stdout," h,h0=64,h3=16,h5=32,p0=78,p0:24=56,p1,p3:0=0,p3:20=32,s=0,\n"); + fprintf(stdout," s0=6,s3=-1,a=0,g=1,z=1\n"); + fprintf(stdout," means\n"); + fprintf(stdout," predefined EPB in MH, rs(64,32) from TPH 0 to TPH 2,\n"); + fprintf(stdout," CRC-16 in TPH 3 and TPH 4, CRC-32 in remaining TPHs,\n"); + fprintf(stdout," UEP rs(78,32) for packets 0 to 23 of tile 0,\n"); + fprintf(stdout," UEP rs(56,32) for packs. 24 to the last of tilepart 0,\n"); + fprintf(stdout," UEP rs default for packets of tilepart 1,\n"); + fprintf(stdout," no UEP for packets 0 to 19 of tilepart 3,\n"); + fprintf(stdout," UEP CRC-32 for packs. 20 of tilepart 3 to last tilepart,\n"); + fprintf(stdout," relative sensitivity ESD for MH,\n"); + fprintf(stdout," TSE ESD from TPH 0 to TPH 2, byte range with automatic\n"); + fprintf(stdout," size of addresses and 1 byte for each sensitivity value\n"); + fprintf(stdout,"\n"); + fprintf(stdout," ex.:\n"); + fprintf(stdout," h,s,p\n"); + fprintf(stdout," means\n"); + fprintf(stdout," default protection to headers (MH and TPHs) as well as\n"); + fprintf(stdout," data packets, one ESD in MH\n"); + fprintf(stdout,"\n"); + fprintf(stdout," N.B.: use the following recommendations when specifying\n"); + fprintf(stdout," the JPWL parameters list\n"); + fprintf(stdout," - when you use UEP, always pair the 'p' option with 'h'\n"); + fprintf(stdout," \n"); #endif /* USE_JPWL */ -/* < \n"); - fprintf(stdout," Currently accepts PBM, PGM, PPM, PNM, PAM, PGX, PNG, BMP, TIF, RAW, RAWL and TGA formats\n"); - fprintf(stdout,"\n"); - fprintf(stdout,"-i : source file (-i source.pnm also *pbm, *.pgm, *.ppm, *.pam, *.pgx, *png, *.bmp, *.tif, *.raw, *.tga) \n"); - fprintf(stdout," When using this option -o must be used\n"); - fprintf(stdout,"\n"); - fprintf(stdout,"-o : destination file (-o dest.j2k or .jp2) \n"); - fprintf(stdout,"\n"); - fprintf(stdout,"Optional Parameters:\n"); - fprintf(stdout,"\n"); - fprintf(stdout,"-h : display the help information \n "); - fprintf(stdout,"\n"); - fprintf(stdout,"-cinema2K : Digital Cinema 2K profile compliant codestream for 2K resolution.(-CINEMA2K 24 or 48) \n"); - fprintf(stdout," Need to specify the frames per second for a 2K resolution. Only 24 or 48 fps is allowed\n"); - fprintf(stdout,"\n"); - fprintf(stdout,"-cinema4K : Digital Cinema 4K profile compliant codestream for 4K resolution \n"); - fprintf(stdout," Frames per second not required. Default value is 24fps\n"); - fprintf(stdout,"\n"); - fprintf(stdout,"-r : different compression ratios for successive layers (-r 20,10,5)\n "); - fprintf(stdout," - The rate specified for each quality level is the desired \n"); - fprintf(stdout," compression factor.\n"); - fprintf(stdout," Example: -r 20,10,1 means quality 1: compress 20x, \n"); - fprintf(stdout," quality 2: compress 10x and quality 3: compress lossless\n"); - fprintf(stdout,"\n"); - fprintf(stdout," (options -r and -q cannot be used together)\n "); - fprintf(stdout,"\n"); + /* <> */ -#ifdef USE_JPWL - fprintf(stdout,"-W : adoption of JPWL (Part 11) capabilities (-W params)\n"); - fprintf(stdout," The parameters can be written and repeated in any order:\n"); - fprintf(stdout," [h<=type>,s<=method>,a=,...\n"); - fprintf(stdout," ...,z=,g=,p<=type>]\n"); - fprintf(stdout,"\n"); - fprintf(stdout," h selects the header error protection (EPB): 'type' can be\n"); - fprintf(stdout," [0=none 1,absent=predefined 16=CRC-16 32=CRC-32 37-128=RS]\n"); - fprintf(stdout," if 'tilepart' is absent, it is for main and tile headers\n"); - fprintf(stdout," if 'tilepart' is present, it applies from that tile\n"); - fprintf(stdout," onwards, up to the next h<> spec, or to the last tilepart\n"); - fprintf(stdout," in the codestream (max. %d specs)\n", JPWL_MAX_NO_TILESPECS); - fprintf(stdout,"\n"); - fprintf(stdout," p selects the packet error protection (EEP/UEP with EPBs)\n"); - fprintf(stdout," to be applied to raw data: 'type' can be\n"); - fprintf(stdout," [0=none 1,absent=predefined 16=CRC-16 32=CRC-32 37-128=RS]\n"); - fprintf(stdout," if 'tilepart:pack' is absent, it is from tile 0, packet 0\n"); - fprintf(stdout," if 'tilepart:pack' is present, it applies from that tile\n"); - fprintf(stdout," and that packet onwards, up to the next packet spec\n"); - fprintf(stdout," or to the last packet in the last tilepart in the stream\n"); - fprintf(stdout," (max. %d specs)\n", JPWL_MAX_NO_PACKSPECS); - fprintf(stdout,"\n"); - fprintf(stdout," s enables sensitivity data insertion (ESD): 'method' can be\n"); - fprintf(stdout," [-1=NO ESD 0=RELATIVE ERROR 1=MSE 2=MSE REDUCTION 3=PSNR\n"); - fprintf(stdout," 4=PSNR INCREMENT 5=MAXERR 6=TSE 7=RESERVED]\n"); - fprintf(stdout," if 'tilepart' is absent, it is for main header only\n"); - fprintf(stdout," if 'tilepart' is present, it applies from that tile\n"); - fprintf(stdout," onwards, up to the next s<> spec, or to the last tilepart\n"); - fprintf(stdout," in the codestream (max. %d specs)\n", JPWL_MAX_NO_TILESPECS); - fprintf(stdout,"\n"); - fprintf(stdout," g determines the addressing mode: can be\n"); - fprintf(stdout," [0=PACKET 1=BYTE RANGE 2=PACKET RANGE]\n"); - fprintf(stdout,"\n"); - fprintf(stdout," a determines the size of data addressing: can be\n"); - fprintf(stdout," 2/4 bytes (small/large codestreams). If not set, auto-mode\n"); - fprintf(stdout,"\n"); - fprintf(stdout," z determines the size of sensitivity values: can be\n"); - fprintf(stdout," 1/2 bytes, for the transformed pseudo-floating point value\n"); - fprintf(stdout,"\n"); - fprintf(stdout," ex.:\n"); - fprintf(stdout," h,h0=64,h3=16,h5=32,p0=78,p0:24=56,p1,p3:0=0,p3:20=32,s=0,\n"); - fprintf(stdout," s0=6,s3=-1,a=0,g=1,z=1\n"); - fprintf(stdout," means\n"); - fprintf(stdout," predefined EPB in MH, rs(64,32) from TPH 0 to TPH 2,\n"); - fprintf(stdout," CRC-16 in TPH 3 and TPH 4, CRC-32 in remaining TPHs,\n"); - fprintf(stdout," UEP rs(78,32) for packets 0 to 23 of tile 0,\n"); - fprintf(stdout," UEP rs(56,32) for packs. 24 to the last of tilepart 0,\n"); - fprintf(stdout," UEP rs default for packets of tilepart 1,\n"); - fprintf(stdout," no UEP for packets 0 to 19 of tilepart 3,\n"); - fprintf(stdout," UEP CRC-32 for packs. 20 of tilepart 3 to last tilepart,\n"); - fprintf(stdout," relative sensitivity ESD for MH,\n"); - fprintf(stdout," TSE ESD from TPH 0 to TPH 2, byte range with automatic\n"); - fprintf(stdout," size of addresses and 1 byte for each sensitivity value\n"); - fprintf(stdout,"\n"); - fprintf(stdout," ex.:\n"); - fprintf(stdout," h,s,p\n"); - fprintf(stdout," means\n"); - fprintf(stdout," default protection to headers (MH and TPHs) as well as\n"); - fprintf(stdout," data packets, one ESD in MH\n"); - fprintf(stdout,"\n"); - fprintf(stdout," N.B.: use the following recommendations when specifying\n"); - fprintf(stdout," the JPWL parameters list\n"); - fprintf(stdout," - when you use UEP, always pair the 'p' option with 'h'\n"); - fprintf(stdout," \n"); -#endif /* USE_JPWL */ -/* <d_name)==0 || strcmp("..",content->d_name)==0 ) - continue; - num_images++; - } - return num_images; + num_images=0; + while((content=readdir(dir))!=NULL){ + if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 ) + continue; + num_images++; + } + return num_images; } static int load_images(dircnt_t *dirptr, char *imgdirpath){ - DIR *dir; - struct dirent* content; - int i = 0; + DIR *dir; + struct dirent* content; + int i = 0; - /*Reading the input images from given input directory*/ + /*Reading the input images from given input directory*/ - dir= opendir(imgdirpath); - if(!dir){ - fprintf(stderr,"Could not open Folder %s\n",imgdirpath); - return 1; - }else { - fprintf(stderr,"Folder opened successfully\n"); - } + dir= opendir(imgdirpath); + if(!dir){ + fprintf(stderr,"Could not open Folder %s\n",imgdirpath); + return 1; + }else { + fprintf(stderr,"Folder opened successfully\n"); + } - while((content=readdir(dir))!=NULL){ - if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 ) - continue; + while((content=readdir(dir))!=NULL){ + if(strcmp(".",content->d_name)==0 || strcmp("..",content->d_name)==0 ) + continue; - strcpy(dirptr->filename[i],content->d_name); - i++; - } - return 0; + strcpy(dirptr->filename[i],content->d_name); + i++; + } + return 0; } static int get_file_format(char *filename) { - unsigned int i; - static const char *extension[] = { - "pgx", "pnm", "pgm", "ppm", "pbm", "pam", "bmp", "tif", "raw", "rawl", "tga", "png", "j2k", "jp2", "j2c", "jpc" + unsigned int i; + static const char *extension[] = { + "pgx", "pnm", "pgm", "ppm", "pbm", "pam", "bmp", "tif", "raw", "rawl", "tga", "png", "j2k", "jp2", "j2c", "jpc" }; - static const int format[] = { - PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, RAWL_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, J2K_CFMT, J2K_CFMT + static const int format[] = { + PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, RAWL_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, J2K_CFMT, J2K_CFMT }; - char * ext = strrchr(filename, '.'); - if (ext == NULL) - return -1; - ext++; - for(i = 0; i < sizeof(format)/sizeof(*format); i++) { - if(strcasecmp(ext, extension[i]) == 0) { - return format[i]; - } - } - return -1; + char * ext = strrchr(filename, '.'); + if (ext == NULL) + return -1; + ext++; + for(i = 0; i < sizeof(format)/sizeof(*format); i++) { + if(strcasecmp(ext, extension[i]) == 0) { + return format[i]; + } + } + return -1; } static char * get_file_name(char *name){ - char *fname; - fname= (char*)malloc(OPJ_PATH_LEN*sizeof(char)); - fname= strtok(name,"."); - return fname; + char *fname; + fname= (char*)malloc(OPJ_PATH_LEN*sizeof(char)); + fname= strtok(name,"."); + return fname; } static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_cparameters_t *parameters){ - char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],outfilename[OPJ_PATH_LEN],temp_ofname[OPJ_PATH_LEN]; - char *temp_p, temp1[OPJ_PATH_LEN]=""; + char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],outfilename[OPJ_PATH_LEN],temp_ofname[OPJ_PATH_LEN]; + char *temp_p, temp1[OPJ_PATH_LEN]=""; - strcpy(image_filename,dirptr->filename[imageno]); - fprintf(stderr,"File Number %d \"%s\"\n",imageno,image_filename); - parameters->decod_format = get_file_format(image_filename); - if (parameters->decod_format == -1) - return 1; - sprintf(infilename,"%s/%s",img_fol->imgdirpath,image_filename); - strncpy(parameters->infile, infilename, sizeof(infilename)); + strcpy(image_filename,dirptr->filename[imageno]); + fprintf(stderr,"File Number %d \"%s\"\n",imageno,image_filename); + parameters->decod_format = get_file_format(image_filename); + if (parameters->decod_format == -1) + return 1; + sprintf(infilename,"%s/%s",img_fol->imgdirpath,image_filename); + strncpy(parameters->infile, infilename, sizeof(infilename)); - /*Set output file*/ - strcpy(temp_ofname,get_file_name(image_filename)); - while((temp_p = strtok(NULL,".")) != NULL){ - strcat(temp_ofname,temp1); - sprintf(temp1,".%s",temp_p); - } - if(img_fol->set_out_format==1){ - sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format); - strncpy(parameters->outfile, outfilename, sizeof(outfilename)); - } - return 0; + /*Set output file*/ + strcpy(temp_ofname,get_file_name(image_filename)); + while((temp_p = strtok(NULL,".")) != NULL){ + strcat(temp_ofname,temp1); + sprintf(temp1,".%s",temp_p); + } + if(img_fol->set_out_format==1){ + sprintf(outfilename,"%s/%s.%s",img_fol->imgdirpath,temp_ofname,img_fol->out_format); + strncpy(parameters->outfile, outfilename, sizeof(outfilename)); + } + return 0; } static int initialise_4K_poc(opj_poc_t *POC, int numres){ - POC[0].tile = 1; - POC[0].resno0 = 0; - POC[0].compno0 = 0; - POC[0].layno1 = 1; - POC[0].resno1 = numres-1; - POC[0].compno1 = 3; - POC[0].prg1 = OPJ_CPRL; - POC[1].tile = 1; - POC[1].resno0 = numres-1; - POC[1].compno0 = 0; - POC[1].layno1 = 1; - POC[1].resno1 = numres; - POC[1].compno1 = 3; - POC[1].prg1 = OPJ_CPRL; - return 2; + POC[0].tile = 1; + POC[0].resno0 = 0; + POC[0].compno0 = 0; + POC[0].layno1 = 1; + POC[0].resno1 = numres-1; + POC[0].compno1 = 3; + POC[0].prg1 = OPJ_CPRL; + POC[1].tile = 1; + POC[1].resno0 = numres-1; + POC[1].compno0 = 0; + POC[1].layno1 = 1; + POC[1].resno1 = numres; + POC[1].compno1 = 3; + POC[1].prg1 = OPJ_CPRL; + return 2; } -static void cinema_parameters(opj_cparameters_t *parameters){ - parameters->tile_size_on = OPJ_FALSE; - parameters->cp_tdx=1; - parameters->cp_tdy=1; +static void set_cinema_parameters(opj_cparameters_t *parameters){ - /*Tile part*/ - parameters->tp_flag = 'C'; - parameters->tp_on = 1; + /* No tiling */ + parameters->tile_size_on = OPJ_FALSE; + parameters->cp_tdx=1; + parameters->cp_tdy=1; - /*Tile and Image shall be at (0,0)*/ - parameters->cp_tx0 = 0; - parameters->cp_ty0 = 0; - parameters->image_offset_x0 = 0; - parameters->image_offset_y0 = 0; + /* One tile part for each component */ + parameters->tp_flag = 'C'; + parameters->tp_on = 1; - /*Codeblock size= 32*32*/ - parameters->cblockw_init = 32; - parameters->cblockh_init = 32; - parameters->csty |= 0x01; + /* Tile and Image shall be at (0,0) */ + parameters->cp_tx0 = 0; + parameters->cp_ty0 = 0; + parameters->image_offset_x0 = 0; + parameters->image_offset_y0 = 0; - /*The progression order shall be CPRL*/ - parameters->prog_order = OPJ_CPRL; + /* Codeblock size= 32*32 */ + parameters->cblockw_init = 32; + parameters->cblockh_init = 32; - /* No ROI */ - parameters->roi_compno = -1; + /* Use of precincts */ + parameters->csty |= 0x01; - parameters->subsampling_dx = 1; parameters->subsampling_dy = 1; + /* The progression order shall be CPRL */ + parameters->prog_order = OPJ_CPRL; - /* 9-7 transform */ - parameters->irreversible = 1; + /* No ROI */ + parameters->roi_compno = -1; + + /* No subsampling */ + parameters->subsampling_dx = 1; + parameters->subsampling_dy = 1; + + /* 9-7 transform */ + parameters->irreversible = 1; } -static void cinema_setup_encoder(opj_cparameters_t *parameters,opj_image_t *image, img_fol_t *img_fol){ - int i; - float temp_rate; +static void setup_cinema_encoder(opj_cparameters_t *parameters,opj_image_t *image, img_fol_t *img_fol){ + int i; + float temp_rate; - switch (parameters->cp_cinema){ - case OPJ_CINEMA2K_24: - case OPJ_CINEMA2K_48: - if(parameters->numresolution > 6){ - parameters->numresolution = 6; - } - if (!((image->comps[0].w == 2048) | (image->comps[0].h == 1080))){ - fprintf(stdout,"Image coordinates %d x %d is not 2K compliant.\nJPEG Digital Cinema Profile-3 " - "(2K profile) compliance requires that at least one of coordinates match 2048 x 1080\n", - image->comps[0].w,image->comps[0].h); - parameters->cp_rsiz = OPJ_STD_RSIZ; - } - break; + /* Size and resolution levels */ + switch (parameters->cp_cinema){ + case OPJ_CINEMA2K_24: + case OPJ_CINEMA2K_48: + if(parameters->numresolution > 6){ + fprintf(stdout,"JPEG 2000 Profile-3 (2k dc profile) requires:\n" + "Number of decomposition levels <= 5\n" + "-> Number of decomposition levels forced to 5"); + parameters->numresolution = 6; + } + if (!((image->comps[0].w == 2048) | (image->comps[0].h == 1080))){ + fprintf(stdout,"Image coordinates %d x %d is not 2K compliant.\n" + "JPEG 2000 Profile-3 (2k dc profile) requires:\n" + "at least one of coordinates match 2048 x 1080\n", + image->comps[0].w,image->comps[0].h); + parameters->cp_rsiz = OPJ_STD_RSIZ; + } + break; + case OPJ_CINEMA4K_24: + if(parameters->numresolution < 1){ + fprintf(stdout,"JPEG 2000 Profile-4 (4k dc profile) requires:\n" + "Number of decomposition levels >= 1 && <= 6\n" + "-> Number of decomposition levels forced to 1"); + parameters->numresolution = 1; + }else if(parameters->numresolution > 7){ + fprintf(stdout,"JPEG 2000 Profile-4 (4k dc profile) requires:\n" + "Number of decomposition levels >= 1 && <= 6\n" + "-> Number of decomposition levels forced to 6"); + parameters->numresolution = 7; + } + if (!((image->comps[0].w == 4096) | (image->comps[0].h == 2160))){ + fprintf(stdout,"Image coordinates %d x %d is not 2K compliant.\n" + "JPEG 2000 Profile-4 (4k dc profile) requires:\n" + "at least one of coordinates match 4096 x 2160\n", + image->comps[0].w,image->comps[0].h); + parameters->cp_rsiz = OPJ_STD_RSIZ; + } + parameters->numpocs = initialise_4K_poc(parameters->POC,parameters->numresolution); + break; + default : + break; + } - case OPJ_CINEMA4K_24: - if(parameters->numresolution < 1){ - parameters->numresolution = 1; - }else if(parameters->numresolution > 7){ - parameters->numresolution = 7; - } - if (!((image->comps[0].w == 4096) | (image->comps[0].h == 2160))){ - fprintf(stdout,"Image coordinates %d x %d is not 4K compliant.\nJPEG Digital Cinema Profile-4" - "(4K profile) compliance requires that at least one of coordinates match 4096 x 2160\n", - image->comps[0].w,image->comps[0].h); - parameters->cp_rsiz = OPJ_STD_RSIZ; - } - parameters->numpocs = initialise_4K_poc(parameters->POC,parameters->numresolution); - break; - default : - break; - } + /* Limited bit-rate */ + switch (parameters->cp_cinema){ + case OPJ_CINEMA2K_24: + case OPJ_CINEMA4K_24: + for(i=0 ; itcp_numlayers ; i++){ + temp_rate = 0 ; + if (img_fol->rates[i]== 0){ + parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ + (CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy); + }else{ + temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ + (img_fol->rates[i] * 8 * image->comps[0].dx * image->comps[0].dy); + if (temp_rate > CINEMA_24_CS ){ + parameters->tcp_rates[i]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ + (CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy); + }else{ + parameters->tcp_rates[i]= img_fol->rates[i]; + } + } + } + parameters->max_comp_size = COMP_24_CS; + break; - switch (parameters->cp_cinema){ - case OPJ_CINEMA2K_24: - case OPJ_CINEMA4K_24: - for(i=0 ; itcp_numlayers ; i++){ - temp_rate = 0 ; - if (img_fol->rates[i]== 0){ - parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy); - }else{ - temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (img_fol->rates[i] * 8 * image->comps[0].dx * image->comps[0].dy); - if (temp_rate > CINEMA_24_CS ){ - parameters->tcp_rates[i]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy); - }else{ - parameters->tcp_rates[i]= img_fol->rates[i]; - } - } - } - parameters->max_comp_size = COMP_24_CS; - break; - - case OPJ_CINEMA2K_48: - for(i=0 ; itcp_numlayers ; i++){ - temp_rate = 0 ; - if (img_fol->rates[i]== 0){ - parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy); - }else{ - temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (img_fol->rates[i] * 8 * image->comps[0].dx * image->comps[0].dy); - if (temp_rate > CINEMA_48_CS ){ - parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy); - }else{ - parameters->tcp_rates[i]= img_fol->rates[i]; - } - } - } - parameters->max_comp_size = COMP_48_CS; - break; - default: - break; - } - parameters->cp_disto_alloc = 1; + case OPJ_CINEMA2K_48: + for(i=0 ; itcp_numlayers ; i++){ + temp_rate = 0 ; + if (img_fol->rates[i]== 0){ + parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ + (CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy); + }else{ + temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ + (img_fol->rates[i] * 8 * image->comps[0].dx * image->comps[0].dy); + if (temp_rate > CINEMA_48_CS ){ + parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ + (CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy); + }else{ + parameters->tcp_rates[i]= img_fol->rates[i]; + } + } + } + parameters->max_comp_size = COMP_48_CS; + break; + default: + break; + } + parameters->cp_disto_alloc = 1; } /* ------------------------------------------------------------------------------------ */ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters, - img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename) { - int i, j, totlen, c; - opj_option_t long_option[]={ - {"cinema2K",REQ_ARG, NULL ,'w'}, - {"cinema4K",NO_ARG, NULL ,'y'}, - {"ImgDir",REQ_ARG, NULL ,'z'}, - {"TP",REQ_ARG, NULL ,'u'}, - {"SOP",NO_ARG, NULL ,'S'}, - {"EPH",NO_ARG, NULL ,'E'}, - {"OutFor",REQ_ARG, NULL ,'O'}, - {"POC",REQ_ARG, NULL ,'P'}, - {"ROI",REQ_ARG, NULL ,'R'}, - {"jpip",NO_ARG, NULL, 'J'} - }; + img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename) { + int i, j, totlen, c; + opj_option_t long_option[]={ + {"cinema2K",REQ_ARG, NULL ,'w'}, + {"cinema4K",NO_ARG, NULL ,'y'}, + {"ImgDir",REQ_ARG, NULL ,'z'}, + {"TP",REQ_ARG, NULL ,'u'}, + {"SOP",NO_ARG, NULL ,'S'}, + {"EPH",NO_ARG, NULL ,'E'}, + {"OutFor",REQ_ARG, NULL ,'O'}, + {"POC",REQ_ARG, NULL ,'P'}, + {"ROI",REQ_ARG, NULL ,'R'}, + {"jpip",NO_ARG, NULL, 'J'} + }; - /* parse the command line */ - const char optlist[] = "i:o:r:q:n:b:c:t:p:s:SEM:x:R:d:T:If:P:C:F:u:J" + /* parse the command line */ + const char optlist[] = "i:o:r:q:n:b:c:t:p:s:SEM:x:R:d:T:If:P:C:F:u:J" + #ifdef USE_JPWL + "W:" + #endif /* USE_JPWL */ + "h"; + + totlen=sizeof(long_option); + img_fol->set_out_format=0; + raw_cp->rawWidth = 0; + + do{ + c = opj_getopt_long(argc, argv, optlist,long_option,totlen); + if (c == -1) + break; + switch (c) { + case 'i': /* input file */ + { + char *infile = opj_optarg; + parameters->decod_format = get_file_format(infile); + switch(parameters->decod_format) { + case PGX_DFMT: + case PXM_DFMT: + case BMP_DFMT: + case TIF_DFMT: + case RAW_DFMT: + case RAWL_DFMT: + case TGA_DFMT: + case PNG_DFMT: + break; + default: + fprintf(stderr, + "!! Unrecognized format for infile : %s " + "[accept only *.pnm, *.pgm, *.ppm, *.pgx, *png, *.bmp, *.tif, *.raw or *.tga] !!\n\n", + infile); + return 1; + } + strncpy(parameters->infile, infile, sizeof(parameters->infile)-1); + } + break; + + /* ----------------------------------------------------- */ + + case 'o': /* output file */ + { + char *outfile = opj_optarg; + parameters->cod_format = get_file_format(outfile); + switch(parameters->cod_format) { + case J2K_CFMT: + case JP2_CFMT: + break; + default: + fprintf(stderr, "Unknown output format image %s [only *.j2k, *.j2c or *.jp2]!! \n", outfile); + return 1; + } + strncpy(parameters->outfile, outfile, sizeof(parameters->outfile)-1); + } + break; + + /* ----------------------------------------------------- */ + case 'O': /* output format */ + { + char outformat[50]; + char *of = opj_optarg; + sprintf(outformat,".%s",of); + img_fol->set_out_format = 1; + parameters->cod_format = get_file_format(outformat); + switch(parameters->cod_format) { + case J2K_CFMT: + case JP2_CFMT: + img_fol->out_format = opj_optarg; + break; + default: + fprintf(stderr, "Unknown output format image [only j2k, j2c, jp2]!! \n"); + return 1; + } + } + break; + + + /* ----------------------------------------------------- */ + + + case 'r': /* rates rates/distorsion */ + { + char *s = opj_optarg; + parameters->tcp_numlayers = 0; + while (sscanf(s, "%f", ¶meters->tcp_rates[parameters->tcp_numlayers]) == 1) { + parameters->tcp_numlayers++; + while (*s && *s != ',') { + s++; + } + if (!*s) + break; + s++; + } + parameters->cp_disto_alloc = 1; + } + break; + + /* ----------------------------------------------------- */ + + + case 'F': /* Raw image format parameters */ + { + char signo; + char *s = opj_optarg; + if (sscanf(s, "%d,%d,%d,%d,%c", &raw_cp->rawWidth, &raw_cp->rawHeight, &raw_cp->rawComp, &raw_cp->rawBitDepth, &signo) == 5) { + if (signo == 's') { + raw_cp->rawSigned = OPJ_TRUE; + fprintf(stdout,"\nRaw file parameters: %d,%d,%d,%d Signed\n", raw_cp->rawWidth, raw_cp->rawHeight, raw_cp->rawComp, raw_cp->rawBitDepth); + } + else if (signo == 'u') { + raw_cp->rawSigned = OPJ_FALSE; + fprintf(stdout,"\nRaw file parameters: %d,%d,%d,%d Unsigned\n", raw_cp->rawWidth, raw_cp->rawHeight, raw_cp->rawComp, raw_cp->rawBitDepth); + } + else { + fprintf(stderr,"\nError: invalid raw image parameters: Unknown sign of raw file\n"); + fprintf(stderr,"Please use the Format option -F:\n"); + fprintf(stderr,"-F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n"); + fprintf(stderr,"Example: -i lena.raw -o lena.j2k -F 512,512,3,8,u\n"); + fprintf(stderr,"Aborting\n"); + } + } + else { + fprintf(stderr,"\nError: invalid raw image parameters\n"); + fprintf(stderr,"Please use the Format option -F:\n"); + fprintf(stderr,"-F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n"); + fprintf(stderr,"Example: -i lena.raw -o lena.j2k -F 512,512,3,8,u\n"); + fprintf(stderr,"Aborting\n"); + return 1; + } + } + break; + + /* ----------------------------------------------------- */ + + case 'q': /* add fixed_quality */ + { + char *s = opj_optarg; + while (sscanf(s, "%f", ¶meters->tcp_distoratio[parameters->tcp_numlayers]) == 1) { + parameters->tcp_numlayers++; + while (*s && *s != ',') { + s++; + } + if (!*s) + break; + s++; + } + parameters->cp_fixed_quality = 1; + } + break; + + /* dda */ + /* ----------------------------------------------------- */ + + case 'f': /* mod fixed_quality (before : -q) */ + { + int *row = NULL, *col = NULL; + int numlayers = 0, numresolution = 0, matrix_width = 0; + + char *s = opj_optarg; + sscanf(s, "%d", &numlayers); + s++; + if (numlayers > 9) + s++; + + parameters->tcp_numlayers = numlayers; + numresolution = parameters->numresolution; + matrix_width = numresolution * 3; + parameters->cp_matrice = (int *) malloc(numlayers * matrix_width * sizeof(int)); + s = s + 2; + + for (i = 0; i < numlayers; i++) { + row = ¶meters->cp_matrice[i * matrix_width]; + col = row; + parameters->tcp_rates[i] = 1; + sscanf(s, "%d,", &col[0]); + s += 2; + if (col[0] > 9) + s++; + col[1] = 0; + col[2] = 0; + for (j = 1; j < numresolution; j++) { + col += 3; + sscanf(s, "%d,%d,%d", &col[0], &col[1], &col[2]); + s += 6; + if (col[0] > 9) + s++; + if (col[1] > 9) + s++; + if (col[2] > 9) + s++; + } + if (i < numlayers - 1) + s++; + } + parameters->cp_fixed_alloc = 1; + } + break; + + /* ----------------------------------------------------- */ + + case 't': /* tiles */ + { + sscanf(opj_optarg, "%d,%d", ¶meters->cp_tdx, ¶meters->cp_tdy); + parameters->tile_size_on = OPJ_TRUE; + } + break; + + /* ----------------------------------------------------- */ + + case 'n': /* resolution */ + { + sscanf(opj_optarg, "%d", ¶meters->numresolution); + } + break; + + /* ----------------------------------------------------- */ + case 'c': /* precinct dimension */ + { + char sep; + int res_spec = 0; + + char *s = opj_optarg; + do { + sep = 0; + sscanf(s, "[%d,%d]%c", ¶meters->prcw_init[res_spec], + ¶meters->prch_init[res_spec], &sep); + parameters->csty |= 0x01; + res_spec++; + s = strpbrk(s, "]") + 2; + } + while (sep == ','); + parameters->res_spec = res_spec; + } + break; + + /* ----------------------------------------------------- */ + + case 'b': /* code-block dimension */ + { + int cblockw_init = 0, cblockh_init = 0; + sscanf(opj_optarg, "%d,%d", &cblockw_init, &cblockh_init); + if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024 + || cblockw_init < 4 || cblockh_init > 1024 || cblockh_init < 4) { + fprintf(stderr, + "!! Size of code_block error (option -b) !!\n\nRestriction :\n" + " * width*height<=4096\n * 4<=width,height<= 1024\n\n"); + return 1; + } + parameters->cblockw_init = cblockw_init; + parameters->cblockh_init = cblockh_init; + } + break; + + /* ----------------------------------------------------- */ + + case 'x': /* creation of index file */ + { + char *index = opj_optarg; + strncpy(indexfilename, index, OPJ_PATH_LEN); + } + break; + + /* ----------------------------------------------------- */ + + case 'p': /* progression order */ + { + char progression[4]; + + strncpy(progression, opj_optarg, 4); + parameters->prog_order = give_progression(progression); + if (parameters->prog_order == -1) { + fprintf(stderr, "Unrecognized progression order " + "[LRCP, RLCP, RPCL, PCRL, CPRL] !!\n"); + return 1; + } + } + break; + + /* ----------------------------------------------------- */ + + case 's': /* subsampling factor */ + { + if (sscanf(opj_optarg, "%d,%d", ¶meters->subsampling_dx, + ¶meters->subsampling_dy) != 2) { + fprintf(stderr, "'-s' sub-sampling argument error ! [-s dx,dy]\n"); + return 1; + } + } + break; + + /* ----------------------------------------------------- */ + + case 'd': /* coordonnate of the reference grid */ + { + if (sscanf(opj_optarg, "%d,%d", ¶meters->image_offset_x0, + ¶meters->image_offset_y0) != 2) { + fprintf(stderr, "-d 'coordonnate of the reference grid' argument " + "error !! [-d x0,y0]\n"); + return 1; + } + } + break; + + /* ----------------------------------------------------- */ + + case 'h': /* display an help description */ + encode_help_display(); + return 1; + + /* ----------------------------------------------------- */ + + case 'P': /* POC */ + { + int numpocs = 0; /* number of progression order change (POC) default 0 */ + opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */ + + char *s = opj_optarg; + POC = parameters->POC; + + while (sscanf(s, "T%d=%d,%d,%d,%d,%d,%4s", &POC[numpocs].tile, + &POC[numpocs].resno0, &POC[numpocs].compno0, + &POC[numpocs].layno1, &POC[numpocs].resno1, + &POC[numpocs].compno1, POC[numpocs].progorder) == 7) { + POC[numpocs].prg1 = give_progression(POC[numpocs].progorder); + numpocs++; + while (*s && *s != '/') { + s++; + } + if (!*s) { + break; + } + s++; + } + parameters->numpocs = numpocs; + } + break; + + /* ------------------------------------------------------ */ + + case 'S': /* SOP marker */ + { + parameters->csty |= 0x02; + } + break; + + /* ------------------------------------------------------ */ + + case 'E': /* EPH marker */ + { + parameters->csty |= 0x04; + } + break; + + /* ------------------------------------------------------ */ + + case 'M': /* Mode switch pas tous au point !! */ + { + int value = 0; + if (sscanf(opj_optarg, "%d", &value) == 1) { + for (i = 0; i <= 5; i++) { + int cache = value & (1 << i); + if (cache) + parameters->mode |= (1 << i); + } + } + } + break; + + /* ------------------------------------------------------ */ + + case 'R': /* ROI */ + { + if (sscanf(opj_optarg, "c=%d,U=%d", ¶meters->roi_compno, + ¶meters->roi_shift) != 2) { + fprintf(stderr, "ROI error !! [-ROI c='compno',U='shift']\n"); + return 1; + } + } + break; + + /* ------------------------------------------------------ */ + + case 'T': /* Tile offset */ + { + if (sscanf(opj_optarg, "%d,%d", ¶meters->cp_tx0, ¶meters->cp_ty0) != 2) { + fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]"); + return 1; + } + } + break; + + /* ------------------------------------------------------ */ + + case 'C': /* add a comment */ + { + parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1); + if(parameters->cp_comment) { + strcpy(parameters->cp_comment, opj_optarg); + } + } + break; + + + /* ------------------------------------------------------ */ + + case 'I': /* reversible or not */ + { + parameters->irreversible = 1; + } + break; + + /* ------------------------------------------------------ */ + + case 'u': /* Tile part generation*/ + { + parameters->tp_flag = opj_optarg[0]; + parameters->tp_on = 1; + } + break; + + /* ------------------------------------------------------ */ + + case 'z': /* Image Directory path */ + { + img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1); + strcpy(img_fol->imgdirpath,opj_optarg); + img_fol->set_imgdir=1; + } + break; + + /* ------------------------------------------------------ */ + + case 'w': /* Digital Cinema 2K profile compliance*/ + { + int fps=0; + sscanf(opj_optarg,"%d",&fps); + if(fps == 24){ + parameters->cp_cinema = OPJ_CINEMA2K_24; + }else if(fps == 48 ){ + parameters->cp_cinema = OPJ_CINEMA2K_48; + }else { + fprintf(stderr,"Incorrect value!! must be 24 or 48\n"); + return 1; + } + fprintf(stdout,"CINEMA 2K compliant codestream\n"); + parameters->cp_rsiz = OPJ_CINEMA2K; + + } + break; + + /* ------------------------------------------------------ */ + + case 'y': /* Digital Cinema 4K profile compliance*/ + { + parameters->cp_cinema = OPJ_CINEMA4K_24; + fprintf(stdout,"CINEMA 4K compliant codestream\n"); + parameters->cp_rsiz = OPJ_CINEMA4K; + } + break; + + /* ------------------------------------------------------ */ + case 'm': /* mct input file */ + { + char *lFilename = opj_optarg; + char *lMatrix; + char *lCurrentPtr ; + float *lCurrentDoublePtr; + float *lSpace; + int *l_int_ptr; + int lNbComp = 0, lTotalComp, lMctComp, i, lStrLen; + + /* Open file */ + FILE * lFile = fopen(lFilename,"r"); + if (lFile == NULL) { + return 1; + } + + /* Set size of file and read its content*/ + fseek(lFile,0,SEEK_END); + lStrLen = ftell(lFile); + fseek(lFile,0,SEEK_SET); + lMatrix = (char *) malloc(lStrLen + 1); + fread(lMatrix, lStrLen, 1, lFile); + fclose(lFile); + + lMatrix[lStrLen] = 0; + lCurrentPtr = lMatrix; + + /* replace ',' by 0 */ + while (*lCurrentPtr != 0 ) { + if (*lCurrentPtr == ' ') { + *lCurrentPtr = 0; + ++lNbComp; + } + ++lCurrentPtr; + } + ++lNbComp; + lCurrentPtr = lMatrix; + + lNbComp = (int) (sqrt(4*lNbComp + 1)/2. - 0.5); + lMctComp = lNbComp * lNbComp; + lTotalComp = lMctComp + lNbComp; + lSpace = (float *) malloc(lTotalComp * sizeof(float)); + lCurrentDoublePtr = lSpace; + for (i=0;i> */ #ifdef USE_JPWL - "W:" + /* ------------------------------------------------------ */ + + case 'W': /* JPWL capabilities switched on */ + { + char *token = NULL; + int hprot, pprot, sens, addr, size, range; + + /* we need to enable indexing */ + if (!indexfilename || !*indexfilename) { + strncpy(indexfilename, JPWL_PRIVATEINDEX_NAME, OPJ_PATH_LEN); + } + + /* search for different protection methods */ + + /* break the option in comma points and parse the result */ + token = strtok(opj_optarg, ","); + while(token != NULL) { + + /* search header error protection method */ + if (*token == 'h') { + + static int tile = 0, tilespec = 0, lasttileno = 0; + + hprot = 1; /* predefined method */ + + if(sscanf(token, "h=%d", &hprot) == 1) { + /* Main header, specified */ + if (!((hprot == 0) || (hprot == 1) || (hprot == 16) || (hprot == 32) || + ((hprot >= 37) && (hprot <= 128)))) { + fprintf(stderr, "ERROR -> invalid main header protection method h = %d\n", hprot); + return 1; + } + parameters->jpwl_hprot_MH = hprot; + + } else if(sscanf(token, "h%d=%d", &tile, &hprot) == 2) { + /* Tile part header, specified */ + if (!((hprot == 0) || (hprot == 1) || (hprot == 16) || (hprot == 32) || + ((hprot >= 37) && (hprot <= 128)))) { + fprintf(stderr, "ERROR -> invalid tile part header protection method h = %d\n", hprot); + return 1; + } + if (tile < 0) { + fprintf(stderr, "ERROR -> invalid tile part number on protection method t = %d\n", tile); + return 1; + } + if (tilespec < JPWL_MAX_NO_TILESPECS) { + parameters->jpwl_hprot_TPH_tileno[tilespec] = lasttileno = tile; + parameters->jpwl_hprot_TPH[tilespec++] = hprot; + } + + } else if(sscanf(token, "h%d", &tile) == 1) { + /* Tile part header, unspecified */ + if (tile < 0) { + fprintf(stderr, "ERROR -> invalid tile part number on protection method t = %d\n", tile); + return 1; + } + if (tilespec < JPWL_MAX_NO_TILESPECS) { + parameters->jpwl_hprot_TPH_tileno[tilespec] = lasttileno = tile; + parameters->jpwl_hprot_TPH[tilespec++] = hprot; + } + + + } else if (!strcmp(token, "h")) { + /* Main header, unspecified */ + parameters->jpwl_hprot_MH = hprot; + + } else { + fprintf(stderr, "ERROR -> invalid protection method selection = %s\n", token); + return 1; + }; + + } + + /* search packet error protection method */ + if (*token == 'p') { + + static int pack = 0, tile = 0, packspec = 0; + + pprot = 1; /* predefined method */ + + if (sscanf(token, "p=%d", &pprot) == 1) { + /* Method for all tiles and all packets */ + if (!((pprot == 0) || (pprot == 1) || (pprot == 16) || (pprot == 32) || + ((pprot >= 37) && (pprot <= 128)))) { + fprintf(stderr, "ERROR -> invalid default packet protection method p = %d\n", pprot); + return 1; + } + parameters->jpwl_pprot_tileno[0] = 0; + parameters->jpwl_pprot_packno[0] = 0; + parameters->jpwl_pprot[0] = pprot; + + } else if (sscanf(token, "p%d=%d", &tile, &pprot) == 2) { + /* method specified from that tile on */ + if (!((pprot == 0) || (pprot == 1) || (pprot == 16) || (pprot == 32) || + ((pprot >= 37) && (pprot <= 128)))) { + fprintf(stderr, "ERROR -> invalid packet protection method p = %d\n", pprot); + return 1; + } + if (tile < 0) { + fprintf(stderr, "ERROR -> invalid tile part number on protection method p = %d\n", tile); + return 1; + } + if (packspec < JPWL_MAX_NO_PACKSPECS) { + parameters->jpwl_pprot_tileno[packspec] = tile; + parameters->jpwl_pprot_packno[packspec] = 0; + parameters->jpwl_pprot[packspec++] = pprot; + } + + } else if (sscanf(token, "p%d:%d=%d", &tile, &pack, &pprot) == 3) { + /* method fully specified from that tile and that packet on */ + if (!((pprot == 0) || (pprot == 1) || (pprot == 16) || (pprot == 32) || + ((pprot >= 37) && (pprot <= 128)))) { + fprintf(stderr, "ERROR -> invalid packet protection method p = %d\n", pprot); + return 1; + } + if (tile < 0) { + fprintf(stderr, "ERROR -> invalid tile part number on protection method p = %d\n", tile); + return 1; + } + if (pack < 0) { + fprintf(stderr, "ERROR -> invalid packet number on protection method p = %d\n", pack); + return 1; + } + if (packspec < JPWL_MAX_NO_PACKSPECS) { + parameters->jpwl_pprot_tileno[packspec] = tile; + parameters->jpwl_pprot_packno[packspec] = pack; + parameters->jpwl_pprot[packspec++] = pprot; + } + + } else if (sscanf(token, "p%d:%d", &tile, &pack) == 2) { + /* default method from that tile and that packet on */ + if (!((pprot == 0) || (pprot == 1) || (pprot == 16) || (pprot == 32) || + ((pprot >= 37) && (pprot <= 128)))) { + fprintf(stderr, "ERROR -> invalid packet protection method p = %d\n", pprot); + return 1; + } + if (tile < 0) { + fprintf(stderr, "ERROR -> invalid tile part number on protection method p = %d\n", tile); + return 1; + } + if (pack < 0) { + fprintf(stderr, "ERROR -> invalid packet number on protection method p = %d\n", pack); + return 1; + } + if (packspec < JPWL_MAX_NO_PACKSPECS) { + parameters->jpwl_pprot_tileno[packspec] = tile; + parameters->jpwl_pprot_packno[packspec] = pack; + parameters->jpwl_pprot[packspec++] = pprot; + } + + } else if (sscanf(token, "p%d", &tile) == 1) { + /* default from a tile on */ + if (tile < 0) { + fprintf(stderr, "ERROR -> invalid tile part number on protection method p = %d\n", tile); + return 1; + } + if (packspec < JPWL_MAX_NO_PACKSPECS) { + parameters->jpwl_pprot_tileno[packspec] = tile; + parameters->jpwl_pprot_packno[packspec] = 0; + parameters->jpwl_pprot[packspec++] = pprot; + } + + + } else if (!strcmp(token, "p")) { + /* all default */ + parameters->jpwl_pprot_tileno[0] = 0; + parameters->jpwl_pprot_packno[0] = 0; + parameters->jpwl_pprot[0] = pprot; + + } else { + fprintf(stderr, "ERROR -> invalid protection method selection = %s\n", token); + return 1; + }; + + } + + /* search sensitivity method */ + if (*token == 's') { + + static int tile = 0, tilespec = 0, lasttileno = 0; + + sens = 0; /* predefined: relative error */ + + if(sscanf(token, "s=%d", &sens) == 1) { + /* Main header, specified */ + if ((sens < -1) || (sens > 7)) { + fprintf(stderr, "ERROR -> invalid main header sensitivity method s = %d\n", sens); + return 1; + } + parameters->jpwl_sens_MH = sens; + + } else if(sscanf(token, "s%d=%d", &tile, &sens) == 2) { + /* Tile part header, specified */ + if ((sens < -1) || (sens > 7)) { + fprintf(stderr, "ERROR -> invalid tile part header sensitivity method s = %d\n", sens); + return 1; + } + if (tile < 0) { + fprintf(stderr, "ERROR -> invalid tile part number on sensitivity method t = %d\n", tile); + return 1; + } + if (tilespec < JPWL_MAX_NO_TILESPECS) { + parameters->jpwl_sens_TPH_tileno[tilespec] = lasttileno = tile; + parameters->jpwl_sens_TPH[tilespec++] = sens; + } + + } else if(sscanf(token, "s%d", &tile) == 1) { + /* Tile part header, unspecified */ + if (tile < 0) { + fprintf(stderr, "ERROR -> invalid tile part number on sensitivity method t = %d\n", tile); + return 1; + } + if (tilespec < JPWL_MAX_NO_TILESPECS) { + parameters->jpwl_sens_TPH_tileno[tilespec] = lasttileno = tile; + parameters->jpwl_sens_TPH[tilespec++] = hprot; + } + + } else if (!strcmp(token, "s")) { + /* Main header, unspecified */ + parameters->jpwl_sens_MH = sens; + + } else { + fprintf(stderr, "ERROR -> invalid sensitivity method selection = %s\n", token); + return 1; + }; + + parameters->jpwl_sens_size = 2; /* 2 bytes for default size */ + } + + /* search addressing size */ + if (*token == 'a') { + + + addr = 0; /* predefined: auto */ + + if(sscanf(token, "a=%d", &addr) == 1) { + /* Specified */ + if ((addr != 0) && (addr != 2) && (addr != 4)) { + fprintf(stderr, "ERROR -> invalid addressing size a = %d\n", addr); + return 1; + } + parameters->jpwl_sens_addr = addr; + + } else if (!strcmp(token, "a")) { + /* default */ + parameters->jpwl_sens_addr = addr; /* auto for default size */ + + } else { + fprintf(stderr, "ERROR -> invalid addressing selection = %s\n", token); + return 1; + }; + + } + + /* search sensitivity size */ + if (*token == 'z') { + + + size = 1; /* predefined: 1 byte */ + + if(sscanf(token, "z=%d", &size) == 1) { + /* Specified */ + if ((size != 0) && (size != 1) && (size != 2)) { + fprintf(stderr, "ERROR -> invalid sensitivity size z = %d\n", size); + return 1; + } + parameters->jpwl_sens_size = size; + + } else if (!strcmp(token, "a")) { + /* default */ + parameters->jpwl_sens_size = size; /* 1 for default size */ + + } else { + fprintf(stderr, "ERROR -> invalid size selection = %s\n", token); + return 1; + }; + + } + + /* search range method */ + if (*token == 'g') { + + + range = 0; /* predefined: 0 (packet) */ + + if(sscanf(token, "g=%d", &range) == 1) { + /* Specified */ + if ((range < 0) || (range > 3)) { + fprintf(stderr, "ERROR -> invalid sensitivity range method g = %d\n", range); + return 1; + } + parameters->jpwl_sens_range = range; + + } else if (!strcmp(token, "g")) { + /* default */ + parameters->jpwl_sens_range = range; + + } else { + fprintf(stderr, "ERROR -> invalid range selection = %s\n", token); + return 1; + }; + + } + + /* next token or bust */ + token = strtok(NULL, ","); + }; + + + /* some info */ + fprintf(stdout, "Info: JPWL capabilities enabled\n"); + parameters->jpwl_epc_on = OPJ_TRUE; + + } + break; #endif /* USE_JPWL */ - "h"; - - totlen=sizeof(long_option); - img_fol->set_out_format=0; - raw_cp->rawWidth = 0; - - do{ - c = opj_getopt_long(argc, argv, optlist,long_option,totlen); - if (c == -1) - break; - switch (c) { - case 'i': /* input file */ - { - char *infile = opj_optarg; - parameters->decod_format = get_file_format(infile); - switch(parameters->decod_format) { - case PGX_DFMT: - case PXM_DFMT: - case BMP_DFMT: - case TIF_DFMT: - case RAW_DFMT: - case RAWL_DFMT: - case TGA_DFMT: - case PNG_DFMT: - break; - default: - fprintf(stderr, - "!! Unrecognized format for infile : %s " - "[accept only *.pnm, *.pgm, *.ppm, *.pgx, *png, *.bmp, *.tif, *.raw or *.tga] !!\n\n", - infile); - return 1; - } - strncpy(parameters->infile, infile, sizeof(parameters->infile)-1); - } - break; - - /* ----------------------------------------------------- */ - - case 'o': /* output file */ - { - char *outfile = opj_optarg; - parameters->cod_format = get_file_format(outfile); - switch(parameters->cod_format) { - case J2K_CFMT: - case JP2_CFMT: - break; - default: - fprintf(stderr, "Unknown output format image %s [only *.j2k, *.j2c or *.jp2]!! \n", outfile); - return 1; - } - strncpy(parameters->outfile, outfile, sizeof(parameters->outfile)-1); - } - break; - - /* ----------------------------------------------------- */ - case 'O': /* output format */ - { - char outformat[50]; - char *of = opj_optarg; - sprintf(outformat,".%s",of); - img_fol->set_out_format = 1; - parameters->cod_format = get_file_format(outformat); - switch(parameters->cod_format) { - case J2K_CFMT: - case JP2_CFMT: - img_fol->out_format = opj_optarg; - break; - default: - fprintf(stderr, "Unknown output format image [only j2k, j2c, jp2]!! \n"); - return 1; - } - } - break; - - - /* ----------------------------------------------------- */ - - - case 'r': /* rates rates/distorsion */ - { - char *s = opj_optarg; - parameters->tcp_numlayers = 0; - while (sscanf(s, "%f", ¶meters->tcp_rates[parameters->tcp_numlayers]) == 1) { - parameters->tcp_numlayers++; - while (*s && *s != ',') { - s++; - } - if (!*s) - break; - s++; - } - parameters->cp_disto_alloc = 1; - } - break; - - /* ----------------------------------------------------- */ - - - case 'F': /* Raw image format parameters */ - { - char signo; - char *s = opj_optarg; - if (sscanf(s, "%d,%d,%d,%d,%c", &raw_cp->rawWidth, &raw_cp->rawHeight, &raw_cp->rawComp, &raw_cp->rawBitDepth, &signo) == 5) { - if (signo == 's') { - raw_cp->rawSigned = OPJ_TRUE; - fprintf(stdout,"\nRaw file parameters: %d,%d,%d,%d Signed\n", raw_cp->rawWidth, raw_cp->rawHeight, raw_cp->rawComp, raw_cp->rawBitDepth); - } - else if (signo == 'u') { - raw_cp->rawSigned = OPJ_FALSE; - fprintf(stdout,"\nRaw file parameters: %d,%d,%d,%d Unsigned\n", raw_cp->rawWidth, raw_cp->rawHeight, raw_cp->rawComp, raw_cp->rawBitDepth); - } - else { - fprintf(stderr,"\nError: invalid raw image parameters: Unknown sign of raw file\n"); - fprintf(stderr,"Please use the Format option -F:\n"); - fprintf(stderr,"-F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n"); - fprintf(stderr,"Example: -i lena.raw -o lena.j2k -F 512,512,3,8,u\n"); - fprintf(stderr,"Aborting\n"); - } - } - else { - fprintf(stderr,"\nError: invalid raw image parameters\n"); - fprintf(stderr,"Please use the Format option -F:\n"); - fprintf(stderr,"-F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n"); - fprintf(stderr,"Example: -i lena.raw -o lena.j2k -F 512,512,3,8,u\n"); - fprintf(stderr,"Aborting\n"); - return 1; - } - } - break; - - /* ----------------------------------------------------- */ - - case 'q': /* add fixed_quality */ - { - char *s = opj_optarg; - while (sscanf(s, "%f", ¶meters->tcp_distoratio[parameters->tcp_numlayers]) == 1) { - parameters->tcp_numlayers++; - while (*s && *s != ',') { - s++; - } - if (!*s) - break; - s++; - } - parameters->cp_fixed_quality = 1; - } - break; - - /* dda */ - /* ----------------------------------------------------- */ - - case 'f': /* mod fixed_quality (before : -q) */ - { - int *row = NULL, *col = NULL; - int numlayers = 0, numresolution = 0, matrix_width = 0; - - char *s = opj_optarg; - sscanf(s, "%d", &numlayers); - s++; - if (numlayers > 9) - s++; - - parameters->tcp_numlayers = numlayers; - numresolution = parameters->numresolution; - matrix_width = numresolution * 3; - parameters->cp_matrice = (int *) malloc(numlayers * matrix_width * sizeof(int)); - s = s + 2; - - for (i = 0; i < numlayers; i++) { - row = ¶meters->cp_matrice[i * matrix_width]; - col = row; - parameters->tcp_rates[i] = 1; - sscanf(s, "%d,", &col[0]); - s += 2; - if (col[0] > 9) - s++; - col[1] = 0; - col[2] = 0; - for (j = 1; j < numresolution; j++) { - col += 3; - sscanf(s, "%d,%d,%d", &col[0], &col[1], &col[2]); - s += 6; - if (col[0] > 9) - s++; - if (col[1] > 9) - s++; - if (col[2] > 9) - s++; - } - if (i < numlayers - 1) - s++; - } - parameters->cp_fixed_alloc = 1; - } - break; - - /* ----------------------------------------------------- */ - - case 't': /* tiles */ - { - sscanf(opj_optarg, "%d,%d", ¶meters->cp_tdx, ¶meters->cp_tdy); - parameters->tile_size_on = OPJ_TRUE; - } - break; - - /* ----------------------------------------------------- */ - - case 'n': /* resolution */ - { - sscanf(opj_optarg, "%d", ¶meters->numresolution); - } - break; - - /* ----------------------------------------------------- */ - case 'c': /* precinct dimension */ - { - char sep; - int res_spec = 0; - - char *s = opj_optarg; - do { - sep = 0; - sscanf(s, "[%d,%d]%c", ¶meters->prcw_init[res_spec], - ¶meters->prch_init[res_spec], &sep); - parameters->csty |= 0x01; - res_spec++; - s = strpbrk(s, "]") + 2; - } - while (sep == ','); - parameters->res_spec = res_spec; - } - break; - - /* ----------------------------------------------------- */ - - case 'b': /* code-block dimension */ - { - int cblockw_init = 0, cblockh_init = 0; - sscanf(opj_optarg, "%d,%d", &cblockw_init, &cblockh_init); - if (cblockw_init * cblockh_init > 4096 || cblockw_init > 1024 - || cblockw_init < 4 || cblockh_init > 1024 || cblockh_init < 4) { - fprintf(stderr, - "!! Size of code_block error (option -b) !!\n\nRestriction :\n" - " * width*height<=4096\n * 4<=width,height<= 1024\n\n"); - return 1; - } - parameters->cblockw_init = cblockw_init; - parameters->cblockh_init = cblockh_init; - } - break; - - /* ----------------------------------------------------- */ - - case 'x': /* creation of index file */ - { - char *index = opj_optarg; - strncpy(indexfilename, index, OPJ_PATH_LEN); - } - break; - - /* ----------------------------------------------------- */ - - case 'p': /* progression order */ - { - char progression[4]; - - strncpy(progression, opj_optarg, 4); - parameters->prog_order = give_progression(progression); - if (parameters->prog_order == -1) { - fprintf(stderr, "Unrecognized progression order " - "[LRCP, RLCP, RPCL, PCRL, CPRL] !!\n"); - return 1; - } - } - break; - - /* ----------------------------------------------------- */ - - case 's': /* subsampling factor */ - { - if (sscanf(opj_optarg, "%d,%d", ¶meters->subsampling_dx, - ¶meters->subsampling_dy) != 2) { - fprintf(stderr, "'-s' sub-sampling argument error ! [-s dx,dy]\n"); - return 1; - } - } - break; - - /* ----------------------------------------------------- */ - - case 'd': /* coordonnate of the reference grid */ - { - if (sscanf(opj_optarg, "%d,%d", ¶meters->image_offset_x0, - ¶meters->image_offset_y0) != 2) { - fprintf(stderr, "-d 'coordonnate of the reference grid' argument " - "error !! [-d x0,y0]\n"); - return 1; - } - } - break; - - /* ----------------------------------------------------- */ - - case 'h': /* display an help description */ - encode_help_display(); - return 1; - - /* ----------------------------------------------------- */ - - case 'P': /* POC */ - { - int numpocs = 0; /* number of progression order change (POC) default 0 */ - opj_poc_t *POC = NULL; /* POC : used in case of Progression order change */ - - char *s = opj_optarg; - POC = parameters->POC; - - while (sscanf(s, "T%d=%d,%d,%d,%d,%d,%4s", &POC[numpocs].tile, - &POC[numpocs].resno0, &POC[numpocs].compno0, - &POC[numpocs].layno1, &POC[numpocs].resno1, - &POC[numpocs].compno1, POC[numpocs].progorder) == 7) { - POC[numpocs].prg1 = give_progression(POC[numpocs].progorder); - numpocs++; - while (*s && *s != '/') { - s++; - } - if (!*s) { - break; - } - s++; - } - parameters->numpocs = numpocs; - } - break; - - /* ------------------------------------------------------ */ - - case 'S': /* SOP marker */ - { - parameters->csty |= 0x02; - } - break; - - /* ------------------------------------------------------ */ - - case 'E': /* EPH marker */ - { - parameters->csty |= 0x04; - } - break; - - /* ------------------------------------------------------ */ - - case 'M': /* Mode switch pas tous au point !! */ - { - int value = 0; - if (sscanf(opj_optarg, "%d", &value) == 1) { - for (i = 0; i <= 5; i++) { - int cache = value & (1 << i); - if (cache) - parameters->mode |= (1 << i); - } - } - } - break; - - /* ------------------------------------------------------ */ - - case 'R': /* ROI */ - { - if (sscanf(opj_optarg, "c=%d,U=%d", ¶meters->roi_compno, - ¶meters->roi_shift) != 2) { - fprintf(stderr, "ROI error !! [-ROI c='compno',U='shift']\n"); - return 1; - } - } - break; - - /* ------------------------------------------------------ */ - - case 'T': /* Tile offset */ - { - if (sscanf(opj_optarg, "%d,%d", ¶meters->cp_tx0, ¶meters->cp_ty0) != 2) { - fprintf(stderr, "-T 'tile offset' argument error !! [-T X0,Y0]"); - return 1; - } - } - break; - - /* ------------------------------------------------------ */ - - case 'C': /* add a comment */ - { - parameters->cp_comment = (char*)malloc(strlen(opj_optarg) + 1); - if(parameters->cp_comment) { - strcpy(parameters->cp_comment, opj_optarg); - } - } - break; - - - /* ------------------------------------------------------ */ - - case 'I': /* reversible or not */ - { - parameters->irreversible = 1; - } - break; - - /* ------------------------------------------------------ */ - - case 'u': /* Tile part generation*/ - { - parameters->tp_flag = opj_optarg[0]; - parameters->tp_on = 1; - } - break; - - /* ------------------------------------------------------ */ - - case 'z': /* Image Directory path */ - { - img_fol->imgdirpath = (char*)malloc(strlen(opj_optarg) + 1); - strcpy(img_fol->imgdirpath,opj_optarg); - img_fol->set_imgdir=1; - } - break; - - /* ------------------------------------------------------ */ - - case 'w': /* Digital Cinema 2K profile compliance*/ - { - int fps=0; - sscanf(opj_optarg,"%d",&fps); - if(fps == 24){ - parameters->cp_cinema = OPJ_CINEMA2K_24; - }else if(fps == 48 ){ - parameters->cp_cinema = OPJ_CINEMA2K_48; - }else { - fprintf(stderr,"Incorrect value!! must be 24 or 48\n"); - return 1; - } - fprintf(stdout,"CINEMA 2K compliant codestream\n"); - parameters->cp_rsiz = OPJ_CINEMA2K; - - } - break; - - /* ------------------------------------------------------ */ - - case 'y': /* Digital Cinema 4K profile compliance*/ - { - parameters->cp_cinema = OPJ_CINEMA4K_24; - fprintf(stdout,"CINEMA 4K compliant codestream\n"); - parameters->cp_rsiz = OPJ_CINEMA4K; - } - break; - - /* ------------------------------------------------------ */ - case 'm': /* mct input file */ - { - char *lFilename = opj_optarg; - char *lMatrix; - char *lCurrentPtr ; - float *lCurrentDoublePtr; - float *lSpace; - int *l_int_ptr; - int lNbComp = 0, lTotalComp, lMctComp, i, lStrLen; - - /* Open file */ - FILE * lFile = fopen(lFilename,"r"); - if (lFile == NULL) { - return 1; - } - - /* Set size of file and read its content*/ - fseek(lFile,0,SEEK_END); - lStrLen = ftell(lFile); - fseek(lFile,0,SEEK_SET); - lMatrix = (char *) malloc(lStrLen + 1); - fread(lMatrix, lStrLen, 1, lFile); - fclose(lFile); - - lMatrix[lStrLen] = 0; - lCurrentPtr = lMatrix; - - /* replace ',' by 0 */ - while (*lCurrentPtr != 0 ) { - if (*lCurrentPtr == ' ') { - *lCurrentPtr = 0; - ++lNbComp; - } - ++lCurrentPtr; - } - ++lNbComp; - lCurrentPtr = lMatrix; - - lNbComp = (int) (sqrt(4*lNbComp + 1)/2. - 0.5); - lMctComp = lNbComp * lNbComp; - lTotalComp = lMctComp + lNbComp; - lSpace = (float *) malloc(lTotalComp * sizeof(float)); - lCurrentDoublePtr = lSpace; - for (i=0;i> */ -#ifdef USE_JPWL - /* ------------------------------------------------------ */ - - case 'W': /* JPWL capabilities switched on */ - { - char *token = NULL; - int hprot, pprot, sens, addr, size, range; - - /* we need to enable indexing */ - if (!indexfilename || !*indexfilename) { - strncpy(indexfilename, JPWL_PRIVATEINDEX_NAME, OPJ_PATH_LEN); - } - - /* search for different protection methods */ - - /* break the option in comma points and parse the result */ - token = strtok(opj_optarg, ","); - while(token != NULL) { - - /* search header error protection method */ - if (*token == 'h') { - - static int tile = 0, tilespec = 0, lasttileno = 0; - - hprot = 1; /* predefined method */ - - if(sscanf(token, "h=%d", &hprot) == 1) { - /* Main header, specified */ - if (!((hprot == 0) || (hprot == 1) || (hprot == 16) || (hprot == 32) || - ((hprot >= 37) && (hprot <= 128)))) { - fprintf(stderr, "ERROR -> invalid main header protection method h = %d\n", hprot); - return 1; - } - parameters->jpwl_hprot_MH = hprot; - - } else if(sscanf(token, "h%d=%d", &tile, &hprot) == 2) { - /* Tile part header, specified */ - if (!((hprot == 0) || (hprot == 1) || (hprot == 16) || (hprot == 32) || - ((hprot >= 37) && (hprot <= 128)))) { - fprintf(stderr, "ERROR -> invalid tile part header protection method h = %d\n", hprot); - return 1; - } - if (tile < 0) { - fprintf(stderr, "ERROR -> invalid tile part number on protection method t = %d\n", tile); - return 1; - } - if (tilespec < JPWL_MAX_NO_TILESPECS) { - parameters->jpwl_hprot_TPH_tileno[tilespec] = lasttileno = tile; - parameters->jpwl_hprot_TPH[tilespec++] = hprot; - } - - } else if(sscanf(token, "h%d", &tile) == 1) { - /* Tile part header, unspecified */ - if (tile < 0) { - fprintf(stderr, "ERROR -> invalid tile part number on protection method t = %d\n", tile); - return 1; - } - if (tilespec < JPWL_MAX_NO_TILESPECS) { - parameters->jpwl_hprot_TPH_tileno[tilespec] = lasttileno = tile; - parameters->jpwl_hprot_TPH[tilespec++] = hprot; - } - - - } else if (!strcmp(token, "h")) { - /* Main header, unspecified */ - parameters->jpwl_hprot_MH = hprot; - - } else { - fprintf(stderr, "ERROR -> invalid protection method selection = %s\n", token); - return 1; - }; - - } - - /* search packet error protection method */ - if (*token == 'p') { - - static int pack = 0, tile = 0, packspec = 0; - - pprot = 1; /* predefined method */ - - if (sscanf(token, "p=%d", &pprot) == 1) { - /* Method for all tiles and all packets */ - if (!((pprot == 0) || (pprot == 1) || (pprot == 16) || (pprot == 32) || - ((pprot >= 37) && (pprot <= 128)))) { - fprintf(stderr, "ERROR -> invalid default packet protection method p = %d\n", pprot); - return 1; - } - parameters->jpwl_pprot_tileno[0] = 0; - parameters->jpwl_pprot_packno[0] = 0; - parameters->jpwl_pprot[0] = pprot; - - } else if (sscanf(token, "p%d=%d", &tile, &pprot) == 2) { - /* method specified from that tile on */ - if (!((pprot == 0) || (pprot == 1) || (pprot == 16) || (pprot == 32) || - ((pprot >= 37) && (pprot <= 128)))) { - fprintf(stderr, "ERROR -> invalid packet protection method p = %d\n", pprot); - return 1; - } - if (tile < 0) { - fprintf(stderr, "ERROR -> invalid tile part number on protection method p = %d\n", tile); - return 1; - } - if (packspec < JPWL_MAX_NO_PACKSPECS) { - parameters->jpwl_pprot_tileno[packspec] = tile; - parameters->jpwl_pprot_packno[packspec] = 0; - parameters->jpwl_pprot[packspec++] = pprot; - } - - } else if (sscanf(token, "p%d:%d=%d", &tile, &pack, &pprot) == 3) { - /* method fully specified from that tile and that packet on */ - if (!((pprot == 0) || (pprot == 1) || (pprot == 16) || (pprot == 32) || - ((pprot >= 37) && (pprot <= 128)))) { - fprintf(stderr, "ERROR -> invalid packet protection method p = %d\n", pprot); - return 1; - } - if (tile < 0) { - fprintf(stderr, "ERROR -> invalid tile part number on protection method p = %d\n", tile); - return 1; - } - if (pack < 0) { - fprintf(stderr, "ERROR -> invalid packet number on protection method p = %d\n", pack); - return 1; - } - if (packspec < JPWL_MAX_NO_PACKSPECS) { - parameters->jpwl_pprot_tileno[packspec] = tile; - parameters->jpwl_pprot_packno[packspec] = pack; - parameters->jpwl_pprot[packspec++] = pprot; - } - - } else if (sscanf(token, "p%d:%d", &tile, &pack) == 2) { - /* default method from that tile and that packet on */ - if (!((pprot == 0) || (pprot == 1) || (pprot == 16) || (pprot == 32) || - ((pprot >= 37) && (pprot <= 128)))) { - fprintf(stderr, "ERROR -> invalid packet protection method p = %d\n", pprot); - return 1; - } - if (tile < 0) { - fprintf(stderr, "ERROR -> invalid tile part number on protection method p = %d\n", tile); - return 1; - } - if (pack < 0) { - fprintf(stderr, "ERROR -> invalid packet number on protection method p = %d\n", pack); - return 1; - } - if (packspec < JPWL_MAX_NO_PACKSPECS) { - parameters->jpwl_pprot_tileno[packspec] = tile; - parameters->jpwl_pprot_packno[packspec] = pack; - parameters->jpwl_pprot[packspec++] = pprot; - } - - } else if (sscanf(token, "p%d", &tile) == 1) { - /* default from a tile on */ - if (tile < 0) { - fprintf(stderr, "ERROR -> invalid tile part number on protection method p = %d\n", tile); - return 1; - } - if (packspec < JPWL_MAX_NO_PACKSPECS) { - parameters->jpwl_pprot_tileno[packspec] = tile; - parameters->jpwl_pprot_packno[packspec] = 0; - parameters->jpwl_pprot[packspec++] = pprot; - } - - - } else if (!strcmp(token, "p")) { - /* all default */ - parameters->jpwl_pprot_tileno[0] = 0; - parameters->jpwl_pprot_packno[0] = 0; - parameters->jpwl_pprot[0] = pprot; - - } else { - fprintf(stderr, "ERROR -> invalid protection method selection = %s\n", token); - return 1; - }; - - } - - /* search sensitivity method */ - if (*token == 's') { - - static int tile = 0, tilespec = 0, lasttileno = 0; - - sens = 0; /* predefined: relative error */ - - if(sscanf(token, "s=%d", &sens) == 1) { - /* Main header, specified */ - if ((sens < -1) || (sens > 7)) { - fprintf(stderr, "ERROR -> invalid main header sensitivity method s = %d\n", sens); - return 1; - } - parameters->jpwl_sens_MH = sens; - - } else if(sscanf(token, "s%d=%d", &tile, &sens) == 2) { - /* Tile part header, specified */ - if ((sens < -1) || (sens > 7)) { - fprintf(stderr, "ERROR -> invalid tile part header sensitivity method s = %d\n", sens); - return 1; - } - if (tile < 0) { - fprintf(stderr, "ERROR -> invalid tile part number on sensitivity method t = %d\n", tile); - return 1; - } - if (tilespec < JPWL_MAX_NO_TILESPECS) { - parameters->jpwl_sens_TPH_tileno[tilespec] = lasttileno = tile; - parameters->jpwl_sens_TPH[tilespec++] = sens; - } - - } else if(sscanf(token, "s%d", &tile) == 1) { - /* Tile part header, unspecified */ - if (tile < 0) { - fprintf(stderr, "ERROR -> invalid tile part number on sensitivity method t = %d\n", tile); - return 1; - } - if (tilespec < JPWL_MAX_NO_TILESPECS) { - parameters->jpwl_sens_TPH_tileno[tilespec] = lasttileno = tile; - parameters->jpwl_sens_TPH[tilespec++] = hprot; - } - - } else if (!strcmp(token, "s")) { - /* Main header, unspecified */ - parameters->jpwl_sens_MH = sens; - - } else { - fprintf(stderr, "ERROR -> invalid sensitivity method selection = %s\n", token); - return 1; - }; - - parameters->jpwl_sens_size = 2; /* 2 bytes for default size */ - } - - /* search addressing size */ - if (*token == 'a') { - - - addr = 0; /* predefined: auto */ - - if(sscanf(token, "a=%d", &addr) == 1) { - /* Specified */ - if ((addr != 0) && (addr != 2) && (addr != 4)) { - fprintf(stderr, "ERROR -> invalid addressing size a = %d\n", addr); - return 1; - } - parameters->jpwl_sens_addr = addr; - - } else if (!strcmp(token, "a")) { - /* default */ - parameters->jpwl_sens_addr = addr; /* auto for default size */ - - } else { - fprintf(stderr, "ERROR -> invalid addressing selection = %s\n", token); - return 1; - }; - - } - - /* search sensitivity size */ - if (*token == 'z') { - - - size = 1; /* predefined: 1 byte */ - - if(sscanf(token, "z=%d", &size) == 1) { - /* Specified */ - if ((size != 0) && (size != 1) && (size != 2)) { - fprintf(stderr, "ERROR -> invalid sensitivity size z = %d\n", size); - return 1; - } - parameters->jpwl_sens_size = size; - - } else if (!strcmp(token, "a")) { - /* default */ - parameters->jpwl_sens_size = size; /* 1 for default size */ - - } else { - fprintf(stderr, "ERROR -> invalid size selection = %s\n", token); - return 1; - }; - - } - - /* search range method */ - if (*token == 'g') { - - - range = 0; /* predefined: 0 (packet) */ - - if(sscanf(token, "g=%d", &range) == 1) { - /* Specified */ - if ((range < 0) || (range > 3)) { - fprintf(stderr, "ERROR -> invalid sensitivity range method g = %d\n", range); - return 1; - } - parameters->jpwl_sens_range = range; - - } else if (!strcmp(token, "g")) { - /* default */ - parameters->jpwl_sens_range = range; - - } else { - fprintf(stderr, "ERROR -> invalid range selection = %s\n", token); - return 1; - }; - - } - - /* next token or bust */ - token = strtok(NULL, ","); - }; - - - /* some info */ - fprintf(stdout, "Info: JPWL capabilities enabled\n"); - parameters->jpwl_epc_on = OPJ_TRUE; - - } - break; -#endif /* USE_JPWL */ -/* <jpip_on = OPJ_TRUE; - } - break; - /* ------------------------------------------------------ */ - - - default: - fprintf(stderr, "ERROR -> Command line not valid\n"); - return 1; - } - }while(c != -1); - - /* check for possible errors */ - if (parameters->cp_cinema){ - if(parameters->tcp_numlayers > 1){ - parameters->cp_rsiz = OPJ_STD_RSIZ; - fprintf(stdout,"Warning: DC profiles do not allow more than one quality layer. The codestream created will not be compliant with the DC profile\n"); - } - } - if(img_fol->set_imgdir == 1){ - if(!(parameters->infile[0] == 0)){ - fprintf(stderr, "Error: options -ImgDir and -i cannot be used together !!\n"); - return 1; - } - if(img_fol->set_out_format == 0){ - fprintf(stderr, "Error: When -ImgDir is used, -OutFor must be used !!\n"); - fprintf(stderr, "Only one format allowed! Valid formats are j2k and jp2!!\n"); - return 1; - } - if(!((parameters->outfile[0] == 0))){ - fprintf(stderr, "Error: options -ImgDir and -o cannot be used together !!\n"); - fprintf(stderr, "Specify OutputFormat using -OutFor !!\n"); - return 1; - } - }else{ - if((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) { - fprintf(stderr, "Example: %s -i image.ppm -o image.j2k\n",argv[0]); - fprintf(stderr, " Try: %s -h\n",argv[0]); - return 1; - } - } - - if ( (parameters->decod_format == RAW_DFMT && raw_cp->rawWidth == 0) - || (parameters->decod_format == RAWL_DFMT && raw_cp->rawWidth == 0)) { - fprintf(stderr,"\nError: invalid raw image parameters\n"); - fprintf(stderr,"Please use the Format option -F:\n"); - fprintf(stderr,"-F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n"); - fprintf(stderr,"Example: -i lena.raw -o lena.j2k -F 512,512,3,8,u\n"); - fprintf(stderr,"Aborting\n"); - return 1; - } - - if ((parameters->cp_disto_alloc || parameters->cp_fixed_alloc || parameters->cp_fixed_quality) - && (!(parameters->cp_disto_alloc ^ parameters->cp_fixed_alloc ^ parameters->cp_fixed_quality))) { - fprintf(stderr, "Error: options -r -q and -f cannot be used together !!\n"); - return 1; - } /* mod fixed_quality */ - - /* if no rate entered, lossless by default */ - if (parameters->tcp_numlayers == 0) { - parameters->tcp_rates[0] = 0; /* MOD antonin : losslessbug */ - parameters->tcp_numlayers++; - parameters->cp_disto_alloc = 1; - } - - if((parameters->cp_tx0 > parameters->image_offset_x0) || (parameters->cp_ty0 > parameters->image_offset_y0)) { - fprintf(stderr, - "Error: Tile offset dimension is unnappropriate --> TX0(%d)<=IMG_X0(%d) TYO(%d)<=IMG_Y0(%d) \n", - parameters->cp_tx0, parameters->image_offset_x0, parameters->cp_ty0, parameters->image_offset_y0); - return 1; - } - - for (i = 0; i < parameters->numpocs; i++) { - if (parameters->POC[i].prg == -1) { - fprintf(stderr, - "Unrecognized progression order in option -P (POC n %d) [LRCP, RLCP, RPCL, PCRL, CPRL] !!\n", - i + 1); - } - } - - return 0; + /* <jpip_on = OPJ_TRUE; + } + break; + /* ------------------------------------------------------ */ + + + default: + fprintf(stderr, "ERROR -> Command line not valid\n"); + return 1; + } + }while(c != -1); + + /* check for possible errors */ + if (parameters->cp_cinema){ + if(parameters->tcp_numlayers > 1){ + parameters->cp_rsiz = OPJ_STD_RSIZ; + fprintf(stdout,"Warning: DC profiles do not allow more than one quality layer. The codestream created will not be compliant with the DC profile\n"); + } + } + if(img_fol->set_imgdir == 1){ + if(!(parameters->infile[0] == 0)){ + fprintf(stderr, "Error: options -ImgDir and -i cannot be used together !!\n"); + return 1; + } + if(img_fol->set_out_format == 0){ + fprintf(stderr, "Error: When -ImgDir is used, -OutFor must be used !!\n"); + fprintf(stderr, "Only one format allowed! Valid formats are j2k and jp2!!\n"); + return 1; + } + if(!((parameters->outfile[0] == 0))){ + fprintf(stderr, "Error: options -ImgDir and -o cannot be used together !!\n"); + fprintf(stderr, "Specify OutputFormat using -OutFor !!\n"); + return 1; + } + }else{ + if((parameters->infile[0] == 0) || (parameters->outfile[0] == 0)) { + fprintf(stderr, "Example: %s -i image.ppm -o image.j2k\n",argv[0]); + fprintf(stderr, " Try: %s -h\n",argv[0]); + return 1; + } + } + + if ( (parameters->decod_format == RAW_DFMT && raw_cp->rawWidth == 0) + || (parameters->decod_format == RAWL_DFMT && raw_cp->rawWidth == 0)) { + fprintf(stderr,"\nError: invalid raw image parameters\n"); + fprintf(stderr,"Please use the Format option -F:\n"); + fprintf(stderr,"-F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n"); + fprintf(stderr,"Example: -i lena.raw -o lena.j2k -F 512,512,3,8,u\n"); + fprintf(stderr,"Aborting\n"); + return 1; + } + + if ((parameters->cp_disto_alloc || parameters->cp_fixed_alloc || parameters->cp_fixed_quality) + && (!(parameters->cp_disto_alloc ^ parameters->cp_fixed_alloc ^ parameters->cp_fixed_quality))) { + fprintf(stderr, "Error: options -r -q and -f cannot be used together !!\n"); + return 1; + } /* mod fixed_quality */ + + /* if no rate entered, lossless by default */ + if (parameters->tcp_numlayers == 0) { + parameters->tcp_rates[0] = 0; /* MOD antonin : losslessbug */ + parameters->tcp_numlayers++; + parameters->cp_disto_alloc = 1; + } + + if((parameters->cp_tx0 > parameters->image_offset_x0) || (parameters->cp_ty0 > parameters->image_offset_y0)) { + fprintf(stderr, + "Error: Tile offset dimension is unnappropriate --> TX0(%d)<=IMG_X0(%d) TYO(%d)<=IMG_Y0(%d) \n", + parameters->cp_tx0, parameters->image_offset_x0, parameters->cp_ty0, parameters->image_offset_y0); + return 1; + } + + for (i = 0; i < parameters->numpocs; i++) { + if (parameters->POC[i].prg == -1) { + fprintf(stderr, + "Unrecognized progression order in option -P (POC n %d) [LRCP, RLCP, RPCL, PCRL, CPRL] !!\n", + i + 1); + } + } + + return 0; } /* -------------------------------------------------------------------------- */ @@ -1542,44 +1560,44 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param sample error callback expecting a FILE* client object */ static void error_file_callback(const char *msg, void *client_data) { - FILE *stream = (FILE*)client_data; - fprintf(stream, "[ERROR] %s", msg); + FILE *stream = (FILE*)client_data; + fprintf(stream, "[ERROR] %s", msg); } /** sample warning callback expecting a FILE* client object */ static void warning_file_callback(const char *msg, void *client_data) { - FILE *stream = (FILE*)client_data; - fprintf(stream, "[WARNING] %s", msg); + FILE *stream = (FILE*)client_data; + fprintf(stream, "[WARNING] %s", msg); } /** sample debug callback expecting a FILE* client object */ static void info_file_callback(const char *msg, void *client_data) { - FILE *stream = (FILE*)client_data; - fprintf(stream, "[INFO] %s", msg); + FILE *stream = (FILE*)client_data; + fprintf(stream, "[INFO] %s", msg); } /** sample error debug callback expecting no client object */ static void error_callback(const char *msg, void *client_data) { - (void)client_data; - fprintf(stdout, "[ERROR] %s", msg); + (void)client_data; + fprintf(stdout, "[ERROR] %s", msg); } /** sample warning debug callback expecting no client object */ static void warning_callback(const char *msg, void *client_data) { - (void)client_data; - fprintf(stdout, "[WARNING] %s", msg); + (void)client_data; + fprintf(stdout, "[WARNING] %s", msg); } /** sample debug callback expecting no client object */ static void info_callback(const char *msg, void *client_data) { - (void)client_data; - fprintf(stdout, "[INFO] %s", msg); + (void)client_data; + fprintf(stdout, "[INFO] %s", msg); } /* -------------------------------------------------------------------------- */ @@ -1589,303 +1607,303 @@ static void info_callback(const char *msg, void *client_data) { /* -------------------------------------------------------------------------- */ int main(int argc, char **argv) { - opj_cparameters_t parameters; /* compression parameters */ + opj_cparameters_t parameters; /* compression parameters */ - opj_stream_t *l_stream = 00; - opj_codec_t* l_codec = 00; - opj_image_t *image = NULL; - raw_cparameters_t raw_cp; + opj_stream_t *l_stream = 00; + opj_codec_t* l_codec = 00; + opj_image_t *image = NULL; + raw_cparameters_t raw_cp; - char indexfilename[OPJ_PATH_LEN]; /* index file name */ + char indexfilename[OPJ_PATH_LEN]; /* index file name */ - unsigned int i, num_images, imageno; - img_fol_t img_fol; - dircnt_t *dirptr = NULL; + unsigned int i, num_images, imageno; + img_fol_t img_fol; + dircnt_t *dirptr = NULL; - OPJ_BOOL bSuccess; - OPJ_BOOL bUseTiles = OPJ_FALSE; /* OPJ_TRUE */ - OPJ_UINT32 l_nb_tiles = 4; + OPJ_BOOL bSuccess; + OPJ_BOOL bUseTiles = OPJ_FALSE; /* OPJ_TRUE */ + OPJ_UINT32 l_nb_tiles = 4; - /* set encoding parameters to default values */ - opj_set_default_encoder_parameters(¶meters); + /* set encoding parameters to default values */ + opj_set_default_encoder_parameters(¶meters); - /* Initialize indexfilename and img_fol */ - *indexfilename = 0; - memset(&img_fol,0,sizeof(img_fol_t)); + /* Initialize indexfilename and img_fol */ + *indexfilename = 0; + memset(&img_fol,0,sizeof(img_fol_t)); - /* parse input and get user encoding parameters */ - if(parse_cmdline_encoder(argc, argv, ¶meters,&img_fol, &raw_cp, indexfilename) == 1) { - return 1; - } + /* parse input and get user encoding parameters */ + if(parse_cmdline_encoder(argc, argv, ¶meters,&img_fol, &raw_cp, indexfilename) == 1) { + return 1; + } - if (parameters.cp_cinema){ - img_fol.rates = (float*)malloc(parameters.tcp_numlayers * sizeof(float)); - for(i=0; i< parameters.tcp_numlayers; i++){ - img_fol.rates[i] = parameters.tcp_rates[i]; - } - cinema_parameters(¶meters); - } + if (parameters.cp_cinema){ + img_fol.rates = (float*)malloc(parameters.tcp_numlayers * sizeof(float)); + for(i=0; i< parameters.tcp_numlayers; i++){ + img_fol.rates[i] = parameters.tcp_rates[i]; + } + set_cinema_parameters(¶meters); + } - /* Create comment for codestream */ - if(parameters.cp_comment == NULL) { - const char comment[] = "Created by OpenJPEG version "; - const size_t clen = strlen(comment); - const char *version = opj_version(); -/* UniPG>> */ + /* Create comment for codestream */ + if(parameters.cp_comment == NULL) { + const char comment[] = "Created by OpenJPEG version "; + const size_t clen = strlen(comment); + const char *version = opj_version(); + /* UniPG>> */ #ifdef USE_JPWL - parameters.cp_comment = (char*)malloc(clen+strlen(version)+11); - sprintf(parameters.cp_comment,"%s%s with JPWL", comment, version); + parameters.cp_comment = (char*)malloc(clen+strlen(version)+11); + sprintf(parameters.cp_comment,"%s%s with JPWL", comment, version); #else - parameters.cp_comment = (char*)malloc(clen+strlen(version)+1); - sprintf(parameters.cp_comment,"%s%s", comment, version); + parameters.cp_comment = (char*)malloc(clen+strlen(version)+1); + sprintf(parameters.cp_comment,"%s%s", comment, version); #endif -/* <filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/ - dirptr->filename = (char**) malloc(num_images*sizeof(char*)); - if(!dirptr->filename_buf){ - return 0; - } - for(i=0;ifilename[i] = dirptr->filename_buf + i*OPJ_PATH_LEN; - } - } - if(load_images(dirptr,img_fol.imgdirpath)==1){ - return 0; - } - if (num_images==0){ - fprintf(stdout,"Folder is empty\n"); - return 0; - } - }else{ - num_images=1; - } - /*Encoding image one by one*/ - for(imageno=0;imagenofilename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/ + dirptr->filename = (char**) malloc(num_images*sizeof(char*)); + if(!dirptr->filename_buf){ + return 0; + } + for(i=0;ifilename[i] = dirptr->filename_buf + i*OPJ_PATH_LEN; + } + } + if(load_images(dirptr,img_fol.imgdirpath)==1){ + return 0; + } + if (num_images==0){ + fprintf(stdout,"Folder is empty\n"); + return 0; + } + }else{ + num_images=1; + } + /*Encoding image one by one*/ + for(imageno=0;imagenonumcomps == 3 ? 1 : 0; - - if(parameters.cp_cinema){ - cinema_setup_encoder(¶meters,image,&img_fol); - } - - /* encode the destination image */ - /* ---------------------------- */ - - switch(parameters.cod_format) { - case J2K_CFMT: /* JPEG-2000 codestream */ - { - /* Get a decoder handle */ - l_codec = opj_create_compress(OPJ_CODEC_J2K); - break; - } - case JP2_CFMT: /* JPEG 2000 compressed image data */ - { - /* Get a decoder handle */ - l_codec = opj_create_compress(OPJ_CODEC_JP2); - break; - } - default: - fprintf(stderr, "skipping file..\n"); - opj_stream_destroy_v3(l_stream); - continue; - } - - /* catch events using our callbacks and give a local context */ - opj_set_info_handler(l_codec, info_callback,00); - opj_set_warning_handler(l_codec, warning_callback,00); - opj_set_error_handler(l_codec, error_callback,00); - - if( bUseTiles ) { - parameters.cp_tx0 = 0; - parameters.cp_ty0 = 0; - parameters.tile_size_on = OPJ_TRUE; - parameters.cp_tdx = 512; - parameters.cp_tdy = 512; - } - opj_setup_encoder(l_codec, ¶meters, image); - - /* open a byte stream for writing and allocate memory for all tiles */ - l_stream = opj_stream_create_default_file_stream_v3(parameters.outfile,OPJ_FALSE); - if (! l_stream){ - return 1; - } - - /* encode the image */ - bSuccess = opj_start_compress(l_codec,image,l_stream); - if (!bSuccess) { - fprintf(stderr, "failed to encode image: opj_start_compress\n"); - } - if( bUseTiles ) { - OPJ_BYTE *l_data; - OPJ_UINT32 l_data_size = 512*512*3; - l_data = (OPJ_BYTE*) malloc( l_data_size * sizeof(OPJ_BYTE)); - memset(l_data, 0, l_data_size ); - assert( l_data ); - for (i=0;i test_tile_encoder: failed to write the tile %d!\n",i); - opj_stream_destroy_v3(l_stream); - opj_destroy_codec(l_codec); - opj_image_destroy(image); - return 1; + if( !image) { + fprintf(stderr, "Unable to load file: got no image\n"); + return 1; } - } - free(l_data); + + /* Decide if MCT should be used */ + parameters.tcp_mct = image->numcomps == 3 ? 1 : 0; + + if(parameters.cp_cinema){ + setup_cinema_encoder(¶meters,image,&img_fol); + } + + /* encode the destination image */ + /* ---------------------------- */ + + switch(parameters.cod_format) { + case J2K_CFMT: /* JPEG-2000 codestream */ + { + /* Get a decoder handle */ + l_codec = opj_create_compress(OPJ_CODEC_J2K); + break; + } + case JP2_CFMT: /* JPEG 2000 compressed image data */ + { + /* Get a decoder handle */ + l_codec = opj_create_compress(OPJ_CODEC_JP2); + break; + } + default: + fprintf(stderr, "skipping file..\n"); + opj_stream_destroy_v3(l_stream); + continue; + } + + /* catch events using our callbacks and give a local context */ + opj_set_info_handler(l_codec, info_callback,00); + opj_set_warning_handler(l_codec, warning_callback,00); + opj_set_error_handler(l_codec, error_callback,00); + + if( bUseTiles ) { + parameters.cp_tx0 = 0; + parameters.cp_ty0 = 0; + parameters.tile_size_on = OPJ_TRUE; + parameters.cp_tdx = 512; + parameters.cp_tdy = 512; + } + opj_setup_encoder(l_codec, ¶meters, image); + + /* open a byte stream for writing and allocate memory for all tiles */ + l_stream = opj_stream_create_default_file_stream_v3(parameters.outfile,OPJ_FALSE); + if (! l_stream){ + return 1; + } + + /* encode the image */ + bSuccess = opj_start_compress(l_codec,image,l_stream); + if (!bSuccess) { + fprintf(stderr, "failed to encode image: opj_start_compress\n"); + } + if( bUseTiles ) { + OPJ_BYTE *l_data; + OPJ_UINT32 l_data_size = 512*512*3; + l_data = (OPJ_BYTE*) malloc( l_data_size * sizeof(OPJ_BYTE)); + memset(l_data, 0, l_data_size ); + assert( l_data ); + for (i=0;i test_tile_encoder: failed to write the tile %d!\n",i); + opj_stream_destroy_v3(l_stream); + opj_destroy_codec(l_codec); + opj_image_destroy(image); + return 1; + } + } + free(l_data); + } + else { + bSuccess = bSuccess && opj_encode(l_codec, l_stream); + if (!bSuccess) { + fprintf(stderr, "failed to encode image: opj_encode\n"); + } + } + bSuccess = bSuccess && opj_end_compress(l_codec, l_stream); + if (!bSuccess) { + fprintf(stderr, "failed to encode image: opj_end_compress\n"); + } + + if (!bSuccess) { + opj_stream_destroy_v3(l_stream); + opj_destroy_codec(l_codec); + opj_image_destroy(image); + fprintf(stderr, "failed to encode image\n"); + return 1; + } + + fprintf(stderr,"Generated outfile %s\n",parameters.outfile); + /* close and free the byte stream */ + opj_stream_destroy_v3(l_stream); + + /* free remaining compression structures */ + opj_destroy_codec(l_codec); + + /* free image data */ + opj_image_destroy(image); + } - else { - bSuccess = bSuccess && opj_encode(l_codec, l_stream); - if (!bSuccess) { - fprintf(stderr, "failed to encode image: opj_encode\n"); - } - } - bSuccess = bSuccess && opj_end_compress(l_codec, l_stream); - if (!bSuccess) { - fprintf(stderr, "failed to encode image: opj_end_compress\n"); - } - if (!bSuccess) { - opj_stream_destroy_v3(l_stream); - opj_destroy_codec(l_codec); - opj_image_destroy(image); - fprintf(stderr, "failed to encode image\n"); - return 1; - } - - fprintf(stderr,"Generated outfile %s\n",parameters.outfile); - /* close and free the byte stream */ - opj_stream_destroy_v3(l_stream); - - /* free remaining compression structures */ - opj_destroy_codec(l_codec); - - /* free image data */ - opj_image_destroy(image); - - } - - /* free user parameters structure */ - if(parameters.cp_comment) free(parameters.cp_comment); - if(parameters.cp_matrice) free(parameters.cp_matrice); + /* free user parameters structure */ + if(parameters.cp_comment) free(parameters.cp_comment); + if(parameters.cp_matrice) free(parameters.cp_matrice); if(parameters.cp_cinema) free(img_fol.rates); - return 0; + return 0; } From ee3f2ffa19851e5717a14c2517f9599b25080542 Mon Sep 17 00:00:00 2001 From: Antonin Descampe Date: Wed, 22 Jan 2014 18:41:34 +0000 Subject: [PATCH 065/333] [trunk] fixed several bugs in cinema mode (2K 24/48 fps, and 4K). Trunk now produces compliant DCI code-streams. --- src/bin/jp2/opj_compress.c | 244 +++++++++++++++++++---------- src/lib/openjp2/j2k.c | 81 ++++++---- tests/nonregression/CMakeLists.txt | 2 +- 3 files changed, 215 insertions(+), 112 deletions(-) diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index e62a0fad..1934bf76 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -82,8 +82,6 @@ typedef struct img_folder{ char set_imgdir; /** Enable Cod Format for output*/ char set_out_format; - /** User specified rate stored in case of cinema option*/ - float *rates; }img_fol_t; static void encode_help_display(void) { @@ -197,7 +195,7 @@ static void encode_help_display(void) { fprintf(stdout," Indicate multiple modes by adding their values. \n"); fprintf(stdout," ex: RESTART(4) + RESET(2) + SEGMARK(32) = -M 38\n"); fprintf(stdout,"\n"); - fprintf(stdout,"-TP : devide packets of every tile into tile-parts (-TP R) [R, L, C]\n"); + fprintf(stdout,"-TP : divide packets of every tile into tile-parts (-TP R) [R, L, C]\n"); fprintf(stdout,"\n"); fprintf(stdout,"-x : create an index file *.Idx (-x index_name.Idx) \n"); fprintf(stdout,"\n"); @@ -464,7 +462,23 @@ static int initialise_4K_poc(opj_poc_t *POC, int numres){ return 2; } -static void set_cinema_parameters(opj_cparameters_t *parameters){ +static void set_cinema_parameters(opj_cparameters_t *parameters) +{ + /* Configure cinema parameters */ + float max_rate = 0; + float temp_rate = 0; + int i; + + /* profile (Rsiz) */ + switch (parameters->cp_cinema){ + case OPJ_CINEMA2K_24: + case OPJ_CINEMA2K_48: + parameters->cp_rsiz = OPJ_CINEMA2K; + break; + case OPJ_CINEMA4K_24: + parameters->cp_rsiz = OPJ_CINEMA4K; + break; + } /* No tiling */ parameters->tile_size_on = OPJ_FALSE; @@ -485,11 +499,8 @@ static void set_cinema_parameters(opj_cparameters_t *parameters){ parameters->cblockw_init = 32; parameters->cblockh_init = 32; - /* Use of precincts */ - parameters->csty |= 0x01; - - /* The progression order shall be CPRL */ - parameters->prog_order = OPJ_CPRL; + /* Codeblock style: no mode switch enabled */ + parameters->mode = 0; /* No ROI */ parameters->roi_compno = -1; @@ -501,93 +512,113 @@ static void set_cinema_parameters(opj_cparameters_t *parameters){ /* 9-7 transform */ parameters->irreversible = 1; -} + /* Number of layers */ + if (parameters->tcp_numlayers > 1){ + fprintf(stdout,"JPEG 2000 Profile-3 and 4 (2k/4k dc profile) requires:\n" + "1 single quality layer" + "-> Number of layers forced to 1 (rather than %d)\n", + parameters->tcp_numlayers); + parameters->tcp_numlayers = 1; + } -static void setup_cinema_encoder(opj_cparameters_t *parameters,opj_image_t *image, img_fol_t *img_fol){ - int i; - float temp_rate; - - /* Size and resolution levels */ + /* Resolution levels */ switch (parameters->cp_cinema){ case OPJ_CINEMA2K_24: case OPJ_CINEMA2K_48: if(parameters->numresolution > 6){ fprintf(stdout,"JPEG 2000 Profile-3 (2k dc profile) requires:\n" "Number of decomposition levels <= 5\n" - "-> Number of decomposition levels forced to 5"); + "-> Number of decomposition levels forced to 5 (rather than %d)\n", + parameters->numresolution+1); parameters->numresolution = 6; } - if (!((image->comps[0].w == 2048) | (image->comps[0].h == 1080))){ - fprintf(stdout,"Image coordinates %d x %d is not 2K compliant.\n" - "JPEG 2000 Profile-3 (2k dc profile) requires:\n" - "at least one of coordinates match 2048 x 1080\n", - image->comps[0].w,image->comps[0].h); - parameters->cp_rsiz = OPJ_STD_RSIZ; - } break; case OPJ_CINEMA4K_24: - if(parameters->numresolution < 1){ + if(parameters->numresolution < 2){ fprintf(stdout,"JPEG 2000 Profile-4 (4k dc profile) requires:\n" "Number of decomposition levels >= 1 && <= 6\n" - "-> Number of decomposition levels forced to 1"); + "-> Number of decomposition levels forced to 1 (rather than %d)\n", + parameters->numresolution+1); parameters->numresolution = 1; }else if(parameters->numresolution > 7){ fprintf(stdout,"JPEG 2000 Profile-4 (4k dc profile) requires:\n" "Number of decomposition levels >= 1 && <= 6\n" - "-> Number of decomposition levels forced to 6"); + "-> Number of decomposition levels forced to 6 (rather than %d)\n", + parameters->numresolution+1); parameters->numresolution = 7; } - if (!((image->comps[0].w == 4096) | (image->comps[0].h == 2160))){ - fprintf(stdout,"Image coordinates %d x %d is not 2K compliant.\n" - "JPEG 2000 Profile-4 (4k dc profile) requires:\n" - "at least one of coordinates match 4096 x 2160\n", - image->comps[0].w,image->comps[0].h); - parameters->cp_rsiz = OPJ_STD_RSIZ; - } - parameters->numpocs = initialise_4K_poc(parameters->POC,parameters->numresolution); break; default : break; } + /* Precincts */ + parameters->csty |= 0x01; + parameters->res_spec = parameters->numresolution-1; + for (i = 0; ires_spec; i++) { + parameters->prcw_init[i] = 256; + parameters->prch_init[i] = 256; + } + + /* The progression order shall be CPRL */ + parameters->prog_order = OPJ_CPRL; + + /* Progression order changes for 4K, disallowed for 2K */ + if (parameters->cp_cinema == OPJ_CINEMA4K_24) { + parameters->numpocs = initialise_4K_poc(parameters->POC,parameters->numresolution); + } else { + parameters->numpocs = 0; + } +} + +static void set_cinema_rate(opj_cparameters_t *parameters, opj_image_t *image) +{ /* Limited bit-rate */ + float max_rate = 0; + float temp_rate = 0; + parameters->cp_disto_alloc = 1; switch (parameters->cp_cinema){ case OPJ_CINEMA2K_24: case OPJ_CINEMA4K_24: - for(i=0 ; itcp_numlayers ; i++){ - temp_rate = 0 ; - if (img_fol->rates[i]== 0){ - parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy); + max_rate = ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ + (CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy); + if (parameters->tcp_rates[0] == 0){ + parameters->tcp_rates[0] = max_rate; + }else{ + temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ + (parameters->tcp_rates[0] * 8 * image->comps[0].dx * image->comps[0].dy); + if (temp_rate > CINEMA_24_CS ){ + fprintf(stdout,"JPEG 2000 Profile-3 and 4 (2k/4k dc profile) requires:\n" + "Maximum 1302083 compressed bytes @ 24fps\n" + "-> Specified rate (%3.1f) exceeds this limit. Rate will be forced to %3.1f.\n", + parameters->tcp_rates[0], max_rate); + parameters->tcp_rates[0]= max_rate; }else{ - temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (img_fol->rates[i] * 8 * image->comps[0].dx * image->comps[0].dy); - if (temp_rate > CINEMA_24_CS ){ - parameters->tcp_rates[i]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy); - }else{ - parameters->tcp_rates[i]= img_fol->rates[i]; - } + fprintf(stdout,"JPEG 2000 Profile-3 and 4 (2k/4k dc profile):\n" + "INFO : Specified rate (%3.1f) is below the 2k/4k limit @ 24fps.\n", + parameters->tcp_rates[0]); } } parameters->max_comp_size = COMP_24_CS; break; - case OPJ_CINEMA2K_48: - for(i=0 ; itcp_numlayers ; i++){ - temp_rate = 0 ; - if (img_fol->rates[i]== 0){ - parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy); + max_rate = ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ + (CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy); + if (parameters->tcp_rates[0] == 0){ + parameters->tcp_rates[0] = max_rate; + }else{ + temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ + (parameters->tcp_rates[0] * 8 * image->comps[0].dx * image->comps[0].dy); + if (temp_rate > CINEMA_48_CS ){ + fprintf(stdout,"JPEG 2000 Profile-3 (2k dc profile) requires:\n" + "Maximum 651041 compressed bytes @ 48fps\n" + "-> Specified rate (%3.1f) exceeds this limit. Rate will be forced to %3.1f.\n", + parameters->tcp_rates[0], max_rate); + parameters->tcp_rates[0]= max_rate; }else{ - temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (img_fol->rates[i] * 8 * image->comps[0].dx * image->comps[0].dy); - if (temp_rate > CINEMA_48_CS ){ - parameters->tcp_rates[0]= ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy); - }else{ - parameters->tcp_rates[i]= img_fol->rates[i]; - } + fprintf(stdout,"JPEG 2000 Profile-3 (2k dc profile):\n" + "INFO : Specified rate (%3.1f) is below the 2k limit @ 48 fps.\n", + parameters->tcp_rates[0]); } } parameters->max_comp_size = COMP_48_CS; @@ -595,14 +626,73 @@ static void setup_cinema_encoder(opj_cparameters_t *parameters,opj_image_t *imag default: break; } - parameters->cp_disto_alloc = 1; +} + +static OPJ_BOOL is_cinema_compliant(opj_image_t *image, OPJ_CINEMA_MODE cinema_mode) +{ + OPJ_UINT32 i; + + /* Number of components */ + if (image->numcomps != 3){ + fprintf(stdout,"JPEG 2000 Profile-3 (2k dc profile) requires:\n" + "3 components" + "-> Number of components of input image (%d) is not compliant\n" + "-> Non-profile-3 codestream will be generated\n", + image->numcomps); + return OPJ_FALSE; + } + + /* Bitdepth */ + for (i = 0; i < image->numcomps; i++) { + if ((image->comps[i].bpp != 12) | (image->comps[i].sgnd)){ + char signed_str[] = "signed"; + char unsigned_str[] = "unsigned"; + char *tmp_str = image->comps[i].sgnd?signed_str:unsigned_str; + fprintf(stdout,"JPEG 2000 Profile-3 (2k dc profile) requires:\n" + "Precision of each component shall be 12 bits unsigned" + "-> At least component %d of input image (%d bits, %s) is not compliant\n" + "-> Non-profile-3 codestream will be generated\n", + i,image->comps[i].bpp, tmp_str); + return OPJ_FALSE; + } + } + + /* Image size */ + switch (cinema_mode){ + case OPJ_CINEMA2K_24: + case OPJ_CINEMA2K_48: + if (!((image->comps[0].w > 2048) | (image->comps[0].h > 1080))){ + fprintf(stdout,"JPEG 2000 Profile-3 (2k dc profile) requires:\n" + "width <= 2048 and height <= 1080\n" + "-> Input image size %d x %d is not compliant\n" + "-> Non-profile-3 codestream will be generated\n", + image->comps[0].w,image->comps[0].h); + return OPJ_FALSE; + } + break; + case OPJ_CINEMA4K_24: + if (!((image->comps[0].w > 4096) | (image->comps[0].h > 2160))){ + fprintf(stdout,"JPEG 2000 Profile-4 (4k dc profile) requires:\n" + "width <= 4096 and height <= 2160\n" + "-> Image size %d x %d is not compliant\n" + "-> Non-profile-4 codestream will be generated\n", + image->comps[0].w,image->comps[0].h); + return OPJ_FALSE; + } + break; + default : + break; + } + + return OPJ_TRUE; } /* ------------------------------------------------------------------------------------ */ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters, img_fol_t *img_fol, raw_cparameters_t *raw_cp, char *indexfilename) { - int i, j, totlen, c; + OPJ_UINT32 i, j; + int totlen, c; opj_option_t long_option[]={ {"cinema2K",REQ_ARG, NULL ,'w'}, {"cinema4K",NO_ARG, NULL ,'y'}, @@ -775,7 +865,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param case 'f': /* mod fixed_quality (before : -q) */ { int *row = NULL, *col = NULL; - int numlayers = 0, numresolution = 0, matrix_width = 0; + OPJ_UINT32 numlayers = 0, numresolution = 0, matrix_width = 0; char *s = opj_optarg; sscanf(s, "%d", &numlayers); @@ -1063,8 +1153,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param fprintf(stderr,"Incorrect value!! must be 24 or 48\n"); return 1; } - fprintf(stdout,"CINEMA 2K compliant codestream\n"); - parameters->cp_rsiz = OPJ_CINEMA2K; + fprintf(stdout,"CINEMA 2K profile activated\n" + "Other options specified could be overriden\n"); } break; @@ -1074,8 +1164,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param case 'y': /* Digital Cinema 4K profile compliance*/ { parameters->cp_cinema = OPJ_CINEMA4K_24; - fprintf(stdout,"CINEMA 4K compliant codestream\n"); - parameters->cp_rsiz = OPJ_CINEMA4K; + fprintf(stdout,"CINEMA 4K profile activated\n" + "Other options specified could be overriden\n"); } break; @@ -1483,13 +1573,6 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param } }while(c != -1); - /* check for possible errors */ - if (parameters->cp_cinema){ - if(parameters->tcp_numlayers > 1){ - parameters->cp_rsiz = OPJ_STD_RSIZ; - fprintf(stdout,"Warning: DC profiles do not allow more than one quality layer. The codestream created will not be compliant with the DC profile\n"); - } - } if(img_fol->set_imgdir == 1){ if(!(parameters->infile[0] == 0)){ fprintf(stderr, "Error: options -ImgDir and -i cannot be used together !!\n"); @@ -1637,10 +1720,6 @@ int main(int argc, char **argv) { } if (parameters.cp_cinema){ - img_fol.rates = (float*)malloc(parameters.tcp_numlayers * sizeof(float)); - for(i=0; i< parameters.tcp_numlayers; i++){ - img_fol.rates[i] = parameters.tcp_rates[i]; - } set_cinema_parameters(¶meters); } @@ -1802,7 +1881,11 @@ int main(int argc, char **argv) { parameters.tcp_mct = image->numcomps == 3 ? 1 : 0; if(parameters.cp_cinema){ - setup_cinema_encoder(¶meters,image,&img_fol); + if (!is_cinema_compliant(image,parameters.cp_cinema)) { + parameters.cp_rsiz = OPJ_STD_RSIZ; + } + /* This cannot be in set_cinema_parameters because we need size and precision of the input image */ + set_cinema_rate(¶meters,image); } /* encode the destination image */ @@ -1903,7 +1986,6 @@ int main(int argc, char **argv) { /* free user parameters structure */ if(parameters.cp_comment) free(parameters.cp_comment); if(parameters.cp_matrice) free(parameters.cp_matrice); - if(parameters.cp_cinema) free(img_fol.rates); return 0; } diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 6f62ee2e..2740b9d5 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -1040,13 +1040,24 @@ static OPJ_BOOL opj_j2k_read_cbd ( opj_j2k_t *p_j2k, opj_event_mgr_t * p_manager); /** - * Writes the image components. + * Writes COC marker for each component. * * @param p_stream the stream to write data to. * @param p_j2k J2K codec. * @param p_manager the user event manager. */ -static OPJ_BOOL opj_j2k_write_image_components( opj_j2k_t *p_j2k, +static OPJ_BOOL opj_j2k_write_all_coc( opj_j2k_t *p_j2k, + opj_stream_private_t *p_stream, + opj_event_mgr_t * p_manager ); + +/** + * Writes QCC marker for each component. + * + * @param p_stream the stream to write data to. + * @param p_j2k J2K codec. + * @param p_manager the user event manager. +*/ +static OPJ_BOOL opj_j2k_write_all_qcc( opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, opj_event_mgr_t * p_manager ); @@ -4728,7 +4739,7 @@ OPJ_BOOL opj_j2k_write_mct_data_group( opj_j2k_t *p_j2k, return OPJ_TRUE; } -OPJ_BOOL opj_j2k_write_image_components(opj_j2k_t *p_j2k, +OPJ_BOOL opj_j2k_write_all_coc(opj_j2k_t *p_j2k, struct opj_stream_private *p_stream, struct opj_event_mgr * p_manager ) { @@ -4739,12 +4750,29 @@ OPJ_BOOL opj_j2k_write_image_components(opj_j2k_t *p_j2k, assert(p_manager != 00); assert(p_stream != 00); - for (compno = 1; compno < p_j2k->m_private_image->numcomps; ++compno) + for (compno = 0; compno < p_j2k->m_private_image->numcomps; ++compno) { if (! opj_j2k_write_coc(p_j2k,compno,p_stream, p_manager)) { return OPJ_FALSE; } + } + return OPJ_TRUE; +} + +OPJ_BOOL opj_j2k_write_all_qcc(opj_j2k_t *p_j2k, + struct opj_stream_private *p_stream, + struct opj_event_mgr * p_manager ) +{ + OPJ_UINT32 compno; + + /* preconditions */ + assert(p_j2k != 00); + assert(p_manager != 00); + assert(p_stream != 00); + + for (compno = 0; compno < p_j2k->m_private_image->numcomps; ++compno) + { if (! opj_j2k_write_qcc(p_j2k,compno,p_stream, p_manager)) { return OPJ_FALSE; } @@ -4753,6 +4781,7 @@ OPJ_BOOL opj_j2k_write_image_components(opj_j2k_t *p_j2k, return OPJ_TRUE; } + OPJ_BOOL opj_j2k_write_regions( opj_j2k_t *p_j2k, struct opj_stream_private *p_stream, struct opj_event_mgr * p_manager ) @@ -5780,7 +5809,7 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, cp->m_specific_param.m_enc.m_fixed_quality = parameters->cp_fixed_quality; /* mod fixed_quality */ - if (parameters->cp_matrice) { + if (parameters->cp_fixed_alloc && parameters->cp_matrice) { size_t array_size = parameters->tcp_numlayers * parameters->numresolution * 3 * sizeof(OPJ_INT32); cp->m_specific_param.m_enc.m_matrice = (OPJ_INT32 *) opj_malloc(array_size); memcpy(cp->m_specific_param.m_enc.m_matrice, parameters->cp_matrice, array_size); @@ -5992,16 +6021,6 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, tccp->roishift = 0; } - if(parameters->cp_cinema) { - /*Precinct size for lowest frequency subband=128*/ - tccp->prcw[0] = 7; - tccp->prch[0] = 7; - /*Precinct size at all other resolutions = 256*/ - for (j = 1; j < tccp->numresolutions; j++) { - tccp->prcw[j] = 8; - tccp->prch[j] = 8; - } - }else{ if (parameters->csty & J2K_CCP_CSTY_PRT) { OPJ_INT32 p = 0, it_res; for (it_res = tccp->numresolutions - 1; it_res >= 0; it_res--) { @@ -6050,7 +6069,6 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, tccp->prch[j] = 15; } } - } opj_dwt_calc_explicit_stepsizes(tccp, image->comps[i].prec); } @@ -9407,7 +9425,10 @@ void opj_j2k_setup_header_writing (opj_j2k_t *p_j2k) opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)opj_j2k_write_qcd ); if (p_j2k->m_cp.m_specific_param.m_enc.m_cinema) { - opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)opj_j2k_write_image_components ); + /* No need for COC or QCC, QCD and COD are used + opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)opj_j2k_write_all_coc ); + opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)opj_j2k_write_all_qcc ); + */ opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure)opj_j2k_write_tlm ); if (p_j2k->m_cp.m_specific_param.m_enc.m_cinema == OPJ_CINEMA4K_24) { @@ -9442,7 +9463,7 @@ OPJ_BOOL opj_j2k_write_first_tile_part (opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, struct opj_event_mgr * p_manager ) { - OPJ_UINT32 compno; +// OPJ_UINT32 compno; OPJ_UINT32 l_nb_bytes_written = 0; OPJ_UINT32 l_current_nb_bytes_written; OPJ_BYTE * l_begin_data = 00; @@ -9473,19 +9494,19 @@ OPJ_BOOL opj_j2k_write_first_tile_part (opj_j2k_t *p_j2k, p_total_data_size -= l_current_nb_bytes_written; if (l_cp->m_specific_param.m_enc.m_cinema == 0) { - for (compno = 1; compno < p_j2k->m_private_image->numcomps; compno++) { - l_current_nb_bytes_written = 0; - opj_j2k_write_coc_in_memory(p_j2k,compno,p_data,&l_current_nb_bytes_written,p_manager); - l_nb_bytes_written += l_current_nb_bytes_written; - p_data += l_current_nb_bytes_written; - p_total_data_size -= l_current_nb_bytes_written; +// for (compno = 1; compno < p_j2k->m_private_image->numcomps; compno++) { +// l_current_nb_bytes_written = 0; +// opj_j2k_write_coc_in_memory(p_j2k,compno,p_data,&l_current_nb_bytes_written,p_manager); +// l_nb_bytes_written += l_current_nb_bytes_written; +// p_data += l_current_nb_bytes_written; +// p_total_data_size -= l_current_nb_bytes_written; - l_current_nb_bytes_written = 0; - opj_j2k_write_qcc_in_memory(p_j2k,compno,p_data,&l_current_nb_bytes_written,p_manager); - l_nb_bytes_written += l_current_nb_bytes_written; - p_data += l_current_nb_bytes_written; - p_total_data_size -= l_current_nb_bytes_written; - } +// l_current_nb_bytes_written = 0; +// opj_j2k_write_qcc_in_memory(p_j2k,compno,p_data,&l_current_nb_bytes_written,p_manager); +// l_nb_bytes_written += l_current_nb_bytes_written; +// p_data += l_current_nb_bytes_written; +// p_total_data_size -= l_current_nb_bytes_written; +// } if (l_cp->tcps[p_j2k->m_current_tile_number].numpocs) { l_current_nb_bytes_written = 0; diff --git a/tests/nonregression/CMakeLists.txt b/tests/nonregression/CMakeLists.txt index d03eb6aa..b4a7a8d1 100644 --- a/tests/nonregression/CMakeLists.txt +++ b/tests/nonregression/CMakeLists.txt @@ -33,7 +33,7 @@ set(BLACKLIST_JPEG2000 file(GLOB_RECURSE OPJ_DATA_NR_LIST "${INPUT_NR}/*.j2k" "${INPUT_NR}/*.j2c" - "${INPUT_NR}/*.jp2" + #"${INPUT_NR}/*.jp2" #"${INPUT_NR}/*.jpx" ) From 58698b789a641cbbe5c310ce529f262021e72006 Mon Sep 17 00:00:00 2001 From: Antonin Descampe Date: Wed, 22 Jan 2014 18:44:11 +0000 Subject: [PATCH 066/333] [trunk] uncomment tests mistakenly commented in previous commit --- tests/nonregression/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/nonregression/CMakeLists.txt b/tests/nonregression/CMakeLists.txt index b4a7a8d1..d03eb6aa 100644 --- a/tests/nonregression/CMakeLists.txt +++ b/tests/nonregression/CMakeLists.txt @@ -33,7 +33,7 @@ set(BLACKLIST_JPEG2000 file(GLOB_RECURSE OPJ_DATA_NR_LIST "${INPUT_NR}/*.j2k" "${INPUT_NR}/*.j2c" - #"${INPUT_NR}/*.jp2" + "${INPUT_NR}/*.jp2" #"${INPUT_NR}/*.jpx" ) From d143f49a662daf26f1259aaef8d944873c920d89 Mon Sep 17 00:00:00 2001 From: Antonin Descampe Date: Thu, 23 Jan 2014 09:39:02 +0000 Subject: [PATCH 067/333] [trunk] fixed another DCI compliance bug --- src/bin/jp2/opj_compress.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index 1934bf76..ae41b575 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -661,7 +661,7 @@ static OPJ_BOOL is_cinema_compliant(opj_image_t *image, OPJ_CINEMA_MODE cinema_m switch (cinema_mode){ case OPJ_CINEMA2K_24: case OPJ_CINEMA2K_48: - if (!((image->comps[0].w > 2048) | (image->comps[0].h > 1080))){ + if (((image->comps[0].w > 2048) | (image->comps[0].h > 1080))){ fprintf(stdout,"JPEG 2000 Profile-3 (2k dc profile) requires:\n" "width <= 2048 and height <= 1080\n" "-> Input image size %d x %d is not compliant\n" @@ -671,7 +671,7 @@ static OPJ_BOOL is_cinema_compliant(opj_image_t *image, OPJ_CINEMA_MODE cinema_m } break; case OPJ_CINEMA4K_24: - if (!((image->comps[0].w > 4096) | (image->comps[0].h > 2160))){ + if (((image->comps[0].w > 4096) | (image->comps[0].h > 2160))){ fprintf(stdout,"JPEG 2000 Profile-4 (4k dc profile) requires:\n" "width <= 4096 and height <= 2160\n" "-> Image size %d x %d is not compliant\n" From ff1a30d80a8b9817f00656173a2a883bb47ffaee Mon Sep 17 00:00:00 2001 From: Antonin Descampe Date: Thu, 23 Jan 2014 16:33:13 +0000 Subject: [PATCH 068/333] [trunk] added some tests for Cinema2k 48fps and Cinema 4k 24 fps. Fixed a bug in comparePGXimages.c leading to huge Test.xml file uploaded to DashBoard --- tests/comparePGXimages.c | 5 ++++- tests/nonregression/test_suite.ctest.in | 10 +++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/comparePGXimages.c b/tests/comparePGXimages.c index 29300d51..425a66d9 100644 --- a/tests/comparePGXimages.c +++ b/tests/comparePGXimages.c @@ -86,7 +86,7 @@ void comparePGXimages_help_display(void) { fprintf(stdout," -s \t OPTIONAL \t 1 or 2 filename separator to take into account PGX image with different components, " "please indicate b or t before separator to indicate respectively the separator " "for ref/base file and for test file. \n"); - fprintf(stdout," -r \t OPTIONAL \t indicate if you want to run this function as conformance test or as non regression test\n"); + fprintf(stdout," -d \t OPTIONAL \t indicate if you want to run this function as conformance test or as non regression test\n"); fprintf(stdout,"\n"); } @@ -766,6 +766,7 @@ int main(int argc, char **argv) strcat(filenamePNGdiff_it_comp, it_compc); /*printf("filenamePNGdiff_it = %s [%d / %d octets]\n",filenamePNGdiff_it_comp, strlen(filenamePNGdiff_it_comp),memsizedifffilename );*/ + /* if ( imageToPNG(imageBase, filenamePNGbase_it_comp, it_comp) == EXIT_SUCCESS ) { printf(" %s \n", it_comp, filenamePNGbase_it_comp); @@ -780,6 +781,8 @@ int main(int argc, char **argv) { printf(" %s \n", it_comp, filenamePNGdiff_it_comp); } + */ + #endif failed = 1; } diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 86d10576..9a1ccfb2 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -32,9 +32,13 @@ opj_compress -i @INPUT_NR_PATH@/random-issue-0005.tif -o @TEMP_PATH@/random-issu # related to issue 62 opj_compress -i @INPUT_NR_PATH@/tmp-issue-0062.raw -o @TEMP_PATH@/tmp-issue-0062-u.raw.j2k -F 512,512,1,16,u opj_compress -i @INPUT_NR_PATH@/tmp-issue-0062.raw -o @TEMP_PATH@/tmp-issue-0062-s.raw.j2k -F 512,512,1,16,s -opj_compress -i @INPUT_NR_PATH@/X_4_2K_24_185_CBR_WB_000.tif -o @TEMP_PATH@/X_4_2K_24_185_CBR_WB_000.j2k -cinema2K 24 -opj_compress -i @INPUT_NR_PATH@/X_5_2K_24_235_CBR_STEM24_000.tif -o @TEMP_PATH@/X_5_2K_24_235_CBR_STEM24_000.j2k -cinema2K 24 -opj_compress -i @INPUT_NR_PATH@/X_6_2K_24_FULL_CBR_CIRCLE_000.tif -o @TEMP_PATH@/X_6_2K_24_FULL_CBR_CIRCLE_000.j2k -cinema2K 24 +opj_compress -i @INPUT_NR_PATH@/X_4_2K_24_185_CBR_WB_000.tif -o @TEMP_PATH@/X_4_2K_24_185_CBR_WB_000_C2K_24.j2k -cinema2K 24 +opj_compress -i @INPUT_NR_PATH@/X_5_2K_24_235_CBR_STEM24_000.tif -o @TEMP_PATH@/X_5_2K_24_235_CBR_STEM24_000_C2K_24.j2k -cinema2K 24 +opj_compress -i @INPUT_NR_PATH@/X_6_2K_24_FULL_CBR_CIRCLE_000.tif -o @TEMP_PATH@/X_6_2K_24_FULL_CBR_CIRCLE_000_C2K_24.j2k -cinema2K 24 +opj_compress -i @INPUT_NR_PATH@/X_4_2K_24_185_CBR_WB_000.tif -o @TEMP_PATH@/X_4_2K_24_185_CBR_WB_000_C2K_48.j2k -cinema2K 48 +opj_compress -i @INPUT_NR_PATH@/X_5_2K_24_235_CBR_STEM24_000.tif -o @TEMP_PATH@/X_5_2K_24_235_CBR_STEM24_000_C2K_48.j2k -cinema2K 48 +opj_compress -i @INPUT_NR_PATH@/X_6_2K_24_FULL_CBR_CIRCLE_000.tif -o @TEMP_PATH@/X_6_2K_24_FULL_CBR_CIRCLE_000_C2K_48.j2k -cinema2K 48 +opj_compress -i @INPUT_NR_PATH@/ElephantDream_4K.tif -o @TEMP_PATH@/ElephantDream_4K_C4K.j2k -cinema4K # DECODER TEST SUITE opj_decompress -i @INPUT_NR_PATH@/Bretagne2.j2k -o @TEMP_PATH@/Bretagne2.j2k.pgx From caf4e46e069fea1bfd274cb579dc5b9c31bf5ba0 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Feb 2014 10:37:06 +0000 Subject: [PATCH 069/333] Update kakadu cmake module --- cmake/FindKAKADU.cmake | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/cmake/FindKAKADU.cmake b/cmake/FindKAKADU.cmake index 3e0409df..0564a0e6 100644 --- a/cmake/FindKAKADU.cmake +++ b/cmake/FindKAKADU.cmake @@ -1,9 +1,9 @@ # -# this module looks for KAKADu +# this module looks for KAKADU # http://www.kakadusoftware.com/ # # -# Copyright (c) 2006-2011 Mathieu Malaterre +# Copyright (c) 2006-2014 Mathieu Malaterre # # Redistribution and use is allowed according to the terms of the New # BSD license. @@ -14,6 +14,11 @@ find_program(KDU_EXPAND_EXECUTABLE kdu_expand ) +find_program(KDU_COMPRESS_EXECUTABLE + kdu_compress + ) + mark_as_advanced( KDU_EXPAND_EXECUTABLE + KDU_COMPRESS_EXECUTABLE ) From c81fb397bb1517c7d06fd894ea8d14aed86da1e4 Mon Sep 17 00:00:00 2001 From: Antonin Descampe Date: Wed, 12 Feb 2014 14:56:49 +0000 Subject: [PATCH 070/333] [trunk]re-indenting convert.c --- src/bin/jp2/convert.c | 5586 ++++++++++++++++++++--------------------- 1 file changed, 2793 insertions(+), 2793 deletions(-) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index 1b6e688b..4144a395 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -54,11 +54,11 @@ * log2(a) */ static int int_floorlog2(int a) { - int l; - for (l = 0; a > 1; l++) { - a >>= 1; - } - return l; + int l; + for (l = 0; a > 1; l++) { + a >>= 1; + } + return l; } /* -->> -->> -->> -->> @@ -95,7 +95,7 @@ struct tga_header static unsigned short get_ushort(unsigned short val) { #ifdef WORDS_BIGENDIAN - return( ((val & 0xff) << 8) + (val >> 8) ); + return( ((val & 0xff) << 8) + (val >> 8) ); #else return( val ); #endif @@ -105,399 +105,399 @@ static unsigned short get_ushort(unsigned short val) { #define TGA_HEADER_SIZE 18 static int tga_readheader(FILE *fp, unsigned int *bits_per_pixel, - unsigned int *width, unsigned int *height, int *flip_image) + unsigned int *width, unsigned int *height, int *flip_image) { - int palette_size; - unsigned char *tga ; - unsigned char id_len, cmap_type, image_type; - unsigned char pixel_depth, image_desc; - unsigned short cmap_index, cmap_len, cmap_entry_size; - unsigned short x_origin, y_origin, image_w, image_h; + int palette_size; + unsigned char *tga ; + unsigned char id_len, cmap_type, image_type; + unsigned char pixel_depth, image_desc; + unsigned short cmap_index, cmap_len, cmap_entry_size; + unsigned short x_origin, y_origin, image_w, image_h; - if (!bits_per_pixel || !width || !height || !flip_image) - return 0; - tga = (unsigned char*)malloc(18); + if (!bits_per_pixel || !width || !height || !flip_image) + return 0; + tga = (unsigned char*)malloc(18); - if ( fread(tga, TGA_HEADER_SIZE, 1, fp) != 1 ) - { - fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); - return 0 ; - } - id_len = (unsigned char)tga[0]; - cmap_type = (unsigned char)tga[1]; - image_type = (unsigned char)tga[2]; - cmap_index = get_ushort(*(unsigned short*)(&tga[3])); - cmap_len = get_ushort(*(unsigned short*)(&tga[5])); - cmap_entry_size = (unsigned char)tga[7]; + if ( fread(tga, TGA_HEADER_SIZE, 1, fp) != 1 ) + { + fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); + return 0 ; + } + id_len = (unsigned char)tga[0]; + cmap_type = (unsigned char)tga[1]; + image_type = (unsigned char)tga[2]; + cmap_index = get_ushort(*(unsigned short*)(&tga[3])); + cmap_len = get_ushort(*(unsigned short*)(&tga[5])); + cmap_entry_size = (unsigned char)tga[7]; - x_origin = get_ushort(*(unsigned short*)(&tga[8])); - y_origin = get_ushort(*(unsigned short*)(&tga[10])); - image_w = get_ushort(*(unsigned short*)(&tga[12])); - image_h = get_ushort(*(unsigned short*)(&tga[14])); - pixel_depth = (unsigned char)tga[16]; - image_desc = (unsigned char)tga[17]; + x_origin = get_ushort(*(unsigned short*)(&tga[8])); + y_origin = get_ushort(*(unsigned short*)(&tga[10])); + image_w = get_ushort(*(unsigned short*)(&tga[12])); + image_h = get_ushort(*(unsigned short*)(&tga[14])); + pixel_depth = (unsigned char)tga[16]; + image_desc = (unsigned char)tga[17]; - free(tga); + free(tga); - *bits_per_pixel = (unsigned int)pixel_depth; - *width = (unsigned int)image_w; - *height = (unsigned int)image_h; + *bits_per_pixel = (unsigned int)pixel_depth; + *width = (unsigned int)image_w; + *height = (unsigned int)image_h; - /* Ignore tga identifier, if present ... */ - if (id_len) - { - unsigned char *id = (unsigned char *) malloc(id_len); - if ( !fread(id, id_len, 1, fp) ) - { - fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); - free(id); - return 0 ; - } - free(id); - } + /* Ignore tga identifier, if present ... */ + if (id_len) + { + unsigned char *id = (unsigned char *) malloc(id_len); + if ( !fread(id, id_len, 1, fp) ) + { + fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); + free(id); + return 0 ; + } + free(id); + } - /* Test for compressed formats ... not yet supported ... - // Note :- 9 - RLE encoded palettized. - // 10 - RLE encoded RGB. */ - if (image_type > 8) - { - fprintf(stderr, "Sorry, compressed tga files are not currently supported.\n"); - return 0 ; - } + /* Test for compressed formats ... not yet supported ... + // Note :- 9 - RLE encoded palettized. + // 10 - RLE encoded RGB. */ + if (image_type > 8) + { + fprintf(stderr, "Sorry, compressed tga files are not currently supported.\n"); + return 0 ; + } - *flip_image = !(image_desc & 32); + *flip_image = !(image_desc & 32); - /* Palettized formats are not yet supported, skip over the palette, if present ... */ - palette_size = cmap_len * (cmap_entry_size/8); - - if (palette_size>0) - { - fprintf(stderr, "File contains a palette - not yet supported."); - fseek(fp, palette_size, SEEK_CUR); - } - return 1; + /* Palettized formats are not yet supported, skip over the palette, if present ... */ + palette_size = cmap_len * (cmap_entry_size/8); + + if (palette_size>0) + { + fprintf(stderr, "File contains a palette - not yet supported."); + fseek(fp, palette_size, SEEK_CUR); + } + return 1; } #if WORDS_BIGENDIAN == 1 static inline int16_t swap16(int16_t x) { - return((((u_int16_t)x & 0x00ffU) << 8) | - (((u_int16_t)x & 0xff00U) >> 8)); + return((((u_int16_t)x & 0x00ffU) << 8) | + (((u_int16_t)x & 0xff00U) >> 8)); } #endif static int tga_writeheader(FILE *fp, int bits_per_pixel, int width, int height, - OPJ_BOOL flip_image) + OPJ_BOOL flip_image) { - unsigned short image_w, image_h, us0; - unsigned char uc0, image_type; - unsigned char pixel_depth, image_desc; + unsigned short image_w, image_h, us0; + unsigned char uc0, image_type; + unsigned char pixel_depth, image_desc; - if (!bits_per_pixel || !width || !height) - return 0; + if (!bits_per_pixel || !width || !height) + return 0; - pixel_depth = 0; + pixel_depth = 0; - if ( bits_per_pixel < 256 ) - pixel_depth = (unsigned char)bits_per_pixel; - else{ - fprintf(stderr,"ERROR: Wrong bits per pixel inside tga_header"); - return 0; - } - uc0 = 0; + if ( bits_per_pixel < 256 ) + pixel_depth = (unsigned char)bits_per_pixel; + else{ + fprintf(stderr,"ERROR: Wrong bits per pixel inside tga_header"); + return 0; + } + uc0 = 0; - if(fwrite(&uc0, 1, 1, fp) != 1) goto fails; /* id_length */ - if(fwrite(&uc0, 1, 1, fp) != 1) goto fails; /* colour_map_type */ + if(fwrite(&uc0, 1, 1, fp) != 1) goto fails; /* id_length */ + if(fwrite(&uc0, 1, 1, fp) != 1) goto fails; /* colour_map_type */ - image_type = 2; /* Uncompressed. */ - if(fwrite(&image_type, 1, 1, fp) != 1) goto fails; + image_type = 2; /* Uncompressed. */ + if(fwrite(&image_type, 1, 1, fp) != 1) goto fails; - us0 = 0; - if(fwrite(&us0, 2, 1, fp) != 1) goto fails; /* colour_map_index */ - if(fwrite(&us0, 2, 1, fp) != 1) goto fails; /* colour_map_length */ - if(fwrite(&uc0, 1, 1, fp) != 1) goto fails; /* colour_map_entry_size */ + us0 = 0; + if(fwrite(&us0, 2, 1, fp) != 1) goto fails; /* colour_map_index */ + if(fwrite(&us0, 2, 1, fp) != 1) goto fails; /* colour_map_length */ + if(fwrite(&uc0, 1, 1, fp) != 1) goto fails; /* colour_map_entry_size */ - if(fwrite(&us0, 2, 1, fp) != 1) goto fails; /* x_origin */ - if(fwrite(&us0, 2, 1, fp) != 1) goto fails; /* y_origin */ + if(fwrite(&us0, 2, 1, fp) != 1) goto fails; /* x_origin */ + if(fwrite(&us0, 2, 1, fp) != 1) goto fails; /* y_origin */ - image_w = (unsigned short)width; - image_h = (unsigned short) height; + image_w = (unsigned short)width; + image_h = (unsigned short) height; #if WORDS_BIGENDIAN == 0 - if(fwrite(&image_w, 2, 1, fp) != 1) goto fails; - if(fwrite(&image_h, 2, 1, fp) != 1) goto fails; + if(fwrite(&image_w, 2, 1, fp) != 1) goto fails; + if(fwrite(&image_h, 2, 1, fp) != 1) goto fails; #else - image_w = swap16(image_w); - image_h = swap16(image_h); - if(fwrite(&image_w, 2, 1, fp) != 1) goto fails; - if(fwrite(&image_h, 2, 1, fp) != 1) goto fails; + image_w = swap16(image_w); + image_h = swap16(image_h); + if(fwrite(&image_w, 2, 1, fp) != 1) goto fails; + if(fwrite(&image_h, 2, 1, fp) != 1) goto fails; #endif - if(fwrite(&pixel_depth, 1, 1, fp) != 1) goto fails; + if(fwrite(&pixel_depth, 1, 1, fp) != 1) goto fails; - image_desc = 8; /* 8 bits per component. */ + image_desc = 8; /* 8 bits per component. */ - if (flip_image) - image_desc |= 32; - if(fwrite(&image_desc, 1, 1, fp) != 1) goto fails; + if (flip_image) + image_desc |= 32; + if(fwrite(&image_desc, 1, 1, fp) != 1) goto fails; - return 1; + return 1; fails: - fputs("\nwrite_tgaheader: write ERROR\n", stderr); - return 0; + fputs("\nwrite_tgaheader: write ERROR\n", stderr); + return 0; } opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters) { - FILE *f; - opj_image_t *image; - unsigned int image_width, image_height, pixel_bit_depth; - unsigned int x, y; - int flip_image=0; - opj_image_cmptparm_t cmptparm[4]; /* maximum 4 components */ - int numcomps; - OPJ_COLOR_SPACE color_space; - OPJ_BOOL mono ; - OPJ_BOOL save_alpha; - int subsampling_dx, subsampling_dy; - int i; + FILE *f; + opj_image_t *image; + unsigned int image_width, image_height, pixel_bit_depth; + unsigned int x, y; + int flip_image=0; + opj_image_cmptparm_t cmptparm[4]; /* maximum 4 components */ + int numcomps; + OPJ_COLOR_SPACE color_space; + OPJ_BOOL mono ; + OPJ_BOOL save_alpha; + int subsampling_dx, subsampling_dy; + int i; - f = fopen(filename, "rb"); - if (!f) { - fprintf(stderr, "Failed to open %s for reading !!\n", filename); - return 0; - } + f = fopen(filename, "rb"); + if (!f) { + fprintf(stderr, "Failed to open %s for reading !!\n", filename); + return 0; + } - if (!tga_readheader(f, &pixel_bit_depth, &image_width, &image_height, &flip_image)) - return NULL; + if (!tga_readheader(f, &pixel_bit_depth, &image_width, &image_height, &flip_image)) + return NULL; - /* We currently only support 24 & 32 bit tga's ... */ - if (!((pixel_bit_depth == 24) || (pixel_bit_depth == 32))) - return NULL; + /* We currently only support 24 & 32 bit tga's ... */ + if (!((pixel_bit_depth == 24) || (pixel_bit_depth == 32))) + return NULL; - /* initialize image components */ - memset(&cmptparm[0], 0, 4 * sizeof(opj_image_cmptparm_t)); + /* initialize image components */ + memset(&cmptparm[0], 0, 4 * sizeof(opj_image_cmptparm_t)); - mono = (pixel_bit_depth == 8) || (pixel_bit_depth == 16); /* Mono with & without alpha. */ - save_alpha = (pixel_bit_depth == 16) || (pixel_bit_depth == 32); /* Mono with alpha, or RGB with alpha */ + mono = (pixel_bit_depth == 8) || (pixel_bit_depth == 16); /* Mono with & without alpha. */ + save_alpha = (pixel_bit_depth == 16) || (pixel_bit_depth == 32); /* Mono with alpha, or RGB with alpha */ - if (mono) { - color_space = OPJ_CLRSPC_GRAY; - numcomps = save_alpha ? 2 : 1; - } - else { - numcomps = save_alpha ? 4 : 3; - color_space = OPJ_CLRSPC_SRGB; - } + if (mono) { + color_space = OPJ_CLRSPC_GRAY; + numcomps = save_alpha ? 2 : 1; + } + else { + numcomps = save_alpha ? 4 : 3; + color_space = OPJ_CLRSPC_SRGB; + } - subsampling_dx = parameters->subsampling_dx; - subsampling_dy = parameters->subsampling_dy; + subsampling_dx = parameters->subsampling_dx; + subsampling_dy = parameters->subsampling_dy; - for (i = 0; i < numcomps; i++) { - cmptparm[i].prec = 8; - cmptparm[i].bpp = 8; - cmptparm[i].sgnd = 0; - cmptparm[i].dx = subsampling_dx; - cmptparm[i].dy = subsampling_dy; - cmptparm[i].w = image_width; - cmptparm[i].h = image_height; - } + for (i = 0; i < numcomps; i++) { + cmptparm[i].prec = 8; + cmptparm[i].bpp = 8; + cmptparm[i].sgnd = 0; + cmptparm[i].dx = subsampling_dx; + cmptparm[i].dy = subsampling_dy; + cmptparm[i].w = image_width; + cmptparm[i].h = image_height; + } - /* create the image */ - image = opj_image_create(numcomps, &cmptparm[0], color_space); + /* create the image */ + image = opj_image_create(numcomps, &cmptparm[0], color_space); - if (!image) - return NULL; + if (!image) + return NULL; - /* set image offset and reference grid */ - image->x0 = parameters->image_offset_x0; - image->y0 = parameters->image_offset_y0; - image->x1 = !image->x0 ? (image_width - 1) * subsampling_dx + 1 : image->x0 + (image_width - 1) * subsampling_dx + 1; - image->y1 = !image->y0 ? (image_height - 1) * subsampling_dy + 1 : image->y0 + (image_height - 1) * subsampling_dy + 1; + /* set image offset and reference grid */ + image->x0 = parameters->image_offset_x0; + image->y0 = parameters->image_offset_y0; + image->x1 = !image->x0 ? (image_width - 1) * subsampling_dx + 1 : image->x0 + (image_width - 1) * subsampling_dx + 1; + image->y1 = !image->y0 ? (image_height - 1) * subsampling_dy + 1 : image->y0 + (image_height - 1) * subsampling_dy + 1; - /* set image data */ - for (y=0; y < image_height; y++) - { - int index; + /* set image data */ + for (y=0; y < image_height; y++) + { + int index; - if (flip_image) - index = (image_height-y-1)*image_width; - else - index = y*image_width; + if (flip_image) + index = (image_height-y-1)*image_width; + else + index = y*image_width; - if (numcomps==3) - { - for (x=0;xcomps[0].data[index]=r; - image->comps[1].data[index]=g; - image->comps[2].data[index]=b; - index++; - } - } - else if (numcomps==4) - { - for (x=0;xcomps[0].data[index]=r; + image->comps[1].data[index]=g; + image->comps[2].data[index]=b; + index++; + } + } + else if (numcomps==4) + { + for (x=0;xcomps[0].data[index]=r; - image->comps[1].data[index]=g; - image->comps[2].data[index]=b; - image->comps[3].data[index]=a; - index++; - } - } - else { - fprintf(stderr, "Currently unsupported bit depth : %s\n", filename); - } - } - return image; + image->comps[0].data[index]=r; + image->comps[1].data[index]=g; + image->comps[2].data[index]=b; + image->comps[3].data[index]=a; + index++; + } + } + else { + fprintf(stderr, "Currently unsupported bit depth : %s\n", filename); + } + } + return image; } int imagetotga(opj_image_t * image, const char *outfile) { - int width, height, bpp, x, y; - OPJ_BOOL write_alpha; - int i, adjustR, adjustG, adjustB; - unsigned int alpha_channel; - float r,g,b,a; - unsigned char value; - float scale; - FILE *fdest; - size_t res; + int width, height, bpp, x, y; + OPJ_BOOL write_alpha; + int i, adjustR, adjustG, adjustB; + unsigned int alpha_channel; + float r,g,b,a; + unsigned char value; + float scale; + FILE *fdest; + size_t res; - fdest = fopen(outfile, "wb"); - if (!fdest) { - fprintf(stderr, "ERROR -> failed to open %s for writing\n", outfile); - return 1; - } - - for (i = 0; i < image->numcomps-1; i++) { - if ((image->comps[0].dx != image->comps[i+1].dx) - ||(image->comps[0].dy != image->comps[i+1].dy) - ||(image->comps[0].prec != image->comps[i+1].prec)) { - fprintf(stderr, "Unable to create a tga file with such J2K image charateristics."); - return 1; - } - } - - width = image->comps[0].w; - height = image->comps[0].h; - - /* Mono with alpha, or RGB with alpha. */ - write_alpha = (image->numcomps==2) || (image->numcomps==4); - - /* Write TGA header */ - bpp = write_alpha ? 32 : 24; - if (!tga_writeheader(fdest, bpp, width , height, OPJ_TRUE)) - return 1; - - alpha_channel = image->numcomps-1; - - scale = 255.0f / (float)((1<comps[0].prec)-1); - - adjustR = (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); - adjustG = (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); - adjustB = (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); - - for (y=0; y < height; y++) { - unsigned int index=y*width; - - for (x=0; x < width; x++, index++) { - r = (float)(image->comps[0].data[index] + adjustR); - - if (image->numcomps>2) { - g = (float)(image->comps[1].data[index] + adjustG); - b = (float)(image->comps[2].data[index] + adjustB); - } - else {/* Greyscale ... */ - g = r; - b = r; - } - - /* TGA format writes BGR ... */ - value = (unsigned char)(b*scale); - res = fwrite(&value,1,1,fdest); - if( res < 1 ) { - fprintf(stderr, "failed to write 1 byte for %s\n", outfile); + fdest = fopen(outfile, "wb"); + if (!fdest) { + fprintf(stderr, "ERROR -> failed to open %s for writing\n", outfile); return 1; - } + } - value = (unsigned char)(g*scale); - res = fwrite(&value,1,1,fdest); - if( res < 1 ) { - fprintf(stderr, "failed to write 1 byte for %s\n", outfile); - return 1; - } - - value = (unsigned char)(r*scale); - res = fwrite(&value,1,1,fdest); - if( res < 1 ) { - fprintf(stderr, "failed to write 1 byte for %s\n", outfile); - return 1; - } - - if (write_alpha) { - a = (float)(image->comps[alpha_channel].data[index]); - value = (unsigned char)(a*scale); - res = fwrite(&value,1,1,fdest); - if( res < 1 ) { - fprintf(stderr, "failed to write 1 byte for %s\n", outfile); - return 1; + for (i = 0; i < image->numcomps-1; i++) { + if ((image->comps[0].dx != image->comps[i+1].dx) + ||(image->comps[0].dy != image->comps[i+1].dy) + ||(image->comps[0].prec != image->comps[i+1].prec)) { + fprintf(stderr, "Unable to create a tga file with such J2K image charateristics."); + return 1; } - } - } - } + } - return 0; + width = image->comps[0].w; + height = image->comps[0].h; + + /* Mono with alpha, or RGB with alpha. */ + write_alpha = (image->numcomps==2) || (image->numcomps==4); + + /* Write TGA header */ + bpp = write_alpha ? 32 : 24; + if (!tga_writeheader(fdest, bpp, width , height, OPJ_TRUE)) + return 1; + + alpha_channel = image->numcomps-1; + + scale = 255.0f / (float)((1<comps[0].prec)-1); + + adjustR = (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); + adjustG = (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); + adjustB = (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); + + for (y=0; y < height; y++) { + unsigned int index=y*width; + + for (x=0; x < width; x++, index++) { + r = (float)(image->comps[0].data[index] + adjustR); + + if (image->numcomps>2) { + g = (float)(image->comps[1].data[index] + adjustG); + b = (float)(image->comps[2].data[index] + adjustB); + } + else {/* Greyscale ... */ + g = r; + b = r; + } + + /* TGA format writes BGR ... */ + value = (unsigned char)(b*scale); + res = fwrite(&value,1,1,fdest); + if( res < 1 ) { + fprintf(stderr, "failed to write 1 byte for %s\n", outfile); + return 1; + } + + value = (unsigned char)(g*scale); + res = fwrite(&value,1,1,fdest); + if( res < 1 ) { + fprintf(stderr, "failed to write 1 byte for %s\n", outfile); + return 1; + } + + value = (unsigned char)(r*scale); + res = fwrite(&value,1,1,fdest); + if( res < 1 ) { + fprintf(stderr, "failed to write 1 byte for %s\n", outfile); + return 1; + } + + if (write_alpha) { + a = (float)(image->comps[alpha_channel].data[index]); + value = (unsigned char)(a*scale); + res = fwrite(&value,1,1,fdest); + if( res < 1 ) { + fprintf(stderr, "failed to write 1 byte for %s\n", outfile); + return 1; + } + } + } + } + + return 0; } /* -->> -->> -->> -->> @@ -513,686 +513,686 @@ typedef unsigned short int WORD; typedef unsigned int DWORD; typedef struct { - WORD bfType; /* 'BM' for Bitmap (19776) */ - DWORD bfSize; /* Size of the file */ - WORD bfReserved1; /* Reserved : 0 */ - WORD bfReserved2; /* Reserved : 0 */ - DWORD bfOffBits; /* Offset */ + WORD bfType; /* 'BM' for Bitmap (19776) */ + DWORD bfSize; /* Size of the file */ + WORD bfReserved1; /* Reserved : 0 */ + WORD bfReserved2; /* Reserved : 0 */ + DWORD bfOffBits; /* Offset */ } BITMAPFILEHEADER_t; typedef struct { - DWORD biSize; /* Size of the structure in bytes */ - DWORD biWidth; /* Width of the image in pixels */ - DWORD biHeight; /* Heigth of the image in pixels */ - WORD biPlanes; /* 1 */ - WORD biBitCount; /* Number of color bits by pixels */ - DWORD biCompression; /* Type of encoding 0: none 1: RLE8 2: RLE4 */ - DWORD biSizeImage; /* Size of the image in bytes */ - DWORD biXpelsPerMeter; /* Horizontal (X) resolution in pixels/meter */ - DWORD biYpelsPerMeter; /* Vertical (Y) resolution in pixels/meter */ - DWORD biClrUsed; /* Number of color used in the image (0: ALL) */ - DWORD biClrImportant; /* Number of important color (0: ALL) */ + DWORD biSize; /* Size of the structure in bytes */ + DWORD biWidth; /* Width of the image in pixels */ + DWORD biHeight; /* Heigth of the image in pixels */ + WORD biPlanes; /* 1 */ + WORD biBitCount; /* Number of color bits by pixels */ + DWORD biCompression; /* Type of encoding 0: none 1: RLE8 2: RLE4 */ + DWORD biSizeImage; /* Size of the image in bytes */ + DWORD biXpelsPerMeter; /* Horizontal (X) resolution in pixels/meter */ + DWORD biYpelsPerMeter; /* Vertical (Y) resolution in pixels/meter */ + DWORD biClrUsed; /* Number of color used in the image (0: ALL) */ + DWORD biClrImportant; /* Number of important color (0: ALL) */ } BITMAPINFOHEADER_t; opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters) { - int subsampling_dx = parameters->subsampling_dx; - int subsampling_dy = parameters->subsampling_dy; + int subsampling_dx = parameters->subsampling_dx; + int subsampling_dy = parameters->subsampling_dy; - int i, numcomps, w, h; - OPJ_COLOR_SPACE color_space; - opj_image_cmptparm_t cmptparm[3]; /* maximum of 3 components */ - opj_image_t * image = NULL; + int i, numcomps, w, h; + OPJ_COLOR_SPACE color_space; + opj_image_cmptparm_t cmptparm[3]; /* maximum of 3 components */ + opj_image_t * image = NULL; - FILE *IN; - BITMAPFILEHEADER_t File_h; - BITMAPINFOHEADER_t Info_h; - unsigned char *RGB; - unsigned char *table_R, *table_G, *table_B; - unsigned int j, PAD = 0; + FILE *IN; + BITMAPFILEHEADER_t File_h; + BITMAPINFOHEADER_t Info_h; + unsigned char *RGB; + unsigned char *table_R, *table_G, *table_B; + unsigned int j, PAD = 0; - int x, y, index; - int gray_scale = 1; - int has_color; - DWORD W, H; - - IN = fopen(filename, "rb"); - if (!IN) - { - fprintf(stderr, "Failed to open %s for reading !!\n", filename); - return NULL; - } - - File_h.bfType = getc(IN); - File_h.bfType = (getc(IN) << 8) + File_h.bfType; - - if (File_h.bfType != 19778) - { - fprintf(stderr,"Error, not a BMP file!\n"); - fclose(IN); - return NULL; - } - /* FILE HEADER */ - /* ------------- */ - File_h.bfSize = getc(IN); - File_h.bfSize = (getc(IN) << 8) + File_h.bfSize; - File_h.bfSize = (getc(IN) << 16) + File_h.bfSize; - File_h.bfSize = (getc(IN) << 24) + File_h.bfSize; + int x, y, index; + int gray_scale = 1; + int has_color; + DWORD W, H; - File_h.bfReserved1 = getc(IN); - File_h.bfReserved1 = (getc(IN) << 8) + File_h.bfReserved1; + IN = fopen(filename, "rb"); + if (!IN) + { + fprintf(stderr, "Failed to open %s for reading !!\n", filename); + return NULL; + } - File_h.bfReserved2 = getc(IN); - File_h.bfReserved2 = (getc(IN) << 8) + File_h.bfReserved2; + File_h.bfType = getc(IN); + File_h.bfType = (getc(IN) << 8) + File_h.bfType; - File_h.bfOffBits = getc(IN); - File_h.bfOffBits = (getc(IN) << 8) + File_h.bfOffBits; - File_h.bfOffBits = (getc(IN) << 16) + File_h.bfOffBits; - File_h.bfOffBits = (getc(IN) << 24) + File_h.bfOffBits; + if (File_h.bfType != 19778) + { + fprintf(stderr,"Error, not a BMP file!\n"); + fclose(IN); + return NULL; + } + /* FILE HEADER */ + /* ------------- */ + File_h.bfSize = getc(IN); + File_h.bfSize = (getc(IN) << 8) + File_h.bfSize; + File_h.bfSize = (getc(IN) << 16) + File_h.bfSize; + File_h.bfSize = (getc(IN) << 24) + File_h.bfSize; - /* INFO HEADER */ - /* ------------- */ + File_h.bfReserved1 = getc(IN); + File_h.bfReserved1 = (getc(IN) << 8) + File_h.bfReserved1; - Info_h.biSize = getc(IN); - Info_h.biSize = (getc(IN) << 8) + Info_h.biSize; - Info_h.biSize = (getc(IN) << 16) + Info_h.biSize; - Info_h.biSize = (getc(IN) << 24) + Info_h.biSize; + File_h.bfReserved2 = getc(IN); + File_h.bfReserved2 = (getc(IN) << 8) + File_h.bfReserved2; - if(Info_h.biSize != 40) - { - fprintf(stderr,"Error, unknown BMP header size %d\n", Info_h.biSize); - fclose(IN); - return NULL; - } - Info_h.biWidth = getc(IN); - Info_h.biWidth = (getc(IN) << 8) + Info_h.biWidth; - Info_h.biWidth = (getc(IN) << 16) + Info_h.biWidth; - Info_h.biWidth = (getc(IN) << 24) + Info_h.biWidth; - w = Info_h.biWidth; + File_h.bfOffBits = getc(IN); + File_h.bfOffBits = (getc(IN) << 8) + File_h.bfOffBits; + File_h.bfOffBits = (getc(IN) << 16) + File_h.bfOffBits; + File_h.bfOffBits = (getc(IN) << 24) + File_h.bfOffBits; - Info_h.biHeight = getc(IN); - Info_h.biHeight = (getc(IN) << 8) + Info_h.biHeight; - Info_h.biHeight = (getc(IN) << 16) + Info_h.biHeight; - Info_h.biHeight = (getc(IN) << 24) + Info_h.biHeight; - h = Info_h.biHeight; + /* INFO HEADER */ + /* ------------- */ - Info_h.biPlanes = getc(IN); - Info_h.biPlanes = (getc(IN) << 8) + Info_h.biPlanes; + Info_h.biSize = getc(IN); + Info_h.biSize = (getc(IN) << 8) + Info_h.biSize; + Info_h.biSize = (getc(IN) << 16) + Info_h.biSize; + Info_h.biSize = (getc(IN) << 24) + Info_h.biSize; - Info_h.biBitCount = getc(IN); - Info_h.biBitCount = (getc(IN) << 8) + Info_h.biBitCount; + if(Info_h.biSize != 40) + { + fprintf(stderr,"Error, unknown BMP header size %d\n", Info_h.biSize); + fclose(IN); + return NULL; + } + Info_h.biWidth = getc(IN); + Info_h.biWidth = (getc(IN) << 8) + Info_h.biWidth; + Info_h.biWidth = (getc(IN) << 16) + Info_h.biWidth; + Info_h.biWidth = (getc(IN) << 24) + Info_h.biWidth; + w = Info_h.biWidth; - Info_h.biCompression = getc(IN); - Info_h.biCompression = (getc(IN) << 8) + Info_h.biCompression; - Info_h.biCompression = (getc(IN) << 16) + Info_h.biCompression; - Info_h.biCompression = (getc(IN) << 24) + Info_h.biCompression; + Info_h.biHeight = getc(IN); + Info_h.biHeight = (getc(IN) << 8) + Info_h.biHeight; + Info_h.biHeight = (getc(IN) << 16) + Info_h.biHeight; + Info_h.biHeight = (getc(IN) << 24) + Info_h.biHeight; + h = Info_h.biHeight; - Info_h.biSizeImage = getc(IN); - Info_h.biSizeImage = (getc(IN) << 8) + Info_h.biSizeImage; - Info_h.biSizeImage = (getc(IN) << 16) + Info_h.biSizeImage; - Info_h.biSizeImage = (getc(IN) << 24) + Info_h.biSizeImage; + Info_h.biPlanes = getc(IN); + Info_h.biPlanes = (getc(IN) << 8) + Info_h.biPlanes; - Info_h.biXpelsPerMeter = getc(IN); - Info_h.biXpelsPerMeter = (getc(IN) << 8) + Info_h.biXpelsPerMeter; - Info_h.biXpelsPerMeter = (getc(IN) << 16) + Info_h.biXpelsPerMeter; - Info_h.biXpelsPerMeter = (getc(IN) << 24) + Info_h.biXpelsPerMeter; + Info_h.biBitCount = getc(IN); + Info_h.biBitCount = (getc(IN) << 8) + Info_h.biBitCount; - Info_h.biYpelsPerMeter = getc(IN); - Info_h.biYpelsPerMeter = (getc(IN) << 8) + Info_h.biYpelsPerMeter; - Info_h.biYpelsPerMeter = (getc(IN) << 16) + Info_h.biYpelsPerMeter; - Info_h.biYpelsPerMeter = (getc(IN) << 24) + Info_h.biYpelsPerMeter; + Info_h.biCompression = getc(IN); + Info_h.biCompression = (getc(IN) << 8) + Info_h.biCompression; + Info_h.biCompression = (getc(IN) << 16) + Info_h.biCompression; + Info_h.biCompression = (getc(IN) << 24) + Info_h.biCompression; - Info_h.biClrUsed = getc(IN); - Info_h.biClrUsed = (getc(IN) << 8) + Info_h.biClrUsed; - Info_h.biClrUsed = (getc(IN) << 16) + Info_h.biClrUsed; - Info_h.biClrUsed = (getc(IN) << 24) + Info_h.biClrUsed; + Info_h.biSizeImage = getc(IN); + Info_h.biSizeImage = (getc(IN) << 8) + Info_h.biSizeImage; + Info_h.biSizeImage = (getc(IN) << 16) + Info_h.biSizeImage; + Info_h.biSizeImage = (getc(IN) << 24) + Info_h.biSizeImage; - Info_h.biClrImportant = getc(IN); - Info_h.biClrImportant = (getc(IN) << 8) + Info_h.biClrImportant; - Info_h.biClrImportant = (getc(IN) << 16) + Info_h.biClrImportant; - Info_h.biClrImportant = (getc(IN) << 24) + Info_h.biClrImportant; + Info_h.biXpelsPerMeter = getc(IN); + Info_h.biXpelsPerMeter = (getc(IN) << 8) + Info_h.biXpelsPerMeter; + Info_h.biXpelsPerMeter = (getc(IN) << 16) + Info_h.biXpelsPerMeter; + Info_h.biXpelsPerMeter = (getc(IN) << 24) + Info_h.biXpelsPerMeter; - /* Read the data and store them in the OUT file */ + Info_h.biYpelsPerMeter = getc(IN); + Info_h.biYpelsPerMeter = (getc(IN) << 8) + Info_h.biYpelsPerMeter; + Info_h.biYpelsPerMeter = (getc(IN) << 16) + Info_h.biYpelsPerMeter; + Info_h.biYpelsPerMeter = (getc(IN) << 24) + Info_h.biYpelsPerMeter; - if (Info_h.biBitCount == 24) - { - numcomps = 3; - color_space = OPJ_CLRSPC_SRGB; - /* initialize image components */ - memset(&cmptparm[0], 0, 3 * sizeof(opj_image_cmptparm_t)); - for(i = 0; i < numcomps; i++) - { - cmptparm[i].prec = 8; - cmptparm[i].bpp = 8; - cmptparm[i].sgnd = 0; - cmptparm[i].dx = subsampling_dx; - cmptparm[i].dy = subsampling_dy; - cmptparm[i].w = w; - cmptparm[i].h = h; - } - /* create the image */ - image = opj_image_create(numcomps, &cmptparm[0], color_space); - if(!image) - { - fclose(IN); - return NULL; - } + Info_h.biClrUsed = getc(IN); + Info_h.biClrUsed = (getc(IN) << 8) + Info_h.biClrUsed; + Info_h.biClrUsed = (getc(IN) << 16) + Info_h.biClrUsed; + Info_h.biClrUsed = (getc(IN) << 24) + Info_h.biClrUsed; - /* set image offset and reference grid */ - image->x0 = parameters->image_offset_x0; - image->y0 = parameters->image_offset_y0; - image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : image->x0 + (w - 1) * subsampling_dx + 1; - image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : image->y0 + (h - 1) * subsampling_dy + 1; + Info_h.biClrImportant = getc(IN); + Info_h.biClrImportant = (getc(IN) << 8) + Info_h.biClrImportant; + Info_h.biClrImportant = (getc(IN) << 16) + Info_h.biClrImportant; + Info_h.biClrImportant = (getc(IN) << 24) + Info_h.biClrImportant; - /* set image data */ + /* Read the data and store them in the OUT file */ - /* Place the cursor at the beginning of the image information */ - fseek(IN, 0, SEEK_SET); - fseek(IN, File_h.bfOffBits, SEEK_SET); - - W = Info_h.biWidth; - H = Info_h.biHeight; + if (Info_h.biBitCount == 24) + { + numcomps = 3; + color_space = OPJ_CLRSPC_SRGB; + /* initialize image components */ + memset(&cmptparm[0], 0, 3 * sizeof(opj_image_cmptparm_t)); + for(i = 0; i < numcomps; i++) + { + cmptparm[i].prec = 8; + cmptparm[i].bpp = 8; + cmptparm[i].sgnd = 0; + cmptparm[i].dx = subsampling_dx; + cmptparm[i].dy = subsampling_dy; + cmptparm[i].w = w; + cmptparm[i].h = h; + } + /* create the image */ + image = opj_image_create(numcomps, &cmptparm[0], color_space); + if(!image) + { + fclose(IN); + return NULL; + } - /* PAD = 4 - (3 * W) % 4; */ - /* PAD = (PAD == 4) ? 0 : PAD; */ - PAD = (3 * W) % 4 ? 4 - (3 * W) % 4 : 0; - - RGB = (unsigned char *) - malloc((3 * W + PAD) * H * sizeof(unsigned char)); - - if ( fread(RGB, sizeof(unsigned char), (3 * W + PAD) * H, IN) != (3 * W + PAD) * H ) - { - free(RGB); - opj_image_destroy(image); - fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); - return NULL; - } - - index = 0; + /* set image offset and reference grid */ + image->x0 = parameters->image_offset_x0; + image->y0 = parameters->image_offset_y0; + image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : image->x0 + (w - 1) * subsampling_dx + 1; + image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : image->y0 + (h - 1) * subsampling_dy + 1; - for(y = 0; y < (int)H; y++) - { - unsigned char *scanline = RGB + (3 * W + PAD) * (H - 1 - y); - for(x = 0; x < (int)W; x++) - { - unsigned char *pixel = &scanline[3 * x]; - image->comps[0].data[index] = pixel[2]; /* R */ - image->comps[1].data[index] = pixel[1]; /* G */ - image->comps[2].data[index] = pixel[0]; /* B */ - index++; - } - } - free(RGB); - }/* if (Info_h.biBitCount == 24) */ - else - if (Info_h.biBitCount == 8 && Info_h.biCompression == 0)/*RGB */ - { - if(Info_h.biClrUsed == 0) Info_h.biClrUsed = 256; - else - if(Info_h.biClrUsed > 256) Info_h.biClrUsed = 256; + /* set image data */ - table_R = (unsigned char *) malloc(256 * sizeof(unsigned char)); - table_G = (unsigned char *) malloc(256 * sizeof(unsigned char)); - table_B = (unsigned char *) malloc(256 * sizeof(unsigned char)); - - has_color = 0; - for (j = 0; j < Info_h.biClrUsed; j++) - { - table_B[j] = (unsigned char)getc(IN); - table_G[j] = (unsigned char)getc(IN); - table_R[j] = (unsigned char)getc(IN); - getc(IN); - has_color += - !(table_R[j] == table_G[j] && table_R[j] == table_B[j]); - } - if(has_color) gray_scale = 0; - - /* Place the cursor at the beginning of the image information */ - fseek(IN, 0, SEEK_SET); - fseek(IN, File_h.bfOffBits, SEEK_SET); - - W = Info_h.biWidth; - H = Info_h.biHeight; - if (Info_h.biWidth % 2) - W++; - - numcomps = gray_scale ? 1 : 3; - color_space = gray_scale ? OPJ_CLRSPC_GRAY : OPJ_CLRSPC_SRGB; - /* initialize image components */ - memset(&cmptparm[0], 0, 3 * sizeof(opj_image_cmptparm_t)); - for(i = 0; i < numcomps; i++) - { - cmptparm[i].prec = 8; - cmptparm[i].bpp = 8; - cmptparm[i].sgnd = 0; - cmptparm[i].dx = subsampling_dx; - cmptparm[i].dy = subsampling_dy; - cmptparm[i].w = w; - cmptparm[i].h = h; - } - /* create the image */ - image = opj_image_create(numcomps, &cmptparm[0], color_space); - if(!image) - { - fclose(IN); - free(table_R); free(table_G); free(table_B); - return NULL; - } + /* Place the cursor at the beginning of the image information */ + fseek(IN, 0, SEEK_SET); + fseek(IN, File_h.bfOffBits, SEEK_SET); - /* set image offset and reference grid */ - image->x0 = parameters->image_offset_x0; - image->y0 = parameters->image_offset_y0; - image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : image->x0 + (w - 1) * subsampling_dx + 1; - image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : image->y0 + (h - 1) * subsampling_dy + 1; + W = Info_h.biWidth; + H = Info_h.biHeight; - /* set image data */ + /* PAD = 4 - (3 * W) % 4; */ + /* PAD = (PAD == 4) ? 0 : PAD; */ + PAD = (3 * W) % 4 ? 4 - (3 * W) % 4 : 0; - RGB = (unsigned char *) malloc(W * H * sizeof(unsigned char)); - - if ( fread(RGB, sizeof(unsigned char), W * H, IN) != W * H ) - { - free(table_R); - free(table_G); - free(table_B); - free(RGB); - opj_image_destroy(image); - fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); - return NULL; - } - if (gray_scale) - { - index = 0; - for (j = 0; j < W * H; j++) - { - if ((j % W < W - 1 && Info_h.biWidth % 2) || !(Info_h.biWidth % 2)) - { - image->comps[0].data[index] = - table_R[RGB[W * H - ((j) / (W) + 1) * W + (j) % (W)]]; - index++; - } - } + RGB = (unsigned char *) + malloc((3 * W + PAD) * H * sizeof(unsigned char)); - } - else - { - index = 0; - for (j = 0; j < W * H; j++) - { - if ((j % W < W - 1 && Info_h.biWidth % 2) - || !(Info_h.biWidth % 2)) - { - unsigned char pixel_index = - RGB[W * H - ((j) / (W) + 1) * W + (j) % (W)]; - image->comps[0].data[index] = table_R[pixel_index]; - image->comps[1].data[index] = table_G[pixel_index]; - image->comps[2].data[index] = table_B[pixel_index]; - index++; - } - } - } - free(RGB); - free(table_R); - free(table_G); - free(table_B); - }/* RGB8 */ - else - if (Info_h.biBitCount == 8 && Info_h.biCompression == 1)/*RLE8*/ - { - unsigned char *pix, *beyond; - int *gray, *red, *green, *blue; - unsigned int x, y, max; - int i, c, c1; - unsigned char uc; + if ( fread(RGB, sizeof(unsigned char), (3 * W + PAD) * H, IN) != (3 * W + PAD) * H ) + { + free(RGB); + opj_image_destroy(image); + fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); + return NULL; + } - if (Info_h.biClrUsed == 0) - Info_h.biClrUsed = 256; - else if (Info_h.biClrUsed > 256) - Info_h.biClrUsed = 256; + index = 0; - table_R = (unsigned char *) malloc(256 * sizeof(unsigned char)); - table_G = (unsigned char *) malloc(256 * sizeof(unsigned char)); - table_B = (unsigned char *) malloc(256 * sizeof(unsigned char)); + for(y = 0; y < (int)H; y++) + { + unsigned char *scanline = RGB + (3 * W + PAD) * (H - 1 - y); + for(x = 0; x < (int)W; x++) + { + unsigned char *pixel = &scanline[3 * x]; + image->comps[0].data[index] = pixel[2]; /* R */ + image->comps[1].data[index] = pixel[1]; /* G */ + image->comps[2].data[index] = pixel[0]; /* B */ + index++; + } + } + free(RGB); + }/* if (Info_h.biBitCount == 24) */ + else + if (Info_h.biBitCount == 8 && Info_h.biCompression == 0)/*RGB */ + { + if(Info_h.biClrUsed == 0) Info_h.biClrUsed = 256; + else + if(Info_h.biClrUsed > 256) Info_h.biClrUsed = 256; - has_color = 0; - for (j = 0; j < Info_h.biClrUsed; j++) - { - table_B[j] = (unsigned char)getc(IN); - table_G[j] = (unsigned char)getc(IN); - table_R[j] = (unsigned char)getc(IN); - getc(IN); - has_color += !(table_R[j] == table_G[j] && table_R[j] == table_B[j]); - } + table_R = (unsigned char *) malloc(256 * sizeof(unsigned char)); + table_G = (unsigned char *) malloc(256 * sizeof(unsigned char)); + table_B = (unsigned char *) malloc(256 * sizeof(unsigned char)); - if (has_color) - gray_scale = 0; + has_color = 0; + for (j = 0; j < Info_h.biClrUsed; j++) + { + table_B[j] = (unsigned char)getc(IN); + table_G[j] = (unsigned char)getc(IN); + table_R[j] = (unsigned char)getc(IN); + getc(IN); + has_color += + !(table_R[j] == table_G[j] && table_R[j] == table_B[j]); + } + if(has_color) gray_scale = 0; - numcomps = gray_scale ? 1 : 3; - color_space = gray_scale ? OPJ_CLRSPC_GRAY : OPJ_CLRSPC_SRGB; - /* initialize image components */ - memset(&cmptparm[0], 0, 3 * sizeof(opj_image_cmptparm_t)); - for (i = 0; i < numcomps; i++) - { - cmptparm[i].prec = 8; - cmptparm[i].bpp = 8; - cmptparm[i].sgnd = 0; - cmptparm[i].dx = subsampling_dx; - cmptparm[i].dy = subsampling_dy; - cmptparm[i].w = w; - cmptparm[i].h = h; - } - /* create the image */ - image = opj_image_create(numcomps, &cmptparm[0], color_space); - if (!image) - { - fclose(IN); - free(table_R); - free(table_G); - free(table_B); - return NULL; - } + /* Place the cursor at the beginning of the image information */ + fseek(IN, 0, SEEK_SET); + fseek(IN, File_h.bfOffBits, SEEK_SET); - /* set image offset and reference grid */ - image->x0 = parameters->image_offset_x0; - image->y0 = parameters->image_offset_y0; - image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : image->x0 + (w - - 1) * subsampling_dx + 1; - image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : image->y0 + (h - - 1) * subsampling_dy + 1; + W = Info_h.biWidth; + H = Info_h.biHeight; + if (Info_h.biWidth % 2) + W++; - /* set image data */ + numcomps = gray_scale ? 1 : 3; + color_space = gray_scale ? OPJ_CLRSPC_GRAY : OPJ_CLRSPC_SRGB; + /* initialize image components */ + memset(&cmptparm[0], 0, 3 * sizeof(opj_image_cmptparm_t)); + for(i = 0; i < numcomps; i++) + { + cmptparm[i].prec = 8; + cmptparm[i].bpp = 8; + cmptparm[i].sgnd = 0; + cmptparm[i].dx = subsampling_dx; + cmptparm[i].dy = subsampling_dy; + cmptparm[i].w = w; + cmptparm[i].h = h; + } + /* create the image */ + image = opj_image_create(numcomps, &cmptparm[0], color_space); + if(!image) + { + fclose(IN); + free(table_R); free(table_G); free(table_B); + return NULL; + } - /* Place the cursor at the beginning of the image information */ - fseek(IN, 0, SEEK_SET); - fseek(IN, File_h.bfOffBits, SEEK_SET); + /* set image offset and reference grid */ + image->x0 = parameters->image_offset_x0; + image->y0 = parameters->image_offset_y0; + image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : image->x0 + (w - 1) * subsampling_dx + 1; + image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : image->y0 + (h - 1) * subsampling_dy + 1; - W = Info_h.biWidth; - H = Info_h.biHeight; - RGB = (unsigned char *) calloc(1, W * H * sizeof(unsigned char)); - beyond = RGB + W * H; - pix = beyond - W; - x = y = 0; + /* set image data */ - while (y < H) - { - c = getc(IN); + RGB = (unsigned char *) malloc(W * H * sizeof(unsigned char)); - if (c) - { - c1 = getc(IN); + if ( fread(RGB, sizeof(unsigned char), W * H, IN) != W * H ) + { + free(table_R); + free(table_G); + free(table_B); + free(RGB); + opj_image_destroy(image); + fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); + return NULL; + } + if (gray_scale) + { + index = 0; + for (j = 0; j < W * H; j++) + { + if ((j % W < W - 1 && Info_h.biWidth % 2) || !(Info_h.biWidth % 2)) + { + image->comps[0].data[index] = + table_R[RGB[W * H - ((j) / (W) + 1) * W + (j) % (W)]]; + index++; + } + } - for (i = 0; i < c && x < W && pix < beyond; i++, x++, pix++) - *pix = (unsigned char)c1; - } - else - { - c = getc(IN); + } + else + { + index = 0; + for (j = 0; j < W * H; j++) + { + if ((j % W < W - 1 && Info_h.biWidth % 2) + || !(Info_h.biWidth % 2)) + { + unsigned char pixel_index = + RGB[W * H - ((j) / (W) + 1) * W + (j) % (W)]; + image->comps[0].data[index] = table_R[pixel_index]; + image->comps[1].data[index] = table_G[pixel_index]; + image->comps[2].data[index] = table_B[pixel_index]; + index++; + } + } + } + free(RGB); + free(table_R); + free(table_G); + free(table_B); + }/* RGB8 */ + else + if (Info_h.biBitCount == 8 && Info_h.biCompression == 1)/*RLE8*/ + { + unsigned char *pix, *beyond; + int *gray, *red, *green, *blue; + unsigned int x, y, max; + int i, c, c1; + unsigned char uc; - if (c == 0x00) /* EOL */ - { - x = 0; - ++y; - pix = RGB + x + (H - y - 1) * W; - } - else if (c == 0x01) /* EOP */ - break; - else if (c == 0x02) /* MOVE by dxdy */ - { - c = getc(IN); - x += c; - c = getc(IN); - y += c; - pix = RGB + (H - y - 1) * W + x; - } - else /* 03 .. 255 */ - { - i = 0; - for (; i < c && x < W && pix < beyond; i++, x++, pix++) - { - c1 = getc(IN); - *pix = (unsigned char)c1; - } - if (c & 1) /* skip padding byte */ - getc(IN); - } - } - }/* while() */ + if (Info_h.biClrUsed == 0) + Info_h.biClrUsed = 256; + else if (Info_h.biClrUsed > 256) + Info_h.biClrUsed = 256; - if (gray_scale) - { - gray = image->comps[0].data; - pix = RGB; - max = W * H; + table_R = (unsigned char *) malloc(256 * sizeof(unsigned char)); + table_G = (unsigned char *) malloc(256 * sizeof(unsigned char)); + table_B = (unsigned char *) malloc(256 * sizeof(unsigned char)); - while (max--) - { - uc = *pix++; + has_color = 0; + for (j = 0; j < Info_h.biClrUsed; j++) + { + table_B[j] = (unsigned char)getc(IN); + table_G[j] = (unsigned char)getc(IN); + table_R[j] = (unsigned char)getc(IN); + getc(IN); + has_color += !(table_R[j] == table_G[j] && table_R[j] == table_B[j]); + } - *gray++ = table_R[uc]; - } - } - else - { - /*int *red, *green, *blue;*/ + if (has_color) + gray_scale = 0; - red = image->comps[0].data; - green = image->comps[1].data; - blue = image->comps[2].data; - pix = RGB; - max = W * H; + numcomps = gray_scale ? 1 : 3; + color_space = gray_scale ? OPJ_CLRSPC_GRAY : OPJ_CLRSPC_SRGB; + /* initialize image components */ + memset(&cmptparm[0], 0, 3 * sizeof(opj_image_cmptparm_t)); + for (i = 0; i < numcomps; i++) + { + cmptparm[i].prec = 8; + cmptparm[i].bpp = 8; + cmptparm[i].sgnd = 0; + cmptparm[i].dx = subsampling_dx; + cmptparm[i].dy = subsampling_dy; + cmptparm[i].w = w; + cmptparm[i].h = h; + } + /* create the image */ + image = opj_image_create(numcomps, &cmptparm[0], color_space); + if (!image) + { + fclose(IN); + free(table_R); + free(table_G); + free(table_B); + return NULL; + } - while (max--) - { - uc = *pix++; + /* set image offset and reference grid */ + image->x0 = parameters->image_offset_x0; + image->y0 = parameters->image_offset_y0; + image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : image->x0 + (w + - 1) * subsampling_dx + 1; + image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : image->y0 + (h + - 1) * subsampling_dy + 1; - *red++ = table_R[uc]; - *green++ = table_G[uc]; - *blue++ = table_B[uc]; - } - } - free(RGB); - free(table_R); - free(table_G); - free(table_B); - }/* RLE8 */ - else - { - fprintf(stderr, - "Other system than 24 bits/pixels or 8 bits (no RLE coding) " - "is not yet implemented [%d]\n", Info_h.biBitCount); - } - fclose(IN); - return image; + /* set image data */ + + /* Place the cursor at the beginning of the image information */ + fseek(IN, 0, SEEK_SET); + fseek(IN, File_h.bfOffBits, SEEK_SET); + + W = Info_h.biWidth; + H = Info_h.biHeight; + RGB = (unsigned char *) calloc(1, W * H * sizeof(unsigned char)); + beyond = RGB + W * H; + pix = beyond - W; + x = y = 0; + + while (y < H) + { + c = getc(IN); + + if (c) + { + c1 = getc(IN); + + for (i = 0; i < c && x < W && pix < beyond; i++, x++, pix++) + *pix = (unsigned char)c1; + } + else + { + c = getc(IN); + + if (c == 0x00) /* EOL */ + { + x = 0; + ++y; + pix = RGB + x + (H - y - 1) * W; + } + else if (c == 0x01) /* EOP */ + break; + else if (c == 0x02) /* MOVE by dxdy */ + { + c = getc(IN); + x += c; + c = getc(IN); + y += c; + pix = RGB + (H - y - 1) * W + x; + } + else /* 03 .. 255 */ + { + i = 0; + for (; i < c && x < W && pix < beyond; i++, x++, pix++) + { + c1 = getc(IN); + *pix = (unsigned char)c1; + } + if (c & 1) /* skip padding byte */ + getc(IN); + } + } + }/* while() */ + + if (gray_scale) + { + gray = image->comps[0].data; + pix = RGB; + max = W * H; + + while (max--) + { + uc = *pix++; + + *gray++ = table_R[uc]; + } + } + else + { + /*int *red, *green, *blue;*/ + + red = image->comps[0].data; + green = image->comps[1].data; + blue = image->comps[2].data; + pix = RGB; + max = W * H; + + while (max--) + { + uc = *pix++; + + *red++ = table_R[uc]; + *green++ = table_G[uc]; + *blue++ = table_B[uc]; + } + } + free(RGB); + free(table_R); + free(table_G); + free(table_B); + }/* RLE8 */ + else + { + fprintf(stderr, + "Other system than 24 bits/pixels or 8 bits (no RLE coding) " + "is not yet implemented [%d]\n", Info_h.biBitCount); + } + fclose(IN); + return image; } int imagetobmp(opj_image_t * image, const char *outfile) { - int w, h; - int i, pad; - FILE *fdest = NULL; - int adjustR, adjustG, adjustB; + int w, h; + int i, pad; + FILE *fdest = NULL; + int adjustR, adjustG, adjustB; - if (image->comps[0].prec < 8) { - fprintf(stderr, "Unsupported number of components: %d\n", image->comps[0].prec); - return 1; - } - if (image->numcomps >= 3 && image->comps[0].dx == image->comps[1].dx - && image->comps[1].dx == image->comps[2].dx - && image->comps[0].dy == image->comps[1].dy - && image->comps[1].dy == image->comps[2].dy - && image->comps[0].prec == image->comps[1].prec - && image->comps[1].prec == image->comps[2].prec) { - - /* -->> -->> -->> -->> - 24 bits color - <<-- <<-- <<-- <<-- */ - - fdest = fopen(outfile, "wb"); - if (!fdest) { - fprintf(stderr, "ERROR -> failed to open %s for writing\n", outfile); - return 1; - } - - w = image->comps[0].w; - h = image->comps[0].h; - - fprintf(fdest, "BM"); - - /* FILE HEADER */ - /* ------------- */ - fprintf(fdest, "%c%c%c%c", - (unsigned char) (h * w * 3 + 3 * h * (w % 2) + 54) & 0xff, - (unsigned char) ((h * w * 3 + 3 * h * (w % 2) + 54) >> 8) & 0xff, - (unsigned char) ((h * w * 3 + 3 * h * (w % 2) + 54) >> 16) & 0xff, - (unsigned char) ((h * w * 3 + 3 * h * (w % 2) + 54) >> 24) & 0xff); - fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, ((0) >> 24) & 0xff); - fprintf(fdest, "%c%c%c%c", (54) & 0xff, ((54) >> 8) & 0xff,((54) >> 16) & 0xff, ((54) >> 24) & 0xff); - - /* INFO HEADER */ - /* ------------- */ - fprintf(fdest, "%c%c%c%c", (40) & 0xff, ((40) >> 8) & 0xff, ((40) >> 16) & 0xff, ((40) >> 24) & 0xff); - fprintf(fdest, "%c%c%c%c", (unsigned char) ((w) & 0xff), - (unsigned char) ((w) >> 8) & 0xff, - (unsigned char) ((w) >> 16) & 0xff, - (unsigned char) ((w) >> 24) & 0xff); - fprintf(fdest, "%c%c%c%c", (unsigned char) ((h) & 0xff), - (unsigned char) ((h) >> 8) & 0xff, - (unsigned char) ((h) >> 16) & 0xff, - (unsigned char) ((h) >> 24) & 0xff); - fprintf(fdest, "%c%c", (1) & 0xff, ((1) >> 8) & 0xff); - fprintf(fdest, "%c%c", (24) & 0xff, ((24) >> 8) & 0xff); - fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, ((0) >> 24) & 0xff); - fprintf(fdest, "%c%c%c%c", (unsigned char) (3 * h * w + 3 * h * (w % 2)) & 0xff, - (unsigned char) ((h * w * 3 + 3 * h * (w % 2)) >> 8) & 0xff, - (unsigned char) ((h * w * 3 + 3 * h * (w % 2)) >> 16) & 0xff, - (unsigned char) ((h * w * 3 + 3 * h * (w % 2)) >> 24) & 0xff); - fprintf(fdest, "%c%c%c%c", (7834) & 0xff, ((7834) >> 8) & 0xff, ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff); - fprintf(fdest, "%c%c%c%c", (7834) & 0xff, ((7834) >> 8) & 0xff, ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff); - fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, ((0) >> 24) & 0xff); - fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, ((0) >> 24) & 0xff); - - if (image->comps[0].prec > 8) { - adjustR = image->comps[0].prec - 8; - printf("BMP CONVERSION: Truncating component 0 from %d bits to 8 bits\n", image->comps[0].prec); - } - else - adjustR = 0; - if (image->comps[1].prec > 8) { - adjustG = image->comps[1].prec - 8; - printf("BMP CONVERSION: Truncating component 1 from %d bits to 8 bits\n", image->comps[1].prec); - } - else - adjustG = 0; - if (image->comps[2].prec > 8) { - adjustB = image->comps[2].prec - 8; - printf("BMP CONVERSION: Truncating component 2 from %d bits to 8 bits\n", image->comps[2].prec); - } - else - adjustB = 0; + if (image->comps[0].prec < 8) { + fprintf(stderr, "Unsupported number of components: %d\n", image->comps[0].prec); + return 1; + } + if (image->numcomps >= 3 && image->comps[0].dx == image->comps[1].dx + && image->comps[1].dx == image->comps[2].dx + && image->comps[0].dy == image->comps[1].dy + && image->comps[1].dy == image->comps[2].dy + && image->comps[0].prec == image->comps[1].prec + && image->comps[1].prec == image->comps[2].prec) { - for (i = 0; i < w * h; i++) { - unsigned char rc, gc, bc; - int r, g, b; - - r = image->comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]; - r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); - r = ((r >> adjustR)+((r >> (adjustR-1))%2)); - if(r > 255) r = 255; else if(r < 0) r = 0; - rc = (unsigned char)r; + /* -->> -->> -->> -->> + 24 bits color + <<-- <<-- <<-- <<-- */ - g = image->comps[1].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]; - g += (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); - g = ((g >> adjustG)+((g >> (adjustG-1))%2)); - if(g > 255) g = 255; else if(g < 0) g = 0; - gc = (unsigned char)g; + fdest = fopen(outfile, "wb"); + if (!fdest) { + fprintf(stderr, "ERROR -> failed to open %s for writing\n", outfile); + return 1; + } - b = image->comps[2].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]; - b += (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); - b = ((b >> adjustB)+((b >> (adjustB-1))%2)); - if(b > 255) b = 255; else if(b < 0) b = 0; - bc = (unsigned char)b; + w = image->comps[0].w; + h = image->comps[0].h; - fprintf(fdest, "%c%c%c", bc, gc, rc); - - if ((i + 1) % w == 0) { - for (pad = (3 * w) % 4 ? 4 - (3 * w) % 4 : 0; pad > 0; pad--) /* ADD */ - fprintf(fdest, "%c", 0); - } - } - fclose(fdest); - } else { /* Gray-scale */ + fprintf(fdest, "BM"); - /* -->> -->> -->> -->> - 8 bits non code (Gray scale) - <<-- <<-- <<-- <<-- */ + /* FILE HEADER */ + /* ------------- */ + fprintf(fdest, "%c%c%c%c", + (unsigned char) (h * w * 3 + 3 * h * (w % 2) + 54) & 0xff, + (unsigned char) ((h * w * 3 + 3 * h * (w % 2) + 54) >> 8) & 0xff, + (unsigned char) ((h * w * 3 + 3 * h * (w % 2) + 54) >> 16) & 0xff, + (unsigned char) ((h * w * 3 + 3 * h * (w % 2) + 54) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, ((0) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (54) & 0xff, ((54) >> 8) & 0xff,((54) >> 16) & 0xff, ((54) >> 24) & 0xff); - fdest = fopen(outfile, "wb"); - w = image->comps[0].w; - h = image->comps[0].h; - - fprintf(fdest, "BM"); - - /* FILE HEADER */ - /* ------------- */ - fprintf(fdest, "%c%c%c%c", (unsigned char) (h * w + 54 + 1024 + h * (w % 2)) & 0xff, - (unsigned char) ((h * w + 54 + 1024 + h * (w % 2)) >> 8) & 0xff, - (unsigned char) ((h * w + 54 + 1024 + h * (w % 2)) >> 16) & 0xff, - (unsigned char) ((h * w + 54 + 1024 + w * (w % 2)) >> 24) & 0xff); - fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, ((0) >> 24) & 0xff); - fprintf(fdest, "%c%c%c%c", (54 + 1024) & 0xff, ((54 + 1024) >> 8) & 0xff, - ((54 + 1024) >> 16) & 0xff, - ((54 + 1024) >> 24) & 0xff); - - /* INFO HEADER */ - /* ------------- */ - fprintf(fdest, "%c%c%c%c", (40) & 0xff, ((40) >> 8) & 0xff, ((40) >> 16) & 0xff, ((40) >> 24) & 0xff); - fprintf(fdest, "%c%c%c%c", (unsigned char) ((w) & 0xff), - (unsigned char) ((w) >> 8) & 0xff, - (unsigned char) ((w) >> 16) & 0xff, - (unsigned char) ((w) >> 24) & 0xff); - fprintf(fdest, "%c%c%c%c", (unsigned char) ((h) & 0xff), - (unsigned char) ((h) >> 8) & 0xff, - (unsigned char) ((h) >> 16) & 0xff, - (unsigned char) ((h) >> 24) & 0xff); - fprintf(fdest, "%c%c", (1) & 0xff, ((1) >> 8) & 0xff); - fprintf(fdest, "%c%c", (8) & 0xff, ((8) >> 8) & 0xff); - fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, ((0) >> 24) & 0xff); - fprintf(fdest, "%c%c%c%c", (unsigned char) (h * w + h * (w % 2)) & 0xff, - (unsigned char) ((h * w + h * (w % 2)) >> 8) & 0xff, - (unsigned char) ((h * w + h * (w % 2)) >> 16) & 0xff, - (unsigned char) ((h * w + h * (w % 2)) >> 24) & 0xff); - fprintf(fdest, "%c%c%c%c", (7834) & 0xff, ((7834) >> 8) & 0xff, ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff); - fprintf(fdest, "%c%c%c%c", (7834) & 0xff, ((7834) >> 8) & 0xff, ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff); - fprintf(fdest, "%c%c%c%c", (256) & 0xff, ((256) >> 8) & 0xff, ((256) >> 16) & 0xff, ((256) >> 24) & 0xff); - fprintf(fdest, "%c%c%c%c", (256) & 0xff, ((256) >> 8) & 0xff, ((256) >> 16) & 0xff, ((256) >> 24) & 0xff); + /* INFO HEADER */ + /* ------------- */ + fprintf(fdest, "%c%c%c%c", (40) & 0xff, ((40) >> 8) & 0xff, ((40) >> 16) & 0xff, ((40) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (unsigned char) ((w) & 0xff), + (unsigned char) ((w) >> 8) & 0xff, + (unsigned char) ((w) >> 16) & 0xff, + (unsigned char) ((w) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (unsigned char) ((h) & 0xff), + (unsigned char) ((h) >> 8) & 0xff, + (unsigned char) ((h) >> 16) & 0xff, + (unsigned char) ((h) >> 24) & 0xff); + fprintf(fdest, "%c%c", (1) & 0xff, ((1) >> 8) & 0xff); + fprintf(fdest, "%c%c", (24) & 0xff, ((24) >> 8) & 0xff); + fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, ((0) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (unsigned char) (3 * h * w + 3 * h * (w % 2)) & 0xff, + (unsigned char) ((h * w * 3 + 3 * h * (w % 2)) >> 8) & 0xff, + (unsigned char) ((h * w * 3 + 3 * h * (w % 2)) >> 16) & 0xff, + (unsigned char) ((h * w * 3 + 3 * h * (w % 2)) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (7834) & 0xff, ((7834) >> 8) & 0xff, ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (7834) & 0xff, ((7834) >> 8) & 0xff, ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, ((0) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, ((0) >> 24) & 0xff); - if (image->comps[0].prec > 8) { - adjustR = image->comps[0].prec - 8; - printf("BMP CONVERSION: Truncating component 0 from %d bits to 8 bits\n", image->comps[0].prec); - }else - adjustR = 0; + if (image->comps[0].prec > 8) { + adjustR = image->comps[0].prec - 8; + printf("BMP CONVERSION: Truncating component 0 from %d bits to 8 bits\n", image->comps[0].prec); + } + else + adjustR = 0; + if (image->comps[1].prec > 8) { + adjustG = image->comps[1].prec - 8; + printf("BMP CONVERSION: Truncating component 1 from %d bits to 8 bits\n", image->comps[1].prec); + } + else + adjustG = 0; + if (image->comps[2].prec > 8) { + adjustB = image->comps[2].prec - 8; + printf("BMP CONVERSION: Truncating component 2 from %d bits to 8 bits\n", image->comps[2].prec); + } + else + adjustB = 0; - for (i = 0; i < 256; i++) { - fprintf(fdest, "%c%c%c%c", i, i, i, 0); - } + for (i = 0; i < w * h; i++) { + unsigned char rc, gc, bc; + int r, g, b; - for (i = 0; i < w * h; i++) { - int r; - - r = image->comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]; - r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); - r = ((r >> adjustR)+((r >> (adjustR-1))%2)); - if(r > 255) r = 255; else if(r < 0) r = 0; + r = image->comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]; + r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); + r = ((r >> adjustR)+((r >> (adjustR-1))%2)); + if(r > 255) r = 255; else if(r < 0) r = 0; + rc = (unsigned char)r; - fprintf(fdest, "%c", (unsigned char)r); + g = image->comps[1].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]; + g += (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); + g = ((g >> adjustG)+((g >> (adjustG-1))%2)); + if(g > 255) g = 255; else if(g < 0) g = 0; + gc = (unsigned char)g; - if ((i + 1) % w == 0) { - for (pad = w % 4 ? 4 - w % 4 : 0; pad > 0; pad--) /* ADD */ - fprintf(fdest, "%c", 0); - } - } - fclose(fdest); - } + b = image->comps[2].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]; + b += (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); + b = ((b >> adjustB)+((b >> (adjustB-1))%2)); + if(b > 255) b = 255; else if(b < 0) b = 0; + bc = (unsigned char)b; - return 0; + fprintf(fdest, "%c%c%c", bc, gc, rc); + + if ((i + 1) % w == 0) { + for (pad = (3 * w) % 4 ? 4 - (3 * w) % 4 : 0; pad > 0; pad--) /* ADD */ + fprintf(fdest, "%c", 0); + } + } + fclose(fdest); + } else { /* Gray-scale */ + + /* -->> -->> -->> -->> + 8 bits non code (Gray scale) + <<-- <<-- <<-- <<-- */ + + fdest = fopen(outfile, "wb"); + w = image->comps[0].w; + h = image->comps[0].h; + + fprintf(fdest, "BM"); + + /* FILE HEADER */ + /* ------------- */ + fprintf(fdest, "%c%c%c%c", (unsigned char) (h * w + 54 + 1024 + h * (w % 2)) & 0xff, + (unsigned char) ((h * w + 54 + 1024 + h * (w % 2)) >> 8) & 0xff, + (unsigned char) ((h * w + 54 + 1024 + h * (w % 2)) >> 16) & 0xff, + (unsigned char) ((h * w + 54 + 1024 + w * (w % 2)) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, ((0) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (54 + 1024) & 0xff, ((54 + 1024) >> 8) & 0xff, + ((54 + 1024) >> 16) & 0xff, + ((54 + 1024) >> 24) & 0xff); + + /* INFO HEADER */ + /* ------------- */ + fprintf(fdest, "%c%c%c%c", (40) & 0xff, ((40) >> 8) & 0xff, ((40) >> 16) & 0xff, ((40) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (unsigned char) ((w) & 0xff), + (unsigned char) ((w) >> 8) & 0xff, + (unsigned char) ((w) >> 16) & 0xff, + (unsigned char) ((w) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (unsigned char) ((h) & 0xff), + (unsigned char) ((h) >> 8) & 0xff, + (unsigned char) ((h) >> 16) & 0xff, + (unsigned char) ((h) >> 24) & 0xff); + fprintf(fdest, "%c%c", (1) & 0xff, ((1) >> 8) & 0xff); + fprintf(fdest, "%c%c", (8) & 0xff, ((8) >> 8) & 0xff); + fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, ((0) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (unsigned char) (h * w + h * (w % 2)) & 0xff, + (unsigned char) ((h * w + h * (w % 2)) >> 8) & 0xff, + (unsigned char) ((h * w + h * (w % 2)) >> 16) & 0xff, + (unsigned char) ((h * w + h * (w % 2)) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (7834) & 0xff, ((7834) >> 8) & 0xff, ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (7834) & 0xff, ((7834) >> 8) & 0xff, ((7834) >> 16) & 0xff, ((7834) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (256) & 0xff, ((256) >> 8) & 0xff, ((256) >> 16) & 0xff, ((256) >> 24) & 0xff); + fprintf(fdest, "%c%c%c%c", (256) & 0xff, ((256) >> 8) & 0xff, ((256) >> 16) & 0xff, ((256) >> 24) & 0xff); + + if (image->comps[0].prec > 8) { + adjustR = image->comps[0].prec - 8; + printf("BMP CONVERSION: Truncating component 0 from %d bits to 8 bits\n", image->comps[0].prec); + }else + adjustR = 0; + + for (i = 0; i < 256; i++) { + fprintf(fdest, "%c%c%c%c", i, i, i, 0); + } + + for (i = 0; i < w * h; i++) { + int r; + + r = image->comps[0].data[w * h - ((i) / (w) + 1) * w + (i) % (w)]; + r += (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); + r = ((r >> adjustR)+((r >> (adjustR-1))%2)); + if(r > 255) r = 255; else if(r < 0) r = 0; + + fprintf(fdest, "%c", (unsigned char)r); + + if ((i + 1) % w == 0) { + for (pad = w % 4 ? 4 - w % 4 : 0; pad > 0; pad--) /* ADD */ + fprintf(fdest, "%c", 0); + } + } + fclose(fdest); + } + + return 0; } /* -->> -->> -->> -->> @@ -1204,263 +1204,263 @@ PGX IMAGE FORMAT static unsigned char readuchar(FILE * f) { - unsigned char c1; - if ( !fread(&c1, 1, 1, f) ) - { - fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); - return 0; - } - return c1; + unsigned char c1; + if ( !fread(&c1, 1, 1, f) ) + { + fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); + return 0; + } + return c1; } static unsigned short readushort(FILE * f, int bigendian) { - unsigned char c1, c2; - if ( !fread(&c1, 1, 1, f) ) - { - fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); - return 0; - } - if ( !fread(&c2, 1, 1, f) ) - { - fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); - return 0; - } - if (bigendian) - return (c1 << 8) + c2; - else - return (c2 << 8) + c1; + unsigned char c1, c2; + if ( !fread(&c1, 1, 1, f) ) + { + fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); + return 0; + } + if ( !fread(&c2, 1, 1, f) ) + { + fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); + return 0; + } + if (bigendian) + return (c1 << 8) + c2; + else + return (c2 << 8) + c1; } static unsigned int readuint(FILE * f, int bigendian) { - unsigned char c1, c2, c3, c4; - if ( !fread(&c1, 1, 1, f) ) - { - fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); - return 0; - } - if ( !fread(&c2, 1, 1, f) ) - { - fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); - return 0; - } - if ( !fread(&c3, 1, 1, f) ) - { - fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); - return 0; - } - if ( !fread(&c4, 1, 1, f) ) - { - fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); - return 0; - } - if (bigendian) - return (c1 << 24) + (c2 << 16) + (c3 << 8) + c4; - else - return (c4 << 24) + (c3 << 16) + (c2 << 8) + c1; + unsigned char c1, c2, c3, c4; + if ( !fread(&c1, 1, 1, f) ) + { + fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); + return 0; + } + if ( !fread(&c2, 1, 1, f) ) + { + fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); + return 0; + } + if ( !fread(&c3, 1, 1, f) ) + { + fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); + return 0; + } + if ( !fread(&c4, 1, 1, f) ) + { + fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); + return 0; + } + if (bigendian) + return (c1 << 24) + (c2 << 16) + (c3 << 8) + c4; + else + return (c4 << 24) + (c3 << 16) + (c2 << 8) + c1; } opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters) { - FILE *f = NULL; - int w, h, prec; - int i, numcomps, max; - OPJ_COLOR_SPACE color_space; - opj_image_cmptparm_t cmptparm; /* maximum of 1 component */ - opj_image_t * image = NULL; - int adjustS, ushift, dshift, force8; + FILE *f = NULL; + int w, h, prec; + int i, numcomps, max; + OPJ_COLOR_SPACE color_space; + opj_image_cmptparm_t cmptparm; /* maximum of 1 component */ + opj_image_t * image = NULL; + int adjustS, ushift, dshift, force8; - char endian1,endian2,sign; - char signtmp[32]; + char endian1,endian2,sign; + char signtmp[32]; - char temp[32]; - int bigendian; - opj_image_comp_t *comp = NULL; + char temp[32]; + int bigendian; + opj_image_comp_t *comp = NULL; - numcomps = 1; - color_space = OPJ_CLRSPC_GRAY; + numcomps = 1; + color_space = OPJ_CLRSPC_GRAY; - memset(&cmptparm, 0, sizeof(opj_image_cmptparm_t)); + memset(&cmptparm, 0, sizeof(opj_image_cmptparm_t)); - max = 0; + max = 0; - f = fopen(filename, "rb"); - if (!f) { - fprintf(stderr, "Failed to open %s for reading !\n", filename); - return NULL; - } + f = fopen(filename, "rb"); + if (!f) { + fprintf(stderr, "Failed to open %s for reading !\n", filename); + return NULL; + } - fseek(f, 0, SEEK_SET); - if( fscanf(f, "PG%[ \t]%c%c%[ \t+-]%d%[ \t]%d%[ \t]%d",temp,&endian1,&endian2,signtmp,&prec,temp,&w,temp,&h) != 9){ - fprintf(stderr, "ERROR: Failed to read the right number of element from the fscanf() function!\n"); - return NULL; - } + fseek(f, 0, SEEK_SET); + if( fscanf(f, "PG%[ \t]%c%c%[ \t+-]%d%[ \t]%d%[ \t]%d",temp,&endian1,&endian2,signtmp,&prec,temp,&w,temp,&h) != 9){ + fprintf(stderr, "ERROR: Failed to read the right number of element from the fscanf() function!\n"); + return NULL; + } - i=0; - sign='+'; - while (signtmp[i]!='\0') { - if (signtmp[i]=='-') sign='-'; - i++; - } - - fgetc(f); - if (endian1=='M' && endian2=='L') { - bigendian = 1; - } else if (endian2=='M' && endian1=='L') { - bigendian = 0; - } else { - fprintf(stderr, "Bad pgx header, please check input file\n"); - return NULL; - } + i=0; + sign='+'; + while (signtmp[i]!='\0') { + if (signtmp[i]=='-') sign='-'; + i++; + } - /* initialize image component */ + fgetc(f); + if (endian1=='M' && endian2=='L') { + bigendian = 1; + } else if (endian2=='M' && endian1=='L') { + bigendian = 0; + } else { + fprintf(stderr, "Bad pgx header, please check input file\n"); + return NULL; + } - cmptparm.x0 = parameters->image_offset_x0; - cmptparm.y0 = parameters->image_offset_y0; - cmptparm.w = !cmptparm.x0 ? (w - 1) * parameters->subsampling_dx + 1 : cmptparm.x0 + (w - 1) * parameters->subsampling_dx + 1; - cmptparm.h = !cmptparm.y0 ? (h - 1) * parameters->subsampling_dy + 1 : cmptparm.y0 + (h - 1) * parameters->subsampling_dy + 1; - - if (sign == '-') { - cmptparm.sgnd = 1; - } else { - cmptparm.sgnd = 0; - } - if(prec < 8) - { - force8 = 1; - ushift = 8 - prec; dshift = prec - ushift; - if(cmptparm.sgnd) adjustS = (1<<(prec - 1)); else adjustS = 0; - cmptparm.sgnd = 0; - prec = 8; - } - else ushift = dshift = force8 = adjustS = 0; + /* initialize image component */ - cmptparm.prec = prec; - cmptparm.bpp = prec; - cmptparm.dx = parameters->subsampling_dx; - cmptparm.dy = parameters->subsampling_dy; - - /* create the image */ - image = opj_image_create(numcomps, &cmptparm, color_space); - if(!image) { - fclose(f); - return NULL; - } - /* set image offset and reference grid */ - image->x0 = cmptparm.x0; - image->y0 = cmptparm.x0; - image->x1 = cmptparm.w; - image->y1 = cmptparm.h; + cmptparm.x0 = parameters->image_offset_x0; + cmptparm.y0 = parameters->image_offset_y0; + cmptparm.w = !cmptparm.x0 ? (w - 1) * parameters->subsampling_dx + 1 : cmptparm.x0 + (w - 1) * parameters->subsampling_dx + 1; + cmptparm.h = !cmptparm.y0 ? (h - 1) * parameters->subsampling_dy + 1 : cmptparm.y0 + (h - 1) * parameters->subsampling_dy + 1; - /* set image data */ + if (sign == '-') { + cmptparm.sgnd = 1; + } else { + cmptparm.sgnd = 0; + } + if(prec < 8) + { + force8 = 1; + ushift = 8 - prec; dshift = prec - ushift; + if(cmptparm.sgnd) adjustS = (1<<(prec - 1)); else adjustS = 0; + cmptparm.sgnd = 0; + prec = 8; + } + else ushift = dshift = force8 = adjustS = 0; - comp = &image->comps[0]; + cmptparm.prec = prec; + cmptparm.bpp = prec; + cmptparm.dx = parameters->subsampling_dx; + cmptparm.dy = parameters->subsampling_dy; - for (i = 0; i < w * h; i++) { - int v; - if(force8) - { - v = readuchar(f) + adjustS; - v = (v<>dshift); - comp->data[i] = (unsigned char)v; + /* create the image */ + image = opj_image_create(numcomps, &cmptparm, color_space); + if(!image) { + fclose(f); + return NULL; + } + /* set image offset and reference grid */ + image->x0 = cmptparm.x0; + image->y0 = cmptparm.x0; + image->x1 = cmptparm.w; + image->y1 = cmptparm.h; - if(v > max) max = v; + /* set image data */ - continue; - } - if (comp->prec == 8) { - if (!comp->sgnd) { - v = readuchar(f); - } else { - v = (char) readuchar(f); - } - } else if (comp->prec <= 16) { - if (!comp->sgnd) { - v = readushort(f, bigendian); - } else { - v = (short) readushort(f, bigendian); - } - } else { - if (!comp->sgnd) { - v = readuint(f, bigendian); - } else { - v = (int) readuint(f, bigendian); - } - } - if (v > max) - max = v; - comp->data[i] = v; - } - fclose(f); - comp->bpp = int_floorlog2(max) + 1; + comp = &image->comps[0]; - return image; + for (i = 0; i < w * h; i++) { + int v; + if(force8) + { + v = readuchar(f) + adjustS; + v = (v<>dshift); + comp->data[i] = (unsigned char)v; + + if(v > max) max = v; + + continue; + } + if (comp->prec == 8) { + if (!comp->sgnd) { + v = readuchar(f); + } else { + v = (char) readuchar(f); + } + } else if (comp->prec <= 16) { + if (!comp->sgnd) { + v = readushort(f, bigendian); + } else { + v = (short) readushort(f, bigendian); + } + } else { + if (!comp->sgnd) { + v = readuint(f, bigendian); + } else { + v = (int) readuint(f, bigendian); + } + } + if (v > max) + max = v; + comp->data[i] = v; + } + fclose(f); + comp->bpp = int_floorlog2(max) + 1; + + return image; } int imagetopgx(opj_image_t * image, const char *outfile) { - int w, h; - int i, j, compno; - FILE *fdest = NULL; + int w, h; + int i, j, compno; + FILE *fdest = NULL; - for (compno = 0; compno < image->numcomps; compno++) { - opj_image_comp_t *comp = &image->comps[compno]; - char bname[256]; /* buffer for name */ - char *name = bname; /* pointer */ - int nbytes = 0; - size_t res; - const size_t olen = strlen(outfile); - const size_t dotpos = olen - 4; - const size_t total = dotpos + 1 + 1 + 4; /* '-' + '[1-3]' + '.pgx' */ - if( outfile[dotpos] != '.' ) { - /* `pgx` was recognized but there is no dot at expected position */ - fprintf(stderr, "ERROR -> Impossible happen." ); - return 1; - } - if( total > 256 ) { - name = (char*)malloc(total+1); - } - strncpy(name, outfile, dotpos); - /*if (image->numcomps > 1) {*/ - sprintf(name+dotpos, "_%d.pgx", compno); - /*} else { - strcpy(name+dotpos, ".pgx"); - }*/ - fdest = fopen(name, "wb"); - if (!fdest) { - fprintf(stderr, "ERROR -> failed to open %s for writing\n", name); - return 1; - } - /* dont need name anymore */ - if( total > 256 ) { - free(name); - } - - w = image->comps[compno].w; - h = image->comps[compno].h; - - fprintf(fdest, "PG ML %c %d %d %d\n", comp->sgnd ? '-' : '+', comp->prec, w, h); - if (comp->prec <= 8) { - nbytes = 1; - } else if (comp->prec <= 16) { - nbytes = 2; - } else { - nbytes = 4; - } - for (i = 0; i < w * h; i++) { - int v = image->comps[compno].data[i]; - for (j = nbytes - 1; j >= 0; j--) { - char byte = (char) (v >> (j * 8)); - res = fwrite(&byte, 1, 1, fdest); - if( res < 1 ) { - fprintf(stderr, "failed to write 1 byte for %s\n", name); - return 1; + for (compno = 0; compno < image->numcomps; compno++) { + opj_image_comp_t *comp = &image->comps[compno]; + char bname[256]; /* buffer for name */ + char *name = bname; /* pointer */ + int nbytes = 0; + size_t res; + const size_t olen = strlen(outfile); + const size_t dotpos = olen - 4; + const size_t total = dotpos + 1 + 1 + 4; /* '-' + '[1-3]' + '.pgx' */ + if( outfile[dotpos] != '.' ) { + /* `pgx` was recognized but there is no dot at expected position */ + fprintf(stderr, "ERROR -> Impossible happen." ); + return 1; + } + if( total > 256 ) { + name = (char*)malloc(total+1); + } + strncpy(name, outfile, dotpos); + /*if (image->numcomps > 1) {*/ + sprintf(name+dotpos, "_%d.pgx", compno); + /*} else { + strcpy(name+dotpos, ".pgx"); + }*/ + fdest = fopen(name, "wb"); + if (!fdest) { + fprintf(stderr, "ERROR -> failed to open %s for writing\n", name); + return 1; + } + /* dont need name anymore */ + if( total > 256 ) { + free(name); } - } - } - fclose(fdest); - } - return 0; + w = image->comps[compno].w; + h = image->comps[compno].h; + + fprintf(fdest, "PG ML %c %d %d %d\n", comp->sgnd ? '-' : '+', comp->prec, w, h); + if (comp->prec <= 8) { + nbytes = 1; + } else if (comp->prec <= 16) { + nbytes = 2; + } else { + nbytes = 4; + } + for (i = 0; i < w * h; i++) { + int v = image->comps[compno].data[i]; + for (j = nbytes - 1; j >= 0; j--) { + char byte = (char) (v >> (j * 8)); + res = fwrite(&byte, 1, 1, fdest); + if( res < 1 ) { + fprintf(stderr, "failed to write 1 byte for %s\n", name); + return 1; + } + } + } + fclose(fdest); + } + + return 0; } /* -->> -->> -->> -->> @@ -1479,11 +1479,11 @@ struct pnm_header static char *skip_white(char *s) { while(*s) - { - if(*s == '\n' || *s == '\r') return NULL; - if(isspace(*s)) { ++s; continue; } - return s; - } + { + if(*s == '\n' || *s == '\r') return NULL; + if(isspace(*s)) { ++s; continue; } + return s; + } return NULL; } @@ -1499,10 +1499,10 @@ static char *skip_int(char *start, int *out_n) start = s; while(*s) - { - if( !isdigit(*s)) break; - ++s; - } + { + if( !isdigit(*s)) break; + ++s; + } c = *s; *s = 0; *out_n = atoi(start); *s = c; return s; } @@ -1517,10 +1517,10 @@ static char *skip_idf(char *start, char out_idf[256]) start = s; while(*s) - { - if(isalpha(*s) || *s == '_') { ++s; continue; } - break; - } + { + if(isalpha(*s) || *s == '_') { ++s; continue; } + break; + } c = *s; *s = 0; strncpy(out_idf, start, 255); *s = c; return s; } @@ -1534,149 +1534,149 @@ static void read_pnm_header(FILE *reader, struct pnm_header *ph) if (fgets(line, 250, reader) == NULL) { - fprintf(stderr,"\nWARNING: fgets return a NULL value"); - return; + fprintf(stderr,"\nWARNING: fgets return a NULL value"); + return; } if(line[0] != 'P') - { - fprintf(stderr,"read_pnm_header:PNM:magic P missing\n"); return; - } + { + fprintf(stderr,"read_pnm_header:PNM:magic P missing\n"); return; + } format = atoi(line + 1); if(format < 1 || format > 7) - { - fprintf(stderr,"read_pnm_header:magic format %d invalid\n", format); - return; - } + { + fprintf(stderr,"read_pnm_header:magic format %d invalid\n", format); + return; + } ph->format = format; ttype = end = have_wh = 0; while(fgets(line, 250, reader)) - { - if(*line == '#') continue; + { + if(*line == '#') continue; - s = line; + s = line; - if(format == 7) - { - s = skip_idf(s, idf); + if(format == 7) + { + s = skip_idf(s, idf); - if(s == NULL || *s == 0) return; + if(s == NULL || *s == 0) return; - if(strcmp(idf, "ENDHDR") == 0) - { - end = 1; break; - } - if(strcmp(idf, "WIDTH") == 0) - { - s = skip_int(s, &ph->width); - if(s == NULL || *s == 0) return; + if(strcmp(idf, "ENDHDR") == 0) + { + end = 1; break; + } + if(strcmp(idf, "WIDTH") == 0) + { + s = skip_int(s, &ph->width); + if(s == NULL || *s == 0) return; - continue; - } - if(strcmp(idf, "HEIGHT") == 0) - { - s = skip_int(s, &ph->height); - if(s == NULL || *s == 0) return; + continue; + } + if(strcmp(idf, "HEIGHT") == 0) + { + s = skip_int(s, &ph->height); + if(s == NULL || *s == 0) return; - continue; - } - if(strcmp(idf, "DEPTH") == 0) - { - s = skip_int(s, &ph->depth); - if(s == NULL || *s == 0) return; + continue; + } + if(strcmp(idf, "DEPTH") == 0) + { + s = skip_int(s, &ph->depth); + if(s == NULL || *s == 0) return; - continue; - } - if(strcmp(idf, "MAXVAL") == 0) - { - s = skip_int(s, &ph->maxval); - if(s == NULL || *s == 0) return; + continue; + } + if(strcmp(idf, "MAXVAL") == 0) + { + s = skip_int(s, &ph->maxval); + if(s == NULL || *s == 0) return; - continue; - } - if(strcmp(idf, "TUPLTYPE") == 0) - { - s = skip_idf(s, type); - if(s == NULL || *s == 0) return; + continue; + } + if(strcmp(idf, "TUPLTYPE") == 0) + { + s = skip_idf(s, type); + if(s == NULL || *s == 0) return; - if(strcmp(type, "BLACKANDWHITE") == 0) - { - ph->bw = 1; ttype = 1; continue; - } - if(strcmp(type, "GRAYSCALE") == 0) - { - ph->gray = 1; ttype = 1; continue; - } - if(strcmp(type, "GRAYSCALE_ALPHA") == 0) - { - ph->graya = 1; ttype = 1; continue; - } - if(strcmp(type, "RGB") == 0) - { - ph->rgb = 1; ttype = 1; continue; - } - if(strcmp(type, "RGB_ALPHA") == 0) - { - ph->rgba = 1; ttype = 1; continue; - } - fprintf(stderr,"read_pnm_header:unknown P7 TUPLTYPE %s\n",type); - return; - } - fprintf(stderr,"read_pnm_header:unknown P7 idf %s\n",idf); - return; - } /* if(format == 7) */ + if(strcmp(type, "BLACKANDWHITE") == 0) + { + ph->bw = 1; ttype = 1; continue; + } + if(strcmp(type, "GRAYSCALE") == 0) + { + ph->gray = 1; ttype = 1; continue; + } + if(strcmp(type, "GRAYSCALE_ALPHA") == 0) + { + ph->graya = 1; ttype = 1; continue; + } + if(strcmp(type, "RGB") == 0) + { + ph->rgb = 1; ttype = 1; continue; + } + if(strcmp(type, "RGB_ALPHA") == 0) + { + ph->rgba = 1; ttype = 1; continue; + } + fprintf(stderr,"read_pnm_header:unknown P7 TUPLTYPE %s\n",type); + return; + } + fprintf(stderr,"read_pnm_header:unknown P7 idf %s\n",idf); + return; + } /* if(format == 7) */ - if( !have_wh) - { - s = skip_int(s, &ph->width); + if( !have_wh) + { + s = skip_int(s, &ph->width); - s = skip_int(s, &ph->height); + s = skip_int(s, &ph->height); - have_wh = 1; + have_wh = 1; - if(format == 1 || format == 4) break; + if(format == 1 || format == 4) break; - continue; - } - if(format == 2 || format == 3 || format == 5 || format == 6) - { -/* P2, P3, P5, P6: */ - s = skip_int(s, &ph->maxval); + continue; + } + if(format == 2 || format == 3 || format == 5 || format == 6) + { + /* P2, P3, P5, P6: */ + s = skip_int(s, &ph->maxval); - if(ph->maxval > 65535) return; - } - break; - }/* while(fgets( ) */ + if(ph->maxval > 65535) return; + } + break; + }/* while(fgets( ) */ if(format == 2 || format == 3 || format > 4) - { - if(ph->maxval < 1 || ph->maxval > 65535) return; - } + { + if(ph->maxval < 1 || ph->maxval > 65535) return; + } if(ph->width < 1 || ph->height < 1) return; if(format == 7) - { - if(!end) - { - fprintf(stderr,"read_pnm_header:P7 without ENDHDR\n"); return; - } - if(ph->depth < 1 || ph->depth > 4) return; + { + if(!end) + { + fprintf(stderr,"read_pnm_header:P7 without ENDHDR\n"); return; + } + if(ph->depth < 1 || ph->depth > 4) return; - if(ph->width && ph->height && ph->depth & ph->maxval && ttype) - ph->ok = 1; - } + if(ph->width && ph->height && ph->depth & ph->maxval && ttype) + ph->ok = 1; + } else - { - if(format != 1 && format != 4) - { - if(ph->width && ph->height && ph->maxval) ph->ok = 1; - } - else - { - if(ph->width && ph->height) ph->ok = 1; - ph->maxval = 255; - } - } + { + if(format != 1 && format != 4) + { + if(ph->width && ph->height && ph->maxval) ph->ok = 1; + } + else + { + if(ph->width && ph->height) ph->ok = 1; + ph->maxval = 255; + } + } } static int has_prec(int val) @@ -1700,31 +1700,31 @@ static int has_prec(int val) } opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters) { - int subsampling_dx = parameters->subsampling_dx; - int subsampling_dy = parameters->subsampling_dy; + int subsampling_dx = parameters->subsampling_dx; + int subsampling_dy = parameters->subsampling_dy; - FILE *fp = NULL; - int i, compno, numcomps, w, h, prec, format; - OPJ_COLOR_SPACE color_space; - opj_image_cmptparm_t cmptparm[4]; /* RGBA: max. 4 components */ - opj_image_t * image = NULL; - struct pnm_header header_info; - - if((fp = fopen(filename, "rb")) == NULL) - { - fprintf(stderr, "pnmtoimage:Failed to open %s for reading!\n",filename); - return NULL; - } - memset(&header_info, 0, sizeof(struct pnm_header)); + FILE *fp = NULL; + int i, compno, numcomps, w, h, prec, format; + OPJ_COLOR_SPACE color_space; + opj_image_cmptparm_t cmptparm[4]; /* RGBA: max. 4 components */ + opj_image_t * image = NULL; + struct pnm_header header_info; - read_pnm_header(fp, &header_info); + if((fp = fopen(filename, "rb")) == NULL) + { + fprintf(stderr, "pnmtoimage:Failed to open %s for reading!\n",filename); + return NULL; + } + memset(&header_info, 0, sizeof(struct pnm_header)); - if(!header_info.ok) { fclose(fp); return NULL; } + read_pnm_header(fp, &header_info); - format = header_info.format; + if(!header_info.ok) { fclose(fp); return NULL; } + + format = header_info.format; switch(format) - { + { case 1: /* ascii bitmap */ case 4: /* raw bitmap */ numcomps = 1; @@ -1742,18 +1742,18 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters) { case 7: /* arbitrary map */ numcomps = header_info.depth; - break; + break; default: fclose(fp); return NULL; - } + } if(numcomps < 3) - color_space = OPJ_CLRSPC_GRAY;/* GRAY, GRAYA */ + color_space = OPJ_CLRSPC_GRAY;/* GRAY, GRAYA */ else - color_space = OPJ_CLRSPC_SRGB;/* RGB, RGBA */ + color_space = OPJ_CLRSPC_SRGB;/* RGB, RGBA */ prec = has_prec(header_info.maxval); - if(prec < 8) prec = 8; + if(prec < 8) prec = 8; w = header_info.width; h = header_info.height; @@ -1763,120 +1763,120 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters) { memset(&cmptparm[0], 0, numcomps * sizeof(opj_image_cmptparm_t)); for(i = 0; i < numcomps; i++) - { - cmptparm[i].prec = prec; - cmptparm[i].bpp = prec; - cmptparm[i].sgnd = 0; - cmptparm[i].dx = subsampling_dx; - cmptparm[i].dy = subsampling_dy; - cmptparm[i].w = w; - cmptparm[i].h = h; - } + { + cmptparm[i].prec = prec; + cmptparm[i].bpp = prec; + cmptparm[i].sgnd = 0; + cmptparm[i].dx = subsampling_dx; + cmptparm[i].dy = subsampling_dy; + cmptparm[i].w = w; + cmptparm[i].h = h; + } image = opj_image_create(numcomps, &cmptparm[0], color_space); if(!image) { fclose(fp); return NULL; } -/* set image offset and reference grid */ - image->x0 = parameters->image_offset_x0; - image->y0 = parameters->image_offset_y0; - image->x1 = parameters->image_offset_x0 + (w - 1) * subsampling_dx + 1; - image->y1 = parameters->image_offset_y0 + (h - 1) * subsampling_dy + 1; + /* set image offset and reference grid */ + image->x0 = parameters->image_offset_x0; + image->y0 = parameters->image_offset_y0; + image->x1 = parameters->image_offset_x0 + (w - 1) * subsampling_dx + 1; + image->y1 = parameters->image_offset_y0 + (h - 1) * subsampling_dy + 1; if((format == 2) || (format == 3)) /* ascii pixmap */ - { - unsigned int index; + { + unsigned int index; - for (i = 0; i < w * h; i++) - { - for(compno = 0; compno < numcomps; compno++) - { - index = 0; - if (fscanf(fp, "%u", &index) != 1) - fprintf(stderr, "\nWARNING: fscanf return a number of element different from the expected.\n"); + for (i = 0; i < w * h; i++) + { + for(compno = 0; compno < numcomps; compno++) + { + index = 0; + if (fscanf(fp, "%u", &index) != 1) + fprintf(stderr, "\nWARNING: fscanf return a number of element different from the expected.\n"); - image->comps[compno].data[i] = (index * 255)/header_info.maxval; - } - } - } + image->comps[compno].data[i] = (index * 255)/header_info.maxval; + } + } + } else - if((format == 5) - || (format == 6) - ||((format == 7) - && ( header_info.gray || header_info.graya - || header_info.rgb || header_info.rgba)))/* binary pixmap */ - { - unsigned char c0, c1, one; + if((format == 5) + || (format == 6) + ||((format == 7) + && ( header_info.gray || header_info.graya + || header_info.rgb || header_info.rgba)))/* binary pixmap */ + { + unsigned char c0, c1, one; - one = (prec < 9); + one = (prec < 9); - for (i = 0; i < w * h; i++) - { - for(compno = 0; compno < numcomps; compno++) - { - if ( !fread(&c0, 1, 1, fp) ) - fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); - if(one) - { - image->comps[compno].data[i] = c0; - } + for (i = 0; i < w * h; i++) + { + for(compno = 0; compno < numcomps; compno++) + { + if ( !fread(&c0, 1, 1, fp) ) + fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); + if(one) + { + image->comps[compno].data[i] = c0; + } + else + { + if ( !fread(&c1, 1, 1, fp) ) + fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); + /* netpbm: */ + image->comps[compno].data[i] = ((c0<<8) | c1); + } + } + } + } else - { - if ( !fread(&c1, 1, 1, fp) ) - fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); -/* netpbm: */ - image->comps[compno].data[i] = ((c0<<8) | c1); - } - } - } - } - else - if(format == 1) /* ascii bitmap */ - { - for (i = 0; i < w * h; i++) - { - unsigned int index; + if(format == 1) /* ascii bitmap */ + { + for (i = 0; i < w * h; i++) + { + unsigned int index; - if ( fscanf(fp, "%u", &index) != 1) - fprintf(stderr, "\nWARNING: fscanf return a number of element different from the expected.\n"); + if ( fscanf(fp, "%u", &index) != 1) + fprintf(stderr, "\nWARNING: fscanf return a number of element different from the expected.\n"); - image->comps[0].data[i] = (index?0:255); - } - } - else - if(format == 4) - { - int x, y, bit; - unsigned char uc; + image->comps[0].data[i] = (index?0:255); + } + } + else + if(format == 4) + { + int x, y, bit; + unsigned char uc; - i = 0; - for(y = 0; y < h; ++y) - { - bit = -1; uc = 0; + i = 0; + for(y = 0; y < h; ++y) + { + bit = -1; uc = 0; - for(x = 0; x < w; ++x) - { - if(bit == -1) - { - bit = 7; - uc = (unsigned char)getc(fp); - } - image->comps[0].data[i] = (((uc>>bit) & 1)?0:255); - --bit; ++i; - } - } - } - else - if((format == 7 && header_info.bw)) /*MONO*/ - { - unsigned char uc; + for(x = 0; x < w; ++x) + { + if(bit == -1) + { + bit = 7; + uc = (unsigned char)getc(fp); + } + image->comps[0].data[i] = (((uc>>bit) & 1)?0:255); + --bit; ++i; + } + } + } + else + if((format == 7 && header_info.bw)) /*MONO*/ + { + unsigned char uc; - for(i = 0; i < w * h; ++i) - { - if ( !fread(&uc, 1, 1, fp) ) - fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); - image->comps[0].data[i] = (uc & 1)?0:255; - } - } + for(i = 0; i < w * h; ++i) + { + if ( !fread(&uc, 1, 1, fp) ) + fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); + image->comps[0].data[i] = (uc & 1)?0:255; + } + } fclose(fp); return image; @@ -1884,563 +1884,563 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters) { int imagetopnm(opj_image_t * image, const char *outfile) { - int *red, *green, *blue, *alpha; - int wr, hr, max; - int i, compno, ncomp; - int adjustR, adjustG, adjustB, adjustA; - int fails, two, want_gray, has_alpha, triple; - int prec, v; - FILE *fdest = NULL; - const char *tmp = outfile; - char *destname; - alpha = NULL; + int *red, *green, *blue, *alpha; + int wr, hr, max; + int i, compno, ncomp; + int adjustR, adjustG, adjustB, adjustA; + int fails, two, want_gray, has_alpha, triple; + int prec, v; + FILE *fdest = NULL; + const char *tmp = outfile; + char *destname; + alpha = NULL; if((prec = image->comps[0].prec) > 16) - { - fprintf(stderr,"%s:%d:imagetopnm\n\tprecision %d is larger than 16" - "\n\t: refused.\n",__FILE__,__LINE__,prec); - return 1; - } + { + fprintf(stderr,"%s:%d:imagetopnm\n\tprecision %d is larger than 16" + "\n\t: refused.\n",__FILE__,__LINE__,prec); + return 1; + } two = has_alpha = 0; fails = 1; - ncomp = image->numcomps; + ncomp = image->numcomps; - while (*tmp) ++tmp; tmp -= 2; - want_gray = (*tmp == 'g' || *tmp == 'G'); - ncomp = image->numcomps; + while (*tmp) ++tmp; tmp -= 2; + want_gray = (*tmp == 'g' || *tmp == 'G'); + ncomp = image->numcomps; - if(want_gray) ncomp = 1; + if(want_gray) ncomp = 1; - if (ncomp == 2 /* GRAYA */ - || (ncomp > 2 /* RGB, RGBA */ - && image->comps[0].dx == image->comps[1].dx - && image->comps[1].dx == image->comps[2].dx - && image->comps[0].dy == image->comps[1].dy - && image->comps[1].dy == image->comps[2].dy - && image->comps[0].prec == image->comps[1].prec - && image->comps[1].prec == image->comps[2].prec - )) - { - fdest = fopen(outfile, "wb"); + if (ncomp == 2 /* GRAYA */ + || (ncomp > 2 /* RGB, RGBA */ + && image->comps[0].dx == image->comps[1].dx + && image->comps[1].dx == image->comps[2].dx + && image->comps[0].dy == image->comps[1].dy + && image->comps[1].dy == image->comps[2].dy + && image->comps[0].prec == image->comps[1].prec + && image->comps[1].prec == image->comps[2].prec + )) + { + fdest = fopen(outfile, "wb"); - if (!fdest) - { - fprintf(stderr, "ERROR -> failed to open %s for writing\n", outfile); - return fails; - } - two = (prec > 8); - triple = (ncomp > 2); - wr = image->comps[0].w; hr = image->comps[0].h; - max = (1< failed to open %s for writing\n", outfile); + return fails; + } + two = (prec > 8); + triple = (ncomp > 2); + wr = image->comps[0].w; hr = image->comps[0].h; + max = (1<comps[0].data; + red = image->comps[0].data; - if(triple) - { - green = image->comps[1].data; - blue = image->comps[2].data; - } - else green = blue = NULL; - - if(has_alpha) - { - const char *tt = (triple?"RGB_ALPHA":"GRAYSCALE_ALPHA"); - - fprintf(fdest, "P7\n# OpenJPEG-%s\nWIDTH %d\nHEIGHT %d\nDEPTH %d\n" - "MAXVAL %d\nTUPLTYPE %s\nENDHDR\n", opj_version(), - wr, hr, ncomp, max, tt); - alpha = image->comps[ncomp - 1].data; - adjustA = (image->comps[ncomp - 1].sgnd ? - 1 << (image->comps[ncomp - 1].prec - 1) : 0); - } - else - { - fprintf(fdest, "P6\n# OpenJPEG-%s\n%d %d\n%d\n", - opj_version(), wr, hr, max); - adjustA = 0; - } - adjustR = (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); - - if(triple) - { - adjustG = (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); - adjustB = (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); - } - else adjustG = adjustB = 0; - - for(i = 0; i < wr * hr; ++i) - { - if(two) - { - v = *red + adjustR; ++red; -/* netpbm: */ - fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v); - - if(triple) - { - v = *green + adjustG; ++green; -/* netpbm: */ - fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v); - - v = *blue + adjustB; ++blue; -/* netpbm: */ - fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v); - - }/* if(triple) */ + if(triple) + { + green = image->comps[1].data; + blue = image->comps[2].data; + } + else green = blue = NULL; if(has_alpha) - { - v = *alpha + adjustA; ++alpha; -/* netpbm: */ - fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v); - } - continue; + { + const char *tt = (triple?"RGB_ALPHA":"GRAYSCALE_ALPHA"); - } /* if(two) */ + fprintf(fdest, "P7\n# OpenJPEG-%s\nWIDTH %d\nHEIGHT %d\nDEPTH %d\n" + "MAXVAL %d\nTUPLTYPE %s\nENDHDR\n", opj_version(), + wr, hr, ncomp, max, tt); + alpha = image->comps[ncomp - 1].data; + adjustA = (image->comps[ncomp - 1].sgnd ? + 1 << (image->comps[ncomp - 1].prec - 1) : 0); + } + else + { + fprintf(fdest, "P6\n# OpenJPEG-%s\n%d %d\n%d\n", + opj_version(), wr, hr, max); + adjustA = 0; + } + adjustR = (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); -/* prec <= 8: */ + if(triple) + { + adjustG = (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); + adjustB = (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); + } + else adjustG = adjustB = 0; - fprintf(fdest, "%c", (unsigned char)*red++); - if(triple) - fprintf(fdest, "%c%c",(unsigned char)*green++, (unsigned char)*blue++); + for(i = 0; i < wr * hr; ++i) + { + if(two) + { + v = *red + adjustR; ++red; + /* netpbm: */ + fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v); - if(has_alpha) - fprintf(fdest, "%c", (unsigned char)*alpha++); + if(triple) + { + v = *green + adjustG; ++green; + /* netpbm: */ + fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v); - } /* for(i */ + v = *blue + adjustB; ++blue; + /* netpbm: */ + fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v); - fclose(fdest); return 0; - } + }/* if(triple) */ -/* YUV or MONO: */ + if(has_alpha) + { + v = *alpha + adjustA; ++alpha; + /* netpbm: */ + fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v); + } + continue; - if (image->numcomps > ncomp) - { - fprintf(stderr,"WARNING -> [PGM file] Only the first component\n"); - fprintf(stderr," is written to the file\n"); - } - destname = (char*)malloc(strlen(outfile) + 8); + } /* if(two) */ - for (compno = 0; compno < ncomp; compno++) - { - if (ncomp > 1) - sprintf(destname, "%d.%s", compno, outfile); - else - sprintf(destname, "%s", outfile); + /* prec <= 8: */ - fdest = fopen(destname, "wb"); - if (!fdest) - { - fprintf(stderr, "ERROR -> failed to open %s for writing\n", destname); - free(destname); - return 1; - } - wr = image->comps[compno].w; hr = image->comps[compno].h; - prec = image->comps[compno].prec; - max = (1<comps[compno].data; - adjustR = - (image->comps[compno].sgnd ? 1 << (image->comps[compno].prec - 1) : 0); + } /* for(i */ - if(prec > 8) - { - for (i = 0; i < wr * hr; i++) - { - v = *red + adjustR; ++red; -/* netpbm: */ - fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v); + fclose(fdest); return 0; + } - if(has_alpha) - { - v = *alpha++; -/* netpbm: */ - fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v); - } - }/* for(i */ - } - else /* prec <= 8 */ - { - for(i = 0; i < wr * hr; ++i) - { - fprintf(fdest, "%c", (unsigned char)(*red + adjustR)); ++red; - } - } - fclose(fdest); - } /* for (compno */ - free(destname); + /* YUV or MONO: */ - return 0; + if (image->numcomps > ncomp) + { + fprintf(stderr,"WARNING -> [PGM file] Only the first component\n"); + fprintf(stderr," is written to the file\n"); + } + destname = (char*)malloc(strlen(outfile) + 8); + + for (compno = 0; compno < ncomp; compno++) + { + if (ncomp > 1) + sprintf(destname, "%d.%s", compno, outfile); + else + sprintf(destname, "%s", outfile); + + fdest = fopen(destname, "wb"); + if (!fdest) + { + fprintf(stderr, "ERROR -> failed to open %s for writing\n", destname); + free(destname); + return 1; + } + wr = image->comps[compno].w; hr = image->comps[compno].h; + prec = image->comps[compno].prec; + max = (1<comps[compno].data; + adjustR = + (image->comps[compno].sgnd ? 1 << (image->comps[compno].prec - 1) : 0); + + if(prec > 8) + { + for (i = 0; i < wr * hr; i++) + { + v = *red + adjustR; ++red; + /* netpbm: */ + fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v); + + if(has_alpha) + { + v = *alpha++; + /* netpbm: */ + fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v); + } + }/* for(i */ + } + else /* prec <= 8 */ + { + for(i = 0; i < wr * hr; ++i) + { + fprintf(fdest, "%c", (unsigned char)(*red + adjustR)); ++red; + } + } + fclose(fdest); + } /* for (compno */ + free(destname); + + return 0; }/* imagetopnm() */ #ifdef OPJ_HAVE_LIBTIFF /* -->> -->> -->> -->> - TIFF IMAGE FORMAT + TIFF IMAGE FORMAT <<-- <<-- <<-- <<-- */ int imagetotif(opj_image_t * image, const char *outfile) { - int width, height, imgsize; - int bps,index,adjust, sgnd; - int ushift, dshift, has_alpha, force16; - TIFF *tif; - tdata_t buf; - tstrip_t strip; - tsize_t strip_size; + int width, height, imgsize; + int bps,index,adjust, sgnd; + int ushift, dshift, has_alpha, force16; + TIFF *tif; + tdata_t buf; + tstrip_t strip; + tsize_t strip_size; - ushift = dshift = force16 = has_alpha = 0; - bps = image->comps[0].prec; + ushift = dshift = force16 = has_alpha = 0; + bps = image->comps[0].prec; - if(bps > 8 && bps < 16) - { - ushift = 16 - bps; dshift = bps - ushift; - bps = 16; force16 = 1; - } + if(bps > 8 && bps < 16) + { + ushift = 16 - bps; dshift = bps - ushift; + bps = 16; force16 = 1; + } - if(bps != 8 && bps != 16) - { - fprintf(stderr,"imagetotif: Bits=%d, Only 8 and 16 bits implemented\n", - bps); - fprintf(stderr,"\tAborting\n"); - return 1; - } - tif = TIFFOpen(outfile, "wb"); + if(bps != 8 && bps != 16) + { + fprintf(stderr,"imagetotif: Bits=%d, Only 8 and 16 bits implemented\n", + bps); + fprintf(stderr,"\tAborting\n"); + return 1; + } + tif = TIFFOpen(outfile, "wb"); - if (!tif) - { - fprintf(stderr, "imagetotif:failed to open %s for writing\n", outfile); - return 1; - } - sgnd = image->comps[0].sgnd; - adjust = sgnd ? 1 << (image->comps[0].prec - 1) : 0; + if (!tif) + { + fprintf(stderr, "imagetotif:failed to open %s for writing\n", outfile); + return 1; + } + sgnd = image->comps[0].sgnd; + adjust = sgnd ? 1 << (image->comps[0].prec - 1) : 0; - if(image->numcomps >= 3 - && image->comps[0].dx == image->comps[1].dx - && image->comps[1].dx == image->comps[2].dx - && image->comps[0].dy == image->comps[1].dy - && image->comps[1].dy == image->comps[2].dy - && image->comps[0].prec == image->comps[1].prec - && image->comps[1].prec == image->comps[2].prec) - { - has_alpha = (image->numcomps == 4); + if(image->numcomps >= 3 + && image->comps[0].dx == image->comps[1].dx + && image->comps[1].dx == image->comps[2].dx + && image->comps[0].dy == image->comps[1].dy + && image->comps[1].dy == image->comps[2].dy + && image->comps[0].prec == image->comps[1].prec + && image->comps[1].prec == image->comps[2].prec) + { + has_alpha = (image->numcomps == 4); - width = image->comps[0].w; - height = image->comps[0].h; - imgsize = width * height ; - - TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width); - TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height); - TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3 + has_alpha); - TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bps); - TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); - TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); - TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB); - TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, 1); - strip_size = TIFFStripSize(tif); - buf = _TIFFmalloc(strip_size); - index=0; + width = image->comps[0].w; + height = image->comps[0].h; + imgsize = width * height ; - for(strip = 0; strip < TIFFNumberOfStrips(tif); strip++) - { - unsigned char *dat8; - tsize_t i, ssize, last_i = 0; - int step, restx; - ssize = TIFFStripSize(tif); - dat8 = (unsigned char*)buf; + TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width); + TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height); + TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 3 + has_alpha); + TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bps); + TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); + TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); + TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_RGB); + TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, 1); + strip_size = TIFFStripSize(tif); + buf = _TIFFmalloc(strip_size); + index=0; - if(bps == 8) - { - step = 3 + has_alpha; - restx = step - 1; + for(strip = 0; strip < TIFFNumberOfStrips(tif); strip++) + { + unsigned char *dat8; + tsize_t i, ssize, last_i = 0; + int step, restx; + ssize = TIFFStripSize(tif); + dat8 = (unsigned char*)buf; - for(i=0; i < ssize - restx; i += step) - { - int r, g, b, a = 0; + if(bps == 8) + { + step = 3 + has_alpha; + restx = step - 1; - if(index < imgsize) - { - r = image->comps[0].data[index]; - g = image->comps[1].data[index]; - b = image->comps[2].data[index]; - if(has_alpha) a = image->comps[3].data[index]; + for(i=0; i < ssize - restx; i += step) + { + int r, g, b, a = 0; - if(sgnd) - { - r += adjust; - g += adjust; - b += adjust; - if(has_alpha) a += adjust; - } - dat8[i+0] = r ; - dat8[i+1] = g ; - dat8[i+2] = b ; - if(has_alpha) dat8[i+3] = a; + if(index < imgsize) + { + r = image->comps[0].data[index]; + g = image->comps[1].data[index]; + b = image->comps[2].data[index]; + if(has_alpha) a = image->comps[3].data[index]; - index++; - last_i = i + step; - } - else - break; - }/*for(i = 0;)*/ + if(sgnd) + { + r += adjust; + g += adjust; + b += adjust; + if(has_alpha) a += adjust; + } + dat8[i+0] = r ; + dat8[i+1] = g ; + dat8[i+2] = b ; + if(has_alpha) dat8[i+3] = a; - if(last_i < ssize) - { - for(i = last_i; i < ssize; i += step) - { - int r, g, b, a = 0; + index++; + last_i = i + step; + } + else + break; + }/*for(i = 0;)*/ - if(index < imgsize) - { - r = image->comps[0].data[index]; - g = image->comps[1].data[index]; - b = image->comps[2].data[index]; - if(has_alpha) a = image->comps[3].data[index]; + if(last_i < ssize) + { + for(i = last_i; i < ssize; i += step) + { + int r, g, b, a = 0; - if(sgnd) - { - r += adjust; - g += adjust; - b += adjust; - if(has_alpha) a += adjust; - } - dat8[i+0] = r ; - if(i+1 < ssize) dat8[i+1] = g ; else break; - if(i+2 < ssize) dat8[i+2] = b ; else break; - if(has_alpha) - { - if(i+3 < ssize) dat8[i+3] = a ; else break; - } - index++; - } - else - break; - }/*for(i)*/ - }/*if(last_i < ssize)*/ + if(index < imgsize) + { + r = image->comps[0].data[index]; + g = image->comps[1].data[index]; + b = image->comps[2].data[index]; + if(has_alpha) a = image->comps[3].data[index]; - } /*if(bps == 8)*/ - else - if(bps == 16) - { - step = 6 + has_alpha + has_alpha; - restx = step - 1; + if(sgnd) + { + r += adjust; + g += adjust; + b += adjust; + if(has_alpha) a += adjust; + } + dat8[i+0] = r ; + if(i+1 < ssize) dat8[i+1] = g ; else break; + if(i+2 < ssize) dat8[i+2] = b ; else break; + if(has_alpha) + { + if(i+3 < ssize) dat8[i+3] = a ; else break; + } + index++; + } + else + break; + }/*for(i)*/ + }/*if(last_i < ssize)*/ - for(i = 0; i < ssize - restx ; i += step) - { - int r, g, b, a = 0; + } /*if(bps == 8)*/ + else + if(bps == 16) + { + step = 6 + has_alpha + has_alpha; + restx = step - 1; - if(index < imgsize) - { - r = image->comps[0].data[index]; - g = image->comps[1].data[index]; - b = image->comps[2].data[index]; - if(has_alpha) a = image->comps[3].data[index]; + for(i = 0; i < ssize - restx ; i += step) + { + int r, g, b, a = 0; - if(sgnd) - { - r += adjust; - g += adjust; - b += adjust; - if(has_alpha) a += adjust; - } - if(force16) - { - r = (r<>dshift); - g = (g<>dshift); - b = (b<>dshift); - if(has_alpha) a = (a<>dshift); - } - dat8[i+0] = r;/*LSB*/ - dat8[i+1] = (r >> 8);/*MSB*/ - dat8[i+2] = g; - dat8[i+3] = (g >> 8); - dat8[i+4] = b; - dat8[i+5] = (b >> 8); - if(has_alpha) - { - dat8[i+6] = a; - dat8[i+7] = (a >> 8); - } - index++; - last_i = i + step; - } - else - break; - }/*for(i = 0;)*/ + if(index < imgsize) + { + r = image->comps[0].data[index]; + g = image->comps[1].data[index]; + b = image->comps[2].data[index]; + if(has_alpha) a = image->comps[3].data[index]; - if(last_i < ssize) - { - for(i = last_i ; i < ssize ; i += step) - { - int r, g, b, a = 0; + if(sgnd) + { + r += adjust; + g += adjust; + b += adjust; + if(has_alpha) a += adjust; + } + if(force16) + { + r = (r<>dshift); + g = (g<>dshift); + b = (b<>dshift); + if(has_alpha) a = (a<>dshift); + } + dat8[i+0] = r;/*LSB*/ + dat8[i+1] = (r >> 8);/*MSB*/ + dat8[i+2] = g; + dat8[i+3] = (g >> 8); + dat8[i+4] = b; + dat8[i+5] = (b >> 8); + if(has_alpha) + { + dat8[i+6] = a; + dat8[i+7] = (a >> 8); + } + index++; + last_i = i + step; + } + else + break; + }/*for(i = 0;)*/ - if(index < imgsize) - { - r = image->comps[0].data[index]; - g = image->comps[1].data[index]; - b = image->comps[2].data[index]; - if(has_alpha) a = image->comps[3].data[index]; + if(last_i < ssize) + { + for(i = last_i ; i < ssize ; i += step) + { + int r, g, b, a = 0; - if(sgnd) - { - r += adjust; - g += adjust; - b += adjust; - if(has_alpha) a += adjust; - } - if(force16) - { - r = (r<>dshift); - g = (g<>dshift); - b = (b<>dshift); - if(has_alpha) a = (a<>dshift); - } - dat8[i+0] = r;/*LSB*/ - if(i+1 < ssize) dat8[i+1] = (r >> 8);else break;/*MSB*/ - if(i+2 < ssize) dat8[i+2] = g; else break; - if(i+3 < ssize) dat8[i+3] = (g >> 8);else break; - if(i+4 < ssize) dat8[i+4] = b; else break; - if(i+5 < ssize) dat8[i+5] = (b >> 8);else break; + if(index < imgsize) + { + r = image->comps[0].data[index]; + g = image->comps[1].data[index]; + b = image->comps[2].data[index]; + if(has_alpha) a = image->comps[3].data[index]; - if(has_alpha) - { - if(i+6 < ssize) dat8[i+6] = a; else break; - if(i+7 < ssize) dat8[i+7] = (a >> 8); else break; - } - index++; - } - else - break; - }/*for(i)*/ - }/*if(last_i < ssize)*/ + if(sgnd) + { + r += adjust; + g += adjust; + b += adjust; + if(has_alpha) a += adjust; + } + if(force16) + { + r = (r<>dshift); + g = (g<>dshift); + b = (b<>dshift); + if(has_alpha) a = (a<>dshift); + } + dat8[i+0] = r;/*LSB*/ + if(i+1 < ssize) dat8[i+1] = (r >> 8);else break;/*MSB*/ + if(i+2 < ssize) dat8[i+2] = g; else break; + if(i+3 < ssize) dat8[i+3] = (g >> 8);else break; + if(i+4 < ssize) dat8[i+4] = b; else break; + if(i+5 < ssize) dat8[i+5] = (b >> 8);else break; - }/*if(bps == 16)*/ - (void)TIFFWriteEncodedStrip(tif, strip, (void*)buf, strip_size); - }/*for(strip = 0; )*/ + if(has_alpha) + { + if(i+6 < ssize) dat8[i+6] = a; else break; + if(i+7 < ssize) dat8[i+7] = (a >> 8); else break; + } + index++; + } + else + break; + }/*for(i)*/ + }/*if(last_i < ssize)*/ - _TIFFfree((void*)buf); - TIFFClose(tif); + }/*if(bps == 16)*/ + (void)TIFFWriteEncodedStrip(tif, strip, (void*)buf, strip_size); + }/*for(strip = 0; )*/ - return 0; - }/*RGB(A)*/ + _TIFFfree((void*)buf); + TIFFClose(tif); - if(image->numcomps == 1 /* GRAY */ - || ( image->numcomps == 2 /* GRAY_ALPHA */ - && image->comps[0].dx == image->comps[1].dx - && image->comps[0].dy == image->comps[1].dy - && image->comps[0].prec == image->comps[1].prec)) - { - int step; + return 0; + }/*RGB(A)*/ - has_alpha = (image->numcomps == 2); + if(image->numcomps == 1 /* GRAY */ + || ( image->numcomps == 2 /* GRAY_ALPHA */ + && image->comps[0].dx == image->comps[1].dx + && image->comps[0].dy == image->comps[1].dy + && image->comps[0].prec == image->comps[1].prec)) + { + int step; - width = image->comps[0].w; - height = image->comps[0].h; - imgsize = width * height; + has_alpha = (image->numcomps == 2); -/* Set tags */ - TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width); - TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height); - TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1 + has_alpha); - TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bps); - TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); - TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); - TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK); - TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, 1); + width = image->comps[0].w; + height = image->comps[0].h; + imgsize = width * height; -/* Get a buffer for the data */ - strip_size = TIFFStripSize(tif); - buf = _TIFFmalloc(strip_size); - index = 0; + /* Set tags */ + TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width); + TIFFSetField(tif, TIFFTAG_IMAGELENGTH, height); + TIFFSetField(tif, TIFFTAG_SAMPLESPERPIXEL, 1 + has_alpha); + TIFFSetField(tif, TIFFTAG_BITSPERSAMPLE, bps); + TIFFSetField(tif, TIFFTAG_ORIENTATION, ORIENTATION_TOPLEFT); + TIFFSetField(tif, TIFFTAG_PLANARCONFIG, PLANARCONFIG_CONTIG); + TIFFSetField(tif, TIFFTAG_PHOTOMETRIC, PHOTOMETRIC_MINISBLACK); + TIFFSetField(tif, TIFFTAG_ROWSPERSTRIP, 1); - for(strip = 0; strip < TIFFNumberOfStrips(tif); strip++) - { - unsigned char *dat8; - tsize_t i, ssize = TIFFStripSize(tif); - dat8 = (unsigned char*)buf; + /* Get a buffer for the data */ + strip_size = TIFFStripSize(tif); + buf = _TIFFmalloc(strip_size); + index = 0; - if(bps == 8) - { - step = 1 + has_alpha; + for(strip = 0; strip < TIFFNumberOfStrips(tif); strip++) + { + unsigned char *dat8; + tsize_t i, ssize = TIFFStripSize(tif); + dat8 = (unsigned char*)buf; - for(i=0; i < ssize; i += step) - { - if(index < imgsize) - { - int r, a = 0; + if(bps == 8) + { + step = 1 + has_alpha; - r = image->comps[0].data[index]; - if(has_alpha) a = image->comps[1].data[index]; + for(i=0; i < ssize; i += step) + { + if(index < imgsize) + { + int r, a = 0; - if(sgnd) - { - r += adjust; - if(has_alpha) a += adjust; - } - dat8[i+0] = r; - if(has_alpha) dat8[i+1] = a; - index++; - } - else - break; - }/*for(i )*/ - }/*if(bps == 8*/ - else - if(bps == 16) - { - step = 2 + has_alpha + has_alpha; + r = image->comps[0].data[index]; + if(has_alpha) a = image->comps[1].data[index]; - for(i=0; i < ssize; i += step) - { - if(index < imgsize) - { - int r, a = 0; + if(sgnd) + { + r += adjust; + if(has_alpha) a += adjust; + } + dat8[i+0] = r; + if(has_alpha) dat8[i+1] = a; + index++; + } + else + break; + }/*for(i )*/ + }/*if(bps == 8*/ + else + if(bps == 16) + { + step = 2 + has_alpha + has_alpha; - r = image->comps[0].data[index]; - if(has_alpha) a = image->comps[1].data[index]; + for(i=0; i < ssize; i += step) + { + if(index < imgsize) + { + int r, a = 0; - if(sgnd) - { - r += adjust; - if(has_alpha) a += adjust; - } - if(force16) - { - r = (r<>dshift); - if(has_alpha) a = (a<>dshift); - } - dat8[i+0] = r;/*LSB*/ - dat8[i+1] = r >> 8;/*MSB*/ - if(has_alpha) - { - dat8[i+2] = a; - dat8[i+3] = a >> 8; - } - index++; - }/*if(index < imgsize)*/ - else - break; - }/*for(i )*/ - } - (void)TIFFWriteEncodedStrip(tif, strip, (void*)buf, strip_size); - }/*for(strip*/ + r = image->comps[0].data[index]; + if(has_alpha) a = image->comps[1].data[index]; - _TIFFfree(buf); - TIFFClose(tif); + if(sgnd) + { + r += adjust; + if(has_alpha) a += adjust; + } + if(force16) + { + r = (r<>dshift); + if(has_alpha) a = (a<>dshift); + } + dat8[i+0] = r;/*LSB*/ + dat8[i+1] = r >> 8;/*MSB*/ + if(has_alpha) + { + dat8[i+2] = a; + dat8[i+3] = a >> 8; + } + index++; + }/*if(index < imgsize)*/ + else + break; + }/*for(i )*/ + } + (void)TIFFWriteEncodedStrip(tif, strip, (void*)buf, strip_size); + }/*for(strip*/ - return 0; - } + _TIFFfree(buf); + TIFFClose(tif); - TIFFClose(tif); + return 0; + } - fprintf(stderr,"imagetotif: Bad color format.\n" - "\tOnly RGB(A) and GRAY(A) has been implemented\n"); - fprintf(stderr,"\tFOUND: numcomps(%d)\n\tAborting\n", - image->numcomps); + TIFFClose(tif); - return 1; + fprintf(stderr,"imagetotif: Bad color format.\n" + "\tOnly RGB(A) and GRAY(A) has been implemented\n"); + fprintf(stderr,"\tFOUND: numcomps(%d)\n\tAborting\n", + image->numcomps); + + return 1; }/* imagetotif() */ /* @@ -2449,349 +2449,349 @@ int imagetotif(opj_image_t * image, const char *outfile) */ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) { - int subsampling_dx = parameters->subsampling_dx; - int subsampling_dy = parameters->subsampling_dy; - TIFF *tif; - tdata_t buf; - tstrip_t strip; - tsize_t strip_size; - int j, numcomps, w, h,index; - OPJ_COLOR_SPACE color_space; - opj_image_cmptparm_t cmptparm[4]; /* RGBA */ - opj_image_t *image = NULL; - int imgsize = 0; - int has_alpha = 0; - unsigned short tiBps, tiPhoto, tiSf, tiSpp, tiPC; - unsigned int tiWidth, tiHeight; + int subsampling_dx = parameters->subsampling_dx; + int subsampling_dy = parameters->subsampling_dy; + TIFF *tif; + tdata_t buf; + tstrip_t strip; + tsize_t strip_size; + int j, numcomps, w, h,index; + OPJ_COLOR_SPACE color_space; + opj_image_cmptparm_t cmptparm[4]; /* RGBA */ + opj_image_t *image = NULL; + int imgsize = 0; + int has_alpha = 0; + unsigned short tiBps, tiPhoto, tiSf, tiSpp, tiPC; + unsigned int tiWidth, tiHeight; - tif = TIFFOpen(filename, "r"); + tif = TIFFOpen(filename, "r"); - if(!tif) - { - fprintf(stderr, "tiftoimage:Failed to open %s for reading\n", filename); - return 0; - } - tiBps = tiPhoto = tiSf = tiSpp = tiPC = 0; - tiWidth = tiHeight = 0; + if(!tif) + { + fprintf(stderr, "tiftoimage:Failed to open %s for reading\n", filename); + return 0; + } + tiBps = tiPhoto = tiSf = tiSpp = tiPC = 0; + tiWidth = tiHeight = 0; - TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &tiWidth); - TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &tiHeight); - TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &tiBps); - TIFFGetField(tif, TIFFTAG_SAMPLEFORMAT, &tiSf); - TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &tiSpp); - TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &tiPhoto); - TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &tiPC); - w= tiWidth; - h= tiHeight; + TIFFGetField(tif, TIFFTAG_IMAGEWIDTH, &tiWidth); + TIFFGetField(tif, TIFFTAG_IMAGELENGTH, &tiHeight); + TIFFGetField(tif, TIFFTAG_BITSPERSAMPLE, &tiBps); + TIFFGetField(tif, TIFFTAG_SAMPLEFORMAT, &tiSf); + TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &tiSpp); + TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &tiPhoto); + TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &tiPC); + w= tiWidth; + h= tiHeight; - if(tiBps != 8 && tiBps != 16 && tiBps != 12) tiBps = 0; - if(tiPhoto != 1 && tiPhoto != 2) tiPhoto = 0; + if(tiBps != 8 && tiBps != 16 && tiBps != 12) tiBps = 0; + if(tiPhoto != 1 && tiPhoto != 2) tiPhoto = 0; if( !tiBps || !tiPhoto) - { - if( !tiBps) - fprintf(stderr,"imagetotif: Bits=%d, Only 8 and 16 bits" - " implemented\n",tiBps); - else - if( !tiPhoto) - fprintf(stderr,"tiftoimage: Bad color format %d.\n\tOnly RGB(A)" - " and GRAY(A) has been implemented\n",(int) tiPhoto); + { + if( !tiBps) + fprintf(stderr,"imagetotif: Bits=%d, Only 8 and 16 bits" + " implemented\n",tiBps); + else + if( !tiPhoto) + fprintf(stderr,"tiftoimage: Bad color format %d.\n\tOnly RGB(A)" + " and GRAY(A) has been implemented\n",(int) tiPhoto); - fprintf(stderr,"\tAborting\n"); - TIFFClose(tif); + fprintf(stderr,"\tAborting\n"); + TIFFClose(tif); - return NULL; - } + return NULL; + } - {/* From: tiff-4.0.x/libtiff/tif_getimage.c : */ - uint16* sampleinfo; - uint16 extrasamples; + {/* From: tiff-4.0.x/libtiff/tif_getimage.c : */ + uint16* sampleinfo; + uint16 extrasamples; - TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES, - &extrasamples, &sampleinfo); + TIFFGetFieldDefaulted(tif, TIFFTAG_EXTRASAMPLES, + &extrasamples, &sampleinfo); - if(extrasamples >= 1) - { - switch(sampleinfo[0]) - { - case EXTRASAMPLE_UNSPECIFIED: -/* Workaround for some images without correct info about alpha channel + if(extrasamples >= 1) + { + switch(sampleinfo[0]) + { + case EXTRASAMPLE_UNSPECIFIED: + /* Workaround for some images without correct info about alpha channel */ - if(tiSpp > 3) - has_alpha = 1; - break; + if(tiSpp > 3) + has_alpha = 1; + break; - case EXTRASAMPLE_ASSOCALPHA: /* data pre-multiplied */ - case EXTRASAMPLE_UNASSALPHA: /* data not pre-multiplied */ - has_alpha = 1; - break; - } - } - else /* extrasamples == 0 */ - if(tiSpp == 4 || tiSpp == 2) has_alpha = 1; - } + case EXTRASAMPLE_ASSOCALPHA: /* data pre-multiplied */ + case EXTRASAMPLE_UNASSALPHA: /* data not pre-multiplied */ + has_alpha = 1; + break; + } + } + else /* extrasamples == 0 */ + if(tiSpp == 4 || tiSpp == 2) has_alpha = 1; + } -/* initialize image components + /* initialize image components */ - memset(&cmptparm[0], 0, 4 * sizeof(opj_image_cmptparm_t)); + memset(&cmptparm[0], 0, 4 * sizeof(opj_image_cmptparm_t)); - if(tiPhoto == PHOTOMETRIC_RGB) /* RGB(A) */ - { - numcomps = 3 + has_alpha; - color_space = OPJ_CLRSPC_SRGB; + if(tiPhoto == PHOTOMETRIC_RGB) /* RGB(A) */ + { + numcomps = 3 + has_alpha; + color_space = OPJ_CLRSPC_SRGB; -/*#define USETILEMODE*/ - for(j = 0; j < numcomps; j++) - { - if(parameters->cp_cinema) - { - cmptparm[j].prec = 12; - cmptparm[j].bpp = 12; - } - else - { - cmptparm[j].prec = tiBps; - cmptparm[j].bpp = tiBps; - } - cmptparm[j].dx = subsampling_dx; - cmptparm[j].dy = subsampling_dy; - cmptparm[j].w = w; - cmptparm[j].h = h; + /*#define USETILEMODE*/ + for(j = 0; j < numcomps; j++) + { + if(parameters->cp_cinema) + { + cmptparm[j].prec = 12; + cmptparm[j].bpp = 12; + } + else + { + cmptparm[j].prec = tiBps; + cmptparm[j].bpp = tiBps; + } + cmptparm[j].dx = subsampling_dx; + cmptparm[j].dy = subsampling_dy; + cmptparm[j].w = w; + cmptparm[j].h = h; #ifdef USETILEMODE - cmptparm[j].x0 = 0; - cmptparm[j].y0 = 0; + cmptparm[j].x0 = 0; + cmptparm[j].y0 = 0; #endif - } + } #ifdef USETILEMODE - image = opj_image_tile_create(numcomps,&cmptparm[0],color_space); + image = opj_image_tile_create(numcomps,&cmptparm[0],color_space); #else - image = opj_image_create(numcomps, &cmptparm[0], color_space); + image = opj_image_create(numcomps, &cmptparm[0], color_space); #endif - if(!image) - { - TIFFClose(tif); - return NULL; - } -/* set image offset and reference grid + if(!image) + { + TIFFClose(tif); + return NULL; + } + /* set image offset and reference grid */ - image->x0 = parameters->image_offset_x0; - image->y0 = parameters->image_offset_y0; - image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : - image->x0 + (w - 1) * subsampling_dx + 1; - image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : - image->y0 + (h - 1) * subsampling_dy + 1; + image->x0 = parameters->image_offset_x0; + image->y0 = parameters->image_offset_y0; + image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : + image->x0 + (w - 1) * subsampling_dx + 1; + image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : + image->y0 + (h - 1) * subsampling_dy + 1; - buf = _TIFFmalloc(TIFFStripSize(tif)); + buf = _TIFFmalloc(TIFFStripSize(tif)); - strip_size=TIFFStripSize(tif); - index = 0; - imgsize = image->comps[0].w * image->comps[0].h ; -/* Read the Image components + strip_size=TIFFStripSize(tif); + index = 0; + imgsize = image->comps[0].w * image->comps[0].h ; + /* Read the Image components */ - for(strip = 0; strip < TIFFNumberOfStrips(tif); strip++) - { - unsigned char *dat8; - int step; - tsize_t i, ssize; - ssize = TIFFReadEncodedStrip(tif, strip, buf, strip_size); - dat8 = (unsigned char*)buf; + for(strip = 0; strip < TIFFNumberOfStrips(tif); strip++) + { + unsigned char *dat8; + int step; + tsize_t i, ssize; + ssize = TIFFReadEncodedStrip(tif, strip, buf, strip_size); + dat8 = (unsigned char*)buf; - if(tiBps == 16) - { - step = 6 + has_alpha + has_alpha; + if(tiBps == 16) + { + step = 6 + has_alpha + has_alpha; - for(i = 0; i < ssize; i += step) - { - if(index < imgsize) - { - image->comps[0].data[index] = ( dat8[i+1] << 8 ) | dat8[i+0]; /* R */ - image->comps[1].data[index] = ( dat8[i+3] << 8 ) | dat8[i+2]; /* G */ - image->comps[2].data[index] = ( dat8[i+5] << 8 ) | dat8[i+4]; /* B */ - if(has_alpha) - image->comps[3].data[index] = ( dat8[i+7] << 8 ) | dat8[i+6]; + for(i = 0; i < ssize; i += step) + { + if(index < imgsize) + { + image->comps[0].data[index] = ( dat8[i+1] << 8 ) | dat8[i+0]; /* R */ + image->comps[1].data[index] = ( dat8[i+3] << 8 ) | dat8[i+2]; /* G */ + image->comps[2].data[index] = ( dat8[i+5] << 8 ) | dat8[i+4]; /* B */ + if(has_alpha) + image->comps[3].data[index] = ( dat8[i+7] << 8 ) | dat8[i+6]; - if(parameters->cp_cinema) - { -/* Rounding 16 to 12 bits + if(parameters->cp_cinema) + { + /* Rounding 16 to 12 bits */ - image->comps[0].data[index] = - (image->comps[0].data[index] + 0x08) >> 4 ; - image->comps[1].data[index] = - (image->comps[1].data[index] + 0x08) >> 4 ; - image->comps[2].data[index] = - (image->comps[2].data[index] + 0x08) >> 4 ; - if(has_alpha) - image->comps[3].data[index] = - (image->comps[3].data[index] + 0x08) >> 4 ; - } - index++; - } - else - break; - }/*for(i = 0)*/ - }/*if(tiBps == 16)*/ - else - if(tiBps == 8) - { - step = 3 + has_alpha; + image->comps[0].data[index] = + (image->comps[0].data[index] + 0x08) >> 4 ; + image->comps[1].data[index] = + (image->comps[1].data[index] + 0x08) >> 4 ; + image->comps[2].data[index] = + (image->comps[2].data[index] + 0x08) >> 4 ; + if(has_alpha) + image->comps[3].data[index] = + (image->comps[3].data[index] + 0x08) >> 4 ; + } + index++; + } + else + break; + }/*for(i = 0)*/ + }/*if(tiBps == 16)*/ + else + if(tiBps == 8) + { + step = 3 + has_alpha; - for(i = 0; i < ssize; i += step) - { - if(index < imgsize) - { + for(i = 0; i < ssize; i += step) + { + if(index < imgsize) + { #ifndef USETILEMODE - image->comps[0].data[index] = dat8[i+0];/* R */ - image->comps[1].data[index] = dat8[i+1];/* G */ - image->comps[2].data[index] = dat8[i+2];/* B */ - if(has_alpha) - image->comps[3].data[index] = dat8[i+3]; + image->comps[0].data[index] = dat8[i+0];/* R */ + image->comps[1].data[index] = dat8[i+1];/* G */ + image->comps[2].data[index] = dat8[i+2];/* B */ + if(has_alpha) + image->comps[3].data[index] = dat8[i+3]; #endif - if(parameters->cp_cinema) - { -/* Rounding 8 to 12 bits + if(parameters->cp_cinema) + { + /* Rounding 8 to 12 bits */ #ifndef USETILEMODE - image->comps[0].data[index] = image->comps[0].data[index] << 4 ; - image->comps[1].data[index] = image->comps[1].data[index] << 4 ; - image->comps[2].data[index] = image->comps[2].data[index] << 4 ; - if(has_alpha) - image->comps[3].data[index] = image->comps[3].data[index] << 4 ; + image->comps[0].data[index] = image->comps[0].data[index] << 4 ; + image->comps[1].data[index] = image->comps[1].data[index] << 4 ; + image->comps[2].data[index] = image->comps[2].data[index] << 4 ; + if(has_alpha) + image->comps[3].data[index] = image->comps[3].data[index] << 4 ; #endif - } - index++; - }/*if(index*/ - else - break; - }/*for(i )*/ - }/*if( tiBps == 8)*/ - else - if(tiBps == 12)/* CINEMA file */ - { - step = 9; + } + index++; + }/*if(index*/ + else + break; + }/*for(i )*/ + }/*if( tiBps == 8)*/ + else + if(tiBps == 12)/* CINEMA file */ + { + step = 9; - for(i = 0; i < ssize; i += step) - { - if((index < imgsize)&(index+1 < imgsize)) - { - image->comps[0].data[index] = ( dat8[i+0]<<4 ) |(dat8[i+1]>>4); - image->comps[1].data[index] = ((dat8[i+1]& 0x0f)<< 8) | dat8[i+2]; + for(i = 0; i < ssize; i += step) + { + if((index < imgsize)&(index+1 < imgsize)) + { + image->comps[0].data[index] = ( dat8[i+0]<<4 ) |(dat8[i+1]>>4); + image->comps[1].data[index] = ((dat8[i+1]& 0x0f)<< 8) | dat8[i+2]; - image->comps[2].data[index] = ( dat8[i+3]<<4) |(dat8[i+4]>>4); - image->comps[0].data[index+1] = ((dat8[i+4]& 0x0f)<< 8) | dat8[i+5]; + image->comps[2].data[index] = ( dat8[i+3]<<4) |(dat8[i+4]>>4); + image->comps[0].data[index+1] = ((dat8[i+4]& 0x0f)<< 8) | dat8[i+5]; - image->comps[1].data[index+1] = ( dat8[i+6] <<4) |(dat8[i+7]>>4); - image->comps[2].data[index+1] = ((dat8[i+7]& 0x0f)<< 8) | dat8[i+8]; + image->comps[1].data[index+1] = ( dat8[i+6] <<4) |(dat8[i+7]>>4); + image->comps[2].data[index+1] = ((dat8[i+7]& 0x0f)<< 8) | dat8[i+8]; - index += 2; - } - else - break; - }/*for(i )*/ - } - }/*for(strip = 0; )*/ + index += 2; + } + else + break; + }/*for(i )*/ + } + }/*for(strip = 0; )*/ - _TIFFfree(buf); - TIFFClose(tif); + _TIFFfree(buf); + TIFFClose(tif); - return image; - }/*RGB(A)*/ + return image; + }/*RGB(A)*/ - if(tiPhoto == PHOTOMETRIC_MINISBLACK) /* GRAY(A) */ - { - numcomps = 1 + has_alpha; - color_space = OPJ_CLRSPC_GRAY; + if(tiPhoto == PHOTOMETRIC_MINISBLACK) /* GRAY(A) */ + { + numcomps = 1 + has_alpha; + color_space = OPJ_CLRSPC_GRAY; - for(j = 0; j < numcomps; ++j) - { - cmptparm[j].prec = tiBps; - cmptparm[j].bpp = tiBps; - cmptparm[j].dx = subsampling_dx; - cmptparm[j].dy = subsampling_dy; - cmptparm[j].w = w; - cmptparm[j].h = h; - } + for(j = 0; j < numcomps; ++j) + { + cmptparm[j].prec = tiBps; + cmptparm[j].bpp = tiBps; + cmptparm[j].dx = subsampling_dx; + cmptparm[j].dy = subsampling_dy; + cmptparm[j].w = w; + cmptparm[j].h = h; + } #ifdef USETILEMODE - image = opj_image_tile_create(numcomps,&cmptparm[0],color_space); + image = opj_image_tile_create(numcomps,&cmptparm[0],color_space); #else - image = opj_image_create(numcomps, &cmptparm[0], color_space); + image = opj_image_create(numcomps, &cmptparm[0], color_space); #endif - if(!image) - { - TIFFClose(tif); - return NULL; - } -/* set image offset and reference grid + if(!image) + { + TIFFClose(tif); + return NULL; + } + /* set image offset and reference grid */ - image->x0 = parameters->image_offset_x0; - image->y0 = parameters->image_offset_y0; - image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : - image->x0 + (w - 1) * subsampling_dx + 1; - image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : - image->y0 + (h - 1) * subsampling_dy + 1; + image->x0 = parameters->image_offset_x0; + image->y0 = parameters->image_offset_y0; + image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : + image->x0 + (w - 1) * subsampling_dx + 1; + image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : + image->y0 + (h - 1) * subsampling_dy + 1; - buf = _TIFFmalloc(TIFFStripSize(tif)); + buf = _TIFFmalloc(TIFFStripSize(tif)); - strip_size = TIFFStripSize(tif); - index = 0; - imgsize = image->comps[0].w * image->comps[0].h ; -/* Read the Image components + strip_size = TIFFStripSize(tif); + index = 0; + imgsize = image->comps[0].w * image->comps[0].h ; + /* Read the Image components */ - for(strip = 0; strip < TIFFNumberOfStrips(tif); strip++) - { - unsigned char *dat8; - tsize_t i, ssize; - int step; + for(strip = 0; strip < TIFFNumberOfStrips(tif); strip++) + { + unsigned char *dat8; + tsize_t i, ssize; + int step; - ssize = TIFFReadEncodedStrip(tif, strip, buf, strip_size); - dat8 = (unsigned char*)buf; + ssize = TIFFReadEncodedStrip(tif, strip, buf, strip_size); + dat8 = (unsigned char*)buf; - if(tiBps == 16) - { - step = 2 + has_alpha + has_alpha; + if(tiBps == 16) + { + step = 2 + has_alpha + has_alpha; - for(i = 0; i < ssize; i += step) - { - if(index < imgsize) - { - image->comps[0].data[index] = ( dat8[i+1] << 8 ) | dat8[i+0]; - if(has_alpha) - image->comps[1].data[index] = ( dat8[i+3] << 8 ) | dat8[i+2]; - index++; - } - else - break; - }/*for(i )*/ - } - else - if(tiBps == 8) - { - step = 1 + has_alpha; + for(i = 0; i < ssize; i += step) + { + if(index < imgsize) + { + image->comps[0].data[index] = ( dat8[i+1] << 8 ) | dat8[i+0]; + if(has_alpha) + image->comps[1].data[index] = ( dat8[i+3] << 8 ) | dat8[i+2]; + index++; + } + else + break; + }/*for(i )*/ + } + else + if(tiBps == 8) + { + step = 1 + has_alpha; - for(i = 0; i < ssize; i += step) - { - if(index < imgsize) - { - image->comps[0].data[index] = dat8[i+0]; - if(has_alpha) - image->comps[1].data[index] = dat8[i+1]; - index++; - } - else - break; - }/*for(i )*/ - } - }/*for(strip = 0;*/ + for(i = 0; i < ssize; i += step) + { + if(index < imgsize) + { + image->comps[0].data[index] = dat8[i+0]; + if(has_alpha) + image->comps[1].data[index] = dat8[i+1]; + index++; + } + else + break; + }/*for(i )*/ + } + }/*for(strip = 0;*/ - _TIFFfree(buf); - TIFFClose(tif); + _TIFFfree(buf); + TIFFClose(tif); - }/*GRAY(A)*/ + }/*GRAY(A)*/ - return image; + return image; }/* tiftoimage() */ @@ -2799,290 +2799,290 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) /* -->> -->> -->> -->> - RAW IMAGE FORMAT + RAW IMAGE FORMAT <<-- <<-- <<-- <<-- */ static opj_image_t* rawtoimage_common(const char *filename, opj_cparameters_t *parameters, raw_cparameters_t *raw_cp, OPJ_BOOL big_endian) { - int subsampling_dx = parameters->subsampling_dx; - int subsampling_dy = parameters->subsampling_dy; + int subsampling_dx = parameters->subsampling_dx; + int subsampling_dy = parameters->subsampling_dy; - FILE *f = NULL; - int i, compno, numcomps, w, h; - OPJ_COLOR_SPACE color_space; - opj_image_cmptparm_t *cmptparm; - opj_image_t * image = NULL; - unsigned short ch; - - if((! (raw_cp->rawWidth & raw_cp->rawHeight & raw_cp->rawComp & raw_cp->rawBitDepth)) == 0) - { - fprintf(stderr,"\nError: invalid raw image parameters\n"); - fprintf(stderr,"Please use the Format option -F:\n"); - fprintf(stderr,"-F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n"); - fprintf(stderr,"Example: -i lena.raw -o lena.j2k -F 512,512,3,8,u\n"); - fprintf(stderr,"Aborting\n"); - return NULL; - } + FILE *f = NULL; + int i, compno, numcomps, w, h; + OPJ_COLOR_SPACE color_space; + opj_image_cmptparm_t *cmptparm; + opj_image_t * image = NULL; + unsigned short ch; - f = fopen(filename, "rb"); - if (!f) { - fprintf(stderr, "Failed to open %s for reading !!\n", filename); - fprintf(stderr,"Aborting\n"); - return NULL; - } - numcomps = raw_cp->rawComp; - color_space = OPJ_CLRSPC_SRGB; - w = raw_cp->rawWidth; - h = raw_cp->rawHeight; - cmptparm = (opj_image_cmptparm_t*) malloc(numcomps * sizeof(opj_image_cmptparm_t)); - - /* initialize image components */ - memset(&cmptparm[0], 0, numcomps * sizeof(opj_image_cmptparm_t)); - for(i = 0; i < numcomps; i++) { - cmptparm[i].prec = raw_cp->rawBitDepth; - cmptparm[i].bpp = raw_cp->rawBitDepth; - cmptparm[i].sgnd = raw_cp->rawSigned; - cmptparm[i].dx = subsampling_dx; - cmptparm[i].dy = subsampling_dy; - cmptparm[i].w = w; - cmptparm[i].h = h; - } - /* create the image */ - image = opj_image_create(numcomps, &cmptparm[0], color_space); - if(!image) { - fclose(f); - return NULL; - } - /* set image offset and reference grid */ - image->x0 = parameters->image_offset_x0; - image->y0 = parameters->image_offset_y0; - image->x1 = parameters->image_offset_x0 + (w - 1) * subsampling_dx + 1; - image->y1 = parameters->image_offset_y0 + (h - 1) * subsampling_dy + 1; + if((! (raw_cp->rawWidth & raw_cp->rawHeight & raw_cp->rawComp & raw_cp->rawBitDepth)) == 0) + { + fprintf(stderr,"\nError: invalid raw image parameters\n"); + fprintf(stderr,"Please use the Format option -F:\n"); + fprintf(stderr,"-F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n"); + fprintf(stderr,"Example: -i lena.raw -o lena.j2k -F 512,512,3,8,u\n"); + fprintf(stderr,"Aborting\n"); + return NULL; + } - if(raw_cp->rawBitDepth <= 8) - { - unsigned char value = 0; - for(compno = 0; compno < numcomps; compno++) { - for (i = 0; i < w * h; i++) { - if (!fread(&value, 1, 1, f)) { - fprintf(stderr,"Error reading raw file. End of file probably reached.\n"); - return NULL; - } - image->comps[compno].data[i] = raw_cp->rawSigned?(char)value:value; - } - } - } - else if(raw_cp->rawBitDepth <= 16) - { - unsigned short value; - for(compno = 0; compno < numcomps; compno++) { - for (i = 0; i < w * h; i++) { - unsigned char temp1; - unsigned char temp2; - if (!fread(&temp1, 1, 1, f)) { - fprintf(stderr,"Error reading raw file. End of file probably reached.\n"); - return NULL; - } - if (!fread(&temp2, 1, 1, f)) { - fprintf(stderr,"Error reading raw file. End of file probably reached.\n"); - return NULL; - } - if( big_endian ) - { - value = temp1 << 8; - value += temp2; - } - else - { - value = temp2 << 8; - value += temp1; - } - image->comps[compno].data[i] = raw_cp->rawSigned?(short)value:value; - } - } - } - else { - fprintf(stderr,"OpenJPEG cannot encode raw components with bit depth higher than 16 bits.\n"); - return NULL; - } + f = fopen(filename, "rb"); + if (!f) { + fprintf(stderr, "Failed to open %s for reading !!\n", filename); + fprintf(stderr,"Aborting\n"); + return NULL; + } + numcomps = raw_cp->rawComp; + color_space = OPJ_CLRSPC_SRGB; + w = raw_cp->rawWidth; + h = raw_cp->rawHeight; + cmptparm = (opj_image_cmptparm_t*) malloc(numcomps * sizeof(opj_image_cmptparm_t)); - if (fread(&ch, 1, 1, f)) { - fprintf(stderr,"Warning. End of raw file not reached... processing anyway\n"); - } - fclose(f); + /* initialize image components */ + memset(&cmptparm[0], 0, numcomps * sizeof(opj_image_cmptparm_t)); + for(i = 0; i < numcomps; i++) { + cmptparm[i].prec = raw_cp->rawBitDepth; + cmptparm[i].bpp = raw_cp->rawBitDepth; + cmptparm[i].sgnd = raw_cp->rawSigned; + cmptparm[i].dx = subsampling_dx; + cmptparm[i].dy = subsampling_dy; + cmptparm[i].w = w; + cmptparm[i].h = h; + } + /* create the image */ + image = opj_image_create(numcomps, &cmptparm[0], color_space); + if(!image) { + fclose(f); + return NULL; + } + /* set image offset and reference grid */ + image->x0 = parameters->image_offset_x0; + image->y0 = parameters->image_offset_y0; + image->x1 = parameters->image_offset_x0 + (w - 1) * subsampling_dx + 1; + image->y1 = parameters->image_offset_y0 + (h - 1) * subsampling_dy + 1; - return image; + if(raw_cp->rawBitDepth <= 8) + { + unsigned char value = 0; + for(compno = 0; compno < numcomps; compno++) { + for (i = 0; i < w * h; i++) { + if (!fread(&value, 1, 1, f)) { + fprintf(stderr,"Error reading raw file. End of file probably reached.\n"); + return NULL; + } + image->comps[compno].data[i] = raw_cp->rawSigned?(char)value:value; + } + } + } + else if(raw_cp->rawBitDepth <= 16) + { + unsigned short value; + for(compno = 0; compno < numcomps; compno++) { + for (i = 0; i < w * h; i++) { + unsigned char temp1; + unsigned char temp2; + if (!fread(&temp1, 1, 1, f)) { + fprintf(stderr,"Error reading raw file. End of file probably reached.\n"); + return NULL; + } + if (!fread(&temp2, 1, 1, f)) { + fprintf(stderr,"Error reading raw file. End of file probably reached.\n"); + return NULL; + } + if( big_endian ) + { + value = temp1 << 8; + value += temp2; + } + else + { + value = temp2 << 8; + value += temp1; + } + image->comps[compno].data[i] = raw_cp->rawSigned?(short)value:value; + } + } + } + else { + fprintf(stderr,"OpenJPEG cannot encode raw components with bit depth higher than 16 bits.\n"); + return NULL; + } + + if (fread(&ch, 1, 1, f)) { + fprintf(stderr,"Warning. End of raw file not reached... processing anyway\n"); + } + fclose(f); + + return image; } opj_image_t* rawltoimage(const char *filename, opj_cparameters_t *parameters, raw_cparameters_t *raw_cp) { - return rawtoimage_common(filename, parameters, raw_cp, OPJ_FALSE); + return rawtoimage_common(filename, parameters, raw_cp, OPJ_FALSE); } opj_image_t* rawtoimage(const char *filename, opj_cparameters_t *parameters, raw_cparameters_t *raw_cp) { - return rawtoimage_common(filename, parameters, raw_cp, OPJ_TRUE); + return rawtoimage_common(filename, parameters, raw_cp, OPJ_TRUE); } static int imagetoraw_common(opj_image_t * image, const char *outfile, OPJ_BOOL big_endian) { - FILE *rawFile = NULL; - size_t res; - int compno; - int w, h; - int line, row; - int *ptr; + FILE *rawFile = NULL; + size_t res; + int compno; + int w, h; + int line, row; + int *ptr; - if((image->numcomps * image->x1 * image->y1) == 0) - { - fprintf(stderr,"\nError: invalid raw image parameters\n"); - return 1; - } + if((image->numcomps * image->x1 * image->y1) == 0) + { + fprintf(stderr,"\nError: invalid raw image parameters\n"); + return 1; + } - rawFile = fopen(outfile, "wb"); - if (!rawFile) { - fprintf(stderr, "Failed to open %s for writing !!\n", outfile); - return 1; - } + rawFile = fopen(outfile, "wb"); + if (!rawFile) { + fprintf(stderr, "Failed to open %s for writing !!\n", outfile); + return 1; + } - fprintf(stdout,"Raw image characteristics: %d components\n", image->numcomps); + fprintf(stdout,"Raw image characteristics: %d components\n", image->numcomps); - for(compno = 0; compno < image->numcomps; compno++) - { - fprintf(stdout,"Component %d characteristics: %dx%dx%d %s\n", compno, image->comps[compno].w, - image->comps[compno].h, image->comps[compno].prec, image->comps[compno].sgnd==1 ? "signed": "unsigned"); + for(compno = 0; compno < image->numcomps; compno++) + { + fprintf(stdout,"Component %d characteristics: %dx%dx%d %s\n", compno, image->comps[compno].w, + image->comps[compno].h, image->comps[compno].prec, image->comps[compno].sgnd==1 ? "signed": "unsigned"); - w = image->comps[compno].w; - h = image->comps[compno].h; + w = image->comps[compno].w; + h = image->comps[compno].h; - if(image->comps[compno].prec <= 8) - { - if(image->comps[compno].sgnd == 1) - { - signed char curr; - int mask = (1 << image->comps[compno].prec) - 1; - ptr = image->comps[compno].data; - for (line = 0; line < h; line++) { - for(row = 0; row < w; row++) { - curr = (signed char) (*ptr & mask); - res = fwrite(&curr, sizeof(signed char), 1, rawFile); - if( res < 1 ) { - fprintf(stderr, "failed to write 1 byte for %s\n", outfile); - return 1; + if(image->comps[compno].prec <= 8) + { + if(image->comps[compno].sgnd == 1) + { + signed char curr; + int mask = (1 << image->comps[compno].prec) - 1; + ptr = image->comps[compno].data; + for (line = 0; line < h; line++) { + for(row = 0; row < w; row++) { + curr = (signed char) (*ptr & mask); + res = fwrite(&curr, sizeof(signed char), 1, rawFile); + if( res < 1 ) { + fprintf(stderr, "failed to write 1 byte for %s\n", outfile); + return 1; + } + ptr++; + } + } } - ptr++; - } - } - } - else if(image->comps[compno].sgnd == 0) - { - unsigned char curr; - int mask = (1 << image->comps[compno].prec) - 1; - ptr = image->comps[compno].data; - for (line = 0; line < h; line++) { - for(row = 0; row < w; row++) { - curr = (unsigned char) (*ptr & mask); - res = fwrite(&curr, sizeof(unsigned char), 1, rawFile); - if( res < 1 ) { - fprintf(stderr, "failed to write 1 byte for %s\n", outfile); - return 1; + else if(image->comps[compno].sgnd == 0) + { + unsigned char curr; + int mask = (1 << image->comps[compno].prec) - 1; + ptr = image->comps[compno].data; + for (line = 0; line < h; line++) { + for(row = 0; row < w; row++) { + curr = (unsigned char) (*ptr & mask); + res = fwrite(&curr, sizeof(unsigned char), 1, rawFile); + if( res < 1 ) { + fprintf(stderr, "failed to write 1 byte for %s\n", outfile); + return 1; + } + ptr++; + } + } } - ptr++; - } - } - } - } - else if(image->comps[compno].prec <= 16) - { - if(image->comps[compno].sgnd == 1) - { - signed short int curr; - int mask = (1 << image->comps[compno].prec) - 1; - ptr = image->comps[compno].data; - for (line = 0; line < h; line++) { - for(row = 0; row < w; row++) { - unsigned char temp1; - unsigned char temp2; - curr = (signed short int) (*ptr & mask); - if( big_endian ) - { - temp1 = (unsigned char) (curr >> 8); - temp2 = (unsigned char) curr; - } - else - { - temp2 = (unsigned char) (curr >> 8); - temp1 = (unsigned char) curr; - } - res = fwrite(&temp1, 1, 1, rawFile); - if( res < 1 ) { - fprintf(stderr, "failed to write 1 byte for %s\n", outfile); - return 1; + } + else if(image->comps[compno].prec <= 16) + { + if(image->comps[compno].sgnd == 1) + { + signed short int curr; + int mask = (1 << image->comps[compno].prec) - 1; + ptr = image->comps[compno].data; + for (line = 0; line < h; line++) { + for(row = 0; row < w; row++) { + unsigned char temp1; + unsigned char temp2; + curr = (signed short int) (*ptr & mask); + if( big_endian ) + { + temp1 = (unsigned char) (curr >> 8); + temp2 = (unsigned char) curr; + } + else + { + temp2 = (unsigned char) (curr >> 8); + temp1 = (unsigned char) curr; + } + res = fwrite(&temp1, 1, 1, rawFile); + if( res < 1 ) { + fprintf(stderr, "failed to write 1 byte for %s\n", outfile); + return 1; + } + res = fwrite(&temp2, 1, 1, rawFile); + if( res < 1 ) { + fprintf(stderr, "failed to write 1 byte for %s\n", outfile); + return 1; + } + ptr++; + } + } } - res = fwrite(&temp2, 1, 1, rawFile); - if( res < 1 ) { - fprintf(stderr, "failed to write 1 byte for %s\n", outfile); - return 1; + else if(image->comps[compno].sgnd == 0) + { + unsigned short int curr; + int mask = (1 << image->comps[compno].prec) - 1; + ptr = image->comps[compno].data; + for (line = 0; line < h; line++) { + for(row = 0; row < w; row++) { + unsigned char temp1; + unsigned char temp2; + curr = (unsigned short int) (*ptr & mask); + if( big_endian ) + { + temp1 = (unsigned char) (curr >> 8); + temp2 = (unsigned char) curr; + } + else + { + temp2 = (unsigned char) (curr >> 8); + temp1 = (unsigned char) curr; + } + res = fwrite(&temp1, 1, 1, rawFile); + if( res < 1 ) { + fprintf(stderr, "failed to write 1 byte for %s\n", outfile); + return 1; + } + res = fwrite(&temp2, 1, 1, rawFile); + if( res < 1 ) { + fprintf(stderr, "failed to write 1 byte for %s\n", outfile); + return 1; + } + ptr++; + } + } } - ptr++; - } - } - } - else if(image->comps[compno].sgnd == 0) - { - unsigned short int curr; - int mask = (1 << image->comps[compno].prec) - 1; - ptr = image->comps[compno].data; - for (line = 0; line < h; line++) { - for(row = 0; row < w; row++) { - unsigned char temp1; - unsigned char temp2; - curr = (unsigned short int) (*ptr & mask); - if( big_endian ) - { - temp1 = (unsigned char) (curr >> 8); - temp2 = (unsigned char) curr; - } - else - { - temp2 = (unsigned char) (curr >> 8); - temp1 = (unsigned char) curr; - } - res = fwrite(&temp1, 1, 1, rawFile); - if( res < 1 ) { - fprintf(stderr, "failed to write 1 byte for %s\n", outfile); - return 1; - } - res = fwrite(&temp2, 1, 1, rawFile); - if( res < 1 ) { - fprintf(stderr, "failed to write 1 byte for %s\n", outfile); - return 1; - } - ptr++; - } - } - } - } - else if (image->comps[compno].prec <= 32) - { - fprintf(stderr,"More than 16 bits per component no handled yet\n"); - return 1; - } - else - { - fprintf(stderr,"Error: invalid precision: %d\n", image->comps[compno].prec); - return 1; - } - } - fclose(rawFile); - return 0; + } + else if (image->comps[compno].prec <= 32) + { + fprintf(stderr,"More than 16 bits per component no handled yet\n"); + return 1; + } + else + { + fprintf(stderr,"Error: invalid precision: %d\n", image->comps[compno].prec); + return 1; + } + } + fclose(rawFile); + return 0; } int imagetoraw(opj_image_t * image, const char *outfile) { - return imagetoraw_common(image, outfile, OPJ_TRUE); + return imagetoraw_common(image, outfile, OPJ_TRUE); } int imagetorawl(opj_image_t * image, const char *outfile) { - return imagetoraw_common(image, outfile, OPJ_FALSE); + return imagetoraw_common(image, outfile, OPJ_FALSE); } #ifdef OPJ_HAVE_LIBPNG @@ -3093,257 +3093,257 @@ int imagetorawl(opj_image_t * image, const char *outfile) opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params) { - png_structp png; - png_infop info; - double gamma, display_exponent; - int bit_depth, interlace_type,compression_type, filter_type; - int unit; - png_uint_32 resx, resy; - unsigned int i, j; - png_uint_32 width, height; - int color_type, has_alpha, is16; - unsigned char *s; - FILE *reader; - unsigned char **rows; -/* j2k: */ - opj_image_t *image; - opj_image_cmptparm_t cmptparm[4]; - int sub_dx, sub_dy; - unsigned int nr_comp; - int *r, *g, *b, *a; - unsigned char sigbuf[8]; + png_structp png; + png_infop info; + double gamma, display_exponent; + int bit_depth, interlace_type,compression_type, filter_type; + int unit; + png_uint_32 resx, resy; + unsigned int i, j; + png_uint_32 width, height; + int color_type, has_alpha, is16; + unsigned char *s; + FILE *reader; + unsigned char **rows; + /* j2k: */ + opj_image_t *image; + opj_image_cmptparm_t cmptparm[4]; + int sub_dx, sub_dy; + unsigned int nr_comp; + int *r, *g, *b, *a; + unsigned char sigbuf[8]; - if((reader = fopen(read_idf, "rb")) == NULL) - { - fprintf(stderr,"pngtoimage: can not open %s\n",read_idf); - return NULL; - } - image = NULL; png = NULL; rows = NULL; + if((reader = fopen(read_idf, "rb")) == NULL) + { + fprintf(stderr,"pngtoimage: can not open %s\n",read_idf); + return NULL; + } + image = NULL; png = NULL; rows = NULL; - if(fread(sigbuf, 1, MAGIC_SIZE, reader) != MAGIC_SIZE - || memcmp(sigbuf, PNG_MAGIC, MAGIC_SIZE) != 0) - { - fprintf(stderr,"pngtoimage: %s is no valid PNG file\n",read_idf); - goto fin; - } -/* libpng-VERSION/example.c: + if(fread(sigbuf, 1, MAGIC_SIZE, reader) != MAGIC_SIZE + || memcmp(sigbuf, PNG_MAGIC, MAGIC_SIZE) != 0) + { + fprintf(stderr,"pngtoimage: %s is no valid PNG file\n",read_idf); + goto fin; + } + /* libpng-VERSION/example.c: * PC : screen_gamma = 2.2; * Mac: screen_gamma = 1.7 or 1.0; */ - display_exponent = 2.2; + display_exponent = 2.2; - if((png = png_create_read_struct(PNG_LIBPNG_VER_STRING, - NULL, NULL, NULL)) == NULL) - goto fin; - if((info = png_create_info_struct(png)) == NULL) - goto fin; + if((png = png_create_read_struct(PNG_LIBPNG_VER_STRING, + NULL, NULL, NULL)) == NULL) + goto fin; + if((info = png_create_info_struct(png)) == NULL) + goto fin; - if(setjmp(png_jmpbuf(png))) - goto fin; + if(setjmp(png_jmpbuf(png))) + goto fin; - png_init_io(png, reader); - png_set_sig_bytes(png, MAGIC_SIZE); + png_init_io(png, reader); + png_set_sig_bytes(png, MAGIC_SIZE); - png_read_info(png, info); + png_read_info(png, info); - if(png_get_IHDR(png, info, &width, &height, - &bit_depth, &color_type, &interlace_type, - &compression_type, &filter_type) == 0) - goto fin; + if(png_get_IHDR(png, info, &width, &height, + &bit_depth, &color_type, &interlace_type, + &compression_type, &filter_type) == 0) + goto fin; -/* png_set_expand(): + /* png_set_expand(): * expand paletted images to RGB, expand grayscale images of * less than 8-bit depth to 8-bit depth, and expand tRNS chunks * to alpha channels. */ - if(color_type == PNG_COLOR_TYPE_PALETTE) - png_set_expand(png); - else - if(color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) - png_set_expand(png); + if(color_type == PNG_COLOR_TYPE_PALETTE) + png_set_expand(png); + else + if(color_type == PNG_COLOR_TYPE_GRAY && bit_depth < 8) + png_set_expand(png); - if(png_get_valid(png, info, PNG_INFO_tRNS)) - png_set_expand(png); + if(png_get_valid(png, info, PNG_INFO_tRNS)) + png_set_expand(png); - is16 = (bit_depth == 16); + is16 = (bit_depth == 16); -/* GRAY => RGB; GRAY_ALPHA => RGBA + /* GRAY => RGB; GRAY_ALPHA => RGBA */ - if(color_type == PNG_COLOR_TYPE_GRAY - || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) - { - png_set_gray_to_rgb(png); - color_type = - (color_type == PNG_COLOR_TYPE_GRAY? PNG_COLOR_TYPE_RGB: - PNG_COLOR_TYPE_RGB_ALPHA); - } - if( !png_get_gAMA(png, info, &gamma)) - gamma = 0.45455; + if(color_type == PNG_COLOR_TYPE_GRAY + || color_type == PNG_COLOR_TYPE_GRAY_ALPHA) + { + png_set_gray_to_rgb(png); + color_type = + (color_type == PNG_COLOR_TYPE_GRAY? PNG_COLOR_TYPE_RGB: + PNG_COLOR_TYPE_RGB_ALPHA); + } + if( !png_get_gAMA(png, info, &gamma)) + gamma = 0.45455; - png_set_gamma(png, display_exponent, gamma); + png_set_gamma(png, display_exponent, gamma); - png_read_update_info(png, info); + png_read_update_info(png, info); - png_get_pHYs(png, info, &resx, &resy, &unit); + png_get_pHYs(png, info, &resx, &resy, &unit); - color_type = png_get_color_type(png, info); + color_type = png_get_color_type(png, info); - has_alpha = (color_type == PNG_COLOR_TYPE_RGB_ALPHA); + has_alpha = (color_type == PNG_COLOR_TYPE_RGB_ALPHA); - nr_comp = 3 + has_alpha; + nr_comp = 3 + has_alpha; - bit_depth = png_get_bit_depth(png, info); + bit_depth = png_get_bit_depth(png, info); - rows = (unsigned char**)calloc(height+1, sizeof(unsigned char*)); - for(i = 0; i < height; ++i) - rows[i] = (unsigned char*)malloc(png_get_rowbytes(png,info)); + rows = (unsigned char**)calloc(height+1, sizeof(unsigned char*)); + for(i = 0; i < height; ++i) + rows[i] = (unsigned char*)malloc(png_get_rowbytes(png,info)); - png_read_image(png, rows); + png_read_image(png, rows); - memset(&cmptparm, 0, 4 * sizeof(opj_image_cmptparm_t)); + memset(&cmptparm, 0, 4 * sizeof(opj_image_cmptparm_t)); - sub_dx = params->subsampling_dx; sub_dy = params->subsampling_dy; + sub_dx = params->subsampling_dx; sub_dy = params->subsampling_dy; - for(i = 0; i < nr_comp; ++i) - { - cmptparm[i].prec = bit_depth; -/* bits_per_pixel: 8 or 16 */ - cmptparm[i].bpp = bit_depth; - cmptparm[i].sgnd = 0; - cmptparm[i].dx = sub_dx; - cmptparm[i].dy = sub_dy; - cmptparm[i].w = width; - cmptparm[i].h = height; - } + for(i = 0; i < nr_comp; ++i) + { + cmptparm[i].prec = bit_depth; + /* bits_per_pixel: 8 or 16 */ + cmptparm[i].bpp = bit_depth; + cmptparm[i].sgnd = 0; + cmptparm[i].dx = sub_dx; + cmptparm[i].dy = sub_dy; + cmptparm[i].w = width; + cmptparm[i].h = height; + } - image = opj_image_create(nr_comp, &cmptparm[0], OPJ_CLRSPC_SRGB); + image = opj_image_create(nr_comp, &cmptparm[0], OPJ_CLRSPC_SRGB); - if(image == NULL) goto fin; + if(image == NULL) goto fin; image->x0 = params->image_offset_x0; image->y0 = params->image_offset_y0; image->x1 = image->x0 + (width - 1) * sub_dx + 1 + image->x0; image->y1 = image->y0 + (height - 1) * sub_dy + 1 + image->y0; - r = image->comps[0].data; - g = image->comps[1].data; - b = image->comps[2].data; - a = image->comps[3].data; + r = image->comps[0].data; + g = image->comps[1].data; + b = image->comps[2].data; + a = image->comps[3].data; - for(i = 0; i < height; ++i) - { - s = rows[i]; + for(i = 0; i < height; ++i) + { + s = rows[i]; - for(j = 0; j < width; ++j) - { - if(is16) - { - *r++ = s[0]<<8|s[1]; s += 2; + for(j = 0; j < width; ++j) + { + if(is16) + { + *r++ = s[0]<<8|s[1]; s += 2; - *g++ = s[0]<<8|s[1]; s += 2; - - *b++ = s[0]<<8|s[1]; s += 2; - - if(has_alpha) { *a++ = s[0]<<8|s[1]; s += 2; } + *g++ = s[0]<<8|s[1]; s += 2; - continue; - } - *r++ = *s++; *g++ = *s++; *b++ = *s++; + *b++ = s[0]<<8|s[1]; s += 2; - if(has_alpha) *a++ = *s++; - } - } + if(has_alpha) { *a++ = s[0]<<8|s[1]; s += 2; } + + continue; + } + *r++ = *s++; *g++ = *s++; *b++ = *s++; + + if(has_alpha) *a++ = *s++; + } + } fin: - if(rows) - { - for(i = 0; i < height; ++i) - free(rows[i]); - free(rows); - } - if(png) - png_destroy_read_struct(&png, &info, NULL); + if(rows) + { + for(i = 0; i < height; ++i) + free(rows[i]); + free(rows); + } + if(png) + png_destroy_read_struct(&png, &info, NULL); - fclose(reader); + fclose(reader); - return image; + return image; }/* pngtoimage() */ int imagetopng(opj_image_t * image, const char *write_idf) { - FILE *writer; - png_structp png; - png_infop info; - int *red, *green, *blue, *alpha; - unsigned char *row_buf, *d; - int has_alpha, width, height, nr_comp, color_type; - int adjustR, adjustG, adjustB, adjustA, x, y, fails; - int prec, ushift, dshift, is16, force16, force8; - unsigned short mask = 0xffff; - png_color_8 sig_bit; + FILE *writer; + png_structp png; + png_infop info; + int *red, *green, *blue, *alpha; + unsigned char *row_buf, *d; + int has_alpha, width, height, nr_comp, color_type; + int adjustR, adjustG, adjustB, adjustA, x, y, fails; + int prec, ushift, dshift, is16, force16, force8; + unsigned short mask = 0xffff; + png_color_8 sig_bit; - is16 = force16 = force8 = ushift = dshift = 0; fails = 1; - prec = image->comps[0].prec; - nr_comp = image->numcomps; + is16 = force16 = force8 = ushift = dshift = 0; fails = 1; + prec = image->comps[0].prec; + nr_comp = image->numcomps; - if(prec > 8 && prec < 16) - { - ushift = 16 - prec; dshift = prec - ushift; - prec = 16; force16 = 1; - } - else - if(prec < 8 && nr_comp > 1)/* GRAY_ALPHA, RGB, RGB_ALPHA */ - { - ushift = 8 - prec; dshift = 8 - ushift; - prec = 8; force8 = 1; - } + if(prec > 8 && prec < 16) + { + ushift = 16 - prec; dshift = prec - ushift; + prec = 16; force16 = 1; + } + else + if(prec < 8 && nr_comp > 1)/* GRAY_ALPHA, RGB, RGB_ALPHA */ + { + ushift = 8 - prec; dshift = 8 - ushift; + prec = 8; force8 = 1; + } - if(prec != 1 && prec != 2 && prec != 4 && prec != 8 && prec != 16) - { - fprintf(stderr,"imagetopng: can not create %s" - "\n\twrong bit_depth %d\n", write_idf, prec); - return fails; - } - writer = fopen(write_idf, "wb"); + if(prec != 1 && prec != 2 && prec != 4 && prec != 8 && prec != 16) + { + fprintf(stderr,"imagetopng: can not create %s" + "\n\twrong bit_depth %d\n", write_idf, prec); + return fails; + } + writer = fopen(write_idf, "wb"); - if(writer == NULL) return fails; + if(writer == NULL) return fails; - info = NULL; has_alpha = 0; + info = NULL; has_alpha = 0; -/* Create and initialize the png_struct with the desired error handler + /* Create and initialize the png_struct with the desired error handler * functions. If you want to use the default stderr and longjump method, * you can supply NULL for the last three parameters. We also check that * the library version is compatible with the one used at compile time, * in case we are using dynamically linked libraries. REQUIRED. */ - png = png_create_write_struct(PNG_LIBPNG_VER_STRING, - NULL, NULL, NULL); -/*png_voidp user_error_ptr, user_error_fn, user_warning_fn); */ + png = png_create_write_struct(PNG_LIBPNG_VER_STRING, + NULL, NULL, NULL); + /*png_voidp user_error_ptr, user_error_fn, user_warning_fn); */ - if(png == NULL) goto fin; + if(png == NULL) goto fin; -/* Allocate/initialize the image information data. REQUIRED + /* Allocate/initialize the image information data. REQUIRED */ - info = png_create_info_struct(png); + info = png_create_info_struct(png); - if(info == NULL) goto fin; + if(info == NULL) goto fin; -/* Set error handling. REQUIRED if you are not supplying your own + /* Set error handling. REQUIRED if you are not supplying your own * error handling functions in the png_create_write_struct() call. */ - if(setjmp(png_jmpbuf(png))) goto fin; + if(setjmp(png_jmpbuf(png))) goto fin; -/* I/O initialization functions is REQUIRED + /* I/O initialization functions is REQUIRED */ - png_init_io(png, writer); + png_init_io(png, writer); -/* Set the image information here. Width and height are up to 2^31, + /* Set the image information here. Width and height are up to 2^31, * bit_depth is one of 1, 2, 4, 8, or 16, but valid values also depend on * the color_type selected. color_type is one of PNG_COLOR_TYPE_GRAY, * PNG_COLOR_TYPE_GRAY_ALPHA, PNG_COLOR_TYPE_PALETTE, PNG_COLOR_TYPE_RGB, * or PNG_COLOR_TYPE_RGB_ALPHA. interlace is either PNG_INTERLACE_NONE or * PNG_INTERLACE_ADAM7, and the compression_type and filter_type MUST - * currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE. + * currently be PNG_COMPRESSION_TYPE_BASE and PNG_FILTER_TYPE_BASE. * REQUIRED * * ERRORS: @@ -3352,276 +3352,276 @@ int imagetopng(opj_image_t * image, const char *write_idf) * color_type == PNG_COLOR_TYPE_RGB && bit_depth < 8 * color_type == PNG_COLOR_TYPE_GRAY_ALPHA && bit_depth < 8 * color_type == PNG_COLOR_TYPE_RGB_ALPHA) && bit_depth < 8 - * + * */ - png_set_compression_level(png, Z_BEST_COMPRESSION); + png_set_compression_level(png, Z_BEST_COMPRESSION); - if(prec == 16) mask = 0xffff; - else - if(prec == 8) mask = 0x00ff; - else - if(prec == 4) mask = 0x000f; - else - if(prec == 2) mask = 0x0003; - else - if(prec == 1) mask = 0x0001; + if(prec == 16) mask = 0xffff; + else + if(prec == 8) mask = 0x00ff; + else + if(prec == 4) mask = 0x000f; + else + if(prec == 2) mask = 0x0003; + else + if(prec == 1) mask = 0x0001; - if(nr_comp >= 3 - && image->comps[0].dx == image->comps[1].dx - && image->comps[1].dx == image->comps[2].dx - && image->comps[0].dy == image->comps[1].dy - && image->comps[1].dy == image->comps[2].dy - && image->comps[0].prec == image->comps[1].prec - && image->comps[1].prec == image->comps[2].prec) - { - int v; + if(nr_comp >= 3 + && image->comps[0].dx == image->comps[1].dx + && image->comps[1].dx == image->comps[2].dx + && image->comps[0].dy == image->comps[1].dy + && image->comps[1].dy == image->comps[2].dy + && image->comps[0].prec == image->comps[1].prec + && image->comps[1].prec == image->comps[2].prec) + { + int v; - has_alpha = (nr_comp > 3); + has_alpha = (nr_comp > 3); - is16 = (prec == 16); - - width = image->comps[0].w; - height = image->comps[0].h; + is16 = (prec == 16); - red = image->comps[0].data; - green = image->comps[1].data; - blue = image->comps[2].data; + width = image->comps[0].w; + height = image->comps[0].h; - sig_bit.red = sig_bit.green = sig_bit.blue = prec; + red = image->comps[0].data; + green = image->comps[1].data; + blue = image->comps[2].data; - if(has_alpha) - { - sig_bit.alpha = prec; - alpha = image->comps[3].data; - color_type = PNG_COLOR_TYPE_RGB_ALPHA; - adjustA = (image->comps[3].sgnd ? 1 << (image->comps[3].prec - 1) : 0); - } - else - { - sig_bit.alpha = 0; alpha = NULL; - color_type = PNG_COLOR_TYPE_RGB; - adjustA = 0; - } - png_set_sBIT(png, info, &sig_bit); + sig_bit.red = sig_bit.green = sig_bit.blue = prec; - png_set_IHDR(png, info, width, height, prec, - color_type, - PNG_INTERLACE_NONE, - PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); + if(has_alpha) + { + sig_bit.alpha = prec; + alpha = image->comps[3].data; + color_type = PNG_COLOR_TYPE_RGB_ALPHA; + adjustA = (image->comps[3].sgnd ? 1 << (image->comps[3].prec - 1) : 0); + } + else + { + sig_bit.alpha = 0; alpha = NULL; + color_type = PNG_COLOR_TYPE_RGB; + adjustA = 0; + } + png_set_sBIT(png, info, &sig_bit); - png_set_gamma(png, 2.2, 1./2.2); - png_set_sRGB(png, info, PNG_sRGB_INTENT_PERCEPTUAL); -/*=============================*/ - png_write_info(png, info); -/*=============================*/ - if(prec < 8) - { - png_set_packing(png); - } - adjustR = (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); - adjustG = (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); - adjustB = (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); + png_set_IHDR(png, info, width, height, prec, + color_type, + PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); - row_buf = (unsigned char*)malloc(width * nr_comp * 2); + png_set_gamma(png, 2.2, 1./2.2); + png_set_sRGB(png, info, PNG_sRGB_INTENT_PERCEPTUAL); + /*=============================*/ + png_write_info(png, info); + /*=============================*/ + if(prec < 8) + { + png_set_packing(png); + } + adjustR = (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); + adjustG = (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); + adjustB = (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); - for(y = 0; y < height; ++y) - { - d = row_buf; + row_buf = (unsigned char*)malloc(width * nr_comp * 2); - for(x = 0; x < width; ++x) - { - if(is16) - { - v = *red + adjustR; ++red; - - if(force16) { v = (v<>dshift); } + for(y = 0; y < height; ++y) + { + d = row_buf; - *d++ = (unsigned char)(v>>8); *d++ = (unsigned char)v; + for(x = 0; x < width; ++x) + { + if(is16) + { + v = *red + adjustR; ++red; - v = *green + adjustG; ++green; - - if(force16) { v = (v<>dshift); } + if(force16) { v = (v<>dshift); } - *d++ = (unsigned char)(v>>8); *d++ = (unsigned char)v; + *d++ = (unsigned char)(v>>8); *d++ = (unsigned char)v; - v = *blue + adjustB; ++blue; - - if(force16) { v = (v<>dshift); } + v = *green + adjustG; ++green; - *d++ = (unsigned char)(v>>8); *d++ = (unsigned char)v; + if(force16) { v = (v<>dshift); } - if(has_alpha) - { - v = *alpha + adjustA; ++alpha; - - if(force16) { v = (v<>dshift); } + *d++ = (unsigned char)(v>>8); *d++ = (unsigned char)v; - *d++ = (unsigned char)(v>>8); *d++ = (unsigned char)v; - } - continue; - }/* if(is16) */ + v = *blue + adjustB; ++blue; - v = *red + adjustR; ++red; + if(force16) { v = (v<>dshift); } - if(force8) { v = (v<>dshift); } + *d++ = (unsigned char)(v>>8); *d++ = (unsigned char)v; - *d++ = (unsigned char)(v & mask); + if(has_alpha) + { + v = *alpha + adjustA; ++alpha; - v = *green + adjustG; ++green; + if(force16) { v = (v<>dshift); } - if(force8) { v = (v<>dshift); } + *d++ = (unsigned char)(v>>8); *d++ = (unsigned char)v; + } + continue; + }/* if(is16) */ - *d++ = (unsigned char)(v & mask); + v = *red + adjustR; ++red; - v = *blue + adjustB; ++blue; + if(force8) { v = (v<>dshift); } - if(force8) { v = (v<>dshift); } + *d++ = (unsigned char)(v & mask); - *d++ = (unsigned char)(v & mask); + v = *green + adjustG; ++green; - if(has_alpha) - { - v = *alpha + adjustA; ++alpha; + if(force8) { v = (v<>dshift); } - if(force8) { v = (v<>dshift); } + *d++ = (unsigned char)(v & mask); - *d++ = (unsigned char)(v & mask); - } - } /* for(x) */ + v = *blue + adjustB; ++blue; - png_write_row(png, row_buf); + if(force8) { v = (v<>dshift); } - } /* for(y) */ - free(row_buf); + *d++ = (unsigned char)(v & mask); - }/* nr_comp >= 3 */ - else - if(nr_comp == 1 /* GRAY */ - || ( nr_comp == 2 /* GRAY_ALPHA */ - && image->comps[0].dx == image->comps[1].dx - && image->comps[0].dy == image->comps[1].dy - && image->comps[0].prec == image->comps[1].prec)) - { - int v; + if(has_alpha) + { + v = *alpha + adjustA; ++alpha; - red = image->comps[0].data; + if(force8) { v = (v<>dshift); } - sig_bit.gray = prec; - sig_bit.red = sig_bit.green = sig_bit.blue = sig_bit.alpha = 0; - alpha = NULL; adjustA = 0; - color_type = PNG_COLOR_TYPE_GRAY; + *d++ = (unsigned char)(v & mask); + } + } /* for(x) */ - if(nr_comp == 2) - { - has_alpha = 1; sig_bit.alpha = prec; - alpha = image->comps[1].data; - color_type = PNG_COLOR_TYPE_GRAY_ALPHA; - adjustA = (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); - } - width = image->comps[0].w; - height = image->comps[0].h; + png_write_row(png, row_buf); - png_set_IHDR(png, info, width, height, sig_bit.gray, - color_type, - PNG_INTERLACE_NONE, - PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); + } /* for(y) */ + free(row_buf); - png_set_sBIT(png, info, &sig_bit); + }/* nr_comp >= 3 */ + else + if(nr_comp == 1 /* GRAY */ + || ( nr_comp == 2 /* GRAY_ALPHA */ + && image->comps[0].dx == image->comps[1].dx + && image->comps[0].dy == image->comps[1].dy + && image->comps[0].prec == image->comps[1].prec)) + { + int v; - png_set_gamma(png, 2.2, 1./2.2); - png_set_sRGB(png, info, PNG_sRGB_INTENT_PERCEPTUAL); -/*=============================*/ - png_write_info(png, info); -/*=============================*/ - adjustR = (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); + red = image->comps[0].data; - if(prec < 8) - { - png_set_packing(png); - } + sig_bit.gray = prec; + sig_bit.red = sig_bit.green = sig_bit.blue = sig_bit.alpha = 0; + alpha = NULL; adjustA = 0; + color_type = PNG_COLOR_TYPE_GRAY; - if(prec > 8) - { - row_buf = (unsigned char*) - malloc(width * nr_comp * sizeof(unsigned short)); + if(nr_comp == 2) + { + has_alpha = 1; sig_bit.alpha = prec; + alpha = image->comps[1].data; + color_type = PNG_COLOR_TYPE_GRAY_ALPHA; + adjustA = (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); + } + width = image->comps[0].w; + height = image->comps[0].h; - for(y = 0; y < height; ++y) - { - d = row_buf; + png_set_IHDR(png, info, width, height, sig_bit.gray, + color_type, + PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); - for(x = 0; x < width; ++x) - { - v = *red + adjustR; ++red; + png_set_sBIT(png, info, &sig_bit); - if(force16) { v = (v<>dshift); } + png_set_gamma(png, 2.2, 1./2.2); + png_set_sRGB(png, info, PNG_sRGB_INTENT_PERCEPTUAL); + /*=============================*/ + png_write_info(png, info); + /*=============================*/ + adjustR = (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); - *d++ = (unsigned char)(v>>8); *d++ = (unsigned char)v; + if(prec < 8) + { + png_set_packing(png); + } - if(has_alpha) - { - v = *alpha++; + if(prec > 8) + { + row_buf = (unsigned char*) + malloc(width * nr_comp * sizeof(unsigned short)); - if(force16) { v = (v<>dshift); } + for(y = 0; y < height; ++y) + { + d = row_buf; - *d++ = (unsigned char)(v>>8); *d++ = (unsigned char)v; - } - }/* for(x) */ - png_write_row(png, row_buf); + for(x = 0; x < width; ++x) + { + v = *red + adjustR; ++red; - } /* for(y) */ - free(row_buf); - } - else /* prec <= 8 */ - { - row_buf = (unsigned char*)calloc(width, nr_comp * 2); + if(force16) { v = (v<>dshift); } - for(y = 0; y < height; ++y) - { - d = row_buf; + *d++ = (unsigned char)(v>>8); *d++ = (unsigned char)v; - for(x = 0; x < width; ++x) - { - v = *red + adjustR; ++red; + if(has_alpha) + { + v = *alpha++; - if(force8) { v = (v<>dshift); } + if(force16) { v = (v<>dshift); } - *d++ = (unsigned char)(v & mask); + *d++ = (unsigned char)(v>>8); *d++ = (unsigned char)v; + } + }/* for(x) */ + png_write_row(png, row_buf); - if(has_alpha) - { - v = *alpha + adjustA; ++alpha; + } /* for(y) */ + free(row_buf); + } + else /* prec <= 8 */ + { + row_buf = (unsigned char*)calloc(width, nr_comp * 2); - if(force8) { v = (v<>dshift); } + for(y = 0; y < height; ++y) + { + d = row_buf; - *d++ = (unsigned char)(v & mask); - } - }/* for(x) */ + for(x = 0; x < width; ++x) + { + v = *red + adjustR; ++red; - png_write_row(png, row_buf); + if(force8) { v = (v<>dshift); } - } /* for(y) */ - free(row_buf); - } - } - else - { - fprintf(stderr,"imagetopng: can not create %s\n",write_idf); - goto fin; - } - png_write_end(png, info); + *d++ = (unsigned char)(v & mask); - fails = 0; + if(has_alpha) + { + v = *alpha + adjustA; ++alpha; + + if(force8) { v = (v<>dshift); } + + *d++ = (unsigned char)(v & mask); + } + }/* for(x) */ + + png_write_row(png, row_buf); + + } /* for(y) */ + free(row_buf); + } + } + else + { + fprintf(stderr,"imagetopng: can not create %s\n",write_idf); + goto fin; + } + png_write_end(png, info); + + fails = 0; fin: - if(png) - { - png_destroy_write_struct(&png, &info); - } - fclose(writer); + if(png) + { + png_destroy_write_struct(&png, &info); + } + fclose(writer); - if(fails) remove(write_idf); + if(fails) remove(write_idf); - return fails; + return fails; }/* imagetopng() */ #endif /* OPJ_HAVE_LIBPNG */ From d6c0c851256400a3cc9a9188a603ec97fb066eee Mon Sep 17 00:00:00 2001 From: Antonin Descampe Date: Wed, 12 Feb 2014 15:16:36 +0000 Subject: [PATCH 071/333] [trunk] added a warning when tif conversion changes input image bitdepth --- src/bin/jp2/convert.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index 4144a395..6997def9 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -2535,6 +2535,14 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) */ memset(&cmptparm[0], 0, 4 * sizeof(opj_image_cmptparm_t)); + if ((tiPhoto == PHOTOMETRIC_RGB) && (parameters->cp_cinema)) { + fprintf(stdout,"WARNING:\n" + "Input image bitdepth is %d bits\n" + "TIF conversion has automatically rescaled to 12-bits\n" + "to comply with cinema profiles.\n", + tiBps); + } + if(tiPhoto == PHOTOMETRIC_RGB) /* RGB(A) */ { numcomps = 3 + has_alpha; From 780120c9a24ba018da398849c284d29de854e11a Mon Sep 17 00:00:00 2001 From: Antonin Descampe Date: Wed, 12 Feb 2014 16:16:21 +0000 Subject: [PATCH 072/333] [trunk] moved logic related to cinema profiles in library (was in opj_compress.c). This enables one using the library with its own executable to easily ask for cinema profiles. --- src/bin/jp2/opj_compress.c | 260 ------------------------------------- src/lib/openjp2/j2k.c | 257 ++++++++++++++++++++++++++++++++++++ 2 files changed, 257 insertions(+), 260 deletions(-) diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index ae41b575..73fdc064 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -61,11 +61,6 @@ #include "format_defs.h" -#define CINEMA_24_CS 1302083 /*Codestream length for 24fps*/ -#define CINEMA_48_CS 651041 /*Codestream length for 48fps*/ -#define COMP_24_CS 1041666 /*Maximum size per color component for 2K & 4K @ 24fps*/ -#define COMP_48_CS 520833 /*Maximum size per color component for 2K @ 48fps*/ - typedef struct dircnt{ /** Buffer for holding images read from Directory*/ char *filename_buf; @@ -444,249 +439,6 @@ static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_c return 0; } -static int initialise_4K_poc(opj_poc_t *POC, int numres){ - POC[0].tile = 1; - POC[0].resno0 = 0; - POC[0].compno0 = 0; - POC[0].layno1 = 1; - POC[0].resno1 = numres-1; - POC[0].compno1 = 3; - POC[0].prg1 = OPJ_CPRL; - POC[1].tile = 1; - POC[1].resno0 = numres-1; - POC[1].compno0 = 0; - POC[1].layno1 = 1; - POC[1].resno1 = numres; - POC[1].compno1 = 3; - POC[1].prg1 = OPJ_CPRL; - return 2; -} - -static void set_cinema_parameters(opj_cparameters_t *parameters) -{ - /* Configure cinema parameters */ - float max_rate = 0; - float temp_rate = 0; - int i; - - /* profile (Rsiz) */ - switch (parameters->cp_cinema){ - case OPJ_CINEMA2K_24: - case OPJ_CINEMA2K_48: - parameters->cp_rsiz = OPJ_CINEMA2K; - break; - case OPJ_CINEMA4K_24: - parameters->cp_rsiz = OPJ_CINEMA4K; - break; - } - - /* No tiling */ - parameters->tile_size_on = OPJ_FALSE; - parameters->cp_tdx=1; - parameters->cp_tdy=1; - - /* One tile part for each component */ - parameters->tp_flag = 'C'; - parameters->tp_on = 1; - - /* Tile and Image shall be at (0,0) */ - parameters->cp_tx0 = 0; - parameters->cp_ty0 = 0; - parameters->image_offset_x0 = 0; - parameters->image_offset_y0 = 0; - - /* Codeblock size= 32*32 */ - parameters->cblockw_init = 32; - parameters->cblockh_init = 32; - - /* Codeblock style: no mode switch enabled */ - parameters->mode = 0; - - /* No ROI */ - parameters->roi_compno = -1; - - /* No subsampling */ - parameters->subsampling_dx = 1; - parameters->subsampling_dy = 1; - - /* 9-7 transform */ - parameters->irreversible = 1; - - /* Number of layers */ - if (parameters->tcp_numlayers > 1){ - fprintf(stdout,"JPEG 2000 Profile-3 and 4 (2k/4k dc profile) requires:\n" - "1 single quality layer" - "-> Number of layers forced to 1 (rather than %d)\n", - parameters->tcp_numlayers); - parameters->tcp_numlayers = 1; - } - - /* Resolution levels */ - switch (parameters->cp_cinema){ - case OPJ_CINEMA2K_24: - case OPJ_CINEMA2K_48: - if(parameters->numresolution > 6){ - fprintf(stdout,"JPEG 2000 Profile-3 (2k dc profile) requires:\n" - "Number of decomposition levels <= 5\n" - "-> Number of decomposition levels forced to 5 (rather than %d)\n", - parameters->numresolution+1); - parameters->numresolution = 6; - } - break; - case OPJ_CINEMA4K_24: - if(parameters->numresolution < 2){ - fprintf(stdout,"JPEG 2000 Profile-4 (4k dc profile) requires:\n" - "Number of decomposition levels >= 1 && <= 6\n" - "-> Number of decomposition levels forced to 1 (rather than %d)\n", - parameters->numresolution+1); - parameters->numresolution = 1; - }else if(parameters->numresolution > 7){ - fprintf(stdout,"JPEG 2000 Profile-4 (4k dc profile) requires:\n" - "Number of decomposition levels >= 1 && <= 6\n" - "-> Number of decomposition levels forced to 6 (rather than %d)\n", - parameters->numresolution+1); - parameters->numresolution = 7; - } - break; - default : - break; - } - - /* Precincts */ - parameters->csty |= 0x01; - parameters->res_spec = parameters->numresolution-1; - for (i = 0; ires_spec; i++) { - parameters->prcw_init[i] = 256; - parameters->prch_init[i] = 256; - } - - /* The progression order shall be CPRL */ - parameters->prog_order = OPJ_CPRL; - - /* Progression order changes for 4K, disallowed for 2K */ - if (parameters->cp_cinema == OPJ_CINEMA4K_24) { - parameters->numpocs = initialise_4K_poc(parameters->POC,parameters->numresolution); - } else { - parameters->numpocs = 0; - } -} - -static void set_cinema_rate(opj_cparameters_t *parameters, opj_image_t *image) -{ - /* Limited bit-rate */ - float max_rate = 0; - float temp_rate = 0; - parameters->cp_disto_alloc = 1; - switch (parameters->cp_cinema){ - case OPJ_CINEMA2K_24: - case OPJ_CINEMA4K_24: - max_rate = ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy); - if (parameters->tcp_rates[0] == 0){ - parameters->tcp_rates[0] = max_rate; - }else{ - temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (parameters->tcp_rates[0] * 8 * image->comps[0].dx * image->comps[0].dy); - if (temp_rate > CINEMA_24_CS ){ - fprintf(stdout,"JPEG 2000 Profile-3 and 4 (2k/4k dc profile) requires:\n" - "Maximum 1302083 compressed bytes @ 24fps\n" - "-> Specified rate (%3.1f) exceeds this limit. Rate will be forced to %3.1f.\n", - parameters->tcp_rates[0], max_rate); - parameters->tcp_rates[0]= max_rate; - }else{ - fprintf(stdout,"JPEG 2000 Profile-3 and 4 (2k/4k dc profile):\n" - "INFO : Specified rate (%3.1f) is below the 2k/4k limit @ 24fps.\n", - parameters->tcp_rates[0]); - } - } - parameters->max_comp_size = COMP_24_CS; - break; - case OPJ_CINEMA2K_48: - max_rate = ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy); - if (parameters->tcp_rates[0] == 0){ - parameters->tcp_rates[0] = max_rate; - }else{ - temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (parameters->tcp_rates[0] * 8 * image->comps[0].dx * image->comps[0].dy); - if (temp_rate > CINEMA_48_CS ){ - fprintf(stdout,"JPEG 2000 Profile-3 (2k dc profile) requires:\n" - "Maximum 651041 compressed bytes @ 48fps\n" - "-> Specified rate (%3.1f) exceeds this limit. Rate will be forced to %3.1f.\n", - parameters->tcp_rates[0], max_rate); - parameters->tcp_rates[0]= max_rate; - }else{ - fprintf(stdout,"JPEG 2000 Profile-3 (2k dc profile):\n" - "INFO : Specified rate (%3.1f) is below the 2k limit @ 48 fps.\n", - parameters->tcp_rates[0]); - } - } - parameters->max_comp_size = COMP_48_CS; - break; - default: - break; - } -} - -static OPJ_BOOL is_cinema_compliant(opj_image_t *image, OPJ_CINEMA_MODE cinema_mode) -{ - OPJ_UINT32 i; - - /* Number of components */ - if (image->numcomps != 3){ - fprintf(stdout,"JPEG 2000 Profile-3 (2k dc profile) requires:\n" - "3 components" - "-> Number of components of input image (%d) is not compliant\n" - "-> Non-profile-3 codestream will be generated\n", - image->numcomps); - return OPJ_FALSE; - } - - /* Bitdepth */ - for (i = 0; i < image->numcomps; i++) { - if ((image->comps[i].bpp != 12) | (image->comps[i].sgnd)){ - char signed_str[] = "signed"; - char unsigned_str[] = "unsigned"; - char *tmp_str = image->comps[i].sgnd?signed_str:unsigned_str; - fprintf(stdout,"JPEG 2000 Profile-3 (2k dc profile) requires:\n" - "Precision of each component shall be 12 bits unsigned" - "-> At least component %d of input image (%d bits, %s) is not compliant\n" - "-> Non-profile-3 codestream will be generated\n", - i,image->comps[i].bpp, tmp_str); - return OPJ_FALSE; - } - } - - /* Image size */ - switch (cinema_mode){ - case OPJ_CINEMA2K_24: - case OPJ_CINEMA2K_48: - if (((image->comps[0].w > 2048) | (image->comps[0].h > 1080))){ - fprintf(stdout,"JPEG 2000 Profile-3 (2k dc profile) requires:\n" - "width <= 2048 and height <= 1080\n" - "-> Input image size %d x %d is not compliant\n" - "-> Non-profile-3 codestream will be generated\n", - image->comps[0].w,image->comps[0].h); - return OPJ_FALSE; - } - break; - case OPJ_CINEMA4K_24: - if (((image->comps[0].w > 4096) | (image->comps[0].h > 2160))){ - fprintf(stdout,"JPEG 2000 Profile-4 (4k dc profile) requires:\n" - "width <= 4096 and height <= 2160\n" - "-> Image size %d x %d is not compliant\n" - "-> Non-profile-4 codestream will be generated\n", - image->comps[0].w,image->comps[0].h); - return OPJ_FALSE; - } - break; - default : - break; - } - - return OPJ_TRUE; -} - /* ------------------------------------------------------------------------------------ */ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *parameters, @@ -1719,10 +1471,6 @@ int main(int argc, char **argv) { return 1; } - if (parameters.cp_cinema){ - set_cinema_parameters(¶meters); - } - /* Create comment for codestream */ if(parameters.cp_comment == NULL) { const char comment[] = "Created by OpenJPEG version "; @@ -1880,14 +1628,6 @@ int main(int argc, char **argv) { /* Decide if MCT should be used */ parameters.tcp_mct = image->numcomps == 3 ? 1 : 0; - if(parameters.cp_cinema){ - if (!is_cinema_compliant(image,parameters.cp_cinema)) { - parameters.cp_rsiz = OPJ_STD_RSIZ; - } - /* This cannot be in set_cinema_parameters because we need size and precision of the input image */ - set_cinema_rate(¶meters,image); - } - /* encode the destination image */ /* ---------------------------- */ diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 2740b9d5..555c5928 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -36,6 +36,11 @@ #include "opj_includes.h" +#define CINEMA_24_CS 1302083 /*Codestream length for 24fps*/ +#define CINEMA_48_CS 651041 /*Codestream length for 48fps*/ +#define COMP_24_CS 1041666 /*Maximum size per color component for 2K & 4K @ 24fps*/ +#define COMP_48_CS 520833 /*Maximum size per color component for 2K @ 48fps*/ + /** @defgroup J2K J2K - JPEG-2000 codestream reader/writer */ /*@{*/ @@ -1142,6 +1147,12 @@ static OPJ_FLOAT32 opj_j2k_get_tp_stride (opj_tcp_t * p_tcp); static OPJ_FLOAT32 opj_j2k_get_default_stride (opj_tcp_t * p_tcp); +static int opj_j2k_initialise_4K_poc(opj_poc_t *POC, int numres); + +static void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *image); + +static OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_CINEMA_MODE cinema_mode); + /*@}*/ /*@}*/ @@ -5779,6 +5790,244 @@ opj_j2k_t* opj_j2k_create_compress(void) return l_j2k; } +int opj_j2k_initialise_4K_poc(opj_poc_t *POC, int numres){ + POC[0].tile = 1; + POC[0].resno0 = 0; + POC[0].compno0 = 0; + POC[0].layno1 = 1; + POC[0].resno1 = numres-1; + POC[0].compno1 = 3; + POC[0].prg1 = OPJ_CPRL; + POC[1].tile = 1; + POC[1].resno0 = numres-1; + POC[1].compno0 = 0; + POC[1].layno1 = 1; + POC[1].resno1 = numres; + POC[1].compno1 = 3; + POC[1].prg1 = OPJ_CPRL; + return 2; +} + +void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *image) +{ + /* Configure cinema parameters */ + float max_rate = 0; + float temp_rate = 0; + int i; + + /* profile (Rsiz) */ + switch (parameters->cp_cinema){ + case OPJ_CINEMA2K_24: + case OPJ_CINEMA2K_48: + parameters->cp_rsiz = OPJ_CINEMA2K; + break; + case OPJ_CINEMA4K_24: + parameters->cp_rsiz = OPJ_CINEMA4K; + break; + } + + /* No tiling */ + parameters->tile_size_on = OPJ_FALSE; + parameters->cp_tdx=1; + parameters->cp_tdy=1; + + /* One tile part for each component */ + parameters->tp_flag = 'C'; + parameters->tp_on = 1; + + /* Tile and Image shall be at (0,0) */ + parameters->cp_tx0 = 0; + parameters->cp_ty0 = 0; + parameters->image_offset_x0 = 0; + parameters->image_offset_y0 = 0; + + /* Codeblock size= 32*32 */ + parameters->cblockw_init = 32; + parameters->cblockh_init = 32; + + /* Codeblock style: no mode switch enabled */ + parameters->mode = 0; + + /* No ROI */ + parameters->roi_compno = -1; + + /* No subsampling */ + parameters->subsampling_dx = 1; + parameters->subsampling_dy = 1; + + /* 9-7 transform */ + parameters->irreversible = 1; + + /* Number of layers */ + if (parameters->tcp_numlayers > 1){ + fprintf(stdout,"JPEG 2000 Profile-3 and 4 (2k/4k dc profile) requires:\n" + "1 single quality layer" + "-> Number of layers forced to 1 (rather than %d)\n", + parameters->tcp_numlayers); + parameters->tcp_numlayers = 1; + } + + /* Resolution levels */ + switch (parameters->cp_cinema){ + case OPJ_CINEMA2K_24: + case OPJ_CINEMA2K_48: + if(parameters->numresolution > 6){ + fprintf(stdout,"JPEG 2000 Profile-3 (2k dc profile) requires:\n" + "Number of decomposition levels <= 5\n" + "-> Number of decomposition levels forced to 5 (rather than %d)\n", + parameters->numresolution+1); + parameters->numresolution = 6; + } + break; + case OPJ_CINEMA4K_24: + if(parameters->numresolution < 2){ + fprintf(stdout,"JPEG 2000 Profile-4 (4k dc profile) requires:\n" + "Number of decomposition levels >= 1 && <= 6\n" + "-> Number of decomposition levels forced to 1 (rather than %d)\n", + parameters->numresolution+1); + parameters->numresolution = 1; + }else if(parameters->numresolution > 7){ + fprintf(stdout,"JPEG 2000 Profile-4 (4k dc profile) requires:\n" + "Number of decomposition levels >= 1 && <= 6\n" + "-> Number of decomposition levels forced to 6 (rather than %d)\n", + parameters->numresolution+1); + parameters->numresolution = 7; + } + break; + default : + break; + } + + /* Precincts */ + parameters->csty |= 0x01; + parameters->res_spec = parameters->numresolution-1; + for (i = 0; ires_spec; i++) { + parameters->prcw_init[i] = 256; + parameters->prch_init[i] = 256; + } + + /* The progression order shall be CPRL */ + parameters->prog_order = OPJ_CPRL; + + /* Progression order changes for 4K, disallowed for 2K */ + if (parameters->cp_cinema == OPJ_CINEMA4K_24) { + parameters->numpocs = opj_j2k_initialise_4K_poc(parameters->POC,parameters->numresolution); + } else { + parameters->numpocs = 0; + } + + /* Limited bit-rate */ + parameters->cp_disto_alloc = 1; + switch (parameters->cp_cinema){ + case OPJ_CINEMA2K_24: + case OPJ_CINEMA4K_24: + max_rate = ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ + (CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy); + if (parameters->tcp_rates[0] == 0){ + parameters->tcp_rates[0] = max_rate; + }else{ + temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ + (parameters->tcp_rates[0] * 8 * image->comps[0].dx * image->comps[0].dy); + if (temp_rate > CINEMA_24_CS ){ + fprintf(stdout,"JPEG 2000 Profile-3 and 4 (2k/4k dc profile) requires:\n" + "Maximum 1302083 compressed bytes @ 24fps\n" + "-> Specified rate (%3.1f) exceeds this limit. Rate will be forced to %3.1f.\n", + parameters->tcp_rates[0], max_rate); + parameters->tcp_rates[0]= max_rate; + }else{ + fprintf(stdout,"JPEG 2000 Profile-3 and 4 (2k/4k dc profile):\n" + "INFO : Specified rate (%3.1f) is below the 2k/4k limit @ 24fps.\n", + parameters->tcp_rates[0]); + } + } + parameters->max_comp_size = COMP_24_CS; + break; + case OPJ_CINEMA2K_48: + max_rate = ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ + (CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy); + if (parameters->tcp_rates[0] == 0){ + parameters->tcp_rates[0] = max_rate; + }else{ + temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ + (parameters->tcp_rates[0] * 8 * image->comps[0].dx * image->comps[0].dy); + if (temp_rate > CINEMA_48_CS ){ + fprintf(stdout,"JPEG 2000 Profile-3 (2k dc profile) requires:\n" + "Maximum 651041 compressed bytes @ 48fps\n" + "-> Specified rate (%3.1f) exceeds this limit. Rate will be forced to %3.1f.\n", + parameters->tcp_rates[0], max_rate); + parameters->tcp_rates[0]= max_rate; + }else{ + fprintf(stdout,"JPEG 2000 Profile-3 (2k dc profile):\n" + "INFO : Specified rate (%3.1f) is below the 2k limit @ 48 fps.\n", + parameters->tcp_rates[0]); + } + } + parameters->max_comp_size = COMP_48_CS; + break; + default: + break; + } +} + +OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_CINEMA_MODE cinema_mode) +{ + OPJ_UINT32 i; + + /* Number of components */ + if (image->numcomps != 3){ + fprintf(stdout,"JPEG 2000 Profile-3 (2k dc profile) requires:\n" + "3 components" + "-> Number of components of input image (%d) is not compliant\n" + "-> Non-profile-3 codestream will be generated\n", + image->numcomps); + return OPJ_FALSE; + } + + /* Bitdepth */ + for (i = 0; i < image->numcomps; i++) { + if ((image->comps[i].bpp != 12) | (image->comps[i].sgnd)){ + char signed_str[] = "signed"; + char unsigned_str[] = "unsigned"; + char *tmp_str = image->comps[i].sgnd?signed_str:unsigned_str; + fprintf(stdout,"JPEG 2000 Profile-3 (2k dc profile) requires:\n" + "Precision of each component shall be 12 bits unsigned" + "-> At least component %d of input image (%d bits, %s) is not compliant\n" + "-> Non-profile-3 codestream will be generated\n", + i,image->comps[i].bpp, tmp_str); + return OPJ_FALSE; + } + } + + /* Image size */ + switch (cinema_mode){ + case OPJ_CINEMA2K_24: + case OPJ_CINEMA2K_48: + if (((image->comps[0].w > 2048) | (image->comps[0].h > 1080))){ + fprintf(stdout,"JPEG 2000 Profile-3 (2k dc profile) requires:\n" + "width <= 2048 and height <= 1080\n" + "-> Input image size %d x %d is not compliant\n" + "-> Non-profile-3 codestream will be generated\n", + image->comps[0].w,image->comps[0].h); + return OPJ_FALSE; + } + break; + case OPJ_CINEMA4K_24: + if (((image->comps[0].w > 4096) | (image->comps[0].h > 2160))){ + fprintf(stdout,"JPEG 2000 Profile-4 (4k dc profile) requires:\n" + "width <= 4096 and height <= 2160\n" + "-> Image size %d x %d is not compliant\n" + "-> Non-profile-4 codestream will be generated\n", + image->comps[0].w,image->comps[0].h); + return OPJ_FALSE; + } + break; + default : + break; + } + + return OPJ_TRUE; +} + void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, opj_cparameters_t *parameters, opj_image_t *image, @@ -5798,6 +6047,14 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, cp->tw = 1; cp->th = 1; + /* set cinema parameters if required */ + if (parameters->cp_cinema){ + opj_j2k_set_cinema_parameters(parameters,image); + if (!opj_j2k_is_cinema_compliant(image,parameters->cp_cinema)) { + parameters->cp_rsiz = OPJ_STD_RSIZ; + } + } + /* copy user encoding parameters */ From e826e9281e084032815c05830d6e4b2fa584f722 Mon Sep 17 00:00:00 2001 From: Antonin Descampe Date: Wed, 12 Feb 2014 16:33:19 +0000 Subject: [PATCH 073/333] [trunk] replaced fprintf with event_mgr in cinema-related stuff in j2k.c --- src/lib/openjp2/j2k.c | 48 +++++++++++++++++++++++++++---------------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 555c5928..d6b7d6a6 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -1149,9 +1149,9 @@ static OPJ_FLOAT32 opj_j2k_get_default_stride (opj_tcp_t * p_tcp); static int opj_j2k_initialise_4K_poc(opj_poc_t *POC, int numres); -static void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *image); +static void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *image, opj_event_mgr_t *p_manager); -static OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_CINEMA_MODE cinema_mode); +static OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_CINEMA_MODE cinema_mode, opj_event_mgr_t *p_manager); /*@}*/ @@ -5808,7 +5808,7 @@ int opj_j2k_initialise_4K_poc(opj_poc_t *POC, int numres){ return 2; } -void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *image) +void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *image, opj_event_mgr_t *p_manager) { /* Configure cinema parameters */ float max_rate = 0; @@ -5860,7 +5860,8 @@ void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *i /* Number of layers */ if (parameters->tcp_numlayers > 1){ - fprintf(stdout,"JPEG 2000 Profile-3 and 4 (2k/4k dc profile) requires:\n" + opj_event_msg(p_manager, EVT_WARNING, + "JPEG 2000 Profile-3 and 4 (2k/4k dc profile) requires:\n" "1 single quality layer" "-> Number of layers forced to 1 (rather than %d)\n", parameters->tcp_numlayers); @@ -5872,7 +5873,8 @@ void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *i case OPJ_CINEMA2K_24: case OPJ_CINEMA2K_48: if(parameters->numresolution > 6){ - fprintf(stdout,"JPEG 2000 Profile-3 (2k dc profile) requires:\n" + opj_event_msg(p_manager, EVT_WARNING, + "JPEG 2000 Profile-3 (2k dc profile) requires:\n" "Number of decomposition levels <= 5\n" "-> Number of decomposition levels forced to 5 (rather than %d)\n", parameters->numresolution+1); @@ -5881,13 +5883,15 @@ void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *i break; case OPJ_CINEMA4K_24: if(parameters->numresolution < 2){ - fprintf(stdout,"JPEG 2000 Profile-4 (4k dc profile) requires:\n" + opj_event_msg(p_manager, EVT_WARNING, + "JPEG 2000 Profile-4 (4k dc profile) requires:\n" "Number of decomposition levels >= 1 && <= 6\n" "-> Number of decomposition levels forced to 1 (rather than %d)\n", parameters->numresolution+1); parameters->numresolution = 1; }else if(parameters->numresolution > 7){ - fprintf(stdout,"JPEG 2000 Profile-4 (4k dc profile) requires:\n" + opj_event_msg(p_manager, EVT_WARNING, + "JPEG 2000 Profile-4 (4k dc profile) requires:\n" "Number of decomposition levels >= 1 && <= 6\n" "-> Number of decomposition levels forced to 6 (rather than %d)\n", parameters->numresolution+1); @@ -5929,13 +5933,15 @@ void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *i temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ (parameters->tcp_rates[0] * 8 * image->comps[0].dx * image->comps[0].dy); if (temp_rate > CINEMA_24_CS ){ - fprintf(stdout,"JPEG 2000 Profile-3 and 4 (2k/4k dc profile) requires:\n" + opj_event_msg(p_manager, EVT_WARNING, + "JPEG 2000 Profile-3 and 4 (2k/4k dc profile) requires:\n" "Maximum 1302083 compressed bytes @ 24fps\n" "-> Specified rate (%3.1f) exceeds this limit. Rate will be forced to %3.1f.\n", parameters->tcp_rates[0], max_rate); parameters->tcp_rates[0]= max_rate; }else{ - fprintf(stdout,"JPEG 2000 Profile-3 and 4 (2k/4k dc profile):\n" + opj_event_msg(p_manager, EVT_WARNING, + "JPEG 2000 Profile-3 and 4 (2k/4k dc profile):\n" "INFO : Specified rate (%3.1f) is below the 2k/4k limit @ 24fps.\n", parameters->tcp_rates[0]); } @@ -5951,13 +5957,15 @@ void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *i temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ (parameters->tcp_rates[0] * 8 * image->comps[0].dx * image->comps[0].dy); if (temp_rate > CINEMA_48_CS ){ - fprintf(stdout,"JPEG 2000 Profile-3 (2k dc profile) requires:\n" + opj_event_msg(p_manager, EVT_WARNING, + "JPEG 2000 Profile-3 (2k dc profile) requires:\n" "Maximum 651041 compressed bytes @ 48fps\n" "-> Specified rate (%3.1f) exceeds this limit. Rate will be forced to %3.1f.\n", parameters->tcp_rates[0], max_rate); parameters->tcp_rates[0]= max_rate; }else{ - fprintf(stdout,"JPEG 2000 Profile-3 (2k dc profile):\n" + opj_event_msg(p_manager, EVT_WARNING, + "JPEG 2000 Profile-3 (2k dc profile):\n" "INFO : Specified rate (%3.1f) is below the 2k limit @ 48 fps.\n", parameters->tcp_rates[0]); } @@ -5969,13 +5977,14 @@ void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *i } } -OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_CINEMA_MODE cinema_mode) +OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_CINEMA_MODE cinema_mode, opj_event_mgr_t *p_manager) { OPJ_UINT32 i; /* Number of components */ if (image->numcomps != 3){ - fprintf(stdout,"JPEG 2000 Profile-3 (2k dc profile) requires:\n" + opj_event_msg(p_manager, EVT_WARNING, + "JPEG 2000 Profile-3 (2k dc profile) requires:\n" "3 components" "-> Number of components of input image (%d) is not compliant\n" "-> Non-profile-3 codestream will be generated\n", @@ -5989,7 +5998,8 @@ OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_CINEMA_MODE cinema_ char signed_str[] = "signed"; char unsigned_str[] = "unsigned"; char *tmp_str = image->comps[i].sgnd?signed_str:unsigned_str; - fprintf(stdout,"JPEG 2000 Profile-3 (2k dc profile) requires:\n" + opj_event_msg(p_manager, EVT_WARNING, + "JPEG 2000 Profile-3 (2k dc profile) requires:\n" "Precision of each component shall be 12 bits unsigned" "-> At least component %d of input image (%d bits, %s) is not compliant\n" "-> Non-profile-3 codestream will be generated\n", @@ -6003,7 +6013,8 @@ OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_CINEMA_MODE cinema_ case OPJ_CINEMA2K_24: case OPJ_CINEMA2K_48: if (((image->comps[0].w > 2048) | (image->comps[0].h > 1080))){ - fprintf(stdout,"JPEG 2000 Profile-3 (2k dc profile) requires:\n" + opj_event_msg(p_manager, EVT_WARNING, + "JPEG 2000 Profile-3 (2k dc profile) requires:\n" "width <= 2048 and height <= 1080\n" "-> Input image size %d x %d is not compliant\n" "-> Non-profile-3 codestream will be generated\n", @@ -6013,7 +6024,8 @@ OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_CINEMA_MODE cinema_ break; case OPJ_CINEMA4K_24: if (((image->comps[0].w > 4096) | (image->comps[0].h > 2160))){ - fprintf(stdout,"JPEG 2000 Profile-4 (4k dc profile) requires:\n" + opj_event_msg(p_manager, EVT_WARNING, + "JPEG 2000 Profile-4 (4k dc profile) requires:\n" "width <= 4096 and height <= 2160\n" "-> Image size %d x %d is not compliant\n" "-> Non-profile-4 codestream will be generated\n", @@ -6049,8 +6061,8 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, /* set cinema parameters if required */ if (parameters->cp_cinema){ - opj_j2k_set_cinema_parameters(parameters,image); - if (!opj_j2k_is_cinema_compliant(image,parameters->cp_cinema)) { + opj_j2k_set_cinema_parameters(parameters,image,p_manager); + if (!opj_j2k_is_cinema_compliant(image,parameters->cp_cinema,p_manager)) { parameters->cp_rsiz = OPJ_STD_RSIZ; } } From 33d8f08964ca48183241d680ccd692378e25cc70 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 24 Feb 2014 08:52:44 +0000 Subject: [PATCH 074/333] [trunk] Fix a warning about type conversion. Use a trick where unsigned wrapping is legal --- src/lib/openjp2/bio.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/openjp2/bio.c b/src/lib/openjp2/bio.c index 797e01e1..213a9941 100644 --- a/src/lib/openjp2/bio.c +++ b/src/lib/openjp2/bio.c @@ -146,17 +146,17 @@ void opj_bio_init_dec(opj_bio_t *bio, OPJ_BYTE *bp, OPJ_UINT32 len) { } void opj_bio_write(opj_bio_t *bio, OPJ_UINT32 v, OPJ_UINT32 n) { - OPJ_INT32 i; - for (i = n - 1; i >= 0; i--) { + OPJ_UINT32 i; + for (i = n - 1; i < n; i--) { opj_bio_putbit(bio, (v >> i) & 1); } } OPJ_UINT32 opj_bio_read(opj_bio_t *bio, OPJ_UINT32 n) { - OPJ_INT32 i; + OPJ_UINT32 i; OPJ_UINT32 v; v = 0; - for (i = n - 1; i >= 0; i--) { + for (i = n - 1; i < n; i--) { v += opj_bio_getbit(bio) << i; } return v; From 9efad435090f5871b888041f2cc1f855aca0486e Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 24 Feb 2014 12:48:23 +0000 Subject: [PATCH 075/333] [trunk] Prefer the new style cmake: add_test command Fixes issues 258 --- tests/CMakeLists.txt | 38 +++++++++++----------- tests/conformance/CMakeLists.txt | 52 +++++++++++++++--------------- tests/nonregression/CMakeLists.txt | 32 +++++++++--------- tests/unit/CMakeLists.txt | 6 ++-- 4 files changed, 64 insertions(+), 64 deletions(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 74555dc7..77c4dd61 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -45,38 +45,38 @@ add_executable(test_tile_encoder test_tile_encoder.c) target_link_libraries(test_tile_encoder ${OPENJPEG_LIBRARY_NAME}) # Let's try a couple of possibilities: -add_test(tte0 ${EXECUTABLE_OUTPUT_PATH}/test_tile_encoder) -add_test(tte1 ${EXECUTABLE_OUTPUT_PATH}/test_tile_encoder 3 2048 2048 1024 1024 8 1 tte1.j2k) -add_test(tte2 ${EXECUTABLE_OUTPUT_PATH}/test_tile_encoder 3 2048 2048 1024 1024 8 1 tte2.jp2) -add_test(tte3 ${EXECUTABLE_OUTPUT_PATH}/test_tile_encoder 1 2048 2048 1024 1024 8 1 tte3.j2k) -add_test(tte4 ${EXECUTABLE_OUTPUT_PATH}/test_tile_encoder 1 256 256 128 128 8 0 tte4.j2k) -add_test(tte5 ${EXECUTABLE_OUTPUT_PATH}/test_tile_encoder 1 512 512 256 256 8 0 tte5.j2k) -#add_test(tte6 ${EXECUTABLE_OUTPUT_PATH}/test_tile_encoder 1 8192 8192 512 512 8 0 tte6.j2k) -#add_test(tte7 ${EXECUTABLE_OUTPUT_PATH}/test_tile_encoder 1 32768 32768 512 512 8 0 tte7.jp2) +add_test(NAME tte0 COMMAND test_tile_encoder) +add_test(NAME tte1 COMMAND test_tile_encoder 3 2048 2048 1024 1024 8 1 tte1.j2k) +add_test(NAME tte2 COMMAND test_tile_encoder 3 2048 2048 1024 1024 8 1 tte2.jp2) +add_test(NAME tte3 COMMAND test_tile_encoder 1 2048 2048 1024 1024 8 1 tte3.j2k) +add_test(NAME tte4 COMMAND test_tile_encoder 1 256 256 128 128 8 0 tte4.j2k) +add_test(NAME tte5 COMMAND test_tile_encoder 1 512 512 256 256 8 0 tte5.j2k) +#add_test(NAME tte6 COMMAND test_tile_encoder 1 8192 8192 512 512 8 0 tte6.j2k) +#add_test(NAME tte7 COMMAND test_tile_encoder 1 32768 32768 512 512 8 0 tte7.jp2) add_executable(test_tile_decoder test_tile_decoder.c) target_link_libraries(test_tile_decoder ${OPENJPEG_LIBRARY_NAME}) -add_test(ttd0 ${EXECUTABLE_OUTPUT_PATH}/test_tile_decoder) +add_test(NAME ttd0 COMMAND test_tile_decoder) set_property(TEST ttd0 APPEND PROPERTY DEPENDS tte0) -add_test(ttd1 ${EXECUTABLE_OUTPUT_PATH}/test_tile_decoder 0 0 1024 1024 tte1.j2k) +add_test(NAME ttd1 COMMAND test_tile_decoder 0 0 1024 1024 tte1.j2k) set_property(TEST ttd1 APPEND PROPERTY DEPENDS tte1) -add_test(ttd2 ${EXECUTABLE_OUTPUT_PATH}/test_tile_decoder 0 0 1024 1024 tte2.jp2) +add_test(NAME ttd2 COMMAND test_tile_decoder 0 0 1024 1024 tte2.jp2) set_property(TEST ttd2 APPEND PROPERTY DEPENDS tte2) -#add_test(ttd6 ${EXECUTABLE_OUTPUT_PATH}/test_tile_decoder 0 0 512 512 tte6.j2k) +#add_test(NAME ttd6 COMMAND test_tile_decoder 0 0 512 512 tte6.j2k) #set_property(TEST ttd6 APPEND PROPERTY DEPENDS tte6) -#add_test(ttd7 ${EXECUTABLE_OUTPUT_PATH}/test_tile_decoder 0 0 512 512 tte7.jp2) +#add_test(NAME ttd7 COMMAND test_tile_decoder 0 0 512 512 tte7.jp2) #set_property(TEST ttd7 APPEND PROPERTY DEPENDS tte7) -add_test(rta1 ${EXECUTABLE_OUTPUT_PATH}/j2k_random_tile_access tte1.j2k) +add_test(NAME rta1 COMMAND j2k_random_tile_access tte1.j2k) set_property(TEST rta1 APPEND PROPERTY DEPENDS tte1) -add_test(rta2 ${EXECUTABLE_OUTPUT_PATH}/j2k_random_tile_access tte2.jp2) +add_test(NAME rta2 COMMAND j2k_random_tile_access tte2.jp2) set_property(TEST rta2 APPEND PROPERTY DEPENDS tte2) -add_test(rta3 ${EXECUTABLE_OUTPUT_PATH}/j2k_random_tile_access tte3.j2k) +add_test(NAME rta3 COMMAND j2k_random_tile_access tte3.j2k) set_property(TEST rta3 APPEND PROPERTY DEPENDS tte3) -add_test(rta4 ${EXECUTABLE_OUTPUT_PATH}/j2k_random_tile_access tte4.j2k) +add_test(NAME rta4 COMMAND j2k_random_tile_access tte4.j2k) set_property(TEST rta4 APPEND PROPERTY DEPENDS tte4) -add_test(rta5 ${EXECUTABLE_OUTPUT_PATH}/j2k_random_tile_access tte5.j2k) +add_test(NAME rta5 COMMAND j2k_random_tile_access tte5.j2k) set_property(TEST rta5 APPEND PROPERTY DEPENDS tte5) # No image send to the dashboard if lib PNG is not available. @@ -94,7 +94,7 @@ if(BUILD_JPIP) set(s "${JPIP_SERVER}?target=16.jp2&fsiz=170,170&cnew=http&type=jpp-stream") set(p "${CMAKE_CURRENT_BINARY_DIR}/jpip.dat") set(md5 "62b00c620fb0a600c5ffd413cada4674") - add_test(TestJPIP1 ${CMAKE_COMMAND} -DD_URL:STRING=${s} -DD_FILE:PATH=${p} + add_test(NAME TestJPIP1 COMMAND ${CMAKE_COMMAND} -DD_URL:STRING=${s} -DD_FILE:PATH=${p} -DEXPECTED_MD5=${md5} -P ${PROJECT_SOURCE_DIR}/CMake/JPIPTestDriver.cmake) endif() endif() diff --git a/tests/conformance/CMakeLists.txt b/tests/conformance/CMakeLists.txt index 14c5471a..6f80cf12 100644 --- a/tests/conformance/CMakeLists.txt +++ b/tests/conformance/CMakeLists.txt @@ -327,15 +327,15 @@ foreach(numFileC1P0 RANGE 1 16) list(GET C1P0_PEAK_list ${numFileC1P0} PEAK_limit) list(GET C1P0_MSE_list ${numFileC1P0} MSE_limit) - add_test(ETS-C1P0-${filenameInput}-decode - ${EXECUTABLE_OUTPUT_PATH}/opj_decompress + add_test(NAME ETS-C1P0-${filenameInput}-decode + COMMAND opj_decompress -i ${INPUT_CONF}/${filenameInput} -o ${TEMP}/c1${filenameInput}.pgx -r ${ResFactor} ) - add_test(ETS-C1P0-${filenameInput}-compare2ref - ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages + add_test(NAME ETS-C1P0-${filenameInput}-compare2ref + COMMAND comparePGXimages -b ${BASELINE_CONF}/${filenameRef} -t ${TEMP}/c1${filenameInput}.pgx -n ${nbComponents} @@ -348,8 +348,8 @@ foreach(numFileC1P0 RANGE 1 16) PROPERTIES DEPENDS ETS-C1P0-${filenameInput}-decode) - add_test(NR-C1P0-${filenameInput}-compare2base - ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages + add_test(NAME NR-C1P0-${filenameInput}-compare2base + COMMAND comparePGXimages -b ${BASELINE_NR}/opj_${filenameRef} -t ${TEMP}/c1${filenameInput}.pgx -n ${nbComponents} @@ -384,15 +384,15 @@ foreach(numFileC1P1 RANGE 1 7) list(GET C1P1_PEAK_list ${numFileC1P1} PEAK_limit) list(GET C1P1_MSE_list ${numFileC1P1} MSE_limit) - add_test(ETS-C1P1-${filenameInput}-decode - ${EXECUTABLE_OUTPUT_PATH}/opj_decompress + add_test(NAME ETS-C1P1-${filenameInput}-decode + COMMAND opj_decompress -i ${INPUT_CONF}/${filenameInput} -o ${TEMP}/c1${filenameInput}.pgx -r 0 ) - add_test(ETS-C1P1-${filenameInput}-compare2ref - ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages + add_test(NAME ETS-C1P1-${filenameInput}-compare2ref + COMMAND comparePGXimages -b ${BASELINE_CONF}/${filenameRef} -t ${TEMP}/c1${filenameInput}.pgx -n ${nbComponents} @@ -405,8 +405,8 @@ foreach(numFileC1P1 RANGE 1 7) PROPERTIES DEPENDS ETS-C1P1-${filenameInput}-decode) - add_test(NR-C1P1-${filenameInput}-compare2base - ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages + add_test(NAME NR-C1P1-${filenameInput}-compare2base + COMMAND comparePGXimages -b ${BASELINE_NR}/opj_${filenameRef} -t ${TEMP}/c1${filenameInput}.pgx -n ${nbComponents} @@ -437,8 +437,8 @@ foreach(numFileJP2 RANGE 1 9) # Get corresponding tests parameters list(GET JP2_PEAK_list ${numFileJP2} PEAK_limit) - add_test(ETS-JP2-${filenameInput}-decode - ${EXECUTABLE_OUTPUT_PATH}/opj_decompress + add_test(NAME ETS-JP2-${filenameInput}-decode + COMMAND opj_decompress -i ${INPUT_CONF}/${filenameInput} -o ${TEMP}/${filenameInput}.tif ) @@ -489,14 +489,14 @@ foreach(numFileP0 RANGE 1 16) get_filename_component(filenameRefSub ${filenameInput} NAME_WE) - add_test(NR-${filenameInput}-dump - ${EXECUTABLE_OUTPUT_PATH}/opj_dump + add_test(NAME NR-${filenameInput}-dump + COMMAND opj_dump -i ${INPUT_CONF}/${filenameInput} -o ${TEMP}/${filenameInput}.txt ) - add_test(NR-${filenameInput}-compare_dump2base - ${EXECUTABLE_OUTPUT_PATH}/compare_dump_files + add_test(NAME NR-${filenameInput}-compare_dump2base + COMMAND compare_dump_files -b ${BASELINE_NR}/opj_v2_${filenameRefSub}.txt -t ${TEMP}/${filenameInput}.txt ) @@ -518,14 +518,14 @@ foreach(numFileP1 RANGE 1 7) set( filenameInput p1_0${numFileP1}.j2k ) get_filename_component(filenameInputSub ${filenameInput} NAME_WE) - add_test(NR-${filenameInput}-dump - ${EXECUTABLE_OUTPUT_PATH}/opj_dump + add_test(NAME NR-${filenameInput}-dump + COMMAND opj_dump -i ${INPUT_CONF}/${filenameInput} -o ${TEMP}/${filenameInput}.txt ) - add_test(NR-${filenameInput}-compare_dump2base - ${EXECUTABLE_OUTPUT_PATH}/compare_dump_files + add_test(NAME NR-${filenameInput}-compare_dump2base + COMMAND compare_dump_files -b ${BASELINE_NR}/opj_v2_${filenameInputSub}.txt -t ${TEMP}/${filenameInput}.txt ) @@ -547,14 +547,14 @@ foreach(numFileJP2 RANGE 1 9) set( filenameInput "file${numFileJP2}.jp2" ) get_filename_component(filenameInputSub ${filenameInput} NAME_WE) - add_test(NR-${filenameInput}-dump - ${EXECUTABLE_OUTPUT_PATH}/opj_dump + add_test(NAME NR-${filenameInput}-dump + COMMAND opj_dump -i ${INPUT_CONF}/${filenameInput} -o ${TEMP}/${filenameInput}.txt ) - add_test(NR-${filenameInput}-compare_dump2base - ${EXECUTABLE_OUTPUT_PATH}/compare_dump_files + add_test(NAME NR-${filenameInput}-compare_dump2base + COMMAND compare_dump_files -b ${BASELINE_NR}/opj_v2_${filenameInputSub}.txt -t ${TEMP}/${filenameInput}.txt ) diff --git a/tests/nonregression/CMakeLists.txt b/tests/nonregression/CMakeLists.txt index d03eb6aa..0bcf86bc 100644 --- a/tests/nonregression/CMakeLists.txt +++ b/tests/nonregression/CMakeLists.txt @@ -43,8 +43,8 @@ foreach(INPUT_FILENAME ${OPJ_DATA_NR_LIST}) string(REGEX MATCH ${INPUT_FILENAME_NAME} bad_jpeg2000 ${BLACKLIST_JPEG2000}) # Dump the input image - add_test(NR-${INPUT_FILENAME_NAME}-dump - ${EXECUTABLE_OUTPUT_PATH}/opj_dump + add_test(NAME NR-${INPUT_FILENAME_NAME}-dump + COMMAND opj_dump -i ${INPUT_FILENAME} -o ${TEMP}/${INPUT_FILENAME_NAME}.txt -v @@ -57,8 +57,8 @@ foreach(INPUT_FILENAME ${OPJ_DATA_NR_LIST}) else() # Compare the dump output with the baseline - add_test(NR-${INPUT_FILENAME_NAME}-compare_dump2base - ${EXECUTABLE_OUTPUT_PATH}/compare_dump_files + add_test(NAME NR-${INPUT_FILENAME_NAME}-compare_dump2base + COMMAND compare_dump_files -b ${BASELINE_NR}/opj_v2_${INPUT_FILENAME_NAME_WE}.txt -t ${TEMP}/${INPUT_FILENAME_NAME}.txt ) @@ -229,8 +229,8 @@ foreach(OPJ_TEST_CMD_LINE ${OPJ_TEST_CMD_LINE_LIST}) math(EXPR IT_TEST_ENC "${IT_TEST_ENC}+1" ) # Encode an image into the jpeg2000 format - add_test(NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-encode - ${EXECUTABLE_OUTPUT_PATH}/opj_compress + add_test(NAME NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-encode + COMMAND opj_compress ${CMD_ARG_LIST_2} ) @@ -239,8 +239,8 @@ foreach(OPJ_TEST_CMD_LINE ${OPJ_TEST_CMD_LINE_LIST}) else() # Dump the encoding file - add_test(NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-dump - ${EXECUTABLE_OUTPUT_PATH}/opj_dump + add_test(NAME NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-dump + COMMAND opj_dump -i ${OUTPUT_FILENAME} -o ${OUTPUT_FILENAME}-ENC-${IT_TEST_ENC}.txt ) @@ -249,8 +249,8 @@ foreach(OPJ_TEST_CMD_LINE ${OPJ_TEST_CMD_LINE_LIST}) NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-encode) # Compare the dump file with the baseline - add_test(NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-compare_dump2base - ${EXECUTABLE_OUTPUT_PATH}/compare_dump_files + add_test(NAME NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-compare_dump2base + COMMAND compare_dump_files -b ${BASELINE_NR}/opj_v2_${OUTPUT_FILENAME_NAME_WE}-ENC-${IT_TEST_ENC}.txt -t ${OUTPUT_FILENAME}-ENC-${IT_TEST_ENC}.txt ) @@ -261,8 +261,8 @@ foreach(OPJ_TEST_CMD_LINE ${OPJ_TEST_CMD_LINE_LIST}) # Decode the encoding file with kakadu expand command if (KDU_EXPAND_EXECUTABLE) - add_test(NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-decode-ref - ${KDU_EXPAND_EXECUTABLE} + add_test(NAME NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-decode-ref + COMMAND ${KDU_EXPAND_EXECUTABLE} -i ${OUTPUT_FILENAME} -o ${OUTPUT_FILENAME}.raw ) @@ -272,8 +272,8 @@ foreach(OPJ_TEST_CMD_LINE ${OPJ_TEST_CMD_LINE_LIST}) NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-encode) # Compare the decoding file with baseline generated from the kdu_expand and baseline.j2k - add_test(NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-compare_dec-ref-out2base - ${EXECUTABLE_OUTPUT_PATH}/compareRAWimages + add_test(NAME NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-compare_dec-ref-out2base + COMMAND compareRAWimages -b ${BASELINE_NR}/opj_${OUTPUT_FILENAME_NAME_WE}-ENC-${IT_TEST_ENC}.raw -t ${OUTPUT_FILENAME}.raw ) @@ -290,8 +290,8 @@ foreach(OPJ_TEST_CMD_LINE ${OPJ_TEST_CMD_LINE_LIST}) math(EXPR IT_TEST_DEC "${IT_TEST_DEC}+1" ) # Decode the input image - add_test(NR-DEC-${INPUT_FILENAME_NAME}-${IT_TEST_DEC}-decode - ${EXECUTABLE_OUTPUT_PATH}/opj_decompress + add_test(NAME NR-DEC-${INPUT_FILENAME_NAME}-${IT_TEST_DEC}-decode + COMMAND opj_decompress ${CMD_ARG_LIST_2} ) diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index d6bca7ad..a22d00a1 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -13,6 +13,6 @@ target_link_libraries(testempty0 openjp2) target_link_libraries(testempty1 openjp2) target_link_libraries(testempty2 openjp2) -add_test(testempty0 ${EXECUTABLE_OUTPUT_PATH}/testempty0) -add_test(testempty1 ${EXECUTABLE_OUTPUT_PATH}/testempty1) -add_test(testempty2 ${EXECUTABLE_OUTPUT_PATH}/testempty2) +add_test(NAME testempty0 COMMAND testempty0) +add_test(NAME testempty1 COMMAND testempty1) +add_test(NAME testempty2 COMMAND testempty2) From f42c26adbdf50978df6429f9cb595ab97d486745 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 24 Feb 2014 14:10:11 +0000 Subject: [PATCH 076/333] [trunk] Make sure to handle ret value in test --- tests/unit/testempty1.c | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/tests/unit/testempty1.c b/tests/unit/testempty1.c index 17d16a17..ed9d636f 100644 --- a/tests/unit/testempty1.c +++ b/tests/unit/testempty1.c @@ -39,7 +39,7 @@ void info_callback(const char *msg, void *v); void error_callback(const char *msg, void *v) { (void)msg; (void)v; -assert(0); +puts(msg); } void warning_callback(const char *msg, void *v) { (void)msg; @@ -98,10 +98,10 @@ int main(int argc, char *argv[]) } } - /* catch events using our callbacks and give a local context */ - opj_set_info_handler(l_codec, info_callback,00); - opj_set_warning_handler(l_codec, warning_callback,00); - opj_set_error_handler(l_codec, error_callback,00); + /* catch events using our callbacks and give a local context */ + opj_set_info_handler(l_codec, info_callback,00); + opj_set_warning_handler(l_codec, warning_callback,00); + opj_set_error_handler(l_codec, error_callback,00); l_codec = opj_create_compress(OPJ_CODEC_J2K); opj_set_info_handler(l_codec, info_callback,00); @@ -113,6 +113,13 @@ int main(int argc, char *argv[]) l_stream = opj_stream_create_default_file_stream_v3("testempty1.j2k",OPJ_FALSE); assert(l_stream); bSuccess = opj_start_compress(l_codec,image,l_stream); + if( !bSuccess ) + { + opj_stream_destroy_v3(l_stream); + opj_destroy_codec(l_codec); + opj_image_destroy(image); + return 0; + } assert( bSuccess ); bSuccess = opj_encode(l_codec, l_stream); From c91044a4a7e4ff909848f17c506e633a6d6f4746 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 24 Feb 2014 14:22:25 +0000 Subject: [PATCH 077/333] [trunk] Make sure to handle ret value, and properly initialize output file --- tests/unit/testempty2.c | 32 ++++++++++++++++++++++++-------- 1 file changed, 24 insertions(+), 8 deletions(-) diff --git a/tests/unit/testempty2.c b/tests/unit/testempty2.c index 8d9bc282..e342e015 100644 --- a/tests/unit/testempty2.c +++ b/tests/unit/testempty2.c @@ -40,7 +40,7 @@ void info_callback(const char *msg, void *v); void error_callback(const char *msg, void *v) { (void)msg; (void)v; -assert(0); +puts(msg); } void warning_callback(const char *msg, void *v) { (void)msg; @@ -73,7 +73,7 @@ int main(int argc, char *argv[]) opj_image_t *image; opj_codec_t* l_codec = 00; OPJ_BOOL bSuccess; - opj_stream_t *l_stream = 00; + opj_stream_t *l_stream = 00; (void)argc; (void)argv; @@ -87,6 +87,7 @@ int main(int argc, char *argv[]) cmptparm.dy = subsampling_dy; cmptparm.w = image_width; cmptparm.h = image_height; + strncpy(parameters.outfile, outputfile, sizeof(parameters.outfile)-1); image = opj_image_create(numcomps, &cmptparm, color_space); assert( image ); @@ -100,10 +101,10 @@ int main(int argc, char *argv[]) } } - /* catch events using our callbacks and give a local context */ - opj_set_info_handler(l_codec, info_callback,00); - opj_set_warning_handler(l_codec, warning_callback,00); - opj_set_error_handler(l_codec, error_callback,00); + /* catch events using our callbacks and give a local context */ + opj_set_info_handler(l_codec, info_callback,00); + opj_set_warning_handler(l_codec, warning_callback,00); + opj_set_error_handler(l_codec, error_callback,00); l_codec = opj_create_compress(OPJ_CODEC_J2K); opj_set_info_handler(l_codec, info_callback,00); @@ -113,8 +114,23 @@ int main(int argc, char *argv[]) opj_setup_encoder(l_codec, ¶meters, image); l_stream = opj_stream_create_default_file_stream_v3(parameters.outfile,OPJ_FALSE); + if( !l_stream ) + { + fprintf( stderr, "Something went wrong during creation of stream\n" ); + opj_destroy_codec(l_codec); + opj_image_destroy(image); + opj_stream_destroy_v3(l_stream); + return 1; + } assert(l_stream); bSuccess = opj_start_compress(l_codec,image,l_stream); + if( !bSuccess ) + { + opj_stream_destroy_v3(l_stream); + opj_destroy_codec(l_codec); + opj_image_destroy(image); + return 0; + } assert( bSuccess ); bSuccess = opj_encode(l_codec, l_stream); @@ -131,7 +147,7 @@ int main(int argc, char *argv[]) /* read back the generated file */ { opj_codec_t* d_codec = 00; - opj_dparameters_t dparameters; + opj_dparameters_t dparameters; d_codec = opj_create_decompress(OPJ_CODEC_J2K); opj_set_info_handler(d_codec, info_callback,00); @@ -150,7 +166,7 @@ int main(int argc, char *argv[]) bSuccess = opj_decode(l_codec, l_stream, image); assert( bSuccess ); - bSuccess = opj_end_decompress(l_codec, l_stream); + bSuccess = opj_end_decompress(l_codec, l_stream); assert( bSuccess ); opj_stream_destroy_v3(l_stream); From 963283d7d0c89bf097c3be4b123c8e58d9d306c0 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 24 Feb 2014 14:27:02 +0000 Subject: [PATCH 078/333] [trunk] Fix warning about signed/unsigned mismatch --- tests/unit/testempty1.c | 10 +++++----- tests/unit/testempty2.c | 12 +++++++----- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/tests/unit/testempty1.c b/tests/unit/testempty1.c index ed9d636f..01547e3d 100644 --- a/tests/unit/testempty1.c +++ b/tests/unit/testempty1.c @@ -57,15 +57,15 @@ int main(int argc, char *argv[]) const char * v = opj_version(); const OPJ_COLOR_SPACE color_space = OPJ_CLRSPC_GRAY; - int numcomps = 1; + unsigned int numcomps = 1; int i; - int image_width = 256; - int image_height = 256; + unsigned int image_width = 256; + unsigned int image_height = 256; opj_cparameters_t parameters; - int subsampling_dx = 0; - int subsampling_dy = 0; + unsigned int subsampling_dx = 0; + unsigned int subsampling_dy = 0; opj_image_cmptparm_t cmptparm; opj_image_t *image; diff --git a/tests/unit/testempty2.c b/tests/unit/testempty2.c index e342e015..dbbbaf93 100644 --- a/tests/unit/testempty2.c +++ b/tests/unit/testempty2.c @@ -58,15 +58,15 @@ int main(int argc, char *argv[]) const char * v = opj_version(); const OPJ_COLOR_SPACE color_space = OPJ_CLRSPC_GRAY; - int numcomps = 1; + unsigned int numcomps = 1; int i; - int image_width = 256; - int image_height = 256; + unsigned int image_width = 256; + unsigned int image_height = 256; opj_cparameters_t parameters; - int subsampling_dx = parameters.subsampling_dx; - int subsampling_dy = parameters.subsampling_dy; + unsigned int subsampling_dx; + unsigned int subsampling_dy; const char outputfile[] = "testempty2.j2k"; opj_image_cmptparm_t cmptparm; @@ -80,6 +80,8 @@ int main(int argc, char *argv[]) opj_set_default_encoder_parameters(¶meters); parameters.cod_format = J2K_CFMT; puts(v); + subsampling_dx = (unsigned int)parameters.subsampling_dx; + subsampling_dy = (unsigned int)parameters.subsampling_dy; cmptparm.prec = 8; cmptparm.bpp = 8; cmptparm.sgnd = 0; From f38e29d00a380f3ec03c700dffefa2d648123476 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 24 Feb 2014 14:50:40 +0000 Subject: [PATCH 079/333] [trunk] Fix two simple warnings about sign mismatch --- tests/unit/testempty1.c | 2 +- tests/unit/testempty2.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/unit/testempty1.c b/tests/unit/testempty1.c index 01547e3d..f4140f64 100644 --- a/tests/unit/testempty1.c +++ b/tests/unit/testempty1.c @@ -58,7 +58,7 @@ int main(int argc, char *argv[]) const OPJ_COLOR_SPACE color_space = OPJ_CLRSPC_GRAY; unsigned int numcomps = 1; - int i; + unsigned int i; unsigned int image_width = 256; unsigned int image_height = 256; diff --git a/tests/unit/testempty2.c b/tests/unit/testempty2.c index dbbbaf93..764b14cc 100644 --- a/tests/unit/testempty2.c +++ b/tests/unit/testempty2.c @@ -59,7 +59,7 @@ int main(int argc, char *argv[]) const OPJ_COLOR_SPACE color_space = OPJ_CLRSPC_GRAY; unsigned int numcomps = 1; - int i; + unsigned int i; unsigned int image_width = 256; unsigned int image_height = 256; From 228e0a3d7924479f763ae164ff4fc70891f0ef7d Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 24 Feb 2014 14:55:32 +0000 Subject: [PATCH 080/333] [trunk] Fix a simple mem leak --- src/bin/jp2/convert.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index 6997def9..0b1291de 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -2856,6 +2856,7 @@ static opj_image_t* rawtoimage_common(const char *filename, opj_cparameters_t *p } /* create the image */ image = opj_image_create(numcomps, &cmptparm[0], color_space); + free(cmptparm); if(!image) { fclose(f); return NULL; From ff0a9f763e98242cc6517e4a2aa80a3b4d9ee9e2 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 24 Feb 2014 16:07:21 +0000 Subject: [PATCH 081/333] [trunk] improve test suite by checking against a reference md5 --- tests/nonregression/CMakeLists.txt | 6 ++++ tests/nonregression/checkmd5refs.cmake | 48 ++++++++++++++++++++++++++ tests/nonregression/md5refs.txt | 0 3 files changed, 54 insertions(+) create mode 100644 tests/nonregression/checkmd5refs.cmake create mode 100644 tests/nonregression/md5refs.txt diff --git a/tests/nonregression/CMakeLists.txt b/tests/nonregression/CMakeLists.txt index 0bcf86bc..95fd08af 100644 --- a/tests/nonregression/CMakeLists.txt +++ b/tests/nonregression/CMakeLists.txt @@ -300,6 +300,12 @@ foreach(OPJ_TEST_CMD_LINE ${OPJ_TEST_CMD_LINE_LIST}) set_tests_properties(NR-DEC-${INPUT_FILENAME_NAME}-${IT_TEST_DEC}-decode PROPERTIES WILL_FAIL TRUE) else() + # if not failed, check against registered md5: + add_test(NAME NR-DEC-${INPUT_FILENAME_NAME}-${IT_TEST_DEC}-decode-md5 COMMAND ${CMAKE_COMMAND} + -DREFFILE:STRING=${CMAKE_CURRENT_SOURCE_DIR}/md5refs.txt + -DFILENAME:STRING=${INPUT_FILENAME_NAME} + -P ${CMAKE_CURRENT_SOURCE_DIR}/checkmd5refs.cmake) + # FIXME: add a compare2base function base on raw which # can output png diff files if necesary diff --git a/tests/nonregression/checkmd5refs.cmake b/tests/nonregression/checkmd5refs.cmake new file mode 100644 index 00000000..fd583e2a --- /dev/null +++ b/tests/nonregression/checkmd5refs.cmake @@ -0,0 +1,48 @@ +# Copyright (c) 2014 Mathieu Malaterre +# +# Redistribution and use is allowed according to the terms of the New +# BSD license. +# For details see the accompanying COPYING-CMAKE-SCRIPTS file. + +# check md5 refs +# +# This script will be used to make sure we never introduce a regression on any +# of the nonregression file. +# +# The approach is relatively simple, we compute a md5sum for each of the decode +# file. Anytime the md5sum is different from the reference one, we assume +# something went wrong and simply fails. of course if could happen during the +# course of openjpeg development that the internals are changed that impact the +# decoding process that the output would be bitwise different (while PSNR would +# be kept identical). + +#message("0: ${REFFILE}") +#message("1: ${CMAKE_CURRENT_BINARY_DIR}") +#message("2: ${FILENAME}") +execute_process( + COMMAND ${CMAKE_COMMAND} -E md5sum ${FILENAME}.png + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Temporary + RESULT_VARIABLE res + OUTPUT_VARIABLE output + ERROR_VARIABLE error_output + OUTPUT_STRIP_TRAILING_WHITESPACE # important +) + +# Pass the output back to ctest +if(res) + message(SEND_ERROR "md5 could not be computed, it failed with value ${res}. Output was: ${error_output}") +endif() + +#message("3: ${output}") + +file(READ ${REFFILE} variable) +#message("4: ${variable}") +string(REGEX MATCH "^.*${FILENAME}.png" output_var ${variable}) + +#message("5: ${output_var}") + +if("${output_var}" STREQUAL "${output}") + #message("6: eqal") +else() + message(SEND_ERROR "not equal: [${output_var}] vs [${output}]") +endif() diff --git a/tests/nonregression/md5refs.txt b/tests/nonregression/md5refs.txt new file mode 100644 index 00000000..e69de29b From 531cd5dd1428a126515d7376899abed0913deef5 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 24 Feb 2014 16:09:42 +0000 Subject: [PATCH 082/333] [trunk] add test demonstrating a regression in 1.5.0 and up. Update issue 205 --- tests/nonregression/test_suite.ctest.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 9a1ccfb2..d551cbb0 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -97,6 +97,8 @@ opj_decompress -i @INPUT_NR_PATH@/file409752.jp2 -o @TEMP_PATH@/file409752.png opj_decompress -i @INPUT_NR_PATH@/issue188_beach_64bitsbox.jp2 -o @TEMP_PATH@/issue188_beach_64bitsbox.jp2.tif # issue 206 opj_decompress -i @INPUT_NR_PATH@/issue206_image-000.jp2 -o @TEMP_PATH@/issue206_image-000.jp2.png +# issue 205 +opj_decompress -i @INPUT_NR_PATH@/issue205.jp2 -o @TEMP_PATH@/issue205.jp2.png # decode with specific area # prec=12; nb_c=1 From c55e164e87fcdc2a974474863d7c550f0218598f Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 24 Feb 2014 16:55:13 +0000 Subject: [PATCH 083/333] [trunk] Make sure to always output pgx file. Handle case where multiple pgx files are generated. Fixes all tests. --- tests/nonregression/checkmd5refs.cmake | 56 ++++++++++------- tests/nonregression/md5refs.txt | 83 +++++++++++++++++++++++++ tests/nonregression/test_suite.ctest.in | 8 +-- 3 files changed, 119 insertions(+), 28 deletions(-) diff --git a/tests/nonregression/checkmd5refs.cmake b/tests/nonregression/checkmd5refs.cmake index fd583e2a..80de4ea9 100644 --- a/tests/nonregression/checkmd5refs.cmake +++ b/tests/nonregression/checkmd5refs.cmake @@ -19,30 +19,38 @@ #message("0: ${REFFILE}") #message("1: ${CMAKE_CURRENT_BINARY_DIR}") #message("2: ${FILENAME}") -execute_process( - COMMAND ${CMAKE_COMMAND} -E md5sum ${FILENAME}.png - WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Temporary - RESULT_VARIABLE res - OUTPUT_VARIABLE output - ERROR_VARIABLE error_output - OUTPUT_STRIP_TRAILING_WHITESPACE # important -) - -# Pass the output back to ctest -if(res) - message(SEND_ERROR "md5 could not be computed, it failed with value ${res}. Output was: ${error_output}") -endif() - -#message("3: ${output}") +file(GLOB globfiles "Temporary/${FILENAME}*.pgx" ) +#message("6: ${globfiles}") +# REFFILE follow what md5sum -c would expect as input: file(READ ${REFFILE} variable) -#message("4: ${variable}") -string(REGEX MATCH "^.*${FILENAME}.png" output_var ${variable}) +#string(REGEX REPLACE "\r?\n" ";" variable "${variable}") -#message("5: ${output_var}") - -if("${output_var}" STREQUAL "${output}") - #message("6: eqal") -else() - message(SEND_ERROR "not equal: [${output_var}] vs [${output}]") -endif() +foreach(pgxfullpath ${globfiles}) + get_filename_component(pgxfile ${pgxfullpath} NAME) + #message("8: ${pgxfile}") + execute_process( + COMMAND ${CMAKE_COMMAND} -E md5sum ${pgxfile} + WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Temporary + RESULT_VARIABLE res + OUTPUT_VARIABLE output + ERROR_VARIABLE error_output + OUTPUT_STRIP_TRAILING_WHITESPACE # important + ) + + # Pass the output back to ctest + if(res) + message(SEND_ERROR "md5 could not be computed, it failed with value ${res}. Output was: ${error_output}") + endif() + #message("3: ${output}") + + #message("4: ${variable}") + string(REGEX MATCH "[0-9a-f]+ ${pgxfile}" output_var "${variable}") + #message("5: ${output_var}") + + if("${output_var}" STREQUAL "${output}") + #message("6: eqal") + else() + message(SEND_ERROR "not equal: [${output_var}] vs [${output}]") + endif() +endforeach() diff --git a/tests/nonregression/md5refs.txt b/tests/nonregression/md5refs.txt index e69de29b..94cec750 100644 --- a/tests/nonregression/md5refs.txt +++ b/tests/nonregression/md5refs.txt @@ -0,0 +1,83 @@ +6f22c9a9bd474202ac6cd3a066e15200 _00042.j2k_0.pgx +a3a0606dfa0779d657c6a923b90e4678 _00042.j2k_1.pgx +106954dc468dfe0884d02268e91f9f5b _00042.j2k_2.pgx +8889def55f1e18dae6002b9b3a6dd152 123.j2c_0.pgx +4a0daf7a9065101379eaebc28e436b1e Bretagne2.j2k_0.pgx +07578fc7bf81d3da694de8ae27308b82 Bretagne2.j2k_1.pgx +3690c42f83bad42f4abea48525d45e0e Bretagne2.j2k_2.pgx +8889def55f1e18dae6002b9b3a6dd152 bug.j2c_0.pgx +22c8d33a956ba83079d1102457bc77a1 buxI.j2k_0.pgx +b8f473c07ba5ebfc195bdd53c3b3b97f buxR.j2k_0.pgx +05c062aca83d13b8095460f38a690a08 Cannotreaddatawithnosizeknown.j2k_0.pgx +6276da0ec5fac44d683d3468b290331d cthead1.j2k_0.pgx +8afcac9a696cc8d753b0eb9f4ae692ff CT_Phillips_JPEG2K_Decompr_Problem.j2k_0.pgx +04d35ab6160c9029549f72358df984da file409752_0.pgx +2813bd6fdc2c306b91b3da3688b8bf49 file409752_1.pgx +e273e2aaea4a4fc1b2cf7c09c53c3cc6 file409752_2.pgx +05c062aca83d13b8095460f38a690a08 illegalcolortransform.j2k_0.pgx +cb28787aa7c223f03e6acad71e244108 issue104_jpxstream.jp2_0.pgx +cb28787aa7c223f03e6acad71e244108 issue104_jpxstream.jp2_1.pgx +cb28787aa7c223f03e6acad71e244108 issue104_jpxstream.jp2_2.pgx +adda4f5e46845b96dd3df14a76aa7229 issue188_beach_64bitsbox.jp2_0.pgx +90a9709c166019d1e101e7b96d257ed9 issue188_beach_64bitsbox.jp2_1.pgx +37e23d2df06ee60bf0f9f5e1c16054d8 issue188_beach_64bitsbox.jp2_2.pgx +cb89739232898a823355861d834b5734 issue205.jp2_0.pgx +a09d34928fd86e6f2d7e6edc1764d2b7 issue205.jp2_1.pgx +6f712d0685f2c5522f01b238365f4284 issue205.jp2_2.pgx +de992d54d59032eb07d21983dbe8155b issue205.jp2_3.pgx +8fae7a39e459409f64e4529d2214087a issue206_image-000.jp2_0.pgx +555a504a93c9a14f61c894da3b393e87 issue206_image-000.jp2_1.pgx +5f06b7c45446ae20c22cada46478a9dc issue206_image-000.jp2_2.pgx +4093cc34d838780b35a8be410247fa7f j2k32.j2k_0.pgx +ce4e556aaa0844b92a92c35c200fc43e j2k32.j2k_1.pgx +ea926520f990640862f3fe6616097613 j2k32.j2k_2.pgx +66b60e866991e03f9a2de18e80d3102b kakadu_v4-4_openjpegv2_broken.j2k_0.pgx +12a8a4668315d9ae27969991251ce85f kodak_2layers_lrcp.j2c_0.pgx +56d0b0c547d6d5bb12f0c36e88722b11 kodak_2layers_lrcp.j2c_1.pgx +48ba092fb40090c160bbd08bdf7bdbf2 kodak_2layers_lrcp.j2c_2.pgx +05c062aca83d13b8095460f38a690a08 MarkerIsNotCompliant.j2k_0.pgx +ff73d2bd32951d9e55b02186aac24aff Marrin.jp2_0.pgx +55ce884dd2346af6a5172a434ee578fa Marrin.jp2_1.pgx +29131264861b4ee21011149b27e4d488 mem-b2ace68c-1381.jp2_0.pgx +29131264861b4ee21011149b27e4d488 mem-b2ace68c-1381.jp2_1.pgx +29131264861b4ee21011149b27e4d488 mem-b2ace68c-1381.jp2_2.pgx +df568fe0529219cc2c8f215e236f4b3d mem-b2ace68c-1381.jp2_3.pgx +41ec1a0228c703b10f95388c1160753b mem-b2b86b74-2753.jp2_0.pgx +41ec1a0228c703b10f95388c1160753b mem-b2b86b74-2753.jp2_1.pgx +41ec1a0228c703b10f95388c1160753b mem-b2b86b74-2753.jp2_2.pgx +97557ab9e38a7aff621e583fbb66b099 merged.jp2_0.pgx +386fbdcd294429733e3272d62ed5a15a merged.jp2_1.pgx +d3907bbd67be1dae31b4377fa4dc0373 merged.jp2_2.pgx +de8bba9ac366eeb2f170f0cf3605cf12 movie_00000.j2k_0.pgx +334bac3285f7138e9dd29d59bdcb22ff movie_00000.j2k_1.pgx +5511d2c96d1d1f2062491e00d5234506 movie_00000.j2k_2.pgx +de8bba9ac366eeb2f170f0cf3605cf12 movie_00001.j2k_0.pgx +334bac3285f7138e9dd29d59bdcb22ff movie_00001.j2k_1.pgx +5511d2c96d1d1f2062491e00d5234506 movie_00001.j2k_2.pgx +de8bba9ac366eeb2f170f0cf3605cf12 movie_00002.j2k_0.pgx +334bac3285f7138e9dd29d59bdcb22ff movie_00002.j2k_1.pgx +5511d2c96d1d1f2062491e00d5234506 movie_00002.j2k_2.pgx +951a55623a92e97a064a350f11c2637d orb-blue10-lin-j2k.j2k_0.pgx +5033aaf699dfa3dfe041af33c9ad688d orb-blue10-lin-j2k.j2k_1.pgx +dbe33d72484caedf9c2cc18fd670884c orb-blue10-lin-j2k.j2k_2.pgx +0fec67d9546171699958c6682e725b79 orb-blue10-lin-j2k.j2k_3.pgx +84462261381b6732ec4f2addb0070d24 orb-blue10-lin-jp2.jp2_0.pgx +6129edf57e5db2344fcde5ce99ae8732 orb-blue10-lin-jp2.jp2_1.pgx +fdad26b1e078aa32bd4b77a5f44da43c orb-blue10-lin-jp2.jp2_2.pgx +0fec67d9546171699958c6682e725b79 orb-blue10-lin-jp2.jp2_3.pgx +671feee525e2485060536edbf21380f1 orb-blue10-win-j2k.j2k_0.pgx +912cdee24dd360b7999f7ee4a51083b4 orb-blue10-win-j2k.j2k_1.pgx +64833b4b7557936b9233087e92f8ae28 orb-blue10-win-j2k.j2k_2.pgx +789a299a1523b2d9d3f561d12a2da817 orb-blue10-win-j2k.j2k_3.pgx +671feee525e2485060536edbf21380f1 orb-blue10-win-jp2.jp2_0.pgx +7442756e83571c0e87493e03f12b2d34 orb-blue10-win-jp2.jp2_1.pgx +5f99ff2aeb17e167fe7049bcf339d0b3 orb-blue10-win-jp2.jp2_2.pgx +fe028d56d6c7aaee87239a115093412a orb-blue10-win-jp2.jp2_3.pgx +371aa0a7ff40a73b45f1fa41e210d1db pacs.ge.j2k_0.pgx +6ae110e1fb5a869af3dbc5fbc735b0bd relax.jp2_0.pgx +518a8f28dacc034982507f43763b88dd relax.jp2_1.pgx +c678b04f4d3e59b9d66a8bce37c553c0 relax.jp2_2.pgx +cdb1d69eb48ffd8545751326b86d9d7e test_lossless.j2k_0.pgx +a37e7e5811d7c0c7adb61582790ccd33 text_GBR.jp2_0.pgx +fc2173be54954a146b4e2887ee14be06 text_GBR.jp2_1.pgx +14108b4fb8d9126750db0424417ed17d text_GBR.jp2_2.pgx diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index d551cbb0..aa60876d 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -92,13 +92,13 @@ opj_decompress -i @INPUT_NR_PATH@/mem-b2b86b74-2753.jp2 -o @TEMP_PATH@/mem-b2b8 # issue 194 raised by the gdal fuzzer test (should nicely failed) ! opj_decompress -i @INPUT_NR_PATH@/gdal_fuzzer_check_comp_dx_dy.jp2 -o @TEMP_PATH@/gdal_fuzzer_check_comp_dx_dy.pgx # issue 202 -opj_decompress -i @INPUT_NR_PATH@/file409752.jp2 -o @TEMP_PATH@/file409752.png +opj_decompress -i @INPUT_NR_PATH@/file409752.jp2 -o @TEMP_PATH@/file409752.pgx # issue 188 -opj_decompress -i @INPUT_NR_PATH@/issue188_beach_64bitsbox.jp2 -o @TEMP_PATH@/issue188_beach_64bitsbox.jp2.tif +opj_decompress -i @INPUT_NR_PATH@/issue188_beach_64bitsbox.jp2 -o @TEMP_PATH@/issue188_beach_64bitsbox.jp2.pgx # issue 206 -opj_decompress -i @INPUT_NR_PATH@/issue206_image-000.jp2 -o @TEMP_PATH@/issue206_image-000.jp2.png +opj_decompress -i @INPUT_NR_PATH@/issue206_image-000.jp2 -o @TEMP_PATH@/issue206_image-000.jp2.pgx # issue 205 -opj_decompress -i @INPUT_NR_PATH@/issue205.jp2 -o @TEMP_PATH@/issue205.jp2.png +opj_decompress -i @INPUT_NR_PATH@/issue205.jp2 -o @TEMP_PATH@/issue205.jp2.pgx # decode with specific area # prec=12; nb_c=1 From d847e477f083388e79d6debbdff4a8bff09bd964 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 24 Feb 2014 17:22:48 +0000 Subject: [PATCH 084/333] [trunk] add missing private lib. Update issue 223 --- src/lib/openjp2/libopenjp2.pc.cmake.in | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/openjp2/libopenjp2.pc.cmake.in b/src/lib/openjp2/libopenjp2.pc.cmake.in index 42f33d0c..62159b00 100644 --- a/src/lib/openjp2/libopenjp2.pc.cmake.in +++ b/src/lib/openjp2/libopenjp2.pc.cmake.in @@ -10,4 +10,5 @@ Description: JPEG2000 library (Part 1 and 2) URL: http://www.openjpeg.org/ Version: @OPENJPEG_VERSION@ Libs: -L${libdir} -lopenjp2 +Libs.private: -lm Cflags: -I${includedir} From 00b049866bd33355462ca161764c2fa4493b4ab7 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 25 Feb 2014 10:06:37 +0000 Subject: [PATCH 085/333] [trunk] Run sumatrapdf test cases --- tests/nonregression/test_suite.ctest.in | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index aa60876d..dde8a58f 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -99,6 +99,21 @@ opj_decompress -i @INPUT_NR_PATH@/issue188_beach_64bitsbox.jp2 -o @TEMP_PATH@/i opj_decompress -i @INPUT_NR_PATH@/issue206_image-000.jp2 -o @TEMP_PATH@/issue206_image-000.jp2.pgx # issue 205 opj_decompress -i @INPUT_NR_PATH@/issue205.jp2 -o @TEMP_PATH@/issue205.jp2.pgx +# issue 225 (sumatrapdf) +opj_decompress -i @INPUT_NR_PATH@/451.pdf.SIGSEGV.5b5.3723.jp2 -o @TEMP_PATH@/451.pdf.SIGSEGV.5b5.3723.jp2.pgx +opj_decompress -i @INPUT_NR_PATH@/1888.pdf.asan.35.988.jp2 -o @TEMP_PATH@/1888.pdf.asan.35.988.jp2.pgx +opj_decompress -i @INPUT_NR_PATH@/2539.pdf.SIGFPE.706.1712.jp2 -o @TEMP_PATH@/2539.pdf.SIGFPE.706.1712.jp2.pgx +opj_decompress -i @INPUT_NR_PATH@/2236.pdf.SIGSEGV.398.1376.jp2 -o @TEMP_PATH@/2236.pdf.SIGSEGV.398.1376.jp.pgx2 +opj_decompress -i @INPUT_NR_PATH@/1336.pdf.asan.47.376.jp2 -o @TEMP_PATH@/1336.pdf.asan.47.376.jp2.pgx +opj_decompress -i @INPUT_NR_PATH@/1851.pdf.SIGSEGV.ce9.948.jp2 -o @TEMP_PATH@/1851.pdf.SIGSEGV.ce9.948.jp2.pgx +opj_decompress -i @INPUT_NR_PATH@/4149.pdf.SIGSEGV.cf7.3501.jp2 -o @TEMP_PATH@/4149.pdf.SIGSEGV.cf7.3501.jp.pgx2 +opj_decompress -i @INPUT_NR_PATH@/4035.pdf.SIGSEGV.d8b.3375.jp2 -o @TEMP_PATH@/4035.pdf.SIGSEGV.d8b.3375.jp.pgx2 +opj_decompress -i @INPUT_NR_PATH@/2977.pdf.asan.67.2198.jp2 -o @TEMP_PATH@/2977.pdf.asan.67.2198.jp2.pgx +opj_decompress -i @INPUT_NR_PATH@/451.pdf.SIGSEGV.ce9.3723.jp2 -o @TEMP_PATH@/451.pdf.SIGSEGV.ce9.3723.jp2.pgx +opj_decompress -i @INPUT_NR_PATH@/3635.pdf.asan.77.2930.jp2 -o @TEMP_PATH@/3635.pdf.asan.77.2930.jp2.pgx +opj_decompress -i @INPUT_NR_PATH@/1802.pdf.SIGSEGV.36e.894.jp2 -o @TEMP_PATH@/1802.pdf.SIGSEGV.36e.894.jp2.pgx +opj_decompress -i @INPUT_NR_PATH@/451.pdf.SIGSEGV.f4c.3723.jp2 -o @TEMP_PATH@/451.pdf.SIGSEGV.f4c.3723.jp2.pgx +opj_decompress -i @INPUT_NR_PATH@/2.pdf.SIGFPE.706.1112.jp2 -o @TEMP_PATH@/2.pdf.SIGFPE.706.1112.jp2.pgx # decode with specific area # prec=12; nb_c=1 From 1378475573b2fd61c54f2fe295e40f183762f435 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 25 Feb 2014 10:30:40 +0000 Subject: [PATCH 086/333] [trunk] Run test case for issue 228. Output has been validated. Fixes issue 228 --- tests/nonregression/md5refs.txt | 1 + tests/nonregression/test_suite.ctest.in | 2 ++ 2 files changed, 3 insertions(+) diff --git a/tests/nonregression/md5refs.txt b/tests/nonregression/md5refs.txt index 94cec750..8d98c567 100644 --- a/tests/nonregression/md5refs.txt +++ b/tests/nonregression/md5refs.txt @@ -28,6 +28,7 @@ de992d54d59032eb07d21983dbe8155b issue205.jp2_3.pgx 8fae7a39e459409f64e4529d2214087a issue206_image-000.jp2_0.pgx 555a504a93c9a14f61c894da3b393e87 issue206_image-000.jp2_1.pgx 5f06b7c45446ae20c22cada46478a9dc issue206_image-000.jp2_2.pgx +e1807db57b5f5192c4b77b83e8b5c477 issue228.j2k_0.pgx 4093cc34d838780b35a8be410247fa7f j2k32.j2k_0.pgx ce4e556aaa0844b92a92c35c200fc43e j2k32.j2k_1.pgx ea926520f990640862f3fe6616097613 j2k32.j2k_2.pgx diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index dde8a58f..b4a66629 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -114,6 +114,8 @@ opj_decompress -i @INPUT_NR_PATH@/3635.pdf.asan.77.2930.jp2 -o @TEMP_PATH@/3 opj_decompress -i @INPUT_NR_PATH@/1802.pdf.SIGSEGV.36e.894.jp2 -o @TEMP_PATH@/1802.pdf.SIGSEGV.36e.894.jp2.pgx opj_decompress -i @INPUT_NR_PATH@/451.pdf.SIGSEGV.f4c.3723.jp2 -o @TEMP_PATH@/451.pdf.SIGSEGV.f4c.3723.jp2.pgx opj_decompress -i @INPUT_NR_PATH@/2.pdf.SIGFPE.706.1112.jp2 -o @TEMP_PATH@/2.pdf.SIGFPE.706.1112.jp2.pgx +# issue 228 (16bits/lossy) +opj_decompress -i @INPUT_NR_PATH@/issue228.j2k -o @TEMP_PATH@/issue228.j2k.pgx # decode with specific area # prec=12; nb_c=1 From 3ca312033f99eea39fecd83dde5e5797436d6648 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 25 Feb 2014 10:35:07 +0000 Subject: [PATCH 087/333] [trunk] Clarify raw input in openjpeg. LSB vs MSB are now documented. Fixes issue 62 --- src/bin/common/format_defs.h | 4 ++-- src/bin/jp2/opj_compress.c | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bin/common/format_defs.h b/src/bin/common/format_defs.h index e82986cc..386f21dc 100644 --- a/src/bin/common/format_defs.h +++ b/src/bin/common/format_defs.h @@ -41,9 +41,9 @@ #define BMP_DFMT 12 #define YUV_DFMT 13 #define TIF_DFMT 14 -#define RAW_DFMT 15 +#define RAW_DFMT 15 /* MSB / Big Endian */ #define TGA_DFMT 16 #define PNG_DFMT 17 -#define RAWL_DFMT 18 +#define RAWL_DFMT 18 /* LSB / Little Endian */ #endif /* _OPJ_FORMAT_DEFS_H_ */ diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index 73fdc064..7b1c9471 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -133,7 +133,7 @@ static void encode_help_display(void) { fprintf(stdout,"-OutFor \n"); fprintf(stdout," REQUIRED only if -ImgDir is used\n"); fprintf(stdout," Need to specify only format without filename \n"); - fprintf(stdout," Currently accepts PBM, PGM, PPM, PNM, PAM, PGX, PNG, BMP, TIF, RAW, RAWL and TGA formats\n"); + fprintf(stdout," Currently accepts PBM, PGM, PPM, PNM, PAM, PGX, PNG, BMP, TIF, RAW (MSB), RAWL (LSB) and TGA formats\n"); fprintf(stdout,"\n"); fprintf(stdout,"-i : source file (-i source.pnm also *pbm, *.pgm, *.ppm, *.pam, *.pgx, *png, *.bmp, *.tif, *.raw, *.tga) \n"); fprintf(stdout," When using this option -o must be used\n"); From 876c02206da3017745fdd1ab7f555a956c73ca0c Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 25 Feb 2014 13:28:37 +0000 Subject: [PATCH 088/333] [trunk] Import commit f4139d702559649e577a5df9cfd64b0ca6107a7a from ghostpdl Several functions accept a buffer size but never actually check whether the buffer overflows during reading/writing. This fixes all cases where a size variable has explicitly been marked as unused (through a (void) cast). This was discovered while investigating an assertion caused by 7cc691f332f26802c64cdc47e17bff8b_signal_sigabrt_7ffff6d59425_2247_2509.pdf among others. Thanks to Mateusz Jurczyk and Gynvael Coldwind of the Google Security Team for providing the example files. --- src/lib/openjp2/event.c | 2 +- src/lib/openjp2/jp2.c | 27 +++++++++++++++++++++++++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/src/lib/openjp2/event.c b/src/lib/openjp2/event.c index 6c53515b..42f59f0f 100644 --- a/src/lib/openjp2/event.c +++ b/src/lib/openjp2/event.c @@ -118,7 +118,7 @@ OPJ_BOOL opj_event_msg(opj_event_mgr_t* p_event_mgr, OPJ_INT32 event_type, const str_length = (strlen(fmt) > OPJ_MSG_SIZE) ? OPJ_MSG_SIZE : strlen(fmt); (void)str_length; /* parse the format string and put the result in 'message' */ - vsprintf(message, fmt, arg); /* UniPG */ + vsnprintf(message, OPJ_MSG_SIZE, fmt, arg); /* UniPG */ /* deinitialize the optional parameter list */ va_end(arg); diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c index 77df1529..af25f328 100644 --- a/src/lib/openjp2/jp2.c +++ b/src/lib/openjp2/jp2.c @@ -837,6 +837,7 @@ OPJ_BOOL opj_jp2_read_pclr( opj_jp2_t *jp2, OPJ_UINT16 nr_entries,nr_channels; OPJ_UINT16 i, j; OPJ_UINT32 l_value; + OPJ_BYTE *orig_header_data = p_pclr_header_data; /* preconditions */ assert(p_pclr_header_data != 00); @@ -847,6 +848,9 @@ OPJ_BOOL opj_jp2_read_pclr( opj_jp2_t *jp2, if(jp2->color.jp2_pclr) return OPJ_FALSE; + if (p_pclr_header_size < 3) + return OPJ_FALSE; + opj_read_bytes(p_pclr_header_data, &l_value , 2); /* NE */ p_pclr_header_data += 2; nr_entries = (OPJ_UINT16) l_value; @@ -855,6 +859,9 @@ OPJ_BOOL opj_jp2_read_pclr( opj_jp2_t *jp2, ++p_pclr_header_data; nr_channels = (OPJ_UINT16) l_value; + if (p_pclr_header_size < 3 + (OPJ_UINT32)nr_channels || nr_channels == 0 || nr_entries >= (OPJ_UINT32)-1 / nr_channels) + return OPJ_FALSE; + entries = (OPJ_UINT32*) opj_malloc(nr_channels * nr_entries * sizeof(OPJ_UINT32)); if (!entries) return OPJ_FALSE; @@ -902,6 +909,11 @@ OPJ_BOOL opj_jp2_read_pclr( opj_jp2_t *jp2, for(i = 0; i < nr_channels; ++i) { OPJ_INT32 bytes_to_read = (channel_size[i]+7)>>3; + if (bytes_to_read > sizeof(OPJ_UINT32)) + bytes_to_read = sizeof(OPJ_UINT32); + if ((ptrdiff_t)p_pclr_header_size < p_pclr_header_data - orig_header_data + bytes_to_read) + return OPJ_FALSE; + opj_read_bytes(p_pclr_header_data, &l_value , bytes_to_read); /* Cji */ p_pclr_header_data += bytes_to_read; *entries = (OPJ_UINT32) l_value; @@ -943,6 +955,11 @@ OPJ_BOOL opj_jp2_read_cmap( opj_jp2_t * jp2, } nr_channels = jp2->color.jp2_pclr->nr_channels; + if (p_cmap_header_size < (OPJ_UINT32)nr_channels * 4) { + opj_event_msg(p_manager, EVT_ERROR, "Insufficient data for CMAP box.\n"); + return OPJ_FALSE; + } + cmap = (opj_jp2_cmap_comp_t*) opj_malloc(nr_channels * sizeof(opj_jp2_cmap_comp_t)); if (!cmap) return OPJ_FALSE; @@ -1022,6 +1039,11 @@ OPJ_BOOL opj_jp2_read_cdef( opj_jp2_t * jp2, * inside a JP2 Header box.'*/ if(jp2->color.jp2_cdef) return OPJ_FALSE; + if (p_cdef_header_size < 2) { + opj_event_msg(p_manager, EVT_ERROR, "Insufficient data for CDEF box.\n"); + return OPJ_FALSE; + } + opj_read_bytes(p_cdef_header_data,&l_value ,2); /* N */ p_cdef_header_data+= 2; @@ -1030,6 +1052,11 @@ OPJ_BOOL opj_jp2_read_cdef( opj_jp2_t * jp2, return OPJ_FALSE; } + if (p_cdef_header_size < 2 + (OPJ_UINT32)(OPJ_UINT16)l_value * 6) { + opj_event_msg(p_manager, EVT_ERROR, "Insufficient data for CDEF box.\n"); + return OPJ_FALSE; + } + cdef_info = (opj_jp2_cdef_info_t*) opj_malloc(l_value * sizeof(opj_jp2_cdef_info_t)); if (!cdef_info) return OPJ_FALSE; From 6145c8280478c84658982d110dbc72fff4979e0d Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 25 Feb 2014 13:33:43 +0000 Subject: [PATCH 089/333] [trunk] Import commit 8ec8321df613986e8642e2975f7182072eb4be62 from ghostpdl make opj_stream_set_user_data accept a NULL stream for consistency with opj_stream_set_* which does so. Update issue 225 --- src/lib/openjp2/cio.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/openjp2/cio.c b/src/lib/openjp2/cio.c index 8fce9812..062627f0 100644 --- a/src/lib/openjp2/cio.c +++ b/src/lib/openjp2/cio.c @@ -256,12 +256,16 @@ void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_strea void OPJ_CALLCONV opj_stream_set_user_data(opj_stream_t* p_stream, void * p_data) { opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; + if (!l_stream) + return; l_stream->m_user_data = p_data; } void OPJ_CALLCONV opj_stream_set_user_data_length(opj_stream_t* p_stream, OPJ_UINT64 data_length) { opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; + if (!l_stream) + return; l_stream->m_user_data_length = data_length; } From 901c9d8ae02a264fef45f700e11e7cda99b1d9ed Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 25 Feb 2014 13:38:32 +0000 Subject: [PATCH 090/333] [trunk] Import commit fc884aee2b69c78500e65c3d05bf216791a9ea4a from ghostpdl prevent heap overflow in opj_t2_read_packet_header Also prevent a double-free of segment data under OOM conditions. Problem found in a test file, 1802.pdf.SIGSEGV.36e.894 supplied by Mateusz "j00ru" Jurczyk and Gynvael Coldwind of the Google Security Team using Address Sanitizer. Many thanks! Update issue 225 --- src/lib/openjp2/t2.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c index a3cf75d9..7c1eb704 100644 --- a/src/lib/openjp2/t2.c +++ b/src/lib/openjp2/t2.c @@ -981,6 +981,11 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, do { l_cblk->segs[l_segno].numnewpasses = opj_int_min(l_cblk->segs[l_segno].maxpasses - l_cblk->segs[l_segno].numpasses, n); l_cblk->segs[l_segno].newlen = opj_bio_read(l_bio, l_cblk->numlenbits + opj_uint_floorlog2(l_cblk->segs[l_segno].numnewpasses)); + /* testcase 1802.pdf.SIGSEGV.36e.894 */ + if (l_cblk->segs[l_segno].newlen > *l_modified_length_ptr) { + opj_bio_destroy(l_bio); + return OPJ_FALSE; + } n -= l_cblk->segs[l_segno].numnewpasses; if (n > 0) { @@ -1116,6 +1121,7 @@ OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2, OPJ_BYTE* new_cblk_data = (OPJ_BYTE*) opj_realloc(l_cblk->data, l_cblk->data_current_size + l_seg->newlen); if(! new_cblk_data) { opj_free(l_cblk->data); + l_cblk->data = NULL; l_cblk->data_max_size = 0; /* opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to realloc code block cata!\n"); */ return OPJ_FALSE; From a466755bbb02b6e02f4d1e34f5c2f32df7b71d75 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 25 Feb 2014 13:39:50 +0000 Subject: [PATCH 091/333] [trunk] import commit 83dad6a76536222a3a51146f942e733a2e90ec52 from ghostpdl fix potential NULL-pointer dereference caused by testing the wrong variable after opj_realloc (happens only in OOM situations) Update issue 225 --- src/lib/openjp2/jp2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c index af25f328..d3f7515b 100644 --- a/src/lib/openjp2/jp2.c +++ b/src/lib/openjp2/jp2.c @@ -1719,7 +1719,7 @@ OPJ_BOOL opj_jp2_read_header_procedure( opj_jp2_t *jp2, if (l_current_handler != 00) { if (l_current_data_size > l_last_data_size) { OPJ_BYTE* new_current_data = (OPJ_BYTE*)opj_realloc(l_current_data,l_current_data_size); - if (!l_current_data){ + if (!new_current_data) { opj_free(l_current_data); opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to handle jpeg2000 box\n"); return OPJ_FALSE; From 7ce3f3c1a636439a6f0dc5fffc58f7f69f9febd4 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 25 Feb 2014 13:50:29 +0000 Subject: [PATCH 092/333] [trunk] Import commit 4cee6ceab21025079f439bb152fb9d8ae8c5c832 from ghostpdl Bug 694906: fix potential heap overflow in opj_t2_read_packet_header Update issue 225 --- src/lib/openjp2/t2.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c index 7c1eb704..17d5b22c 100644 --- a/src/lib/openjp2/t2.c +++ b/src/lib/openjp2/t2.c @@ -885,7 +885,9 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, /* EPH markers */ if (p_tcp->csty & J2K_CP_CSTY_EPH) { - if ((*l_header_data) != 0xff || (*(l_header_data + 1) != 0x92)) { + if (p_max_length < 2) { + fprintf(stderr, "Not enough space for expected EPH marker\n"); + } else if ((*l_header_data) != 0xff || (*(l_header_data + 1) != 0x92)) { printf("Error : expected EPH marker\n"); } else { l_header_data += 2; @@ -1014,7 +1016,9 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, /* EPH markers */ if (p_tcp->csty & J2K_CP_CSTY_EPH) { - if ((*l_header_data) != 0xff || (*(l_header_data + 1) != 0x92)) { + if (p_max_length < 2) { + fprintf(stderr, "Not enough space for expected EPH marker\n"); + } else if ((*l_header_data) != 0xff || (*(l_header_data + 1) != 0x92)) { /* TODO opj_event_msg(t2->cinfo->event_mgr, EVT_ERROR, "Expected EPH marker\n"); */ } else { l_header_data += 2; From e260ec6e9d85a81d950956227c343a1c38815b42 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 25 Feb 2014 14:03:30 +0000 Subject: [PATCH 093/333] [trunk] Import commit 87b08a096bb8ad61f9dbe4811e208d9c9d7fe63b from ghostpdl don't define lrintf for MSVC 2013 (fix compilation breakage) Update issue 225 --- src/lib/openjp2/opj_includes.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/openjp2/opj_includes.h b/src/lib/openjp2/opj_includes.h index 9d74e470..bdbb7c6c 100644 --- a/src/lib/openjp2/opj_includes.h +++ b/src/lib/openjp2/opj_includes.h @@ -129,8 +129,8 @@ Most compilers implement their own version of this keyword ... #endif #endif -/* MSVC and Borland C do not have lrintf */ -#if defined(_MSC_VER) || defined(__BORLANDC__) +/* MSVC before 2013 and Borland C do not have lrintf */ +#if defined(_MSC_VER) && (_MSC_VER < 1800) || defined(__BORLANDC__) static INLINE long lrintf(float f){ #ifdef _M_X64 return (long)((f>0.0f) ? (f + 0.5f):(f -0.5f)); From 7dd65e84e61db4e5c4d36fa16a5da49e176acf64 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 25 Feb 2014 14:14:56 +0000 Subject: [PATCH 094/333] [trunk] Revert r2415 for now since it introduce large regression --- src/lib/openjp2/t2.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c index 17d5b22c..0982d6b5 100644 --- a/src/lib/openjp2/t2.c +++ b/src/lib/openjp2/t2.c @@ -983,11 +983,6 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, do { l_cblk->segs[l_segno].numnewpasses = opj_int_min(l_cblk->segs[l_segno].maxpasses - l_cblk->segs[l_segno].numpasses, n); l_cblk->segs[l_segno].newlen = opj_bio_read(l_bio, l_cblk->numlenbits + opj_uint_floorlog2(l_cblk->segs[l_segno].numnewpasses)); - /* testcase 1802.pdf.SIGSEGV.36e.894 */ - if (l_cblk->segs[l_segno].newlen > *l_modified_length_ptr) { - opj_bio_destroy(l_bio); - return OPJ_FALSE; - } n -= l_cblk->segs[l_segno].numnewpasses; if (n > 0) { @@ -1125,7 +1120,6 @@ OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2, OPJ_BYTE* new_cblk_data = (OPJ_BYTE*) opj_realloc(l_cblk->data, l_cblk->data_current_size + l_seg->newlen); if(! new_cblk_data) { opj_free(l_cblk->data); - l_cblk->data = NULL; l_cblk->data_max_size = 0; /* opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to realloc code block cata!\n"); */ return OPJ_FALSE; From ed2af11102ec261c49740598c97baa0a2993f95f Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 25 Feb 2014 15:36:09 +0000 Subject: [PATCH 095/333] [trunk] Run decoder on issue 229 test cases Update issue 229 --- tests/nonregression/test_suite.ctest.in | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index b4a66629..17a95c53 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -116,6 +116,11 @@ opj_decompress -i @INPUT_NR_PATH@/451.pdf.SIGSEGV.f4c.3723.jp2 -o @TEMP_PATH@/4 opj_decompress -i @INPUT_NR_PATH@/2.pdf.SIGFPE.706.1112.jp2 -o @TEMP_PATH@/2.pdf.SIGFPE.706.1112.jp2.pgx # issue 228 (16bits/lossy) opj_decompress -i @INPUT_NR_PATH@/issue228.j2k -o @TEMP_PATH@/issue228.j2k.pgx +# issue 229 +opj_decompress -i @INPUT_NR_PATH@/27ac957758a35d00d6765a0c86350d9c.SIGFPE.d25.537.jpc -o @TEMP_PATH@27ac957758a35d00d6765a0c86350d9c.SIGFPE.d25.537.jpc.pgx +opj_decompress -i @INPUT_NR_PATH@/26ccf3651020967f7778238ef5af08af.SIGFPE.d25.527.jp2 -o @TEMP_PATH@26ccf3651020967f7778238ef5af08af.SIGFPE.d25.527.jp2.pgx +opj_decompress -i @INPUT_NR_PATH@/0290cb77c5df21828fa74cf2ab2c84d8.SIGFPE.d25.31.jp2 -o @TEMP_PATH@0290cb77c5df21828fa74cf2ab2c84d8.SIGFPE.d25.31.jp2.pgx +opj_decompress -i @INPUT_NR_PATH@/3672da2f1f67bbecad27d7181b4e9d7c.SIGFPE.d25.805.jpc -o @TEMP_PATH@3672da2f1f67bbecad27d7181b4e9d7c.SIGFPE.d25.805.jpc.pgx # decode with specific area # prec=12; nb_c=1 From 18771f1b6aec5109407a919db7f238cc7ce49df3 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 25 Feb 2014 16:16:34 +0000 Subject: [PATCH 096/333] [trunk] For now assume any provided stream should not get decompressed. Update issue 225 --- tests/nonregression/test_suite.ctest.in | 36 ++++++++++++------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 17a95c53..0056a45d 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -100,27 +100,27 @@ opj_decompress -i @INPUT_NR_PATH@/issue206_image-000.jp2 -o @TEMP_PATH@/issue20 # issue 205 opj_decompress -i @INPUT_NR_PATH@/issue205.jp2 -o @TEMP_PATH@/issue205.jp2.pgx # issue 225 (sumatrapdf) -opj_decompress -i @INPUT_NR_PATH@/451.pdf.SIGSEGV.5b5.3723.jp2 -o @TEMP_PATH@/451.pdf.SIGSEGV.5b5.3723.jp2.pgx -opj_decompress -i @INPUT_NR_PATH@/1888.pdf.asan.35.988.jp2 -o @TEMP_PATH@/1888.pdf.asan.35.988.jp2.pgx -opj_decompress -i @INPUT_NR_PATH@/2539.pdf.SIGFPE.706.1712.jp2 -o @TEMP_PATH@/2539.pdf.SIGFPE.706.1712.jp2.pgx -opj_decompress -i @INPUT_NR_PATH@/2236.pdf.SIGSEGV.398.1376.jp2 -o @TEMP_PATH@/2236.pdf.SIGSEGV.398.1376.jp.pgx2 -opj_decompress -i @INPUT_NR_PATH@/1336.pdf.asan.47.376.jp2 -o @TEMP_PATH@/1336.pdf.asan.47.376.jp2.pgx -opj_decompress -i @INPUT_NR_PATH@/1851.pdf.SIGSEGV.ce9.948.jp2 -o @TEMP_PATH@/1851.pdf.SIGSEGV.ce9.948.jp2.pgx -opj_decompress -i @INPUT_NR_PATH@/4149.pdf.SIGSEGV.cf7.3501.jp2 -o @TEMP_PATH@/4149.pdf.SIGSEGV.cf7.3501.jp.pgx2 -opj_decompress -i @INPUT_NR_PATH@/4035.pdf.SIGSEGV.d8b.3375.jp2 -o @TEMP_PATH@/4035.pdf.SIGSEGV.d8b.3375.jp.pgx2 -opj_decompress -i @INPUT_NR_PATH@/2977.pdf.asan.67.2198.jp2 -o @TEMP_PATH@/2977.pdf.asan.67.2198.jp2.pgx -opj_decompress -i @INPUT_NR_PATH@/451.pdf.SIGSEGV.ce9.3723.jp2 -o @TEMP_PATH@/451.pdf.SIGSEGV.ce9.3723.jp2.pgx -opj_decompress -i @INPUT_NR_PATH@/3635.pdf.asan.77.2930.jp2 -o @TEMP_PATH@/3635.pdf.asan.77.2930.jp2.pgx -opj_decompress -i @INPUT_NR_PATH@/1802.pdf.SIGSEGV.36e.894.jp2 -o @TEMP_PATH@/1802.pdf.SIGSEGV.36e.894.jp2.pgx -opj_decompress -i @INPUT_NR_PATH@/451.pdf.SIGSEGV.f4c.3723.jp2 -o @TEMP_PATH@/451.pdf.SIGSEGV.f4c.3723.jp2.pgx -opj_decompress -i @INPUT_NR_PATH@/2.pdf.SIGFPE.706.1112.jp2 -o @TEMP_PATH@/2.pdf.SIGFPE.706.1112.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/451.pdf.SIGSEGV.5b5.3723.jp2 -o @TEMP_PATH@/451.pdf.SIGSEGV.5b5.3723.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/1888.pdf.asan.35.988.jp2 -o @TEMP_PATH@/1888.pdf.asan.35.988.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/2539.pdf.SIGFPE.706.1712.jp2 -o @TEMP_PATH@/2539.pdf.SIGFPE.706.1712.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/2236.pdf.SIGSEGV.398.1376.jp2 -o @TEMP_PATH@/2236.pdf.SIGSEGV.398.1376.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/1336.pdf.asan.47.376.jp2 -o @TEMP_PATH@/1336.pdf.asan.47.376.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/1851.pdf.SIGSEGV.ce9.948.jp2 -o @TEMP_PATH@/1851.pdf.SIGSEGV.ce9.948.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/4149.pdf.SIGSEGV.cf7.3501.jp2 -o @TEMP_PATH@/4149.pdf.SIGSEGV.cf7.3501.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/4035.pdf.SIGSEGV.d8b.3375.jp2 -o @TEMP_PATH@/4035.pdf.SIGSEGV.d8b.3375.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/2977.pdf.asan.67.2198.jp2 -o @TEMP_PATH@/2977.pdf.asan.67.2198.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/451.pdf.SIGSEGV.ce9.3723.jp2 -o @TEMP_PATH@/451.pdf.SIGSEGV.ce9.3723.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/3635.pdf.asan.77.2930.jp2 -o @TEMP_PATH@/3635.pdf.asan.77.2930.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/1802.pdf.SIGSEGV.36e.894.jp2 -o @TEMP_PATH@/1802.pdf.SIGSEGV.36e.894.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/451.pdf.SIGSEGV.f4c.3723.jp2 -o @TEMP_PATH@/451.pdf.SIGSEGV.f4c.3723.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/2.pdf.SIGFPE.706.1112.jp2 -o @TEMP_PATH@/2.pdf.SIGFPE.706.1112.jp2.pgx # issue 228 (16bits/lossy) opj_decompress -i @INPUT_NR_PATH@/issue228.j2k -o @TEMP_PATH@/issue228.j2k.pgx # issue 229 -opj_decompress -i @INPUT_NR_PATH@/27ac957758a35d00d6765a0c86350d9c.SIGFPE.d25.537.jpc -o @TEMP_PATH@27ac957758a35d00d6765a0c86350d9c.SIGFPE.d25.537.jpc.pgx -opj_decompress -i @INPUT_NR_PATH@/26ccf3651020967f7778238ef5af08af.SIGFPE.d25.527.jp2 -o @TEMP_PATH@26ccf3651020967f7778238ef5af08af.SIGFPE.d25.527.jp2.pgx -opj_decompress -i @INPUT_NR_PATH@/0290cb77c5df21828fa74cf2ab2c84d8.SIGFPE.d25.31.jp2 -o @TEMP_PATH@0290cb77c5df21828fa74cf2ab2c84d8.SIGFPE.d25.31.jp2.pgx -opj_decompress -i @INPUT_NR_PATH@/3672da2f1f67bbecad27d7181b4e9d7c.SIGFPE.d25.805.jpc -o @TEMP_PATH@3672da2f1f67bbecad27d7181b4e9d7c.SIGFPE.d25.805.jpc.pgx +!opj_decompress -i @INPUT_NR_PATH@/27ac957758a35d00d6765a0c86350d9c.SIGFPE.d25.537.jpc -o @TEMP_PATH@27ac957758a35d00d6765a0c86350d9c.SIGFPE.d25.537.jpc.pgx +!opj_decompress -i @INPUT_NR_PATH@/26ccf3651020967f7778238ef5af08af.SIGFPE.d25.527.jp2 -o @TEMP_PATH@26ccf3651020967f7778238ef5af08af.SIGFPE.d25.527.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/0290cb77c5df21828fa74cf2ab2c84d8.SIGFPE.d25.31.jp2 -o @TEMP_PATH@0290cb77c5df21828fa74cf2ab2c84d8.SIGFPE.d25.31.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/3672da2f1f67bbecad27d7181b4e9d7c.SIGFPE.d25.805.jpc -o @TEMP_PATH@3672da2f1f67bbecad27d7181b4e9d7c.SIGFPE.d25.805.jpc.pgx # decode with specific area # prec=12; nb_c=1 From 902177696320f2ee61c4f27f274c31cb46586fc1 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 25 Feb 2014 16:36:26 +0000 Subject: [PATCH 097/333] [trunk] New decoded files are passing. Adding reference files. Update issue 225 --- tests/nonregression/md5refs.txt | 4 ++++ tests/nonregression/test_suite.ctest.in | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/tests/nonregression/md5refs.txt b/tests/nonregression/md5refs.txt index 8d98c567..5932ea47 100644 --- a/tests/nonregression/md5refs.txt +++ b/tests/nonregression/md5refs.txt @@ -2,6 +2,10 @@ a3a0606dfa0779d657c6a923b90e4678 _00042.j2k_1.pgx 106954dc468dfe0884d02268e91f9f5b _00042.j2k_2.pgx 8889def55f1e18dae6002b9b3a6dd152 123.j2c_0.pgx +ee6881e50c9cf17994ac74c2bee956a8 1888.pdf.asan.35.988.jp2_0.pgx +1514d460fa6da37aece72c3a786ad40a 451.pdf.SIGSEGV.ce9.3723.jp2_0.pgx +398b39afd263f967045928ba38a7ea51 451.pdf.SIGSEGV.ce9.3723.jp2_1.pgx +64beae9da75e1c3716af24ea231285d7 451.pdf.SIGSEGV.ce9.3723.jp2_2.pgx 4a0daf7a9065101379eaebc28e436b1e Bretagne2.j2k_0.pgx 07578fc7bf81d3da694de8ae27308b82 Bretagne2.j2k_1.pgx 3690c42f83bad42f4abea48525d45e0e Bretagne2.j2k_2.pgx diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 0056a45d..bbfea36d 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -101,7 +101,7 @@ opj_decompress -i @INPUT_NR_PATH@/issue206_image-000.jp2 -o @TEMP_PATH@/issue20 opj_decompress -i @INPUT_NR_PATH@/issue205.jp2 -o @TEMP_PATH@/issue205.jp2.pgx # issue 225 (sumatrapdf) !opj_decompress -i @INPUT_NR_PATH@/451.pdf.SIGSEGV.5b5.3723.jp2 -o @TEMP_PATH@/451.pdf.SIGSEGV.5b5.3723.jp2.pgx -!opj_decompress -i @INPUT_NR_PATH@/1888.pdf.asan.35.988.jp2 -o @TEMP_PATH@/1888.pdf.asan.35.988.jp2.pgx +opj_decompress -i @INPUT_NR_PATH@/1888.pdf.asan.35.988.jp2 -o @TEMP_PATH@/1888.pdf.asan.35.988.jp2.pgx !opj_decompress -i @INPUT_NR_PATH@/2539.pdf.SIGFPE.706.1712.jp2 -o @TEMP_PATH@/2539.pdf.SIGFPE.706.1712.jp2.pgx !opj_decompress -i @INPUT_NR_PATH@/2236.pdf.SIGSEGV.398.1376.jp2 -o @TEMP_PATH@/2236.pdf.SIGSEGV.398.1376.jp2.pgx !opj_decompress -i @INPUT_NR_PATH@/1336.pdf.asan.47.376.jp2 -o @TEMP_PATH@/1336.pdf.asan.47.376.jp2.pgx @@ -109,7 +109,7 @@ opj_decompress -i @INPUT_NR_PATH@/issue205.jp2 -o @TEMP_PATH@/issue205.jp2.pgx !opj_decompress -i @INPUT_NR_PATH@/4149.pdf.SIGSEGV.cf7.3501.jp2 -o @TEMP_PATH@/4149.pdf.SIGSEGV.cf7.3501.jp2.pgx !opj_decompress -i @INPUT_NR_PATH@/4035.pdf.SIGSEGV.d8b.3375.jp2 -o @TEMP_PATH@/4035.pdf.SIGSEGV.d8b.3375.jp2.pgx !opj_decompress -i @INPUT_NR_PATH@/2977.pdf.asan.67.2198.jp2 -o @TEMP_PATH@/2977.pdf.asan.67.2198.jp2.pgx -!opj_decompress -i @INPUT_NR_PATH@/451.pdf.SIGSEGV.ce9.3723.jp2 -o @TEMP_PATH@/451.pdf.SIGSEGV.ce9.3723.jp2.pgx +opj_decompress -i @INPUT_NR_PATH@/451.pdf.SIGSEGV.ce9.3723.jp2 -o @TEMP_PATH@/451.pdf.SIGSEGV.ce9.3723.jp2.pgx !opj_decompress -i @INPUT_NR_PATH@/3635.pdf.asan.77.2930.jp2 -o @TEMP_PATH@/3635.pdf.asan.77.2930.jp2.pgx !opj_decompress -i @INPUT_NR_PATH@/1802.pdf.SIGSEGV.36e.894.jp2 -o @TEMP_PATH@/1802.pdf.SIGSEGV.36e.894.jp2.pgx !opj_decompress -i @INPUT_NR_PATH@/451.pdf.SIGSEGV.f4c.3723.jp2 -o @TEMP_PATH@/451.pdf.SIGSEGV.f4c.3723.jp2.pgx From 563d238fa0f22c62c675a78f52429aad7ac4bbe3 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 25 Feb 2014 16:49:26 +0000 Subject: [PATCH 098/333] [trunk] Create a new static *_impl function to avoid a warning triggered by the deprecation mecanism Fixes issue 257 --- src/lib/openjp2/openjpeg.c | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/src/lib/openjp2/openjpeg.c b/src/lib/openjp2/openjpeg.c index 78b5a564..31199b24 100644 --- a/src/lib/openjp2/openjpeg.c +++ b/src/lib/openjp2/openjpeg.c @@ -1030,17 +1030,7 @@ void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t **p_cstr_index) } /* ---------------------------------------------------------------------- */ -opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file, OPJ_BOOL p_is_read_stream) -{ - return opj_stream_create_file_stream(p_file,OPJ_J2K_STREAM_CHUNK_SIZE,p_is_read_stream); -} - -opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream_v3 (const char *fname, OPJ_BOOL p_is_read_stream) -{ - return opj_stream_create_file_stream_v3(fname, OPJ_J2K_STREAM_CHUNK_SIZE, p_is_read_stream); -} - -opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream ( FILE * p_file, +static opj_stream_t* opj_stream_create_file_stream_impl ( FILE * p_file, OPJ_SIZE_T p_size, OPJ_BOOL p_is_read_stream) { @@ -1065,6 +1055,23 @@ opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream ( FILE * p_file, return l_stream; } +opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file, OPJ_BOOL p_is_read_stream) +{ + return opj_stream_create_file_stream_impl(p_file,OPJ_J2K_STREAM_CHUNK_SIZE,p_is_read_stream); +} + +opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream_v3 (const char *fname, OPJ_BOOL p_is_read_stream) +{ + return opj_stream_create_file_stream_v3(fname, OPJ_J2K_STREAM_CHUNK_SIZE, p_is_read_stream); +} + +opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream ( FILE * p_file, + OPJ_SIZE_T p_size, + OPJ_BOOL p_is_read_stream) +{ + return opj_stream_create_file_stream_impl(p_file,p_size,p_is_read_stream); +} + opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream_v3 ( const char *fname, OPJ_SIZE_T p_size, From 4c1023dac6125805e5ce092aefbc92fa6668dd99 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 25 Feb 2014 16:53:42 +0000 Subject: [PATCH 099/333] [trunk] deprecationg warning issued by java compiler should be ignored --- cmake/CTestCustom.cmake.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cmake/CTestCustom.cmake.in b/cmake/CTestCustom.cmake.in index cdde4a7e..e04ba593 100644 --- a/cmake/CTestCustom.cmake.in +++ b/cmake/CTestCustom.cmake.in @@ -27,6 +27,8 @@ set(CTEST_CUSTOM_WARNING_EXCEPTION # Suppress warning caused by intentional messages about deprecation ".*warning,.* is deprecated" + # java also warns about deprecated API + "java.*deprecation" # supress warnings caused by 3rd party libs: ".*thirdparty.*" "libtiff.*has no symbols" From 163c7e34605a8b5e1ea69f81a8c9ea068d42fd53 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 25 Feb 2014 17:15:22 +0000 Subject: [PATCH 100/333] [trunk] Run decoder on input dataset from issue 254. Add fake md5sum to make sure the test is failing. Update issue 254 --- tests/nonregression/md5refs.txt | 3 +++ tests/nonregression/test_suite.ctest.in | 2 ++ 2 files changed, 5 insertions(+) diff --git a/tests/nonregression/md5refs.txt b/tests/nonregression/md5refs.txt index 5932ea47..e86b39f7 100644 --- a/tests/nonregression/md5refs.txt +++ b/tests/nonregression/md5refs.txt @@ -33,6 +33,9 @@ de992d54d59032eb07d21983dbe8155b issue205.jp2_3.pgx 555a504a93c9a14f61c894da3b393e87 issue206_image-000.jp2_1.pgx 5f06b7c45446ae20c22cada46478a9dc issue206_image-000.jp2_2.pgx e1807db57b5f5192c4b77b83e8b5c477 issue228.j2k_0.pgx +611948e70370bf132839fc37109859c7 issue254.jp2_0.pgx +611948e70370bf132839fc37109859c7 issue254.jp2_1.pgx +611948e70370bf132839fc37109859c7 issue254.jp2_2.pgx 4093cc34d838780b35a8be410247fa7f j2k32.j2k_0.pgx ce4e556aaa0844b92a92c35c200fc43e j2k32.j2k_1.pgx ea926520f990640862f3fe6616097613 j2k32.j2k_2.pgx diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index bbfea36d..1671971a 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -121,6 +121,8 @@ opj_decompress -i @INPUT_NR_PATH@/issue228.j2k -o @TEMP_PATH@/i !opj_decompress -i @INPUT_NR_PATH@/26ccf3651020967f7778238ef5af08af.SIGFPE.d25.527.jp2 -o @TEMP_PATH@26ccf3651020967f7778238ef5af08af.SIGFPE.d25.527.jp2.pgx !opj_decompress -i @INPUT_NR_PATH@/0290cb77c5df21828fa74cf2ab2c84d8.SIGFPE.d25.31.jp2 -o @TEMP_PATH@0290cb77c5df21828fa74cf2ab2c84d8.SIGFPE.d25.31.jp2.pgx !opj_decompress -i @INPUT_NR_PATH@/3672da2f1f67bbecad27d7181b4e9d7c.SIGFPE.d25.805.jpc -o @TEMP_PATH@3672da2f1f67bbecad27d7181b4e9d7c.SIGFPE.d25.805.jpc.pgx +# issue 254 (loss in quality) +opj_decompress -i @INPUT_NR_PATH@/issue254.jp2 -o @TEMP_PATH@/issue254.jp2.pgx # decode with specific area # prec=12; nb_c=1 From b56fb96b1b0feaa80890ed0a77b1d7d43ca2212f Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 09:35:11 +0000 Subject: [PATCH 101/333] [trunk] Fix invalid write access in JPIP code. Fixes issue 261 --- src/lib/openjpip/msgqueue_manager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/openjpip/msgqueue_manager.c b/src/lib/openjpip/msgqueue_manager.c index 6cb19544..fab9a59c 100644 --- a/src/lib/openjpip/msgqueue_manager.c +++ b/src/lib/openjpip/msgqueue_manager.c @@ -692,7 +692,7 @@ placeholder_param_t * parse_phld( Byte_t *datastream, Byte8_t metalength) phld = (placeholder_param_t *)opj_malloc( sizeof(placeholder_param_t)); phld->LBox = big4( datastream); - strcpy( phld->TBox, "phld"); + strncpy( phld->TBox, "phld", 4); phld->Flags = big4( datastream+8); phld->OrigID = big8( datastream+12); phld->OrigBHlen = (Byte_t)(metalength - 20); From e231a84b2fdabc626458065842a293238653d0c0 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 09:40:19 +0000 Subject: [PATCH 102/333] [trunk] Properly store and use value returned by fread. Also invert nmemb and size in fread call. Fixes issue 262 --- src/bin/jp2/opj_compress.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index 7b1c9471..da89e512 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -930,7 +930,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param float *lCurrentDoublePtr; float *lSpace; int *l_int_ptr; - int lNbComp = 0, lTotalComp, lMctComp, i, lStrLen; + int lNbComp = 0, lTotalComp, lMctComp, i, lStrLen, lStrFread; /* Open file */ FILE * lFile = fopen(lFilename,"r"); @@ -943,8 +943,9 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param lStrLen = ftell(lFile); fseek(lFile,0,SEEK_SET); lMatrix = (char *) malloc(lStrLen + 1); - fread(lMatrix, lStrLen, 1, lFile); + lStrFread = fread(lMatrix, 1, lStrLen, lFile); fclose(lFile); + if( lStrLen != lStrFread ) return 1; lMatrix[lStrLen] = 0; lCurrentPtr = lMatrix; From c4317177f3196a16563b3af22085ccea4ad2a79c Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 09:46:01 +0000 Subject: [PATCH 103/333] [trunk] Remove simple warnings about unused functions --- src/bin/jp2/opj_compress.c | 22 ---------------------- tests/test_tile_encoder.c | 14 -------------- 2 files changed, 36 deletions(-) diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index da89e512..33efe757 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -1392,28 +1392,6 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param /* -------------------------------------------------------------------------- */ -/** -sample error callback expecting a FILE* client object -*/ -static void error_file_callback(const char *msg, void *client_data) { - FILE *stream = (FILE*)client_data; - fprintf(stream, "[ERROR] %s", msg); -} -/** -sample warning callback expecting a FILE* client object -*/ -static void warning_file_callback(const char *msg, void *client_data) { - FILE *stream = (FILE*)client_data; - fprintf(stream, "[WARNING] %s", msg); -} -/** -sample debug callback expecting a FILE* client object -*/ -static void info_file_callback(const char *msg, void *client_data) { - FILE *stream = (FILE*)client_data; - fprintf(stream, "[INFO] %s", msg); -} - /** sample error debug callback expecting no client object */ diff --git a/tests/test_tile_encoder.c b/tests/test_tile_encoder.c index dbc3f037..62becce7 100644 --- a/tests/test_tile_encoder.c +++ b/tests/test_tile_encoder.c @@ -35,20 +35,6 @@ /* -------------------------------------------------------------------------- */ -/** -sample error callback expecting a FILE* client object -*/ -static void error_callback_file(const char *msg, void *client_data) { - FILE *stream = (FILE*)client_data; - fprintf(stream, "[ERROR] %s", msg); -} -/** -sample warning callback expecting a FILE* client object -*/ -static void warning_callback_file(const char *msg, void *client_data) { - FILE *stream = (FILE*)client_data; - fprintf(stream, "[WARNING] %s", msg); -} /** sample error debug callback expecting no client object */ From 36a7d23273df027c879d882011450a503c9fd415 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 09:47:53 +0000 Subject: [PATCH 104/333] [trunk] regex would not be used to remove java deprecation warning from dashboard --- cmake/CTestCustom.cmake.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmake/CTestCustom.cmake.in b/cmake/CTestCustom.cmake.in index e04ba593..a19c2913 100644 --- a/cmake/CTestCustom.cmake.in +++ b/cmake/CTestCustom.cmake.in @@ -28,7 +28,7 @@ set(CTEST_CUSTOM_WARNING_EXCEPTION # Suppress warning caused by intentional messages about deprecation ".*warning,.* is deprecated" # java also warns about deprecated API - "java.*deprecation" + ".*java.*deprecation" # supress warnings caused by 3rd party libs: ".*thirdparty.*" "libtiff.*has no symbols" From d5f71c2e1dfbe88d7c63220261f4848ddefa9911 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 09:51:37 +0000 Subject: [PATCH 105/333] [trunk] Fix TestJPIP1 on case sensitive system --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 77c4dd61..04cd62dc 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -95,6 +95,6 @@ if(BUILD_JPIP) set(p "${CMAKE_CURRENT_BINARY_DIR}/jpip.dat") set(md5 "62b00c620fb0a600c5ffd413cada4674") add_test(NAME TestJPIP1 COMMAND ${CMAKE_COMMAND} -DD_URL:STRING=${s} -DD_FILE:PATH=${p} - -DEXPECTED_MD5=${md5} -P ${PROJECT_SOURCE_DIR}/CMake/JPIPTestDriver.cmake) + -DEXPECTED_MD5=${md5} -P ${PROJECT_SOURCE_DIR}/cmake/JPIPTestDriver.cmake) endif() endif() From 9d848e3f5e34c93d206ab7a2961f1f31ec56f820 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 09:57:38 +0000 Subject: [PATCH 106/333] [trunk] Clearly indicate that mem-b2ace68c-1381.jp2 should not be decompressed. Update issue 250 --- tests/nonregression/CMakeLists.txt | 1 + tests/nonregression/test_suite.ctest.in | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/nonregression/CMakeLists.txt b/tests/nonregression/CMakeLists.txt index 95fd08af..6116bf8c 100644 --- a/tests/nonregression/CMakeLists.txt +++ b/tests/nonregression/CMakeLists.txt @@ -28,6 +28,7 @@ set(BLACKLIST_JPEG2000 gdal_fuzzer_check_comp_dx_dy.jp2 gdal_fuzzer_check_number_of_tiles.jp2 gdal_fuzzer_unchecked_numresolutions.jp2 + mem-b2ace68c-1381.jp2 ) file(GLOB_RECURSE OPJ_DATA_NR_LIST diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 1671971a..0237b95f 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -80,7 +80,7 @@ opj_decompress -i @INPUT_NR_PATH@/kodak_2layers_lrcp.j2c -o @TEMP_PATH@/kodak_2 # related to issue 104 which is closed opj_decompress -i @INPUT_NR_PATH@/issue104_jpxstream.jp2 -o @TEMP_PATH@/issue104_jpxstream.jp2.pgx # File not supported by kakadu (Malformed PCLR box) and not supoprter by openjpeg (problem with value of TPSot) -opj_decompress -i @INPUT_NR_PATH@/mem-b2ace68c-1381.jp2 -o @TEMP_PATH@/mem-b2ace68c-1381.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/mem-b2ace68c-1381.jp2 -o @TEMP_PATH@/mem-b2ace68c-1381.jp2.pgx # File which produced weird output with kakadu and not supoprter by openjpeg (problem with value of TPSot, issue 202, 206, 208) opj_decompress -i @INPUT_NR_PATH@/mem-b2b86b74-2753.jp2 -o @TEMP_PATH@/mem-b2b86b74-2753.jp2.pgx # issue 191 raised by the gdal fuzzer test (should properly failed) From 820c04c6799ea38aacd4e5d637073e6ab1ec643c Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 10:48:06 +0000 Subject: [PATCH 107/333] [trunk] Update file extension function to handle cases where filename containes multiples dots. Update issue 250 --- tests/nonregression/CMakeLists.txt | 15 ++++++++++++++- tests/nonregression/test_suite.ctest.in | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/tests/nonregression/CMakeLists.txt b/tests/nonregression/CMakeLists.txt index 6116bf8c..f756fe81 100644 --- a/tests/nonregression/CMakeLists.txt +++ b/tests/nonregression/CMakeLists.txt @@ -18,8 +18,16 @@ find_package(KAKADU) # GENERATION OF THE TEST SUITE (DUMP) # Dump all files with the selected extension inside the input directory +# technically opj_dump should simply parse these one, since syntax is ok. +set(BLACKLIST_JPEG2000_TMP + 2539.pdf.SIGFPE.706.1712.jp2 + 0290cb77c5df21828fa74cf2ab2c84d8.SIGFPE.d25.31.jp2 + 26ccf3651020967f7778238ef5af08af.SIGFPE.d25.527.jp2 + ) + # Define a list of file which should be gracefully rejected: set(BLACKLIST_JPEG2000 + ${BLACKLIST_JPEG2000_TMP} broken.jp2 broken2.jp2 broken3.jp2 @@ -29,6 +37,7 @@ set(BLACKLIST_JPEG2000 gdal_fuzzer_check_number_of_tiles.jp2 gdal_fuzzer_unchecked_numresolutions.jp2 mem-b2ace68c-1381.jp2 + 1851.pdf.SIGSEGV.ce9.948.jp2 ) file(GLOB_RECURSE OPJ_DATA_NR_LIST @@ -40,7 +49,11 @@ file(GLOB_RECURSE OPJ_DATA_NR_LIST foreach(INPUT_FILENAME ${OPJ_DATA_NR_LIST}) get_filename_component(INPUT_FILENAME_NAME ${INPUT_FILENAME} NAME) - get_filename_component(INPUT_FILENAME_NAME_WE ${INPUT_FILENAME_NAME} NAME_WE) + #get_filename_component(INPUT_FILENAME_NAME_WE ${INPUT_FILENAME_NAME} NAME_WE) + # cannot use longest extension function, since some name contains multiples + # dots. Instead write out own shortest extension function: + string(FIND ${INPUT_FILENAME_NAME} "." SHORTEST_EXT_POS REVERSE) + string(SUBSTRING ${INPUT_FILENAME_NAME} 0 ${SHORTEST_EXT_POS} INPUT_FILENAME_NAME_WE) string(REGEX MATCH ${INPUT_FILENAME_NAME} bad_jpeg2000 ${BLACKLIST_JPEG2000}) # Dump the input image diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 0237b95f..6348ff59 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -101,7 +101,7 @@ opj_decompress -i @INPUT_NR_PATH@/issue206_image-000.jp2 -o @TEMP_PATH@/issue20 opj_decompress -i @INPUT_NR_PATH@/issue205.jp2 -o @TEMP_PATH@/issue205.jp2.pgx # issue 225 (sumatrapdf) !opj_decompress -i @INPUT_NR_PATH@/451.pdf.SIGSEGV.5b5.3723.jp2 -o @TEMP_PATH@/451.pdf.SIGSEGV.5b5.3723.jp2.pgx -opj_decompress -i @INPUT_NR_PATH@/1888.pdf.asan.35.988.jp2 -o @TEMP_PATH@/1888.pdf.asan.35.988.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/1888.pdf.asan.35.988.jp2 -o @TEMP_PATH@/1888.pdf.asan.35.988.jp2.pgx !opj_decompress -i @INPUT_NR_PATH@/2539.pdf.SIGFPE.706.1712.jp2 -o @TEMP_PATH@/2539.pdf.SIGFPE.706.1712.jp2.pgx !opj_decompress -i @INPUT_NR_PATH@/2236.pdf.SIGSEGV.398.1376.jp2 -o @TEMP_PATH@/2236.pdf.SIGSEGV.398.1376.jp2.pgx !opj_decompress -i @INPUT_NR_PATH@/1336.pdf.asan.47.376.jp2 -o @TEMP_PATH@/1336.pdf.asan.47.376.jp2.pgx From 3da30304fc1225ab55ab7c5e791870fec1b0b3c3 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 11:03:55 +0000 Subject: [PATCH 108/333] [trunk] Import patch from sumatrapdf team. This adds alpha handling. This patch changes ABI. Update issue 225 --- src/lib/openjp2/jp2.c | 9 ++++++++- src/lib/openjp2/openjpeg.h | 2 ++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c index d3f7515b..9dde2e97 100644 --- a/src/lib/openjp2/jp2.c +++ b/src/lib/openjp2/jp2.c @@ -995,7 +995,12 @@ void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color) for(i = 0; i < n; ++i) { /* WATCH: acn = asoc - 1 ! */ - if((asoc = info[i].asoc) == 0) continue; + if((asoc = info[i].asoc) == 0) + { + if (i < image->numcomps) + image->comps[i].alpha = info[i].typ; + continue; + } cn = info[i].cn; acn = asoc - 1; @@ -1011,6 +1016,8 @@ void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color) info[i].asoc = cn + 1; info[acn].asoc = info[acn].cn + 1; } + + image->comps[cn].alpha = info[i].typ; } if(color->jp2_cdef->info) opj_free(color->jp2_cdef->info); diff --git a/src/lib/openjp2/openjpeg.h b/src/lib/openjp2/openjpeg.h index bbc74577..4792433a 100644 --- a/src/lib/openjp2/openjpeg.h +++ b/src/lib/openjp2/openjpeg.h @@ -538,6 +538,8 @@ typedef struct opj_image_comp { OPJ_UINT32 factor; /** image component data */ OPJ_INT32 *data; + /** alpha channel */ + OPJ_UINT16 alpha; } opj_image_comp_t; /** From 70ede09310ac29eaf109792c61a7dc42f1b94811 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 11:04:33 +0000 Subject: [PATCH 109/333] [trunk] Import patch from sumatrapdf team. This patch adds new colorspace handling. Update issue 225 --- src/lib/openjp2/openjpeg.h | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/lib/openjp2/openjpeg.h b/src/lib/openjp2/openjpeg.h index 4792433a..338a771d 100644 --- a/src/lib/openjp2/openjpeg.h +++ b/src/lib/openjp2/openjpeg.h @@ -193,10 +193,11 @@ typedef enum PROG_ORDER { */ typedef enum COLOR_SPACE { OPJ_CLRSPC_UNKNOWN = -1, /**< not supported by the library */ - OPJ_CLRSPC_UNSPECIFIED = 0, /**< not specified in the codestream */ + OPJ_CLRSPC_UNSPECIFIED = 0, /**< not specified in the codestream */ OPJ_CLRSPC_SRGB = 1, /**< sRGB */ OPJ_CLRSPC_GRAY = 2, /**< grayscale */ - OPJ_CLRSPC_SYCC = 3 /**< YUV */ + OPJ_CLRSPC_SYCC = 3, /**< YUV */ + OPJ_CLRSPC_EYCC = 4 /**< e-YCC */ } OPJ_COLOR_SPACE; /** From 1dedf7f0cd371368f1bbbfd05c8e17efce59b94f Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 11:05:31 +0000 Subject: [PATCH 110/333] [trunk] Import patch from sumatrapdf team. Add a new function to check color box. Update issue 225 --- src/lib/openjp2/jp2.c | 78 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c index 9dde2e97..3678be67 100644 --- a/src/lib/openjp2/jp2.c +++ b/src/lib/openjp2/jp2.c @@ -752,6 +752,77 @@ void opj_jp2_free_pclr(opj_jp2_color_t *color) opj_free(color->jp2_pclr); color->jp2_pclr = NULL; } +static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color, opj_event_mgr_t *p_manager) +{ + OPJ_UINT16 i; + + /* testcase 4149.pdf.SIGSEGV.cf7.3501 */ + if (color->jp2_cdef) { + opj_jp2_cdef_info_t *info = color->jp2_cdef->info; + OPJ_UINT16 n = color->jp2_cdef->n; + + for (i = 0; i < n; i++) { + if (info[i].cn >= image->numcomps) { + opj_event_msg(p_manager, EVT_ERROR, "Invalid component index %d (>= %d).\n", info[i].cn, image->numcomps); + return OPJ_FALSE; + } + if (info[i].asoc > 0 && (OPJ_UINT32)(info[i].asoc - 1) >= image->numcomps) { + opj_event_msg(p_manager, EVT_ERROR, "Invalid component index %d (>= %d).\n", info[i].asoc - 1, image->numcomps); + return OPJ_FALSE; + } + } + } + + /* testcases 451.pdf.SIGSEGV.f4c.3723, 451.pdf.SIGSEGV.5b5.3723 and + 66ea31acbb0f23a2bbc91f64d69a03f5_signal_sigsegv_13937c0_7030_5725.pdf */ + if (color->jp2_pclr && color->jp2_pclr->cmap) { + OPJ_UINT16 nr_channels = color->jp2_pclr->nr_channels; + opj_jp2_cmap_comp_t *cmap = color->jp2_pclr->cmap; + OPJ_BOOL *pcol_usage, is_sane = OPJ_TRUE; + + /* verify that all original components match an existing one */ + for (i = 0; i < nr_channels; i++) { + if (cmap[i].cmp >= image->numcomps) { + opj_event_msg(p_manager, EVT_ERROR, "Invalid component index %d (>= %d).\n", cmap[i].cmp, image->numcomps); + is_sane = OPJ_FALSE; + } + } + + pcol_usage = opj_calloc(nr_channels, sizeof(OPJ_BOOL)); + if (!pcol_usage) { + opj_event_msg(p_manager, EVT_ERROR, "Unexpected OOM.\n"); + return OPJ_FALSE; + } + /* verify that no component is targeted more than once */ + for (i = 0; i < nr_channels; i++) { + OPJ_UINT16 pcol = cmap[i].pcol; + if (pcol >= nr_channels) { + opj_event_msg(p_manager, EVT_ERROR, "Invalid component/palette index for direct mapping %d.\n", pcol); + is_sane = OPJ_FALSE; + } + else if (pcol_usage[pcol]) { + opj_event_msg(p_manager, EVT_ERROR, "Component %d is mapped twice.\n", pcol); + is_sane = OPJ_FALSE; + } + else + pcol_usage[pcol] = OPJ_TRUE; + } + /* verify that all components are targeted at least once */ + for (i = 0; i < nr_channels; i++) { + if (!pcol_usage[i]) { + opj_event_msg(p_manager, EVT_ERROR, "Component %d doesn't have a mapping.\n", i); + is_sane = OPJ_FALSE; + } + } + opj_free(pcol_usage); + if (!is_sane) { + return OPJ_FALSE; + } + } + + return OPJ_TRUE; +} + void opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color) { opj_image_comp_t *old_comps, *new_comps; @@ -1188,6 +1259,9 @@ OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2, } if (!jp2->ignore_pclr_cmap_cdef){ + if (!opj_jp2_check_color(p_image, &(jp2->color), p_manager)) { + return OPJ_FALSE; + } /* Set Image Color Space */ if (jp2->enumcs == 16) @@ -2368,6 +2442,10 @@ OPJ_BOOL opj_jp2_get_tile( opj_jp2_t *p_jp2, return OPJ_FALSE; } + if (!opj_jp2_check_color(p_image, &(p_jp2->color), p_manager)) { + return OPJ_FALSE; + } + /* Set Image Color Space */ if (p_jp2->enumcs == 16) p_image->color_space = OPJ_CLRSPC_SRGB; From 4a39ee9bbc20411c7d5de3ee1c9844e94a42be3d Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 11:06:18 +0000 Subject: [PATCH 111/333] [trunk] Import patch from sumatrapdf team. Add detection for testcase 1802.pdf.SIGSEGV.36e.894 Update issue 225 --- src/lib/openjp2/t2.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c index 0982d6b5..2271ea6b 100644 --- a/src/lib/openjp2/t2.c +++ b/src/lib/openjp2/t2.c @@ -983,6 +983,11 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, do { l_cblk->segs[l_segno].numnewpasses = opj_int_min(l_cblk->segs[l_segno].maxpasses - l_cblk->segs[l_segno].numpasses, n); l_cblk->segs[l_segno].newlen = opj_bio_read(l_bio, l_cblk->numlenbits + opj_uint_floorlog2(l_cblk->segs[l_segno].numnewpasses)); + /* testcase 1802.pdf.SIGSEGV.36e.894 */ + if (l_cblk->segs[l_segno].newlen > *l_modified_length_ptr) { + opj_bio_destroy(l_bio); + return OPJ_FALSE; + } n -= l_cblk->segs[l_segno].numnewpasses; if (n > 0) { From 241769dc2fac48b9ba6527fe62d536998dda4fa3 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 11:08:25 +0000 Subject: [PATCH 112/333] [trunk] Import patch from sumatrapdf team. This handle testcase 4035.pdf.SIGSEGV.d8b.3375 Update issue 225 --- src/lib/openjp2/j2k.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index d6b7d6a6..52cf06c5 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -1954,6 +1954,12 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, return OPJ_FALSE; } + /* testcase 4035.pdf.SIGSEGV.d8b.3375 */ + if (l_image->x0 > l_image->x1 || l_image->y0 > l_image->y1) { + opj_event_msg(p_manager, EVT_ERROR, "Error with SIZ marker: negative image size (%d x %d)\n", l_image->x1 - l_image->x0, l_image->y1 - l_image->y0); + return OPJ_FALSE; + } + #ifdef USE_JPWL if (l_cp->correct) { /* if JPWL is on, we check whether TX errors have damaged From 0ae6ff80187bbd8d9467b500799cb752b3f921c0 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 11:09:20 +0000 Subject: [PATCH 113/333] [trunk] Import patch from sumatrapdf team. This handle testcase 2539.pdf.SIGFPE.706.1712 Update issue 225 --- src/lib/openjp2/j2k.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 52cf06c5..a6397eff 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -1959,6 +1959,11 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, opj_event_msg(p_manager, EVT_ERROR, "Error with SIZ marker: negative image size (%d x %d)\n", l_image->x1 - l_image->x0, l_image->y1 - l_image->y0); return OPJ_FALSE; } + /* testcase 2539.pdf.SIGFPE.706.1712 (also 3622.pdf.SIGFPE.706.2916 and 4008.pdf.SIGFPE.706.3345 and maybe more) */ + if (!(l_cp->tdx * l_cp->tdy)) { + opj_event_msg(p_manager, EVT_ERROR, "Error with SIZ marker: invalid tile size (tdx: %d, tdy: %d)\n", l_cp->tdx, l_cp->tdy); + return OPJ_FALSE; + } #ifdef USE_JPWL if (l_cp->correct) { From 7195a23a9d761d00bcf674ad1424648435fcfc57 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 11:09:59 +0000 Subject: [PATCH 114/333] [trunk] Import patch from sumatrapdf team. This handle testcase 1610.pdf.SIGSEGV.59c.681 Update issue 225 --- src/lib/openjp2/j2k.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index a6397eff..120e94fc 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -1965,6 +1965,12 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, return OPJ_FALSE; } + /* testcase 1610.pdf.SIGSEGV.59c.681 */ + if (((OPJ_UINT64)l_image->x1) * ((OPJ_UINT64)l_image->y1) != (l_image->x1 * l_image->y1)) { + opj_event_msg(p_manager, EVT_ERROR, "Prevent buffer overflow (x1: %d, y1: %d)", l_image->x1, l_image->y1); + return OPJ_FALSE; + } + #ifdef USE_JPWL if (l_cp->correct) { /* if JPWL is on, we check whether TX errors have damaged From 3a155ceda60ef29d97f4faa6dded7716af8a2ebe Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 11:10:40 +0000 Subject: [PATCH 115/333] [trunk] Import patch from sumatrapdf team. This handle testcase 2.pdf.SIGFPE.706.1112 Update issue 225 --- src/lib/openjp2/j2k.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 120e94fc..005698ab 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -3915,6 +3915,12 @@ OPJ_BOOL opj_j2k_read_sot ( opj_j2k_t *p_j2k, opj_read_bytes(p_header_data,&(p_j2k->m_current_tile_number),2); /* Isot */ p_header_data+=2; + /* testcase 2.pdf.SIGFPE.706.1112 */ + if (p_j2k->m_current_tile_number >= l_cp->tw * l_cp->th) { + opj_event_msg(p_manager, EVT_ERROR, "Invalid tile number %d\n", p_j2k->m_current_tile_number); + return OPJ_FALSE; + } + l_tcp = &l_cp->tcps[p_j2k->m_current_tile_number]; l_tile_x = p_j2k->m_current_tile_number % l_cp->tw; l_tile_y = p_j2k->m_current_tile_number / l_cp->tw; From 29a29d62103cf180bdfee69409fd32c0375f1ab9 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 11:11:33 +0000 Subject: [PATCH 116/333] [trunk] Import patch from sumatrapdf team. This handle testcase 451.pdf.SIGSEGV.ce9.3723 Update issue 225 --- src/lib/openjp2/j2k.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 005698ab..d94c664f 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -4010,20 +4010,19 @@ OPJ_BOOL opj_j2k_read_sot ( opj_j2k_t *p_j2k, if (l_num_parts != 0) { /* Number of tile-part header is provided by this tile-part header */ /* Useful to manage the case of textGBR.jp2 file because two values of TNSot are allowed: the correct numbers of * tile-parts for that tile and zero (A.4.2 of 15444-1 : 2002). */ - if (l_tcp->m_nb_tile_parts) { - if (l_current_part >= l_tcp->m_nb_tile_parts){ - opj_event_msg(p_manager, EVT_ERROR, "In SOT marker, TPSot (%d) is not valid regards to the current " - "number of tile-part (%d), giving up\n", l_current_part, l_tcp->m_nb_tile_parts ); - p_j2k->m_specific_param.m_decoder.m_last_tile_part = 1; - return OPJ_FALSE; - } + if (l_num_parts < l_tcp->m_nb_tile_parts) { + l_num_parts = l_tcp->m_nb_tile_parts; + } + if (l_current_part >= l_num_parts) { + /* testcase 451.pdf.SIGSEGV.ce9.3723 */ + l_num_parts = l_current_part + 1; } l_tcp->m_nb_tile_parts = l_num_parts; } /* If know the number of tile part header we will check if we didn't read the last*/ if (l_tcp->m_nb_tile_parts) { - if (l_tcp->m_nb_tile_parts == (l_current_part + 1)) { + if (l_tcp->m_nb_tile_parts == l_current_part) { p_j2k->m_specific_param.m_decoder.m_can_decode = 1; /* Process the last tile-part header*/ } } From adb237cfa891b6f5fa51a471944bb591e5f26273 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 11:13:21 +0000 Subject: [PATCH 117/333] [trunk] Import patch from sumatrapdf team. Original commit is 5b0c9985e3359aca9b3fcfd94424166aa61a141a. Update issue 225 --- src/lib/openjp2/j2k.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index d94c664f..3cdbfcef 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -4091,7 +4091,7 @@ OPJ_BOOL opj_j2k_read_sot ( opj_j2k_t *p_j2k, if ( l_current_part >= p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps ){ opj_tp_index_t *new_tp_index; - p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps += 10; + p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps = l_current_part + 1; new_tp_index = (opj_tp_index_t *) opj_realloc( p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].tp_index, p_j2k->cstr_index->tile_index[p_j2k->m_current_tile_number].current_nb_tps * sizeof(opj_tp_index_t)); From 5f3470fcd0f6b4e8be178b3c18c03de21fd29012 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 11:14:27 +0000 Subject: [PATCH 118/333] [trunk] Import patch from sumatrapdf team. This handle testcase 3635.pdf.asan.77.2930 Update issue 225 --- src/lib/openjp2/j2k.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 3cdbfcef..5bbad1b9 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -4481,6 +4481,14 @@ static OPJ_BOOL opj_j2k_read_rgn (opj_j2k_t *p_j2k, }; #endif /* USE_JPWL */ + /* testcase 3635.pdf.asan.77.2930 */ + if (l_comp_room >= l_nb_comp) { + opj_event_msg(p_manager, EVT_ERROR, + "JPWL: bad component number in RGN (%d when there are only %d)\n", + l_comp_room, l_nb_comp); + return OPJ_FALSE; + } + opj_read_bytes(p_header_data,(OPJ_UINT32 *) (&(l_tcp->tccps[l_comp_no].roishift)),1); /* SPrgn */ ++p_header_data; From 005e75bdc390fb81307d325ee90086a26e95f954 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 11:16:32 +0000 Subject: [PATCH 119/333] [trunk] Import (ugly) patch from sumatrapdf team. This feels like a hack rather than a solution. Fixes issue 226 --- src/lib/openjp2/j2k.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 5bbad1b9..aa4f1d1d 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -7367,6 +7367,12 @@ OPJ_BOOL opj_j2k_read_tile_header( opj_j2k_t * p_j2k, /* Read 2 bytes from the buffer as the marker size */ opj_read_bytes(p_j2k->m_specific_param.m_decoder.m_header_data,&l_marker_size,2); + /* cf. https://code.google.com/p/openjpeg/issues/detail?id=226 */ + if (l_current_marker == 0x8080 && opj_stream_get_number_byte_left(p_stream) == 0) { + p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_NEOC; + break; + } + /* Why this condition? FIXME */ if (p_j2k->m_specific_param.m_decoder.m_state & J2K_STATE_TPH){ p_j2k->m_specific_param.m_decoder.m_sot_length -= (l_marker_size + 2); From 19887b7b8c4e1cdc54d25a3d10be2415a1385816 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 11:17:18 +0000 Subject: [PATCH 120/333] [trunk] Import patch from sumatrapdf team. This handle testcase 2977.pdf.asan.67.2198 Update issue 225 --- src/lib/openjp2/j2k.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index aa4f1d1d..792c1c9f 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -7766,6 +7766,10 @@ OPJ_BOOL opj_j2k_update_image_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data, opj_im if( (l_offset_x0_src < 0 ) || (l_offset_y0_src < 0 ) || (l_offset_x1_src < 0 ) || (l_offset_y1_src < 0 ) ){ return OPJ_FALSE; } + /* testcase 2977.pdf.asan.67.2198 */ + if ((OPJ_INT32)l_width_dest < 0 || (OPJ_INT32)l_height_dest < 0) { + return OPJ_FALSE; + } /*-----*/ /* Compute the input buffer offset */ From 533d92aa8e586dfd35cba92f467261ea400871eb Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 11:21:18 +0000 Subject: [PATCH 121/333] [trunk] Import patch from sumatrapdf team. This handle some testcase with no input dataset, but changes looks ok. Update issue 225 --- src/lib/openjp2/jp2.c | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c index 3678be67..0af1f960 100644 --- a/src/lib/openjp2/jp2.c +++ b/src/lib/openjp2/jp2.c @@ -980,6 +980,11 @@ OPJ_BOOL opj_jp2_read_pclr( opj_jp2_t *jp2, for(i = 0; i < nr_channels; ++i) { OPJ_INT32 bytes_to_read = (channel_size[i]+7)>>3; + if (bytes_to_read > sizeof(OPJ_UINT32)) + bytes_to_read = sizeof(OPJ_UINT32); + if ((ptrdiff_t)p_pclr_header_size < p_pclr_header_data - orig_header_data + bytes_to_read) + return OPJ_FALSE; + if (bytes_to_read > sizeof(OPJ_UINT32)) bytes_to_read = sizeof(OPJ_UINT32); if ((ptrdiff_t)p_pclr_header_size < p_pclr_header_data - orig_header_data + bytes_to_read) @@ -1031,6 +1036,11 @@ OPJ_BOOL opj_jp2_read_cmap( opj_jp2_t * jp2, return OPJ_FALSE; } + if (p_cmap_header_size < (OPJ_UINT32)nr_channels * 4) { + opj_event_msg(p_manager, EVT_ERROR, "Insufficient data for CMAP box.\n"); + return OPJ_FALSE; + } + cmap = (opj_jp2_cmap_comp_t*) opj_malloc(nr_channels * sizeof(opj_jp2_cmap_comp_t)); if (!cmap) return OPJ_FALSE; @@ -1122,6 +1132,11 @@ OPJ_BOOL opj_jp2_read_cdef( opj_jp2_t * jp2, return OPJ_FALSE; } + if (p_cdef_header_size < 2) { + opj_event_msg(p_manager, EVT_ERROR, "Insufficient data for CDEF box.\n"); + return OPJ_FALSE; + } + opj_read_bytes(p_cdef_header_data,&l_value ,2); /* N */ p_cdef_header_data+= 2; @@ -1135,6 +1150,11 @@ OPJ_BOOL opj_jp2_read_cdef( opj_jp2_t * jp2, return OPJ_FALSE; } + if (p_cdef_header_size < 2 + (OPJ_UINT32)(OPJ_UINT16)l_value * 6) { + opj_event_msg(p_manager, EVT_ERROR, "Insufficient data for CDEF box.\n"); + return OPJ_FALSE; + } + cdef_info = (opj_jp2_cdef_info_t*) opj_malloc(l_value * sizeof(opj_jp2_cdef_info_t)); if (!cdef_info) return OPJ_FALSE; From 51e3764519d77210f8e6bb707fbe009fcf867a87 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 11:22:34 +0000 Subject: [PATCH 122/333] [trunk] Import patch from sumatrapdf team. This handle some Part-2 compliant file, by being more tolerant in COLR box. No testcase for now. Fixes issue 247 --- src/lib/openjp2/jp2.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c index 0af1f960..f8eb907d 100644 --- a/src/lib/openjp2/jp2.c +++ b/src/lib/openjp2/jp2.c @@ -1222,10 +1222,14 @@ OPJ_BOOL opj_jp2_read_colr( opj_jp2_t *jp2, ++p_colr_header_data; if (jp2->meth == 1) { - if (p_colr_header_size != 7) { - opj_event_msg(p_manager, EVT_ERROR, "Bad BPCC header box (bad size)\n"); + if (p_colr_header_size < 7) { + opj_event_msg(p_manager, EVT_ERROR, "Bad COLR header box (bad size: %d)\n", p_colr_header_size); return OPJ_FALSE; } + if (p_colr_header_size > 7) { + /* testcase Altona_Technical_v20_x4.pdf */ + opj_event_msg(p_manager, EVT_WARNING, "Bad COLR header box (bad size: %d)\n", p_colr_header_size); + } opj_read_bytes(p_colr_header_data,&jp2->enumcs ,4); /* EnumCS */ From 4a7ba87d99a48af0ed7f8cc2b6bb72152d2833fe Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 11:24:38 +0000 Subject: [PATCH 123/333] [trunk] Import patch from sumatrapdf team. Start using new color space when found. Update issue 225 --- src/lib/openjp2/jp2.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c index f8eb907d..978f3c57 100644 --- a/src/lib/openjp2/jp2.c +++ b/src/lib/openjp2/jp2.c @@ -1294,6 +1294,8 @@ OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2, p_image->color_space = OPJ_CLRSPC_GRAY; else if (jp2->enumcs == 18) p_image->color_space = OPJ_CLRSPC_SYCC; + else if (jp2->enumcs == 24) + p_image->color_space = OPJ_CLRSPC_EYCC; else p_image->color_space = OPJ_CLRSPC_UNKNOWN; From 37a8d2acc1945010fc4b76255003d1f9e9edefa8 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 11:25:27 +0000 Subject: [PATCH 124/333] [trunk] Import patch from sumatrapdf team. This handle testcase 1851.pdf.SIGSEGV.ce9.948 Update issue 225 --- src/lib/openjp2/jp2.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c index 978f3c57..544ce91b 100644 --- a/src/lib/openjp2/jp2.c +++ b/src/lib/openjp2/jp2.c @@ -1819,6 +1819,12 @@ OPJ_BOOL opj_jp2_read_header_procedure( opj_jp2_t *jp2, opj_free(l_current_data); return OPJ_FALSE; } + /* testcase 1851.pdf.SIGSEGV.ce9.948 */ + else if (box.length < l_nb_bytes_read) { + opj_event_msg(p_manager, EVT_ERROR, "invalid box size %d (%x)\n", box.length, box.type); + opj_free(l_current_data); + return OPJ_FALSE; + } l_current_handler = opj_jp2_find_handler(box.type); l_current_data_size = box.length - l_nb_bytes_read; From 7247543da37bea539149f3391a529e5a0739beff Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 11:26:09 +0000 Subject: [PATCH 125/333] [trunk] Import patch from sumatrapdf team. This handle testcase 1888.pdf.asan.35.988 Update issue 225 --- src/lib/openjp2/tcd.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib/openjp2/tcd.c b/src/lib/openjp2/tcd.c index fc77b5e4..cba1e245 100644 --- a/src/lib/openjp2/tcd.c +++ b/src/lib/openjp2/tcd.c @@ -663,6 +663,11 @@ OPJ_BOOL FUNCTION ( opj_tcd_t *p_tcd, \ l_tile->y0 = opj_int_max(l_cp->ty0 + q * l_cp->tdy, l_image->y0); \ l_tile->x1 = opj_int_min(l_cp->tx0 + (p + 1) * l_cp->tdx, l_image->x1); \ l_tile->y1 = opj_int_min(l_cp->ty0 + (q + 1) * l_cp->tdy, l_image->y1); \ + /* testcase 1888.pdf.asan.35.988 */ \ + if (l_tccp->numresolutions == 0) { \ + fprintf(stderr, "tiles require at least one resolution\n"); \ + return OPJ_FALSE; \ + } \ /*fprintf(stderr, "Tile border = %d,%d,%d,%d\n", l_tile->x0, l_tile->y0,l_tile->x1,l_tile->y1);*/ \ \ /*tile->numcomps = image->numcomps; */ \ From 23ea2708812b5f529592ed41d2204b20695d48d6 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 11:27:01 +0000 Subject: [PATCH 126/333] [trunk] Import patch from sumatrapdf team. This handle testcase 1336.pdf.asan.47.376 Update issue 225 --- src/lib/openjp2/tcd.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/lib/openjp2/tcd.c b/src/lib/openjp2/tcd.c index cba1e245..4388819a 100644 --- a/src/lib/openjp2/tcd.c +++ b/src/lib/openjp2/tcd.c @@ -1578,7 +1578,13 @@ OPJ_BOOL opj_tcd_mct_decode ( opj_tcd_t *p_tcd ) l_samples = (l_tile_comp->x1 - l_tile_comp->x0) * (l_tile_comp->y1 - l_tile_comp->y0); if (l_tile->numcomps >= 3 ){ - if (l_tcp->mct == 2) { + /* testcase 1336.pdf.asan.47.376 */ + if ((l_tile->comps[0].x1 - l_tile->comps[0].x0) * (l_tile->comps[0].y1 - l_tile->comps[0].y0) < (OPJ_INT32)l_samples || + (l_tile->comps[1].x1 - l_tile->comps[1].x0) * (l_tile->comps[1].y1 - l_tile->comps[1].y0) < (OPJ_INT32)l_samples || + (l_tile->comps[2].x1 - l_tile->comps[2].x0) * (l_tile->comps[2].y1 - l_tile->comps[2].y0) < (OPJ_INT32)l_samples) { + fprintf(stderr, "Tiles don't all have the same dimension. Skip the MCT step.\n"); + } + else if (l_tcp->mct == 2) { OPJ_BYTE ** l_data; if (! l_tcp->m_mct_decoding_matrix) { @@ -1659,6 +1665,8 @@ OPJ_BOOL opj_tcd_dc_level_shift_decode ( opj_tcd_t *p_tcd ) l_height = (l_res->y1 - l_res->y0); l_stride = (l_tile_comp->x1 - l_tile_comp->x0) - l_width; + assert(l_height == 0 || l_width + l_stride <= l_tile_comp->data_size / l_height); /*MUPDF*/ + if (l_img_comp->sgnd) { l_min = -(1 << (l_img_comp->prec - 1)); l_max = (1 << (l_img_comp->prec - 1)) - 1; From 05dae25a228861509330f308e5781571426b2ad5 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 12:30:44 +0000 Subject: [PATCH 127/333] [trunk] Revert r2453 since it breaks conformance test ETS-C1P1-p1_06.j2k-decode --- src/lib/openjp2/t2.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c index 2271ea6b..0982d6b5 100644 --- a/src/lib/openjp2/t2.c +++ b/src/lib/openjp2/t2.c @@ -983,11 +983,6 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, do { l_cblk->segs[l_segno].numnewpasses = opj_int_min(l_cblk->segs[l_segno].maxpasses - l_cblk->segs[l_segno].numpasses, n); l_cblk->segs[l_segno].newlen = opj_bio_read(l_bio, l_cblk->numlenbits + opj_uint_floorlog2(l_cblk->segs[l_segno].numnewpasses)); - /* testcase 1802.pdf.SIGSEGV.36e.894 */ - if (l_cblk->segs[l_segno].newlen > *l_modified_length_ptr) { - opj_bio_destroy(l_bio); - return OPJ_FALSE; - } n -= l_cblk->segs[l_segno].numnewpasses; if (n > 0) { From 3fe9243e1ce92336b61524d06e5cfddd5c981bba Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 12:33:49 +0000 Subject: [PATCH 128/333] [trunk] revert r2460 since it breaks ETS-C1P0-p0_03.j2k-decode. Update issue 225 --- src/lib/openjp2/j2k.c | 8 -------- 1 file changed, 8 deletions(-) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 792c1c9f..11d66a18 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -4481,14 +4481,6 @@ static OPJ_BOOL opj_j2k_read_rgn (opj_j2k_t *p_j2k, }; #endif /* USE_JPWL */ - /* testcase 3635.pdf.asan.77.2930 */ - if (l_comp_room >= l_nb_comp) { - opj_event_msg(p_manager, EVT_ERROR, - "JPWL: bad component number in RGN (%d when there are only %d)\n", - l_comp_room, l_nb_comp); - return OPJ_FALSE; - } - opj_read_bytes(p_header_data,(OPJ_UINT32 *) (&(l_tcp->tccps[l_comp_no].roishift)),1); /* SPrgn */ ++p_header_data; From 52440cc2e61aa3ec363fe8739b426250e42243bc Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 12:54:02 +0000 Subject: [PATCH 129/333] [trunk] Remove a simple warning about a cast --- src/lib/openjp2/t2.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c index 0982d6b5..6aee8c72 100644 --- a/src/lib/openjp2/t2.c +++ b/src/lib/openjp2/t2.c @@ -441,7 +441,8 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2, /* don't forget to release pi */ opj_pi_destroy(l_pi,l_nb_pocs); - *p_data_read = l_current_data - p_src; + assert( l_current_data - p_src < UINT32_MAX ); + *p_data_read = (OPJ_UINT32)(l_current_data - p_src); return OPJ_TRUE; } From 7f277fea948958f419f1930da97fa0ebd16953b7 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 14:00:21 +0000 Subject: [PATCH 130/333] [trunk] Remove some simple warnings about cast, and unused functions --- tests/test_tile_decoder.c | 16 +--------------- tests/test_tile_encoder.c | 4 ++-- 2 files changed, 3 insertions(+), 17 deletions(-) diff --git a/tests/test_tile_decoder.c b/tests/test_tile_decoder.c index 5a53beea..7560af5f 100644 --- a/tests/test_tile_decoder.c +++ b/tests/test_tile_decoder.c @@ -99,7 +99,7 @@ static int infile_format(const char *fname) return -1; memset(buf, 0, 12); - l_nb_read = fread(buf, 1, 12, reader); + l_nb_read = (unsigned int)fread(buf, 1, 12, reader); fclose(reader); if (l_nb_read != 12) return -1; @@ -136,20 +136,6 @@ static int infile_format(const char *fname) /* -------------------------------------------------------------------------- */ -/** - sample error callback expecting a FILE* client object - */ -static void error_callback_file(const char *msg, void *client_data) { - FILE *stream = (FILE*)client_data; - fprintf(stream, "[ERROR] %s", msg); -} -/** - sample warning callback expecting a FILE* client object - */ -static void warning_callback_file(const char *msg, void *client_data) { - FILE *stream = (FILE*)client_data; - fprintf(stream, "[WARNING] %s", msg); -} /** sample error debug callback expecting no client object */ diff --git a/tests/test_tile_encoder.c b/tests/test_tile_encoder.c index 62becce7..89b5f901 100644 --- a/tests/test_tile_encoder.c +++ b/tests/test_tile_encoder.c @@ -132,7 +132,7 @@ int main (int argc, char *argv[]) fprintf(stdout, "Encoding random values -> keep in mind that this is very hard to compress\n"); for (i=0;i Date: Wed, 26 Feb 2014 14:04:03 +0000 Subject: [PATCH 131/333] [trunk] Add missing include dir for wx app --- src/bin/wx/OPJViewer/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bin/wx/OPJViewer/CMakeLists.txt b/src/bin/wx/OPJViewer/CMakeLists.txt index 1b61c830..66cf01d2 100644 --- a/src/bin/wx/OPJViewer/CMakeLists.txt +++ b/src/bin/wx/OPJViewer/CMakeLists.txt @@ -9,6 +9,7 @@ include_directories( ${OPENJPEG_SOURCE_DIR}/src/lib ${OPENJPEG_SOURCE_DIR}/src/bin ${OPENJPEG_SOURCE_DIR}/src/lib/openjp2 + ${OPENJPEG_BINARY_DIR}/src/lib/openjp2 # opj_config.h and opj_config_private.h ) # original flags: From 97c376e06d0c58b3d2961f1dfd5026eeaaa78fc8 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 14:23:30 +0000 Subject: [PATCH 132/333] [trunk] When no output PGX file is found, report an error --- tests/nonregression/checkmd5refs.cmake | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/nonregression/checkmd5refs.cmake b/tests/nonregression/checkmd5refs.cmake index 80de4ea9..87c0695a 100644 --- a/tests/nonregression/checkmd5refs.cmake +++ b/tests/nonregression/checkmd5refs.cmake @@ -21,6 +21,9 @@ #message("2: ${FILENAME}") file(GLOB globfiles "Temporary/${FILENAME}*.pgx" ) #message("6: ${globfiles}") +if(NOT globfiles) + message(SEND_ERROR "Could not find output PGX files: ${FILENAME}") +endif() # REFFILE follow what md5sum -c would expect as input: file(READ ${REFFILE} variable) From 5e77c4e936b1d90b95ee6cbce03e70178f15373d Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 14:24:02 +0000 Subject: [PATCH 133/333] [trunk] add test suite for issue 142 Fixes issue 142 --- tests/nonregression/md5refs.txt | 3 +++ tests/nonregression/test_suite.ctest.in | 2 ++ 2 files changed, 5 insertions(+) diff --git a/tests/nonregression/md5refs.txt b/tests/nonregression/md5refs.txt index e86b39f7..94751a07 100644 --- a/tests/nonregression/md5refs.txt +++ b/tests/nonregression/md5refs.txt @@ -21,6 +21,9 @@ e273e2aaea4a4fc1b2cf7c09c53c3cc6 file409752_2.pgx 05c062aca83d13b8095460f38a690a08 illegalcolortransform.j2k_0.pgx cb28787aa7c223f03e6acad71e244108 issue104_jpxstream.jp2_0.pgx cb28787aa7c223f03e6acad71e244108 issue104_jpxstream.jp2_1.pgx +619694e5674992b3286244bf13058f7c issue142.j2k_0.pgx +c675c4b77dc3cc2a0d6542a32b438a48 issue142.j2k_1.pgx +663ebdd12dd6a36915ea1152c43cb69a issue142.j2k_2.pgx cb28787aa7c223f03e6acad71e244108 issue104_jpxstream.jp2_2.pgx adda4f5e46845b96dd3df14a76aa7229 issue188_beach_64bitsbox.jp2_0.pgx 90a9709c166019d1e101e7b96d257ed9 issue188_beach_64bitsbox.jp2_1.pgx diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 6348ff59..6962abb8 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -123,6 +123,8 @@ opj_decompress -i @INPUT_NR_PATH@/issue228.j2k -o @TEMP_PATH@/i !opj_decompress -i @INPUT_NR_PATH@/3672da2f1f67bbecad27d7181b4e9d7c.SIGFPE.d25.805.jpc -o @TEMP_PATH@3672da2f1f67bbecad27d7181b4e9d7c.SIGFPE.d25.805.jpc.pgx # issue 254 (loss in quality) opj_decompress -i @INPUT_NR_PATH@/issue254.jp2 -o @TEMP_PATH@/issue254.jp2.pgx +# issue 142 +opj_decompress -i @INPUT_NR_PATH@/issue142.j2k -o @TEMP_PATH@/issue142.j2k.pgx # decode with specific area # prec=12; nb_c=1 From 9f3687f917d45f2e9f3eeade014302e0ec6a4680 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 14:28:17 +0000 Subject: [PATCH 134/333] [trunk] fixes test NR-DEC-file409752.jp2-40-decode, use proper naming convention (need to keep file extension) --- tests/nonregression/md5refs.txt | 6 +++--- tests/nonregression/test_suite.ctest.in | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/nonregression/md5refs.txt b/tests/nonregression/md5refs.txt index 94751a07..48180b43 100644 --- a/tests/nonregression/md5refs.txt +++ b/tests/nonregression/md5refs.txt @@ -15,9 +15,9 @@ b8f473c07ba5ebfc195bdd53c3b3b97f buxR.j2k_0.pgx 05c062aca83d13b8095460f38a690a08 Cannotreaddatawithnosizeknown.j2k_0.pgx 6276da0ec5fac44d683d3468b290331d cthead1.j2k_0.pgx 8afcac9a696cc8d753b0eb9f4ae692ff CT_Phillips_JPEG2K_Decompr_Problem.j2k_0.pgx -04d35ab6160c9029549f72358df984da file409752_0.pgx -2813bd6fdc2c306b91b3da3688b8bf49 file409752_1.pgx -e273e2aaea4a4fc1b2cf7c09c53c3cc6 file409752_2.pgx +04d35ab6160c9029549f72358df984da file409752.jp2_0.pgx +2813bd6fdc2c306b91b3da3688b8bf49 file409752.jp2_1.pgx +e273e2aaea4a4fc1b2cf7c09c53c3cc6 file409752.jp2_2.pgx 05c062aca83d13b8095460f38a690a08 illegalcolortransform.j2k_0.pgx cb28787aa7c223f03e6acad71e244108 issue104_jpxstream.jp2_0.pgx cb28787aa7c223f03e6acad71e244108 issue104_jpxstream.jp2_1.pgx diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 6962abb8..c8a49f84 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -92,7 +92,7 @@ opj_decompress -i @INPUT_NR_PATH@/mem-b2b86b74-2753.jp2 -o @TEMP_PATH@/mem-b2b8 # issue 194 raised by the gdal fuzzer test (should nicely failed) ! opj_decompress -i @INPUT_NR_PATH@/gdal_fuzzer_check_comp_dx_dy.jp2 -o @TEMP_PATH@/gdal_fuzzer_check_comp_dx_dy.pgx # issue 202 -opj_decompress -i @INPUT_NR_PATH@/file409752.jp2 -o @TEMP_PATH@/file409752.pgx +opj_decompress -i @INPUT_NR_PATH@/file409752.jp2 -o @TEMP_PATH@/file409752.jp2.pgx # issue 188 opj_decompress -i @INPUT_NR_PATH@/issue188_beach_64bitsbox.jp2 -o @TEMP_PATH@/issue188_beach_64bitsbox.jp2.pgx # issue 206 From 6f3a7ef3c818934eb163a9d9f82fd2d591da809b Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 14:32:11 +0000 Subject: [PATCH 135/333] [trunk] run test suite on input dataset from issue 134 Fixes issue 134 --- tests/nonregression/md5refs.txt | 3 +++ tests/nonregression/test_suite.ctest.in | 2 ++ 2 files changed, 5 insertions(+) diff --git a/tests/nonregression/md5refs.txt b/tests/nonregression/md5refs.txt index 48180b43..f30fd37e 100644 --- a/tests/nonregression/md5refs.txt +++ b/tests/nonregression/md5refs.txt @@ -20,6 +20,9 @@ b8f473c07ba5ebfc195bdd53c3b3b97f buxR.j2k_0.pgx e273e2aaea4a4fc1b2cf7c09c53c3cc6 file409752.jp2_2.pgx 05c062aca83d13b8095460f38a690a08 illegalcolortransform.j2k_0.pgx cb28787aa7c223f03e6acad71e244108 issue104_jpxstream.jp2_0.pgx +c74edbb49e132b2cfc1eaf7908197b17 issue134.jp2_0.pgx +16fe8ed450da10a6aaae4cf6f467fc21 issue134.jp2_1.pgx +c6091c07bf0ff221008dfb60d893cdff issue134.jp2_2.pgx cb28787aa7c223f03e6acad71e244108 issue104_jpxstream.jp2_1.pgx 619694e5674992b3286244bf13058f7c issue142.j2k_0.pgx c675c4b77dc3cc2a0d6542a32b438a48 issue142.j2k_1.pgx diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index c8a49f84..3b0b52a8 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -125,6 +125,8 @@ opj_decompress -i @INPUT_NR_PATH@/issue228.j2k -o @TEMP_PATH@/i opj_decompress -i @INPUT_NR_PATH@/issue254.jp2 -o @TEMP_PATH@/issue254.jp2.pgx # issue 142 opj_decompress -i @INPUT_NR_PATH@/issue142.j2k -o @TEMP_PATH@/issue142.j2k.pgx +# issue 134 +opj_decompress -i @INPUT_NR_PATH@/issue134.jp2 -o @TEMP_PATH@/issue134.jp2.pgx # decode with specific area # prec=12; nb_c=1 From 6deb1a83b5e83c82d710667cc2ae141b664a4fbf Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 15:14:27 +0000 Subject: [PATCH 136/333] [trunk] Add more details in case test fails --- tests/compareRAWimages.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/compareRAWimages.c b/tests/compareRAWimages.c index 32575c68..4f183529 100644 --- a/tests/compareRAWimages.c +++ b/tests/compareRAWimages.c @@ -38,8 +38,6 @@ #include "opj_getopt.h" -void compareRAWimages_help_display(void); - typedef struct test_cmp_parameters { /** */ @@ -51,7 +49,7 @@ typedef struct test_cmp_parameters /******************************************************************************* * Command line help function *******************************************************************************/ -void compareRAWimages_help_display(void) { +static void compareRAWimages_help_display(void) { fprintf(stdout,"\nList of parameters for the comparePGX function \n"); fprintf(stdout,"\n"); fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline RAW image \n"); @@ -119,6 +117,7 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) *******************************************************************************/ int main(int argc, char **argv) { + int pos = 0; test_cmp_parameters inParam; FILE *file_test=NULL, *file_base=NULL; unsigned char equal = 1; @@ -191,7 +190,7 @@ int main(int argc, char **argv) /* Read one byte*/ if (!fread(&value_base, 1, 1, file_base)) { - eof_base = 1;; + eof_base = 1; } /* End of file reached by the two files?*/ @@ -208,9 +207,10 @@ int main(int argc, char **argv) /* Binary values are equal?*/ if (value_test != value_base) { - fprintf(stdout,"Binary values read in the file are different.\n"); + fprintf(stdout,"Binary values read in the file are different %x vs %x at position %d.\n", value_test, value_base, pos); equal = 0; } + pos++; } /* Free Memory */ From d74579aa38a85753127446c9c3654672d028b4c6 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 15:21:03 +0000 Subject: [PATCH 137/333] [trunk] Run test suite on issue 141. Add a fake dataset to report that test is failing. Update issue 141 --- 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 3b0b52a8..904d9458 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -127,6 +127,9 @@ opj_decompress -i @INPUT_NR_PATH@/issue254.jp2 -o @TEMP_PATH@/i opj_decompress -i @INPUT_NR_PATH@/issue142.j2k -o @TEMP_PATH@/issue142.j2k.pgx # issue 134 opj_decompress -i @INPUT_NR_PATH@/issue134.jp2 -o @TEMP_PATH@/issue134.jp2.pgx +# issue 141 +opj_compress -i @INPUT_NR_PATH@/issue141.rawl -o @TEMP_PATH@/issue141.rawl.j2k -F 2048,2816,1,16,u +opj_compress -i @INPUT_NR_PATH@/issue141.rawl -o @TEMP_PATH@/issue141.rawl.j2k -F 2048,2816,1,16,u -I # decode with specific area # prec=12; nb_c=1 From 9ac3ae12707f4383825608ce7f8b0f351d248787 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 15:41:57 +0000 Subject: [PATCH 138/333] [trunk] kakadu does not support 451.pdf.SIGSEGV.ce9.372 we should not pretend to be able to decompress it Update issue 225 --- tests/nonregression/md5refs.txt | 3 --- tests/nonregression/test_suite.ctest.in | 2 +- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/tests/nonregression/md5refs.txt b/tests/nonregression/md5refs.txt index f30fd37e..4e2877d0 100644 --- a/tests/nonregression/md5refs.txt +++ b/tests/nonregression/md5refs.txt @@ -3,9 +3,6 @@ a3a0606dfa0779d657c6a923b90e4678 _00042.j2k_1.pgx 106954dc468dfe0884d02268e91f9f5b _00042.j2k_2.pgx 8889def55f1e18dae6002b9b3a6dd152 123.j2c_0.pgx ee6881e50c9cf17994ac74c2bee956a8 1888.pdf.asan.35.988.jp2_0.pgx -1514d460fa6da37aece72c3a786ad40a 451.pdf.SIGSEGV.ce9.3723.jp2_0.pgx -398b39afd263f967045928ba38a7ea51 451.pdf.SIGSEGV.ce9.3723.jp2_1.pgx -64beae9da75e1c3716af24ea231285d7 451.pdf.SIGSEGV.ce9.3723.jp2_2.pgx 4a0daf7a9065101379eaebc28e436b1e Bretagne2.j2k_0.pgx 07578fc7bf81d3da694de8ae27308b82 Bretagne2.j2k_1.pgx 3690c42f83bad42f4abea48525d45e0e Bretagne2.j2k_2.pgx diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 904d9458..549fa910 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -109,7 +109,7 @@ opj_decompress -i @INPUT_NR_PATH@/issue205.jp2 -o @TEMP_PATH@/issue205.jp2.pgx !opj_decompress -i @INPUT_NR_PATH@/4149.pdf.SIGSEGV.cf7.3501.jp2 -o @TEMP_PATH@/4149.pdf.SIGSEGV.cf7.3501.jp2.pgx !opj_decompress -i @INPUT_NR_PATH@/4035.pdf.SIGSEGV.d8b.3375.jp2 -o @TEMP_PATH@/4035.pdf.SIGSEGV.d8b.3375.jp2.pgx !opj_decompress -i @INPUT_NR_PATH@/2977.pdf.asan.67.2198.jp2 -o @TEMP_PATH@/2977.pdf.asan.67.2198.jp2.pgx -opj_decompress -i @INPUT_NR_PATH@/451.pdf.SIGSEGV.ce9.3723.jp2 -o @TEMP_PATH@/451.pdf.SIGSEGV.ce9.3723.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/451.pdf.SIGSEGV.ce9.3723.jp2 -o @TEMP_PATH@/451.pdf.SIGSEGV.ce9.3723.jp2.pgx !opj_decompress -i @INPUT_NR_PATH@/3635.pdf.asan.77.2930.jp2 -o @TEMP_PATH@/3635.pdf.asan.77.2930.jp2.pgx !opj_decompress -i @INPUT_NR_PATH@/1802.pdf.SIGSEGV.36e.894.jp2 -o @TEMP_PATH@/1802.pdf.SIGSEGV.36e.894.jp2.pgx !opj_decompress -i @INPUT_NR_PATH@/451.pdf.SIGSEGV.f4c.3723.jp2 -o @TEMP_PATH@/451.pdf.SIGSEGV.f4c.3723.jp2.pgx From 91f521ef92572af05609325ac374c1cea4e41cb2 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 15:55:49 +0000 Subject: [PATCH 139/333] [trunk] Update missing md5sums --- tests/nonregression/checkmd5refs.cmake | 2 +- tests/nonregression/md5refs.txt | 40 ++++++++++++++++++++++++-- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/tests/nonregression/checkmd5refs.cmake b/tests/nonregression/checkmd5refs.cmake index 87c0695a..9c1fa6ca 100644 --- a/tests/nonregression/checkmd5refs.cmake +++ b/tests/nonregression/checkmd5refs.cmake @@ -19,7 +19,7 @@ #message("0: ${REFFILE}") #message("1: ${CMAKE_CURRENT_BINARY_DIR}") #message("2: ${FILENAME}") -file(GLOB globfiles "Temporary/${FILENAME}*.pgx" ) +file(GLOB globfiles "Temporary/${FILENAME}*.pgx" "Temporary/${FILENAME}*.png") #message("6: ${globfiles}") if(NOT globfiles) message(SEND_ERROR "Could not find output PGX files: ${FILENAME}") diff --git a/tests/nonregression/md5refs.txt b/tests/nonregression/md5refs.txt index 4e2877d0..94c1a083 100644 --- a/tests/nonregression/md5refs.txt +++ b/tests/nonregression/md5refs.txt @@ -84,11 +84,45 @@ fdad26b1e078aa32bd4b77a5f44da43c orb-blue10-lin-jp2.jp2_2.pgx 7442756e83571c0e87493e03f12b2d34 orb-blue10-win-jp2.jp2_1.pgx 5f99ff2aeb17e167fe7049bcf339d0b3 orb-blue10-win-jp2.jp2_2.pgx fe028d56d6c7aaee87239a115093412a orb-blue10-win-jp2.jp2_3.pgx +344233bbe643ad651f82d4e8aaa3be54 p0_04_1.j2k.png +d105747d8fb755ef18b37ef83832f7d3 p0_04_2.j2k.png +89000c4cb8a83fcb4166624055905258 p0_04_3.j2k.png +af2a3ce7be9c8fb2db66ddbceff1dd53 p0_04_4.j2k.png +757340902e8dc6d5baa4f8f4628e2bc4 p0_04_5.j2k.png +4ec7002317a835f71630a7787cbff30a p0_04.j2k.png +4fecc6d5ebdc2db3bf3ef6bbbbb5b031 p1_04_10.j2k.png +ab969b1d17341d062a6f4d6966a1f221 p1_04_11.j2k.png +70fd9d6f155585258b13cb4b6c469e3f p1_04_12.j2k.png +38f9113129eed30445266dd67ac8ad7d p1_04_13.j2k.png +92945201639e6d8718dc474058f63e45 p1_04_14.j2k.png +bf7b8807d1617b8baa1cbd11af727061 p1_04_15.j2k.png +22afbf50bda7cd1ad562e6c0601c759a p1_04_16.j2k.png +d41f829c40140ec9972edf86681ee53a p1_04_17_t63.j2k.png +70fd9d6f155585258b13cb4b6c469e3f p1_04_17_t63_r2.j2k.png +80bde56ea4d1a5c2b81f3c4227ef754c p1_04_18.t12.j2k.png +5bb3e76ec9d742ec742959f3bb865018 p1_04_19_t12_r1.j2k.png +ef287e72806290a81f61e3d271bdb1dc p1_04_1.j2k.png +d41f829c40140ec9972edf86681ee53a p1_04_2.j2k.png +4dd2a41c60bcf71b8c410833b12706cf p1_04_3.j2k.png +75b9b427ddded86219e361206669482a p1_04_4.j2k.png +de2e66f82b9da9bc2dabda183a455b2f p1_04_5.j2k.png +d12b3c90d4b1cf78f0ad23eedcabe0ea p1_04_6.j2k.png +b3fccf3cbb7186841ba7b86e34cac0c2 p1_04.j2k.png +da21d175c4dcb03ce1f0a227f49ed7b8 p1_06_1.j2k.png +071597783b2141a12db1765b85943c1d p1_06_1.j2k_t5.png +5c434a489375fc9624bab49679cdec76 p1_06_2.j2k.png +6778de9e9236144747fe4542d03bf6e5 p1_06_2.j2k_t9.png +ce2de61ad83a71c9b13ca5df0a987a69 p1_06_3.j2k.png +18f9fbfb0d29e83f697fa93523c53a2b p1_06_4.j2k.png +66ede889502134412872b9d8b1e40887 p1_06_5.j2k.png +85a2b9a1324d72a8cec7041f80529242 p1_06.j2k.png +af083204299bbdd993286892b4c9cd29 p1_06.j2k_r4.png +af083204299bbdd993286892b4c9cd29 p1_06.j2k_t0.png 371aa0a7ff40a73b45f1fa41e210d1db pacs.ge.j2k_0.pgx 6ae110e1fb5a869af3dbc5fbc735b0bd relax.jp2_0.pgx 518a8f28dacc034982507f43763b88dd relax.jp2_1.pgx c678b04f4d3e59b9d66a8bce37c553c0 relax.jp2_2.pgx cdb1d69eb48ffd8545751326b86d9d7e test_lossless.j2k_0.pgx -a37e7e5811d7c0c7adb61582790ccd33 text_GBR.jp2_0.pgx -fc2173be54954a146b4e2887ee14be06 text_GBR.jp2_1.pgx -14108b4fb8d9126750db0424417ed17d text_GBR.jp2_2.pgx +efc9c7f21a542a7888a9eeb73b0f7092 text_GBR.jp2_0.pgx +54790b332b3dcbda28e1bcb31270b946 text_GBR.jp2_1.pgx +d9bcbdc818febb8c0a6bc5f940a4ea85 text_GBR.jp2_2.pgx From 1c209d711e277066d595db1ab2e817f6644ff815 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 16:20:36 +0000 Subject: [PATCH 140/333] [trunk] run test suite on dataset from issue 135. Add fake md5sum to make sure tests is failing. Update issue 135 --- tests/nonregression/md5refs.txt | 3 +++ tests/nonregression/test_suite.ctest.in | 2 ++ 2 files changed, 5 insertions(+) diff --git a/tests/nonregression/md5refs.txt b/tests/nonregression/md5refs.txt index 94c1a083..14e862c6 100644 --- a/tests/nonregression/md5refs.txt +++ b/tests/nonregression/md5refs.txt @@ -20,6 +20,9 @@ cb28787aa7c223f03e6acad71e244108 issue104_jpxstream.jp2_0.pgx c74edbb49e132b2cfc1eaf7908197b17 issue134.jp2_0.pgx 16fe8ed450da10a6aaae4cf6f467fc21 issue134.jp2_1.pgx c6091c07bf0ff221008dfb60d893cdff issue134.jp2_2.pgx +12a8a4668315d9ae27969991251ce853 issue135.j2k_0.pgx +56d0b0c547d6d5bb12f0c36e88722b13 issue135.j2k_1.pgx +48ba092fb40090c160bbd08bdf7bdbf3 issue135.j2k_2.pgx cb28787aa7c223f03e6acad71e244108 issue104_jpxstream.jp2_1.pgx 619694e5674992b3286244bf13058f7c issue142.j2k_0.pgx c675c4b77dc3cc2a0d6542a32b438a48 issue142.j2k_1.pgx diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 549fa910..97af701b 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -127,6 +127,8 @@ opj_decompress -i @INPUT_NR_PATH@/issue254.jp2 -o @TEMP_PATH@/i opj_decompress -i @INPUT_NR_PATH@/issue142.j2k -o @TEMP_PATH@/issue142.j2k.pgx # issue 134 opj_decompress -i @INPUT_NR_PATH@/issue134.jp2 -o @TEMP_PATH@/issue134.jp2.pgx +# issue 135 +opj_decompress -i @INPUT_NR_PATH@/issue135.j2k -o @TEMP_PATH@/issue135.j2k.pgx # issue 141 opj_compress -i @INPUT_NR_PATH@/issue141.rawl -o @TEMP_PATH@/issue141.rawl.j2k -F 2048,2816,1,16,u opj_compress -i @INPUT_NR_PATH@/issue141.rawl -o @TEMP_PATH@/issue141.rawl.j2k -F 2048,2816,1,16,u -I From abf2f7f05ec7f3fd66d433a1b7327cbf31de5832 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 16:31:27 +0000 Subject: [PATCH 141/333] [trunk] Run test suite on dataset from issue 211. Test is now passing nicely. Fixes issue 211 --- tests/nonregression/md5refs.txt | 2 ++ tests/nonregression/test_suite.ctest.in | 2 ++ 2 files changed, 4 insertions(+) diff --git a/tests/nonregression/md5refs.txt b/tests/nonregression/md5refs.txt index 14e862c6..44f6df5a 100644 --- a/tests/nonregression/md5refs.txt +++ b/tests/nonregression/md5refs.txt @@ -38,6 +38,8 @@ de992d54d59032eb07d21983dbe8155b issue205.jp2_3.pgx 8fae7a39e459409f64e4529d2214087a issue206_image-000.jp2_0.pgx 555a504a93c9a14f61c894da3b393e87 issue206_image-000.jp2_1.pgx 5f06b7c45446ae20c22cada46478a9dc issue206_image-000.jp2_2.pgx +a0823d21d9de699353a3bd1adb23bd1c issue211.jp2_0.pgx +1820161df26c360a62d11800d6cf173f issue211.jp2_1.pgx e1807db57b5f5192c4b77b83e8b5c477 issue228.j2k_0.pgx 611948e70370bf132839fc37109859c7 issue254.jp2_0.pgx 611948e70370bf132839fc37109859c7 issue254.jp2_1.pgx diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 97af701b..ffb302c4 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -129,6 +129,8 @@ opj_decompress -i @INPUT_NR_PATH@/issue142.j2k -o @TEMP_PATH@/i opj_decompress -i @INPUT_NR_PATH@/issue134.jp2 -o @TEMP_PATH@/issue134.jp2.pgx # issue 135 opj_decompress -i @INPUT_NR_PATH@/issue135.j2k -o @TEMP_PATH@/issue135.j2k.pgx +# issue 211 +opj_decompress -i @INPUT_NR_PATH@/issue211.jp2 -o @TEMP_PATH@/issue211.jp2.pgx # issue 141 opj_compress -i @INPUT_NR_PATH@/issue141.rawl -o @TEMP_PATH@/issue141.rawl.j2k -F 2048,2816,1,16,u opj_compress -i @INPUT_NR_PATH@/issue141.rawl -o @TEMP_PATH@/issue141.rawl.j2k -F 2048,2816,1,16,u -I From ac1dfd466205956a2c173e2dbe4b45eb124ed989 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 26 Feb 2014 17:13:46 +0000 Subject: [PATCH 142/333] [trunk] Import test case from issue 208. This appears to be fixed now. Fixes issue 208 --- tests/nonregression/md5refs.txt | 4 ++++ tests/nonregression/test_suite.ctest.in | 2 ++ 2 files changed, 6 insertions(+) diff --git a/tests/nonregression/md5refs.txt b/tests/nonregression/md5refs.txt index 44f6df5a..1bfadb4b 100644 --- a/tests/nonregression/md5refs.txt +++ b/tests/nonregression/md5refs.txt @@ -38,6 +38,10 @@ de992d54d59032eb07d21983dbe8155b issue205.jp2_3.pgx 8fae7a39e459409f64e4529d2214087a issue206_image-000.jp2_0.pgx 555a504a93c9a14f61c894da3b393e87 issue206_image-000.jp2_1.pgx 5f06b7c45446ae20c22cada46478a9dc issue206_image-000.jp2_2.pgx +b7073a2c1b5a42f9555eb0f0bd3c6510 issue208.jp2_0.pgx +df65beeb8fd056c8f7b8dfc699caa12b issue208.jp2_1.pgx +15cba2ad37c1a8e1eb3eb4bc42d5a2a2 issue208.jp2_2.pgx +301fabf4aac5729b44aab845580d5038 issue208.jp2_3.pgx a0823d21d9de699353a3bd1adb23bd1c issue211.jp2_0.pgx 1820161df26c360a62d11800d6cf173f issue211.jp2_1.pgx e1807db57b5f5192c4b77b83e8b5c477 issue228.j2k_0.pgx diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index ffb302c4..61177cad 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -129,6 +129,8 @@ opj_decompress -i @INPUT_NR_PATH@/issue142.j2k -o @TEMP_PATH@/i opj_decompress -i @INPUT_NR_PATH@/issue134.jp2 -o @TEMP_PATH@/issue134.jp2.pgx # issue 135 opj_decompress -i @INPUT_NR_PATH@/issue135.j2k -o @TEMP_PATH@/issue135.j2k.pgx +# issue 208 +opj_decompress -i @INPUT_NR_PATH@/issue208.jp2 -o @TEMP_PATH@/issue208.jp2.pgx # issue 211 opj_decompress -i @INPUT_NR_PATH@/issue211.jp2 -o @TEMP_PATH@/issue211.jp2.pgx # issue 141 From a7cc5b6a5d793746772a3bb2e9e12f5e08ad9bc3 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 27 Feb 2014 08:38:55 +0000 Subject: [PATCH 143/333] [trunk] simplify code using for loop --- tests/unit/CMakeLists.txt | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/tests/unit/CMakeLists.txt b/tests/unit/CMakeLists.txt index a22d00a1..ae47b88e 100644 --- a/tests/unit/CMakeLists.txt +++ b/tests/unit/CMakeLists.txt @@ -5,14 +5,13 @@ include_directories( ${OPENJPEG_SOURCE_DIR}/src/lib/openjp2 ) -add_executable(testempty0 testempty0.c) -add_executable(testempty1 testempty1.c) -add_executable(testempty2 testempty2.c) - -target_link_libraries(testempty0 openjp2) -target_link_libraries(testempty1 openjp2) -target_link_libraries(testempty2 openjp2) - -add_test(NAME testempty0 COMMAND testempty0) -add_test(NAME testempty1 COMMAND testempty1) -add_test(NAME testempty2 COMMAND testempty2) +set(unit_test + testempty0 + testempty1 + testempty2 +) +foreach(ut ${unit_test}) + add_executable(${ut} ${ut}.c) + target_link_libraries(${ut} openjp2) + add_test(NAME ${ut} COMMAND ${ut}) +endforeach() From 8a4095b40566634a17912e10f1cc041c96f0d162 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 27 Feb 2014 09:56:06 +0000 Subject: [PATCH 144/333] [trunk] add a sentinel in debug code --- src/lib/openjp2/j2k.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 11d66a18..924fdd60 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -6314,6 +6314,7 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, if (parameters->csty & J2K_CCP_CSTY_PRT) { OPJ_INT32 p = 0, it_res; + assert( tccp->numresolutions > 0 ); for (it_res = tccp->numresolutions - 1; it_res >= 0; it_res--) { if (p < parameters->res_spec) { From 7c120281c7659809a783d0b1bcfd844e634b77c8 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 27 Feb 2014 10:02:46 +0000 Subject: [PATCH 145/333] [trunk] improve command line parser syntax checking --- src/bin/jp2/opj_compress.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index 33efe757..5ed5228f 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -683,10 +683,17 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param int res_spec = 0; char *s = opj_optarg; + int ret; do { sep = 0; - sscanf(s, "[%d,%d]%c", ¶meters->prcw_init[res_spec], + ret = sscanf(s, "[%d,%d]%c", ¶meters->prcw_init[res_spec], ¶meters->prch_init[res_spec], &sep); + if( !(ret == 2 && sep == 0) && !(ret == 3 && sep == ',') ) + { + fprintf(stderr,"\nError: could not parse precinct dimension: '%s' %x\n", s, sep); + fprintf(stderr,"Example: -i lena.raw -o lena.j2k -c [128,128],[128,128]\n"); + return 1; + } parameters->csty |= 0x01; res_spec++; s = strpbrk(s, "]") + 2; From ad895fadb129c0633c16226113febdd8f2b58906 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 27 Feb 2014 10:03:11 +0000 Subject: [PATCH 146/333] [trunk] add issue 46 to the test suite Fixes issue 46 --- tests/nonregression/test_suite.ctest.in | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 61177cad..a3409e36 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -39,6 +39,11 @@ opj_compress -i @INPUT_NR_PATH@/X_4_2K_24_185_CBR_WB_000.tif -o @TEMP_PATH@/X_4_ opj_compress -i @INPUT_NR_PATH@/X_5_2K_24_235_CBR_STEM24_000.tif -o @TEMP_PATH@/X_5_2K_24_235_CBR_STEM24_000_C2K_48.j2k -cinema2K 48 opj_compress -i @INPUT_NR_PATH@/X_6_2K_24_FULL_CBR_CIRCLE_000.tif -o @TEMP_PATH@/X_6_2K_24_FULL_CBR_CIRCLE_000_C2K_48.j2k -cinema2K 48 opj_compress -i @INPUT_NR_PATH@/ElephantDream_4K.tif -o @TEMP_PATH@/ElephantDream_4K_C4K.j2k -cinema4K +# issue 141 +opj_compress -i @INPUT_NR_PATH@/issue141.rawl -o @TEMP_PATH@/issue141.rawl.j2k -F 2048,2816,1,16,u +opj_compress -i @INPUT_NR_PATH@/issue141.rawl -o @TEMP_PATH@/issue141.rawl.j2k -F 2048,2816,1,16,u -I +# issue 46: +opj_compress -i @INPUT_NR_PATH@/Bretagne2.ppm -o @TEMP_PATH@/Bretagne2_0.j2k -c [64,64] # DECODER TEST SUITE opj_decompress -i @INPUT_NR_PATH@/Bretagne2.j2k -o @TEMP_PATH@/Bretagne2.j2k.pgx @@ -133,9 +138,6 @@ opj_decompress -i @INPUT_NR_PATH@/issue135.j2k -o @TEMP_PATH@/i opj_decompress -i @INPUT_NR_PATH@/issue208.jp2 -o @TEMP_PATH@/issue208.jp2.pgx # issue 211 opj_decompress -i @INPUT_NR_PATH@/issue211.jp2 -o @TEMP_PATH@/issue211.jp2.pgx -# issue 141 -opj_compress -i @INPUT_NR_PATH@/issue141.rawl -o @TEMP_PATH@/issue141.rawl.j2k -F 2048,2816,1,16,u -opj_compress -i @INPUT_NR_PATH@/issue141.rawl -o @TEMP_PATH@/issue141.rawl.j2k -F 2048,2816,1,16,u -I # decode with specific area # prec=12; nb_c=1 From 6ae56f302e6786a54e9fc518413246dbd4f38ccd Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 27 Feb 2014 14:17:53 +0000 Subject: [PATCH 147/333] [trunk] Make sure that opj_decompress only output a single component Update issue 110 --- tests/nonregression/md5refs.txt | 5 ++--- tests/nonregression/test_suite.ctest.in | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/tests/nonregression/md5refs.txt b/tests/nonregression/md5refs.txt index 1bfadb4b..8dfb9126 100644 --- a/tests/nonregression/md5refs.txt +++ b/tests/nonregression/md5refs.txt @@ -16,18 +16,17 @@ b8f473c07ba5ebfc195bdd53c3b3b97f buxR.j2k_0.pgx 2813bd6fdc2c306b91b3da3688b8bf49 file409752.jp2_1.pgx e273e2aaea4a4fc1b2cf7c09c53c3cc6 file409752.jp2_2.pgx 05c062aca83d13b8095460f38a690a08 illegalcolortransform.j2k_0.pgx -cb28787aa7c223f03e6acad71e244108 issue104_jpxstream.jp2_0.pgx +cccccccccccccccccccccccccccccccc issue104_jpxstream.jp2_0.pgx c74edbb49e132b2cfc1eaf7908197b17 issue134.jp2_0.pgx 16fe8ed450da10a6aaae4cf6f467fc21 issue134.jp2_1.pgx c6091c07bf0ff221008dfb60d893cdff issue134.jp2_2.pgx 12a8a4668315d9ae27969991251ce853 issue135.j2k_0.pgx 56d0b0c547d6d5bb12f0c36e88722b13 issue135.j2k_1.pgx 48ba092fb40090c160bbd08bdf7bdbf3 issue135.j2k_2.pgx -cb28787aa7c223f03e6acad71e244108 issue104_jpxstream.jp2_1.pgx 619694e5674992b3286244bf13058f7c issue142.j2k_0.pgx c675c4b77dc3cc2a0d6542a32b438a48 issue142.j2k_1.pgx 663ebdd12dd6a36915ea1152c43cb69a issue142.j2k_2.pgx -cb28787aa7c223f03e6acad71e244108 issue104_jpxstream.jp2_2.pgx +cb28787aa7c223f03e6acad71e244108 issue110.jp2_0.pgx adda4f5e46845b96dd3df14a76aa7229 issue188_beach_64bitsbox.jp2_0.pgx 90a9709c166019d1e101e7b96d257ed9 issue188_beach_64bitsbox.jp2_1.pgx 37e23d2df06ee60bf0f9f5e1c16054d8 issue188_beach_64bitsbox.jp2_2.pgx diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index a3409e36..029df974 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -82,7 +82,7 @@ opj_decompress -i @INPUT_NR_PATH@/pacs.ge.j2k -o @TEMP_PATH@/pacs.ge.j2k.pgx # related to issue 135 opj_decompress -i @INPUT_NR_PATH@/kodak_2layers_lrcp.j2c -o @TEMP_PATH@/kodak_2layers_lrcp.j2c.pgx opj_decompress -i @INPUT_NR_PATH@/kodak_2layers_lrcp.j2c -o @TEMP_PATH@/kodak_2layers_lrcp.j2c.pgx -l 2 -# related to issue 104 which is closed +# related to issue 104 and 110 opj_decompress -i @INPUT_NR_PATH@/issue104_jpxstream.jp2 -o @TEMP_PATH@/issue104_jpxstream.jp2.pgx # File not supported by kakadu (Malformed PCLR box) and not supoprter by openjpeg (problem with value of TPSot) !opj_decompress -i @INPUT_NR_PATH@/mem-b2ace68c-1381.jp2 -o @TEMP_PATH@/mem-b2ace68c-1381.jp2.pgx From 094465a710925e56291f379fd9aaa7b592d2878a Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 27 Feb 2014 14:43:17 +0000 Subject: [PATCH 148/333] [trunk] run test suite to illustrate patch from r2458 --- tests/nonregression/test_suite.ctest.in | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 029df974..00d77b3d 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -119,6 +119,7 @@ opj_decompress -i @INPUT_NR_PATH@/issue205.jp2 -o @TEMP_PATH@/issue205.jp2.pgx !opj_decompress -i @INPUT_NR_PATH@/1802.pdf.SIGSEGV.36e.894.jp2 -o @TEMP_PATH@/1802.pdf.SIGSEGV.36e.894.jp2.pgx !opj_decompress -i @INPUT_NR_PATH@/451.pdf.SIGSEGV.f4c.3723.jp2 -o @TEMP_PATH@/451.pdf.SIGSEGV.f4c.3723.jp2.pgx !opj_decompress -i @INPUT_NR_PATH@/2.pdf.SIGFPE.706.1112.jp2 -o @TEMP_PATH@/2.pdf.SIGFPE.706.1112.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/147af3f1083de4393666b7d99b01b58b_signal_sigsegv_130c531_6155_5136.jp2 -o @INPUT_NR_PATH@/147af3f1083de4393666b7d99b01b58b_signal_sigsegv_130c531_6155_5136.jp2.pgx # issue 228 (16bits/lossy) opj_decompress -i @INPUT_NR_PATH@/issue228.j2k -o @TEMP_PATH@/issue228.j2k.pgx # issue 229 From 86cdc91180316e5e98b001788354855dc8472d7c Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 27 Feb 2014 15:00:54 +0000 Subject: [PATCH 149/333] [trunk] Try to run test suite on invalid dataset from sumatrapdf team Update issue 225 --- tests/nonregression/test_suite.ctest.in | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 00d77b3d..0f952ac3 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -119,7 +119,8 @@ opj_decompress -i @INPUT_NR_PATH@/issue205.jp2 -o @TEMP_PATH@/issue205.jp2.pgx !opj_decompress -i @INPUT_NR_PATH@/1802.pdf.SIGSEGV.36e.894.jp2 -o @TEMP_PATH@/1802.pdf.SIGSEGV.36e.894.jp2.pgx !opj_decompress -i @INPUT_NR_PATH@/451.pdf.SIGSEGV.f4c.3723.jp2 -o @TEMP_PATH@/451.pdf.SIGSEGV.f4c.3723.jp2.pgx !opj_decompress -i @INPUT_NR_PATH@/2.pdf.SIGFPE.706.1112.jp2 -o @TEMP_PATH@/2.pdf.SIGFPE.706.1112.jp2.pgx -!opj_decompress -i @INPUT_NR_PATH@/147af3f1083de4393666b7d99b01b58b_signal_sigsegv_130c531_6155_5136.jp2 -o @INPUT_NR_PATH@/147af3f1083de4393666b7d99b01b58b_signal_sigsegv_130c531_6155_5136.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/147af3f1083de4393666b7d99b01b58b_signal_sigsegv_130c531_6155_5136.jp2 -o @TEMP_PATH@/147af3f1083de4393666b7d99b01b58b_signal_sigsegv_130c531_6155_5136.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/4241ac039aba57e6a9c948d519d94216_asan_heap-oob_14650f2_7469_602.jp2 -o @TEMP_PATH@/4241ac039aba57e6a9c948d519d94216_asan_heap-oob_14650f2_7469_602.jp2 # issue 228 (16bits/lossy) opj_decompress -i @INPUT_NR_PATH@/issue228.j2k -o @TEMP_PATH@/issue228.j2k.pgx # issue 229 From 6a6fa7027a1d1aac466bfb09fd3b431dc30f1c1f Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 27 Feb 2014 17:04:06 +0000 Subject: [PATCH 150/333] [trunk] Import patch from issue 171. Only the imagetoraw part was not applied. Update issue 171 --- src/bin/jp2/convert.c | 313 +++++++++++++++++++++++++++++------------- 1 file changed, 215 insertions(+), 98 deletions(-) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index 0b1291de..a4b52040 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -406,7 +406,7 @@ opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters) { int imagetotga(opj_image_t * image, const char *outfile) { int width, height, bpp, x, y; OPJ_BOOL write_alpha; - int i, adjustR, adjustG, adjustB; + int i, v, adjustR, adjustG, adjustB, fails; unsigned int alpha_channel; float r,g,b,a; unsigned char value; @@ -437,8 +437,9 @@ int imagetotga(opj_image_t * image, const char *outfile) { /* Write TGA header */ bpp = write_alpha ? 32 : 24; + if (!tga_writeheader(fdest, bpp, width , height, OPJ_TRUE)) - return 1; + goto fin; alpha_channel = image->numcomps-1; @@ -448,56 +449,74 @@ int imagetotga(opj_image_t * image, const char *outfile) { adjustG = (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); adjustB = (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); - for (y=0; y < height; y++) { - unsigned int index=y*width; + for (y=0; y < height; y++) + { + unsigned int index=y*width; - for (x=0; x < width; x++, index++) { - r = (float)(image->comps[0].data[index] + adjustR); + for (x=0; x < width; x++, index++) + { + r = (float)(image->comps[0].data[index] + adjustR); - if (image->numcomps>2) { - g = (float)(image->comps[1].data[index] + adjustG); - b = (float)(image->comps[2].data[index] + adjustB); - } - else {/* Greyscale ... */ - g = r; - b = r; - } + if (image->numcomps > 2) + { + g = (float)(image->comps[1].data[index] + adjustG); + b = (float)(image->comps[2].data[index] + adjustB); + } + else + {/* Greyscale ... */ + g = r; + b = r; + } - /* TGA format writes BGR ... */ - value = (unsigned char)(b*scale); - res = fwrite(&value,1,1,fdest); - if( res < 1 ) { - fprintf(stderr, "failed to write 1 byte for %s\n", outfile); - return 1; - } +/* TGA format writes BGR ... */ + if(b > 255.) b = 255.; else if(b < 0.) b = 0.; + value = (unsigned char)(b*scale); + res = fwrite(&value,1,1,fdest); - value = (unsigned char)(g*scale); - res = fwrite(&value,1,1,fdest); - if( res < 1 ) { - fprintf(stderr, "failed to write 1 byte for %s\n", outfile); - return 1; - } + if( res < 1 ) + { + fprintf(stderr, "failed to write 1 byte for %s\n", outfile); + goto fin; + } + if(g > 255.) g = 255.; else if(g < 0.) g = 0.; + value = (unsigned char)(g*scale); + res = fwrite(&value,1,1,fdest); - value = (unsigned char)(r*scale); - res = fwrite(&value,1,1,fdest); - if( res < 1 ) { - fprintf(stderr, "failed to write 1 byte for %s\n", outfile); - return 1; - } + if( res < 1 ) + { + fprintf(stderr, "failed to write 1 byte for %s\n", outfile); + goto fin; + } + if(r > 255.) r = 255.; else if(r < 0.) r = 0.; + value = (unsigned char)(r*scale); + res = fwrite(&value,1,1,fdest); - if (write_alpha) { - a = (float)(image->comps[alpha_channel].data[index]); - value = (unsigned char)(a*scale); - res = fwrite(&value,1,1,fdest); - if( res < 1 ) { - fprintf(stderr, "failed to write 1 byte for %s\n", outfile); - return 1; - } - } - } - } + if( res < 1 ) + { + fprintf(stderr, "failed to write 1 byte for %s\n", outfile); + goto fin; + } - return 0; + if (write_alpha) + { + a = (float)(image->comps[alpha_channel].data[index]); + if(a > 255.) a = 255.; else if(a < 0.) a = 0.; + value = (unsigned char)(a*scale); + res = fwrite(&value,1,1,fdest); + + if( res < 1 ) + { + fprintf(stderr, "failed to write 1 byte for %s\n", outfile); + goto fin; + } + } + } + } + fails = 0; +fin: + fclose(fdest); + + return fails; } /* -->> -->> -->> -->> @@ -1397,70 +1416,90 @@ opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters) { return image; } -int imagetopgx(opj_image_t * image, const char *outfile) { +int imagetopgx(opj_image_t * image, const char *outfile) +{ int w, h; - int i, j, compno; + int i, j, compno, fails; FILE *fdest = NULL; - for (compno = 0; compno < image->numcomps; compno++) { - opj_image_comp_t *comp = &image->comps[compno]; - char bname[256]; /* buffer for name */ + for (compno = 0; compno < image->numcomps; compno++) + { + opj_image_comp_t *comp = &image->comps[compno]; + char bname[256]; /* buffer for name */ char *name = bname; /* pointer */ int nbytes = 0; size_t res; const size_t olen = strlen(outfile); const size_t dotpos = olen - 4; const size_t total = dotpos + 1 + 1 + 4; /* '-' + '[1-3]' + '.pgx' */ - if( outfile[dotpos] != '.' ) { - /* `pgx` was recognized but there is no dot at expected position */ + + if( outfile[dotpos] != '.' ) + { +/* `pgx` was recognized but there is no dot at expected position */ fprintf(stderr, "ERROR -> Impossible happen." ); return 1; - } - if( total > 256 ) { - name = (char*)malloc(total+1); - } + } + if( total > 256 ) + { + name = (char*)malloc(total+1); + } strncpy(name, outfile, dotpos); /*if (image->numcomps > 1) {*/ sprintf(name+dotpos, "_%d.pgx", compno); /*} else { strcpy(name+dotpos, ".pgx"); }*/ - fdest = fopen(name, "wb"); - if (!fdest) { - fprintf(stderr, "ERROR -> failed to open %s for writing\n", name); - return 1; - } - /* dont need name anymore */ - if( total > 256 ) { + fdest = fopen(name, "wb"); + if (!fdest) + { + fprintf(stderr, "ERROR -> failed to open %s for writing\n", name); + return 1; + } +/* dont need name anymore */ + if( total > 256 ) free(name); - } + + fails = 1; + w = image->comps[compno].w; + h = image->comps[compno].h; - w = image->comps[compno].w; - h = image->comps[compno].h; + fprintf(fdest, "PG ML %c %d %d %d\n", comp->sgnd ? '-' : '+', + comp->prec, w, h); - fprintf(fdest, "PG ML %c %d %d %d\n", comp->sgnd ? '-' : '+', comp->prec, w, h); - if (comp->prec <= 8) { - nbytes = 1; - } else if (comp->prec <= 16) { - nbytes = 2; - } else { - nbytes = 4; - } - for (i = 0; i < w * h; i++) { - int v = image->comps[compno].data[i]; - for (j = nbytes - 1; j >= 0; j--) { - char byte = (char) (v >> (j * 8)); - res = fwrite(&byte, 1, 1, fdest); - if( res < 1 ) { - fprintf(stderr, "failed to write 1 byte for %s\n", name); - return 1; - } - } - } - fclose(fdest); - } + if (comp->prec <= 8) + nbytes = 1; + else + if (comp->prec <= 16) + nbytes = 2; + else + nbytes = 4; - return 0; + for (i = 0; i < w * h; i++) + { + int v, val = image->comps[compno].data[i]; + unsigned char byte; + + for (j = nbytes - 1; j >= 0; j--) + { + v = (int)(val >> (j * 8)); + if(v > 255) v = 255; else if(v < 0) v = 0; + byte = (unsigned char)v; + res = fwrite(&byte, 1, 1, fdest); + + if( res < 1 ) + { + fprintf(stderr, "failed to write 1 byte for %s\n", name); + goto fin; + } + } + } + fclose(fdest); fdest = NULL; + } + fails = 0; +fin: + if(fdest) fclose(fdest); + + return fails; } /* -->> -->> -->> -->> @@ -1893,7 +1932,9 @@ int imagetopnm(opj_image_t * image, const char *outfile) FILE *fdest = NULL; const char *tmp = outfile; char *destname; - alpha = NULL; + + alpha = NULL; + if((prec = image->comps[0].prec) > 16) { fprintf(stderr,"%s:%d:imagetopnm\n\tprecision %d is larger than 16" @@ -1971,16 +2012,22 @@ int imagetopnm(opj_image_t * image, const char *outfile) if(two) { v = *red + adjustR; ++red; +if(v > 65535) v = 65535; else if(v < 0) v = 0; + /* netpbm: */ fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v); if(triple) { v = *green + adjustG; ++green; +if(v > 65535) v = 65535; else if(v < 0) v = 0; + /* netpbm: */ fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v); v = *blue + adjustB; ++blue; +if(v > 65535) v = 65535; else if(v < 0) v = 0; + /* netpbm: */ fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v); @@ -1989,6 +2036,8 @@ int imagetopnm(opj_image_t * image, const char *outfile) if(has_alpha) { v = *alpha + adjustA; ++alpha; + if(v > 65535) v = 65535; else if(v < 0) v = 0; + /* netpbm: */ fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v); } @@ -1997,14 +2046,28 @@ int imagetopnm(opj_image_t * image, const char *outfile) } /* if(two) */ /* prec <= 8: */ + v = *red++; + if(v > 255) v = 255; else if(v < 0) v = 0; - fprintf(fdest, "%c", (unsigned char)*red++); + fprintf(fdest, "%c", (unsigned char)v); if(triple) - fprintf(fdest, "%c%c",(unsigned char)*green++, (unsigned char)*blue++); + { + v = *green++; + if(v > 255) v = 255; else if(v < 0) v = 0; + fprintf(fdest, "%c", (unsigned char)v); + v = *blue++; + if(v > 255) v = 255; else if(v < 0) v = 0; + + fprintf(fdest, "%c", (unsigned char)v); + } if(has_alpha) - fprintf(fdest, "%c", (unsigned char)*alpha++); + { + v = *alpha++; + if(v > 255) v = 255; else if(v < 0) v = 0; + fprintf(fdest, "%c", (unsigned char)v); + } } /* for(i */ fclose(fdest); return 0; @@ -2049,12 +2112,16 @@ int imagetopnm(opj_image_t * image, const char *outfile) for (i = 0; i < wr * hr; i++) { v = *red + adjustR; ++red; +if(v > 65535) v = 65535; else if(v < 0) v = 0; + /* netpbm: */ fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v); if(has_alpha) { v = *alpha++; +if(v > 65535) v = 65535; else if(v < 0) v = 0; + /* netpbm: */ fprintf(fdest, "%c%c",(unsigned char)(v>>8), (unsigned char)v); } @@ -2064,7 +2131,10 @@ int imagetopnm(opj_image_t * image, const char *outfile) { for(i = 0; i < wr * hr; ++i) { - fprintf(fdest, "%c", (unsigned char)(*red + adjustR)); ++red; + v = *red + adjustR; ++red; + if(v > 255) v = 255; else if(v < 0) v = 0; + + fprintf(fdest, "%c", (unsigned char)v); } } fclose(fdest); @@ -2174,10 +2244,17 @@ int imagetotif(opj_image_t * image, const char *outfile) b += adjust; if(has_alpha) a += adjust; } + if(r > 255) r = 255; else if(r < 0) r = 0; dat8[i+0] = r ; + if(g > 255) g = 255; else if(g < 0) g = 0; dat8[i+1] = g ; + if(b > 255) b = 255; else if(b < 0) b = 0; dat8[i+2] = b ; - if(has_alpha) dat8[i+3] = a; + if(has_alpha) + { + if(a > 255) a = 255; else if(a < 0) a = 0; + dat8[i+3] = a; + } index++; last_i = i + step; @@ -2206,11 +2283,17 @@ int imagetotif(opj_image_t * image, const char *outfile) b += adjust; if(has_alpha) a += adjust; } + if(r > 255) r = 255; else if(r < 0) r = 0; + if(g > 255) g = 255; else if(g < 0) g = 0; + if(b > 255) b = 255; else if(b < 0) b = 0; + dat8[i+0] = r ; if(i+1 < ssize) dat8[i+1] = g ; else break; if(i+2 < ssize) dat8[i+2] = b ; else break; if(has_alpha) { + if(a > 255) a = 255; else if(a < 0) a = 0; + if(i+3 < ssize) dat8[i+3] = a ; else break; } index++; @@ -2252,6 +2335,10 @@ int imagetotif(opj_image_t * image, const char *outfile) b = (b<>dshift); if(has_alpha) a = (a<>dshift); } + if(r > 65535) r = 65535; else if(r < 0) r = 0; + if(g > 65535) g = 65535; else if(g < 0) g = 0; + if(b > 65535) b = 65535; else if(b < 0) b = 0; + dat8[i+0] = r;/*LSB*/ dat8[i+1] = (r >> 8);/*MSB*/ dat8[i+2] = g; @@ -2260,6 +2347,7 @@ int imagetotif(opj_image_t * image, const char *outfile) dat8[i+5] = (b >> 8); if(has_alpha) { + if(a > 65535) a = 65535; else if(a < 0) a = 0; dat8[i+6] = a; dat8[i+7] = (a >> 8); } @@ -2297,6 +2385,10 @@ int imagetotif(opj_image_t * image, const char *outfile) b = (b<>dshift); if(has_alpha) a = (a<>dshift); } + if(r > 65535) r = 65535; else if(r < 0) r = 0; + if(g > 65535) g = 65535; else if(g < 0) g = 0; + if(b > 65535) b = 65535; else if(b < 0) b = 0; + dat8[i+0] = r;/*LSB*/ if(i+1 < ssize) dat8[i+1] = (r >> 8);else break;/*MSB*/ if(i+2 < ssize) dat8[i+2] = g; else break; @@ -2306,6 +2398,7 @@ int imagetotif(opj_image_t * image, const char *outfile) if(has_alpha) { + if(a > 65535) a = 65535; else if(a < 0) a = 0; if(i+6 < ssize) dat8[i+6] = a; else break; if(i+7 < ssize) dat8[i+7] = (a >> 8); else break; } @@ -2379,13 +2472,19 @@ int imagetotif(opj_image_t * image, const char *outfile) r += adjust; if(has_alpha) a += adjust; } + if(r > 255) r = 255; else if(r < 0) r = 0; dat8[i+0] = r; - if(has_alpha) dat8[i+1] = a; - index++; + + if(has_alpha) + { + if(a > 255) a = 255; else if(a < 0) a = 0; + dat8[i+1] = a; } + index++; + } else break; - }/*for(i )*/ + }/*for(i )*/ }/*if(bps == 8*/ else if(bps == 16) @@ -2411,10 +2510,12 @@ int imagetotif(opj_image_t * image, const char *outfile) r = (r<>dshift); if(has_alpha) a = (a<>dshift); } + if(r > 65535) r = 65535; else if(r < 0) r = 0; dat8[i+0] = r;/*LSB*/ dat8[i+1] = r >> 8;/*MSB*/ if(has_alpha) { + if(a > 65535) a = 65535; else if(a < 0) a = 0; dat8[i+2] = a; dat8[i+3] = a >> 8; } @@ -2490,7 +2591,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) if( !tiBps || !tiPhoto) { if( !tiBps) - fprintf(stderr,"imagetotif: Bits=%d, Only 8 and 16 bits" + fprintf(stderr,"tiftoimage: Bits=%d, Only 8 and 16 bits" " implemented\n",tiBps); else if( !tiPhoto) @@ -3427,6 +3528,10 @@ int imagetopng(opj_image_t * image, const char *write_idf) { png_set_packing(png); } +printf("%s:%d:sgnd(%d,%d,%d) w(%d) h(%d) alpha(%d)\n",__FILE__,__LINE__, +image->comps[0].sgnd, +image->comps[1].sgnd,image->comps[2].sgnd,width,height,has_alpha); + adjustR = (image->comps[0].sgnd ? 1 << (image->comps[0].prec - 1) : 0); adjustG = (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); adjustB = (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); @@ -3442,18 +3547,21 @@ int imagetopng(opj_image_t * image, const char *write_idf) if(is16) { v = *red + adjustR; ++red; + if(v > 65535) v = 65535; else if(v < 0) v = 0; if(force16) { v = (v<>dshift); } *d++ = (unsigned char)(v>>8); *d++ = (unsigned char)v; v = *green + adjustG; ++green; + if(v > 65535) v = 65535; else if(v < 0) v = 0; if(force16) { v = (v<>dshift); } *d++ = (unsigned char)(v>>8); *d++ = (unsigned char)v; v = *blue + adjustB; ++blue; + if(v > 65535) v = 65535; else if(v < 0) v = 0; if(force16) { v = (v<>dshift); } @@ -3462,6 +3570,7 @@ int imagetopng(opj_image_t * image, const char *write_idf) if(has_alpha) { v = *alpha + adjustA; ++alpha; + if(v > 65535) v = 65535; else if(v < 0) v = 0; if(force16) { v = (v<>dshift); } @@ -3471,18 +3580,21 @@ int imagetopng(opj_image_t * image, const char *write_idf) }/* if(is16) */ v = *red + adjustR; ++red; + if(v > 255) v = 255; else if(v < 0) v = 0; if(force8) { v = (v<>dshift); } *d++ = (unsigned char)(v & mask); v = *green + adjustG; ++green; + if(v > 255) v = 255; else if(v < 0) v = 0; if(force8) { v = (v<>dshift); } *d++ = (unsigned char)(v & mask); v = *blue + adjustB; ++blue; + if(v > 255) v = 255; else if(v < 0) v = 0; if(force8) { v = (v<>dshift); } @@ -3491,6 +3603,7 @@ int imagetopng(opj_image_t * image, const char *write_idf) if(has_alpha) { v = *alpha + adjustA; ++alpha; + if(v > 255) v = 255; else if(v < 0) v = 0; if(force8) { v = (v<>dshift); } @@ -3561,6 +3674,7 @@ int imagetopng(opj_image_t * image, const char *write_idf) for(x = 0; x < width; ++x) { v = *red + adjustR; ++red; + if(v > 65535) v = 65535; else if(v < 0) v = 0; if(force16) { v = (v<>dshift); } @@ -3569,6 +3683,7 @@ int imagetopng(opj_image_t * image, const char *write_idf) if(has_alpha) { v = *alpha++; + if(v > 65535) v = 65535; else if(v < 0) v = 0; if(force16) { v = (v<>dshift); } @@ -3591,6 +3706,7 @@ int imagetopng(opj_image_t * image, const char *write_idf) for(x = 0; x < width; ++x) { v = *red + adjustR; ++red; + if(v > 255) v = 255; else if(v < 0) v = 0; if(force8) { v = (v<>dshift); } @@ -3599,6 +3715,7 @@ int imagetopng(opj_image_t * image, const char *write_idf) if(has_alpha) { v = *alpha + adjustA; ++alpha; + if(v > 255) v = 255; else if(v < 0) v = 0; if(force8) { v = (v<>dshift); } From a3472624683709544fa98c33ed8a3137b4436959 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 27 Feb 2014 17:21:00 +0000 Subject: [PATCH 151/333] [trunk] Import patch from issue 218. No dataset to check, so blindly applied it. Fixes issue 218 --- src/lib/openjp2/jp2.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c index 544ce91b..d59ec434 100644 --- a/src/lib/openjp2/jp2.c +++ b/src/lib/openjp2/jp2.c @@ -823,6 +823,7 @@ static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color, return OPJ_TRUE; } +// file9.jp2 void opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color) { opj_image_comp_t *old_comps, *new_comps; @@ -1076,7 +1077,8 @@ void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color) for(i = 0; i < n; ++i) { /* WATCH: acn = asoc - 1 ! */ - if((asoc = info[i].asoc) == 0) + asoc = info[i].asoc; + if(asoc == 0 || asoc == 65535) { if (i < image->numcomps) image->comps[i].alpha = info[i].typ; @@ -1085,6 +1087,11 @@ void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color) cn = info[i].cn; acn = asoc - 1; + if( cn >= image->numcomps || acn >= image->numcomps ) + { + fprintf(stderr, "cn=%d, acn=%d, numcomps=%d\n", cn, acn, image->numcomps); + continue; + } if(cn != acn) { From 65503dad73ca98890aaf5c08432ace46265dddf3 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 28 Feb 2014 08:28:25 +0000 Subject: [PATCH 152/333] [trunk] Fix find_path behavior within cross-compilation execution --- CMakeLists.txt | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 72f985f6..7d0abd01 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -281,9 +281,8 @@ if(BUILD_TESTING) # They could be found via svn on the OpenJPEG google code project # svn checkout http://openjpeg.googlecode.com/svn/data (about 70 Mo) find_path(OPJ_DATA_ROOT README-OPJ-Data - PATHS - $ENV{OPJ_DATA_ROOT} - ${CMAKE_SOURCE_DIR}/../data + PATHS $ENV{OPJ_DATA_ROOT} ${CMAKE_SOURCE_DIR}/../data + NO_DEFAULT_PATH NO_CMAKE_FIND_ROOT_PATH ) # Add repository where to find tests From 7a89d731f75f420d1ddc8be004fcf71145286245 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 28 Feb 2014 09:52:35 +0000 Subject: [PATCH 153/333] [trunk] Merge final patch from issue 171 with code simplification. also handles signed case properly. Fixes issue 171 --- src/bin/jp2/convert.c | 102 ++++++++++++++++-------------------------- 1 file changed, 39 insertions(+), 63 deletions(-) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index a4b52040..f59ec7f9 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -3036,9 +3036,10 @@ static int imagetoraw_common(opj_image_t * image, const char *outfile, OPJ_BOOL FILE *rawFile = NULL; size_t res; int compno; - int w, h; - int line, row; + int w, h, fails; + int line, row, curr, mask; int *ptr; + unsigned char uc; if((image->numcomps * image->x1 * image->y1) == 0) { @@ -3052,6 +3053,7 @@ static int imagetoraw_common(opj_image_t * image, const char *outfile, OPJ_BOOL return 1; } + fails = 1; fprintf(stdout,"Raw image characteristics: %d components\n", image->numcomps); for(compno = 0; compno < image->numcomps; compno++) @@ -3066,16 +3068,17 @@ static int imagetoraw_common(opj_image_t * image, const char *outfile, OPJ_BOOL { if(image->comps[compno].sgnd == 1) { - signed char curr; - int mask = (1 << image->comps[compno].prec) - 1; + mask = (1 << image->comps[compno].prec) - 1; ptr = image->comps[compno].data; for (line = 0; line < h; line++) { for(row = 0; row < w; row++) { - curr = (signed char) (*ptr & mask); - res = fwrite(&curr, sizeof(signed char), 1, rawFile); + curr = *ptr; + if(curr > 127) curr = 127; else if(curr < -128) curr = -128; + uc = (unsigned char) (curr & mask); + res = fwrite(&uc, 1, 1, rawFile); if( res < 1 ) { fprintf(stderr, "failed to write 1 byte for %s\n", outfile); - return 1; + goto fin; } ptr++; } @@ -3083,16 +3086,17 @@ static int imagetoraw_common(opj_image_t * image, const char *outfile, OPJ_BOOL } else if(image->comps[compno].sgnd == 0) { - unsigned char curr; - int mask = (1 << image->comps[compno].prec) - 1; + mask = (1 << image->comps[compno].prec) - 1; ptr = image->comps[compno].data; for (line = 0; line < h; line++) { for(row = 0; row < w; row++) { - curr = (unsigned char) (*ptr & mask); - res = fwrite(&curr, sizeof(unsigned char), 1, rawFile); + curr = *ptr; + if(curr > 255) curr = 255; else if(curr < 0) curr = 0; + uc = (unsigned char) (curr & mask); + res = fwrite(&uc, 1, 1, rawFile); if( res < 1 ) { fprintf(stderr, "failed to write 1 byte for %s\n", outfile); - return 1; + goto fin; } ptr++; } @@ -3103,33 +3107,18 @@ static int imagetoraw_common(opj_image_t * image, const char *outfile, OPJ_BOOL { if(image->comps[compno].sgnd == 1) { - signed short int curr; - int mask = (1 << image->comps[compno].prec) - 1; + union { signed short val; signed char vals[2] } uc; + mask = (1 << image->comps[compno].prec) - 1; ptr = image->comps[compno].data; for (line = 0; line < h; line++) { for(row = 0; row < w; row++) { - unsigned char temp1; - unsigned char temp2; - curr = (signed short int) (*ptr & mask); - if( big_endian ) - { - temp1 = (unsigned char) (curr >> 8); - temp2 = (unsigned char) curr; - } - else - { - temp2 = (unsigned char) (curr >> 8); - temp1 = (unsigned char) curr; - } - res = fwrite(&temp1, 1, 1, rawFile); - if( res < 1 ) { - fprintf(stderr, "failed to write 1 byte for %s\n", outfile); - return 1; - } - res = fwrite(&temp2, 1, 1, rawFile); - if( res < 1 ) { - fprintf(stderr, "failed to write 1 byte for %s\n", outfile); - return 1; + curr = *ptr; + if(curr > 32767 ) curr = 32767; else if( curr < -32768) curr = -32768; + uc.val = (signed short)(curr & mask); + res = fwrite(uc.vals, 1, 2, rawFile); + if( res < 2 ) { + fprintf(stderr, "failed to write 2 byte for %s\n", outfile); + goto fin; } ptr++; } @@ -3137,33 +3126,18 @@ static int imagetoraw_common(opj_image_t * image, const char *outfile, OPJ_BOOL } else if(image->comps[compno].sgnd == 0) { - unsigned short int curr; - int mask = (1 << image->comps[compno].prec) - 1; + union { unsigned short val; unsigned char vals[2] } uc; + mask = (1 << image->comps[compno].prec) - 1; ptr = image->comps[compno].data; for (line = 0; line < h; line++) { for(row = 0; row < w; row++) { - unsigned char temp1; - unsigned char temp2; - curr = (unsigned short int) (*ptr & mask); - if( big_endian ) - { - temp1 = (unsigned char) (curr >> 8); - temp2 = (unsigned char) curr; - } - else - { - temp2 = (unsigned char) (curr >> 8); - temp1 = (unsigned char) curr; - } - res = fwrite(&temp1, 1, 1, rawFile); - if( res < 1 ) { - fprintf(stderr, "failed to write 1 byte for %s\n", outfile); - return 1; - } - res = fwrite(&temp2, 1, 1, rawFile); - if( res < 1 ) { - fprintf(stderr, "failed to write 1 byte for %s\n", outfile); - return 1; + curr = *ptr; + if(curr > 65536 ) curr = 65536; else if( curr < 0) curr = 0; + uc.val = (unsigned short)(curr & mask); + res = fwrite(uc.vals, 1, 2, rawFile); + if( res < 2 ) { + fprintf(stderr, "failed to write 2 byte for %s\n", outfile); + goto fin; } ptr++; } @@ -3173,16 +3147,18 @@ static int imagetoraw_common(opj_image_t * image, const char *outfile, OPJ_BOOL else if (image->comps[compno].prec <= 32) { fprintf(stderr,"More than 16 bits per component no handled yet\n"); - return 1; + goto fin; } else { fprintf(stderr,"Error: invalid precision: %d\n", image->comps[compno].prec); - return 1; + goto fin; } } + fails = 0; +fin: fclose(rawFile); - return 0; + return fails; } int imagetoraw(opj_image_t * image, const char *outfile) From 1eb67ca49d9ea8434aa4876d256929b7fe02b393 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 28 Feb 2014 12:06:57 +0000 Subject: [PATCH 154/333] [trunk] Remove some simple warnings in opj_dump --- src/bin/jp2/opj_dump.c | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/src/bin/jp2/opj_dump.c b/src/bin/jp2/opj_dump.c index 23913899..19ed2971 100644 --- a/src/bin/jp2/opj_dump.c +++ b/src/bin/jp2/opj_dump.c @@ -75,14 +75,13 @@ typedef struct img_folder{ /* -------------------------------------------------------------------------- */ /* Declarations */ -int get_num_images(char *imgdirpath); -int load_images(dircnt_t *dirptr, char *imgdirpath); -int get_file_format(const char *filename); -char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters); +static int get_num_images(char *imgdirpath); +static int load_images(dircnt_t *dirptr, char *imgdirpath); +static int get_file_format(const char *filename); +static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters); static int infile_format(const char *fname); -int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol); -int parse_DA_values( char* inArg, unsigned int *DA_x0, unsigned int *DA_y0, unsigned int *DA_x1, unsigned int *DA_y1); +static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol); /* -------------------------------------------------------------------------- */ static void decode_help_display(void) { @@ -116,7 +115,7 @@ static void decode_help_display(void) { } /* -------------------------------------------------------------------------- */ -int get_num_images(char *imgdirpath){ +static int get_num_images(char *imgdirpath){ DIR *dir; struct dirent* content; int num_images = 0; @@ -138,7 +137,7 @@ int get_num_images(char *imgdirpath){ } /* -------------------------------------------------------------------------- */ -int load_images(dircnt_t *dirptr, char *imgdirpath){ +static int load_images(dircnt_t *dirptr, char *imgdirpath){ DIR *dir; struct dirent* content; int i = 0; @@ -164,7 +163,7 @@ int load_images(dircnt_t *dirptr, char *imgdirpath){ } /* -------------------------------------------------------------------------- */ -int get_file_format(const char *filename) { +static int get_file_format(const char *filename) { unsigned int i; static const char *extension[] = {"pgx", "pnm", "pgm", "ppm", "bmp","tif", "raw", "tga", "png", "j2k", "jp2", "jpt", "j2c", "jpc" }; static const int format[] = { PGX_DFMT, PXM_DFMT, PXM_DFMT, PXM_DFMT, BMP_DFMT, TIF_DFMT, RAW_DFMT, TGA_DFMT, PNG_DFMT, J2K_CFMT, JP2_CFMT, JPT_CFMT, J2K_CFMT, J2K_CFMT }; @@ -184,7 +183,7 @@ int get_file_format(const char *filename) { } /* -------------------------------------------------------------------------- */ -char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters){ +static char get_next_file(int imageno,dircnt_t *dirptr,img_fol_t *img_fol, opj_dparameters_t *parameters){ char image_filename[OPJ_PATH_LEN], infilename[OPJ_PATH_LEN],outfilename[OPJ_PATH_LEN],temp_ofname[OPJ_PATH_LEN]; char *temp_p, temp1[OPJ_PATH_LEN]=""; @@ -221,7 +220,7 @@ static int infile_format(const char *fname) const char *s, *magic_s; int ext_format, magic_format; unsigned char buf[12]; - unsigned int l_nb_read; + size_t l_nb_read; reader = fopen(fname, "rb"); @@ -269,7 +268,7 @@ static int infile_format(const char *fname) * Parse the command line */ /* -------------------------------------------------------------------------- */ -int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol) { +static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,img_fol_t *img_fol) { int totlen, c; opj_option_t long_option[]={ {"ImgDir",REQ_ARG, NULL ,'y'}, From cbe77e24127b4df123c85f365ea0de4490de9835 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 28 Feb 2014 12:30:11 +0000 Subject: [PATCH 155/333] [trunk] run test suite on dataset from issue 171 Fixes issue 171 --- tests/nonregression/md5refs.txt | 3 +++ tests/nonregression/test_suite.ctest.in | 2 ++ 2 files changed, 5 insertions(+) diff --git a/tests/nonregression/md5refs.txt b/tests/nonregression/md5refs.txt index 8dfb9126..d967192e 100644 --- a/tests/nonregression/md5refs.txt +++ b/tests/nonregression/md5refs.txt @@ -27,6 +27,9 @@ c6091c07bf0ff221008dfb60d893cdff issue134.jp2_2.pgx c675c4b77dc3cc2a0d6542a32b438a48 issue142.j2k_1.pgx 663ebdd12dd6a36915ea1152c43cb69a issue142.j2k_2.pgx cb28787aa7c223f03e6acad71e244108 issue110.jp2_0.pgx +820b37ef934bd17d45dd73f5dc4d95b7 issue171.jp2_0.pgx +4596dcd3efa51f84824b60353e2af306 issue171.jp2_1.pgx +c2a656096b1965c3b4a26563d6ade467 issue171.jp2_2.pgx adda4f5e46845b96dd3df14a76aa7229 issue188_beach_64bitsbox.jp2_0.pgx 90a9709c166019d1e101e7b96d257ed9 issue188_beach_64bitsbox.jp2_1.pgx 37e23d2df06ee60bf0f9f5e1c16054d8 issue188_beach_64bitsbox.jp2_2.pgx diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 0f952ac3..1c57aece 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -140,6 +140,8 @@ opj_decompress -i @INPUT_NR_PATH@/issue135.j2k -o @TEMP_PATH@/i opj_decompress -i @INPUT_NR_PATH@/issue208.jp2 -o @TEMP_PATH@/issue208.jp2.pgx # issue 211 opj_decompress -i @INPUT_NR_PATH@/issue211.jp2 -o @TEMP_PATH@/issue211.jp2.pgx +# issue 171 +opj_decompress -i @INPUT_NR_PATH@/issue171.jp2 -o @TEMP_PATH@/issue171.jp2.pgx # decode with specific area # prec=12; nb_c=1 From 816db977fd7bf70d61b95e179d47bf2e0050eed6 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 28 Feb 2014 13:19:03 +0000 Subject: [PATCH 156/333] [trunk] Remove a simple warning, and use static to detect unused functions. Simplify function declarations. --- tests/comparePGXimages.c | 422 +++++++++++++++++++-------------------- 1 file changed, 209 insertions(+), 213 deletions(-) diff --git a/tests/comparePGXimages.c b/tests/comparePGXimages.c index 425a66d9..e7b779e5 100644 --- a/tests/comparePGXimages.c +++ b/tests/comparePGXimages.c @@ -44,11 +44,214 @@ #include "format_defs.h" #include "convert.h" -double* parseToleranceValues( char* inArg, const int nbcomp); -void comparePGXimages_help_display(void); -opj_image_t* readImageFromFilePGX(char* filename, int nbFilenamePGX, char *separator); +/******************************************************************************* + * Parse MSE and PEAK input values ( + * separator = ":" + *******************************************************************************/ +static double* parseToleranceValues( char* inArg, const int nbcomp) +{ + double* outArgs= malloc(nbcomp * sizeof(double)); + int it_comp = 0; + char delims[] = ":"; + char *result = NULL; + result = strtok( inArg, delims ); + + while( (result != NULL) && (it_comp < nbcomp )) + { + outArgs[it_comp] = atof(result); + result = strtok( NULL, delims ); + it_comp++; + } + + if (it_comp != nbcomp) + { + free(outArgs); + return NULL; + } + else + return outArgs; +} + +/******************************************************************************* + * Command line help function + *******************************************************************************/ +static void comparePGXimages_help_display(void) { + fprintf(stdout,"\nList of parameters for the comparePGX function \n"); + fprintf(stdout,"\n"); + fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline PGX image \n"); + fprintf(stdout," -t \t REQUIRED \t filename to the test PGX image\n"); + fprintf(stdout," -n \t REQUIRED \t number of component of the image (used to generate correct filename)\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 image with different components, " + "please indicate b or t before separator to indicate respectively the separator " + "for ref/base file and for test file. \n"); + fprintf(stdout," -d \t OPTIONAL \t indicate if you want to run this function as conformance test or as non regression test\n"); + fprintf(stdout,"\n"); +} + +/******************************************************************************* + * Create filenames from a filename by used separator and nb components + * (begin to 0) + *******************************************************************************/ +static char* createMultiComponentsFilename(const char* inFilename, const int indexF, const char* separator) +{ + char s[255]; + char *outFilename, *ptr; + char token = '.'; + int posToken = 0; + + /*printf("inFilename = %s\n", inFilename);*/ + if ((ptr = strrchr(inFilename, token)) != NULL) + { + posToken = (int) (strlen(inFilename) - strlen(ptr)); + /*printf("Position of %c character inside inFilename = %d\n", token, posToken);*/ + } + else + { + /*printf("Token %c not found\n", token);*/ + outFilename = (char*)malloc(1); + outFilename[0] = '\0'; + return outFilename; + } + + outFilename = (char*)malloc((posToken + 7) * sizeof(char)); /*6*/ + + strncpy(outFilename, inFilename, posToken); + + outFilename[posToken] = '\0'; + + strcat(outFilename, separator); + + sprintf(s, "%i", indexF); + strcat(outFilename, s); + + strcat(outFilename, ".pgx"); + + /*printf("outfilename: %s\n", outFilename);*/ + return outFilename; +} + +/******************************************************************************* + * + *******************************************************************************/ +static opj_image_t* readImageFromFilePGX(char* filename, int nbFilenamePGX, char *separator) +{ + int it_file; + opj_image_t* image_read = NULL; + opj_image_t* image = NULL; + opj_cparameters_t parameters; + opj_image_cmptparm_t* param_image_read; + int** data; + + /* If separator is empty => nb file to read is equal to one*/ + if ( strlen(separator) == 0 ) + nbFilenamePGX = 1; + + /* set encoding parameters to default values */ + opj_set_default_encoder_parameters(¶meters); + parameters.decod_format = PGX_DFMT; + strncpy(parameters.infile, filename, sizeof(parameters.infile)-1); + + /* Allocate memory*/ + param_image_read = malloc(nbFilenamePGX * sizeof(opj_image_cmptparm_t)); + data = malloc(nbFilenamePGX * sizeof(*data)); + + it_file = 0; + for (it_file = 0; it_file < nbFilenamePGX; it_file++) + { + /* Create the right filename*/ + char *filenameComponentPGX; + if (strlen(separator) == 0) + { + filenameComponentPGX = malloc((strlen(filename) + 1) * sizeof(*filenameComponentPGX)); + strcpy(filenameComponentPGX, filename); + } + else + filenameComponentPGX = createMultiComponentsFilename(filename, it_file, separator); + + /* Read the pgx file corresponding to the component */ + image_read = pgxtoimage(filenameComponentPGX, ¶meters); + if (!image_read) + { + int it_free_data; + fprintf(stderr, "Unable to load pgx file\n"); + + free(param_image_read); + + for (it_free_data = 0; it_free_data < it_file; it_free_data++) { + free(data[it_free_data]); + } + free(data); + + free(filenameComponentPGX); + + return NULL; + } + + /* Set the image_read parameters*/ + param_image_read[it_file].x0 = 0; + param_image_read[it_file].y0 = 0; + param_image_read[it_file].dx = 0; + param_image_read[it_file].dy = 0; + param_image_read[it_file].h = image_read->comps->h; + param_image_read[it_file].w = image_read->comps->w; + param_image_read[it_file].bpp = image_read->comps->bpp; + param_image_read[it_file].prec = image_read->comps->prec; + param_image_read[it_file].sgnd = image_read->comps->sgnd; + + /* Copy data*/ + data[it_file] = malloc(param_image_read[it_file].h * param_image_read[it_file].w * sizeof(int)); + memcpy(data[it_file], image_read->comps->data, image_read->comps->h * image_read->comps->w * sizeof(int)); + + /* Free memory*/ + opj_image_destroy(image_read); + free(filenameComponentPGX); + } + + image = opj_image_create(nbFilenamePGX, param_image_read, OPJ_CLRSPC_UNSPECIFIED); + for (it_file = 0; it_file < nbFilenamePGX; it_file++) + { + /* Copy data into output image and free memory*/ + memcpy(image->comps[it_file].data, data[it_file], image->comps[it_file].h * image->comps[it_file].w * sizeof(int)); + free(data[it_file]); + } + + /* Free memory*/ + free(param_image_read); + free(data); + + return image; +} + #ifdef OPJ_HAVE_LIBPNG -int imageToPNG(const opj_image_t* image, const char* filename, int num_comp_select); +/******************************************************************************* + * + *******************************************************************************/ +static int imageToPNG(const opj_image_t* image, const char* filename, int num_comp_select) +{ + opj_image_cmptparm_t param_image_write; + opj_image_t* image_write = NULL; + + param_image_write.x0 = 0; + param_image_write.y0 = 0; + param_image_write.dx = 0; + param_image_write.dy = 0; + param_image_write.h = image->comps[num_comp_select].h; + param_image_write.w = image->comps[num_comp_select].w; + param_image_write.bpp = image->comps[num_comp_select].bpp; + param_image_write.prec = image->comps[num_comp_select].prec; + param_image_write.sgnd = image->comps[num_comp_select].sgnd; + + image_write = opj_image_create(1, ¶m_image_write, OPJ_CLRSPC_GRAY); + memcpy(image_write->comps->data, image->comps[num_comp_select].data, param_image_write.h * param_image_write.w * sizeof(int)); + + imagetopng(image_write, filename); + + opj_image_destroy(image_write); + + return EXIT_SUCCESS; +} #endif typedef struct test_cmp_parameters @@ -72,24 +275,6 @@ typedef struct test_cmp_parameters } test_cmp_parameters; -/******************************************************************************* - * Command line help function - *******************************************************************************/ -void comparePGXimages_help_display(void) { - fprintf(stdout,"\nList of parameters for the comparePGX function \n"); - fprintf(stdout,"\n"); - fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline PGX image \n"); - fprintf(stdout," -t \t REQUIRED \t filename to the test PGX image\n"); - fprintf(stdout," -n \t REQUIRED \t number of component of the image (used to generate correct filename)\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 image with different components, " - "please indicate b or t before separator to indicate respectively the separator " - "for ref/base file and for test file. \n"); - fprintf(stdout," -d \t OPTIONAL \t indicate if you want to run this function as conformance test or as non regression test\n"); - fprintf(stdout,"\n"); -} - /******************************************************************************* * Parse command line *******************************************************************************/ @@ -301,196 +486,6 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) return EXIT_SUCCESS; } -/******************************************************************************* - * Parse MSE and PEAK input values ( - * separator = ":" - *******************************************************************************/ -double* parseToleranceValues( char* inArg, const int nbcomp) -{ - double* outArgs= malloc(nbcomp * sizeof(double)); - int it_comp = 0; - char delims[] = ":"; - char *result = NULL; - result = strtok( inArg, delims ); - - while( (result != NULL) && (it_comp < nbcomp )) - { - outArgs[it_comp] = atof(result); - result = strtok( NULL, delims ); - it_comp++; - } - - if (it_comp != nbcomp) - { - free(outArgs); - return NULL; - } - else - return outArgs; -} -/******************************************************************************* - * Create filenames from a filename by used separator and nb components - * (begin to 0) - *******************************************************************************/ -static char* createMultiComponentsFilename(const char* inFilename, const int indexF, const char* separator) -{ - char s[255]; - char *outFilename, *ptr; - char token = '.'; - int posToken = 0; - - /*printf("inFilename = %s\n", inFilename);*/ - if ((ptr = strrchr(inFilename, token)) != NULL) - { - posToken = (int) (strlen(inFilename) - strlen(ptr)); - /*printf("Position of %c character inside inFilename = %d\n", token, posToken);*/ - } - else - { - /*printf("Token %c not found\n", token);*/ - outFilename = (char*)malloc(1); - outFilename[0] = '\0'; - return outFilename; - } - - outFilename = (char*)malloc((posToken + 7) * sizeof(char)); /*6*/ - - strncpy(outFilename, inFilename, posToken); - - outFilename[posToken] = '\0'; - - strcat(outFilename, separator); - - sprintf(s, "%i", indexF); - strcat(outFilename, s); - - strcat(outFilename, ".pgx"); - - /*printf("outfilename: %s\n", outFilename);*/ - return outFilename; -} -/******************************************************************************* - * - *******************************************************************************/ -opj_image_t* readImageFromFilePGX(char* filename, int nbFilenamePGX, char *separator) -{ - int it_file; - opj_image_t* image_read = NULL; - opj_image_t* image = NULL; - opj_cparameters_t parameters; - opj_image_cmptparm_t* param_image_read; - int** data; - - /* If separator is empty => nb file to read is equal to one*/ - if ( strlen(separator) == 0 ) - nbFilenamePGX = 1; - - /* set encoding parameters to default values */ - opj_set_default_encoder_parameters(¶meters); - parameters.decod_format = PGX_DFMT; - strncpy(parameters.infile, filename, sizeof(parameters.infile)-1); - - /* Allocate memory*/ - param_image_read = malloc(nbFilenamePGX * sizeof(opj_image_cmptparm_t)); - data = malloc(nbFilenamePGX * sizeof(*data)); - - it_file = 0; - for (it_file = 0; it_file < nbFilenamePGX; it_file++) - { - /* Create the right filename*/ - char *filenameComponentPGX; - if (strlen(separator) == 0) - { - filenameComponentPGX = malloc((strlen(filename) + 1) * sizeof(*filenameComponentPGX)); - strcpy(filenameComponentPGX, filename); - } - else - filenameComponentPGX = createMultiComponentsFilename(filename, it_file, separator); - - /* Read the pgx file corresponding to the component */ - image_read = pgxtoimage(filenameComponentPGX, ¶meters); - if (!image_read) - { - int it_free_data; - fprintf(stderr, "Unable to load pgx file\n"); - - free(param_image_read); - - for (it_free_data = 0; it_free_data < it_file; it_free_data++) { - free(data[it_free_data]); - } - free(data); - - free(filenameComponentPGX); - - return NULL; - } - - /* Set the image_read parameters*/ - param_image_read[it_file].x0 = 0; - param_image_read[it_file].y0 = 0; - param_image_read[it_file].dx = 0; - param_image_read[it_file].dy = 0; - param_image_read[it_file].h = image_read->comps->h; - param_image_read[it_file].w = image_read->comps->w; - param_image_read[it_file].bpp = image_read->comps->bpp; - param_image_read[it_file].prec = image_read->comps->prec; - param_image_read[it_file].sgnd = image_read->comps->sgnd; - - /* Copy data*/ - data[it_file] = malloc(param_image_read[it_file].h * param_image_read[it_file].w * sizeof(int)); - memcpy(data[it_file], image_read->comps->data, image_read->comps->h * image_read->comps->w * sizeof(int)); - - /* Free memory*/ - opj_image_destroy(image_read); - free(filenameComponentPGX); - } - - image = opj_image_create(nbFilenamePGX, param_image_read, OPJ_CLRSPC_UNSPECIFIED); - for (it_file = 0; it_file < nbFilenamePGX; it_file++) - { - /* Copy data into output image and free memory*/ - memcpy(image->comps[it_file].data, data[it_file], image->comps[it_file].h * image->comps[it_file].w * sizeof(int)); - free(data[it_file]); - } - - /* Free memory*/ - free(param_image_read); - free(data); - - return image; -} - -/******************************************************************************* - * - *******************************************************************************/ -#ifdef OPJ_HAVE_LIBPNG -int imageToPNG(const opj_image_t* image, const char* filename, int num_comp_select) -{ - opj_image_cmptparm_t param_image_write; - opj_image_t* image_write = NULL; - - param_image_write.x0 = 0; - param_image_write.y0 = 0; - param_image_write.dx = 0; - param_image_write.dy = 0; - param_image_write.h = image->comps[num_comp_select].h; - param_image_write.w = image->comps[num_comp_select].w; - param_image_write.bpp = image->comps[num_comp_select].bpp; - param_image_write.prec = image->comps[num_comp_select].prec; - param_image_write.sgnd = image->comps[num_comp_select].sgnd; - - image_write = opj_image_create(1, ¶m_image_write, OPJ_CLRSPC_GRAY); - memcpy(image_write->comps->data, image->comps[num_comp_select].data, param_image_write.h * param_image_write.w * sizeof(int)); - - imagetopng(image_write, filename); - - opj_image_destroy(image_write); - - return EXIT_SUCCESS; -} -#endif - /******************************************************************************* * MAIN *******************************************************************************/ @@ -501,7 +496,8 @@ int main(int argc, char **argv) int failed = 0; int nbFilenamePGXbase, nbFilenamePGXtest; char *filenamePNGtest= NULL, *filenamePNGbase = NULL, *filenamePNGdiff = NULL; - int memsizebasefilename, memsizetestfilename, memsizedifffilename; + int memsizebasefilename, memsizetestfilename; + size_t memsizedifffilename; int valueDiff = 0, nbPixelDiff = 0; double sumDiff = 0.0; /* Structures to store image parameters and data*/ From ecbebe2847b8c10faca2b46751cce2b2cc199d47 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 28 Feb 2014 13:59:59 +0000 Subject: [PATCH 157/333] [trunk] Some code cleanup add sentinels --- tests/comparePGXimages.c | 154 ++++++++++++++++++++------------------- 1 file changed, 80 insertions(+), 74 deletions(-) diff --git a/tests/comparePGXimages.c b/tests/comparePGXimages.c index e7b779e5..7001b760 100644 --- a/tests/comparePGXimages.c +++ b/tests/comparePGXimages.c @@ -36,6 +36,7 @@ #include #include #include +#include #include "opj_apps_config.h" #include "opj_getopt.h" @@ -52,30 +53,30 @@ static double* parseToleranceValues( char* inArg, const int nbcomp) { double* outArgs= malloc(nbcomp * sizeof(double)); int it_comp = 0; - char delims[] = ":"; - char *result = NULL; - result = strtok( inArg, delims ); + const char delims[] = ":"; + char *result = strtok( inArg, delims ); while( (result != NULL) && (it_comp < nbcomp )) { - outArgs[it_comp] = atof(result); - result = strtok( NULL, delims ); - it_comp++; + outArgs[it_comp] = atof(result); + result = strtok( NULL, delims ); + it_comp++; } if (it_comp != nbcomp) - { - free(outArgs); + { + free(outArgs); return NULL; - } - else - return outArgs; + } + // else + return outArgs; } /******************************************************************************* * Command line help function *******************************************************************************/ -static void comparePGXimages_help_display(void) { +static void comparePGXimages_help_display(void) +{ fprintf(stdout,"\nList of parameters for the comparePGX function \n"); fprintf(stdout,"\n"); fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline PGX image \n"); @@ -98,7 +99,7 @@ static char* createMultiComponentsFilename(const char* inFilename, const int ind { char s[255]; char *outFilename, *ptr; - char token = '.'; + const char token = '.'; int posToken = 0; /*printf("inFilename = %s\n", inFilename);*/ @@ -135,7 +136,7 @@ static char* createMultiComponentsFilename(const char* inFilename, const int ind /******************************************************************************* * *******************************************************************************/ -static opj_image_t* readImageFromFilePGX(char* filename, int nbFilenamePGX, char *separator) +static opj_image_t* readImageFromFilePGX(const char* filename, int nbFilenamePGX, const char *separator) { int it_file; opj_image_t* image_read = NULL; @@ -146,18 +147,18 @@ static opj_image_t* readImageFromFilePGX(char* filename, int nbFilenamePGX, char /* If separator is empty => nb file to read is equal to one*/ if ( strlen(separator) == 0 ) - nbFilenamePGX = 1; + nbFilenamePGX = 1; /* set encoding parameters to default values */ opj_set_default_encoder_parameters(¶meters); parameters.decod_format = PGX_DFMT; strncpy(parameters.infile, filename, sizeof(parameters.infile)-1); + assert( parameters.infile[sizeof(parameters.infile)] == 0 ); /* Allocate memory*/ param_image_read = malloc(nbFilenamePGX * sizeof(opj_image_cmptparm_t)); data = malloc(nbFilenamePGX * sizeof(*data)); - it_file = 0; for (it_file = 0; it_file < nbFilenamePGX; it_file++) { /* Create the right filename*/ @@ -173,21 +174,21 @@ static opj_image_t* readImageFromFilePGX(char* filename, int nbFilenamePGX, char /* Read the pgx file corresponding to the component */ image_read = pgxtoimage(filenameComponentPGX, ¶meters); if (!image_read) - { - int it_free_data; - fprintf(stderr, "Unable to load pgx file\n"); + { + int it_free_data; + fprintf(stderr, "Unable to load pgx file\n"); - free(param_image_read); + free(param_image_read); - for (it_free_data = 0; it_free_data < it_file; it_free_data++) { - free(data[it_free_data]); - } - free(data); + for (it_free_data = 0; it_free_data < it_file; it_free_data++) { + free(data[it_free_data]); + } + free(data); - free(filenameComponentPGX); + free(filenameComponentPGX); - return NULL; - } + return NULL; + } /* Set the image_read parameters*/ param_image_read[it_file].x0 = 0; @@ -294,6 +295,8 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) param->tabMSEvalues = NULL; param->tabPEAKvalues = NULL; param->nr_flag = 0; + param->separator_base[0] = 0; + param->separator_test[0] = 0; opj_opterr = 0; @@ -350,13 +353,13 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) { for (index = opj_optind; index < argc; index++) fprintf(stderr,"Non-option argument %s\n", argv[index]); - return EXIT_FAILURE; + return 1; } if (param->nbcomp == 0) { fprintf(stderr,"Need to indicate the number of components !\n"); - return EXIT_FAILURE; + return 1; } else { @@ -367,7 +370,7 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) if ( (param->tabMSEvalues == NULL) || (param->tabPEAKvalues == NULL)) { fprintf(stderr,"MSE and PEAK values are not correct (respectively need %d values)\n",param->nbcomp); - return EXIT_FAILURE; + return 1; } } /*else @@ -399,19 +402,21 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) resultB = strtok(resultT, "b"); if (strlen(resultB) == 1) { - param->separator_base[0] = separatorList[1];param->separator_base[1] = '\0'; - param->separator_test[0] ='\0'; + param->separator_base[0] = separatorList[1]; + param->separator_base[1] = 0; + param->separator_test[0] = 0; } else /* not found b*/ { free(separatorList2); - return EXIT_FAILURE; + return 1; } } else /* found t*/ { - param->separator_base[0] ='\0'; - param->separator_test[0] = separatorList[1];param->separator_test[1] = '\0'; + param->separator_base[0] = 0; + param->separator_test[0] = separatorList[1]; + param->separator_test[1] = 0; } /*printf("sep b = %s [%d] and sep t = %s [%d]\n",param->separator_base, strlen(param->separator_base), param->separator_test, strlen(param->separator_test) );*/ } @@ -425,13 +430,15 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) resultB = strtok(resultT, "b"); if (strlen(resultB) == 1) /* found b after t*/ { - param->separator_test[0] = separatorList[1];param->separator_test[1] = '\0'; - param->separator_base[0] = separatorList[3];param->separator_base[1] = '\0'; + param->separator_test[0] = separatorList[1]; + param->separator_test[1] = 0; + param->separator_base[0] = separatorList[3]; + param->separator_base[1] = 0; } else /* didn't find b after t*/ { free(separatorList2); - return EXIT_FAILURE; + return 1; } } else /* == 2, didn't find t in first place*/ @@ -440,13 +447,15 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) resultB = strtok(resultT, "b"); if (strlen(resultB) == 1) /* found b in first place*/ { - param->separator_base[0] = separatorList[1]; param->separator_base[1] = '\0'; - param->separator_test[0] = separatorList[3]; param->separator_test[1] = '\0'; + param->separator_base[0] = separatorList[1]; + param->separator_base[1] = 0; + param->separator_test[0] = separatorList[3]; + param->separator_test[1] = 0; } else /* didn't found b in first place => problem*/ { free(separatorList2); - return EXIT_FAILURE; + return 1; } } } @@ -454,20 +463,20 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) } else /* wrong number of argument after -s*/ { - return EXIT_FAILURE; + return 1; } } else { if (param->nbcomp == 1) { - param->separator_base[0] = '\0'; - param->separator_test[0] = '\0'; + assert( param->separator_base[0] == 0 ); + assert( param->separator_test[0] == 0 ); } else { fprintf(stderr,"If number of component is > 1, we need separator\n"); - return EXIT_FAILURE; + return 1; } } @@ -475,15 +484,15 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) if ( (param->nr_flag) && (flagP || flagM) ) { fprintf(stderr,"Wrong input parameters list: it is non-regression test or tolerance comparison\n"); - return EXIT_FAILURE; + return 1; } if ( (!param->nr_flag) && (!flagP || !flagM) ) { fprintf(stderr,"Wrong input parameters list: it is non-regression test or tolerance comparison\n"); - return EXIT_FAILURE; + return 1; } - return EXIT_SUCCESS; + return 0; } /******************************************************************************* @@ -505,13 +514,13 @@ int main(int argc, char **argv) opj_image_cmptparm_t* param_image_diff; /* Get parameters from command line*/ - if( parse_cmdline_cmp(argc, argv, &inParam) == EXIT_FAILURE ) + if( parse_cmdline_cmp(argc, argv, &inParam) ) { comparePGXimages_help_display(); - if (inParam.tabMSEvalues) free(inParam.tabMSEvalues); - if (inParam.tabPEAKvalues) free(inParam.tabPEAKvalues); - if (inParam.base_filename) free(inParam.base_filename); - if (inParam.test_filename) free(inParam.test_filename); + free(inParam.tabMSEvalues); + free(inParam.tabPEAKvalues); + free(inParam.base_filename); + free(inParam.test_filename); return EXIT_FAILURE; } @@ -570,10 +579,10 @@ int main(int argc, char **argv) } else { - if (inParam.tabMSEvalues) free(inParam.tabMSEvalues); - if (inParam.tabPEAKvalues) free(inParam.tabPEAKvalues); - if (inParam.base_filename) free(inParam.base_filename); - if (inParam.test_filename) free(inParam.test_filename); + free(inParam.tabMSEvalues); + free(inParam.tabPEAKvalues); + free(inParam.base_filename); + free(inParam.test_filename); return EXIT_FAILURE; } @@ -591,10 +600,10 @@ int main(int argc, char **argv) } else { - if (inParam.tabMSEvalues) free(inParam.tabMSEvalues); - if (inParam.tabPEAKvalues) free(inParam.tabPEAKvalues); - if (inParam.base_filename) free(inParam.base_filename); - if (inParam.test_filename) free(inParam.test_filename); + free(inParam.tabMSEvalues); + free(inParam.tabPEAKvalues); + free(inParam.base_filename); + free(inParam.test_filename); free(filenamePNGbase); return EXIT_FAILURE; } @@ -697,19 +706,19 @@ int main(int argc, char **argv) char *filenamePNGbase_it_comp, *filenamePNGtest_it_comp, *filenamePNGdiff_it_comp; filenamePNGbase_it_comp = (char*) malloc(memsizebasefilename); - filenamePNGbase_it_comp[0] = '\0'; + filenamePNGbase_it_comp[0] = 0; strncpy(filenamePNGbase_it_comp,filenamePNGbase,strlen(filenamePNGbase)); - filenamePNGbase_it_comp[strlen(filenamePNGbase)] = '\0'; + filenamePNGbase_it_comp[strlen(filenamePNGbase)] = 0; filenamePNGtest_it_comp = (char*) malloc(memsizetestfilename); - filenamePNGtest_it_comp[0] = '\0'; + filenamePNGtest_it_comp[0] = 0; strncpy(filenamePNGtest_it_comp,filenamePNGtest,strlen(filenamePNGtest)); - filenamePNGtest_it_comp[strlen(filenamePNGtest)] = '\0'; + filenamePNGtest_it_comp[strlen(filenamePNGtest)] = 0; filenamePNGdiff_it_comp = (char*) malloc(memsizedifffilename); - filenamePNGdiff_it_comp[0] = '\0'; + filenamePNGdiff_it_comp[0] = 0; strncpy(filenamePNGdiff_it_comp,filenamePNGdiff,strlen(filenamePNGdiff)); - filenamePNGdiff_it_comp[strlen(filenamePNGdiff)] = '\0'; + filenamePNGdiff_it_comp[strlen(filenamePNGdiff)] = 0; for (itpxl = 0; itpxl < ((imageDiff->comps)[it_comp]).w * ((imageDiff->comps)[it_comp]).h; itpxl++) { @@ -803,11 +812,8 @@ int main(int argc, char **argv) free(inParam.base_filename); free(inParam.test_filename); - if (failed) - return EXIT_FAILURE; - else - { - printf("---- TEST SUCCEED ----\n"); - return EXIT_SUCCESS; - } + if (failed) return EXIT_FAILURE; + + printf("---- TEST SUCCEED ----\n"); + return EXIT_SUCCESS; } From 82647e79c7c71810255cd5bafcc70f6b21bb4221 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 28 Feb 2014 14:17:30 +0000 Subject: [PATCH 158/333] [trunk] Simplify code to centralize code cleanup --- tests/comparePGXimages.c | 150 ++++++++++++++++----------------------- 1 file changed, 61 insertions(+), 89 deletions(-) diff --git a/tests/comparePGXimages.c b/tests/comparePGXimages.c index 7001b760..ae460d62 100644 --- a/tests/comparePGXimages.c +++ b/tests/comparePGXimages.c @@ -502,7 +502,7 @@ int main(int argc, char **argv) { test_cmp_parameters inParam; OPJ_UINT32 it_comp, itpxl; - int failed = 0; + int failed = 1; int nbFilenamePGXbase, nbFilenamePGXtest; char *filenamePNGtest= NULL, *filenamePNGbase = NULL, *filenamePNGdiff = NULL; int memsizebasefilename, memsizetestfilename; @@ -511,17 +511,13 @@ int main(int argc, char **argv) double sumDiff = 0.0; /* Structures to store image parameters and data*/ opj_image_t *imageBase = NULL, *imageTest = NULL, *imageDiff = NULL; - opj_image_cmptparm_t* param_image_diff; + opj_image_cmptparm_t* param_image_diff = NULL; /* Get parameters from command line*/ if( parse_cmdline_cmp(argc, argv, &inParam) ) { comparePGXimages_help_display(); - free(inParam.tabMSEvalues); - free(inParam.tabPEAKvalues); - free(inParam.base_filename); - free(inParam.test_filename); - return EXIT_FAILURE; + goto cleanup; } /* Display Parameters*/ @@ -573,17 +569,13 @@ int main(int argc, char **argv) filenamePNGbase = (char*) malloc(memsizebasefilename); filenamePNGbase[0] = '\0'; strncpy(filenamePNGbase, inParam.test_filename, strlen(inParam.test_filename)); - filenamePNGbase[strlen(inParam.test_filename)] = '\0'; + filenamePNGbase[strlen(inParam.test_filename)] = 0; strcat(filenamePNGbase, ".base"); /*printf("filenamePNGbase = %s [%d / %d octets]\n",filenamePNGbase, strlen(filenamePNGbase),memsizebasefilename );*/ } else { - free(inParam.tabMSEvalues); - free(inParam.tabPEAKvalues); - free(inParam.base_filename); - free(inParam.test_filename); - return EXIT_FAILURE; + goto cleanup; } /*----------TEST IMAGE--------*/ @@ -594,18 +586,13 @@ int main(int argc, char **argv) filenamePNGtest = (char*) malloc(memsizetestfilename); filenamePNGtest[0] = '\0'; strncpy(filenamePNGtest, inParam.test_filename, strlen(inParam.test_filename)); - filenamePNGtest[strlen(inParam.test_filename)] = '\0'; + filenamePNGtest[strlen(inParam.test_filename)] = 0; strcat(filenamePNGtest, ".test"); /*printf("filenamePNGtest = %s [%d / %d octets]\n",filenamePNGtest, strlen(filenamePNGtest),memsizetestfilename );*/ } else { - free(inParam.tabMSEvalues); - free(inParam.tabPEAKvalues); - free(inParam.base_filename); - free(inParam.test_filename); - free(filenamePNGbase); - return EXIT_FAILURE; + goto cleanup; } /*----------DIFF IMAGE--------*/ @@ -626,7 +613,7 @@ int main(int argc, char **argv) if (imageBase->comps[it_comp].sgnd != imageTest->comps[it_comp].sgnd) { printf("ERROR: sign mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).sgnd, ((imageTest->comps)[it_comp]).sgnd); - failed = 1; + goto cleanup; } else param_image_diff[it_comp].sgnd = 0 ; @@ -634,7 +621,7 @@ int main(int argc, char **argv) if (((imageBase->comps)[it_comp]).prec != ((imageTest->comps)[it_comp]).prec) { printf("ERROR: prec mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).prec, ((imageTest->comps)[it_comp]).prec); - failed = 1; + goto cleanup; } else param_image_diff[it_comp].prec = 8 ; @@ -642,7 +629,7 @@ int main(int argc, char **argv) if (((imageBase->comps)[it_comp]).bpp != ((imageTest->comps)[it_comp]).bpp) { printf("ERROR: byte per pixel mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).bpp, ((imageTest->comps)[it_comp]).bpp); - failed = 1; + goto cleanup; } else param_image_diff[it_comp].bpp = 1 ; @@ -650,7 +637,7 @@ int main(int argc, char **argv) if (((imageBase->comps)[it_comp]).h != ((imageTest->comps)[it_comp]).h) { printf("ERROR: height mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).h, ((imageTest->comps)[it_comp]).h); - failed = 1; + goto cleanup; } else param_image_diff[it_comp].h = imageBase->comps[it_comp].h ; @@ -658,43 +645,24 @@ int main(int argc, char **argv) if (((imageBase->comps)[it_comp]).w != ((imageTest->comps)[it_comp]).w) { printf("ERROR: width mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).w, ((imageTest->comps)[it_comp]).w); - failed = 1; + goto cleanup; } else param_image_diff[it_comp].w = imageBase->comps[it_comp].w ; } - /* If only one parameter is different, we stop the test*/ - if (failed) - { - free(inParam.tabMSEvalues); - free(inParam.tabPEAKvalues); - free(inParam.base_filename); - free(inParam.test_filename); - - free(filenamePNGbase); - free(filenamePNGtest); - - opj_image_destroy(imageBase); - opj_image_destroy(imageTest); - - free(param_image_diff); - - return EXIT_FAILURE; - } - imageDiff = opj_image_create(imageBase->numcomps, param_image_diff, OPJ_CLRSPC_UNSPECIFIED); /* Free memory*/ - free(param_image_diff); + free(param_image_diff); param_image_diff = NULL; /* Measurement computation*/ printf("Step 2 -> measurement comparison\n"); memsizedifffilename = strlen(inParam.test_filename) + 1 + 5 + 2 + 4; filenamePNGdiff = (char*) malloc(memsizedifffilename); - filenamePNGdiff[0] = '\0'; + filenamePNGdiff[0] = 0; strncpy(filenamePNGdiff, inParam.test_filename, strlen(inParam.test_filename)); - filenamePNGdiff[strlen(inParam.test_filename)] = '\0'; + filenamePNGdiff[strlen(inParam.test_filename)] = 0; strcat(filenamePNGdiff, ".diff"); /*printf("filenamePNGdiff = %s [%d / %d octets]\n",filenamePNGdiff, strlen(filenamePNGdiff),memsizedifffilename );*/ @@ -703,23 +671,6 @@ int main(int argc, char **argv) { double SE=0,PEAK=0; double MSE=0; - char *filenamePNGbase_it_comp, *filenamePNGtest_it_comp, *filenamePNGdiff_it_comp; - - filenamePNGbase_it_comp = (char*) malloc(memsizebasefilename); - filenamePNGbase_it_comp[0] = 0; - strncpy(filenamePNGbase_it_comp,filenamePNGbase,strlen(filenamePNGbase)); - filenamePNGbase_it_comp[strlen(filenamePNGbase)] = 0; - - filenamePNGtest_it_comp = (char*) malloc(memsizetestfilename); - filenamePNGtest_it_comp[0] = 0; - strncpy(filenamePNGtest_it_comp,filenamePNGtest,strlen(filenamePNGtest)); - filenamePNGtest_it_comp[strlen(filenamePNGtest)] = 0; - - filenamePNGdiff_it_comp = (char*) malloc(memsizedifffilename); - filenamePNGdiff_it_comp[0] = 0; - strncpy(filenamePNGdiff_it_comp,filenamePNGdiff,strlen(filenamePNGdiff)); - filenamePNGdiff_it_comp[strlen(filenamePNGdiff)] = 0; - for (itpxl = 0; itpxl < ((imageDiff->comps)[it_comp]).w * ((imageDiff->comps)[it_comp]).h; itpxl++) { if (abs( ((imageBase->comps)[it_comp]).data[itpxl] - ((imageTest->comps)[it_comp]).data[itpxl] ) > 0) @@ -746,9 +697,9 @@ int main(int argc, char **argv) if ( (MSE > inParam.tabMSEvalues[it_comp]) || (PEAK > inParam.tabPEAKvalues[it_comp]) ) { printf("ERROR: MSE (%f) or PEAK (%f) values produced by the decoded file are greater " - "than the allowable error (respectively %f and %f) \n", - MSE, PEAK, inParam.tabMSEvalues[it_comp], inParam.tabPEAKvalues[it_comp]); - failed = 1; + "than the allowable error (respectively %f and %f) \n", + MSE, PEAK, inParam.tabMSEvalues[it_comp], inParam.tabPEAKvalues[it_comp]); + goto cleanup; } } else /* Non regression-test */ @@ -756,48 +707,72 @@ int main(int argc, char **argv) if ( nbPixelDiff > 0) { char it_compc[255]; - it_compc[0] = '\0'; + it_compc[0] = 0; printf(" %d \n", it_comp, nbPixelDiff); printf(" %f \n", it_comp, sumDiff); #ifdef OPJ_HAVE_LIBPNG - sprintf(it_compc, "_%i", it_comp); - strcat(it_compc,".png"); - strcat(filenamePNGbase_it_comp, it_compc); - /*printf("filenamePNGbase_it = %s [%d / %d octets]\n",filenamePNGbase_it_comp, strlen(filenamePNGbase_it_comp),memsizebasefilename );*/ - strcat(filenamePNGtest_it_comp, it_compc); - /*printf("filenamePNGtest_it = %s [%d / %d octets]\n",filenamePNGtest_it_comp, strlen(filenamePNGtest_it_comp),memsizetestfilename );*/ - strcat(filenamePNGdiff_it_comp, it_compc); - /*printf("filenamePNGdiff_it = %s [%d / %d octets]\n",filenamePNGdiff_it_comp, strlen(filenamePNGdiff_it_comp),memsizedifffilename );*/ + { + char *filenamePNGbase_it_comp, *filenamePNGtest_it_comp, *filenamePNGdiff_it_comp; - /* - if ( imageToPNG(imageBase, filenamePNGbase_it_comp, it_comp) == EXIT_SUCCESS ) + filenamePNGbase_it_comp = (char*) malloc(memsizebasefilename); + filenamePNGbase_it_comp[0] = 0; + strncpy(filenamePNGbase_it_comp,filenamePNGbase,strlen(filenamePNGbase)); + filenamePNGbase_it_comp[strlen(filenamePNGbase)] = 0; + + filenamePNGtest_it_comp = (char*) malloc(memsizetestfilename); + filenamePNGtest_it_comp[0] = 0; + strncpy(filenamePNGtest_it_comp,filenamePNGtest,strlen(filenamePNGtest)); + filenamePNGtest_it_comp[strlen(filenamePNGtest)] = 0; + + filenamePNGdiff_it_comp = (char*) malloc(memsizedifffilename); + filenamePNGdiff_it_comp[0] = 0; + strncpy(filenamePNGdiff_it_comp,filenamePNGdiff,strlen(filenamePNGdiff)); + filenamePNGdiff_it_comp[strlen(filenamePNGdiff)] = 0; + + + sprintf(it_compc, "_%i", it_comp); + strcat(it_compc,".png"); + strcat(filenamePNGbase_it_comp, it_compc); + /*printf("filenamePNGbase_it = %s [%d / %d octets]\n",filenamePNGbase_it_comp, strlen(filenamePNGbase_it_comp),memsizebasefilename );*/ + strcat(filenamePNGtest_it_comp, it_compc); + /*printf("filenamePNGtest_it = %s [%d / %d octets]\n",filenamePNGtest_it_comp, strlen(filenamePNGtest_it_comp),memsizetestfilename );*/ + strcat(filenamePNGdiff_it_comp, it_compc); + /*printf("filenamePNGdiff_it = %s [%d / %d octets]\n",filenamePNGdiff_it_comp, strlen(filenamePNGdiff_it_comp),memsizedifffilename );*/ + + /* + if ( imageToPNG(imageBase, filenamePNGbase_it_comp, it_comp) == EXIT_SUCCESS ) { printf(" %s \n", it_comp, filenamePNGbase_it_comp); } - if ( imageToPNG(imageTest, filenamePNGtest_it_comp, it_comp) == EXIT_SUCCESS ) + if ( imageToPNG(imageTest, filenamePNGtest_it_comp, it_comp) == EXIT_SUCCESS ) { printf(" %s \n", it_comp, filenamePNGtest_it_comp); } - if ( imageToPNG(imageDiff, filenamePNGdiff_it_comp, it_comp) == EXIT_SUCCESS ) + if ( imageToPNG(imageDiff, filenamePNGdiff_it_comp, it_comp) == EXIT_SUCCESS ) { printf(" %s \n", it_comp, filenamePNGdiff_it_comp); } - */ + */ + free(filenamePNGbase_it_comp); + free(filenamePNGtest_it_comp); + free(filenamePNGdiff_it_comp); + } #endif - failed = 1; + goto cleanup; } } - free(filenamePNGbase_it_comp); - free(filenamePNGtest_it_comp); - free(filenamePNGdiff_it_comp); } /* it_comp loop */ + printf("---- TEST SUCCEED ----\n"); + failed = 0; +cleanup: /*-----------------------------*/ + free(param_image_diff); /* Free memory */ opj_image_destroy(imageBase); opj_image_destroy(imageTest); @@ -812,8 +787,5 @@ int main(int argc, char **argv) free(inParam.base_filename); free(inParam.test_filename); - if (failed) return EXIT_FAILURE; - - printf("---- TEST SUCCEED ----\n"); - return EXIT_SUCCESS; + return failed ? EXIT_FAILURE : EXIT_SUCCESS; } From d2dc1597fe8f9aaede3772c064dd6db5d7f2e15a Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 28 Feb 2014 14:23:30 +0000 Subject: [PATCH 159/333] [trunk] Prefer strcpy since it copies trailing 0 directly --- tests/comparePGXimages.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/tests/comparePGXimages.c b/tests/comparePGXimages.c index ae460d62..9b8a85f5 100644 --- a/tests/comparePGXimages.c +++ b/tests/comparePGXimages.c @@ -717,20 +717,13 @@ int main(int argc, char **argv) char *filenamePNGbase_it_comp, *filenamePNGtest_it_comp, *filenamePNGdiff_it_comp; filenamePNGbase_it_comp = (char*) malloc(memsizebasefilename); - filenamePNGbase_it_comp[0] = 0; - strncpy(filenamePNGbase_it_comp,filenamePNGbase,strlen(filenamePNGbase)); - filenamePNGbase_it_comp[strlen(filenamePNGbase)] = 0; + strcpy(filenamePNGbase_it_comp,filenamePNGbase); filenamePNGtest_it_comp = (char*) malloc(memsizetestfilename); - filenamePNGtest_it_comp[0] = 0; - strncpy(filenamePNGtest_it_comp,filenamePNGtest,strlen(filenamePNGtest)); - filenamePNGtest_it_comp[strlen(filenamePNGtest)] = 0; + strcpy(filenamePNGtest_it_comp,filenamePNGtest); filenamePNGdiff_it_comp = (char*) malloc(memsizedifffilename); - filenamePNGdiff_it_comp[0] = 0; - strncpy(filenamePNGdiff_it_comp,filenamePNGdiff,strlen(filenamePNGdiff)); - filenamePNGdiff_it_comp[strlen(filenamePNGdiff)] = 0; - + strcpy(filenamePNGdiff_it_comp,filenamePNGdiff); sprintf(it_compc, "_%i", it_comp); strcat(it_compc,".png"); From 6ee2a51edc06ca7092fc5ee186850a240515809d Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 28 Feb 2014 14:31:01 +0000 Subject: [PATCH 160/333] [trunk] Remove PNG generation code for now --- tests/comparePGXimages.c | 45 ++++++++++++++-------------------------- 1 file changed, 15 insertions(+), 30 deletions(-) diff --git a/tests/comparePGXimages.c b/tests/comparePGXimages.c index 9b8a85f5..a6159b10 100644 --- a/tests/comparePGXimages.c +++ b/tests/comparePGXimages.c @@ -225,7 +225,7 @@ static opj_image_t* readImageFromFilePGX(const char* filename, int nbFilenamePGX return image; } -#ifdef OPJ_HAVE_LIBPNG +#if defined(OPJ_HAVE_LIBPNG) && 0 /* remove for now */ /******************************************************************************* * *******************************************************************************/ @@ -503,7 +503,7 @@ int main(int argc, char **argv) test_cmp_parameters inParam; OPJ_UINT32 it_comp, itpxl; int failed = 1; - int nbFilenamePGXbase, nbFilenamePGXtest; + int nbFilenamePGXbase = 0, nbFilenamePGXtest = 0; char *filenamePNGtest= NULL, *filenamePNGbase = NULL, *filenamePNGdiff = NULL; int memsizebasefilename, memsizetestfilename; size_t memsizedifffilename; @@ -545,14 +545,10 @@ int main(int argc, char **argv) printf(" Non-regression test = %d\n", inParam.nr_flag); } - if (strlen(inParam.separator_base) == 0) - nbFilenamePGXbase = 0; - else + if (strlen(inParam.separator_base) != 0) nbFilenamePGXbase = inParam.nbcomp; - if (strlen(inParam.separator_test) == 0) - nbFilenamePGXtest = 0; - else + if (strlen(inParam.separator_test) != 0) nbFilenamePGXtest = inParam.nbcomp; printf(" NbFilename to generate from base filename = %d\n", nbFilenamePGXbase); @@ -567,9 +563,7 @@ int main(int argc, char **argv) if ( imageBase != NULL) { filenamePNGbase = (char*) malloc(memsizebasefilename); - filenamePNGbase[0] = '\0'; - strncpy(filenamePNGbase, inParam.test_filename, strlen(inParam.test_filename)); - filenamePNGbase[strlen(inParam.test_filename)] = 0; + strcpy(filenamePNGbase, inParam.test_filename); strcat(filenamePNGbase, ".base"); /*printf("filenamePNGbase = %s [%d / %d octets]\n",filenamePNGbase, strlen(filenamePNGbase),memsizebasefilename );*/ } @@ -584,9 +578,7 @@ int main(int argc, char **argv) if ( imageTest != NULL) { filenamePNGtest = (char*) malloc(memsizetestfilename); - filenamePNGtest[0] = '\0'; - strncpy(filenamePNGtest, inParam.test_filename, strlen(inParam.test_filename)); - filenamePNGtest[strlen(inParam.test_filename)] = 0; + strcpy(filenamePNGtest, inParam.test_filename); strcat(filenamePNGtest, ".test"); /*printf("filenamePNGtest = %s [%d / %d octets]\n",filenamePNGtest, strlen(filenamePNGtest),memsizetestfilename );*/ } @@ -609,46 +601,41 @@ int main(int argc, char **argv) param_image_diff[it_comp].y0 = 0; param_image_diff[it_comp].dx = 0; param_image_diff[it_comp].dy = 0; + param_image_diff[it_comp].sgnd = 0; + param_image_diff[it_comp].prec = 8; + param_image_diff[it_comp].bpp = 1; + param_image_diff[it_comp].h = imageBase->comps[it_comp].h; + param_image_diff[it_comp].w = imageBase->comps[it_comp].w; if (imageBase->comps[it_comp].sgnd != imageTest->comps[it_comp].sgnd) { printf("ERROR: sign mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).sgnd, ((imageTest->comps)[it_comp]).sgnd); goto cleanup; } - else - param_image_diff[it_comp].sgnd = 0 ; if (((imageBase->comps)[it_comp]).prec != ((imageTest->comps)[it_comp]).prec) { printf("ERROR: prec mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).prec, ((imageTest->comps)[it_comp]).prec); goto cleanup; } - else - param_image_diff[it_comp].prec = 8 ; if (((imageBase->comps)[it_comp]).bpp != ((imageTest->comps)[it_comp]).bpp) { printf("ERROR: byte per pixel mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).bpp, ((imageTest->comps)[it_comp]).bpp); goto cleanup; } - else - param_image_diff[it_comp].bpp = 1 ; if (((imageBase->comps)[it_comp]).h != ((imageTest->comps)[it_comp]).h) { printf("ERROR: height mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).h, ((imageTest->comps)[it_comp]).h); goto cleanup; } - else - param_image_diff[it_comp].h = imageBase->comps[it_comp].h ; if (((imageBase->comps)[it_comp]).w != ((imageTest->comps)[it_comp]).w) { printf("ERROR: width mismatch [comp %d] (%d><%d)\n", it_comp, ((imageBase->comps)[it_comp]).w, ((imageTest->comps)[it_comp]).w); goto cleanup; } - else - param_image_diff[it_comp].w = imageBase->comps[it_comp].w ; } imageDiff = opj_image_create(imageBase->numcomps, param_image_diff, OPJ_CLRSPC_UNSPECIFIED); @@ -660,9 +647,7 @@ int main(int argc, char **argv) memsizedifffilename = strlen(inParam.test_filename) + 1 + 5 + 2 + 4; filenamePNGdiff = (char*) malloc(memsizedifffilename); - filenamePNGdiff[0] = 0; - strncpy(filenamePNGdiff, inParam.test_filename, strlen(inParam.test_filename)); - filenamePNGdiff[strlen(inParam.test_filename)] = 0; + strcpy(filenamePNGdiff, inParam.test_filename); strcat(filenamePNGdiff, ".diff"); /*printf("filenamePNGdiff = %s [%d / %d octets]\n",filenamePNGdiff, strlen(filenamePNGdiff),memsizedifffilename );*/ @@ -677,10 +662,10 @@ int main(int argc, char **argv) { valueDiff = ((imageBase->comps)[it_comp]).data[itpxl] - ((imageTest->comps)[it_comp]).data[itpxl]; ((imageDiff->comps)[it_comp]).data[itpxl] = abs(valueDiff); - sumDiff += (double)valueDiff; + sumDiff += valueDiff; nbPixelDiff++; - SE += (double)(valueDiff * valueDiff); + SE += (double)valueDiff * valueDiff; PEAK = (PEAK > abs(valueDiff)) ? PEAK : abs(valueDiff); } else @@ -762,7 +747,7 @@ int main(int argc, char **argv) } /* it_comp loop */ printf("---- TEST SUCCEED ----\n"); - failed = 0; + failed = 0; cleanup: /*-----------------------------*/ free(param_image_diff); From b7bccf86c38d5fe7550437f96725c308f932f053 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 28 Feb 2014 14:38:45 +0000 Subject: [PATCH 161/333] [trunk] final round of minor cleanups --- tests/comparePGXimages.c | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/tests/comparePGXimages.c b/tests/comparePGXimages.c index a6159b10..5f629641 100644 --- a/tests/comparePGXimages.c +++ b/tests/comparePGXimages.c @@ -560,32 +560,24 @@ int main(int argc, char **argv) memsizetestfilename = (int)strlen(inParam.test_filename) + 1 + 5 + 2 + 4; imageBase = readImageFromFilePGX( inParam.base_filename, nbFilenamePGXbase, inParam.separator_base); - if ( imageBase != NULL) - { - filenamePNGbase = (char*) malloc(memsizebasefilename); - strcpy(filenamePNGbase, inParam.test_filename); - strcat(filenamePNGbase, ".base"); - /*printf("filenamePNGbase = %s [%d / %d octets]\n",filenamePNGbase, strlen(filenamePNGbase),memsizebasefilename );*/ - } - else - { + if ( imageBase == NULL ) goto cleanup; - } + + filenamePNGbase = (char*) malloc(memsizebasefilename); + strcpy(filenamePNGbase, inParam.test_filename); + strcat(filenamePNGbase, ".base"); + /*printf("filenamePNGbase = %s [%d / %d octets]\n",filenamePNGbase, strlen(filenamePNGbase),memsizebasefilename );*/ /*----------TEST IMAGE--------*/ imageTest = readImageFromFilePGX(inParam.test_filename, nbFilenamePGXtest, inParam.separator_test); - if ( imageTest != NULL) - { - filenamePNGtest = (char*) malloc(memsizetestfilename); - strcpy(filenamePNGtest, inParam.test_filename); - strcat(filenamePNGtest, ".test"); - /*printf("filenamePNGtest = %s [%d / %d octets]\n",filenamePNGtest, strlen(filenamePNGtest),memsizetestfilename );*/ - } - else - { + if ( imageTest == NULL ) goto cleanup; - } + + filenamePNGtest = (char*) malloc(memsizetestfilename); + strcpy(filenamePNGtest, inParam.test_filename); + strcat(filenamePNGtest, ".test"); + /*printf("filenamePNGtest = %s [%d / %d octets]\n",filenamePNGtest, strlen(filenamePNGtest),memsizetestfilename );*/ /*----------DIFF IMAGE--------*/ From fc855084a0bf7bbc5f74b586bbe1a415d5063a94 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 28 Feb 2014 14:52:58 +0000 Subject: [PATCH 162/333] [trunk] Really apply r2460 this time, but fix the original typo in the submitted patch Update issue 225 --- src/lib/openjp2/j2k.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 924fdd60..bd39f759 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -4481,6 +4481,14 @@ static OPJ_BOOL opj_j2k_read_rgn (opj_j2k_t *p_j2k, }; #endif /* USE_JPWL */ + /* testcase 3635.pdf.asan.77.2930 */ + if (l_comp_no >= l_nb_comp) { + opj_event_msg(p_manager, EVT_ERROR, + "bad component number in RGN (%d when there are only %d)\n", + l_comp_no, l_nb_comp); + return OPJ_FALSE; + } + opj_read_bytes(p_header_data,(OPJ_UINT32 *) (&(l_tcp->tccps[l_comp_no].roishift)),1); /* SPrgn */ ++p_header_data; From a9e6268766e10419904b18512c03fe3d1529a308 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 28 Feb 2014 14:54:37 +0000 Subject: [PATCH 163/333] [trunk] Fix JPIP test with updated md5sum --- tests/CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 04cd62dc..b40af1c5 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -93,7 +93,7 @@ if(BUILD_JPIP) #set(s "http://jpip.example.com/myFCGI?target=16.jp2&fsiz=170,170&cnew=http&type=jpp-stream") set(s "${JPIP_SERVER}?target=16.jp2&fsiz=170,170&cnew=http&type=jpp-stream") set(p "${CMAKE_CURRENT_BINARY_DIR}/jpip.dat") - set(md5 "62b00c620fb0a600c5ffd413cada4674") + set(md5 "d41d8cd98f00b204e9800998ecf8427e") add_test(NAME TestJPIP1 COMMAND ${CMAKE_COMMAND} -DD_URL:STRING=${s} -DD_FILE:PATH=${p} -DEXPECTED_MD5=${md5} -P ${PROJECT_SOURCE_DIR}/cmake/JPIPTestDriver.cmake) endif() From 1b93cb8c0a0f613a3c87d00a373c36b036e83b8b Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 28 Feb 2014 15:14:53 +0000 Subject: [PATCH 164/333] [trunk] Mark a file as being invalid for opj_dump --- tests/nonregression/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/nonregression/CMakeLists.txt b/tests/nonregression/CMakeLists.txt index f756fe81..ce2dd8b6 100644 --- a/tests/nonregression/CMakeLists.txt +++ b/tests/nonregression/CMakeLists.txt @@ -23,6 +23,7 @@ set(BLACKLIST_JPEG2000_TMP 2539.pdf.SIGFPE.706.1712.jp2 0290cb77c5df21828fa74cf2ab2c84d8.SIGFPE.d25.31.jp2 26ccf3651020967f7778238ef5af08af.SIGFPE.d25.527.jp2 + 4035.pdf.SIGSEGV.d8b.3375.jp2 ) # Define a list of file which should be gracefully rejected: From fd5f21af0077d59160cdab83e5ea01022313ca5e Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 28 Feb 2014 15:24:33 +0000 Subject: [PATCH 165/333] [trunk] Rework r2458, instead we should reject 451.pdf.SIGSEGV.ce9.3723 since tile-parts are out of order (as per kakadu behavior). Update issue 225 --- src/lib/openjp2/j2k.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index bd39f759..9637b552 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -4010,12 +4010,20 @@ OPJ_BOOL opj_j2k_read_sot ( opj_j2k_t *p_j2k, if (l_num_parts != 0) { /* Number of tile-part header is provided by this tile-part header */ /* Useful to manage the case of textGBR.jp2 file because two values of TNSot are allowed: the correct numbers of * tile-parts for that tile and zero (A.4.2 of 15444-1 : 2002). */ - if (l_num_parts < l_tcp->m_nb_tile_parts) { - l_num_parts = l_tcp->m_nb_tile_parts; + if (l_tcp->m_nb_tile_parts) { + if (l_current_part >= l_tcp->m_nb_tile_parts){ + opj_event_msg(p_manager, EVT_ERROR, "In SOT marker, TPSot (%d) is not valid regards to the current " + "number of tile-part (%d), giving up\n", l_current_part, l_tcp->m_nb_tile_parts ); + p_j2k->m_specific_param.m_decoder.m_last_tile_part = 1; + return OPJ_FALSE; + } } - if (l_current_part >= l_num_parts) { - /* testcase 451.pdf.SIGSEGV.ce9.3723 */ - l_num_parts = l_current_part + 1; + if( l_current_part >= l_num_parts ) { + /* testcase 451.pdf.SIGSEGV.ce9.3723 */ + opj_event_msg(p_manager, EVT_ERROR, "In SOT marker, TPSot (%d) is not valid regards to the current " + "number of tile-part (header) (%d), giving up\n", l_current_part, l_num_parts ); + p_j2k->m_specific_param.m_decoder.m_last_tile_part = 1; + return OPJ_FALSE; } l_tcp->m_nb_tile_parts = l_num_parts; } From cf91ebf2788f3df4391cc6ace557248bcb45acfb Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 28 Feb 2014 15:27:30 +0000 Subject: [PATCH 166/333] [trunk] Re-import chunk from r2458 that made textGBR.jp2 to fail otherwise Update issue 225 --- src/lib/openjp2/j2k.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 9637b552..7485e752 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -4030,7 +4030,7 @@ OPJ_BOOL opj_j2k_read_sot ( opj_j2k_t *p_j2k, /* If know the number of tile part header we will check if we didn't read the last*/ if (l_tcp->m_nb_tile_parts) { - if (l_tcp->m_nb_tile_parts == l_current_part) { + if (l_tcp->m_nb_tile_parts == (l_current_part+1)) { p_j2k->m_specific_param.m_decoder.m_can_decode = 1; /* Process the last tile-part header*/ } } From c53e2960a06556b73a0be593cfba742e401c7273 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 28 Feb 2014 16:01:07 +0000 Subject: [PATCH 167/333] [trunk] Remove easy uint32 <-> int32 conversions --- src/lib/openjp2/j2k.c | 48 +++++++++++++++++++++---------------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 7485e752..4d988df5 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -1569,7 +1569,7 @@ OPJ_BOOL opj_j2k_check_poc_val( const opj_poc_t *p_pocs, OPJ_UINT32 opj_j2k_get_num_tp(opj_cp_t *cp, OPJ_UINT32 pino, OPJ_UINT32 tileno) { const OPJ_CHAR *prog = 00; - OPJ_UINT32 i; + OPJ_INT32 i; OPJ_UINT32 tpnum = 1; opj_tcp_t *tcp = 00; opj_poc_t * l_current_poc = 00; @@ -2235,7 +2235,7 @@ OPJ_BOOL opj_j2k_write_com( opj_j2k_t *p_j2k, assert(p_manager != 00); l_comment = p_j2k->m_cp.comment; - l_comment_size = strlen(l_comment); + l_comment_size = (OPJ_UINT32)strlen(l_comment); l_total_com_size = l_comment_size + 6; if (l_total_com_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_size) { @@ -4227,7 +4227,7 @@ OPJ_BOOL opj_j2k_read_sod (opj_j2k_t *p_j2k, opj_event_mgr_t * p_manager ) { - OPJ_UINT32 l_current_read_size; + OPJ_SIZE_T l_current_read_size; opj_codestream_index_t * l_cstr_index = 00; OPJ_BYTE ** l_current_data = 00; opj_tcp_t * l_tcp = 00; @@ -4332,7 +4332,7 @@ OPJ_BOOL opj_j2k_read_sod (opj_j2k_t *p_j2k, p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_TPHSOT; } - *l_tile_len += l_current_read_size; + *l_tile_len += (OPJ_UINT32)l_current_read_size; return OPJ_TRUE; } @@ -4544,7 +4544,7 @@ OPJ_BOOL opj_j2k_update_rates( opj_j2k_t *p_j2k, l_bits_empty = 8 * l_image->comps->dx * l_image->comps->dy; l_size_pixel = l_image->numcomps * l_image->comps->prec; - l_sot_remove = ((OPJ_FLOAT32) opj_stream_tell(p_stream)) / (l_cp->th * l_cp->tw); + l_sot_remove = (OPJ_FLOAT32) opj_stream_tell(p_stream) / (OPJ_FLOAT32)(l_cp->th * l_cp->tw); if (l_cp->m_specific_param.m_enc.m_tp_on) { l_tp_stride_func = opj_j2k_get_tp_stride; @@ -4555,7 +4555,7 @@ OPJ_BOOL opj_j2k_update_rates( opj_j2k_t *p_j2k, for (i=0;ith;++i) { for (j=0;jtw;++j) { - OPJ_FLOAT32 l_offset = ((*l_tp_stride_func)(l_tcp)) / l_tcp->numlayers; + OPJ_FLOAT32 l_offset = (OPJ_FLOAT32)(*l_tp_stride_func)(l_tcp) / (OPJ_FLOAT32)l_tcp->numlayers; /* 4 borders of the tile rescale on the image if necessary */ l_x0 = opj_int_max(l_cp->tx0 + j * l_cp->tdx, l_image->x0); @@ -5619,7 +5619,7 @@ OPJ_BOOL opj_j2k_add_mct(opj_tcp_t * p_tcp, opj_image_t * p_image, OPJ_UINT32 p_ } l_nb_elem = p_image->numcomps * p_image->numcomps; - l_mct_size = l_nb_elem * sizeof(OPJ_FLOAT32); + l_mct_size = l_nb_elem * (OPJ_UINT32)sizeof(OPJ_FLOAT32); p_tcp->m_mct_decoding_matrix = (OPJ_FLOAT32*)opj_malloc(l_mct_size); if (! p_tcp->m_mct_decoding_matrix ) { @@ -5638,7 +5638,7 @@ OPJ_BOOL opj_j2k_add_mct(opj_tcp_t * p_tcp, opj_image_t * p_image, OPJ_UINT32 p_ } l_nb_elem = p_image->numcomps; - l_offset_size = l_nb_elem * sizeof(OPJ_UINT32); + l_offset_size = l_nb_elem * (OPJ_UINT32)sizeof(OPJ_UINT32); l_offset_data = (OPJ_UINT32*)opj_malloc(l_offset_size); if (! l_offset_data ) { @@ -5849,8 +5849,8 @@ int opj_j2k_initialise_4K_poc(opj_poc_t *POC, int numres){ void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *image, opj_event_mgr_t *p_manager) { /* Configure cinema parameters */ - float max_rate = 0; - float temp_rate = 0; + OPJ_FLOAT32 max_rate = 0; + OPJ_FLOAT32 temp_rate = 0; int i; /* profile (Rsiz) */ @@ -5963,13 +5963,13 @@ void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *i switch (parameters->cp_cinema){ case OPJ_CINEMA2K_24: case OPJ_CINEMA4K_24: - max_rate = ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy); + max_rate = (OPJ_FLOAT32) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)/ + (OPJ_FLOAT32)(CINEMA_24_CS * 8 * image->comps[0].dx * image->comps[0].dy); if (parameters->tcp_rates[0] == 0){ parameters->tcp_rates[0] = max_rate; }else{ - temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (parameters->tcp_rates[0] * 8 * image->comps[0].dx * image->comps[0].dy); + temp_rate =(OPJ_FLOAT32)(image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)/ + (OPJ_FLOAT32)(parameters->tcp_rates[0] * 8 * image->comps[0].dx * image->comps[0].dy); if (temp_rate > CINEMA_24_CS ){ opj_event_msg(p_manager, EVT_WARNING, "JPEG 2000 Profile-3 and 4 (2k/4k dc profile) requires:\n" @@ -6274,7 +6274,7 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, if (parameters->mct_data) { - OPJ_UINT32 lMctSize = image->numcomps * image->numcomps * sizeof(OPJ_FLOAT32); + OPJ_UINT32 lMctSize = image->numcomps * image->numcomps * (OPJ_UINT32)sizeof(OPJ_FLOAT32); OPJ_FLOAT32 * lTmpBuf = (OPJ_FLOAT32*)opj_malloc(lMctSize); OPJ_INT32 * l_dc_shift = (OPJ_INT32 *) ((OPJ_BYTE *) parameters->mct_data + lMctSize); @@ -7006,9 +7006,9 @@ static OPJ_BOOL opj_j2k_copy_default_tcp_and_create_tcd ( opj_j2k_t * p_j2 l_image = p_j2k->m_private_image; l_nb_tiles = p_j2k->m_cp.th * p_j2k->m_cp.tw; l_tcp = p_j2k->m_cp.tcps; - l_tccp_size = l_image->numcomps * sizeof(opj_tccp_t); + l_tccp_size = l_image->numcomps * (OPJ_UINT32)sizeof(opj_tccp_t); l_default_tcp = p_j2k->m_specific_param.m_decoder.m_default_tcp; - l_mct_size = l_image->numcomps * l_image->numcomps * sizeof(OPJ_FLOAT32); + l_mct_size = l_image->numcomps * l_image->numcomps * (OPJ_UINT32)sizeof(OPJ_FLOAT32); /* For each tile */ for (i=0; im_nb_max_mct_records * sizeof(opj_mct_data_t); + l_mct_records_size = l_default_tcp->m_nb_max_mct_records * (OPJ_UINT32)sizeof(opj_mct_data_t); l_tcp->m_mct_records = (opj_mct_data_t*)opj_malloc(l_mct_records_size); if (! l_tcp->m_mct_records) { return OPJ_FALSE; @@ -7059,7 +7059,7 @@ static OPJ_BOOL opj_j2k_copy_default_tcp_and_create_tcd ( opj_j2k_t * p_j2 } /* Get the mcc_record of the dflt_tile_cp and copy them into the current tile cp*/ - l_mcc_records_size = l_default_tcp->m_nb_max_mcc_records * sizeof(opj_simple_mcc_decorrelation_data_t); + l_mcc_records_size = l_default_tcp->m_nb_max_mcc_records * (OPJ_UINT32)sizeof(opj_simple_mcc_decorrelation_data_t); l_tcp->m_mcc_records = (opj_simple_mcc_decorrelation_data_t*) opj_malloc(l_mcc_records_size); if (! l_tcp->m_mcc_records) { return OPJ_FALSE; @@ -7073,12 +7073,12 @@ static OPJ_BOOL opj_j2k_copy_default_tcp_and_create_tcd ( opj_j2k_t * p_j2 for (j=0;jm_nb_max_mcc_records;++j) { if (l_src_mcc_rec->m_decorrelation_array) { - l_offset = l_src_mcc_rec->m_decorrelation_array - l_default_tcp->m_mct_records; + l_offset = (OPJ_UINT32)(l_src_mcc_rec->m_decorrelation_array - l_default_tcp->m_mct_records); l_dest_mcc_rec->m_decorrelation_array = l_tcp->m_mct_records + l_offset; } if (l_src_mcc_rec->m_offset_array) { - l_offset = l_src_mcc_rec->m_offset_array - l_default_tcp->m_mct_records; + l_offset = (OPJ_UINT32)(l_src_mcc_rec->m_offset_array - l_default_tcp->m_mct_records); l_dest_mcc_rec->m_offset_array = l_tcp->m_mct_records + l_offset; } @@ -8354,7 +8354,7 @@ void opj_j2k_copy_tile_component_parameters( opj_j2k_t *p_j2k ) l_ref_tccp = &l_tcp->tccps[0]; l_copied_tccp = l_ref_tccp + 1; - l_prc_size = l_ref_tccp->numresolutions * sizeof(OPJ_UINT32); + l_prc_size = l_ref_tccp->numresolutions * (OPJ_UINT32)sizeof(OPJ_UINT32); for (i=1; im_private_image->numcomps; ++i) { l_copied_tccp->numresolutions = l_ref_tccp->numresolutions; @@ -9596,7 +9596,7 @@ void opj_j2k_get_tile_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data) else { for (j=0;j Date: Fri, 28 Feb 2014 16:04:11 +0000 Subject: [PATCH 168/333] [trunk] Make sure to run *-decode-md5 only after *-decode tests. Update md5 since recent code change. --- tests/nonregression/CMakeLists.txt | 3 ++ tests/nonregression/md5refs.txt | 85 +++++++++++++++--------------- 2 files changed, 45 insertions(+), 43 deletions(-) diff --git a/tests/nonregression/CMakeLists.txt b/tests/nonregression/CMakeLists.txt index ce2dd8b6..11eb47af 100644 --- a/tests/nonregression/CMakeLists.txt +++ b/tests/nonregression/CMakeLists.txt @@ -321,6 +321,9 @@ foreach(OPJ_TEST_CMD_LINE ${OPJ_TEST_CMD_LINE_LIST}) -DFILENAME:STRING=${INPUT_FILENAME_NAME} -P ${CMAKE_CURRENT_SOURCE_DIR}/checkmd5refs.cmake) + set_tests_properties(NR-DEC-${INPUT_FILENAME_NAME}-${IT_TEST_DEC}-decode-md5 + PROPERTIES DEPENDS NR-DEC-${INPUT_FILENAME_NAME}-${IT_TEST_DEC}-decode + ) # FIXME: add a compare2base function base on raw which # can output png diff files if necesary diff --git a/tests/nonregression/md5refs.txt b/tests/nonregression/md5refs.txt index d967192e..f9984b1a 100644 --- a/tests/nonregression/md5refs.txt +++ b/tests/nonregression/md5refs.txt @@ -1,32 +1,35 @@ -6f22c9a9bd474202ac6cd3a066e15200 _00042.j2k_0.pgx -a3a0606dfa0779d657c6a923b90e4678 _00042.j2k_1.pgx -106954dc468dfe0884d02268e91f9f5b _00042.j2k_2.pgx -8889def55f1e18dae6002b9b3a6dd152 123.j2c_0.pgx -ee6881e50c9cf17994ac74c2bee956a8 1888.pdf.asan.35.988.jp2_0.pgx +71673036d224dedba4969aacb7a89316 _00042.j2k_0.pgx +3f4af6ee5b706a6d43a70fb78e5b0061 _00042.j2k_1.pgx +05e2676e5a1c8a61bdd8477fbbf5ab32 _00042.j2k_2.pgx +e3cd8edf8a8f1975f65ed0aae4ee5069 123.j2c_0.pgx +4bddb9f5c5f437fe1053af4d61d9202e 1336.pdf.asan.47.376.jp2_0.pgx +f38167b983f0de0ab77e71de291bf5c0 1336.pdf.asan.47.376.jp2_1.pgx +d9a4feed1773b7b1ae5c20bdbdd37291 1336.pdf.asan.47.376.jp2_2.pgx 4a0daf7a9065101379eaebc28e436b1e Bretagne2.j2k_0.pgx 07578fc7bf81d3da694de8ae27308b82 Bretagne2.j2k_1.pgx 3690c42f83bad42f4abea48525d45e0e Bretagne2.j2k_2.pgx -8889def55f1e18dae6002b9b3a6dd152 bug.j2c_0.pgx -22c8d33a956ba83079d1102457bc77a1 buxI.j2k_0.pgx -b8f473c07ba5ebfc195bdd53c3b3b97f buxR.j2k_0.pgx -05c062aca83d13b8095460f38a690a08 Cannotreaddatawithnosizeknown.j2k_0.pgx +e3cd8edf8a8f1975f65ed0aae4ee5069 bug.j2c_0.pgx +a4c4714bfd4f12ba6d2e81129205ce50 buxI.j2k_0.pgx +a7be45c89d53dd4beac927a7a1d4ed29 buxR.j2k_0.pgx +903b6d8166de3d39f70c7a924afb9887 Cannotreaddatawithnosizeknown.j2k_0.pgx 6276da0ec5fac44d683d3468b290331d cthead1.j2k_0.pgx -8afcac9a696cc8d753b0eb9f4ae692ff CT_Phillips_JPEG2K_Decompr_Problem.j2k_0.pgx +79cee673f96a3c8ae00412927af283dc CT_Phillips_JPEG2K_Decompr_Problem.j2k_0.pgx 04d35ab6160c9029549f72358df984da file409752.jp2_0.pgx 2813bd6fdc2c306b91b3da3688b8bf49 file409752.jp2_1.pgx e273e2aaea4a4fc1b2cf7c09c53c3cc6 file409752.jp2_2.pgx -05c062aca83d13b8095460f38a690a08 illegalcolortransform.j2k_0.pgx +903b6d8166de3d39f70c7a924afb9887 illegalcolortransform.j2k_0.pgx cccccccccccccccccccccccccccccccc issue104_jpxstream.jp2_0.pgx +cb28787aa7c223f03e6acad71e244108 issue104_jpxstream.jp2_1.pgx +cb28787aa7c223f03e6acad71e244108 issue104_jpxstream.jp2_2.pgx c74edbb49e132b2cfc1eaf7908197b17 issue134.jp2_0.pgx 16fe8ed450da10a6aaae4cf6f467fc21 issue134.jp2_1.pgx c6091c07bf0ff221008dfb60d893cdff issue134.jp2_2.pgx -12a8a4668315d9ae27969991251ce853 issue135.j2k_0.pgx -56d0b0c547d6d5bb12f0c36e88722b13 issue135.j2k_1.pgx -48ba092fb40090c160bbd08bdf7bdbf3 issue135.j2k_2.pgx -619694e5674992b3286244bf13058f7c issue142.j2k_0.pgx -c675c4b77dc3cc2a0d6542a32b438a48 issue142.j2k_1.pgx -663ebdd12dd6a36915ea1152c43cb69a issue142.j2k_2.pgx -cb28787aa7c223f03e6acad71e244108 issue110.jp2_0.pgx +cccccccccccccccccccccccccccccccc issue135.j2k_0.pgx +cccccccccccccccccccccccccccccccc issue135.j2k_1.pgx +cccccccccccccccccccccccccccccccc issue135.j2k_2.pgx +833cde271689e4690a7c96a621c3d067 issue142.j2k_0.pgx +50a38e56f388c94a1459db35907331ba issue142.j2k_1.pgx +a2df1b66dfa7eaac5f3b9c839c5b84cc issue142.j2k_2.pgx 820b37ef934bd17d45dd73f5dc4d95b7 issue171.jp2_0.pgx 4596dcd3efa51f84824b60353e2af306 issue171.jp2_1.pgx c2a656096b1965c3b4a26563d6ade467 issue171.jp2_2.pgx @@ -40,30 +43,26 @@ de992d54d59032eb07d21983dbe8155b issue205.jp2_3.pgx 8fae7a39e459409f64e4529d2214087a issue206_image-000.jp2_0.pgx 555a504a93c9a14f61c894da3b393e87 issue206_image-000.jp2_1.pgx 5f06b7c45446ae20c22cada46478a9dc issue206_image-000.jp2_2.pgx -b7073a2c1b5a42f9555eb0f0bd3c6510 issue208.jp2_0.pgx -df65beeb8fd056c8f7b8dfc699caa12b issue208.jp2_1.pgx -15cba2ad37c1a8e1eb3eb4bc42d5a2a2 issue208.jp2_2.pgx -301fabf4aac5729b44aab845580d5038 issue208.jp2_3.pgx +8c0025fe9ffbff839e7735c18f56f596 issue208.jp2_0.pgx +285fedd7e5e92624177d00eaa543e551 issue208.jp2_1.pgx +bc5178a807be5901938d7f555275933f issue208.jp2_2.pgx +37546d44ecf7f2ea40a4f25d177910f3 issue208.jp2_3.pgx a0823d21d9de699353a3bd1adb23bd1c issue211.jp2_0.pgx 1820161df26c360a62d11800d6cf173f issue211.jp2_1.pgx -e1807db57b5f5192c4b77b83e8b5c477 issue228.j2k_0.pgx -611948e70370bf132839fc37109859c7 issue254.jp2_0.pgx -611948e70370bf132839fc37109859c7 issue254.jp2_1.pgx -611948e70370bf132839fc37109859c7 issue254.jp2_2.pgx -4093cc34d838780b35a8be410247fa7f j2k32.j2k_0.pgx -ce4e556aaa0844b92a92c35c200fc43e j2k32.j2k_1.pgx -ea926520f990640862f3fe6616097613 j2k32.j2k_2.pgx -66b60e866991e03f9a2de18e80d3102b kakadu_v4-4_openjpegv2_broken.j2k_0.pgx -12a8a4668315d9ae27969991251ce85f kodak_2layers_lrcp.j2c_0.pgx -56d0b0c547d6d5bb12f0c36e88722b11 kodak_2layers_lrcp.j2c_1.pgx -48ba092fb40090c160bbd08bdf7bdbf2 kodak_2layers_lrcp.j2c_2.pgx -05c062aca83d13b8095460f38a690a08 MarkerIsNotCompliant.j2k_0.pgx +a442b31e2b7fd49a85a5afa6f6cd9a18 issue228.j2k_0.pgx +cccccccccccccccccccccccccccccccc issue254.jp2_0.pgx +cccccccccccccccccccccccccccccccc issue254.jp2_1.pgx +cccccccccccccccccccccccccccccccc issue254.jp2_2.pgx +5abdd78e99dcce6a7f4370140966eb89 j2k32.j2k_0.pgx +ab505e4ddc590b0410798af1cb2dbb40 j2k32.j2k_1.pgx +2eff0259c7e5a60981dc2daf25d69804 j2k32.j2k_2.pgx +cdc63501aa572e5dfc32ccec3499f436 kakadu_v4-4_openjpegv2_broken.j2k_0.pgx +de45172778ff18043e445615c112d0ba kodak_2layers_lrcp.j2c_0.pgx +1bd43cbf9639ee08b2945f2a27045618 kodak_2layers_lrcp.j2c_1.pgx +cbaa10e5a2a795a4552632910c16e81c kodak_2layers_lrcp.j2c_2.pgx +903b6d8166de3d39f70c7a924afb9887 MarkerIsNotCompliant.j2k_0.pgx ff73d2bd32951d9e55b02186aac24aff Marrin.jp2_0.pgx 55ce884dd2346af6a5172a434ee578fa Marrin.jp2_1.pgx -29131264861b4ee21011149b27e4d488 mem-b2ace68c-1381.jp2_0.pgx -29131264861b4ee21011149b27e4d488 mem-b2ace68c-1381.jp2_1.pgx -29131264861b4ee21011149b27e4d488 mem-b2ace68c-1381.jp2_2.pgx -df568fe0529219cc2c8f215e236f4b3d mem-b2ace68c-1381.jp2_3.pgx 41ec1a0228c703b10f95388c1160753b mem-b2b86b74-2753.jp2_0.pgx 41ec1a0228c703b10f95388c1160753b mem-b2b86b74-2753.jp2_1.pgx 41ec1a0228c703b10f95388c1160753b mem-b2b86b74-2753.jp2_2.pgx @@ -129,11 +128,11 @@ ce2de61ad83a71c9b13ca5df0a987a69 p1_06_3.j2k.png 85a2b9a1324d72a8cec7041f80529242 p1_06.j2k.png af083204299bbdd993286892b4c9cd29 p1_06.j2k_r4.png af083204299bbdd993286892b4c9cd29 p1_06.j2k_t0.png -371aa0a7ff40a73b45f1fa41e210d1db pacs.ge.j2k_0.pgx +b219d8a1338e9ce6ffd29dd076bbd28d pacs.ge.j2k_0.pgx 6ae110e1fb5a869af3dbc5fbc735b0bd relax.jp2_0.pgx 518a8f28dacc034982507f43763b88dd relax.jp2_1.pgx c678b04f4d3e59b9d66a8bce37c553c0 relax.jp2_2.pgx -cdb1d69eb48ffd8545751326b86d9d7e test_lossless.j2k_0.pgx -efc9c7f21a542a7888a9eeb73b0f7092 text_GBR.jp2_0.pgx -54790b332b3dcbda28e1bcb31270b946 text_GBR.jp2_1.pgx -d9bcbdc818febb8c0a6bc5f940a4ea85 text_GBR.jp2_2.pgx +921798f6d894a0a44df5082639ea968f test_lossless.j2k_0.pgx +a37e7e5811d7c0c7adb61582790ccd33 text_GBR.jp2_0.pgx +fc2173be54954a146b4e2887ee14be06 text_GBR.jp2_1.pgx +14108b4fb8d9126750db0424417ed17d text_GBR.jp2_2.pgx From ec593a2549b77d0958d58717688797350e0d29d0 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 28 Feb 2014 17:29:28 +0000 Subject: [PATCH 169/333] [trunk] Partially rework r2506, original patch from issue 171 was totally bogus (untested?) and did break most of the test (eg. p1_04 family) convert.c duplicate a lot of code, this patch only adresses the PGX codec section of the code. Update issue 171 Update issue 264 --- src/bin/jp2/convert.c | 153 ++++++++++++++++++++++-------------------- 1 file changed, 82 insertions(+), 71 deletions(-) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index f59ec7f9..4b7886df 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -1416,90 +1416,101 @@ opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters) { return image; } +#define CLAMP(x,a,b) x < a ? a : (x > b ? b : x) + +static inline int clamp( const int value, const int prec, const int sgnd ) +{ + if( sgnd ) + { + if (prec <= 8) return CLAMP(value,-128,127); + else if (prec <= 16) return CLAMP(value,-32768,32767); + else return CLAMP(value,-2147483648,2147483647); + } + else + { + if (prec <= 8) return CLAMP(value,0,255); + else if (prec <= 16) return CLAMP(value,0,65535); + else return CLAMP(value,0,4294967295); + } +} + int imagetopgx(opj_image_t * image, const char *outfile) { - int w, h; - int i, j, compno, fails; - FILE *fdest = NULL; + int w, h; + int i, j, compno, fails = 1; + FILE *fdest = NULL; - for (compno = 0; compno < image->numcomps; compno++) - { - opj_image_comp_t *comp = &image->comps[compno]; - char bname[256]; /* buffer for name */ - char *name = bname; /* pointer */ - int nbytes = 0; - size_t res; - const size_t olen = strlen(outfile); - const size_t dotpos = olen - 4; - const size_t total = dotpos + 1 + 1 + 4; /* '-' + '[1-3]' + '.pgx' */ + for (compno = 0; compno < image->numcomps; compno++) + { + opj_image_comp_t *comp = &image->comps[compno]; + char bname[256]; /* buffer for name */ + char *name = bname; /* pointer */ + int nbytes = 0; + size_t res; + const size_t olen = strlen(outfile); + const size_t dotpos = olen - 4; + const size_t total = dotpos + 1 + 1 + 4; /* '-' + '[1-3]' + '.pgx' */ if( outfile[dotpos] != '.' ) - { -/* `pgx` was recognized but there is no dot at expected position */ - fprintf(stderr, "ERROR -> Impossible happen." ); - return 1; - } + { + /* `pgx` was recognized but there is no dot at expected position */ + fprintf(stderr, "ERROR -> Impossible happen." ); + goto fin; + } if( total > 256 ) - { - name = (char*)malloc(total+1); - } - strncpy(name, outfile, dotpos); - /*if (image->numcomps > 1) {*/ - sprintf(name+dotpos, "_%d.pgx", compno); - /*} else { - strcpy(name+dotpos, ".pgx"); - }*/ - fdest = fopen(name, "wb"); - if (!fdest) - { - fprintf(stderr, "ERROR -> failed to open %s for writing\n", name); - return 1; - } -/* dont need name anymore */ - if( total > 256 ) - free(name); - - fails = 1; - w = image->comps[compno].w; - h = image->comps[compno].h; + { + name = (char*)malloc(total+1); + } + strncpy(name, outfile, dotpos); + sprintf(name+dotpos, "_%d.pgx", compno); + fdest = fopen(name, "wb"); + /* dont need name anymore */ + if( total > 256 ) free(name); + if (!fdest) + { + fprintf(stderr, "ERROR -> failed to open %s for writing\n", name); + goto fin; + } - fprintf(fdest, "PG ML %c %d %d %d\n", comp->sgnd ? '-' : '+', - comp->prec, w, h); + w = image->comps[compno].w; + h = image->comps[compno].h; - if (comp->prec <= 8) - nbytes = 1; - else - if (comp->prec <= 16) - nbytes = 2; - else - nbytes = 4; + fprintf(fdest, "PG ML %c %d %d %d\n", comp->sgnd ? '-' : '+', comp->prec, + w, h); - for (i = 0; i < w * h; i++) - { - int v, val = image->comps[compno].data[i]; - unsigned char byte; + if (comp->prec <= 8) + nbytes = 1; + else if (comp->prec <= 16) + nbytes = 2; + else + nbytes = 4; - for (j = nbytes - 1; j >= 0; j--) - { - v = (int)(val >> (j * 8)); - if(v > 255) v = 255; else if(v < 0) v = 0; - byte = (unsigned char)v; - res = fwrite(&byte, 1, 1, fdest); + for (i = 0; i < w * h; i++) + { + /* FIXME: clamp func is being called within a loop */ + const int val = clamp(image->comps[compno].data[i], + comp->prec, comp->sgnd); - if( res < 1 ) - { - fprintf(stderr, "failed to write 1 byte for %s\n", name); - goto fin; - } - } - } - fclose(fdest); fdest = NULL; - } - fails = 0; + for (j = nbytes - 1; j >= 0; j--) + { + int v = (int)(val >> (j * 8)); + unsigned char byte = (unsigned char)v; + res = fwrite(&byte, 1, 1, fdest); + + if( res < 1 ) + { + fprintf(stderr, "failed to write 1 byte for %s\n", name); + goto fin; + } + } + } + fclose(fdest); fdest = NULL; + } + fails = 0; fin: - if(fdest) fclose(fdest); + if(fdest) fclose(fdest); - return fails; + return fails; } /* -->> -->> -->> -->> From 6d0785a78fecc58cf4bb571956547999c4d1e437 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Sat, 1 Mar 2014 10:41:46 +0000 Subject: [PATCH 170/333] [trunk] Fix compilation on MSVC compiler --- src/bin/jp2/convert.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index 4b7886df..ce7ecf2e 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -3118,7 +3118,7 @@ static int imagetoraw_common(opj_image_t * image, const char *outfile, OPJ_BOOL { if(image->comps[compno].sgnd == 1) { - union { signed short val; signed char vals[2] } uc; + union { signed short val; signed char vals[2]; } uc; mask = (1 << image->comps[compno].prec) - 1; ptr = image->comps[compno].data; for (line = 0; line < h; line++) { @@ -3137,7 +3137,7 @@ static int imagetoraw_common(opj_image_t * image, const char *outfile, OPJ_BOOL } else if(image->comps[compno].sgnd == 0) { - union { unsigned short val; unsigned char vals[2] } uc; + union { unsigned short val; unsigned char vals[2]; } uc; mask = (1 << image->comps[compno].prec) - 1; ptr = image->comps[compno].data; for (line = 0; line < h; line++) { From 2c876b676564879380f0d239e4fe723933e71717 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Sun, 2 Mar 2014 10:16:54 +0000 Subject: [PATCH 171/333] [trunk] Remove simple warnings about comments, missing case in switch statement --- src/lib/openjp2/j2k.c | 30 +++++++++++++++++------------- src/lib/openjp2/jp2.c | 2 +- src/lib/openjp2/tcd.c | 2 +- 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 4d988df5..4ec94195 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -5862,6 +5862,9 @@ void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *i case OPJ_CINEMA4K_24: parameters->cp_rsiz = OPJ_CINEMA4K; break; + case OPJ_OFF: + assert(0); + break; } /* No tiling */ @@ -9781,7 +9784,6 @@ OPJ_BOOL opj_j2k_write_first_tile_part (opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, struct opj_event_mgr * p_manager ) { -// OPJ_UINT32 compno; OPJ_UINT32 l_nb_bytes_written = 0; OPJ_UINT32 l_current_nb_bytes_written; OPJ_BYTE * l_begin_data = 00; @@ -9812,19 +9814,21 @@ OPJ_BOOL opj_j2k_write_first_tile_part (opj_j2k_t *p_j2k, p_total_data_size -= l_current_nb_bytes_written; if (l_cp->m_specific_param.m_enc.m_cinema == 0) { -// for (compno = 1; compno < p_j2k->m_private_image->numcomps; compno++) { -// l_current_nb_bytes_written = 0; -// opj_j2k_write_coc_in_memory(p_j2k,compno,p_data,&l_current_nb_bytes_written,p_manager); -// l_nb_bytes_written += l_current_nb_bytes_written; -// p_data += l_current_nb_bytes_written; -// p_total_data_size -= l_current_nb_bytes_written; +#if 0 + for (compno = 1; compno < p_j2k->m_private_image->numcomps; compno++) { + l_current_nb_bytes_written = 0; + opj_j2k_write_coc_in_memory(p_j2k,compno,p_data,&l_current_nb_bytes_written,p_manager); + l_nb_bytes_written += l_current_nb_bytes_written; + p_data += l_current_nb_bytes_written; + p_total_data_size -= l_current_nb_bytes_written; -// l_current_nb_bytes_written = 0; -// opj_j2k_write_qcc_in_memory(p_j2k,compno,p_data,&l_current_nb_bytes_written,p_manager); -// l_nb_bytes_written += l_current_nb_bytes_written; -// p_data += l_current_nb_bytes_written; -// p_total_data_size -= l_current_nb_bytes_written; -// } + l_current_nb_bytes_written = 0; + opj_j2k_write_qcc_in_memory(p_j2k,compno,p_data,&l_current_nb_bytes_written,p_manager); + l_nb_bytes_written += l_current_nb_bytes_written; + p_data += l_current_nb_bytes_written; + p_total_data_size -= l_current_nb_bytes_written; + } +#endif if (l_cp->tcps[p_j2k->m_current_tile_number].numpocs) { l_current_nb_bytes_written = 0; diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c index d59ec434..92a3726a 100644 --- a/src/lib/openjp2/jp2.c +++ b/src/lib/openjp2/jp2.c @@ -823,7 +823,7 @@ static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color, return OPJ_TRUE; } -// file9.jp2 +/* file9.jp2 */ void opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color) { opj_image_comp_t *old_comps, *new_comps; diff --git a/src/lib/openjp2/tcd.c b/src/lib/openjp2/tcd.c index 4388819a..f44d3e96 100644 --- a/src/lib/openjp2/tcd.c +++ b/src/lib/openjp2/tcd.c @@ -1006,7 +1006,7 @@ OPJ_BOOL opj_tcd_code_block_enc_allocate (opj_tcd_cblk_enc_t * p_code_block) { if (! p_code_block->data) { - p_code_block->data = (OPJ_BYTE*) opj_malloc(OPJ_J2K_DEFAULT_CBLK_DATA_SIZE); //why +1 ? + p_code_block->data = (OPJ_BYTE*) opj_malloc(OPJ_J2K_DEFAULT_CBLK_DATA_SIZE); /*why +1 ?*/ if(! p_code_block->data) { return OPJ_FALSE; } From decace60dac7c83e1dbca3fe400adf1dbea4147f Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Sun, 2 Mar 2014 10:20:57 +0000 Subject: [PATCH 172/333] [trunk] Remove warning about -2147483648 (aka INT_MIN), causing this decimal constant is unsigned only in ISO C90 --- src/bin/jp2/convert.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index ce7ecf2e..d0f73130 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -1424,7 +1424,7 @@ static inline int clamp( const int value, const int prec, const int sgnd ) { if (prec <= 8) return CLAMP(value,-128,127); else if (prec <= 16) return CLAMP(value,-32768,32767); - else return CLAMP(value,-2147483648,2147483647); + else return CLAMP(value,-2147483647-1,2147483647); } else { From a149502c01d91bb598a154d3fcb08b71632fe579 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Sun, 2 Mar 2014 10:23:05 +0000 Subject: [PATCH 173/333] [trunk] Remove some simple warnings about var being set but not used --- src/bin/jp2/convert.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index d0f73130..059f4aec 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -109,10 +109,10 @@ static int tga_readheader(FILE *fp, unsigned int *bits_per_pixel, { int palette_size; unsigned char *tga ; - unsigned char id_len, cmap_type, image_type; + unsigned char id_len, /*cmap_type,*/ image_type; unsigned char pixel_depth, image_desc; - unsigned short cmap_index, cmap_len, cmap_entry_size; - unsigned short x_origin, y_origin, image_w, image_h; + unsigned short /*cmap_index,*/ cmap_len, cmap_entry_size; + unsigned short /*x_origin, y_origin,*/ image_w, image_h; if (!bits_per_pixel || !width || !height || !flip_image) return 0; @@ -124,15 +124,17 @@ static int tga_readheader(FILE *fp, unsigned int *bits_per_pixel, return 0 ; } id_len = (unsigned char)tga[0]; - cmap_type = (unsigned char)tga[1]; + /*cmap_type = (unsigned char)tga[1];*/ image_type = (unsigned char)tga[2]; - cmap_index = get_ushort(*(unsigned short*)(&tga[3])); + /*cmap_index = get_ushort(*(unsigned short*)(&tga[3]));*/ cmap_len = get_ushort(*(unsigned short*)(&tga[5])); cmap_entry_size = (unsigned char)tga[7]; +#if 0 x_origin = get_ushort(*(unsigned short*)(&tga[8])); y_origin = get_ushort(*(unsigned short*)(&tga[10])); +#endif image_w = get_ushort(*(unsigned short*)(&tga[12])); image_h = get_ushort(*(unsigned short*)(&tga[14])); pixel_depth = (unsigned char)tga[16]; @@ -406,7 +408,7 @@ opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters) { int imagetotga(opj_image_t * image, const char *outfile) { int width, height, bpp, x, y; OPJ_BOOL write_alpha; - int i, v, adjustR, adjustG, adjustB, fails; + int i, adjustR, adjustG, adjustB, fails; unsigned int alpha_channel; float r,g,b,a; unsigned char value; From 43382a9b9cfca89a0aea061f9901f194fa692485 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 3 Mar 2014 07:58:59 +0000 Subject: [PATCH 174/333] [trunk] Remove unused variables from test --- tests/test_tile_decoder.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/test_tile_decoder.c b/tests/test_tile_decoder.c index 7560af5f..700dab1c 100644 --- a/tests/test_tile_decoder.c +++ b/tests/test_tile_decoder.c @@ -172,7 +172,7 @@ int main (int argc, char *argv[]) OPJ_BYTE * l_data = (OPJ_BYTE *) malloc(1000); OPJ_BOOL l_go_on = OPJ_TRUE; OPJ_INT32 l_tile_x0=0, l_tile_y0=0 ; - OPJ_UINT32 l_tile_width=0, l_tile_height=0, l_nb_tiles_x=0, l_nb_tiles_y=0, l_nb_comps=0 ; + OPJ_UINT32 l_nb_comps=0 ; OPJ_INT32 l_current_tile_x0,l_current_tile_y0,l_current_tile_x1,l_current_tile_y1; int da_x0=0; From a68a3feb600cfd2f7df1fc80ce729f6173dc40fd Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 3 Mar 2014 08:17:20 +0000 Subject: [PATCH 175/333] [trunk] Remove deprecated functions (not called anywhere in the code base). Update issue 268 --- src/lib/openjp2/j2k.c | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 4ec94195..29d2a5c1 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -473,6 +473,7 @@ static OPJ_BOOL opj_j2k_read_cod ( opj_j2k_t *p_j2k, OPJ_UINT32 p_header_size, opj_event_mgr_t * p_manager); +#if 0 /** * Writes the COC marker (Coding style component) * @@ -485,6 +486,9 @@ static OPJ_BOOL opj_j2k_write_coc( opj_j2k_t *p_j2k, OPJ_UINT32 p_comp_no, opj_stream_private_t *p_stream, opj_event_mgr_t * p_manager ); +#endif + +#if 0 /** * Writes the COC marker (Coding style component) * @@ -499,6 +503,7 @@ static void opj_j2k_write_coc_in_memory(opj_j2k_t *p_j2k, OPJ_BYTE * p_data, OPJ_UINT32 * p_data_written, opj_event_mgr_t * p_manager ); +#endif /** * Gets the maximum size taken by a coc. @@ -541,6 +546,7 @@ static OPJ_BOOL opj_j2k_read_qcd ( opj_j2k_t *p_j2k, OPJ_BYTE * p_header_data, OPJ_UINT32 p_header_size, opj_event_mgr_t * p_manager ); +#if 0 /** * Writes the QCC marker (quantization component) * @@ -553,7 +559,9 @@ static OPJ_BOOL opj_j2k_write_qcc( opj_j2k_t *p_j2k, OPJ_UINT32 p_comp_no, opj_stream_private_t *p_stream, opj_event_mgr_t * p_manager ); +#endif +#if 0 /** * Writes the QCC marker (quantization component) * @@ -568,6 +576,7 @@ static void opj_j2k_write_qcc_in_memory(opj_j2k_t *p_j2k, OPJ_BYTE * p_data, OPJ_UINT32 * p_data_written, opj_event_mgr_t * p_manager ); +#endif /** * Gets the maximum size taken by a qcc. @@ -851,6 +860,7 @@ static OPJ_BOOL opj_j2k_write_eoc( opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, opj_event_mgr_t * p_manager ); +#if 0 /** * Reads a EOC marker (End Of Codestream) * @@ -861,6 +871,7 @@ static OPJ_BOOL opj_j2k_write_eoc( opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_read_eoc ( opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, opj_event_mgr_t * p_manager ); +#endif /** * Writes the CBD-MCT-MCC-MCO markers (Multi components transform) @@ -1044,6 +1055,7 @@ static OPJ_BOOL opj_j2k_read_cbd ( opj_j2k_t *p_j2k, OPJ_UINT32 p_header_size, opj_event_mgr_t * p_manager); +#if 0 /** * Writes COC marker for each component. * @@ -1054,7 +1066,9 @@ static OPJ_BOOL opj_j2k_read_cbd ( opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_write_all_coc( opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, opj_event_mgr_t * p_manager ); +#endif +#if 0 /** * Writes QCC marker for each component. * @@ -1065,6 +1079,7 @@ static OPJ_BOOL opj_j2k_write_all_coc( opj_j2k_t *p_j2k, static OPJ_BOOL opj_j2k_write_all_qcc( opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, opj_event_mgr_t * p_manager ); +#endif /** * Writes regions of interests. @@ -2456,6 +2471,7 @@ static OPJ_BOOL opj_j2k_read_cod ( opj_j2k_t *p_j2k, return OPJ_TRUE; } +#if 0 OPJ_BOOL opj_j2k_write_coc( opj_j2k_t *p_j2k, OPJ_UINT32 p_comp_no, opj_stream_private_t *p_stream, @@ -2500,7 +2516,9 @@ OPJ_BOOL opj_j2k_write_coc( opj_j2k_t *p_j2k, return OPJ_TRUE; } +#endif +#if 0 void opj_j2k_write_coc_in_memory( opj_j2k_t *p_j2k, OPJ_UINT32 p_comp_no, OPJ_BYTE * p_data, @@ -2545,6 +2563,7 @@ void opj_j2k_write_coc_in_memory( opj_j2k_t *p_j2k, opj_j2k_write_SPCod_SPCoc(p_j2k,p_j2k->m_current_tile_number,0,l_current_data,&l_remaining_size,p_manager); * p_data_written = l_coc_size; } +#endif OPJ_UINT32 opj_j2k_get_max_coc_size(opj_j2k_t *p_j2k) { @@ -2718,6 +2737,7 @@ static OPJ_BOOL opj_j2k_read_qcd ( opj_j2k_t *p_j2k, return OPJ_TRUE; } +#if 0 OPJ_BOOL opj_j2k_write_qcc( opj_j2k_t *p_j2k, OPJ_UINT32 p_comp_no, opj_stream_private_t *p_stream, @@ -2756,7 +2776,9 @@ OPJ_BOOL opj_j2k_write_qcc( opj_j2k_t *p_j2k, return OPJ_TRUE; } +#endif +#if 0 void opj_j2k_write_qcc_in_memory( opj_j2k_t *p_j2k, OPJ_UINT32 p_comp_no, OPJ_BYTE * p_data, @@ -2805,6 +2827,7 @@ void opj_j2k_write_qcc_in_memory( opj_j2k_t *p_j2k, *p_data_written = l_qcc_size; } +#endif OPJ_UINT32 opj_j2k_get_max_qcc_size (opj_j2k_t *p_j2k) { @@ -4677,6 +4700,7 @@ OPJ_BOOL opj_j2k_update_rates( opj_j2k_t *p_j2k, return OPJ_TRUE; } +#if 0 OPJ_BOOL opj_j2k_read_eoc ( opj_j2k_t *p_j2k, opj_stream_private_t *p_stream, opj_event_mgr_t * p_manager ) @@ -4725,6 +4749,7 @@ OPJ_BOOL opj_j2k_read_eoc ( opj_j2k_t *p_j2k, opj_tcd_destroy(l_tcd); return OPJ_TRUE; } +#endif OPJ_BOOL opj_j2k_get_end_header(opj_j2k_t *p_j2k, struct opj_stream_private *p_stream, @@ -4788,6 +4813,7 @@ OPJ_BOOL opj_j2k_write_mct_data_group( opj_j2k_t *p_j2k, return OPJ_TRUE; } +#if 0 OPJ_BOOL opj_j2k_write_all_coc(opj_j2k_t *p_j2k, struct opj_stream_private *p_stream, struct opj_event_mgr * p_manager ) @@ -4808,7 +4834,9 @@ OPJ_BOOL opj_j2k_write_all_coc(opj_j2k_t *p_j2k, return OPJ_TRUE; } +#endif +#if 0 OPJ_BOOL opj_j2k_write_all_qcc(opj_j2k_t *p_j2k, struct opj_stream_private *p_stream, struct opj_event_mgr * p_manager ) @@ -4829,6 +4857,7 @@ OPJ_BOOL opj_j2k_write_all_qcc(opj_j2k_t *p_j2k, return OPJ_TRUE; } +#endif OPJ_BOOL opj_j2k_write_regions( opj_j2k_t *p_j2k, From d14c475de7d759db4927c6004044bee8c2cf3510 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 3 Mar 2014 08:27:40 +0000 Subject: [PATCH 176/333] [trunk] Remove warning about unused function Update issue 268 --- src/bin/jpip/opj_jpip_transcode.c | 52 ++++++++++++++++++------------- 1 file changed, 30 insertions(+), 22 deletions(-) diff --git a/src/bin/jpip/opj_jpip_transcode.c b/src/bin/jpip/opj_jpip_transcode.c index 825c087a..64dc842d 100644 --- a/src/bin/jpip/opj_jpip_transcode.c +++ b/src/bin/jpip/opj_jpip_transcode.c @@ -46,24 +46,17 @@ static int jpip_to_jp2(int argc,char *argv[]) { jpip_dec_param_t *dec; - if( argc < 3){ - fprintf( stderr, "Too few arguments:\n"); - fprintf( stderr, " - input jpt or jpp file\n"); - fprintf( stderr, " - output jp2 file\n"); - return -1; - } - dec = init_jpipdecoder( OPJ_TRUE); if(!( fread_jpip( argv[1], dec))) - return -1; + return 1; decode_jpip( dec); if(!(fwrite_jp2k( argv[2], dec))) - return -1; + return 1; - output_log( OPJ_TRUE, OPJ_FALSE, OPJ_TRUE, dec); + /* output_log( OPJ_TRUE, OPJ_FALSE, OPJ_TRUE, dec); */ destroy_jpipdecoder( &dec); @@ -85,22 +78,15 @@ static int jpip_to_j2k(int argc,char *argv[]) { jpip_dec_param_t *dec; - if( argc < 3){ - fprintf( stderr, "Too few arguments:\n"); - fprintf( stderr, " - input jpt or jpp file\n"); - fprintf( stderr, " - output j2k file\n"); - return -1; - } - dec = init_jpipdecoder( OPJ_FALSE); if(!( fread_jpip( argv[1], dec))) - return -1; + return 1; decode_jpip( dec); - if(!( fwrite_jp2k( argv[2], dec))) - return -1; + if(!(fwrite_jp2k( argv[2], dec))) + return 1; /* output_log( OPJ_TRUE, OPJ_FALSE, OPJ_FALSE, dec); */ @@ -111,6 +97,28 @@ static int jpip_to_j2k(int argc,char *argv[]) int main(int argc,char *argv[]) { - /* MM: FIXME */ - return jpip_to_jp2(argc,argv); + char *ext; + if( argc < 3){ + fprintf( stderr, "Too few arguments:\n"); + fprintf( stderr, " - input jpt or jpp file\n"); + fprintf( stderr, " - output j2k file\n"); + return 1; + } + + ext = strrchr( argv[2], '.' ); + if( ext ) + { + // strcasecmp ? + if( strcmp(ext, ".jp2" ) == 0 ) + { + return jpip_to_jp2(argc,argv); + } + if( strcmp(ext, ".j2k" ) == 0 ) + { + return jpip_to_j2k(argc,argv); + } + } + + fprintf( stderr, "Invalid file extension for output file: %s\n", argv[2]); + return 1; } From 3c7a7a167550cfe9edebbbb7429aa8724f47edf2 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 3 Mar 2014 08:30:36 +0000 Subject: [PATCH 177/333] [trunk] Remove deprecated functions. Update issue 268 --- src/lib/openjp2/jp2.c | 4 ++++ src/lib/openjp2/t1.c | 9 ++++++++- 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c index 92a3726a..7aa38f04 100644 --- a/src/lib/openjp2/jp2.c +++ b/src/lib/openjp2/jp2.c @@ -2712,6 +2712,7 @@ static OPJ_BOOL opj_jpip_write_cidx(opj_jp2_t *jp2, return OPJ_TRUE; } +#if 0 static void write_prxy( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_stream_private_t *cio, opj_event_mgr_t * p_manager ) { @@ -2744,8 +2745,10 @@ static void write_prxy( int offset_jp2c, int length_jp2c, int offset_idx, int le opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_seek(cio, lenp+len,p_manager); } +#endif +#if 0 static int write_fidx( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_stream_private_t *cio, opj_event_mgr_t * p_manager ) { @@ -2767,4 +2770,5 @@ static int write_fidx( int offset_jp2c, int length_jp2c, int offset_idx, int len return len; } +#endif #endif /* USE_JPIP */ diff --git a/src/lib/openjp2/t1.c b/src/lib/openjp2/t1.c index 6e2b557f..240126c9 100644 --- a/src/lib/openjp2/t1.c +++ b/src/lib/openjp2/t1.c @@ -62,6 +62,7 @@ static void opj_t1_enc_sigpass_step(opj_t1_t *t1, /** Decode significant pass */ +#if 0 static void opj_t1_dec_sigpass_step(opj_t1_t *t1, opj_flag_t *flagsp, OPJ_INT32 *datap, @@ -69,6 +70,7 @@ static void opj_t1_dec_sigpass_step(opj_t1_t *t1, OPJ_INT32 oneplushalf, OPJ_BYTE type, OPJ_UINT32 vsc); +#endif static INLINE void opj_t1_dec_sigpass_step_raw( opj_t1_t *t1, @@ -161,6 +163,7 @@ static void opj_t1_dec_refpass_mqc_vsc( /** Decode refinement pass */ +#if 0 static void opj_t1_dec_refpass_step(opj_t1_t *t1, opj_flag_t *flagsp, OPJ_INT32 *datap, @@ -168,6 +171,7 @@ static void opj_t1_dec_refpass_step(opj_t1_t *t1, OPJ_INT32 neghalf, OPJ_BYTE type, OPJ_UINT32 vsc); +#endif static INLINE void opj_t1_dec_refpass_step_raw( opj_t1_t *t1, @@ -1678,6 +1682,7 @@ void opj_t1_encode_cblk(opj_t1_t *t1, } } +#if 0 void opj_t1_dec_refpass_step( opj_t1_t *t1, opj_flag_t *flagsp, OPJ_INT32 *datap, @@ -1705,9 +1710,11 @@ void opj_t1_dec_refpass_step( opj_t1_t *t1, *flagsp |= T1_REFINE; } } /* VSC and BYPASS by Antonin */ +#endif +#if 0 void opj_t1_dec_sigpass_step( opj_t1_t *t1, opj_flag_t *flagsp, OPJ_INT32 *datap, @@ -1741,4 +1748,4 @@ void opj_t1_dec_sigpass_step( opj_t1_t *t1, *flagsp |= T1_VISIT; } } /* VSC and BYPASS by Antonin */ - +#endif From 3ecccb7410d567a660bda84a538d9fd4ea0964b3 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 3 Mar 2014 08:45:21 +0000 Subject: [PATCH 178/333] [trunk] Fix md5 values for decode-md5 tests. Update issue 250 --- tests/nonregression/md5refs.txt | 52 ++++++++++++++++----------------- 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/tests/nonregression/md5refs.txt b/tests/nonregression/md5refs.txt index f9984b1a..7b7505cb 100644 --- a/tests/nonregression/md5refs.txt +++ b/tests/nonregression/md5refs.txt @@ -1,35 +1,35 @@ -71673036d224dedba4969aacb7a89316 _00042.j2k_0.pgx -3f4af6ee5b706a6d43a70fb78e5b0061 _00042.j2k_1.pgx -05e2676e5a1c8a61bdd8477fbbf5ab32 _00042.j2k_2.pgx -e3cd8edf8a8f1975f65ed0aae4ee5069 123.j2c_0.pgx +6f22c9a9bd474202ac6cd3a066e15200 _00042.j2k_0.pgx +a3a0606dfa0779d657c6a923b90e4678 _00042.j2k_1.pgx +106954dc468dfe0884d02268e91f9f5b _00042.j2k_2.pgx +8889def55f1e18dae6002b9b3a6dd152 123.j2c_0.pgx 4bddb9f5c5f437fe1053af4d61d9202e 1336.pdf.asan.47.376.jp2_0.pgx f38167b983f0de0ab77e71de291bf5c0 1336.pdf.asan.47.376.jp2_1.pgx d9a4feed1773b7b1ae5c20bdbdd37291 1336.pdf.asan.47.376.jp2_2.pgx 4a0daf7a9065101379eaebc28e436b1e Bretagne2.j2k_0.pgx 07578fc7bf81d3da694de8ae27308b82 Bretagne2.j2k_1.pgx 3690c42f83bad42f4abea48525d45e0e Bretagne2.j2k_2.pgx -e3cd8edf8a8f1975f65ed0aae4ee5069 bug.j2c_0.pgx -a4c4714bfd4f12ba6d2e81129205ce50 buxI.j2k_0.pgx -a7be45c89d53dd4beac927a7a1d4ed29 buxR.j2k_0.pgx -903b6d8166de3d39f70c7a924afb9887 Cannotreaddatawithnosizeknown.j2k_0.pgx +8889def55f1e18dae6002b9b3a6dd152 bug.j2c_0.pgx +22c8d33a956ba83079d1102457bc77a1 buxI.j2k_0.pgx +b8f473c07ba5ebfc195bdd53c3b3b97f buxR.j2k_0.pgx +05c062aca83d13b8095460f38a690a08 Cannotreaddatawithnosizeknown.j2k_0.pgx 6276da0ec5fac44d683d3468b290331d cthead1.j2k_0.pgx -79cee673f96a3c8ae00412927af283dc CT_Phillips_JPEG2K_Decompr_Problem.j2k_0.pgx +8afcac9a696cc8d753b0eb9f4ae692ff CT_Phillips_JPEG2K_Decompr_Problem.j2k_0.pgx 04d35ab6160c9029549f72358df984da file409752.jp2_0.pgx 2813bd6fdc2c306b91b3da3688b8bf49 file409752.jp2_1.pgx e273e2aaea4a4fc1b2cf7c09c53c3cc6 file409752.jp2_2.pgx -903b6d8166de3d39f70c7a924afb9887 illegalcolortransform.j2k_0.pgx +05c062aca83d13b8095460f38a690a08 illegalcolortransform.j2k_0.pgx cccccccccccccccccccccccccccccccc issue104_jpxstream.jp2_0.pgx -cb28787aa7c223f03e6acad71e244108 issue104_jpxstream.jp2_1.pgx -cb28787aa7c223f03e6acad71e244108 issue104_jpxstream.jp2_2.pgx +cccccccccccccccccccccccccccccccc issue104_jpxstream.jp2_1.pgx +cccccccccccccccccccccccccccccccc issue104_jpxstream.jp2_2.pgx c74edbb49e132b2cfc1eaf7908197b17 issue134.jp2_0.pgx 16fe8ed450da10a6aaae4cf6f467fc21 issue134.jp2_1.pgx c6091c07bf0ff221008dfb60d893cdff issue134.jp2_2.pgx cccccccccccccccccccccccccccccccc issue135.j2k_0.pgx cccccccccccccccccccccccccccccccc issue135.j2k_1.pgx cccccccccccccccccccccccccccccccc issue135.j2k_2.pgx -833cde271689e4690a7c96a621c3d067 issue142.j2k_0.pgx -50a38e56f388c94a1459db35907331ba issue142.j2k_1.pgx -a2df1b66dfa7eaac5f3b9c839c5b84cc issue142.j2k_2.pgx +619694e5674992b3286244bf13058f7c issue142.j2k_0.pgx +c675c4b77dc3cc2a0d6542a32b438a48 issue142.j2k_1.pgx +663ebdd12dd6a36915ea1152c43cb69a issue142.j2k_2.pgx 820b37ef934bd17d45dd73f5dc4d95b7 issue171.jp2_0.pgx 4596dcd3efa51f84824b60353e2af306 issue171.jp2_1.pgx c2a656096b1965c3b4a26563d6ade467 issue171.jp2_2.pgx @@ -49,18 +49,18 @@ bc5178a807be5901938d7f555275933f issue208.jp2_2.pgx 37546d44ecf7f2ea40a4f25d177910f3 issue208.jp2_3.pgx a0823d21d9de699353a3bd1adb23bd1c issue211.jp2_0.pgx 1820161df26c360a62d11800d6cf173f issue211.jp2_1.pgx -a442b31e2b7fd49a85a5afa6f6cd9a18 issue228.j2k_0.pgx +e1807db57b5f5192c4b77b83e8b5c477 issue228.j2k_0.pgx cccccccccccccccccccccccccccccccc issue254.jp2_0.pgx cccccccccccccccccccccccccccccccc issue254.jp2_1.pgx cccccccccccccccccccccccccccccccc issue254.jp2_2.pgx -5abdd78e99dcce6a7f4370140966eb89 j2k32.j2k_0.pgx -ab505e4ddc590b0410798af1cb2dbb40 j2k32.j2k_1.pgx -2eff0259c7e5a60981dc2daf25d69804 j2k32.j2k_2.pgx -cdc63501aa572e5dfc32ccec3499f436 kakadu_v4-4_openjpegv2_broken.j2k_0.pgx -de45172778ff18043e445615c112d0ba kodak_2layers_lrcp.j2c_0.pgx -1bd43cbf9639ee08b2945f2a27045618 kodak_2layers_lrcp.j2c_1.pgx -cbaa10e5a2a795a4552632910c16e81c kodak_2layers_lrcp.j2c_2.pgx -903b6d8166de3d39f70c7a924afb9887 MarkerIsNotCompliant.j2k_0.pgx +4093cc34d838780b35a8be410247fa7f j2k32.j2k_0.pgx +ce4e556aaa0844b92a92c35c200fc43e j2k32.j2k_1.pgx +ea926520f990640862f3fe6616097613 j2k32.j2k_2.pgx +66b60e866991e03f9a2de18e80d3102b kakadu_v4-4_openjpegv2_broken.j2k_0.pgx +12a8a4668315d9ae27969991251ce85f kodak_2layers_lrcp.j2c_0.pgx +56d0b0c547d6d5bb12f0c36e88722b11 kodak_2layers_lrcp.j2c_1.pgx +48ba092fb40090c160bbd08bdf7bdbf2 kodak_2layers_lrcp.j2c_2.pgx +05c062aca83d13b8095460f38a690a08 MarkerIsNotCompliant.j2k_0.pgx ff73d2bd32951d9e55b02186aac24aff Marrin.jp2_0.pgx 55ce884dd2346af6a5172a434ee578fa Marrin.jp2_1.pgx 41ec1a0228c703b10f95388c1160753b mem-b2b86b74-2753.jp2_0.pgx @@ -128,11 +128,11 @@ ce2de61ad83a71c9b13ca5df0a987a69 p1_06_3.j2k.png 85a2b9a1324d72a8cec7041f80529242 p1_06.j2k.png af083204299bbdd993286892b4c9cd29 p1_06.j2k_r4.png af083204299bbdd993286892b4c9cd29 p1_06.j2k_t0.png -b219d8a1338e9ce6ffd29dd076bbd28d pacs.ge.j2k_0.pgx +371aa0a7ff40a73b45f1fa41e210d1db pacs.ge.j2k_0.pgx 6ae110e1fb5a869af3dbc5fbc735b0bd relax.jp2_0.pgx 518a8f28dacc034982507f43763b88dd relax.jp2_1.pgx c678b04f4d3e59b9d66a8bce37c553c0 relax.jp2_2.pgx -921798f6d894a0a44df5082639ea968f test_lossless.j2k_0.pgx +cdb1d69eb48ffd8545751326b86d9d7e test_lossless.j2k_0.pgx a37e7e5811d7c0c7adb61582790ccd33 text_GBR.jp2_0.pgx fc2173be54954a146b4e2887ee14be06 text_GBR.jp2_1.pgx 14108b4fb8d9126750db0424417ed17d text_GBR.jp2_2.pgx From 9863d8d1d24f2331193d5a42473fbd2422debee8 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 3 Mar 2014 08:49:28 +0000 Subject: [PATCH 179/333] [trunk] Avoid conflicting declarion for fseek in openjp2 vs fseek in openjpip --- src/lib/openjp2/opj_includes.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/openjp2/opj_includes.h b/src/lib/openjp2/opj_includes.h index bdbb7c6c..346f3a3c 100644 --- a/src/lib/openjp2/opj_includes.h +++ b/src/lib/openjp2/opj_includes.h @@ -56,10 +56,12 @@ ftello() only on systems with special LFS support since some systems (e.g. FreeBSD) support a 64-bit off_t by default. */ +#if !defined(OPENJPIP_H_) && defined(SERVER) /* server implementation uses fcgi/fseek*/ #if defined(OPJ_HAVE_FSEEKO) # define fseek fseeko # define ftell ftello #endif +#endif #if defined(WIN32) && !defined(Windows95) && !defined(__BORLANDC__) && \ From 75715635e8554aba7df44cb945ca163732526cf7 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 3 Mar 2014 10:38:41 +0000 Subject: [PATCH 180/333] [trunk] Remove 3635.pdf.asan.77.2930.jp2 from opj_dump tests Update issue 250 --- tests/nonregression/CMakeLists.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/nonregression/CMakeLists.txt b/tests/nonregression/CMakeLists.txt index 11eb47af..33c17895 100644 --- a/tests/nonregression/CMakeLists.txt +++ b/tests/nonregression/CMakeLists.txt @@ -24,6 +24,7 @@ set(BLACKLIST_JPEG2000_TMP 0290cb77c5df21828fa74cf2ab2c84d8.SIGFPE.d25.31.jp2 26ccf3651020967f7778238ef5af08af.SIGFPE.d25.527.jp2 4035.pdf.SIGSEGV.d8b.3375.jp2 + 3635.pdf.asan.77.2930.jp2 ) # Define a list of file which should be gracefully rejected: From 339952c2af6332f46938e3824c70d3d5091bf474 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 3 Mar 2014 10:41:13 +0000 Subject: [PATCH 181/333] [trunk] Remove simple warnings --- src/bin/jpip/opj_jpip_transcode.c | 2 +- tests/comparePGXimages.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/jpip/opj_jpip_transcode.c b/src/bin/jpip/opj_jpip_transcode.c index 64dc842d..83232d67 100644 --- a/src/bin/jpip/opj_jpip_transcode.c +++ b/src/bin/jpip/opj_jpip_transcode.c @@ -108,7 +108,7 @@ int main(int argc,char *argv[]) ext = strrchr( argv[2], '.' ); if( ext ) { - // strcasecmp ? + /* strcasecmp ? */ if( strcmp(ext, ".jp2" ) == 0 ) { return jpip_to_jp2(argc,argv); diff --git a/tests/comparePGXimages.c b/tests/comparePGXimages.c index 5f629641..a495f548 100644 --- a/tests/comparePGXimages.c +++ b/tests/comparePGXimages.c @@ -68,7 +68,7 @@ static double* parseToleranceValues( char* inArg, const int nbcomp) free(outArgs); return NULL; } - // else + /* else */ return outArgs; } From 16febebd28aafe8a47472d669b399dded8f84c5e Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 3 Mar 2014 11:30:54 +0000 Subject: [PATCH 182/333] [trunk] Explicitely trigger issue 229, there may be an impact in code execution. The assert may get removed afterward Update issue 229 --- src/lib/openjp2/opj_intmath.h | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/openjp2/opj_intmath.h b/src/lib/openjp2/opj_intmath.h index 94512afc..73d08a28 100644 --- a/src/lib/openjp2/opj_intmath.h +++ b/src/lib/openjp2/opj_intmath.h @@ -102,6 +102,7 @@ Divide an integer and round upwards @return Returns a divided by b */ static INLINE OPJ_INT32 opj_int_ceildiv(OPJ_INT32 a, OPJ_INT32 b) { + assert(b); return (a + b - 1) / b; } From 25255c4ed1cb1974857189a2a5c67f878c923cc3 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 3 Mar 2014 11:36:31 +0000 Subject: [PATCH 183/333] [trunk] remove all api with invalid FILE* parameters which could leads to issues when applications are compiled with different flags from openjpeg. Fixes issue 198 --- src/lib/openjp2/openjpeg.c | 38 --------------------------- src/lib/openjp2/openjpeg.h | 18 ------------- src/lib/openjpip/jp2k_decoder.c | 6 ++--- src/lib/openjpip/jp2k_decoder.h | 2 +- src/lib/openjpip/jpipstream_manager.c | 27 ++++++++++++++----- 5 files changed, 24 insertions(+), 67 deletions(-) diff --git a/src/lib/openjp2/openjpeg.c b/src/lib/openjp2/openjpeg.c index 31199b24..957143f3 100644 --- a/src/lib/openjp2/openjpeg.c +++ b/src/lib/openjp2/openjpeg.c @@ -1029,49 +1029,11 @@ void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t **p_cstr_index) } } -/* ---------------------------------------------------------------------- */ -static opj_stream_t* opj_stream_create_file_stream_impl ( FILE * p_file, - OPJ_SIZE_T p_size, - OPJ_BOOL p_is_read_stream) -{ - opj_stream_t* l_stream = 00; - - if (! p_file) { - return NULL; - } - - l_stream = opj_stream_create(p_size,p_is_read_stream); - if (! l_stream) { - return NULL; - } - - opj_stream_set_user_data(l_stream, p_file); - opj_stream_set_user_data_length(l_stream, opj_get_data_length_from_file(p_file)); - opj_stream_set_read_function(l_stream, (opj_stream_read_fn) opj_read_from_file); - opj_stream_set_write_function(l_stream, (opj_stream_write_fn) opj_write_from_file); - opj_stream_set_skip_function(l_stream, (opj_stream_skip_fn) opj_skip_from_file); - opj_stream_set_seek_function(l_stream, (opj_stream_seek_fn) opj_seek_from_file); - - return l_stream; -} - -opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file, OPJ_BOOL p_is_read_stream) -{ - return opj_stream_create_file_stream_impl(p_file,OPJ_J2K_STREAM_CHUNK_SIZE,p_is_read_stream); -} - opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream_v3 (const char *fname, OPJ_BOOL p_is_read_stream) { return opj_stream_create_file_stream_v3(fname, OPJ_J2K_STREAM_CHUNK_SIZE, p_is_read_stream); } -opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream ( FILE * p_file, - OPJ_SIZE_T p_size, - OPJ_BOOL p_is_read_stream) -{ - return opj_stream_create_file_stream_impl(p_file,p_size,p_is_read_stream); -} - opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream_v3 ( const char *fname, OPJ_SIZE_T p_size, diff --git a/src/lib/openjp2/openjpeg.h b/src/lib/openjp2/openjpeg.h index 338a771d..8170f7a4 100644 --- a/src/lib/openjp2/openjpeg.h +++ b/src/lib/openjp2/openjpeg.h @@ -1060,14 +1060,6 @@ OPJ_API void OPJ_CALLCONV opj_stream_set_user_data (opj_stream_t* p_stream, void */ OPJ_API void OPJ_CALLCONV opj_stream_set_user_data_length(opj_stream_t* p_stream, OPJ_UINT64 data_length); -/** - * Helper function. - * Sets the stream to be a file stream. The FILE must have been open previously. - * @param p_file the file stream to operate on - * @param p_is_read_stream whether the stream is a read stream (true) or not (false) -*/ -OPJ_DEPRECATED(OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file, OPJ_BOOL p_is_read_stream)); - /** * Create a stream from a file identified with its filename with default parameters (helper function) * @param fname the filename of the file to stream @@ -1075,16 +1067,6 @@ OPJ_DEPRECATED(OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file */ OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream_v3 (const char *fname, OPJ_BOOL p_is_read_stream); -/** - * FIXME DOC - * @param p_file the file stream to operate on - * @param p_buffer_size size of the chunk used to stream - * @param p_is_read_stream whether the stream is a read stream (true) or not (false) -*/ -OPJ_DEPRECATED(OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (FILE * p_file, - OPJ_SIZE_T p_buffer_size, - OPJ_BOOL p_is_read_stream)); - /** Create a stream from a file identified with its filename with a specific buffer size * @param fname the filename of the file to stream * @param p_buffer_size size of the chunk used to stream diff --git a/src/lib/openjpip/jp2k_decoder.c b/src/lib/openjpip/jp2k_decoder.c index 9bbfe00d..a1878adc 100644 --- a/src/lib/openjpip/jp2k_decoder.c +++ b/src/lib/openjpip/jp2k_decoder.c @@ -43,7 +43,7 @@ static void info_callback(const char *msg, void *client_data); static Byte_t * imagetopnm(opj_image_t *image, ihdrbox_param_t **ihdrbox); -Byte_t * j2k_to_pnm( FILE *fp, ihdrbox_param_t **ihdrbox) +Byte_t * j2k_to_pnm( const char *fn, ihdrbox_param_t **ihdrbox) { Byte_t *pnmstream = NULL; opj_dparameters_t parameters; /* decompression parameters */ @@ -51,13 +51,11 @@ Byte_t * j2k_to_pnm( FILE *fp, ihdrbox_param_t **ihdrbox) opj_codec_t *l_codec = NULL; /* handle to a decompressor */ opj_stream_t *l_stream = NULL; - - /* set decoding parameters to default values */ opj_set_default_decoder_parameters(¶meters); /* set a byte stream */ - l_stream = opj_stream_create_default_file_stream( fp, 1); + l_stream = opj_stream_create_default_file_stream_v3( fn, OPJ_TRUE); if (!l_stream){ fprintf(stderr, "ERROR -> failed to create the stream from the file\n"); return NULL; diff --git a/src/lib/openjpip/jp2k_decoder.h b/src/lib/openjpip/jp2k_decoder.h index a53b1537..7fc8e961 100644 --- a/src/lib/openjpip/jp2k_decoder.h +++ b/src/lib/openjpip/jp2k_decoder.h @@ -34,6 +34,6 @@ #include "byte_manager.h" #include "ihdrbox_manager.h" -Byte_t * j2k_to_pnm( FILE *fp, ihdrbox_param_t **ihdrbox); +Byte_t * j2k_to_pnm( const char *fn, ihdrbox_param_t **ihdrbox); #endif /* !JP2K_DECODER_H_ */ diff --git a/src/lib/openjpip/jpipstream_manager.c b/src/lib/openjpip/jpipstream_manager.c index 3227af75..6649129c 100644 --- a/src/lib/openjpip/jpipstream_manager.c +++ b/src/lib/openjpip/jpipstream_manager.c @@ -76,19 +76,34 @@ Byte_t * jpipstream_to_pnm( Byte_t *jpipstream, msgqueue_param_t *msgqueue, Byte Byte_t *pnmstream; Byte_t *j2kstream; /* j2k or jp2 codestream */ Byte8_t j2klen; + size_t retlen; FILE *fp; const char j2kfname[] = "tmp.j2k"; - j2kstream = recons_j2k( msgqueue, jpipstream, csn, fw, fh, &j2klen); - fp = fopen( j2kfname, "w+b"); - fwrite( j2kstream, j2klen, 1, fp); + if( !fp ) + { + return NULL; + } + j2kstream = recons_j2k( msgqueue, jpipstream, csn, fw, fh, &j2klen); + if( !j2kstream ) + { + fclose(fp); + remove( j2kfname); + return NULL; + } + + retlen = fwrite( j2kstream, 1, j2klen, fp); opj_free( j2kstream); - fseek( fp, 0, SEEK_SET); + fclose(fp); + if( retlen != j2klen ) + { + remove( j2kfname); + return NULL; + } - pnmstream = j2k_to_pnm( fp, ihdrbox); + pnmstream = j2k_to_pnm( j2kfname, ihdrbox); - fclose( fp); remove( j2kfname); return pnmstream; From b330c104924b377f60846cdcc87659607d3a848c Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 3 Mar 2014 11:40:59 +0000 Subject: [PATCH 184/333] [trunk] remove some simple warnings about unused params --- src/bin/jp2/convert.c | 1 + src/bin/jpip/opj_jpip_transcode.c | 8 ++++---- tests/unit/testempty0.c | 6 +++++- 3 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index 059f4aec..9baf5723 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -3053,6 +3053,7 @@ static int imagetoraw_common(opj_image_t * image, const char *outfile, OPJ_BOOL int line, row, curr, mask; int *ptr; unsigned char uc; + (void)big_endian; if((image->numcomps * image->x1 * image->y1) == 0) { diff --git a/src/bin/jpip/opj_jpip_transcode.c b/src/bin/jpip/opj_jpip_transcode.c index 83232d67..6776f1a6 100644 --- a/src/bin/jpip/opj_jpip_transcode.c +++ b/src/bin/jpip/opj_jpip_transcode.c @@ -42,7 +42,7 @@ * or * % ./jpip_to_jp2 input.jpp output.jp2 */ -static int jpip_to_jp2(int argc,char *argv[]) +static int jpip_to_jp2(char *argv[]) { jpip_dec_param_t *dec; @@ -74,7 +74,7 @@ static int jpip_to_jp2(int argc,char *argv[]) * or * % ./jpip_to_j2k input.jpp output.j2k */ -static int jpip_to_j2k(int argc,char *argv[]) +static int jpip_to_j2k(char *argv[]) { jpip_dec_param_t *dec; @@ -111,11 +111,11 @@ int main(int argc,char *argv[]) /* strcasecmp ? */ if( strcmp(ext, ".jp2" ) == 0 ) { - return jpip_to_jp2(argc,argv); + return jpip_to_jp2(argv); } if( strcmp(ext, ".j2k" ) == 0 ) { - return jpip_to_j2k(argc,argv); + return jpip_to_j2k(argv); } } diff --git a/tests/unit/testempty0.c b/tests/unit/testempty0.c index 8edd2a6c..09850604 100644 --- a/tests/unit/testempty0.c +++ b/tests/unit/testempty0.c @@ -1,3 +1,7 @@ #include "openjpeg.h" -int main(int argc, char **argv) { return 0; } +int main(int argc, char **argv) { + (void)argc; + (void)argv; + return 0; +} From 18049fe3e0dadd6765f030e71d647d6865e8625d Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 3 Mar 2014 11:48:27 +0000 Subject: [PATCH 185/333] [trunk] Import left over from patch submitted as issue 225 (comment #14) Update issue 225 --- src/lib/openjp2/opj_malloc.h | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/lib/openjp2/opj_malloc.h b/src/lib/openjp2/opj_malloc.h index aef2ee3b..95ad1472 100644 --- a/src/lib/openjp2/opj_malloc.h +++ b/src/lib/openjp2/opj_malloc.h @@ -48,8 +48,13 @@ Allocate an uninitialized memory block #ifdef ALLOC_PERF_OPT void * OPJ_CALLCONV opj_malloc(size_t size); #else +/* prevent assertion on overflow for MSVC */ +#ifdef _MSC_VER +#define opj_malloc(size) ((size_t)(size) >= (size_t)-0x100 ? NULL : malloc(size)) +#else #define opj_malloc(size) malloc(size) #endif +#endif /** Allocate a memory block with elements initialized to 0 @@ -60,8 +65,13 @@ Allocate a memory block with elements initialized to 0 #ifdef ALLOC_PERF_OPT void * OPJ_CALLCONV opj_calloc(size_t _NumOfElements, size_t _SizeOfElements); #else +/* prevent assertion on overflow for MSVC */ +#ifdef _MSC_VER +#define opj_calloc(num, size) ((size_t)(num) != 0 && (size_t)(num) >= (size_t)-0x100 / (size_t)(size) ? NULL : calloc(num, size)) +#else #define opj_calloc(num, size) calloc(num, size) #endif +#endif /** Allocate memory aligned to a 16 byte boundry @@ -139,8 +149,13 @@ Reallocate memory blocks. #ifdef ALLOC_PERF_OPT void * OPJ_CALLCONV opj_realloc(void * m, size_t s); #else +/* prevent assertion on overflow for MSVC */ +#ifdef _MSC_VER +#define opj_realloc(m, s) ((size_t)(s) >= (size_t)-0x100 ? NULL : realloc(m, s)) +#else #define opj_realloc(m, s) realloc(m, s) #endif +#endif /** Deallocates or frees a memory block. From 11f402b44ae63295663737e355d1319b6e50f84b Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 3 Mar 2014 12:00:24 +0000 Subject: [PATCH 186/333] [trunk] Remove easy to fix warnings about conversion --- src/bin/common/color.c | 3 ++- src/bin/jp2/opj_decompress.c | 2 +- src/lib/openjp2/dwt.c | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bin/common/color.c b/src/bin/common/color.c index f18eb801..6cb98497 100644 --- a/src/bin/common/color.c +++ b/src/bin/common/color.c @@ -388,7 +388,8 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. " if(image->numcomps > 2)/* RGB, RGBA */ { unsigned short *inbuf, *outbuf, *in, *out; - max = max_w * max_h; nr_samples = max * 3 * sizeof(unsigned short); + max = max_w * max_h; + nr_samples = (cmsUInt32Number)(max * 3 * sizeof(unsigned short)); in = inbuf = (unsigned short*)malloc(nr_samples); out = outbuf = (unsigned short*)malloc(nr_samples); diff --git a/src/bin/jp2/opj_decompress.c b/src/bin/jp2/opj_decompress.c index b2e4e83c..dd1a0775 100644 --- a/src/bin/jp2/opj_decompress.c +++ b/src/bin/jp2/opj_decompress.c @@ -271,7 +271,7 @@ static int infile_format(const char *fname) const char *s, *magic_s; int ext_format, magic_format; unsigned char buf[12]; - unsigned int l_nb_read; + OPJ_SIZE_T l_nb_read; reader = fopen(fname, "rb"); diff --git a/src/lib/openjp2/dwt.c b/src/lib/openjp2/dwt.c index 7d87a9f8..c617ffcf 100644 --- a/src/lib/openjp2/dwt.c +++ b/src/lib/openjp2/dwt.c @@ -404,7 +404,7 @@ INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_tcd_tilecomp_t * tilec,void (*p_fun rw = l_cur_res->x1 - l_cur_res->x0; rh = l_cur_res->y1 - l_cur_res->y0; - l_data_size = opj_dwt_max_resolution( tilec->resolutions,tilec->numresolutions) * sizeof(OPJ_INT32); + l_data_size = opj_dwt_max_resolution( tilec->resolutions,tilec->numresolutions) * (OPJ_UINT32)sizeof(OPJ_INT32); bj = (OPJ_INT32*)opj_malloc(l_data_size); if (! bj) { return OPJ_FALSE; From e92fe4c1a481dac441993e49ffde59443d388922 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 3 Mar 2014 12:01:36 +0000 Subject: [PATCH 187/333] [trunk] Remove warning about cast double -> int. Instead use bit-shifting (compile time computation) --- src/lib/openjpip/j2kheader_manager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/openjpip/j2kheader_manager.c b/src/lib/openjpip/j2kheader_manager.c index 7b78368d..e8422573 100644 --- a/src/lib/openjpip/j2kheader_manager.c +++ b/src/lib/openjpip/j2kheader_manager.c @@ -139,7 +139,7 @@ CODmarker_param_t get_CODmkrdata_from_j2kstream( Byte_t *CODstream) else{ COD.XPsiz = (Byte4_t *)opj_malloc( sizeof(Byte4_t)); COD.YPsiz = (Byte4_t *)opj_malloc( sizeof(Byte4_t)); - COD.XPsiz[0] = COD.YPsiz[0] = pow(2,15); + COD.XPsiz[0] = COD.YPsiz[0] = 1<<15; /*pow(2,15)*/ } return COD; } From 80c510601512841f73e5872b9b6525dcb93dcfc7 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 3 Mar 2014 12:11:53 +0000 Subject: [PATCH 188/333] [trunk] fgets takes an int as parameter --- tests/compare_dump_files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/compare_dump_files.c b/tests/compare_dump_files.c index 6bc5145b..61048c97 100644 --- a/tests/compare_dump_files.c +++ b/tests/compare_dump_files.c @@ -187,7 +187,7 @@ int main(int argc, char **argv) if(chbase != chtest) { - size_t nbytes = 2048; + int nbytes = 2048; int CRLF_shift=1; char *strbase, *strtest, *strbase_d, *strtest_d; From 171ec1583d19827c52429fa1ddfed0b359468b4f Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 3 Mar 2014 12:13:11 +0000 Subject: [PATCH 189/333] [trunk] Remove some simple warnings about conversion --- src/lib/openjp2/invert.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/openjp2/invert.c b/src/lib/openjp2/invert.c index 5e2d6614..92de0a85 100644 --- a/src/lib/openjp2/invert.c +++ b/src/lib/openjp2/invert.c @@ -67,8 +67,8 @@ OPJ_BOOL opj_matrix_inversion_f(OPJ_FLOAT32 * pSrcMatrix, OPJ_UINT32 nb_compo) { OPJ_BYTE * l_data = 00; - OPJ_UINT32 l_permutation_size = nb_compo * sizeof(OPJ_UINT32); - OPJ_UINT32 l_swap_size = nb_compo * sizeof(OPJ_FLOAT32); + OPJ_UINT32 l_permutation_size = nb_compo * (OPJ_UINT32)sizeof(OPJ_UINT32); + OPJ_UINT32 l_swap_size = nb_compo * (OPJ_UINT32)sizeof(OPJ_FLOAT32); OPJ_UINT32 l_total_size = l_permutation_size + 3 * l_swap_size; OPJ_UINT32 * lPermutations = 00; OPJ_FLOAT32 * l_double_data = 00; @@ -109,7 +109,7 @@ OPJ_BOOL opj_lupDecompose(OPJ_FLOAT32 * matrix,OPJ_UINT32 * permutations, OPJ_UINT32 i,j,k; OPJ_FLOAT32 p; OPJ_UINT32 lLastColum = nb_compo - 1; - OPJ_UINT32 lSwapSize = nb_compo * sizeof(OPJ_FLOAT32); + OPJ_UINT32 lSwapSize = nb_compo * (OPJ_UINT32)sizeof(OPJ_FLOAT32); OPJ_FLOAT32 * lTmpMatrix = matrix; OPJ_FLOAT32 * lColumnMatrix,* lDestMatrix; OPJ_UINT32 offset = 1; @@ -272,7 +272,7 @@ void opj_lupInvert (OPJ_FLOAT32 * pSrcMatrix, OPJ_UINT32 j,i; OPJ_FLOAT32 * lCurrentPtr; OPJ_FLOAT32 * lLineMatrix = pDestMatrix; - OPJ_UINT32 lSwapSize = nb_compo * sizeof(OPJ_FLOAT32); + OPJ_UINT32 lSwapSize = nb_compo * (OPJ_UINT32)sizeof(OPJ_FLOAT32); for (j = 0; j < nb_compo; ++j) { lCurrentPtr = lLineMatrix++; From 74600cfb1489033cadfc1125062c695ebf8980b9 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 3 Mar 2014 15:47:23 +0000 Subject: [PATCH 190/333] [trunk] Review warning about types conversion, and add cast when needed --- src/lib/openjp2/jp2.c | 54 ++++++++++++++++++++++--------------------- 1 file changed, 28 insertions(+), 26 deletions(-) diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c index 7aa38f04..01fcf8da 100644 --- a/src/lib/openjp2/jp2.c +++ b/src/lib/openjp2/jp2.c @@ -442,7 +442,7 @@ static void opj_jp2_setup_header_reading (opj_jp2_t *jp2); assert(p_number_bytes_read != 00); assert(p_manager != 00); - *p_number_bytes_read = opj_stream_read_data(cio,l_data_header,8,p_manager); + *p_number_bytes_read = (OPJ_UINT32)opj_stream_read_data(cio,l_data_header,8,p_manager); if (*p_number_bytes_read != 8) { return OPJ_FALSE; } @@ -451,10 +451,12 @@ static void opj_jp2_setup_header_reading (opj_jp2_t *jp2); opj_read_bytes(l_data_header,&(box->length), 4); opj_read_bytes(l_data_header+4,&(box->type), 4); - if(box->length == 0)/* last box */ + if(box->length == 0)/* last box */ { - box->length = opj_stream_get_number_byte_left(cio); - return OPJ_TRUE; + const OPJ_OFF_T bleft = opj_stream_get_number_byte_left(cio); + box->length = (OPJ_UINT32)bleft; + assert( (OPJ_OFF_T)box->length == bleft ); + return OPJ_TRUE; } /* do we have a "special very large box ?" */ @@ -462,7 +464,7 @@ static void opj_jp2_setup_header_reading (opj_jp2_t *jp2); if (box->length == 1) { OPJ_UINT32 l_xl_part_size; - OPJ_UINT32 l_nb_bytes_read = opj_stream_read_data(cio,l_data_header,8,p_manager); + OPJ_UINT32 l_nb_bytes_read = (OPJ_UINT32)opj_stream_read_data(cio,l_data_header,8,p_manager); if (l_nb_bytes_read != 8) { if (l_nb_bytes_read > 0) { *p_number_bytes_read += l_nb_bytes_read; @@ -973,8 +975,8 @@ OPJ_BOOL opj_jp2_read_pclr( opj_jp2_t *jp2, opj_read_bytes(p_pclr_header_data, &l_value , 1); /* Bi */ ++p_pclr_header_data; - channel_size[i] = (l_value & 0x7f) + 1; - channel_sign[i] = (l_value & 0x80)? 1 : 0; + channel_size[i] = (OPJ_BYTE)((l_value & 0x7f) + 1); + channel_sign[i] = (l_value & 0x80) ? 1 : 0; } for(j = 0; j < nr_entries; ++j) { @@ -1074,24 +1076,24 @@ void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color) info = color->jp2_cdef->info; n = color->jp2_cdef->n; - for(i = 0; i < n; ++i) - { - /* WATCH: acn = asoc - 1 ! */ + for(i = 0; i < n; ++i) + { + /* WATCH: acn = asoc - 1 ! */ asoc = info[i].asoc; - if(asoc == 0 || asoc == 65535) - { - if (i < image->numcomps) - image->comps[i].alpha = info[i].typ; - continue; - } + if(asoc == 0 || asoc == 65535) + { + if (i < image->numcomps) + image->comps[i].alpha = info[i].typ; + continue; + } - cn = info[i].cn; - acn = asoc - 1; - if( cn >= image->numcomps || acn >= image->numcomps ) - { - fprintf(stderr, "cn=%d, acn=%d, numcomps=%d\n", cn, acn, image->numcomps); - continue; - } + cn = info[i].cn; + acn = (OPJ_INT16)(asoc - 1); + if( cn >= image->numcomps || acn >= image->numcomps ) + { + fprintf(stderr, "cn=%d, acn=%d, numcomps=%d\n", cn, acn, image->numcomps); + continue; + } if(cn != acn) { @@ -1101,8 +1103,8 @@ void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color) memcpy(&image->comps[cn], &image->comps[acn], sizeof(opj_image_comp_t)); memcpy(&image->comps[acn], &saved, sizeof(opj_image_comp_t)); - info[i].asoc = cn + 1; - info[acn].asoc = info[acn].cn + 1; + info[i].asoc = (OPJ_UINT16)(cn + 1); + info[acn].asoc = (OPJ_UINT16)(info[acn].cn + 1); } image->comps[cn].alpha = info[i].typ; @@ -1848,7 +1850,7 @@ OPJ_BOOL opj_jp2_read_header_procedure( opj_jp2_t *jp2, l_last_data_size = l_current_data_size; } - l_nb_bytes_read = opj_stream_read_data(stream,l_current_data,l_current_data_size,p_manager); + l_nb_bytes_read = (OPJ_UINT32)opj_stream_read_data(stream,l_current_data,l_current_data_size,p_manager); if (l_nb_bytes_read != l_current_data_size) { opj_event_msg(p_manager, EVT_ERROR, "Problem with reading JPEG2000 box, stream error\n"); opj_free(l_current_data); From b1b17ee264461b58ad1d04c883300cffdae020e9 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 3 Mar 2014 15:55:06 +0000 Subject: [PATCH 191/333] [trunk] Prefer compile time constant to avoid conversion double -> int --- src/lib/openjpip/index_manager.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/openjpip/index_manager.c b/src/lib/openjpip/index_manager.c index 5ca3f043..573deb26 100644 --- a/src/lib/openjpip/index_manager.c +++ b/src/lib/openjpip/index_manager.c @@ -646,7 +646,7 @@ OPJ_BOOL set_CODmkrdata( markeridx_param_t *codmkidx, codestream_param_t codestr COD->XPsiz = (Byte4_t *)opj_malloc( sizeof(Byte4_t)); COD->YPsiz = (Byte4_t *)opj_malloc( sizeof(Byte4_t)); - COD->XPsiz[0] = COD->YPsiz[0] = pow(2,15); + COD->XPsiz[0] = COD->YPsiz[0] = 1 << 15; /* pow(2,15); */ } return OPJ_TRUE; } From 24eca792ff2e70df7667ad43b415bd58f75a3a94 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 3 Mar 2014 15:55:27 +0000 Subject: [PATCH 192/333] [trunk] Remove some more warnings about conversion --- src/lib/openjp2/mct.c | 2 +- src/lib/openjp2/raw.c | 4 +++- src/lib/openjp2/tgt.c | 4 ++-- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/lib/openjp2/mct.c b/src/lib/openjp2/mct.c index 5e933ce5..d2754dc2 100644 --- a/src/lib/openjp2/mct.c +++ b/src/lib/openjp2/mct.c @@ -230,7 +230,7 @@ OPJ_BOOL opj_mct_encode_custom( lCurrentMatrix = lCurrentData + pNbComp; for (i =0;ibp - raw->start; + const ptrdiff_t diff = raw->bp - raw->start; + assert( diff <= 0xffffffff && diff >= 0 ); /* UINT32_MAX */ + return (OPJ_UINT32)diff; } void opj_raw_init_dec(opj_raw_t *raw, OPJ_BYTE *bp, OPJ_UINT32 len) { diff --git a/src/lib/openjp2/tgt.c b/src/lib/openjp2/tgt.c index 6fd85587..81b05482 100644 --- a/src/lib/openjp2/tgt.c +++ b/src/lib/openjp2/tgt.c @@ -87,7 +87,7 @@ opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv) { return 00; } memset(tree->nodes,0,tree->numnodes * sizeof(opj_tgt_node_t)); - tree->nodes_size = tree->numnodes * sizeof(opj_tgt_node_t); + tree->nodes_size = tree->numnodes * (OPJ_UINT32)sizeof(opj_tgt_node_t); node = tree->nodes; l_parent_node = &tree->nodes[tree->numleafsh * tree->numleafsv]; @@ -166,7 +166,7 @@ opj_tgt_tree_t *opj_tgt_init(opj_tgt_tree_t * p_tree,OPJ_UINT32 p_num_leafs_h, O opj_tgt_destroy(p_tree); return 00; } - l_node_size = p_tree->numnodes * sizeof(opj_tgt_node_t); + l_node_size = p_tree->numnodes * (OPJ_UINT32)sizeof(opj_tgt_node_t); if (l_node_size > p_tree->nodes_size) { opj_tgt_node_t* new_nodes = (opj_tgt_node_t*) opj_realloc(p_tree->nodes, l_node_size); From 765c4ab4f48e5bb9b02b8860400587e1ce97d9a5 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 3 Mar 2014 16:02:16 +0000 Subject: [PATCH 193/333] [trunk] rework code to avoid a warning. this also remove a division and prefer bit-shift --- src/lib/openjp2/t2.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c index 6aee8c72..0bda8be0 100644 --- a/src/lib/openjp2/t2.c +++ b/src/lib/openjp2/t2.c @@ -547,8 +547,13 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, c[1] = 145; c[2] = 0; c[3] = 4; +#if 0 c[4] = (tile->packno % 65536) / 256; c[5] = (tile->packno % 65536) % 256; +#else + c[4] = (tile->packno >> 8) & 0xff; /* packno is uint32_t */ + c[5] = tile->packno & 0xff; +#endif c += 6; length -= 6; } From 7afad19c7745cf7e1db6ab8961a90a89b2f654c2 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 3 Mar 2014 16:02:36 +0000 Subject: [PATCH 194/333] [trunk] Remove a simple warning about int -> float conversion --- src/lib/openjp2/t1.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/openjp2/t1.c b/src/lib/openjp2/t1.c index 240126c9..8fde5488 100644 --- a/src/lib/openjp2/t1.c +++ b/src/lib/openjp2/t1.c @@ -1331,7 +1331,7 @@ OPJ_BOOL opj_t1_decode_cblks( opj_t1_t* t1, for (j = 0; j < cblk_h; ++j) { OPJ_FLOAT32* restrict tiledp2 = tiledp; for (i = 0; i < cblk_w; ++i) { - OPJ_FLOAT32 tmp = *datap * band->stepsize; + OPJ_FLOAT32 tmp = (OPJ_FLOAT32)*datap * band->stepsize; *tiledp2 = tmp; datap++; tiledp2++; From 44ca89eff7f6054bfdc8f7e688eda3a343569c21 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 3 Mar 2014 16:08:03 +0000 Subject: [PATCH 195/333] [trunk] Remove remainings conversion issues in t2.c + clock.c --- src/lib/openjp2/opj_clock.c | 4 ++-- src/lib/openjp2/t2.c | 17 +++++++++-------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/src/lib/openjp2/opj_clock.c b/src/lib/openjp2/opj_clock.c index dbbf6e0a..5f2ab9dc 100644 --- a/src/lib/openjp2/opj_clock.c +++ b/src/lib/openjp2/opj_clock.c @@ -51,9 +51,9 @@ OPJ_FLOAT64 opj_clock(void) { getrusage(0,&t); /* (2) What is the elapsed time ? - CPU time = User time + System time */ /* (2a) Get the seconds */ - procTime = t.ru_utime.tv_sec + t.ru_stime.tv_sec; + procTime = (OPJ_FLOAT64)(t.ru_utime.tv_sec + t.ru_stime.tv_sec); /* (2b) More precisely! Get the microseconds part ! */ - return ( procTime + (t.ru_utime.tv_usec + t.ru_stime.tv_usec) * 1e-6 ) ; + return ( procTime + (OPJ_FLOAT64)(t.ru_utime.tv_usec + t.ru_stime.tv_usec) * 1e-6 ) ; #endif } diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c index 0bda8be0..480944de 100644 --- a/src/lib/openjp2/t2.c +++ b/src/lib/openjp2/t2.c @@ -676,7 +676,7 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, return OPJ_FALSE; /* modified to eliminate longjmp !! */ } - l_nb_bytes = opj_bio_numbytes(bio); + l_nb_bytes = (OPJ_UINT32)opj_bio_numbytes(bio); c += l_nb_bytes; length -= l_nb_bytes; @@ -740,7 +740,8 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, ++band; } - * p_data_written += (c - dest); + assert( c >= dest ); + * p_data_written += (OPJ_UINT32)(c - dest); return OPJ_TRUE; } @@ -876,7 +877,7 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, else { /* Normal Case */ l_header_data_start = &(l_current_data); l_header_data = *l_header_data_start; - l_remaining_length = p_src_data+p_max_length-l_header_data; + l_remaining_length = (OPJ_UINT32)(p_src_data+p_max_length-l_header_data); l_modified_length_ptr = &(l_remaining_length); } @@ -900,7 +901,7 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, } } - l_header_length = (l_header_data - *l_header_data_start); + l_header_length = (OPJ_UINT32)(l_header_data - *l_header_data_start); *l_modified_length_ptr -= l_header_length; *l_header_data_start += l_header_length; @@ -913,7 +914,7 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, /* INDEX >> */ * p_is_data_present = OPJ_FALSE; - *p_data_read = l_current_data - p_src_data; + *p_data_read = (OPJ_UINT32)(l_current_data - p_src_data); return OPJ_TRUE; } @@ -1026,7 +1027,7 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, } } - l_header_length = (l_header_data - *l_header_data_start); + l_header_length = (OPJ_UINT32)(l_header_data - *l_header_data_start); *l_modified_length_ptr -= l_header_length; *l_header_data_start += l_header_length; @@ -1039,7 +1040,7 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, /* INDEX >> */ *p_is_data_present = OPJ_TRUE; - *p_data_read = l_current_data - p_src_data; + *p_data_read = (OPJ_UINT32)(l_current_data - p_src_data); return OPJ_TRUE; } @@ -1162,7 +1163,7 @@ OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2, ++l_band; } - *(p_data_read) = l_current_data - p_src_data; + *(p_data_read) = (OPJ_UINT32)(l_current_data - p_src_data); return OPJ_TRUE; } From d643ff5dbc192375e2b3f3e3aa210f64399c2b95 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 3 Mar 2014 16:11:41 +0000 Subject: [PATCH 196/333] [trunk] Remove remaining conversion issues in mqc.c --- src/lib/openjp2/mqc.c | 16 +++++++++------- src/lib/openjp2/openjpeg.c | 4 ++-- 2 files changed, 11 insertions(+), 9 deletions(-) diff --git a/src/lib/openjp2/mqc.c b/src/lib/openjp2/mqc.c index 2ab61c44..e0ecde43 100644 --- a/src/lib/openjp2/mqc.c +++ b/src/lib/openjp2/mqc.c @@ -199,13 +199,13 @@ static opj_mqc_state_t mqc_states[47 * 2] = { void opj_mqc_byteout(opj_mqc_t *mqc) { if (*mqc->bp == 0xff) { mqc->bp++; - *mqc->bp = mqc->c >> 20; + *mqc->bp = (OPJ_BYTE)(mqc->c >> 20); mqc->c &= 0xfffff; mqc->ct = 7; } else { if ((mqc->c & 0x8000000) == 0) { /* ((mqc->c&0x8000000)==0) CHANGE */ mqc->bp++; - *mqc->bp = mqc->c >> 19; + *mqc->bp = (OPJ_BYTE)(mqc->c >> 19); mqc->c &= 0x7ffff; mqc->ct = 8; } else { @@ -213,12 +213,12 @@ void opj_mqc_byteout(opj_mqc_t *mqc) { if (*mqc->bp == 0xff) { mqc->c &= 0x7ffffff; mqc->bp++; - *mqc->bp = mqc->c >> 20; + *mqc->bp = (OPJ_BYTE)(mqc->c >> 20); mqc->c &= 0xfffff; mqc->ct = 7; } else { mqc->bp++; - *mqc->bp = mqc->c >> 19; + *mqc->bp = (OPJ_BYTE)(mqc->c >> 19); mqc->c &= 0x7ffff; mqc->ct = 8; } @@ -371,7 +371,9 @@ void opj_mqc_destroy(opj_mqc_t *mqc) { } OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc) { - return mqc->bp - mqc->start; + const ptrdiff_t diff = mqc->bp - mqc->start; + assert( diff <= 0xffffffff && diff >= 0 ); /* UINT32_MAX */ + return (OPJ_UINT32)diff; } void opj_mqc_init_enc(opj_mqc_t *mqc, OPJ_BYTE *bp) { @@ -420,7 +422,7 @@ void opj_mqc_bypass_enc(opj_mqc_t *mqc, OPJ_UINT32 d) { mqc->c = mqc->c + (d << mqc->ct); if (mqc->ct == 0) { mqc->bp++; - *mqc->bp = mqc->c; + *mqc->bp = (OPJ_BYTE)mqc->c; mqc->ct = 8; if (*mqc->bp == 0xff) { mqc->ct = 7; @@ -441,7 +443,7 @@ OPJ_UINT32 opj_mqc_bypass_flush_enc(opj_mqc_t *mqc) { bit_padding = (bit_padding + 1) & 0x01; } mqc->bp++; - *mqc->bp = mqc->c; + *mqc->bp = (OPJ_BYTE)mqc->c; mqc->ct = 8; mqc->c = 0; } diff --git a/src/lib/openjp2/openjpeg.c b/src/lib/openjp2/openjpeg.c index 957143f3..ad011163 100644 --- a/src/lib/openjp2/openjpeg.c +++ b/src/lib/openjp2/openjpeg.c @@ -900,8 +900,8 @@ OPJ_BOOL OPJ_CALLCONV opj_set_MCT(opj_cparameters_t *parameters, OPJ_FLOAT32 * pEncodingMatrix, OPJ_INT32 * p_dc_shift,OPJ_UINT32 pNbComp) { - OPJ_UINT32 l_matrix_size = pNbComp * pNbComp * sizeof(OPJ_FLOAT32); - OPJ_UINT32 l_dc_shift_size = pNbComp * sizeof(OPJ_INT32); + OPJ_UINT32 l_matrix_size = pNbComp * pNbComp * (OPJ_UINT32)sizeof(OPJ_FLOAT32); + OPJ_UINT32 l_dc_shift_size = pNbComp * (OPJ_UINT32)sizeof(OPJ_INT32); OPJ_UINT32 l_mct_total_size = l_matrix_size + l_dc_shift_size; /* add MCT capability */ From 51caff5dcfb8dced1677991610f739a7dde70a2e Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 4 Mar 2014 08:40:06 +0000 Subject: [PATCH 197/333] [trunk] Revert portion of r2562, need to investigate issue. Update issue 269 --- src/lib/openjp2/mqc.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/openjp2/mqc.c b/src/lib/openjp2/mqc.c index e0ecde43..5fcbe6fd 100644 --- a/src/lib/openjp2/mqc.c +++ b/src/lib/openjp2/mqc.c @@ -372,7 +372,9 @@ void opj_mqc_destroy(opj_mqc_t *mqc) { OPJ_UINT32 opj_mqc_numbytes(opj_mqc_t *mqc) { const ptrdiff_t diff = mqc->bp - mqc->start; +#if 0 assert( diff <= 0xffffffff && diff >= 0 ); /* UINT32_MAX */ +#endif return (OPJ_UINT32)diff; } From 0c80fcff2a880aef6bc2757fcb374ab57512d7eb Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 4 Mar 2014 09:14:47 +0000 Subject: [PATCH 198/333] [trunk] Add a TIFF compare function (PEAK/MSE) Fixes issue 100 --- tests/comparePGXimages.c | 161 +++++++++++++++++++++++++++---- tests/conformance/CMakeLists.txt | 59 +++++------ 2 files changed, 171 insertions(+), 49 deletions(-) diff --git a/tests/comparePGXimages.c b/tests/comparePGXimages.c index a495f548..39599173 100644 --- a/tests/comparePGXimages.c +++ b/tests/comparePGXimages.c @@ -92,8 +92,8 @@ static void comparePGXimages_help_display(void) } /******************************************************************************* - * Create filenames from a filename by used separator and nb components - * (begin to 0) + * Create filenames from a filename using separator and nb components + * (begin from 0) *******************************************************************************/ static char* createMultiComponentsFilename(const char* inFilename, const int indexF, const char* separator) { @@ -136,6 +136,95 @@ static char* createMultiComponentsFilename(const char* inFilename, const int ind /******************************************************************************* * *******************************************************************************/ +static opj_image_t* readImageFromFileTIF(const char* filename, int nbFilenamePGX, const char *separator) +{ + int it_file; + opj_image_t* image_read = NULL; + opj_image_t* image = NULL; + opj_cparameters_t parameters; + opj_image_cmptparm_t* param_image_read; + int** data; + + /* If separator is empty => nb file to read is equal to one*/ + if ( strlen(separator) == 0 ) + nbFilenamePGX = 1; + + /* set encoding parameters to default values */ + opj_set_default_encoder_parameters(¶meters); + parameters.decod_format = TIF_DFMT; + strncpy(parameters.infile, filename, sizeof(parameters.infile)-1); + assert( parameters.infile[sizeof(parameters.infile)] == 0 ); + + /* Allocate memory*/ + param_image_read = malloc(nbFilenamePGX * sizeof(opj_image_cmptparm_t)); + data = malloc(nbFilenamePGX * sizeof(*data)); + + for (it_file = 0; it_file < nbFilenamePGX; it_file++) + { + /* Create the right filename*/ + char *filenameComponentPGX; + if (strlen(separator) == 0) + { + filenameComponentPGX = malloc((strlen(filename) + 1) * sizeof(*filenameComponentPGX)); + strcpy(filenameComponentPGX, filename); + } + else + filenameComponentPGX = createMultiComponentsFilename(filename, it_file, separator); + + /* Read the tif file corresponding to the component */ + image_read = tiftoimage(filenameComponentPGX, ¶meters); + if (!image_read) + { + int it_free_data; + fprintf(stderr, "Unable to load pgx file\n"); + + free(param_image_read); + + for (it_free_data = 0; it_free_data < it_file; it_free_data++) { + free(data[it_free_data]); + } + free(data); + + free(filenameComponentPGX); + + return NULL; + } + + /* Set the image_read parameters*/ + param_image_read[it_file].x0 = 0; + param_image_read[it_file].y0 = 0; + param_image_read[it_file].dx = 0; + param_image_read[it_file].dy = 0; + param_image_read[it_file].h = image_read->comps->h; + param_image_read[it_file].w = image_read->comps->w; + param_image_read[it_file].bpp = image_read->comps->bpp; + param_image_read[it_file].prec = image_read->comps->prec; + param_image_read[it_file].sgnd = image_read->comps->sgnd; + + /* Copy data*/ + data[it_file] = malloc(param_image_read[it_file].h * param_image_read[it_file].w * sizeof(int)); + memcpy(data[it_file], image_read->comps->data, image_read->comps->h * image_read->comps->w * sizeof(int)); + + /* Free memory*/ + opj_image_destroy(image_read); + free(filenameComponentPGX); + } + + image = opj_image_create(nbFilenamePGX, param_image_read, OPJ_CLRSPC_UNSPECIFIED); + for (it_file = 0; it_file < nbFilenamePGX; it_file++) + { + /* Copy data into output image and free memory*/ + memcpy(image->comps[it_file].data, data[it_file], image->comps[it_file].h * image->comps[it_file].w * sizeof(int)); + free(data[it_file]); + } + + /* Free memory*/ + free(param_image_read); + free(data); + + return image; +} + static opj_image_t* readImageFromFilePGX(const char* filename, int nbFilenamePGX, const char *separator) { int it_file; @@ -276,6 +365,19 @@ typedef struct test_cmp_parameters } test_cmp_parameters; +/* return decode format PGX / TIF , return -1 on error */ +static int get_decod_format(test_cmp_parameters* param) +{ + const int dot = '.'; + char * base_ext = strrchr(param->base_filename, dot); + char * test_ext = strrchr(param->test_filename, dot); + if( !base_ext || !test_ext ) return -1; + if( strcmp(base_ext,test_ext) != 0 ) return -1; + if( strcmp(base_ext,".pgx") == 0 ) return PGX_DFMT; + if( strcmp(base_ext,".tif") == 0 ) return TIF_DFMT; + return -1; +} + /******************************************************************************* * Parse command line *******************************************************************************/ @@ -361,22 +463,16 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) fprintf(stderr,"Need to indicate the number of components !\n"); return 1; } - else + /* else */ + if ( flagM && flagP ) { - if ( flagM && flagP ) + param->tabMSEvalues = parseToleranceValues( MSElistvalues, param->nbcomp); + param->tabPEAKvalues = parseToleranceValues( PEAKlistvalues, param->nbcomp); + if ( (param->tabMSEvalues == NULL) || (param->tabPEAKvalues == NULL)) { - param->tabMSEvalues = parseToleranceValues( MSElistvalues, param->nbcomp); - param->tabPEAKvalues = parseToleranceValues( PEAKlistvalues, param->nbcomp); - if ( (param->tabMSEvalues == NULL) || (param->tabPEAKvalues == NULL)) - { - fprintf(stderr,"MSE and PEAK values are not correct (respectively need %d values)\n",param->nbcomp); - return 1; - } + fprintf(stderr,"MSE and PEAK values are not correct (respectively need %d values)\n",param->nbcomp); + return 1; } - /*else - { - - }*/ } /* Get separators after corresponding letter (b or t)*/ @@ -512,6 +608,7 @@ int main(int argc, char **argv) /* Structures to store image parameters and data*/ opj_image_t *imageBase = NULL, *imageTest = NULL, *imageDiff = NULL; opj_image_cmptparm_t* param_image_diff = NULL; + int decod_format; /* Get parameters from command line*/ if( parse_cmdline_cmp(argc, argv, &inParam) ) @@ -559,9 +656,22 @@ int main(int argc, char **argv) memsizebasefilename = (int)strlen(inParam.test_filename) + 1 + 5 + 2 + 4; memsizetestfilename = (int)strlen(inParam.test_filename) + 1 + 5 + 2 + 4; - imageBase = readImageFromFilePGX( inParam.base_filename, nbFilenamePGXbase, inParam.separator_base); - if ( imageBase == NULL ) - goto cleanup; + decod_format = get_decod_format(&inParam); + if( decod_format == -1 ) goto cleanup; + assert( decod_format == PGX_DFMT || decod_format == TIF_DFMT ); + + if( decod_format == PGX_DFMT ) + { + imageBase = readImageFromFilePGX( inParam.base_filename, nbFilenamePGXbase, inParam.separator_base); + if ( imageBase == NULL ) + goto cleanup; + } + else if( decod_format == TIF_DFMT ) + { + imageBase = readImageFromFileTIF( inParam.base_filename, nbFilenamePGXbase, ""); + if ( imageBase == NULL ) + goto cleanup; + } filenamePNGbase = (char*) malloc(memsizebasefilename); strcpy(filenamePNGbase, inParam.test_filename); @@ -570,9 +680,18 @@ int main(int argc, char **argv) /*----------TEST IMAGE--------*/ - imageTest = readImageFromFilePGX(inParam.test_filename, nbFilenamePGXtest, inParam.separator_test); - if ( imageTest == NULL ) - goto cleanup; + if( decod_format == PGX_DFMT ) + { + imageTest = readImageFromFilePGX(inParam.test_filename, nbFilenamePGXtest, inParam.separator_test); + if ( imageTest == NULL ) + goto cleanup; + } + else if( decod_format == TIF_DFMT ) + { + imageTest = readImageFromFileTIF(inParam.test_filename, nbFilenamePGXtest, ""); + if ( imageTest == NULL ) + goto cleanup; + } filenamePNGtest = (char*) malloc(memsizetestfilename); strcpy(filenamePNGtest, inParam.test_filename); diff --git a/tests/conformance/CMakeLists.txt b/tests/conformance/CMakeLists.txt index 6f80cf12..57fd2568 100644 --- a/tests/conformance/CMakeLists.txt +++ b/tests/conformance/CMakeLists.txt @@ -438,34 +438,37 @@ foreach(numFileJP2 RANGE 1 9) list(GET JP2_PEAK_list ${numFileJP2} PEAK_limit) add_test(NAME ETS-JP2-${filenameInput}-decode - COMMAND opj_decompress - -i ${INPUT_CONF}/${filenameInput} - -o ${TEMP}/${filenameInput}.tif - ) -# -# FIXME: Need to implement a compare tif images function -# -# add_test(ETS-JP2-${filenameInput}-compare2ref -# ${EXECUTABLE_OUTPUT_PATH}/compareTIFimages -# -b ${BASELINE_CONF}/${filenameRef_tif} -# -t ${TEMP}/${filenameInput}.pgx -# -p 4 -# ) -# -# set_tests_properties(ETS-JP2-${filenameInput}-compare2ref -# PROPERTIES DEPENDS -# ETS-JP2-${filenameInput}-decode) -# -# add_test(NR-JP2-${filenameInput}-compare2base -# ${EXECUTABLE_OUTPUT_PATH}/compareTIFimages -# -b ${BASELINE_NR}/opj_${filenameRef} -# -t ${TEMP}/${filenameInput}.tif -# -d -# ) -# -# set_tests_properties(NR-JP2-${filenameInput}-compare2base -# PROPERTIES DEPENDS -# ETS-JP2-${filenameInput}-decode) + COMMAND opj_decompress + -i ${INPUT_CONF}/${filenameInput} + -o ${TEMP}/${filenameInput}.tif + ) + + add_test(NAME ETS-JP2-${filenameInput}-compare2ref + COMMAND comparePGXimages + -b ${BASELINE_CONF}/${filenameRef} + -t ${TEMP}/${filenameInput}.tif + -n 3 + -p 4:4:4 + -m 4:4:4 + -s b_t_ + ) + + set_tests_properties(ETS-JP2-${filenameInput}-compare2ref + PROPERTIES DEPENDS + ETS-JP2-${filenameInput}-decode) + + add_test(NAME NR-JP2-${filenameInput}-compare2base + COMMAND comparePGXimages + -b ${BASELINE_NR}/opj_${filenameRef} + -t ${TEMP}/${filenameInput}.tif + -n 3 + -d + -s b_t_ + ) + + set_tests_properties(NR-JP2-${filenameInput}-compare2base + PROPERTIES DEPENDS + ETS-JP2-${filenameInput}-decode) endforeach() From 7185faa8570248a024504a18b88ba9a60d8e46b0 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 4 Mar 2014 09:19:49 +0000 Subject: [PATCH 199/333] [trunk] Remove warning about conversion. Update issue 256 --- src/lib/openjp2/tcd.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/lib/openjp2/tcd.c b/src/lib/openjp2/tcd.c index f44d3e96..19ccca71 100644 --- a/src/lib/openjp2/tcd.c +++ b/src/lib/openjp2/tcd.c @@ -301,7 +301,7 @@ void opj_tcd_makelayer_fixed(opj_tcd_t *tcd, OPJ_UINT32 layno, OPJ_UINT32 final) for (j = 0; j < tilec->numresolutions; j++) { for (k = 0; k < 3; k++) { matrice[i][j][k] = - (OPJ_INT32) (cp->m_specific_param.m_enc.m_matrice[i * tilec->numresolutions * 3 + j * 3 + k] + (OPJ_INT32) ((OPJ_FLOAT32)cp->m_specific_param.m_enc.m_matrice[i * tilec->numresolutions * 3 + j * 3 + k] * (OPJ_FLOAT32) (tcd->image->comps[compno].prec / 16.0)); } } @@ -580,7 +580,7 @@ OPJ_BOOL opj_tcd_init( opj_tcd_t *p_tcd, } memset(p_tcd->tcd_image->tiles,0, sizeof(opj_tcd_tile_t)); - l_tile_comp_size = p_image->numcomps * sizeof(opj_tcd_tilecomp_t); + l_tile_comp_size = p_image->numcomps * (OPJ_UINT32)sizeof(opj_tcd_tilecomp_t); p_tcd->tcd_image->tiles->comps = (opj_tcd_tilecomp_t *) opj_malloc(l_tile_comp_size); if (! p_tcd->tcd_image->tiles->comps ) { return OPJ_FALSE; @@ -1691,7 +1691,7 @@ OPJ_BOOL opj_tcd_dc_level_shift_decode ( opj_tcd_t *p_tcd ) for (j=0;jm_dc_level_shift, l_min, l_max); ; + *l_current_ptr = opj_int_clamp((OPJ_INT32)lrintf(l_value) + l_tccp->m_dc_level_shift, l_min, l_max); ; ++l_current_ptr; } l_current_ptr += l_stride; From 36320b4bf45359dd649ab682a58d07383bc2703e Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 4 Mar 2014 09:30:07 +0000 Subject: [PATCH 200/333] [trunk] Remove more conversion warnings. Update issue 256 --- src/bin/jp2/convert.c | 106 +++++++++++++++++++++--------------------- 1 file changed, 52 insertions(+), 54 deletions(-) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index 9baf5723..23a3aecc 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -584,8 +584,8 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters) return NULL; } - File_h.bfType = getc(IN); - File_h.bfType = (getc(IN) << 8) + File_h.bfType; + File_h.bfType = (WORD)getc(IN); + File_h.bfType = (WORD)((getc(IN) << 8) + File_h.bfType); if (File_h.bfType != 19778) { @@ -600,11 +600,11 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters) File_h.bfSize = (getc(IN) << 16) + File_h.bfSize; File_h.bfSize = (getc(IN) << 24) + File_h.bfSize; - File_h.bfReserved1 = getc(IN); - File_h.bfReserved1 = (getc(IN) << 8) + File_h.bfReserved1; + File_h.bfReserved1 = (WORD)getc(IN); + File_h.bfReserved1 = (WORD)((getc(IN) << 8) + File_h.bfReserved1); - File_h.bfReserved2 = getc(IN); - File_h.bfReserved2 = (getc(IN) << 8) + File_h.bfReserved2; + File_h.bfReserved2 = (WORD)getc(IN); + File_h.bfReserved2 = (WORD)((getc(IN) << 8) + File_h.bfReserved2); File_h.bfOffBits = getc(IN); File_h.bfOffBits = (getc(IN) << 8) + File_h.bfOffBits; @@ -637,11 +637,11 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters) Info_h.biHeight = (getc(IN) << 24) + Info_h.biHeight; h = Info_h.biHeight; - Info_h.biPlanes = getc(IN); - Info_h.biPlanes = (getc(IN) << 8) + Info_h.biPlanes; + Info_h.biPlanes = (WORD)getc(IN); + Info_h.biPlanes = (WORD)((getc(IN) << 8) + Info_h.biPlanes); - Info_h.biBitCount = getc(IN); - Info_h.biBitCount = (getc(IN) << 8) + Info_h.biBitCount; + Info_h.biBitCount = (WORD)getc(IN); + Info_h.biBitCount = (WORD)((getc(IN) << 8) + Info_h.biBitCount); Info_h.biCompression = getc(IN); Info_h.biCompression = (getc(IN) << 8) + Info_h.biCompression; @@ -1248,9 +1248,9 @@ static unsigned short readushort(FILE * f, int bigendian) return 0; } if (bigendian) - return (c1 << 8) + c2; + return (unsigned short)((c1 << 8) + c2); else - return (c2 << 8) + c1; + return (unsigned short)((c2 << 8) + c1); } static unsigned int readuint(FILE * f, int bigendian) @@ -2258,15 +2258,15 @@ int imagetotif(opj_image_t * image, const char *outfile) if(has_alpha) a += adjust; } if(r > 255) r = 255; else if(r < 0) r = 0; - dat8[i+0] = r ; + dat8[i+0] = (unsigned char)r ; if(g > 255) g = 255; else if(g < 0) g = 0; - dat8[i+1] = g ; + dat8[i+1] = (unsigned char)g ; if(b > 255) b = 255; else if(b < 0) b = 0; - dat8[i+2] = b ; + dat8[i+2] = (unsigned char)b ; if(has_alpha) { if(a > 255) a = 255; else if(a < 0) a = 0; - dat8[i+3] = a; + dat8[i+3] = (unsigned char)a; } index++; @@ -2300,14 +2300,14 @@ int imagetotif(opj_image_t * image, const char *outfile) if(g > 255) g = 255; else if(g < 0) g = 0; if(b > 255) b = 255; else if(b < 0) b = 0; - dat8[i+0] = r ; - if(i+1 < ssize) dat8[i+1] = g ; else break; - if(i+2 < ssize) dat8[i+2] = b ; else break; + dat8[i+0] = (unsigned char)r ; + if(i+1 < ssize) dat8[i+1] = (unsigned char)g ; else break; + if(i+2 < ssize) dat8[i+2] = (unsigned char)b ; else break; if(has_alpha) { if(a > 255) a = 255; else if(a < 0) a = 0; - if(i+3 < ssize) dat8[i+3] = a ; else break; + if(i+3 < ssize) dat8[i+3] = (unsigned char)a ; else break; } index++; } @@ -2352,17 +2352,17 @@ int imagetotif(opj_image_t * image, const char *outfile) if(g > 65535) g = 65535; else if(g < 0) g = 0; if(b > 65535) b = 65535; else if(b < 0) b = 0; - dat8[i+0] = r;/*LSB*/ - dat8[i+1] = (r >> 8);/*MSB*/ - dat8[i+2] = g; - dat8[i+3] = (g >> 8); - dat8[i+4] = b; - dat8[i+5] = (b >> 8); + dat8[i+0] = (unsigned char)r;/*LSB*/ + dat8[i+1] = (unsigned char)(r >> 8);/*MSB*/ + dat8[i+2] = (unsigned char)g; + dat8[i+3] = (unsigned char)(g >> 8); + dat8[i+4] = (unsigned char)b; + dat8[i+5] = (unsigned char)(b >> 8); if(has_alpha) { if(a > 65535) a = 65535; else if(a < 0) a = 0; - dat8[i+6] = a; - dat8[i+7] = (a >> 8); + dat8[i+6] = (unsigned char)a; + dat8[i+7] = (unsigned char)(a >> 8); } index++; last_i = i + step; @@ -2402,18 +2402,18 @@ int imagetotif(opj_image_t * image, const char *outfile) if(g > 65535) g = 65535; else if(g < 0) g = 0; if(b > 65535) b = 65535; else if(b < 0) b = 0; - dat8[i+0] = r;/*LSB*/ - if(i+1 < ssize) dat8[i+1] = (r >> 8);else break;/*MSB*/ - if(i+2 < ssize) dat8[i+2] = g; else break; - if(i+3 < ssize) dat8[i+3] = (g >> 8);else break; - if(i+4 < ssize) dat8[i+4] = b; else break; - if(i+5 < ssize) dat8[i+5] = (b >> 8);else break; + dat8[i+0] = (unsigned char) r;/*LSB*/ + if(i+1 < ssize) dat8[i+1] = (unsigned char)(r >> 8);else break;/*MSB*/ + if(i+2 < ssize) dat8[i+2] = (unsigned char) g; else break; + if(i+3 < ssize) dat8[i+3] = (unsigned char)(g >> 8);else break; + if(i+4 < ssize) dat8[i+4] = (unsigned char) b; else break; + if(i+5 < ssize) dat8[i+5] = (unsigned char)(b >> 8);else break; if(has_alpha) { if(a > 65535) a = 65535; else if(a < 0) a = 0; - if(i+6 < ssize) dat8[i+6] = a; else break; - if(i+7 < ssize) dat8[i+7] = (a >> 8); else break; + if(i+6 < ssize) dat8[i+6] = (unsigned char)a; else break; + if(i+7 < ssize) dat8[i+7] = (unsigned char)(a >> 8); else break; } index++; } @@ -2486,12 +2486,12 @@ int imagetotif(opj_image_t * image, const char *outfile) if(has_alpha) a += adjust; } if(r > 255) r = 255; else if(r < 0) r = 0; - dat8[i+0] = r; + dat8[i+0] = (unsigned char)r; if(has_alpha) { if(a > 255) a = 255; else if(a < 0) a = 0; - dat8[i+1] = a; + dat8[i+1] = (unsigned char)a; } index++; } @@ -2524,13 +2524,13 @@ int imagetotif(opj_image_t * image, const char *outfile) if(has_alpha) a = (a<>dshift); } if(r > 65535) r = 65535; else if(r < 0) r = 0; - dat8[i+0] = r;/*LSB*/ - dat8[i+1] = r >> 8;/*MSB*/ + dat8[i+0] = (unsigned char)r;/*LSB*/ + dat8[i+1] = (unsigned char)(r >> 8);/*MSB*/ if(has_alpha) { if(a > 65535) a = 65535; else if(a < 0) a = 0; - dat8[i+2] = a; - dat8[i+3] = a >> 8; + dat8[i+2] = (unsigned char)a; + dat8[i+3] = (unsigned char)(a >> 8); } index++; }/*if(index < imgsize)*/ @@ -3011,13 +3011,11 @@ static opj_image_t* rawtoimage_common(const char *filename, opj_cparameters_t *p } if( big_endian ) { - value = temp1 << 8; - value += temp2; + value = (unsigned short)(temp1 << 8 + temp2); } else { - value = temp2 << 8; - value += temp1; + value = (unsigned short)(temp2 << 8 + temp1); } image->comps[compno].data[i] = raw_cp->rawSigned?(short)value:value; } @@ -3312,8 +3310,8 @@ opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params) cmptparm[i].sgnd = 0; cmptparm[i].dx = sub_dx; cmptparm[i].dy = sub_dy; - cmptparm[i].w = width; - cmptparm[i].h = height; + cmptparm[i].w = (OPJ_UINT32)width; + cmptparm[i].h = (OPJ_UINT32)height; } image = opj_image_create(nr_comp, &cmptparm[0], OPJ_CLRSPC_SRGB); @@ -3322,8 +3320,8 @@ opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params) image->x0 = params->image_offset_x0; image->y0 = params->image_offset_y0; - image->x1 = image->x0 + (width - 1) * sub_dx + 1 + image->x0; - image->y1 = image->y0 + (height - 1) * sub_dy + 1 + image->y0; + image->x1 = (OPJ_UINT32)(image->x0 + (width - 1) * sub_dx + 1 + image->x0); + image->y1 = (OPJ_UINT32)(image->y0 + (height - 1) * sub_dy + 1 + image->y0); r = image->comps[0].data; g = image->comps[1].data; @@ -3487,11 +3485,11 @@ int imagetopng(opj_image_t * image, const char *write_idf) green = image->comps[1].data; blue = image->comps[2].data; - sig_bit.red = sig_bit.green = sig_bit.blue = prec; + sig_bit.red = sig_bit.green = sig_bit.blue = (png_byte)prec; if(has_alpha) { - sig_bit.alpha = prec; + sig_bit.alpha = (png_byte)prec; alpha = image->comps[3].data; color_type = PNG_COLOR_TYPE_RGB_ALPHA; adjustA = (image->comps[3].sgnd ? 1 << (image->comps[3].prec - 1) : 0); @@ -3618,14 +3616,14 @@ image->comps[1].sgnd,image->comps[2].sgnd,width,height,has_alpha); red = image->comps[0].data; - sig_bit.gray = prec; + sig_bit.gray = (png_byte)prec; sig_bit.red = sig_bit.green = sig_bit.blue = sig_bit.alpha = 0; alpha = NULL; adjustA = 0; color_type = PNG_COLOR_TYPE_GRAY; if(nr_comp == 2) { - has_alpha = 1; sig_bit.alpha = prec; + has_alpha = 1; sig_bit.alpha = (png_byte)prec; alpha = image->comps[1].data; color_type = PNG_COLOR_TYPE_GRAY_ALPHA; adjustA = (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); From 872368d25c2186e631bc629b2aaf72d21a715c54 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 4 Mar 2014 09:32:19 +0000 Subject: [PATCH 201/333] [trunk] Remove another warning. ftell returns long int Update issue 256 --- src/bin/jp2/opj_compress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index 5ed5228f..ea941510 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -937,7 +937,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param float *lCurrentDoublePtr; float *lSpace; int *l_int_ptr; - int lNbComp = 0, lTotalComp, lMctComp, i, lStrLen, lStrFread; + int lNbComp = 0, lTotalComp, lMctComp, i; long int lStrLen, lStrFread; /* Open file */ FILE * lFile = fopen(lFilename,"r"); From f7da94610d8a74eebe238561a0509496e97f7815 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 4 Mar 2014 09:55:38 +0000 Subject: [PATCH 202/333] [trunk] Remove some conversion warnings reported by gcc Update issue 256 --- src/lib/openjp2/j2k.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 29d2a5c1..90e5cad8 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -4592,7 +4592,7 @@ OPJ_BOOL opj_j2k_update_rates( opj_j2k_t *p_j2k, if (*l_rates) { *l_rates = (( (OPJ_FLOAT32) (l_size_pixel * (l_x1 - l_x0) * (l_y1 - l_y0))) / - ((*l_rates) * l_bits_empty) + ((*l_rates) * (OPJ_FLOAT32)l_bits_empty) ) - l_offset; @@ -4604,7 +4604,7 @@ OPJ_BOOL opj_j2k_update_rates( opj_j2k_t *p_j2k, if (*l_rates) { *l_rates = (( (OPJ_FLOAT32) (l_size_pixel * (l_x1 - l_x0) * (l_y1 - l_y0))) / - ((*l_rates) * l_bits_empty) + ((*l_rates) * (OPJ_FLOAT32)l_bits_empty) ) - l_offset; @@ -6001,7 +6001,7 @@ void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *i parameters->tcp_rates[0] = max_rate; }else{ temp_rate =(OPJ_FLOAT32)(image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec)/ - (OPJ_FLOAT32)(parameters->tcp_rates[0] * 8 * image->comps[0].dx * image->comps[0].dy); + (parameters->tcp_rates[0] * 8 * (OPJ_FLOAT32)image->comps[0].dx * (OPJ_FLOAT32)image->comps[0].dy); if (temp_rate > CINEMA_24_CS ){ opj_event_msg(p_manager, EVT_WARNING, "JPEG 2000 Profile-3 and 4 (2k/4k dc profile) requires:\n" @@ -6020,12 +6020,12 @@ void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *i break; case OPJ_CINEMA2K_48: max_rate = ((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy); + (float)(CINEMA_48_CS * 8 * image->comps[0].dx * image->comps[0].dy); if (parameters->tcp_rates[0] == 0){ parameters->tcp_rates[0] = max_rate; }else{ temp_rate =((float) (image->numcomps * image->comps[0].w * image->comps[0].h * image->comps[0].prec))/ - (parameters->tcp_rates[0] * 8 * image->comps[0].dx * image->comps[0].dy); + (parameters->tcp_rates[0] * 8 * (float)image->comps[0].dx * (float)image->comps[0].dy); if (temp_rate > CINEMA_48_CS ){ opj_event_msg(p_manager, EVT_WARNING, "JPEG 2000 Profile-3 (2k dc profile) requires:\n" @@ -6143,9 +6143,9 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, cp->m_specific_param.m_enc.m_cinema = parameters->cp_cinema; cp->m_specific_param.m_enc.m_max_comp_size = parameters->max_comp_size; cp->rsiz = parameters->cp_rsiz; - cp->m_specific_param.m_enc.m_disto_alloc = parameters->cp_disto_alloc; - cp->m_specific_param.m_enc.m_fixed_alloc = parameters->cp_fixed_alloc; - cp->m_specific_param.m_enc.m_fixed_quality = parameters->cp_fixed_quality; + cp->m_specific_param.m_enc.m_disto_alloc = parameters->cp_disto_alloc & 1u; + cp->m_specific_param.m_enc.m_fixed_alloc = parameters->cp_fixed_alloc & 1u; + cp->m_specific_param.m_enc.m_fixed_quality = parameters->cp_fixed_quality & 1u; /* mod fixed_quality */ if (parameters->cp_fixed_alloc && parameters->cp_matrice) { From 07193e2a34aaf11d18ffe87877be3af536a3fec6 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 4 Mar 2014 09:58:07 +0000 Subject: [PATCH 203/333] [trunk] remove more conversion warning in multi-lines macro. C allow simple tricks such as to find those: gcc -E tcd.c | sed '/^\#/d' | indent -st -i2 > clean.c Update issue 256 --- src/lib/openjp2/tcd.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/openjp2/tcd.c b/src/lib/openjp2/tcd.c index 19ccca71..a1672fc3 100644 --- a/src/lib/openjp2/tcd.c +++ b/src/lib/openjp2/tcd.c @@ -682,7 +682,7 @@ OPJ_BOOL FUNCTION ( opj_tcd_t *p_tcd, \ /*fprintf(stderr, "\tTile compo border = %d,%d,%d,%d\n", l_tilec->x0, l_tilec->y0,l_tilec->x1,l_tilec->y1);*/ \ \ l_data_size = (l_tilec->x1 - l_tilec->x0) \ - * (l_tilec->y1 - l_tilec->y0) * sizeof(OPJ_UINT32 );\ + * (l_tilec->y1 - l_tilec->y0) * (OPJ_UINT32)sizeof(OPJ_UINT32 );\ l_tilec->numresolutions = l_tccp->numresolutions; \ if (l_tccp->numresolutions < l_cp->m_specific_param.m_dec.m_reduce) { \ l_tilec->minimum_num_resolutions = 1; \ @@ -716,7 +716,7 @@ OPJ_BOOL FUNCTION ( opj_tcd_t *p_tcd, \ l_tilec->data_size = l_data_size; \ } \ \ - l_data_size = l_tilec->numresolutions * sizeof(opj_tcd_resolution_t); \ + l_data_size = l_tilec->numresolutions * (OPJ_UINT32)sizeof(opj_tcd_resolution_t); \ \ if (l_tilec->resolutions == 00) { \ l_tilec->resolutions = (opj_tcd_resolution_t *) opj_malloc(l_data_size); \ @@ -782,7 +782,7 @@ OPJ_BOOL FUNCTION ( opj_tcd_t *p_tcd, \ /*fprintf(stderr, "\t\t\tres_pw=%d, res_ph=%d\n", l_res->pw, l_res->ph );*/ \ \ l_nb_precincts = l_res->pw * l_res->ph; \ - l_nb_precinct_size = l_nb_precincts * sizeof(opj_tcd_precinct_t); \ + l_nb_precinct_size = l_nb_precincts * (OPJ_UINT32)sizeof(opj_tcd_precinct_t); \ if (resno == 0) { \ tlcbgxstart = l_tl_prc_x_start; \ tlcbgystart = l_tl_prc_y_start; \ @@ -894,7 +894,7 @@ OPJ_BOOL FUNCTION ( opj_tcd_t *p_tcd, \ \ l_nb_code_blocks = l_current_precinct->cw * l_current_precinct->ch; \ /*fprintf(stderr, "\t\t\t\t precinct_cw = %d x recinct_ch = %d\n",l_current_precinct->cw, l_current_precinct->ch); */ \ - l_nb_code_blocks_size = l_nb_code_blocks * sizeof(TYPE); \ + l_nb_code_blocks_size = l_nb_code_blocks * (OPJ_UINT32)sizeof(TYPE); \ \ if (! l_current_precinct->cblks.ELEMENT) { \ l_current_precinct->cblks.ELEMENT = (TYPE*) opj_malloc(l_nb_code_blocks_size); \ From 1ef677f2648c2fc424183f38225ce1fa4bf390c9 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 4 Mar 2014 10:32:26 +0000 Subject: [PATCH 204/333] [trunk] Make sure to reject images such as 1336.pdf.asan.47.376.jp2 Fixes issue 267 --- src/lib/openjp2/tcd.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/openjp2/tcd.c b/src/lib/openjp2/tcd.c index a1672fc3..e0752724 100644 --- a/src/lib/openjp2/tcd.c +++ b/src/lib/openjp2/tcd.c @@ -1583,6 +1583,7 @@ OPJ_BOOL opj_tcd_mct_decode ( opj_tcd_t *p_tcd ) (l_tile->comps[1].x1 - l_tile->comps[1].x0) * (l_tile->comps[1].y1 - l_tile->comps[1].y0) < (OPJ_INT32)l_samples || (l_tile->comps[2].x1 - l_tile->comps[2].x0) * (l_tile->comps[2].y1 - l_tile->comps[2].y0) < (OPJ_INT32)l_samples) { fprintf(stderr, "Tiles don't all have the same dimension. Skip the MCT step.\n"); + return OPJ_FALSE; } else if (l_tcp->mct == 2) { OPJ_BYTE ** l_data; From 4d5d1f0f66b9146b81bac94b6c8a3fc4b3ff2d54 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 5 Mar 2014 09:45:04 +0000 Subject: [PATCH 205/333] [trunk] Handle cmap where direct use is specified (issue235_cmapsubbox.jp2) I doubt the old code ever work. The new code copy the old codestream bytes into the new components (instead of copying the pointer). Technically the issue235.jp2 file should be handled since I.5.3.5 specifies that: ... If the JP2 Header box does not contain a Component Mapping box, the components shall be mapped directly to channels, such that component i is mapped to channel i. ... Update issue 235 --- src/lib/openjp2/jp2.c | 63 ++++++++++++++++++++++++++++--------------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c index 01fcf8da..87a32abc 100644 --- a/src/lib/openjp2/jp2.c +++ b/src/lib/openjp2/jp2.c @@ -797,21 +797,28 @@ static OPJ_BOOL opj_jp2_check_color(opj_image_t *image, opj_jp2_color_t *color, } /* verify that no component is targeted more than once */ for (i = 0; i < nr_channels; i++) { - OPJ_UINT16 pcol = cmap[i].pcol; + OPJ_UINT16 pcol = cmap[i].pcol; + assert(cmap[i].mtyp == 0 || cmap[i].mtyp == 1); if (pcol >= nr_channels) { opj_event_msg(p_manager, EVT_ERROR, "Invalid component/palette index for direct mapping %d.\n", pcol); is_sane = OPJ_FALSE; } - else if (pcol_usage[pcol]) { + else if (pcol_usage[pcol] && cmap[i].mtyp == 1) { opj_event_msg(p_manager, EVT_ERROR, "Component %d is mapped twice.\n", pcol); is_sane = OPJ_FALSE; } + else if (cmap[i].mtyp == 0 && cmap[i].pcol != 0) { + /* I.5.3.5 PCOL: If the value of the MTYP field for this channel is 0, then + * the value of this field shall be 0. */ + opj_event_msg(p_manager, EVT_ERROR, "Direct use at #%d however pcol=%d.\n", i, pcol); + is_sane = OPJ_FALSE; + } else pcol_usage[pcol] = OPJ_TRUE; } /* verify that all components are targeted at least once */ for (i = 0; i < nr_channels; i++) { - if (!pcol_usage[i]) { + if (!pcol_usage[i] && cmap[i].mtyp != 0) { opj_event_msg(p_manager, EVT_ERROR, "Component %d doesn't have a mapping.\n", i); is_sane = OPJ_FALSE; } @@ -850,40 +857,52 @@ void opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color) for(i = 0; i < nr_channels; ++i) { pcol = cmap[i].pcol; cmp = cmap[i].cmp; - new_comps[pcol] = old_comps[cmp]; - /* Direct use */ - if(cmap[i].mtyp == 0){ - old_comps[cmp].data = NULL; continue; - } + if(cmap[i].mtyp == 0){ + assert( pcol == 0 ); + new_comps[i] = old_comps[cmp]; + } else { + assert( i == pcol ); + new_comps[pcol] = old_comps[cmp]; + } /* Palette mapping: */ - new_comps[pcol].data = (OPJ_INT32*) + new_comps[i].data = (OPJ_INT32*) opj_malloc(old_comps[cmp].w * old_comps[cmp].h * sizeof(OPJ_INT32)); - new_comps[pcol].prec = channel_size[i]; - new_comps[pcol].sgnd = channel_sign[i]; + new_comps[i].prec = channel_size[i]; + new_comps[i].sgnd = channel_sign[i]; } top_k = color->jp2_pclr->nr_entries - 1; for(i = 0; i < nr_channels; ++i) { - /* Direct use: */ - if(cmap[i].mtyp == 0) continue; - /* Palette mapping: */ cmp = cmap[i].cmp; pcol = cmap[i].pcol; src = old_comps[cmp].data; - dst = new_comps[pcol].data; + assert( src ); max = new_comps[pcol].w * new_comps[pcol].h; - for(j = 0; j < max; ++j) - { - /* The index */ - if((k = src[j]) < 0) k = 0; else if(k > top_k) k = top_k; + /* Direct use: */ + if(cmap[i].mtyp == 0) { + assert( cmp == 0 ); + dst = new_comps[i].data; + assert( dst ); + for(j = 0; j < max; ++j) { + dst[j] = src[j]; + } + } + else { + assert( i == pcol ); + dst = new_comps[pcol].data; + assert( dst ); + for(j = 0; j < max; ++j) { + /* The index */ + if((k = src[j]) < 0) k = 0; else if(k > top_k) k = top_k; - /* The colour */ - dst[j] = entries[k * nr_channels + pcol]; - } + /* The colour */ + dst[j] = entries[k * nr_channels + pcol]; + } + } } max = image->numcomps; From 275680bdb74c612aa3b2726792e269400e4c8ff4 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 6 Mar 2014 14:43:21 +0000 Subject: [PATCH 206/333] [trunk] Make sure that all output files from the test suite are using a different output name Fixes issue 271 --- tests/nonregression/CMakeLists.txt | 1 + tests/nonregression/checkmd5refs.cmake | 11 ++++- tests/nonregression/md5refs.txt | 53 ++++++++++++++++--------- tests/nonregression/test_suite.ctest.in | 46 ++++++++++----------- 4 files changed, 67 insertions(+), 44 deletions(-) diff --git a/tests/nonregression/CMakeLists.txt b/tests/nonregression/CMakeLists.txt index 33c17895..8b85827c 100644 --- a/tests/nonregression/CMakeLists.txt +++ b/tests/nonregression/CMakeLists.txt @@ -320,6 +320,7 @@ foreach(OPJ_TEST_CMD_LINE ${OPJ_TEST_CMD_LINE_LIST}) add_test(NAME NR-DEC-${INPUT_FILENAME_NAME}-${IT_TEST_DEC}-decode-md5 COMMAND ${CMAKE_COMMAND} -DREFFILE:STRING=${CMAKE_CURRENT_SOURCE_DIR}/md5refs.txt -DFILENAME:STRING=${INPUT_FILENAME_NAME} + -DOUTFILENAME:STRING=${OUTPUT_FILENAME} -P ${CMAKE_CURRENT_SOURCE_DIR}/checkmd5refs.cmake) set_tests_properties(NR-DEC-${INPUT_FILENAME_NAME}-${IT_TEST_DEC}-decode-md5 diff --git a/tests/nonregression/checkmd5refs.cmake b/tests/nonregression/checkmd5refs.cmake index 9c1fa6ca..f94d7c09 100644 --- a/tests/nonregression/checkmd5refs.cmake +++ b/tests/nonregression/checkmd5refs.cmake @@ -19,10 +19,17 @@ #message("0: ${REFFILE}") #message("1: ${CMAKE_CURRENT_BINARY_DIR}") #message("2: ${FILENAME}") -file(GLOB globfiles "Temporary/${FILENAME}*.pgx" "Temporary/${FILENAME}*.png") +#get_filename_component(pgxfile ${pgxfullpath} NAME) +get_filename_component(OUTFILENAME_NAME ${OUTFILENAME} NAME) +string(FIND ${OUTFILENAME_NAME} "." SHORTEST_EXT_POS REVERSE) +string(SUBSTRING ${OUTFILENAME_NAME} 0 ${SHORTEST_EXT_POS} OUTFILENAME_NAME_WE) +#message("3: ${OUTFILENAME_NAME}") +#message("4: ${OUTFILENAME_NAME_WE}") +#file(GLOB globfiles "Temporary/${FILENAME}*.pgx" "Temporary/${FILENAME}*.png") +file(GLOB globfiles "Temporary/${OUTFILENAME_NAME_WE}*.pgx" "Temporary/${OUTFILENAME_NAME_WE}*.png") #message("6: ${globfiles}") if(NOT globfiles) - message(SEND_ERROR "Could not find output PGX files: ${FILENAME}") + message(SEND_ERROR "Could not find output PGX files: ${OUTFILENAME_NAME_WE}") endif() # REFFILE follow what md5sum -c would expect as input: diff --git a/tests/nonregression/md5refs.txt b/tests/nonregression/md5refs.txt index 7b7505cb..7b46562f 100644 --- a/tests/nonregression/md5refs.txt +++ b/tests/nonregression/md5refs.txt @@ -2,9 +2,6 @@ a3a0606dfa0779d657c6a923b90e4678 _00042.j2k_1.pgx 106954dc468dfe0884d02268e91f9f5b _00042.j2k_2.pgx 8889def55f1e18dae6002b9b3a6dd152 123.j2c_0.pgx -4bddb9f5c5f437fe1053af4d61d9202e 1336.pdf.asan.47.376.jp2_0.pgx -f38167b983f0de0ab77e71de291bf5c0 1336.pdf.asan.47.376.jp2_1.pgx -d9a4feed1773b7b1ae5c20bdbdd37291 1336.pdf.asan.47.376.jp2_2.pgx 4a0daf7a9065101379eaebc28e436b1e Bretagne2.j2k_0.pgx 07578fc7bf81d3da694de8ae27308b82 Bretagne2.j2k_1.pgx 3690c42f83bad42f4abea48525d45e0e Bretagne2.j2k_2.pgx @@ -94,12 +91,18 @@ fdad26b1e078aa32bd4b77a5f44da43c orb-blue10-lin-jp2.jp2_2.pgx 7442756e83571c0e87493e03f12b2d34 orb-blue10-win-jp2.jp2_1.pgx 5f99ff2aeb17e167fe7049bcf339d0b3 orb-blue10-win-jp2.jp2_2.pgx fe028d56d6c7aaee87239a115093412a orb-blue10-win-jp2.jp2_3.pgx -344233bbe643ad651f82d4e8aaa3be54 p0_04_1.j2k.png -d105747d8fb755ef18b37ef83832f7d3 p0_04_2.j2k.png -89000c4cb8a83fcb4166624055905258 p0_04_3.j2k.png -af2a3ce7be9c8fb2db66ddbceff1dd53 p0_04_4.j2k.png -757340902e8dc6d5baa4f8f4628e2bc4 p0_04_5.j2k.png -4ec7002317a835f71630a7787cbff30a p0_04.j2k.png +dc78dd4b7739c92cd5291b043cc232ed p0_04_1.j2k.png +e157ce3ec092931d48cdaf275180ed34 p0_04_2.j2k.png +0f0a9b3b8b41f2afaf5d80bf2f36f68c p0_04_3.j2k.png +f78b09250d08365b836654f717ec798c p0_04_4.j2k.png +d7243f4004a30d8856ef4dfa0b9f4bc8 p0_04_5.j2k.png +344233bbe643ad651f82d4e8aaa3be54 p0_04_6_1.j2k.png +d105747d8fb755ef18b37ef83832f7d3 p0_04_6_2.j2k.png +89000c4cb8a83fcb4166624055905258 p0_04_6_3.j2k.png +af2a3ce7be9c8fb2db66ddbceff1dd53 p0_04_6_4.j2k.png +757340902e8dc6d5baa4f8f4628e2bc4 p0_04_6_5.j2k.png +4ec7002317a835f71630a7787cbff30a p0_04_6.j2k.png +d7ed089096806af2f1bf687e1adb427f p0_04.j2k.png 4fecc6d5ebdc2db3bf3ef6bbbbb5b031 p1_04_10.j2k.png ab969b1d17341d062a6f4d6966a1f221 p1_04_11.j2k.png 70fd9d6f155585258b13cb4b6c469e3f p1_04_12.j2k.png @@ -118,16 +121,28 @@ d41f829c40140ec9972edf86681ee53a p1_04_2.j2k.png de2e66f82b9da9bc2dabda183a455b2f p1_04_5.j2k.png d12b3c90d4b1cf78f0ad23eedcabe0ea p1_04_6.j2k.png b3fccf3cbb7186841ba7b86e34cac0c2 p1_04.j2k.png -da21d175c4dcb03ce1f0a227f49ed7b8 p1_06_1.j2k.png -071597783b2141a12db1765b85943c1d p1_06_1.j2k_t5.png -5c434a489375fc9624bab49679cdec76 p1_06_2.j2k.png -6778de9e9236144747fe4542d03bf6e5 p1_06_2.j2k_t9.png -ce2de61ad83a71c9b13ca5df0a987a69 p1_06_3.j2k.png -18f9fbfb0d29e83f697fa93523c53a2b p1_06_4.j2k.png -66ede889502134412872b9d8b1e40887 p1_06_5.j2k.png -85a2b9a1324d72a8cec7041f80529242 p1_06.j2k.png -af083204299bbdd993286892b4c9cd29 p1_06.j2k_r4.png -af083204299bbdd993286892b4c9cd29 p1_06.j2k_t0.png +071597783b2141a12db1765b85943c1d p1_06_10_1.j2k.png +6778de9e9236144747fe4542d03bf6e5 p1_06_10_2.j2k.png +af083204299bbdd993286892b4c9cd29 p1_06_10.j2k.png +af083204299bbdd993286892b4c9cd29 p1_06_11.j2k.png +72a7f65be34450c9ec126fbc58399354 p1_06_1.j2k.png +85b4f3b8f7b987f83972a820d34372a7 p1_06_2.j2k.png +d4fc3ff73e8b5eafbcc2a111b97d362b p1_06_3.j2k.png +a954722553fb25692556cfa87a26bc1a p1_06_4.j2k.png +a62bb79d066e230ea7b34e24681de189 p1_06_5.j2k.png +13d78a5091b06239c2b2012f7927dce8 p1_06_6.j2k.png +da21d175c4dcb03ce1f0a227f49ed7b8 p1_06_7_1.j2k.png +5c434a489375fc9624bab49679cdec76 p1_06_7_2.j2k.png +ce2de61ad83a71c9b13ca5df0a987a69 p1_06_7_3.j2k.png +18f9fbfb0d29e83f697fa93523c53a2b p1_06_7_4.j2k.png +66ede889502134412872b9d8b1e40887 p1_06_7_5.j2k.png +071597783b2141a12db1765b85943c1d p1_06_7_6.j2k.png +85a2b9a1324d72a8cec7041f80529242 p1_06_7.j2k.png +7045c8722e92fb2d447a6dc235a3c619 p1_06_9_1.j2k.png +d41856648d936229f1e3e2cf7d7c7a4d p1_06_9_2.j2k.png +85b4f3b8f7b987f83972a820d34372a7 p1_06_9_3.j2k.png +5fa6e85d6cfa0ed51e5933b2e35f4854 p1_06_9.j2k.png +2e80dbe4a6af432b7f1b54dfa4e164ae p1_06.j2k.png 371aa0a7ff40a73b45f1fa41e210d1db pacs.ge.j2k_0.pgx 6ae110e1fb5a869af3dbc5fbc735b0bd relax.jp2_0.pgx 518a8f28dacc034982507f43763b88dd relax.jp2_1.pgx diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 1c57aece..a0c89eda 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -173,27 +173,27 @@ opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_3.j2k.png -d opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_4.j2k.png -d 3,3,9,9 opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_5.j2k.png -d 4,4,7,7 opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_6.j2k.png -d 4,4,5,5 -opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06.j2k.png -d 0,0,12,12 -r 1 -opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_1.j2k.png -d 1,8,8,11 -r 1 -opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_2.j2k.png -d 9,9,12,12 -r 1 -opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_3.j2k.png -d 10,4,12,10 -r 1 -opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_4.j2k.png -d 3,3,9,9 -r 1 -opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_5.j2k.png -d 4,4,7,7 -r 1 -opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_6.j2k.png -d 4,4,5,5 -r 1 +opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_7.j2k.png -d 0,0,12,12 -r 1 +opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_7_1.j2k.png -d 1,8,8,11 -r 1 +opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_7_2.j2k.png -d 9,9,12,12 -r 1 +opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_7_3.j2k.png -d 10,4,12,10 -r 1 +opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_7_4.j2k.png -d 3,3,9,9 -r 1 +opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_7_5.j2k.png -d 4,4,7,7 -r 1 +opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_7_6.j2k.png -d 4,4,5,5 -r 1 -opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_6.j2k.png -d 9,9,12,12 -r 2 +opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_8_6.j2k.png -d 9,9,12,12 -r 2 -opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06.j2k_t0.png -t 0 -opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_1.j2k_t5.png -t 5 -opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_2.j2k_t9.png -t 9 -opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_3.j2k_t15.png -t 15 +opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_9.j2k.png -t 0 +opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_9_1.j2k.png -t 5 +opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_9_2.j2k.png -t 9 +opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_9_3.j2k.png -t 15 -opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06.j2k_t0.png -t 0 -r 2 -opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_1.j2k_t5.png -t 5 -r 2 -opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_2.j2k_t9.png -t 9 -r 2 -opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_3.j2k_t15.png -t 15 -r 2 +opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_10.j2k.png -t 0 -r 2 +opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_10_1.j2k.png -t 5 -r 2 +opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_10_2.j2k.png -t 9 -r 2 +opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_10_3.j2k.png -t 15 -r 2 -opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06.j2k_r4.png -r 4 +opj_decompress -i @INPUT_CONF_PATH@/p1_06.j2k -o @TEMP_PATH@/p1_06_11.j2k.png -r 4 # prec=4; nb_c=3 ; signd=yes opj_decompress -i @INPUT_CONF_PATH@/p0_04.j2k -o @TEMP_PATH@/p0_04.j2k.png -d 0,0,256,256 @@ -202,12 +202,12 @@ opj_decompress -i @INPUT_CONF_PATH@/p0_04.j2k -o @TEMP_PATH@/p0_04_2.j2k.png -d opj_decompress -i @INPUT_CONF_PATH@/p0_04.j2k -o @TEMP_PATH@/p0_04_3.j2k.png -d 10,150,190,210 opj_decompress -i @INPUT_CONF_PATH@/p0_04.j2k -o @TEMP_PATH@/p0_04_4.j2k.png -d 100,80,200,150 opj_decompress -i @INPUT_CONF_PATH@/p0_04.j2k -o @TEMP_PATH@/p0_04_5.j2k.png -d 150,20,200,50 -opj_decompress -i @INPUT_CONF_PATH@/p0_04.j2k -o @TEMP_PATH@/p0_04.j2k.png -d 0,0,256,256 -r 2 -opj_decompress -i @INPUT_CONF_PATH@/p0_04.j2k -o @TEMP_PATH@/p0_04_1.j2k.png -d 128,0,256,128 -r 2 -opj_decompress -i @INPUT_CONF_PATH@/p0_04.j2k -o @TEMP_PATH@/p0_04_2.j2k.png -d 50,10,120,200 -r 2 -opj_decompress -i @INPUT_CONF_PATH@/p0_04.j2k -o @TEMP_PATH@/p0_04_3.j2k.png -d 10,150,190,210 -r 2 -opj_decompress -i @INPUT_CONF_PATH@/p0_04.j2k -o @TEMP_PATH@/p0_04_4.j2k.png -d 100,80,200,150 -r 2 -opj_decompress -i @INPUT_CONF_PATH@/p0_04.j2k -o @TEMP_PATH@/p0_04_5.j2k.png -d 150,20,200,50 -r 2 +opj_decompress -i @INPUT_CONF_PATH@/p0_04.j2k -o @TEMP_PATH@/p0_04_6.j2k.png -d 0,0,256,256 -r 2 +opj_decompress -i @INPUT_CONF_PATH@/p0_04.j2k -o @TEMP_PATH@/p0_04_6_1.j2k.png -d 128,0,256,128 -r 2 +opj_decompress -i @INPUT_CONF_PATH@/p0_04.j2k -o @TEMP_PATH@/p0_04_6_2.j2k.png -d 50,10,120,200 -r 2 +opj_decompress -i @INPUT_CONF_PATH@/p0_04.j2k -o @TEMP_PATH@/p0_04_6_3.j2k.png -d 10,150,190,210 -r 2 +opj_decompress -i @INPUT_CONF_PATH@/p0_04.j2k -o @TEMP_PATH@/p0_04_6_4.j2k.png -d 100,80,200,150 -r 2 +opj_decompress -i @INPUT_CONF_PATH@/p0_04.j2k -o @TEMP_PATH@/p0_04_6_5.j2k.png -d 150,20,200,50 -r 2 # prec=8; nb_c=1 ; non standard origin (image offset and tile offset); sample sep: 2x1 #opj_decompress -i @INPUT_CONF_PATH@/p1_01.j2k -o @TEMP_PATH@/p1_01.j2k.png -d 5,128,127,226 From 8d3ef0729cd787cdb9337d9b25e4862fcc847a0d Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 6 Mar 2014 14:47:52 +0000 Subject: [PATCH 207/333] [trunk] Remove simple warning about unused variables --- tests/test_tile_decoder.c | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/test_tile_decoder.c b/tests/test_tile_decoder.c index 700dab1c..96b5e829 100644 --- a/tests/test_tile_decoder.c +++ b/tests/test_tile_decoder.c @@ -171,7 +171,6 @@ int main (int argc, char *argv[]) OPJ_UINT32 l_tile_index; OPJ_BYTE * l_data = (OPJ_BYTE *) malloc(1000); OPJ_BOOL l_go_on = OPJ_TRUE; - OPJ_INT32 l_tile_x0=0, l_tile_y0=0 ; OPJ_UINT32 l_nb_comps=0 ; OPJ_INT32 l_current_tile_x0,l_current_tile_y0,l_current_tile_x1,l_current_tile_y1; From 8a959bb1f4f814d517cebb5c0378957cf598f855 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 6 Mar 2014 14:50:42 +0000 Subject: [PATCH 208/333] [trunk] Remove out of bound access in code and simplify code. this is a test tool, security is not an issue here. --- tests/comparePGXimages.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/comparePGXimages.c b/tests/comparePGXimages.c index 39599173..3e44d632 100644 --- a/tests/comparePGXimages.c +++ b/tests/comparePGXimages.c @@ -152,8 +152,7 @@ static opj_image_t* readImageFromFileTIF(const char* filename, int nbFilenamePGX /* set encoding parameters to default values */ opj_set_default_encoder_parameters(¶meters); parameters.decod_format = TIF_DFMT; - strncpy(parameters.infile, filename, sizeof(parameters.infile)-1); - assert( parameters.infile[sizeof(parameters.infile)] == 0 ); + strcpy(parameters.infile, filename); /* Allocate memory*/ param_image_read = malloc(nbFilenamePGX * sizeof(opj_image_cmptparm_t)); From 7e64eb5414c42ee4299703048864d07acb4f78fc Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 6 Mar 2014 15:00:41 +0000 Subject: [PATCH 209/333] [trunk] Remove some easy warnings about sign compare reported by gcc --- src/bin/jp2/convert.c | 37 +++++++++++++++++++------------------ src/lib/openjp2/jp2.c | 2 +- tests/unit/testempty1.c | 2 +- tests/unit/testempty2.c | 2 +- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index 23a3aecc..b4d9544e 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -408,7 +408,8 @@ opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters) { int imagetotga(opj_image_t * image, const char *outfile) { int width, height, bpp, x, y; OPJ_BOOL write_alpha; - int i, adjustR, adjustG, adjustB, fails; + unsigned int i; + int adjustR, adjustG, adjustB, fails; unsigned int alpha_channel; float r,g,b,a; unsigned char value; @@ -702,8 +703,8 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters) /* set image offset and reference grid */ image->x0 = parameters->image_offset_x0; image->y0 = parameters->image_offset_y0; - image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : image->x0 + (w - 1) * subsampling_dx + 1; - image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : image->y0 + (h - 1) * subsampling_dy + 1; + image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : (int)(image->x0 + (w - 1) * subsampling_dx + 1); + image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : (int)(image->y0 + (h - 1) * subsampling_dy + 1); /* set image data */ @@ -803,8 +804,8 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters) /* set image offset and reference grid */ image->x0 = parameters->image_offset_x0; image->y0 = parameters->image_offset_y0; - image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : image->x0 + (w - 1) * subsampling_dx + 1; - image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : image->y0 + (h - 1) * subsampling_dy + 1; + image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : (int)(image->x0 + (w - 1) * subsampling_dx + 1); + image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : (int)(image->y0 + (h - 1) * subsampling_dy + 1); /* set image data */ @@ -915,10 +916,8 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters) /* set image offset and reference grid */ image->x0 = parameters->image_offset_x0; image->y0 = parameters->image_offset_y0; - image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : image->x0 + (w - - 1) * subsampling_dx + 1; - image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : image->y0 + (h - - 1) * subsampling_dy + 1; + image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : (int)(image->x0 + (w - 1) * subsampling_dx + 1); + image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : (int)(image->y0 + (h - 1) * subsampling_dy + 1); /* set image data */ @@ -1338,8 +1337,8 @@ opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters) { cmptparm.x0 = parameters->image_offset_x0; cmptparm.y0 = parameters->image_offset_y0; - cmptparm.w = !cmptparm.x0 ? (w - 1) * parameters->subsampling_dx + 1 : cmptparm.x0 + (w - 1) * parameters->subsampling_dx + 1; - cmptparm.h = !cmptparm.y0 ? (h - 1) * parameters->subsampling_dy + 1 : cmptparm.y0 + (h - 1) * parameters->subsampling_dy + 1; + cmptparm.w = !cmptparm.x0 ? (w - 1) * parameters->subsampling_dx + 1 : (int)(cmptparm.x0 + (w - 1) * parameters->subsampling_dx + 1); + cmptparm.h = !cmptparm.y0 ? (h - 1) * parameters->subsampling_dy + 1 : (int)(cmptparm.y0 + (h - 1) * parameters->subsampling_dy + 1); if (sign == '-') { cmptparm.sgnd = 1; @@ -1439,7 +1438,8 @@ static inline int clamp( const int value, const int prec, const int sgnd ) int imagetopgx(opj_image_t * image, const char *outfile) { int w, h; - int i, j, compno, fails = 1; + int i, j, fails = 1; + unsigned int compno; FILE *fdest = NULL; for (compno = 0; compno < image->numcomps; compno++) @@ -1938,7 +1938,8 @@ int imagetopnm(opj_image_t * image, const char *outfile) { int *red, *green, *blue, *alpha; int wr, hr, max; - int i, compno, ncomp; + int i; + unsigned int compno, ncomp; int adjustR, adjustG, adjustB, adjustA; int fails, two, want_gray, has_alpha, triple; int prec, v; @@ -2701,9 +2702,9 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) image->x0 = parameters->image_offset_x0; image->y0 = parameters->image_offset_y0; image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : - image->x0 + (w - 1) * subsampling_dx + 1; + (int)(image->x0 + (w - 1) * subsampling_dx + 1); image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : - image->y0 + (h - 1) * subsampling_dy + 1; + (int)(image->y0 + (h - 1) * subsampling_dy + 1); buf = _TIFFmalloc(TIFFStripSize(tif)); @@ -2851,9 +2852,9 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) image->x0 = parameters->image_offset_x0; image->y0 = parameters->image_offset_y0; image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : - image->x0 + (w - 1) * subsampling_dx + 1; + (int)(image->x0 + (w - 1) * subsampling_dx + 1); image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : - image->y0 + (h - 1) * subsampling_dy + 1; + (int)(image->y0 + (h - 1) * subsampling_dy + 1); buf = _TIFFmalloc(TIFFStripSize(tif)); @@ -3046,7 +3047,7 @@ static int imagetoraw_common(opj_image_t * image, const char *outfile, OPJ_BOOL { FILE *rawFile = NULL; size_t res; - int compno; + unsigned int compno; int w, h, fails; int line, row, curr, mask; int *ptr; diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c index 87a32abc..4a6b346e 100644 --- a/src/lib/openjp2/jp2.c +++ b/src/lib/openjp2/jp2.c @@ -1000,7 +1000,7 @@ OPJ_BOOL opj_jp2_read_pclr( opj_jp2_t *jp2, for(j = 0; j < nr_entries; ++j) { for(i = 0; i < nr_channels; ++i) { - OPJ_INT32 bytes_to_read = (channel_size[i]+7)>>3; + OPJ_UINT32 bytes_to_read = (channel_size[i]+7)>>3; if (bytes_to_read > sizeof(OPJ_UINT32)) bytes_to_read = sizeof(OPJ_UINT32); diff --git a/tests/unit/testempty1.c b/tests/unit/testempty1.c index f4140f64..a2ae2d2d 100644 --- a/tests/unit/testempty1.c +++ b/tests/unit/testempty1.c @@ -91,7 +91,7 @@ int main(int argc, char *argv[]) for (i = 0; i < image_width * image_height; i++) { - int compno; + unsigned int compno; for(compno = 0; compno < numcomps; compno++) { image->comps[compno].data[i] = 0; diff --git a/tests/unit/testempty2.c b/tests/unit/testempty2.c index 764b14cc..abafa5b3 100644 --- a/tests/unit/testempty2.c +++ b/tests/unit/testempty2.c @@ -96,7 +96,7 @@ int main(int argc, char *argv[]) for (i = 0; i < image_width * image_height; i++) { - int compno; + unsigned int compno; for(compno = 0; compno < numcomps; compno++) { image->comps[compno].data[i] = 0; From eea18e856ea3acf8309a647bb8603e01a0011011 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 6 Mar 2014 15:05:00 +0000 Subject: [PATCH 210/333] [trunk] Remove warning about sign conversion. Update issue 256 --- tests/test_tile_encoder.c | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/test_tile_encoder.c b/tests/test_tile_encoder.c index 89b5f901..4330fb7d 100644 --- a/tests/test_tile_encoder.c +++ b/tests/test_tile_encoder.c @@ -101,7 +101,7 @@ int main (int argc, char *argv[]) /* should be test_tile_encoder 3 2000 2000 1000 1000 8 tte1.j2k */ if( argc == 9 ) { - num_comps = atoi( argv[1] ); + num_comps = (OPJ_UINT32)atoi( argv[1] ); image_width = atoi( argv[2] ); image_height = atoi( argv[3] ); tile_width = atoi( argv[4] ); @@ -125,10 +125,10 @@ int main (int argc, char *argv[]) { return 1; } - l_nb_tiles = (image_width/tile_width) * (image_height/tile_height); - l_data_size = tile_width * tile_height * num_comps * (comp_prec/8); + l_nb_tiles = (OPJ_UINT32)(image_width/tile_width) * (OPJ_UINT32)(image_height/tile_height); + l_data_size = (OPJ_UINT32)tile_width * (OPJ_UINT32)tile_height * (OPJ_UINT32)num_comps * (OPJ_UINT32)(comp_prec/8); - l_data = (OPJ_BYTE*) malloc(tile_width * tile_height * num_comps * (comp_prec/8) * sizeof(OPJ_BYTE)); + l_data = (OPJ_BYTE*) malloc(l_data_size * sizeof(OPJ_BYTE)); fprintf(stdout, "Encoding random values -> keep in mind that this is very hard to compress\n"); for (i=0;idx = 1; l_current_param_ptr->dy = 1; - l_current_param_ptr->h = image_height; - l_current_param_ptr->w = image_width; + l_current_param_ptr->h = (OPJ_UINT32)image_height; + l_current_param_ptr->w = (OPJ_UINT32)image_width; l_current_param_ptr->sgnd = 0; - l_current_param_ptr->prec = comp_prec; + l_current_param_ptr->prec = (OPJ_UINT32)comp_prec; l_current_param_ptr->x0 = 0; l_current_param_ptr->y0 = 0; @@ -252,8 +252,8 @@ int main (int argc, char *argv[]) l_image->x0 = 0; l_image->y0 = 0; - l_image->x1 = image_width; - l_image->y1 = image_height; + l_image->x1 = (OPJ_UINT32)image_width; + l_image->y1 = (OPJ_UINT32)image_height; l_image->color_space = OPJ_CLRSPC_SRGB; if (! opj_setup_encoder(l_codec,&l_param,l_image)) { From 17d9caae83f2864978a5bb4023a426bc0eb9a004 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 6 Mar 2014 15:10:39 +0000 Subject: [PATCH 211/333] [trunk] Remove warning about sign conversion. Update issue 256 --- tests/compare_dump_files.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/tests/compare_dump_files.c b/tests/compare_dump_files.c index 61048c97..6519d715 100644 --- a/tests/compare_dump_files.c +++ b/tests/compare_dump_files.c @@ -78,7 +78,7 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) { case 'b': sizemembasefile = (int)strlen(opj_optarg)+1; - param->base_filename = (char*) malloc(sizemembasefile); + param->base_filename = (char*) malloc((size_t)sizemembasefile); param->base_filename[0] = '\0'; strncpy(param->base_filename, opj_optarg, strlen(opj_optarg)); param->base_filename[strlen(opj_optarg)] = '\0'; @@ -86,7 +86,7 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) break; case 't': sizememtestfile = (int) strlen(opj_optarg) + 1; - param->test_filename = (char*) malloc(sizememtestfile); + param->test_filename = (char*) malloc((size_t)sizememtestfile); param->test_filename[0] = '\0'; strncpy(param->test_filename, opj_optarg, strlen(opj_optarg)); param->test_filename[strlen(opj_optarg)] = '\0'; @@ -162,7 +162,7 @@ int main(int argc, char **argv) } printf("Ok.\n"); - pos=ftell(fbase); + pos=(unsigned long)ftell(fbase); while(!feof(fbase)) { @@ -192,7 +192,7 @@ int main(int argc, char **argv) char *strbase, *strtest, *strbase_d, *strtest_d; printf("Files differ at line %lu:\n", l); - fseek(fbase,pos,SEEK_SET); + fseek(fbase,(long)pos,SEEK_SET); /* Take into account CRLF characters when we write \n into // dump file when we used WIN platform*/ @@ -200,11 +200,11 @@ int main(int argc, char **argv) CRLF_shift = 2; fseek(ftest,pos + l - 1,SEEK_SET); #else - fseek(ftest,pos,SEEK_SET); + fseek(ftest,(long)pos,SEEK_SET); #endif - strbase = (char *) malloc(nbytes + 1); - strtest = (char *) malloc(nbytes + 1); + strbase = (char *) malloc((size_t)nbytes + 1); + strtest = (char *) malloc((size_t)nbytes + 1); if (fgets(strbase, nbytes, fbase) == NULL) fprintf(stderr,"\nWARNING: fgets return a NULL value"); @@ -217,9 +217,9 @@ int main(int argc, char **argv) strbase_d = (char *) malloc(strlen(strbase)+1); strtest_d = (char *) malloc(strlen(strtest)+1); strncpy(strbase_d, strbase, strlen(strbase)-1); - strncpy(strtest_d, strtest, strlen(strtest)-CRLF_shift); + strncpy(strtest_d, strtest, strlen(strtest)-(size_t)CRLF_shift); strbase_d[strlen(strbase)-1] = '\0'; - strtest_d[strlen(strtest)-CRLF_shift] = '\0'; + strtest_d[strlen(strtest)-(size_t)CRLF_shift] = '\0'; printf("<%s> vs. <%s>\n", strbase_d, strtest_d); free(strbase_d);free(strtest_d); } @@ -236,7 +236,7 @@ int main(int argc, char **argv) if (chbase == '\n') { l++; - pos = ftell(fbase); + pos = (unsigned long)ftell(fbase); } } } From 79faedfb9b490e00affa34ef51cd40e8531a391e Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 6 Mar 2014 15:16:44 +0000 Subject: [PATCH 212/333] [trunk] Remove warning about sign conversion. Update issue 256 --- tests/comparePGXimages.c | 34 +++++++++++++++++----------------- tests/compareRAWimages.c | 4 ++-- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/tests/comparePGXimages.c b/tests/comparePGXimages.c index 3e44d632..dfd72a24 100644 --- a/tests/comparePGXimages.c +++ b/tests/comparePGXimages.c @@ -51,7 +51,7 @@ *******************************************************************************/ static double* parseToleranceValues( char* inArg, const int nbcomp) { - double* outArgs= malloc(nbcomp * sizeof(double)); + double* outArgs= malloc((size_t)nbcomp * sizeof(double)); int it_comp = 0; const char delims[] = ":"; char *result = strtok( inArg, delims ); @@ -116,9 +116,9 @@ static char* createMultiComponentsFilename(const char* inFilename, const int ind return outFilename; } - outFilename = (char*)malloc((posToken + 7) * sizeof(char)); /*6*/ + outFilename = (char*)malloc((size_t)(posToken + 7) * sizeof(char)); /*6*/ - strncpy(outFilename, inFilename, posToken); + strncpy(outFilename, inFilename, (size_t)posToken); outFilename[posToken] = '\0'; @@ -155,8 +155,8 @@ static opj_image_t* readImageFromFileTIF(const char* filename, int nbFilenamePGX strcpy(parameters.infile, filename); /* Allocate memory*/ - param_image_read = malloc(nbFilenamePGX * sizeof(opj_image_cmptparm_t)); - data = malloc(nbFilenamePGX * sizeof(*data)); + param_image_read = malloc((size_t)nbFilenamePGX * sizeof(opj_image_cmptparm_t)); + data = malloc((size_t)nbFilenamePGX * sizeof(*data)); for (it_file = 0; it_file < nbFilenamePGX; it_file++) { @@ -209,7 +209,7 @@ static opj_image_t* readImageFromFileTIF(const char* filename, int nbFilenamePGX free(filenameComponentPGX); } - image = opj_image_create(nbFilenamePGX, param_image_read, OPJ_CLRSPC_UNSPECIFIED); + image = opj_image_create((OPJ_UINT32)nbFilenamePGX, param_image_read, OPJ_CLRSPC_UNSPECIFIED); for (it_file = 0; it_file < nbFilenamePGX; it_file++) { /* Copy data into output image and free memory*/ @@ -244,8 +244,8 @@ static opj_image_t* readImageFromFilePGX(const char* filename, int nbFilenamePGX assert( parameters.infile[sizeof(parameters.infile)] == 0 ); /* Allocate memory*/ - param_image_read = malloc(nbFilenamePGX * sizeof(opj_image_cmptparm_t)); - data = malloc(nbFilenamePGX * sizeof(*data)); + param_image_read = malloc((size_t)nbFilenamePGX * sizeof(opj_image_cmptparm_t)); + data = malloc((size_t)nbFilenamePGX * sizeof(*data)); for (it_file = 0; it_file < nbFilenamePGX; it_file++) { @@ -298,7 +298,7 @@ static opj_image_t* readImageFromFilePGX(const char* filename, int nbFilenamePGX free(filenameComponentPGX); } - image = opj_image_create(nbFilenamePGX, param_image_read, OPJ_CLRSPC_UNSPECIFIED); + image = opj_image_create((OPJ_UINT32)nbFilenamePGX, param_image_read, OPJ_CLRSPC_UNSPECIFIED); for (it_file = 0; it_file < nbFilenamePGX; it_file++) { /* Copy data into output image and free memory*/ @@ -332,7 +332,7 @@ static int imageToPNG(const opj_image_t* image, const char* filename, int num_co param_image_write.prec = image->comps[num_comp_select].prec; param_image_write.sgnd = image->comps[num_comp_select].sgnd; - image_write = opj_image_create(1, ¶m_image_write, OPJ_CLRSPC_GRAY); + image_write = opj_image_create(1u, ¶m_image_write, OPJ_CLRSPC_GRAY); memcpy(image_write->comps->data, image->comps[num_comp_select].data, param_image_write.h * param_image_write.w * sizeof(int)); imagetopng(image_write, filename); @@ -406,7 +406,7 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) { case 'b': sizemembasefile = (int)strlen(opj_optarg)+1; - param->base_filename = (char*) malloc(sizemembasefile); + param->base_filename = (char*) malloc((size_t)sizemembasefile); param->base_filename[0] = '\0'; strncpy(param->base_filename, opj_optarg, strlen(opj_optarg)); param->base_filename[strlen(opj_optarg)] = '\0'; @@ -414,7 +414,7 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) break; case 't': sizememtestfile = (int) strlen(opj_optarg) + 1; - param->test_filename = (char*) malloc(sizememtestfile); + param->test_filename = (char*) malloc((size_t)sizememtestfile); param->test_filename[0] = '\0'; strncpy(param->test_filename, opj_optarg, strlen(opj_optarg)); param->test_filename[strlen(opj_optarg)] = '\0'; @@ -481,7 +481,7 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) { /* keep original string*/ int sizeseplist = (int)strlen(separatorList)+1; - char* separatorList2 = (char*)malloc( sizeseplist ); + char* separatorList2 = (char*)malloc( (size_t)sizeseplist ); separatorList2[0] = '\0'; strncpy(separatorList2, separatorList, strlen(separatorList)); separatorList2[strlen(separatorList)] = '\0'; @@ -672,7 +672,7 @@ int main(int argc, char **argv) goto cleanup; } - filenamePNGbase = (char*) malloc(memsizebasefilename); + filenamePNGbase = (char*) malloc((size_t)memsizebasefilename); strcpy(filenamePNGbase, inParam.test_filename); strcat(filenamePNGbase, ".base"); /*printf("filenamePNGbase = %s [%d / %d octets]\n",filenamePNGbase, strlen(filenamePNGbase),memsizebasefilename );*/ @@ -692,7 +692,7 @@ int main(int argc, char **argv) goto cleanup; } - filenamePNGtest = (char*) malloc(memsizetestfilename); + filenamePNGtest = (char*) malloc((size_t)memsizetestfilename); strcpy(filenamePNGtest, inParam.test_filename); strcat(filenamePNGtest, ".test"); /*printf("filenamePNGtest = %s [%d / %d octets]\n",filenamePNGtest, strlen(filenamePNGtest),memsizetestfilename );*/ @@ -811,10 +811,10 @@ int main(int argc, char **argv) { char *filenamePNGbase_it_comp, *filenamePNGtest_it_comp, *filenamePNGdiff_it_comp; - filenamePNGbase_it_comp = (char*) malloc(memsizebasefilename); + filenamePNGbase_it_comp = (char*) malloc((size_t)memsizebasefilename); strcpy(filenamePNGbase_it_comp,filenamePNGbase); - filenamePNGtest_it_comp = (char*) malloc(memsizetestfilename); + filenamePNGtest_it_comp = (char*) malloc((size_t)memsizetestfilename); strcpy(filenamePNGtest_it_comp,filenamePNGtest); filenamePNGdiff_it_comp = (char*) malloc(memsizedifffilename); diff --git a/tests/compareRAWimages.c b/tests/compareRAWimages.c index 4f183529..b19c2148 100644 --- a/tests/compareRAWimages.c +++ b/tests/compareRAWimages.c @@ -77,7 +77,7 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) { case 'b': sizemembasefile = (int)strlen(opj_optarg)+1; - param->base_filename = (char*) malloc(sizemembasefile); + param->base_filename = (char*) malloc((size_t)sizemembasefile); param->base_filename[0] = '\0'; strncpy(param->base_filename, opj_optarg, strlen(opj_optarg)); param->base_filename[strlen(opj_optarg)] = '\0'; @@ -85,7 +85,7 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) break; case 't': sizememtestfile = (int) strlen(opj_optarg) + 1; - param->test_filename = (char*) malloc(sizememtestfile); + param->test_filename = (char*) malloc((size_t)sizememtestfile); param->test_filename[0] = '\0'; strncpy(param->test_filename, opj_optarg, strlen(opj_optarg)); param->test_filename[strlen(opj_optarg)] = '\0'; From 93bc3cb628582a7c225ef27dc6d9093773be1afb Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 6 Mar 2014 16:01:23 +0000 Subject: [PATCH 213/333] [trunk] Remove warning about sign conversion. Update issue 256 --- src/bin/jp2/convert.c | 394 +++++++++++++++++++++--------------------- 1 file changed, 197 insertions(+), 197 deletions(-) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index b4d9544e..a49ea838 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -302,23 +302,23 @@ opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters) { cmptparm[i].prec = 8; cmptparm[i].bpp = 8; cmptparm[i].sgnd = 0; - cmptparm[i].dx = subsampling_dx; - cmptparm[i].dy = subsampling_dy; + cmptparm[i].dx = (OPJ_UINT32)subsampling_dx; + cmptparm[i].dy = (OPJ_UINT32)subsampling_dy; cmptparm[i].w = image_width; cmptparm[i].h = image_height; } /* create the image */ - image = opj_image_create(numcomps, &cmptparm[0], color_space); + image = opj_image_create((OPJ_UINT32)numcomps, &cmptparm[0], color_space); if (!image) return NULL; /* set image offset and reference grid */ - image->x0 = parameters->image_offset_x0; - image->y0 = parameters->image_offset_y0; - image->x1 = !image->x0 ? (image_width - 1) * subsampling_dx + 1 : image->x0 + (image_width - 1) * subsampling_dx + 1; - image->y1 = !image->y0 ? (image_height - 1) * subsampling_dy + 1 : image->y0 + (image_height - 1) * subsampling_dy + 1; + image->x0 = (OPJ_UINT32)parameters->image_offset_x0; + image->y0 = (OPJ_UINT32)parameters->image_offset_y0; + image->x1 = !image->x0 ? (OPJ_UINT32)(image_width - 1) * (OPJ_UINT32)subsampling_dx + 1 : image->x0 + (OPJ_UINT32)(image_width - 1) * (OPJ_UINT32)subsampling_dx + 1; + image->y1 = !image->y0 ? (OPJ_UINT32)(image_height - 1) * (OPJ_UINT32)subsampling_dy + 1 : image->y0 + (OPJ_UINT32)(image_height - 1) * (OPJ_UINT32)subsampling_dy + 1; /* set image data */ for (y=0; y < image_height; y++) @@ -326,9 +326,9 @@ opj_image_t* tgatoimage(const char *filename, opj_cparameters_t *parameters) { int index; if (flip_image) - index = (image_height-y-1)*image_width; + index = (int)((image_height-y-1)*image_width); else - index = y*image_width; + index = (int)(y*image_width); if (numcomps==3) { @@ -432,8 +432,8 @@ int imagetotga(opj_image_t * image, const char *outfile) { } } - width = image->comps[0].w; - height = image->comps[0].h; + width = (int)image->comps[0].w; + height = (int)image->comps[0].h; /* Mono with alpha, or RGB with alpha. */ write_alpha = (image->numcomps==2) || (image->numcomps==4); @@ -454,7 +454,7 @@ int imagetotga(opj_image_t * image, const char *outfile) { for (y=0; y < height; y++) { - unsigned int index=y*width; + unsigned int index= (unsigned int)(y*width); for (x=0; x < width; x++, index++) { @@ -596,10 +596,10 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters) } /* FILE HEADER */ /* ------------- */ - File_h.bfSize = getc(IN); - File_h.bfSize = (getc(IN) << 8) + File_h.bfSize; - File_h.bfSize = (getc(IN) << 16) + File_h.bfSize; - File_h.bfSize = (getc(IN) << 24) + File_h.bfSize; + File_h.bfSize = (DWORD)getc(IN); + File_h.bfSize = (DWORD)(getc(IN) << 8) + File_h.bfSize; + File_h.bfSize = (DWORD)(getc(IN) << 16) + File_h.bfSize; + File_h.bfSize = (DWORD)(getc(IN) << 24) + File_h.bfSize; File_h.bfReserved1 = (WORD)getc(IN); File_h.bfReserved1 = (WORD)((getc(IN) << 8) + File_h.bfReserved1); @@ -607,18 +607,18 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters) File_h.bfReserved2 = (WORD)getc(IN); File_h.bfReserved2 = (WORD)((getc(IN) << 8) + File_h.bfReserved2); - File_h.bfOffBits = getc(IN); - File_h.bfOffBits = (getc(IN) << 8) + File_h.bfOffBits; - File_h.bfOffBits = (getc(IN) << 16) + File_h.bfOffBits; - File_h.bfOffBits = (getc(IN) << 24) + File_h.bfOffBits; + File_h.bfOffBits = (DWORD)getc(IN); + File_h.bfOffBits = (DWORD)(getc(IN) << 8) + File_h.bfOffBits; + File_h.bfOffBits = (DWORD)(getc(IN) << 16) + File_h.bfOffBits; + File_h.bfOffBits = (DWORD)(getc(IN) << 24) + File_h.bfOffBits; /* INFO HEADER */ /* ------------- */ - Info_h.biSize = getc(IN); - Info_h.biSize = (getc(IN) << 8) + Info_h.biSize; - Info_h.biSize = (getc(IN) << 16) + Info_h.biSize; - Info_h.biSize = (getc(IN) << 24) + Info_h.biSize; + Info_h.biSize = (DWORD)getc(IN); + Info_h.biSize = (DWORD)(getc(IN) << 8) + Info_h.biSize; + Info_h.biSize = (DWORD)(getc(IN) << 16) + Info_h.biSize; + Info_h.biSize = (DWORD)(getc(IN) << 24) + Info_h.biSize; if(Info_h.biSize != 40) { @@ -626,17 +626,17 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters) fclose(IN); return NULL; } - Info_h.biWidth = getc(IN); - Info_h.biWidth = (getc(IN) << 8) + Info_h.biWidth; - Info_h.biWidth = (getc(IN) << 16) + Info_h.biWidth; - Info_h.biWidth = (getc(IN) << 24) + Info_h.biWidth; - w = Info_h.biWidth; + Info_h.biWidth = (DWORD)getc(IN); + Info_h.biWidth = (DWORD)(getc(IN) << 8) + Info_h.biWidth; + Info_h.biWidth = (DWORD)(getc(IN) << 16) + Info_h.biWidth; + Info_h.biWidth = (DWORD)(getc(IN) << 24) + Info_h.biWidth; + w = (int)Info_h.biWidth; - Info_h.biHeight = getc(IN); - Info_h.biHeight = (getc(IN) << 8) + Info_h.biHeight; - Info_h.biHeight = (getc(IN) << 16) + Info_h.biHeight; - Info_h.biHeight = (getc(IN) << 24) + Info_h.biHeight; - h = Info_h.biHeight; + Info_h.biHeight = (DWORD)getc(IN); + Info_h.biHeight = (DWORD)(getc(IN) << 8) + Info_h.biHeight; + Info_h.biHeight = (DWORD)(getc(IN) << 16) + Info_h.biHeight; + Info_h.biHeight = (DWORD)(getc(IN) << 24) + Info_h.biHeight; + h = (int)Info_h.biHeight; Info_h.biPlanes = (WORD)getc(IN); Info_h.biPlanes = (WORD)((getc(IN) << 8) + Info_h.biPlanes); @@ -644,35 +644,35 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters) Info_h.biBitCount = (WORD)getc(IN); Info_h.biBitCount = (WORD)((getc(IN) << 8) + Info_h.biBitCount); - Info_h.biCompression = getc(IN); - Info_h.biCompression = (getc(IN) << 8) + Info_h.biCompression; - Info_h.biCompression = (getc(IN) << 16) + Info_h.biCompression; - Info_h.biCompression = (getc(IN) << 24) + Info_h.biCompression; + Info_h.biCompression = (DWORD)getc(IN); + Info_h.biCompression = (DWORD)(getc(IN) << 8) + Info_h.biCompression; + Info_h.biCompression = (DWORD)(getc(IN) << 16) + Info_h.biCompression; + Info_h.biCompression = (DWORD)(getc(IN) << 24) + Info_h.biCompression; - Info_h.biSizeImage = getc(IN); - Info_h.biSizeImage = (getc(IN) << 8) + Info_h.biSizeImage; - Info_h.biSizeImage = (getc(IN) << 16) + Info_h.biSizeImage; - Info_h.biSizeImage = (getc(IN) << 24) + Info_h.biSizeImage; + Info_h.biSizeImage = (DWORD)getc(IN); + Info_h.biSizeImage = (DWORD)(getc(IN) << 8) + Info_h.biSizeImage; + Info_h.biSizeImage = (DWORD)(getc(IN) << 16) + Info_h.biSizeImage; + Info_h.biSizeImage = (DWORD)(getc(IN) << 24) + Info_h.biSizeImage; - Info_h.biXpelsPerMeter = getc(IN); - Info_h.biXpelsPerMeter = (getc(IN) << 8) + Info_h.biXpelsPerMeter; - Info_h.biXpelsPerMeter = (getc(IN) << 16) + Info_h.biXpelsPerMeter; - Info_h.biXpelsPerMeter = (getc(IN) << 24) + Info_h.biXpelsPerMeter; + Info_h.biXpelsPerMeter = (DWORD)getc(IN); + Info_h.biXpelsPerMeter = (DWORD)(getc(IN) << 8) + Info_h.biXpelsPerMeter; + Info_h.biXpelsPerMeter = (DWORD)(getc(IN) << 16) + Info_h.biXpelsPerMeter; + Info_h.biXpelsPerMeter = (DWORD)(getc(IN) << 24) + Info_h.biXpelsPerMeter; - Info_h.biYpelsPerMeter = getc(IN); - Info_h.biYpelsPerMeter = (getc(IN) << 8) + Info_h.biYpelsPerMeter; - Info_h.biYpelsPerMeter = (getc(IN) << 16) + Info_h.biYpelsPerMeter; - Info_h.biYpelsPerMeter = (getc(IN) << 24) + Info_h.biYpelsPerMeter; + Info_h.biYpelsPerMeter = (DWORD)getc(IN); + Info_h.biYpelsPerMeter = (DWORD)(getc(IN) << 8) + Info_h.biYpelsPerMeter; + Info_h.biYpelsPerMeter = (DWORD)(getc(IN) << 16) + Info_h.biYpelsPerMeter; + Info_h.biYpelsPerMeter = (DWORD)(getc(IN) << 24) + Info_h.biYpelsPerMeter; - Info_h.biClrUsed = getc(IN); - Info_h.biClrUsed = (getc(IN) << 8) + Info_h.biClrUsed; - Info_h.biClrUsed = (getc(IN) << 16) + Info_h.biClrUsed; - Info_h.biClrUsed = (getc(IN) << 24) + Info_h.biClrUsed; + Info_h.biClrUsed = (DWORD)getc(IN); + Info_h.biClrUsed = (DWORD)(getc(IN) << 8) + Info_h.biClrUsed; + Info_h.biClrUsed = (DWORD)(getc(IN) << 16) + Info_h.biClrUsed; + Info_h.biClrUsed = (DWORD)(getc(IN) << 24) + Info_h.biClrUsed; - Info_h.biClrImportant = getc(IN); - Info_h.biClrImportant = (getc(IN) << 8) + Info_h.biClrImportant; - Info_h.biClrImportant = (getc(IN) << 16) + Info_h.biClrImportant; - Info_h.biClrImportant = (getc(IN) << 24) + Info_h.biClrImportant; + Info_h.biClrImportant = (DWORD)getc(IN); + Info_h.biClrImportant = (DWORD)(getc(IN) << 8) + Info_h.biClrImportant; + Info_h.biClrImportant = (DWORD)(getc(IN) << 16) + Info_h.biClrImportant; + Info_h.biClrImportant = (DWORD)(getc(IN) << 24) + Info_h.biClrImportant; /* Read the data and store them in the OUT file */ @@ -687,13 +687,13 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters) cmptparm[i].prec = 8; cmptparm[i].bpp = 8; cmptparm[i].sgnd = 0; - cmptparm[i].dx = subsampling_dx; - cmptparm[i].dy = subsampling_dy; - cmptparm[i].w = w; - cmptparm[i].h = h; + cmptparm[i].dx = (OPJ_UINT32)subsampling_dx; + cmptparm[i].dy = (OPJ_UINT32)subsampling_dy; + cmptparm[i].w = (OPJ_UINT32)w; + cmptparm[i].h = (OPJ_UINT32)h; } /* create the image */ - image = opj_image_create(numcomps, &cmptparm[0], color_space); + image = opj_image_create((OPJ_UINT32)numcomps, &cmptparm[0], color_space); if(!image) { fclose(IN); @@ -701,10 +701,10 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters) } /* set image offset and reference grid */ - image->x0 = parameters->image_offset_x0; - image->y0 = parameters->image_offset_y0; - image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : (int)(image->x0 + (w - 1) * subsampling_dx + 1); - image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : (int)(image->y0 + (h - 1) * subsampling_dy + 1); + image->x0 = (OPJ_UINT32)parameters->image_offset_x0; + image->y0 = (OPJ_UINT32)parameters->image_offset_y0; + image->x1 = !image->x0 ? (OPJ_UINT32)(w - 1) * (OPJ_UINT32)subsampling_dx + 1 : image->x0 + (OPJ_UINT32)(w - 1) * (OPJ_UINT32)subsampling_dx + 1; + image->y1 = !image->y0 ? (OPJ_UINT32)(h - 1) * (OPJ_UINT32)subsampling_dy + 1 : image->y0 + (OPJ_UINT32)(h - 1) * (OPJ_UINT32)subsampling_dy + 1; /* set image data */ @@ -734,7 +734,7 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters) for(y = 0; y < (int)H; y++) { - unsigned char *scanline = RGB + (3 * W + PAD) * (H - 1 - y); + unsigned char *scanline = RGB + (3 * (unsigned int)W + PAD) * ((unsigned int)H - 1 - (unsigned int)y); for(x = 0; x < (int)W; x++) { unsigned char *pixel = &scanline[3 * x]; @@ -787,13 +787,13 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters) cmptparm[i].prec = 8; cmptparm[i].bpp = 8; cmptparm[i].sgnd = 0; - cmptparm[i].dx = subsampling_dx; - cmptparm[i].dy = subsampling_dy; - cmptparm[i].w = w; - cmptparm[i].h = h; + cmptparm[i].dx = (OPJ_UINT32)subsampling_dx; + cmptparm[i].dy = (OPJ_UINT32)subsampling_dy; + cmptparm[i].w = (OPJ_UINT32)w; + cmptparm[i].h = (OPJ_UINT32)h; } /* create the image */ - image = opj_image_create(numcomps, &cmptparm[0], color_space); + image = opj_image_create((OPJ_UINT32)numcomps, &cmptparm[0], color_space); if(!image) { fclose(IN); @@ -802,10 +802,10 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters) } /* set image offset and reference grid */ - image->x0 = parameters->image_offset_x0; - image->y0 = parameters->image_offset_y0; - image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : (int)(image->x0 + (w - 1) * subsampling_dx + 1); - image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : (int)(image->y0 + (h - 1) * subsampling_dy + 1); + image->x0 = (OPJ_UINT32)parameters->image_offset_x0; + image->y0 = (OPJ_UINT32)parameters->image_offset_y0; + image->x1 = !image->x0 ? (OPJ_UINT32)(w - 1) * (OPJ_UINT32)subsampling_dx + 1 : image->x0 + (OPJ_UINT32)(w - 1) * (OPJ_UINT32)subsampling_dx + 1; + image->y1 = !image->y0 ? (OPJ_UINT32)(h - 1) * (OPJ_UINT32)subsampling_dy + 1 : image->y0 + (OPJ_UINT32)(h - 1) * (OPJ_UINT32)subsampling_dy + 1; /* set image data */ @@ -897,13 +897,13 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters) cmptparm[i].prec = 8; cmptparm[i].bpp = 8; cmptparm[i].sgnd = 0; - cmptparm[i].dx = subsampling_dx; - cmptparm[i].dy = subsampling_dy; - cmptparm[i].w = w; - cmptparm[i].h = h; + cmptparm[i].dx = (OPJ_UINT32)subsampling_dx; + cmptparm[i].dy = (OPJ_UINT32)subsampling_dy; + cmptparm[i].w = (OPJ_UINT32)w; + cmptparm[i].h = (OPJ_UINT32)h; } /* create the image */ - image = opj_image_create(numcomps, &cmptparm[0], color_space); + image = opj_image_create((OPJ_UINT32)numcomps, &cmptparm[0], color_space); if (!image) { fclose(IN); @@ -914,10 +914,10 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters) } /* set image offset and reference grid */ - image->x0 = parameters->image_offset_x0; - image->y0 = parameters->image_offset_y0; - image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : (int)(image->x0 + (w - 1) * subsampling_dx + 1); - image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : (int)(image->y0 + (h - 1) * subsampling_dy + 1); + image->x0 = (OPJ_UINT32)parameters->image_offset_x0; + image->y0 = (OPJ_UINT32)parameters->image_offset_y0; + image->x1 = !image->x0 ? (OPJ_UINT32)(w - 1) * (OPJ_UINT32)subsampling_dx + 1 : image->x0 + (OPJ_UINT32)(w - 1) * (OPJ_UINT32)subsampling_dx + 1; + image->y1 = !image->y0 ? (OPJ_UINT32)(h - 1) * (OPJ_UINT32)subsampling_dy + 1 : image->y0 + (OPJ_UINT32)(h - 1) * (OPJ_UINT32)subsampling_dy + 1; /* set image data */ @@ -958,9 +958,9 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters) else if (c == 0x02) /* MOVE by dxdy */ { c = getc(IN); - x += c; + x += (unsigned int)c; c = getc(IN); - y += c; + y += (unsigned int)c; pix = RGB + (H - y - 1) * W + x; } else /* 03 .. 255 */ @@ -1051,8 +1051,8 @@ int imagetobmp(opj_image_t * image, const char *outfile) { return 1; } - w = image->comps[0].w; - h = image->comps[0].h; + w = (int)image->comps[0].w; + h = (int)image->comps[0].h; fprintf(fdest, "BM"); @@ -1090,19 +1090,19 @@ int imagetobmp(opj_image_t * image, const char *outfile) { fprintf(fdest, "%c%c%c%c", (0) & 0xff, ((0) >> 8) & 0xff, ((0) >> 16) & 0xff, ((0) >> 24) & 0xff); if (image->comps[0].prec > 8) { - adjustR = image->comps[0].prec - 8; + adjustR = (int)image->comps[0].prec - 8; printf("BMP CONVERSION: Truncating component 0 from %d bits to 8 bits\n", image->comps[0].prec); } else adjustR = 0; if (image->comps[1].prec > 8) { - adjustG = image->comps[1].prec - 8; + adjustG = (int)image->comps[1].prec - 8; printf("BMP CONVERSION: Truncating component 1 from %d bits to 8 bits\n", image->comps[1].prec); } else adjustG = 0; if (image->comps[2].prec > 8) { - adjustB = image->comps[2].prec - 8; + adjustB = (int)image->comps[2].prec - 8; printf("BMP CONVERSION: Truncating component 2 from %d bits to 8 bits\n", image->comps[2].prec); } else @@ -1145,8 +1145,8 @@ int imagetobmp(opj_image_t * image, const char *outfile) { <<-- <<-- <<-- <<-- */ fdest = fopen(outfile, "wb"); - w = image->comps[0].w; - h = image->comps[0].h; + w = (int)image->comps[0].w; + h = (int)image->comps[0].h; fprintf(fdest, "BM"); @@ -1185,7 +1185,7 @@ int imagetobmp(opj_image_t * image, const char *outfile) { fprintf(fdest, "%c%c%c%c", (256) & 0xff, ((256) >> 8) & 0xff, ((256) >> 16) & 0xff, ((256) >> 24) & 0xff); if (image->comps[0].prec > 8) { - adjustR = image->comps[0].prec - 8; + adjustR = (int)image->comps[0].prec - 8; printf("BMP CONVERSION: Truncating component 0 from %d bits to 8 bits\n", image->comps[0].prec); }else adjustR = 0; @@ -1276,9 +1276,9 @@ static unsigned int readuint(FILE * f, int bigendian) return 0; } if (bigendian) - return (c1 << 24) + (c2 << 16) + (c3 << 8) + c4; + return (unsigned int)(c1 << 24) + (unsigned int)(c2 << 16) + (unsigned int)(c3 << 8) + c4; else - return (c4 << 24) + (c3 << 16) + (c2 << 8) + c1; + return (unsigned int)(c4 << 24) + (unsigned int)(c3 << 16) + (unsigned int)(c2 << 8) + c1; } opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters) { @@ -1335,10 +1335,10 @@ opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters) { /* initialize image component */ - cmptparm.x0 = parameters->image_offset_x0; - cmptparm.y0 = parameters->image_offset_y0; - cmptparm.w = !cmptparm.x0 ? (w - 1) * parameters->subsampling_dx + 1 : (int)(cmptparm.x0 + (w - 1) * parameters->subsampling_dx + 1); - cmptparm.h = !cmptparm.y0 ? (h - 1) * parameters->subsampling_dy + 1 : (int)(cmptparm.y0 + (h - 1) * parameters->subsampling_dy + 1); + cmptparm.x0 = (OPJ_UINT32)parameters->image_offset_x0; + cmptparm.y0 = (OPJ_UINT32)parameters->image_offset_y0; + cmptparm.w = !cmptparm.x0 ? (OPJ_UINT32)((w - 1) * parameters->subsampling_dx + 1) : cmptparm.x0 + (OPJ_UINT32)(w - 1) * (OPJ_UINT32)parameters->subsampling_dx + 1; + cmptparm.h = !cmptparm.y0 ? (OPJ_UINT32)((h - 1) * parameters->subsampling_dy + 1) : cmptparm.y0 + (OPJ_UINT32)(h - 1) * (OPJ_UINT32)parameters->subsampling_dy + 1; if (sign == '-') { cmptparm.sgnd = 1; @@ -1355,13 +1355,13 @@ opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters) { } else ushift = dshift = force8 = adjustS = 0; - cmptparm.prec = prec; - cmptparm.bpp = prec; - cmptparm.dx = parameters->subsampling_dx; - cmptparm.dy = parameters->subsampling_dy; + cmptparm.prec = (OPJ_UINT32)prec; + cmptparm.bpp = (OPJ_UINT32)prec; + cmptparm.dx = (OPJ_UINT32)parameters->subsampling_dx; + cmptparm.dy = (OPJ_UINT32)parameters->subsampling_dy; /* create the image */ - image = opj_image_create(numcomps, &cmptparm, color_space); + image = opj_image_create((OPJ_UINT32)numcomps, &cmptparm, color_space); if(!image) { fclose(f); return NULL; @@ -1402,7 +1402,7 @@ opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters) { } } else { if (!comp->sgnd) { - v = readuint(f, bigendian); + v = (int)readuint(f, bigendian); } else { v = (int) readuint(f, bigendian); } @@ -1412,7 +1412,7 @@ opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters) { comp->data[i] = v; } fclose(f); - comp->bpp = int_floorlog2(max) + 1; + comp->bpp = (OPJ_UINT32)int_floorlog2(max) + 1; return image; } @@ -1474,8 +1474,8 @@ int imagetopgx(opj_image_t * image, const char *outfile) goto fin; } - w = image->comps[compno].w; - h = image->comps[compno].h; + w = (int)image->comps[compno].w; + h = (int)image->comps[compno].h; fprintf(fdest, "PG ML %c %d %d %d\n", comp->sgnd ? '-' : '+', comp->prec, w, h); @@ -1491,7 +1491,7 @@ int imagetopgx(opj_image_t * image, const char *outfile) { /* FIXME: clamp func is being called within a loop */ const int val = clamp(image->comps[compno].data[i], - comp->prec, comp->sgnd); + (int)comp->prec, (int)comp->sgnd); for (j = nbytes - 1; j >= 0; j--) { @@ -1812,27 +1812,27 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters) { subsampling_dx = parameters->subsampling_dx; subsampling_dy = parameters->subsampling_dy; - memset(&cmptparm[0], 0, numcomps * sizeof(opj_image_cmptparm_t)); + memset(&cmptparm[0], 0, (size_t)numcomps * sizeof(opj_image_cmptparm_t)); for(i = 0; i < numcomps; i++) { - cmptparm[i].prec = prec; - cmptparm[i].bpp = prec; + cmptparm[i].prec = (OPJ_UINT32)prec; + cmptparm[i].bpp = (OPJ_UINT32)prec; cmptparm[i].sgnd = 0; - cmptparm[i].dx = subsampling_dx; - cmptparm[i].dy = subsampling_dy; - cmptparm[i].w = w; - cmptparm[i].h = h; + cmptparm[i].dx = (OPJ_UINT32)subsampling_dx; + cmptparm[i].dy = (OPJ_UINT32)subsampling_dy; + cmptparm[i].w = (OPJ_UINT32)w; + cmptparm[i].h = (OPJ_UINT32)h; } - image = opj_image_create(numcomps, &cmptparm[0], color_space); + image = opj_image_create((OPJ_UINT32)numcomps, &cmptparm[0], color_space); if(!image) { fclose(fp); return NULL; } /* set image offset and reference grid */ - image->x0 = parameters->image_offset_x0; - image->y0 = parameters->image_offset_y0; - image->x1 = parameters->image_offset_x0 + (w - 1) * subsampling_dx + 1; - image->y1 = parameters->image_offset_y0 + (h - 1) * subsampling_dy + 1; + image->x0 = (OPJ_UINT32)parameters->image_offset_x0; + image->y0 = (OPJ_UINT32)parameters->image_offset_y0; + image->x1 = (OPJ_UINT32)(parameters->image_offset_x0 + (w - 1) * subsampling_dx + 1); + image->y1 = (OPJ_UINT32)(parameters->image_offset_y0 + (h - 1) * subsampling_dy + 1); if((format == 2) || (format == 3)) /* ascii pixmap */ { @@ -1846,7 +1846,7 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters) { if (fscanf(fp, "%u", &index) != 1) fprintf(stderr, "\nWARNING: fscanf return a number of element different from the expected.\n"); - image->comps[compno].data[i] = (index * 255)/header_info.maxval; + image->comps[compno].data[i] = (OPJ_INT32)(index * 255)/header_info.maxval; } } } @@ -1949,7 +1949,7 @@ int imagetopnm(opj_image_t * image, const char *outfile) alpha = NULL; - if((prec = image->comps[0].prec) > 16) + if((prec = (int)image->comps[0].prec) > 16) { fprintf(stderr,"%s:%d:imagetopnm\n\tprecision %d is larger than 16" "\n\t: refused.\n",__FILE__,__LINE__,prec); @@ -1983,7 +1983,7 @@ int imagetopnm(opj_image_t * image, const char *outfile) } two = (prec > 8); triple = (ncomp > 2); - wr = image->comps[0].w; hr = image->comps[0].h; + wr = (int)image->comps[0].w; hr = (int)image->comps[0].h; max = (1<comps[0].data; @@ -2110,8 +2110,8 @@ if(v > 65535) v = 65535; else if(v < 0) v = 0; free(destname); return 1; } - wr = image->comps[compno].w; hr = image->comps[compno].h; - prec = image->comps[compno].prec; + wr = (int)image->comps[compno].w; hr = (int)image->comps[compno].h; + prec = (int)image->comps[compno].prec; max = (1<comps[0].prec; + bps = (int)image->comps[0].prec; if(bps > 8 && bps < 16) { @@ -2198,7 +2198,7 @@ int imagetotif(opj_image_t * image, const char *outfile) fprintf(stderr, "imagetotif:failed to open %s for writing\n", outfile); return 1; } - sgnd = image->comps[0].sgnd; + sgnd = (int)image->comps[0].sgnd; adjust = sgnd ? 1 << (image->comps[0].prec - 1) : 0; if(image->numcomps >= 3 @@ -2211,8 +2211,8 @@ int imagetotif(opj_image_t * image, const char *outfile) { has_alpha = (image->numcomps == 4); - width = image->comps[0].w; - height = image->comps[0].h; + width = (int)image->comps[0].w; + height = (int)image->comps[0].h; imgsize = width * height ; TIFFSetField(tif, TIFFTAG_IMAGEWIDTH, width); @@ -2443,8 +2443,8 @@ int imagetotif(opj_image_t * image, const char *outfile) has_alpha = (image->numcomps == 2); - width = image->comps[0].w; - height = image->comps[0].h; + width = (int)image->comps[0].w; + height = (int)image->comps[0].h; imgsize = width * height; /* Set tags */ @@ -2596,8 +2596,8 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) TIFFGetField(tif, TIFFTAG_SAMPLESPERPIXEL, &tiSpp); TIFFGetField(tif, TIFFTAG_PHOTOMETRIC, &tiPhoto); TIFFGetField(tif, TIFFTAG_PLANARCONFIG, &tiPC); - w= tiWidth; - h= tiHeight; + w= (int)tiWidth; + h= (int)tiHeight; if(tiBps != 8 && tiBps != 16 && tiBps != 12) tiBps = 0; if(tiPhoto != 1 && tiPhoto != 2) tiPhoto = 0; @@ -2676,10 +2676,10 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) cmptparm[j].prec = tiBps; cmptparm[j].bpp = tiBps; } - cmptparm[j].dx = subsampling_dx; - cmptparm[j].dy = subsampling_dy; - cmptparm[j].w = w; - cmptparm[j].h = h; + cmptparm[j].dx = (OPJ_UINT32)subsampling_dx; + cmptparm[j].dy = (OPJ_UINT32)subsampling_dy; + cmptparm[j].w = (OPJ_UINT32)w; + cmptparm[j].h = (OPJ_UINT32)h; #ifdef USETILEMODE cmptparm[j].x0 = 0; cmptparm[j].y0 = 0; @@ -2689,7 +2689,7 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) #ifdef USETILEMODE image = opj_image_tile_create(numcomps,&cmptparm[0],color_space); #else - image = opj_image_create(numcomps, &cmptparm[0], color_space); + image = opj_image_create((OPJ_UINT32)numcomps, &cmptparm[0], color_space); #endif if(!image) @@ -2699,18 +2699,18 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) } /* set image offset and reference grid */ - image->x0 = parameters->image_offset_x0; - image->y0 = parameters->image_offset_y0; - image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : - (int)(image->x0 + (w - 1) * subsampling_dx + 1); - image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : - (int)(image->y0 + (h - 1) * subsampling_dy + 1); + image->x0 = (OPJ_UINT32)parameters->image_offset_x0; + image->y0 = (OPJ_UINT32)parameters->image_offset_y0; + image->x1 = !image->x0 ? (OPJ_UINT32)(w - 1) * (OPJ_UINT32)subsampling_dx + 1 : + image->x0 + (OPJ_UINT32)(w - 1) * (OPJ_UINT32)subsampling_dx + 1; + image->y1 = !image->y0 ? (OPJ_UINT32)(h - 1) * (OPJ_UINT32)subsampling_dy + 1 : + image->y0 + (OPJ_UINT32)(h - 1) * (OPJ_UINT32)subsampling_dy + 1; buf = _TIFFmalloc(TIFFStripSize(tif)); strip_size=TIFFStripSize(tif); index = 0; - imgsize = image->comps[0].w * image->comps[0].h ; + imgsize = (int)(image->comps[0].w * image->comps[0].h); /* Read the Image components */ for(strip = 0; strip < TIFFNumberOfStrips(tif); strip++) @@ -2831,15 +2831,15 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) { cmptparm[j].prec = tiBps; cmptparm[j].bpp = tiBps; - cmptparm[j].dx = subsampling_dx; - cmptparm[j].dy = subsampling_dy; - cmptparm[j].w = w; - cmptparm[j].h = h; + cmptparm[j].dx = (OPJ_UINT32)subsampling_dx; + cmptparm[j].dy = (OPJ_UINT32)subsampling_dy; + cmptparm[j].w = (OPJ_UINT32)w; + cmptparm[j].h = (OPJ_UINT32)h; } #ifdef USETILEMODE image = opj_image_tile_create(numcomps,&cmptparm[0],color_space); #else - image = opj_image_create(numcomps, &cmptparm[0], color_space); + image = opj_image_create((OPJ_UINT32)numcomps, &cmptparm[0], color_space); #endif if(!image) @@ -2849,18 +2849,18 @@ opj_image_t* tiftoimage(const char *filename, opj_cparameters_t *parameters) } /* set image offset and reference grid */ - image->x0 = parameters->image_offset_x0; - image->y0 = parameters->image_offset_y0; - image->x1 = !image->x0 ? (w - 1) * subsampling_dx + 1 : - (int)(image->x0 + (w - 1) * subsampling_dx + 1); - image->y1 = !image->y0 ? (h - 1) * subsampling_dy + 1 : - (int)(image->y0 + (h - 1) * subsampling_dy + 1); + image->x0 = (OPJ_UINT32)parameters->image_offset_x0; + image->y0 = (OPJ_UINT32)parameters->image_offset_y0; + image->x1 = !image->x0 ? (OPJ_UINT32)(w - 1) * (OPJ_UINT32)subsampling_dx + 1 : + image->x0 + (OPJ_UINT32)(w - 1) * (OPJ_UINT32)subsampling_dx + 1; + image->y1 = !image->y0 ? (OPJ_UINT32)(h - 1) * (OPJ_UINT32)subsampling_dy + 1 : + image->y0 + (OPJ_UINT32)(h - 1) * (OPJ_UINT32)subsampling_dy + 1; buf = _TIFFmalloc(TIFFStripSize(tif)); strip_size = TIFFStripSize(tif); index = 0; - imgsize = image->comps[0].w * image->comps[0].h ; + imgsize = (int)(image->comps[0].w * image->comps[0].h); /* Read the Image components */ for(strip = 0; strip < TIFFNumberOfStrips(tif); strip++) @@ -2956,31 +2956,31 @@ static opj_image_t* rawtoimage_common(const char *filename, opj_cparameters_t *p color_space = OPJ_CLRSPC_SRGB; w = raw_cp->rawWidth; h = raw_cp->rawHeight; - cmptparm = (opj_image_cmptparm_t*) malloc(numcomps * sizeof(opj_image_cmptparm_t)); + cmptparm = (opj_image_cmptparm_t*) malloc((size_t)numcomps * sizeof(opj_image_cmptparm_t)); /* initialize image components */ - memset(&cmptparm[0], 0, numcomps * sizeof(opj_image_cmptparm_t)); + memset(&cmptparm[0], 0, (size_t)numcomps * sizeof(opj_image_cmptparm_t)); for(i = 0; i < numcomps; i++) { - cmptparm[i].prec = raw_cp->rawBitDepth; - cmptparm[i].bpp = raw_cp->rawBitDepth; - cmptparm[i].sgnd = raw_cp->rawSigned; - cmptparm[i].dx = subsampling_dx; - cmptparm[i].dy = subsampling_dy; - cmptparm[i].w = w; - cmptparm[i].h = h; + cmptparm[i].prec = (OPJ_UINT32)raw_cp->rawBitDepth; + cmptparm[i].bpp = (OPJ_UINT32)raw_cp->rawBitDepth; + cmptparm[i].sgnd = (OPJ_UINT32)raw_cp->rawSigned; + cmptparm[i].dx = (OPJ_UINT32)subsampling_dx; + cmptparm[i].dy = (OPJ_UINT32)subsampling_dy; + cmptparm[i].w = (OPJ_UINT32)w; + cmptparm[i].h = (OPJ_UINT32)h; } /* create the image */ - image = opj_image_create(numcomps, &cmptparm[0], color_space); + image = opj_image_create((OPJ_UINT32)numcomps, &cmptparm[0], color_space); free(cmptparm); if(!image) { fclose(f); return NULL; } /* set image offset and reference grid */ - image->x0 = parameters->image_offset_x0; - image->y0 = parameters->image_offset_y0; - image->x1 = parameters->image_offset_x0 + (w - 1) * subsampling_dx + 1; - image->y1 = parameters->image_offset_y0 + (h - 1) * subsampling_dy + 1; + image->x0 = (OPJ_UINT32)parameters->image_offset_x0; + image->y0 = (OPJ_UINT32)parameters->image_offset_y0; + image->x1 = (OPJ_UINT32)parameters->image_offset_x0 + (OPJ_UINT32)(w - 1) * (OPJ_UINT32)subsampling_dx + 1; + image->y1 = (OPJ_UINT32)parameters->image_offset_y0 + (OPJ_UINT32)(h - 1) * (OPJ_UINT32)subsampling_dy + 1; if(raw_cp->rawBitDepth <= 8) { @@ -3074,8 +3074,8 @@ static int imagetoraw_common(opj_image_t * image, const char *outfile, OPJ_BOOL fprintf(stdout,"Component %d characteristics: %dx%dx%d %s\n", compno, image->comps[compno].w, image->comps[compno].h, image->comps[compno].prec, image->comps[compno].sgnd==1 ? "signed": "unsigned"); - w = image->comps[compno].w; - h = image->comps[compno].h; + w = (int)image->comps[compno].w; + h = (int)image->comps[compno].h; if(image->comps[compno].prec <= 8) { @@ -3289,7 +3289,7 @@ opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params) has_alpha = (color_type == PNG_COLOR_TYPE_RGB_ALPHA); - nr_comp = 3 + has_alpha; + nr_comp = 3 + (unsigned int)has_alpha; bit_depth = png_get_bit_depth(png, info); @@ -3305,12 +3305,12 @@ opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params) for(i = 0; i < nr_comp; ++i) { - cmptparm[i].prec = bit_depth; + cmptparm[i].prec = (OPJ_UINT32)bit_depth; /* bits_per_pixel: 8 or 16 */ - cmptparm[i].bpp = bit_depth; + cmptparm[i].bpp = (OPJ_UINT32)bit_depth; cmptparm[i].sgnd = 0; - cmptparm[i].dx = sub_dx; - cmptparm[i].dy = sub_dy; + cmptparm[i].dx = (OPJ_UINT32)sub_dx; + cmptparm[i].dy = (OPJ_UINT32)sub_dy; cmptparm[i].w = (OPJ_UINT32)width; cmptparm[i].h = (OPJ_UINT32)height; } @@ -3319,10 +3319,10 @@ opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params) if(image == NULL) goto fin; - image->x0 = params->image_offset_x0; - image->y0 = params->image_offset_y0; - image->x1 = (OPJ_UINT32)(image->x0 + (width - 1) * sub_dx + 1 + image->x0); - image->y1 = (OPJ_UINT32)(image->y0 + (height - 1) * sub_dy + 1 + image->y0); + image->x0 = (OPJ_UINT32)params->image_offset_x0; + image->y0 = (OPJ_UINT32)params->image_offset_y0; + image->x1 = (OPJ_UINT32)(image->x0 + (width - 1) * (OPJ_UINT32)sub_dx + 1 + image->x0); + image->y1 = (OPJ_UINT32)(image->y0 + (height - 1) * (OPJ_UINT32)sub_dy + 1 + image->y0); r = image->comps[0].data; g = image->comps[1].data; @@ -3382,8 +3382,8 @@ int imagetopng(opj_image_t * image, const char *write_idf) png_color_8 sig_bit; is16 = force16 = force8 = ushift = dshift = 0; fails = 1; - prec = image->comps[0].prec; - nr_comp = image->numcomps; + prec = (int)image->comps[0].prec; + nr_comp = (int)image->numcomps; if(prec > 8 && prec < 16) { @@ -3479,8 +3479,8 @@ int imagetopng(opj_image_t * image, const char *write_idf) is16 = (prec == 16); - width = image->comps[0].w; - height = image->comps[0].h; + width = (int)image->comps[0].w; + height = (int)image->comps[0].h; red = image->comps[0].data; green = image->comps[1].data; @@ -3503,7 +3503,7 @@ int imagetopng(opj_image_t * image, const char *write_idf) } png_set_sBIT(png, info, &sig_bit); - png_set_IHDR(png, info, width, height, prec, + png_set_IHDR(png, info, (png_uint_32)width, (png_uint_32)height, prec, color_type, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); @@ -3525,7 +3525,7 @@ image->comps[1].sgnd,image->comps[2].sgnd,width,height,has_alpha); adjustG = (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); adjustB = (image->comps[2].sgnd ? 1 << (image->comps[2].prec - 1) : 0); - row_buf = (unsigned char*)malloc(width * nr_comp * 2); + row_buf = (unsigned char*)malloc((size_t)width * (size_t)nr_comp * 2); for(y = 0; y < height; ++y) { @@ -3629,10 +3629,10 @@ image->comps[1].sgnd,image->comps[2].sgnd,width,height,has_alpha); color_type = PNG_COLOR_TYPE_GRAY_ALPHA; adjustA = (image->comps[1].sgnd ? 1 << (image->comps[1].prec - 1) : 0); } - width = image->comps[0].w; - height = image->comps[0].h; + width = (int)image->comps[0].w; + height = (int)image->comps[0].h; - png_set_IHDR(png, info, width, height, sig_bit.gray, + png_set_IHDR(png, info, (png_uint_32)width, (png_uint_32)height, sig_bit.gray, color_type, PNG_INTERLACE_NONE, PNG_COMPRESSION_TYPE_BASE, PNG_FILTER_TYPE_BASE); @@ -3654,7 +3654,7 @@ image->comps[1].sgnd,image->comps[2].sgnd,width,height,has_alpha); if(prec > 8) { row_buf = (unsigned char*) - malloc(width * nr_comp * sizeof(unsigned short)); + malloc((size_t)width * (size_t)nr_comp * sizeof(unsigned short)); for(y = 0; y < height; ++y) { @@ -3686,7 +3686,7 @@ image->comps[1].sgnd,image->comps[2].sgnd,width,height,has_alpha); } else /* prec <= 8 */ { - row_buf = (unsigned char*)calloc(width, nr_comp * 2); + row_buf = (unsigned char*)calloc((size_t)width, (size_t)nr_comp * 2); for(y = 0; y < height; ++y) { From 0f45e38b521e3a6244f19565d124f7c82bdb84f2 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 6 Mar 2014 16:26:24 +0000 Subject: [PATCH 214/333] [trunk] Remove warning about sign conversion. Update issue 256 --- src/lib/openjp2/j2k.c | 108 +++++++++++++++++++++--------------------- 1 file changed, 54 insertions(+), 54 deletions(-) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 90e5cad8..3d527f81 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -7778,7 +7778,7 @@ OPJ_BOOL opj_j2k_update_image_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data, opj_im } if ( l_y0_dest < (OPJ_UINT32)l_res->y0 ) { - l_start_y_dest = l_res->y0 - l_y0_dest; + l_start_y_dest = (OPJ_UINT32)l_res->y0 - l_y0_dest; l_offset_y0_src = 0; if ( l_y1_dest >= (OPJ_UINT32)l_res->y1 ) { @@ -7786,21 +7786,21 @@ OPJ_BOOL opj_j2k_update_image_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data, opj_im l_offset_y1_src = 0; } else { - l_height_dest = l_y1_dest - l_res->y0 ; - l_offset_y1_src = l_height_src - l_height_dest; + l_height_dest = l_y1_dest - (OPJ_UINT32)l_res->y0 ; + l_offset_y1_src = (OPJ_INT32)(l_height_src - l_height_dest); } } else { l_start_y_dest = 0 ; - l_offset_y0_src = l_y0_dest - l_res->y0; + l_offset_y0_src = (OPJ_INT32)l_y0_dest - l_res->y0; if ( l_y1_dest >= (OPJ_UINT32)l_res->y1 ) { - l_height_dest = l_height_src - l_offset_y0_src; + l_height_dest = l_height_src - (OPJ_UINT32)l_offset_y0_src; l_offset_y1_src = 0; } else { l_height_dest = l_img_comp_dest->h ; - l_offset_y1_src = l_res->y1 - l_y1_dest; + l_offset_y1_src = l_res->y1 - (OPJ_INT32)l_y1_dest; } } @@ -7814,13 +7814,13 @@ OPJ_BOOL opj_j2k_update_image_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data, opj_im /*-----*/ /* Compute the input buffer offset */ - l_start_offset_src = l_offset_x0_src + l_offset_y0_src * l_width_src; + l_start_offset_src = l_offset_x0_src + l_offset_y0_src * (OPJ_INT32)l_width_src; l_line_offset_src = l_offset_x1_src + l_offset_x0_src; - l_end_offset_src = l_offset_y1_src * l_width_src - l_offset_x0_src; + l_end_offset_src = l_offset_y1_src * (OPJ_INT32)l_width_src - l_offset_x0_src; /* Compute the output buffer offset */ - l_start_offset_dest = l_start_x_dest + l_start_y_dest * l_img_comp_dest->w; - l_line_offset_dest = l_img_comp_dest->w - l_width_dest; + l_start_offset_dest = (OPJ_INT32)(l_start_x_dest + l_start_y_dest * l_img_comp_dest->w); + l_line_offset_dest = (OPJ_INT32)(l_img_comp_dest->w - l_width_dest); /* Move the output buffer to the first place where we will write*/ l_dest_ptr = l_img_comp_dest->data + l_start_offset_dest; @@ -7979,8 +7979,8 @@ OPJ_BOOL opj_j2k_set_decode_area( opj_j2k_t *p_j2k, p_image->x0 = l_image->x0; } else { - p_j2k->m_specific_param.m_decoder.m_start_tile_x = (p_start_x - l_cp->tx0) / l_cp->tdx; - p_image->x0 = p_start_x; + p_j2k->m_specific_param.m_decoder.m_start_tile_x = ((OPJ_UINT32)p_start_x - l_cp->tx0) / l_cp->tdx; + p_image->x0 = (OPJ_UINT32)p_start_x; } /* Up */ @@ -7998,8 +7998,8 @@ OPJ_BOOL opj_j2k_set_decode_area( opj_j2k_t *p_j2k, p_image->y0 = l_image->y0; } else { - p_j2k->m_specific_param.m_decoder.m_start_tile_y = (p_start_y - l_cp->ty0) / l_cp->tdy; - p_image->y0 = p_start_y; + p_j2k->m_specific_param.m_decoder.m_start_tile_y = ((OPJ_UINT32)p_start_y - l_cp->ty0) / l_cp->tdy; + p_image->y0 = (OPJ_UINT32)p_start_y; } /* Right */ @@ -8019,8 +8019,8 @@ OPJ_BOOL opj_j2k_set_decode_area( opj_j2k_t *p_j2k, p_image->x1 = l_image->x1; } else { - p_j2k->m_specific_param.m_decoder.m_end_tile_x = opj_int_ceildiv((p_end_x - l_cp->tx0), l_cp->tdx); - p_image->x1 = p_end_x; + p_j2k->m_specific_param.m_decoder.m_end_tile_x = (OPJ_UINT32)opj_int_ceildiv(p_end_x - (OPJ_INT32)l_cp->tx0, (OPJ_INT32)l_cp->tdx); + p_image->x1 = (OPJ_UINT32)p_end_x; } /* Bottom */ @@ -8038,8 +8038,8 @@ OPJ_BOOL opj_j2k_set_decode_area( opj_j2k_t *p_j2k, p_image->y1 = l_image->y1; } else{ - p_j2k->m_specific_param.m_decoder.m_end_tile_y = opj_int_ceildiv((p_end_y - l_cp->ty0), l_cp->tdy); - p_image->y1 = p_end_y; + p_j2k->m_specific_param.m_decoder.m_end_tile_y = (OPJ_UINT32)opj_int_ceildiv(p_end_y - (OPJ_INT32)l_cp->ty0, (OPJ_INT32)l_cp->tdy); + p_image->y1 = (OPJ_UINT32)p_end_y; } /* ----- */ @@ -8050,30 +8050,30 @@ OPJ_BOOL opj_j2k_set_decode_area( opj_j2k_t *p_j2k, { OPJ_INT32 l_h,l_w; - l_img_comp->x0 = opj_int_ceildiv(p_image->x0, l_img_comp->dx); - l_img_comp->y0 = opj_int_ceildiv(p_image->y0, l_img_comp->dy); - l_comp_x1 = opj_int_ceildiv(p_image->x1, l_img_comp->dx); - l_comp_y1 = opj_int_ceildiv(p_image->y1, l_img_comp->dy); + l_img_comp->x0 = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)p_image->x0, (OPJ_INT32)l_img_comp->dx); + l_img_comp->y0 = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)p_image->y0, (OPJ_INT32)l_img_comp->dy); + l_comp_x1 = opj_int_ceildiv((OPJ_INT32)p_image->x1, (OPJ_INT32)l_img_comp->dx); + l_comp_y1 = opj_int_ceildiv((OPJ_INT32)p_image->y1, (OPJ_INT32)l_img_comp->dy); - l_w = opj_int_ceildivpow2(l_comp_x1, l_img_comp->factor) - - opj_int_ceildivpow2(l_img_comp->x0, l_img_comp->factor); + l_w = opj_int_ceildivpow2(l_comp_x1, (OPJ_INT32)l_img_comp->factor) + - opj_int_ceildivpow2((OPJ_INT32)l_img_comp->x0, (OPJ_INT32)l_img_comp->factor); if (l_w < 0){ opj_event_msg(p_manager, EVT_ERROR, "Size x of the decoded component image is incorrect (comp[%d].w=%d).\n", it_comp, l_w); return OPJ_FALSE; } - l_img_comp->w = l_w; + l_img_comp->w = (OPJ_UINT32)l_w; - l_h = opj_int_ceildivpow2(l_comp_y1, l_img_comp->factor) - - opj_int_ceildivpow2(l_img_comp->y0, l_img_comp->factor); + l_h = opj_int_ceildivpow2(l_comp_y1, (OPJ_INT32)l_img_comp->factor) + - opj_int_ceildivpow2((OPJ_INT32)l_img_comp->y0, (OPJ_INT32)l_img_comp->factor); if (l_h < 0){ opj_event_msg(p_manager, EVT_ERROR, "Size y of the decoded component image is incorrect (comp[%d].h=%d).\n", it_comp, l_h); return OPJ_FALSE; } - l_img_comp->h = l_h; + l_img_comp->h = (OPJ_UINT32)l_h; l_img_comp++; } @@ -8474,7 +8474,7 @@ OPJ_BOOL opj_j2k_write_SQcd_SQcc( opj_j2k_t *p_j2k, ++p_data; for (l_band_no = 0; l_band_no < l_num_bands; ++l_band_no) { - l_expn = l_tccp->stepsizes[l_band_no].expn; + l_expn = (OPJ_UINT32)l_tccp->stepsizes[l_band_no].expn; opj_write_bytes(p_data, l_expn << 3, 1); /* SPqcx_i */ ++p_data; } @@ -8491,8 +8491,8 @@ OPJ_BOOL opj_j2k_write_SQcd_SQcc( opj_j2k_t *p_j2k, ++p_data; for (l_band_no = 0; l_band_no < l_num_bands; ++l_band_no) { - l_expn = l_tccp->stepsizes[l_band_no].expn; - l_mant = l_tccp->stepsizes[l_band_no].mant; + l_expn = (OPJ_UINT32)l_tccp->stepsizes[l_band_no].expn; + l_mant = (OPJ_UINT32)l_tccp->stepsizes[l_band_no].mant; opj_write_bytes(p_data, (l_expn << 11) + l_mant, 2); /* SPqcx_i */ p_data += 2; @@ -8590,7 +8590,7 @@ OPJ_BOOL opj_j2k_read_SQcd_SQcc(opj_j2k_t *p_j2k, opj_read_bytes(l_current_ptr, &l_tmp ,1); /* SPqcx_i */ ++l_current_ptr; if (l_band_no < OPJ_J2K_MAXBANDS){ - l_tccp->stepsizes[l_band_no].expn = l_tmp>>3; + l_tccp->stepsizes[l_band_no].expn = (OPJ_INT32)(l_tmp >> 3); l_tccp->stepsizes[l_band_no].mant = 0; } } @@ -8601,7 +8601,7 @@ OPJ_BOOL opj_j2k_read_SQcd_SQcc(opj_j2k_t *p_j2k, opj_read_bytes(l_current_ptr, &l_tmp ,2); /* SPqcx_i */ l_current_ptr+=2; if (l_band_no < OPJ_J2K_MAXBANDS){ - l_tccp->stepsizes[l_band_no].expn = l_tmp >> 11; + l_tccp->stepsizes[l_band_no].expn = (OPJ_INT32)(l_tmp >> 11); l_tccp->stepsizes[l_band_no].mant = l_tmp & 0x7ff; } } @@ -8612,8 +8612,8 @@ OPJ_BOOL opj_j2k_read_SQcd_SQcc(opj_j2k_t *p_j2k, if (l_tccp->qntsty == J2K_CCP_QNTSTY_SIQNT) { for (l_band_no = 1; l_band_no < OPJ_J2K_MAXBANDS; l_band_no++) { l_tccp->stepsizes[l_band_no].expn = - ((l_tccp->stepsizes[0].expn) - ((l_band_no - 1) / 3) > 0) ? - (l_tccp->stepsizes[0].expn) - ((l_band_no - 1) / 3) : 0; + ((OPJ_INT32)(l_tccp->stepsizes[0].expn) - (OPJ_INT32)((l_band_no - 1) / 3) > 0) ? + (OPJ_INT32)(l_tccp->stepsizes[0].expn) - (OPJ_INT32)((l_band_no - 1) / 3) : 0; l_tccp->stepsizes[l_band_no].mant = l_tccp->stepsizes[0].mant; } } @@ -8768,7 +8768,7 @@ void opj_j2k_dump_MH_info(opj_j2k_t* p_j2k, FILE* out_stream) if (l_default_tile) { OPJ_INT32 compno; - OPJ_INT32 numcomps = p_j2k->m_private_image->numcomps; + OPJ_INT32 numcomps = (OPJ_INT32)p_j2k->m_private_image->numcomps; fprintf(out_stream, "\t default tile {\n"); fprintf(out_stream, "\t\t csty=%#x\n", l_default_tile->csty); @@ -8800,7 +8800,7 @@ void opj_j2k_dump_MH_info(opj_j2k_t* p_j2k, FILE* out_stream) fprintf(out_stream, "\t\t\t qntsty=%d\n", l_tccp->qntsty); fprintf(out_stream, "\t\t\t numgbits=%d\n", l_tccp->numgbits); fprintf(out_stream, "\t\t\t stepsizes (m,e)="); - numbands = (l_tccp->qntsty == J2K_CCP_QNTSTY_SIQNT) ? 1 : l_tccp->numresolutions * 3 - 2; + numbands = (l_tccp->qntsty == J2K_CCP_QNTSTY_SIQNT) ? 1 : (OPJ_INT32)l_tccp->numresolutions * 3 - 2; for (bandno = 0; bandno < numbands; bandno++) { fprintf(out_stream, "(%d,%d) ", l_tccp->stepsizes[bandno].mant, l_tccp->stepsizes[bandno].expn); @@ -8924,11 +8924,11 @@ opj_codestream_info_v2_t* j2k_get_cstr_info(opj_j2k_t* p_j2k) l_tccp_info->qntsty = l_tccp->qntsty; l_tccp_info->numgbits = l_tccp->numgbits; - numbands = (l_tccp->qntsty == J2K_CCP_QNTSTY_SIQNT) ? 1 : l_tccp->numresolutions * 3 - 2; + numbands = (l_tccp->qntsty == J2K_CCP_QNTSTY_SIQNT) ? 1 : (OPJ_INT32)l_tccp->numresolutions * 3 - 2; if (numbands < OPJ_J2K_MAXBANDS) { for (bandno = 0; bandno < numbands; bandno++) { - l_tccp_info->stepsizes_mant[bandno] = l_tccp->stepsizes[bandno].mant; - l_tccp_info->stepsizes_expn[bandno] = l_tccp->stepsizes[bandno].expn; + l_tccp_info->stepsizes_mant[bandno] = (OPJ_UINT32)l_tccp->stepsizes[bandno].mant; + l_tccp_info->stepsizes_expn[bandno] = (OPJ_UINT32)l_tccp->stepsizes[bandno].expn; } } @@ -9185,7 +9185,7 @@ static OPJ_BOOL opj_j2k_decode_one_tile ( opj_j2k_t *p_j2k, } } /* Move into the codestream to the first SOT used to decode the desired tile */ - l_tile_no_to_dec = p_j2k->m_specific_param.m_decoder.m_tile_ind_to_dec; + l_tile_no_to_dec = (OPJ_UINT32)p_j2k->m_specific_param.m_decoder.m_tile_ind_to_dec; if (p_j2k->cstr_index->tile_index) if(p_j2k->cstr_index->tile_index->tp_index) { @@ -9366,13 +9366,13 @@ OPJ_BOOL opj_j2k_get_tile( opj_j2k_t *p_j2k, l_img_comp->factor = p_j2k->m_private_image->comps[compno].factor; - l_img_comp->x0 = opj_int_ceildiv(p_image->x0, l_img_comp->dx); - l_img_comp->y0 = opj_int_ceildiv(p_image->y0, l_img_comp->dy); - l_comp_x1 = opj_int_ceildiv(p_image->x1, l_img_comp->dx); - l_comp_y1 = opj_int_ceildiv(p_image->y1, l_img_comp->dy); + l_img_comp->x0 = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)p_image->x0, (OPJ_INT32)l_img_comp->dx); + l_img_comp->y0 = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)p_image->y0, (OPJ_INT32)l_img_comp->dy); + l_comp_x1 = opj_int_ceildiv((OPJ_INT32)p_image->x1, (OPJ_INT32)l_img_comp->dx); + l_comp_y1 = opj_int_ceildiv((OPJ_INT32)p_image->y1, (OPJ_INT32)l_img_comp->dy); - l_img_comp->w = opj_int_ceildivpow2(l_comp_x1, l_img_comp->factor) - opj_int_ceildivpow2(l_img_comp->x0, l_img_comp->factor); - l_img_comp->h = opj_int_ceildivpow2(l_comp_y1, l_img_comp->factor) - opj_int_ceildivpow2(l_img_comp->y0, l_img_comp->factor); + l_img_comp->w = (OPJ_UINT32)(opj_int_ceildivpow2(l_comp_x1, (OPJ_INT32)l_img_comp->factor) - opj_int_ceildivpow2((OPJ_INT32)l_img_comp->x0, (OPJ_INT32)l_img_comp->factor)); + l_img_comp->h = (OPJ_UINT32)(opj_int_ceildivpow2(l_comp_y1, (OPJ_INT32)l_img_comp->factor) - opj_int_ceildivpow2((OPJ_INT32)l_img_comp->y0, (OPJ_INT32)l_img_comp->factor)); l_img_comp++; } @@ -9388,7 +9388,7 @@ OPJ_BOOL opj_j2k_get_tile( opj_j2k_t *p_j2k, } opj_copy_image_header(p_image, p_j2k->m_output_image); - p_j2k->m_specific_param.m_decoder.m_tile_ind_to_dec = tile_index; + p_j2k->m_specific_param.m_decoder.m_tile_ind_to_dec = (OPJ_INT32)tile_index; /* customization of the decoding */ opj_j2k_setup_decoding_tile(p_j2k); @@ -9603,13 +9603,13 @@ void opj_j2k_get_tile_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data) l_size_comp = 4; } - l_width = (l_tilec->x1 - l_tilec->x0); - l_height = (l_tilec->y1 - l_tilec->y0); - l_offset_x = opj_int_ceildiv(l_image->x0, l_img_comp->dx); - l_offset_y = opj_int_ceildiv(l_image->y0, l_img_comp->dy); - l_image_width = opj_int_ceildiv(l_image->x1 - l_image->x0, l_img_comp->dx); + l_width = (OPJ_UINT32)(l_tilec->x1 - l_tilec->x0); + l_height = (OPJ_UINT32)(l_tilec->y1 - l_tilec->y0); + l_offset_x = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)l_image->x0, (OPJ_INT32)l_img_comp->dx); + l_offset_y = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)l_image->y0, (OPJ_INT32)l_img_comp->dy); + l_image_width = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)l_image->x1 - (OPJ_INT32)l_image->x0, (OPJ_INT32)l_img_comp->dx); l_stride = l_image_width - l_width; - l_src_ptr = l_img_comp->data + (l_tilec->x0 - l_offset_x) + (l_tilec->y0 - l_offset_y) * l_image_width; + l_src_ptr = l_img_comp->data + ((OPJ_UINT32)l_tilec->x0 - l_offset_x) + ((OPJ_UINT32)l_tilec->y0 - l_offset_y) * l_image_width; switch (l_size_comp) { case 1: From dd5c3a9c8e4343cf438b807372e58a0742273dbf Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 6 Mar 2014 16:29:03 +0000 Subject: [PATCH 215/333] [trunk] Remove some easy warnings --- src/bin/jp2/convert.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index a49ea838..f99cd169 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -1431,7 +1431,7 @@ static inline int clamp( const int value, const int prec, const int sgnd ) { if (prec <= 8) return CLAMP(value,0,255); else if (prec <= 16) return CLAMP(value,0,65535); - else return CLAMP(value,0,4294967295); + else return value; /*CLAMP(value,0,4294967295);*/ } } @@ -3012,11 +3012,11 @@ static opj_image_t* rawtoimage_common(const char *filename, opj_cparameters_t *p } if( big_endian ) { - value = (unsigned short)(temp1 << 8 + temp2); + value = (unsigned short)((temp1 << 8) + temp2); } else { - value = (unsigned short)(temp2 << 8 + temp1); + value = (unsigned short)((temp2 << 8) + temp1); } image->comps[compno].data[i] = raw_cp->rawSigned?(short)value:value; } From 445f696dc66111bd4644d2d0741d78829e0045e4 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 6 Mar 2014 16:59:34 +0000 Subject: [PATCH 216/333] [trunk] Remove warning about sign conversion. Update issue 256 --- src/lib/openjp2/j2k.c | 88 +++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 3d527f81..1cc79f07 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -4901,12 +4901,12 @@ OPJ_BOOL opj_j2k_write_epc( opj_j2k_t *p_j2k, l_cstr_index = p_j2k->cstr_index; if (l_cstr_index) { - l_cstr_index->codestream_size = opj_stream_tell(p_stream); + l_cstr_index->codestream_size = (OPJ_UINT64)opj_stream_tell(p_stream); /* UniPG>> */ /* The following adjustment is done to adjust the codestream size */ /* if SOD is not at 0 in the buffer. Useful in case of JP2, where */ /* the first bunch of bytes is not in the codestream */ - l_cstr_index->codestream_size -= l_cstr_index->main_head_start; + l_cstr_index->codestream_size -= (OPJ_UINT64)l_cstr_index->main_head_start; /* <numcomps;++i) { - l_tccp->m_dc_level_shift = *(l_current_offset_data++); + l_tccp->m_dc_level_shift = (OPJ_INT32)*(l_current_offset_data++); ++l_tccp; } @@ -5862,14 +5862,14 @@ int opj_j2k_initialise_4K_poc(opj_poc_t *POC, int numres){ POC[0].resno0 = 0; POC[0].compno0 = 0; POC[0].layno1 = 1; - POC[0].resno1 = numres-1; + POC[0].resno1 = (OPJ_UINT32)(numres-1); POC[0].compno1 = 3; POC[0].prg1 = OPJ_CPRL; POC[1].tile = 1; - POC[1].resno0 = numres-1; + POC[1].resno0 = (OPJ_UINT32)(numres-1); POC[1].compno0 = 0; POC[1].layno1 = 1; - POC[1].resno1 = numres; + POC[1].resno1 = (OPJ_UINT32)numres; POC[1].compno1 = 3; POC[1].prg1 = OPJ_CPRL; return 2; @@ -5985,7 +5985,7 @@ void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *i /* Progression order changes for 4K, disallowed for 2K */ if (parameters->cp_cinema == OPJ_CINEMA4K_24) { - parameters->numpocs = opj_j2k_initialise_4K_poc(parameters->POC,parameters->numresolution); + parameters->numpocs = (OPJ_UINT32)opj_j2k_initialise_4K_poc(parameters->POC,parameters->numresolution); } else { parameters->numpocs = 0; } @@ -6141,26 +6141,26 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, copy user encoding parameters */ cp->m_specific_param.m_enc.m_cinema = parameters->cp_cinema; - cp->m_specific_param.m_enc.m_max_comp_size = parameters->max_comp_size; + cp->m_specific_param.m_enc.m_max_comp_size = (OPJ_UINT32)parameters->max_comp_size; cp->rsiz = parameters->cp_rsiz; - cp->m_specific_param.m_enc.m_disto_alloc = parameters->cp_disto_alloc & 1u; - cp->m_specific_param.m_enc.m_fixed_alloc = parameters->cp_fixed_alloc & 1u; - cp->m_specific_param.m_enc.m_fixed_quality = parameters->cp_fixed_quality & 1u; + cp->m_specific_param.m_enc.m_disto_alloc = (OPJ_UINT32)parameters->cp_disto_alloc & 1u; + cp->m_specific_param.m_enc.m_fixed_alloc = (OPJ_UINT32)parameters->cp_fixed_alloc & 1u; + cp->m_specific_param.m_enc.m_fixed_quality = (OPJ_UINT32)parameters->cp_fixed_quality & 1u; /* mod fixed_quality */ if (parameters->cp_fixed_alloc && parameters->cp_matrice) { - size_t array_size = parameters->tcp_numlayers * parameters->numresolution * 3 * sizeof(OPJ_INT32); + size_t array_size = (size_t)parameters->tcp_numlayers * (size_t)parameters->numresolution * 3 * sizeof(OPJ_INT32); cp->m_specific_param.m_enc.m_matrice = (OPJ_INT32 *) opj_malloc(array_size); memcpy(cp->m_specific_param.m_enc.m_matrice, parameters->cp_matrice, array_size); } /* tiles */ - cp->tdx = parameters->cp_tdx; - cp->tdy = parameters->cp_tdy; + cp->tdx = (OPJ_UINT32)parameters->cp_tdx; + cp->tdy = (OPJ_UINT32)parameters->cp_tdy; /* tile offset */ - cp->tx0 = parameters->cp_tx0; - cp->ty0 = parameters->cp_ty0; + cp->tx0 = (OPJ_UINT32)parameters->cp_tx0; + cp->ty0 = (OPJ_UINT32)parameters->cp_ty0; /* comment string */ if(parameters->cp_comment) { @@ -6175,15 +6175,15 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, */ if (parameters->tile_size_on) { - cp->tw = opj_int_ceildiv(image->x1 - cp->tx0, cp->tdx); - cp->th = opj_int_ceildiv(image->y1 - cp->ty0, cp->tdy); + cp->tw = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)(image->x1 - cp->tx0), (OPJ_INT32)cp->tdx); + cp->th = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)(image->y1 - cp->ty0), (OPJ_INT32)cp->tdy); } else { cp->tdx = image->x1 - cp->tx0; cp->tdy = image->y1 - cp->ty0; } if (parameters->tp_on) { - cp->m_specific_param.m_enc.m_tp_flag = parameters->tp_flag; + cp->m_specific_param.m_enc.m_tp_flag = (OPJ_BYTE)parameters->tp_flag; cp->m_specific_param.m_enc.m_tp_on = 1; } @@ -6248,13 +6248,13 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, cp->tcps = (opj_tcp_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tcp_t)); if (parameters->numpocs) { /* initialisation of POC */ - opj_j2k_check_poc_val(parameters->POC,parameters->numpocs, parameters->numresolution, image->numcomps, parameters->tcp_numlayers, p_manager); + opj_j2k_check_poc_val(parameters->POC,parameters->numpocs, (OPJ_UINT32)parameters->numresolution, image->numcomps, (OPJ_UINT32)parameters->tcp_numlayers, p_manager); /* TODO MSD use the return value*/ } for (tileno = 0; tileno < cp->tw * cp->th; tileno++) { opj_tcp_t *tcp = &cp->tcps[tileno]; - tcp->numlayers = parameters->tcp_numlayers; + tcp->numlayers = (OPJ_UINT32)parameters->tcp_numlayers; for (j = 0; j < tcp->numlayers; j++) { if(cp->m_specific_param.m_enc.m_cinema){ @@ -6271,9 +6271,9 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, } } - tcp->csty = parameters->csty; + tcp->csty = (OPJ_UINT32)parameters->csty; tcp->prg = parameters->prog_order; - tcp->mct = parameters->tcp_mct; + tcp->mct = (OPJ_UINT32)parameters->tcp_mct; numpocs_tile = 0; tcp->POC = 0; @@ -6346,10 +6346,10 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, opj_tccp_t *tccp = &tcp->tccps[i]; tccp->csty = parameters->csty & 0x01; /* 0 => one precinct || 1 => custom precinct */ - tccp->numresolutions = parameters->numresolution; - tccp->cblkw = opj_int_floorlog2(parameters->cblockw_init); - tccp->cblkh = opj_int_floorlog2(parameters->cblockh_init); - tccp->cblksty = parameters->mode; + tccp->numresolutions = (OPJ_UINT32)parameters->numresolution; + tccp->cblkw = (OPJ_UINT32)opj_int_floorlog2(parameters->cblockw_init); + tccp->cblkh = (OPJ_UINT32)opj_int_floorlog2(parameters->cblockh_init); + tccp->cblksty = (OPJ_UINT32)parameters->mode; tccp->qmfbid = parameters->irreversible ? 0 : 1; tccp->qntsty = parameters->irreversible ? J2K_CCP_QNTSTY_SEQNT : J2K_CCP_QNTSTY_NOQNT; tccp->numgbits = 2; @@ -6363,19 +6363,19 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, if (parameters->csty & J2K_CCP_CSTY_PRT) { OPJ_INT32 p = 0, it_res; assert( tccp->numresolutions > 0 ); - for (it_res = tccp->numresolutions - 1; it_res >= 0; it_res--) { + for (it_res = (OPJ_INT32)tccp->numresolutions - 1; it_res >= 0; it_res--) { if (p < parameters->res_spec) { if (parameters->prcw_init[p] < 1) { tccp->prcw[it_res] = 1; } else { - tccp->prcw[it_res] = opj_int_floorlog2(parameters->prcw_init[p]); + tccp->prcw[it_res] = (OPJ_UINT32)opj_int_floorlog2(parameters->prcw_init[p]); } if (parameters->prch_init[p] < 1) { tccp->prch[it_res] = 1; }else { - tccp->prch[it_res] = opj_int_floorlog2(parameters->prch_init[p]); + tccp->prch[it_res] = (OPJ_UINT32)opj_int_floorlog2(parameters->prch_init[p]); } } else { @@ -6391,13 +6391,13 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, if (size_prcw < 1) { tccp->prcw[it_res] = 1; } else { - tccp->prcw[it_res] = opj_int_floorlog2(size_prcw); + tccp->prcw[it_res] = (OPJ_UINT32)opj_int_floorlog2(size_prcw); } if (size_prch < 1) { tccp->prch[it_res] = 1; } else { - tccp->prch[it_res] = opj_int_floorlog2(size_prch); + tccp->prch[it_res] = (OPJ_UINT32)opj_int_floorlog2(size_prch); } } p++; @@ -6427,7 +6427,7 @@ static OPJ_BOOL opj_j2k_add_mhmarker(opj_codestream_index_t *cstr_index, OPJ_UIN /* expand the list? */ if ((cstr_index->marknum + 1) > cstr_index->maxmarknum) { opj_marker_info_t *new_marker; - cstr_index->maxmarknum = 100 + (OPJ_INT32) ((OPJ_FLOAT32) cstr_index->maxmarknum * 1.0F); + cstr_index->maxmarknum = (OPJ_UINT32)(100 + (OPJ_INT32) ((OPJ_FLOAT32) cstr_index->maxmarknum * 1.0F)); new_marker = (opj_marker_info_t *) opj_realloc(cstr_index->marker, cstr_index->maxmarknum *sizeof(opj_marker_info_t)); if (! new_marker) { opj_free(cstr_index->marker); @@ -6456,7 +6456,7 @@ static OPJ_BOOL opj_j2k_add_tlmarker(OPJ_UINT32 tileno, opj_codestream_index_t * /* expand the list? */ if ((cstr_index->tile_index[tileno].marknum + 1) > cstr_index->tile_index[tileno].maxmarknum) { opj_marker_info_t *new_marker; - cstr_index->tile_index[tileno].maxmarknum = 100 + (OPJ_INT32) ((OPJ_FLOAT32) cstr_index->tile_index[tileno].maxmarknum * 1.0F); + cstr_index->tile_index[tileno].maxmarknum = (OPJ_UINT32)(100 + (OPJ_INT32) ((OPJ_FLOAT32) cstr_index->tile_index[tileno].maxmarknum * 1.0F)); new_marker = (opj_marker_info_t *) opj_realloc( cstr_index->tile_index[tileno].marker, cstr_index->tile_index[tileno].maxmarknum *sizeof(opj_marker_info_t)); @@ -7727,12 +7727,12 @@ OPJ_BOOL opj_j2k_update_image_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data, opj_im l_res->x0, l_res->x1, l_res->y0, l_res->y1); }*/ - l_width_src = (l_res->x1 - l_res->x0); - l_height_src = (l_res->y1 - l_res->y0); + l_width_src = (OPJ_UINT8)(l_res->x1 - l_res->x0); + l_height_src = (OPJ_UINT32)(l_res->y1 - l_res->y0); /* Border of the current output component*/ - l_x0_dest = opj_int_ceildivpow2(l_img_comp_dest->x0, l_img_comp_dest->factor); - l_y0_dest = opj_int_ceildivpow2(l_img_comp_dest->y0, l_img_comp_dest->factor); + l_x0_dest = (OPJ_UINT32)opj_int_ceildivpow2((OPJ_INT32)l_img_comp_dest->x0, (OPJ_INT32)l_img_comp_dest->factor); + l_y0_dest = (OPJ_UINT32)opj_int_ceildivpow2((OPJ_INT32)l_img_comp_dest->y0, (OPJ_INT32)l_img_comp_dest->factor); l_x1_dest = l_x0_dest + l_img_comp_dest->w; l_y1_dest = l_y0_dest + l_img_comp_dest->h; @@ -7751,7 +7751,7 @@ OPJ_BOOL opj_j2k_update_image_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data, opj_im assert( l_res->x0 >= 0); assert( l_res->x1 >= 0); if ( l_x0_dest < (OPJ_UINT32)l_res->x0 ) { - l_start_x_dest = l_res->x0 - l_x0_dest; + l_start_x_dest = (OPJ_UINT32)l_res->x0 - l_x0_dest; l_offset_x0_src = 0; if ( l_x1_dest >= (OPJ_UINT32)l_res->x1 ) { @@ -7759,21 +7759,21 @@ OPJ_BOOL opj_j2k_update_image_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data, opj_im l_offset_x1_src = 0; } else { - l_width_dest = l_x1_dest - l_res->x0 ; - l_offset_x1_src = l_width_src - l_width_dest; + l_width_dest = l_x1_dest - (OPJ_UINT32)l_res->x0 ; + l_offset_x1_src = (OPJ_INT32)(l_width_src - l_width_dest); } } else { l_start_x_dest = 0 ; - l_offset_x0_src = l_x0_dest - l_res->x0; + l_offset_x0_src = (OPJ_INT32)l_x0_dest - l_res->x0; if ( l_x1_dest >= (OPJ_UINT32)l_res->x1 ) { - l_width_dest = l_width_src - l_offset_x0_src; + l_width_dest = l_width_src - (OPJ_UINT32)l_offset_x0_src; l_offset_x1_src = 0; } else { l_width_dest = l_img_comp_dest->w ; - l_offset_x1_src = l_res->x1 - l_x1_dest; + l_offset_x1_src = l_res->x1 - (OPJ_INT32)l_x1_dest; } } From 6790587db882ebedc6c8b8e03210638026df34c3 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 6 Mar 2014 17:25:08 +0000 Subject: [PATCH 217/333] [trunk] Revert r2597 for now, since it breaks a lot of tests --- src/lib/openjp2/j2k.c | 88 +++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 1cc79f07..3d527f81 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -4901,12 +4901,12 @@ OPJ_BOOL opj_j2k_write_epc( opj_j2k_t *p_j2k, l_cstr_index = p_j2k->cstr_index; if (l_cstr_index) { - l_cstr_index->codestream_size = (OPJ_UINT64)opj_stream_tell(p_stream); + l_cstr_index->codestream_size = opj_stream_tell(p_stream); /* UniPG>> */ /* The following adjustment is done to adjust the codestream size */ /* if SOD is not at 0 in the buffer. Useful in case of JP2, where */ /* the first bunch of bytes is not in the codestream */ - l_cstr_index->codestream_size -= (OPJ_UINT64)l_cstr_index->main_head_start; + l_cstr_index->codestream_size -= l_cstr_index->main_head_start; /* <numcomps;++i) { - l_tccp->m_dc_level_shift = (OPJ_INT32)*(l_current_offset_data++); + l_tccp->m_dc_level_shift = *(l_current_offset_data++); ++l_tccp; } @@ -5862,14 +5862,14 @@ int opj_j2k_initialise_4K_poc(opj_poc_t *POC, int numres){ POC[0].resno0 = 0; POC[0].compno0 = 0; POC[0].layno1 = 1; - POC[0].resno1 = (OPJ_UINT32)(numres-1); + POC[0].resno1 = numres-1; POC[0].compno1 = 3; POC[0].prg1 = OPJ_CPRL; POC[1].tile = 1; - POC[1].resno0 = (OPJ_UINT32)(numres-1); + POC[1].resno0 = numres-1; POC[1].compno0 = 0; POC[1].layno1 = 1; - POC[1].resno1 = (OPJ_UINT32)numres; + POC[1].resno1 = numres; POC[1].compno1 = 3; POC[1].prg1 = OPJ_CPRL; return 2; @@ -5985,7 +5985,7 @@ void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *i /* Progression order changes for 4K, disallowed for 2K */ if (parameters->cp_cinema == OPJ_CINEMA4K_24) { - parameters->numpocs = (OPJ_UINT32)opj_j2k_initialise_4K_poc(parameters->POC,parameters->numresolution); + parameters->numpocs = opj_j2k_initialise_4K_poc(parameters->POC,parameters->numresolution); } else { parameters->numpocs = 0; } @@ -6141,26 +6141,26 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, copy user encoding parameters */ cp->m_specific_param.m_enc.m_cinema = parameters->cp_cinema; - cp->m_specific_param.m_enc.m_max_comp_size = (OPJ_UINT32)parameters->max_comp_size; + cp->m_specific_param.m_enc.m_max_comp_size = parameters->max_comp_size; cp->rsiz = parameters->cp_rsiz; - cp->m_specific_param.m_enc.m_disto_alloc = (OPJ_UINT32)parameters->cp_disto_alloc & 1u; - cp->m_specific_param.m_enc.m_fixed_alloc = (OPJ_UINT32)parameters->cp_fixed_alloc & 1u; - cp->m_specific_param.m_enc.m_fixed_quality = (OPJ_UINT32)parameters->cp_fixed_quality & 1u; + cp->m_specific_param.m_enc.m_disto_alloc = parameters->cp_disto_alloc & 1u; + cp->m_specific_param.m_enc.m_fixed_alloc = parameters->cp_fixed_alloc & 1u; + cp->m_specific_param.m_enc.m_fixed_quality = parameters->cp_fixed_quality & 1u; /* mod fixed_quality */ if (parameters->cp_fixed_alloc && parameters->cp_matrice) { - size_t array_size = (size_t)parameters->tcp_numlayers * (size_t)parameters->numresolution * 3 * sizeof(OPJ_INT32); + size_t array_size = parameters->tcp_numlayers * parameters->numresolution * 3 * sizeof(OPJ_INT32); cp->m_specific_param.m_enc.m_matrice = (OPJ_INT32 *) opj_malloc(array_size); memcpy(cp->m_specific_param.m_enc.m_matrice, parameters->cp_matrice, array_size); } /* tiles */ - cp->tdx = (OPJ_UINT32)parameters->cp_tdx; - cp->tdy = (OPJ_UINT32)parameters->cp_tdy; + cp->tdx = parameters->cp_tdx; + cp->tdy = parameters->cp_tdy; /* tile offset */ - cp->tx0 = (OPJ_UINT32)parameters->cp_tx0; - cp->ty0 = (OPJ_UINT32)parameters->cp_ty0; + cp->tx0 = parameters->cp_tx0; + cp->ty0 = parameters->cp_ty0; /* comment string */ if(parameters->cp_comment) { @@ -6175,15 +6175,15 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, */ if (parameters->tile_size_on) { - cp->tw = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)(image->x1 - cp->tx0), (OPJ_INT32)cp->tdx); - cp->th = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)(image->y1 - cp->ty0), (OPJ_INT32)cp->tdy); + cp->tw = opj_int_ceildiv(image->x1 - cp->tx0, cp->tdx); + cp->th = opj_int_ceildiv(image->y1 - cp->ty0, cp->tdy); } else { cp->tdx = image->x1 - cp->tx0; cp->tdy = image->y1 - cp->ty0; } if (parameters->tp_on) { - cp->m_specific_param.m_enc.m_tp_flag = (OPJ_BYTE)parameters->tp_flag; + cp->m_specific_param.m_enc.m_tp_flag = parameters->tp_flag; cp->m_specific_param.m_enc.m_tp_on = 1; } @@ -6248,13 +6248,13 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, cp->tcps = (opj_tcp_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tcp_t)); if (parameters->numpocs) { /* initialisation of POC */ - opj_j2k_check_poc_val(parameters->POC,parameters->numpocs, (OPJ_UINT32)parameters->numresolution, image->numcomps, (OPJ_UINT32)parameters->tcp_numlayers, p_manager); + opj_j2k_check_poc_val(parameters->POC,parameters->numpocs, parameters->numresolution, image->numcomps, parameters->tcp_numlayers, p_manager); /* TODO MSD use the return value*/ } for (tileno = 0; tileno < cp->tw * cp->th; tileno++) { opj_tcp_t *tcp = &cp->tcps[tileno]; - tcp->numlayers = (OPJ_UINT32)parameters->tcp_numlayers; + tcp->numlayers = parameters->tcp_numlayers; for (j = 0; j < tcp->numlayers; j++) { if(cp->m_specific_param.m_enc.m_cinema){ @@ -6271,9 +6271,9 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, } } - tcp->csty = (OPJ_UINT32)parameters->csty; + tcp->csty = parameters->csty; tcp->prg = parameters->prog_order; - tcp->mct = (OPJ_UINT32)parameters->tcp_mct; + tcp->mct = parameters->tcp_mct; numpocs_tile = 0; tcp->POC = 0; @@ -6346,10 +6346,10 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, opj_tccp_t *tccp = &tcp->tccps[i]; tccp->csty = parameters->csty & 0x01; /* 0 => one precinct || 1 => custom precinct */ - tccp->numresolutions = (OPJ_UINT32)parameters->numresolution; - tccp->cblkw = (OPJ_UINT32)opj_int_floorlog2(parameters->cblockw_init); - tccp->cblkh = (OPJ_UINT32)opj_int_floorlog2(parameters->cblockh_init); - tccp->cblksty = (OPJ_UINT32)parameters->mode; + tccp->numresolutions = parameters->numresolution; + tccp->cblkw = opj_int_floorlog2(parameters->cblockw_init); + tccp->cblkh = opj_int_floorlog2(parameters->cblockh_init); + tccp->cblksty = parameters->mode; tccp->qmfbid = parameters->irreversible ? 0 : 1; tccp->qntsty = parameters->irreversible ? J2K_CCP_QNTSTY_SEQNT : J2K_CCP_QNTSTY_NOQNT; tccp->numgbits = 2; @@ -6363,19 +6363,19 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, if (parameters->csty & J2K_CCP_CSTY_PRT) { OPJ_INT32 p = 0, it_res; assert( tccp->numresolutions > 0 ); - for (it_res = (OPJ_INT32)tccp->numresolutions - 1; it_res >= 0; it_res--) { + for (it_res = tccp->numresolutions - 1; it_res >= 0; it_res--) { if (p < parameters->res_spec) { if (parameters->prcw_init[p] < 1) { tccp->prcw[it_res] = 1; } else { - tccp->prcw[it_res] = (OPJ_UINT32)opj_int_floorlog2(parameters->prcw_init[p]); + tccp->prcw[it_res] = opj_int_floorlog2(parameters->prcw_init[p]); } if (parameters->prch_init[p] < 1) { tccp->prch[it_res] = 1; }else { - tccp->prch[it_res] = (OPJ_UINT32)opj_int_floorlog2(parameters->prch_init[p]); + tccp->prch[it_res] = opj_int_floorlog2(parameters->prch_init[p]); } } else { @@ -6391,13 +6391,13 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, if (size_prcw < 1) { tccp->prcw[it_res] = 1; } else { - tccp->prcw[it_res] = (OPJ_UINT32)opj_int_floorlog2(size_prcw); + tccp->prcw[it_res] = opj_int_floorlog2(size_prcw); } if (size_prch < 1) { tccp->prch[it_res] = 1; } else { - tccp->prch[it_res] = (OPJ_UINT32)opj_int_floorlog2(size_prch); + tccp->prch[it_res] = opj_int_floorlog2(size_prch); } } p++; @@ -6427,7 +6427,7 @@ static OPJ_BOOL opj_j2k_add_mhmarker(opj_codestream_index_t *cstr_index, OPJ_UIN /* expand the list? */ if ((cstr_index->marknum + 1) > cstr_index->maxmarknum) { opj_marker_info_t *new_marker; - cstr_index->maxmarknum = (OPJ_UINT32)(100 + (OPJ_INT32) ((OPJ_FLOAT32) cstr_index->maxmarknum * 1.0F)); + cstr_index->maxmarknum = 100 + (OPJ_INT32) ((OPJ_FLOAT32) cstr_index->maxmarknum * 1.0F); new_marker = (opj_marker_info_t *) opj_realloc(cstr_index->marker, cstr_index->maxmarknum *sizeof(opj_marker_info_t)); if (! new_marker) { opj_free(cstr_index->marker); @@ -6456,7 +6456,7 @@ static OPJ_BOOL opj_j2k_add_tlmarker(OPJ_UINT32 tileno, opj_codestream_index_t * /* expand the list? */ if ((cstr_index->tile_index[tileno].marknum + 1) > cstr_index->tile_index[tileno].maxmarknum) { opj_marker_info_t *new_marker; - cstr_index->tile_index[tileno].maxmarknum = (OPJ_UINT32)(100 + (OPJ_INT32) ((OPJ_FLOAT32) cstr_index->tile_index[tileno].maxmarknum * 1.0F)); + cstr_index->tile_index[tileno].maxmarknum = 100 + (OPJ_INT32) ((OPJ_FLOAT32) cstr_index->tile_index[tileno].maxmarknum * 1.0F); new_marker = (opj_marker_info_t *) opj_realloc( cstr_index->tile_index[tileno].marker, cstr_index->tile_index[tileno].maxmarknum *sizeof(opj_marker_info_t)); @@ -7727,12 +7727,12 @@ OPJ_BOOL opj_j2k_update_image_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data, opj_im l_res->x0, l_res->x1, l_res->y0, l_res->y1); }*/ - l_width_src = (OPJ_UINT8)(l_res->x1 - l_res->x0); - l_height_src = (OPJ_UINT32)(l_res->y1 - l_res->y0); + l_width_src = (l_res->x1 - l_res->x0); + l_height_src = (l_res->y1 - l_res->y0); /* Border of the current output component*/ - l_x0_dest = (OPJ_UINT32)opj_int_ceildivpow2((OPJ_INT32)l_img_comp_dest->x0, (OPJ_INT32)l_img_comp_dest->factor); - l_y0_dest = (OPJ_UINT32)opj_int_ceildivpow2((OPJ_INT32)l_img_comp_dest->y0, (OPJ_INT32)l_img_comp_dest->factor); + l_x0_dest = opj_int_ceildivpow2(l_img_comp_dest->x0, l_img_comp_dest->factor); + l_y0_dest = opj_int_ceildivpow2(l_img_comp_dest->y0, l_img_comp_dest->factor); l_x1_dest = l_x0_dest + l_img_comp_dest->w; l_y1_dest = l_y0_dest + l_img_comp_dest->h; @@ -7751,7 +7751,7 @@ OPJ_BOOL opj_j2k_update_image_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data, opj_im assert( l_res->x0 >= 0); assert( l_res->x1 >= 0); if ( l_x0_dest < (OPJ_UINT32)l_res->x0 ) { - l_start_x_dest = (OPJ_UINT32)l_res->x0 - l_x0_dest; + l_start_x_dest = l_res->x0 - l_x0_dest; l_offset_x0_src = 0; if ( l_x1_dest >= (OPJ_UINT32)l_res->x1 ) { @@ -7759,21 +7759,21 @@ OPJ_BOOL opj_j2k_update_image_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data, opj_im l_offset_x1_src = 0; } else { - l_width_dest = l_x1_dest - (OPJ_UINT32)l_res->x0 ; - l_offset_x1_src = (OPJ_INT32)(l_width_src - l_width_dest); + l_width_dest = l_x1_dest - l_res->x0 ; + l_offset_x1_src = l_width_src - l_width_dest; } } else { l_start_x_dest = 0 ; - l_offset_x0_src = (OPJ_INT32)l_x0_dest - l_res->x0; + l_offset_x0_src = l_x0_dest - l_res->x0; if ( l_x1_dest >= (OPJ_UINT32)l_res->x1 ) { - l_width_dest = l_width_src - (OPJ_UINT32)l_offset_x0_src; + l_width_dest = l_width_src - l_offset_x0_src; l_offset_x1_src = 0; } else { l_width_dest = l_img_comp_dest->w ; - l_offset_x1_src = l_res->x1 - (OPJ_INT32)l_x1_dest; + l_offset_x1_src = l_res->x1 - l_x1_dest; } } From f5630ab88e8279fbb011e6f33d1f5bd759a220b1 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 08:11:49 +0000 Subject: [PATCH 218/333] [trunk] Simplify code and remove bogus out of bound check --- tests/comparePGXimages.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tests/comparePGXimages.c b/tests/comparePGXimages.c index dfd72a24..77714ddc 100644 --- a/tests/comparePGXimages.c +++ b/tests/comparePGXimages.c @@ -240,8 +240,7 @@ static opj_image_t* readImageFromFilePGX(const char* filename, int nbFilenamePGX /* set encoding parameters to default values */ opj_set_default_encoder_parameters(¶meters); parameters.decod_format = PGX_DFMT; - strncpy(parameters.infile, filename, sizeof(parameters.infile)-1); - assert( parameters.infile[sizeof(parameters.infile)] == 0 ); + strcpy(parameters.infile, filename); /* Allocate memory*/ param_image_read = malloc((size_t)nbFilenamePGX * sizeof(opj_image_cmptparm_t)); From 37128c34a9d2f1815923e88a517919f18a97f1be Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 08:48:47 +0000 Subject: [PATCH 219/333] [trunk] Fix mem leaks reported by cppcheck --- src/lib/openjp2/j2k.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 3d527f81..b22f4790 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -1501,6 +1501,7 @@ OPJ_BOOL opj_j2k_check_poc_val( const opj_poc_t *p_pocs, memset(packet_array,0,step_l * p_num_layers* sizeof(OPJ_UINT32)); if (p_nb_pocs == 0) { + opj_free(packet_array); return OPJ_TRUE; } @@ -9194,12 +9195,14 @@ static OPJ_BOOL opj_j2k_decode_one_tile ( opj_j2k_t *p_j2k, * so move to the last SOT read */ if ( !(opj_stream_read_seek(p_stream, p_j2k->m_specific_param.m_decoder.m_last_sot_read_pos+2, p_manager)) ){ opj_event_msg(p_manager, EVT_ERROR, "Problem with seek function\n"); + opj_free(l_current_data); return OPJ_FALSE; } } else{ if ( !(opj_stream_read_seek(p_stream, p_j2k->cstr_index->tile_index[l_tile_no_to_dec].tp_index[0].start_pos+2, p_manager)) ) { opj_event_msg(p_manager, EVT_ERROR, "Problem with seek function\n"); + opj_free(l_current_data); return OPJ_FALSE; } } From a734e447b557b2b1ce76bb28bfa38e0bae8da931 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 09:03:15 +0000 Subject: [PATCH 220/333] [trunk] Remove TIFF warning handler. This help test suite run smoothly on windows by removing the message box. Fixes issue 276 --- tests/comparePGXimages.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/tests/comparePGXimages.c b/tests/comparePGXimages.c index 77714ddc..3db1dca8 100644 --- a/tests/comparePGXimages.c +++ b/tests/comparePGXimages.c @@ -145,6 +145,12 @@ static opj_image_t* readImageFromFileTIF(const char* filename, int nbFilenamePGX opj_image_cmptparm_t* param_image_read; int** data; + /* conformance test suite produce annoying warning: + * TIFFReadDirectory: Warning, /.../data/baseline/conformance/jp2_1.tif: unknown field with tag 37724 (0x935c) encountered. + * On Win32 this open a message box by default, so remove it from the test suite: + */ + TIFFSetWarningHandler(NULL); + /* If separator is empty => nb file to read is equal to one*/ if ( strlen(separator) == 0 ) nbFilenamePGX = 1; From 99b40e82570462fc7ec306329e3cc84cd3e7c145 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 09:14:39 +0000 Subject: [PATCH 221/333] [trunk] Remove warning about implicitly defined function --- tests/comparePGXimages.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/comparePGXimages.c b/tests/comparePGXimages.c index 3db1dca8..c6ccf488 100644 --- a/tests/comparePGXimages.c +++ b/tests/comparePGXimages.c @@ -45,6 +45,10 @@ #include "format_defs.h" #include "convert.h" +#ifdef OPJ_HAVE_LIBTIFF +#include /* TIFFSetWarningHandler */ +#endif /* OPJ_HAVE_LIBTIFF */ + /******************************************************************************* * Parse MSE and PEAK input values ( * separator = ":" From 016b9fc052607add5458aa90e939b902036b363a Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 09:15:27 +0000 Subject: [PATCH 222/333] [trunk] Fix compilation in visual studio, inline cannot be used directly. Fixes issue 272 --- src/bin/jp2/convert.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index f99cd169..1e578c07 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -1419,7 +1419,13 @@ opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters) { #define CLAMP(x,a,b) x < a ? a : (x > b ? b : x) -static inline int clamp( const int value, const int prec, const int sgnd ) +#ifdef _MSC_VER +#define STIN static __inline +#else +#define STIN static inline +#endif + +STIN int clamp( const int value, const int prec, const int sgnd ) { if( sgnd ) { From 5f7ad58f48c4565d2f30cbb2b76bc0cda5bdcdac Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 09:33:32 +0000 Subject: [PATCH 223/333] [trunk] Remove self-assignement. Fixes issue 273 --- src/lib/openjp2/cio.c | 1 - 1 file changed, 1 deletion(-) diff --git a/src/lib/openjp2/cio.c b/src/lib/openjp2/cio.c index 062627f0..57d4ccd2 100644 --- a/src/lib/openjp2/cio.c +++ b/src/lib/openjp2/cio.c @@ -522,7 +522,6 @@ OPJ_OFF_T opj_stream_write_skip (opj_stream_private_t * p_stream, OPJ_OFF_T p_si if (! l_is_written) { p_stream->m_status |= opj_stream_e_error; p_stream->m_bytes_in_buffer = 0; - p_stream->m_current_data = p_stream->m_current_data; return (OPJ_OFF_T) -1; } /* then skip */ From a7b051b172b7d8d1171729732e5b29aa80600d08 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 09:44:32 +0000 Subject: [PATCH 224/333] [trunk] Update memory management mecanism Fixes issue 253 --- src/lib/openjp2/openjpeg.c | 117 ------------------------ src/lib/openjp2/opj_codec.h | 160 +++++++++++++++++++++++++++++++++ src/lib/openjp2/opj_includes.h | 1 + 3 files changed, 161 insertions(+), 117 deletions(-) create mode 100644 src/lib/openjp2/opj_codec.h diff --git a/src/lib/openjp2/openjpeg.c b/src/lib/openjp2/openjpeg.c index ad011163..08610c8c 100644 --- a/src/lib/openjp2/openjpeg.c +++ b/src/lib/openjp2/openjpeg.c @@ -32,123 +32,6 @@ #include "opj_includes.h" -/** - * Decompression handler. - */ -typedef struct opj_decompression -{ - /** Main header reading function handler*/ - OPJ_BOOL (*opj_read_header) ( struct opj_stream_private * cio, - void * p_codec, - opj_image_t **p_image, - struct opj_event_mgr * p_manager); - /** Decoding function */ - OPJ_BOOL (*opj_decode) ( void * p_codec, - struct opj_stream_private *p_cio, - opj_image_t *p_image, - struct opj_event_mgr * p_manager); - /** FIXME DOC */ - OPJ_BOOL (*opj_read_tile_header)( void * p_codec, - OPJ_UINT32 * p_tile_index, - OPJ_UINT32* p_data_size, - OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0, - OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1, - OPJ_UINT32 * p_nb_comps, - OPJ_BOOL * p_should_go_on, - struct opj_stream_private *p_cio, - struct opj_event_mgr * p_manager); - /** FIXME DOC */ - OPJ_BOOL (*opj_decode_tile_data)( void * p_codec, - OPJ_UINT32 p_tile_index, - OPJ_BYTE * p_data, - OPJ_UINT32 p_data_size, - struct opj_stream_private *p_cio, - struct opj_event_mgr * p_manager); - /** Reading function used after codestream if necessary */ - OPJ_BOOL (* opj_end_decompress) ( void *p_codec, - struct opj_stream_private *cio, - struct opj_event_mgr * p_manager); - /** Codec destroy function handler*/ - void (*opj_destroy) (void * p_codec); - /** Setup decoder function handler */ - void (*opj_setup_decoder) (void * p_codec, opj_dparameters_t * p_param); - /** Set decode area function handler */ - OPJ_BOOL (*opj_set_decode_area) ( void * p_codec, - opj_image_t* p_image, - OPJ_INT32 p_start_x, OPJ_INT32 p_end_x, - OPJ_INT32 p_start_y, OPJ_INT32 p_end_y, - struct opj_event_mgr * p_manager); - - /** Get tile function */ - OPJ_BOOL (*opj_get_decoded_tile) ( void *p_codec, - opj_stream_private_t *p_cio, - opj_image_t *p_image, - struct opj_event_mgr * p_manager, - OPJ_UINT32 tile_index); - - /** Set the decoded resolution factor */ - OPJ_BOOL (*opj_set_decoded_resolution_factor) ( void * p_codec, - OPJ_UINT32 res_factor, - opj_event_mgr_t * p_manager); - -}opj_decompression_t; - -/** - * Compression handler. FIXME DOC - */ -typedef struct opj_compression -{ - OPJ_BOOL (* opj_start_compress) ( void *p_codec, - struct opj_stream_private *cio, - struct opj_image * p_image, - struct opj_event_mgr * p_manager); - - OPJ_BOOL (* opj_encode) ( void * p_codec, - struct opj_stream_private *p_cio, - struct opj_event_mgr * p_manager); - - OPJ_BOOL (* opj_write_tile) ( void * p_codec, - OPJ_UINT32 p_tile_index, - OPJ_BYTE * p_data, - OPJ_UINT32 p_data_size, - struct opj_stream_private * p_cio, - struct opj_event_mgr * p_manager); - - OPJ_BOOL (* opj_end_compress) ( void * p_codec, - struct opj_stream_private *p_cio, - struct opj_event_mgr * p_manager); - - void (* opj_destroy) (void * p_codec); - - void (* opj_setup_encoder) ( void * p_codec, - opj_cparameters_t * p_param, - struct opj_image * p_image, - struct opj_event_mgr * p_manager); - -}opj_compression_t; - -/** - * Main codec handler used for compression or decompression. - */ -typedef struct opj_codec_private -{ - /** FIXME DOC */ - union - { - opj_decompression_t m_decompression; - opj_compression_t m_compression; - } m_codec_data; - /** FIXME DOC*/ - void * m_codec; - /** Event handler */ - opj_event_mgr_t m_event_mgr; - /** Flag to indicate if the codec is used to decode or encode*/ - OPJ_BOOL is_decompressor; - void (*opj_dump_codec) (void * p_codec, OPJ_INT32 info_flag, FILE* output_stream); - opj_codestream_info_v2_t* (*opj_get_codec_info)(void* p_codec); - opj_codestream_index_t* (*opj_get_codec_index)(void* p_codec); -} -opj_codec_private_t; /* ---------------------------------------------------------------------- */ /* Functions to set the message handlers */ diff --git a/src/lib/openjp2/opj_codec.h b/src/lib/openjp2/opj_codec.h new file mode 100644 index 00000000..6ac0f28f --- /dev/null +++ b/src/lib/openjp2/opj_codec.h @@ -0,0 +1,160 @@ +/* + * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium + * Copyright (c) 2002-2007, Professor Benoit Macq + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +#ifndef __OPJ_CODEC_H +#define __OPJ_CODEC_H +/** +@file opj_codec.h +*/ + + +/** + * Main codec handler used for compression or decompression. + */ +typedef struct opj_codec_private +{ + /** FIXME DOC */ + union + { + /** + * Decompression handler. + */ + struct opj_decompression + { + /** Main header reading function handler */ + OPJ_BOOL (*opj_read_header) ( struct opj_stream_private * cio, + void * p_codec, + opj_image_t **p_image, + struct opj_event_mgr * p_manager); + + /** Decoding function */ + OPJ_BOOL (*opj_decode) ( void * p_codec, + struct opj_stream_private * p_cio, + opj_image_t * p_image, + struct opj_event_mgr * p_manager); + + /** FIXME DOC */ + OPJ_BOOL (*opj_read_tile_header)( void * p_codec, + OPJ_UINT32 * p_tile_index, + OPJ_UINT32 * p_data_size, + OPJ_INT32 * p_tile_x0, + OPJ_INT32 * p_tile_y0, + OPJ_INT32 * p_tile_x1, + OPJ_INT32 * p_tile_y1, + OPJ_UINT32 * p_nb_comps, + OPJ_BOOL * p_should_go_on, + struct opj_stream_private * p_cio, + struct opj_event_mgr * p_manager); + + /** FIXME DOC */ + OPJ_BOOL (*opj_decode_tile_data)( void * p_codec, + OPJ_UINT32 p_tile_index, + OPJ_BYTE * p_data, + OPJ_UINT32 p_data_size, + struct opj_stream_private * p_cio, + struct opj_event_mgr * p_manager); + + /** Reading function used after codestream if necessary */ + OPJ_BOOL (* opj_end_decompress) ( void *p_codec, + struct opj_stream_private * cio, + struct opj_event_mgr * p_manager); + + /** Codec destroy function handler */ + void (*opj_destroy) (void * p_codec); + + /** Setup decoder function handler */ + void (*opj_setup_decoder) ( void * p_codec, opj_dparameters_t * p_param); + + /** Set decode area function handler */ + OPJ_BOOL (*opj_set_decode_area) ( void * p_codec, + opj_image_t * p_image, + OPJ_INT32 p_start_x, + OPJ_INT32 p_end_x, + OPJ_INT32 p_start_y, + OPJ_INT32 p_end_y, + struct opj_event_mgr * p_manager); + + /** Get tile function */ + OPJ_BOOL (*opj_get_decoded_tile) ( void *p_codec, + opj_stream_private_t * p_cio, + opj_image_t *p_image, + struct opj_event_mgr * p_manager, + OPJ_UINT32 tile_index); + + /** Set the decoded resolution factor */ + OPJ_BOOL (*opj_set_decoded_resolution_factor) ( void * p_codec, + OPJ_UINT32 res_factor, + opj_event_mgr_t * p_manager); + } m_decompression; + + /** + * Compression handler. FIXME DOC + */ + struct opj_compression + { + OPJ_BOOL (* opj_start_compress) ( void *p_codec, + struct opj_stream_private * cio, + struct opj_image * p_image, + struct opj_event_mgr * p_manager); + + OPJ_BOOL (* opj_encode) ( void * p_codec, + struct opj_stream_private *p_cio, + struct opj_event_mgr * p_manager); + + OPJ_BOOL (* opj_write_tile) ( void * p_codec, + OPJ_UINT32 p_tile_index, + OPJ_BYTE * p_data, + OPJ_UINT32 p_data_size, + struct opj_stream_private * p_cio, + struct opj_event_mgr * p_manager); + + OPJ_BOOL (* opj_end_compress) ( void * p_codec, + struct opj_stream_private * p_cio, + struct opj_event_mgr * p_manager); + + void (* opj_destroy) (void * p_codec); + + void (* opj_setup_encoder) ( void * p_codec, + opj_cparameters_t * p_param, + struct opj_image * p_image, + struct opj_event_mgr * p_manager); + } m_compression; + } m_codec_data; + /** FIXME DOC*/ + void * m_codec; + /** Event handler */ + opj_event_mgr_t m_event_mgr; + /** Flag to indicate if the codec is used to decode or encode*/ + OPJ_BOOL is_decompressor; + void (*opj_dump_codec) (void * p_codec, OPJ_INT32 info_flag, FILE* output_stream); + opj_codestream_info_v2_t* (*opj_get_codec_info)(void* p_codec); + opj_codestream_index_t* (*opj_get_codec_index)(void* p_codec); +} +opj_codec_private_t; + + +#endif /* __OPJ_CODEC_H */ + diff --git a/src/lib/openjp2/opj_includes.h b/src/lib/openjp2/opj_includes.h index 346f3a3c..f7f1f585 100644 --- a/src/lib/openjp2/opj_includes.h +++ b/src/lib/openjp2/opj_includes.h @@ -187,6 +187,7 @@ static INLINE long lrintf(float f){ /* < Date: Fri, 7 Mar 2014 09:58:32 +0000 Subject: [PATCH 225/333] [trunk] un-deprecated opj_stream_destroy API, import patch manually In some case user still want to be able to call opj_stream_destroy. Fixes issue 227 --- src/lib/openjp2/cio.c | 18 ++++++------------ src/lib/openjp2/cio.h | 7 +++++++ src/lib/openjp2/openjpeg.c | 2 +- src/lib/openjp2/openjpeg.h | 10 ++++++++-- 4 files changed, 22 insertions(+), 15 deletions(-) diff --git a/src/lib/openjp2/cio.c b/src/lib/openjp2/cio.c index 57d4ccd2..f7f1bc72 100644 --- a/src/lib/openjp2/cio.c +++ b/src/lib/openjp2/cio.c @@ -189,6 +189,9 @@ void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream) opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; if (l_stream) { + if (l_stream->m_free_user_data_fn) { + l_stream->m_free_user_data_fn(l_stream->m_user_data); + } opj_free(l_stream->m_stored_data); l_stream->m_stored_data = 00; opj_free(l_stream); @@ -197,17 +200,7 @@ void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream) void OPJ_CALLCONV opj_stream_destroy_v3(opj_stream_t* p_stream) { - opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; - - if (l_stream) { - FILE *fp = (FILE*)l_stream->m_user_data; - if(fp) - fclose(fp); - - opj_free(l_stream->m_stored_data); - l_stream->m_stored_data = 00; - opj_free(l_stream); - } + opj_stream_destroy(p_stream); } void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, opj_stream_read_fn p_function) @@ -253,12 +246,13 @@ void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_strea l_stream->m_skip_fn = p_function; } -void OPJ_CALLCONV opj_stream_set_user_data(opj_stream_t* p_stream, void * p_data) +void OPJ_CALLCONV opj_stream_set_user_data(opj_stream_t* p_stream, void * p_data, opj_stream_free_user_data_fn p_function) { opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; if (!l_stream) return; l_stream->m_user_data = p_data; + l_stream->m_free_user_data_fn = p_function; } void OPJ_CALLCONV opj_stream_set_user_data_length(opj_stream_t* p_stream, OPJ_UINT64 data_length) diff --git a/src/lib/openjp2/cio.h b/src/lib/openjp2/cio.h index 8e162a16..edbc2009 100644 --- a/src/lib/openjp2/cio.h +++ b/src/lib/openjp2/cio.h @@ -85,6 +85,13 @@ typedef struct opj_stream_private */ void * m_user_data; + /** + * Pointer to function to free m_user_data (NULL at initialization) + * when destroying the stream. If pointer is NULL the function is not + * called and the m_user_data is not freed (even if non-NULL). + */ + opj_stream_free_user_data_fn m_free_user_data_fn; + /** * User data length */ diff --git a/src/lib/openjp2/openjpeg.c b/src/lib/openjp2/openjpeg.c index 08610c8c..05a9938d 100644 --- a/src/lib/openjp2/openjpeg.c +++ b/src/lib/openjp2/openjpeg.c @@ -944,7 +944,7 @@ opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream_v3 ( return NULL; } - opj_stream_set_user_data(l_stream, p_file); + opj_stream_set_user_data(l_stream, p_file, (opj_stream_free_user_data_fn) fclose); opj_stream_set_user_data_length(l_stream, opj_get_data_length_from_file(p_file)); opj_stream_set_read_function(l_stream, (opj_stream_read_fn) opj_read_from_file); opj_stream_set_write_function(l_stream, (opj_stream_write_fn) opj_write_from_file); diff --git a/src/lib/openjp2/openjpeg.h b/src/lib/openjp2/openjpeg.h index 8170f7a4..d3339954 100644 --- a/src/lib/openjp2/openjpeg.h +++ b/src/lib/openjp2/openjpeg.h @@ -500,6 +500,11 @@ typedef OPJ_OFF_T (* opj_stream_skip_fn) (OPJ_OFF_T p_nb_bytes, void * p_user_da */ typedef OPJ_BOOL (* opj_stream_seek_fn) (OPJ_OFF_T p_nb_bytes, void * p_user_data) ; +/* + * Callback function prototype for free user data function + */ +typedef void (* opj_stream_free_user_data_fn) (void * p_user_data) ; + /* * JPEG2000 Stream. */ @@ -1007,7 +1012,7 @@ OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size, O * * @param p_stream the stream to destroy. */ -OPJ_DEPRECATED(OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream)); +OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream); /** * Destroys a stream created by opj_create_stream. This function does NOT close the abstract stream. @@ -1049,8 +1054,9 @@ OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, o * Sets the given data to be used as a user data for the stream. * @param p_stream the stream to modify * @param p_data the data to set. + * @param p_function the function to free p_data when opj_stream_destroy() is called. */ -OPJ_API void OPJ_CALLCONV opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data); +OPJ_API void OPJ_CALLCONV opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data, opj_stream_free_user_data_fn p_function); /** * Sets the length of the user data for the stream. From c0c086388b3576bda3da06a38add8322d4737c77 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 10:03:56 +0000 Subject: [PATCH 226/333] [trunk] Fix warning about sign conversion Update issue 256 --- src/lib/openjp2/tgt.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib/openjp2/tgt.c b/src/lib/openjp2/tgt.c index 81b05482..44252ba7 100644 --- a/src/lib/openjp2/tgt.c +++ b/src/lib/openjp2/tgt.c @@ -62,11 +62,11 @@ opj_tgt_tree_t *opj_tgt_create(OPJ_UINT32 numleafsh, OPJ_UINT32 numleafsv) { tree->numleafsv = numleafsv; numlvls = 0; - nplh[0] = numleafsh; - nplv[0] = numleafsv; + nplh[0] = (OPJ_INT32)numleafsh; + nplv[0] = (OPJ_INT32)numleafsv; tree->numnodes = 0; do { - n = nplh[numlvls] * nplv[numlvls]; + n = (OPJ_UINT32)(nplh[numlvls] * nplv[numlvls]); nplh[numlvls + 1] = (nplh[numlvls] + 1) / 2; nplv[numlvls + 1] = (nplv[numlvls] + 1) / 2; tree->numnodes += n; @@ -148,12 +148,12 @@ opj_tgt_tree_t *opj_tgt_init(opj_tgt_tree_t * p_tree,OPJ_UINT32 p_num_leafs_h, O p_tree->numleafsv = p_num_leafs_v; l_num_levels = 0; - l_nplh[0] = p_num_leafs_h; - l_nplv[0] = p_num_leafs_v; + l_nplh[0] = (OPJ_INT32)p_num_leafs_h; + l_nplv[0] = (OPJ_INT32)p_num_leafs_v; p_tree->numnodes = 0; do { - n = l_nplh[l_num_levels] * l_nplv[l_num_levels]; + n = (OPJ_UINT32)(l_nplh[l_num_levels] * l_nplv[l_num_levels]); l_nplh[l_num_levels + 1] = (l_nplh[l_num_levels] + 1) / 2; l_nplv[l_num_levels + 1] = (l_nplv[l_num_levels] + 1) / 2; p_tree->numnodes += n; From 7b335eb635dc281b968acdc845028e449a4baca5 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 10:19:39 +0000 Subject: [PATCH 227/333] [trunk] Another of fixes for warning about sign conversion Update issue 256 --- src/lib/openjp2/dwt.c | 88 +++++++++++++++++++++---------------------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/src/lib/openjp2/dwt.c b/src/lib/openjp2/dwt.c index c617ffcf..e8e679d8 100644 --- a/src/lib/openjp2/dwt.c +++ b/src/lib/openjp2/dwt.c @@ -389,13 +389,13 @@ INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_tcd_tilecomp_t * tilec,void (*p_fun OPJ_INT32 rw; /* width of the resolution level computed */ OPJ_INT32 rh; /* height of the resolution level computed */ - OPJ_INT32 l_data_size; + OPJ_UINT32 l_data_size; opj_tcd_resolution_t * l_cur_res = 0; opj_tcd_resolution_t * l_last_res = 0; w = tilec->x1-tilec->x0; - l = tilec->numresolutions-1; + l = (OPJ_INT32)tilec->numresolutions-1; a = tilec->data; l_cur_res = tilec->resolutions + l; @@ -405,7 +405,7 @@ INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_tcd_tilecomp_t * tilec,void (*p_fun rh = l_cur_res->y1 - l_cur_res->y0; l_data_size = opj_dwt_max_resolution( tilec->resolutions,tilec->numresolutions) * (OPJ_UINT32)sizeof(OPJ_INT32); - bj = (OPJ_INT32*)opj_malloc(l_data_size); + bj = (OPJ_INT32*)opj_malloc((size_t)l_data_size); if (! bj) { return OPJ_FALSE; } @@ -531,7 +531,7 @@ void opj_dwt_calc_explicit_stepsizes(opj_tccp_t * tccp, OPJ_UINT32 prec) { OPJ_FLOAT64 norm = opj_dwt_norms_real[orient][level]; stepsize = (1 << (gain)) / norm; } - opj_dwt_encode_stepsize((OPJ_INT32) floor(stepsize * 8192.0), prec + gain, &tccp->stepsizes[bandno]); + opj_dwt_encode_stepsize((OPJ_INT32) floor(stepsize * 8192.0), (OPJ_INT32)(prec + gain), &tccp->stepsizes[bandno]); } } @@ -543,9 +543,9 @@ OPJ_UINT32 opj_dwt_max_resolution(opj_tcd_resolution_t* restrict r, OPJ_UINT32 i OPJ_UINT32 w; while( --i ) { ++r; - if( mr < ( w = r->x1 - r->x0 ) ) + if( mr < ( w = (OPJ_UINT32)(r->x1 - r->x0) ) ) mr = w ; - if( mr < ( w = r->y1 - r->y0 ) ) + if( mr < ( w = (OPJ_UINT32)(r->y1 - r->y0) ) ) mr = w ; } return mr ; @@ -560,10 +560,10 @@ OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres, DWT1D opj_tcd_resolution_t* tr = tilec->resolutions; - OPJ_UINT32 rw = tr->x1 - tr->x0; /* width of the resolution level computed */ - OPJ_UINT32 rh = tr->y1 - tr->y0; /* height of the resolution level computed */ + OPJ_UINT32 rw = (OPJ_UINT32)(tr->x1 - tr->x0); /* width of the resolution level computed */ + OPJ_UINT32 rh = (OPJ_UINT32)(tr->y1 - tr->y0); /* height of the resolution level computed */ - OPJ_UINT32 w = tilec->x1 - tilec->x0; + OPJ_UINT32 w = (OPJ_UINT32)(tilec->x1 - tilec->x0); h.mem = (OPJ_INT32*) opj_aligned_malloc(opj_dwt_max_resolution(tr, numres) * sizeof(OPJ_INT32)); @@ -578,13 +578,13 @@ OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres, DWT1D OPJ_UINT32 j; ++tr; - h.sn = rw; - v.sn = rh; + h.sn = (OPJ_INT32)rw; + v.sn = (OPJ_INT32)rh; - rw = tr->x1 - tr->x0; - rh = tr->y1 - tr->y0; + rw = (OPJ_UINT32)(tr->x1 - tr->x0); + rh = (OPJ_UINT32)(tr->y1 - tr->y0); - h.dn = rw - h.sn; + h.dn = (OPJ_INT32)(rw - (OPJ_UINT32)h.sn); h.cas = tr->x0 % 2; for(j = 0; j < rh; ++j) { @@ -593,12 +593,12 @@ OPJ_BOOL opj_dwt_decode_tile(opj_tcd_tilecomp_t* tilec, OPJ_UINT32 numres, DWT1D memcpy(&tiledp[j*w], h.mem, rw * sizeof(OPJ_INT32)); } - v.dn = rh - v.sn; + v.dn = (OPJ_INT32)(rh - (OPJ_UINT32)v.sn); v.cas = tr->y0 % 2; for(j = 0; j < rw; ++j){ OPJ_UINT32 k; - opj_dwt_interleave_v(&v, &tiledp[j], w); + opj_dwt_interleave_v(&v, &tiledp[j], (OPJ_INT32)w); (dwt_1D)(&v); for(k = 0; k < rh; ++k) { tiledp[k * w + j] = v.mem[k]; @@ -657,14 +657,14 @@ void opj_v4dwt_interleave_v(opj_v4dwt_t* restrict v , OPJ_FLOAT32* restrict a , OPJ_INT32 i; for(i = 0; i < v->sn; ++i){ - memcpy(&bi[i*2], &a[i*x], nb_elts_read * sizeof(OPJ_FLOAT32)); + memcpy(&bi[i*2], &a[i*x], (size_t)nb_elts_read * sizeof(OPJ_FLOAT32)); } a += v->sn * x; bi = v->wavelet + 1 - v->cas; for(i = 0; i < v->dn; ++i){ - memcpy(&bi[i*2], &a[i*x], nb_elts_read * sizeof(OPJ_FLOAT32)); + memcpy(&bi[i*2], &a[i*x], (size_t)nb_elts_read * sizeof(OPJ_FLOAT32)); } } @@ -833,40 +833,40 @@ OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, OPJ_UINT32 numr opj_tcd_resolution_t* res = tilec->resolutions; - OPJ_UINT32 rw = res->x1 - res->x0; /* width of the resolution level computed */ - OPJ_UINT32 rh = res->y1 - res->y0; /* height of the resolution level computed */ + OPJ_UINT32 rw = (OPJ_UINT32)(res->x1 - res->x0); /* width of the resolution level computed */ + OPJ_UINT32 rh = (OPJ_UINT32)(res->y1 - res->y0); /* height of the resolution level computed */ - OPJ_UINT32 w = tilec->x1 - tilec->x0; + OPJ_UINT32 w = (OPJ_UINT32)(tilec->x1 - tilec->x0); h.wavelet = (opj_v4_t*) opj_aligned_malloc((opj_dwt_max_resolution(res, numres)+5) * sizeof(opj_v4_t)); v.wavelet = h.wavelet; while( --numres) { OPJ_FLOAT32 * restrict aj = (OPJ_FLOAT32*) tilec->data; - OPJ_UINT32 bufsize = (tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0); + OPJ_UINT32 bufsize = (OPJ_UINT32)((tilec->x1 - tilec->x0) * (tilec->y1 - tilec->y0)); OPJ_INT32 j; - h.sn = rw; - v.sn = rh; + h.sn = (OPJ_INT32)rw; + v.sn = (OPJ_INT32)rh; ++res; - rw = res->x1 - res->x0; /* width of the resolution level computed */ - rh = res->y1 - res->y0; /* height of the resolution level computed */ + rw = (OPJ_UINT32)(res->x1 - res->x0); /* width of the resolution level computed */ + rh = (OPJ_UINT32)(res->y1 - res->y0); /* height of the resolution level computed */ - h.dn = rw - h.sn; + h.dn = (OPJ_INT32)(rw - (OPJ_UINT32)h.sn); h.cas = res->x0 % 2; - for(j = rh; j > 3; j -= 4) { + for(j = (OPJ_INT32)rh; j > 3; j -= 4) { OPJ_INT32 k; - opj_v4dwt_interleave_h(&h, aj, w, bufsize); + opj_v4dwt_interleave_h(&h, aj, (OPJ_INT32)w, (OPJ_INT32)bufsize); opj_v4dwt_decode(&h); - for(k = rw; --k >= 0;){ - aj[k ] = h.wavelet[k].f[0]; - aj[k+w ] = h.wavelet[k].f[1]; - aj[k+w*2] = h.wavelet[k].f[2]; - aj[k+w*3] = h.wavelet[k].f[3]; + for(k = (OPJ_INT32)rw; --k >= 0;){ + aj[k ] = h.wavelet[k].f[0]; + aj[k+(OPJ_INT32)w ] = h.wavelet[k].f[1]; + aj[k+(OPJ_INT32)w*2] = h.wavelet[k].f[2]; + aj[k+(OPJ_INT32)w*3] = h.wavelet[k].f[3]; } aj += w*4; @@ -876,25 +876,25 @@ OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, OPJ_UINT32 numr if (rh & 0x03) { OPJ_INT32 k; j = rh & 0x03; - opj_v4dwt_interleave_h(&h, aj, w, bufsize); + opj_v4dwt_interleave_h(&h, aj, (OPJ_INT32)w, (OPJ_INT32)bufsize); opj_v4dwt_decode(&h); - for(k = rw; --k >= 0;){ + for(k = (OPJ_INT32)rw; --k >= 0;){ switch(j) { - case 3: aj[k+w*2] = h.wavelet[k].f[2]; - case 2: aj[k+w ] = h.wavelet[k].f[1]; - case 1: aj[k ] = h.wavelet[k].f[0]; + case 3: aj[k+(OPJ_INT32)w*2] = h.wavelet[k].f[2]; + case 2: aj[k+(OPJ_INT32)w ] = h.wavelet[k].f[1]; + case 1: aj[k ] = h.wavelet[k].f[0]; } } } - v.dn = rh - v.sn; + v.dn = (OPJ_INT32)(rh - (OPJ_UINT32)v.sn); v.cas = res->y0 % 2; aj = (OPJ_FLOAT32*) tilec->data; - for(j = rw; j > 3; j -= 4){ + for(j = (OPJ_INT32)rw; j > 3; j -= 4){ OPJ_UINT32 k; - opj_v4dwt_interleave_v(&v, aj, w, 4); + opj_v4dwt_interleave_v(&v, aj, (OPJ_INT32)w, 4); opj_v4dwt_decode(&v); for(k = 0; k < rh; ++k){ @@ -908,11 +908,11 @@ OPJ_BOOL opj_dwt_decode_real(opj_tcd_tilecomp_t* restrict tilec, OPJ_UINT32 numr j = rw & 0x03; - opj_v4dwt_interleave_v(&v, aj, w, j); + opj_v4dwt_interleave_v(&v, aj, (OPJ_INT32)w, j); opj_v4dwt_decode(&v); for(k = 0; k < rh; ++k){ - memcpy(&aj[k*w], &v.wavelet[k], j * sizeof(OPJ_FLOAT32)); + memcpy(&aj[k*w], &v.wavelet[k], (size_t)j * sizeof(OPJ_FLOAT32)); } } } From e71431ec78249b9d089a340befc18b151326c81f Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 10:21:51 +0000 Subject: [PATCH 228/333] [trunk] Fix simple warning about sign conversion Update issue 256 --- src/lib/openjp2/invert.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/openjp2/invert.c b/src/lib/openjp2/invert.c index 92de0a85..bb6672d4 100644 --- a/src/lib/openjp2/invert.c +++ b/src/lib/openjp2/invert.c @@ -250,7 +250,7 @@ void opj_lupSolve (OPJ_FLOAT32 * pResult, lTmpMatrix = lLineMatrix; u = *(lTmpMatrix++); lCurrentPtr = lDestPtr--; - for (j = k + 1; j < nb_compo; ++j) { + for (j = (OPJ_UINT32)(k + 1); j < nb_compo; ++j) { /* sum += matrix[k][j] * x[j] */ sum += (*(lTmpMatrix++)) * (*(lCurrentPtr++)); } From 76cd9b7f7274ad1ba7ad91441e6744805f8c7786 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 10:25:16 +0000 Subject: [PATCH 229/333] [trunk] Another round of fixes for sign conversion warnings. Update issue 256 --- src/lib/openjp2/mqc.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/lib/openjp2/mqc.c b/src/lib/openjp2/mqc.c index 5fcbe6fd..677884c3 100644 --- a/src/lib/openjp2/mqc.c +++ b/src/lib/openjp2/mqc.c @@ -274,10 +274,10 @@ void opj_mqc_setbits(opj_mqc_t *mqc) { static INLINE OPJ_INT32 opj_mqc_mpsexchange(opj_mqc_t *const mqc) { OPJ_INT32 d; if (mqc->a < (*mqc->curctx)->qeval) { - d = 1 - (*mqc->curctx)->mps; + d = (OPJ_INT32)(1 - (*mqc->curctx)->mps); *mqc->curctx = (*mqc->curctx)->nlps; } else { - d = (*mqc->curctx)->mps; + d = (OPJ_INT32)(*mqc->curctx)->mps; *mqc->curctx = (*mqc->curctx)->nmps; } @@ -288,11 +288,11 @@ static INLINE OPJ_INT32 opj_mqc_lpsexchange(opj_mqc_t *const mqc) { OPJ_INT32 d; if (mqc->a < (*mqc->curctx)->qeval) { mqc->a = (*mqc->curctx)->qeval; - d = (*mqc->curctx)->mps; + d = (OPJ_INT32)(*mqc->curctx)->mps; *mqc->curctx = (*mqc->curctx)->nmps; } else { mqc->a = (*mqc->curctx)->qeval; - d = 1 - (*mqc->curctx)->mps; + d = (OPJ_INT32)(1 - (*mqc->curctx)->mps); *mqc->curctx = (*mqc->curctx)->nlps; } @@ -441,7 +441,7 @@ OPJ_UINT32 opj_mqc_bypass_flush_enc(opj_mqc_t *mqc) { if (mqc->ct != 0) { while (mqc->ct > 0) { mqc->ct--; - mqc->c += bit_padding << mqc->ct; + mqc->c += (OPJ_UINT32)(bit_padding << mqc->ct); bit_padding = (bit_padding + 1) & 0x01; } mqc->bp++; @@ -464,11 +464,11 @@ OPJ_UINT32 opj_mqc_restart_enc(opj_mqc_t *mqc) { OPJ_UINT32 correction = 1; /* */ - OPJ_INT32 n = 27 - 15 - mqc->ct; + OPJ_INT32 n = (OPJ_INT32)(27 - 15 - mqc->ct); mqc->c <<= mqc->ct; while (n > 0) { opj_mqc_byteout(mqc); - n -= mqc->ct; + n -= (OPJ_INT32)mqc->ct; mqc->c <<= mqc->ct; } opj_mqc_byteout(mqc); @@ -489,13 +489,13 @@ void opj_mqc_restart_init_enc(opj_mqc_t *mqc) { } void opj_mqc_erterm_enc(opj_mqc_t *mqc) { - OPJ_INT32 k = 11 - mqc->ct + 1; + OPJ_INT32 k = (OPJ_INT32)(11 - mqc->ct + 1); while (k > 0) { mqc->c <<= mqc->ct; mqc->ct = 0; opj_mqc_byteout(mqc); - k -= mqc->ct; + k -= (OPJ_INT32)mqc->ct; } if (*mqc->bp != 0xff) { @@ -518,7 +518,7 @@ OPJ_BOOL opj_mqc_init_dec(opj_mqc_t *mqc, OPJ_BYTE *bp, OPJ_UINT32 len) { mqc->end = bp + len; mqc->bp = bp; if (len==0) mqc->c = 0xff << 16; - else mqc->c = *mqc->bp << 16; + else mqc->c = (OPJ_UINT32)(*mqc->bp << 16); #ifdef MQC_PERF_OPT /* TODO_MSD: check this option and put in experimental */ { @@ -583,7 +583,7 @@ OPJ_INT32 opj_mqc_decode(opj_mqc_t *const mqc) { d = opj_mqc_mpsexchange(mqc); opj_mqc_renormd(mqc); } else { - d = (*mqc->curctx)->mps; + d = (OPJ_INT32)(*mqc->curctx)->mps; } } @@ -598,7 +598,7 @@ void opj_mqc_resetstates(opj_mqc_t *mqc) { } void opj_mqc_setstate(opj_mqc_t *mqc, OPJ_UINT32 ctxno, OPJ_UINT32 msb, OPJ_INT32 prob) { - mqc->ctxs[ctxno] = &mqc_states[msb + (prob << 1)]; + mqc->ctxs[ctxno] = &mqc_states[msb + (OPJ_UINT32)(prob << 1)]; } From e4d077bc986cf8586994c7fa1e035f8c7e5ce82c Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 11:06:13 +0000 Subject: [PATCH 230/333] [trunk] Another round of fixes for sign conversion warnings. Update issue 256 --- src/lib/openjp2/pi.c | 258 +++++++++++++++++++++---------------------- 1 file changed, 129 insertions(+), 129 deletions(-) diff --git a/src/lib/openjp2/pi.c b/src/lib/openjp2/pi.c index d0af7652..eeb14b7d 100644 --- a/src/lib/openjp2/pi.c +++ b/src/lib/openjp2/pi.c @@ -320,8 +320,8 @@ OPJ_BOOL opj_pi_next_rpcl(opj_pi_iterator_t * pi) { for (resno = 0; resno < comp->numresolutions; resno++) { OPJ_UINT32 dx, dy; res = &comp->resolutions[resno]; - dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno)); - dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno)); + dx = comp->dx * (1u << (res->pdx + comp->numresolutions - 1 - resno)); + dy = comp->dy * (1u << (res->pdy + comp->numresolutions - 1 - resno)); pi->dx = !pi->dx ? dx : opj_uint_min(pi->dx, dx); pi->dy = !pi->dy ? dy : opj_uint_min(pi->dy, dy); } @@ -334,8 +334,8 @@ if (!pi->tp_on){ pi->poc.tx1 = pi->tx1; } for (pi->resno = pi->poc.resno0; pi->resno < pi->poc.resno1; pi->resno++) { - for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; pi->y += pi->dy - (pi->y % pi->dy)) { - for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; pi->x += pi->dx - (pi->x % pi->dx)) { + for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; pi->y += (OPJ_INT32)(pi->dy - (OPJ_UINT32)(pi->y % (OPJ_INT32)pi->dy))) { + for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; pi->x += (OPJ_INT32)(pi->dx - (OPJ_UINT32)(pi->x % (OPJ_INT32)pi->dx))) { for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { OPJ_UINT32 levelno; OPJ_INT32 trx0, try0; @@ -348,16 +348,16 @@ if (!pi->tp_on){ } res = &comp->resolutions[pi->resno]; levelno = comp->numresolutions - 1 - pi->resno; - trx0 = opj_int_ceildiv(pi->tx0, comp->dx << levelno); - try0 = opj_int_ceildiv(pi->ty0, comp->dy << levelno); - trx1 = opj_int_ceildiv(pi->tx1, comp->dx << levelno); - try1 = opj_int_ceildiv(pi->ty1, comp->dy << levelno); + trx0 = opj_int_ceildiv(pi->tx0, (OPJ_INT32)(comp->dx << levelno)); + try0 = opj_int_ceildiv(pi->ty0, (OPJ_INT32)(comp->dy << levelno)); + trx1 = opj_int_ceildiv(pi->tx1, (OPJ_INT32)(comp->dx << levelno)); + try1 = opj_int_ceildiv(pi->ty1, (OPJ_INT32)(comp->dy << levelno)); rpx = res->pdx + levelno; rpy = res->pdy + levelno; - if (!((pi->y % (comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){ + if (!((pi->y % (OPJ_INT32)(comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){ continue; } - if (!((pi->x % (comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){ + if (!((pi->x % (OPJ_INT32)(comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){ continue; } @@ -365,11 +365,11 @@ if (!pi->tp_on){ if ((trx0==trx1)||(try0==try1)) continue; - prci = opj_int_floordivpow2(opj_int_ceildiv(pi->x, comp->dx << levelno), res->pdx) - - opj_int_floordivpow2(trx0, res->pdx); - prcj = opj_int_floordivpow2(opj_int_ceildiv(pi->y, comp->dy << levelno), res->pdy) - - opj_int_floordivpow2(try0, res->pdy); - pi->precno = prci + prcj * res->pw; + prci = opj_int_floordivpow2(opj_int_ceildiv(pi->x, (OPJ_INT32)(comp->dx << levelno)), (OPJ_INT32)res->pdx) + - opj_int_floordivpow2(trx0, (OPJ_INT32)res->pdx); + prcj = opj_int_floordivpow2(opj_int_ceildiv(pi->y, (OPJ_INT32)(comp->dy << levelno)), (OPJ_INT32)res->pdy) + - opj_int_floordivpow2(try0, (OPJ_INT32)res->pdy); + pi->precno = (OPJ_UINT32)(prci + prcj * (OPJ_INT32)res->pw); for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) { index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; if (!pi->include[index]) { @@ -404,8 +404,8 @@ OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi) { for (resno = 0; resno < comp->numresolutions; resno++) { OPJ_UINT32 dx, dy; res = &comp->resolutions[resno]; - dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno)); - dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno)); + dx = comp->dx * (1u << (res->pdx + comp->numresolutions - 1 - resno)); + dy = comp->dy * (1u << (res->pdy + comp->numresolutions - 1 - resno)); pi->dx = !pi->dx ? dx : opj_uint_min(pi->dx, dx); pi->dy = !pi->dy ? dy : opj_uint_min(pi->dy, dy); } @@ -417,8 +417,8 @@ OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi) { pi->poc.ty1 = pi->ty1; pi->poc.tx1 = pi->tx1; } - for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; pi->y += pi->dy - (pi->y % pi->dy)) { - for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; pi->x += pi->dx - (pi->x % pi->dx)) { + for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; pi->y += (OPJ_INT32)(pi->dy - (OPJ_UINT32)(pi->y % (OPJ_INT32)pi->dy))) { + for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; pi->x += (OPJ_INT32)(pi->dx - (OPJ_UINT32)(pi->x % (OPJ_INT32)pi->dx))) { for (pi->compno = pi->poc.compno0; pi->compno < pi->poc.compno1; pi->compno++) { comp = &pi->comps[pi->compno]; for (pi->resno = pi->poc.resno0; pi->resno < opj_uint_min(pi->poc.resno1, comp->numresolutions); pi->resno++) { @@ -429,16 +429,16 @@ OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi) { OPJ_INT32 prci, prcj; res = &comp->resolutions[pi->resno]; levelno = comp->numresolutions - 1 - pi->resno; - trx0 = opj_int_ceildiv(pi->tx0, comp->dx << levelno); - try0 = opj_int_ceildiv(pi->ty0, comp->dy << levelno); - trx1 = opj_int_ceildiv(pi->tx1, comp->dx << levelno); - try1 = opj_int_ceildiv(pi->ty1, comp->dy << levelno); + trx0 = opj_int_ceildiv(pi->tx0, (OPJ_INT32)(comp->dx << levelno)); + try0 = opj_int_ceildiv(pi->ty0, (OPJ_INT32)(comp->dy << levelno)); + trx1 = opj_int_ceildiv(pi->tx1, (OPJ_INT32)(comp->dx << levelno)); + try1 = opj_int_ceildiv(pi->ty1, (OPJ_INT32)(comp->dy << levelno)); rpx = res->pdx + levelno; rpy = res->pdy + levelno; - if (!((pi->y % (comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){ + if (!((pi->y % (OPJ_INT32)(comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){ continue; } - if (!((pi->x % (comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){ + if (!((pi->x % (OPJ_INT32)(comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){ continue; } @@ -446,11 +446,11 @@ OPJ_BOOL opj_pi_next_pcrl(opj_pi_iterator_t * pi) { if ((trx0==trx1)||(try0==try1)) continue; - prci = opj_int_floordivpow2(opj_int_ceildiv(pi->x, comp->dx << levelno), res->pdx) - - opj_int_floordivpow2(trx0, res->pdx); - prcj = opj_int_floordivpow2(opj_int_ceildiv(pi->y, comp->dy << levelno), res->pdy) - - opj_int_floordivpow2(try0, res->pdy); - pi->precno = prci + prcj * res->pw; + prci = opj_int_floordivpow2(opj_int_ceildiv(pi->x, (OPJ_INT32)(comp->dx << levelno)), (OPJ_INT32)res->pdx) + - opj_int_floordivpow2(trx0, (OPJ_INT32)res->pdx); + prcj = opj_int_floordivpow2(opj_int_ceildiv(pi->y, (OPJ_INT32)(comp->dy << levelno)), (OPJ_INT32)res->pdy) + - opj_int_floordivpow2(try0, (OPJ_INT32)res->pdy); + pi->precno = (OPJ_UINT32)(prci + prcj * (OPJ_INT32)res->pw); for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) { index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; if (!pi->include[index]) { @@ -487,8 +487,8 @@ OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi) { for (resno = 0; resno < comp->numresolutions; resno++) { OPJ_UINT32 dx, dy; res = &comp->resolutions[resno]; - dx = comp->dx * (1 << (res->pdx + comp->numresolutions - 1 - resno)); - dy = comp->dy * (1 << (res->pdy + comp->numresolutions - 1 - resno)); + dx = comp->dx * (1u << (res->pdx + comp->numresolutions - 1 - resno)); + dy = comp->dy * (1u << (res->pdy + comp->numresolutions - 1 - resno)); pi->dx = !pi->dx ? dx : opj_uint_min(pi->dx, dx); pi->dy = !pi->dy ? dy : opj_uint_min(pi->dy, dy); } @@ -498,8 +498,8 @@ OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi) { pi->poc.ty1 = pi->ty1; pi->poc.tx1 = pi->tx1; } - for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; pi->y += pi->dy - (pi->y % pi->dy)) { - for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; pi->x += pi->dx - (pi->x % pi->dx)) { + for (pi->y = pi->poc.ty0; pi->y < pi->poc.ty1; pi->y += (OPJ_INT32)(pi->dy - (OPJ_UINT32)(pi->y % (OPJ_INT32)pi->dy))) { + for (pi->x = pi->poc.tx0; pi->x < pi->poc.tx1; pi->x += (OPJ_INT32)(pi->dx - (OPJ_UINT32)(pi->x % (OPJ_INT32)pi->dx))) { for (pi->resno = pi->poc.resno0; pi->resno < opj_uint_min(pi->poc.resno1, comp->numresolutions); pi->resno++) { OPJ_UINT32 levelno; OPJ_INT32 trx0, try0; @@ -508,16 +508,16 @@ OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi) { OPJ_INT32 prci, prcj; res = &comp->resolutions[pi->resno]; levelno = comp->numresolutions - 1 - pi->resno; - trx0 = opj_int_ceildiv(pi->tx0, comp->dx << levelno); - try0 = opj_int_ceildiv(pi->ty0, comp->dy << levelno); - trx1 = opj_int_ceildiv(pi->tx1, comp->dx << levelno); - try1 = opj_int_ceildiv(pi->ty1, comp->dy << levelno); + trx0 = opj_int_ceildiv(pi->tx0, (OPJ_INT32)(comp->dx << levelno)); + try0 = opj_int_ceildiv(pi->ty0, (OPJ_INT32)(comp->dy << levelno)); + trx1 = opj_int_ceildiv(pi->tx1, (OPJ_INT32)(comp->dx << levelno)); + try1 = opj_int_ceildiv(pi->ty1, (OPJ_INT32)(comp->dy << levelno)); rpx = res->pdx + levelno; rpy = res->pdy + levelno; - if (!((pi->y % (comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){ + if (!((pi->y % (OPJ_INT32)(comp->dy << rpy) == 0) || ((pi->y == pi->ty0) && ((try0 << levelno) % (1 << rpy))))){ continue; } - if (!((pi->x % (comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){ + if (!((pi->x % (OPJ_INT32)(comp->dx << rpx) == 0) || ((pi->x == pi->tx0) && ((trx0 << levelno) % (1 << rpx))))){ continue; } @@ -525,11 +525,11 @@ OPJ_BOOL opj_pi_next_cprl(opj_pi_iterator_t * pi) { if ((trx0==trx1)||(try0==try1)) continue; - prci = opj_int_floordivpow2(opj_int_ceildiv(pi->x, comp->dx << levelno), res->pdx) - - opj_int_floordivpow2(trx0, res->pdx); - prcj = opj_int_floordivpow2(opj_int_ceildiv(pi->y, comp->dy << levelno), res->pdy) - - opj_int_floordivpow2(try0, res->pdy); - pi->precno = prci + prcj * res->pw; + prci = opj_int_floordivpow2(opj_int_ceildiv(pi->x, (OPJ_INT32)(comp->dx << levelno)), (OPJ_INT32)res->pdx) + - opj_int_floordivpow2(trx0, (OPJ_INT32)res->pdx); + prcj = opj_int_floordivpow2(opj_int_ceildiv(pi->y, (OPJ_INT32)(comp->dy << levelno)), (OPJ_INT32)res->pdy) + - opj_int_floordivpow2(try0, (OPJ_INT32)res->pdy); + pi->precno = (OPJ_UINT32)(prci + prcj * (OPJ_INT32)res->pw); for (pi->layno = pi->poc.layno0; pi->layno < pi->poc.layno1; pi->layno++) { index = pi->layno * pi->step_l + pi->resno * pi->step_r + pi->compno * pi->step_c + pi->precno * pi->step_p; if (!pi->include[index]) { @@ -583,10 +583,10 @@ void opj_get_encoding_parameters( const opj_image_t *p_image, q = p_tileno / p_cp->tw; /* find extent of tile */ - *p_tx0 = opj_int_max(p_cp->tx0 + p * p_cp->tdx, p_image->x0); - *p_tx1 = opj_int_min(p_cp->tx0 + (p + 1) * p_cp->tdx, p_image->x1); - *p_ty0 = opj_int_max(p_cp->ty0 + q * p_cp->tdy, p_image->y0); - *p_ty1 = opj_int_min(p_cp->ty0 + (q + 1) * p_cp->tdy, p_image->y1); + *p_tx0 = opj_int_max((OPJ_INT32)(p_cp->tx0 + p * p_cp->tdx), (OPJ_INT32)p_image->x0); + *p_tx1 = opj_int_min((OPJ_INT32)(p_cp->tx0 + (p + 1) * p_cp->tdx), (OPJ_INT32)p_image->x1); + *p_ty0 = opj_int_max((OPJ_INT32)(p_cp->ty0 + q * p_cp->tdy), (OPJ_INT32)p_image->y0); + *p_ty1 = opj_int_min((OPJ_INT32)(p_cp->ty0 + (q + 1) * p_cp->tdy), (OPJ_INT32)p_image->y1); /* max precision is 0 (can only grow) */ *p_max_prec = 0; @@ -606,10 +606,10 @@ void opj_get_encoding_parameters( const opj_image_t *p_image, OPJ_UINT32 l_product; OPJ_INT32 l_tcx0, l_tcy0, l_tcx1, l_tcy1; - l_tcx0 = opj_int_ceildiv(*p_tx0, l_img_comp->dx); - l_tcy0 = opj_int_ceildiv(*p_ty0, l_img_comp->dy); - l_tcx1 = opj_int_ceildiv(*p_tx1, l_img_comp->dx); - l_tcy1 = opj_int_ceildiv(*p_ty1, l_img_comp->dy); + l_tcx0 = opj_int_ceildiv(*p_tx0, (OPJ_INT32)l_img_comp->dx); + l_tcy0 = opj_int_ceildiv(*p_ty0, (OPJ_INT32)l_img_comp->dy); + l_tcx1 = opj_int_ceildiv(*p_tx1, (OPJ_INT32)l_img_comp->dx); + l_tcy1 = opj_int_ceildiv(*p_ty1, (OPJ_INT32)l_img_comp->dy); if (l_tccp->numresolutions > *p_max_res) { *p_max_res = l_tccp->numresolutions; @@ -623,8 +623,8 @@ void opj_get_encoding_parameters( const opj_image_t *p_image, l_pdx = l_tccp->prcw[resno]; l_pdy = l_tccp->prch[resno]; - l_dx = l_img_comp->dx * (1 << (l_pdx + l_tccp->numresolutions - 1 - resno)); - l_dy = l_img_comp->dy * (1 << (l_pdy + l_tccp->numresolutions - 1 - resno)); + l_dx = l_img_comp->dx * (1u << (l_pdx + l_tccp->numresolutions - 1 - resno)); + l_dy = l_img_comp->dy * (1u << (l_pdy + l_tccp->numresolutions - 1 - resno)); /* take the minimum size for dx for each comp and resolution */ *p_dx_min = opj_uint_min(*p_dx_min, l_dx); @@ -633,19 +633,19 @@ void opj_get_encoding_parameters( const opj_image_t *p_image, /* various calculations of extents */ l_level_no = l_tccp->numresolutions - 1 - resno; - l_rx0 = opj_int_ceildivpow2(l_tcx0, l_level_no); - l_ry0 = opj_int_ceildivpow2(l_tcy0, l_level_no); - l_rx1 = opj_int_ceildivpow2(l_tcx1, l_level_no); - l_ry1 = opj_int_ceildivpow2(l_tcy1, l_level_no); + l_rx0 = opj_int_ceildivpow2(l_tcx0, (OPJ_INT32)l_level_no); + l_ry0 = opj_int_ceildivpow2(l_tcy0, (OPJ_INT32)l_level_no); + l_rx1 = opj_int_ceildivpow2(l_tcx1, (OPJ_INT32)l_level_no); + l_ry1 = opj_int_ceildivpow2(l_tcy1, (OPJ_INT32)l_level_no); - l_px0 = opj_int_floordivpow2(l_rx0, l_pdx) << l_pdx; - l_py0 = opj_int_floordivpow2(l_ry0, l_pdy) << l_pdy; - l_px1 = opj_int_ceildivpow2(l_rx1, l_pdx) << l_pdx; + l_px0 = opj_int_floordivpow2(l_rx0, (OPJ_INT32)l_pdx) << l_pdx; + l_py0 = opj_int_floordivpow2(l_ry0, (OPJ_INT32)l_pdy) << l_pdy; + l_px1 = opj_int_ceildivpow2(l_rx1, (OPJ_INT32)l_pdx) << l_pdx; - py1 = opj_int_ceildivpow2(l_ry1, l_pdy) << l_pdy; + py1 = opj_int_ceildivpow2(l_ry1, (OPJ_INT32)l_pdy) << l_pdy; - l_pw = (l_rx0==l_rx1)?0:((l_px1 - l_px0) >> l_pdx); - l_ph = (l_ry0==l_ry1)?0:((py1 - l_py0) >> l_pdy); + l_pw = (l_rx0==l_rx1)?0:(OPJ_UINT32)((l_px1 - l_px0) >> l_pdx); + l_ph = (l_ry0==l_ry1)?0:(OPJ_UINT32)((py1 - l_py0) >> l_pdy); l_product = l_pw * l_ph; @@ -702,10 +702,10 @@ void opj_get_all_encoding_parameters( const opj_image_t *p_image, q = tileno / p_cp->tw; /* here calculation of tx0, tx1, ty0, ty1, maxprec, l_dx and l_dy */ - *p_tx0 = opj_int_max(p_cp->tx0 + p * p_cp->tdx, p_image->x0); - *p_tx1 = opj_int_min(p_cp->tx0 + (p + 1) * p_cp->tdx, p_image->x1); - *p_ty0 = opj_int_max(p_cp->ty0 + q * p_cp->tdy, p_image->y0); - *p_ty1 = opj_int_min(p_cp->ty0 + (q + 1) * p_cp->tdy, p_image->y1); + *p_tx0 = opj_int_max((OPJ_INT32)(p_cp->tx0 + p * p_cp->tdx), (OPJ_INT32)p_image->x0); + *p_tx1 = opj_int_min((OPJ_INT32)(p_cp->tx0 + (p + 1) * p_cp->tdx), (OPJ_INT32)p_image->x1); + *p_ty0 = opj_int_max((OPJ_INT32)(p_cp->ty0 + q * p_cp->tdy), (OPJ_INT32)p_image->y0); + *p_ty1 = opj_int_min((OPJ_INT32)(p_cp->ty0 + (q + 1) * p_cp->tdy), (OPJ_INT32)p_image->y1); /* max precision and resolution is 0 (can only grow)*/ *p_max_prec = 0; @@ -726,10 +726,10 @@ void opj_get_all_encoding_parameters( const opj_image_t *p_image, lResolutionPtr = p_resolutions[compno]; - l_tcx0 = opj_int_ceildiv(*p_tx0, l_img_comp->dx); - l_tcy0 = opj_int_ceildiv(*p_ty0, l_img_comp->dy); - l_tcx1 = opj_int_ceildiv(*p_tx1, l_img_comp->dx); - l_tcy1 = opj_int_ceildiv(*p_ty1, l_img_comp->dy); + l_tcx0 = opj_int_ceildiv(*p_tx0, (OPJ_INT32)l_img_comp->dx); + l_tcy0 = opj_int_ceildiv(*p_ty0, (OPJ_INT32)l_img_comp->dy); + l_tcx1 = opj_int_ceildiv(*p_tx1, (OPJ_INT32)l_img_comp->dx); + l_tcy1 = opj_int_ceildiv(*p_ty1, (OPJ_INT32)l_img_comp->dy); if (l_tccp->numresolutions > *p_max_res) { *p_max_res = l_tccp->numresolutions; @@ -745,23 +745,23 @@ void opj_get_all_encoding_parameters( const opj_image_t *p_image, l_pdy = l_tccp->prch[resno]; *lResolutionPtr++ = l_pdx; *lResolutionPtr++ = l_pdy; - l_dx = l_img_comp->dx * (1 << (l_pdx + l_level_no)); - l_dy = l_img_comp->dy * (1 << (l_pdy + l_level_no)); + l_dx = l_img_comp->dx * (1u << (l_pdx + l_level_no)); + l_dy = l_img_comp->dy * (1u << (l_pdy + l_level_no)); /* take the minimum size for l_dx for each comp and resolution*/ - *p_dx_min = opj_int_min(*p_dx_min, l_dx); - *p_dy_min = opj_int_min(*p_dy_min, l_dy); + *p_dx_min = (OPJ_UINT32)opj_int_min((OPJ_INT32)*p_dx_min, (OPJ_INT32)l_dx); + *p_dy_min = (OPJ_UINT32)opj_int_min((OPJ_INT32)*p_dy_min, (OPJ_INT32)l_dy); /* various calculations of extents*/ - l_rx0 = opj_int_ceildivpow2(l_tcx0, l_level_no); - l_ry0 = opj_int_ceildivpow2(l_tcy0, l_level_no); - l_rx1 = opj_int_ceildivpow2(l_tcx1, l_level_no); - l_ry1 = opj_int_ceildivpow2(l_tcy1, l_level_no); - l_px0 = opj_int_floordivpow2(l_rx0, l_pdx) << l_pdx; - l_py0 = opj_int_floordivpow2(l_ry0, l_pdy) << l_pdy; - l_px1 = opj_int_ceildivpow2(l_rx1, l_pdx) << l_pdx; - py1 = opj_int_ceildivpow2(l_ry1, l_pdy) << l_pdy; - l_pw = (l_rx0==l_rx1)?0:((l_px1 - l_px0) >> l_pdx); - l_ph = (l_ry0==l_ry1)?0:((py1 - l_py0) >> l_pdy); + l_rx0 = opj_int_ceildivpow2(l_tcx0, (OPJ_INT32)l_level_no); + l_ry0 = opj_int_ceildivpow2(l_tcy0, (OPJ_INT32)l_level_no); + l_rx1 = opj_int_ceildivpow2(l_tcx1, (OPJ_INT32)l_level_no); + l_ry1 = opj_int_ceildivpow2(l_tcy1, (OPJ_INT32)l_level_no); + l_px0 = opj_int_floordivpow2(l_rx0, (OPJ_INT32)l_pdx) << l_pdx; + l_py0 = opj_int_floordivpow2(l_ry0, (OPJ_INT32)l_pdy) << l_pdy; + l_px1 = opj_int_ceildivpow2(l_rx1, (OPJ_INT32)l_pdx) << l_pdx; + py1 = opj_int_ceildivpow2(l_ry1, (OPJ_INT32)l_pdy) << l_pdy; + l_pw = (l_rx0==l_rx1)?0:(OPJ_UINT32)((l_px1 - l_px0) >> l_pdx); + l_ph = (l_ry0==l_ry1)?0:(OPJ_UINT32)((py1 - l_py0) >> l_pdy); *lResolutionPtr++ = l_pw; *lResolutionPtr++ = l_ph; l_product = l_pw * l_ph; @@ -890,10 +890,10 @@ void opj_pi_update_encode_poc_and_final ( opj_cp_t *p_cp, l_current_poc->prcS = 0; l_current_poc->prcE = p_max_prec; - l_current_poc->txS = p_tx0; - l_current_poc->txE = p_tx1; - l_current_poc->tyS = p_ty0; - l_current_poc->tyE = p_ty1; + l_current_poc->txS = (OPJ_UINT32)p_tx0; + l_current_poc->txE = (OPJ_UINT32)p_tx1; + l_current_poc->tyS = (OPJ_UINT32)p_ty0; + l_current_poc->tyE = (OPJ_UINT32)p_ty1; l_current_poc->dx = p_dx_min; l_current_poc->dy = p_dy_min; @@ -910,10 +910,10 @@ void opj_pi_update_encode_poc_and_final ( opj_cp_t *p_cp, l_current_poc->layS = (l_current_poc->layE > (l_current_poc-1)->layE) ? l_current_poc->layE : 0; l_current_poc->prcE = p_max_prec; - l_current_poc->txS = p_tx0; - l_current_poc->txE = p_tx1; - l_current_poc->tyS = p_ty0; - l_current_poc->tyE = p_ty1; + l_current_poc->txS = (OPJ_UINT32)p_tx0; + l_current_poc->txE = (OPJ_UINT32)p_tx1; + l_current_poc->tyS = (OPJ_UINT32)p_ty0; + l_current_poc->tyE = (OPJ_UINT32)p_ty1; l_current_poc->dx = p_dx_min; l_current_poc->dy = p_dy_min; ++ l_current_poc; @@ -965,10 +965,10 @@ void opj_pi_update_encode_not_poc ( opj_cp_t *p_cp, l_current_poc->prg = l_tcp->prg; l_current_poc->prcS = 0; l_current_poc->prcE = p_max_prec; - l_current_poc->txS = p_tx0; - l_current_poc->txE = p_tx1; - l_current_poc->tyS = p_ty0; - l_current_poc->tyE = p_ty1; + l_current_poc->txS = (OPJ_UINT32)p_tx0; + l_current_poc->txE = (OPJ_UINT32)p_tx1; + l_current_poc->tyS = (OPJ_UINT32)p_ty0; + l_current_poc->tyE = (OPJ_UINT32)p_ty1; l_current_poc->dx = p_dx_min; l_current_poc->dy = p_dy_min; ++ l_current_poc; @@ -1557,10 +1557,10 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi, pi[pino].poc.layno1 = tcp->layE; pi[pino].poc.precno0 = tcp->prcS; pi[pino].poc.precno1 = tcp->prcE; - pi[pino].poc.tx0 = tcp->txS; - pi[pino].poc.ty0 = tcp->tyS; - pi[pino].poc.tx1 = tcp->txE; - pi[pino].poc.ty1 = tcp->tyE; + pi[pino].poc.tx0 = (OPJ_INT32)tcp->txS; + pi[pino].poc.ty0 = (OPJ_INT32)tcp->tyS; + pi[pino].poc.tx1 = (OPJ_INT32)tcp->txE; + pi[pino].poc.ty1 = (OPJ_INT32)tcp->tyE; }else { for(i=tppos+1;i<4;i++){ switch(prog[i]){ @@ -1584,10 +1584,10 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi, pi[pino].poc.precno1 = tcp->prcE; break; default: - pi[pino].poc.tx0 = tcp->txS; - pi[pino].poc.ty0 = tcp->tyS; - pi[pino].poc.tx1 = tcp->txE; - pi[pino].poc.ty1 = tcp->tyE; + pi[pino].poc.tx0 = (OPJ_INT32)tcp->txS; + pi[pino].poc.ty0 = (OPJ_INT32)tcp->tyS; + pi[pino].poc.tx1 = (OPJ_INT32)tcp->txE; + pi[pino].poc.ty1 = (OPJ_INT32)tcp->tyE; break; } break; @@ -1627,12 +1627,12 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi, default: tcp->tx0_t = tcp->txS; tcp->ty0_t = tcp->tyS; - pi[pino].poc.tx0 = tcp->tx0_t; - pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx - (tcp->tx0_t % tcp->dx); - pi[pino].poc.ty0 = tcp->ty0_t; - pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy); - tcp->tx0_t = pi[pino].poc.tx1; - tcp->ty0_t = pi[pino].poc.ty1; + pi[pino].poc.tx0 = (OPJ_INT32)tcp->tx0_t; + pi[pino].poc.tx1 = (OPJ_INT32)(tcp->tx0_t + tcp->dx - (tcp->tx0_t % tcp->dx)); + pi[pino].poc.ty0 = (OPJ_INT32)tcp->ty0_t; + pi[pino].poc.ty1 = (OPJ_INT32)(tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy)); + tcp->tx0_t = (OPJ_UINT32)pi[pino].poc.tx1; + tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1; break; } break; @@ -1662,10 +1662,10 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi, pi[pino].poc.precno1 = tcp->prc_t; break; default: - pi[pino].poc.tx0 = tcp->tx0_t - tcp->dx - (tcp->tx0_t % tcp->dx); - pi[pino].poc.tx1 = tcp->tx0_t ; - pi[pino].poc.ty0 = tcp->ty0_t - tcp->dy - (tcp->ty0_t % tcp->dy); - pi[pino].poc.ty1 = tcp->ty0_t ; + pi[pino].poc.tx0 = (OPJ_INT32)(tcp->tx0_t - tcp->dx - (tcp->tx0_t % tcp->dx)); + pi[pino].poc.tx1 = (OPJ_INT32)tcp->tx0_t ; + pi[pino].poc.ty0 = (OPJ_INT32)(tcp->ty0_t - tcp->dy - (tcp->ty0_t % tcp->dy)); + pi[pino].poc.ty1 = (OPJ_INT32)tcp->ty0_t ; break; } break; @@ -1752,29 +1752,29 @@ void opj_pi_create_encode( opj_pi_iterator_t *pi, if(tcp->ty0_t >= tcp->tyE){ if(opj_pi_check_next_level(i-1,cp,tileno,pino,prog)){ tcp->ty0_t = tcp->tyS; - pi[pino].poc.ty0 = tcp->ty0_t; - pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy); - tcp->ty0_t = pi[pino].poc.ty1; + pi[pino].poc.ty0 = (OPJ_INT32)tcp->ty0_t; + pi[pino].poc.ty1 = (OPJ_INT32)(tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy)); + tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1; incr_top=1;resetX=1; }else{ incr_top=0;resetX=0; } }else{ - pi[pino].poc.ty0 = tcp->ty0_t; - pi[pino].poc.ty1 = tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy); - tcp->ty0_t = pi[pino].poc.ty1; + pi[pino].poc.ty0 = (OPJ_INT32)tcp->ty0_t; + pi[pino].poc.ty1 = (OPJ_INT32)(tcp->ty0_t + tcp->dy - (tcp->ty0_t % tcp->dy)); + tcp->ty0_t = (OPJ_UINT32)pi[pino].poc.ty1; incr_top=0;resetX=1; } if(resetX==1){ tcp->tx0_t = tcp->txS; - pi[pino].poc.tx0 = tcp->tx0_t; - pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx- (tcp->tx0_t % tcp->dx); - tcp->tx0_t = pi[pino].poc.tx1; + pi[pino].poc.tx0 = (OPJ_INT32)tcp->tx0_t; + pi[pino].poc.tx1 = (OPJ_INT32)(tcp->tx0_t + tcp->dx- (tcp->tx0_t % tcp->dx)); + tcp->tx0_t = (OPJ_UINT32)pi[pino].poc.tx1; } }else{ - pi[pino].poc.tx0 = tcp->tx0_t; - pi[pino].poc.tx1 = tcp->tx0_t + tcp->dx- (tcp->tx0_t % tcp->dx); - tcp->tx0_t = pi[pino].poc.tx1; + pi[pino].poc.tx0 = (OPJ_INT32)tcp->tx0_t; + pi[pino].poc.tx1 = (OPJ_INT32)(tcp->tx0_t + tcp->dx- (tcp->tx0_t % tcp->dx)); + tcp->tx0_t = (OPJ_UINT32)pi[pino].poc.tx1; incr_top=0; } break; From c302979738c3a50b102f76f38109cd0ec5149691 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 11:08:35 +0000 Subject: [PATCH 231/333] [trunk] Remove simple warning about functions not used --- src/bin/mj2/opj_mj2_compress.c | 7 ------- src/bin/mj2/opj_mj2_decompress.c | 7 ------- 2 files changed, 14 deletions(-) diff --git a/src/bin/mj2/opj_mj2_compress.c b/src/bin/mj2/opj_mj2_compress.c index c8f6642b..afe37679 100644 --- a/src/bin/mj2/opj_mj2_compress.c +++ b/src/bin/mj2/opj_mj2_compress.c @@ -61,13 +61,6 @@ static void warning_callback(const char *msg, void *client_data) { FILE *stream = (FILE*)client_data; fprintf(stream, "[WARNING] %s", msg); } -/** -sample debug callback expecting a FILE* client object -*/ -static void info_callback(const char *msg, void *client_data) { - FILE *stream = (FILE*)client_data; - fprintf(stream, "[INFO] %s", msg); -} /* -------------------------------------------------------------------------- */ diff --git a/src/bin/mj2/opj_mj2_decompress.c b/src/bin/mj2/opj_mj2_decompress.c index e9278a50..086918c7 100644 --- a/src/bin/mj2/opj_mj2_decompress.c +++ b/src/bin/mj2/opj_mj2_decompress.c @@ -61,13 +61,6 @@ static void warning_callback(const char *msg, void *client_data) { FILE *stream = (FILE*)client_data; fprintf(stream, "[WARNING] %s", msg); } -/** -sample debug callback expecting a FILE* client object -*/ -static void info_callback(const char *msg, void *client_data) { - FILE *stream = (FILE*)client_data; - fprintf(stream, "[INFO] %s", msg); -} /* -------------------------------------------------------------------------- */ From fc9248ea2bbf946076fb7f292ccbbf4ebbb56fe5 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 11:11:43 +0000 Subject: [PATCH 232/333] [trunk] Remove simple warnings about format --- src/bin/jp2/opj_compress.c | 4 ++-- src/bin/jp2/opj_decompress.c | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index ea941510..799230c1 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -620,7 +620,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param OPJ_UINT32 numlayers = 0, numresolution = 0, matrix_width = 0; char *s = opj_optarg; - sscanf(s, "%d", &numlayers); + sscanf(s, "%ud", &numlayers); s++; if (numlayers > 9) s++; @@ -787,7 +787,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param char *s = opj_optarg; POC = parameters->POC; - while (sscanf(s, "T%d=%d,%d,%d,%d,%d,%4s", &POC[numpocs].tile, + while (sscanf(s, "T%ud=%ud,%ud,%ud,%ud,%ud,%4s", &POC[numpocs].tile, &POC[numpocs].resno0, &POC[numpocs].compno0, &POC[numpocs].layno1, &POC[numpocs].resno1, &POC[numpocs].compno1, POC[numpocs].progorder) == 7) { diff --git a/src/bin/jp2/opj_decompress.c b/src/bin/jp2/opj_decompress.c index dd1a0775..da069aec 100644 --- a/src/bin/jp2/opj_decompress.c +++ b/src/bin/jp2/opj_decompress.c @@ -447,7 +447,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i case 'r': /* reduce option */ { - sscanf(opj_optarg, "%d", ¶meters->cp_reduce); + sscanf(opj_optarg, "%ud", ¶meters->cp_reduce); } break; @@ -456,7 +456,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i case 'l': /* layering option */ { - sscanf(opj_optarg, "%d", ¶meters->cp_layer); + sscanf(opj_optarg, "%ud", ¶meters->cp_layer); } break; @@ -496,7 +496,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i case 't': /* Input tile index */ { - sscanf(opj_optarg, "%d", ¶meters->tile_index); + sscanf(opj_optarg, "%ud", ¶meters->tile_index); parameters->nb_tile_to_decode = 1; } break; From 22d11a9ccb6f4ba2deff425ea56ca68e864ce50e Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 11:17:51 +0000 Subject: [PATCH 233/333] [trunk] Remove mem leak and warning reported by clang --- src/bin/jp2/opj_compress.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index 799230c1..0f1b9580 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -408,9 +408,7 @@ static int get_file_format(char *filename) { } static char * get_file_name(char *name){ - char *fname; - fname= (char*)malloc(OPJ_PATH_LEN*sizeof(char)); - fname= strtok(name,"."); + char *fname = strtok(name,"."); return fname; } From 9d216954762b0177bc7eaef9af651988f7c79aec Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 11:20:59 +0000 Subject: [PATCH 234/333] [trunk] As reported by clang analyzer thoses values were never read --- src/lib/openjp2/dwt.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/lib/openjp2/dwt.c b/src/lib/openjp2/dwt.c index e8e679d8..b36d68dd 100644 --- a/src/lib/openjp2/dwt.c +++ b/src/lib/openjp2/dwt.c @@ -401,9 +401,6 @@ INLINE OPJ_BOOL opj_dwt_encode_procedure(opj_tcd_tilecomp_t * tilec,void (*p_fun l_cur_res = tilec->resolutions + l; l_last_res = l_cur_res - 1; - rw = l_cur_res->x1 - l_cur_res->x0; - rh = l_cur_res->y1 - l_cur_res->y0; - l_data_size = opj_dwt_max_resolution( tilec->resolutions,tilec->numresolutions) * (OPJ_UINT32)sizeof(OPJ_INT32); bj = (OPJ_INT32*)opj_malloc((size_t)l_data_size); if (! bj) { From e238148d4241884157f5b6a0ac72d8f2739f6f3f Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 11:27:34 +0000 Subject: [PATCH 235/333] [trunk] Another round of fixes for sign conversion warnings. Update issue 256 --- src/lib/openjp2/image.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/lib/openjp2/image.c b/src/lib/openjp2/image.c index 1b14f685..24f868d4 100644 --- a/src/lib/openjp2/image.c +++ b/src/lib/openjp2/image.c @@ -106,23 +106,23 @@ void opj_image_comp_header_update(opj_image_t * p_image_header, const struct opj OPJ_INT32 l_comp_x0, l_comp_y0, l_comp_x1, l_comp_y1; opj_image_comp_t* l_img_comp = NULL; - l_x0 = opj_int_max(p_cp->tx0 , p_image_header->x0); - l_y0 = opj_int_max(p_cp->ty0 , p_image_header->y0); - l_x1 = opj_int_min(p_cp->tx0 + p_cp->tw * p_cp->tdx, p_image_header->x1); - l_y1 = opj_int_min(p_cp->ty0 + p_cp->th * p_cp->tdy, p_image_header->y1); + l_x0 = opj_int_max((OPJ_INT32)p_cp->tx0 , (OPJ_INT32)p_image_header->x0); + l_y0 = opj_int_max((OPJ_INT32)p_cp->ty0 , (OPJ_INT32)p_image_header->y0); + l_x1 = opj_int_min((OPJ_INT32)(p_cp->tx0 + p_cp->tw * p_cp->tdx), (OPJ_INT32)p_image_header->x1); + l_y1 = opj_int_min((OPJ_INT32)(p_cp->ty0 + p_cp->th * p_cp->tdy), (OPJ_INT32)p_image_header->y1); l_img_comp = p_image_header->comps; for (i = 0; i < p_image_header->numcomps; ++i) { - l_comp_x0 = opj_int_ceildiv(l_x0, l_img_comp->dx); - l_comp_y0 = opj_int_ceildiv(l_y0, l_img_comp->dy); - l_comp_x1 = opj_int_ceildiv(l_x1, l_img_comp->dx); - l_comp_y1 = opj_int_ceildiv(l_y1, l_img_comp->dy); - l_width = opj_int_ceildivpow2(l_comp_x1 - l_comp_x0, l_img_comp->factor); - l_height = opj_int_ceildivpow2(l_comp_y1 - l_comp_y0, l_img_comp->factor); + l_comp_x0 = opj_int_ceildiv(l_x0, (OPJ_INT32)l_img_comp->dx); + l_comp_y0 = opj_int_ceildiv(l_y0, (OPJ_INT32)l_img_comp->dy); + l_comp_x1 = opj_int_ceildiv(l_x1, (OPJ_INT32)l_img_comp->dx); + l_comp_y1 = opj_int_ceildiv(l_y1, (OPJ_INT32)l_img_comp->dy); + l_width = (OPJ_UINT32)opj_int_ceildivpow2(l_comp_x1 - l_comp_x0, (OPJ_INT32)l_img_comp->factor); + l_height = (OPJ_UINT32)opj_int_ceildivpow2(l_comp_y1 - l_comp_y0, (OPJ_INT32)l_img_comp->factor); l_img_comp->w = l_width; l_img_comp->h = l_height; - l_img_comp->x0 = l_comp_x0/*l_x0*/; - l_img_comp->y0 = l_comp_y0/*l_y0*/; + l_img_comp->x0 = (OPJ_UINT32)l_comp_x0/*l_x0*/; + l_img_comp->y0 = (OPJ_UINT32)l_comp_y0/*l_y0*/; ++l_img_comp; } } From 2a07d3d26b4bdec320c5b99cca07a41e5957d514 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 11:28:34 +0000 Subject: [PATCH 236/333] [trunk] Another round of fixes for sign conversion warnings. Update issue 256 --- src/lib/openjp2/openjpeg.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/openjp2/openjpeg.c b/src/lib/openjp2/openjpeg.c index 05a9938d..0522acb0 100644 --- a/src/lib/openjp2/openjpeg.c +++ b/src/lib/openjp2/openjpeg.c @@ -94,10 +94,10 @@ static OPJ_UINT64 opj_get_data_length_from_file (FILE * p_file) OPJ_OFF_T file_length = 0; OPJ_FSEEK(p_file, 0, SEEK_END); - file_length = (OPJ_UINT64)OPJ_FTELL(p_file); + file_length = (OPJ_OFF_T)OPJ_FTELL(p_file); OPJ_FSEEK(p_file, 0, SEEK_SET); - return file_length; + return (OPJ_UINT64)file_length; } static OPJ_SIZE_T opj_write_from_file (void * p_buffer, OPJ_SIZE_T p_nb_bytes, FILE * p_file) From ee3b02932a0c9502c41a7757d5622243ebff1d37 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 11:43:50 +0000 Subject: [PATCH 237/333] [trunk] Another round of fixes for sign conversion warnings. Update issue 256 --- src/lib/openjp2/t1.c | 36 ++++++++++++++++++------------------ 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/lib/openjp2/t1.c b/src/lib/openjp2/t1.c index 8fde5488..3f7613a5 100644 --- a/src/lib/openjp2/t1.c +++ b/src/lib/openjp2/t1.c @@ -1260,7 +1260,7 @@ OPJ_BOOL opj_t1_decode_cblks( opj_t1_t* t1, ) { OPJ_UINT32 resno, bandno, precno, cblkno; - OPJ_UINT32 tile_w = tilec->x1 - tilec->x0; + OPJ_UINT32 tile_w = (OPJ_UINT32)(tilec->x1 - tilec->x0); for (resno = 0; resno < tilec->minimum_num_resolutions; ++resno) { opj_tcd_resolution_t* res = &tilec->resolutions[resno]; @@ -1283,7 +1283,7 @@ OPJ_BOOL opj_t1_decode_cblks( opj_t1_t* t1, t1, cblk, band->bandno, - tccp->roishift, + (OPJ_UINT32)tccp->roishift, tccp->cblksty)) { return OPJ_FALSE; } @@ -1319,7 +1319,7 @@ OPJ_BOOL opj_t1_decode_cblks( opj_t1_t* t1, /*tiledp=(void*)&tilec->data[(y * tile_w) + x];*/ if (tccp->qmfbid == 1) { - OPJ_INT32* restrict tiledp = &tilec->data[(y * tile_w) + x]; + OPJ_INT32* restrict tiledp = &tilec->data[(OPJ_UINT32)y * tile_w + (OPJ_UINT32)x]; for (j = 0; j < cblk_h; ++j) { for (i = 0; i < cblk_w; ++i) { OPJ_INT32 tmp = datap[(j * cblk_w) + i]; @@ -1327,7 +1327,7 @@ OPJ_BOOL opj_t1_decode_cblks( opj_t1_t* t1, } } } else { /* if (tccp->qmfbid == 0) */ - OPJ_FLOAT32* restrict tiledp = (OPJ_FLOAT32*) &tilec->data[(y * tile_w) + x]; + OPJ_FLOAT32* restrict tiledp = (OPJ_FLOAT32*) &tilec->data[(OPJ_UINT32)y * tile_w + (OPJ_UINT32)x]; for (j = 0; j < cblk_h; ++j) { OPJ_FLOAT32* restrict tiledp2 = tiledp; for (i = 0; i < cblk_w; ++i) { @@ -1370,13 +1370,13 @@ OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1, if(!opj_t1_allocate_buffers( t1, - cblk->x1 - cblk->x0, - cblk->y1 - cblk->y0)) + (OPJ_UINT32)(cblk->x1 - cblk->x0), + (OPJ_UINT32)(cblk->y1 - cblk->y0))) { return OPJ_FALSE; } - bpno = roishift + cblk->numbps - 1; + bpno = (OPJ_INT32)(roishift + cblk->numbps - 1); passtype = 2; opj_mqc_resetstates(mqc); @@ -1405,18 +1405,18 @@ OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1, switch (passtype) { case 0: if (type == T1_TYPE_RAW) { - opj_t1_dec_sigpass_raw(t1, bpno+1, orient, cblksty); + opj_t1_dec_sigpass_raw(t1, bpno+1, (OPJ_INT32)orient, (OPJ_INT32)cblksty); } else { if (cblksty & J2K_CCP_CBLKSTY_VSC) { - opj_t1_dec_sigpass_mqc_vsc(t1, bpno+1, orient); + opj_t1_dec_sigpass_mqc_vsc(t1, bpno+1, (OPJ_INT32)orient); } else { - opj_t1_dec_sigpass_mqc(t1, bpno+1, orient); + opj_t1_dec_sigpass_mqc(t1, bpno+1, (OPJ_INT32)orient); } } break; case 1: if (type == T1_TYPE_RAW) { - opj_t1_dec_refpass_raw(t1, bpno+1, cblksty); + opj_t1_dec_refpass_raw(t1, bpno+1, (OPJ_INT32)cblksty); } else { if (cblksty & J2K_CCP_CBLKSTY_VSC) { opj_t1_dec_refpass_mqc_vsc(t1, bpno+1); @@ -1426,7 +1426,7 @@ OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1, } break; case 2: - opj_t1_dec_clnpass(t1, bpno+1, orient, cblksty); + opj_t1_dec_clnpass(t1, bpno+1, (OPJ_INT32)orient, (OPJ_INT32)cblksty); break; } @@ -1461,7 +1461,7 @@ OPJ_BOOL opj_t1_encode_cblks( opj_t1_t *t1, for (compno = 0; compno < tile->numcomps; ++compno) { opj_tcd_tilecomp_t* tilec = &tile->comps[compno]; opj_tccp_t* tccp = &tcp->tccps[compno]; - OPJ_UINT32 tile_w = tilec->x1 - tilec->x0; + OPJ_UINT32 tile_w = (OPJ_UINT32)(tilec->x1 - tilec->x0); for (resno = 0; resno < tilec->numresolutions; ++resno) { opj_tcd_resolution_t *res = &tilec->resolutions[resno]; @@ -1494,8 +1494,8 @@ OPJ_BOOL opj_t1_encode_cblks( opj_t1_t *t1, if(!opj_t1_allocate_buffers( t1, - cblk->x1 - cblk->x0, - cblk->y1 - cblk->y0)) + (OPJ_UINT32)(cblk->x1 - cblk->x0), + (OPJ_UINT32)(cblk->y1 - cblk->y0))) { return OPJ_FALSE; } @@ -1504,7 +1504,7 @@ OPJ_BOOL opj_t1_encode_cblks( opj_t1_t *t1, cblk_w = t1->w; cblk_h = t1->h; - tiledp=&tilec->data[(y * tile_w) + x]; + tiledp=&tilec->data[(OPJ_UINT32)y * tile_w + (OPJ_UINT32)x]; if (tccp->qmfbid == 1) { for (j = 0; j < cblk_h; ++j) { for (i = 0; i < cblk_w; ++i) { @@ -1577,9 +1577,9 @@ void opj_t1_encode_cblk(opj_t1_t *t1, max = opj_int_max(max, tmp); } - cblk->numbps = max ? (opj_int_floorlog2(max) + 1) - T1_NMSEDEC_FRACBITS : 0; + cblk->numbps = max ? (OPJ_UINT32)((opj_int_floorlog2(max) + 1) - T1_NMSEDEC_FRACBITS) : 0; - bpno = cblk->numbps - 1; + bpno = (OPJ_INT32)(cblk->numbps - 1); passtype = 2; opj_mqc_resetstates(mqc); From 01b4bb5447515739770319fa62684a1b3a9e2881 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 11:57:37 +0000 Subject: [PATCH 238/333] [trunk] Another round of fixes for sign conversion warnings. Update issue 256 --- src/lib/openjp2/t2.c | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c index 480944de..0a2cff15 100644 --- a/src/lib/openjp2/t2.c +++ b/src/lib/openjp2/t2.c @@ -573,7 +573,8 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, cblk = &prc->cblks.enc[cblkno]; cblk->numpasses = 0; - opj_tgt_setvalue(prc->imsbtree, cblkno, band->numbps - cblk->numbps); + assert(band->numbps>=0); + opj_tgt_setvalue(prc->imsbtree, cblkno, (OPJ_INT32)((OPJ_UINT32)band->numbps - cblk->numbps)); } ++band; } @@ -595,7 +596,7 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, opj_tcd_layer_t *layer = &cblk->layers[layno]; if (!cblk->numpasses && layer->numpasses) { - opj_tgt_setvalue(prc->incltree, cblkno, layno); + opj_tgt_setvalue(prc->incltree, cblkno, (OPJ_INT32)layno); } ++cblk; @@ -611,7 +612,7 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, /* cblk inclusion bits */ if (!cblk->numpasses) { - opj_tgt_encode(bio, prc->incltree, cblkno, layno + 1); + opj_tgt_encode(bio, prc->incltree, cblkno, (OPJ_INT32)(layno + 1)); } else { opj_bio_write(bio, layer->numpasses != 0, 1); } @@ -639,14 +640,14 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, len += pass->len; if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) { - increment = opj_int_max(increment, opj_int_floorlog2(len) + 1 - (cblk->numlenbits + opj_int_floorlog2(nump))); + increment = opj_uint_max(increment, opj_uint_floorlog2(len) + 1 - (cblk->numlenbits + opj_uint_floorlog2(nump))); len = 0; nump = 0; } ++pass; } - opj_t2_putcommacode(bio, increment); + opj_t2_putcommacode(bio, (OPJ_INT32)increment); /* computation of the new Length indicator */ cblk->numlenbits += increment; @@ -658,7 +659,7 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, len += pass->len; if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) { - opj_bio_write(bio, len, cblk->numlenbits + opj_int_floorlog2(nump)); + opj_bio_write(bio, len, cblk->numlenbits + (OPJ_UINT32)opj_int_floorlog2((OPJ_INT32)nump)); len = 0; nump = 0; } @@ -935,7 +936,7 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, /* if cblk not yet included before --> inclusion tagtree */ if (!l_cblk->numsegs) { - l_included = opj_tgt_decode(l_bio, l_prc->incltree, cblkno, p_pi->layno + 1); + l_included = opj_tgt_decode(l_bio, l_prc->incltree, cblkno, (OPJ_INT32)(p_pi->layno + 1)); /* else one bit */ } else { @@ -953,11 +954,12 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, if (!l_cblk->numsegs) { OPJ_UINT32 i = 0; - while (!opj_tgt_decode(l_bio, l_prc->imsbtree, cblkno, i)) { + while (!opj_tgt_decode(l_bio, l_prc->imsbtree, cblkno, (OPJ_INT32)i)) { ++i; } - l_cblk->numbps = l_band->numbps + 1 - i; + assert(l_band->numbps >= 0); + l_cblk->numbps = (OPJ_UINT32)l_band->numbps + 1 - i; l_cblk->numlenbits = 3; } @@ -985,13 +987,13 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, } } } - n = l_cblk->numnewpasses; + n = (OPJ_INT32)l_cblk->numnewpasses; do { - l_cblk->segs[l_segno].numnewpasses = opj_int_min(l_cblk->segs[l_segno].maxpasses - l_cblk->segs[l_segno].numpasses, n); + l_cblk->segs[l_segno].numnewpasses = (OPJ_UINT32)opj_int_min((OPJ_INT32)(l_cblk->segs[l_segno].maxpasses - l_cblk->segs[l_segno].numpasses), n); l_cblk->segs[l_segno].newlen = opj_bio_read(l_bio, l_cblk->numlenbits + opj_uint_floorlog2(l_cblk->segs[l_segno].numnewpasses)); - n -= l_cblk->segs[l_segno].numnewpasses; + n -= (OPJ_INT32)l_cblk->segs[l_segno].numnewpasses; if (n > 0) { ++l_segno; From 740924fa61f106fc5126df2d626e0c9091ea8e34 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 11:59:29 +0000 Subject: [PATCH 239/333] [trunk] Another round of fixes for sign conversion warnings. Update issue 256 --- src/bin/jp2/opj_dump.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bin/jp2/opj_dump.c b/src/bin/jp2/opj_dump.c index 19ed2971..b849149f 100644 --- a/src/bin/jp2/opj_dump.c +++ b/src/bin/jp2/opj_dump.c @@ -437,8 +437,8 @@ int main(int argc, char *argv[]) dirptr=(dircnt_t*)malloc(sizeof(dircnt_t)); if(dirptr){ - dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/ - dirptr->filename = (char**) malloc(num_images*sizeof(char*)); + dirptr->filename_buf = (char*)malloc((size_t)num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/ + dirptr->filename = (char**) malloc((size_t)num_images*sizeof(char*)); if(!dirptr->filename_buf){ return EXIT_FAILURE; From 472ce191832f429ca652d04c4b5f80af0b0c4f89 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 12:01:41 +0000 Subject: [PATCH 240/333] [trunk] Another round of fixes for sign conversion warnings. Update issue 256 --- src/bin/jp2/opj_decompress.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/bin/jp2/opj_decompress.c b/src/bin/jp2/opj_decompress.c index da069aec..b19e01a9 100644 --- a/src/bin/jp2/opj_decompress.c +++ b/src/bin/jp2/opj_decompress.c @@ -481,7 +481,7 @@ int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *parameters,i case 'd': /* Input decode ROI */ { int size_optarg = (int)strlen(opj_optarg) + 1; - char *ROI_values = (char*) malloc(size_optarg); + char *ROI_values = (char*) malloc((size_t)size_optarg); ROI_values[0] = '\0'; strncpy(ROI_values, opj_optarg, strlen(opj_optarg)); ROI_values[strlen(opj_optarg)] = '\0'; @@ -639,8 +639,8 @@ int parse_DA_values( char* inArg, unsigned int *DA_x0, unsigned int *DA_y0, unsi return EXIT_FAILURE; } else{ - *DA_x0 = values[0]; *DA_y0 = values[1]; - *DA_x1 = values[2]; *DA_y1 = values[3]; + *DA_x0 = (OPJ_UINT32)values[0]; *DA_y0 = (OPJ_UINT32)values[1]; + *DA_x1 = (OPJ_UINT32)values[2]; *DA_y1 = (OPJ_UINT32)values[3]; return EXIT_SUCCESS; } } @@ -710,8 +710,8 @@ int main(int argc, char **argv) dirptr=(dircnt_t*)malloc(sizeof(dircnt_t)); if(dirptr){ - dirptr->filename_buf = (char*)malloc(num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/ - dirptr->filename = (char**) malloc(num_images*sizeof(char*)); + dirptr->filename_buf = (char*)malloc((size_t)num_images*OPJ_PATH_LEN*sizeof(char)); /* Stores at max 10 image file names*/ + dirptr->filename = (char**) malloc((size_t)num_images*sizeof(char*)); if(!dirptr->filename_buf){ return EXIT_FAILURE; @@ -805,8 +805,8 @@ int main(int argc, char **argv) if (!parameters.nb_tile_to_decode) { /* Optional if you want decode the entire image */ - if (!opj_set_decode_area(l_codec, image, parameters.DA_x0, - parameters.DA_y0, parameters.DA_x1, parameters.DA_y1)){ + if (!opj_set_decode_area(l_codec, image, (OPJ_INT32)parameters.DA_x0, + (OPJ_INT32)parameters.DA_y0, (OPJ_INT32)parameters.DA_x1, (OPJ_INT32)parameters.DA_y1)){ fprintf(stderr, "ERROR -> opj_decompress: failed to set the decoded area\n"); opj_stream_destroy_v3(l_stream); opj_destroy_codec(l_codec); From 956b1a7697ac1210a0d6df934399691ea8055583 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 12:06:00 +0000 Subject: [PATCH 241/333] [trunk] Another round of fixes for sign conversion warnings. Update issue 256 --- src/bin/jp2/opj_compress.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index 0f1b9580..e42e88df 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -623,8 +623,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param if (numlayers > 9) s++; - parameters->tcp_numlayers = numlayers; - numresolution = parameters->numresolution; + parameters->tcp_numlayers = (int)numlayers; + numresolution = (OPJ_UINT32)parameters->numresolution; matrix_width = numresolution * 3; parameters->cp_matrice = (int *) malloc(numlayers * matrix_width * sizeof(int)); s = s + 2; @@ -799,7 +799,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param } s++; } - parameters->numpocs = numpocs; + parameters->numpocs = (OPJ_UINT32)numpocs; } break; @@ -935,7 +935,8 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param float *lCurrentDoublePtr; float *lSpace; int *l_int_ptr; - int lNbComp = 0, lTotalComp, lMctComp, i; long int lStrLen, lStrFread; + int lNbComp = 0, lTotalComp, lMctComp, i; + size_t lStrLen, lStrFread; /* Open file */ FILE * lFile = fopen(lFilename,"r"); @@ -945,7 +946,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param /* Set size of file and read its content*/ fseek(lFile,0,SEEK_END); - lStrLen = ftell(lFile); + lStrLen = (size_t)ftell(lFile); fseek(lFile,0,SEEK_SET); lMatrix = (char *) malloc(lStrLen + 1); lStrFread = fread(lMatrix, 1, lStrLen, lFile); @@ -969,7 +970,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param lNbComp = (int) (sqrt(4*lNbComp + 1)/2. - 0.5); lMctComp = lNbComp * lNbComp; lTotalComp = lMctComp + lNbComp; - lSpace = (float *) malloc(lTotalComp * sizeof(float)); + lSpace = (float *) malloc((size_t)lTotalComp * sizeof(float)); lCurrentDoublePtr = lSpace; for (i=0;i Date: Fri, 7 Mar 2014 13:14:26 +0000 Subject: [PATCH 242/333] [trunk] Revert r2623 for now --- src/lib/openjp2/t2.c | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c index 0a2cff15..480944de 100644 --- a/src/lib/openjp2/t2.c +++ b/src/lib/openjp2/t2.c @@ -573,8 +573,7 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, cblk = &prc->cblks.enc[cblkno]; cblk->numpasses = 0; - assert(band->numbps>=0); - opj_tgt_setvalue(prc->imsbtree, cblkno, (OPJ_INT32)((OPJ_UINT32)band->numbps - cblk->numbps)); + opj_tgt_setvalue(prc->imsbtree, cblkno, band->numbps - cblk->numbps); } ++band; } @@ -596,7 +595,7 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, opj_tcd_layer_t *layer = &cblk->layers[layno]; if (!cblk->numpasses && layer->numpasses) { - opj_tgt_setvalue(prc->incltree, cblkno, (OPJ_INT32)layno); + opj_tgt_setvalue(prc->incltree, cblkno, layno); } ++cblk; @@ -612,7 +611,7 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, /* cblk inclusion bits */ if (!cblk->numpasses) { - opj_tgt_encode(bio, prc->incltree, cblkno, (OPJ_INT32)(layno + 1)); + opj_tgt_encode(bio, prc->incltree, cblkno, layno + 1); } else { opj_bio_write(bio, layer->numpasses != 0, 1); } @@ -640,14 +639,14 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, len += pass->len; if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) { - increment = opj_uint_max(increment, opj_uint_floorlog2(len) + 1 - (cblk->numlenbits + opj_uint_floorlog2(nump))); + increment = opj_int_max(increment, opj_int_floorlog2(len) + 1 - (cblk->numlenbits + opj_int_floorlog2(nump))); len = 0; nump = 0; } ++pass; } - opj_t2_putcommacode(bio, (OPJ_INT32)increment); + opj_t2_putcommacode(bio, increment); /* computation of the new Length indicator */ cblk->numlenbits += increment; @@ -659,7 +658,7 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, len += pass->len; if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) { - opj_bio_write(bio, len, cblk->numlenbits + (OPJ_UINT32)opj_int_floorlog2((OPJ_INT32)nump)); + opj_bio_write(bio, len, cblk->numlenbits + opj_int_floorlog2(nump)); len = 0; nump = 0; } @@ -936,7 +935,7 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, /* if cblk not yet included before --> inclusion tagtree */ if (!l_cblk->numsegs) { - l_included = opj_tgt_decode(l_bio, l_prc->incltree, cblkno, (OPJ_INT32)(p_pi->layno + 1)); + l_included = opj_tgt_decode(l_bio, l_prc->incltree, cblkno, p_pi->layno + 1); /* else one bit */ } else { @@ -954,12 +953,11 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, if (!l_cblk->numsegs) { OPJ_UINT32 i = 0; - while (!opj_tgt_decode(l_bio, l_prc->imsbtree, cblkno, (OPJ_INT32)i)) { + while (!opj_tgt_decode(l_bio, l_prc->imsbtree, cblkno, i)) { ++i; } - assert(l_band->numbps >= 0); - l_cblk->numbps = (OPJ_UINT32)l_band->numbps + 1 - i; + l_cblk->numbps = l_band->numbps + 1 - i; l_cblk->numlenbits = 3; } @@ -987,13 +985,13 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, } } } - n = (OPJ_INT32)l_cblk->numnewpasses; + n = l_cblk->numnewpasses; do { - l_cblk->segs[l_segno].numnewpasses = (OPJ_UINT32)opj_int_min((OPJ_INT32)(l_cblk->segs[l_segno].maxpasses - l_cblk->segs[l_segno].numpasses), n); + l_cblk->segs[l_segno].numnewpasses = opj_int_min(l_cblk->segs[l_segno].maxpasses - l_cblk->segs[l_segno].numpasses, n); l_cblk->segs[l_segno].newlen = opj_bio_read(l_bio, l_cblk->numlenbits + opj_uint_floorlog2(l_cblk->segs[l_segno].numnewpasses)); - n -= (OPJ_INT32)l_cblk->segs[l_segno].numnewpasses; + n -= l_cblk->segs[l_segno].numnewpasses; if (n > 0) { ++l_segno; From 33c472d7340c69a53f461e52678833496a9e31ce Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 13:29:35 +0000 Subject: [PATCH 243/333] [trunk] Redo r2623, and remove guilty section Update issue 256 --- src/lib/openjp2/t2.c | 24 +++++++++++++----------- 1 file changed, 13 insertions(+), 11 deletions(-) diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c index 480944de..a819b832 100644 --- a/src/lib/openjp2/t2.c +++ b/src/lib/openjp2/t2.c @@ -573,7 +573,8 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, cblk = &prc->cblks.enc[cblkno]; cblk->numpasses = 0; - opj_tgt_setvalue(prc->imsbtree, cblkno, band->numbps - cblk->numbps); + assert(band->numbps>=0); + opj_tgt_setvalue(prc->imsbtree, cblkno, (OPJ_INT32)((OPJ_UINT32)band->numbps - cblk->numbps)); } ++band; } @@ -595,7 +596,7 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, opj_tcd_layer_t *layer = &cblk->layers[layno]; if (!cblk->numpasses && layer->numpasses) { - opj_tgt_setvalue(prc->incltree, cblkno, layno); + opj_tgt_setvalue(prc->incltree, cblkno, (OPJ_INT32)layno); } ++cblk; @@ -611,7 +612,7 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, /* cblk inclusion bits */ if (!cblk->numpasses) { - opj_tgt_encode(bio, prc->incltree, cblkno, layno + 1); + opj_tgt_encode(bio, prc->incltree, cblkno, (OPJ_INT32)(layno + 1)); } else { opj_bio_write(bio, layer->numpasses != 0, 1); } @@ -646,7 +647,7 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, ++pass; } - opj_t2_putcommacode(bio, increment); + opj_t2_putcommacode(bio, (OPJ_INT32)increment); /* computation of the new Length indicator */ cblk->numlenbits += increment; @@ -658,7 +659,7 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, len += pass->len; if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) { - opj_bio_write(bio, len, cblk->numlenbits + opj_int_floorlog2(nump)); + opj_bio_write(bio, len, cblk->numlenbits + (OPJ_UINT32)opj_int_floorlog2((OPJ_INT32)nump)); len = 0; nump = 0; } @@ -935,7 +936,7 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, /* if cblk not yet included before --> inclusion tagtree */ if (!l_cblk->numsegs) { - l_included = opj_tgt_decode(l_bio, l_prc->incltree, cblkno, p_pi->layno + 1); + l_included = opj_tgt_decode(l_bio, l_prc->incltree, cblkno, (OPJ_INT32)(p_pi->layno + 1)); /* else one bit */ } else { @@ -953,11 +954,12 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, if (!l_cblk->numsegs) { OPJ_UINT32 i = 0; - while (!opj_tgt_decode(l_bio, l_prc->imsbtree, cblkno, i)) { + while (!opj_tgt_decode(l_bio, l_prc->imsbtree, cblkno, (OPJ_INT32)i)) { ++i; } - l_cblk->numbps = l_band->numbps + 1 - i; + assert(l_band->numbps >= 0); + l_cblk->numbps = (OPJ_UINT32)l_band->numbps + 1 - i; l_cblk->numlenbits = 3; } @@ -985,13 +987,13 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, } } } - n = l_cblk->numnewpasses; + n = (OPJ_INT32)l_cblk->numnewpasses; do { - l_cblk->segs[l_segno].numnewpasses = opj_int_min(l_cblk->segs[l_segno].maxpasses - l_cblk->segs[l_segno].numpasses, n); + l_cblk->segs[l_segno].numnewpasses = (OPJ_UINT32)opj_int_min((OPJ_INT32)(l_cblk->segs[l_segno].maxpasses - l_cblk->segs[l_segno].numpasses), n); l_cblk->segs[l_segno].newlen = opj_bio_read(l_bio, l_cblk->numlenbits + opj_uint_floorlog2(l_cblk->segs[l_segno].numnewpasses)); - n -= l_cblk->segs[l_segno].numnewpasses; + n -= (OPJ_INT32)l_cblk->segs[l_segno].numnewpasses; if (n > 0) { ++l_segno; From f9a0f869e35c3cc579fcdc38e81fb9fce7ffc3c6 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 13:31:25 +0000 Subject: [PATCH 244/333] [trunk] Another round of fixes for sign conversion warnings. Update issue 256 --- src/lib/openjp2/tpix_manager.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/lib/openjp2/tpix_manager.c b/src/lib/openjp2/tpix_manager.c index 429f5089..5e440e1e 100644 --- a/src/lib/openjp2/tpix_manager.c +++ b/src/lib/openjp2/tpix_manager.c @@ -80,7 +80,7 @@ int opj_write_tpix( int coff, opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_seek(cio, lenp+len,p_manager); - return len; + return (int)len; } int opj_write_tpixfaix( int coff, @@ -92,15 +92,15 @@ int opj_write_tpixfaix( int coff, { OPJ_UINT32 len; OPJ_OFF_T lenp; - int i, j; - int Aux; - int num_max_tile_parts; - int size_of_coding; /* 4 or 8 */ + OPJ_UINT32 i, j; + OPJ_UINT32 Aux; + OPJ_UINT32 num_max_tile_parts; + OPJ_UINT32 size_of_coding; /* 4 or 8 */ opj_tp_info_t tp; OPJ_BYTE l_data_header [8]; - int version; + OPJ_UINT32 version; - num_max_tile_parts = get_num_max_tile_parts( cstr_info); + num_max_tile_parts = (OPJ_UINT32)get_num_max_tile_parts( cstr_info); if( j2klen > pow( 2, 32)){ size_of_coding = 8; @@ -120,24 +120,24 @@ int opj_write_tpixfaix( int coff, opj_write_bytes(l_data_header,num_max_tile_parts,size_of_coding); /* NMAX */ opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager); - opj_write_bytes(l_data_header,cstr_info.tw*cstr_info.th,size_of_coding); /* M */ + opj_write_bytes(l_data_header,(OPJ_UINT32)(cstr_info.tw*cstr_info.th),size_of_coding); /* M */ opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager); - for (i = 0; i < cstr_info.tw*cstr_info.th; i++) + for (i = 0; i < (OPJ_UINT32)(cstr_info.tw*cstr_info.th); i++) { - for (j = 0; j < cstr_info.tile[i].num_tps; j++) + for (j = 0; j < (OPJ_UINT32)cstr_info.tile[i].num_tps; j++) { tp = cstr_info.tile[i].tp[j]; - opj_write_bytes(l_data_header,tp.tp_start_pos-coff,size_of_coding); /* start position */ + opj_write_bytes(l_data_header,(OPJ_UINT32)(tp.tp_start_pos-coff),size_of_coding); /* start position */ opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager); - opj_write_bytes(l_data_header,tp.tp_end_pos-tp.tp_start_pos+1,size_of_coding); /* length */ + opj_write_bytes(l_data_header,(OPJ_UINT32)(tp.tp_end_pos-tp.tp_start_pos+1),size_of_coding); /* length */ opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager); if (version & 0x02) { if( cstr_info.tile[i].num_tps == 1 && cstr_info.numdecompos[compno] > 1) - Aux = cstr_info.numdecompos[compno] + 1; + Aux = (OPJ_UINT32)(cstr_info.numdecompos[compno] + 1); else Aux = j + 1; @@ -171,7 +171,7 @@ int opj_write_tpixfaix( int coff, opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_seek(cio, lenp+len,p_manager); - return len; + return (int)len; } int get_num_max_tile_parts( opj_codestream_info_t cstr_info) From 71d244a5b64b817dd4a5486bd2c5773f5ec55b2e Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 13:33:47 +0000 Subject: [PATCH 245/333] [trunk] Another round of fixes for sign conversion warnings. Update issue 256 --- src/lib/openjp2/thix_manager.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib/openjp2/thix_manager.c b/src/lib/openjp2/thix_manager.c index 229676ef..e3ebf110 100644 --- a/src/lib/openjp2/thix_manager.c +++ b/src/lib/openjp2/thix_manager.c @@ -48,7 +48,7 @@ int opj_write_thix( int coff, opj_codestream_info_t cstr_info, opj_stream_privat OPJ_OFF_T lenp; lenp = 0; - box = (opj_jp2_box_t *)opj_calloc( cstr_info.tw*cstr_info.th, sizeof(opj_jp2_box_t)); + box = (opj_jp2_box_t *)opj_calloc( (size_t)(cstr_info.tw*cstr_info.th), sizeof(opj_jp2_box_t)); for ( i = 0; i < 2 ; i++ ){ if (i) @@ -62,7 +62,7 @@ int opj_write_thix( int coff, opj_codestream_info_t cstr_info, opj_stream_privat opj_write_manf( i, cstr_info.tw*cstr_info.th, box, cio, p_manager); for (tileno = 0; tileno < cstr_info.tw*cstr_info.th; tileno++){ - box[tileno].length = opj_write_tilemhix( coff, cstr_info, tileno, cio,p_manager); + box[tileno].length = (OPJ_UINT32)opj_write_tilemhix( coff, cstr_info, tileno, cio,p_manager); box[tileno].type = JPIP_MHIX; } @@ -76,7 +76,7 @@ int opj_write_thix( int coff, opj_codestream_info_t cstr_info, opj_stream_privat opj_free(box); - return len; + return (int)len; } /* @@ -107,7 +107,7 @@ int opj_write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, o tile = cstr_info.tile[tileno]; tp = tile.tp[0]; - opj_write_bytes(l_data_header,tp.tp_end_header-tp.tp_start_pos+1, 8); /* TLEN */ + opj_write_bytes(l_data_header,(OPJ_UINT32)(tp.tp_end_header-tp.tp_start_pos+1), 8); /* TLEN */ opj_stream_write_data(cio,l_data_header,8,p_manager); marker = cstr_info.tile[tileno].marker; @@ -118,7 +118,7 @@ int opj_write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, o opj_stream_write_data(cio,l_data_header,4,p_manager); opj_write_bytes( l_data_header, (OPJ_UINT32)(marker[i].pos-coff), 8); opj_stream_write_data(cio,l_data_header,8,p_manager); - opj_write_bytes( l_data_header, marker[i].len, 2); + opj_write_bytes( l_data_header, (OPJ_UINT32)marker[i].len, 2); opj_stream_write_data(cio,l_data_header,2,p_manager); } @@ -130,5 +130,5 @@ int opj_write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, o opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_seek(cio, lenp+len,p_manager); - return len; + return (int)len; } From 4f84d1693a01f3699b0e1cce5fb8b591440f3ddd Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 13:37:45 +0000 Subject: [PATCH 246/333] [trunk] Another round of fixes for sign conversion warnings. Update issue 256 --- src/lib/openjp2/ppix_manager.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/lib/openjp2/ppix_manager.c b/src/lib/openjp2/ppix_manager.c index 5428df61..dff49530 100644 --- a/src/lib/openjp2/ppix_manager.c +++ b/src/lib/openjp2/ppix_manager.c @@ -60,7 +60,7 @@ int opj_write_ppix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, /* printf("cstr_info.packno %d\n", cstr_info.packno); //NMAX? */ lenp = -1; - box = (opj_jp2_box_t *)opj_calloc( cstr_info.numcomps, sizeof(opj_jp2_box_t)); + box = (opj_jp2_box_t *)opj_calloc( (size_t)cstr_info.numcomps, sizeof(opj_jp2_box_t)); for (i=0;i<2;i++){ if (i) @@ -75,7 +75,7 @@ int opj_write_ppix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, opj_write_manf( i, cstr_info.numcomps, box, cio, p_manager); for (compno=0; compno Date: Fri, 7 Mar 2014 13:40:54 +0000 Subject: [PATCH 247/333] [trunk] Another round of fixes for sign conversion warnings. Update issue 256 --- src/lib/openjp2/phix_manager.c | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/src/lib/openjp2/phix_manager.c b/src/lib/openjp2/phix_manager.c index b4d5a40d..8346e69d 100644 --- a/src/lib/openjp2/phix_manager.c +++ b/src/lib/openjp2/phix_manager.c @@ -52,11 +52,11 @@ int opj_write_phix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, opj_event_mgr_t * p_manager ) { OPJ_BYTE l_data_header [8]; - int len, compno, i; + OPJ_UINT32 len, compno, i; opj_jp2_box_t *box; OPJ_OFF_T lenp = 0; - box = (opj_jp2_box_t *)opj_calloc( cstr_info.numcomps, sizeof(opj_jp2_box_t)); + box = (opj_jp2_box_t *)opj_calloc( (size_t)cstr_info.numcomps, sizeof(opj_jp2_box_t)); for( i=0;i<2;i++){ if (i) @@ -67,10 +67,10 @@ int opj_write_phix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, opj_write_bytes(l_data_header,JPIP_PHIX,4); /* PHIX */ opj_stream_write_data(cio,l_data_header,4,p_manager); - opj_write_manf( i, cstr_info.numcomps, box, cio, p_manager ); + opj_write_manf( (int)i, cstr_info.numcomps, box, cio, p_manager ); - for( compno=0; compno Date: Fri, 7 Mar 2014 13:43:15 +0000 Subject: [PATCH 248/333] [trunk] Another round of fixes for sign conversion warnings. Update issue 256 --- src/lib/openjp2/cidx_manager.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/lib/openjp2/cidx_manager.c b/src/lib/openjp2/cidx_manager.c index b0e6d9c3..8324717f 100644 --- a/src/lib/openjp2/cidx_manager.c +++ b/src/lib/openjp2/cidx_manager.c @@ -79,25 +79,25 @@ int opj_write_cidx( int offset, opj_stream_private_t *cio, opj_codestream_info_t opj_write_manf( i, num_box, box, cio,p_manager); num_box = 0; - box[num_box].length = opj_write_mainmhix( offset, cstr_info, cio,p_manager); + box[num_box].length = (OPJ_UINT32)opj_write_mainmhix( offset, cstr_info, cio,p_manager); box[num_box].type = JPIP_MHIX; num_box++; - box[num_box].length = opj_write_tpix( offset, cstr_info, j2klen, cio,p_manager); + box[num_box].length = (OPJ_UINT32)opj_write_tpix( offset, cstr_info, j2klen, cio,p_manager); box[num_box].type = JPIP_TPIX; num_box++; - box[num_box].length = opj_write_thix( offset, cstr_info, cio, p_manager); + box[num_box].length = (OPJ_UINT32)opj_write_thix( offset, cstr_info, cio, p_manager); box[num_box].type = JPIP_THIX; num_box++; EPHused = opj_check_EPHuse( offset, cstr_info.marker, cstr_info.marknum, cio,p_manager); - box[num_box].length = opj_write_ppix( offset, cstr_info, EPHused, j2klen, cio,p_manager); + box[num_box].length = (OPJ_UINT32)opj_write_ppix( offset, cstr_info, EPHused, j2klen, cio,p_manager); box[num_box].type = JPIP_PPIX; num_box++; - box[num_box].length = opj_write_phix( offset, cstr_info, EPHused, j2klen, cio,p_manager); + box[num_box].length = (OPJ_UINT32)opj_write_phix( offset, cstr_info, EPHused, j2klen, cio,p_manager); box[num_box].type = JPIP_PHIX; num_box++; @@ -110,7 +110,7 @@ int opj_write_cidx( int offset, opj_stream_private_t *cio, opj_codestream_info_t opj_free( box); - return len; + return (int)len; } @@ -128,8 +128,8 @@ void opj_write_cptr(int coff, int clen, opj_stream_private_t *cio, opj_write_bytes( l_data_header, JPIP_CPTR, 4); /* T */ opj_write_bytes( l_data_header+4, 0, 2); /* DR A PRECISER !! */ opj_write_bytes( l_data_header+6, 0, 2); /* CONT */ - opj_write_bytes( l_data_header+8, coff, 8); /* COFF A PRECISER !! */ - opj_write_bytes( l_data_header+16, clen, 8); /* CLEN */ + opj_write_bytes( l_data_header+8, (OPJ_UINT32)coff, 8); /* COFF A PRECISER !! */ + opj_write_bytes( l_data_header+16, (OPJ_UINT32)clen, 8); /* CLEN */ opj_stream_write_data(cio,l_data_header,3*8,p_manager); len = (OPJ_UINT32) (opj_stream_tell(cio) - lenp); @@ -179,7 +179,7 @@ int opj_write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_stream_pr opj_event_mgr_t * p_manager ) { OPJ_BYTE l_data_header [8]; - int i; + OPJ_UINT32 i; OPJ_UINT32 len; OPJ_OFF_T lenp; @@ -188,16 +188,16 @@ int opj_write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_stream_pr opj_write_bytes(l_data_header,JPIP_MHIX,4); /* MHIX */ opj_stream_write_data(cio,l_data_header,4,p_manager); - opj_write_bytes(l_data_header, cstr_info.main_head_end-cstr_info.main_head_start+1, 8); /* TLEN */ + opj_write_bytes(l_data_header, (OPJ_UINT32)(cstr_info.main_head_end-cstr_info.main_head_start+1), 8); /* TLEN */ opj_stream_write_data(cio,l_data_header,8,p_manager); - for(i = 1; i < cstr_info.marknum; i++){ /* Marker restricted to 1 apparition, skip SOC marker */ + for(i = 1; i < (OPJ_UINT32)cstr_info.marknum; i++){ /* Marker restricted to 1 apparition, skip SOC marker */ opj_write_bytes( l_data_header, cstr_info.marker[i].type, 2); opj_write_bytes( l_data_header+2, 0, 2); opj_stream_write_data(cio,l_data_header,4,p_manager); opj_write_bytes( l_data_header,(OPJ_UINT32) (cstr_info.marker[i].pos-coff), 8); opj_stream_write_data(cio,l_data_header,8,p_manager); - opj_write_bytes( l_data_header, cstr_info.marker[i].len, 2); + opj_write_bytes( l_data_header, (OPJ_UINT32)cstr_info.marker[i].len, 2); opj_stream_write_data(cio,l_data_header,2,p_manager); } @@ -207,7 +207,7 @@ int opj_write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_stream_pr opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_seek(cio, lenp+len,p_manager); - return len; + return (int)len; } OPJ_BOOL opj_check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_stream_private_t *cio, From 581d2ba8b4c0411af5193966cdc4d9cc011f0070 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 13:50:58 +0000 Subject: [PATCH 249/333] [trunk] Rework r2597, make sure test suite is passing now. Update issue 256 --- src/lib/openjp2/t2.c | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c index a819b832..480944de 100644 --- a/src/lib/openjp2/t2.c +++ b/src/lib/openjp2/t2.c @@ -573,8 +573,7 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, cblk = &prc->cblks.enc[cblkno]; cblk->numpasses = 0; - assert(band->numbps>=0); - opj_tgt_setvalue(prc->imsbtree, cblkno, (OPJ_INT32)((OPJ_UINT32)band->numbps - cblk->numbps)); + opj_tgt_setvalue(prc->imsbtree, cblkno, band->numbps - cblk->numbps); } ++band; } @@ -596,7 +595,7 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, opj_tcd_layer_t *layer = &cblk->layers[layno]; if (!cblk->numpasses && layer->numpasses) { - opj_tgt_setvalue(prc->incltree, cblkno, (OPJ_INT32)layno); + opj_tgt_setvalue(prc->incltree, cblkno, layno); } ++cblk; @@ -612,7 +611,7 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, /* cblk inclusion bits */ if (!cblk->numpasses) { - opj_tgt_encode(bio, prc->incltree, cblkno, (OPJ_INT32)(layno + 1)); + opj_tgt_encode(bio, prc->incltree, cblkno, layno + 1); } else { opj_bio_write(bio, layer->numpasses != 0, 1); } @@ -647,7 +646,7 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, ++pass; } - opj_t2_putcommacode(bio, (OPJ_INT32)increment); + opj_t2_putcommacode(bio, increment); /* computation of the new Length indicator */ cblk->numlenbits += increment; @@ -659,7 +658,7 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, len += pass->len; if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) { - opj_bio_write(bio, len, cblk->numlenbits + (OPJ_UINT32)opj_int_floorlog2((OPJ_INT32)nump)); + opj_bio_write(bio, len, cblk->numlenbits + opj_int_floorlog2(nump)); len = 0; nump = 0; } @@ -936,7 +935,7 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, /* if cblk not yet included before --> inclusion tagtree */ if (!l_cblk->numsegs) { - l_included = opj_tgt_decode(l_bio, l_prc->incltree, cblkno, (OPJ_INT32)(p_pi->layno + 1)); + l_included = opj_tgt_decode(l_bio, l_prc->incltree, cblkno, p_pi->layno + 1); /* else one bit */ } else { @@ -954,12 +953,11 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, if (!l_cblk->numsegs) { OPJ_UINT32 i = 0; - while (!opj_tgt_decode(l_bio, l_prc->imsbtree, cblkno, (OPJ_INT32)i)) { + while (!opj_tgt_decode(l_bio, l_prc->imsbtree, cblkno, i)) { ++i; } - assert(l_band->numbps >= 0); - l_cblk->numbps = (OPJ_UINT32)l_band->numbps + 1 - i; + l_cblk->numbps = l_band->numbps + 1 - i; l_cblk->numlenbits = 3; } @@ -987,13 +985,13 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, } } } - n = (OPJ_INT32)l_cblk->numnewpasses; + n = l_cblk->numnewpasses; do { - l_cblk->segs[l_segno].numnewpasses = (OPJ_UINT32)opj_int_min((OPJ_INT32)(l_cblk->segs[l_segno].maxpasses - l_cblk->segs[l_segno].numpasses), n); + l_cblk->segs[l_segno].numnewpasses = opj_int_min(l_cblk->segs[l_segno].maxpasses - l_cblk->segs[l_segno].numpasses, n); l_cblk->segs[l_segno].newlen = opj_bio_read(l_bio, l_cblk->numlenbits + opj_uint_floorlog2(l_cblk->segs[l_segno].numnewpasses)); - n -= (OPJ_INT32)l_cblk->segs[l_segno].numnewpasses; + n -= l_cblk->segs[l_segno].numnewpasses; if (n > 0) { ++l_segno; From cc1354ebfa057b55d42fc6b50ad580877abf48a7 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 14:00:47 +0000 Subject: [PATCH 250/333] [trunk] Another round of fixes for sign conversion warnings. Update issue 256 --- src/lib/openjp2/tcd.c | 44 +++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 22 deletions(-) diff --git a/src/lib/openjp2/tcd.c b/src/lib/openjp2/tcd.c index e0752724..a58cf47e 100644 --- a/src/lib/openjp2/tcd.c +++ b/src/lib/openjp2/tcd.c @@ -320,7 +320,7 @@ void opj_tcd_makelayer_fixed(opj_tcd_t *tcd, OPJ_UINT32 layno, OPJ_UINT32 final) opj_tcd_cblk_enc_t *cblk = &prc->cblks.enc[cblkno]; opj_tcd_layer_t *layer = &cblk->layers[layno]; OPJ_UINT32 n; - OPJ_INT32 imsb = tcd->image->comps[compno].prec - cblk->numbps; /* number of bit-plan equal to zero */ + OPJ_INT32 imsb = (OPJ_INT32)(tcd->image->comps[compno].prec - cblk->numbps); /* number of bit-plan equal to zero */ /* Correction of the matrix of coefficient to include the IMSB information */ if (layno == 0) { @@ -421,10 +421,10 @@ OPJ_BOOL opj_tcd_rateallocate( opj_tcd_t *tcd, OPJ_FLOAT64 dd, rdslope; if (passno == 0) { - dr = pass->rate; + dr = (OPJ_INT32)pass->rate; dd = pass->distortiondec; } else { - dr = pass->rate - cblk->passes[passno - 1].rate; + dr = (OPJ_INT32)(pass->rate - cblk->passes[passno - 1].rate); dd = pass->distortiondec - cblk->passes[passno - 1].distortiondec; } @@ -1090,7 +1090,7 @@ OPJ_UINT32 opj_tcd_get_decoded_tile_size ( opj_tcd_t *p_tcd ) } l_res = l_tile_comp->resolutions + l_tile_comp->minimum_num_resolutions - 1; - l_data_size += l_size_comp * (l_res->x1 - l_res->x0) * (l_res->y1 - l_res->y0); + l_data_size += l_size_comp * (OPJ_UINT32)((l_res->x1 - l_res->x0) * (l_res->y1 - l_res->y0)); ++l_img_comp; ++l_tile_comp; } @@ -1121,14 +1121,14 @@ OPJ_BOOL opj_tcd_encode_tile( opj_tcd_t *p_tcd, for (i = 0; i < l_tilec_idx->numresolutions; i++) { opj_tcd_resolution_t *l_res_idx = &l_tilec_idx->resolutions[i]; - p_cstr_info->tile[p_tile_no].pw[i] = l_res_idx->pw; - p_cstr_info->tile[p_tile_no].ph[i] = l_res_idx->ph; + p_cstr_info->tile[p_tile_no].pw[i] = (int)l_res_idx->pw; + p_cstr_info->tile[p_tile_no].ph[i] = (int)l_res_idx->ph; l_num_packs += l_res_idx->pw * l_res_idx->ph; - p_cstr_info->tile[p_tile_no].pdx[i] = l_tccp->prcw[i]; - p_cstr_info->tile[p_tile_no].pdy[i] = l_tccp->prch[i]; + p_cstr_info->tile[p_tile_no].pdx[i] = (int)l_tccp->prcw[i]; + p_cstr_info->tile[p_tile_no].pdy[i] = (int)l_tccp->prch[i]; } - p_cstr_info->tile[p_tile_no].packet = (opj_packet_info_t*) opj_calloc(p_cstr_info->numcomps * p_cstr_info->numlayers * l_num_packs, sizeof(opj_packet_info_t)); + p_cstr_info->tile[p_tile_no].packet = (opj_packet_info_t*) opj_calloc((size_t)p_cstr_info->numcomps * (size_t)p_cstr_info->numlayers * l_num_packs, sizeof(opj_packet_info_t)); } /* << INDEX */ @@ -1291,9 +1291,9 @@ OPJ_BOOL opj_tcd_update_tile_data ( opj_tcd_t *p_tcd, l_size_comp = l_img_comp->prec >> 3; /*(/ 8)*/ l_remaining = l_img_comp->prec & 7; /* (%8) */ l_res = l_tilec->resolutions + l_img_comp->resno_decoded; - l_width = (l_res->x1 - l_res->x0); - l_height = (l_res->y1 - l_res->y0); - l_stride = (l_tilec->x1 - l_tilec->x0) - l_width; + l_width = (OPJ_UINT32)(l_res->x1 - l_res->x0); + l_height = (OPJ_UINT32)(l_res->y1 - l_res->y0); + l_stride = (OPJ_UINT32)(l_tilec->x1 - l_tilec->x0) - l_width; if (l_remaining) { ++l_size_comp; @@ -1321,7 +1321,7 @@ OPJ_BOOL opj_tcd_update_tile_data ( opj_tcd_t *p_tcd, else { for (j=0;jx1 - l_tile_comp->x0) * (l_tile_comp->y1 - l_tile_comp->y0); + l_samples = (OPJ_UINT32)((l_tile_comp->x1 - l_tile_comp->x0) * (l_tile_comp->y1 - l_tile_comp->y0)); if (l_tile->numcomps >= 3 ){ /* testcase 1336.pdf.asan.47.376 */ @@ -1662,9 +1662,9 @@ OPJ_BOOL opj_tcd_dc_level_shift_decode ( opj_tcd_t *p_tcd ) for (compno = 0; compno < l_tile->numcomps; compno++) { l_res = l_tile_comp->resolutions + l_img_comp->resno_decoded; - l_width = (l_res->x1 - l_res->x0); - l_height = (l_res->y1 - l_res->y0); - l_stride = (l_tile_comp->x1 - l_tile_comp->x0) - l_width; + l_width = (OPJ_UINT32)(l_res->x1 - l_res->x0); + l_height = (OPJ_UINT32)(l_res->y1 - l_res->y0); + l_stride = (OPJ_UINT32)(l_tile_comp->x1 - l_tile_comp->x0) - l_width; assert(l_height == 0 || l_width + l_stride <= l_tile_comp->data_size / l_height); /*MUPDF*/ @@ -1803,7 +1803,7 @@ OPJ_UINT32 opj_tcd_get_encoded_tile_size ( opj_tcd_t *p_tcd ) l_size_comp = 4; } - l_data_size += l_size_comp * (l_tilec->x1 - l_tilec->x0) * (l_tilec->y1 - l_tilec->y0); + l_data_size += l_size_comp * (OPJ_UINT32)((l_tilec->x1 - l_tilec->x0) * (l_tilec->y1 - l_tilec->y0)); ++l_img_comp; ++l_tilec; } @@ -1828,7 +1828,7 @@ OPJ_BOOL opj_tcd_dc_level_shift_encode ( opj_tcd_t *p_tcd ) for (compno = 0; compno < l_tile->numcomps; compno++) { l_current_ptr = l_tile_comp->data; - l_nb_elem = (l_tile_comp->x1 - l_tile_comp->x0) * (l_tile_comp->y1 - l_tile_comp->y0); + l_nb_elem = (OPJ_UINT32)((l_tile_comp->x1 - l_tile_comp->x0) * (l_tile_comp->y1 - l_tile_comp->y0)); if (l_tccp->qmfbid == 1) { for (i = 0; i < l_nb_elem; ++i) { @@ -1855,7 +1855,7 @@ OPJ_BOOL opj_tcd_mct_encode ( opj_tcd_t *p_tcd ) { opj_tcd_tile_t * l_tile = p_tcd->tcd_image->tiles; opj_tcd_tilecomp_t * l_tile_comp = p_tcd->tcd_image->tiles->comps; - OPJ_UINT32 samples = (l_tile_comp->x1 - l_tile_comp->x0) * (l_tile_comp->y1 - l_tile_comp->y0); + OPJ_UINT32 samples = (OPJ_UINT32)((l_tile_comp->x1 - l_tile_comp->x0) * (l_tile_comp->y1 - l_tile_comp->y0)); OPJ_UINT32 i; OPJ_BYTE ** l_data = 00; opj_tcp_t * l_tcp = p_tcd->tcp; @@ -2052,7 +2052,7 @@ OPJ_BOOL opj_tcd_copy_tile_data ( opj_tcd_t *p_tcd, for (i=0;iimage->numcomps;++i) { l_size_comp = l_img_comp->prec >> 3; /*(/ 8)*/ l_remaining = l_img_comp->prec & 7; /* (%8) */ - l_nb_elem = (l_tilec->x1 - l_tilec->x0) * (l_tilec->y1 - l_tilec->y0); + l_nb_elem = (OPJ_UINT32)((l_tilec->x1 - l_tilec->x0) * (l_tilec->y1 - l_tilec->y0)); if (l_remaining) { ++l_size_comp; From ffad2fbe55d9df5cd51ba230a47d8a87b277be31 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 14:14:31 +0000 Subject: [PATCH 251/333] [trunk] Another round of fixes for sign conversion warnings. Update issue 256 --- src/lib/openjp2/jp2.c | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c index 4a6b346e..c845df1f 100644 --- a/src/lib/openjp2/jp2.c +++ b/src/lib/openjp2/jp2.c @@ -614,7 +614,7 @@ OPJ_BYTE * opj_jp2_write_bpcc( opj_jp2_t *jp2, { OPJ_UINT32 i; /* room for 8 bytes for box and 1 byte for each component */ - OPJ_INT32 l_bpcc_size = 8 + jp2->numcomps; + OPJ_UINT32 l_bpcc_size = 8 + jp2->numcomps; OPJ_BYTE * l_bpcc_data,* l_current_bpcc_ptr; /* preconditions */ @@ -900,7 +900,7 @@ void opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color) if((k = src[j]) < 0) k = 0; else if(k > top_k) k = top_k; /* The colour */ - dst[j] = entries[k * nr_channels + pcol]; + dst[j] = (OPJ_INT32)entries[k * nr_channels + pcol]; } } } @@ -955,7 +955,7 @@ OPJ_BOOL opj_jp2_read_pclr( opj_jp2_t *jp2, if (p_pclr_header_size < 3 + (OPJ_UINT32)nr_channels || nr_channels == 0 || nr_entries >= (OPJ_UINT32)-1 / nr_channels) return OPJ_FALSE; - entries = (OPJ_UINT32*) opj_malloc(nr_channels * nr_entries * sizeof(OPJ_UINT32)); + entries = (OPJ_UINT32*) opj_malloc((size_t)nr_channels * nr_entries * sizeof(OPJ_UINT32)); if (!entries) return OPJ_FALSE; channel_size = (OPJ_BYTE*) opj_malloc(nr_channels); @@ -1000,7 +1000,7 @@ OPJ_BOOL opj_jp2_read_pclr( opj_jp2_t *jp2, for(j = 0; j < nr_entries; ++j) { for(i = 0; i < nr_channels; ++i) { - OPJ_UINT32 bytes_to_read = (channel_size[i]+7)>>3; + OPJ_UINT32 bytes_to_read = (OPJ_UINT32)((channel_size[i]+7)>>3); if (bytes_to_read > sizeof(OPJ_UINT32)) bytes_to_read = sizeof(OPJ_UINT32); @@ -1107,7 +1107,7 @@ void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color) } cn = info[i].cn; - acn = (OPJ_INT16)(asoc - 1); + acn = (OPJ_UINT16)(asoc - 1); if( cn >= image->numcomps || acn >= image->numcomps ) { fprintf(stderr, "cn=%d, acn=%d, numcomps=%d\n", cn, acn, image->numcomps); @@ -1266,16 +1266,16 @@ OPJ_BOOL opj_jp2_read_colr( opj_jp2_t *jp2, else if (jp2->meth == 2) { /* ICC profile */ OPJ_INT32 it_icc_value = 0; - OPJ_INT32 icc_len = p_colr_header_size - 3; + OPJ_INT32 icc_len = (OPJ_INT32)p_colr_header_size - 3; - jp2->color.icc_profile_len = icc_len; - jp2->color.icc_profile_buf = (OPJ_BYTE*) opj_malloc(icc_len); + jp2->color.icc_profile_len = (OPJ_UINT32)icc_len; + jp2->color.icc_profile_buf = (OPJ_BYTE*) opj_malloc((size_t)icc_len); if (!jp2->color.icc_profile_buf) { jp2->color.icc_profile_len = 0; return OPJ_FALSE; } - memset(jp2->color.icc_profile_buf, 0, icc_len * sizeof(OPJ_BYTE)); + memset(jp2->color.icc_profile_buf, 0, (size_t)icc_len * sizeof(OPJ_BYTE)); for (it_icc_value = 0; it_icc_value < icc_len; ++it_icc_value) { @@ -1360,7 +1360,7 @@ OPJ_BOOL opj_jp2_write_jp2h(opj_jp2_t *jp2, OPJ_INT32 i, l_nb_pass; /* size of data for super box*/ - OPJ_INT32 l_jp2h_size = 8; + OPJ_UINT32 l_jp2h_size = 8; OPJ_BOOL l_result = OPJ_TRUE; /* to store the data of the super box */ @@ -1587,7 +1587,8 @@ void opj_jp2_setup_encoder( opj_jp2_t *jp2, opj_event_mgr_t * p_manager) { OPJ_UINT32 i; - OPJ_INT32 depth_0, sign; + OPJ_UINT32 depth_0; + OPJ_UINT32 sign; if(!jp2 || !parameters || !image) return; @@ -1636,7 +1637,7 @@ void opj_jp2_setup_encoder( opj_jp2_t *jp2, sign = image->comps[0].sgnd; jp2->bpc = depth_0 + (sign << 7); for (i = 1; i < image->numcomps; i++) { - OPJ_INT32 depth = image->comps[i].prec - 1; + OPJ_UINT32 depth = image->comps[i].prec - 1; sign = image->comps[i].sgnd; if (depth_0 != depth) jp2->bpc = 255; @@ -2242,11 +2243,11 @@ OPJ_BOOL opj_jp2_read_boxhdr_char( opj_jp2_box_t *box, /* process read data */ opj_read_bytes(p_data, &l_value, 4); p_data += 4; - box->length = (OPJ_INT32)(l_value); + box->length = (OPJ_UINT32)(l_value); opj_read_bytes(p_data, &l_value, 4); p_data += 4; - box->type = (OPJ_INT32)(l_value); + box->type = (OPJ_UINT32)(l_value); *p_number_bytes_read = 8; @@ -2271,7 +2272,7 @@ OPJ_BOOL opj_jp2_read_boxhdr_char( opj_jp2_box_t *box, opj_read_bytes(p_data, &l_value, 4); *p_number_bytes_read += 4; - box->length = (OPJ_INT32)(l_value); + box->length = (OPJ_UINT32)(l_value); if (box->length == 0) { opj_event_msg(p_manager, EVT_ERROR, "Cannot handle box of undefined sizes\n"); From 440ef4873b079046b4c7d22694542779d0af70ac Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 14:33:03 +0000 Subject: [PATCH 252/333] [trunk] Also override the default error handler for TIFF files --- tests/comparePGXimages.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/comparePGXimages.c b/tests/comparePGXimages.c index c6ccf488..978b9610 100644 --- a/tests/comparePGXimages.c +++ b/tests/comparePGXimages.c @@ -149,11 +149,13 @@ static opj_image_t* readImageFromFileTIF(const char* filename, int nbFilenamePGX opj_image_cmptparm_t* param_image_read; int** data; - /* conformance test suite produce annoying warning: + /* conformance test suite produce annoying warning/error: * TIFFReadDirectory: Warning, /.../data/baseline/conformance/jp2_1.tif: unknown field with tag 37724 (0x935c) encountered. + * TIFFOpen: /.../data/baseline/nonregression/opj_jp2_1.tif: Cannot open. * On Win32 this open a message box by default, so remove it from the test suite: */ TIFFSetWarningHandler(NULL); + TIFFSetErrorHandler(NULL); /* If separator is empty => nb file to read is equal to one*/ if ( strlen(separator) == 0 ) From a0aa8dd851ecb8ff333a0881a73e88e11bb0007e Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 16:15:59 +0000 Subject: [PATCH 253/333] [trunk] Rework the code to simplify cleanup code --- tests/compareRAWimages.c | 264 ++++++++++++++++----------------------- 1 file changed, 109 insertions(+), 155 deletions(-) diff --git a/tests/compareRAWimages.c b/tests/compareRAWimages.c index b19c2148..b4fa9427 100644 --- a/tests/compareRAWimages.c +++ b/tests/compareRAWimages.c @@ -40,21 +40,21 @@ typedef struct test_cmp_parameters { - /** */ - char* base_filename; - /** */ - char* test_filename; + /** */ + char* base_filename; + /** */ + char* test_filename; } test_cmp_parameters; /******************************************************************************* * Command line help function *******************************************************************************/ static void compareRAWimages_help_display(void) { - fprintf(stdout,"\nList of parameters for the comparePGX function \n"); - fprintf(stdout,"\n"); - fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline RAW image \n"); - fprintf(stdout," -t \t REQUIRED \t filename to the test RAW image\n"); - fprintf(stdout,"\n"); + fprintf(stdout,"\nList of parameters for the comparePGX function \n"); + fprintf(stdout,"\n"); + fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline RAW image \n"); + fprintf(stdout," -t \t REQUIRED \t filename to the test RAW image\n"); + fprintf(stdout,"\n"); } /******************************************************************************* @@ -62,54 +62,52 @@ static void compareRAWimages_help_display(void) { *******************************************************************************/ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) { - int sizemembasefile, sizememtestfile; - int index; - const char optlist[] = "b:t:"; - int c; + size_t sizemembasefile, sizememtestfile; + int index; + const char optlist[] = "b:t:"; + int c; - /* Init parameters*/ - param->base_filename = NULL; - param->test_filename = NULL; + /* Init parameters*/ + param->base_filename = NULL; + param->test_filename = NULL; - opj_opterr = 0; - while ((c = opj_getopt(argc, argv, optlist)) != -1) - switch (c) - { - case 'b': - sizemembasefile = (int)strlen(opj_optarg)+1; - param->base_filename = (char*) malloc((size_t)sizemembasefile); - param->base_filename[0] = '\0'; - strncpy(param->base_filename, opj_optarg, strlen(opj_optarg)); - param->base_filename[strlen(opj_optarg)] = '\0'; - /*printf("param->base_filename = %s [%d / %d]\n", param->base_filename, strlen(param->base_filename), sizemembasefile );*/ - break; - case 't': - sizememtestfile = (int) strlen(opj_optarg) + 1; - param->test_filename = (char*) malloc((size_t)sizememtestfile); - param->test_filename[0] = '\0'; - strncpy(param->test_filename, opj_optarg, strlen(opj_optarg)); - param->test_filename[strlen(opj_optarg)] = '\0'; - /*printf("param->test_filename = %s [%d / %d]\n", param->test_filename, strlen(param->test_filename), sizememtestfile);*/ - break; - case '?': - if ((opj_optopt == 'b') || (opj_optopt == 't')) - fprintf(stderr, "Option -%c requires an argument.\n", opj_optopt); - else - if (isprint(opj_optopt)) fprintf(stderr, "Unknown option `-%c'.\n", opj_optopt); - else fprintf(stderr, "Unknown option character `\\x%x'.\n", opj_optopt); - return 1; - default: - fprintf(stderr, "WARNING -> this option is not valid \"-%c %s\"\n", c, opj_optarg); - break; - } + opj_opterr = 0; + while ((c = opj_getopt(argc, argv, optlist)) != -1) + switch (c) + { + case 'b': + sizemembasefile = strlen(opj_optarg)+1; + free(param->base_filename); // handle dup option + param->base_filename = (char*) malloc(sizemembasefile); + strcpy(param->base_filename, opj_optarg); + /*printf("param->base_filename = %s [%d / %d]\n", param->base_filename, strlen(param->base_filename), sizemembasefile );*/ + break; + case 't': + sizememtestfile = strlen(opj_optarg) + 1; + free(param->test_filename); // handle dup option + param->test_filename = (char*) malloc(sizememtestfile); + strcpy(param->test_filename, opj_optarg); + /*printf("param->test_filename = %s [%d / %d]\n", param->test_filename, strlen(param->test_filename), sizememtestfile);*/ + break; + case '?': + if ((opj_optopt == 'b') || (opj_optopt == 't')) + fprintf(stderr, "Option -%c requires an argument.\n", opj_optopt); + else + if (isprint(opj_optopt)) fprintf(stderr, "Unknown option `-%c'.\n", opj_optopt); + else fprintf(stderr, "Unknown option character `\\x%x'.\n", opj_optopt); + return 1; + default: + fprintf(stderr, "WARNING -> this option is not valid \"-%c %s\"\n", c, opj_optarg); + break; + } - if (opj_optind != argc) { - for (index = opj_optind; index < argc; index++) - fprintf(stderr,"Non-option argument %s\n", argv[index]); - return EXIT_FAILURE; - } + if (opj_optind != argc) { + for (index = opj_optind; index < argc; index++) + fprintf(stderr,"Non-option argument %s\n", argv[index]); + return 1; + } - return EXIT_SUCCESS; + return 0; } /******************************************************************************* @@ -118,119 +116,75 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) int main(int argc, char **argv) { int pos = 0; - test_cmp_parameters inParam; - FILE *file_test=NULL, *file_base=NULL; - unsigned char equal = 1; + test_cmp_parameters inParam; + FILE *file_test=NULL, *file_base=NULL; + unsigned char equal = 1; - /* Get parameters from command line*/ - if (parse_cmdline_cmp(argc, argv, &inParam) == EXIT_FAILURE) - { - compareRAWimages_help_display(); + /* Get parameters from command line*/ + if (parse_cmdline_cmp(argc, argv, &inParam)) + { + compareRAWimages_help_display(); + goto cleanup; + } - /* Free Memory */ - if (inParam.base_filename){ - free(inParam.base_filename); - inParam.base_filename = NULL; - } - if (inParam.test_filename){ - free(inParam.test_filename); - inParam.test_filename = NULL; - } + file_test = fopen(inParam.test_filename, "rb"); + if (!file_test) { + fprintf(stderr, "Failed to open %s for reading !!\n", inParam.test_filename); + goto cleanup; + } - return EXIT_FAILURE; - } + file_base = fopen(inParam.base_filename, "rb"); + if (!file_base) { + fprintf(stderr, "Failed to open %s for reading !!\n", inParam.base_filename); + goto cleanup; + } - file_test = fopen(inParam.test_filename, "rb"); - if (!file_test) { - fprintf(stderr, "Failed to open %s for reading !!\n", inParam.test_filename); + /* Read simultaneously the two files*/ + while (equal) + { + unsigned char value_test = 0; + unsigned char eof_test = 0; + unsigned char value_base = 0; + unsigned char eof_base = 0; - /* Free Memory */ - if (inParam.base_filename){ - free(inParam.base_filename); - inParam.base_filename = NULL; - } - if (inParam.test_filename){ - free(inParam.test_filename); - inParam.test_filename = NULL; - } + /* Read one byte*/ + if (!fread(&value_test, 1, 1, file_test)) { + eof_test = 1; + } - return EXIT_FAILURE; - } + /* Read one byte*/ + if (!fread(&value_base, 1, 1, file_base)) { + eof_base = 1; + } - file_base = fopen(inParam.base_filename, "rb"); - if (!file_base) { - fprintf(stderr, "Failed to open %s for reading !!\n", inParam.base_filename); + /* End of file reached by the two files?*/ + if (eof_test && eof_base) + break; - /* Free Memory */ - if (inParam.base_filename){ - free(inParam.base_filename); - inParam.base_filename = NULL; - } - if (inParam.test_filename){ - free(inParam.test_filename); - inParam.test_filename = NULL; - } + /* End of file reached only by one file?*/ + if (eof_test || eof_base) + { + fprintf(stdout,"Files have different sizes.\n"); + equal = 0; + } - fclose(file_test); - return EXIT_FAILURE; - } - - /* Read simultaneously the two files*/ - while (equal) - { - unsigned char value_test = 0; - unsigned char eof_test = 0; - unsigned char value_base = 0; - unsigned char eof_base = 0; - - /* Read one byte*/ - if (!fread(&value_test, 1, 1, file_test)) { - eof_test = 1; - } - - /* Read one byte*/ - if (!fread(&value_base, 1, 1, file_base)) { - eof_base = 1; - } - - /* End of file reached by the two files?*/ - if (eof_test && eof_base) - break; - - /* End of file reached only by one file?*/ - if (eof_test || eof_base) - { - fprintf(stdout,"Files have different sizes.\n"); - equal = 0; - } - - /* Binary values are equal?*/ - if (value_test != value_base) - { - fprintf(stdout,"Binary values read in the file are different %x vs %x at position %d.\n", value_test, value_base, pos); - equal = 0; - } + /* Binary values are equal?*/ + if (value_test != value_base) + { + fprintf(stdout,"Binary values read in the file are different %x vs %x at position %d.\n", value_test, value_base, pos); + equal = 0; + } pos++; - } + } - /* Free Memory */ - if (inParam.base_filename){ - free(inParam.base_filename); - inParam.base_filename = NULL; - } - if (inParam.test_filename){ - free(inParam.test_filename); - inParam.test_filename = NULL; - } + if(equal) fprintf(stdout,"---- TEST SUCCEED: Files are equal ----\n"); +cleanup: + if(file_test) fclose(file_test); + if(file_base) fclose(file_base); - fclose(file_test); - fclose(file_base); + /* Free Memory */ + free(inParam.base_filename); + free(inParam.test_filename); - if (equal) - { - fprintf(stdout,"---- TEST SUCCEED: Files are equal ----\n"); - return EXIT_SUCCESS; - } - else - return EXIT_FAILURE; + return equal ? EXIT_SUCCESS : EXIT_FAILURE; } From aedff8a0009c34fa4940463498ae27d9938b7fcd Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 16:17:21 +0000 Subject: [PATCH 254/333] [trunk] Use C-style comments --- tests/compareRAWimages.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/compareRAWimages.c b/tests/compareRAWimages.c index b4fa9427..d913cf9b 100644 --- a/tests/compareRAWimages.c +++ b/tests/compareRAWimages.c @@ -77,14 +77,14 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) { case 'b': sizemembasefile = strlen(opj_optarg)+1; - free(param->base_filename); // handle dup option + free(param->base_filename); /* handle dup option */ param->base_filename = (char*) malloc(sizemembasefile); strcpy(param->base_filename, opj_optarg); /*printf("param->base_filename = %s [%d / %d]\n", param->base_filename, strlen(param->base_filename), sizemembasefile );*/ break; case 't': sizememtestfile = strlen(opj_optarg) + 1; - free(param->test_filename); // handle dup option + free(param->test_filename); /* handle dup option */ param->test_filename = (char*) malloc(sizememtestfile); strcpy(param->test_filename, opj_optarg); /*printf("param->test_filename = %s [%d / %d]\n", param->test_filename, strlen(param->test_filename), sizememtestfile);*/ From 6b942376798af17e198b395167f895afc61f306c Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 16:24:24 +0000 Subject: [PATCH 255/333] [trunk] Cleanup commit. Rename compare family since comparePGX now support TIFF. Rename compareRAWimage for clarity since it merely compare files (not images). --- tests/CMakeLists.txt | 14 ++++---- .../{comparePGXimages.c => compare_images.c} | 8 ++--- ...compareRAWimages.c => compare_raw_files.c} | 10 +++--- tests/conformance/CMakeLists.txt | 36 +++++++++---------- tests/nonregression/CMakeLists.txt | 4 +-- 5 files changed, 37 insertions(+), 35 deletions(-) rename tests/{comparePGXimages.c => compare_images.c} (99%) rename tests/{compareRAWimages.c => compare_raw_files.c} (96%) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index b40af1c5..625199f7 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -11,7 +11,7 @@ include_directories( ) # First thing define the common source: -set(comparePGXimages_SRCS comparePGXimages.c +set(compare_images_SRCS compare_images.c ${OPENJPEG_SOURCE_DIR}/src/bin/jp2/convert.c ${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.c ) @@ -19,19 +19,19 @@ set(comparePGXimages_SRCS comparePGXimages.c set(compare_dump_files_SRCS compare_dump_files.c ${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.c) -set(compareRAWimages_SRCS compareRAWimages.c +set(compare_raw_files_SRCS compare_raw_files.c ${OPENJPEG_SOURCE_DIR}/src/bin/common/opj_getopt.c) -add_executable(comparePGXimages ${comparePGXimages_SRCS}) -target_link_libraries(comparePGXimages +add_executable(compare_images ${compare_images_SRCS}) +target_link_libraries(compare_images ${OPENJPEG_LIBRARY_NAME} ${PNG_LIBNAME} ${TIFF_LIBNAME} ) # To support universal exe: if(ZLIB_FOUND AND APPLE) - target_link_libraries(comparePGXimages z) + target_link_libraries(compare_images z) else(ZLIB_FOUND AND APPLE) - target_link_libraries(comparePGXimages ${Z_LIBNAME}) + target_link_libraries(compare_images ${Z_LIBNAME}) endif() add_executable(compare_dump_files ${compare_dump_files_SRCS}) @@ -39,7 +39,7 @@ add_executable(compare_dump_files ${compare_dump_files_SRCS}) add_executable(j2k_random_tile_access j2k_random_tile_access.c) target_link_libraries(j2k_random_tile_access ${OPENJPEG_LIBRARY_NAME}) -add_executable(compareRAWimages ${compareRAWimages_SRCS}) +add_executable(compare_raw_files ${compare_raw_files_SRCS}) add_executable(test_tile_encoder test_tile_encoder.c) target_link_libraries(test_tile_encoder ${OPENJPEG_LIBRARY_NAME}) diff --git a/tests/comparePGXimages.c b/tests/compare_images.c similarity index 99% rename from tests/comparePGXimages.c rename to tests/compare_images.c index 978b9610..9f15f04d 100644 --- a/tests/comparePGXimages.c +++ b/tests/compare_images.c @@ -25,7 +25,7 @@ */ /* - * comparePGXimages.c + * compare_images.c * * Created on: 8 juil. 2011 * Author: mickael @@ -79,9 +79,9 @@ static double* parseToleranceValues( char* inArg, const int nbcomp) /******************************************************************************* * Command line help function *******************************************************************************/ -static void comparePGXimages_help_display(void) +static void compare_images_help_display(void) { - fprintf(stdout,"\nList of parameters for the comparePGX function \n"); + fprintf(stdout,"\nList of parameters for the compare_images function \n"); fprintf(stdout,"\n"); fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline PGX image \n"); fprintf(stdout," -t \t REQUIRED \t filename to the test PGX image\n"); @@ -623,7 +623,7 @@ int main(int argc, char **argv) /* Get parameters from command line*/ if( parse_cmdline_cmp(argc, argv, &inParam) ) { - comparePGXimages_help_display(); + compare_images_help_display(); goto cleanup; } diff --git a/tests/compareRAWimages.c b/tests/compare_raw_files.c similarity index 96% rename from tests/compareRAWimages.c rename to tests/compare_raw_files.c index d913cf9b..e7ab8c94 100644 --- a/tests/compareRAWimages.c +++ b/tests/compare_raw_files.c @@ -25,10 +25,12 @@ */ /* - * compareRAWimages.c + * compare_raw_files.c * * Created on: 31 August 2011 * Author: mickael + * + * This is equivalent to the UNIX `cmp` command */ #include @@ -49,8 +51,8 @@ typedef struct test_cmp_parameters /******************************************************************************* * Command line help function *******************************************************************************/ -static void compareRAWimages_help_display(void) { - fprintf(stdout,"\nList of parameters for the comparePGX function \n"); +static void compare_raw_files_help_display(void) { + fprintf(stdout,"\nList of parameters for the compare_raw_files function \n"); fprintf(stdout,"\n"); fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline RAW image \n"); fprintf(stdout," -t \t REQUIRED \t filename to the test RAW image\n"); @@ -123,7 +125,7 @@ int main(int argc, char **argv) /* Get parameters from command line*/ if (parse_cmdline_cmp(argc, argv, &inParam)) { - compareRAWimages_help_display(); + compare_raw_files_help_display(); goto cleanup; } diff --git a/tests/conformance/CMakeLists.txt b/tests/conformance/CMakeLists.txt index 57fd2568..e47002f1 100644 --- a/tests/conformance/CMakeLists.txt +++ b/tests/conformance/CMakeLists.txt @@ -59,7 +59,7 @@ set(COMMENTCODEVAR FALSE) # ) # add_test(ETS-C0P0-${filenameInput}-r0-compare2ref -# ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages +# ${EXECUTABLE_OUTPUT_PATH}/compare_images # -b ${BASELINE_CONF}/${filenameRefSub}r0.pgx # -t ${TEMP}/c0${filenameInput}-r0.pgx # -n ${nbComponents} @@ -73,7 +73,7 @@ set(COMMENTCODEVAR FALSE) # ETS-C0P0-${filenameInput}-r0-decode) # add_test(NR-C0P0-${filenameInput}-r0-compare2base -# ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages +# ${EXECUTABLE_OUTPUT_PATH}/compare_images # -b ${BASELINE_NR}/opj_${filenameRefSub}-r0.pgx # -t ${TEMP}/c0${filenameInput}-r0.pgx # -n ${nbComponents} @@ -94,7 +94,7 @@ set(COMMENTCODEVAR FALSE) # ) # add_test(ETS-C0P0-${filenameInput}-r1-compare2ref -# ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages +# ${EXECUTABLE_OUTPUT_PATH}/compare_images # -b ${BASELINE_CONF}/${filenameRefSub}r1.pgx # -t ${TEMP}/c0${filenameInput}-r1.pgx # -n ${nbComponents} @@ -108,7 +108,7 @@ set(COMMENTCODEVAR FALSE) # ETS-C0P0-${filenameInput}-r1-decode) # add_test(NR-C0P0-${filenameInput}-r1-compare2base -# ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages +# ${EXECUTABLE_OUTPUT_PATH}/compare_images # -b ${BASELINE_NR}/opj_${filenameRefSub}-r1.pgx # -t ${TEMP}/c0${filenameInput}-r1.pgx # -n ${nbComponents} @@ -130,7 +130,7 @@ set(COMMENTCODEVAR FALSE) # ) # add_test(ETS-C0P0-${filenameInput}-compare2ref -# ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages +# ${EXECUTABLE_OUTPUT_PATH}/compare_images # -b ${BASELINE_CONF}/${filenameRef} # -t ${TEMP}/c0${filenameInput}.pgx # -n ${nbComponents} @@ -144,7 +144,7 @@ set(COMMENTCODEVAR FALSE) # ETS-C0P0-${filenameInput}-decode) # add_test(NR-C0P0-${filenameInput}-compare2base -# ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages +# ${EXECUTABLE_OUTPUT_PATH}/compare_images # -b ${BASELINE_NR}/opj_${filenameRef} # -t ${TEMP}/c0${filenameInput}.pgx # -n ${nbComponents} @@ -198,7 +198,7 @@ set(COMMENTCODEVAR FALSE) # ) # add_test(ETS-C0P1-${filenameInput}-r0-compare2ref -# ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages +# ${EXECUTABLE_OUTPUT_PATH}/compare_images # -b ${BASELINE_CONF}/${filenameRefSub}r0.pgx # -t ${TEMP}/c0${filenameInput}-r0.pgx # -n ${nbComponents} @@ -212,7 +212,7 @@ set(COMMENTCODEVAR FALSE) # ETS-C0P1-${filenameInput}-r0-decode) # add_test(NR-C0P1-${filenameInput}-r0-compare2base -# ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages +# ${EXECUTABLE_OUTPUT_PATH}/compare_images # -b ${BASELINE_NR}/opj_${filenameRefSub}-r0.pgx # -t ${TEMP}/c0${filenameInput}-r0.pgx # -n ${nbComponents} @@ -233,7 +233,7 @@ set(COMMENTCODEVAR FALSE) # ) # add_test(ETS-C0P1-${filenameInput}-r3-compare2ref -# ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages +# ${EXECUTABLE_OUTPUT_PATH}/compare_images # -b ${BASELINE_CONF}/${filenameRefSub}r3.pgx # -t ${TEMP}/c0${filenameInput}-r3.pgx # -n ${nbComponents} @@ -247,7 +247,7 @@ set(COMMENTCODEVAR FALSE) # ETS-C0P1-${filenameInput}-r3-decode) # add_test(NR-C0P1-${filenameInput}-r3-compare2base -# ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages +# ${EXECUTABLE_OUTPUT_PATH}/compare_images # -b ${BASELINE_NR}/opj_${filenameRefSub}-r3.pgx # -t ${TEMP}/c0${filenameInput}-r3.pgx # -n ${nbComponents} @@ -269,7 +269,7 @@ set(COMMENTCODEVAR FALSE) # ) # add_test(ETS-C0P1-${filenameInput}-compare2ref -# ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages +# ${EXECUTABLE_OUTPUT_PATH}/compare_images # -b ${BASELINE_CONF}/${filenameRef} # -t ${TEMP}/c0${filenameInput}.pgx # -n ${nbComponents} @@ -283,7 +283,7 @@ set(COMMENTCODEVAR FALSE) # ETS-C0P1-${filenameInput}-decode) # add_test(NR-C0P1-${filenameInput}-compare2base -# ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages +# ${EXECUTABLE_OUTPUT_PATH}/compare_images # -b ${BASELINE_NR}/opj_${filenameRef} # -t ${TEMP}/c0${filenameInput}.pgx # -n ${nbComponents} @@ -335,7 +335,7 @@ foreach(numFileC1P0 RANGE 1 16) ) add_test(NAME ETS-C1P0-${filenameInput}-compare2ref - COMMAND comparePGXimages + COMMAND compare_images -b ${BASELINE_CONF}/${filenameRef} -t ${TEMP}/c1${filenameInput}.pgx -n ${nbComponents} @@ -349,7 +349,7 @@ foreach(numFileC1P0 RANGE 1 16) ETS-C1P0-${filenameInput}-decode) add_test(NAME NR-C1P0-${filenameInput}-compare2base - COMMAND comparePGXimages + COMMAND compare_images -b ${BASELINE_NR}/opj_${filenameRef} -t ${TEMP}/c1${filenameInput}.pgx -n ${nbComponents} @@ -392,7 +392,7 @@ foreach(numFileC1P1 RANGE 1 7) ) add_test(NAME ETS-C1P1-${filenameInput}-compare2ref - COMMAND comparePGXimages + COMMAND compare_images -b ${BASELINE_CONF}/${filenameRef} -t ${TEMP}/c1${filenameInput}.pgx -n ${nbComponents} @@ -406,7 +406,7 @@ foreach(numFileC1P1 RANGE 1 7) ETS-C1P1-${filenameInput}-decode) add_test(NAME NR-C1P1-${filenameInput}-compare2base - COMMAND comparePGXimages + COMMAND compare_images -b ${BASELINE_NR}/opj_${filenameRef} -t ${TEMP}/c1${filenameInput}.pgx -n ${nbComponents} @@ -444,7 +444,7 @@ foreach(numFileJP2 RANGE 1 9) ) add_test(NAME ETS-JP2-${filenameInput}-compare2ref - COMMAND comparePGXimages + COMMAND compare_images -b ${BASELINE_CONF}/${filenameRef} -t ${TEMP}/${filenameInput}.tif -n 3 @@ -458,7 +458,7 @@ foreach(numFileJP2 RANGE 1 9) ETS-JP2-${filenameInput}-decode) add_test(NAME NR-JP2-${filenameInput}-compare2base - COMMAND comparePGXimages + COMMAND compare_images -b ${BASELINE_NR}/opj_${filenameRef} -t ${TEMP}/${filenameInput}.tif -n 3 diff --git a/tests/nonregression/CMakeLists.txt b/tests/nonregression/CMakeLists.txt index 8b85827c..f21a0908 100644 --- a/tests/nonregression/CMakeLists.txt +++ b/tests/nonregression/CMakeLists.txt @@ -289,7 +289,7 @@ foreach(OPJ_TEST_CMD_LINE ${OPJ_TEST_CMD_LINE_LIST}) # Compare the decoding file with baseline generated from the kdu_expand and baseline.j2k add_test(NAME NR-ENC-${INPUT_FILENAME_NAME}-${IT_TEST_ENC}-compare_dec-ref-out2base - COMMAND compareRAWimages + COMMAND compare_raw_files -b ${BASELINE_NR}/opj_${OUTPUT_FILENAME_NAME_WE}-ENC-${IT_TEST_ENC}.raw -t ${OUTPUT_FILENAME}.raw ) @@ -330,7 +330,7 @@ foreach(OPJ_TEST_CMD_LINE ${OPJ_TEST_CMD_LINE_LIST}) # FIXME: add a compare2base function base on raw which # can output png diff files if necesary # add_test(NR-${filename}-compare2base -# ${EXECUTABLE_OUTPUT_PATH}/comparePGXimages +# ${EXECUTABLE_OUTPUT_PATH}/compare_images # -b ${BASELINE_NR}/opj_${filenameRef} # -t ${TEMP}/${filename}.pgx # -n ${nbComponents} From fa1c2454e6d57685f58f1ce3c198945d5d5fe324 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 17:18:13 +0000 Subject: [PATCH 256/333] [trunk] Add new test suite that run on kakadu conformance images --- tests/compare_images.c | 109 ++++++++++++++++++++++++++++++- tests/conformance/CMakeLists.txt | 72 ++++++++++++++++++++ 2 files changed, 179 insertions(+), 2 deletions(-) diff --git a/tests/compare_images.c b/tests/compare_images.c index 9f15f04d..fba89710 100644 --- a/tests/compare_images.c +++ b/tests/compare_images.c @@ -140,6 +140,94 @@ static char* createMultiComponentsFilename(const char* inFilename, const int ind /******************************************************************************* * *******************************************************************************/ +static opj_image_t* readImageFromFilePPM(const char* filename, int nbFilenamePGX, const char *separator) +{ + int it_file; + opj_image_t* image_read = NULL; + opj_image_t* image = NULL; + opj_cparameters_t parameters; + opj_image_cmptparm_t* param_image_read; + int** data; + + /* If separator is empty => nb file to read is equal to one*/ + if ( strlen(separator) == 0 ) + nbFilenamePGX = 1; + + /* set encoding parameters to default values */ + opj_set_default_encoder_parameters(¶meters); + parameters.decod_format = PXM_DFMT; + strcpy(parameters.infile, filename); + + /* Allocate memory*/ + param_image_read = malloc((size_t)nbFilenamePGX * sizeof(opj_image_cmptparm_t)); + data = malloc((size_t)nbFilenamePGX * sizeof(*data)); + + for (it_file = 0; it_file < nbFilenamePGX; it_file++) + { + /* Create the right filename*/ + char *filenameComponentPGX; + if (strlen(separator) == 0) + { + filenameComponentPGX = malloc((strlen(filename) + 1) * sizeof(*filenameComponentPGX)); + strcpy(filenameComponentPGX, filename); + } + else + filenameComponentPGX = createMultiComponentsFilename(filename, it_file, separator); + + /* Read the tif file corresponding to the component */ + image_read = pnmtoimage(filenameComponentPGX, ¶meters); + if (!image_read) + { + int it_free_data; + fprintf(stderr, "Unable to load pgx file\n"); + + free(param_image_read); + + for (it_free_data = 0; it_free_data < it_file; it_free_data++) { + free(data[it_free_data]); + } + free(data); + + free(filenameComponentPGX); + + return NULL; + } + + /* Set the image_read parameters*/ + param_image_read[it_file].x0 = 0; + param_image_read[it_file].y0 = 0; + param_image_read[it_file].dx = 0; + param_image_read[it_file].dy = 0; + param_image_read[it_file].h = image_read->comps->h; + param_image_read[it_file].w = image_read->comps->w; + param_image_read[it_file].bpp = image_read->comps->bpp; + param_image_read[it_file].prec = image_read->comps->prec; + param_image_read[it_file].sgnd = image_read->comps->sgnd; + + /* Copy data*/ + data[it_file] = malloc(param_image_read[it_file].h * param_image_read[it_file].w * sizeof(int)); + memcpy(data[it_file], image_read->comps->data, image_read->comps->h * image_read->comps->w * sizeof(int)); + + /* Free memory*/ + opj_image_destroy(image_read); + free(filenameComponentPGX); + } + + image = opj_image_create((OPJ_UINT32)nbFilenamePGX, param_image_read, OPJ_CLRSPC_UNSPECIFIED); + for (it_file = 0; it_file < nbFilenamePGX; it_file++) + { + /* Copy data into output image and free memory*/ + memcpy(image->comps[it_file].data, data[it_file], image->comps[it_file].h * image->comps[it_file].w * sizeof(int)); + free(data[it_file]); + } + + /* Free memory*/ + free(param_image_read); + free(data); + + return image; +} + static opj_image_t* readImageFromFileTIF(const char* filename, int nbFilenamePGX, const char *separator) { int it_file; @@ -385,6 +473,7 @@ static int get_decod_format(test_cmp_parameters* param) if( strcmp(base_ext,test_ext) != 0 ) return -1; if( strcmp(base_ext,".pgx") == 0 ) return PGX_DFMT; if( strcmp(base_ext,".tif") == 0 ) return TIF_DFMT; + if( strcmp(base_ext,".ppm") == 0 ) return PXM_DFMT; return -1; } @@ -667,8 +756,12 @@ int main(int argc, char **argv) memsizetestfilename = (int)strlen(inParam.test_filename) + 1 + 5 + 2 + 4; decod_format = get_decod_format(&inParam); - if( decod_format == -1 ) goto cleanup; - assert( decod_format == PGX_DFMT || decod_format == TIF_DFMT ); + if( decod_format == -1 ) + { + fprintf( stderr, "Unhandled file format\n" ); + goto cleanup; + } + assert( decod_format == PGX_DFMT || decod_format == TIF_DFMT || decod_format == PXM_DFMT ); if( decod_format == PGX_DFMT ) { @@ -682,6 +775,12 @@ int main(int argc, char **argv) if ( imageBase == NULL ) goto cleanup; } + else if( decod_format == PXM_DFMT ) + { + imageBase = readImageFromFilePPM( inParam.base_filename, nbFilenamePGXbase, ""); + if ( imageBase == NULL ) + goto cleanup; + } filenamePNGbase = (char*) malloc((size_t)memsizebasefilename); strcpy(filenamePNGbase, inParam.test_filename); @@ -702,6 +801,12 @@ int main(int argc, char **argv) if ( imageTest == NULL ) goto cleanup; } + else if( decod_format == PXM_DFMT ) + { + imageTest = readImageFromFilePPM(inParam.test_filename, nbFilenamePGXtest, ""); + if ( imageTest == NULL ) + goto cleanup; + } filenamePNGtest = (char*) malloc((size_t)memsizetestfilename); strcpy(filenamePNGtest, inParam.test_filename); diff --git a/tests/conformance/CMakeLists.txt b/tests/conformance/CMakeLists.txt index e47002f1..358a3f35 100644 --- a/tests/conformance/CMakeLists.txt +++ b/tests/conformance/CMakeLists.txt @@ -472,6 +472,78 @@ foreach(numFileJP2 RANGE 1 9) endforeach() +#-------------------------------------------------------------------------- +# Tests about Kakadu/J2K file +# try to decode +# compare to ref file +# non regression comparison + +# Tolerances given by ??? + +set(kdu_j2k_conf_files + a1_mono + a2_colr + a3_mono + a4_colr + a5_mono + a6_mono_colr + b1_mono + b2_mono + b3_mono + c1_mono + c2_mono + d1_colr + d2_colr + e1_colr + e2_colr + f1_mono + f2_mono + g1_colr + g2_colr + g3_colr + g4_colr +) + +foreach(kdu_file ${kdu_j2k_conf_files}) + + # Build filenames + set( filenameInput "${kdu_file}.j2c" ) + set( filenameRef "${kdu_file}.ppm" ) + + add_test(NAME ETS-KDU-${filenameInput}-decode + COMMAND opj_decompress + -i ${INPUT_CONF}/${filenameInput} + -o ${TEMP}/${filenameInput}.ppm + ) + + add_test(NAME ETS-KDU-${filenameInput}-compare2ref + COMMAND compare_images + -b ${BASELINE_CONF}/${filenameRef} + -t ${TEMP}/${filenameInput}.ppm + -n 3 + -p 4:4:4 + -m 4:4:4 + -s b_t_ + ) + + set_tests_properties(ETS-KDU-${filenameInput}-compare2ref + PROPERTIES DEPENDS + ETS-KDU-${filenameInput}-decode) + + add_test(NAME NR-KDU-${filenameInput}-compare2base + COMMAND compare_images + -b ${BASELINE_NR}/opj_${filenameRef} + -t ${TEMP}/${filenameInput}.ppm + -n 3 + -d + -s b_t_ + ) + + set_tests_properties(NR-KDU-${filenameInput}-compare2base + PROPERTIES DEPENDS + ETS-KDU-${filenameInput}-decode) +endforeach() + #--------------------------------------------------------------------------# #--------------------------------------------------------------------------# #--------------------------------------------------------------------------# From f54de95802a9f94cf673f2363d06f05d34d543c7 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 7 Mar 2014 17:23:19 +0000 Subject: [PATCH 257/333] [trunk] Upon failure, need to return proper return code --- src/bin/jp2/opj_decompress.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/bin/jp2/opj_decompress.c b/src/bin/jp2/opj_decompress.c index b19e01a9..44431f20 100644 --- a/src/bin/jp2/opj_decompress.c +++ b/src/bin/jp2/opj_decompress.c @@ -676,7 +676,6 @@ static void info_callback(const char *msg, void *client_data) { /* -------------------------------------------------------------------------- */ int main(int argc, char **argv) { - opj_dparameters_t parameters; /* decompression parameters */ opj_image_t* image = NULL; opj_stream_t *l_stream = NULL; /* Stream */ @@ -688,6 +687,7 @@ int main(int argc, char **argv) OPJ_INT32 num_images, imageno; img_fol_t img_fol; dircnt_t *dirptr = NULL; + int failed = 0; /* set decoding parameters to default values */ opj_set_default_decoder_parameters(¶meters); @@ -871,7 +871,8 @@ int main(int argc, char **argv) switch (parameters.cod_format) { case PXM_DFMT: /* PNM PGM PPM */ if (imagetopnm(image, parameters.outfile)) { - fprintf(stdout,"Outfile %s not generated\n",parameters.outfile); + fprintf(stderr,"Outfile %s not generated\n",parameters.outfile); + failed = 1; } else { fprintf(stdout,"Generated Outfile %s\n",parameters.outfile); @@ -961,7 +962,7 @@ int main(int argc, char **argv) opj_destroy_cstr_index(&cstr_index); } - return EXIT_SUCCESS; + return failed ? EXIT_FAILURE : EXIT_SUCCESS; } /*end main*/ From 2001932c56f7e66b6a1113cf28805a8b896a5e85 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 10 Mar 2014 08:13:05 +0000 Subject: [PATCH 258/333] [trunk] Remove 2 warnings about set but not used variables --- src/bin/common/color.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/bin/common/color.c b/src/bin/common/color.c index 6cb98497..e17be420 100644 --- a/src/bin/common/color.c +++ b/src/bin/common/color.c @@ -360,6 +360,9 @@ out_space, in_type,out_type ); +#else + (void)prec; + (void)in_space; #endif /* DEBUG_PROFILE */ transform = cmsCreateTransform(in_prof, in_type, From b4789129102adc8f0fbfe9c22230c196ecd39c03 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 10 Mar 2014 08:15:43 +0000 Subject: [PATCH 259/333] [trunk] remove a warning when using strict prototype --- src/lib/openjp2/t1_generate_luts.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/lib/openjp2/t1_generate_luts.c b/src/lib/openjp2/t1_generate_luts.c index d1843248..b2944d8c 100644 --- a/src/lib/openjp2/t1_generate_luts.c +++ b/src/lib/openjp2/t1_generate_luts.c @@ -181,7 +181,8 @@ static void dump_array16(int array[],int size){ printf("0x%04x\n};\n\n", array[size]); } -int main(){ +int main(int argc, char **argv) +{ int i, j; double u, v, t; @@ -190,6 +191,7 @@ int main(){ int lut_nmsedec_sig0[1 << T1_NMSEDEC_BITS]; int lut_nmsedec_ref[1 << T1_NMSEDEC_BITS]; int lut_nmsedec_ref0[1 << T1_NMSEDEC_BITS]; + (void)argc; (void)argv; printf("/* This file was automatically generated by t1_generate_luts.c */\n\n"); From e02ba05034de2d4bfb68419b0e4819441f9166e7 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 10 Mar 2014 08:25:08 +0000 Subject: [PATCH 260/333] [trunk] Fix warnings about shadow variables --- src/bin/jp2/convert.c | 23 ++++++++++++----------- src/bin/jp2/opj_compress.c | 6 +++--- src/lib/openjpip/jp2k_encoder.c | 4 ++-- tests/compare_images.c | 10 +++++----- 4 files changed, 22 insertions(+), 21 deletions(-) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index 1e578c07..72babbaa 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -573,7 +573,8 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters) unsigned char *table_R, *table_G, *table_B; unsigned int j, PAD = 0; - int x, y, index; + unsigned int x, y; + int index; int gray_scale = 1; int has_color; DWORD W, H; @@ -732,10 +733,10 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters) index = 0; - for(y = 0; y < (int)H; y++) + for(y = 0; y < H; y++) { unsigned char *scanline = RGB + (3 * (unsigned int)W + PAD) * ((unsigned int)H - 1 - (unsigned int)y); - for(x = 0; x < (int)W; x++) + for(x = 0; x < W; x++) { unsigned char *pixel = &scanline[3 * x]; image->comps[0].data[index] = pixel[2]; /* R */ @@ -862,8 +863,8 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters) { unsigned char *pix, *beyond; int *gray, *red, *green, *blue; - unsigned int x, y, max; - int i, c, c1; + unsigned int max; + int c, c1; unsigned char uc; if (Info_h.biClrUsed == 0) @@ -3126,15 +3127,15 @@ static int imagetoraw_common(opj_image_t * image, const char *outfile, OPJ_BOOL { if(image->comps[compno].sgnd == 1) { - union { signed short val; signed char vals[2]; } uc; + union { signed short val; signed char vals[2]; } uc16; mask = (1 << image->comps[compno].prec) - 1; ptr = image->comps[compno].data; for (line = 0; line < h; line++) { for(row = 0; row < w; row++) { curr = *ptr; if(curr > 32767 ) curr = 32767; else if( curr < -32768) curr = -32768; - uc.val = (signed short)(curr & mask); - res = fwrite(uc.vals, 1, 2, rawFile); + uc16.val = (signed short)(curr & mask); + res = fwrite(uc16.vals, 1, 2, rawFile); if( res < 2 ) { fprintf(stderr, "failed to write 2 byte for %s\n", outfile); goto fin; @@ -3145,15 +3146,15 @@ static int imagetoraw_common(opj_image_t * image, const char *outfile, OPJ_BOOL } else if(image->comps[compno].sgnd == 0) { - union { unsigned short val; unsigned char vals[2]; } uc; + union { unsigned short val; unsigned char vals[2]; } uc16; mask = (1 << image->comps[compno].prec) - 1; ptr = image->comps[compno].data; for (line = 0; line < h; line++) { for(row = 0; row < w; row++) { curr = *ptr; if(curr > 65536 ) curr = 65536; else if( curr < 0) curr = 0; - uc.val = (unsigned short)(curr & mask); - res = fwrite(uc.vals, 1, 2, rawFile); + uc16.val = (unsigned short)(curr & mask); + res = fwrite(uc16.vals, 1, 2, rawFile); if( res < 2 ) { fprintf(stderr, "failed to write 2 byte for %s\n", outfile); goto fin; diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index e42e88df..ffb76349 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -935,7 +935,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param float *lCurrentDoublePtr; float *lSpace; int *l_int_ptr; - int lNbComp = 0, lTotalComp, lMctComp, i; + int lNbComp = 0, lTotalComp, lMctComp, i2; size_t lStrLen, lStrFread; /* Open file */ @@ -972,14 +972,14 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param lTotalComp = lMctComp + lNbComp; lSpace = (float *) malloc((size_t)lTotalComp * sizeof(float)); lCurrentDoublePtr = lSpace; - for (i=0;ifirst; while( msg){ - if( isJPPstream){ + if( isjppstream){ if((msg->class_id == TILE_HEADER_MSG) && msg->csn == csn && last_tileID < msg->in_class_id) last_tileID = msg->in_class_id; } diff --git a/tests/compare_images.c b/tests/compare_images.c index fba89710..5dfd69d1 100644 --- a/tests/compare_images.c +++ b/tests/compare_images.c @@ -729,14 +729,14 @@ int main(int argc, char **argv) if ( (inParam.tabMSEvalues != NULL) && (inParam.tabPEAKvalues != NULL)) { - int it_comp; + int it_comp2; printf(" MSE values = ["); - for (it_comp = 0; it_comp < inParam.nbcomp; it_comp++) - printf(" %f ", inParam.tabMSEvalues[it_comp]); + for (it_comp2 = 0; it_comp2 < inParam.nbcomp; it_comp2++) + printf(" %f ", inParam.tabMSEvalues[it_comp2]); printf("]\n"); printf(" PEAK values = ["); - for (it_comp = 0; it_comp < inParam.nbcomp; it_comp++) - printf(" %f ", inParam.tabPEAKvalues[it_comp]); + for (it_comp2 = 0; it_comp2 < inParam.nbcomp; it_comp2++) + printf(" %f ", inParam.tabPEAKvalues[it_comp2]); printf("]\n"); printf(" Non-regression test = %d\n", inParam.nr_flag); } From 666ef53fd24e4816ae8f63e19943a0257f3e1869 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 10 Mar 2014 08:40:02 +0000 Subject: [PATCH 261/333] [trunk] Make sure to always initialize variable --- src/bin/jp2/convert.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index 72babbaa..c170db71 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -416,6 +416,7 @@ int imagetotga(opj_image_t * image, const char *outfile) { float scale; FILE *fdest; size_t res; + fails = 1; fdest = fopen(outfile, "wb"); if (!fdest) { From 24966ffbda1ef1ebb47a6a1056fa20ee3f8ed0c1 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 10 Mar 2014 09:36:14 +0000 Subject: [PATCH 262/333] [trunk] Fix compilation when TIFF lib is neither found nor compiled --- tests/compare_images.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/compare_images.c b/tests/compare_images.c index 5dfd69d1..01ccd8e5 100644 --- a/tests/compare_images.c +++ b/tests/compare_images.c @@ -242,8 +242,10 @@ static opj_image_t* readImageFromFileTIF(const char* filename, int nbFilenamePGX * TIFFOpen: /.../data/baseline/nonregression/opj_jp2_1.tif: Cannot open. * On Win32 this open a message box by default, so remove it from the test suite: */ +#ifdef OPJ_HAVE_LIBTIFF TIFFSetWarningHandler(NULL); TIFFSetErrorHandler(NULL); +#endif /* If separator is empty => nb file to read is equal to one*/ if ( strlen(separator) == 0 ) @@ -271,11 +273,13 @@ static opj_image_t* readImageFromFileTIF(const char* filename, int nbFilenamePGX filenameComponentPGX = createMultiComponentsFilename(filename, it_file, separator); /* Read the tif file corresponding to the component */ +#ifdef OPJ_HAVE_LIBTIFF image_read = tiftoimage(filenameComponentPGX, ¶meters); +#endif if (!image_read) { int it_free_data; - fprintf(stderr, "Unable to load pgx file\n"); + fprintf(stderr, "Unable to load TIF file\n"); free(param_image_read); From 7aee50de97436ff492b1655c4e43258492b86e64 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 10 Mar 2014 09:56:22 +0000 Subject: [PATCH 263/333] [trunk] First pass to cleanup compare_dump_files --- tests/compare_dump_files.c | 136 +++++++++++++++++-------------------- 1 file changed, 61 insertions(+), 75 deletions(-) diff --git a/tests/compare_dump_files.c b/tests/compare_dump_files.c index 6519d715..37178b13 100644 --- a/tests/compare_dump_files.c +++ b/tests/compare_dump_files.c @@ -62,7 +62,7 @@ static void compare_dump_files_help_display(void) { *******************************************************************************/ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) { - int sizemembasefile, sizememtestfile; + size_t sizemembasefile, sizememtestfile; int index; const char optlist[] = "b:t:"; int c; @@ -76,43 +76,40 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) while ((c = opj_getopt(argc, argv, optlist)) != -1) switch (c) { - case 'b': - sizemembasefile = (int)strlen(opj_optarg)+1; - param->base_filename = (char*) malloc((size_t)sizemembasefile); - param->base_filename[0] = '\0'; - strncpy(param->base_filename, opj_optarg, strlen(opj_optarg)); - param->base_filename[strlen(opj_optarg)] = '\0'; - /*printf("param->base_filename = %s [%d / %d]\n", param->base_filename, strlen(param->base_filename), sizemembasefile );*/ - break; - case 't': - sizememtestfile = (int) strlen(opj_optarg) + 1; - param->test_filename = (char*) malloc((size_t)sizememtestfile); - param->test_filename[0] = '\0'; - strncpy(param->test_filename, opj_optarg, strlen(opj_optarg)); - param->test_filename[strlen(opj_optarg)] = '\0'; - /*printf("param->test_filename = %s [%d / %d]\n", param->test_filename, strlen(param->test_filename), sizememtestfile);*/ - break; - case '?': - if ( (opj_optopt == 'b') || (opj_optopt == 't') ) - fprintf(stderr, "Option -%c requires an argument.\n", opj_optopt); - else - if (isprint(opj_optopt)) fprintf(stderr, "Unknown option `-%c'.\n", opj_optopt); - else fprintf(stderr, "Unknown option character `\\x%x'.\n", opj_optopt); - return 1; - default: - fprintf(stderr, "WARNING -> this option is not valid \"-%c %s\"\n", c, opj_optarg); - break; + case 'b': + sizemembasefile = strlen(opj_optarg) + 1; + param->base_filename = (char*) malloc(sizemembasefile); + strcpy(param->base_filename, opj_optarg); + /*printf("param->base_filename = %s [%d / %d]\n", param->base_filename, strlen(param->base_filename), sizemembasefile );*/ + break; + case 't': + sizememtestfile = strlen(opj_optarg) + 1; + param->test_filename = (char*) malloc(sizememtestfile); + strcpy(param->test_filename, opj_optarg); + /*printf("param->test_filename = %s [%d / %d]\n", param->test_filename, strlen(param->test_filename), sizememtestfile);*/ + break; + case '?': + if ( (opj_optopt == 'b') || (opj_optopt == 't') ) + fprintf(stderr, "Option -%c requires an argument.\n", opj_optopt); + else + if (isprint(opj_optopt)) fprintf(stderr, "Unknown option `-%c'.\n", opj_optopt); + else fprintf(stderr, "Unknown option character `\\x%x'.\n", opj_optopt); + return 1; + default: + fprintf(stderr, "WARNING -> this option is not valid \"-%c %s\"\n", c, opj_optarg); + break; } if (opj_optind != argc) { for (index = opj_optind; index < argc; index++) fprintf(stderr,"Non-option argument %s\n", argv[index]); - return EXIT_FAILURE; + return 1; } - return EXIT_SUCCESS; + return 0; } + /******************************************************************************* * MAIN *******************************************************************************/ @@ -124,29 +121,24 @@ int main(int argc, char **argv) int same = 1; unsigned long l=1, pos; - if( parse_cmdline_cmp(argc, argv, &inParam) == EXIT_FAILURE ) + if( parse_cmdline_cmp(argc, argv, &inParam) == 1 ) { compare_dump_files_help_display(); - if (!inParam.base_filename) free(inParam.base_filename); - if (!inParam.test_filename) free(inParam.test_filename); - return EXIT_FAILURE; + goto cleanup; } /* Display Parameters*/ printf("******Parameters********* \n"); printf(" base_filename = %s\n" - " test_filename = %s\n", - inParam.base_filename, inParam.test_filename); + " test_filename = %s\n", + inParam.base_filename, inParam.test_filename); printf("************************* \n"); /* open base file */ printf("Try to open: %s for reading ... ", inParam.base_filename); if((fbase = fopen(inParam.base_filename, "rb"))==NULL) { - printf("Failed.\n"); - free(inParam.base_filename); - free(inParam.test_filename); - return EXIT_FAILURE; + goto cleanup; } printf("Ok.\n"); @@ -154,11 +146,7 @@ int main(int argc, char **argv) printf("Try to open: %s for reading ... ", inParam.test_filename); if((ftest = fopen(inParam.test_filename, "rb"))==NULL) { - printf("Failed.\n"); - fclose(fbase); - free(inParam.base_filename); - free(inParam.test_filename); - return EXIT_FAILURE; + goto cleanup; } printf("Ok.\n"); @@ -170,14 +158,14 @@ int main(int argc, char **argv) if(ferror(fbase)) { printf("Error reading base file.\n"); - return EXIT_FAILURE; + goto cleanup; } chtest = fgetc(ftest); if(ferror(ftest)) { printf("Error reading test file.\n"); - return EXIT_FAILURE; + goto cleanup; } /* CRLF problem (Baseline must be always generated by unix platform)*/ @@ -206,29 +194,30 @@ int main(int argc, char **argv) strbase = (char *) malloc((size_t)nbytes + 1); strtest = (char *) malloc((size_t)nbytes + 1); - if (fgets(strbase, nbytes, fbase) == NULL) - fprintf(stderr,"\nWARNING: fgets return a NULL value"); - else - { - if (fgets(strtest, nbytes, ftest) == NULL) - fprintf(stderr,"\nWARNING: fgets return a NULL value"); - else - { - strbase_d = (char *) malloc(strlen(strbase)+1); - strtest_d = (char *) malloc(strlen(strtest)+1); - strncpy(strbase_d, strbase, strlen(strbase)-1); - strncpy(strtest_d, strtest, strlen(strtest)-(size_t)CRLF_shift); - strbase_d[strlen(strbase)-1] = '\0'; - strtest_d[strlen(strtest)-(size_t)CRLF_shift] = '\0'; - printf("<%s> vs. <%s>\n", strbase_d, strtest_d); - free(strbase_d);free(strtest_d); - } - } + if (fgets(strbase, nbytes, fbase) == NULL) + fprintf(stderr,"\nWARNING: fgets return a NULL value"); + else + { + if (fgets(strtest, nbytes, ftest) == NULL) + fprintf(stderr,"\nWARNING: fgets return a NULL value"); + else + { + strbase_d = (char *) malloc(strlen(strbase)+1); + strtest_d = (char *) malloc(strlen(strtest)+1); + strncpy(strbase_d, strbase, strlen(strbase)-1); + strncpy(strtest_d, strtest, strlen(strtest)-(size_t)CRLF_shift); + strbase_d[strlen(strbase)-1] = '\0'; + strtest_d[strlen(strtest)-(size_t)CRLF_shift] = '\0'; + printf("<%s> vs. <%s>\n", strbase_d, strtest_d); + free(strbase_d); + free(strtest_d); + } + } - free(strbase);free(strtest); - - same = 0; + free(strbase); + free(strtest); + same = 0; break; } else @@ -241,18 +230,15 @@ int main(int argc, char **argv) } } + printf("\n***** TEST SUCCEED: Files are the same. *****\n"); +cleanup: /*Close File*/ - fclose(fbase); - fclose(ftest); + if(fbase) fclose(fbase); + if(ftell) fclose(ftest); /* Free memory*/ free(inParam.base_filename); free(inParam.test_filename); - if(same) - { - printf("\n***** TEST SUCCEED: Files are the same. *****\n"); - return EXIT_SUCCESS; - } - else return EXIT_FAILURE; + return same ? EXIT_SUCCESS : EXIT_FAILURE; } From 9155e9891130689d3cc89aaac798efc86a9b9e7b Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 10 Mar 2014 10:09:30 +0000 Subject: [PATCH 264/333] [trunk] rework actual code to handle DOS/UNIX end of lines in a transparent manner. This will help cross compilation cases --- tests/compare_dump_files.c | 88 ++++++-------------------------------- 1 file changed, 14 insertions(+), 74 deletions(-) diff --git a/tests/compare_dump_files.c b/tests/compare_dump_files.c index 37178b13..1f457501 100644 --- a/tests/compare_dump_files.c +++ b/tests/compare_dump_files.c @@ -29,13 +29,13 @@ * * Created on: 25 juil. 2011 * Author: mickael - * BASELINE MUST BE GENERATED BY UNIX PLATFORM REGARDING TO THE CRLF PROBLEM */ #include #include #include #include +#include #include "opj_getopt.h" @@ -117,9 +117,11 @@ int main(int argc, char **argv) { test_cmp_parameters inParam; FILE *fbase=NULL, *ftest=NULL; - int chbase, chtest; int same = 1; - unsigned long l=1, pos; + char lbase[256]; + char strbase[256]; + char ltest[256]; + char strtest[256]; if( parse_cmdline_cmp(argc, argv, &inParam) == 1 ) { @@ -150,86 +152,24 @@ int main(int argc, char **argv) } printf("Ok.\n"); - pos=(unsigned long)ftell(fbase); - - while(!feof(fbase)) + while (fgets(lbase, sizeof(lbase), fbase) && fgets(ltest,sizeof(ltest),ftest)) { - chbase = fgetc(fbase); - if(ferror(fbase)) + int nbase = sscanf(lbase, "%255[^\r\n]", strbase); + int ntest = sscanf(ltest, "%255[^\r\n]", strtest); + assert( nbase != 255 && ntest != 255 ); + if( nbase != 1 || ntest != 1 ) { - printf("Error reading base file.\n"); + fprintf(stderr, "could not parse line from files\n" ); goto cleanup; } - - chtest = fgetc(ftest); - if(ferror(ftest)) + if( strcmp( strbase, strtest ) != 0 ) { - printf("Error reading test file.\n"); + fprintf(stderr,"<%s> vs. <%s>\n", strbase, strtest); goto cleanup; } - - /* CRLF problem (Baseline must be always generated by unix platform)*/ - if (chbase == '\n' && chtest == '\r') - if (fgetc(ftest) == '\n') - chtest = '\n'; - - if(chbase != chtest) - { - int nbytes = 2048; - int CRLF_shift=1; - char *strbase, *strtest, *strbase_d, *strtest_d; - - printf("Files differ at line %lu:\n", l); - fseek(fbase,(long)pos,SEEK_SET); - - /* Take into account CRLF characters when we write \n into - // dump file when we used WIN platform*/ -#ifdef _WIN32 - CRLF_shift = 2; - fseek(ftest,pos + l - 1,SEEK_SET); -#else - fseek(ftest,(long)pos,SEEK_SET); -#endif - - strbase = (char *) malloc((size_t)nbytes + 1); - strtest = (char *) malloc((size_t)nbytes + 1); - - if (fgets(strbase, nbytes, fbase) == NULL) - fprintf(stderr,"\nWARNING: fgets return a NULL value"); - else - { - if (fgets(strtest, nbytes, ftest) == NULL) - fprintf(stderr,"\nWARNING: fgets return a NULL value"); - else - { - strbase_d = (char *) malloc(strlen(strbase)+1); - strtest_d = (char *) malloc(strlen(strtest)+1); - strncpy(strbase_d, strbase, strlen(strbase)-1); - strncpy(strtest_d, strtest, strlen(strtest)-(size_t)CRLF_shift); - strbase_d[strlen(strbase)-1] = '\0'; - strtest_d[strlen(strtest)-(size_t)CRLF_shift] = '\0'; - printf("<%s> vs. <%s>\n", strbase_d, strtest_d); - free(strbase_d); - free(strtest_d); - } - } - - free(strbase); - free(strtest); - - same = 0; - break; - } - else - { - if (chbase == '\n') - { - l++; - pos = (unsigned long)ftell(fbase); - } - } } + same = 0; printf("\n***** TEST SUCCEED: Files are the same. *****\n"); cleanup: /*Close File*/ From f7bc0b49cbdd68e2c16f623d7c6617ded6ace0bf Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 10 Mar 2014 10:12:25 +0000 Subject: [PATCH 265/333] [trunk] Fix typo in the code --- tests/compare_dump_files.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/compare_dump_files.c b/tests/compare_dump_files.c index 1f457501..10245339 100644 --- a/tests/compare_dump_files.c +++ b/tests/compare_dump_files.c @@ -174,7 +174,7 @@ int main(int argc, char **argv) cleanup: /*Close File*/ if(fbase) fclose(fbase); - if(ftell) fclose(ftest); + if(ftest) fclose(ftest); /* Free memory*/ free(inParam.base_filename); From 76af73bc7257ce09ff35c32439bc7714c4164a4a Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 10 Mar 2014 10:43:45 +0000 Subject: [PATCH 266/333] [trunk] Fix inversion in code convention --- tests/compare_dump_files.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/compare_dump_files.c b/tests/compare_dump_files.c index 10245339..946c92a5 100644 --- a/tests/compare_dump_files.c +++ b/tests/compare_dump_files.c @@ -117,7 +117,7 @@ int main(int argc, char **argv) { test_cmp_parameters inParam; FILE *fbase=NULL, *ftest=NULL; - int same = 1; + int same = 0; char lbase[256]; char strbase[256]; char ltest[256]; @@ -169,7 +169,7 @@ int main(int argc, char **argv) } } - same = 0; + same = 1; printf("\n***** TEST SUCCEED: Files are the same. *****\n"); cleanup: /*Close File*/ From 9a52b30c3d9aba4de5c21c555b0c159da7f423f4 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 10 Mar 2014 10:52:09 +0000 Subject: [PATCH 267/333] [trunk] Properly handle PGM file generation when fullpath is specified in the cmd line This will break a very old behavior (since 2005), but avoid writing in un-expected places for users This also make the behavior similar with PGX file generation --- src/bin/jp2/convert.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index c170db71..e946ca18 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -2106,8 +2106,15 @@ if(v > 65535) v = 65535; else if(v < 0) v = 0; for (compno = 0; compno < ncomp; compno++) { - if (ncomp > 1) - sprintf(destname, "%d.%s", compno, outfile); + if (ncomp > 1) + { + /*sprintf(destname, "%d.%s", compno, outfile);*/ + const size_t olen = strlen(outfile); + const size_t dotpos = olen - 4; + + strncpy(destname, outfile, dotpos); + sprintf(destname+dotpos, "_%d.pgm", compno); + } else sprintf(destname, "%s", outfile); From 836ec0592074daf8c7bcbb9495be02b4be1aae87 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 10 Mar 2014 12:20:55 +0000 Subject: [PATCH 268/333] [trunk] Handle multi components files with PGM outputs --- tests/compare_images.c | 48 ++++++++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/tests/compare_images.c b/tests/compare_images.c index 01ccd8e5..88d874ba 100644 --- a/tests/compare_images.c +++ b/tests/compare_images.c @@ -83,18 +83,29 @@ static void compare_images_help_display(void) { fprintf(stdout,"\nList of parameters for the compare_images function \n"); fprintf(stdout,"\n"); - fprintf(stdout," -b \t REQUIRED \t filename to the reference/baseline PGX image \n"); - fprintf(stdout," -t \t REQUIRED \t filename to the test PGX image\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," -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 image with different components, " + fprintf(stdout," -s \t OPTIONAL \t 1 or 2 filename separator to take into account PGX/PNM image with different components, " "please indicate b or t before separator to indicate respectively the separator " "for ref/base file and for test file. \n"); fprintf(stdout," -d \t OPTIONAL \t indicate if you want to run this function as conformance test or as non regression test\n"); fprintf(stdout,"\n"); } +static int get_decod_format_from_string(const char *filename) +{ + const int dot = '.'; + char * ext = strrchr(filename, dot); + if( strcmp(ext,".pgx") == 0 ) return PGX_DFMT; + if( strcmp(ext,".tif") == 0 ) return TIF_DFMT; + if( strcmp(ext,".ppm") == 0 ) return PXM_DFMT; + return -1; +} + + /******************************************************************************* * Create filenames from a filename using separator and nb components * (begin from 0) @@ -105,6 +116,7 @@ static char* createMultiComponentsFilename(const char* inFilename, const int ind char *outFilename, *ptr; const char token = '.'; int posToken = 0; + int decod_format; /*printf("inFilename = %s\n", inFilename);*/ if ((ptr = strrchr(inFilename, token)) != NULL) @@ -131,7 +143,15 @@ static char* createMultiComponentsFilename(const char* inFilename, const int ind sprintf(s, "%i", indexF); strcat(outFilename, s); - strcat(outFilename, ".pgx"); + decod_format = get_decod_format_from_string(inFilename); + if( decod_format == PGX_DFMT ) + { + strcat(outFilename, ".pgx"); + } + else if( decod_format == PXM_DFMT ) + { + strcat(outFilename, ".pgm"); + } /*printf("outfilename: %s\n", outFilename);*/ return outFilename; @@ -467,18 +487,14 @@ typedef struct test_cmp_parameters } test_cmp_parameters; -/* return decode format PGX / TIF , return -1 on error */ +/* return decode format PGX / TIF / PPM , return -1 on error */ static int get_decod_format(test_cmp_parameters* param) { - const int dot = '.'; - char * base_ext = strrchr(param->base_filename, dot); - char * test_ext = strrchr(param->test_filename, dot); - if( !base_ext || !test_ext ) return -1; - if( strcmp(base_ext,test_ext) != 0 ) return -1; - if( strcmp(base_ext,".pgx") == 0 ) return PGX_DFMT; - if( strcmp(base_ext,".tif") == 0 ) return TIF_DFMT; - if( strcmp(base_ext,".ppm") == 0 ) return PXM_DFMT; - return -1; + int base_format = get_decod_format_from_string( param->base_filename ); + int test_format = get_decod_format_from_string( param->test_filename ); + if( base_format != test_format ) return -1; + /* handle case -1: */ + return base_format; } /******************************************************************************* @@ -781,7 +797,7 @@ int main(int argc, char **argv) } else if( decod_format == PXM_DFMT ) { - imageBase = readImageFromFilePPM( inParam.base_filename, nbFilenamePGXbase, ""); + imageBase = readImageFromFilePPM( inParam.base_filename, nbFilenamePGXbase, inParam.separator_base); if ( imageBase == NULL ) goto cleanup; } @@ -807,7 +823,7 @@ int main(int argc, char **argv) } else if( decod_format == PXM_DFMT ) { - imageTest = readImageFromFilePPM(inParam.test_filename, nbFilenamePGXtest, ""); + imageTest = readImageFromFilePPM(inParam.test_filename, nbFilenamePGXtest, inParam.separator_test); if ( imageTest == NULL ) goto cleanup; } From b01c1240cf20bebe6b315a3a9faffe9f8142598b Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 10 Mar 2014 12:22:56 +0000 Subject: [PATCH 269/333] [trunk] Fix simple sign conversion warnings only visible on 32bits arch --- src/bin/jp2/convert.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index e946ca18..90684a2c 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -712,7 +712,7 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters) /* Place the cursor at the beginning of the image information */ fseek(IN, 0, SEEK_SET); - fseek(IN, File_h.bfOffBits, SEEK_SET); + fseek(IN, (long)File_h.bfOffBits, SEEK_SET); W = Info_h.biWidth; H = Info_h.biHeight; @@ -773,7 +773,7 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters) /* Place the cursor at the beginning of the image information */ fseek(IN, 0, SEEK_SET); - fseek(IN, File_h.bfOffBits, SEEK_SET); + fseek(IN, (long)File_h.bfOffBits, SEEK_SET); W = Info_h.biWidth; H = Info_h.biHeight; @@ -925,7 +925,7 @@ opj_image_t* bmptoimage(const char *filename, opj_cparameters_t *parameters) /* Place the cursor at the beginning of the image information */ fseek(IN, 0, SEEK_SET); - fseek(IN, File_h.bfOffBits, SEEK_SET); + fseek(IN, (long)File_h.bfOffBits, SEEK_SET); W = Info_h.biWidth; H = Info_h.biHeight; From 856fc0652f6739fe93821d6da635a46da288791e Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 10 Mar 2014 13:05:20 +0000 Subject: [PATCH 270/333] [trunk] Properly handle number of components to run kakadu test suite. Update issue 266 --- tests/compare_images.c | 38 ++++++++++++-------------------- tests/conformance/CMakeLists.txt | 12 ++++++---- 2 files changed, 22 insertions(+), 28 deletions(-) diff --git a/tests/compare_images.c b/tests/compare_images.c index 88d874ba..2e101246 100644 --- a/tests/compare_images.c +++ b/tests/compare_images.c @@ -115,13 +115,13 @@ static char* createMultiComponentsFilename(const char* inFilename, const int ind char s[255]; char *outFilename, *ptr; const char token = '.'; - int posToken = 0; + size_t posToken = 0; int decod_format; /*printf("inFilename = %s\n", inFilename);*/ if ((ptr = strrchr(inFilename, token)) != NULL) { - posToken = (int) (strlen(inFilename) - strlen(ptr)); + posToken = strlen(inFilename) - strlen(ptr); /*printf("Position of %c character inside inFilename = %d\n", token, posToken);*/ } else @@ -132,14 +132,10 @@ static char* createMultiComponentsFilename(const char* inFilename, const int ind return outFilename; } - outFilename = (char*)malloc((size_t)(posToken + 7) * sizeof(char)); /*6*/ - - strncpy(outFilename, inFilename, (size_t)posToken); - - outFilename[posToken] = '\0'; + outFilename = (char*)malloc((posToken + 7) * sizeof(char)); /*6*/ + strncpy(outFilename, inFilename, posToken); strcat(outFilename, separator); - sprintf(s, "%i", indexF); strcat(outFilename, s); @@ -504,7 +500,7 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) { char *MSElistvalues = NULL; char *PEAKlistvalues= NULL; char *separatorList = NULL; - int sizemembasefile, sizememtestfile; + size_t sizemembasefile, sizememtestfile; int index, flagM=0, flagP=0; const char optlist[] = "b:t:n:m:p:s:d"; int c; @@ -525,19 +521,15 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) switch (c) { case 'b': - sizemembasefile = (int)strlen(opj_optarg)+1; - param->base_filename = (char*) malloc((size_t)sizemembasefile); - param->base_filename[0] = '\0'; - strncpy(param->base_filename, opj_optarg, strlen(opj_optarg)); - param->base_filename[strlen(opj_optarg)] = '\0'; + sizemembasefile = strlen(opj_optarg) + 1; + param->base_filename = (char*) malloc(sizemembasefile); + strcpy(param->base_filename, opj_optarg); /*printf("param->base_filename = %s [%d / %d]\n", param->base_filename, strlen(param->base_filename), sizemembasefile );*/ break; case 't': - sizememtestfile = (int) strlen(opj_optarg) + 1; - param->test_filename = (char*) malloc((size_t)sizememtestfile); - param->test_filename[0] = '\0'; - strncpy(param->test_filename, opj_optarg, strlen(opj_optarg)); - param->test_filename[strlen(opj_optarg)] = '\0'; + sizememtestfile = strlen(opj_optarg) + 1; + param->test_filename = (char*) malloc(sizememtestfile); + strcpy(param->test_filename, opj_optarg); /*printf("param->test_filename = %s [%d / %d]\n", param->test_filename, strlen(param->test_filename), sizememtestfile);*/ break; case 'n': @@ -600,11 +592,9 @@ static int parse_cmdline_cmp(int argc, char **argv, test_cmp_parameters* param) if( (strlen(separatorList) ==2) || (strlen(separatorList) ==4) ) { /* keep original string*/ - int sizeseplist = (int)strlen(separatorList)+1; - char* separatorList2 = (char*)malloc( (size_t)sizeseplist ); - separatorList2[0] = '\0'; - strncpy(separatorList2, separatorList, strlen(separatorList)); - separatorList2[strlen(separatorList)] = '\0'; + size_t sizeseplist = strlen(separatorList)+1; + char* separatorList2 = (char*)malloc( sizeseplist ); + strcpy(separatorList2, separatorList); /*printf("separatorList2 = %s [%d / %d]\n", separatorList2, strlen(separatorList2), sizeseplist);*/ if (strlen(separatorList) == 2) /* one separator behind b or t*/ diff --git a/tests/conformance/CMakeLists.txt b/tests/conformance/CMakeLists.txt index 358a3f35..e00e9853 100644 --- a/tests/conformance/CMakeLists.txt +++ b/tests/conformance/CMakeLists.txt @@ -516,14 +516,19 @@ foreach(kdu_file ${kdu_j2k_conf_files}) -o ${TEMP}/${filenameInput}.ppm ) + if("${kdu_file}" STREQUAL "a6_mono_colr") + set(kdu_test_args "-n 4 -s b_t_") + else() + set(kdu_test_args "-n 1") + endif() + add_test(NAME ETS-KDU-${filenameInput}-compare2ref COMMAND compare_images -b ${BASELINE_CONF}/${filenameRef} -t ${TEMP}/${filenameInput}.ppm - -n 3 + ${kdu_test_args} -p 4:4:4 -m 4:4:4 - -s b_t_ ) set_tests_properties(ETS-KDU-${filenameInput}-compare2ref @@ -534,9 +539,8 @@ foreach(kdu_file ${kdu_j2k_conf_files}) COMMAND compare_images -b ${BASELINE_NR}/opj_${filenameRef} -t ${TEMP}/${filenameInput}.ppm - -n 3 + ${kdu_test_args} -d - -s b_t_ ) set_tests_properties(NR-KDU-${filenameInput}-compare2base From aea18173d190f216e2f4228a3dc6fb86dbe724b9 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 10 Mar 2014 13:31:51 +0000 Subject: [PATCH 271/333] [trunk] Tweak JP2 conformance test suite add documentation --- tests/conformance/CMakeLists.txt | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/conformance/CMakeLists.txt b/tests/conformance/CMakeLists.txt index e00e9853..fb29f27f 100644 --- a/tests/conformance/CMakeLists.txt +++ b/tests/conformance/CMakeLists.txt @@ -426,7 +426,8 @@ endforeach() # compare to ref file # non regression comparison -# Tolerances given by Table G.1 +# Tolerances given by Part 4 - Table G.1 +# Peak is set to 4 only foreach(numFileJP2 RANGE 1 9) @@ -434,9 +435,6 @@ foreach(numFileJP2 RANGE 1 9) set( filenameInput "file${numFileJP2}.jp2" ) set( filenameRef jp2_${numFileJP2}.tif ) - # Get corresponding tests parameters - list(GET JP2_PEAK_list ${numFileJP2} PEAK_limit) - add_test(NAME ETS-JP2-${filenameInput}-decode COMMAND opj_decompress -i ${INPUT_CONF}/${filenameInput} @@ -449,7 +447,7 @@ foreach(numFileJP2 RANGE 1 9) -t ${TEMP}/${filenameInput}.tif -n 3 -p 4:4:4 - -m 4:4:4 + -m 1:1:1 -s b_t_ ) From 4de95f320f8127d2d1d35e594b53ecf53c4c6345 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 10 Mar 2014 13:51:16 +0000 Subject: [PATCH 272/333] [trunk] Run richter test suite, correct a regression introduced in r2668 --- tests/compare_images.c | 1 + tests/conformance/CMakeLists.txt | 61 ++++++++++++++++++++++++++++++-- 2 files changed, 59 insertions(+), 3 deletions(-) diff --git a/tests/compare_images.c b/tests/compare_images.c index 2e101246..a9a44ca7 100644 --- a/tests/compare_images.c +++ b/tests/compare_images.c @@ -135,6 +135,7 @@ static char* createMultiComponentsFilename(const char* inFilename, const int ind outFilename = (char*)malloc((posToken + 7) * sizeof(char)); /*6*/ strncpy(outFilename, inFilename, posToken); + outFilename[posToken] = '\0'; strcat(outFilename, separator); sprintf(s, "%i", indexF); strcat(outFilename, s); diff --git a/tests/conformance/CMakeLists.txt b/tests/conformance/CMakeLists.txt index fb29f27f..85c2cf86 100644 --- a/tests/conformance/CMakeLists.txt +++ b/tests/conformance/CMakeLists.txt @@ -515,9 +515,9 @@ foreach(kdu_file ${kdu_j2k_conf_files}) ) if("${kdu_file}" STREQUAL "a6_mono_colr") - set(kdu_test_args "-n 4 -s b_t_") + set(kdu_test_args -n 4 -s b_t_) else() - set(kdu_test_args "-n 1") + set(kdu_test_args -n 1) endif() add_test(NAME ETS-KDU-${filenameInput}-compare2ref @@ -526,7 +526,7 @@ foreach(kdu_file ${kdu_j2k_conf_files}) -t ${TEMP}/${filenameInput}.ppm ${kdu_test_args} -p 4:4:4 - -m 4:4:4 + -m 1:1:1 ) set_tests_properties(ETS-KDU-${filenameInput}-compare2ref @@ -546,6 +546,61 @@ foreach(kdu_file ${kdu_j2k_conf_files}) ETS-KDU-${filenameInput}-decode) endforeach() +#-------------------------------------------------------------------------- +# Tests about Richter/J2K file +# try to decode +# compare to ref file +# non regression comparison + +# Tolerances given by ??? + +set(richter_jp2_conf_files + subsampling_1 + subsampling_2 + zoo1 + zoo2 +) + +foreach(r_file ${richter_jp2_conf_files}) + + # Build filenames + set( filenameInput "${r_file}.jp2" ) + set( filenameRef "${r_file}.ppm" ) + + add_test(NAME ETS-RIC-${filenameInput}-decode + COMMAND opj_decompress + -i ${INPUT_CONF}/${filenameInput} + -o ${TEMP}/${filenameInput}.ppm + ) + + set(ric_test_args -n 1) + + add_test(NAME ETS-RIC-${filenameInput}-compare2ref + COMMAND compare_images + -b ${BASELINE_CONF}/${filenameRef} + -t ${TEMP}/${filenameInput}.ppm + ${ric_test_args} + -p 4:4:4 + -m 2:2:2 + ) + + set_tests_properties(ETS-RIC-${filenameInput}-compare2ref + PROPERTIES DEPENDS + ETS-RIC-${filenameInput}-decode) + + add_test(NAME NR-RIC-${filenameInput}-compare2base + COMMAND compare_images + -b ${BASELINE_NR}/opj_${filenameRef} + -t ${TEMP}/${filenameInput}.ppm + ${ric_test_args} + -d + ) + + set_tests_properties(NR-RIC-${filenameInput}-compare2base + PROPERTIES DEPENDS + ETS-RIC-${filenameInput}-decode) +endforeach() + #--------------------------------------------------------------------------# #--------------------------------------------------------------------------# #--------------------------------------------------------------------------# From 8411ed4f80963cd8404d0e0b504bf061a84a28ba Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 10 Mar 2014 14:05:25 +0000 Subject: [PATCH 273/333] [trunk] Remove warning about sign conversion in color.c Update issue 256 --- src/bin/common/color.c | 57 +++++++++++++++++++++--------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/src/bin/common/color.c b/src/bin/common/color.c index e17be420..5024ac9e 100644 --- a/src/bin/common/color.c +++ b/src/bin/common/color.c @@ -86,19 +86,19 @@ static void sycc444_to_rgb(opj_image_t *img) const int *y, *cb, *cr; int maxw, maxh, max, i, offset, upb; - i = img->comps[0].prec; + i = (int)img->comps[0].prec; offset = 1<<(i - 1); upb = (1<comps[0].w; maxh = img->comps[0].h; + maxw = (int)img->comps[0].w; maxh = (int)img->comps[0].h; max = maxw * maxh; y = img->comps[0].data; cb = img->comps[1].data; cr = img->comps[2].data; - d0 = r = (int*)malloc(sizeof(int) * max); - d1 = g = (int*)malloc(sizeof(int) * max); - d2 = b = (int*)malloc(sizeof(int) * max); + d0 = r = (int*)malloc(sizeof(int) * (size_t)max); + d1 = g = (int*)malloc(sizeof(int) * (size_t)max); + d2 = b = (int*)malloc(sizeof(int) * (size_t)max); for(i = 0; i < max; ++i) { @@ -119,19 +119,19 @@ static void sycc422_to_rgb(opj_image_t *img) int maxw, maxh, max, offset, upb; int i, j; - i = img->comps[0].prec; + i = (int)img->comps[0].prec; offset = 1<<(i - 1); upb = (1<comps[0].w; maxh = img->comps[0].h; + maxw = (int)img->comps[0].w; maxh = (int)img->comps[0].h; max = maxw * maxh; y = img->comps[0].data; cb = img->comps[1].data; cr = img->comps[2].data; - d0 = r = (int*)malloc(sizeof(int) * max); - d1 = g = (int*)malloc(sizeof(int) * max); - d2 = b = (int*)malloc(sizeof(int) * max); + d0 = r = (int*)malloc(sizeof(int) * (size_t)max); + d1 = g = (int*)malloc(sizeof(int) * (size_t)max); + d2 = b = (int*)malloc(sizeof(int) * (size_t)max); for(i=0; i < maxh; ++i) { @@ -150,8 +150,8 @@ static void sycc422_to_rgb(opj_image_t *img) free(img->comps[1].data); img->comps[1].data = d1; free(img->comps[2].data); img->comps[2].data = d2; - img->comps[1].w = maxw; img->comps[1].h = maxh; - img->comps[2].w = maxw; img->comps[2].h = maxh; + img->comps[1].w = (OPJ_UINT32)maxw; img->comps[1].h = (OPJ_UINT32)maxh; + img->comps[2].w = (OPJ_UINT32)maxw; img->comps[2].h = (OPJ_UINT32)maxh; img->comps[1].dx = img->comps[0].dx; img->comps[2].dx = img->comps[0].dx; img->comps[1].dy = img->comps[0].dy; @@ -166,19 +166,19 @@ static void sycc420_to_rgb(opj_image_t *img) int maxw, maxh, max, offset, upb; int i, j; - i = img->comps[0].prec; + i = (int)img->comps[0].prec; offset = 1<<(i - 1); upb = (1<comps[0].w; maxh = img->comps[0].h; + maxw = (int)img->comps[0].w; maxh = (int)img->comps[0].h; max = maxw * maxh; y = img->comps[0].data; cb = img->comps[1].data; cr = img->comps[2].data; - d0 = r = (int*)malloc(sizeof(int) * max); - d1 = g = (int*)malloc(sizeof(int) * max); - d2 = b = (int*)malloc(sizeof(int) * max); + d0 = r = (int*)malloc(sizeof(int) * (size_t)max); + d1 = g = (int*)malloc(sizeof(int) * (size_t)max); + d2 = b = (int*)malloc(sizeof(int) * (size_t)max); for(i=0; i < maxh; i += 2) { @@ -209,8 +209,8 @@ static void sycc420_to_rgb(opj_image_t *img) free(img->comps[1].data); img->comps[1].data = d1; free(img->comps[2].data); img->comps[2].data = d2; - img->comps[1].w = maxw; img->comps[1].h = maxh; - img->comps[2].w = maxw; img->comps[2].h = maxh; + img->comps[1].w = (OPJ_UINT32)maxw; img->comps[1].h = (OPJ_UINT32)maxh; + img->comps[2].w = (OPJ_UINT32)maxw; img->comps[2].h = (OPJ_UINT32)maxh; img->comps[1].dx = img->comps[0].dx; img->comps[2].dx = img->comps[0].dx; img->comps[1].dy = img->comps[0].dy; @@ -302,8 +302,9 @@ void color_apply_icc_profile(opj_image_t *image) intent = cmsGetHeaderRenderingIntent(in_prof); - max_w = image->comps[0].w; max_h = image->comps[0].h; - prec = image->comps[0].prec; + max_w = (int)image->comps[0].w; + max_h = (int)image->comps[0].h; + prec = (int)image->comps[0].prec; oldspace = image->color_space; if(out_space == cmsSigRgbData) /* enumCS 16 */ @@ -392,7 +393,7 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. " { unsigned short *inbuf, *outbuf, *in, *out; max = max_w * max_h; - nr_samples = (cmsUInt32Number)(max * 3 * sizeof(unsigned short)); + nr_samples = (cmsUInt32Number)max * 3 * (cmsUInt32Number)sizeof(unsigned short); in = inbuf = (unsigned short*)malloc(nr_samples); out = outbuf = (unsigned short*)malloc(nr_samples); @@ -407,7 +408,7 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. " *in++ = (unsigned short)*b++; } - cmsDoTransform(transform, inbuf, outbuf, max); + cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); r = image->comps[0].data; g = image->comps[1].data; @@ -424,8 +425,8 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. " else /* GRAY, GRAYA */ { unsigned char *in, *inbuf, *out, *outbuf; - - max = max_w * max_h; nr_samples = max * 3 * sizeof(unsigned char); + max = max_w * max_h; + nr_samples = (cmsUInt32Number)max * 3 * sizeof(unsigned char); in = inbuf = (unsigned char*)malloc(nr_samples); out = outbuf = (unsigned char*)malloc(nr_samples); @@ -438,8 +439,8 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. " image->comps[1] = image->comps[0]; image->comps[2] = image->comps[0]; - image->comps[1].data = (int*)calloc(max, sizeof(int)); - image->comps[2].data = (int*)calloc(max, sizeof(int)); + image->comps[1].data = (int*)calloc((size_t)max, sizeof(int)); + image->comps[2].data = (int*)calloc((size_t)max, sizeof(int)); image->numcomps += 2; @@ -449,7 +450,7 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. " { *in++ = (unsigned char)*r++; } - cmsDoTransform(transform, inbuf, outbuf, max); + cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); r = image->comps[0].data; g = image->comps[1].data; From c02c1432e89cca24f20f04266c332a94741a4520 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 10 Mar 2014 14:15:27 +0000 Subject: [PATCH 274/333] [trunk] Remove a set of warning about sign conversion Update issue 266 --- src/lib/openjp2/j2k.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index b22f4790..0752eab2 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -7728,12 +7728,12 @@ OPJ_BOOL opj_j2k_update_image_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data, opj_im l_res->x0, l_res->x1, l_res->y0, l_res->y1); }*/ - l_width_src = (l_res->x1 - l_res->x0); - l_height_src = (l_res->y1 - l_res->y0); + l_width_src = (OPJ_UINT32)(l_res->x1 - l_res->x0); + l_height_src = (OPJ_UINT32)(l_res->y1 - l_res->y0); /* Border of the current output component*/ - l_x0_dest = opj_int_ceildivpow2(l_img_comp_dest->x0, l_img_comp_dest->factor); - l_y0_dest = opj_int_ceildivpow2(l_img_comp_dest->y0, l_img_comp_dest->factor); + l_x0_dest = (OPJ_UINT32)opj_int_ceildivpow2((OPJ_INT32)l_img_comp_dest->x0, (OPJ_INT32)l_img_comp_dest->factor); + l_y0_dest = (OPJ_UINT32)opj_int_ceildivpow2((OPJ_INT32)l_img_comp_dest->y0, (OPJ_INT32)l_img_comp_dest->factor); l_x1_dest = l_x0_dest + l_img_comp_dest->w; l_y1_dest = l_y0_dest + l_img_comp_dest->h; @@ -7752,7 +7752,7 @@ OPJ_BOOL opj_j2k_update_image_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data, opj_im assert( l_res->x0 >= 0); assert( l_res->x1 >= 0); if ( l_x0_dest < (OPJ_UINT32)l_res->x0 ) { - l_start_x_dest = l_res->x0 - l_x0_dest; + l_start_x_dest = (OPJ_UINT32)l_res->x0 - l_x0_dest; l_offset_x0_src = 0; if ( l_x1_dest >= (OPJ_UINT32)l_res->x1 ) { @@ -7760,21 +7760,21 @@ OPJ_BOOL opj_j2k_update_image_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data, opj_im l_offset_x1_src = 0; } else { - l_width_dest = l_x1_dest - l_res->x0 ; - l_offset_x1_src = l_width_src - l_width_dest; + l_width_dest = l_x1_dest - (OPJ_UINT32)l_res->x0 ; + l_offset_x1_src = (OPJ_INT32)(l_width_src - l_width_dest); } } else { l_start_x_dest = 0 ; - l_offset_x0_src = l_x0_dest - l_res->x0; + l_offset_x0_src = (OPJ_INT32)l_x0_dest - l_res->x0; if ( l_x1_dest >= (OPJ_UINT32)l_res->x1 ) { - l_width_dest = l_width_src - l_offset_x0_src; + l_width_dest = l_width_src - (OPJ_UINT32)l_offset_x0_src; l_offset_x1_src = 0; } else { l_width_dest = l_img_comp_dest->w ; - l_offset_x1_src = l_res->x1 - l_x1_dest; + l_offset_x1_src = l_res->x1 - (OPJ_INT32)l_x1_dest; } } From 9095c7361e56ccdce2b493deb4f7b421c5c6de12 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 10 Mar 2014 14:51:59 +0000 Subject: [PATCH 275/333] [trunk] Remove old warnings about deprecated API --- cmake/CTestCustom.cmake.in | 1 + 1 file changed, 1 insertion(+) diff --git a/cmake/CTestCustom.cmake.in b/cmake/CTestCustom.cmake.in index a19c2913..a8cb57ae 100644 --- a/cmake/CTestCustom.cmake.in +++ b/cmake/CTestCustom.cmake.in @@ -29,6 +29,7 @@ set(CTEST_CUSTOM_WARNING_EXCEPTION ".*warning,.* is deprecated" # java also warns about deprecated API ".*java.*deprecation" + ".*deprecation.*" # supress warnings caused by 3rd party libs: ".*thirdparty.*" "libtiff.*has no symbols" From 76557d2eb3dedc1f1d362e61fb51d7ba65137450 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 10 Mar 2014 15:51:05 +0000 Subject: [PATCH 276/333] [trunk] Another round of fixes for sign conversion warnings. Update issue 256 --- src/lib/openjp2/j2k.c | 102 +++++++++++++++++++++--------------------- 1 file changed, 51 insertions(+), 51 deletions(-) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 0752eab2..a9b42697 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -2049,10 +2049,10 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, l_img_comp->sgnd = tmp >> 7; opj_read_bytes(p_header_data,&tmp,1); /* XRsiz_i */ ++p_header_data; - l_img_comp->dx = (OPJ_INT32)tmp; /* should be between 1 and 255 */ + l_img_comp->dx = (OPJ_UINT32)tmp; /* should be between 1 and 255 */ opj_read_bytes(p_header_data,&tmp,1); /* YRsiz_i */ ++p_header_data; - l_img_comp->dy = (OPJ_INT32)tmp; /* should be between 1 and 255 */ + l_img_comp->dy = (OPJ_UINT32)tmp; /* should be between 1 and 255 */ if( l_img_comp->dx < 1 || l_img_comp->dx > 255 || l_img_comp->dy < 1 || l_img_comp->dy > 255 ) { opj_event_msg(p_manager, EVT_ERROR, @@ -2094,8 +2094,8 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, } /* Compute the number of tiles */ - l_cp->tw = opj_int_ceildiv(l_image->x1 - l_cp->tx0, l_cp->tdx); - l_cp->th = opj_int_ceildiv(l_image->y1 - l_cp->ty0, l_cp->tdy); + l_cp->tw = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)(l_image->x1 - l_cp->tx0), (OPJ_INT32)l_cp->tdx); + l_cp->th = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)(l_image->y1 - l_cp->ty0), (OPJ_INT32)l_cp->tdy); /* Check that the number of tiles is valid */ if (l_cp->tw == 0 || l_cp->th == 0 || l_cp->tw > 65535 / l_cp->th) { @@ -2110,8 +2110,8 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, if (p_j2k->m_specific_param.m_decoder.m_discard_tiles) { p_j2k->m_specific_param.m_decoder.m_start_tile_x = (p_j2k->m_specific_param.m_decoder.m_start_tile_x - l_cp->tx0) / l_cp->tdx; p_j2k->m_specific_param.m_decoder.m_start_tile_y = (p_j2k->m_specific_param.m_decoder.m_start_tile_y - l_cp->ty0) / l_cp->tdy; - p_j2k->m_specific_param.m_decoder.m_end_tile_x = opj_int_ceildiv((p_j2k->m_specific_param.m_decoder.m_end_tile_x - l_cp->tx0), l_cp->tdx); - p_j2k->m_specific_param.m_decoder.m_end_tile_y = opj_int_ceildiv((p_j2k->m_specific_param.m_decoder.m_end_tile_y - l_cp->ty0), l_cp->tdy); + p_j2k->m_specific_param.m_decoder.m_end_tile_x = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)(p_j2k->m_specific_param.m_decoder.m_end_tile_x - l_cp->tx0), (OPJ_INT32)l_cp->tdx); + p_j2k->m_specific_param.m_decoder.m_end_tile_y = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)(p_j2k->m_specific_param.m_decoder.m_end_tile_y - l_cp->ty0), (OPJ_INT32)l_cp->tdy); } else { p_j2k->m_specific_param.m_decoder.m_start_tile_x = 0; @@ -3038,9 +3038,9 @@ void opj_j2k_write_poc_in_memory( opj_j2k_t *p_j2k, ++l_current_data; /* change the value of the max layer according to the actual number of layers in the file, components and resolutions*/ - l_current_poc->layno1 = opj_int_min(l_current_poc->layno1, l_tcp->numlayers); - l_current_poc->resno1 = opj_int_min(l_current_poc->resno1, l_tccp->numresolutions); - l_current_poc->compno1 = opj_int_min(l_current_poc->compno1, l_nb_comp); + l_current_poc->layno1 = (OPJ_UINT32)opj_int_min((OPJ_INT32)l_current_poc->layno1, (OPJ_INT32)l_tcp->numlayers); + l_current_poc->resno1 = (OPJ_UINT32)opj_int_min((OPJ_INT32)l_current_poc->resno1, (OPJ_INT32)l_tccp->numresolutions); + l_current_poc->compno1 = (OPJ_UINT32)opj_int_min((OPJ_INT32)l_current_poc->compno1, (OPJ_INT32)l_nb_comp); ++l_current_poc; } @@ -4408,7 +4408,7 @@ OPJ_BOOL opj_j2k_read_sod (opj_j2k_t *p_j2k, opj_write_bytes(l_current_data, 0,1); /* Srgn */ ++l_current_data; - opj_write_bytes(l_current_data, l_tccp->roishift,1); /* SPrgn */ + opj_write_bytes(l_current_data, (OPJ_UINT32)l_tccp->roishift,1); /* SPrgn */ ++l_current_data; if (opj_stream_write_data(p_stream,p_j2k->m_specific_param.m_encoder.m_header_tile_data,l_rgn_size,p_manager) != l_rgn_size) { @@ -4582,16 +4582,16 @@ OPJ_BOOL opj_j2k_update_rates( opj_j2k_t *p_j2k, OPJ_FLOAT32 l_offset = (OPJ_FLOAT32)(*l_tp_stride_func)(l_tcp) / (OPJ_FLOAT32)l_tcp->numlayers; /* 4 borders of the tile rescale on the image if necessary */ - l_x0 = opj_int_max(l_cp->tx0 + j * l_cp->tdx, l_image->x0); - l_y0 = opj_int_max(l_cp->ty0 + i * l_cp->tdy, l_image->y0); - l_x1 = opj_int_min(l_cp->tx0 + (j + 1) * l_cp->tdx, l_image->x1); - l_y1 = opj_int_min(l_cp->ty0 + (i + 1) * l_cp->tdy, l_image->y1); + l_x0 = opj_int_max((OPJ_INT32)(l_cp->tx0 + j * l_cp->tdx), (OPJ_INT32)l_image->x0); + l_y0 = opj_int_max((OPJ_INT32)(l_cp->ty0 + i * l_cp->tdy), (OPJ_INT32)l_image->y0); + l_x1 = opj_int_min((OPJ_INT32)(l_cp->tx0 + (j + 1) * l_cp->tdx), (OPJ_INT32)l_image->x1); + l_y1 = opj_int_min((OPJ_INT32)(l_cp->ty0 + (i + 1) * l_cp->tdy), (OPJ_INT32)l_image->y1); l_rates = l_tcp->rates; /* Modification of the RATE >> */ if (*l_rates) { - *l_rates = (( (OPJ_FLOAT32) (l_size_pixel * (l_x1 - l_x0) * (l_y1 - l_y0))) + *l_rates = (( (OPJ_FLOAT32) (l_size_pixel * (OPJ_UINT32)(l_x1 - l_x0) * (OPJ_UINT32)(l_y1 - l_y0))) / ((*l_rates) * (OPJ_FLOAT32)l_bits_empty) ) @@ -4603,7 +4603,7 @@ OPJ_BOOL opj_j2k_update_rates( opj_j2k_t *p_j2k, for (k = 1; k < l_tcp->numlayers; ++k) { if (*l_rates) { - *l_rates = (( (OPJ_FLOAT32) (l_size_pixel * (l_x1 - l_x0) * (l_y1 - l_y0))) + *l_rates = (( (OPJ_FLOAT32) (l_size_pixel * (OPJ_UINT32)(l_x1 - l_x0) * (OPJ_UINT32)(l_y1 - l_y0))) / ((*l_rates) * (OPJ_FLOAT32)l_bits_empty) ) @@ -4902,12 +4902,12 @@ OPJ_BOOL opj_j2k_write_epc( opj_j2k_t *p_j2k, l_cstr_index = p_j2k->cstr_index; if (l_cstr_index) { - l_cstr_index->codestream_size = opj_stream_tell(p_stream); + l_cstr_index->codestream_size = (OPJ_UINT64)opj_stream_tell(p_stream); /* UniPG>> */ /* The following adjustment is done to adjust the codestream size */ /* if SOD is not at 0 in the buffer. Useful in case of JP2, where */ /* the first bunch of bytes is not in the codestream */ - l_cstr_index->codestream_size -= l_cstr_index->main_head_start; + l_cstr_index->codestream_size -= (OPJ_UINT64)l_cstr_index->main_head_start; /* <numcomps;++i) { - l_tccp->m_dc_level_shift = *(l_current_offset_data++); + l_tccp->m_dc_level_shift = (OPJ_INT32)*(l_current_offset_data++); ++l_tccp; } @@ -5863,14 +5863,14 @@ int opj_j2k_initialise_4K_poc(opj_poc_t *POC, int numres){ POC[0].resno0 = 0; POC[0].compno0 = 0; POC[0].layno1 = 1; - POC[0].resno1 = numres-1; + POC[0].resno1 = (OPJ_UINT32)(numres-1); POC[0].compno1 = 3; POC[0].prg1 = OPJ_CPRL; POC[1].tile = 1; - POC[1].resno0 = numres-1; + POC[1].resno0 = (OPJ_UINT32)(numres-1); POC[1].compno0 = 0; POC[1].layno1 = 1; - POC[1].resno1 = numres; + POC[1].resno1 = (OPJ_UINT32)numres; POC[1].compno1 = 3; POC[1].prg1 = OPJ_CPRL; return 2; @@ -5986,7 +5986,7 @@ void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *i /* Progression order changes for 4K, disallowed for 2K */ if (parameters->cp_cinema == OPJ_CINEMA4K_24) { - parameters->numpocs = opj_j2k_initialise_4K_poc(parameters->POC,parameters->numresolution); + parameters->numpocs = (OPJ_UINT32)opj_j2k_initialise_4K_poc(parameters->POC,parameters->numresolution); } else { parameters->numpocs = 0; } @@ -6142,26 +6142,26 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, copy user encoding parameters */ cp->m_specific_param.m_enc.m_cinema = parameters->cp_cinema; - cp->m_specific_param.m_enc.m_max_comp_size = parameters->max_comp_size; + cp->m_specific_param.m_enc.m_max_comp_size = (OPJ_UINT32)parameters->max_comp_size; cp->rsiz = parameters->cp_rsiz; - cp->m_specific_param.m_enc.m_disto_alloc = parameters->cp_disto_alloc & 1u; - cp->m_specific_param.m_enc.m_fixed_alloc = parameters->cp_fixed_alloc & 1u; - cp->m_specific_param.m_enc.m_fixed_quality = parameters->cp_fixed_quality & 1u; + cp->m_specific_param.m_enc.m_disto_alloc = (OPJ_UINT32)parameters->cp_disto_alloc & 1u; + cp->m_specific_param.m_enc.m_fixed_alloc = (OPJ_UINT32)parameters->cp_fixed_alloc & 1u; + cp->m_specific_param.m_enc.m_fixed_quality = (OPJ_UINT32)parameters->cp_fixed_quality & 1u; /* mod fixed_quality */ if (parameters->cp_fixed_alloc && parameters->cp_matrice) { - size_t array_size = parameters->tcp_numlayers * parameters->numresolution * 3 * sizeof(OPJ_INT32); + size_t array_size = (size_t)parameters->tcp_numlayers * (size_t)parameters->numresolution * 3 * sizeof(OPJ_INT32); cp->m_specific_param.m_enc.m_matrice = (OPJ_INT32 *) opj_malloc(array_size); memcpy(cp->m_specific_param.m_enc.m_matrice, parameters->cp_matrice, array_size); } /* tiles */ - cp->tdx = parameters->cp_tdx; - cp->tdy = parameters->cp_tdy; + cp->tdx = (OPJ_UINT32)parameters->cp_tdx; + cp->tdy = (OPJ_UINT32)parameters->cp_tdy; /* tile offset */ - cp->tx0 = parameters->cp_tx0; - cp->ty0 = parameters->cp_ty0; + cp->tx0 = (OPJ_UINT32)parameters->cp_tx0; + cp->ty0 = (OPJ_UINT32)parameters->cp_ty0; /* comment string */ if(parameters->cp_comment) { @@ -6176,15 +6176,15 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, */ if (parameters->tile_size_on) { - cp->tw = opj_int_ceildiv(image->x1 - cp->tx0, cp->tdx); - cp->th = opj_int_ceildiv(image->y1 - cp->ty0, cp->tdy); + cp->tw = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)(image->x1 - cp->tx0), (OPJ_INT32)cp->tdx); + cp->th = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)(image->y1 - cp->ty0), (OPJ_INT32)cp->tdy); } else { cp->tdx = image->x1 - cp->tx0; cp->tdy = image->y1 - cp->ty0; } if (parameters->tp_on) { - cp->m_specific_param.m_enc.m_tp_flag = parameters->tp_flag; + cp->m_specific_param.m_enc.m_tp_flag = (OPJ_BYTE)parameters->tp_flag; cp->m_specific_param.m_enc.m_tp_on = 1; } @@ -6249,13 +6249,13 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, cp->tcps = (opj_tcp_t*) opj_calloc(cp->tw * cp->th, sizeof(opj_tcp_t)); if (parameters->numpocs) { /* initialisation of POC */ - opj_j2k_check_poc_val(parameters->POC,parameters->numpocs, parameters->numresolution, image->numcomps, parameters->tcp_numlayers, p_manager); + opj_j2k_check_poc_val(parameters->POC,parameters->numpocs, (OPJ_UINT32)parameters->numresolution, image->numcomps, (OPJ_UINT32)parameters->tcp_numlayers, p_manager); /* TODO MSD use the return value*/ } for (tileno = 0; tileno < cp->tw * cp->th; tileno++) { opj_tcp_t *tcp = &cp->tcps[tileno]; - tcp->numlayers = parameters->tcp_numlayers; + tcp->numlayers = (OPJ_UINT32)parameters->tcp_numlayers; for (j = 0; j < tcp->numlayers; j++) { if(cp->m_specific_param.m_enc.m_cinema){ @@ -6272,9 +6272,9 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, } } - tcp->csty = parameters->csty; + tcp->csty = (OPJ_UINT32)parameters->csty; tcp->prg = parameters->prog_order; - tcp->mct = parameters->tcp_mct; + tcp->mct = (OPJ_UINT32)parameters->tcp_mct; numpocs_tile = 0; tcp->POC = 0; @@ -6347,10 +6347,10 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, opj_tccp_t *tccp = &tcp->tccps[i]; tccp->csty = parameters->csty & 0x01; /* 0 => one precinct || 1 => custom precinct */ - tccp->numresolutions = parameters->numresolution; - tccp->cblkw = opj_int_floorlog2(parameters->cblockw_init); - tccp->cblkh = opj_int_floorlog2(parameters->cblockh_init); - tccp->cblksty = parameters->mode; + tccp->numresolutions = (OPJ_UINT32)parameters->numresolution; + tccp->cblkw = (OPJ_UINT32)opj_int_floorlog2(parameters->cblockw_init); + tccp->cblkh = (OPJ_UINT32)opj_int_floorlog2(parameters->cblockh_init); + tccp->cblksty = (OPJ_UINT32)parameters->mode; tccp->qmfbid = parameters->irreversible ? 0 : 1; tccp->qntsty = parameters->irreversible ? J2K_CCP_QNTSTY_SEQNT : J2K_CCP_QNTSTY_NOQNT; tccp->numgbits = 2; @@ -6364,19 +6364,19 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, if (parameters->csty & J2K_CCP_CSTY_PRT) { OPJ_INT32 p = 0, it_res; assert( tccp->numresolutions > 0 ); - for (it_res = tccp->numresolutions - 1; it_res >= 0; it_res--) { + for (it_res = (OPJ_INT32)tccp->numresolutions - 1; it_res >= 0; it_res--) { if (p < parameters->res_spec) { if (parameters->prcw_init[p] < 1) { tccp->prcw[it_res] = 1; } else { - tccp->prcw[it_res] = opj_int_floorlog2(parameters->prcw_init[p]); + tccp->prcw[it_res] = (OPJ_UINT32)opj_int_floorlog2(parameters->prcw_init[p]); } if (parameters->prch_init[p] < 1) { tccp->prch[it_res] = 1; }else { - tccp->prch[it_res] = opj_int_floorlog2(parameters->prch_init[p]); + tccp->prch[it_res] = (OPJ_UINT32)opj_int_floorlog2(parameters->prch_init[p]); } } else { @@ -6392,13 +6392,13 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, if (size_prcw < 1) { tccp->prcw[it_res] = 1; } else { - tccp->prcw[it_res] = opj_int_floorlog2(size_prcw); + tccp->prcw[it_res] = (OPJ_UINT32)opj_int_floorlog2(size_prcw); } if (size_prch < 1) { tccp->prch[it_res] = 1; } else { - tccp->prch[it_res] = opj_int_floorlog2(size_prch); + tccp->prch[it_res] = (OPJ_UINT32)opj_int_floorlog2(size_prch); } } p++; @@ -6428,7 +6428,7 @@ static OPJ_BOOL opj_j2k_add_mhmarker(opj_codestream_index_t *cstr_index, OPJ_UIN /* expand the list? */ if ((cstr_index->marknum + 1) > cstr_index->maxmarknum) { opj_marker_info_t *new_marker; - cstr_index->maxmarknum = 100 + (OPJ_INT32) ((OPJ_FLOAT32) cstr_index->maxmarknum * 1.0F); + cstr_index->maxmarknum = (OPJ_UINT32)(100 + (OPJ_FLOAT32) cstr_index->maxmarknum); new_marker = (opj_marker_info_t *) opj_realloc(cstr_index->marker, cstr_index->maxmarknum *sizeof(opj_marker_info_t)); if (! new_marker) { opj_free(cstr_index->marker); @@ -6457,7 +6457,7 @@ static OPJ_BOOL opj_j2k_add_tlmarker(OPJ_UINT32 tileno, opj_codestream_index_t * /* expand the list? */ if ((cstr_index->tile_index[tileno].marknum + 1) > cstr_index->tile_index[tileno].maxmarknum) { opj_marker_info_t *new_marker; - cstr_index->tile_index[tileno].maxmarknum = 100 + (OPJ_INT32) ((OPJ_FLOAT32) cstr_index->tile_index[tileno].maxmarknum * 1.0F); + cstr_index->tile_index[tileno].maxmarknum = (OPJ_UINT32)(100 + (OPJ_FLOAT32) cstr_index->tile_index[tileno].maxmarknum); new_marker = (opj_marker_info_t *) opj_realloc( cstr_index->tile_index[tileno].marker, cstr_index->tile_index[tileno].maxmarknum *sizeof(opj_marker_info_t)); @@ -7633,7 +7633,7 @@ OPJ_BOOL opj_j2k_decode_tile ( opj_j2k_t * p_j2k, opj_j2k_tcp_data_destroy(l_tcp); p_j2k->m_specific_param.m_decoder.m_can_decode = 0; - p_j2k->m_specific_param.m_decoder.m_state &= (~ (0x0080));/* FIXME J2K_DEC_STATE_DATA);*/ + p_j2k->m_specific_param.m_decoder.m_state &= (~ (0x0080u));/* FIXME J2K_DEC_STATE_DATA);*/ if(opj_stream_get_number_byte_left(p_stream) == 0 && p_j2k->m_specific_param.m_decoder.m_state == J2K_STATE_NEOC){ From 73c9e856420532f3351b285517fe9a2d43394b93 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 10 Mar 2014 16:17:01 +0000 Subject: [PATCH 277/333] [trunk] Another round of fixes for sign conversion warnings. Update issue 256 --- src/lib/openjp2/t1.c | 98 ++++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/src/lib/openjp2/t1.c b/src/lib/openjp2/t1.c index 3f7613a5..59a219da 100644 --- a/src/lib/openjp2/t1.c +++ b/src/lib/openjp2/t1.c @@ -371,25 +371,25 @@ void opj_t1_enc_sigpass_step( opj_t1_t *t1, opj_mqc_t *mqc = t1->mqc; /* MQC component */ - flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); + flag = vsc ? (OPJ_UINT32)((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (OPJ_UINT32)(*flagsp); if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) { v = opj_int_abs(*datap) & one ? 1 : 0; opj_mqc_setcurctx(mqc, opj_t1_getctxno_zc(flag, orient)); /* ESSAI */ if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ - opj_mqc_bypass_enc(mqc, v); + opj_mqc_bypass_enc(mqc, (OPJ_UINT32)v); } else { - opj_mqc_encode(mqc, v); + opj_mqc_encode(mqc, (OPJ_UINT32)v); } if (v) { v = *datap < 0 ? 1 : 0; - *nmsedec += opj_t1_getnmsedec_sig(opj_int_abs(*datap), bpno + T1_NMSEDEC_FRACBITS); + *nmsedec += opj_t1_getnmsedec_sig((OPJ_UINT32)opj_int_abs(*datap), (OPJ_UINT32)(bpno + T1_NMSEDEC_FRACBITS)); opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc(flag)); /* ESSAI */ if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ - opj_mqc_bypass_enc(mqc, v); + opj_mqc_bypass_enc(mqc, (OPJ_UINT32)v); } else { - opj_mqc_encode(mqc, v ^ opj_t1_getspb(flag)); + opj_mqc_encode(mqc, (OPJ_UINT32)(v ^ opj_t1_getspb((OPJ_UINT32)flag))); } - opj_t1_updateflags(flagsp, v, t1->flags_stride); + opj_t1_updateflags(flagsp, (OPJ_UINT32)v, t1->flags_stride); } *flagsp |= T1_VISIT; } @@ -411,9 +411,9 @@ static INLINE void opj_t1_dec_sigpass_step_raw( flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) { if (opj_raw_decode(raw)) { - v = opj_raw_decode(raw); /* ESSAI */ + v = (OPJ_INT32)opj_raw_decode(raw); /* ESSAI */ *datap = v ? -oneplushalf : oneplushalf; - opj_t1_updateflags(flagsp, v, t1->flags_stride); + opj_t1_updateflags(flagsp, (OPJ_UINT32)v, t1->flags_stride); } *flagsp |= T1_VISIT; } @@ -432,12 +432,12 @@ INLINE void opj_t1_dec_sigpass_step_mqc( flag = *flagsp; if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) { - opj_mqc_setcurctx(mqc, opj_t1_getctxno_zc(flag, orient)); + opj_mqc_setcurctx(mqc, opj_t1_getctxno_zc((OPJ_UINT32)flag, (OPJ_UINT32)orient)); if (opj_mqc_decode(mqc)) { - opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc(flag)); - v = opj_mqc_decode(mqc) ^ opj_t1_getspb(flag); + opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc((OPJ_UINT32)flag)); + v = opj_mqc_decode(mqc) ^ opj_t1_getspb((OPJ_UINT32)flag); *datap = v ? -oneplushalf : oneplushalf; - opj_t1_updateflags(flagsp, v, t1->flags_stride); + opj_t1_updateflags(flagsp, (OPJ_UINT32)v, t1->flags_stride); } *flagsp |= T1_VISIT; } @@ -457,12 +457,12 @@ INLINE void opj_t1_dec_sigpass_step_mqc_vsc( flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); if ((flag & T1_SIG_OTH) && !(flag & (T1_SIG | T1_VISIT))) { - opj_mqc_setcurctx(mqc, opj_t1_getctxno_zc(flag, orient)); + opj_mqc_setcurctx(mqc, opj_t1_getctxno_zc((OPJ_UINT32)flag, (OPJ_UINT32)orient)); if (opj_mqc_decode(mqc)) { - opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc(flag)); - v = opj_mqc_decode(mqc) ^ opj_t1_getspb(flag); + opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc((OPJ_UINT32)flag)); + v = opj_mqc_decode(mqc) ^ opj_t1_getspb((OPJ_UINT32)flag); *datap = v ? -oneplushalf : oneplushalf; - opj_t1_updateflags(flagsp, v, t1->flags_stride); + opj_t1_updateflags(flagsp, (OPJ_UINT32)v, t1->flags_stride); } *flagsp |= T1_VISIT; } @@ -541,7 +541,7 @@ void opj_t1_dec_sigpass_mqc( one = 1 << bpno; half = one >> 1; oneplushalf = one | half; - for (k = 0; k < (t1->h & ~3); k += 4) { + for (k = 0; k < (t1->h & ~3u); k += 4) { for (i = 0; i < t1->w; ++i) { OPJ_INT32 *data2 = data1 + i; opj_flag_t *flags2 = flags1 + i; @@ -614,15 +614,15 @@ void opj_t1_enc_refpass_step( opj_t1_t *t1, opj_mqc_t *mqc = t1->mqc; /* MQC component */ - flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); + flag = vsc ? (OPJ_UINT32)((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (OPJ_UINT32)(*flagsp); if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) { - *nmsedec += opj_t1_getnmsedec_ref(opj_int_abs(*datap), bpno + T1_NMSEDEC_FRACBITS); + *nmsedec += opj_t1_getnmsedec_ref((OPJ_UINT32)opj_int_abs(*datap), (OPJ_UINT32)(bpno + T1_NMSEDEC_FRACBITS)); v = opj_int_abs(*datap) & one ? 1 : 0; opj_mqc_setcurctx(mqc, opj_t1_getctxno_mag(flag)); /* ESSAI */ if (type == T1_TYPE_RAW) { /* BYPASS/LAZY MODE */ - opj_mqc_bypass_enc(mqc, v); + opj_mqc_bypass_enc(mqc, (OPJ_UINT32)v); } else { - opj_mqc_encode(mqc, v); + opj_mqc_encode(mqc, (OPJ_UINT32)v); } *flagsp |= T1_REFINE; } @@ -642,7 +642,7 @@ INLINE void opj_t1_dec_refpass_step_raw( flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) { - v = opj_raw_decode(raw); + v = (OPJ_INT32)opj_raw_decode(raw); t = v ? poshalf : neghalf; *datap += *datap < 0 ? -t : t; *flagsp |= T1_REFINE; @@ -662,7 +662,7 @@ INLINE void opj_t1_dec_refpass_step_mqc( flag = *flagsp; if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) { - opj_mqc_setcurctx(mqc, opj_t1_getctxno_mag(flag)); /* ESSAI */ + opj_mqc_setcurctx(mqc, opj_t1_getctxno_mag((OPJ_UINT32)flag)); /* ESSAI */ v = opj_mqc_decode(mqc); t = v ? poshalf : neghalf; *datap += *datap < 0 ? -t : t; @@ -684,7 +684,7 @@ INLINE void opj_t1_dec_refpass_step_mqc_vsc( flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); if ((flag & (T1_SIG | T1_VISIT)) == T1_SIG) { - opj_mqc_setcurctx(mqc, opj_t1_getctxno_mag(flag)); /* ESSAI */ + opj_mqc_setcurctx(mqc, opj_t1_getctxno_mag((OPJ_UINT32)flag)); /* ESSAI */ v = opj_mqc_decode(mqc); t = v ? poshalf : neghalf; *datap += *datap < 0 ? -t : t; @@ -761,7 +761,7 @@ void opj_t1_dec_refpass_mqc( one = 1 << bpno; poshalf = one >> 1; neghalf = bpno > 0 ? -poshalf : -1; - for (k = 0; k < (t1->h & ~3); k += 4) { + for (k = 0; k < (t1->h & ~3u); k += 4) { for (i = 0; i < t1->w; ++i) { OPJ_INT32 *data2 = data1 + i; opj_flag_t *flags2 = flags1 + i; @@ -835,21 +835,21 @@ void opj_t1_enc_clnpass_step( opj_mqc_t *mqc = t1->mqc; /* MQC component */ - flag = vsc ? ((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (*flagsp); + flag = vsc ? (OPJ_UINT32)((*flagsp) & (~(T1_SIG_S | T1_SIG_SE | T1_SIG_SW | T1_SGN_S))) : (OPJ_UINT32)(*flagsp); if (partial) { goto LABEL_PARTIAL; } if (!(*flagsp & (T1_SIG | T1_VISIT))) { opj_mqc_setcurctx(mqc, opj_t1_getctxno_zc(flag, orient)); v = opj_int_abs(*datap) & one ? 1 : 0; - opj_mqc_encode(mqc, v); + opj_mqc_encode(mqc, (OPJ_UINT32)v); if (v) { LABEL_PARTIAL: - *nmsedec += opj_t1_getnmsedec_sig(opj_int_abs(*datap), bpno + T1_NMSEDEC_FRACBITS); + *nmsedec += opj_t1_getnmsedec_sig((OPJ_UINT32)opj_int_abs(*datap), (OPJ_UINT32)(bpno + T1_NMSEDEC_FRACBITS)); opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc(flag)); v = *datap < 0 ? 1 : 0; - opj_mqc_encode(mqc, v ^ opj_t1_getspb(flag)); - opj_t1_updateflags(flagsp, v, t1->flags_stride); + opj_mqc_encode(mqc, (OPJ_UINT32)(v ^ opj_t1_getspb((OPJ_UINT32)flag))); + opj_t1_updateflags(flagsp, (OPJ_UINT32)v, t1->flags_stride); } } *flagsp &= ~T1_VISIT; @@ -868,10 +868,10 @@ static void opj_t1_dec_clnpass_step_partial( OPJ_ARG_NOT_USED(orient); flag = *flagsp; - opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc(flag)); - v = opj_mqc_decode(mqc) ^ opj_t1_getspb(flag); + opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc((OPJ_UINT32)flag)); + v = opj_mqc_decode(mqc) ^ opj_t1_getspb((OPJ_UINT32)flag); *datap = v ? -oneplushalf : oneplushalf; - opj_t1_updateflags(flagsp, v, t1->flags_stride); + opj_t1_updateflags(flagsp, (OPJ_UINT32)v, t1->flags_stride); *flagsp &= ~T1_VISIT; } /* VSC and BYPASS by Antonin */ @@ -888,12 +888,12 @@ static void opj_t1_dec_clnpass_step( flag = *flagsp; if (!(flag & (T1_SIG | T1_VISIT))) { - opj_mqc_setcurctx(mqc, opj_t1_getctxno_zc(flag, orient)); + opj_mqc_setcurctx(mqc, opj_t1_getctxno_zc((OPJ_UINT32)flag, (OPJ_UINT32)orient)); if (opj_mqc_decode(mqc)) { - opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc(flag)); - v = opj_mqc_decode(mqc) ^ opj_t1_getspb(flag); + opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc((OPJ_UINT32)flag)); + v = opj_mqc_decode(mqc) ^ opj_t1_getspb((OPJ_UINT32)flag); *datap = v ? -oneplushalf : oneplushalf; - opj_t1_updateflags(flagsp, v, t1->flags_stride); + opj_t1_updateflags(flagsp, (OPJ_UINT32)v, t1->flags_stride); } } *flagsp &= ~T1_VISIT; @@ -917,13 +917,13 @@ static void opj_t1_dec_clnpass_step_vsc( goto LABEL_PARTIAL; } if (!(flag & (T1_SIG | T1_VISIT))) { - opj_mqc_setcurctx(mqc, opj_t1_getctxno_zc(flag, orient)); + opj_mqc_setcurctx(mqc, opj_t1_getctxno_zc((OPJ_UINT32)flag, (OPJ_UINT32)orient)); if (opj_mqc_decode(mqc)) { LABEL_PARTIAL: - opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc(flag)); - v = opj_mqc_decode(mqc) ^ opj_t1_getspb(flag); + opj_mqc_setcurctx(mqc, opj_t1_getctxno_sc((OPJ_UINT32)flag)); + v = opj_mqc_decode(mqc) ^ opj_t1_getspb((OPJ_UINT32)flag); *datap = v ? -oneplushalf : oneplushalf; - opj_t1_updateflags(flagsp, v, t1->flags_stride); + opj_t1_updateflags(flagsp, (OPJ_UINT32)v, t1->flags_stride); } } *flagsp &= ~T1_VISIT; @@ -1033,7 +1033,7 @@ static void opj_t1_dec_clnpass( } else { runlen = 0; } - for (j = k + runlen; j < k + 4 && j < t1->h; ++j) { + for (j = k + (OPJ_UINT32)runlen; j < k + 4 && j < t1->h; ++j) { vsc = (j == k + 3 || j == t1->h - 1) ? 1 : 0; opj_t1_dec_clnpass_step_vsc( t1, @@ -1041,7 +1041,7 @@ static void opj_t1_dec_clnpass( &t1->data[(j * t1->w) + i], orient, oneplushalf, - agg && (j == k + runlen), + agg && (j == k + (OPJ_UINT32)runlen), vsc); } } @@ -1049,7 +1049,7 @@ static void opj_t1_dec_clnpass( } else { OPJ_INT32 *data1 = t1->data; opj_flag_t *flags1 = &t1->flags[1]; - for (k = 0; k < (t1->h & ~3); k += 4) { + for (k = 0; k < (t1->h & ~3u); k += 4) { for (i = 0; i < t1->w; ++i) { OPJ_INT32 *data2 = data1 + i; opj_flag_t *flags2 = flags1 + i; @@ -1065,11 +1065,11 @@ static void opj_t1_dec_clnpass( opj_mqc_setcurctx(mqc, T1_CTXNO_UNI); runlen = opj_mqc_decode(mqc); runlen = (runlen << 1) | opj_mqc_decode(mqc); - flags2 += runlen * t1->flags_stride; - data2 += runlen * t1->w; - for (j = k + runlen; j < k + 4 && j < t1->h; ++j) { + flags2 += (OPJ_UINT32)runlen * t1->flags_stride; + data2 += (OPJ_UINT32)runlen * t1->w; + for (j = k + (OPJ_UINT32)runlen; j < k + 4 && j < t1->h; ++j) { flags2 += t1->flags_stride; - if (agg && (j == k + runlen)) { + if (agg && (j == k + (OPJ_UINT32)runlen)) { opj_t1_dec_clnpass_step_partial(t1, flags2, data2, orient, oneplushalf); } else { opj_t1_dec_clnpass_step(t1, flags2, data2, orient, oneplushalf); From 1778e2576e8f440c6a47c37fc37f6ae7c0c31371 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 10 Mar 2014 16:17:12 +0000 Subject: [PATCH 278/333] [trunk] Another round of fixes for sign conversion warnings. Update issue 256 --- src/lib/openjp2/t2.c | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c index 480944de..abac3fe4 100644 --- a/src/lib/openjp2/t2.c +++ b/src/lib/openjp2/t2.c @@ -573,7 +573,7 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, cblk = &prc->cblks.enc[cblkno]; cblk->numpasses = 0; - opj_tgt_setvalue(prc->imsbtree, cblkno, band->numbps - cblk->numbps); + opj_tgt_setvalue(prc->imsbtree, cblkno, band->numbps - (OPJ_INT32)cblk->numbps); } ++band; } @@ -595,7 +595,7 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, opj_tcd_layer_t *layer = &cblk->layers[layno]; if (!cblk->numpasses && layer->numpasses) { - opj_tgt_setvalue(prc->incltree, cblkno, layno); + opj_tgt_setvalue(prc->incltree, cblkno, (OPJ_INT32)layno); } ++cblk; @@ -611,7 +611,7 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, /* cblk inclusion bits */ if (!cblk->numpasses) { - opj_tgt_encode(bio, prc->incltree, cblkno, layno + 1); + opj_tgt_encode(bio, prc->incltree, cblkno, (OPJ_INT32)(layno + 1)); } else { opj_bio_write(bio, layer->numpasses != 0, 1); } @@ -639,14 +639,15 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, len += pass->len; if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) { - increment = opj_int_max(increment, opj_int_floorlog2(len) + 1 - (cblk->numlenbits + opj_int_floorlog2(nump))); + increment = (OPJ_UINT32)opj_int_max((OPJ_INT32)increment, opj_int_floorlog2((OPJ_INT32)len) + 1 + - ((OPJ_INT32)cblk->numlenbits + opj_int_floorlog2((OPJ_INT32)nump))); len = 0; nump = 0; } ++pass; } - opj_t2_putcommacode(bio, increment); + opj_t2_putcommacode(bio, (OPJ_INT32)increment); /* computation of the new Length indicator */ cblk->numlenbits += increment; @@ -658,7 +659,7 @@ OPJ_BOOL opj_t2_encode_packet( OPJ_UINT32 tileno, len += pass->len; if (pass->term || passno == (cblk->numpasses + layer->numpasses) - 1) { - opj_bio_write(bio, len, cblk->numlenbits + opj_int_floorlog2(nump)); + opj_bio_write(bio, (OPJ_UINT32)len, cblk->numlenbits + (OPJ_UINT32)opj_int_floorlog2((OPJ_INT32)nump)); len = 0; nump = 0; } @@ -935,7 +936,7 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, /* if cblk not yet included before --> inclusion tagtree */ if (!l_cblk->numsegs) { - l_included = opj_tgt_decode(l_bio, l_prc->incltree, cblkno, p_pi->layno + 1); + l_included = opj_tgt_decode(l_bio, l_prc->incltree, cblkno, (OPJ_INT32)(p_pi->layno + 1)); /* else one bit */ } else { @@ -953,11 +954,11 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, if (!l_cblk->numsegs) { OPJ_UINT32 i = 0; - while (!opj_tgt_decode(l_bio, l_prc->imsbtree, cblkno, i)) { + while (!opj_tgt_decode(l_bio, l_prc->imsbtree, cblkno, (OPJ_INT32)i)) { ++i; } - l_cblk->numbps = l_band->numbps + 1 - i; + l_cblk->numbps = (OPJ_UINT32)l_band->numbps + 1 - i; l_cblk->numlenbits = 3; } @@ -985,13 +986,13 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, } } } - n = l_cblk->numnewpasses; + n = (OPJ_INT32)l_cblk->numnewpasses; do { - l_cblk->segs[l_segno].numnewpasses = opj_int_min(l_cblk->segs[l_segno].maxpasses - l_cblk->segs[l_segno].numpasses, n); + l_cblk->segs[l_segno].numnewpasses = (OPJ_UINT32)opj_int_min((OPJ_INT32)(l_cblk->segs[l_segno].maxpasses - l_cblk->segs[l_segno].numpasses), n); l_cblk->segs[l_segno].newlen = opj_bio_read(l_bio, l_cblk->numlenbits + opj_uint_floorlog2(l_cblk->segs[l_segno].numnewpasses)); - n -= l_cblk->segs[l_segno].numnewpasses; + n -= (OPJ_INT32)l_cblk->segs[l_segno].numnewpasses; if (n > 0) { ++l_segno; From 2e7b8fb9a1e03a59017dc3d453b176f343144c89 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 10 Mar 2014 16:43:04 +0000 Subject: [PATCH 279/333] [trunk] Another final round of fixes for sign conversion warnings. Fixes issue 256 --- src/lib/openjp2/tcd.c | 86 +++++++++++++++++++++---------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/src/lib/openjp2/tcd.c b/src/lib/openjp2/tcd.c index a58cf47e..001d4ce5 100644 --- a/src/lib/openjp2/tcd.c +++ b/src/lib/openjp2/tcd.c @@ -347,12 +347,12 @@ void opj_tcd_makelayer_fixed(opj_tcd_t *tcd, OPJ_UINT32 layno, OPJ_UINT32 final) n = cblk->numpassesinlayers; if (cblk->numpassesinlayers == 0) { if (value != 0) { - n = 3 * value - 2 + cblk->numpassesinlayers; + n = 3 * (OPJ_UINT32)value - 2 + cblk->numpassesinlayers; } else { n = cblk->numpassesinlayers; } } else { - n = 3 * value + cblk->numpassesinlayers; + n = 3 * (OPJ_UINT32)value + cblk->numpassesinlayers; } layer->numpasses = n - cblk->numpassesinlayers; @@ -659,10 +659,10 @@ OPJ_BOOL FUNCTION ( opj_tcd_t *p_tcd, \ /*fprintf(stderr, "Tile coordinate = %d,%d\n", p, q);*/ \ \ /* 4 borders of the tile rescale on the image if necessary */ \ - l_tile->x0 = opj_int_max(l_cp->tx0 + p * l_cp->tdx, l_image->x0); \ - l_tile->y0 = opj_int_max(l_cp->ty0 + q * l_cp->tdy, l_image->y0); \ - l_tile->x1 = opj_int_min(l_cp->tx0 + (p + 1) * l_cp->tdx, l_image->x1); \ - l_tile->y1 = opj_int_min(l_cp->ty0 + (q + 1) * l_cp->tdy, l_image->y1); \ + l_tile->x0 = opj_int_max((OPJ_INT32)(l_cp->tx0 + p * l_cp->tdx), (OPJ_INT32)l_image->x0); \ + l_tile->y0 = opj_int_max((OPJ_INT32)(l_cp->ty0 + q * l_cp->tdy), (OPJ_INT32)l_image->y0); \ + l_tile->x1 = opj_int_min((OPJ_INT32)(l_cp->tx0 + (p + 1) * l_cp->tdx), (OPJ_INT32)l_image->x1); \ + l_tile->y1 = opj_int_min((OPJ_INT32)(l_cp->ty0 + (q + 1) * l_cp->tdy), (OPJ_INT32)l_image->y1); \ /* testcase 1888.pdf.asan.35.988 */ \ if (l_tccp->numresolutions == 0) { \ fprintf(stderr, "tiles require at least one resolution\n"); \ @@ -675,14 +675,14 @@ OPJ_BOOL FUNCTION ( opj_tcd_t *p_tcd, \ /*fprintf(stderr, "compno = %d/%d\n", compno, l_tile->numcomps);*/ \ \ /* border of each l_tile component (global) */ \ - l_tilec->x0 = opj_int_ceildiv(l_tile->x0, l_image_comp->dx); \ - l_tilec->y0 = opj_int_ceildiv(l_tile->y0, l_image_comp->dy); \ - l_tilec->x1 = opj_int_ceildiv(l_tile->x1, l_image_comp->dx); \ - l_tilec->y1 = opj_int_ceildiv(l_tile->y1, l_image_comp->dy); \ + l_tilec->x0 = opj_int_ceildiv(l_tile->x0, (OPJ_INT32)l_image_comp->dx); \ + l_tilec->y0 = opj_int_ceildiv(l_tile->y0, (OPJ_INT32)l_image_comp->dy); \ + l_tilec->x1 = opj_int_ceildiv(l_tile->x1, (OPJ_INT32)l_image_comp->dx); \ + l_tilec->y1 = opj_int_ceildiv(l_tile->y1, (OPJ_INT32)l_image_comp->dy); \ /*fprintf(stderr, "\tTile compo border = %d,%d,%d,%d\n", l_tilec->x0, l_tilec->y0,l_tilec->x1,l_tilec->y1);*/ \ \ - l_data_size = (l_tilec->x1 - l_tilec->x0) \ - * (l_tilec->y1 - l_tilec->y0) * (OPJ_UINT32)sizeof(OPJ_UINT32 );\ + l_data_size = (OPJ_UINT32)(l_tilec->x1 - l_tilec->x0) \ + * (OPJ_UINT32)(l_tilec->y1 - l_tilec->y0) * (OPJ_UINT32)sizeof(OPJ_UINT32 );\ l_tilec->numresolutions = l_tccp->numresolutions; \ if (l_tccp->numresolutions < l_cp->m_specific_param.m_dec.m_reduce) { \ l_tilec->minimum_num_resolutions = 1; \ @@ -761,24 +761,24 @@ OPJ_BOOL FUNCTION ( opj_tcd_t *p_tcd, \ OPJ_UINT32 cblkwidthexpn, cblkheightexpn; \ \ /* border for each resolution level (global) */ \ - l_res->x0 = opj_int_ceildivpow2(l_tilec->x0, l_level_no); \ - l_res->y0 = opj_int_ceildivpow2(l_tilec->y0, l_level_no); \ - l_res->x1 = opj_int_ceildivpow2(l_tilec->x1, l_level_no); \ - l_res->y1 = opj_int_ceildivpow2(l_tilec->y1, l_level_no); \ + l_res->x0 = opj_int_ceildivpow2(l_tilec->x0, (OPJ_INT32)l_level_no); \ + l_res->y0 = opj_int_ceildivpow2(l_tilec->y0, (OPJ_INT32)l_level_no); \ + l_res->x1 = opj_int_ceildivpow2(l_tilec->x1, (OPJ_INT32)l_level_no); \ + l_res->y1 = opj_int_ceildivpow2(l_tilec->y1, (OPJ_INT32)l_level_no); \ /*fprintf(stderr, "\t\t\tres_x0= %d, res_y0 =%d, res_x1=%d, res_y1=%d\n", l_res->x0, l_res->y0, l_res->x1, l_res->y1);*/ \ /* p. 35, table A-23, ISO/IEC FDIS154444-1 : 2000 (18 august 2000) */ \ l_pdx = l_tccp->prcw[resno]; \ l_pdy = l_tccp->prch[resno]; \ /*fprintf(stderr, "\t\t\tpdx=%d, pdy=%d\n", l_pdx, l_pdy);*/ \ /* p. 64, B.6, ISO/IEC FDIS15444-1 : 2000 (18 august 2000) */ \ - l_tl_prc_x_start = opj_int_floordivpow2(l_res->x0, l_pdx) << l_pdx; \ - l_tl_prc_y_start = opj_int_floordivpow2(l_res->y0, l_pdy) << l_pdy; \ - l_br_prc_x_end = opj_int_ceildivpow2(l_res->x1, l_pdx) << l_pdx; \ - l_br_prc_y_end = opj_int_ceildivpow2(l_res->y1, l_pdy) << l_pdy; \ + l_tl_prc_x_start = opj_int_floordivpow2(l_res->x0, (OPJ_INT32)l_pdx) << l_pdx; \ + l_tl_prc_y_start = opj_int_floordivpow2(l_res->y0, (OPJ_INT32)l_pdy) << l_pdy; \ + l_br_prc_x_end = opj_int_ceildivpow2(l_res->x1, (OPJ_INT32)l_pdx) << l_pdx; \ + l_br_prc_y_end = opj_int_ceildivpow2(l_res->y1, (OPJ_INT32)l_pdy) << l_pdy; \ /*fprintf(stderr, "\t\t\tprc_x_start=%d, prc_y_start=%d, br_prc_x_end=%d, br_prc_y_end=%d \n", l_tl_prc_x_start, l_tl_prc_y_start, l_br_prc_x_end ,l_br_prc_y_end );*/ \ \ - l_res->pw = (l_res->x0 == l_res->x1) ? 0 : ((l_br_prc_x_end - l_tl_prc_x_start) >> l_pdx); \ - l_res->ph = (l_res->y0 == l_res->y1) ? 0 : ((l_br_prc_y_end - l_tl_prc_y_start) >> l_pdy); \ + l_res->pw = (l_res->x0 == l_res->x1) ? 0 : (OPJ_UINT32)((l_br_prc_x_end - l_tl_prc_x_start) >> l_pdx); \ + l_res->ph = (l_res->y0 == l_res->y1) ? 0 : (OPJ_UINT32)((l_br_prc_y_end - l_tl_prc_y_start) >> l_pdy); \ /*fprintf(stderr, "\t\t\tres_pw=%d, res_ph=%d\n", l_res->pw, l_res->ph );*/ \ \ l_nb_precincts = l_res->pw * l_res->ph; \ @@ -812,29 +812,29 @@ OPJ_BOOL FUNCTION ( opj_tcd_t *p_tcd, \ \ if (resno == 0) { \ l_band->bandno = 0 ; \ - l_band->x0 = opj_int_ceildivpow2(l_tilec->x0, l_level_no); \ - l_band->y0 = opj_int_ceildivpow2(l_tilec->y0, l_level_no); \ - l_band->x1 = opj_int_ceildivpow2(l_tilec->x1, l_level_no); \ - l_band->y1 = opj_int_ceildivpow2(l_tilec->y1, l_level_no); \ + l_band->x0 = opj_int_ceildivpow2(l_tilec->x0, (OPJ_INT32)l_level_no); \ + l_band->y0 = opj_int_ceildivpow2(l_tilec->y0, (OPJ_INT32)l_level_no); \ + l_band->x1 = opj_int_ceildivpow2(l_tilec->x1, (OPJ_INT32)l_level_no); \ + l_band->y1 = opj_int_ceildivpow2(l_tilec->y1, (OPJ_INT32)l_level_no); \ } \ else { \ l_band->bandno = bandno + 1; \ /* x0b = 1 if bandno = 1 or 3 */ \ l_x0b = l_band->bandno&1; \ /* y0b = 1 if bandno = 2 or 3 */ \ - l_y0b = (l_band->bandno)>>1; \ + l_y0b = (OPJ_INT32)((l_band->bandno)>>1); \ /* l_band border (global) */ \ - l_band->x0 = opj_int_ceildivpow2(l_tilec->x0 - (1 << l_level_no) * l_x0b, l_level_no + 1); \ - l_band->y0 = opj_int_ceildivpow2(l_tilec->y0 - (1 << l_level_no) * l_y0b, l_level_no + 1); \ - l_band->x1 = opj_int_ceildivpow2(l_tilec->x1 - (1 << l_level_no) * l_x0b, l_level_no + 1); \ - l_band->y1 = opj_int_ceildivpow2(l_tilec->y1 - (1 << l_level_no) * l_y0b, l_level_no + 1); \ + l_band->x0 = opj_int_ceildivpow2(l_tilec->x0 - (1 << l_level_no) * l_x0b, (OPJ_INT32)(l_level_no + 1)); \ + l_band->y0 = opj_int_ceildivpow2(l_tilec->y0 - (1 << l_level_no) * l_y0b, (OPJ_INT32)(l_level_no + 1)); \ + l_band->x1 = opj_int_ceildivpow2(l_tilec->x1 - (1 << l_level_no) * l_x0b, (OPJ_INT32)(l_level_no + 1)); \ + l_band->y1 = opj_int_ceildivpow2(l_tilec->y1 - (1 << l_level_no) * l_y0b, (OPJ_INT32)(l_level_no + 1)); \ } \ \ /** avoid an if with storing function pointer */ \ l_gain = (*l_gain_ptr) (l_band->bandno); \ - numbps = l_image_comp->prec + l_gain; \ + numbps = (OPJ_INT32)(l_image_comp->prec + l_gain); \ l_band->stepsize = (OPJ_FLOAT32)(((1.0 + l_step_size->mant / 2048.0) * pow(2.0, (OPJ_INT32) (numbps - l_step_size->expn)))) * FRACTION; \ - l_band->numbps = l_step_size->expn + l_tccp->numgbits - 1; /* WHY -1 ? */ \ + l_band->numbps = l_step_size->expn + (OPJ_INT32)l_tccp->numgbits - 1; /* WHY -1 ? */ \ \ if (! l_band->precincts) { \ l_band->precincts = (opj_tcd_precinct_t *) opj_malloc( /*3 * */ l_nb_precinct_size); \ @@ -865,8 +865,8 @@ OPJ_BOOL FUNCTION ( opj_tcd_t *p_tcd, \ l_current_precinct = l_band->precincts; \ for (precno = 0; precno < l_nb_precincts; ++precno) { \ OPJ_INT32 tlcblkxstart, tlcblkystart, brcblkxend, brcblkyend; \ - OPJ_INT32 cbgxstart = tlcbgxstart + (precno % l_res->pw) * (1 << cbgwidthexpn); \ - OPJ_INT32 cbgystart = tlcbgystart + (precno / l_res->pw) * (1 << cbgheightexpn); \ + OPJ_INT32 cbgxstart = tlcbgxstart + (OPJ_INT32)(precno % l_res->pw) * (1 << cbgwidthexpn); \ + OPJ_INT32 cbgystart = tlcbgystart + (OPJ_INT32)(precno / l_res->pw) * (1 << cbgheightexpn); \ OPJ_INT32 cbgxend = cbgxstart + (1 << cbgwidthexpn); \ OPJ_INT32 cbgyend = cbgystart + (1 << cbgheightexpn); \ /*fprintf(stderr, "\t precno=%d; bandno=%d, resno=%d; compno=%d\n", precno, bandno , resno, compno);*/ \ @@ -881,16 +881,16 @@ OPJ_BOOL FUNCTION ( opj_tcd_t *p_tcd, \ l_current_precinct->y1 = opj_int_min(cbgyend, l_band->y1); \ /*fprintf(stderr, "\t prc_x0=%d; prc_y0=%d, prc_x1=%d; prc_y1=%d\n",l_current_precinct->x0, l_current_precinct->y0 ,l_current_precinct->x1, l_current_precinct->y1);*/ \ \ - tlcblkxstart = opj_int_floordivpow2(l_current_precinct->x0, cblkwidthexpn) << cblkwidthexpn; \ + tlcblkxstart = opj_int_floordivpow2(l_current_precinct->x0, (OPJ_INT32)cblkwidthexpn) << cblkwidthexpn; \ /*fprintf(stderr, "\t tlcblkxstart =%d\n",tlcblkxstart );*/ \ - tlcblkystart = opj_int_floordivpow2(l_current_precinct->y0, cblkheightexpn) << cblkheightexpn; \ + tlcblkystart = opj_int_floordivpow2(l_current_precinct->y0, (OPJ_INT32)cblkheightexpn) << cblkheightexpn; \ /*fprintf(stderr, "\t tlcblkystart =%d\n",tlcblkystart );*/ \ - brcblkxend = opj_int_ceildivpow2(l_current_precinct->x1, cblkwidthexpn) << cblkwidthexpn; \ + brcblkxend = opj_int_ceildivpow2(l_current_precinct->x1, (OPJ_INT32)cblkwidthexpn) << cblkwidthexpn; \ /*fprintf(stderr, "\t brcblkxend =%d\n",brcblkxend );*/ \ - brcblkyend = opj_int_ceildivpow2(l_current_precinct->y1, cblkheightexpn) << cblkheightexpn; \ + brcblkyend = opj_int_ceildivpow2(l_current_precinct->y1, (OPJ_INT32)cblkheightexpn) << cblkheightexpn; \ /*fprintf(stderr, "\t brcblkyend =%d\n",brcblkyend );*/ \ - l_current_precinct->cw = (brcblkxend - tlcblkxstart) >> cblkwidthexpn; \ - l_current_precinct->ch = (brcblkyend - tlcblkystart) >> cblkheightexpn; \ + l_current_precinct->cw = (OPJ_UINT32)((brcblkxend - tlcblkxstart) >> cblkwidthexpn); \ + l_current_precinct->ch = (OPJ_UINT32)((brcblkyend - tlcblkystart) >> cblkheightexpn); \ \ l_nb_code_blocks = l_current_precinct->cw * l_current_precinct->ch; \ /*fprintf(stderr, "\t\t\t\t precinct_cw = %d x recinct_ch = %d\n",l_current_precinct->cw, l_current_precinct->ch); */ \ @@ -962,8 +962,8 @@ OPJ_BOOL FUNCTION ( opj_tcd_t *p_tcd, \ l_code_block = l_current_precinct->cblks.ELEMENT; \ \ for (cblkno = 0; cblkno < l_nb_code_blocks; ++cblkno) { \ - OPJ_INT32 cblkxstart = tlcblkxstart + (cblkno % l_current_precinct->cw) * (1 << cblkwidthexpn); \ - OPJ_INT32 cblkystart = tlcblkystart + (cblkno / l_current_precinct->cw) * (1 << cblkheightexpn); \ + OPJ_INT32 cblkxstart = tlcblkxstart + (OPJ_INT32)(cblkno % l_current_precinct->cw) * (1 << cblkwidthexpn); \ + OPJ_INT32 cblkystart = tlcblkystart + (OPJ_INT32)(cblkno / l_current_precinct->cw) * (1 << cblkheightexpn); \ OPJ_INT32 cblkxend = cblkxstart + (1 << cblkwidthexpn); \ OPJ_INT32 cblkyend = cblkystart + (1 << cblkheightexpn); \ \ From fcc658f10669f76555dea1abf9a4cf7ed70662a9 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 11 Mar 2014 09:11:35 +0000 Subject: [PATCH 280/333] [trunk] Fix compilation errors when JPWL and/or MJ2 are build --- src/bin/common/color.c | 10 ++++++++++ src/bin/mj2/CMakeLists.txt | 4 ++++ 2 files changed, 14 insertions(+) diff --git a/src/bin/common/color.c b/src/bin/common/color.c index 5024ac9e..a9b5e0c7 100644 --- a/src/bin/common/color.c +++ b/src/bin/common/color.c @@ -150,8 +150,13 @@ static void sycc422_to_rgb(opj_image_t *img) free(img->comps[1].data); img->comps[1].data = d1; free(img->comps[2].data); img->comps[2].data = d2; +#if defined(USE_JPWL) || defined(USE_MJ2) + img->comps[1].w = maxw; img->comps[1].h = maxh; + img->comps[2].w = maxw; img->comps[2].h = maxh; +#else img->comps[1].w = (OPJ_UINT32)maxw; img->comps[1].h = (OPJ_UINT32)maxh; img->comps[2].w = (OPJ_UINT32)maxw; img->comps[2].h = (OPJ_UINT32)maxh; +#endif img->comps[1].dx = img->comps[0].dx; img->comps[2].dx = img->comps[0].dx; img->comps[1].dy = img->comps[0].dy; @@ -209,8 +214,13 @@ static void sycc420_to_rgb(opj_image_t *img) free(img->comps[1].data); img->comps[1].data = d1; free(img->comps[2].data); img->comps[2].data = d2; +#if defined(USE_JPWL) || defined(USE_MJ2) + img->comps[1].w = maxw; img->comps[1].h = maxh; + img->comps[2].w = maxw; img->comps[2].h = maxh; +#else img->comps[1].w = (OPJ_UINT32)maxw; img->comps[1].h = (OPJ_UINT32)maxh; img->comps[2].w = (OPJ_UINT32)maxw; img->comps[2].h = (OPJ_UINT32)maxh; +#endif img->comps[1].dx = img->comps[0].dx; img->comps[2].dx = img->comps[0].dx; img->comps[1].dy = img->comps[0].dy; diff --git a/src/bin/mj2/CMakeLists.txt b/src/bin/mj2/CMakeLists.txt index e6b005b6..78ad7543 100644 --- a/src/bin/mj2/CMakeLists.txt +++ b/src/bin/mj2/CMakeLists.txt @@ -32,6 +32,10 @@ foreach(exe ${MJ2_SRCS} ${OPENJPEG_SOURCE_DIR}/src/bin/common/color.c ) + set_property( + TARGET ${exe} + APPEND PROPERTY COMPILE_DEFINITIONS USE_MJ2 + ) target_link_libraries(${exe} ${LCMS_LIBNAME} openmj2) if(UNIX) From fa436eb36871b2c0c996823af7fceb1f629d0ebf Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 11 Mar 2014 10:27:01 +0000 Subject: [PATCH 281/333] [trunk] Rework fseek ifdefs blockers, it breaks the 64bits behavior for fseeko --- src/lib/openjp2/opj_includes.h | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/lib/openjp2/opj_includes.h b/src/lib/openjp2/opj_includes.h index f7f1f585..8b072c58 100644 --- a/src/lib/openjp2/opj_includes.h +++ b/src/lib/openjp2/opj_includes.h @@ -56,12 +56,10 @@ ftello() only on systems with special LFS support since some systems (e.g. FreeBSD) support a 64-bit off_t by default. */ -#if !defined(OPENJPIP_H_) && defined(SERVER) /* server implementation uses fcgi/fseek*/ -#if defined(OPJ_HAVE_FSEEKO) +#if defined(OPJ_HAVE_FSEEKO) && !defined(fseek) # define fseek fseeko # define ftell ftello #endif -#endif #if defined(WIN32) && !defined(Windows95) && !defined(__BORLANDC__) && \ From 5dd770746bed0b2b1cddc80588a66082b08fa4b9 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 11 Mar 2014 10:28:04 +0000 Subject: [PATCH 282/333] [trunk] Fix remainings warnings on linux/32bits arch --- src/lib/openjp2/jp2.c | 4 ++-- src/lib/openjp2/raw.c | 2 +- src/lib/openjp2/t2.c | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c index c845df1f..7ed9a54c 100644 --- a/src/lib/openjp2/jp2.c +++ b/src/lib/openjp2/jp2.c @@ -1004,12 +1004,12 @@ OPJ_BOOL opj_jp2_read_pclr( opj_jp2_t *jp2, if (bytes_to_read > sizeof(OPJ_UINT32)) bytes_to_read = sizeof(OPJ_UINT32); - if ((ptrdiff_t)p_pclr_header_size < p_pclr_header_data - orig_header_data + bytes_to_read) + if ((ptrdiff_t)p_pclr_header_size < p_pclr_header_data - orig_header_data + (ptrdiff_t)bytes_to_read) return OPJ_FALSE; if (bytes_to_read > sizeof(OPJ_UINT32)) bytes_to_read = sizeof(OPJ_UINT32); - if ((ptrdiff_t)p_pclr_header_size < p_pclr_header_data - orig_header_data + bytes_to_read) + if ((ptrdiff_t)p_pclr_header_size < p_pclr_header_data - orig_header_data + (ptrdiff_t)bytes_to_read) return OPJ_FALSE; opj_read_bytes(p_pclr_header_data, &l_value , bytes_to_read); /* Cji */ diff --git a/src/lib/openjp2/raw.c b/src/lib/openjp2/raw.c index 3d0aa5ba..8e705ccd 100644 --- a/src/lib/openjp2/raw.c +++ b/src/lib/openjp2/raw.c @@ -55,7 +55,7 @@ void opj_raw_destroy(opj_raw_t *raw) { OPJ_UINT32 opj_raw_numbytes(opj_raw_t *raw) { const ptrdiff_t diff = raw->bp - raw->start; - assert( diff <= 0xffffffff && diff >= 0 ); /* UINT32_MAX */ + assert( diff <= (ptrdiff_t)0xffffffff && diff >= 0 ); /* UINT32_MAX */ return (OPJ_UINT32)diff; } diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c index abac3fe4..c7e29952 100644 --- a/src/lib/openjp2/t2.c +++ b/src/lib/openjp2/t2.c @@ -441,7 +441,7 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2, /* don't forget to release pi */ opj_pi_destroy(l_pi,l_nb_pocs); - assert( l_current_data - p_src < UINT32_MAX ); + assert( l_current_data - p_src < (ptrdiff_t)UINT32_MAX ); *p_data_read = (OPJ_UINT32)(l_current_data - p_src); return OPJ_TRUE; } From ddb1d5776639db998bdf9a585830c4e354e65a21 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 11 Mar 2014 12:56:52 +0000 Subject: [PATCH 283/333] [trunk] Rework assertion to work on 32bits system --- src/lib/openjp2/t2.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c index c7e29952..9cfc0363 100644 --- a/src/lib/openjp2/t2.c +++ b/src/lib/openjp2/t2.c @@ -441,7 +441,7 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2, /* don't forget to release pi */ opj_pi_destroy(l_pi,l_nb_pocs); - assert( l_current_data - p_src < (ptrdiff_t)UINT32_MAX ); + assert( (OPJ_INT64)(l_current_data - p_src) < (OPJ_INT64)UINT32_MAX ); *p_data_read = (OPJ_UINT32)(l_current_data - p_src); return OPJ_TRUE; } From db82cf77784b1046ebc8c1eb8e700fdc3812bbdd Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 11 Mar 2014 15:17:39 +0000 Subject: [PATCH 284/333] [trunk] Add debug info to track issue 80 Update issue 80 --- src/lib/openjp2/j2k.c | 2 ++ src/lib/openjp2/t2.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index a9b42697..466e61b2 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -7619,6 +7619,7 @@ OPJ_BOOL opj_j2k_decode_tile ( opj_j2k_t * p_j2k, p_j2k->cstr_index) ) { opj_j2k_tcp_destroy(l_tcp); p_j2k->m_specific_param.m_decoder.m_state |= 0x8000;/*FIXME J2K_DEC_STATE_ERR;*/ + opj_event_msg(p_manager, EVT_ERROR, "Failed to decode.\n"); return OPJ_FALSE; } @@ -9120,6 +9121,7 @@ OPJ_BOOL opj_j2k_decode_tiles ( opj_j2k_t *p_j2k, if (! opj_j2k_decode_tile(p_j2k,l_current_tile_no,l_current_data,l_data_size,p_stream,p_manager)) { opj_free(l_current_data); + opj_event_msg(p_manager, EVT_ERROR, "Failed to decode tile %d/%d\n", l_current_tile_no +1, p_j2k->m_cp.th * p_j2k->m_cp.tw); return OPJ_FALSE; } opj_event_msg(p_manager, EVT_INFO, "Tile %d/%d has been decoded.\n", l_current_tile_no +1, p_j2k->m_cp.th * p_j2k->m_cp.tw); diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c index 9cfc0363..dd5f9cc3 100644 --- a/src/lib/openjp2/t2.c +++ b/src/lib/openjp2/t2.c @@ -896,7 +896,7 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, if (p_max_length < 2) { fprintf(stderr, "Not enough space for expected EPH marker\n"); } else if ((*l_header_data) != 0xff || (*(l_header_data + 1) != 0x92)) { - printf("Error : expected EPH marker\n"); + fprintf(stderr, "Error : expected EPH marker\n"); } else { l_header_data += 2; } @@ -1224,6 +1224,8 @@ OPJ_BOOL opj_t2_skip_packet_data( opj_t2_t* p_t2, do { if (* p_data_read + l_seg->newlen > p_max_length) { + fprintf(stderr, "segment too long (%d) with max (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n", + l_seg->newlen, p_max_length, cblkno, p_pi->precno, bandno, p_pi->resno, p_pi->compno); return OPJ_FALSE; } From 59270c39a7357c777e7c9ba90b8c14a40e282d68 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 11 Mar 2014 15:21:12 +0000 Subject: [PATCH 285/333] [trunk] Re-active old warning about missing SOP marker --- src/lib/openjp2/t2.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c index dd5f9cc3..eb78c4b9 100644 --- a/src/lib/openjp2/t2.c +++ b/src/lib/openjp2/t2.c @@ -845,6 +845,7 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, if (p_tcp->csty & J2K_CP_CSTY_SOP) { if ((*l_current_data) != 0xff || (*(l_current_data + 1) != 0x91)) { /* TODO opj_event_msg(t2->cinfo->event_mgr, EVT_WARNING, "Expected SOP marker\n"); */ + fprintf(stderr, "Error : expected SOP marker\n"); } else { l_current_data += 6; } From 6b51d11d085753c64fb7c2908068730bcf95d5cf Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 12 Mar 2014 10:10:21 +0000 Subject: [PATCH 286/333] [trunk] Make sure when reading POC that number of layers (layer end) is within acceptable bound. Fixes issue 80 --- src/lib/openjp2/j2k.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 466e61b2..ce5ef77f 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -3175,6 +3175,8 @@ static OPJ_BOOL opj_j2k_read_poc ( opj_j2k_t *p_j2k, opj_read_bytes(p_header_data,&(l_current_poc->compno0),l_comp_room); /* CSpoc_i */ p_header_data+=l_comp_room; opj_read_bytes(p_header_data,&(l_current_poc->layno1),2); /* LYEpoc_i */ + /* make sure layer end is in acceptable bounds */ + l_current_poc->layno1 = opj_uint_min(l_current_poc->layno1, l_tcp->numlayers); p_header_data+=2; opj_read_bytes(p_header_data,&(l_current_poc->resno1),1); /* REpoc_i */ ++p_header_data; From 73315c2edcd5320922aabe6cf07eb666c182eb74 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 12 Mar 2014 10:50:47 +0000 Subject: [PATCH 287/333] [trunk] Simplify code when reading in TIFF images --- tests/compare_images.c | 93 +++++++----------------------------------- 1 file changed, 15 insertions(+), 78 deletions(-) diff --git a/tests/compare_images.c b/tests/compare_images.c index a9a44ca7..12a0809f 100644 --- a/tests/compare_images.c +++ b/tests/compare_images.c @@ -247,12 +247,10 @@ static opj_image_t* readImageFromFilePPM(const char* filename, int nbFilenamePGX static opj_image_t* readImageFromFileTIF(const char* filename, int nbFilenamePGX, const char *separator) { - int it_file; opj_image_t* image_read = NULL; - opj_image_t* image = NULL; opj_cparameters_t parameters; - opj_image_cmptparm_t* param_image_read; - int** data; + (void)nbFilenamePGX; + (void)separator; /* conformance test suite produce annoying warning/error: * TIFFReadDirectory: Warning, /.../data/baseline/conformance/jp2_1.tif: unknown field with tag 37724 (0x935c) encountered. @@ -264,85 +262,24 @@ static opj_image_t* readImageFromFileTIF(const char* filename, int nbFilenamePGX TIFFSetErrorHandler(NULL); #endif - /* If separator is empty => nb file to read is equal to one*/ - if ( strlen(separator) == 0 ) - nbFilenamePGX = 1; - /* set encoding parameters to default values */ opj_set_default_encoder_parameters(¶meters); parameters.decod_format = TIF_DFMT; strcpy(parameters.infile, filename); - /* Allocate memory*/ - param_image_read = malloc((size_t)nbFilenamePGX * sizeof(opj_image_cmptparm_t)); - data = malloc((size_t)nbFilenamePGX * sizeof(*data)); - - for (it_file = 0; it_file < nbFilenamePGX; it_file++) - { - /* Create the right filename*/ - char *filenameComponentPGX; - if (strlen(separator) == 0) - { - filenameComponentPGX = malloc((strlen(filename) + 1) * sizeof(*filenameComponentPGX)); - strcpy(filenameComponentPGX, filename); - } - else - filenameComponentPGX = createMultiComponentsFilename(filename, it_file, separator); - - /* Read the tif file corresponding to the component */ + /* Read the tif file corresponding to the component */ #ifdef OPJ_HAVE_LIBTIFF - image_read = tiftoimage(filenameComponentPGX, ¶meters); + image_read = tiftoimage(filename, ¶meters); #endif - if (!image_read) - { - int it_free_data; - fprintf(stderr, "Unable to load TIF file\n"); - - free(param_image_read); - - for (it_free_data = 0; it_free_data < it_file; it_free_data++) { - free(data[it_free_data]); - } - free(data); - - free(filenameComponentPGX); - - return NULL; - } - - /* Set the image_read parameters*/ - param_image_read[it_file].x0 = 0; - param_image_read[it_file].y0 = 0; - param_image_read[it_file].dx = 0; - param_image_read[it_file].dy = 0; - param_image_read[it_file].h = image_read->comps->h; - param_image_read[it_file].w = image_read->comps->w; - param_image_read[it_file].bpp = image_read->comps->bpp; - param_image_read[it_file].prec = image_read->comps->prec; - param_image_read[it_file].sgnd = image_read->comps->sgnd; - - /* Copy data*/ - data[it_file] = malloc(param_image_read[it_file].h * param_image_read[it_file].w * sizeof(int)); - memcpy(data[it_file], image_read->comps->data, image_read->comps->h * image_read->comps->w * sizeof(int)); - - /* Free memory*/ - opj_image_destroy(image_read); - free(filenameComponentPGX); - } - - image = opj_image_create((OPJ_UINT32)nbFilenamePGX, param_image_read, OPJ_CLRSPC_UNSPECIFIED); - for (it_file = 0; it_file < nbFilenamePGX; it_file++) + if (!image_read) { - /* Copy data into output image and free memory*/ - memcpy(image->comps[it_file].data, data[it_file], image->comps[it_file].h * image->comps[it_file].w * sizeof(int)); - free(data[it_file]); + fprintf(stderr, "Unable to load TIF file\n"); + return NULL; } - /* Free memory*/ - free(param_image_read); - free(data); - - return image; + /* \postconditions */ + assert( image_read->numcomps == 3 ); + return image_read; } static opj_image_t* readImageFromFilePGX(const char* filename, int nbFilenamePGX, const char *separator) @@ -711,7 +648,7 @@ int main(int argc, char **argv) int failed = 1; int nbFilenamePGXbase = 0, nbFilenamePGXtest = 0; char *filenamePNGtest= NULL, *filenamePNGbase = NULL, *filenamePNGdiff = NULL; - int memsizebasefilename, memsizetestfilename; + size_t memsizebasefilename, memsizetestfilename; size_t memsizedifffilename; int valueDiff = 0, nbPixelDiff = 0; double sumDiff = 0.0; @@ -763,8 +700,8 @@ int main(int argc, char **argv) printf("************************* \n"); /*----------BASELINE IMAGE--------*/ - memsizebasefilename = (int)strlen(inParam.test_filename) + 1 + 5 + 2 + 4; - memsizetestfilename = (int)strlen(inParam.test_filename) + 1 + 5 + 2 + 4; + memsizebasefilename = strlen(inParam.test_filename) + 1 + 5 + 2 + 4; + memsizetestfilename = strlen(inParam.test_filename) + 1 + 5 + 2 + 4; decod_format = get_decod_format(&inParam); if( decod_format == -1 ) @@ -793,7 +730,7 @@ int main(int argc, char **argv) goto cleanup; } - filenamePNGbase = (char*) malloc((size_t)memsizebasefilename); + filenamePNGbase = (char*) malloc(memsizebasefilename); strcpy(filenamePNGbase, inParam.test_filename); strcat(filenamePNGbase, ".base"); /*printf("filenamePNGbase = %s [%d / %d octets]\n",filenamePNGbase, strlen(filenamePNGbase),memsizebasefilename );*/ @@ -819,7 +756,7 @@ int main(int argc, char **argv) goto cleanup; } - filenamePNGtest = (char*) malloc((size_t)memsizetestfilename); + filenamePNGtest = (char*) malloc(memsizetestfilename); strcpy(filenamePNGtest, inParam.test_filename); strcat(filenamePNGtest, ".test"); /*printf("filenamePNGtest = %s [%d / %d octets]\n",filenamePNGtest, strlen(filenamePNGtest),memsizetestfilename );*/ From d38e32c036d85a394871c103ab44a20033818b51 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 12 Mar 2014 11:32:44 +0000 Subject: [PATCH 288/333] [trunk] TIFF files in test suite can have 1 or 3 components --- tests/compare_images.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/compare_images.c b/tests/compare_images.c index 12a0809f..b6cc2be4 100644 --- a/tests/compare_images.c +++ b/tests/compare_images.c @@ -278,7 +278,7 @@ static opj_image_t* readImageFromFileTIF(const char* filename, int nbFilenamePGX } /* \postconditions */ - assert( image_read->numcomps == 3 ); + assert( image_read->numcomps == 1 || image_read->numcomps == 3 ); return image_read; } @@ -875,10 +875,10 @@ int main(int argc, char **argv) { char *filenamePNGbase_it_comp, *filenamePNGtest_it_comp, *filenamePNGdiff_it_comp; - filenamePNGbase_it_comp = (char*) malloc((size_t)memsizebasefilename); + filenamePNGbase_it_comp = (char*) malloc(memsizebasefilename); strcpy(filenamePNGbase_it_comp,filenamePNGbase); - filenamePNGtest_it_comp = (char*) malloc((size_t)memsizetestfilename); + filenamePNGtest_it_comp = (char*) malloc(memsizetestfilename); strcpy(filenamePNGtest_it_comp,filenamePNGtest); filenamePNGdiff_it_comp = (char*) malloc(memsizedifffilename); From dd0d2c2f0ae4f7c7bfd91876e7e19f8f3e791440 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 12 Mar 2014 13:55:41 +0000 Subject: [PATCH 289/333] [trunk] Add debug info to be able to test integration with littlecms --- src/bin/common/color.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/bin/common/color.c b/src/bin/common/color.c index a9b5e0c7..8b3d2a7e 100644 --- a/src/bin/common/color.c +++ b/src/bin/common/color.c @@ -33,6 +33,7 @@ #include #include #include +#include #include "opj_apps_config.h" #include "openjpeg.h" @@ -292,6 +293,7 @@ void color_sycc_to_rgb(opj_image_t *img) #endif /* OPJ_HAVE_LIBLCMS1 */ +/*#define DEBUG_PROFILE*/ void color_apply_icc_profile(opj_image_t *image) { cmsHPROFILE in_prof, out_prof; @@ -304,6 +306,11 @@ void color_apply_icc_profile(opj_image_t *image) in_prof = cmsOpenProfileFromMem(image->icc_profile_buf, image->icc_profile_len); +#ifdef DEBUG_PROFILE + FILE *icm = fopen("debug.icm","wb"); + fwrite( image->icc_profile_buf,1, image->icc_profile_len,icm); + fclose(icm); +#endif if(in_prof == NULL) return; From 41add6882bc59e754d1ca08a6c651c39dbd26173 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Wed, 12 Mar 2014 14:18:25 +0000 Subject: [PATCH 290/333] [trunk] Make sure to use 8bits buffer when applying the ICC profile. Fixes issue 281 --- src/bin/common/color.c | 44 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/bin/common/color.c b/src/bin/common/color.c index 8b3d2a7e..47eefa0b 100644 --- a/src/bin/common/color.c +++ b/src/bin/common/color.c @@ -326,8 +326,16 @@ void color_apply_icc_profile(opj_image_t *image) if(out_space == cmsSigRgbData) /* enumCS 16 */ { + if( prec <= 8 ) +{ + in_type = TYPE_RGB_8; + out_type = TYPE_RGB_8; +} +else +{ in_type = TYPE_RGB_16; out_type = TYPE_RGB_16; +} out_prof = cmsCreate_sRGBProfile(); image->color_space = OPJ_CLRSPC_SRGB; } @@ -408,6 +416,41 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. " if(image->numcomps > 2)/* RGB, RGBA */ { + if( prec <= 8 ) +{ + unsigned char *inbuf, *outbuf, *in, *out; + max = max_w * max_h; + nr_samples = (cmsUInt32Number)max * 3 * (cmsUInt32Number)sizeof(unsigned char); + in = inbuf = (unsigned char*)malloc(nr_samples); + out = outbuf = (unsigned char*)malloc(nr_samples); + + r = image->comps[0].data; + g = image->comps[1].data; + b = image->comps[2].data; + + for(i = 0; i < max; ++i) + { + *in++ = (unsigned char)*r++; + *in++ = (unsigned char)*g++; + *in++ = (unsigned char)*b++; + } + + cmsDoTransform(transform, inbuf, outbuf, (cmsUInt32Number)max); + + r = image->comps[0].data; + g = image->comps[1].data; + b = image->comps[2].data; + + for(i = 0; i < max; ++i) + { + *r++ = (int)*out++; + *g++ = (int)*out++; + *b++ = (int)*out++; + } + free(inbuf); free(outbuf); +} +else +{ unsigned short *inbuf, *outbuf, *in, *out; max = max_w * max_h; nr_samples = (cmsUInt32Number)max * 3 * (cmsUInt32Number)sizeof(unsigned short); @@ -438,6 +481,7 @@ fprintf(stderr,"%s:%d:color_apply_icc_profile\n\tcmsCreateTransform failed. " *b++ = (int)*out++; } free(inbuf); free(outbuf); +} } else /* GRAY, GRAYA */ { From c7b646e23afd4875531b0f264aa47f9ee5b8d335 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 13 Mar 2014 09:57:20 +0000 Subject: [PATCH 291/333] [trunk] Add a small helper to spli ppm into 3 pgm files Update issue 235 --- tests/CMakeLists.txt | 2 + tests/ppm2rgb3.c | 132 +++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 tests/ppm2rgb3.c diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 625199f7..a62ceaf9 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -98,3 +98,5 @@ if(BUILD_JPIP) -DEXPECTED_MD5=${md5} -P ${PROJECT_SOURCE_DIR}/cmake/JPIPTestDriver.cmake) endif() endif() + +add_executable(ppm2rgb3 ppm2rgb3.c) diff --git a/tests/ppm2rgb3.c b/tests/ppm2rgb3.c new file mode 100644 index 00000000..9d46f98e --- /dev/null +++ b/tests/ppm2rgb3.c @@ -0,0 +1,132 @@ +/* + * Copyright (c) 2014, Mathieu Malaterre + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Technically on UNIX, one can simply call `ppmtorgb3`, but on my system it + * did not work. So I had to write my own. + */ + +#include /* fprintf */ +#include /* strcmp */ +#include /* malloc */ + +static const char magic[] = "P6"; + +static int readheader( FILE *ppm, int *X, int *Y, int *bpp ) +{ + char buffer[256]; + char strbuffer[256]; + char *line; + int n; + + *X = *Y = *bpp = 0; + + line = fgets(buffer, sizeof(buffer), ppm); + if( !line ) return 0; + n = sscanf(buffer, "%255[^\r\n]", strbuffer); + if( n != 1 ) return 0; + if( strcmp(strbuffer, magic ) != 0 ) return 0; + + /* skip comments */ + while( fgets(buffer, sizeof(buffer), ppm) && *buffer == '#' ) + { + } + n = sscanf(buffer, "%d %d", X,Y); + if( n != 2 ) return 0; + line = fgets(buffer, sizeof(buffer), ppm); + if( !line ) return 0; + n = sscanf(buffer, "%d", bpp); + if( n != 1 ) return 0; + if( *bpp != 255 ) return 0; + + return 1; +} + +static int writeoutput( const char *fn, FILE *ppm, int X, int Y, int bpp ) +{ + FILE *outf[] = {NULL, NULL, NULL}; + int i, x, y = 0; + char outfn[256]; + static const char *exts[3] = { + "red", + "grn", + "blu" + }; + char *image_line = NULL; + int ok = 0; + + /* write single comp as PGM: P5 */ + for( i = 0; i < 3; ++i ) + { + snprintf( outfn, sizeof(outfn), "%s.%s.pgm", fn, exts[i] ); + outf[i] = fopen( outfn, "wb" ); + if( !outf[i] ) goto cleanup; + /* write header */ + fprintf( outf[i], "P5\n" ); + fprintf( outf[i], "%d %d\n", X, Y ); + fprintf( outf[i], "%d\n", bpp ); + } + + /* write pixel data */ + image_line = (char*)malloc( (size_t)X * 3 * sizeof(char) ); + if( !image_line ) goto cleanup; + while( fread(image_line, sizeof(char), (size_t)X * 3, ppm) == (size_t)X * 3 ) + { + for( x = 0; x < X; ++x ) + for( i = 0; i < 3; ++i ) + if( fputc( image_line[3*x+i], outf[i] ) == EOF ) goto cleanup; + ++y; + } + if( y == Y ) + ok = 1; +cleanup: + free(image_line); + for( i = 0; i < 3; ++i ) + if( outf[i] ) fclose( outf[i] ); + + return ok; +} + +int main(int argc, char *argv[]) +{ + const char *fn; + FILE *ppm = NULL; + int X, Y, bpp; + int ok = 0; + + if( argc < 2 ) goto cleanup; + fn = argv[1]; + ppm = fopen( fn, "rb" ); + + if( !readheader( ppm, &X, &Y, &bpp ) ) goto cleanup; + + if( !writeoutput(fn, ppm, X, Y, bpp ) ) goto cleanup; + + ok = 1; +cleanup: + if(ppm) fclose(ppm); + return ok ? EXIT_SUCCESS : EXIT_FAILURE; +} From fe100fb49038b246888fde40878c92ae4878f673 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 13 Mar 2014 10:35:41 +0000 Subject: [PATCH 292/333] [trunk] Add debug code to extract decompressed image right before PCLR handling Update issue 235 --- src/lib/openjp2/j2k.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index ce5ef77f..e446dab0 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -9322,6 +9322,13 @@ OPJ_BOOL opj_j2k_decode(opj_j2k_t * p_j2k, for (compno = 0; compno < p_image->numcomps; compno++) { p_image->comps[compno].resno_decoded = p_j2k->m_output_image->comps[compno].resno_decoded; p_image->comps[compno].data = p_j2k->m_output_image->comps[compno].data; +#if 0 + char fn[256]; + sprintf( fn, "/tmp/%d.raw", compno ); + FILE *debug = fopen( fn, "wb" ); + fwrite( p_image->comps[compno].data, sizeof(OPJ_INT32), p_image->comps[compno].w * p_image->comps[compno].h, debug ); + fclose( debug ); +#endif p_j2k->m_output_image->comps[compno].data = NULL; } From 237253d83bcbade1851fd6ec4c6bdc6b37a25b15 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 13 Mar 2014 10:42:06 +0000 Subject: [PATCH 293/333] [trunk] Add some documention in the pi code --- src/lib/openjp2/pi.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib/openjp2/pi.c b/src/lib/openjp2/pi.c index eeb14b7d..2606051b 100644 --- a/src/lib/openjp2/pi.c +++ b/src/lib/openjp2/pi.c @@ -1001,16 +1001,16 @@ void opj_pi_update_decode_poc (opj_pi_iterator_t * p_pi, l_current_poc = p_tcp->pocs; for (pino = 0;pinopoc.prg = l_current_poc->prg; + l_current_pi->poc.prg = l_current_poc->prg; /* Progression Order #0 */ l_current_pi->first = 1; - l_current_pi->poc.resno0 = l_current_poc->resno0; - l_current_pi->poc.compno0 = l_current_poc->compno0; + l_current_pi->poc.resno0 = l_current_poc->resno0; /* Resolution Level Index #0 (Start) */ + l_current_pi->poc.compno0 = l_current_poc->compno0; /* Component Index #0 (Start) */ l_current_pi->poc.layno0 = 0; l_current_pi->poc.precno0 = 0; - l_current_pi->poc.resno1 = l_current_poc->resno1; - l_current_pi->poc.compno1 = l_current_poc->compno1; - l_current_pi->poc.layno1 = l_current_poc->layno1; + l_current_pi->poc.resno1 = l_current_poc->resno1; /* Resolution Level Index #0 (End) */ + l_current_pi->poc.compno1 = l_current_poc->compno1; /* Component Index #0 (End) */ + l_current_pi->poc.layno1 = l_current_poc->layno1; /* Layer Index #0 (End) */ l_current_pi->poc.precno1 = p_max_precision; ++l_current_pi; ++l_current_poc; From 51ab8cd67dac033c3b7e93e6ae7d0f42f6dcb30b Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 13 Mar 2014 10:46:54 +0000 Subject: [PATCH 294/333] [trunk] Tweak documentation in t2.c. Be more verbose in case of failure. --- src/lib/openjp2/t2.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c index eb78c4b9..f080550e 100644 --- a/src/lib/openjp2/t2.c +++ b/src/lib/openjp2/t2.c @@ -354,8 +354,8 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2, for (pino = 0; pino <= l_tcp->numpocs; ++pino) { - /* if the resolution needed is to low, one dim of the tilec could be equal to zero - * and no packets are used to encode this resolution and + /* if the resolution needed is too low, one dim of the tilec could be equal to zero + * and no packets are used to decode this resolution and * l_current_pi->resno is always >= p_tile->comps[l_current_pi->compno].minimum_num_resolutions * and no l_img_comp->resno_decoded are computed */ @@ -441,7 +441,6 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2, /* don't forget to release pi */ opj_pi_destroy(l_pi,l_nb_pocs); - assert( (OPJ_INT64)(l_current_data - p_src) < (OPJ_INT64)UINT32_MAX ); *p_data_read = (OPJ_UINT32)(l_current_data - p_src); return OPJ_TRUE; } @@ -1024,6 +1023,7 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, fprintf(stderr, "Not enough space for expected EPH marker\n"); } else if ((*l_header_data) != 0xff || (*(l_header_data + 1) != 0x92)) { /* TODO opj_event_msg(t2->cinfo->event_mgr, EVT_ERROR, "Expected EPH marker\n"); */ + fprintf(stderr, "Error : expected EPH marker\n"); } else { l_header_data += 2; } @@ -1102,6 +1102,8 @@ OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2, do { if (l_current_data + l_seg->newlen > p_src_data + p_max_length) { + fprintf(stderr, "read: segment too long (%d) with max (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n", + l_seg->newlen, p_max_length, cblkno, p_pi->precno, bandno, p_pi->resno, p_pi->compno); return OPJ_FALSE; } @@ -1225,7 +1227,7 @@ OPJ_BOOL opj_t2_skip_packet_data( opj_t2_t* p_t2, do { if (* p_data_read + l_seg->newlen > p_max_length) { - fprintf(stderr, "segment too long (%d) with max (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n", + fprintf(stderr, "skip: segment too long (%d) with max (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n", l_seg->newlen, p_max_length, cblkno, p_pi->precno, bandno, p_pi->resno, p_pi->compno); return OPJ_FALSE; } From 320784659d09b702676835ed60fe0e5bb3999860 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 13 Mar 2014 10:56:48 +0000 Subject: [PATCH 295/333] [trunk] Just in case this would be helpful for other, here is the code used to track issue 80 Update issue 80 --- src/lib/openjp2/t2.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c index f080550e..56d5ee99 100644 --- a/src/lib/openjp2/t2.c +++ b/src/lib/openjp2/t2.c @@ -311,6 +311,13 @@ OPJ_BOOL opj_t2_encode_packets( opj_t2_t* p_t2, return OPJ_TRUE; } +/* see issue 80 */ +#if 0 +#define JAS_FPRINTF fprintf +#else +#define JAS_FPRINTF +#endif + OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2, OPJ_UINT32 p_tile_no, opj_tcd_tile_t *p_tile, @@ -368,7 +375,8 @@ OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2, memset(first_pass_failed, OPJ_TRUE, l_image->numcomps * sizeof(OPJ_BOOL)); while (opj_pi_next(l_current_pi)) { - + JAS_FPRINTF( stderr, "packet offset=00000166 prg=%d cmptno=%02d rlvlno=%02d prcno=%03d lyrno=%02d\n\n", + l_current_pi->poc.prg1, l_current_pi->compno, l_current_pi->resno, l_current_pi->precno, l_current_pi->layno ); if (l_tcp->num_layers_to_decode > l_current_pi->layno && l_current_pi->resno < p_tile->comps[l_current_pi->compno].minimum_num_resolutions) { @@ -785,7 +793,6 @@ static OPJ_BOOL opj_t2_skip_packet( opj_t2_t* p_t2, } - OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, opj_tcd_tile_t *p_tile, opj_tcp_t *p_tcp, @@ -885,6 +892,7 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, opj_bio_init_dec(l_bio, l_header_data,*l_modified_length_ptr); l_present = opj_bio_read(l_bio, 1); + JAS_FPRINTF(stderr, "present=%d \n", l_present ); if (!l_present) { /* TODO MSD: no test to control the output of this function*/ opj_bio_inalign(l_bio); @@ -947,6 +955,7 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, if (!l_included) { l_cblk->numnewpasses = 0; ++l_cblk; + JAS_FPRINTF(stderr, "included=%d \n", l_included); continue; } @@ -991,6 +1000,7 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, do { l_cblk->segs[l_segno].numnewpasses = (OPJ_UINT32)opj_int_min((OPJ_INT32)(l_cblk->segs[l_segno].maxpasses - l_cblk->segs[l_segno].numpasses), n); l_cblk->segs[l_segno].newlen = opj_bio_read(l_bio, l_cblk->numlenbits + opj_uint_floorlog2(l_cblk->segs[l_segno].numnewpasses)); + JAS_FPRINTF(stderr, "included=%d numnewpasses=%d increment=%d len=%d \n", l_included, l_cblk->segs[l_segno].numnewpasses, l_increment, l_cblk->segs[l_segno].newlen ); n -= (OPJ_INT32)l_cblk->segs[l_segno].numnewpasses; if (n > 0) { @@ -1030,6 +1040,8 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, } l_header_length = (OPJ_UINT32)(l_header_data - *l_header_data_start); + JAS_FPRINTF( stderr, "hdrlen=%d \n", l_header_length ); + JAS_FPRINTF( stderr, "packet body\n"); *l_modified_length_ptr -= l_header_length; *l_header_data_start += l_header_length; @@ -1251,6 +1263,7 @@ OPJ_BOOL opj_t2_skip_packet_data( opj_t2_t* p_t2, }; #endif /* USE_JPWL */ + JAS_FPRINTF(stderr, "p_data_read (%d) newlen (%d) \n", *p_data_read, l_seg->newlen ); *(p_data_read) += l_seg->newlen; l_seg->numpasses += l_seg->numnewpasses; From f0a2fdd50870d1fc561a0e5a69c8e1cd59d56cf5 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 13 Mar 2014 11:03:05 +0000 Subject: [PATCH 296/333] [trunk] Fix compilation on VS2010 (snprintf is not C89). C++11 should avoid this in the future --- tests/ppm2rgb3.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/ppm2rgb3.c b/tests/ppm2rgb3.c index 9d46f98e..c9b4772a 100644 --- a/tests/ppm2rgb3.c +++ b/tests/ppm2rgb3.c @@ -81,6 +81,9 @@ static int writeoutput( const char *fn, FILE *ppm, int X, int Y, int bpp ) /* write single comp as PGM: P5 */ for( i = 0; i < 3; ++i ) { +#ifdef _MSC_VER +#define snprintf _snprintf /* Visual Studio */ +#endif snprintf( outfn, sizeof(outfn), "%s.%s.pgm", fn, exts[i] ); outf[i] = fopen( outfn, "wb" ); if( !outf[i] ) goto cleanup; From 8447f0a323556081ee2288aa34cfc1c14f96bb59 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 13 Mar 2014 12:26:06 +0000 Subject: [PATCH 297/333] [trunk] Add a double check for user input --- tests/compare_images.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/compare_images.c b/tests/compare_images.c index b6cc2be4..f0dc5e82 100644 --- a/tests/compare_images.c +++ b/tests/compare_images.c @@ -262,6 +262,8 @@ static opj_image_t* readImageFromFileTIF(const char* filename, int nbFilenamePGX TIFFSetErrorHandler(NULL); #endif + if ( strlen(separator) != 0 ) return NULL; + /* set encoding parameters to default values */ opj_set_default_encoder_parameters(¶meters); parameters.decod_format = TIF_DFMT; From 92e07f3b7428afa45c865f19377f96afe95a2302 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 13 Mar 2014 12:26:30 +0000 Subject: [PATCH 298/333] [trunk] Fix test NR-DEC-issue171.jp2-71-decode-md5 after recent code change --- tests/nonregression/md5refs.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/tests/nonregression/md5refs.txt b/tests/nonregression/md5refs.txt index 7b46562f..f52bed61 100644 --- a/tests/nonregression/md5refs.txt +++ b/tests/nonregression/md5refs.txt @@ -27,9 +27,9 @@ cccccccccccccccccccccccccccccccc issue135.j2k_2.pgx 619694e5674992b3286244bf13058f7c issue142.j2k_0.pgx c675c4b77dc3cc2a0d6542a32b438a48 issue142.j2k_1.pgx 663ebdd12dd6a36915ea1152c43cb69a issue142.j2k_2.pgx -820b37ef934bd17d45dd73f5dc4d95b7 issue171.jp2_0.pgx -4596dcd3efa51f84824b60353e2af306 issue171.jp2_1.pgx -c2a656096b1965c3b4a26563d6ade467 issue171.jp2_2.pgx +c44662b1f7fe01caa2ebf3ad62948e3e issue171.jp2_0.pgx +f70e8a4e5dbefeb44d50edd79b6c4cf6 issue171.jp2_1.pgx +18bc167a1c851db2fd9f8c7af3289134 issue171.jp2_2.pgx adda4f5e46845b96dd3df14a76aa7229 issue188_beach_64bitsbox.jp2_0.pgx 90a9709c166019d1e101e7b96d257ed9 issue188_beach_64bitsbox.jp2_1.pgx 37e23d2df06ee60bf0f9f5e1c16054d8 issue188_beach_64bitsbox.jp2_2.pgx From 5624e4a25ffff6fedc0385425ced06240505dcec Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 13 Mar 2014 12:31:41 +0000 Subject: [PATCH 299/333] [trunk] Always report when decompression failed as return code value --- src/bin/jp2/opj_decompress.c | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/bin/jp2/opj_decompress.c b/src/bin/jp2/opj_decompress.c index 44431f20..aded1996 100644 --- a/src/bin/jp2/opj_decompress.c +++ b/src/bin/jp2/opj_decompress.c @@ -881,7 +881,8 @@ int main(int argc, char **argv) case PGX_DFMT: /* PGX */ if(imagetopgx(image, parameters.outfile)){ - fprintf(stdout,"Outfile %s not generated\n",parameters.outfile); + fprintf(stderr,"Outfile %s not generated\n",parameters.outfile); + failed = 1; } else { fprintf(stdout,"Generated Outfile %s\n",parameters.outfile); @@ -890,7 +891,8 @@ int main(int argc, char **argv) case BMP_DFMT: /* BMP */ if(imagetobmp(image, parameters.outfile)){ - fprintf(stdout,"Outfile %s not generated\n",parameters.outfile); + fprintf(stderr,"Outfile %s not generated\n",parameters.outfile); + failed = 1; } else { fprintf(stdout,"Generated Outfile %s\n",parameters.outfile); @@ -899,7 +901,8 @@ int main(int argc, char **argv) #ifdef OPJ_HAVE_LIBTIFF case TIF_DFMT: /* TIFF */ if(imagetotif(image, parameters.outfile)){ - fprintf(stdout,"Outfile %s not generated\n",parameters.outfile); + fprintf(stderr,"Outfile %s not generated\n",parameters.outfile); + failed = 1; } else { fprintf(stdout,"Generated Outfile %s\n",parameters.outfile); @@ -908,7 +911,8 @@ int main(int argc, char **argv) #endif /* OPJ_HAVE_LIBTIFF */ case RAW_DFMT: /* RAW */ if(imagetoraw(image, parameters.outfile)){ - fprintf(stdout,"Error generating raw file. Outfile %s not generated\n",parameters.outfile); + fprintf(stderr,"Error generating raw file. Outfile %s not generated\n",parameters.outfile); + failed = 1; } else { fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile); @@ -917,7 +921,8 @@ int main(int argc, char **argv) case RAWL_DFMT: /* RAWL */ if(imagetorawl(image, parameters.outfile)){ - fprintf(stdout,"Error generating rawl file. Outfile %s not generated\n",parameters.outfile); + fprintf(stderr,"Error generating rawl file. Outfile %s not generated\n",parameters.outfile); + failed = 1; } else { fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile); @@ -926,7 +931,8 @@ int main(int argc, char **argv) case TGA_DFMT: /* TGA */ if(imagetotga(image, parameters.outfile)){ - fprintf(stdout,"Error generating tga file. Outfile %s not generated\n",parameters.outfile); + fprintf(stderr,"Error generating tga file. Outfile %s not generated\n",parameters.outfile); + failed = 1; } else { fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile); @@ -935,7 +941,8 @@ int main(int argc, char **argv) #ifdef OPJ_HAVE_LIBPNG case PNG_DFMT: /* PNG */ if(imagetopng(image, parameters.outfile)){ - fprintf(stdout,"Error generating png file. Outfile %s not generated\n",parameters.outfile); + fprintf(stderr,"Error generating png file. Outfile %s not generated\n",parameters.outfile); + failed = 1; } else { fprintf(stdout,"Successfully generated Outfile %s\n",parameters.outfile); @@ -947,6 +954,7 @@ int main(int argc, char **argv) */ default: fprintf(stderr,"Outfile %s not generated\n",parameters.outfile); + failed = 1; } /* free remaining structures */ From 68398b2a5ac7505d608adc4f45e128a87bab9ce7 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 13 Mar 2014 12:37:36 +0000 Subject: [PATCH 300/333] [trunk] Add documentation to the checkmd5refs cmake module (used for regression testing) --- tests/nonregression/CMakeLists.txt | 1 - tests/nonregression/checkmd5refs.cmake | 30 +++++++++++++------------- 2 files changed, 15 insertions(+), 16 deletions(-) diff --git a/tests/nonregression/CMakeLists.txt b/tests/nonregression/CMakeLists.txt index f21a0908..51664256 100644 --- a/tests/nonregression/CMakeLists.txt +++ b/tests/nonregression/CMakeLists.txt @@ -319,7 +319,6 @@ foreach(OPJ_TEST_CMD_LINE ${OPJ_TEST_CMD_LINE_LIST}) # if not failed, check against registered md5: add_test(NAME NR-DEC-${INPUT_FILENAME_NAME}-${IT_TEST_DEC}-decode-md5 COMMAND ${CMAKE_COMMAND} -DREFFILE:STRING=${CMAKE_CURRENT_SOURCE_DIR}/md5refs.txt - -DFILENAME:STRING=${INPUT_FILENAME_NAME} -DOUTFILENAME:STRING=${OUTPUT_FILENAME} -P ${CMAKE_CURRENT_SOURCE_DIR}/checkmd5refs.cmake) diff --git a/tests/nonregression/checkmd5refs.cmake b/tests/nonregression/checkmd5refs.cmake index f94d7c09..d6198af0 100644 --- a/tests/nonregression/checkmd5refs.cmake +++ b/tests/nonregression/checkmd5refs.cmake @@ -16,29 +16,32 @@ # decoding process that the output would be bitwise different (while PSNR would # be kept identical). -#message("0: ${REFFILE}") -#message("1: ${CMAKE_CURRENT_BINARY_DIR}") -#message("2: ${FILENAME}") -#get_filename_component(pgxfile ${pgxfullpath} NAME) +# Another more conventional approach is to store the generated output from +# openjpeg however storing the full generated output is generally useless since +# we do not really care about the exact pixel value, we simply need to known +# when a code change impact output generation. furthermore storing the +# complete generated output file, tends to make the svn:/openjpeg-data really +# big. + +# This script expect two inputs +# REFFILE: Path to the md5sum.txt file +# OUTFILENAME: The name of the generated file we want to check The script will +# check whether a PGX or a PNG file was generated in the test suite (computed +# from OUTFILENAME) + get_filename_component(OUTFILENAME_NAME ${OUTFILENAME} NAME) string(FIND ${OUTFILENAME_NAME} "." SHORTEST_EXT_POS REVERSE) string(SUBSTRING ${OUTFILENAME_NAME} 0 ${SHORTEST_EXT_POS} OUTFILENAME_NAME_WE) -#message("3: ${OUTFILENAME_NAME}") -#message("4: ${OUTFILENAME_NAME_WE}") -#file(GLOB globfiles "Temporary/${FILENAME}*.pgx" "Temporary/${FILENAME}*.png") file(GLOB globfiles "Temporary/${OUTFILENAME_NAME_WE}*.pgx" "Temporary/${OUTFILENAME_NAME_WE}*.png") -#message("6: ${globfiles}") if(NOT globfiles) message(SEND_ERROR "Could not find output PGX files: ${OUTFILENAME_NAME_WE}") endif() -# REFFILE follow what md5sum -c would expect as input: +# REFFILE follow what `md5sum -c` would expect as input: file(READ ${REFFILE} variable) -#string(REGEX REPLACE "\r?\n" ";" variable "${variable}") foreach(pgxfullpath ${globfiles}) get_filename_component(pgxfile ${pgxfullpath} NAME) - #message("8: ${pgxfile}") execute_process( COMMAND ${CMAKE_COMMAND} -E md5sum ${pgxfile} WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/Temporary @@ -52,14 +55,11 @@ foreach(pgxfullpath ${globfiles}) if(res) message(SEND_ERROR "md5 could not be computed, it failed with value ${res}. Output was: ${error_output}") endif() - #message("3: ${output}") - #message("4: ${variable}") string(REGEX MATCH "[0-9a-f]+ ${pgxfile}" output_var "${variable}") - #message("5: ${output_var}") if("${output_var}" STREQUAL "${output}") - #message("6: eqal") + message(STATUS "equal: [${output_var}] vs [${output}]") else() message(SEND_ERROR "not equal: [${output_var}] vs [${output}]") endif() From 565ef29ae358c1b09f6eb1f58e67df7725ffd2bf Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 13 Mar 2014 13:47:44 +0000 Subject: [PATCH 301/333] [trunk] Make sure to reallocate ppm data buffer when multiple Ippm(i) buffer are found This handle the case where remaining data is exactly Nppm(i) Fixes issue 287 --- src/lib/openjp2/j2k.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index e446dab0..553833a9 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -3634,7 +3634,7 @@ OPJ_BOOL j2k_read_ppm_v3 ( l_remaining_data = p_header_size; /* Next Ippm series is a complete series ?*/ - if (l_remaining_data > l_N_ppm) { + if (l_remaining_data >= l_N_ppm) { OPJ_BYTE *new_ppm_data; /* Increase the size of ppm_data to add the new Ippm series*/ assert(l_cp->ppm_data == l_cp->ppm_buffer && "We need ppm_data and ppm_buffer to be the same when reallocating"); From 6e22c4f68a7e8a633ec3f9a10027fef971511309 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Thu, 13 Mar 2014 15:34:36 +0000 Subject: [PATCH 302/333] [trunk] Add some sanity checks when reading Ippm(i) segments Update issue 288 --- src/lib/openjp2/j2k.c | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 553833a9..7a714f9b 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -3555,6 +3555,17 @@ OPJ_BOOL j2k_read_ppm_v3 ( p_header_data+=4; p_header_size-=4; + /* sanity check: how much bytes is left for Ippm */ + if( p_header_size < l_N_ppm ) + { + opj_event_msg(p_manager, EVT_ERROR, "Not enough bytes (%u) to hold Ippm series (%u), Index (%d)\n", p_header_size, l_N_ppm, l_Z_ppm ); + opj_free(l_cp->ppm_data); + l_cp->ppm_data = NULL; + l_cp->ppm_buffer = NULL; + l_cp->ppm = 0; /* do not use PPM */ + return OPJ_TRUE; + } + /* First PPM marker: Initialization */ l_cp->ppm_len = l_N_ppm; l_cp->ppm_data_read = 0; @@ -3589,6 +3600,16 @@ OPJ_BOOL j2k_read_ppm_v3 ( p_header_data+=4; p_header_size-=4; + /* sanity check: how much bytes is left for Ippm */ + if( p_header_size < l_N_ppm ) + { + opj_event_msg(p_manager, EVT_ERROR, "Not enough bytes (%u) to hold Ippm series (%u), Index (%d)\n", p_header_size, l_N_ppm, l_Z_ppm ); + opj_free(l_cp->ppm_data); + l_cp->ppm_data = NULL; + l_cp->ppm_buffer = NULL; + l_cp->ppm = 0; /* do not use PPM */ + return OPJ_TRUE; + } /* Increase the size of ppm_data to add the new Ippm series*/ assert(l_cp->ppm_data == l_cp->ppm_buffer && "We need ppm_data and ppm_buffer to be the same when reallocating"); new_ppm_data = (OPJ_BYTE *) opj_realloc(l_cp->ppm_data, l_cp->ppm_len + l_N_ppm); From fd3f7ca2bbd7850ea67652ff42e65454ce5334cd Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 14 Mar 2014 08:44:53 +0000 Subject: [PATCH 303/333] [trunk] Remove warnings about unused values introduced in r2710 Thanks to Matthieu Darbois for patch Fixes issue 290 --- src/lib/openjp2/t2.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c index 56d5ee99..82d7a78f 100644 --- a/src/lib/openjp2/t2.c +++ b/src/lib/openjp2/t2.c @@ -315,7 +315,13 @@ OPJ_BOOL opj_t2_encode_packets( opj_t2_t* p_t2, #if 0 #define JAS_FPRINTF fprintf #else -#define JAS_FPRINTF +/* issue 290 */ +static void opj_null_jas_fprintf(FILE* file, const char * format, ...) +{ + (void)file; + (void)format; +} +#define JAS_FPRINTF opj_null_jas_fprintf #endif OPJ_BOOL opj_t2_decode_packets( opj_t2_t *p_t2, From 3e33012bd9e510dd891217f02c5e438d61039a3e Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 14 Mar 2014 09:30:03 +0000 Subject: [PATCH 304/333] [trunk] Mark OpenJPEG to be ABI incompatible with previous one, move to SONAME 7 Also declare this is 2.1.0 (or very close) --- CMakeLists.txt | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7d0abd01..7d6b0b55 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,7 +29,7 @@ include_regular_expression("^.*$") #----------------------------------------------------------------------------- # OPENJPEG version number, useful for packaging and doxygen doc: set(OPENJPEG_VERSION_MAJOR 2) -set(OPENJPEG_VERSION_MINOR 0) +set(OPENJPEG_VERSION_MINOR 1) set(OPENJPEG_VERSION_BUILD 0) set(OPENJPEG_VERSION "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}") @@ -47,11 +47,12 @@ set(PACKAGE_VERSION # 1.5 | 5 # 1.5.1 | 5 # 2.0 | 6 +# 2.1 | 7 # above is the recommendation by the OPJ team. If you really need to override this default, # you can specify your own OPENJPEG_SOVERSION at cmake configuration time: # cmake -DOPENJPEG_SOVERSION:STRING=42 /path/to/openjpeg if(NOT OPENJPEG_SOVERSION) - SET(OPENJPEG_SOVERSION 6) + SET(OPENJPEG_SOVERSION 7) endif(NOT OPENJPEG_SOVERSION) set(OPENJPEG_LIBRARY_PROPERTIES VERSION "${OPENJPEG_VERSION_MAJOR}.${OPENJPEG_VERSION_MINOR}.${OPENJPEG_VERSION_BUILD}" From 3a80b72ac8ab387a4f9cb4ec7143f2da6890499e Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 14 Mar 2014 10:54:08 +0000 Subject: [PATCH 305/333] [trunk] Add a temporary work around for issue 293 As described in the bug report the default allocation mecanism for codeblock data is too small for those dataset (16bits). We would need a finer (more granular) mecanism to reallocated only on demand. For now this help the two failing tests to pass. Fixes issue 293 --- 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 001d4ce5..147bc681 100644 --- a/src/lib/openjp2/tcd.c +++ b/src/lib/openjp2/tcd.c @@ -1006,7 +1006,7 @@ OPJ_BOOL opj_tcd_code_block_enc_allocate (opj_tcd_cblk_enc_t * p_code_block) { if (! p_code_block->data) { - p_code_block->data = (OPJ_BYTE*) opj_malloc(OPJ_J2K_DEFAULT_CBLK_DATA_SIZE); /*why +1 ?*/ + p_code_block->data = (OPJ_BYTE*) opj_malloc(OPJ_J2K_DEFAULT_CBLK_DATA_SIZE*2); /*why +1 ?*/ if(! p_code_block->data) { return OPJ_FALSE; } From b7ebf54a29a9275939bf86b7548f547a8bac3614 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 14 Mar 2014 11:37:44 +0000 Subject: [PATCH 306/333] [trunk] Be more verbose about failure. Update issue 294 --- tests/compare_images.c | 2 +- tests/conformance/CMakeLists.txt | 6 ++---- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/tests/compare_images.c b/tests/compare_images.c index f0dc5e82..38c36f51 100644 --- a/tests/compare_images.c +++ b/tests/compare_images.c @@ -196,7 +196,7 @@ static opj_image_t* readImageFromFilePPM(const char* filename, int nbFilenamePGX if (!image_read) { int it_free_data; - fprintf(stderr, "Unable to load pgx file\n"); + fprintf(stderr, "Unable to load ppm file: %s\n", filenameComponentPGX); free(param_image_read); diff --git a/tests/conformance/CMakeLists.txt b/tests/conformance/CMakeLists.txt index 85c2cf86..bd40328b 100644 --- a/tests/conformance/CMakeLists.txt +++ b/tests/conformance/CMakeLists.txt @@ -515,9 +515,9 @@ foreach(kdu_file ${kdu_j2k_conf_files}) ) if("${kdu_file}" STREQUAL "a6_mono_colr") - set(kdu_test_args -n 4 -s b_t_) + set(kdu_test_args -n 4 -s b_t_ -p 4:4:4:4 -m 1:1:1:1) else() - set(kdu_test_args -n 1) + set(kdu_test_args -n 1 -p 4:4:4 -m 1:1:1) endif() add_test(NAME ETS-KDU-${filenameInput}-compare2ref @@ -525,8 +525,6 @@ foreach(kdu_file ${kdu_j2k_conf_files}) -b ${BASELINE_CONF}/${filenameRef} -t ${TEMP}/${filenameInput}.ppm ${kdu_test_args} - -p 4:4:4 - -m 1:1:1 ) set_tests_properties(ETS-KDU-${filenameInput}-compare2ref From 9194dfb94b0cb26ea1113aadc237350a4db5b030 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 14 Mar 2014 11:42:26 +0000 Subject: [PATCH 307/333] [trunk] Rework r2731 since it breaks non-regression testing --- tests/conformance/CMakeLists.txt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/tests/conformance/CMakeLists.txt b/tests/conformance/CMakeLists.txt index bd40328b..0b2ed0a0 100644 --- a/tests/conformance/CMakeLists.txt +++ b/tests/conformance/CMakeLists.txt @@ -515,9 +515,11 @@ foreach(kdu_file ${kdu_j2k_conf_files}) ) if("${kdu_file}" STREQUAL "a6_mono_colr") - set(kdu_test_args -n 4 -s b_t_ -p 4:4:4:4 -m 1:1:1:1) + set(kdu_test_args -n 4 -s b_t_ ) + set(kdu_test_args_tol -p 4:4:4:4 -m 1:1:1:1) else() - set(kdu_test_args -n 1 -p 4:4:4 -m 1:1:1) + set(kdu_test_args -n 1 ) + set(kdu_test_args_tol -p 4:4:4 -m 1:1:1) endif() add_test(NAME ETS-KDU-${filenameInput}-compare2ref @@ -525,6 +527,7 @@ foreach(kdu_file ${kdu_j2k_conf_files}) -b ${BASELINE_CONF}/${filenameRef} -t ${TEMP}/${filenameInput}.ppm ${kdu_test_args} + ${kdu_test_args_tol} ) set_tests_properties(ETS-KDU-${filenameInput}-compare2ref From 9d0bdf69e5b960ce817c4e63420468f3d542f296 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 14 Mar 2014 11:59:18 +0000 Subject: [PATCH 308/333] [trunk] Apply final missing patch from sumatrapdf team: http://bugs.ghostscript.com/show_bug.cgi?id=694893 Update issue 231 --- src/lib/openjp2/opj_intmath.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/openjp2/opj_intmath.h b/src/lib/openjp2/opj_intmath.h index 73d08a28..38edf3f5 100644 --- a/src/lib/openjp2/opj_intmath.h +++ b/src/lib/openjp2/opj_intmath.h @@ -119,7 +119,7 @@ Divide an integer by a power of 2 and round upwards @return Returns a divided by 2^b */ static INLINE OPJ_INT32 opj_int_ceildivpow2(OPJ_INT32 a, OPJ_INT32 b) { - return (a + (1 << b) - 1) >> b; + return (OPJ_INT32)((a + (OPJ_INT64)(1 << b) - 1) >> b); } /** Divide an integer by a power of 2 and round downwards From 138a65d6c143427755d49ec32fe43f17a3e6c8b6 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 14 Mar 2014 12:02:05 +0000 Subject: [PATCH 309/333] [trunk] Move INLINE definition within openjpeg.h header since application may use it --- src/bin/jp2/convert.c | 10 ++-------- src/lib/openjp2/openjpeg.h | 17 +++++++++++++++++ src/lib/openjp2/opj_includes.h | 16 ---------------- 3 files changed, 19 insertions(+), 24 deletions(-) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index 90684a2c..5dd09da7 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -183,7 +183,7 @@ static int tga_readheader(FILE *fp, unsigned int *bits_per_pixel, #if WORDS_BIGENDIAN == 1 -static inline int16_t swap16(int16_t x) +static INLINE int16_t swap16(int16_t x) { return((((u_int16_t)x & 0x00ffU) << 8) | (((u_int16_t)x & 0xff00U) >> 8)); @@ -1421,13 +1421,7 @@ opj_image_t* pgxtoimage(const char *filename, opj_cparameters_t *parameters) { #define CLAMP(x,a,b) x < a ? a : (x > b ? b : x) -#ifdef _MSC_VER -#define STIN static __inline -#else -#define STIN static inline -#endif - -STIN int clamp( const int value, const int prec, const int sgnd ) +static INLINE int clamp( const int value, const int prec, const int sgnd ) { if( sgnd ) { diff --git a/src/lib/openjp2/openjpeg.h b/src/lib/openjp2/openjpeg.h index d3339954..59a1cdc4 100644 --- a/src/lib/openjp2/openjpeg.h +++ b/src/lib/openjp2/openjpeg.h @@ -43,6 +43,23 @@ ========================================================== */ +/* +The inline keyword is supported by C99 but not by C90. +Most compilers implement their own version of this keyword ... +*/ +#ifndef INLINE + #if defined(_MSC_VER) + #define INLINE __forceinline + #elif defined(__GNUC__) + #define INLINE __inline__ + #elif defined(__MWERKS__) + #define INLINE inline + #else + /* add other compilers here ... */ + #define INLINE + #endif /* defined() */ +#endif /* INLINE */ + /* deprecated attribute */ #ifdef __GNUC__ #define OPJ_DEPRECATED(func) func __attribute__ ((deprecated)) diff --git a/src/lib/openjp2/opj_includes.h b/src/lib/openjp2/opj_includes.h index 8b072c58..76380962 100644 --- a/src/lib/openjp2/opj_includes.h +++ b/src/lib/openjp2/opj_includes.h @@ -102,22 +102,6 @@ #define __attribute__(x) /* __attribute__(x) */ #endif -/* -The inline keyword is supported by C99 but not by C90. -Most compilers implement their own version of this keyword ... -*/ -#ifndef INLINE - #if defined(_MSC_VER) - #define INLINE __forceinline - #elif defined(__GNUC__) - #define INLINE __inline__ - #elif defined(__MWERKS__) - #define INLINE inline - #else - /* add other compilers here ... */ - #define INLINE - #endif /* defined() */ -#endif /* INLINE */ /* Are restricted pointers available? (C99) */ #if (__STDC_VERSION__ != 199901L) From b7fe7d25e1fcffe3bca03b61da54a04d72cb7965 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 14 Mar 2014 12:27:01 +0000 Subject: [PATCH 310/333] [trunk] Prevent a leak when reading PPT markers Update issue 295 --- src/lib/openjp2/j2k.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 7a714f9b..93d9999c 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -3803,6 +3803,7 @@ static OPJ_BOOL opj_j2k_read_ppt ( opj_j2k_t *p_j2k, l_tcp->ppt_data_size = 0; l_tcp->ppt_len = p_header_size; + opj_free(l_tcp->ppt_buffer); l_tcp->ppt_buffer = (OPJ_BYTE *) opj_calloc(l_tcp->ppt_len, sizeof(OPJ_BYTE) ); if (l_tcp->ppt_buffer == 00) { opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read PPT marker\n"); From e8abf1fb250819822f6a96b11a5ed1a848f3e47a Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 14 Mar 2014 13:53:36 +0000 Subject: [PATCH 311/333] [trunk] Add internal implementation to dump all tiles/comp info Eg: opj_dump -f 8 -i input.j2k Update issue 3 --- src/bin/jp2/opj_dump.c | 10 +++- src/lib/openjp2/j2k.c | 119 ++++++++++++++++++++----------------- src/lib/openjp2/openjpeg.h | 2 +- 3 files changed, 73 insertions(+), 58 deletions(-) diff --git a/src/bin/jp2/opj_dump.c b/src/bin/jp2/opj_dump.c index b849149f..1742f3eb 100644 --- a/src/bin/jp2/opj_dump.c +++ b/src/bin/jp2/opj_dump.c @@ -71,6 +71,7 @@ typedef struct img_folder{ /** Enable Cod Format for output*/ char set_out_format; + int flag; }img_fol_t; /* -------------------------------------------------------------------------- */ @@ -273,7 +274,7 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param opj_option_t long_option[]={ {"ImgDir",REQ_ARG, NULL ,'y'}, }; - const char optlist[] = "i:o:hv"; + const char optlist[] = "i:o:f:hv"; totlen=sizeof(long_option); img_fol->set_out_format = 0; @@ -313,6 +314,10 @@ static int parse_cmdline_decoder(int argc, char **argv, opj_dparameters_t *param break; /* ----------------------------------------------------- */ + case 'f': /* flag */ + img_fol->flag = atoi(opj_optarg); + break; + /* ----------------------------------------------------- */ case 'h': /* display an help description */ decode_help_display(); @@ -424,6 +429,7 @@ int main(int argc, char *argv[]) /* Initialize img_fol */ memset(&img_fol,0,sizeof(img_fol_t)); + img_fol.flag = OPJ_IMG_INFO | OPJ_J2K_MH_INFO | OPJ_J2K_MH_IND; /* Parse input and get user encoding parameters */ if(parse_cmdline_decoder(argc, argv, ¶meters,&img_fol) == 1) { @@ -544,7 +550,7 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; } - opj_dump_codec(l_codec, OPJ_IMG_INFO | OPJ_J2K_MH_INFO | OPJ_J2K_MH_IND, fout ); + opj_dump_codec(l_codec, img_fol.flag, fout ); cstr_info = opj_get_cstr_info(l_codec); diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 93d9999c..8790fc33 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -8676,6 +8676,58 @@ void opj_j2k_copy_tile_quantization_parameters( opj_j2k_t *p_j2k ) } } +static void opj_j2k_dump_tile_info( opj_tcp_t * l_default_tile,OPJ_INT32 numcomps,FILE* out_stream) +{ + if (l_default_tile) + { + OPJ_INT32 compno; + + fprintf(out_stream, "\t default tile {\n"); + fprintf(out_stream, "\t\t csty=%#x\n", l_default_tile->csty); + fprintf(out_stream, "\t\t prg=%#x\n", l_default_tile->prg); + fprintf(out_stream, "\t\t numlayers=%d\n", l_default_tile->numlayers); + fprintf(out_stream, "\t\t mct=%x\n", l_default_tile->mct); + + for (compno = 0; compno < numcomps; compno++) { + opj_tccp_t *l_tccp = &(l_default_tile->tccps[compno]); + OPJ_UINT32 resno; + OPJ_INT32 bandno, numbands; + + /* coding style*/ + fprintf(out_stream, "\t\t comp %d {\n", compno); + fprintf(out_stream, "\t\t\t csty=%#x\n", l_tccp->csty); + fprintf(out_stream, "\t\t\t numresolutions=%d\n", l_tccp->numresolutions); + fprintf(out_stream, "\t\t\t cblkw=2^%d\n", l_tccp->cblkw); + fprintf(out_stream, "\t\t\t cblkh=2^%d\n", l_tccp->cblkh); + fprintf(out_stream, "\t\t\t cblksty=%#x\n", l_tccp->cblksty); + fprintf(out_stream, "\t\t\t qmfbid=%d\n", l_tccp->qmfbid); + + fprintf(out_stream, "\t\t\t preccintsize (w,h)="); + for (resno = 0; resno < l_tccp->numresolutions; resno++) { + fprintf(out_stream, "(%d,%d) ", l_tccp->prcw[resno], l_tccp->prch[resno]); + } + fprintf(out_stream, "\n"); + + /* quantization style*/ + fprintf(out_stream, "\t\t\t qntsty=%d\n", l_tccp->qntsty); + fprintf(out_stream, "\t\t\t numgbits=%d\n", l_tccp->numgbits); + fprintf(out_stream, "\t\t\t stepsizes (m,e)="); + numbands = (l_tccp->qntsty == J2K_CCP_QNTSTY_SIQNT) ? 1 : (OPJ_INT32)l_tccp->numresolutions * 3 - 2; + for (bandno = 0; bandno < numbands; bandno++) { + fprintf(out_stream, "(%d,%d) ", l_tccp->stepsizes[bandno].mant, + l_tccp->stepsizes[bandno].expn); + } + fprintf(out_stream, "\n"); + + /* RGN value*/ + fprintf(out_stream, "\t\t\t roishift=%d\n", l_tccp->roishift); + + fprintf(out_stream, "\t\t }\n"); + } /*end of component of default tile*/ + fprintf(out_stream, "\t }\n"); /*end of default tile*/ + } +} + void j2k_dump (opj_j2k_t* p_j2k, OPJ_INT32 flag, FILE* out_stream) { /* Check if the flag is compatible with j2k file*/ @@ -8694,6 +8746,16 @@ void j2k_dump (opj_j2k_t* p_j2k, OPJ_INT32 flag, FILE* out_stream) if (flag & OPJ_J2K_MH_INFO){ opj_j2k_dump_MH_info(p_j2k, out_stream); } + /* Dump all tile/codestream info */ + if (flag & OPJ_J2K_TCH_INFO){ + OPJ_UINT32 l_nb_tiles = p_j2k->m_cp.th * p_j2k->m_cp.tw; + OPJ_UINT32 i; + opj_tcp_t * l_tcp = p_j2k->m_cp.tcps; + for (i=0;im_private_image->numcomps, out_stream); + ++l_tcp; + } + } /* Dump the codestream info of the current tile */ if (flag & OPJ_J2K_TH_INFO){ @@ -8780,70 +8842,17 @@ void opj_j2k_dump_MH_index(opj_j2k_t* p_j2k, FILE* out_stream) } + void opj_j2k_dump_MH_info(opj_j2k_t* p_j2k, FILE* out_stream) { - opj_tcp_t * l_default_tile=NULL; fprintf(out_stream, "Codestream info from main header: {\n"); fprintf(out_stream, "\t tx0=%d, ty0=%d\n", p_j2k->m_cp.tx0, p_j2k->m_cp.ty0); fprintf(out_stream, "\t tdx=%d, tdy=%d\n", p_j2k->m_cp.tdx, p_j2k->m_cp.tdy); fprintf(out_stream, "\t tw=%d, th=%d\n", p_j2k->m_cp.tw, p_j2k->m_cp.th); - - l_default_tile = p_j2k->m_specific_param.m_decoder.m_default_tcp; - if (l_default_tile) - { - OPJ_INT32 compno; - OPJ_INT32 numcomps = (OPJ_INT32)p_j2k->m_private_image->numcomps; - - fprintf(out_stream, "\t default tile {\n"); - fprintf(out_stream, "\t\t csty=%#x\n", l_default_tile->csty); - fprintf(out_stream, "\t\t prg=%#x\n", l_default_tile->prg); - fprintf(out_stream, "\t\t numlayers=%d\n", l_default_tile->numlayers); - fprintf(out_stream, "\t\t mct=%x\n", l_default_tile->mct); - - for (compno = 0; compno < numcomps; compno++) { - opj_tccp_t *l_tccp = &(l_default_tile->tccps[compno]); - OPJ_UINT32 resno; - OPJ_INT32 bandno, numbands; - - /* coding style*/ - fprintf(out_stream, "\t\t comp %d {\n", compno); - fprintf(out_stream, "\t\t\t csty=%#x\n", l_tccp->csty); - fprintf(out_stream, "\t\t\t numresolutions=%d\n", l_tccp->numresolutions); - fprintf(out_stream, "\t\t\t cblkw=2^%d\n", l_tccp->cblkw); - fprintf(out_stream, "\t\t\t cblkh=2^%d\n", l_tccp->cblkh); - fprintf(out_stream, "\t\t\t cblksty=%#x\n", l_tccp->cblksty); - fprintf(out_stream, "\t\t\t qmfbid=%d\n", l_tccp->qmfbid); - - fprintf(out_stream, "\t\t\t preccintsize (w,h)="); - for (resno = 0; resno < l_tccp->numresolutions; resno++) { - fprintf(out_stream, "(%d,%d) ", l_tccp->prcw[resno], l_tccp->prch[resno]); - } - fprintf(out_stream, "\n"); - - /* quantization style*/ - fprintf(out_stream, "\t\t\t qntsty=%d\n", l_tccp->qntsty); - fprintf(out_stream, "\t\t\t numgbits=%d\n", l_tccp->numgbits); - fprintf(out_stream, "\t\t\t stepsizes (m,e)="); - numbands = (l_tccp->qntsty == J2K_CCP_QNTSTY_SIQNT) ? 1 : (OPJ_INT32)l_tccp->numresolutions * 3 - 2; - for (bandno = 0; bandno < numbands; bandno++) { - fprintf(out_stream, "(%d,%d) ", l_tccp->stepsizes[bandno].mant, - l_tccp->stepsizes[bandno].expn); - } - fprintf(out_stream, "\n"); - - /* RGN value*/ - fprintf(out_stream, "\t\t\t roishift=%d\n", l_tccp->roishift); - - fprintf(out_stream, "\t\t }\n"); - } /*end of component of default tile*/ - fprintf(out_stream, "\t }\n"); /*end of default tile*/ - - } - + opj_j2k_dump_tile_info(p_j2k->m_specific_param.m_decoder.m_default_tcp,(OPJ_INT32)p_j2k->m_private_image->numcomps, out_stream); fprintf(out_stream, "}\n"); - } void j2k_dump_image_header(opj_image_t* img_header, OPJ_BOOL dev_dump_flag, FILE* out_stream) diff --git a/src/lib/openjp2/openjpeg.h b/src/lib/openjp2/openjpeg.h index 59a1cdc4..1ea2af80 100644 --- a/src/lib/openjp2/openjpeg.h +++ b/src/lib/openjp2/openjpeg.h @@ -160,7 +160,7 @@ typedef size_t OPJ_SIZE_T; #define OPJ_IMG_INFO 1 /**< Basic image information provided to the user */ #define OPJ_J2K_MH_INFO 2 /**< Codestream information based only on the main header */ #define OPJ_J2K_TH_INFO 4 /**< Tile information based on the current tile header */ -/*FIXME #define OPJ_J2K_CSTR_INFO 6*/ /**< */ +#define OPJ_J2K_TCH_INFO 8 /**< Tile/Component information of all tiles */ #define OPJ_J2K_MH_IND 16 /**< Codestream index based only on the main header */ #define OPJ_J2K_TH_IND 32 /**< Tile index based on the current tile */ /*FIXME #define OPJ_J2K_CSTR_IND 48*/ /**< */ From de7460577753a7ed47a292e803428f60eec9dac9 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 14 Mar 2014 14:46:40 +0000 Subject: [PATCH 312/333] [trunk] Fix issue with & vs && Fixes issue 277 --- src/bin/jp2/convert.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index 5dd09da7..3588700b 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -1716,7 +1716,7 @@ static void read_pnm_header(FILE *reader, struct pnm_header *ph) } if(ph->depth < 1 || ph->depth > 4) return; - if(ph->width && ph->height && ph->depth & ph->maxval && ttype) + if(ph->width && ph->height && ph->depth && ph->maxval && ttype) ph->ok = 1; } else From 7e1d01216194f0f7ccf987dde5225144f76b50eb Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 14 Mar 2014 15:01:13 +0000 Subject: [PATCH 313/333] [trunk] Now that issue 165 dataset is in non regression repository, activate code to reject them Fixes issue 165 --- src/lib/openjp2/j2k.c | 5 +++++ tests/nonregression/CMakeLists.txt | 1 + tests/nonregression/test_suite.ctest.in | 2 ++ 3 files changed, 8 insertions(+) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 8790fc33..4434bf11 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -3163,6 +3163,11 @@ static OPJ_BOOL opj_j2k_read_poc ( opj_j2k_t *p_j2k, l_old_poc_nb = l_tcp->POC ? l_tcp->numpocs + 1 : 0; l_current_poc_nb += l_old_poc_nb; + if(l_current_poc_nb >= 32) + { + opj_event_msg(p_manager, EVT_ERROR, "Too many POCs %d\n", l_current_poc_nb); + return OPJ_FALSE; + } assert(l_current_poc_nb < 32); /* now poc is in use.*/ diff --git a/tests/nonregression/CMakeLists.txt b/tests/nonregression/CMakeLists.txt index 51664256..04151aa4 100644 --- a/tests/nonregression/CMakeLists.txt +++ b/tests/nonregression/CMakeLists.txt @@ -25,6 +25,7 @@ set(BLACKLIST_JPEG2000_TMP 26ccf3651020967f7778238ef5af08af.SIGFPE.d25.527.jp2 4035.pdf.SIGSEGV.d8b.3375.jp2 3635.pdf.asan.77.2930.jp2 + issue165.jp2 ) # Define a list of file which should be gracefully rejected: diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index a0c89eda..47d26a93 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -142,6 +142,8 @@ opj_decompress -i @INPUT_NR_PATH@/issue208.jp2 -o @TEMP_PATH@/i opj_decompress -i @INPUT_NR_PATH@/issue211.jp2 -o @TEMP_PATH@/issue211.jp2.pgx # issue 171 opj_decompress -i @INPUT_NR_PATH@/issue171.jp2 -o @TEMP_PATH@/issue171.jp2.pgx +# issue 171 +!opj_decompress -i @INPUT_NR_PATH@/issue165.jp2 -o @TEMP_PATH@/issue165.jp2.pgx # decode with specific area # prec=12; nb_c=1 From 5e91877636fc1a663087e783f7ce93cf44843204 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 14 Mar 2014 15:04:24 +0000 Subject: [PATCH 314/333] [trunk] rework code from r2463. Really there has been some code duplication from r2413 Thanks to John Rogers (oracle.com) for report --- src/lib/openjp2/jp2.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c index 7ed9a54c..51ddab01 100644 --- a/src/lib/openjp2/jp2.c +++ b/src/lib/openjp2/jp2.c @@ -1002,11 +1002,6 @@ OPJ_BOOL opj_jp2_read_pclr( opj_jp2_t *jp2, for(i = 0; i < nr_channels; ++i) { OPJ_UINT32 bytes_to_read = (OPJ_UINT32)((channel_size[i]+7)>>3); - if (bytes_to_read > sizeof(OPJ_UINT32)) - bytes_to_read = sizeof(OPJ_UINT32); - if ((ptrdiff_t)p_pclr_header_size < p_pclr_header_data - orig_header_data + (ptrdiff_t)bytes_to_read) - return OPJ_FALSE; - if (bytes_to_read > sizeof(OPJ_UINT32)) bytes_to_read = sizeof(OPJ_UINT32); if ((ptrdiff_t)p_pclr_header_size < p_pclr_header_data - orig_header_data + (ptrdiff_t)bytes_to_read) From 15863e717071a1b3cfa079653bb7e7996dc14a5b Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 14 Mar 2014 15:06:20 +0000 Subject: [PATCH 315/333] [trunk] rework code from r2463. Really there has been some code duplication from r2413 Thanks to John Rogers (oracle.com) for report --- src/lib/openjp2/jp2.c | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/src/lib/openjp2/jp2.c b/src/lib/openjp2/jp2.c index 51ddab01..32ddd4f4 100644 --- a/src/lib/openjp2/jp2.c +++ b/src/lib/openjp2/jp2.c @@ -1053,11 +1053,6 @@ OPJ_BOOL opj_jp2_read_cmap( opj_jp2_t * jp2, return OPJ_FALSE; } - if (p_cmap_header_size < (OPJ_UINT32)nr_channels * 4) { - opj_event_msg(p_manager, EVT_ERROR, "Insufficient data for CMAP box.\n"); - return OPJ_FALSE; - } - cmap = (opj_jp2_cmap_comp_t*) opj_malloc(nr_channels * sizeof(opj_jp2_cmap_comp_t)); if (!cmap) return OPJ_FALSE; @@ -1155,11 +1150,6 @@ OPJ_BOOL opj_jp2_read_cdef( opj_jp2_t * jp2, return OPJ_FALSE; } - if (p_cdef_header_size < 2) { - opj_event_msg(p_manager, EVT_ERROR, "Insufficient data for CDEF box.\n"); - return OPJ_FALSE; - } - opj_read_bytes(p_cdef_header_data,&l_value ,2); /* N */ p_cdef_header_data+= 2; @@ -1173,11 +1163,6 @@ OPJ_BOOL opj_jp2_read_cdef( opj_jp2_t * jp2, return OPJ_FALSE; } - if (p_cdef_header_size < 2 + (OPJ_UINT32)(OPJ_UINT16)l_value * 6) { - opj_event_msg(p_manager, EVT_ERROR, "Insufficient data for CDEF box.\n"); - return OPJ_FALSE; - } - cdef_info = (opj_jp2_cdef_info_t*) opj_malloc(l_value * sizeof(opj_jp2_cdef_info_t)); if (!cdef_info) return OPJ_FALSE; From a43d206b93c83b255b52b5825b68df8a58a16d27 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 14 Mar 2014 15:10:31 +0000 Subject: [PATCH 316/333] [trunk] Remove duplicate content from test_inline.c Thanks to Matthieu Darbois for report (and patch) Fixes issue 285 --- thirdparty/libtiff/test_inline.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/thirdparty/libtiff/test_inline.c b/thirdparty/libtiff/test_inline.c index ad25a9c6..db0d056c 100644 --- a/thirdparty/libtiff/test_inline.c +++ b/thirdparty/libtiff/test_inline.c @@ -3,8 +3,3 @@ typedef int foo_t; static inline foo_t static_foo(){return 0;} foo_t foo(){return 0;} int main(int argc, char *argv[]){return 0;} -/* Test source lifted from /usr/share/autoconf/autoconf/c.m4 */ -typedef int foo_t; -static inline foo_t static_foo(){return 0;} -foo_t foo(){return 0;} -int main(int argc, char *argv[]){return 0;} From b607da8ae9187196abba38d8f3b6ea751c3ad2f9 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 14 Mar 2014 15:51:53 +0000 Subject: [PATCH 317/333] [trunk] add mecanism to track of addition of new regression files in svn/data. It will report when a J2K files is added but no test is found in the test_suite file --- tests/nonregression/CMakeLists.txt | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/tests/nonregression/CMakeLists.txt b/tests/nonregression/CMakeLists.txt index 04151aa4..a46842be 100644 --- a/tests/nonregression/CMakeLists.txt +++ b/tests/nonregression/CMakeLists.txt @@ -47,6 +47,7 @@ file(GLOB_RECURSE OPJ_DATA_NR_LIST "${INPUT_NR}/*.j2k" "${INPUT_NR}/*.j2c" "${INPUT_NR}/*.jp2" + "${INPUT_NR}/*.jpc" #"${INPUT_NR}/*.jpx" ) @@ -133,6 +134,7 @@ else() endif() +set(nonregression_filenames_used) # Parse the command line found in the file(s) set(IT_TEST_ENC 0) set(IT_TEST_DEC 0) @@ -240,7 +242,6 @@ foreach(OPJ_TEST_CMD_LINE ${OPJ_TEST_CMD_LINE_LIST}) #----- # Now we can add the test suite corresponding to a line command in the file #----- - # ENCODER TEST SUITE if(ENC_TEST_FOUND) math(EXPR IT_TEST_ENC "${IT_TEST_ENC}+1" ) @@ -304,6 +305,10 @@ foreach(OPJ_TEST_CMD_LINE ${OPJ_TEST_CMD_LINE_LIST}) # DECODER TEST SUITE else() + string(FIND ${INPUT_FILENAME} "nonregression" nr_pos) + if(${nr_pos} GREATER 0) + list(APPEND nonregression_filenames_used ${INPUT_FILENAME_NAME}) + endif() math(EXPR IT_TEST_DEC "${IT_TEST_DEC}+1" ) # Decode the input image @@ -349,3 +354,18 @@ foreach(OPJ_TEST_CMD_LINE ${OPJ_TEST_CMD_LINE_LIST}) endif() endforeach() + +set(existing_filenames) +foreach(f ${OPJ_DATA_NR_LIST}) + get_filename_component(ff ${f} NAME) + list(APPEND existing_filenames ${ff}) +endforeach() +list(REMOVE_ITEM existing_filenames ${nonregression_filenames_used}) + +# keep track of new addition: +# if we reach here, then a J2K files was added but no test is present in +# test_suite.ctest.in: +foreach(found_but_no_test ${existing_filenames}) + add_test(NAME Found-But-No-Test-${found_but_no_test} COMMAND ${CMAKE_COMMAND} -E echo "${found_but_no_test}") + set_tests_properties(Found-But-No-Test-${found_but_no_test} PROPERTIES WILL_FAIL TRUE) +endforeach() From 71a9f498b526a71cc938793ac74d4512cb1b8ab6 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Fri, 14 Mar 2014 15:52:22 +0000 Subject: [PATCH 318/333] [trunk] Since r2747 we are now able to track which files are missing from the test_suite. Add them. --- tests/nonregression/test_suite.ctest.in | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 47d26a93..2f856819 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -144,6 +144,10 @@ opj_decompress -i @INPUT_NR_PATH@/issue211.jp2 -o @TEMP_PATH@/i opj_decompress -i @INPUT_NR_PATH@/issue171.jp2 -o @TEMP_PATH@/issue171.jp2.pgx # issue 171 !opj_decompress -i @INPUT_NR_PATH@/issue165.jp2 -o @TEMP_PATH@/issue165.jp2.pgx +# +!opj_decompress -i @INPUT_NR_PATH@/broken.jpc -o @TEMP_PATH@/broken.jpc.pgx +# issue 226 +opj_decompress -i @INPUT_NR_PATH@/issue226.j2k -o @TEMP_PATH@/issue226.j2k.pgx # decode with specific area # prec=12; nb_c=1 From 866cd28ad4d13461d0b47a7c02b67794850d1e2d Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 17 Mar 2014 15:02:49 +0000 Subject: [PATCH 319/333] [trunk] Update BSD-4 copyright into a BSD-3 copyright Fixes issue 300 --- src/bin/common/opj_getopt.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/bin/common/opj_getopt.c b/src/bin/common/opj_getopt.c index 252d8359..6fcead46 100644 --- a/src/bin/common/opj_getopt.c +++ b/src/bin/common/opj_getopt.c @@ -10,11 +10,7 @@ * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors + * 3. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * From 99d1859a44f1200c03ae0453190c46f9c99440ec Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 17 Mar 2014 16:18:22 +0000 Subject: [PATCH 320/333] [trunk] Explicitely reject file4/file6 scenario Update issue 286 --- tests/compare_images.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tests/compare_images.c b/tests/compare_images.c index 38c36f51..cb1b1301 100644 --- a/tests/compare_images.c +++ b/tests/compare_images.c @@ -771,6 +771,13 @@ int main(int argc, char **argv) /* Comparison of header parameters*/ printf("Step 1 -> Header comparison\n"); + /* check dimensions (issue 286)*/ + if(imageBase->numcomps != imageTest->numcomps ) + { + printf("ERROR: dim mismatch (%d><%d)\n", imageBase->numcomps, imageTest->numcomps); + goto cleanup; + } + for (it_comp = 0; it_comp < imageBase->numcomps; it_comp++) { param_image_diff[it_comp].x0 = 0; From 79d18f7fd09d26f57c8ed5cbaac9e684a947630f Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 18 Mar 2014 10:21:11 +0000 Subject: [PATCH 321/333] [trunk] Now that dataset from issue 297 have been imported, run test suite. None of the dataset triggered any buffer overflow. Recent changes in trunk handle all those cases. Update issue 297 --- src/lib/openjp2/j2k.c | 6 +++--- tests/nonregression/CMakeLists.txt | 16 ++++++++++++++++ tests/nonregression/test_suite.ctest.in | 17 +++++++++++++++++ 3 files changed, 36 insertions(+), 3 deletions(-) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 4434bf11..e03db41d 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -1983,7 +1983,7 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k, /* testcase 1610.pdf.SIGSEGV.59c.681 */ if (((OPJ_UINT64)l_image->x1) * ((OPJ_UINT64)l_image->y1) != (l_image->x1 * l_image->y1)) { - opj_event_msg(p_manager, EVT_ERROR, "Prevent buffer overflow (x1: %d, y1: %d)", l_image->x1, l_image->y1); + opj_event_msg(p_manager, EVT_ERROR, "Prevent buffer overflow (x1: %d, y1: %d)\n", l_image->x1, l_image->y1); return OPJ_FALSE; } @@ -3568,7 +3568,7 @@ OPJ_BOOL j2k_read_ppm_v3 ( l_cp->ppm_data = NULL; l_cp->ppm_buffer = NULL; l_cp->ppm = 0; /* do not use PPM */ - return OPJ_TRUE; + return OPJ_FALSE; } /* First PPM marker: Initialization */ @@ -3613,7 +3613,7 @@ OPJ_BOOL j2k_read_ppm_v3 ( l_cp->ppm_data = NULL; l_cp->ppm_buffer = NULL; l_cp->ppm = 0; /* do not use PPM */ - return OPJ_TRUE; + return OPJ_FALSE; } /* Increase the size of ppm_data to add the new Ippm series*/ assert(l_cp->ppm_data == l_cp->ppm_buffer && "We need ppm_data and ppm_buffer to be the same when reallocating"); diff --git a/tests/nonregression/CMakeLists.txt b/tests/nonregression/CMakeLists.txt index a46842be..ee5209e3 100644 --- a/tests/nonregression/CMakeLists.txt +++ b/tests/nonregression/CMakeLists.txt @@ -26,6 +26,22 @@ set(BLACKLIST_JPEG2000_TMP 4035.pdf.SIGSEGV.d8b.3375.jp2 3635.pdf.asan.77.2930.jp2 issue165.jp2 + #edf_c2_1103421.jp2 + edf_c2_1178956.jp2 + edf_c2_1000290.jp2 + #edf_c2_1000691.jp2 # ok + #edf_c2_20.jp2 #looks ok as per kdu_jp2info + edf_c2_1377017.jp2 + edf_c2_1002767.jp2 + #edf_c2_10025.jp2 + edf_c2_1000234.jp2 + edf_c2_225881.jp2 + edf_c2_1000671.jp2 + #edf_c2_1013627.jp2 # weird box, but kdu_jp2info ok + edf_c2_1015644.jp2 + edf_c2_101463.jp2 + edf_c2_1674177.jp2 + edf_c2_1673169.jp2 ) # Define a list of file which should be gracefully rejected: diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index 2f856819..5c5c5091 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -148,6 +148,23 @@ opj_decompress -i @INPUT_NR_PATH@/issue171.jp2 -o @TEMP_PATH@/i !opj_decompress -i @INPUT_NR_PATH@/broken.jpc -o @TEMP_PATH@/broken.jpc.pgx # issue 226 opj_decompress -i @INPUT_NR_PATH@/issue226.j2k -o @TEMP_PATH@/issue226.j2k.pgx +# issue 297 +!opj_decompress -i @INPUT_NR_PATH@/edf_c2_1103421.jp2 -o @TEMP_PATH@/edf_c2_1103421.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/edf_c2_1178956.jp2 -o @TEMP_PATH@/edf_c2_1178956.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/edf_c2_1000290.jp2 -o @TEMP_PATH@/edf_c2_1000290.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/edf_c2_1000691.jp2 -o @TEMP_PATH@/edf_c2_1000691.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/edf_c2_20.jp2 -o @TEMP_PATH@/edf_c2_20.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/edf_c2_1377017.jp2 -o @TEMP_PATH@/edf_c2_1377017.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/edf_c2_1002767.jp2 -o @TEMP_PATH@/edf_c2_1002767.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/edf_c2_10025.jp2 -o @TEMP_PATH@/edf_c2_10025.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/edf_c2_1000234.jp2 -o @TEMP_PATH@/edf_c2_1000234.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/edf_c2_225881.jp2 -o @TEMP_PATH@/edf_c2_225881.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/edf_c2_1000671.jp2 -o @TEMP_PATH@/edf_c2_1000671.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/edf_c2_1013627.jp2 -o @TEMP_PATH@/edf_c2_1013627.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/edf_c2_1015644.jp2 -o @TEMP_PATH@/edf_c2_1015644.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/edf_c2_101463.jp2 -o @TEMP_PATH@/edf_c2_101463.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/edf_c2_1674177.jp2 -o @TEMP_PATH@/edf_c2_1674177.jp2.pgx +!opj_decompress -i @INPUT_NR_PATH@/edf_c2_1673169.jp2 -o @TEMP_PATH@/edf_c2_1673169.jp2.pgx # decode with specific area # prec=12; nb_c=1 From ae49fd1aa9ef6409d958255c1461a8222e2a9ae4 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 18 Mar 2014 14:37:33 +0000 Subject: [PATCH 322/333] [trunk] Update big endian handling no such thing as WORDS_BIGENDIAN (prefer OPJ_BIG_ENDIAN) Update issue 302 --- src/bin/jp2/convert.c | 6 +++--- src/bin/jpwl/convert.c | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index 3588700b..2ab6d628 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -94,7 +94,7 @@ struct tga_header static unsigned short get_ushort(unsigned short val) { -#ifdef WORDS_BIGENDIAN +#ifdef OPJ_BIG_ENDIAN return( ((val & 0xff) << 8) + (val >> 8) ); #else return( val ); @@ -181,7 +181,7 @@ static int tga_readheader(FILE *fp, unsigned int *bits_per_pixel, return 1; } -#if WORDS_BIGENDIAN == 1 +#ifdef OPJ_BIG_ENDIAN static INLINE int16_t swap16(int16_t x) { @@ -228,7 +228,7 @@ static int tga_writeheader(FILE *fp, int bits_per_pixel, int width, int height, image_w = (unsigned short)width; image_h = (unsigned short) height; -#if WORDS_BIGENDIAN == 0 +#ifndef OPJ_BIG_ENDIAN if(fwrite(&image_w, 2, 1, fp) != 1) goto fails; if(fwrite(&image_h, 2, 1, fp) != 1) goto fails; #else diff --git a/src/bin/jpwl/convert.c b/src/bin/jpwl/convert.c index 98f3c62c..50123257 100644 --- a/src/bin/jpwl/convert.c +++ b/src/bin/jpwl/convert.c @@ -94,7 +94,7 @@ struct tga_header static unsigned short get_ushort(unsigned short val) { -#ifdef WORDS_BIGENDIAN +#ifdef OPJ_BIG_ENDIAN return( ((val & 0xff) << 8) + (val >> 8) ); #else return( val ); @@ -179,7 +179,7 @@ static int tga_readheader(FILE *fp, unsigned int *bits_per_pixel, return 1; } -#if WORDS_BIGENDIAN == 1 +#ifdef OPJ_BIG_ENDIAN static inline int16_t swap16(int16_t x) { @@ -226,7 +226,7 @@ static int tga_writeheader(FILE *fp, int bits_per_pixel, int width, int height, image_w = (unsigned short)width; image_h = (unsigned short) height; -#if WORDS_BIGENDIAN == 0 +#ifndef OPJ_BIG_ENDIAN if(fwrite(&image_w, 2, 1, fp) != 1) goto fails; if(fwrite(&image_h, 2, 1, fp) != 1) goto fails; #else From 008de865337989c00879e32f23c8259c1be31d00 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 18 Mar 2014 14:43:18 +0000 Subject: [PATCH 323/333] [trunk] Import git commit 99a6f1af177c15f4db475186b79d169c993494ef from ghostscript team Update issue 296 --- src/lib/openjp2/t2.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c index 82d7a78f..253d14f8 100644 --- a/src/lib/openjp2/t2.c +++ b/src/lib/openjp2/t2.c @@ -855,8 +855,12 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, /* SOP markers */ if (p_tcp->csty & J2K_CP_CSTY_SOP) { - if ((*l_current_data) != 0xff || (*(l_current_data + 1) != 0x91)) { - /* TODO opj_event_msg(t2->cinfo->event_mgr, EVT_WARNING, "Expected SOP marker\n"); */ + if (p_max_length < 6) { + /* TODO opj_event_msg(p_t2->cinfo->event_mgr, EVT_WARNING, "Not enough space for expected SOP marker\n"); */ + printf("Not enough space for expected SOP marker\n"); + } else if ((*l_current_data) != 0xff || (*(l_current_data + 1) != 0x91)) { + /* TODO opj_event_msg(p_t2->cinfo->event_mgr, EVT_WARNING, "Expected SOP marker\n"); */ + printf("Expected SOP marker\n"); fprintf(stderr, "Error : expected SOP marker\n"); } else { l_current_data += 6; From 6d9e8a5a637b7d61d5cf060b735551cf9a624cc0 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 18 Mar 2014 14:43:47 +0000 Subject: [PATCH 324/333] [trunk] Import git commit fc884aee2b69c78500e65c3d05bf216791a9ea4a from ghostscript team Fixes issue 296 --- src/lib/openjp2/t2.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c index 253d14f8..f78d348e 100644 --- a/src/lib/openjp2/t2.c +++ b/src/lib/openjp2/t2.c @@ -985,6 +985,11 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, l_cblk->numnewpasses = opj_t2_getnumpasses(l_bio); l_increment = opj_t2_getcommacode(l_bio); + /* testcase 1802.pdf.SIGSEGV.36e.894 */ + if (l_cblk->segs[l_segno].newlen > *l_modified_length_ptr) { + opj_bio_destroy(l_bio); + return OPJ_FALSE; + } /* length indicator increment */ l_cblk->numlenbits += l_increment; l_segno = 0; @@ -1153,6 +1158,7 @@ OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2, OPJ_BYTE* new_cblk_data = (OPJ_BYTE*) opj_realloc(l_cblk->data, l_cblk->data_current_size + l_seg->newlen); if(! new_cblk_data) { opj_free(l_cblk->data); + l_cblk->data = NULL; l_cblk->data_max_size = 0; /* opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to realloc code block cata!\n"); */ return OPJ_FALSE; From 51ab074d50995d1be19a6662392919de8a9d6061 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 18 Mar 2014 15:00:23 +0000 Subject: [PATCH 325/333] [trunk] User can now control source/target java version Fixes issue 303 --- src/bin/jpip/CMakeLists.txt | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/bin/jpip/CMakeLists.txt b/src/bin/jpip/CMakeLists.txt index 9404c111..821b2015 100644 --- a/src/bin/jpip/CMakeLists.txt +++ b/src/bin/jpip/CMakeLists.txt @@ -59,6 +59,14 @@ endforeach() # Build the two java clients: find_package(Java 1.5 COMPONENTS Development) # javac, jar +# User can override this: +if(NOT DEFINED JAVA_SOURCE_VERSION) + set(JAVA_SOURCE_VERSION 1.5) +endif() +if(NOT DEFINED JAVA_TARGET_VERSION) + set(JAVA_TARGET_VERSION 1.5) +endif() + # Only build the java viewer if dev is found: if(Java_Development_FOUND AND Java_JAVAC_EXECUTABLE) set(jflags $ENV{JFLAGS}) @@ -97,6 +105,7 @@ if(Java_Development_FOUND AND Java_JAVAC_EXECUTABLE) add_custom_command( OUTPUT ${LIBRARY_OUTPUT_PATH}/opj_jpip_viewer.jar COMMAND ${Java_JAVAC_EXECUTABLE} ${jflags} + -source ${JAVA_SOURCE_VERSION} -target ${JAVA_TARGET_VERSION} -classpath ${APACHE_XERCES_JAR} ${java2_srcs} -d ${CMAKE_CURRENT_BINARY_DIR}/classes2 COMMAND ${Java_JAR_EXECUTABLE} cfm ${LIBRARY_OUTPUT_PATH}/opj_jpip_viewer.jar @@ -127,6 +136,7 @@ if(Java_Development_FOUND AND Java_JAVAC_EXECUTABLE) add_custom_command( OUTPUT ${LIBRARY_OUTPUT_PATH}/opj_jpip_viewer.jar COMMAND ${Java_JAVAC_EXECUTABLE} ${jflags} + -source ${JAVA_SOURCE_VERSION} -target ${JAVA_TARGET_VERSION} ${java1_srcs} -d ${CMAKE_CURRENT_BINARY_DIR}/classes1 COMMAND ${Java_JAR_EXECUTABLE} cfm ${LIBRARY_OUTPUT_PATH}/opj_jpip_viewer.jar ${CMAKE_CURRENT_SOURCE_DIR}/opj_viewer/dist/manifest.txt -C From f4707da97aee215a2328ad48114155bd2f13e414 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 18 Mar 2014 15:19:29 +0000 Subject: [PATCH 326/333] [trunk] Revert r2764. It breaks ~230 tests as seen on continuous. Since no dataset is available, the issue 296 will be left open. Update issue 296 --- src/lib/openjp2/t2.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/lib/openjp2/t2.c b/src/lib/openjp2/t2.c index f78d348e..253d14f8 100644 --- a/src/lib/openjp2/t2.c +++ b/src/lib/openjp2/t2.c @@ -985,11 +985,6 @@ OPJ_BOOL opj_t2_read_packet_header( opj_t2_t* p_t2, l_cblk->numnewpasses = opj_t2_getnumpasses(l_bio); l_increment = opj_t2_getcommacode(l_bio); - /* testcase 1802.pdf.SIGSEGV.36e.894 */ - if (l_cblk->segs[l_segno].newlen > *l_modified_length_ptr) { - opj_bio_destroy(l_bio); - return OPJ_FALSE; - } /* length indicator increment */ l_cblk->numlenbits += l_increment; l_segno = 0; @@ -1158,7 +1153,6 @@ OPJ_BOOL opj_t2_read_packet_data( opj_t2_t* p_t2, OPJ_BYTE* new_cblk_data = (OPJ_BYTE*) opj_realloc(l_cblk->data, l_cblk->data_current_size + l_seg->newlen); if(! new_cblk_data) { opj_free(l_cblk->data); - l_cblk->data = NULL; l_cblk->data_max_size = 0; /* opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to realloc code block cata!\n"); */ return OPJ_FALSE; From 5a70e97f515a5cfbbc58e5f0580c731fb5eee677 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 24 Mar 2014 09:49:04 +0000 Subject: [PATCH 327/333] [trunk] Fix typo in comment (this is not j2k_dump) --- src/bin/jp2/opj_decompress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/jp2/opj_decompress.c b/src/bin/jp2/opj_decompress.c index aded1996..661a00f7 100644 --- a/src/bin/jp2/opj_decompress.c +++ b/src/bin/jp2/opj_decompress.c @@ -787,7 +787,7 @@ int main(int argc, char **argv) /* Setup the decoder decoding parameters using user parameters */ if ( !opj_setup_decoder(l_codec, ¶meters) ){ - fprintf(stderr, "ERROR -> j2k_dump: failed to setup the decoder\n"); + fprintf(stderr, "ERROR -> opj_compress: failed to setup the decoder\n"); opj_stream_destroy_v3(l_stream); opj_destroy_codec(l_codec); return EXIT_FAILURE; From 18c5be69e9c2bd195e707a7ef7f1f6625b74a86b Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Mon, 24 Mar 2014 16:01:51 +0000 Subject: [PATCH 328/333] [trunk] Make sure to exit early instead of looping on every single pixels --- src/bin/jp2/convert.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index 2ab6d628..e5a8b0bb 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -1867,8 +1867,12 @@ opj_image_t* pnmtoimage(const char *filename, opj_cparameters_t *parameters) { { for(compno = 0; compno < numcomps; compno++) { - if ( !fread(&c0, 1, 1, fp) ) - fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); + if ( !fread(&c0, 1, 1, fp) ) + { + fprintf(stderr, "\nError: fread return a number of element different from the expected.\n"); + opj_image_destroy(image); + return NULL; + } if(one) { image->comps[compno].data[i] = c0; From 2b93727bea45406118bf6110aa8e725dc6d9f68b Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 25 Mar 2014 10:22:40 +0000 Subject: [PATCH 329/333] [trunk] Add documentation --- tests/ppm2rgb3.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/tests/ppm2rgb3.c b/tests/ppm2rgb3.c index c9b4772a..58e7102c 100644 --- a/tests/ppm2rgb3.c +++ b/tests/ppm2rgb3.c @@ -120,7 +120,11 @@ int main(int argc, char *argv[]) int X, Y, bpp; int ok = 0; - if( argc < 2 ) goto cleanup; + if( argc < 2 ) + { + fprintf( stderr, "%s input.ppm\n", argv[0] ); + goto cleanup; + } fn = argv[1]; ppm = fopen( fn, "rb" ); From 492d8ab7d9dbe9b850cf8c7a9930189a1e864c66 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 25 Mar 2014 10:23:40 +0000 Subject: [PATCH 330/333] [trunk] Rework previous commit r2610 This way we are able to gently deprecate the old API, and preserve ABI Update issue 306 --- src/lib/openjp2/cio.c | 10 +++++++++- src/lib/openjp2/openjpeg.c | 2 +- src/lib/openjp2/openjpeg.h | 10 +++++++++- 3 files changed, 19 insertions(+), 3 deletions(-) diff --git a/src/lib/openjp2/cio.c b/src/lib/openjp2/cio.c index f7f1bc72..bf91371c 100644 --- a/src/lib/openjp2/cio.c +++ b/src/lib/openjp2/cio.c @@ -246,7 +246,15 @@ void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_strea l_stream->m_skip_fn = p_function; } -void OPJ_CALLCONV opj_stream_set_user_data(opj_stream_t* p_stream, void * p_data, opj_stream_free_user_data_fn p_function) +void OPJ_CALLCONV opj_stream_set_user_data(opj_stream_t* p_stream, void * p_data) +{ + opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; + if (!l_stream) + return; + l_stream->m_user_data = p_data; +} + +void OPJ_CALLCONV opj_stream_set_user_data_v3(opj_stream_t* p_stream, void * p_data, opj_stream_free_user_data_fn p_function) { opj_stream_private_t* l_stream = (opj_stream_private_t*) p_stream; if (!l_stream) diff --git a/src/lib/openjp2/openjpeg.c b/src/lib/openjp2/openjpeg.c index 0522acb0..dfb8093c 100644 --- a/src/lib/openjp2/openjpeg.c +++ b/src/lib/openjp2/openjpeg.c @@ -944,7 +944,7 @@ opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream_v3 ( return NULL; } - opj_stream_set_user_data(l_stream, p_file, (opj_stream_free_user_data_fn) fclose); + opj_stream_set_user_data_v3(l_stream, p_file, (opj_stream_free_user_data_fn) fclose); opj_stream_set_user_data_length(l_stream, opj_get_data_length_from_file(p_file)); opj_stream_set_read_function(l_stream, (opj_stream_read_fn) opj_read_from_file); opj_stream_set_write_function(l_stream, (opj_stream_write_fn) opj_write_from_file); diff --git a/src/lib/openjp2/openjpeg.h b/src/lib/openjp2/openjpeg.h index 1ea2af80..466d07fd 100644 --- a/src/lib/openjp2/openjpeg.h +++ b/src/lib/openjp2/openjpeg.h @@ -1067,13 +1067,21 @@ OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, o */ OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, opj_stream_seek_fn p_function); +/** + * Sets the given data to be used as a user data for the stream. + * @param p_stream the stream to modify + * @param p_data the data to set. + * @warning depending on your source object p_stream this function may leak, use opj_stream_set_user_data_v3 +*/ +OPJ_DEPRECATED(OPJ_API void OPJ_CALLCONV opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data)); + /** * Sets the given data to be used as a user data for the stream. * @param p_stream the stream to modify * @param p_data the data to set. * @param p_function the function to free p_data when opj_stream_destroy() is called. */ -OPJ_API void OPJ_CALLCONV opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data, opj_stream_free_user_data_fn p_function); +OPJ_API void OPJ_CALLCONV opj_stream_set_user_data_v3 (opj_stream_t* p_stream, void * p_data, opj_stream_free_user_data_fn p_function); /** * Sets the length of the user data for the stream. From 18d5d25cb6609bfa79aaf7864856033bc508a7b2 Mon Sep 17 00:00:00 2001 From: Mathieu Malaterre Date: Tue, 25 Mar 2014 11:47:34 +0000 Subject: [PATCH 331/333] [trunk] Make sure to not use alpha pointer if it is not an RGBA input Fixes issue 310 --- src/bin/jp2/convert.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index e5a8b0bb..d3e9773c 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -3222,7 +3222,7 @@ opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params) opj_image_cmptparm_t cmptparm[4]; int sub_dx, sub_dy; unsigned int nr_comp; - int *r, *g, *b, *a; + int *r, *g, *b, *a = NULL; unsigned char sigbuf[8]; if((reader = fopen(read_idf, "rb")) == NULL) @@ -3312,7 +3312,7 @@ opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params) png_read_image(png, rows); - memset(&cmptparm, 0, 4 * sizeof(opj_image_cmptparm_t)); + memset(cmptparm, 0, sizeof(cmptparm)); sub_dx = params->subsampling_dx; sub_dy = params->subsampling_dy; @@ -3340,7 +3340,7 @@ opj_image_t *pngtoimage(const char *read_idf, opj_cparameters_t * params) r = image->comps[0].data; g = image->comps[1].data; b = image->comps[2].data; - a = image->comps[3].data; + if(has_alpha) a = image->comps[3].data; for(i = 0; i < height; ++i) { From 2b7d5b18f390315d08c75f59cc1383f8d4e53251 Mon Sep 17 00:00:00 2001 From: Antonin Descampe Date: Tue, 25 Mar 2014 12:38:29 +0000 Subject: [PATCH 332/333] [trunk] add "-mct {0,1,2}" option to opj_compress to allow MCT to be disabled if needed. --- src/bin/jp2/opj_compress.c | 48 ++++++++++++++++++++++++++++++++++---- 1 file changed, 43 insertions(+), 5 deletions(-) diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index ffb76349..95662be9 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -102,6 +102,7 @@ static void encode_help_display(void) { fprintf(stdout,"\n"); fprintf(stdout," * Lossless\n"); fprintf(stdout," * 1 tile\n"); + fprintf(stdout," * RGB->YCC conversion if at least 3 components\n"); fprintf(stdout," * Size of precinct : 2^15 x 2^15 (means 1 precinct)\n"); fprintf(stdout," * Size of code-block : 64 x 64\n"); fprintf(stdout," * Number of resolutions: 6\n"); @@ -208,8 +209,14 @@ static void encode_help_display(void) { fprintf(stdout," -F rawWidth,rawHeight,rawComp,rawBitDepth,s/u (Signed/Unsigned)\n"); fprintf(stdout," Example: -i lena.raw -o lena.j2k -F 512,512,3,8,u\n"); fprintf(stdout,"\n"); - fprintf(stdout,"-m : use array-based MCT, values are coma separated, line by line\n"); - fprintf(stdout," no specific separators between lines, no space allowed between values\n"); + fprintf(stdout,"-mct {0,1,2} : explicitely specifies if an Multiple Component Transform has to be used.\n"); + fprintf(stdout," 0: no MCT ; 1: RGB->YCC conversion ; 2: custom MCT.\n"); + fprintf(stdout," If custom MCT, \"-m\" option has to be used (see hereunder).\n"); + fprintf(stdout," By default, RGB->YCC conversion is used if there are 3 components or more,\n"); + fprintf(stdout," no conversion otherwise.\n"); + fprintf(stdout,"-m : use array-based MCT, values are coma separated, line by line\n"); + fprintf(stdout," no specific separators between lines, no space allowed between values\n"); + fprintf(stdout," If this option is used, it automatically sets \"-mct\" option to 2.\n"); fprintf(stdout,"-jpip : write jpip codestream index box in JP2 output file\n"); fprintf(stdout," NOTICE: currently supports only RPCL order\n"); fprintf(stdout,"\n"); @@ -453,11 +460,12 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param {"OutFor",REQ_ARG, NULL ,'O'}, {"POC",REQ_ARG, NULL ,'P'}, {"ROI",REQ_ARG, NULL ,'R'}, - {"jpip",NO_ARG, NULL, 'J'} + {"jpip",NO_ARG, NULL, 'J'}, + {"mct",REQ_ARG, NULL, 'Y'} }; /* parse the command line */ - const char optlist[] = "i:o:r:q:n:b:c:t:p:s:SEM:x:R:d:T:If:P:C:F:u:J" + const char optlist[] = "i:o:r:q:n:b:c:t:p:s:SEM:x:R:d:T:If:P:C:F:u:JY:" #ifdef USE_JPWL "W:" #endif /* USE_JPWL */ @@ -927,6 +935,22 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param break; /* ------------------------------------------------------ */ + + case 'Y': /* Shall we do an MCT ? 0:no_mct;1:rgb->ycc;2:custom mct (-m option required)*/ + { + int mct_mode=0; + sscanf(opj_optarg,"%d",&mct_mode); + if(mct_mode < 0 || mct_mode > 2){ + fprintf(stderr,"MCT incorrect value!! Current accepted values are 0, 1 or 2.\n"); + return 1; + } + parameters->tcp_mct = mct_mode; + } + break; + + /* ------------------------------------------------------ */ + + case 'm': /* mct input file */ { char *lFilename = opj_optarg; @@ -1452,6 +1476,7 @@ int main(int argc, char **argv) { memset(&img_fol,0,sizeof(img_fol_t)); /* parse input and get user encoding parameters */ + parameters.tcp_mct = -1; /* This will be set later according to the input image or the provided option */ if(parse_cmdline_encoder(argc, argv, ¶meters,&img_fol, &raw_cp, indexfilename) == 1) { return 1; } @@ -1611,7 +1636,20 @@ int main(int argc, char **argv) { } /* Decide if MCT should be used */ - parameters.tcp_mct = image->numcomps == 3 ? 1 : 0; + if (parameters.tcp_mct == -1) { /* mct mode has not been set in commandline */ + parameters.tcp_mct = image->numcomps >= 3 ? 1 : 0; + } else { /* mct mode has been set in commandline */ + if ((parameters.tcp_mct == 1) && (image->numcomps < 3)){ + fprintf(stderr, "RGB->YCC conversion cannot be used:\n"); + fprintf(stderr, "Input image has less than 3 components\n"); + return 1; + } + if ((parameters.tcp_mct == 2) && (!parameters.mct_data)){ + fprintf(stderr, "Custom MCT has been set but no array-based MCT\n"); + fprintf(stderr, "has been provided. Aborting.\n"); + return 1; + } + } /* encode the destination image */ /* ---------------------------- */ From 666f71b2a171f0d5f94dc49ae60f439b0f517c6b Mon Sep 17 00:00:00 2001 From: Antonin Descampe Date: Tue, 25 Mar 2014 13:29:11 +0000 Subject: [PATCH 333/333] [trunk] fixed warning due induced by r2791 --- src/bin/jp2/opj_compress.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index 95662be9..3cd63e2b 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -944,7 +944,7 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param fprintf(stderr,"MCT incorrect value!! Current accepted values are 0, 1 or 2.\n"); return 1; } - parameters->tcp_mct = mct_mode; + parameters->tcp_mct = (char) mct_mode; } break;