From 8d320bbdf88edc09628d532bee6f6b975317a961 Mon Sep 17 00:00:00 2001 From: Antonin Descampe Date: Tue, 9 Dec 2014 12:09:08 +0000 Subject: [PATCH] [trunk] check number of components when getting mct norm (fixes issue 436) --- src/lib/openjp2/j2k.c | 2 +- src/lib/openjp2/t1.c | 24 +++++++++++++++--------- src/lib/openjp2/t1.h | 4 +++- src/lib/openjp2/tcd.c | 5 ++++- 4 files changed, 23 insertions(+), 12 deletions(-) diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index c93b558f..ff00d7c4 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -6571,7 +6571,7 @@ OPJ_BOOL opj_j2k_setup_encoder( opj_j2k_t *p_j2k, } } else { - if(tcp->mct==1 && image->numcomps == 3) { /* RGB->YCC MCT is enabled */ + if(tcp->mct==1 && image->numcomps >= 3) { /* RGB->YCC MCT is enabled */ if ((image->comps[0].dx != image->comps[1].dx) || (image->comps[0].dx != image->comps[2].dx) || (image->comps[0].dy != image->comps[1].dy) || diff --git a/src/lib/openjp2/t1.c b/src/lib/openjp2/t1.c index 11b72a33..e61cd3c9 100644 --- a/src/lib/openjp2/t1.c +++ b/src/lib/openjp2/t1.c @@ -265,7 +265,8 @@ static OPJ_FLOAT64 opj_t1_getwmsedec( OPJ_UINT32 qmfbid, OPJ_FLOAT64 stepsize, OPJ_UINT32 numcomps, - const OPJ_FLOAT64 * mct_norms); + const OPJ_FLOAT64 * mct_norms, + OPJ_UINT32 mct_numcomps); static void opj_t1_encode_cblk( opj_t1_t *t1, opj_tcd_cblk_enc_t* cblk, @@ -277,7 +278,8 @@ static void opj_t1_encode_cblk( opj_t1_t *t1, OPJ_UINT32 cblksty, OPJ_UINT32 numcomps, opj_tcd_tile_t * tile, - const OPJ_FLOAT64 * mct_norms); + const OPJ_FLOAT64 * mct_norms, + OPJ_UINT32 mct_numcomps); /** Decode 1 code-block @@ -1137,12 +1139,13 @@ static OPJ_FLOAT64 opj_t1_getwmsedec( OPJ_UINT32 qmfbid, OPJ_FLOAT64 stepsize, OPJ_UINT32 numcomps, - const OPJ_FLOAT64 * mct_norms) + const OPJ_FLOAT64 * mct_norms, + OPJ_UINT32 mct_numcomps) { OPJ_FLOAT64 w1 = 1, w2, wmsedec; - OPJ_ARG_NOT_USED(numcomps); + OPJ_ARG_NOT_USED(numcomps); - if (mct_norms) { + if (mct_norms && (compno < mct_numcomps)) { w1 = mct_norms[compno]; } @@ -1462,7 +1465,8 @@ OPJ_BOOL opj_t1_decode_cblk(opj_t1_t *t1, OPJ_BOOL opj_t1_encode_cblks( opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp, - const OPJ_FLOAT64 * mct_norms + const OPJ_FLOAT64 * mct_norms, + OPJ_UINT32 mct_numcomps ) { OPJ_UINT32 compno, resno, bandno, precno, cblkno; @@ -1550,7 +1554,8 @@ OPJ_BOOL opj_t1_encode_cblks( opj_t1_t *t1, tccp->cblksty, tile->numcomps, tile, - mct_norms); + mct_norms, + mct_numcomps); } /* cblkno */ } /* precno */ @@ -1571,7 +1576,8 @@ void opj_t1_encode_cblk(opj_t1_t *t1, OPJ_UINT32 cblksty, OPJ_UINT32 numcomps, opj_tcd_tile_t * tile, - const OPJ_FLOAT64 * mct_norms) + const OPJ_FLOAT64 * mct_norms, + OPJ_UINT32 mct_numcomps) { OPJ_FLOAT64 cumwmsedec = 0.0; @@ -1626,7 +1632,7 @@ void opj_t1_encode_cblk(opj_t1_t *t1, } /* fixed_quality */ - tempwmsedec = opj_t1_getwmsedec(nmsedec, compno, level, orient, bpno, qmfbid, stepsize, numcomps,mct_norms) ; + tempwmsedec = opj_t1_getwmsedec(nmsedec, compno, level, orient, bpno, qmfbid, stepsize, numcomps,mct_norms, mct_numcomps) ; cumwmsedec += tempwmsedec; tile->distotile += tempwmsedec; diff --git a/src/lib/openjp2/t1.h b/src/lib/openjp2/t1.h index e1d41ed5..3bc0ad9e 100644 --- a/src/lib/openjp2/t1.h +++ b/src/lib/openjp2/t1.h @@ -126,11 +126,13 @@ Encode the code-blocks of a tile @param tile The tile to encode @param tcp Tile coding parameters @param mct_norms FIXME DOC +@param mct_numcomps Number of components used for MCT */ OPJ_BOOL opj_t1_encode_cblks( opj_t1_t *t1, opj_tcd_tile_t *tile, opj_tcp_t *tcp, - const OPJ_FLOAT64 * mct_norms); + const OPJ_FLOAT64 * mct_norms, + OPJ_UINT32 mct_numcomps); /** Decode the code-blocks of a tile diff --git a/src/lib/openjp2/tcd.c b/src/lib/openjp2/tcd.c index 31e05997..83b02c08 100644 --- a/src/lib/openjp2/tcd.c +++ b/src/lib/openjp2/tcd.c @@ -1989,6 +1989,7 @@ OPJ_BOOL opj_tcd_t1_encode ( opj_tcd_t *p_tcd ) { opj_t1_t * l_t1; const OPJ_FLOAT64 * l_mct_norms; + OPJ_UINT32 l_mct_numcomps = 0U; opj_tcp_t * l_tcp = p_tcd->tcp; l_t1 = opj_t1_create(OPJ_TRUE); @@ -1997,6 +1998,7 @@ OPJ_BOOL opj_tcd_t1_encode ( opj_tcd_t *p_tcd ) } if (l_tcp->mct == 1) { + l_mct_numcomps = 3U; /* irreversible encoding */ if (l_tcp->tccps->qmfbid == 0) { l_mct_norms = opj_mct_get_mct_norms_real(); @@ -2006,10 +2008,11 @@ OPJ_BOOL opj_tcd_t1_encode ( opj_tcd_t *p_tcd ) } } else { + l_mct_numcomps = p_tcd->image->numcomps; l_mct_norms = (const OPJ_FLOAT64 *) (l_tcp->mct_norms); } - if (! opj_t1_encode_cblks(l_t1, p_tcd->tcd_image->tiles , l_tcp, l_mct_norms)) { + if (! opj_t1_encode_cblks(l_t1, p_tcd->tcd_image->tiles , l_tcp, l_mct_norms, l_mct_numcomps)) { opj_t1_destroy(l_t1); return OPJ_FALSE; }