Skip to content

Commit 50b66c1

Browse files
committed
Zero-initialize tile buffer regions of skipped code-blocks, so as to make Valgrind happy
1 parent b3f9c29 commit 50b66c1

File tree

1 file changed

+51
-8
lines changed

1 file changed

+51
-8
lines changed

src/lib/openjp2/t1.c

+51-8
Original file line numberDiff line numberDiff line change
@@ -1771,19 +1771,62 @@ void opj_t1_decode_cblks(opj_tcd_t* tcd,
17711771

17721772
for (precno = 0; precno < res->pw * res->ph; ++precno) {
17731773
opj_tcd_precinct_t* precinct = &band->precincts[precno];
1774+
OPJ_BOOL skip_precinct = OPJ_FALSE;
1775+
1776+
if (!opj_tcd_is_subband_area_of_interest(tcd,
1777+
tilec->compno,
1778+
resno,
1779+
band->bandno,
1780+
(OPJ_UINT32)precinct->x0,
1781+
(OPJ_UINT32)precinct->y0,
1782+
(OPJ_UINT32)precinct->x1,
1783+
(OPJ_UINT32)precinct->y1)) {
1784+
skip_precinct = OPJ_TRUE;
1785+
/* TODO: do a continue here once the below 0 initialization */
1786+
/* of tiledp is removed */
1787+
}
17741788

17751789
for (cblkno = 0; cblkno < precinct->cw * precinct->ch; ++cblkno) {
17761790
opj_tcd_cblk_dec_t* cblk = &precinct->cblks.dec[cblkno];
17771791
opj_t1_cblk_decode_processing_job_t* job;
17781792

1779-
if (!opj_tcd_is_subband_area_of_interest(tcd,
1780-
tilec->compno,
1781-
resno,
1782-
band->bandno,
1783-
(OPJ_UINT32)cblk->x0,
1784-
(OPJ_UINT32)cblk->y0,
1785-
(OPJ_UINT32)cblk->x1,
1786-
(OPJ_UINT32)cblk->y1)) {
1793+
if (skip_precinct ||
1794+
!opj_tcd_is_subband_area_of_interest(tcd,
1795+
tilec->compno,
1796+
resno,
1797+
band->bandno,
1798+
(OPJ_UINT32)cblk->x0,
1799+
(OPJ_UINT32)cblk->y0,
1800+
(OPJ_UINT32)cblk->x1,
1801+
(OPJ_UINT32)cblk->y1)) {
1802+
1803+
/* TODO: remove this once we don't iterate over */
1804+
/* tile pixels that are not in the subwindow of interest */
1805+
OPJ_UINT32 j, i;
1806+
OPJ_INT32 x = cblk->x0 - band->x0;
1807+
OPJ_INT32 y = cblk->y0 - band->y0;
1808+
OPJ_INT32* OPJ_RESTRICT tiledp;
1809+
OPJ_UINT32 tile_w = (OPJ_UINT32)(tilec->x1 - tilec->x0);
1810+
OPJ_UINT32 cblk_w = (OPJ_UINT32)(cblk->x1 - cblk->x0);
1811+
OPJ_UINT32 cblk_h = (OPJ_UINT32)(cblk->y1 - cblk->y0);
1812+
1813+
if (band->bandno & 1) {
1814+
opj_tcd_resolution_t* pres = &tilec->resolutions[resno - 1];
1815+
x += pres->x1 - pres->x0;
1816+
}
1817+
if (band->bandno & 2) {
1818+
opj_tcd_resolution_t* pres = &tilec->resolutions[resno - 1];
1819+
y += pres->y1 - pres->y0;
1820+
}
1821+
1822+
tiledp = &tilec->data[(OPJ_UINT32)y * tile_w +
1823+
(OPJ_UINT32)x];
1824+
1825+
for (j = 0; j < cblk_h; ++j) {
1826+
for (i = 0; i < cblk_w; ++i) {
1827+
((OPJ_INT32*)tiledp)[(j * tile_w) + i] = 0;
1828+
}
1829+
}
17871830
continue;
17881831
}
17891832

0 commit comments

Comments
 (0)