[trunk]clean jpip marker functions but it is still experimental
authorMickael Savinaud <savmickael@users.noreply.github.com>
Thu, 25 Oct 2012 13:15:37 +0000 (13:15 +0000)
committerMickael Savinaud <savmickael@users.noreply.github.com>
Thu, 25 Oct 2012 13:15:37 +0000 (13:15 +0000)
src/lib/openjp2/cidx_manager.c
src/lib/openjp2/cidx_manager.h
src/lib/openjp2/indexbox_manager.h
src/lib/openjp2/phix_manager.c
src/lib/openjp2/ppix_manager.c
src/lib/openjp2/thix_manager.c
src/lib/openjp2/tpix_manager.c

index 0c6c669ecd9b126bb739a521cd37312fcbc2c9a4..7fb6f1b98e7042d3e68bfa652c682fa95d0d710f 100644 (file)
  * @param[in] clen length of j2k codestream
  * @param[in] cio  file output handle
  */
-void write_cptr(int coff, int clen, opj_cio_t *cio);
 
-void write_cptr_v2(int coff, int clen, opj_stream_private_t *cio,
+void opj_write_cptr(int coff, int clen, opj_stream_private_t *cio,
               opj_event_mgr_t * p_manager );
 
-void write_manf_v2(int second, int v, opj_jp2_box_t *box, opj_stream_private_t *cio,
-              opj_event_mgr_t * p_manager );
-
-/* 
- * Write main header index table (box)
- *
- * @param[in] coff offset of j2k codestream
- * @param[in] cstr_info codestream information
- * @param[in] cio  file output handle
- * @return         length of mainmhix box
- */
-int write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_cio_t *cio);
-
-
-/* 
- * Check if EPH option is used
- *
- * @param[in] coff    offset of j2k codestream
- * @param[in] markers marker information
- * @param[in] marknum number of markers
- * @param[in] cio     file output handle
- * @return            true if EPH is used
- */
-opj_bool check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_cio_t *cio);
-
-
-int write_cidx( int offset, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t cstr_info, int j2klen)
-{
-  int len, i, lenp;
-  opj_jp2_box_t *box;
-  int num_box = 0;
-  opj_bool  EPHused;
-  (void)image; /* unused ? */
-
-  lenp = -1;
-  box = (opj_jp2_box_t *)opj_calloc( 32, sizeof(opj_jp2_box_t));
-
-  for (i=0;i<2;i++){
-  
-    if(i)
-      cio_seek( cio, lenp);
-
-    lenp = cio_tell( cio);
 
-    cio_skip( cio, 4);              /* L [at the end] */
-    cio_write( cio, JPIP_CIDX, 4);  /* CIDX           */
-    write_cptr( offset, cstr_info.codestream_size, cio);
 
-    write_manf( i, num_box, box, cio);
-    
-    num_box = 0;
-    box[num_box].length = write_mainmhix( offset, cstr_info, cio);
-    box[num_box].type = JPIP_MHIX;
-    num_box++;
 
-    box[num_box].length = write_tpix( offset, cstr_info, j2klen, cio);
-    box[num_box].type = JPIP_TPIX;
-    num_box++;
-      
-    box[num_box].length = write_thix( offset, cstr_info, cio);
-    box[num_box].type = JPIP_THIX;
-    num_box++;
-
-    EPHused = check_EPHuse( offset, cstr_info.marker, cstr_info.marknum, cio);
-      
-    box[num_box].length = write_ppix( offset, cstr_info, EPHused, j2klen, cio);
-    box[num_box].type = JPIP_PPIX;
-    num_box++;
-    
-    box[num_box].length = write_phix( offset, cstr_info, EPHused, j2klen, cio);
-    box[num_box].type = JPIP_PHIX;
-    num_box++;
-      
-    len = cio_tell( cio)-lenp;
-    cio_seek( cio, lenp);
-    cio_write( cio, len, 4);        /* L             */
-    cio_seek( cio, lenp+len);
-  }
-
-  opj_free( box);
-  
-  return len;
-}
 
