[trunk] Import rev 1103 into trunk.
[openjpeg.git] / applications / mj2 / mj2_convert.c
index 3e6c1229f2235a206e55518451729e532c3d8a07..3d842883fc3f6729092ec97cd3a975f7c11b501f 100644 (file)
@@ -26,7 +26,7 @@
 * POSSIBILITY OF SUCH DAMAGE.
 */
 
-#include "../libopenjpeg/opj_includes.h"
+#include "opj_includes.h"
 #include "mj2.h"
 
 /*  -----------------------          */
 /*                                   */
 /*  -----------------------          */
 
-int yuv_num_frames(mj2_tk_t * tk, char *infile)
+unsigned int yuv_num_frames(mj2_tk_t * tk, char *infile)
 {
-  int numimages, frame_size, prec_size;
-  long end_of_f;
+  unsigned int prec_size;
+  long end_of_f, frame_size;
        FILE *f;
 
   f = fopen(infile,"rb");
   if (!f) {  
     fprintf(stderr, "failed to open %s for reading\n",infile);
-    return -1;
+    return 0;
   }
        prec_size = (tk->depth + 7)/8;/* bytes of precision */
 
-  frame_size = (int) (tk->w * tk->h * (1.0 + (double) 2 / (double) (tk->CbCr_subsampling_dx * tk->CbCr_subsampling_dy)));      /* Calculate frame size */
+  frame_size = (long) (tk->w * tk->h * (1.0 + (double) 2 / (double) (tk->CbCr_subsampling_dx * tk->CbCr_subsampling_dy)));     /* Calculate frame size */
        frame_size *= prec_size; 
        
   fseek(f, 0, SEEK_END);
@@ -60,13 +60,11 @@ int yuv_num_frames(mj2_tk_t * tk, char *infile)
     fprintf(stderr,
                        "YUV does not contains any frame of %d x %d size\n", tk->w,
                        tk->h);
-    return -1;
+    return 0;
   }
+  fclose(f);
        
-  numimages = end_of_f / frame_size;   /* Calculate number of images */
-       fclose(f);
-
-  return numimages;
+  return (unsigned int)(end_of_f / frame_size);
 }
 
 //  -----------------------
@@ -179,7 +177,7 @@ char yuvtoimage(mj2_tk_t * tk, opj_image_t * img, int frame_num, opj_cparameters
 //  -----------------------
 
 
-bool imagetoyuv(opj_image_t * img, char *outfile)
+opj_bool imagetoyuv(opj_image_t * img, char *outfile)
 {
   FILE *f;
   int *data;
@@ -191,18 +189,18 @@ bool imagetoyuv(opj_image_t * img, char *outfile)
       || img->comps[1].dx != img->comps[2].dx) {
       fprintf(stderr,
                                "Error with the input image components size: cannot create yuv file)\n");
-      return false;
+      return OPJ_FALSE;
     }
   } else if (!(img->numcomps == 1)) {
     fprintf(stderr,
       "Error with the number of image components(must be one or three)\n");
-    return false;
+    return OPJ_FALSE;
   }
   
   f = fopen(outfile, "a+b");
   if (!f) {
     fprintf(stderr, "failed to open %s for writing\n", outfile);
-    return false;
+    return OPJ_FALSE;
   }
   is_16 = (img->comps[0].prec > 8);
   prec_bytes = (is_16?2:1);
@@ -262,7 +260,7 @@ bool imagetoyuv(opj_image_t * img, char *outfile)
     }
   }  
   fclose(f);
-  return true;
+  return OPJ_TRUE;
 }
 
 //  -----------------------