From 7d21871ed8124e8e3056e4d81618485596f952df Mon Sep 17 00:00:00 2001 From: Antonin Descampe Date: Thu, 3 Jul 2014 09:15:13 +0000 Subject: [PATCH] [trunk] fixes issue #357. MCT is automatically disabled when subsamppling is detected. --- src/bin/jp2/convert.c | 2 +- src/bin/jp2/opj_compress.c | 10 ++++++++++ src/lib/openjp2/j2k.c | 9 +++++++++ 3 files changed, 20 insertions(+), 1 deletion(-) diff --git a/src/bin/jp2/convert.c b/src/bin/jp2/convert.c index 1b2d3618..9ce3eb39 100644 --- a/src/bin/jp2/convert.c +++ b/src/bin/jp2/convert.c @@ -3018,7 +3018,7 @@ static opj_image_t* rawtoimage_common(const char *filename, opj_cparameters_t *p { unsigned char value = 0; for(compno = 0; compno < numcomps; compno++) { - int nloop = (w*h)/(raw_cp->rawComps[compno].dx*raw_cp->rawComps[compno].dx); + int nloop = (w*h)/(raw_cp->rawComps[compno].dx*raw_cp->rawComps[compno].dy); for (i = 0; i < nloop; i++) { if (!fread(&value, 1, 1, f)) { fprintf(stderr,"Error reading raw file. End of file probably reached.\n"); diff --git a/src/bin/jp2/opj_compress.c b/src/bin/jp2/opj_compress.c index f2b3f2fb..8736f535 100644 --- a/src/bin/jp2/opj_compress.c +++ b/src/bin/jp2/opj_compress.c @@ -1500,6 +1500,16 @@ static int parse_cmdline_encoder(int argc, char **argv, opj_cparameters_t *param } } + /* If subsampled image is provided, automatically disable MCT */ + if ( ((parameters->decod_format == RAW_DFMT) + || (parameters->decod_format == RAWL_DFMT)) + && ((raw_cp->rawComps[1].dx > 1) + || (raw_cp->rawComps[1].dy > 1) + || (raw_cp->rawComps[2].dx > 1) + || (raw_cp->rawComps[2].dy > 1))) { + parameters->tcp_mct = 0; + } + return 0; } diff --git a/src/lib/openjp2/j2k.c b/src/lib/openjp2/j2k.c index 95553735..d06dc05e 100644 --- a/src/lib/openjp2/j2k.c +++ b/src/lib/openjp2/j2k.c @@ -6453,6 +6453,15 @@ void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, opj_j2k_setup_mct_encoding(tcp,image); } else { + 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) || + (image->comps[0].dy != image->comps[2].dy)) { + opj_event_msg(p_manager, EVT_WARNING, "Cannot perform MCT on components with different sizes. Disabling MCT.\n"); + tcp->mct = 0; + } + } for (i = 0; i < image->numcomps; i++) { opj_tccp_t *tccp = &tcp->tccps[i]; opj_image_comp_t * l_comp = &(image->comps[i]);