-int write_cidx_v2( int offset, opj_stream_private_t *cio, opj_codestream_info_t cstr_info, int j2klen,
+int opj_write_cidx( int offset, opj_stream_private_t *cio, opj_codestream_info_t cstr_info, int j2klen,
               opj_event_mgr_t * p_manager )
 {
-  int len, i, lenp;
+  int i;
+  OPJ_OFF_T lenp;
+  OPJ_UINT32 len;
   opj_jp2_box_t *box;
   int num_box = 0;
   opj_bool  EPHused;
@@ -149,51 +70,42 @@ int write_cidx_v2( int offset, opj_stream_private_t *cio, opj_codestream_info_t
     lenp = opj_stream_tell (cio);
 
     opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
-#if 0
-    cio_write( cio, JPIP_CIDX, 4);  /* CIDX           */
-#else
+
     opj_write_bytes(l_data_header,JPIP_CIDX,4); /* CIDX */
     opj_stream_write_data(cio,l_data_header,4,p_manager);
-#endif
-    write_cptr_v2( offset, cstr_info.codestream_size, cio,p_manager);
 
-    write_manf_v2( i, num_box, box, cio,p_manager);
+    opj_write_cptr( offset, cstr_info.codestream_size, cio,p_manager);
+
+    opj_write_manf( i, num_box, box, cio,p_manager);
     
     num_box = 0;
-    box[num_box].length = write_mainmhix_v2( offset, cstr_info, cio,p_manager);
+    box[num_box].length = opj_write_mainmhix( offset, cstr_info, cio,p_manager);
     box[num_box].type = JPIP_MHIX;
     num_box++;
 
-    box[num_box].length = write_tpix_v2( offset, cstr_info, j2klen, cio,p_manager);
+    box[num_box].length = opj_write_tpix( offset, cstr_info, j2klen, cio,p_manager);
     box[num_box].type = JPIP_TPIX;
     num_box++;
       
-    box[num_box].length = write_thix_v2( offset, cstr_info, cio, p_manager);
+    box[num_box].length = opj_write_thix( offset, cstr_info, cio, p_manager);
     box[num_box].type = JPIP_THIX;
     num_box++;
 
-    EPHused = check_EPHuse_v2( offset, cstr_info.marker, cstr_info.marknum, cio,p_manager);
+    EPHused = opj_check_EPHuse( offset, cstr_info.marker, cstr_info.marknum, cio,p_manager);
       
-    box[num_box].length = write_ppix_v2( offset, cstr_info, EPHused, j2klen, cio,p_manager);
+    box[num_box].length = opj_write_ppix( offset, cstr_info, EPHused, j2klen, cio,p_manager);
     box[num_box].type = JPIP_PPIX;
     num_box++;
     
-    box[num_box].length = write_phix_v2( offset, cstr_info, EPHused, j2klen, cio,p_manager);
+    box[num_box].length = opj_write_phix( offset, cstr_info, EPHused, j2klen, cio,p_manager);
     box[num_box].type = JPIP_PHIX;
     num_box++;
       
-#if 0
-    len = cio_tell( cio)-lenp;
-    cio_seek( cio, lenp);
-    cio_write( cio, len, 4);        /* L             */
-    cio_seek( cio, lenp+len);
-#else
-    len = opj_stream_tell(cio)-lenp;
+    len = (OPJ_UINT32) (opj_stream_tell(cio)-lenp);
     opj_stream_seek(cio, lenp,p_manager);
     opj_write_bytes(l_data_header,len,4);/* L  */
     opj_stream_write_data(cio,l_data_header,4,p_manager);
     opj_stream_seek(cio, lenp+len,p_manager);
-#endif
   }
 
   opj_free( box);
@@ -201,42 +113,16 @@ int write_cidx_v2( int offset, opj_stream_private_t *cio, opj_codestream_info_t
   return len;
 }
 
-void write_cptr(int coff, int clen, opj_cio_t *cio)
-{
-  int len, lenp;
-
-  lenp = cio_tell( cio);
-  cio_skip( cio, 4);               /* L [at the end]     */
-  cio_write( cio, JPIP_CPTR, 4);   /* T                  */
-  cio_write( cio, 0, 2);           /* DR  A PRECISER !!  */
-  cio_write( cio, 0, 2);           /* CONT               */
-  cio_write( cio, coff, 8);    /* COFF A PRECISER !! */
-  cio_write( cio, clen, 8);    /* CLEN               */
-  len = cio_tell( cio) - lenp;
-  cio_seek( cio, lenp);
-  cio_write( cio, len, 4);         /* L                  */
-  cio_seek( cio, lenp+len);
-}
 
-void write_cptr_v2(int coff, int clen, opj_stream_private_t *cio,
+
+void opj_write_cptr(int coff, int clen, opj_stream_private_t *cio,
               opj_event_mgr_t * p_manager )
 {
   OPJ_BYTE l_data_header [3*8];
-  int len, lenp;
-
-#if 0
-  lenp = cio_tell( cio);
-  cio_skip( cio, 4);               /* L [at the end]     */
-  cio_write( cio, JPIP_CPTR, 4);   /* T                  */
-  cio_write( cio, 0, 2);           /* DR  A PRECISER !!  */
-  cio_write( cio, 0, 2);           /* CONT               */
-  cio_write( cio, coff, 8);    /* COFF A PRECISER !! */
-  cio_write( cio, clen, 8);    /* CLEN               */
-  len = cio_tell( cio) - lenp;
-  cio_seek( cio, lenp);
-  cio_write( cio, len, 4);         /* L                  */
-  cio_seek( cio, lenp+len);
-#else
+  OPJ_UINT32 len;
+  OPJ_OFF_T lenp;
+
+
   lenp = opj_stream_tell(cio);
   opj_stream_skip( cio, 4, p_manager);               /* L [at the end]     */
   opj_write_bytes( l_data_header, JPIP_CPTR, 4);   /* T                  */
@@ -246,221 +132,105 @@ void write_cptr_v2(int coff, int clen, opj_stream_private_t *cio,
   opj_write_bytes( l_data_header+16, clen, 8);    /* CLEN               */
   opj_stream_write_data(cio,l_data_header,3*8,p_manager);
 
-  len = opj_stream_tell(cio) - lenp;
+  len = (OPJ_UINT32) (opj_stream_tell(cio) - lenp);
   opj_stream_seek(cio,lenp,p_manager);
   opj_write_bytes(l_data_header, len, 4);         /* L                  */
   opj_stream_write_data(cio,l_data_header,4,p_manager);
   opj_stream_seek(cio, lenp+len,p_manager);
-#endif
-}
 
-void write_manf(int second, int v, opj_jp2_box_t *box, opj_cio_t *cio)
-{
-  int len, lenp, i;
-  
-  lenp = cio_tell( cio); 
-  cio_skip( cio, 4);                         /* L [at the end]                    */
-  cio_write( cio, JPIP_MANF,4);              /* T                                 */
+}
 
-  if (second){                          /* Write only during the second pass */
-    for( i=0; i<v; i++){
-      cio_write( cio, box[i].length, 4);  /* Box length                     */ 
-      cio_write( cio, box[i].type, 4); /* Box type                       */
-    }
-  }
 
-  len = cio_tell( cio) - lenp;
-  cio_seek( cio, lenp);
-  cio_write( cio, len, 4);                   /* L                                 */
-  cio_seek( cio, lenp+len);
-}
 
-void write_manf_v2(int second, int v, opj_jp2_box_t *box, opj_stream_private_t *cio,
-              opj_event_mgr_t * p_manager )
+void opj_write_manf(int second, 
+                    int v, 
+                    opj_jp2_box_t *box, 
+                    opj_stream_private_t *cio,
+                    opj_event_mgr_t * p_manager )
 {
   OPJ_BYTE l_data_header [4];
-  int len, lenp, i;
+  int i;
+  OPJ_UINT32 len;
+  OPJ_OFF_T lenp;
   
-#if 0
-  lenp = cio_tell( cio); 
-  cio_skip( cio, 4);                         /* L [at the end]                    */
-  cio_write( cio, JPIP_MANF,4);              /* T                                 */
-#else
   lenp = opj_stream_tell(cio);
   opj_stream_skip( cio, 4, p_manager);             /* L [at the end]     */
   opj_write_bytes( l_data_header, JPIP_MANF, 4);   /* T                  */
   opj_stream_write_data(cio,l_data_header,4,p_manager);
-#endif
 
   if (second){                          /* Write only during the second pass */
     for( i=0; i<v; i++){
-#if 0
-      cio_write( cio, box[i].length, 4);  /* Box length                     */ 
-      cio_write( cio, box[i].type, 4); /* Box type                       */
-#else
       opj_write_bytes( l_data_header, box[i].length, 4); /* Box length                     */
       opj_stream_write_data(cio,l_data_header,4,p_manager);
       opj_write_bytes( l_data_header, box[i].type, 4); /* Box type                       */
       opj_stream_write_data(cio,l_data_header,4,p_manager);
-#endif
     }
   }
 
-#if 0
-  len = cio_tell( cio) - lenp;
-  cio_seek( cio, lenp);
-  cio_write( cio, len, 4);                   /* L                                 */
-  cio_seek( cio, lenp+len);
-#else
-  len = opj_stream_tell(cio) - lenp;
+  len = (OPJ_UINT32) (opj_stream_tell(cio) - lenp);
   opj_stream_seek(cio,lenp,p_manager);
   opj_write_bytes(l_data_header, len, 4);/* L                                 */
   opj_stream_write_data(cio,l_data_header,4,p_manager);
   opj_stream_seek(cio,lenp+len,p_manager);
-#endif
 }
 
-int write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_cio_t *cio)
-{
-  int i;
-  int len, lenp;
-  
-  lenp = cio_tell( cio);
-  cio_skip( cio, 4);                               /* L [at the end]                    */
-  cio_write( cio, JPIP_MHIX, 4);                   /* MHIX                              */
-
-  cio_write( cio, cstr_info.main_head_end-cstr_info.main_head_start+1, 8);        /* TLEN                              */
-
-  for(i = 1; i < cstr_info.marknum; i++){    /* Marker restricted to 1 apparition, skip SOC marker */
-    cio_write( cio, cstr_info.marker[i].type, 2);
-    cio_write( cio, 0, 2);
-    cio_write( cio, cstr_info.marker[i].pos-coff, 8);
-    cio_write( cio, cstr_info.marker[i].len, 2);
-  }
-
-  len = cio_tell( cio) - lenp;
-  cio_seek( cio, lenp);
-  cio_write( cio, len, 4);        /* L           */
-  cio_seek( cio, lenp+len);
-  
-  return len;
-}
 
-int write_mainmhix_v2( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio,
+int opj_write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio,
               opj_event_mgr_t * p_manager )
 {
   OPJ_BYTE l_data_header [8];
   int i;
-  int len, lenp;
+  OPJ_UINT32 len;
+  OPJ_OFF_T lenp;
   
-#if 0
-  lenp = cio_tell( cio);
-  cio_skip( cio, 4);                               /* L [at the end]                    */
-  cio_write( cio, JPIP_MHIX, 4);                   /* MHIX                              */
-#else
   lenp = opj_stream_tell (cio);
   opj_stream_skip(cio, 4, p_manager);               /* L [at the end]                    */
   opj_write_bytes(l_data_header,JPIP_MHIX,4);       /* MHIX                              */
   opj_stream_write_data(cio,l_data_header,4,p_manager);
-#endif
 
-#if 0
-  cio_write( cio, cstr_info.main_head_end-cstr_info.main_head_start+1, 8);        /* TLEN                              */
-#else
   opj_write_bytes(l_data_header, cstr_info.main_head_end-cstr_info.main_head_start+1, 8);        /* TLEN                              */
   opj_stream_write_data(cio,l_data_header,8,p_manager);
-#endif
 
   for(i = 1; i < cstr_info.marknum; i++){    /* Marker restricted to 1 apparition, skip SOC marker */
-#if 0
-    cio_write( cio, cstr_info.marker[i].type, 2);
-    cio_write( cio, 0, 2);
-    cio_write( cio, cstr_info.marker[i].pos-coff, 8);
-    cio_write( cio, cstr_info.marker[i].len, 2);
-#else
     opj_write_bytes( l_data_header, cstr_info.marker[i].type, 2);
     opj_write_bytes( l_data_header+2, 0, 2);
     opj_stream_write_data(cio,l_data_header,4,p_manager);
-    opj_write_bytes( l_data_header, cstr_info.marker[i].pos-coff, 8);
+    opj_write_bytes( l_data_header,(OPJ_UINT32) (cstr_info.marker[i].pos-coff), 8);
     opj_stream_write_data(cio,l_data_header,8,p_manager);
     opj_write_bytes( l_data_header, cstr_info.marker[i].len, 2);
     opj_stream_write_data(cio,l_data_header,2,p_manager);
-#endif
   }
 
-#if 0
-  len = cio_tell( cio) - lenp;
-  cio_seek( cio, lenp);
-  cio_write( cio, len, 4);        /* L           */
-  cio_seek( cio, lenp+len);
-#else
-  len = opj_stream_tell(cio)-lenp;
+  len = (OPJ_UINT32) (opj_stream_tell(cio)-lenp);
   opj_stream_seek(cio, lenp,p_manager);
   opj_write_bytes(l_data_header,len,4);/* L  */
   opj_stream_write_data(cio,l_data_header,4,p_manager);
   opj_stream_seek(cio, lenp+len,p_manager);
-#endif
   
   return len;
 }
 
-opj_bool check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_cio_t *cio)
-{
-  opj_bool EPHused = OPJ_FALSE;
-  int i=0;
-  int org_pos;
-  unsigned int Scod;
-
-  for(i = 0; i < marknum; i++){
-    if( markers[i].type == J2K_MS_COD){
-      org_pos = cio_tell( cio);
-      cio_seek( cio, coff+markers[i].pos+2);
-      
-      Scod = cio_read( cio, 1);
-      if( ((Scod >> 2) & 1))
-  EPHused = OPJ_TRUE;
-      cio_seek( cio, org_pos);
-
-      break;
-    }
-  }    
-  return EPHused;
-}
-
-opj_bool check_EPHuse_v2( int coff, opj_marker_info_t *markers, int marknum, opj_stream_private_t *cio,
+opj_bool opj_check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_stream_private_t *cio,
               opj_event_mgr_t * p_manager )
 {
   OPJ_BYTE l_data_header [4];
   opj_bool EPHused = OPJ_FALSE;
   int i=0;
-  int org_pos;
+  OPJ_OFF_T org_pos;
   unsigned int Scod;
 
   for(i = 0; i < marknum; i++)
     {
     if( markers[i].type == J2K_MS_COD)
       {
-#if 0
-      org_pos = cio_tell( cio);
-      cio_seek( cio, coff+markers[i].pos+2);
-#else
       org_pos = opj_stream_tell(cio);
       opj_stream_seek(cio, coff+markers[i].pos+2,p_manager);
-#endif
 
-#if 0
-      Scod = cio_read( cio, 1);
-#else
       opj_stream_read_data(cio,l_data_header,1,p_manager);
       opj_read_bytes(l_data_header,&Scod,1);
-#endif
       if( ((Scod >> 2) & 1))
         EPHused = OPJ_TRUE;
-#if 0
-      cio_seek( cio, org_pos);
-#else
       opj_stream_seek( cio, org_pos, p_manager);
-#endif
 
       break;
       }
index 1792550506829288f3577e7e8e625181ac39a74f..6c3000ba32da07ad73055d04c4afd6df1bdc0848 100644 (file)
  * @param[in] j2klen    length of j2k codestream
  * @return              length of cidx box
  */
-int write_cidx( int offset, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t cstr_info, int j2klen);
-int write_cidx_v2( int offset, opj_stream_private_t *cio, opj_codestream_info_t cstr_info, int j2klen,
+int opj_write_cidx( int offset, opj_stream_private_t *cio, opj_codestream_info_t cstr_info, int j2klen,
               opj_event_mgr_t * p_manager );
 
-opj_bool check_EPHuse_v2( int coff, opj_marker_info_t *markers, int marknum, opj_stream_private_t *cio,
+/* 
+ * Check if EPH option is used
+ *
+ * @param[in] coff    offset of j2k codestream
+ * @param[in] markers marker information
+ * @param[in] marknum number of markers
+ * @param[in] cio     file output handle
+ * @return            true if EPH is used
+ */
+opj_bool opj_check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_stream_private_t *cio,
               opj_event_mgr_t * p_manager );
 
 #endif      /* !CIDX_MANAGER_H_ */
index d468e72f40596f1254d6e08ba67921d269606799..5c309cb18dabc7b45c12e13b1321e82234137ec8 100644 (file)
@@ -65,8 +65,7 @@
  * @param[in] cio       file output handle
  * @return              length of tpix box
  */
-int write_tpix( int coff, opj_codestream_info_t cstr_info, int j2klen, opj_cio_t *cio);
-int write_tpix_v2( int coff, opj_codestream_info_t cstr_info, int j2klen, opj_stream_private_t *cio,
+int opj_write_tpix( int coff, opj_codestream_info_t cstr_info, int j2klen, opj_stream_private_t *cio,
               opj_event_mgr_t * p_manager );
 
 
@@ -78,8 +77,7 @@ int write_tpix_v2( int coff, opj_codestream_info_t cstr_info, int j2klen, opj_st
  * @param[in] cio       file output handle
  * @return              length of thix box
  */
-int write_thix( int coff, opj_codestream_info_t cstr_info, opj_cio_t *cio);
-int write_thix_v2( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio, opj_event_mgr_t * p_manager );
+int opj_write_thix( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio, opj_event_mgr_t * p_manager );
 
 
 /* 
@@ -92,8 +90,7 @@ int write_thix_v2( int coff, opj_codestream_info_t cstr_info, opj_stream_private
  * @param[in] cio       file output handle
  * @return              length of ppix box
  */
-int write_ppix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio);
-int write_ppix_v2( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_stream_private_t *cio,
+int opj_write_ppix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_stream_private_t *cio,
               opj_event_mgr_t * p_manager );
 
 
@@ -107,8 +104,7 @@ int write_ppix_v2( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused,
  * @param[in] cio       file output handle
  * @return              length of ppix box
  */
-int write_phix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio);
-int write_phix_v2( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_stream_private_t *cio,
+int opj_write_phix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_stream_private_t *cio,
               opj_event_mgr_t * p_manager );
 
 /* 
@@ -119,21 +115,34 @@ int write_phix_v2( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused,
  * @param[in] box    box to be manifested
  * @param[in] cio    file output handle
  */
-void write_manf(int second, int v, opj_jp2_box_t *box, opj_cio_t *cio);
 
-int write_mainmhix_v2( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio,
+void opj_write_manf(int second, 
+                    int v, 
+                    opj_jp2_box_t *box, 
+                    opj_stream_private_t *cio,
+                    opj_event_mgr_t * p_manager );
+
+/* 
+ * Write main header index table (box)
+ *
+ * @param[in] coff offset of j2k codestream
+ * @param[in] cstr_info codestream information
+ * @param[in] cio  file output handle
+ * @return         length of mainmhix box
+ */
+int opj_write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio,
               opj_event_mgr_t * p_manager );
 
-int write_phixfaix_v2( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_stream_private_t *cio,
+int opj_write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_stream_private_t *cio,
               opj_event_mgr_t * p_manager );
 
-int write_ppixfaix_v2( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_stream_private_t *cio,
+int opj_write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_stream_private_t *cio,
               opj_event_mgr_t * p_manager );
 
-int write_tilemhix_v2( int coff, opj_codestream_info_t cstr_info, int tileno, opj_stream_private_t *cio,
+int opj_write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, opj_stream_private_t *cio,
               opj_event_mgr_t * p_manager );
 
-int write_tpixfaix_v2( int coff, int compno, opj_codestream_info_t cstr_info, int j2klen, opj_stream_private_t *cio,
+int opj_write_tpixfaix( int coff, int compno, opj_codestream_info_t cstr_info, int j2klen, opj_stream_private_t *cio,
               opj_event_mgr_t * p_manager );
 
 #endif      /* !INDEXBOX_MANAGER_H_ */
index bb15ed376c2432a0293841bbd41e5ab057c92302..7bb7fe98bcaf45beb74442dc9573132167c9ba4a 100644 (file)
  * @param[in] cio       file output handle
  * @return              length of faix box
  */
-int write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio);
 
-int write_phix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio)
-{
-  int len, lenp=0, compno, i;
-  opj_jp2_box_t *box;
-
-  box = (opj_jp2_box_t *)opj_calloc( cstr_info.numcomps, sizeof(opj_jp2_box_t));
-  
-  for( i=0;i<2;i++){
-    if (i) cio_seek( cio, lenp);
-      
-    lenp = cio_tell( cio);
-    cio_skip( cio, 4);              /* L [at the end] */
-    cio_write( cio, JPIP_PHIX, 4);  /* PHIX           */
-      
-    write_manf( i, cstr_info.numcomps, box, cio);
-
-    for( compno=0; compno<cstr_info.numcomps; compno++){       
-      box[compno].length = write_phixfaix( coff, compno, cstr_info, EPHused, j2klen, cio);
-      box[compno].type = JPIP_FAIX;
-    }
-
-    len = cio_tell( cio)-lenp;
-    cio_seek( cio, lenp);
-    cio_write( cio, len, 4);        /* L              */
-    cio_seek( cio, lenp+len);
-  }
-
-  opj_free(box);
-
-  return len;
-}
-
-int write_phix_v2( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_stream_private_t *cio,
+int opj_write_phix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_stream_private_t *cio,
               opj_event_mgr_t * p_manager )
 {
   OPJ_BYTE l_data_header [8];
-  int len, lenp=0, compno, i;
+  int len, compno, i;
   opj_jp2_box_t *box;
+  OPJ_OFF_T lenp;
 
   box = (opj_jp2_box_t *)opj_calloc( cstr_info.numcomps, sizeof(opj_jp2_box_t));
   
   for( i=0;i<2;i++){
     if (i)
-#if 0
-      cio_seek( cio, lenp);
-#else
       opj_stream_seek( cio, lenp, p_manager);
-#endif
       
-#if 0
-    lenp = cio_tell( cio);
-    cio_skip( cio, 4);              /* L [at the end] */
-    cio_write( cio, JPIP_PHIX, 4);  /* PHIX           */
-#else
     lenp = opj_stream_tell(cio);
     opj_stream_skip(cio, 4, p_manager);         /* L [at the end]      */
     opj_write_bytes(l_data_header,JPIP_PHIX,4); /* PHIX */
     opj_stream_write_data(cio,l_data_header,4,p_manager);
-#endif
       
-    write_manf_v2( i, cstr_info.numcomps, box, cio);
+    opj_write_manf( i, cstr_info.numcomps, box, cio, p_manager );
 
     for( compno=0; compno<cstr_info.numcomps; compno++){       
-      box[compno].length = write_phixfaix_v2( coff, compno, cstr_info, EPHused, j2klen, cio,p_manager);
+      box[compno].length = opj_write_phixfaix( coff, compno, cstr_info, EPHused, j2klen, cio,p_manager);
       box[compno].type = JPIP_FAIX;
     }
 
-#if 0
-    len = cio_tell( cio)-lenp;
-    cio_seek( cio, lenp);
-    cio_write( cio, len, 4);        /* L              */
-    cio_seek( cio, lenp+len);
-#else
-    lenp = opj_stream_tell(cio);
+    len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp);
     opj_stream_seek(cio, 4, p_manager);
     opj_write_bytes(l_data_header,len,4);/* L              */
     opj_stream_write_data(cio,l_data_header,4,p_manager);
     opj_stream_seek( cio, lenp+len,p_manager);
-#endif
   }
 
   opj_free(box);
@@ -135,105 +86,23 @@ int write_phix_v2( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused,
   return len;
 }
 
-int write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio)
-{
-  int len, lenp, tileno, version, i, nmax, size_of_coding; /* 4 or 8 */
-  opj_tile_info_t *tile_Idx;
-  opj_packet_info_t packet;
-  int resno, precno, layno, num_packet;
-  int numOfres, numOfprec, numOflayers;
-  packet.end_ph_pos = packet.start_pos = -1;
-  (void)EPHused; /* unused ? */
 
-  if( j2klen > pow( 2, 32)){
-    size_of_coding =  8;
-    version = 1;
-  }
-  else{
-    size_of_coding = 4;
-    version = 0;
-  }
-
-  lenp = cio_tell( cio);
-  cio_skip( cio, 4);              /* L [at the end]      */
-  cio_write( cio, JPIP_FAIX, 4);  /* FAIX                */ 
-  cio_write( cio, version,1);     /* Version 0 = 4 bytes */
-
-  nmax = 0;
-  for( i=0; i<=cstr_info.numdecompos[compno]; i++)
-    nmax += cstr_info.tile[0].ph[i] * cstr_info.tile[0].pw[i] * cstr_info.numlayers;
-  
-  cio_write( cio, nmax, size_of_coding); /* NMAX */
-  cio_write( cio, cstr_info.tw*cstr_info.th, size_of_coding);      /* M    */
-  
-  for( tileno=0; tileno<cstr_info.tw*cstr_info.th; tileno++){
-    tile_Idx = &cstr_info.tile[ tileno];
-    
-    num_packet = 0;
-    numOfres = cstr_info.numdecompos[compno] + 1;
-
-    for( resno=0; resno<numOfres ; resno++){
-      numOfprec = tile_Idx->pw[resno]*tile_Idx->ph[resno];
-      for( precno=0; precno<numOfprec; precno++){
-       numOflayers = cstr_info.numlayers;
-       for( layno=0; layno<numOflayers; layno++){
-         
-         switch ( cstr_info.prog){
-         case LRCP:
-           packet = tile_Idx->packet[ ((layno*numOfres+resno)*cstr_info.numcomps+compno)*numOfprec+precno];
-           break;
-         case RLCP:
-           packet = tile_Idx->packet[ ((resno*numOflayers+layno)*cstr_info.numcomps+compno)*numOfprec+precno];
-           break;
-         case RPCL:
-           packet = tile_Idx->packet[ ((resno*numOfprec+precno)*cstr_info.numcomps+compno)*numOflayers+layno];
-           break;
-         case PCRL:
-           packet = tile_Idx->packet[ ((precno*cstr_info.numcomps+compno)*numOfres+resno)*numOflayers + layno];
-           break;
-         case CPRL:
-           packet = tile_Idx->packet[ ((compno*numOfprec+precno)*numOfres+resno)*numOflayers + layno];
-           break;
-         default:
-           fprintf( stderr, "failed to ppix indexing\n");
-         }
-
-         cio_write( cio, packet.start_pos-coff, size_of_coding);                /* start position */
-         cio_write( cio, packet.end_ph_pos-packet.start_pos+1, size_of_coding); /* length         */
-         
-         num_packet++;
-       }
-      }
-    }
-
-    /* PADDING */
-    while( num_packet < nmax){
-      cio_write( cio, 0, size_of_coding); /* start position            */
-      cio_write( cio, 0, size_of_coding); /* length                    */
-      num_packet++;
-    }
-  }
-
-  len = cio_tell( cio)-lenp;
-  cio_seek( cio, lenp);
-  cio_write( cio, len, 4);        /* L  */
-  cio_seek( cio, lenp+len);
-
-  return len;
-}
-
-int write_phixfaix_v2( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_stream_private_t *cio,
+int opj_write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_stream_private_t *cio,
               opj_event_mgr_t * p_manager )
 {
-  int len, lenp, tileno, version, i, nmax, size_of_coding; /* 4 or 8 */
+  int tileno, version, i, nmax, size_of_coding; /* 4 or 8 */
   opj_tile_info_t *tile_Idx;
   opj_packet_info_t packet;
   int resno, precno, layno, num_packet;
   int numOfres, numOfprec, numOflayers;
   OPJ_BYTE l_data_header [8];
+  OPJ_OFF_T lenp;
+  OPJ_UINT32 len;
+
   packet.end_ph_pos = packet.start_pos = -1;
   (void)EPHused; /* unused ? */
 
+
   if( j2klen > pow( 2, 32)){
     size_of_coding =  8;
     version = 1;
@@ -243,33 +112,21 @@ int write_phixfaix_v2( int coff, int compno, opj_codestream_info_t cstr_info, op
     version = 0;
   }
 
-#if 0
-  lenp = cio_tell( cio);
-  cio_skip( cio, 4);              /* L [at the end]      */
-  cio_write( cio, JPIP_FAIX, 4);  /* FAIX                */ 
-  cio_write( cio, version,1);     /* Version 0 = 4 bytes */
-#else
   lenp = opj_stream_tell(cio);
   opj_stream_skip(cio, 4, p_manager);         /* L [at the end]      */
   opj_write_bytes(l_data_header,JPIP_FAIX,4); /* FAIX */
   opj_stream_write_data(cio,l_data_header,4,p_manager);
   opj_write_bytes(l_data_header,version,1);   /* Version 0 = 4 bytes */
   opj_stream_write_data(cio,l_data_header,1,p_manager);
-#endif
 
   nmax = 0;
   for( i=0; i<=cstr_info.numdecompos[compno]; i++)
     nmax += cstr_info.tile[0].ph[i] * cstr_info.tile[0].pw[i] * cstr_info.numlayers;
   
-#if 0
-  cio_write( cio, nmax, size_of_coding); /* NMAX */
-  cio_write( cio, cstr_info.tw*cstr_info.th, size_of_coding);      /* M    */
-#else
   opj_write_bytes(l_data_header,nmax,size_of_coding);         /* NMAX           */
   opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
   opj_write_bytes(l_data_header,cstr_info.tw*cstr_info.th,size_of_coding);  /* M              */
   opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
-#endif
   
   for( tileno=0; tileno<cstr_info.tw*cstr_info.th; tileno++){
     tile_Idx = &cstr_info.tile[ tileno];
@@ -303,15 +160,10 @@ int write_phixfaix_v2( int coff, int compno, opj_codestream_info_t cstr_info, op
            fprintf( stderr, "failed to ppix indexing\n");
          }
 
-#if 0
-         cio_write( cio, packet.start_pos-coff, size_of_coding);                /* start position */
-         cio_write( cio, packet.end_ph_pos-packet.start_pos+1, size_of_coding); /* length         */
-#else
-    opj_write_bytes(l_data_header,packet.start_pos-coff,size_of_coding);            /* start position */
+    opj_write_bytes(l_data_header,(OPJ_UINT32)(packet.start_pos-coff),size_of_coding);            /* start position */
     opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
-    opj_write_bytes(l_data_header,packet.end_ph_pos-packet.start_pos+1,size_of_coding); /* length         */
+    opj_write_bytes(l_data_header,(OPJ_UINT32)(packet.end_ph_pos-packet.start_pos+1),size_of_coding); /* length         */
     opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
-#endif
          
          num_packet++;
        }
@@ -320,31 +172,19 @@ int write_phixfaix_v2( int coff, int compno, opj_codestream_info_t cstr_info, op
 
     /* PADDING */
     while( num_packet < nmax){
-#if 0
-      cio_write( cio, 0, size_of_coding); /* start position            */
-      cio_write( cio, 0, size_of_coding); /* length                    */
-#else
       opj_write_bytes(l_data_header,0,size_of_coding);/* start position            */
       opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
       opj_write_bytes(l_data_header,0,size_of_coding);/* length                    */
       opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
-#endif
       num_packet++;
     }
   }
 
-#if 0
-  len = cio_tell( cio)-lenp;
-  cio_seek( cio, lenp);
-  cio_write( cio, len, 4);        /* L  */
-  cio_seek( cio, lenp+len);
-#else
-  len = opj_stream_tell(cio)-lenp;
+  len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp);
   opj_stream_seek(cio, lenp,p_manager);
   opj_write_bytes(l_data_header,len,4);/* L  */
   opj_stream_write_data(cio,l_data_header,4,p_manager);
   opj_stream_seek(cio, lenp+len,p_manager);
-#endif
 
   return len;
 }
index ad1d934b60e0b3fd416b5a1ddeb87ecfda537dd0..a6c51eddb30fb2d0b34069a601ccc79e531c3958 100644 (file)
  * @param[in] cio       file output handle
  * @return              length of faix box
  */
-int write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio);
 
-int write_ppix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio)
-{
-  int len, lenp, compno, i;
-  opj_jp2_box_t *box;
-
-  /*  printf("cstr_info.packno %d\n", cstr_info.packno); //NMAX? */
-
-  lenp = -1;
-  box = (opj_jp2_box_t *)opj_calloc( cstr_info.numcomps, sizeof(opj_jp2_box_t));
-  
-  for (i=0;i<2;i++){
-    if (i) cio_seek( cio, lenp);
-    
-    lenp = cio_tell( cio);
-    cio_skip( cio, 4);              /* L [at the end] */
-    cio_write( cio, JPIP_PPIX, 4);  /* PPIX           */
 
-    write_manf( i, cstr_info.numcomps, box, cio);
-    
-    for (compno=0; compno<cstr_info.numcomps; compno++){
-      box[compno].length = write_ppixfaix( coff, compno, cstr_info, EPHused, j2klen, cio);
-      box[compno].type = JPIP_FAIX;
-    }
-   
-    len = cio_tell( cio)-lenp;
-    cio_seek( cio, lenp);
-    cio_write( cio, len, 4);        /* L              */
-    cio_seek( cio, lenp+len);
-  }
-  
-  opj_free(box);
-
-  return len;
-}
-
-int write_ppix_v2( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_stream_private_t *cio,
+int opj_write_ppix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_stream_private_t *cio,
               opj_event_mgr_t * p_manager )
 {
   OPJ_BYTE l_data_header [4];
-  int len, lenp, compno, i;
+  int compno, i;
   opj_jp2_box_t *box;
+  OPJ_OFF_T lenp;
+  OPJ_UINT32 len;
 
   /*  printf("cstr_info.packno %d\n", cstr_info.packno); //NMAX? */
 
@@ -97,42 +64,27 @@ int write_ppix_v2( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused,
   
   for (i=0;i<2;i++){
     if (i)
-#if 0
-      cio_seek( cio, lenp);
-#else
+
       opj_stream_seek( cio, lenp, p_manager);
-#endif
     
-#if 0
-    lenp = cio_tell( cio);
-    cio_skip( cio, 4);              /* L [at the end] */
-    cio_write( cio, JPIP_PPIX, 4);  /* PPIX           */
-#else
-    lenp = opj_stream_tell(cio);
+    lenp = (OPJ_UINT32)(opj_stream_tell(cio));
     opj_stream_skip( cio, 4, p_manager);       /* L [at the end] */
     opj_write_bytes(l_data_header,JPIP_PPIX,4);/* PPIX           */
     opj_stream_write_data(cio,l_data_header,4,p_manager);
-#endif
 
-    write_manf_v2( i, cstr_info.numcomps, box, cio);
+    opj_write_manf( i, cstr_info.numcomps, box, cio, p_manager);
     
     for (compno=0; compno<cstr_info.numcomps; compno++){
-      box[compno].length = write_ppixfaix_v2( coff, compno, cstr_info, EPHused, j2klen, cio,p_manager);
+      box[compno].length = opj_write_ppixfaix( coff, compno, cstr_info, EPHused, j2klen, cio,p_manager);
       box[compno].type = JPIP_FAIX;
     }
    
-#if 0
-    len = cio_tell( cio)-lenp;
-    cio_seek( cio, lenp);
-    cio_write( cio, len, 4);        /* L              */
-    cio_seek( cio, lenp+len);
-#else
-  len = opj_stream_tell(cio)-lenp;
+
+  len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp);
   opj_stream_seek(cio, lenp,p_manager);
   opj_write_bytes(l_data_header,len,4);/* L              */
   opj_stream_write_data(cio,l_data_header,4,p_manager);
   opj_stream_seek(cio, lenp+len,p_manager);
-#endif
   }
   
   opj_free(box);
@@ -140,97 +92,15 @@ int write_ppix_v2( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused,
   return len;
 }
 
-int write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_cio_t *cio)
-{
-  int len, lenp, tileno, version, i, nmax, size_of_coding; /* 4 or 8*/
-  opj_tile_info_t *tile_Idx;
-  opj_packet_info_t packet;
-  int resno, precno, layno, num_packet;
-  int numOfres, numOfprec, numOflayers;
-  packet.end_pos = packet.end_ph_pos = packet.start_pos = -1;
-  (void)EPHused; /* unused ? */
-
-  if( j2klen > pow( 2, 32)){
-    size_of_coding =  8;
-    version = 1;
-  }
-  else{
-    size_of_coding = 4;
-    version = 0;
-  }
-  
-  lenp = cio_tell( cio);
-  cio_skip( cio, 4);              /* L [at the end]      */
-  cio_write( cio, JPIP_FAIX, 4);  /* FAIX                */ 
-  cio_write( cio, version, 1);     /* Version 0 = 4 bytes */
-
-  nmax = 0;
-  for( i=0; i<=cstr_info.numdecompos[compno]; i++)
-    nmax += cstr_info.tile[0].ph[i] * cstr_info.tile[0].pw[i] * cstr_info.numlayers;
-  
-  cio_write( cio, nmax, size_of_coding); /* NMAX */
-  cio_write( cio, cstr_info.tw*cstr_info.th, size_of_coding);      /* M    */
-
-  for( tileno=0; tileno<cstr_info.tw*cstr_info.th; tileno++){
-    tile_Idx = &cstr_info.tile[ tileno];
-    num_packet=0;
-    numOfres = cstr_info.numdecompos[compno] + 1;
-  
-    for( resno=0; resno<numOfres ; resno++){
-      numOfprec = tile_Idx->pw[resno]*tile_Idx->ph[resno];
-      for( precno=0; precno<numOfprec; precno++){
-       numOflayers = cstr_info.numlayers;
-       for( layno=0; layno<numOflayers; layno++){
-
-         switch ( cstr_info.prog){
-         case LRCP:
-           packet = tile_Idx->packet[ ((layno*numOfres+resno)*cstr_info.numcomps+compno)*numOfprec+precno];
-           break;
-         case RLCP:
-           packet = tile_Idx->packet[ ((resno*numOflayers+layno)*cstr_info.numcomps+compno)*numOfprec+precno];
-           break;
-         case RPCL:
-           packet = tile_Idx->packet[ ((resno*numOfprec+precno)*cstr_info.numcomps+compno)*numOflayers+layno];
-           break;
-         case PCRL:
-           packet = tile_Idx->packet[ ((precno*cstr_info.numcomps+compno)*numOfres+resno)*numOflayers + layno];
-           break;
-         case CPRL:
-           packet = tile_Idx->packet[ ((compno*numOfprec+precno)*numOfres+resno)*numOflayers + layno];
-           break;
-         default:
-           fprintf( stderr, "failed to ppix indexing\n");
-         }
-
-         cio_write( cio, packet.start_pos-coff, size_of_coding);             /* start position */
-         cio_write( cio, packet.end_pos-packet.start_pos+1, size_of_coding); /* length         */
-         
-         num_packet++;
-       }
-      }
-    }
-  
-    while( num_packet < nmax){     /* PADDING */
-      cio_write( cio, 0, size_of_coding); /* start position            */
-      cio_write( cio, 0, size_of_coding); /* length                    */
-      num_packet++;
-    }   
-  }
-
-  len = cio_tell( cio)-lenp;
-  cio_seek( cio, lenp);
-  cio_write( cio, len, 4);        /* L  */
-  cio_seek( cio, lenp+len);
 
-  return len;
-}
 
-int write_ppixfaix_v2( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_stream_private_t *cio,
+int opj_write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_stream_private_t *cio,
               opj_event_mgr_t * p_manager )
 {
   OPJ_BYTE l_data_header [8];
-  int len, lenp, tileno, version, i, nmax, size_of_coding; /* 4 or 8*/
+  int tileno, version, i, nmax, size_of_coding; /* 4 or 8*/
+  OPJ_UINT32 len;
+  OPJ_OFF_T lenp;
   opj_tile_info_t *tile_Idx;
   opj_packet_info_t packet;
   int resno, precno, layno, num_packet;
@@ -247,32 +117,20 @@ int write_ppixfaix_v2( int coff, int compno, opj_codestream_info_t cstr_info, op
     version = 0;
   }
   
-#if 0
-  lenp = cio_tell( cio);
-  cio_skip( cio, 4);              /* L [at the end]      */
-  cio_write( cio, JPIP_FAIX, 4);  /* FAIX                */ 
-  cio_write( cio, version, 1);     /* Version 0 = 4 bytes */
-#else
   lenp = opj_stream_tell(cio);
   opj_stream_skip(cio, 4, p_manager);         /* L [at the end]      */
   opj_write_bytes(l_data_header,JPIP_FAIX,4); /* FAIX */
   opj_write_bytes(l_data_header,version,1);
   opj_stream_write_data(cio,l_data_header,1,p_manager);/* Version 0 = 4 bytes */
-#endif
 
   nmax = 0;
   for( i=0; i<=cstr_info.numdecompos[compno]; i++)
     nmax += cstr_info.tile[0].ph[i] * cstr_info.tile[0].pw[i] * cstr_info.numlayers;
   
-#if 0
-  cio_write( cio, nmax, size_of_coding); /* NMAX */
-  cio_write( cio, cstr_info.tw*cstr_info.th, size_of_coding);      /* M    */
-#else
   opj_write_bytes(l_data_header,nmax,size_of_coding);         /* NMAX           */
   opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
   opj_write_bytes(l_data_header,cstr_info.tw*cstr_info.th,size_of_coding);  /* M              */
   opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
-#endif
 
   for( tileno=0; tileno<cstr_info.tw*cstr_info.th; tileno++){
     tile_Idx = &cstr_info.tile[ tileno];
@@ -306,15 +164,10 @@ int write_ppixfaix_v2( int coff, int compno, opj_codestream_info_t cstr_info, op
            fprintf( stderr, "failed to ppix indexing\n");
          }
 
-#if 0
-         cio_write( cio, packet.start_pos-coff, size_of_coding);             /* start position */
-         cio_write( cio, packet.end_pos-packet.start_pos+1, size_of_coding); /* length         */
-#else
-    opj_write_bytes(l_data_header,packet.start_pos-coff,size_of_coding);            /* start position */
+    opj_write_bytes(l_data_header,(OPJ_UINT32)(packet.start_pos-coff),size_of_coding);            /* start position */
     opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
-    opj_write_bytes(l_data_header,packet.end_pos-packet.start_pos+1,size_of_coding); /* length         */
+    opj_write_bytes(l_data_header,(OPJ_UINT32)(packet.end_pos-packet.start_pos+1),size_of_coding); /* length         */
     opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
-#endif
          
          num_packet++;
        }
@@ -322,31 +175,19 @@ int write_ppixfaix_v2( int coff, int compno, opj_codestream_info_t cstr_info, op
     }
   
     while( num_packet < nmax){     /* PADDING */
-#if 0
-      cio_write( cio, 0, size_of_coding); /* start position            */
-      cio_write( cio, 0, size_of_coding); /* length                    */
-#else
       opj_write_bytes(l_data_header,0,size_of_coding);/* start position            */
       opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
       opj_write_bytes(l_data_header,0,size_of_coding);/* length                    */
       opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
-#endif
       num_packet++;
     }   
   }
 
-#if 0
-  len = cio_tell( cio)-lenp;
-  cio_seek( cio, lenp);
-  cio_write( cio, len, 4);        /* L  */
-  cio_seek( cio, lenp+len);
-#else
-  len = opj_stream_tell(cio)-lenp;
+  len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp);
   opj_stream_seek(cio, lenp,p_manager);
   opj_write_bytes(l_data_header,len,4);/* L  */
   opj_stream_write_data(cio,l_data_header,4,p_manager);
   opj_stream_seek(cio, lenp+len,p_manager);
