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]; 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); opj_write_tpixfaix( coff, 0, cstr_info, j2klen, cio,p_manager); 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); return len; }
static int write_fidx_v2( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, 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_FIDX, 4); /* IPTR */ #else lenp = opj_stream_tell(cio); opj_stream_skip(cio, 4, p_manager); opj_write_bytes(l_data_header,JPIP_FIDX,4); /* FIDX */ opj_stream_write_data(cio,l_data_header,4,p_manager); #endif write_prxy_v2( offset_jp2c, length_jp2c, offset_idx, length_idx, 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; 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; }
void opj_write_manf(int second, int v, opj_jp2_box_t *box, opj_stream_private_t *cio, opj_event_mgr_t * p_manager ) { OPJ_BYTE l_data_header [4]; int i; OPJ_UINT32 len; OPJ_OFF_T lenp; lenp = opj_stream_tell(cio); opj_stream_skip( cio, 4, p_manager); /* L [at the end] */ opj_write_bytes( l_data_header, JPIP_MANF, 4); /* T */ opj_stream_write_data(cio,l_data_header,4,p_manager); if (second){ /* Write only during the second pass */ for( i=0; i<v; i++){ opj_write_bytes( l_data_header, box[i].length, 4); /* Box length */ opj_stream_write_data(cio,l_data_header,4,p_manager); opj_write_bytes( l_data_header, box[i].type, 4); /* Box type */ opj_stream_write_data(cio,l_data_header,4,p_manager); } } 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); }
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]; 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 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); #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_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; }
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); 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; }
static opj_bool opj_jpip_write_fidx(opj_jp2_v2_t *jp2, opj_stream_private_t *cio, opj_event_mgr_t * p_manager ) { OPJ_OFF_T j2k_codestream_exit; OPJ_BYTE l_data_header [24]; /* preconditions */ assert(jp2 != 00); assert(cio != 00); assert(p_manager != 00); assert(opj_stream_has_seek(cio)); opj_write_bytes(l_data_header, 24, 4); /* size of iptr */ opj_write_bytes(l_data_header + 4,JPIP_FIDX,4); /* IPTR */ opj_write_double(l_data_header + 4 + 4, 0); /* offset */ opj_write_double(l_data_header + 8 + 8, 0); /* length */ if (opj_stream_write_data(cio,l_data_header,24,p_manager) != 24) { opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n"); return OPJ_FALSE; } j2k_codestream_exit = opj_stream_tell(cio); if (! opj_stream_seek(cio,j2k_codestream_exit,p_manager)) { opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n"); return OPJ_FALSE; } return OPJ_TRUE; }
static opj_bool opj_jp2_write_jp( opj_jp2_v2_t *jp2, opj_stream_private_t *cio, opj_event_mgr_t * p_manager ) { /* 12 bytes will be read */ unsigned char l_signature_data [12]; /* preconditions */ assert(cio != 00); assert(jp2 != 00); assert(p_manager != 00); /* write box length */ opj_write_bytes(l_signature_data,12,4); /* writes box type */ opj_write_bytes(l_signature_data+4,JP2_JP,4); /* writes magic number*/ opj_write_bytes(l_signature_data+8,0x0d0a870a,4); if (opj_stream_write_data(cio,l_signature_data,12,p_manager) != 12) { return OPJ_FALSE; } return OPJ_TRUE; }
static opj_bool opj_jpip_write_jp2c(opj_jp2_v2_t *jp2, opj_stream_private_t *cio, opj_event_mgr_t * p_manager ) { OPJ_OFF_T j2k_codestream_exit; opj_codestream_info_t cstr_info; OPJ_BYTE l_data_header [8]; OPJ_UINT32 len_jp2c; int len_cidx; int len_fidx; int pos_jp2c; int pos_fidx; int pos_cidx; /* preconditions */ assert(jp2 != 00); assert(cio != 00); assert(p_manager != 00); assert(opj_stream_has_seek(cio)); j2k_codestream_exit = opj_stream_tell(cio); len_jp2c = j2k_codestream_exit - jp2->j2k_codestream_offset; pos_jp2c = jp2->j2k_codestream_offset; opj_write_bytes(l_data_header, len_jp2c, 4); /* size of codestream */ opj_write_bytes(l_data_header + 4,JP2_JP2C,4); /* JP2C */ if (! opj_stream_seek(cio,jp2->j2k_codestream_offset,p_manager)) { opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n"); return OPJ_FALSE; } if (opj_stream_write_data(cio,l_data_header,8,p_manager) != 8) { opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n"); return OPJ_FALSE; } if (! opj_stream_seek(cio,j2k_codestream_exit,p_manager)) { opj_event_msg_v2(p_manager, EVT_ERROR, "Failed to seek in the stream.\n"); return OPJ_FALSE; } /* CIDX */ pos_cidx = opj_stream_tell( cio); /*cinfo = jp2_get_cstr_info(jp2);*/ assert( 0 ); /* MM: FIXME */ len_cidx = write_cidx_v2( pos_jp2c+8, cio, cstr_info, len_jp2c-8,p_manager); /* FIDX */ pos_fidx = opj_stream_tell( cio); len_fidx = write_fidx_v2( pos_jp2c, len_jp2c, pos_cidx, len_cidx, cio, p_manager); return OPJ_TRUE; }
int opj_write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio, opj_event_mgr_t * p_manager ) { OPJ_BYTE l_data_header [8]; OPJ_UINT32 i; OPJ_UINT32 len; OPJ_OFF_T lenp; lenp = opj_stream_tell (cio); opj_stream_skip(cio, 4, p_manager); /* L [at the end] */ opj_write_bytes(l_data_header,JPIP_MHIX,4); /* MHIX */ opj_stream_write_data(cio,l_data_header,4,p_manager); opj_write_bytes(l_data_header, (OPJ_UINT32)(cstr_info.main_head_end-cstr_info.main_head_start+1), 8); /* TLEN */ opj_stream_write_data(cio,l_data_header,8,p_manager); for(i = 1; i < (OPJ_UINT32)cstr_info.marknum; i++){ /* Marker restricted to 1 apparition, skip SOC marker */ opj_write_bytes( l_data_header, cstr_info.marker[i].type, 2); opj_write_bytes( l_data_header+2, 0, 2); opj_stream_write_data(cio,l_data_header,4,p_manager); opj_write_bytes( l_data_header,(OPJ_UINT32) (cstr_info.marker[i].pos-coff), 8); opj_stream_write_data(cio,l_data_header,8,p_manager); opj_write_bytes( l_data_header, (OPJ_UINT32)cstr_info.marker[i].len, 2); opj_stream_write_data(cio,l_data_header,2,p_manager); } 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); return (int)len; }
static opj_bool opj_jp2_write_ftyp(opj_jp2_v2_t *jp2, opj_stream_private_t *cio, opj_event_mgr_t * p_manager ) { unsigned int i; unsigned int l_ftyp_size = 16 + 4 * jp2->numcl; unsigned char * l_ftyp_data, * l_current_data_ptr; opj_bool l_result; /* preconditions */ assert(cio != 00); assert(jp2 != 00); assert(p_manager != 00); l_ftyp_data = (unsigned char *) opj_malloc(l_ftyp_size); if (l_ftyp_data == 00) { opj_event_msg_v2(p_manager, EVT_ERROR, "Not enough memory to handle ftyp data\n"); return OPJ_FALSE; } memset(l_ftyp_data,0,l_ftyp_size); l_current_data_ptr = l_ftyp_data; opj_write_bytes(l_current_data_ptr, l_ftyp_size,4); /* box size */ l_current_data_ptr += 4; opj_write_bytes(l_current_data_ptr, JP2_FTYP,4); /* FTYP */ l_current_data_ptr += 4; opj_write_bytes(l_current_data_ptr, jp2->brand,4); /* BR */ l_current_data_ptr += 4; opj_write_bytes(l_current_data_ptr, jp2->minversion,4); /* MinV */ l_current_data_ptr += 4; for (i = 0; i < jp2->numcl; i++) { opj_write_bytes(l_current_data_ptr, jp2->cl[i],4); /* CL */ } l_result = (opj_stream_write_data(cio,l_ftyp_data,l_ftyp_size,p_manager) == l_ftyp_size); if (! l_result) { opj_event_msg_v2(p_manager, EVT_ERROR, "Error while writing ftyp data to stream\n"); } opj_free(l_ftyp_data); return l_result; }
int opj_write_phix( int coff, opj_codestream_info_t cstr_info, OPJ_BOOL EPHused, int j2klen, opj_stream_private_t *cio, opj_event_mgr_t * p_manager ) { OPJ_BYTE l_data_header [8]; OPJ_UINT32 len, compno, i; opj_jp2_box_t *box; OPJ_OFF_T lenp = 0; box = (opj_jp2_box_t *)opj_calloc( (size_t)cstr_info.numcomps, 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_PHIX,4); /* PHIX */ opj_stream_write_data(cio,l_data_header,4,p_manager); opj_write_manf( (int)i, cstr_info.numcomps, box, cio, p_manager ); for( compno=0; compno<(OPJ_UINT32)cstr_info.numcomps; compno++){ box[compno].length = (OPJ_UINT32)opj_write_phixfaix( coff, (int)compno, cstr_info, EPHused, j2klen, cio,p_manager); box[compno].type = JPIP_FAIX; } len = (OPJ_UINT32)(opj_stream_tell(cio)-lenp); opj_stream_seek(cio, 4, p_manager); opj_write_bytes(l_data_header,len,4);/* L */ opj_stream_write_data(cio,l_data_header,4,p_manager); opj_stream_seek( cio, lenp+len,p_manager); } opj_free(box); return (int)len; }
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]; OPJ_UINT32 len; OPJ_OFF_T lenp; lenp = opj_stream_tell(cio); opj_stream_skip( cio, 4, p_manager); /* L [at the end] */ opj_write_bytes( l_data_header, JPIP_CPTR, 4); /* T */ opj_write_bytes( l_data_header+4, 0, 2); /* DR A PRECISER !! */ opj_write_bytes( l_data_header+6, 0, 2); /* CONT */ opj_write_bytes( l_data_header+8, (OPJ_UINT32)coff, 8); /* COFF A PRECISER !! */ opj_write_bytes( l_data_header+16, (OPJ_UINT32)clen, 8); /* CLEN */ opj_stream_write_data(cio,l_data_header,3*8,p_manager); 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); }
static void write_prxy_v2( int offset_jp2c, int length_jp2c, int offset_idx, int length_idx, opj_stream_private_t *cio, opj_event_mgr_t * p_manager ) { OPJ_BYTE l_data_header [8]; int len, lenp; #if 0 lenp = cio_tell( cio); cio_skip( cio, 4); /* L [at the end] */ cio_write( cio, JPIP_PRXY, 4); /* IPTR */ #else lenp = opj_stream_tell(cio); opj_stream_skip(cio, 4, p_manager); /* L [at the end] */ opj_write_bytes(l_data_header,JPIP_PRXY,4); /* IPTR */ opj_stream_write_data(cio,l_data_header,4,p_manager); #endif #if 0 cio_write( cio, offset_jp2c, 8); /* OOFF */ cio_write( cio, length_jp2c, 4); /* OBH part 1 */ cio_write( cio, JP2_JP2C, 4); /* OBH part 2 */ #else opj_write_bytes( l_data_header, offset_jp2c, 8); /* OOFF */ opj_stream_write_data(cio,l_data_header,8,p_manager); opj_write_bytes( l_data_header, length_jp2c, 4); /* OBH part 1 */ opj_write_bytes( l_data_header+4, JP2_JP2C, 4); /* OBH part 2 */ opj_stream_write_data(cio,l_data_header,8,p_manager); #endif #if 0 cio_write( cio, 1,1); /* NI */ #else opj_write_bytes( l_data_header, 1, 1);/* NI */ opj_stream_write_data(cio,l_data_header,1,p_manager); #endif #if 0 cio_write( cio, offset_idx, 8); /* IOFF */ cio_write( cio, length_idx, 4); /* IBH part 1 */ cio_write( cio, JPIP_CIDX, 4); /* IBH part 2 */ #else opj_write_bytes( l_data_header, offset_idx, 8); /* IOFF */ opj_stream_write_data(cio,l_data_header,8,p_manager); opj_write_bytes( l_data_header, length_idx, 4); /* IBH part 1 */ opj_write_bytes( l_data_header+4, JPIP_CIDX, 4); /* IBH part 2 */ opj_stream_write_data(cio,l_data_header,8,p_manager); #endif #if 0 len = cio_tell( cio)-lenp; cio_seek( cio, lenp); cio_write( cio, len, 4); /* L */ cio_seek( cio, lenp+len); #else len = opj_stream_tell(cio)-lenp; 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 }
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_BYTE l_data_header [8]; int i; opj_tile_info_t tile; opj_tp_info_t tp; int marknum; int len, lenp; opj_marker_info_t *marker; #if 0 lenp = cio_tell( cio); cio_skip( cio, 4); /* L [at the end] */ cio_write( cio, JPIP_MHIX, 4); /* MHIX */ #else lenp = opj_stream_tell (cio); opj_stream_skip(cio, 4, p_manager); /* L [at the end] */ opj_write_bytes(l_data_header,JPIP_MHIX,4); /* MHIX */ opj_stream_write_data(cio,l_data_header,4,p_manager); #endif tile = cstr_info.tile[tileno]; tp = tile.tp[0]; #if 0 cio_write( cio, tp.tp_end_header-tp.tp_start_pos+1, 8); /* TLEN */ #else opj_write_bytes(l_data_header,tp.tp_end_header-tp.tp_start_pos+1, 8); /* TLEN */ opj_stream_write_data(cio,l_data_header,8,p_manager); #endif marker = cstr_info.tile[tileno].marker; for( i=0; i<cstr_info.tile[tileno].marknum; i++){ /* Marker restricted to 1 apparition */ #if 0 cio_write( cio, marker[i].type, 2); cio_write( cio, 0, 2); cio_write( cio, marker[i].pos-coff, 8); cio_write( cio, marker[i].len, 2); #else opj_write_bytes( l_data_header, marker[i].type, 2); opj_write_bytes( l_data_header+2, 0, 2); opj_stream_write_data(cio,l_data_header,4,p_manager); opj_write_bytes( l_data_header, marker[i].pos-coff, 8); opj_stream_write_data(cio,l_data_header,8,p_manager); opj_write_bytes( l_data_header, marker[i].len, 2); opj_stream_write_data(cio,l_data_header,2,p_manager); #endif } /* free( marker);*/ #if 0 len = cio_tell( cio) - lenp; cio_seek( cio, lenp); cio_write( cio, len, 4); /* L */ cio_seek( cio, lenp+len); #else len = opj_stream_tell(cio)-lenp; 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; }
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 i; OPJ_OFF_T lenp; OPJ_UINT32 len; opj_jp2_box_t *box; int num_box = 0; OPJ_BOOL EPHused; OPJ_BYTE l_data_header [4]; lenp = -1; box = (opj_jp2_box_t *)opj_calloc( 32, sizeof(opj_jp2_box_t)); if(box == NULL){ return 0; } 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_CIDX,4); /* CIDX */ opj_stream_write_data(cio,l_data_header,4,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 = (OPJ_UINT32)opj_write_mainmhix( offset, cstr_info, cio,p_manager); box[num_box].type = JPIP_MHIX; num_box++; box[num_box].length = (OPJ_UINT32)opj_write_tpix( offset, cstr_info, j2klen, cio,p_manager); box[num_box].type = JPIP_TPIX; num_box++; box[num_box].length = (OPJ_UINT32)opj_write_thix( offset, cstr_info, cio, p_manager); box[num_box].type = JPIP_THIX; num_box++; EPHused = opj_check_EPHuse( offset, cstr_info.marker, cstr_info.marknum, cio,p_manager); box[num_box].length = (OPJ_UINT32)opj_write_ppix( offset, cstr_info, EPHused, j2klen, cio,p_manager); box[num_box].type = JPIP_PPIX; num_box++; box[num_box].length = (OPJ_UINT32)opj_write_phix( offset, cstr_info, EPHused, j2klen, cio,p_manager); box[num_box].type = JPIP_PHIX; num_box++; 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 (int)len; }
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_UINT32 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; OPJ_UINT32 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; } else{ size_of_coding = 4; version = 0; } 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); nmax = 0; for( i=0; i<=(OPJ_UINT32)cstr_info.numdecompos[compno]; i++) nmax += (OPJ_UINT32)(cstr_info.tile[0].ph[i] * cstr_info.tile[0].pw[i] * cstr_info.numlayers); 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,(OPJ_UINT32)(cstr_info.tw*cstr_info.th),size_of_coding); /* M */ opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager); for( tileno=0; tileno<(OPJ_UINT32)(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 OPJ_LRCP: packet = tile_Idx->packet[ ((layno*numOfres+resno)*cstr_info.numcomps+compno)*numOfprec+precno]; break; case OPJ_RLCP: packet = tile_Idx->packet[ ((resno*numOflayers+layno)*cstr_info.numcomps+compno)*numOfprec+precno]; break; case OPJ_RPCL: packet = tile_Idx->packet[ ((resno*numOfprec+precno)*cstr_info.numcomps+compno)*numOflayers+layno]; break; case OPJ_PCRL: packet = tile_Idx->packet[ ((precno*cstr_info.numcomps+compno)*numOfres+resno)*numOflayers + layno]; break; case OPJ_CPRL: packet = tile_Idx->packet[ ((compno*numOfprec+precno)*numOfres+resno)*numOflayers + layno]; break; default: fprintf( stderr, "failed to ppix indexing\n"); } opj_write_bytes(l_data_header,(OPJ_UINT32)(packet.start_pos-coff),size_of_coding); /* start position */ opj_stream_write_data(cio,l_data_header,size_of_coding,p_manager); opj_write_bytes(l_data_header,(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); num_packet++; } } } /* PADDING */ while( num_packet < nmax){ 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); num_packet++; } } 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); return (int)len; }
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_UINT32 len; OPJ_OFF_T lenp; int i, j; int Aux; int num_max_tile_parts; int size_of_coding; /* 4 or 8 */ opj_tp_info_t tp; OPJ_BYTE l_data_header [8]; 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 = 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); 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); 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]; 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); 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; opj_write_bytes(l_data_header,Aux,4); opj_stream_write_data(cio,l_data_header,4,p_manager); /*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) { 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); if (version & 0x02) opj_write_bytes(l_data_header,0,4); /* Aux_i,j : Auxiliary value */ opj_stream_write_data(cio,l_data_header,4,p_manager); j++; } } 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); return len; }