41
39
* @param[in] clen length of j2k codestream
42
40
* @param[in] cio file output handle
44
void write_cptr(int coff, int clen, opj_cio_t *cio);
48
* Write main header index table (box)
50
* @param[in] coff offset of j2k codestream
51
* @param[in] cstr_info codestream information
52
* @param[in] cio file output handle
53
* @return length of mainmhix box
55
int write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_cio_t *cio);
59
* Check if EPH option is used
61
* @param[in] coff offset of j2k codestream
62
* @param[in] markers marker information
63
* @param[in] marknum number of markers
64
* @param[in] cio file output handle
65
* @return true if EPH is used
67
opj_bool check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_cio_t *cio);
70
int write_cidx( int offset, opj_cio_t *cio, opj_image_t *image, opj_codestream_info_t cstr_info, int j2klen)
43
void opj_write_cptr(int coff, int clen, opj_stream_private_t *cio,
44
opj_event_mgr_t * p_manager );
50
int opj_write_cidx( int offset, opj_stream_private_t *cio, opj_codestream_info_t cstr_info, int j2klen,
51
opj_event_mgr_t * p_manager )
73
56
opj_jp2_box_t *box;
76
(void)image; /* unused ? */
59
OPJ_BYTE l_data_header [4];
79
62
box = (opj_jp2_box_t *)opj_calloc( 32, sizeof(opj_jp2_box_t));
86
lenp = cio_tell( cio);
88
cio_skip( cio, 4); /* L [at the end] */
89
cio_write( cio, JPIP_CIDX, 4); /* CIDX */
90
write_cptr( offset, cstr_info.codestream_size, cio);
92
write_manf( i, num_box, box, cio);
67
opj_stream_seek(cio,lenp,p_manager);
70
lenp = opj_stream_tell (cio);
72
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
74
opj_write_bytes(l_data_header,JPIP_CIDX,4); /* CIDX */
75
opj_stream_write_data(cio,l_data_header,4,p_manager);
77
opj_write_cptr( offset, cstr_info.codestream_size, cio,p_manager);
79
opj_write_manf( i, num_box, box, cio,p_manager);
95
box[num_box].length = write_mainmhix( offset, cstr_info, cio);
82
box[num_box].length = opj_write_mainmhix( offset, cstr_info, cio,p_manager);
96
83
box[num_box].type = JPIP_MHIX;
99
box[num_box].length = write_tpix( offset, cstr_info, j2klen, cio);
86
box[num_box].length = opj_write_tpix( offset, cstr_info, j2klen, cio,p_manager);
100
87
box[num_box].type = JPIP_TPIX;
103
box[num_box].length = write_thix( offset, cstr_info, cio);
90
box[num_box].length = opj_write_thix( offset, cstr_info, cio, p_manager);
104
91
box[num_box].type = JPIP_THIX;
107
EPHused = check_EPHuse( offset, cstr_info.marker, cstr_info.marknum, cio);
94
EPHused = opj_check_EPHuse( offset, cstr_info.marker, cstr_info.marknum, cio,p_manager);
109
box[num_box].length = write_ppix( offset, cstr_info, EPHused, j2klen, cio);
96
box[num_box].length = opj_write_ppix( offset, cstr_info, EPHused, j2klen, cio,p_manager);
110
97
box[num_box].type = JPIP_PPIX;
113
box[num_box].length = write_phix( offset, cstr_info, EPHused, j2klen, cio);
100
box[num_box].length = opj_write_phix( offset, cstr_info, EPHused, j2klen, cio,p_manager);
114
101
box[num_box].type = JPIP_PHIX;
117
len = cio_tell( cio)-lenp;
118
cio_seek( cio, lenp);
119
cio_write( cio, len, 4); /* L */
120
cio_seek( cio, lenp+len);
104
len = (OPJ_UINT32) (opj_stream_tell(cio)-lenp);
105
opj_stream_seek(cio, lenp,p_manager);
106
opj_write_bytes(l_data_header,len,4);/* L */
107
opj_stream_write_data(cio,l_data_header,4,p_manager);
108
opj_stream_seek(cio, lenp+len,p_manager);
128
void write_cptr(int coff, int clen, opj_cio_t *cio)
118
void opj_write_cptr(int coff, int clen, opj_stream_private_t *cio,
119
opj_event_mgr_t * p_manager )
132
lenp = cio_tell( cio);
133
cio_skip( cio, 4); /* L [at the end] */
134
cio_write( cio, JPIP_CPTR, 4); /* T */
135
cio_write( cio, 0, 2); /* DR A PRECISER !! */
136
cio_write( cio, 0, 2); /* CONT */
137
cio_write( cio, coff, 8); /* COFF A PRECISER !! */
138
cio_write( cio, clen, 8); /* CLEN */
139
len = cio_tell( cio) - lenp;
140
cio_seek( cio, lenp);
141
cio_write( cio, len, 4); /* L */
142
cio_seek( cio, lenp+len);
121
OPJ_BYTE l_data_header [3*8];
126
lenp = opj_stream_tell(cio);
127
opj_stream_skip( cio, 4, p_manager); /* L [at the end] */
128
opj_write_bytes( l_data_header, JPIP_CPTR, 4); /* T */
129
opj_write_bytes( l_data_header+4, 0, 2); /* DR A PRECISER !! */
130
opj_write_bytes( l_data_header+6, 0, 2); /* CONT */
131
opj_write_bytes( l_data_header+8, coff, 8); /* COFF A PRECISER !! */
132
opj_write_bytes( l_data_header+16, clen, 8); /* CLEN */
133
opj_stream_write_data(cio,l_data_header,3*8,p_manager);
135
len = (OPJ_UINT32) (opj_stream_tell(cio) - lenp);
136
opj_stream_seek(cio,lenp,p_manager);
137
opj_write_bytes(l_data_header, len, 4); /* L */
138
opj_stream_write_data(cio,l_data_header,4,p_manager);
139
opj_stream_seek(cio, lenp+len,p_manager);
145
void write_manf(int second, int v, opj_jp2_box_t *box, opj_cio_t *cio)
145
void opj_write_manf(int second,
148
opj_stream_private_t *cio,
149
opj_event_mgr_t * p_manager )
151
OPJ_BYTE l_data_header [4];
149
lenp = cio_tell( cio);
150
cio_skip( cio, 4); /* L [at the end] */
151
cio_write( cio, JPIP_MANF,4); /* T */
156
lenp = opj_stream_tell(cio);
157
opj_stream_skip( cio, 4, p_manager); /* L [at the end] */
158
opj_write_bytes( l_data_header, JPIP_MANF, 4); /* T */
159
opj_stream_write_data(cio,l_data_header,4,p_manager);
153
161
if (second){ /* Write only during the second pass */
154
162
for( i=0; i<v; i++){
155
cio_write( cio, box[i].length, 4); /* Box length */
156
cio_write( cio, box[i].type, 4); /* Box type */
163
opj_write_bytes( l_data_header, box[i].length, 4); /* Box length */
164
opj_stream_write_data(cio,l_data_header,4,p_manager);
165
opj_write_bytes( l_data_header, box[i].type, 4); /* Box type */
166
opj_stream_write_data(cio,l_data_header,4,p_manager);
160
len = cio_tell( cio) - lenp;
161
cio_seek( cio, lenp);
162
cio_write( cio, len, 4); /* L */
163
cio_seek( cio, lenp+len);
170
len = (OPJ_UINT32) (opj_stream_tell(cio) - lenp);
171
opj_stream_seek(cio,lenp,p_manager);
172
opj_write_bytes(l_data_header, len, 4);/* L */
173
opj_stream_write_data(cio,l_data_header,4,p_manager);
174
opj_stream_seek(cio,lenp+len,p_manager);
166
int write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_cio_t *cio)
178
int opj_write_mainmhix( int coff, opj_codestream_info_t cstr_info, opj_stream_private_t *cio,
179
opj_event_mgr_t * p_manager )
181
OPJ_BYTE l_data_header [8];
171
lenp = cio_tell( cio);
172
cio_skip( cio, 4); /* L [at the end] */
173
cio_write( cio, JPIP_MHIX, 4); /* MHIX */
186
lenp = opj_stream_tell (cio);
187
opj_stream_skip(cio, 4, p_manager); /* L [at the end] */
188
opj_write_bytes(l_data_header,JPIP_MHIX,4); /* MHIX */
189
opj_stream_write_data(cio,l_data_header,4,p_manager);
175
cio_write( cio, cstr_info.main_head_end-cstr_info.main_head_start+1, 8); /* TLEN */
191
opj_write_bytes(l_data_header, cstr_info.main_head_end-cstr_info.main_head_start+1, 8); /* TLEN */
192
opj_stream_write_data(cio,l_data_header,8,p_manager);
177
194
for(i = 1; i < cstr_info.marknum; i++){ /* Marker restricted to 1 apparition, skip SOC marker */
178
cio_write( cio, cstr_info.marker[i].type, 2);
179
cio_write( cio, 0, 2);
180
cio_write( cio, cstr_info.marker[i].pos-coff, 8);
181
cio_write( cio, cstr_info.marker[i].len, 2);
195
opj_write_bytes( l_data_header, cstr_info.marker[i].type, 2);
196
opj_write_bytes( l_data_header+2, 0, 2);
197
opj_stream_write_data(cio,l_data_header,4,p_manager);
198
opj_write_bytes( l_data_header,(OPJ_UINT32) (cstr_info.marker[i].pos-coff), 8);
199
opj_stream_write_data(cio,l_data_header,8,p_manager);
200
opj_write_bytes( l_data_header, cstr_info.marker[i].len, 2);
201
opj_stream_write_data(cio,l_data_header,2,p_manager);
184
len = cio_tell( cio) - lenp;
185
cio_seek( cio, lenp);
186
cio_write( cio, len, 4); /* L */
187
cio_seek( cio, lenp+len);
204
len = (OPJ_UINT32) (opj_stream_tell(cio)-lenp);
205
opj_stream_seek(cio, lenp,p_manager);
206
opj_write_bytes(l_data_header,len,4);/* L */
207
opj_stream_write_data(cio,l_data_header,4,p_manager);
208
opj_stream_seek(cio, lenp+len,p_manager);
192
opj_bool check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_cio_t *cio)
213
OPJ_BOOL opj_check_EPHuse( int coff, opj_marker_info_t *markers, int marknum, opj_stream_private_t *cio,
214
opj_event_mgr_t * p_manager )
194
opj_bool EPHused = OPJ_FALSE;
216
OPJ_BYTE l_data_header [4];
217
OPJ_BOOL EPHused = OPJ_FALSE;
197
220
unsigned int Scod;
199
for(i = 0; i < marknum; i++){
200
if( markers[i].type == J2K_MS_COD){
201
org_pos = cio_tell( cio);
202
cio_seek( cio, coff+markers[i].pos+2);
204
Scod = cio_read( cio, 1);
222
for(i = 0; i < marknum; i++)
224
if( markers[i].type == J2K_MS_COD)
226
org_pos = opj_stream_tell(cio);
227
opj_stream_seek(cio, coff+markers[i].pos+2,p_manager);
229
opj_stream_read_data(cio,l_data_header,1,p_manager);
230
opj_read_bytes(l_data_header,&Scod,1);
205
231
if( ((Scod >> 2) & 1))
207
cio_seek( cio, org_pos);
233
opj_stream_seek( cio, org_pos, p_manager);