-#endif
 
   return len;
 }
index fe584cbcbc8d19b4e2d4b123ef99d6b27b57fb46..229676ef2cd6b1b0493be069446862fb2c03c781 100644 (file)
 
 #include "opj_includes.h"
 
-/* 
- * Write tile-part headers mhix box
- *
- * @param[in] coff      offset of j2k codestream
- * @param[in] cstr_info codestream information
- * @param[in] tileno    tile number
- * @param[in] cio       file output handle
- * @return              length of mhix box
- */
-int write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, opj_cio_t *cio);
-
-int write_thix( int coff, opj_codestream_info_t cstr_info, opj_cio_t *cio)
-{
-  int len, lenp, i;
-  int tileno;
-  opj_jp2_box_t *box;
-
-  lenp = 0;
-  box = (opj_jp2_box_t *)opj_calloc( cstr_info.tw*cstr_info.th, sizeof(opj_jp2_box_t));
 
-  for ( i = 0; i < 2 ; i++ ){
-    if (i)
-      cio_seek( cio, lenp);
-
-    lenp = cio_tell( cio);
-    cio_skip( cio, 4);              /* L [at the end] */
-    cio_write( cio, JPIP_THIX, 4);  /* THIX           */
-    write_manf( i, cstr_info.tw*cstr_info.th, box, cio);
-    
-    for (tileno = 0; tileno < cstr_info.tw*cstr_info.th; tileno++){
-      box[tileno].length = write_tilemhix( coff, cstr_info, tileno, cio);
-      box[tileno].type = JPIP_MHIX;
-    }
-    len = cio_tell( cio)-lenp;
-    cio_seek( cio, lenp);
-    cio_write( cio, len, 4);        /* L              */
-    cio_seek( cio, lenp+len);
-  }
-
-  opj_free(box);
-
-  return len;
-}
 
