[trunk]clean jpip marker functions but it is still experimental

This commit is contained in:
Mickael Savinaud 2012-10-25 13:15:37 +00:00
parent 4941ebcc91
commit ee8ee69c30
7 changed files with 187 additions and 944 deletions

View File

@ -39,99 +39,20 @@
* @param[in] clen length of j2k codestream * @param[in] clen length of j2k codestream
* @param[in] cio file output handle * @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 ); 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 opj_write_cidx( int offset, opj_stream_private_t *cio, 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,
opj_event_mgr_t * p_manager ) opj_event_mgr_t * p_manager )
{ {
int len, i, lenp; int i;
OPJ_OFF_T lenp;
OPJ_UINT32 len;
opj_jp2_box_t *box; opj_jp2_box_t *box;
int num_box = 0; int num_box = 0;
opj_bool EPHused; 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); lenp = opj_stream_tell (cio);
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */ 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_write_bytes(l_data_header,JPIP_CIDX,4); /* CIDX */
opj_stream_write_data(cio,l_data_header,4,p_manager); 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; 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; box[num_box].type = JPIP_MHIX;
num_box++; 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; box[num_box].type = JPIP_TPIX;
num_box++; 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; box[num_box].type = JPIP_THIX;
num_box++; 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; box[num_box].type = JPIP_PPIX;
num_box++; 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; box[num_box].type = JPIP_PHIX;
num_box++; num_box++;
#if 0 len = (OPJ_UINT32) (opj_stream_tell(cio)-lenp);
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;
opj_stream_seek(cio, lenp,p_manager); opj_stream_seek(cio, lenp,p_manager);
opj_write_bytes(l_data_header,len,4);/* L */ opj_write_bytes(l_data_header,len,4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager); opj_stream_seek(cio, lenp+len,p_manager);
#endif
} }
opj_free( box); opj_free( box);
@ -201,42 +113,16 @@ int write_cidx_v2( int offset, opj_stream_private_t *cio, opj_codestream_info_t
return len; 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_event_mgr_t * p_manager )
{ {
OPJ_BYTE l_data_header [3*8]; 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); lenp = opj_stream_tell(cio);
opj_stream_skip( cio, 4, p_manager); /* L [at the end] */ opj_stream_skip( cio, 4, p_manager); /* L [at the end] */
opj_write_bytes( l_data_header, JPIP_CPTR, 4); /* T */ 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_write_bytes( l_data_header+16, clen, 8); /* CLEN */
opj_stream_write_data(cio,l_data_header,3*8,p_manager); 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_stream_seek(cio,lenp,p_manager);
opj_write_bytes(l_data_header, len, 4); /* L */ opj_write_bytes(l_data_header, len, 4); /* L */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,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; void opj_write_manf(int second,
cio_seek( cio, lenp); int v,
cio_write( cio, len, 4); /* L */ opj_jp2_box_t *box,
cio_seek( cio, lenp+len); 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 )
{ {
OPJ_BYTE l_data_header [4]; 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); lenp = opj_stream_tell(cio);
opj_stream_skip( cio, 4, p_manager); /* L [at the end] */ opj_stream_skip( cio, 4, p_manager); /* L [at the end] */
opj_write_bytes( l_data_header, JPIP_MANF, 4); /* T */ opj_write_bytes( l_data_header, JPIP_MANF, 4); /* T */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
#endif
if (second){ /* Write only during the second pass */ if (second){ /* Write only during the second pass */
for( i=0; i<v; i++){ 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_write_bytes( l_data_header, box[i].length, 4); /* Box length */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_bytes( l_data_header, box[i].type, 4); /* Box type */ opj_write_bytes( l_data_header, box[i].type, 4); /* Box type */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
#endif
} }
} }
#if 0 len = (OPJ_UINT32) (opj_stream_tell(cio) - lenp);
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;
opj_stream_seek(cio,lenp,p_manager); opj_stream_seek(cio,lenp,p_manager);
opj_write_bytes(l_data_header, len, 4);/* L */ opj_write_bytes(l_data_header, len, 4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio,lenp+len,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 */ int opj_write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio,
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,
opj_event_mgr_t * p_manager ) opj_event_mgr_t * p_manager )
{ {
OPJ_BYTE l_data_header [8]; OPJ_BYTE l_data_header [8];
int i; 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); lenp = opj_stream_tell (cio);
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */ opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
opj_write_bytes(l_data_header,JPIP_MHIX,4); /* MHIX */ opj_write_bytes(l_data_header,JPIP_MHIX,4); /* MHIX */
opj_stream_write_data(cio,l_data_header,4,p_manager); 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_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); 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 */ 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, cstr_info.marker[i].type, 2);
opj_write_bytes( l_data_header+2, 0, 2); opj_write_bytes( l_data_header+2, 0, 2);
opj_stream_write_data(cio,l_data_header,4,p_manager); 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_stream_write_data(cio,l_data_header,8,p_manager);
opj_write_bytes( l_data_header, cstr_info.marker[i].len, 2); opj_write_bytes( l_data_header, cstr_info.marker[i].len, 2);
opj_stream_write_data(cio,l_data_header,2,p_manager); opj_stream_write_data(cio,l_data_header,2,p_manager);
#endif
} }
#if 0 len = (OPJ_UINT32) (opj_stream_tell(cio)-lenp);
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;
opj_stream_seek(cio, lenp,p_manager); opj_stream_seek(cio, lenp,p_manager);
opj_write_bytes(l_data_header,len,4);/* L */ opj_write_bytes(l_data_header,len,4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager); opj_stream_seek(cio, lenp+len,p_manager);
#endif
return len; return len;
} }
opj_bool check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_cio_t *cio) opj_bool opj_check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_stream_private_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_event_mgr_t * p_manager ) opj_event_mgr_t * p_manager )
{ {
OPJ_BYTE l_data_header [4]; OPJ_BYTE l_data_header [4];
opj_bool EPHused = OPJ_FALSE; opj_bool EPHused = OPJ_FALSE;
int i=0; int i=0;
int org_pos; OPJ_OFF_T org_pos;
unsigned int Scod; unsigned int Scod;
for(i = 0; i < marknum; i++) for(i = 0; i < marknum; i++)
{ {
if( markers[i].type == J2K_MS_COD) 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); org_pos = opj_stream_tell(cio);
opj_stream_seek(cio, coff+markers[i].pos+2,p_manager); 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_stream_read_data(cio,l_data_header,1,p_manager);
opj_read_bytes(l_data_header,&Scod,1); opj_read_bytes(l_data_header,&Scod,1);
#endif
if( ((Scod >> 2) & 1)) if( ((Scod >> 2) & 1))
EPHused = OPJ_TRUE; EPHused = OPJ_TRUE;
#if 0
cio_seek( cio, org_pos);
#else
opj_stream_seek( cio, org_pos, p_manager); opj_stream_seek( cio, org_pos, p_manager);
#endif
break; break;
} }

View File

@ -50,11 +50,19 @@
* @param[in] j2klen length of j2k codestream * @param[in] j2klen length of j2k codestream
* @return length of cidx box * @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 opj_write_cidx( int offset, opj_stream_private_t *cio, 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,
opj_event_mgr_t * p_manager ); 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 ); opj_event_mgr_t * p_manager );
#endif /* !CIDX_MANAGER_H_ */ #endif /* !CIDX_MANAGER_H_ */

