Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not turn on 'TPsot==TNsot detection fix' when TNsot==1, and #1560

Merged
merged 2 commits into from
Nov 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 16 additions & 3 deletions src/lib/openjp2/j2k.c
Original file line number Diff line number Diff line change
Expand Up @@ -6764,6 +6764,9 @@ void opj_j2k_decoder_set_strict_mode(opj_j2k_t *j2k, OPJ_BOOL strict)
{
if (j2k) {
j2k->m_cp.strict = strict;
if (strict) {
j2k->m_specific_param.m_decoder.m_nb_tile_parts_correction_checked = 1;
}
}
}

Expand Down Expand Up @@ -9964,11 +9967,21 @@ OPJ_BOOL opj_j2k_read_tile_header(opj_j2k_t * p_j2k,
if (p_j2k->m_specific_param.m_decoder.m_can_decode &&
!p_j2k->m_specific_param.m_decoder.m_nb_tile_parts_correction_checked) {
/* Issue 254 */
OPJ_BOOL l_correction_needed;
OPJ_BOOL l_correction_needed = OPJ_FALSE;

p_j2k->m_specific_param.m_decoder.m_nb_tile_parts_correction_checked = 1;
if (!opj_j2k_need_nb_tile_parts_correction(p_stream,
p_j2k->m_current_tile_number, &l_correction_needed, p_manager)) {
if (p_j2k->m_cp.tcps[p_j2k->m_current_tile_number].m_nb_tile_parts == 1) {
/* Skip opj_j2k_need_nb_tile_parts_correction() if there is
* only a single tile part declared. The
* opj_j2k_need_nb_tile_parts_correction() hack was needed
* for files with 5 declared tileparts (where they were
* actually 6).
* Doing it systematically hurts performance when reading
* Sentinel2 L1C JPEG2000 files as explained in
* https://lists.osgeo.org/pipermail/gdal-dev/2024-November/059805.html
*/
} else if (!opj_j2k_need_nb_tile_parts_correction(p_stream,
p_j2k->m_current_tile_number, &l_correction_needed, p_manager)) {
opj_event_msg(p_manager, EVT_ERROR,
"opj_j2k_apply_nb_tile_parts_correction error\n");
return OPJ_FALSE;
Expand Down
12 changes: 8 additions & 4 deletions src/lib/openjp2/openjpeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -546,7 +546,7 @@ typedef struct opj_cparameters {
} opj_cparameters_t;

#define OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG 0x0001
#define OPJ_DPARAMETERS_DUMP_FLAG 0x0002
#define OPJ_DPARAMETERS_DUMP_FLAG 0x0002

/**
* Decompression parameters
Expand Down Expand Up @@ -1348,9 +1348,13 @@ OPJ_API OPJ_BOOL OPJ_CALLCONV opj_setup_decoder(opj_codec_t *p_codec,
opj_dparameters_t *parameters);

/**
* Set strict decoding parameter for this decoder. If strict decoding is enabled, partial bit
* streams will fail to decode. If strict decoding is disabled, the decoder will decode partial
* bitstreams as much as possible without erroring
* Set strict decoding parameter for this decoder.
* If strict decoding is enabled, partial bit streams will fail to decode, and
* the check for invalid TPSOT values added in https://github.com/uclouvain/openjpeg/pull/514
* will be disabled.
* If strict decoding is disabled, the decoder will decode partial
* bitstreams as much as possible without erroring, and the TPSOT fixing logic
* will be enabled.
*
* @param p_codec decompressor handler
* @param strict OPJ_TRUE to enable strict decoding, OPJ_FALSE to disable
Expand Down