[trunk] Fix warnings about shadow variables
[openjpeg.git] / src / bin / mj2 / opj_mj2_wrap.c
index 5d37cd7b1c878511d7e4c7d8330cc637a9de718f..e164e2ea599bc5302068aae2f6664e9d74bfaca2 100644 (file)
@@ -45,10 +45,6 @@ Size of memory first allocated for MOOV box
 */
 #define TEMP_BUF 10000 
 
-#define ENUMCS_GRAY 16
-#define ENUMCS_SRGB 17
-#define ENUMCS_SYCC 18
-
 #define J2K_CODESTREAM_MAGIC "\xff\x4f\xff\x51"
 
 /* -------------------------------------------------------------------------- */
@@ -89,9 +85,7 @@ static int test_image(const char *fname, mj2_cparameters_t *cp)
 
        cio = opj_cio_open((opj_common_ptr)dinfo, src, src_len);
 
-#if 0 /* MM: FIXME */
        image = opj_decode(dinfo, cio);
-#endif
 
        free(src); cio->buffer = NULL;
        opj_cio_close(cio);
@@ -110,9 +104,9 @@ static int test_image(const char *fname, mj2_cparameters_t *cp)
        && (image->comps[2].dx == 2)
        && (image->comps[0].dy == 1)
        && (image->comps[1].dy == 2)