-int write_thix_v2( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio,
+int opj_write_thix( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio,
               opj_event_mgr_t * p_manager )
 {
   OPJ_BYTE l_data_header [4];
-  int len, lenp, i;
+  int i;
   int tileno;
   opj_jp2_box_t *box;
+  OPJ_UINT32 len;
+  OPJ_OFF_T lenp;
 
   lenp = 0;
   box = (opj_jp2_box_t *)opj_calloc( cstr_info.tw*cstr_info.th, sizeof(opj_jp2_box_t));
 
   for ( i = 0; i < 2 ; i++ ){
     if (i)
-#if 0
-      cio_seek( cio, lenp);
-#else
       opj_stream_seek( cio, lenp, p_manager);
-#endif
 
-#if 0
-    lenp = cio_tell( cio);
-    cio_skip( cio, 4);              /* L [at the end] */
-    cio_write( cio, JPIP_THIX, 4);  /* THIX           */
-#else
     lenp = opj_stream_tell(cio);
     opj_stream_skip(cio, 4, p_manager);             /* L [at the end] */
     opj_write_bytes(l_data_header,JPIP_THIX,4); /* THIX */
     opj_stream_write_data(cio,l_data_header,4,p_manager);
-#endif
-    write_manf_v2( i, cstr_info.tw*cstr_info.th, box, cio);
+
+    opj_write_manf( i, cstr_info.tw*cstr_info.th, box, cio, p_manager);
     
     for (tileno = 0; tileno < cstr_info.tw*cstr_info.th; tileno++){
-      box[tileno].length = write_tilemhix_v2( coff, cstr_info, tileno, cio,p_manager);
+      box[tileno].length = opj_write_tilemhix( coff, cstr_info, tileno, cio,p_manager);
       box[tileno].type = JPIP_MHIX;
     }
  
-#if 0
-    len = cio_tell( cio)-lenp;
-    cio_seek( cio, lenp);
-    cio_write( cio, len, 4);        /* L              */
-    cio_seek( cio, lenp+len);
-#else
-    len = opj_stream_tell(cio)-lenp;
+    len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp);
     opj_stream_seek(cio, lenp, p_manager);
     opj_write_bytes(l_data_header,len,4); /* L              */
     opj_stream_write_data(cio,l_data_header,4,p_manager);
     opj_stream_seek( cio, lenp+len,p_manager);
-#endif
-  }
-
-  opj_free(box);
-
-  return len;
-}
-
-int write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, opj_cio_t *cio)
-{
-  int i;
-  opj_tile_info_t tile;
-  opj_tp_info_t tp;
-  int marknum;
-  int len, lenp;
-  opj_marker_info_t *marker;
-
-  lenp = cio_tell( cio);
-  cio_skip( cio, 4);                               /* L [at the end]                    */
-  cio_write( cio, JPIP_MHIX, 4);                   /* MHIX                              */
-
-  tile = cstr_info.tile[tileno];
-  tp = tile.tp[0];
 
-  cio_write( cio, tp.tp_end_header-tp.tp_start_pos+1, 8);  /* TLEN                              */ 
-
-  marker = cstr_info.tile[tileno].marker;
-
-  for( i=0; i<cstr_info.tile[tileno].marknum; i++){             /* Marker restricted to 1 apparition */
-    cio_write( cio, marker[i].type, 2);
-    cio_write( cio, 0, 2);
-    cio_write( cio, marker[i].pos-coff, 8);
-    cio_write( cio, marker[i].len, 2);
   }
-     
-  /*  free( marker);*/
 
-  len = cio_tell( cio) - lenp;
-  cio_seek( cio, lenp);
-  cio_write( cio, len, 4);        /* L           */
-  cio_seek( cio, lenp+len);
+  opj_free(box);
 
   return len;
 }
 
