static OPJ_BOOL opj_j2k_write_first_tile_part(opj_j2k_t *p_j2k,
OPJ_BYTE * p_data,
OPJ_UINT32 * p_data_written,
- OPJ_UINT32 p_total_data_size,
+ OPJ_UINT32 total_data_size,
opj_stream_private_t *p_stream,
struct opj_event_mgr * p_manager);
static OPJ_BOOL opj_j2k_write_all_tile_parts(opj_j2k_t *p_j2k,
OPJ_BYTE * p_data,
OPJ_UINT32 * p_data_written,
- OPJ_UINT32 p_total_data_size,
+ OPJ_UINT32 total_data_size,
opj_stream_private_t *p_stream,
struct opj_event_mgr * p_manager);
*
* @param p_j2k J2K codec.
* @param p_data Output buffer
- * @param p_total_data_size Output buffer size
+ * @param total_data_size Output buffer size
* @param p_data_written Number of bytes written into stream
* @param p_stream the stream to write data to.
* @param p_manager the user event manager.
*/
static OPJ_BOOL opj_j2k_write_sot(opj_j2k_t *p_j2k,
OPJ_BYTE * p_data,
- OPJ_UINT32 p_total_data_size,
+ OPJ_UINT32 total_data_size,
OPJ_UINT32 * p_data_written,
const opj_stream_private_t *p_stream,
opj_event_mgr_t * p_manager);
* @param p_tile_coder FIXME DOC
* @param p_data FIXME DOC
* @param p_data_written FIXME DOC
- * @param p_total_data_size FIXME DOC
+ * @param total_data_size FIXME DOC
* @param p_stream the stream to write data to.
* @param p_manager the user event manager.
*/
opj_tcd_t * p_tile_coder,
OPJ_BYTE * p_data,
OPJ_UINT32 * p_data_written,
- OPJ_UINT32 p_total_data_size,
+ OPJ_UINT32 total_data_size,
const opj_stream_private_t *p_stream,
opj_event_mgr_t * p_manager);
* A nice message is outputted at errors.
*
* @param p_pocs the progression order changes.
+ * @param tileno the tile number of interest
* @param p_nb_pocs the number of progression order changes.
* @param p_nb_resolutions the number of resolutions.
* @param numcomps the number of components
* @return true if the pocs are valid.
*/
static OPJ_BOOL opj_j2k_check_poc_val(const opj_poc_t *p_pocs,
+ OPJ_UINT32 tileno,
OPJ_UINT32 p_nb_pocs,
OPJ_UINT32 p_nb_resolutions,
OPJ_UINT32 numcomps,
}
static OPJ_BOOL opj_j2k_check_poc_val(const opj_poc_t *p_pocs,
+ OPJ_UINT32 tileno,
OPJ_UINT32 p_nb_pocs,
OPJ_UINT32 p_nb_resolutions,
OPJ_UINT32 p_num_comps,
OPJ_UINT32 step_r = p_num_comps * step_c;
OPJ_UINT32 step_l = p_nb_resolutions * step_r;
OPJ_BOOL loss = OPJ_FALSE;
- OPJ_UINT32 layno0 = 0;
+
+ assert(p_nb_pocs > 0);
packet_array = (OPJ_UINT32*) opj_calloc(step_l * p_num_layers,
sizeof(OPJ_UINT32));
return OPJ_FALSE;
}
- if (p_nb_pocs == 0) {
- opj_free(packet_array);
- return OPJ_TRUE;
- }
-
- index = step_r * p_pocs->resno0;
- /* take each resolution for each poc */
- for (resno = p_pocs->resno0 ; resno < p_pocs->resno1 ; ++resno) {
- OPJ_UINT32 res_index = index + p_pocs->compno0 * step_c;
+ /* iterate through all the pocs that match our tile of interest. */
+ for (i = 0; i < p_nb_pocs; ++i) {
+ const opj_poc_t *poc = &p_pocs[i];
+ if (tileno + 1 == poc->tile) {
+ index = step_r * poc->resno0;
- /* take each comp of each resolution for each poc */
- for (compno = p_pocs->compno0 ; compno < p_pocs->compno1 ; ++compno) {
- OPJ_UINT32 comp_index = res_index + layno0 * step_l;
+ /* take each resolution for each poc */
+ for (resno = poc->resno0 ;
+ resno < opj_uint_min(poc->resno1, p_nb_resolutions); ++resno) {
+ OPJ_UINT32 res_index = index + poc->compno0 * step_c;
- /* and finally take each layer of each res of ... */
- for (layno = layno0; layno < p_pocs->layno1 ; ++layno) {
- /*index = step_r * resno + step_c * compno + step_l * layno;*/
- packet_array[comp_index] = 1;
- comp_index += step_l;
- }
-
- res_index += step_c;
- }
+ /* take each comp of each resolution for each poc */
+ for (compno = poc->compno0 ;
+ compno < opj_uint_min(poc->compno1, p_num_comps); ++compno) {
+ /* The layer index always starts at zero for every progression. */
+ const OPJ_UINT32 layno0 = 0;
+ OPJ_UINT32 comp_index = res_index + layno0 * step_l;
- index += step_r;
- }
- ++p_pocs;
-
- /* iterate through all the pocs */
- for (i = 1; i < p_nb_pocs ; ++i) {
- OPJ_UINT32 l_last_layno1 = (p_pocs - 1)->layno1 ;
-
- layno0 = (p_pocs->layno1 > l_last_layno1) ? l_last_layno1 : 0;
- index = step_r * p_pocs->resno0;
-
- /* take each resolution for each poc */
- for (resno = p_pocs->resno0 ; resno < p_pocs->resno1 ; ++resno) {
- OPJ_UINT32 res_index = index + p_pocs->compno0 * step_c;
-
- /* take each comp of each resolution for each poc */
- for (compno = p_pocs->compno0 ; compno < p_pocs->compno1 ; ++compno) {
- OPJ_UINT32 comp_index = res_index + layno0 * step_l;
+ /* and finally take each layer of each res of ... */
+ for (layno = layno0; layno < opj_uint_min(poc->layno1, p_num_layers);
+ ++layno) {
+ packet_array[comp_index] = 1;
+ comp_index += step_l;
+ }
- /* and finally take each layer of each res of ... */
- for (layno = layno0; layno < p_pocs->layno1 ; ++layno) {
- /*index = step_r * resno + step_c * compno + step_l * layno;*/
- packet_array[comp_index] = 1;
- comp_index += step_l;
+ res_index += step_c;
}
- res_index += step_c;
+ index += step_r;
}
-
- index += step_r;
}
-
- ++p_pocs;
}
index = 0;
for (resno = 0; resno < p_nb_resolutions; ++resno) {
for (compno = 0; compno < p_num_comps; ++compno) {
loss |= (packet_array[index] != 1);
- /*index = step_r * resno + step_c * compno + step_l * layno;*/
+#ifdef DEBUG_VERBOSE
+ if (packet_array[index] != 1) {
+ fprintf(stderr,
+ "Missing packet in POC: layno=%d resno=%d compno=%d\n",
+ layno, resno, compno);
+ }
+#endif
index += step_c;
}
}
/* FIXME move it in a index structure included in p_j2k*/
p_j2k->cstr_index->main_head_start = opj_stream_tell(p_stream) - 2;
- opj_event_msg(p_manager, EVT_INFO, "Start to read j2k main header (%d).\n",
+ opj_event_msg(p_manager, EVT_INFO,
+ "Start to read j2k main header (%" PRId64 ").\n",
p_j2k->cstr_index->main_head_start);
/* Add the marker to the codestream index*/
opj_read_bytes(p_header_data, &l_tcp->mct, 1); /* SGcod (C) */
++p_header_data;
+ if (l_tcp->mct > 1) {
+ opj_event_msg(p_manager, EVT_ERROR,
+ "Invalid multiple component transformation\n");
+ return OPJ_FALSE;
+ }
+
p_header_size -= 5;
for (i = 0; i < l_image->numcomps; ++i) {
l_tcp->tccps[i].csty = l_tcp->csty & J2K_CCP_CSTY_PRT;
static OPJ_BOOL opj_j2k_write_sot(opj_j2k_t *p_j2k,
OPJ_BYTE * p_data,
- OPJ_UINT32 p_total_data_size,
+ OPJ_UINT32 total_data_size,
OPJ_UINT32 * p_data_written,
const opj_stream_private_t *p_stream,
opj_event_mgr_t * p_manager
OPJ_UNUSED(p_stream);
- if (p_total_data_size < 12) {
+ if (total_data_size < 12) {
opj_event_msg(p_manager, EVT_ERROR,
"Not enough bytes in output buffer to write SOT marker\n");
return OPJ_FALSE;
opj_tcd_t * p_tile_coder,
OPJ_BYTE * p_data,
OPJ_UINT32 * p_data_written,
- OPJ_UINT32 p_total_data_size,
+ OPJ_UINT32 total_data_size,
const opj_stream_private_t *p_stream,
opj_event_mgr_t * p_manager
)
OPJ_UNUSED(p_stream);
- if (p_total_data_size < 4) {
+ if (total_data_size < 4) {
opj_event_msg(p_manager, EVT_ERROR,
"Not enough bytes in output buffer to write SOD marker\n");
return OPJ_FALSE;
p_data += 2;
/* make room for the EOF marker */
- l_remaining_data = p_total_data_size - 4;
+ l_remaining_data = total_data_size - 4;
/* update tile coder */
p_tile_coder->tp_num =
"Not enough memory to allocate tile coding parameters\n");
return OPJ_FALSE;
}
- if (parameters->numpocs) {
- /* initialisation of POC */
- opj_j2k_check_poc_val(parameters->POC, parameters->numpocs,
- (OPJ_UINT32)parameters->numresolution, image->numcomps,
- (OPJ_UINT32)parameters->tcp_numlayers, p_manager);
- /* TODO MSD use the return value*/
- }
for (tileno = 0; tileno < cp->tw * cp->th; tileno++) {
opj_tcp_t *tcp = &cp->tcps[tileno];
if (parameters->numpocs) {
/* initialisation of POC */
- tcp->POC = 1;
for (i = 0; i < parameters->numpocs; i++) {
if (tileno + 1 == parameters->POC[i].tile) {
opj_poc_t *tcp_poc = &tcp->pocs[numpocs_tile];
}
}
- tcp->numpocs = numpocs_tile - 1 ;
+ if (numpocs_tile) {
+
+ /* TODO MSD use the return value*/
+ opj_j2k_check_poc_val(parameters->POC, tileno, parameters->numpocs,
+ (OPJ_UINT32)parameters->numresolution, image->numcomps,
+ (OPJ_UINT32)parameters->tcp_numlayers, p_manager);
+
+ tcp->POC = 1;
+ tcp->numpocs = numpocs_tile - 1 ;
+ }
} else {
tcp->numpocs = 0;
}
return OPJ_FALSE;
}
- opj_read_bytes(l_current_ptr, &l_tccp->numresolutions,
- 1); /* SPcox (D) */
- ++l_tccp->numresolutions; /* tccp->numresolutions = read() + 1 */
+ /* SPcod (D) / SPcoc (A) */
+ opj_read_bytes(l_current_ptr, &l_tccp->numresolutions, 1);
+ ++l_tccp->numresolutions; /* tccp->numresolutions = read() + 1 */
if (l_tccp->numresolutions > OPJ_J2K_MAXRLVLS) {
opj_event_msg(p_manager, EVT_ERROR,
"Invalid value for numresolutions : %d, max value is set in openjpeg.h at %d\n",
return OPJ_FALSE;
}
- opj_read_bytes(l_current_ptr, &l_tccp->cblkw, 1); /* SPcoc (E) */
+ /* SPcod (E) / SPcoc (B) */
+ opj_read_bytes(l_current_ptr, &l_tccp->cblkw, 1);
++l_current_ptr;
l_tccp->cblkw += 2;
- opj_read_bytes(l_current_ptr, &l_tccp->cblkh, 1); /* SPcoc (F) */
+ /* SPcod (F) / SPcoc (C) */
+ opj_read_bytes(l_current_ptr, &l_tccp->cblkh, 1);
++l_current_ptr;
l_tccp->cblkh += 2;
return OPJ_FALSE;
}
-
- opj_read_bytes(l_current_ptr, &l_tccp->cblksty, 1); /* SPcoc (G) */
+ /* SPcod (G) / SPcoc (D) */
+ opj_read_bytes(l_current_ptr, &l_tccp->cblksty, 1);
++l_current_ptr;
if (l_tccp->cblksty & 0xC0U) { /* 2 msb are reserved, assume we can't read */
opj_event_msg(p_manager, EVT_ERROR,
return OPJ_FALSE;
}
- opj_read_bytes(l_current_ptr, &l_tccp->qmfbid, 1); /* SPcoc (H) */
+ /* SPcod (H) / SPcoc (E) */
+ opj_read_bytes(l_current_ptr, &l_tccp->qmfbid, 1);
++l_current_ptr;
+ if (l_tccp->qmfbid > 1) {
+ opj_event_msg(p_manager, EVT_ERROR,
+ "Error reading SPCod SPCoc element, Invalid transformation found\n");
+ return OPJ_FALSE;
+ }
+
*p_header_size = *p_header_size - 5;
/* use custom precinct size ? */
return OPJ_FALSE;
}
+ /* SPcod (I_i) / SPcoc (F_i) */
for (i = 0; i < l_tccp->numresolutions; ++i) {
- opj_read_bytes(l_current_ptr, &l_tmp, 1); /* SPcoc (I_i) */
+ opj_read_bytes(l_current_ptr, &l_tmp, 1);
++l_current_ptr;
/* Precinct exponent 0 is only allowed for lowest resolution level (Table A.21) */
if ((i != 0) && (((l_tmp & 0xf) == 0) || ((l_tmp >> 4) == 0))) {
return OPJ_TRUE;
}
+static OPJ_BOOL opj_j2k_are_all_used_components_decoded(opj_j2k_t *p_j2k,
+ opj_event_mgr_t * p_manager)
+{
+ OPJ_UINT32 compno;
+ OPJ_BOOL decoded_all_used_components = OPJ_TRUE;
+
+ 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;
+}
+
+
static OPJ_BOOL opj_j2k_decode_tiles(opj_j2k_t *p_j2k,
opj_stream_private_t *p_stream,
opj_event_mgr_t * p_manager)
}
}
+ if (! opj_j2k_are_all_used_components_decoded(p_j2k, p_manager)) {
+ return OPJ_FALSE;
+ }
+
return OPJ_TRUE;
}
}
+ if (! opj_j2k_are_all_used_components_decoded(p_j2k, p_manager)) {
+ return OPJ_FALSE;
+ }
+
return OPJ_TRUE;
}
static OPJ_BOOL opj_j2k_write_first_tile_part(opj_j2k_t *p_j2k,
OPJ_BYTE * p_data,
OPJ_UINT32 * p_data_written,
- OPJ_UINT32 p_total_data_size,
+ OPJ_UINT32 total_data_size,
opj_stream_private_t *p_stream,
struct opj_event_mgr * p_manager)
{
l_current_nb_bytes_written = 0;
l_begin_data = p_data;
- if (! opj_j2k_write_sot(p_j2k, p_data, p_total_data_size,
+ if (! opj_j2k_write_sot(p_j2k, p_data, total_data_size,
&l_current_nb_bytes_written, p_stream,
p_manager)) {
return OPJ_FALSE;
l_nb_bytes_written += l_current_nb_bytes_written;
p_data += l_current_nb_bytes_written;
- p_total_data_size -= l_current_nb_bytes_written;
+ total_data_size -= l_current_nb_bytes_written;
if (!OPJ_IS_CINEMA(l_cp->rsiz)) {
#if 0
p_manager);
l_nb_bytes_written += l_current_nb_bytes_written;
p_data += l_current_nb_bytes_written;
- p_total_data_size -= l_current_nb_bytes_written;
+ total_data_size -= l_current_nb_bytes_written;
l_current_nb_bytes_written = 0;
opj_j2k_write_qcc_in_memory(p_j2k, compno, p_data, &l_current_nb_bytes_written,
p_manager);
l_nb_bytes_written += l_current_nb_bytes_written;
p_data += l_current_nb_bytes_written;
- p_total_data_size -= l_current_nb_bytes_written;
+ total_data_size -= l_current_nb_bytes_written;
}
#endif
- if (l_cp->tcps[p_j2k->m_current_tile_number].numpocs) {
+ if (l_cp->tcps[p_j2k->m_current_tile_number].POC) {
l_current_nb_bytes_written = 0;
opj_j2k_write_poc_in_memory(p_j2k, p_data, &l_current_nb_bytes_written,
p_manager);
l_nb_bytes_written += l_current_nb_bytes_written;
p_data += l_current_nb_bytes_written;
- p_total_data_size -= l_current_nb_bytes_written;
+ total_data_size -= l_current_nb_bytes_written;
}
}
l_current_nb_bytes_written = 0;
if (! opj_j2k_write_sod(p_j2k, l_tcd, p_data, &l_current_nb_bytes_written,
- p_total_data_size, p_stream, p_manager)) {
+ total_data_size, p_stream, p_manager)) {
return OPJ_FALSE;
}
static OPJ_BOOL opj_j2k_write_all_tile_parts(opj_j2k_t *p_j2k,
OPJ_BYTE * p_data,
OPJ_UINT32 * p_data_written,
- OPJ_UINT32 p_total_data_size,
+ OPJ_UINT32 total_data_size,
opj_stream_private_t *p_stream,
struct opj_event_mgr * p_manager
)
l_begin_data = p_data;
if (! opj_j2k_write_sot(p_j2k, p_data,
- p_total_data_size,
+ total_data_size,
&l_current_nb_bytes_written,
p_stream,
p_manager)) {
l_nb_bytes_written += l_current_nb_bytes_written;
p_data += l_current_nb_bytes_written;
- p_total_data_size -= l_current_nb_bytes_written;
+ total_data_size -= l_current_nb_bytes_written;
l_part_tile_size += l_current_nb_bytes_written;
l_current_nb_bytes_written = 0;
if (! opj_j2k_write_sod(p_j2k, l_tcd, p_data, &l_current_nb_bytes_written,
- p_total_data_size, p_stream, p_manager)) {
+ total_data_size, p_stream, p_manager)) {
return OPJ_FALSE;
}
p_data += l_current_nb_bytes_written;
l_nb_bytes_written += l_current_nb_bytes_written;
- p_total_data_size -= l_current_nb_bytes_written;
+ total_data_size -= l_current_nb_bytes_written;
l_part_tile_size += l_current_nb_bytes_written;
/* Writing Psot in SOT marker */
l_begin_data = p_data;
if (! opj_j2k_write_sot(p_j2k, p_data,
- p_total_data_size,
+ total_data_size,
&l_current_nb_bytes_written, p_stream,
p_manager)) {
return OPJ_FALSE;
l_nb_bytes_written += l_current_nb_bytes_written;
p_data += l_current_nb_bytes_written;
- p_total_data_size -= l_current_nb_bytes_written;
+ total_data_size -= l_current_nb_bytes_written;
l_part_tile_size += l_current_nb_bytes_written;
l_current_nb_bytes_written = 0;
if (! opj_j2k_write_sod(p_j2k, l_tcd, p_data, &l_current_nb_bytes_written,
- p_total_data_size, p_stream, p_manager)) {
+ total_data_size, p_stream, p_manager)) {
return OPJ_FALSE;
}
l_nb_bytes_written += l_current_nb_bytes_written;
p_data += l_current_nb_bytes_written;
- p_total_data_size -= l_current_nb_bytes_written;
+ total_data_size -= l_current_nb_bytes_written;
l_part_tile_size += l_current_nb_bytes_written;
/* Writing Psot in SOT marker */