From c7d3b83164b8c0a857fec52da005bd736fcce30c Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Tue, 11 Oct 2011 07:49:16 +0000 Subject: [PATCH] [trunk] WIP: correct mistake with JP2 files and manage correctly the text_GBR.jp2 filecase --- CHANGES | 3 +++ applications/codec/j2k_to_image.c | 9 +-------- libopenjpeg/j2k.c | 11 ++++++++++- libopenjpeg/jp2.c | 5 +++-- tests/nonregression/test_suite.ctest.in | 5 +++-- 5 files changed, 20 insertions(+), 13 deletions(-) diff --git a/CHANGES b/CHANGES index b7519d34..eeccd3b4 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,9 @@ What's New for OpenJPEG ! : changed + : added +October 11, 2011 +* [mickael] WIP: correct mistake with JP2 files and manage correctly the text_GBR.jp2 filecase. + October 10, 2011 * [vincent] fix 'distcheck' rule + [vincent] add libopenjpeg-jpwl.pc.in diff --git a/applications/codec/j2k_to_image.c b/applications/codec/j2k_to_image.c index 65ba1e5a..cbc00606 100644 --- a/applications/codec/j2k_to_image.c +++ b/applications/codec/j2k_to_image.c @@ -579,8 +579,6 @@ int main(int argc, char **argv) opj_image_t image; opj_stream_t *cio = NULL; /* Stream */ opj_codec_t* dinfo = NULL; /* Handle to a decompressor */ - opj_bool bRes1, bRes2; - char indexfilename[OPJ_PATH_LEN]; /* index file name */ @@ -713,13 +711,8 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - /* Get the decoded image */ - bRes1 = opj_decode_v2(dinfo, cio, &image); - bRes2 = opj_end_decompress(dinfo,cio); - - /*if ( !(opj_decode_v2(dinfo, cio, &image)) || !(opj_end_decompress(dinfo,cio)) ) {*/ - if ( !bRes1 || !bRes2) { + if ( !( opj_decode_v2(dinfo, cio, &image) && opj_end_decompress(dinfo,cio) ) ) { fprintf(stderr, "ERROR -> j2k_to_image: failed to decode image!\n"); opj_destroy_codec(dinfo); opj_stream_destroy(cio); diff --git a/libopenjpeg/j2k.c b/libopenjpeg/j2k.c index bc611609..219bb0f7 100644 --- a/libopenjpeg/j2k.c +++ b/libopenjpeg/j2k.c @@ -3362,6 +3362,15 @@ opj_bool j2k_read_sot_v2 ( ++p_header_data; 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_v2(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 ); + return OPJ_FALSE; + } + } l_tcp->m_nb_tile_parts = l_num_parts; } @@ -5709,7 +5718,7 @@ opj_bool j2k_read_tile_header( opj_j2k_v2_t * p_j2k, /* Read the marker segment with the correct marker handler */ if (! (*(l_marker_handler->handler))(p_j2k,p_j2k->m_specific_param.m_decoder.m_header_data,l_marker_size,p_manager)) { - opj_event_msg_v2(p_manager, EVT_ERROR, "Marker is not compliant with its position\n"); + opj_event_msg_v2(p_manager, EVT_ERROR, "Fail to read the current marker segment (%#x)\n", l_current_marker); return OPJ_FALSE; } diff --git a/libopenjpeg/jp2.c b/libopenjpeg/jp2.c index 618f9ab4..d29e060a 100644 --- a/libopenjpeg/jp2.c +++ b/libopenjpeg/jp2.c @@ -1490,8 +1490,8 @@ opj_bool opj_jp2_decode_v2( opj_jp2_v2_t *jp2, struct opj_event_mgr * p_manager) { /* J2K decoding */ - if( j2k_decode_v2(jp2->j2k, cio, p_image, p_manager) ) { - opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to decode J2K image\n"); + if( ! j2k_decode_v2(jp2->j2k, cio, p_image, p_manager) ) { + opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to decode the codestream in the JP2 file\n"); return OPJ_FALSE; } @@ -1521,6 +1521,7 @@ opj_bool opj_jp2_decode_v2( opj_jp2_v2_t *jp2, if(jp2->color.icc_profile_buf) { p_image->icc_profile_buf = jp2->color.icc_profile_buf; p_image->icc_profile_len = jp2->color.icc_profile_len; + jp2->color.icc_profile_buf = NULL; } return OPJ_TRUE; diff --git a/tests/nonregression/test_suite.ctest.in b/tests/nonregression/test_suite.ctest.in index ba89ef7c..b1cba12a 100644 --- a/tests/nonregression/test_suite.ctest.in +++ b/tests/nonregression/test_suite.ctest.in @@ -10,7 +10,7 @@ # image to base) # # Line begin with ! should failed (should be used for bad jpeg2000 file which should be -# gracefully rejected) +# gracefully rejected). Please add a short resume about why this file should be rejected. # # You can use @INPUT_NR_PATH@ and @TEMP_PATH@ cmake variable which refers to OPJ_DATA_ROOT # repository. However you can use relative path or absolute path. @@ -60,4 +60,5 @@ j2k_to_image -i @INPUT_NR_PATH@/orb-blue10-win-j2k.j2k -o @TEMP_PATH@/orb-blue1 j2k_to_image -i @INPUT_NR_PATH@/orb-blue10-win-jp2.jp2 -o @TEMP_PATH@/orb-blue10-win-jp2.jp2.pgx j2k_to_image -i @INPUT_NR_PATH@/relax.jp2 -o @TEMP_PATH@/relax.jp2.pgx j2k_to_image -i @INPUT_NR_PATH@/test_lossless.j2k -o @TEMP_PATH@/test_lossless.j2k.pgx -j2k_to_image -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. +!j2k_to_image -i @INPUT_NR_PATH@/text_GBR.jp2 -o @TEMP_PATH@/text_GBR.jp2.pgx