View File

@ -65,8 +65,7 @@
* @param[in] cio file output handle * @param[in] cio file output handle
* @return length of tpix box * @return length of tpix box
*/ */
int write_tpix( int coff, opj_codestream_info_t cstr_info, int j2klen, opj_cio_t *cio); int opj_write_tpix( int coff, opj_codestream_info_t cstr_info, int j2klen, opj_stream_private_t *cio,
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 ); 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 * @param[in] cio file output handle
* @return length of thix box * @return length of thix box
*/ */
int write_thix( int coff, opj_codestream_info_t cstr_info, opj_cio_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 );
int write_thix_v2( 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 * @param[in] cio file output handle
* @return length of ppix box * @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 opj_write_ppix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_stream_private_t *cio,
int write_ppix_v2( 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_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 * @param[in] cio file output handle
* @return length of ppix box * @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 opj_write_phix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_stream_private_t *cio,
int write_phix_v2( 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_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] box box to be manifested
* @param[in] cio file output handle * @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 ); 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 ); 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 ); 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 ); 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 ); opj_event_mgr_t * p_manager );
#endif /* !INDEXBOX_MANAGER_H_ */ #endif /* !INDEXBOX_MANAGER_H_ */

View File

@ -47,87 +47,38 @@
* @param[in] cio file output handle * @param[in] cio file output handle
* @return length of faix box * @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 opj_write_phix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_stream_private_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,
opj_event_mgr_t * p_manager ) opj_event_mgr_t * p_manager )
{ {
OPJ_BYTE l_data_header [8]; OPJ_BYTE l_data_header [8];
int len, lenp=0, compno, i; int len, compno, i;
opj_jp2_box_t *box; opj_jp2_box_t *box;
OPJ_OFF_T lenp;
box = (opj_jp2_box_t *)opj_calloc( cstr_info.numcomps, sizeof(opj_jp2_box_t)); box = (opj_jp2_box_t *)opj_calloc( cstr_info.numcomps, sizeof(opj_jp2_box_t));
for( i=0;i<2;i++){ for( i=0;i<2;i++){
if (i) if (i)
#if 0
cio_seek( cio, lenp);
#else
opj_stream_seek( cio, lenp, p_manager); 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); lenp = opj_stream_tell(cio);
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */ opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
opj_write_bytes(l_data_header,JPIP_PHIX,4); /* PHIX */ opj_write_bytes(l_data_header,JPIP_PHIX,4); /* PHIX */
opj_stream_write_data(cio,l_data_header,4,p_manager); 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++){ 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; box[compno].type = JPIP_FAIX;
} }
#if 0 len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp);
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_seek(cio, 4, p_manager); opj_stream_seek(cio, 4, p_manager);
opj_write_bytes(l_data_header,len,4);/* L */ opj_write_bytes(l_data_header,len,4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek( cio, lenp+len,p_manager); opj_stream_seek( cio, lenp+len,p_manager);
#endif
} }
opj_free(box); opj_free(box);
@ -135,105 +86,23 @@ int write_phix_v2( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused,
return len; 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)){ int opj_write_phixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_stream_private_t *cio,
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,
opj_event_mgr_t * p_manager ) 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_tile_info_t *tile_Idx;
opj_packet_info_t packet; opj_packet_info_t packet;
int resno, precno, layno, num_packet; int resno, precno, layno, num_packet;
int numOfres, numOfprec, numOflayers; int numOfres, numOfprec, numOflayers;
OPJ_BYTE l_data_header [8]; OPJ_BYTE l_data_header [8];
OPJ_OFF_T lenp;
OPJ_UINT32 len;
packet.end_ph_pos = packet.start_pos = -1; packet.end_ph_pos = packet.start_pos = -1;
(void)EPHused; /* unused ? */ (void)EPHused; /* unused ? */
if( j2klen > pow( 2, 32)){ if( j2klen > pow( 2, 32)){
size_of_coding = 8; size_of_coding = 8;
version = 1; version = 1;
@ -243,33 +112,21 @@ int write_phixfaix_v2( int coff, int compno, opj_codestream_info_t cstr_info, op
version = 0; 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); lenp = opj_stream_tell(cio);
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */ 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,JPIP_FAIX,4); /* FAIX */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_bytes(l_data_header,version,1); /* Version 0 = 4 bytes */ opj_write_bytes(l_data_header,version,1); /* Version 0 = 4 bytes */
opj_stream_write_data(cio,l_data_header,1,p_manager); opj_stream_write_data(cio,l_data_header,1,p_manager);
#endif
nmax = 0; nmax = 0;
for( i=0; i<=cstr_info.numdecompos[compno]; i++) 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; 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_write_bytes(l_data_header,nmax,size_of_coding); /* NMAX */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager); 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_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); 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++){ for( tileno=0; tileno<cstr_info.tw*cstr_info.th; tileno++){
tile_Idx = &cstr_info.tile[ 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"); fprintf( stderr, "failed to ppix indexing\n");
} }
#if 0 opj_write_bytes(l_data_header,(OPJ_UINT32)(packet.start_pos-coff),size_of_coding); /* start position */
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_stream_write_data(cio,l_data_header,size_of_coding,p_manager); 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); opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
#endif
num_packet++; num_packet++;
} }
@ -320,31 +172,19 @@ int write_phixfaix_v2( int coff, int compno, opj_codestream_info_t cstr_info, op
/* PADDING */ /* PADDING */
while( num_packet < nmax){ 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_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_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
opj_write_bytes(l_data_header,0,size_of_coding);/* length */ opj_write_bytes(l_data_header,0,size_of_coding);/* length */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager); opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
#endif
num_packet++; num_packet++;
} }
} }
#if 0 len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp);
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;
opj_stream_seek(cio, lenp,p_manager); opj_stream_seek(cio, lenp,p_manager);
opj_write_bytes(l_data_header,len,4);/* L */ opj_write_bytes(l_data_header,len,4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager); opj_stream_seek(cio, lenp+len,p_manager);
#endif
return len; return len;
} }

