From 49cb46cbaa3223cf91f7d846f0f611114ac3e0df Mon Sep 17 00:00:00 2001 From: Sebastian Rasmussen Date: Wed, 31 Oct 2018 20:22:11 +0100 Subject: [PATCH] openjp2/j2k: Report error if all wanted components are not decoded. Previously the caller had to check whether each component data had been decoded. This means duplicating the checking in every user of openjpeg which is unnecessary. If the caller wantes to decode all or a set of, or a specific component then openjpeg ought to error out if it was unable to do so. Fixes #1158. --- src/bin/jp2/opj_decompress.c | 11 ----------- src/lib/openjp2/j2k.c | 24 ++++++++++++++++++++++++ 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/src/bin/jp2/opj_decompress.c b/src/bin/jp2/opj_decompress.c index a28a194bb..0e55f81ec 100644 --- a/src/bin/jp2/opj_decompress.c +++ b/src/bin/jp2/opj_decompress.c @@ -1570,17 +1570,6 @@ int main(int argc, char **argv) } } - /* FIXME? Shouldn't that situation be considered as an error of */ - /* opj_decode() / opj_get_decoded_tile() ? */ - if (image->comps[0].data == NULL) { - fprintf(stderr, "ERROR -> opj_decompress: no image data!\n"); - opj_destroy_codec(l_codec); - opj_stream_destroy(l_stream); - opj_image_destroy(image); - failed = 1; - goto fin; - } - tCumulative += opj_clock() - t; numDecompressedImages++; diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index b3532854b..c08a693df 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -10677,6 +10677,8 @@ static 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_UINT32 nr_tiles = 0; + OPJ_UINT32 compno; + OPJ_BOOL decoded_all_used_components = OPJ_TRUE; /* Particular case for whole single tile decoding */ /* We can avoid allocating intermediate tile buffers */ @@ -10779,6 +10781,28 @@ static OPJ_BOOL opj_j2k_decode_tiles(opj_j2k_t *p_j2k, } } + if (p_j2k->m_specific_param.m_decoder.m_numcomps_to_decode) { + for (compno = 0; compno < p_j2k->m_specific_param.m_decoder.m_numcomps_to_decode; compno++) { + OPJ_UINT32 dec_compno = p_j2k->m_specific_param.m_decoder.m_comps_indices_to_decode[compno]; + if (p_j2k->m_output_image->comps[dec_compno].data == NULL) { + opj_event_msg(p_manager, EVT_WARNING, "Failed to decode component %d\n", dec_compno); + decoded_all_used_components = OPJ_FALSE; + } + } + } else { + for (compno = 0; compno < p_j2k->m_output_image->numcomps; compno++) { + if (p_j2k->m_output_image->comps[compno].data == NULL) { + opj_event_msg(p_manager, EVT_WARNING, "Failed to decode component %d\n", compno); + decoded_all_used_components = OPJ_FALSE; + } + } + } + + if (decoded_all_used_components == OPJ_FALSE) { + opj_event_msg(p_manager, EVT_ERROR, "Failed to decode all used components\n"); + return OPJ_FALSE; + } + return OPJ_TRUE; }