PR #975 introduced a check that rejects images that have different bit depth/sign per compoment in SIZ marker if the JP2 IHDR box has BPC != 255 This didn't work properly if decoding a .j2k file since the new bit added in opj_cp_t wasn't initialized to the right value. For clarity, tThis new bit has also been renamed to allow_different_bit_depth_sign But looking closer at the code, it seems we were already tolerant to inconsistencies. For example we parsed a JP2 BPCC box even if BPC != 255 (just a warning is emitted) So failing hard in opj_j2k_read_siz() wouldn't be very inconsistent, and that alone cannot protect against other issues, so just emit a warning if BPC != 255 and the SIZ marker contains different bit depth/sign per component. Note: we could also check that the content of JP2 BPCC box is consistant with the one of the SIZ marker.
This commit is contained in:
parent
c38bdbef4f
commit
ac375ac9f5
|
@ -2239,14 +2239,14 @@ static OPJ_BOOL opj_j2k_read_siz(opj_j2k_t *p_j2k,
|
|||
if (i == 0) {
|
||||
l_prec0 = l_img_comp->prec;
|
||||
l_sgnd0 = l_img_comp->sgnd;
|
||||
} else if (l_cp->bpc_is_255 == 0
|
||||
} else if (!l_cp->allow_different_bit_depth_sign
|
||||
&& (l_img_comp->prec != l_prec0 || l_img_comp->sgnd != l_sgnd0)) {
|
||||
opj_event_msg(p_manager, EVT_ERROR,
|
||||
"Invalid precision and/or sgnd values for comp[%d]:\n"
|
||||
opj_event_msg(p_manager, EVT_WARNING,
|
||||
"Despite JP2 BPC!=255, precision and/or sgnd values for comp[%d] is different than comp[0]:\n"
|
||||
" [0] prec(%d) sgnd(%d) [%d] prec(%d) sgnd(%d)\n", i, l_prec0, l_sgnd0,
|
||||
i, l_img_comp->prec, l_img_comp->sgnd);
|
||||
return OPJ_FALSE;
|
||||
}
|
||||
/* TODO: we should perhaps also check against JP2 BPCC values */
|
||||
}
|
||||
opj_read_bytes(p_header_data, &tmp, 1); /* XRsiz_i */
|
||||
++p_header_data;
|
||||
|
@ -9273,6 +9273,9 @@ opj_j2k_t* opj_j2k_create_decompress(void)
|
|||
|
||||
l_j2k->m_is_decoder = 1;
|
||||
l_j2k->m_cp.m_is_decoder = 1;
|
||||
/* in the absence of JP2 boxes, consider different bit depth / sign */
|
||||
/* per component is allowed */
|
||||
l_j2k->m_cp.allow_different_bit_depth_sign = 1;
|
||||
|
||||
#ifdef OPJ_DISABLE_TPSOT_FIX
|
||||
l_j2k->m_specific_param.m_decoder.m_nb_tile_parts_correction_checked = 1;
|
||||
|
|
|
@ -446,7 +446,8 @@ typedef struct opj_cp {
|
|||
OPJ_BITFIELD ppm : 1;
|
||||
/** tells if the parameter is a coding or decoding one */
|
||||
OPJ_BITFIELD m_is_decoder : 1;
|
||||
OPJ_BITFIELD bpc_is_255 : 1;
|
||||
/** whether different bit depth or sign per component is allowed. Decoder only for ow */
|
||||
OPJ_BITFIELD allow_different_bit_depth_sign : 1;
|
||||
/* <<UniPG */
|
||||
} opj_cp_t;
|
||||
|
||||
|
|
|
@ -619,7 +619,7 @@ static OPJ_BOOL opj_jp2_read_ihdr(opj_jp2_t *jp2,
|
|||
opj_read_bytes(p_image_header_data, &(jp2->IPR), 1); /* IPR */
|
||||
++ p_image_header_data;
|
||||
|
||||
jp2->j2k->m_cp.bpc_is_255 = (jp2->bpc == 255);
|
||||
jp2->j2k->m_cp.allow_different_bit_depth_sign = (jp2->bpc == 255);
|
||||
jp2->j2k->ihdr_w = jp2->w;
|
||||
jp2->j2k->ihdr_h = jp2->h;
|
||||
jp2->has_ihdr = 1;
|
||||
|
|
|
@ -300,3 +300,7 @@ f3081c8e9e9a175f223382a7443b480f issue559-eci-091-CIELab.jp2_2.pgx
|
|||
3bf91c974abc17e520c6a5efa883a58a issue653-zero-unknownbox.jp2.png
|
||||
8d7a866d29d5c68dc540b0f0011959a5 issue726.png
|
||||
3bf91c974abc17e520c6a5efa883a58a issue818.png
|
||||
3c7ff2e4bdae849167be36589f32bcd5 issue979.j2k_0.pgx
|
||||
f004b48eafb2e52529cc9c7b6a3ff5d2 issue979.j2k_1.pgx
|
||||
3127bd0a591d113c3c2428c8d2c14ec8 issue979.j2k_2.pgx
|
||||
dacaf60e4c430916a8c2a9ebec32e71c issue979.j2k_3.pgx
|
|
@ -594,3 +594,6 @@ opj_decompress -i @INPUT_NR_PATH@/issue818.jp2 -o @TEMP_PATH@/issue818.png
|
|||
!opj_decompress -i @INPUT_NR_PATH@/issue826.jp2 -o @TEMP_PATH@/issue826.png
|
||||
# issue 820
|
||||
!opj_decompress -i @INPUT_NR_PATH@/issue820.jp2 -o @TEMP_PATH@/issue820.png
|
||||
|
||||
# issue 979 (.j2k with different bit depth per component)
|
||||
opj_decompress -i @INPUT_NR_PATH@/issue979.j2k -o @TEMP_PATH@/issue979.j2k.pgx
|
||||
|
|
Loading…
Reference in New Issue