View File

@ -46,49 +46,16 @@
* @param[in] cio file output handle * @param[in] cio file output handle
* @return length of faix box * @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? */ int opj_write_ppix( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_stream_private_t *cio,
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,
opj_event_mgr_t * p_manager ) opj_event_mgr_t * p_manager )
{ {
OPJ_BYTE l_data_header [4]; OPJ_BYTE l_data_header [4];
int len, lenp, compno, i; int compno, i;
opj_jp2_box_t *box; opj_jp2_box_t *box;
OPJ_OFF_T lenp;
OPJ_UINT32 len;
/* printf("cstr_info.packno %d\n", cstr_info.packno); //NMAX? */ /* 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++){ for (i=0;i<2;i++){
if (i) if (i)
#if 0
cio_seek( cio, lenp);
#else
opj_stream_seek( cio, lenp, p_manager); opj_stream_seek( cio, lenp, p_manager);
#endif
#if 0 lenp = (OPJ_UINT32)(opj_stream_tell(cio));
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);
opj_stream_skip( cio, 4, p_manager); /* L [at the end] */ opj_stream_skip( cio, 4, p_manager); /* L [at the end] */
opj_write_bytes(l_data_header,JPIP_PPIX,4);/* PPIX */ opj_write_bytes(l_data_header,JPIP_PPIX,4);/* PPIX */
opj_stream_write_data(cio,l_data_header,4,p_manager); 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++){ 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; box[compno].type = JPIP_FAIX;
} }
#if 0
len = cio_tell( cio)-lenp; len = (OPJ_UINT32)(opj_stream_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;
opj_stream_seek(cio, lenp,p_manager); opj_stream_seek(cio, lenp,p_manager);
opj_write_bytes(l_data_header,len,4);/* L */ opj_write_bytes(l_data_header,len,4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager); opj_stream_seek(cio, lenp+len,p_manager);
#endif
} }
opj_free(box); opj_free(box);
@ -140,97 +92,15 @@ int write_ppix_v2( int coff, opj_codestream_info_t cstr_info, opj_bool EPHused,
return len; 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; int opj_write_ppixfaix( int coff, int compno, opj_codestream_info_t cstr_info, opj_bool EPHused, int j2klen, opj_stream_private_t *cio,
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,
opj_event_mgr_t * p_manager ) opj_event_mgr_t * p_manager )
{ {
OPJ_BYTE l_data_header [8]; 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_tile_info_t *tile_Idx;
opj_packet_info_t packet; opj_packet_info_t packet;
int resno, precno, layno, num_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; 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); lenp = opj_stream_tell(cio);
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */ 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,JPIP_FAIX,4); /* FAIX */
opj_write_bytes(l_data_header,version,1); opj_write_bytes(l_data_header,version,1);
opj_stream_write_data(cio,l_data_header,1,p_manager);/* Version 0 = 4 bytes */ opj_stream_write_data(cio,l_data_header,1,p_manager);/* Version 0 = 4 bytes */
#endif
nmax = 0; nmax = 0;
for( i=0; i<=cstr_info.numdecompos[compno]; i++) 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; 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_write_bytes(l_data_header,nmax,size_of_coding); /* NMAX */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager); 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_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); 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++){ for( tileno=0; tileno<cstr_info.tw*cstr_info.th; tileno++){
tile_Idx = &cstr_info.tile[ 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"); fprintf( stderr, "failed to ppix indexing\n");
} }
#if 0 opj_write_bytes(l_data_header,(OPJ_UINT32)(packet.start_pos-coff),size_of_coding); /* start position */
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_stream_write_data(cio,l_data_header,size_of_coding,p_manager); 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); opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
#endif
num_packet++; 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 */ 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_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_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
opj_write_bytes(l_data_header,0,size_of_coding);/* length */ opj_write_bytes(l_data_header,0,size_of_coding);/* length */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager); opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
#endif
num_packet++; num_packet++;
} }
} }
#if 0 len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp);
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;
opj_stream_seek(cio, lenp,p_manager); opj_stream_seek(cio, lenp,p_manager);
opj_write_bytes(l_data_header,len,4);/* L */ opj_write_bytes(l_data_header,len,4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager); opj_stream_seek(cio, lenp+len,p_manager);
#endif
return len; return len;
} }