-int write_tilemhix_v2( int coff, opj_codestream_info_t cstr_info, int tileno, opj_stream_private_t *cio,
+/* 
+ * Write tile-part headers mhix box
+ *
+ * @param[in] coff      offset of j2k codestream
+ * @param[in] cstr_info codestream information
+ * @param[in] tileno    tile number
+ * @param[in] cio       file output handle
+ * @return              length of mhix box
+ */
+int opj_write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, opj_stream_private_t *cio,
               opj_event_mgr_t * p_manager )
 {
   OPJ_BYTE l_data_header [8];
   int i;
   opj_tile_info_t tile;
   opj_tp_info_t tp;
-  int marknum;
-  int len, lenp;
   opj_marker_info_t *marker;
+  OPJ_UINT32 len;
+  OPJ_OFF_T lenp;
 
-#if 0
-  lenp = cio_tell( cio);
-  cio_skip( cio, 4);                               /* L [at the end]                    */
-  cio_write( cio, JPIP_MHIX, 4);                   /* MHIX                              */
-#else
   lenp = opj_stream_tell (cio);
   opj_stream_skip(cio, 4, p_manager);               /* L [at the end]                    */
   opj_write_bytes(l_data_header,JPIP_MHIX,4);       /* MHIX                              */
   opj_stream_write_data(cio,l_data_header,4,p_manager);
-#endif
 
   tile = cstr_info.tile[tileno];
   tp = tile.tp[0];
 
-#if 0
-  cio_write( cio, tp.tp_end_header-tp.tp_start_pos+1, 8);  /* TLEN                              */ 
-#else
   opj_write_bytes(l_data_header,tp.tp_end_header-tp.tp_start_pos+1, 8);        /* TLEN                              */
   opj_stream_write_data(cio,l_data_header,8,p_manager);
-#endif
 
   marker = cstr_info.tile[tileno].marker;
 
   for( i=0; i<cstr_info.tile[tileno].marknum; i++){             /* Marker restricted to 1 apparition */
-#if 0
-    cio_write( cio, marker[i].type, 2);
-    cio_write( cio, 0, 2);
-    cio_write( cio, marker[i].pos-coff, 8);
-    cio_write( cio, marker[i].len, 2);
-#else
     opj_write_bytes( l_data_header, marker[i].type, 2);
     opj_write_bytes( l_data_header+2, 0, 2);
     opj_stream_write_data(cio,l_data_header,4,p_manager);
-    opj_write_bytes( l_data_header, marker[i].pos-coff, 8);
+    opj_write_bytes( l_data_header, (OPJ_UINT32)(marker[i].pos-coff), 8);
     opj_stream_write_data(cio,l_data_header,8,p_manager);
     opj_write_bytes( l_data_header, marker[i].len, 2);
     opj_stream_write_data(cio,l_data_header,2,p_manager);
-#endif
   }
      
   /*  free( marker);*/
 
-#if 0
-  len = cio_tell( cio) - lenp;
-  cio_seek( cio, lenp);
-  cio_write( cio, len, 4);        /* L           */
-  cio_seek( cio, lenp+len);
-#else
-  len = opj_stream_tell(cio)-lenp;
+  len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp);
   opj_stream_seek(cio, lenp,p_manager);
   opj_write_bytes(l_data_header,len,4);/* L  */
   opj_stream_write_data(cio,l_data_header,4,p_manager);
   opj_stream_seek(cio, lenp+len,p_manager);
