opj_event_mgr_t * p_manager);
/**
- * Reads a COD marker (Coding Styke defaults)
+ * Reads a COD marker (Coding style defaults)
* @param p_header_data the data contained in the COD box.
* @param p_j2k the jpeg2000 codec.
* @param p_header_size the size of the data contained in the COD marker.
/* 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*/
}
/**
- * Reads a COD marker (Coding Styke defaults)
+ * Reads a COD marker (Coding style defaults)
* @param p_header_data the data contained in the COD box.
* @param p_j2k the jpeg2000 codec.
* @param p_header_size the size of the data contained in the COD marker.
&l_cp->tcps[p_j2k->m_current_tile_number] :
p_j2k->m_specific_param.m_decoder.m_default_tcp;
+#if 0
+ /* This check was added per https://github.com/uclouvain/openjpeg/commit/daed8cc9195555e101ab708a501af2dfe6d5e001 */
+ /* but this is no longer necessary to handle issue476.jp2 */
+ /* and this actually cause issues on legit files. See https://github.com/uclouvain/openjpeg/issues/1043 */
/* Only one COD per tile */
if (l_tcp->cod) {
opj_event_msg(p_manager, EVT_ERROR,
"COD marker already read. No more than one COD marker per tile.\n");
return OPJ_FALSE;
}
+#endif
l_tcp->cod = 1;
/* Make sure room is sufficient */
l_old_poc_nb = l_tcp->POC ? l_tcp->numpocs + 1 : 0;
l_current_poc_nb += l_old_poc_nb;
- if (l_current_poc_nb >= 32) {
+ if (l_current_poc_nb >= J2K_MAX_POCS) {
opj_event_msg(p_manager, EVT_ERROR, "Too many POCs %d\n", l_current_poc_nb);
return OPJ_FALSE;
}
- assert(l_current_poc_nb < 32);
/* now poc is in use.*/
l_tcp->POC = 1;
/* preconditions */
assert(p_tcp != 00);
assert(p_manager != 00);
- assert(p_tcp->ppt_buffer == NULL);
+
+ if (p_tcp->ppt_buffer != NULL) {
+ opj_event_msg(p_manager, EVT_ERROR,
+ "opj_j2k_merge_ppt() has already been called\n");
+ return OPJ_FALSE;
+ }
if (p_tcp->ppt == 0U) {
return OPJ_TRUE;
if (p_j2k->m_specific_param.m_encoder.m_current_tile_part_number == 0) {
p_tile_coder->tcd_image->tiles->packno = 0;
+#ifdef deadcode
if (l_cstr_info) {
l_cstr_info->packno = 0;
}
+#endif
}
*p_data_written = 0;
OPJ_BOOL opj_j2k_set_threads(opj_j2k_t *j2k, OPJ_UINT32 num_threads)
{
- if (opj_has_thread_support()) {
+ /* Currently we pass the thread-pool to the tcd, so we cannot re-set it */
+ /* afterwards */
+ if (opj_has_thread_support() && j2k->m_tcd == NULL) {
opj_thread_pool_destroy(j2k->m_tp);
j2k->m_tp = NULL;
if (num_threads <= (OPJ_UINT32)INT_MAX) {
static int opj_j2k_get_default_thread_count()
{
- const char* num_threads = getenv("OPJ_NUM_THREADS");
- if (num_threads == NULL || !opj_has_thread_support()) {
+ const char* num_threads_str = getenv("OPJ_NUM_THREADS");
+ int num_cpus;
+ int num_threads;
+
+ if (num_threads_str == NULL || !opj_has_thread_support()) {
return 0;
}
- if (strcmp(num_threads, "ALL_CPUS") == 0) {
- return opj_get_num_cpus();
+ num_cpus = opj_get_num_cpus();
+ if (strcmp(num_threads_str, "ALL_CPUS") == 0) {
+ return num_cpus;
}
- return atoi(num_threads);
+ if (num_cpus == 0) {
+ num_cpus = 32;
+ }
+ num_threads = atoi(num_threads_str);
+ if (num_threads < 0) {
+ num_threads = 0;
+ } else if (num_threads > 2 * num_cpus) {
+ num_threads = 2 * num_cpus;
+ }
+ return num_threads;
}
/* ----------------------------------------------------------------------- */
break;
}
- if ((l_tot_len == 0U) || (l_tot_len < 14U)) {
+ if (l_tot_len < 14U) {
/* last SOT until EOC or invalid Psot value */
/* assume all is OK */
if (! opj_stream_seek(p_stream, l_stream_pos_backup, p_manager)) {
/* Current marker is the EOC marker ?*/
if (l_current_marker == J2K_MS_EOC) {
- p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_EOC;
+ if (p_j2k->m_specific_param.m_decoder.m_state != J2K_STATE_EOC) {
+ p_j2k->m_current_tile_number = 0;
+ p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_EOC;
+ }
}
/* FIXME DOC ???*/
}
/* Up */
- if (p_start_x < 0) {
+ if (p_start_y < 0) {
opj_event_msg(p_manager, EVT_ERROR,
"Up position of the decoded area (region_y0=%d) should be >= 0.\n",
p_start_y);
l_current_data = l_new_current_data;
l_max_tile_size = l_current_tile_size;
}
+ if (l_current_data == NULL) {
+ /* Should not happen in practice, but will avoid Coverity to */
+ /* complain about a null pointer dereference */
+ assert(0);
+ return OPJ_FALSE;
+ }
/* copy image data (32 bit) to l_current_data as contiguous, all-component, zero offset buffer */
/* 32 bit components @ 8 bit precision get converted to 8 bit */