View File

@ -35,6 +35,50 @@
#include "opj_includes.h" #include "opj_includes.h"
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 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)
opj_stream_seek( cio, lenp, p_manager);
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);
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 = opj_write_tilemhix( coff, cstr_info, tileno, cio,p_manager);
box[tileno].type = JPIP_MHIX;
}
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);
}
opj_free(box);
return len;
}
/* /*
* Write tile-part headers mhix box * Write tile-part headers mhix box
* *
@ -44,199 +88,47 @@
* @param[in] cio file output handle * @param[in] cio file output handle
* @return length of mhix box * @return length of mhix box
*/ */
int write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, opj_cio_t *cio); int opj_write_tilemhix( int coff, opj_codestream_info_t cstr_info, int tileno, opj_stream_private_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,
opj_event_mgr_t * p_manager )
{
OPJ_BYTE l_data_header [4];
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)
#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);
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].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;
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);
return len;
}
int write_tilemhix_v2( int coff, opj_codestream_info_t cstr_info, int tileno, opj_stream_private_t *cio,
opj_event_mgr_t * p_manager ) opj_event_mgr_t * p_manager )
{ {
OPJ_BYTE l_data_header [8]; OPJ_BYTE l_data_header [8];
int i; int i;
opj_tile_info_t tile; opj_tile_info_t tile;
opj_tp_info_t tp; opj_tp_info_t tp;
int marknum;
int len, lenp;
opj_marker_info_t *marker; 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); lenp = opj_stream_tell (cio);
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */ opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
opj_write_bytes(l_data_header,JPIP_MHIX,4); /* MHIX */ opj_write_bytes(l_data_header,JPIP_MHIX,4); /* MHIX */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
#endif
tile = cstr_info.tile[tileno]; tile = cstr_info.tile[tileno];
tp = tile.tp[0]; 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_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); opj_stream_write_data(cio,l_data_header,8,p_manager);
#endif
marker = cstr_info.tile[tileno].marker; marker = cstr_info.tile[tileno].marker;
for( i=0; i<cstr_info.tile[tileno].marknum; i++){ /* Marker restricted to 1 apparition */ 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, marker[i].type, 2);
opj_write_bytes( l_data_header+2, 0, 2); opj_write_bytes( l_data_header+2, 0, 2);
opj_stream_write_data(cio,l_data_header,4,p_manager); 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_stream_write_data(cio,l_data_header,8,p_manager);
opj_write_bytes( l_data_header, marker[i].len, 2); opj_write_bytes( l_data_header, marker[i].len, 2);
opj_stream_write_data(cio,l_data_header,2,p_manager); opj_stream_write_data(cio,l_data_header,2,p_manager);
#endif
} }
/* free( marker);*/ /* free( marker);*/
#if 0 len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp);
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;
opj_stream_seek(cio, lenp,p_manager); opj_stream_seek(cio, lenp,p_manager);
opj_write_bytes(l_data_header,len,4);/* L */ opj_write_bytes(l_data_header,len,4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager); opj_stream_seek(cio, lenp+len,p_manager);
#endif
return len; return len;
} }

