added support for partial bitstream decoding
This commit is contained in:
parent
99d555c0f1
commit
cf38618234
|
@ -4966,7 +4966,7 @@ static OPJ_BOOL opj_j2k_read_sod(opj_j2k_t *p_j2k,
|
||||||
opj_stream_get_number_byte_left(p_stream)) {
|
opj_stream_get_number_byte_left(p_stream)) {
|
||||||
opj_event_msg(p_manager, EVT_ERROR,
|
opj_event_msg(p_manager, EVT_ERROR,
|
||||||
"Tile part length size inconsistent with stream length\n");
|
"Tile part length size inconsistent with stream length\n");
|
||||||
return OPJ_FALSE;
|
//return OPJ_FALSE;
|
||||||
}
|
}
|
||||||
if (p_j2k->m_specific_param.m_decoder.m_sot_length >
|
if (p_j2k->m_specific_param.m_decoder.m_sot_length >
|
||||||
UINT_MAX - OPJ_COMMON_CBLK_DATA_EXTRA) {
|
UINT_MAX - OPJ_COMMON_CBLK_DATA_EXTRA) {
|
||||||
|
|
|
@ -502,7 +502,6 @@ OPJ_BOOL opj_t2_decode_packets(opj_tcd_t* tcd,
|
||||||
l_current_pi->precno, l_current_pi->layno, skip_packet ? "skipped" : "kept");
|
l_current_pi->precno, l_current_pi->layno, skip_packet ? "skipped" : "kept");
|
||||||
*/
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!skip_packet) {
|
if (!skip_packet) {
|
||||||
l_nb_bytes_read = 0;
|
l_nb_bytes_read = 0;
|
||||||
|
|
||||||
|
@ -1378,6 +1377,7 @@ static OPJ_BOOL opj_t2_read_packet_data(opj_t2_t* p_t2,
|
||||||
opj_tcd_cblk_dec_t* l_cblk = 00;
|
opj_tcd_cblk_dec_t* l_cblk = 00;
|
||||||
opj_tcd_resolution_t* l_res =
|
opj_tcd_resolution_t* l_res =
|
||||||
&p_tile->comps[p_pi->compno].resolutions[p_pi->resno];
|
&p_tile->comps[p_pi->compno].resolutions[p_pi->resno];
|
||||||
|
OPJ_UINT32 partial_buffer = 0;
|
||||||
|
|
||||||
OPJ_ARG_NOT_USED(p_t2);
|
OPJ_ARG_NOT_USED(p_t2);
|
||||||
OPJ_ARG_NOT_USED(pack_info);
|
OPJ_ARG_NOT_USED(pack_info);
|
||||||
|
@ -1397,6 +1397,12 @@ static OPJ_BOOL opj_t2_read_packet_data(opj_t2_t* p_t2,
|
||||||
for (cblkno = 0; cblkno < l_nb_code_blocks; ++cblkno) {
|
for (cblkno = 0; cblkno < l_nb_code_blocks; ++cblkno) {
|
||||||
opj_tcd_seg_t *l_seg = 00;
|
opj_tcd_seg_t *l_seg = 00;
|
||||||
|
|
||||||
|
// if we have a partial data stream, set numchunks to zero
|
||||||
|
// since we have no data to actually decode.
|
||||||
|
if(partial_buffer) {
|
||||||
|
l_cblk->numchunks = 0;
|
||||||
|
}
|
||||||
|
|
||||||
if (!l_cblk->numnewpasses) {
|
if (!l_cblk->numnewpasses) {
|
||||||
/* nothing to do */
|
/* nothing to do */
|
||||||
++l_cblk;
|
++l_cblk;
|
||||||
|
@ -1419,12 +1425,29 @@ static OPJ_BOOL opj_t2_read_packet_data(opj_t2_t* p_t2,
|
||||||
/* Check possible overflow (on l_current_data only, assumes input args already checked) then size */
|
/* Check possible overflow (on l_current_data only, assumes input args already checked) then size */
|
||||||
if ((((OPJ_SIZE_T)l_current_data + (OPJ_SIZE_T)l_seg->newlen) <
|
if ((((OPJ_SIZE_T)l_current_data + (OPJ_SIZE_T)l_seg->newlen) <
|
||||||
(OPJ_SIZE_T)l_current_data) ||
|
(OPJ_SIZE_T)l_current_data) ||
|
||||||
(l_current_data + l_seg->newlen > p_src_data + p_max_length)) {
|
(l_current_data + l_seg->newlen > p_src_data + p_max_length) ||
|
||||||
|
(partial_buffer)) {
|
||||||
opj_event_msg(p_manager, EVT_ERROR,
|
opj_event_msg(p_manager, EVT_ERROR,
|
||||||
"read: segment too long (%d) with max (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n",
|
"read: segment too long (%d) with max (%d) for codeblock %d (p=%d, b=%d, r=%d, c=%d)\n",
|
||||||
l_seg->newlen, p_max_length, cblkno, p_pi->precno, bandno, p_pi->resno,
|
l_seg->newlen, p_max_length, cblkno, p_pi->precno, bandno, p_pi->resno,
|
||||||
p_pi->compno);
|
p_pi->compno);
|
||||||
return OPJ_FALSE;
|
// NOTE - originall we would return OPJ_FALSE here when we encountered partial bitstream
|
||||||
|
//return OPJ_FALSE;
|
||||||
|
|
||||||
|
// skip this codeblock since it is a partial read
|
||||||
|
partial_buffer = 1;
|
||||||
|
l_cblk->numchunks = 0;
|
||||||
|
|
||||||
|
l_seg->numpasses += l_seg->numnewpasses;
|
||||||
|
l_cblk->numnewpasses -= l_seg->numnewpasses;
|
||||||
|
if (l_cblk->numnewpasses > 0) {
|
||||||
|
++l_seg;
|
||||||
|
++l_cblk->numsegs;
|
||||||
|
}
|
||||||
|
if(l_cblk->numnewpasses > 0) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef USE_JPWL
|
#ifdef USE_JPWL
|
||||||
|
@ -1486,8 +1509,12 @@ static OPJ_BOOL opj_t2_read_packet_data(opj_t2_t* p_t2,
|
||||||
++l_band;
|
++l_band;
|
||||||
}
|
}
|
||||||
|
|
||||||
*(p_data_read) = (OPJ_UINT32)(l_current_data - p_src_data);
|
// return the number of bytes read
|
||||||
|
if(partial_buffer) {
|
||||||
|
*(p_data_read) = p_max_length;
|
||||||
|
} else {
|
||||||
|
*(p_data_read) = (OPJ_UINT32)(l_current_data - p_src_data);
|
||||||
|
}
|
||||||
|
|
||||||
return OPJ_TRUE;
|
return OPJ_TRUE;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue