From d72940c56b542799024f3c304187386866052651 Mon Sep 17 00:00:00 2001 From: Antonin Descampe Date: Wed, 22 Oct 2014 13:16:12 +0000 Subject: [PATCH] [trunk] resets code-blocks reused for other tiles than the first one (fixes issue 418) --- src/lib/openjp2/tcd.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/lib/openjp2/tcd.c b/src/lib/openjp2/tcd.c index 7dd93e99..16d7d8f4 100644 --- a/src/lib/openjp2/tcd.c +++ b/src/lib/openjp2/tcd.c @@ -970,15 +970,14 @@ OPJ_BOOL FUNCTION ( opj_tcd_t *p_tcd, \ OPJ_INT32 cblkxend = cblkxstart + (1 << cblkwidthexpn); \ OPJ_INT32 cblkyend = cblkystart + (1 << cblkheightexpn); \ \ + if (! FUNCTION_ELEMENT(l_code_block)) { \ + return OPJ_FALSE; \ + } \ /* code-block size (global) */ \ l_code_block->x0 = opj_int_max(cblkxstart, l_current_precinct->x0); \ l_code_block->y0 = opj_int_max(cblkystart, l_current_precinct->y0); \ l_code_block->x1 = opj_int_min(cblkxend, l_current_precinct->x1); \ l_code_block->y1 = opj_int_min(cblkyend, l_current_precinct->y1); \ - \ - if (! FUNCTION_ELEMENT(l_code_block)) { \ - return OPJ_FALSE; \ - } \ ++l_code_block; \ } \ ++l_current_precinct; \ @@ -1054,9 +1053,19 @@ OPJ_BOOL opj_tcd_code_block_dec_allocate (opj_tcd_cblk_dec_t * p_code_block) p_code_block->m_current_max_segs = OPJ_J2K_DEFAULT_NB_SEGS; /*fprintf(stderr, "m_current_max_segs of code_block->data = %d\n", p_code_block->m_current_max_segs);*/ - } - /* TODO */ - /*p_code_block->numsegs = 0; */ + } else { + /* sanitize */ + OPJ_BYTE* l_data = p_code_block->data; + OPJ_UINT32 l_data_max_size = p_code_block->data_max_size; + opj_tcd_seg_t * l_segs = p_code_block->segs; + OPJ_UINT32 l_current_max_segs = p_code_block->m_current_max_segs; + + memset(p_code_block, 0, sizeof(opj_tcd_cblk_dec_t)); + p_code_block->data = l_data; + p_code_block->data_max_size = l_data_max_size; + p_code_block->segs = l_segs; + p_code_block->m_current_max_segs = l_current_max_segs; + } return OPJ_TRUE; }