MJ2 module: Add two components to mj2.h: meth, enumcs ; Define or reset all component...
[openjpeg.git] / mj2 / mj2_to_frames.c
index b87703cc5ab2c57b62f32f6a3757a6bdb5427358..156a101c71c69d176b28ee2264144c12f6f852b4 100644 (file)
 #include <stdlib.h>
 #include <string.h>
 
+#include "opj_config.h"
 #include "openjpeg.h"
-#include "j2k_lib.h"
-#include "j2k.h"
-#include "jp2.h"
+#include "../libopenjpeg/j2k_lib.h"
+#include "../libopenjpeg/j2k.h"
+#include "../libopenjpeg/jp2.h"
 #include "mj2.h"
 #include "mj2_convert.h"
 
+#ifdef HAVE_LIBLCMS2
+#include <lcms2.h>
+#endif
+#ifdef HAVE_LIBLCMS1
+#include <lcms.h>
+#endif
+#include "color.h"
 /* -------------------------------------------------------------------------- */
 
 /**
@@ -81,8 +89,7 @@ int main(int argc, char *argv[]) {
        unsigned int numframes = 0;
                        
   if (argc != 3) {
-    printf("Bad syntax: Usage: mj2_to_frames inputfile.mj2 outputfile.yuv\n"); 
-    printf("Example: MJ2_decoder foreman.mj2 foreman.yuv\n");
+    printf("Usage: %s inputfile.mj2 outputfile.yuv\n",argv[0]); 
     return 1;
   }
   
@@ -117,11 +124,12 @@ int main(int argc, char *argv[]) {
        /* catch events using our callbacks and give a local context */
        opj_set_event_mgr((opj_common_ptr)dinfo, &event_mgr, stderr);           
 
+       memset(&mj2_parameters, 0, sizeof(mj2_dparameters_t));
        /* set J2K decoding parameters to default values */
        opj_set_default_decoder_parameters(&mj2_parameters.j2k_parameters);
        
        /* setup the decoder decoding parameters using user parameters */
-       mj2_setup_decoder((opj_mj2_t*)dinfo->mj2_handle, &mj2_parameters);
+       mj2_setup_decoder(movie, &mj2_parameters);
                        
   if (mj2_read_struct(file, movie)) // Creating the movie structure
     return 1;  
@@ -169,7 +177,24 @@ int main(int argc, char *argv[]) {
                cio = opj_cio_open((opj_common_ptr)dinfo, frame_codestream, sample->sample_size-8);
                
                img = opj_decode(dinfo, cio); // Decode J2K to image
-                               
+
+#ifdef WANT_SYCC_TO_RGB
+       if(img->color_space == CLRSPC_SYCC)
+  {
+       color_sycc_to_rgb(img);
+  }
+#endif
+
+       if(img->icc_profile_buf)
+  {
+#if defined(HAVE_LIBLCMS1) || defined(HAVE_LIBLCMS2)
+       color_apply_icc_profile(img);
+#endif
+
+       free(img->icc_profile_buf);
+       img->icc_profile_buf = NULL; img->icc_profile_len = 0;
+  }
+
     if (((img->numcomps == 3) && (img->comps[0].dx == img->comps[1].dx / 2) 
       && (img->comps[0].dx == img->comps[2].dx / 2 ) && (img->comps[0].dx == 1)) 
       || (img->numcomps == 1)) {
@@ -183,7 +208,7 @@ int main(int argc, char *argv[]) {
     {
       fprintf(stdout,"The frames will be output in a bmp format (output_1.bmp, ...)\n");
       sprintf(outfilename,"output_%d.bmp",snum);
-      if (imagetobmp(img, outfilename))        // Convert image to YUV
+      if (imagetobmp(img, outfilename))        // Convert image to BMP
                                return 1;
       
     }