From ee8ee69c30ffe3854c84adf13908c2d4b6de5ee1 Mon Sep 17 00:00:00 2001 From: Mickael Savinaud Date: Thu, 25 Oct 2012 13:15:37 +0000 Subject: [PATCH] [trunk]clean jpip marker functions but it is still experimental --- src/lib/openjp2/cidx_manager.c | 306 ++++------------------------- src/lib/openjp2/cidx_manager.h | 14 +- src/lib/openjp2/indexbox_manager.h | 37 ++-- src/lib/openjp2/phix_manager.c | 190 ++---------------- src/lib/openjp2/ppix_manager.c | 193 ++---------------- src/lib/openjp2/thix_manager.c | 206 +++++-------------- src/lib/openjp2/tpix_manager.c | 185 ++++------------- 7 files changed, 187 insertions(+), 944 deletions(-) diff --git a/src/lib/openjp2/cidx_manager.c b/src/lib/openjp2/cidx_manager.c index 0c6c669e..7fb6f1b9 100644 --- a/src/lib/openjp2/cidx_manager.c +++ b/src/lib/openjp2/cidx_manager.c @@ -39,99 +39,20 @@ * @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; + 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_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 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> 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; } diff --git a/src/lib/openjp2/cidx_manager.h b/src/lib/openjp2/cidx_manager.h index 17925505..6c3000ba 100644 --- a/src/lib/openjp2/cidx_manager.h +++ b/src/lib/openjp2/cidx_manager.h @@ -50,11 +50,19 @@ * @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_ */ diff --git a/src/lib/openjp2/indexbox_manager.h b/src/lib/openjp2/indexbox_manager.h index d468e72f..5c309cb1 100644 --- a/src/lib/openjp2/indexbox_manager.h +++ b/src/lib/openjp2/indexbox_manager.h @@ -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_ */ diff --git a/src/lib/openjp2/phix_manager.c b/src/lib/openjp2/phix_manager.c index bb15ed37..7bb7fe98 100644 --- a/src/lib/openjp2/phix_manager.c +++ b/src/lib/openjp2/phix_manager.c @@ -47,87 +47,38 @@ * @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 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; tilenopw[resno]*tile_Idx->ph[resno]; - for( precno=0; precnopacket[ ((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 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; tilenopw[resno]*tile_Idx->ph[resno]; - for( precno=0; precnopacket[ ((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(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 @@ -48,136 +56,42 @@ * @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 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; - 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 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; }