-#endif
 
   return len;
 }
index 0c58a32915b08167aa7d2520e2702e99be5070a2..429f5089f89bdda05a656698bd13c03cc7b9712e 100644 (file)
 
 #define MAX(a,b) ((a)>(b)?(a):(b))
 
+/* 
+ * Get number of maximum tile parts per tile
+ *
+ * @param[in] cstr_info codestream information
+ * @return              number of maximum tile parts per tile
+ */
+int get_num_max_tile_parts( opj_codestream_info_t cstr_info);
+
 
 /* 
  * Write faix box of tpix
  * @param[in] cio       file output handle
  * @return              length of faix box
  */
-int write_tpixfaix( int coff, int compno, opj_codestream_info_t cstr_info, int j2klen, opj_cio_t *cio);
-
 
-int write_tpix( int coff, opj_codestream_info_t cstr_info, int j2klen, opj_cio_t *cio)
-{
-  int len, lenp;
-  lenp = cio_tell( cio);
-  cio_skip( cio, 4);              /* L [at the end] */
-  cio_write( cio, JPIP_TPIX, 4);  /* TPIX           */
-  
-  write_tpixfaix( coff, 0, cstr_info, j2klen, cio);
-
-  len = cio_tell( cio)-lenp;
-  cio_seek( cio, lenp);
-  cio_write( cio, len, 4);        /* L              */
-  cio_seek( cio, lenp+len);
-
-  return len;
-}
-
-int write_tpix_v2( int coff, opj_codestream_info_t cstr_info, int j2klen, opj_stream_private_t *cio,
-              opj_event_mgr_t * p_manager )
+int opj_write_tpix( int coff, 
+                    opj_codestream_info_t cstr_info, 
+                    int j2klen, opj_stream_private_t *cio,
+                    opj_event_mgr_t * p_manager )
 {
   OPJ_BYTE l_data_header [4];
-  int len, lenp;
-#if 0
-  lenp = cio_tell( cio);
-  cio_skip( cio, 4);              /* L [at the end] */
-  cio_write( cio, JPIP_TPIX, 4);  /* TPIX           */
-#else
+  OPJ_UINT32 len;
+  OPJ_OFF_T lenp;
+
   lenp = opj_stream_tell(cio);
   opj_stream_skip(cio, 4, p_manager);
   opj_write_bytes(l_data_header,JPIP_TPIX,4); /* TPIX */
   opj_stream_write_data(cio,l_data_header,4,p_manager);
-#endif
   
-  write_tpixfaix_v2( coff, 0, cstr_info, j2klen, cio,p_manager);
+  opj_write_tpixfaix( coff, 0, cstr_info, j2klen, cio,p_manager);
 
-#if 0
-  len = cio_tell( cio)-lenp;
-  cio_seek( cio, lenp);
-  cio_write( cio, len, 4);        /* L              */
-  cio_seek( cio, lenp+len);
-#else
-  len = opj_stream_tell(cio)-lenp;
+  len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp);
   opj_stream_skip(cio, lenp, p_manager);
   opj_write_bytes(l_data_header,len,4);/* L              */
   opj_stream_write_data(cio,l_data_header,4,p_manager);
   opj_stream_seek(cio, lenp+len,p_manager);
