[trunk] check number of components when getting mct norm (fixes issue 436)

This commit is contained in:
Antonin Descampe 2014-12-09 12:09:08 +00:00
parent 776b83ddbc
commit 8d320bbdf8
4 changed files with 23 additions and 12 deletions

View File

@ -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) ||

View File

@ -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;

View File

@ -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

View File

@ -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;
}