opj_codestream_index_t *p_cstr_index,
opj_event_mgr_t *p_manager);
-static OPJ_BOOL opj_tcd_t1_decode(opj_tcd_t *p_tcd);
+static OPJ_BOOL opj_tcd_t1_decode(opj_tcd_t *p_tcd,
+ opj_event_mgr_t *p_manager);
static OPJ_BOOL opj_tcd_dwt_decode(opj_tcd_t *p_tcd);
for (bandno = 0; bandno < res->numbands; bandno++) {
opj_tcd_band_t *band = &res->bands[bandno];
+ /* Skip empty bands */
+ if (opj_tcd_is_band_empty(band)) {
+ continue;
+ }
+
for (precno = 0; precno < res->pw * res->ph; precno++) {
opj_tcd_precinct_t *prc = &band->precincts[precno];
for (bandno = 0; bandno < res->numbands; bandno++) {
opj_tcd_band_t *band = &res->bands[bandno];
+ /* Skip empty bands */
+ if (opj_tcd_is_band_empty(band)) {
+ continue;
+ }
+
for (precno = 0; precno < res->pw * res->ph; precno++) {
opj_tcd_precinct_t *prc = &band->precincts[precno];
for (bandno = 0; bandno < res->numbands; bandno++) {
opj_tcd_band_t *band = &res->bands[bandno];
+ /* Skip empty bands */
+ if (opj_tcd_is_band_empty(band)) {
+ continue;
+ }
+
for (precno = 0; precno < res->pw * res->ph; precno++) {
opj_tcd_precinct_t *prc = &band->precincts[precno];
cblkheightexpn = opj_uint_min(l_tccp->cblkh, cbgheightexpn);
l_band = l_res->bands;
- for (bandno = 0; bandno < l_res->numbands; ++bandno) {
+ for (bandno = 0; bandno < l_res->numbands; ++bandno, ++l_band, ++l_step_size) {
OPJ_INT32 numbps;
/*fprintf(stderr, "\t\t\tband_no=%d/%d\n", bandno, l_res->numbands );*/
l_level_no), (OPJ_INT32)(l_level_no + 1));
}
+ if (isEncoder) {
+ /* Skip empty bands */
+ if (opj_tcd_is_band_empty(l_band)) {
+ /* Do not zero l_band->precints to avoid leaks */
+ /* but make sure we don't use it later, since */
+ /* it will point to precincts of previous bands... */
+ continue;
+ }
+ }
+
/** avoid an if with storing function pointer */
l_gain = (*l_gain_ptr)(l_band->bandno);
numbps = (OPJ_INT32)(l_image_comp->prec + l_gain);
}
++l_current_precinct;
} /* precno */
- ++l_band;
- ++l_step_size;
} /* bandno */
++l_res;
} /* resno */
if (l_data_size > p_code_block->data_size) {
if (p_code_block->data) {
- opj_free(p_code_block->data - 1); /* again, why -1 */
+ /* We refer to data - 1 since below we incremented it */
+ opj_free(p_code_block->data - 1);
}
p_code_block->data = (OPJ_BYTE*) opj_malloc(l_data_size + 1);
if (! p_code_block->data) {
}
p_code_block->data_size = l_data_size;
+ /* We reserve the initial byte as a fake byte to a non-FF value */
+ /* and increment the data pointer, so that opj_mqc_init_enc() */
+ /* can do bp = data - 1, and opj_mqc_byteout() can safely dereference */
+ /* it. */
p_code_block->data[0] = 0;
p_code_block->data += 1; /*why +1 ?*/
}
/*------------------TIER1-----------------*/
/* FIXME _ProfStart(PGROUP_T1); */
- if
- (! opj_tcd_t1_decode(p_tcd)) {
+ if (! opj_tcd_t1_decode(p_tcd, p_manager)) {
return OPJ_FALSE;
}
/* FIXME _ProfStop(PGROUP_T1); */
return OPJ_TRUE;
}
-static OPJ_BOOL opj_tcd_t1_decode(opj_tcd_t *p_tcd)
+static OPJ_BOOL opj_tcd_t1_decode(opj_tcd_t *p_tcd, opj_event_mgr_t *p_manager)
{
OPJ_UINT32 compno;
opj_tcd_tile_t * l_tile = p_tcd->tcd_image->tiles;
opj_tcd_tilecomp_t* l_tile_comp = l_tile->comps;
opj_tccp_t * l_tccp = p_tcd->tcp->tccps;
volatile OPJ_BOOL ret = OPJ_TRUE;
+ OPJ_BOOL check_pterm = OPJ_FALSE;
+ opj_mutex_t* p_manager_mutex = NULL;
+
+ p_manager_mutex = opj_mutex_create();
+
+ /* Only enable PTERM check if we decode all layers */
+ if (p_tcd->tcp->num_layers_to_decode == p_tcd->tcp->numlayers &&
+ (l_tccp->cblksty & J2K_CCP_CBLKSTY_PTERM) != 0) {
+ check_pterm = OPJ_TRUE;
+ }
for (compno = 0; compno < l_tile->numcomps; ++compno) {
- opj_t1_decode_cblks(p_tcd->thread_pool, &ret, l_tile_comp, l_tccp);
+ opj_t1_decode_cblks(p_tcd->thread_pool, &ret, l_tile_comp, l_tccp,
+ p_manager, p_manager_mutex, check_pterm);
if (!ret) {
break;
}
}
opj_thread_pool_wait_completion(p_tcd->thread_pool, 0);
-
+ if (p_manager_mutex) {
+ opj_mutex_destroy(p_manager_mutex);
+ }
return ret;
}
for (cblkno = 0; cblkno < l_nb_code_blocks; ++cblkno) {
if (l_code_block->data) {
+ /* We refer to data - 1 since below we incremented it */
+ /* in opj_tcd_code_block_enc_allocate_data() */
opj_free(l_code_block->data - 1);
l_code_block->data = 00;
}
return OPJ_TRUE;
}
+
+OPJ_BOOL opj_tcd_is_band_empty(opj_tcd_band_t* band)
+{
+ return (band->x1 - band->x0 == 0) || (band->y1 - band->y0 == 0);
+}