-       && (image->comps[2].dy == 2))// horizontal and vertical
+       && (image->comps[2].dy == 2))/* horizontal and vertical*/
   {
-//   Y420
+/*   Y420*/
        cp->enumcs = ENUMCS_SYCC;
        cp->CbCr_subsampling_dx = 2;
        cp->CbCr_subsampling_dy = 2;
@@ -123,9 +117,9 @@ static int test_image(const char *fname, mj2_cparameters_t *cp)
        && (image->comps[2].dx == 2)
        && (image->comps[0].dy == 1)
        && (image->comps[1].dy == 1)
-       && (image->comps[2].dy == 1))// horizontal only
+       && (image->comps[2].dy == 1))/* horizontal only*/
   {
-//   Y422
+/*   Y422*/
        cp->enumcs = ENUMCS_SYCC;
        cp->CbCr_subsampling_dx = 2;
        cp->CbCr_subsampling_dy = 1;
@@ -138,14 +132,14 @@ static int test_image(const char *fname, mj2_cparameters_t *cp)
        && (image->comps[1].dy == 1)
        && (image->comps[2].dy == 1))
   {
-//   Y444 or RGB
+/*   Y444 or RGB */
 
        if(image->color_space ==  CLRSPC_SRGB)
  {
        cp->enumcs = ENUMCS_SRGB;
 
-//    cp->CbCr_subsampling_dx = 0;
-//    cp->CbCr_subsampling_dy = 0;
+/*    cp->CbCr_subsampling_dx = 0; */
+/*    cp->CbCr_subsampling_dy = 0; */
  }
        else
  {
@@ -163,8 +157,8 @@ static int test_image(const char *fname, mj2_cparameters_t *cp)
        else
    {
        cp->enumcs = ENUMCS_GRAY;
-//  cp->CbCr_subsampling_dx = 0;
-//  cp->CbCr_subsampling_dy = 0;
+/*  cp->CbCr_subsampling_dx = 0; */
+/*  cp->CbCr_subsampling_dy = 0; */
    }
        if(image->icc_profile_buf)
    {
@@ -187,21 +181,21 @@ fin:
 /**
 sample error callback expecting a FILE* client object
 */
-void error_callback(const char *msg, void *client_data) {
+static void error_callback(const char *msg, void *client_data) {
        FILE *stream = (FILE*)client_data;
        fprintf(stream, "[ERROR] %s", msg);
 }
 /**
 sample warning callback expecting a FILE* client object
 */
-void warning_callback(const char *msg, void *client_data) {
+static void warning_callback(const char *msg, void *client_data) {
        FILE *stream = (FILE*)client_data;
        fprintf(stream, "[WARNING] %s", msg);
 }
 /**
 sample debug callback expecting a FILE* client object
 */
-void info_callback(const char *msg, void *client_data) {
+static void info_callback(const char *msg, void *client_data) {
        FILE *stream = (FILE*)client_data;
        fprintf(stream, "[INFO] %s", msg);
 }
@@ -295,7 +289,7 @@ static void setparams(opj_mj2_t *movie, opj_image_t *image) {
   
   movie->tk[0].sample_rate = 25;
   
-  movie->tk[0].jp2_struct.numcomps = image->numcomps;  // NC  
+  movie->tk[0].jp2_struct.numcomps = image->numcomps;  /* NC */
        
        /* Init Standard jp2 structure */
        
@@ -336,7 +330,7 @@ static void setparams(opj_mj2_t *movie, opj_image_t *image) {
     movie->tk[0].jp2_struct.meth = 2;
        
     if (image->numcomps == 1)
-     movie->tk[0].jp2_struct.enumcs = 17;  // Grayscale
+     movie->tk[0].jp2_struct.enumcs = 17;  /* Grayscale */
   
     else   
        if ((image->comps[0].dx == 1) 
@@ -345,7 +339,7 @@ static void setparams(opj_mj2_t *movie, opj_image_t *image) {
     && (image->comps[0].dy == 1) 
        && (image->comps[1].dy == 1) 
        && (image->comps[2].dy == 1)) 
-     movie->tk[0].jp2_struct.enumcs = 16;    // RGB
+     movie->tk[0].jp2_struct.enumcs = 16;    /* RGB */
   
     else   
        if ((image->comps[0].dx == 1) 
@@ -354,10 +348,10 @@ static void setparams(opj_mj2_t *movie, opj_image_t *image) {
     && (image->comps[0].dy == 1) 
        && (image->comps[1].dy == 2) 
        && (image->comps[2].dy == 2)) 
-     movie->tk[0].jp2_struct.enumcs = 18;  // YUV
+     movie->tk[0].jp2_struct.enumcs = 18;  /* YUV */
   
   else
-    movie->tk[0].jp2_struct.enumcs = 0;        // Unkown profile */
+    movie->tk[0].jp2_struct.enumcs = 0;        /* Unkown profile */
 }
 
 int main(int argc, char *argv[]) {
@@ -430,56 +424,58 @@ int main(int argc, char *argv[]) {
   fwrite(buf,cio_tell(cio),1,mj2file);
   free(buf);
        
-  // Insert each j2k codestream in a JP2C box  
+  /* Insert each j2k codestream in a JP2C box */
   snum=0;
   offset = 0;  
   while(1)
   {
+    mj2_sample_t * new_sample;
+    mj2_chunk_t * new_chunk;
     sample = &movie->tk[0].sample[snum];
     sprintf(j2kfilename,"%s_%05d.j2k",argv[1],snum);
     j2kfile = fopen(j2kfilename, "rb");
     if (!j2kfile) {
-      if (snum==0) {  // Could not open a single codestream
+      if (snum==0) {  /* Could not open a single codestream */
                                fprintf(stderr, "failed to open %s for reading\n",j2kfilename);
                                return 1;
       }
-      else {         // Tried to open a inexistant codestream
+      else {         /* Tried to open a inexistant codestream */
                                fprintf(stdout,"%d frames are being added to the MJ2 file\n",snum);
                                break;
       }
     }
 
-    // Calculating offset for samples and chunks
+    /* Calculating offset for samples and chunks */
     offset += cio_tell(cio);     
     sample->offset = offset;
-    movie->tk[0].chunk[snum].offset = offset;  // There will be one sample per chunk
+    movie->tk[0].chunk[snum].offset = offset;  /* There will be one sample per chunk */
     
-    // Calculating sample size
+    /* Calculating sample size */
     fseek(j2kfile,0,SEEK_END); 
-    sample->sample_size = ftell(j2kfile) + 8; // Sample size is codestream + JP2C box header
+    sample->sample_size = ftell(j2kfile) + 8; /* Sample size is codestream + JP2C box header */
     fseek(j2kfile,0,SEEK_SET);
     
-    // Reading siz marker of j2k image for the first codestream
+    /* Reading siz marker of j2k image for the first codestream */
     if (snum==0)             
       read_siz_marker(j2kfile, &img);
     
-    // Writing JP2C box header                     
+    /* Writing JP2C box header */
     frame_codestream = (unsigned char*) malloc (sample->sample_size+8); 
                cio = opj_cio_open(movie->cinfo, frame_codestream, sample->sample_size);    
-    cio_write(cio,sample->sample_size, 4);  // Sample size
-    cio_write(cio,JP2_JP2C, 4);        // JP2C
+    cio_write(cio,sample->sample_size, 4);  /* Sample size */
+    cio_write(cio,JP2_JP2C, 4);        /* JP2C */
     
-    // Writing codestream from J2K file to MJ2 file
+    /* Writing codestream from J2K file to MJ2 file */
     fread(frame_codestream+8,sample->sample_size-8,1,j2kfile);
     fwrite(frame_codestream,sample->sample_size,1,mj2file);
     cio_skip(cio, sample->sample_size-8);
     
-    // Ending loop
+    /* Ending loop */
     fclose(j2kfile);
     snum++;
-    mj2_sample_t * new_sample = (mj2_sample_t*)
+    new_sample = (mj2_sample_t*)
                realloc(movie->tk[0].sample, (snum+1) * sizeof(mj2_sample_t));
-    mj2_chunk_t * new_chunk = (mj2_chunk_t*)
+    new_chunk = (mj2_chunk_t*)
                realloc(movie->tk[0].chunk, (snum+1) * sizeof(mj2_chunk_t));
     if (new_sample && new_chunk) {
         movie->tk[0].sample = new_sample;
@@ -491,7 +487,7 @@ int main(int argc, char *argv[]) {
     free(frame_codestream);
   }
   
-  // Writing the MDAT box length in header
+  /* Writing the MDAT box length in header */
   offset += cio_tell(cio);
   buf = (unsigned char*) malloc (4 * sizeof(unsigned char));
        cio = opj_cio_open(movie->cinfo, buf, 4);
@@ -501,18 +497,18 @@ int main(int argc, char *argv[]) {
   fseek(mj2file,0,SEEK_END);
   free(buf);
        
-  // Setting movie parameters
+  /* Setting movie parameters */
   movie->tk[0].num_samples=snum;
   movie->tk[0].num_chunks=snum;
   setparams(movie, &img);
        
-  // Writing MOOV box 
+  /* Writing MOOV box */
        buf = (unsigned char*) malloc ((TEMP_BUF+snum*20) * sizeof(unsigned char));
        cio = opj_cio_open(movie->cinfo, buf, (TEMP_BUF+snum*20));
        mj2_write_moov(movie, cio);
   fwrite(buf,cio_tell(cio),1,mj2file);
        
-  // Ending program
+  /* Ending program */
   free(img.comps);
   opj_cio_close(cio);