[trunk] Import rev 1103 into trunk.
[openjpeg.git] / applications / mj2 / mj2.c
index 131eaceaff78d92a66da6ed46d40af8d9cfc3d61..886eeac9d04f3c6826e722ed0deeed3233996c6a 100644 (file)
@@ -26,7 +26,7 @@
  * POSSIBILITY OF SUCH DAMAGE.
  */
 
-#include "../libopenjpeg/opj_includes.h"
+#include "opj_includes.h"
 #include "mj2.h"
 
 /** @defgroup JP2 JP2 - JPEG-2000 file format reader/writer */
 /** @name Local static functions */
 /*@{*/
 
-/**
-Read box headers
-@param cinfo Codec context info
-@param cio Input stream
-@param box
-@return Returns true if successful, returns false otherwise
-*/
-/*-- UNUSED
-static bool jp2_read_boxhdr(opj_common_ptr cinfo, opj_cio_t *cio, opj_jp2_box_t *box);
---*/
 /*
 * 
 * Read box headers
@@ -250,9 +240,7 @@ void mj2_tts_decompact(mj2_tk_t * tk)
 */
 void mj2_stsc_decompact(mj2_tk_t * tk)
 {
-  int j, i;
-  unsigned int k;
-  int sampleno=0;
+  unsigned int i, j, k, sampleno = 0;
   
   if (tk->num_samplestochunk == 1) {
     tk->num_chunks =
@@ -293,10 +281,8 @@ void mj2_stsc_decompact(mj2_tk_t * tk)
 */
 void mj2_stco_decompact(mj2_tk_t * tk)
 {
-  int j;
-  unsigned int i;
-  int k = 0;
-  int intra_chunk_offset;
+  unsigned int i, j, k = 0;
+  unsigned int intra_chunk_offset;
        
   for (i = 0; i < tk->num_chunks; i++) {
     intra_chunk_offset = 0;
@@ -595,7 +581,7 @@ int mj2_read_stsz(mj2_tk_t * tk, opj_cio_t *cio)
 */
 void mj2_write_stsc(mj2_tk_t * tk, opj_cio_t *cio)
 {
-  int i;
+  unsigned int i;
   mj2_box_t box;
        
   box.init_pos = cio_tell(cio);
@@ -627,7 +613,7 @@ void mj2_write_stsc(mj2_tk_t * tk, opj_cio_t *cio)
 */
 int mj2_read_stsc(mj2_tk_t * tk, opj_cio_t *cio)
 {
-  int i;
+  unsigned int i;
   mj2_box_t box;
        
   mj2_read_boxhdr(&box, cio);  /* Box Size */
@@ -1110,8 +1096,9 @@ int mj2_read_smj2(opj_image_t * img, mj2_tk_t * tk, opj_cio_t *cio)
 {
   mj2_box_t box;
   mj2_box_t box2;
-  int i;
   opj_jp2_color_t color;
+  int i;
+  opj_bool ok;
        
   mj2_read_boxhdr(&box, cio);
        
@@ -1169,12 +1156,19 @@ int mj2_read_smj2(opj_image_t * img, mj2_tk_t * tk, opj_cio_t *cio)
   tk->or_fieldorder = 0;
        
   cio_skip(cio,2);                     /* Pre-defined = -1 */
+
   memset(&color, 0, sizeof(opj_jp2_color_t));
-       
-  if (!jp2_read_jp2h(&tk->jp2_struct, cio, &color)) {
-               opj_event_msg(tk->cinfo, EVT_ERROR, "Error reading JP2H Box\n");
+  tk->jp2_struct.cinfo = tk->cinfo;
+
+  ok = jp2_read_jp2h(&tk->jp2_struct, cio, &color);
+
+  tk->jp2_struct.cinfo = NULL; 
+
+  if(ok == OPJ_FALSE)
+ {
+       opj_event_msg(tk->cinfo, EVT_ERROR, "Error reading JP2H Box\n");
     return 1;
 }
+ }
 
   tk->jp2_struct.comps = (opj_jp2_comps_t*) opj_malloc(tk->jp2_struct.numcomps * sizeof(opj_jp2_comps_t));
   tk->jp2_struct.cl = (unsigned int*) opj_malloc(sizeof(unsigned int));
@@ -2733,7 +2727,7 @@ opj_dinfo_t* mj2_create_decompress() {
        opj_dinfo_t *dinfo = (opj_dinfo_t*) opj_calloc(1, sizeof(opj_dinfo_t));
        if(!dinfo) return NULL;
 
-       dinfo->is_decompressor = true;  
+       dinfo->is_decompressor = OPJ_TRUE;      
 
        mj2 = (opj_mj2_t*) opj_calloc(1, sizeof(opj_mj2_t));
        dinfo->mj2_handle = mj2;
@@ -2773,9 +2767,9 @@ void mj2_destroy_decompress(opj_mj2_t *movie) {
                        if (tk->name_size != 0)
                                opj_free(tk->name);
                        if (tk->track_type == 0)  {// Video track
-                               if (tk->jp2_struct.comps != 0)
+                               if (tk->jp2_struct.comps != NULL)
                                        opj_free(tk->jp2_struct.comps);
-                               if (tk->jp2_struct.cl != 0)
+                               if (tk->jp2_struct.cl != NULL)
                                        opj_free(tk->jp2_struct.cl);
                                if (tk->num_jp2x != 0)
                                        opj_free(tk->jp2xdata);
@@ -2892,9 +2886,9 @@ void mj2_destroy_compress(opj_mj2_t *movie) {
                        if (tk->name_size != 0)
                                opj_free(tk->name);
                        if (tk->track_type == 0)  {// Video track
-                               if (tk->jp2_struct.comps != 0)
+                               if (tk->jp2_struct.comps != NULL)
                                        opj_free(tk->jp2_struct.comps);
-                               if (tk->jp2_struct.cl != 0)
+                               if (tk->jp2_struct.cl != NULL)
                                        opj_free(tk->jp2_struct.cl);
                                if (tk->num_jp2x != 0)
                                        opj_free(tk->jp2xdata);