-#endif
-
-  return len;
-}
-
-/* 
- * Get number of maximum tile parts per tile
- *
- * @param[in] cstr_info codestream information
- * @return              number of maximum tile parts per tile
- */
-int get_num_max_tile_parts( opj_codestream_info_t cstr_info);
-
-int write_tpixfaix( int coff, int compno, opj_codestream_info_t cstr_info, int j2klen, opj_cio_t *cio)
-{
-  int len, lenp;
-  int i, j;
-  int Aux;
-  int num_max_tile_parts;
-  int size_of_coding; /* 4 or 8 */
-  opj_tp_info_t tp;
-  int version;
-
-  num_max_tile_parts = get_num_max_tile_parts( cstr_info);
-
-  if( j2klen > pow( 2, 32)){
-    size_of_coding =  8;
-    version = num_max_tile_parts == 1 ? 1:3;
-  }
-  else{
-    size_of_coding = 4;
-    version = num_max_tile_parts == 1 ? 0:2;
-  }
-
-  lenp = cio_tell( cio);
-  cio_skip( cio, 4);              /* L [at the end]      */
-  cio_write( cio, JPIP_FAIX, 4);  /* FAIX                */ 
-  cio_write( cio, version, 1);     /* Version 0 = 4 bytes */
-
-  cio_write( cio, num_max_tile_parts, size_of_coding);                      /* NMAX           */
-  cio_write( cio, cstr_info.tw*cstr_info.th, size_of_coding);                               /* M              */
-  for (i = 0; i < cstr_info.tw*cstr_info.th; i++){
-    for (j = 0; j < cstr_info.tile[i].num_tps; j++){
-      tp = cstr_info.tile[i].tp[j];
-      cio_write( cio, tp.tp_start_pos-coff, size_of_coding); /* start position */
-      cio_write( cio, tp.tp_end_pos-tp.tp_start_pos+1, size_of_coding);    /* length         */
-      if (version & 0x02){
-  if( cstr_info.tile[i].num_tps == 1 && cstr_info.numdecompos[compno] > 1)
-    Aux = cstr_info.numdecompos[compno] + 1;
-  else
-    Aux = j + 1;
-      
-  cio_write( cio, Aux,4);
-  /*cio_write(img.tile[i].tile_parts[j].num_reso_AUX,4);*/ /* Aux_i,j : Auxiliary value */
-  /* fprintf(stderr,"AUX value %d\n",Aux);*/
-      }
-      /*cio_write(0,4);*/
-    }
-    /* PADDING */
-    while (j < num_max_tile_parts){
-      cio_write( cio, 0, size_of_coding); /* start position            */
-      cio_write( cio, 0, size_of_coding); /* length                    */
-      if (version & 0x02)
-  cio_write( cio, 0,4);                  /* Aux_i,j : Auxiliary value */
-      j++;
-    }
-  }
-  
-  len = cio_tell( cio)-lenp;
-  cio_seek( cio, lenp);
-  cio_write( cio, len, 4);        /* L  */
-  cio_seek( cio, lenp+len);
 
   return len;
-
 }
 
