diff options
| author | Robert Gabriel Jakabosky <rjakabosky+github@neoawareness.com> | 2022-02-10 21:27:17 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2022-02-10 14:27:17 +0100 |
| commit | 883c31dbe09771aab043744ac2b490d7386878e3 (patch) | |
| tree | 254f62d7e8158b28eea45e6ff6a58b212a380371 /src/lib/openjp2/j2k.c | |
| parent | 99d555c0f1818277645a0c79a5199f2e827d68cc (diff) | |
Add support for partial bitstream decoding (#1407) (fixes #715)
Add a -allow-partial option to opj_decompress utility and a opj_decoder_set_strict_mode() option to the API
Co-authored-by: Chris Hafey <chafey@gmail.com>
Diffstat (limited to 'src/lib/openjp2/j2k.c')
| -rw-r--r-- | src/lib/openjp2/j2k.c | 21 |
1 files changed, 18 insertions, 3 deletions
diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 6cb6b8ca..e7c03ae1 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -4964,9 +4964,14 @@ static OPJ_BOOL opj_j2k_read_sod(opj_j2k_t *p_j2k, /* Check enough bytes left in stream before allocation */ if ((OPJ_OFF_T)p_j2k->m_specific_param.m_decoder.m_sot_length > opj_stream_get_number_byte_left(p_stream)) { - opj_event_msg(p_manager, EVT_ERROR, - "Tile part length size inconsistent with stream length\n"); - return OPJ_FALSE; + if (p_j2k->m_cp.strict) { + opj_event_msg(p_manager, EVT_ERROR, + "Tile part length size inconsistent with stream length\n"); + return OPJ_FALSE; + } else { + opj_event_msg(p_manager, EVT_WARNING, + "Tile part length size inconsistent with stream length\n"); + } } if (p_j2k->m_specific_param.m_decoder.m_sot_length > UINT_MAX - OPJ_COMMON_CBLK_DATA_EXTRA) { @@ -6695,6 +6700,13 @@ void opj_j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters) } } +void opj_j2k_decoder_set_strict_mode(opj_j2k_t *j2k, OPJ_BOOL strict) +{ + if (j2k) { + j2k->m_cp.strict = strict; + } +} + OPJ_BOOL opj_j2k_set_threads(opj_j2k_t *j2k, OPJ_UINT32 num_threads) { /* Currently we pass the thread-pool to the tcd, so we cannot re-set it */ @@ -10409,6 +10421,9 @@ opj_j2k_t* opj_j2k_create_decompress(void) /* per component is allowed */ l_j2k->m_cp.allow_different_bit_depth_sign = 1; + /* Default to using strict mode. */ + l_j2k->m_cp.strict = OPJ_TRUE; + #ifdef OPJ_DISABLE_TPSOT_FIX l_j2k->m_specific_param.m_decoder.m_nb_tile_parts_correction_checked = 1; #endif |
