[trunk] fixes issue #357. MCT is automatically disabled when
authorAntonin Descampe <antonin@gmail.com>
Thu, 3 Jul 2014 09:15:13 +0000 (09:15 +0000)
committerAntonin Descampe <antonin@gmail.com>
Thu, 3 Jul 2014 09:15:13 +0000 (09:15 +0000)
subsamppling is detected.

src/bin/jp2/convert.c
src/bin/jp2/opj_compress.c
src/lib/openjp2/j2k.c

index 1b2d3618ef8debf5977147b97b3b29ae1d542d73..9ce3eb3907140dd48923df3e26632f13f75f70bd 100644 (file)
@@ -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");
index f2b3f2fb17a3467b03382e4568b02008d1a2fd48..8736f5352513b591962726f6af4bcdf74dc5efd8 100644 (file)
@@ -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;
 }
 
index 955537354ede457e12fae692b0d2978fdb011552..d06dc05e2b52a211d8633046148ecf4d9848f2f4 100644 (file)
@@ -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]);