-int write_tpixfaix_v2( int coff, int compno, opj_codestream_info_t cstr_info, int j2klen, opj_stream_private_t *cio,
-              opj_event_mgr_t * p_manager )
+int opj_write_tpixfaix( int coff,
+                        int compno, 
+                        opj_codestream_info_t cstr_info, 
+                        int j2klen, 
+                        opj_stream_private_t *cio,
+                        opj_event_mgr_t * p_manager )
 {
-  int len, lenp;
+  OPJ_UINT32 len;
+  OPJ_OFF_T lenp;
   int i, j;
   int Aux;
   int num_max_tile_parts;
@@ -197,43 +111,29 @@ int write_tpixfaix_v2( int coff, int compno, opj_codestream_info_t cstr_info, in
     version = num_max_tile_parts == 1 ? 0:2;
   }
 
-#if 0
-  lenp = cio_tell( cio);
-  cio_skip( cio, 4);              /* L [at the end]      */
-  cio_write( cio, JPIP_FAIX, 4);  /* FAIX                */ 
-  cio_write( cio, version, 1);     /* Version 0 = 4 bytes */
-#else
   lenp = opj_stream_tell(cio);
   opj_stream_skip(cio, 4, p_manager);         /* L [at the end]      */
   opj_write_bytes(l_data_header,JPIP_FAIX,4); /* FAIX */
   opj_stream_write_data(cio,l_data_header,4,p_manager);
   opj_write_bytes(l_data_header,version,1);   /* Version 0 = 4 bytes */
   opj_stream_write_data(cio,l_data_header,1,p_manager);
-#endif
 
-#if 0
-  cio_write( cio, num_max_tile_parts, size_of_coding);                      /* NMAX           */
-  cio_write( cio, cstr_info.tw*cstr_info.th, size_of_coding);               /* M              */
-#else
   opj_write_bytes(l_data_header,num_max_tile_parts,size_of_coding);         /* NMAX           */
   opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
   opj_write_bytes(l_data_header,cstr_info.tw*cstr_info.th,size_of_coding);  /* M              */
   opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
-#endif
+
   for (i = 0; i < cstr_info.tw*cstr_info.th; i++)
     {
     for (j = 0; j < cstr_info.tile[i].num_tps; j++)
       {
       tp = cstr_info.tile[i].tp[j];
-#if 0
-      cio_write( cio, tp.tp_start_pos-coff, size_of_coding); /* start position */
-      cio_write( cio, tp.tp_end_pos-tp.tp_start_pos+1, size_of_coding);    /* length         */
-#else
+
       opj_write_bytes(l_data_header,tp.tp_start_pos-coff,size_of_coding);            /* start position */
       opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
       opj_write_bytes(l_data_header,tp.tp_end_pos-tp.tp_start_pos+1,size_of_coding); /* length         */
       opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
-#endif
+
       if (version & 0x02)
         {
         if( cstr_info.tile[i].num_tps == 1 && cstr_info.numdecompos[compno] > 1)
@@ -241,12 +141,9 @@ int write_tpixfaix_v2( int coff, int compno, opj_codestream_info_t cstr_info, in
         else
           Aux = j + 1;
 
-#if 0
-        cio_write( cio, Aux,4);
-#else
         opj_write_bytes(l_data_header,Aux,4);
         opj_stream_write_data(cio,l_data_header,4,p_manager);
-#endif
+
         /*cio_write(img.tile[i].tile_parts[j].num_reso_AUX,4);*/ /* Aux_i,j : Auxiliary value */
         /* fprintf(stderr,"AUX value %d\n",Aux);*/
         }
@@ -255,38 +152,24 @@ int write_tpixfaix_v2( int coff, int compno, opj_codestream_info_t cstr_info, in
     /* PADDING */
     while (j < num_max_tile_parts)
       {
-#if 0
-      cio_write( cio, 0, size_of_coding); /* start position            */
-      cio_write( cio, 0, size_of_coding); /* length                    */
-#else
-      opj_write_bytes(l_data_header,0,size_of_coding);/* start position            */
+
+          opj_write_bytes(l_data_header,0,size_of_coding);/* start position            */
       opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
       opj_write_bytes(l_data_header,0,size_of_coding);/* length                    */
       opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
-#endif
+
       if (version & 0x02)
-#if 0
-        cio_write( cio, 0,4);                  /* Aux_i,j : Auxiliary value */
-#else
       opj_write_bytes(l_data_header,0,4);      /* Aux_i,j : Auxiliary value */
       opj_stream_write_data(cio,l_data_header,4,p_manager);
-#endif
       j++;
       }
     }
   
-#if 0
-  len = cio_tell( cio)-lenp;
-  cio_seek( cio, lenp);
-  cio_write( cio, len, 4);        /* L  */
-  cio_seek( cio, lenp+len);
-#else
-  len = opj_stream_tell(cio)-lenp;
+  len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp);
   opj_stream_seek(cio, lenp,p_manager);
   opj_write_bytes(l_data_header,len,4);/* L  */
   opj_stream_write_data(cio,l_data_header,4,p_manager);
   opj_stream_seek(cio, lenp+len,p_manager);
-#endif
 
   return len;
 }