View File

@ -37,6 +37,14 @@
#define MAX(a,b) ((a)>(b)?(a):(b)) #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 * Write faix box of tpix
@ -48,136 +56,42 @@
* @param[in] cio file output handle * @param[in] cio file output handle
* @return length of faix box * @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 opj_write_tpix( int coff,
int write_tpix( int coff, opj_codestream_info_t cstr_info, int j2klen, opj_cio_t *cio) opj_codestream_info_t cstr_info,
{ int j2klen, opj_stream_private_t *cio,
int len, lenp; opj_event_mgr_t * p_manager )
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 )
{ {
OPJ_BYTE l_data_header [4]; OPJ_BYTE l_data_header [4];
int len, lenp; OPJ_UINT32 len;
#if 0 OPJ_OFF_T lenp;
lenp = cio_tell( cio);
cio_skip( cio, 4); /* L [at the end] */
cio_write( cio, JPIP_TPIX, 4); /* TPIX */
#else
lenp = opj_stream_tell(cio); lenp = opj_stream_tell(cio);
opj_stream_skip(cio, 4, p_manager); opj_stream_skip(cio, 4, p_manager);
opj_write_bytes(l_data_header,JPIP_TPIX,4); /* TPIX */ opj_write_bytes(l_data_header,JPIP_TPIX,4); /* TPIX */
opj_stream_write_data(cio,l_data_header,4,p_manager); 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 = (OPJ_UINT32)(opj_stream_tell(cio)-lenp);
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;
opj_stream_skip(cio, lenp, p_manager); opj_stream_skip(cio, lenp, p_manager);
opj_write_bytes(l_data_header,len,4);/* L */ opj_write_bytes(l_data_header,len,4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager); opj_stream_seek(cio, lenp+len,p_manager);
#endif
return len; return len;
} }
/* int opj_write_tpixfaix( int coff,
* Get number of maximum tile parts per tile int compno,
* opj_codestream_info_t cstr_info,
* @param[in] cstr_info codestream information int j2klen,
* @return number of maximum tile parts per tile opj_stream_private_t *cio,
*/ opj_event_mgr_t * p_manager )
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; OPJ_UINT32 len;
int i, j; OPJ_OFF_T lenp;
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;
int i, j; int i, j;
int Aux; int Aux;
int num_max_tile_parts; 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; 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); lenp = opj_stream_tell(cio);
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */ 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,JPIP_FAIX,4); /* FAIX */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_write_bytes(l_data_header,version,1); /* Version 0 = 4 bytes */ opj_write_bytes(l_data_header,version,1); /* Version 0 = 4 bytes */
opj_stream_write_data(cio,l_data_header,1,p_manager); 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_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_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_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); 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 (i = 0; i < cstr_info.tw*cstr_info.th; i++)
{ {
for (j = 0; j < cstr_info.tile[i].num_tps; j++) for (j = 0; j < cstr_info.tile[i].num_tps; j++)
{ {
tp = cstr_info.tile[i].tp[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_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_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_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); opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
#endif
if (version & 0x02) if (version & 0x02)
{ {
if( cstr_info.tile[i].num_tps == 1 && cstr_info.numdecompos[compno] > 1) 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 else
Aux = j + 1; Aux = j + 1;
#if 0
cio_write( cio, Aux,4);
#else
opj_write_bytes(l_data_header,Aux,4); opj_write_bytes(l_data_header,Aux,4);
opj_stream_write_data(cio,l_data_header,4,p_manager); 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 */ /*cio_write(img.tile[i].tile_parts[j].num_reso_AUX,4);*/ /* Aux_i,j : Auxiliary value */
/* fprintf(stderr,"AUX value %d\n",Aux);*/ /* 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 */ /* PADDING */
while (j < num_max_tile_parts) while (j < num_max_tile_parts)
{ {
#if 0
cio_write( cio, 0, size_of_coding); /* start position */ opj_write_bytes(l_data_header,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_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
opj_write_bytes(l_data_header,0,size_of_coding);/* length */ opj_write_bytes(l_data_header,0,size_of_coding);/* length */
opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager); opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager);
#endif
if (version & 0x02) 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_write_bytes(l_data_header,0,4); /* Aux_i,j : Auxiliary value */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
#endif
j++; j++;
} }
} }
#if 0 len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp);
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;
opj_stream_seek(cio, lenp,p_manager); opj_stream_seek(cio, lenp,p_manager);
opj_write_bytes(l_data_header,len,4);/* L */ opj_write_bytes(l_data_header,len,4);/* L */
opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_write_data(cio,l_data_header,4,p_manager);
opj_stream_seek(cio, lenp+len,p_manager); opj_stream_seek(cio, lenp+len,p_manager);
#endif
return len; return len;
} }