OLD | NEW |
1 /* | 1 /* |
2 * The copyright in this software is being made available under the 2-clauses | 2 * The copyright in this software is being made available under the 2-clauses |
3 * BSD License, included below. This software may be subject to other third | 3 * BSD License, included below. This software may be subject to other third |
4 * party and contributor rights, including patent rights, and no such rights | 4 * party and contributor rights, including patent rights, and no such rights |
5 * are granted under this license. | 5 * are granted under this license. |
6 * | 6 * |
7 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium | 7 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium |
8 * Copyright (c) 2002-2014, Professor Benoit Macq | 8 * Copyright (c) 2002-2014, Professor Benoit Macq |
9 * Copyright (c) 2001-2003, David Janssens | 9 * Copyright (c) 2001-2003, David Janssens |
10 * Copyright (c) 2002-2003, Yannick Verschueren | 10 * Copyright (c) 2002-2003, Yannick Verschueren |
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
99 static OPJ_BOOL opj_jp2_read_bpcc( opj_jp2_t *jp2, | 99 static OPJ_BOOL opj_jp2_read_bpcc( opj_jp2_t *jp2, |
100 OPJ_BYTE * p_bpc_header_data, | 100 OPJ_BYTE * p_bpc_header_data, |
101 OPJ_UINT32 p_bpc_header_size, | 101 OPJ_UINT32 p_bpc_header_size, |
102 opj_event_mgr_t * p_manager ); | 102 opj_event_mgr_t * p_manager ); |
103 | 103 |
104 static OPJ_BOOL opj_jp2_read_cdef( opj_jp2_t * jp2, | 104 static OPJ_BOOL opj_jp2_read_cdef( opj_jp2_t * jp2, |
105 OPJ_BYTE * p_cdef_header_data, | 105 OPJ_BYTE * p_cdef_header_data, |
106 OPJ_UINT
32 p_cdef_header_size, | 106 OPJ_UINT
32 p_cdef_header_size, |
107 opj_even
t_mgr_t * p_manager ); | 107 opj_even
t_mgr_t * p_manager ); |
108 | 108 |
109 static void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color); | 109 static void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color, opj_e
vent_mgr_t *); |
110 | 110 |
111 /** | 111 /** |
112 * Writes the Channel Definition box. | 112 * Writes the Channel Definition box. |
113 * | 113 * |
114 * @param jp2 jpeg2000 file codec. | 114 * @param jp2 jpeg2000 file codec. |
115 * @param p_nb_bytes_written pointer to store the nb of bytes written by the
function. | 115 * @param p_nb_bytes_written pointer to store the nb of bytes written by the
function. |
116 * | 116 * |
117 * @return the data being copied. | 117 * @return the data being copied. |
118 */ | 118 */ |
119 static OPJ_BYTE * opj_jp2_write_cdef( opj_jp2_t *jp2, | 119 static OPJ_BYTE * opj_jp2_write_cdef( opj_jp2_t *jp2, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
151 * @param p_header_size the size of the data contained in the FTYP box. | 151 * @param p_header_size the size of the data contained in the FTYP box. |
152 * @param p_manager the user event manager. | 152 * @param p_manager the user event manager. |
153 * | 153 * |
154 * @return true if the FTYP box is valid. | 154 * @return true if the FTYP box is valid. |
155 */ | 155 */ |
156 static OPJ_BOOL opj_jp2_read_ftyp( opj_jp2_t *jp2, | 156 static OPJ_BOOL opj_jp2_read_ftyp( opj_jp2_t *jp2, |
157 OPJ_BYTE
* p_header_data, | 157 OPJ_BYTE
* p_header_data, |
158 OPJ_UINT
32 p_header_size, | 158 OPJ_UINT
32 p_header_size, |
159 opj_even
t_mgr_t * p_manager ); | 159 opj_even
t_mgr_t * p_manager ); |
160 | 160 |
161 OPJ_BOOL opj_jp2_skip_jp2c(» opj_jp2_t *jp2, | 161 static OPJ_BOOL opj_jp2_skip_jp2c(» opj_jp2_t *jp2, |
162 opj_stream_private_t *cio, | 162 opj_stream_private_t *cio, |
163 opj_event_mgr_t * p_manager
); | 163 opj_event_mgr_t * p_manager
); |
164 | 164 |
165 /** | 165 /** |
166 * Reads the Jpeg2000 file Header box - JP2 Header box (warning, this is a super
box). | 166 * Reads the Jpeg2000 file Header box - JP2 Header box (warning, this is a super
box). |
167 * | 167 * |
168 * @param p_header_data the data contained in the file header box. | 168 * @param p_header_data the data contained in the file header box. |
169 * @param jp2 the jpeg2000 file codec. | 169 * @param jp2 the jpeg2000 file codec. |
170 * @param p_header_size the size of the data contained in the file heade
r box. | 170 * @param p_header_size the size of the data contained in the file heade
r box. |
171 * @param p_manager the user event manager. | 171 * @param p_manager the user event manager. |
172 * | 172 * |
173 * @return true if the JP2 Header box was successfully reconized. | 173 * @return true if the JP2 Header box was successfully recognized. |
174 */ | 174 */ |
175 static OPJ_BOOL opj_jp2_read_jp2h( opj_jp2_t *jp2, | 175 static OPJ_BOOL opj_jp2_read_jp2h( opj_jp2_t *jp2, |
176 OPJ_BYTE *p_header_data, | 176 OPJ_BYTE *p_header_data, |
177 OPJ_UINT32 p_header_size, | 177 OPJ_UINT32 p_header_size, |
178 opj_event_mgr_t * p_manager ); | 178 opj_event_mgr_t * p_manager ); |
179 | 179 |
180 /** | 180 /** |
| 181 * Writes the Jpeg2000 file Header box - JP2 Header box (warning, this is a supe
r box). |
| 182 * |
| 183 * @param jp2 the jpeg2000 file codec. |
| 184 * @param stream the stream to write data to. |
| 185 * @param p_manager user event manager. |
| 186 * |
| 187 * @return true if writing was successful. |
| 188 */ |
| 189 static OPJ_BOOL opj_jp2_write_jp2h(opj_jp2_t *jp2, |
| 190
opj_stream_private_t *stream, |
| 191
opj_event_mgr_t * p_manager ); |
| 192 |
| 193 /** |
181 * Writes the Jpeg2000 codestream Header box - JP2C Header box. This function mu
st be called AFTER the coding has been done. | 194 * Writes the Jpeg2000 codestream Header box - JP2C Header box. This function mu
st be called AFTER the coding has been done. |
182 * | 195 * |
183 * @param cio the stream to write data to. | 196 * @param cio the stream to write data to. |
184 * @param jp2 the jpeg2000 file codec. | 197 * @param jp2 the jpeg2000 file codec. |
185 * @param p_manager user event manager. | 198 * @param p_manager user event manager. |
186 * | 199 * |
187 * @return true if writing was successful. | 200 * @return true if writing was successful. |
188 */ | 201 */ |
189 static OPJ_BOOL opj_jp2_write_jp2c( opj_jp2_t *jp2, | 202 static OPJ_BOOL opj_jp2_write_jp2c( opj_jp2_t *jp2, |
190 opj_stream_p
rivate_t *cio, | 203 opj_stream_p
rivate_t *cio, |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
306 opj_event_mgr_t * p_manager ); | 319 opj_event_mgr_t * p_manager ); |
307 | 320 |
308 /*@}*/ | 321 /*@}*/ |
309 | 322 |
310 /*@}*/ | 323 /*@}*/ |
311 | 324 |
312 /** | 325 /** |
313 * Sets up the procedures to do on writing header after the codestream. | 326 * Sets up the procedures to do on writing header after the codestream. |
314 * Developpers wanting to extend the library can add their own writing procedure
s. | 327 * Developpers wanting to extend the library can add their own writing procedure
s. |
315 */ | 328 */ |
316 static void opj_jp2_setup_end_header_writing (opj_jp2_t *jp2); | 329 static OPJ_BOOL opj_jp2_setup_end_header_writing (opj_jp2_t *jp2, opj_event_mgr_
t * p_manager); |
317 | 330 |
318 /** | 331 /** |
319 * Sets up the procedures to do on reading header after the codestream. | 332 * Sets up the procedures to do on reading header after the codestream. |
320 * Developpers wanting to extend the library can add their own writing procedure
s. | 333 * Developpers wanting to extend the library can add their own writing procedure
s. |
321 */ | 334 */ |
322 static void opj_jp2_setup_end_header_reading (opj_jp2_t *jp2); | 335 static OPJ_BOOL opj_jp2_setup_end_header_reading (opj_jp2_t *jp2, opj_event_mgr_
t * p_manager); |
323 | 336 |
324 /** | 337 /** |
325 * Reads a jpeg2000 file header structure. | 338 * Reads a jpeg2000 file header structure. |
326 * | 339 * |
327 * @param jp2 the jpeg2000 file header structure. | 340 * @param jp2 the jpeg2000 file header structure. |
328 * @param stream the stream to read data from. | 341 * @param stream the stream to read data from. |
329 * @param p_manager the user event manager. | 342 * @param p_manager the user event manager. |
330 * | 343 * |
331 * @return true if the box is valid. | 344 * @return true if the box is valid. |
332 */ | 345 */ |
(...skipping 17 matching lines...) Expand all Loading... |
350 opj_event_mgr_t * p_manager ); | 363 opj_event_mgr_t * p_manager ); |
351 | 364 |
352 /** | 365 /** |
353 * Reads a box header. The box is the way data is packed inside a jpeg2000 file
structure. | 366 * Reads a box header. The box is the way data is packed inside a jpeg2000 file
structure. |
354 * | 367 * |
355 * @param cio the input stream
to read data from. | 368 * @param cio the input stream
to read data from. |
356 * @param box the box structur
e to fill. | 369 * @param box the box structur
e to fill. |
357 * @param p_number_bytes_read pointer to an int that will stor
e the number of bytes read from the stream (shoul usually be 2). | 370 * @param p_number_bytes_read pointer to an int that will stor
e the number of bytes read from the stream (shoul usually be 2). |
358 * @param p_manager user event manager. | 371 * @param p_manager user event manager. |
359 * | 372 * |
360 * @return» true if the box is reconized, false otherwise | 373 * @return» true if the box is recognized, false otherwise |
361 */ | 374 */ |
362 static OPJ_BOOL opj_jp2_read_boxhdr(opj_jp2_box_t *box, | 375 static OPJ_BOOL opj_jp2_read_boxhdr(opj_jp2_box_t *box, |
363 OPJ_UINT32 * p_number_bytes_read, | 376 OPJ_UINT32 * p_number_bytes_read, |
364 opj_stream_private_t *cio, | 377 opj_stream_private_t *cio, |
365 opj_event_mgr_t * p_manager); | 378 opj_event_mgr_t * p_manager); |
366 | 379 |
367 /** | 380 /** |
368 * Sets up the validation ,i.e. adds the procedures to lauch to make sure the co
dec parameters | 381 * Sets up the validation ,i.e. adds the procedures to lauch to make sure the co
dec parameters |
369 * are valid. Developpers wanting to extend the library can add their own valida
tion procedures. | 382 * are valid. Developpers wanting to extend the library can add their own valida
tion procedures. |
370 */ | 383 */ |
371 static void opj_jp2_setup_encoding_validation (opj_jp2_t *jp2); | 384 static OPJ_BOOL opj_jp2_setup_encoding_validation (opj_jp2_t *jp2, opj_event_mgr
_t * p_manager); |
372 | 385 |
373 /** | 386 /** |
374 * Sets up the procedures to do on writing header. Developpers wanting to extend
the library can add their own writing procedures. | 387 * Sets up the procedures to do on writing header. Developpers wanting to extend
the library can add their own writing procedures. |
375 */ | 388 */ |
376 static void opj_jp2_setup_header_writing (opj_jp2_t *jp2); | 389 static OPJ_BOOL opj_jp2_setup_header_writing (opj_jp2_t *jp2, opj_event_mgr_t *
p_manager); |
377 | 390 |
378 OPJ_BOOL opj_jp2_default_validation (» opj_jp2_t * jp2, | 391 static OPJ_BOOL opj_jp2_default_validation (» opj_jp2_t * jp2, |
379 opj_stream_private_t *cio, | 392 opj_stream_private_t *cio, |
380 opj_event_mgr_t * p_manager ); | 393 opj_event_mgr_t * p_manager ); |
381 | 394 |
382 /** | 395 /** |
383 * Finds the image execution function related to the given box id. | 396 * Finds the image execution function related to the given box id. |
384 * | 397 * |
385 * @param p_id the id of the handler to fetch. | 398 * @param p_id the id of the handler to fetch. |
386 * | 399 * |
387 * @return the given handler or NULL if it could not be found. | 400 * @return the given handler or NULL if it could not be found. |
388 */ | 401 */ |
389 static const opj_jp2_header_handler_t * opj_jp2_img_find_handler (OPJ_UINT32 p_i
d); | 402 static const opj_jp2_header_handler_t * opj_jp2_img_find_handler (OPJ_UINT32 p_i
d); |
390 | 403 |
391 /** | 404 /** |
392 * Finds the execution function related to the given box id. | 405 * Finds the execution function related to the given box id. |
393 * | 406 * |
394 * @param p_id the id of the handler to fetch. | 407 * @param p_id the id of the handler to fetch. |
395 * | 408 * |
396 * @return the given handler or NULL if it could not be found. | 409 * @return the given handler or NULL if it could not be found. |
397 */ | 410 */ |
398 static const opj_jp2_header_handler_t * opj_jp2_find_handler (OPJ_UINT32 p_id ); | 411 static const opj_jp2_header_handler_t * opj_jp2_find_handler (OPJ_UINT32 p_id ); |
399 | 412 |
400 const opj_jp2_header_handler_t jp2_header [] = | 413 static const opj_jp2_header_handler_t jp2_header [] = |
401 { | 414 { |
402 {JP2_JP,opj_jp2_read_jp}, | 415 {JP2_JP,opj_jp2_read_jp}, |
403 {JP2_FTYP,opj_jp2_read_ftyp}, | 416 {JP2_FTYP,opj_jp2_read_ftyp}, |
404 {JP2_JP2H,opj_jp2_read_jp2h} | 417 {JP2_JP2H,opj_jp2_read_jp2h} |
405 }; | 418 }; |
406 | 419 |
407 const opj_jp2_header_handler_t jp2_img_header [] = | 420 static const opj_jp2_header_handler_t jp2_img_header [] = |
408 { | 421 { |
409 {JP2_IHDR,opj_jp2_read_ihdr}, | 422 {JP2_IHDR,opj_jp2_read_ihdr}, |
410 {JP2_COLR,opj_jp2_read_colr}, | 423 {JP2_COLR,opj_jp2_read_colr}, |
411 {JP2_BPCC,opj_jp2_read_bpcc}, | 424 {JP2_BPCC,opj_jp2_read_bpcc}, |
412 {JP2_PCLR,opj_jp2_read_pclr}, | 425 {JP2_PCLR,opj_jp2_read_pclr}, |
413 {JP2_CMAP,opj_jp2_read_cmap}, | 426 {JP2_CMAP,opj_jp2_read_cmap}, |
414 {JP2_CDEF,opj_jp2_read_cdef} | 427 {JP2_CDEF,opj_jp2_read_cdef} |
415 | 428 |
416 }; | 429 }; |
417 | 430 |
418 /** | 431 /** |
419 * Reads a box header. The box is the way data is packed inside a jpeg2000 file
structure. Data is read from a character string | 432 * Reads a box header. The box is the way data is packed inside a jpeg2000 file
structure. Data is read from a character string |
420 * | 433 * |
421 * @param box the box structur
e to fill. | 434 * @param box the box structur
e to fill. |
422 * @param p_data the character string to
read data from. | 435 * @param p_data the character string to
read data from. |
423 * @param p_number_bytes_read pointer to an int that will stor
e the number of bytes read from the stream (shoul usually be 2). | 436 * @param p_number_bytes_read pointer to an int that will stor
e the number of bytes read from the stream (shoul usually be 2). |
424 * @param p_box_max_size the maximum number of bytes in t
he box. | 437 * @param p_box_max_size the maximum number of bytes in t
he box. |
425 * @param p_manager FIXME DOC | 438 * @param p_manager FIXME DOC |
426 * | 439 * |
427 * @return» true if the box is reconized, false otherwise | 440 * @return» true if the box is recognized, false otherwise |
428 */ | 441 */ |
429 static OPJ_BOOL opj_jp2_read_boxhdr_char( opj_jp2_box_t *box, | 442 static OPJ_BOOL opj_jp2_read_boxhdr_char( opj_jp2_box_t *box, |
430 OPJ_BYTE * p_data, | 443 OPJ_BYTE * p_data, |
431 OPJ_UINT32 * p_number_bytes_read, | 444 OPJ_UINT32 * p_number_bytes_read, |
432 OPJ_UINT32 p_box_max_size, | 445 OPJ_UINT32 p_box_max_size, |
433 opj_event_mgr_t * p_manager ); | 446 opj_event_mgr_t * p_manager ); |
434 | 447 |
435 /** | 448 /** |
436 * Sets up the validation ,i.e. adds the procedures to lauch to make sure the co
dec parameters | 449 * Sets up the validation ,i.e. adds the procedures to lauch to make sure the co
dec parameters |
437 * are valid. Developpers wanting to extend the library can add their own valida
tion procedures. | 450 * are valid. Developpers wanting to extend the library can add their own valida
tion procedures. |
438 */ | 451 */ |
439 static void opj_jp2_setup_decoding_validation (opj_jp2_t *jp2); | 452 static OPJ_BOOL opj_jp2_setup_decoding_validation (opj_jp2_t *jp2, opj_event_mgr
_t * p_manager); |
440 | 453 |
441 /** | 454 /** |
442 * Sets up the procedures to do on reading header. | 455 * Sets up the procedures to do on reading header. |
443 * Developpers wanting to extend the library can add their own writing procedure
s. | 456 * Developpers wanting to extend the library can add their own writing procedure
s. |
444 */ | 457 */ |
445 static void opj_jp2_setup_header_reading (opj_jp2_t *jp2); | 458 static OPJ_BOOL opj_jp2_setup_header_reading (opj_jp2_t *jp2, opj_event_mgr_t *
p_manager); |
446 | 459 |
447 /* ----------------------------------------------------------------------- */ | 460 /* ----------------------------------------------------------------------- */ |
448 OPJ_BOOL opj_jp2_read_boxhdr(opj_jp2_box_t *box, | 461 static OPJ_BOOL opj_jp2_read_boxhdr(opj_jp2_box_t *box, |
449 OPJ_UINT32 * p_number_bytes_read, | 462 OPJ_UINT32 * p_number_bytes_read, |
450 opj_stream_private_t *cio, | 463 opj_stream_private_t *cio, |
451 opj_event_mgr_t * p_manager ) | 464 opj_event_mgr_t * p_manager ) |
452 { | 465 { |
453 /* read header from file */ | 466 /* read header from file */ |
454 OPJ_BYTE l_data_header [8]; | 467 OPJ_BYTE l_data_header [8]; |
455 | 468 |
456 /* preconditions */ | 469 /* preconditions */ |
457 assert(cio != 00); | 470 assert(cio != 00); |
458 assert(box != 00); | 471 assert(box != 00); |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
518 } | 531 } |
519 } | 532 } |
520 | 533 |
521 box.length = cio_tell(cio) - box.init_pos; | 534 box.length = cio_tell(cio) - box.init_pos; |
522 cio_seek(cio, box.init_pos); | 535 cio_seek(cio, box.init_pos); |
523 cio_write(cio, box.length, 4); /* L */ | 536 cio_write(cio, box.length, 4); /* L */ |
524 cio_seek(cio, box.init_pos + box.length); | 537 cio_seek(cio, box.init_pos + box.length); |
525 } | 538 } |
526 #endif | 539 #endif |
527 | 540 |
528 OPJ_BOOL opj_jp2_read_ihdr( opj_jp2_t *jp2, | 541 static OPJ_BOOL opj_jp2_read_ihdr( opj_jp2_t *jp2, |
529 OPJ_BYTE *p_image_header_data, | 542 OPJ_BYTE *p_image_header_data, |
530 OPJ_UINT32 p_image_header_size, | 543 OPJ_UINT32 p_image_header_size, |
531 opj_event_mgr_t * p_manager ) | 544 opj_event_mgr_t * p_manager ) |
532 { | 545 { |
533 /* preconditions */ | 546 /* preconditions */ |
534 assert(p_image_header_data != 00); | 547 assert(p_image_header_data != 00); |
535 assert(jp2 != 00); | 548 assert(jp2 != 00); |
536 assert(p_manager != 00); | 549 assert(p_manager != 00); |
537 | 550 |
538 if (p_image_header_size != 14) { | 551 if (p_image_header_size != 14) { |
(...skipping 27 matching lines...) Expand all Loading... |
566 } | 579 } |
567 | 580 |
568 opj_read_bytes(p_image_header_data,&(jp2->UnkC),1);
/* UnkC */ | 581 opj_read_bytes(p_image_header_data,&(jp2->UnkC),1);
/* UnkC */ |
569 ++ p_image_header_data; | 582 ++ p_image_header_data; |
570 opj_read_bytes(p_image_header_data,&(jp2->IPR),1);
/* IPR */ | 583 opj_read_bytes(p_image_header_data,&(jp2->IPR),1);
/* IPR */ |
571 ++ p_image_header_data; | 584 ++ p_image_header_data; |
572 | 585 |
573 return OPJ_TRUE; | 586 return OPJ_TRUE; |
574 } | 587 } |
575 | 588 |
576 OPJ_BYTE * opj_jp2_write_ihdr(opj_jp2_t *jp2, | 589 static OPJ_BYTE * opj_jp2_write_ihdr(opj_jp2_t *jp2, |
577 OPJ_UINT32 * p_nb_bytes_written | 590 OPJ_UINT32 * p_nb_bytes_written |
578 ) | 591 ) |
579 { | 592 { |
580 OPJ_BYTE * l_ihdr_data,* l_current_ihdr_ptr; | 593 OPJ_BYTE * l_ihdr_data,* l_current_ihdr_ptr; |
581 | 594 |
582 /* preconditions */ | 595 /* preconditions */ |
583 assert(jp2 != 00); | 596 assert(jp2 != 00); |
584 assert(p_nb_bytes_written != 00); | 597 assert(p_nb_bytes_written != 00); |
585 | 598 |
586 /* default image header is 22 bytes wide */ | 599 /* default image header is 22 bytes wide */ |
(...skipping 29 matching lines...) Expand all Loading... |
616 ++l_current_ihdr_ptr; | 629 ++l_current_ihdr_ptr; |
617 | 630 |
618 opj_write_bytes(l_current_ihdr_ptr, jp2->IPR, 1); /* IPR,
no intellectual property */ | 631 opj_write_bytes(l_current_ihdr_ptr, jp2->IPR, 1); /* IPR,
no intellectual property */ |
619 ++l_current_ihdr_ptr; | 632 ++l_current_ihdr_ptr; |
620 | 633 |
621 *p_nb_bytes_written = 22; | 634 *p_nb_bytes_written = 22; |
622 | 635 |
623 return l_ihdr_data; | 636 return l_ihdr_data; |
624 } | 637 } |
625 | 638 |
626 OPJ_BYTE * opj_jp2_write_bpcc(» opj_jp2_t *jp2, | 639 static OPJ_BYTE * opj_jp2_write_bpcc(» opj_jp2_t *jp2, |
627 OPJ_UINT32 * p_nb_bytes_
written | 640 OPJ_UINT32 * p_nb_bytes_
written |
628 ) | 641 ) |
629 { | 642 { |
630 OPJ_UINT32 i; | 643 OPJ_UINT32 i; |
631 /* room for 8 bytes for box and 1 byte for each component */ | 644 /* room for 8 bytes for box and 1 byte for each component */ |
632 OPJ_UINT32 l_bpcc_size = 8 + jp2->numcomps; | 645 OPJ_UINT32 l_bpcc_size = 8 + jp2->numcomps; |
633 OPJ_BYTE * l_bpcc_data,* l_current_bpcc_ptr; | 646 OPJ_BYTE * l_bpcc_data,* l_current_bpcc_ptr; |
634 | 647 |
635 /* preconditions */ | 648 /* preconditions */ |
636 assert(jp2 != 00); | 649 assert(jp2 != 00); |
(...skipping 15 matching lines...) Expand all Loading... |
652 for (i = 0; i < jp2->numcomps; ++i) { | 665 for (i = 0; i < jp2->numcomps; ++i) { |
653 opj_write_bytes(l_current_bpcc_ptr, jp2->comps[i].bpcc, 1); /* w
rite each component information */ | 666 opj_write_bytes(l_current_bpcc_ptr, jp2->comps[i].bpcc, 1); /* w
rite each component information */ |
654 ++l_current_bpcc_ptr; | 667 ++l_current_bpcc_ptr; |
655 } | 668 } |
656 | 669 |
657 *p_nb_bytes_written = l_bpcc_size; | 670 *p_nb_bytes_written = l_bpcc_size; |
658 | 671 |
659 return l_bpcc_data; | 672 return l_bpcc_data; |
660 } | 673 } |
661 | 674 |
662 OPJ_BOOL opj_jp2_read_bpcc( opj_jp2_t *jp2, | 675 static OPJ_BOOL opj_jp2_read_bpcc( opj_jp2_t *jp2, |
663 OPJ_BYTE * p_bpc_header_data, | 676 OPJ_BYTE * p_bpc_header_data, |
664 OPJ_UINT32 p_bpc_header_size, | 677 OPJ_UINT32 p_bpc_header_size, |
665 opj_event_mgr_t * p_manager | 678 opj_event_mgr_t * p_manager |
666 ) | 679 ) |
667 { | 680 { |
668 OPJ_UINT32 i; | 681 OPJ_UINT32 i; |
669 | 682 |
670 /* preconditions */ | 683 /* preconditions */ |
671 assert(p_bpc_header_data != 00); | 684 assert(p_bpc_header_data != 00); |
672 assert(jp2 != 00); | 685 assert(jp2 != 00); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
734 l_current_cdef_ptr += 2; | 747 l_current_cdef_ptr += 2; |
735 l_value = jp2->color.jp2_cdef->info[i].asoc; | 748 l_value = jp2->color.jp2_cdef->info[i].asoc; |
736 opj_write_bytes(l_current_cdef_ptr,l_value,2);
/* Asoci */ | 749 opj_write_bytes(l_current_cdef_ptr,l_value,2);
/* Asoci */ |
737 l_current_cdef_ptr += 2; | 750 l_current_cdef_ptr += 2; |
738 } | 751 } |
739 *p_nb_bytes_written = l_cdef_size; | 752 *p_nb_bytes_written = l_cdef_size; |
740 | 753 |
741 return l_cdef_data; | 754 return l_cdef_data; |
742 } | 755 } |
743 | 756 |
744 OPJ_BYTE * opj_jp2_write_colr( opj_jp2_t *jp2, | 757 static OPJ_BYTE * opj_jp2_write_colr( opj_jp2_t *jp2, |
745 OPJ_UINT32 * p_nb_by
tes_written | 758 OPJ_UINT32 * p_nb_by
tes_written |
746 ) | 759 ) |
747 { | 760 { |
748 /* room for 8 bytes for box 3 for common data and variable upon profile*
/ | 761 /* room for 8 bytes for box 3 for common data and variable upon profile*
/ |
749 OPJ_UINT32 l_colr_size = 11; | 762 OPJ_UINT32 l_colr_size = 11; |
750 OPJ_BYTE * l_colr_data,* l_current_colr_ptr; | 763 OPJ_BYTE * l_colr_data,* l_current_colr_ptr; |
751 | 764 |
752 /* preconditions */ | 765 /* preconditions */ |
753 assert(jp2 != 00); | 766 assert(jp2 != 00); |
754 assert(p_nb_bytes_written != 00); | 767 assert(p_nb_bytes_written != 00); |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
798 ++l_current_colr_ptr; | 811 ++l_current_colr_ptr; |
799 } | 812 } |
800 } | 813 } |
801 } | 814 } |
802 | 815 |
803 *p_nb_bytes_written = l_colr_size; | 816 *p_nb_bytes_written = l_colr_size; |
804 | 817 |
805 return l_colr_data; | 818 return l_colr_data; |
806 } | 819 } |
807 | 820 |
808 void opj_jp2_free_pclr(opj_jp2_color_t *color) | 821 static void opj_jp2_free_pclr(opj_jp2_color_t *color) |
809 { | 822 { |
810 opj_free(color->jp2_pclr->channel_sign); | 823 opj_free(color->jp2_pclr->channel_sign); |
811 opj_free(color->jp2_pclr->channel_size); | 824 opj_free(color->jp2_pclr->channel_size); |
812 opj_free(color->jp2_pclr->entries); | 825 opj_free(color->jp2_pclr->entries); |
813 | 826 |
814 if(color->jp2_pclr->cmap) opj_free(color->jp2_pclr->cmap); | 827 if(color->jp2_pclr->cmap) opj_free(color->jp2_pclr->cmap); |
815 | 828 |
816 opj_free(color->jp2_pclr); color->jp2_pclr = NULL; | 829 opj_free(color->jp2_pclr); color->jp2_pclr = NULL; |
817 } | 830 } |
818 | 831 |
(...skipping 10 matching lines...) Expand all Loading... |
829 /* cdef applies to cmap channels if any */ | 842 /* cdef applies to cmap channels if any */ |
830 if (color->jp2_pclr && color->jp2_pclr->cmap) { | 843 if (color->jp2_pclr && color->jp2_pclr->cmap) { |
831 nr_channels = (OPJ_UINT32)color->jp2_pclr->nr_channels; | 844 nr_channels = (OPJ_UINT32)color->jp2_pclr->nr_channels; |
832 } | 845 } |
833 | 846 |
834 for (i = 0; i < n; i++) { | 847 for (i = 0; i < n; i++) { |
835 if (info[i].cn >= nr_channels) { | 848 if (info[i].cn >= nr_channels) { |
836 opj_event_msg(p_manager, EVT_ERROR, "Invalid com
ponent index %d (>= %d).\n", info[i].cn, nr_channels); | 849 opj_event_msg(p_manager, EVT_ERROR, "Invalid com
ponent index %d (>= %d).\n", info[i].cn, nr_channels); |
837 return OPJ_FALSE; | 850 return OPJ_FALSE; |
838 } | 851 } |
| 852 if (info[i].asoc == 65535U) continue; |
| 853 |
839 if (info[i].asoc > 0 && (OPJ_UINT32)(info[i].asoc - 1) >
= nr_channels) { | 854 if (info[i].asoc > 0 && (OPJ_UINT32)(info[i].asoc - 1) >
= nr_channels) { |
840 opj_event_msg(p_manager, EVT_ERROR, "Invalid com
ponent index %d (>= %d).\n", info[i].asoc - 1, nr_channels); | 855 opj_event_msg(p_manager, EVT_ERROR, "Invalid com
ponent index %d (>= %d).\n", info[i].asoc - 1, nr_channels); |
841 return OPJ_FALSE; | 856 return OPJ_FALSE; |
842 } | 857 } |
843 } | 858 } |
844 | 859 |
845 /* issue 397 */ | 860 /* issue 397 */ |
846 /* ISO 15444-1 states that if cdef is present, it shall contain
a complete list of channel definitions. */ | 861 /* ISO 15444-1 states that if cdef is present, it shall contain
a complete list of channel definitions. */ |
847 while (nr_channels > 0) | 862 while (nr_channels > 0) |
848 { | 863 { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
900 else | 915 else |
901 pcol_usage[pcol] = OPJ_TRUE; | 916 pcol_usage[pcol] = OPJ_TRUE; |
902 } | 917 } |
903 /* verify that all components are targeted at least once */ | 918 /* verify that all components are targeted at least once */ |
904 for (i = 0; i < nr_channels; i++) { | 919 for (i = 0; i < nr_channels; i++) { |
905 if (!pcol_usage[i] && cmap[i].mtyp != 0) { | 920 if (!pcol_usage[i] && cmap[i].mtyp != 0) { |
906 opj_event_msg(p_manager, EVT_ERROR, "Component %
d doesn't have a mapping.\n", i); | 921 opj_event_msg(p_manager, EVT_ERROR, "Component %
d doesn't have a mapping.\n", i); |
907 is_sane = OPJ_FALSE; | 922 is_sane = OPJ_FALSE; |
908 } | 923 } |
909 } | 924 } |
| 925 /* Issue 235/447 weird cmap */ |
| 926 if (1 && is_sane && (image->numcomps==1U)) { |
| 927 for (i = 0; i < nr_channels; i++) { |
| 928 if (!pcol_usage[i]) { |
| 929 is_sane = 0U; |
| 930 opj_event_msg(p_manager, EVT_WARNING, "C
omponent mapping seems wrong. Trying to correct.\n", i); |
| 931 break; |
| 932 } |
| 933 } |
| 934 if (!is_sane) { |
| 935 is_sane = OPJ_TRUE; |
| 936 for (i = 0; i < nr_channels; i++) { |
| 937 cmap[i].mtyp = 1U; |
| 938 cmap[i].pcol = (OPJ_BYTE) i; |
| 939 } |
| 940 } |
| 941 } |
910 opj_free(pcol_usage); | 942 opj_free(pcol_usage); |
911 if (!is_sane) { | 943 if (!is_sane) { |
912 return OPJ_FALSE; | 944 return OPJ_FALSE; |
913 } | 945 } |
914 } | 946 } |
915 | 947 |
916 return OPJ_TRUE; | 948 return OPJ_TRUE; |
917 } | 949 } |
918 | 950 |
919 /* file9.jp2 */ | 951 /* file9.jp2 */ |
920 void opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color) | 952 static void opj_jp2_apply_pclr(opj_image_t *image, opj_jp2_color_t *color) |
921 { | 953 { |
922 opj_image_comp_t *old_comps, *new_comps; | 954 opj_image_comp_t *old_comps, *new_comps; |
923 OPJ_BYTE *channel_size, *channel_sign; | 955 OPJ_BYTE *channel_size, *channel_sign; |
924 OPJ_UINT32 *entries; | 956 OPJ_UINT32 *entries; |
925 opj_jp2_cmap_comp_t *cmap; | 957 opj_jp2_cmap_comp_t *cmap; |
926 OPJ_INT32 *src, *dst; | 958 OPJ_INT32 *src, *dst; |
927 OPJ_UINT32 j, max; | 959 OPJ_UINT32 j, max; |
928 OPJ_UINT16 i, nr_channels, cmp, pcol; | 960 OPJ_UINT16 i, nr_channels, cmp, pcol; |
929 OPJ_INT32 k, top_k; | 961 OPJ_INT32 k, top_k; |
930 | 962 |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1006 } | 1038 } |
1007 | 1039 |
1008 opj_free(old_comps); | 1040 opj_free(old_comps); |
1009 image->comps = new_comps; | 1041 image->comps = new_comps; |
1010 image->numcomps = nr_channels; | 1042 image->numcomps = nr_channels; |
1011 | 1043 |
1012 opj_jp2_free_pclr(color); | 1044 opj_jp2_free_pclr(color); |
1013 | 1045 |
1014 }/* apply_pclr() */ | 1046 }/* apply_pclr() */ |
1015 | 1047 |
1016 OPJ_BOOL opj_jp2_read_pclr(» opj_jp2_t *jp2, | 1048 static OPJ_BOOL opj_jp2_read_pclr(» opj_jp2_t *jp2, |
1017 OPJ_BYTE * p_pclr_header_data, | 1049 OPJ_BYTE * p_pclr_header_data, |
1018 OPJ_UINT32 p_pclr_header_size, | 1050 OPJ_UINT32 p_pclr_header_size, |
1019 opj_event_mgr_t * p_manager | 1051 opj_event_mgr_t * p_manager |
1020 ) | 1052 ) |
1021 { | 1053 { |
1022 opj_jp2_pclr_t *jp2_pclr; | 1054 opj_jp2_pclr_t *jp2_pclr; |
1023 OPJ_BYTE *channel_size, *channel_sign; | 1055 OPJ_BYTE *channel_size, *channel_sign; |
1024 OPJ_UINT32 *entries; | 1056 OPJ_UINT32 *entries; |
1025 OPJ_UINT16 nr_entries,nr_channels; | 1057 OPJ_UINT16 nr_entries,nr_channels; |
1026 OPJ_UINT16 i, j; | 1058 OPJ_UINT16 i, j; |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1113 opj_read_bytes(p_pclr_header_data, &l_value , bytes_to_r
ead); /* Cji */ | 1145 opj_read_bytes(p_pclr_header_data, &l_value , bytes_to_r
ead); /* Cji */ |
1114 p_pclr_header_data += bytes_to_read; | 1146 p_pclr_header_data += bytes_to_read; |
1115 *entries = (OPJ_UINT32) l_value; | 1147 *entries = (OPJ_UINT32) l_value; |
1116 entries++; | 1148 entries++; |
1117 } | 1149 } |
1118 } | 1150 } |
1119 | 1151 |
1120 return OPJ_TRUE; | 1152 return OPJ_TRUE; |
1121 } | 1153 } |
1122 | 1154 |
1123 OPJ_BOOL opj_jp2_read_cmap(» opj_jp2_t * jp2, | 1155 static OPJ_BOOL opj_jp2_read_cmap(» opj_jp2_t * jp2, |
1124 OPJ_BYTE * p_cmap_header_data, | 1156 OPJ_BYTE * p_cmap_header_data, |
1125 OPJ_UINT32 p_cmap_header_size, | 1157 OPJ_UINT32 p_cmap_header_size, |
1126 opj_event_mgr_t * p_manager | 1158 opj_event_mgr_t * p_manager |
1127 ) | 1159 ) |
1128 { | 1160 { |
1129 opj_jp2_cmap_comp_t *cmap; | 1161 opj_jp2_cmap_comp_t *cmap; |
1130 OPJ_BYTE i, nr_channels; | 1162 OPJ_BYTE i, nr_channels; |
1131 OPJ_UINT32 l_value; | 1163 OPJ_UINT32 l_value; |
1132 | 1164 |
1133 /* preconditions */ | 1165 /* preconditions */ |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1173 opj_read_bytes(p_cmap_header_data, &l_value, 1);
/* PCOL^i */ | 1205 opj_read_bytes(p_cmap_header_data, &l_value, 1);
/* PCOL^i */ |
1174 ++p_cmap_header_data; | 1206 ++p_cmap_header_data; |
1175 cmap[i].pcol = (OPJ_BYTE) l_value; | 1207 cmap[i].pcol = (OPJ_BYTE) l_value; |
1176 } | 1208 } |
1177 | 1209 |
1178 jp2->color.jp2_pclr->cmap = cmap; | 1210 jp2->color.jp2_pclr->cmap = cmap; |
1179 | 1211 |
1180 return OPJ_TRUE; | 1212 return OPJ_TRUE; |
1181 } | 1213 } |
1182 | 1214 |
1183 void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color) | 1215 static void opj_jp2_apply_cdef(opj_image_t *image, opj_jp2_color_t *color, opj_e
vent_mgr_t *manager) |
1184 { | 1216 { |
1185 opj_jp2_cdef_info_t *info; | 1217 opj_jp2_cdef_info_t *info; |
1186 OPJ_UINT16 i, n, cn, asoc, acn; | 1218 OPJ_UINT16 i, n, cn, asoc, acn; |
1187 | 1219 |
1188 info = color->jp2_cdef->info; | 1220 info = color->jp2_cdef->info; |
1189 n = color->jp2_cdef->n; | 1221 n = color->jp2_cdef->n; |
1190 | 1222 |
1191 for(i = 0; i < n; ++i) | 1223 for(i = 0; i < n; ++i) |
1192 { | 1224 { |
1193 /* WATCH: acn = asoc - 1 ! */ | 1225 /* WATCH: acn = asoc - 1 ! */ |
1194 asoc = info[i].asoc; | 1226 asoc = info[i].asoc; |
1195 cn = info[i].cn; | 1227 cn = info[i].cn; |
1196 | 1228 |
1197 if( cn >= image->numcomps) | 1229 if( cn >= image->numcomps) |
1198 { | 1230 { |
1199 » » » fprintf(stderr, "cn=%d, numcomps=%d\n", cn, image->numco
mps); | 1231 » » » opj_event_msg(manager, EVT_WARNING, "opj_jp2_apply_cdef:
cn=%d, numcomps=%d\n", cn, image->numcomps); |
1200 continue; | 1232 continue; |
1201 } | 1233 } |
1202 if(asoc == 0 || asoc == 65535) | 1234 if(asoc == 0 || asoc == 65535) |
1203 { | 1235 { |
1204 image->comps[cn].alpha = info[i].typ; | 1236 image->comps[cn].alpha = info[i].typ; |
1205 continue; | 1237 continue; |
1206 } | 1238 } |
1207 | 1239 |
1208 acn = (OPJ_UINT16)(asoc - 1); | 1240 acn = (OPJ_UINT16)(asoc - 1); |
1209 if( acn >= image->numcomps ) | 1241 if( acn >= image->numcomps ) |
1210 { | 1242 { |
1211 » » » fprintf(stderr, "acn=%d, numcomps=%d\n", acn, image->num
comps); | 1243 » » » opj_event_msg(manager, EVT_WARNING, "opj_jp2_apply_cdef:
acn=%d, numcomps=%d\n", acn, image->numcomps); |
1212 continue; | 1244 continue; |
1213 } | 1245 } |
1214 | 1246 |
1215 /* Swap only if color channel */ | 1247 /* Swap only if color channel */ |
1216 if((cn != acn) && (info[i].typ == 0)) | 1248 if((cn != acn) && (info[i].typ == 0)) |
1217 { | 1249 { |
1218 opj_image_comp_t saved; | 1250 opj_image_comp_t saved; |
1219 OPJ_UINT16 j; | 1251 OPJ_UINT16 j; |
1220 | 1252 |
1221 memcpy(&saved, &image->comps[cn], sizeof(opj_image_comp_
t)); | 1253 memcpy(&saved, &image->comps[cn], sizeof(opj_image_comp_
t)); |
(...skipping 15 matching lines...) Expand all Loading... |
1237 | 1269 |
1238 image->comps[cn].alpha = info[i].typ; | 1270 image->comps[cn].alpha = info[i].typ; |
1239 } | 1271 } |
1240 | 1272 |
1241 if(color->jp2_cdef->info) opj_free(color->jp2_cdef->info); | 1273 if(color->jp2_cdef->info) opj_free(color->jp2_cdef->info); |
1242 | 1274 |
1243 opj_free(color->jp2_cdef); color->jp2_cdef = NULL; | 1275 opj_free(color->jp2_cdef); color->jp2_cdef = NULL; |
1244 | 1276 |
1245 }/* jp2_apply_cdef() */ | 1277 }/* jp2_apply_cdef() */ |
1246 | 1278 |
1247 OPJ_BOOL opj_jp2_read_cdef(» opj_jp2_t * jp2, | 1279 static OPJ_BOOL opj_jp2_read_cdef(» opj_jp2_t * jp2, |
1248 OPJ_BYTE * p_cdef_header_data, | 1280 OPJ_BYTE * p_cdef_header_data, |
1249 OPJ_UINT32 p_cdef_header
_size, | 1281 OPJ_UINT32 p_cdef_header
_size, |
1250 opj_event_mgr_t * p_mana
ger | 1282 opj_event_mgr_t * p_mana
ger |
1251 ) | 1283 ) |
1252 { | 1284 { |
1253 opj_jp2_cdef_info_t *cdef_info; | 1285 opj_jp2_cdef_info_t *cdef_info; |
1254 OPJ_UINT16 i; | 1286 OPJ_UINT16 i; |
1255 OPJ_UINT32 l_value; | 1287 OPJ_UINT32 l_value; |
1256 | 1288 |
1257 /* preconditions */ | 1289 /* preconditions */ |
(...skipping 18 matching lines...) Expand all Loading... |
1276 opj_event_msg(p_manager, EVT_ERROR, "Number of channel descripti
on is equal to zero in CDEF box.\n"); | 1308 opj_event_msg(p_manager, EVT_ERROR, "Number of channel descripti
on is equal to zero in CDEF box.\n"); |
1277 return OPJ_FALSE; | 1309 return OPJ_FALSE; |
1278 } | 1310 } |
1279 | 1311 |
1280 if (p_cdef_header_size < 2 + (OPJ_UINT32)(OPJ_UINT16)l_value * 6) { | 1312 if (p_cdef_header_size < 2 + (OPJ_UINT32)(OPJ_UINT16)l_value * 6) { |
1281 opj_event_msg(p_manager, EVT_ERROR, "Insufficient data for CDEF
box.\n"); | 1313 opj_event_msg(p_manager, EVT_ERROR, "Insufficient data for CDEF
box.\n"); |
1282 return OPJ_FALSE; | 1314 return OPJ_FALSE; |
1283 } | 1315 } |
1284 | 1316 |
1285 cdef_info = (opj_jp2_cdef_info_t*) opj_malloc(l_value * sizeof(opj_jp2_c
def_info_t)); | 1317 cdef_info = (opj_jp2_cdef_info_t*) opj_malloc(l_value * sizeof(opj_jp2_c
def_info_t)); |
1286 if (!cdef_info) | 1318 » if (!cdef_info) |
1287 return OPJ_FALSE; | 1319 » » return OPJ_FALSE; |
1288 | 1320 |
1289 jp2->color.jp2_cdef = (opj_jp2_cdef_t*)opj_malloc(sizeof(opj_jp2_cdef_t)
); | 1321 jp2->color.jp2_cdef = (opj_jp2_cdef_t*)opj_malloc(sizeof(opj_jp2_cdef_t)
); |
1290 if(!jp2->color.jp2_cdef) | 1322 » if(!jp2->color.jp2_cdef) |
1291 { | 1323 » { |
1292 opj_free(cdef_info); | 1324 » » opj_free(cdef_info); |
1293 return OPJ_FALSE; | 1325 » » return OPJ_FALSE; |
1294 } | 1326 » } |
1295 jp2->color.jp2_cdef->info = cdef_info; | 1327 jp2->color.jp2_cdef->info = cdef_info; |
1296 jp2->color.jp2_cdef->n = (OPJ_UINT16) l_value; | 1328 jp2->color.jp2_cdef->n = (OPJ_UINT16) l_value; |
1297 | 1329 |
1298 for(i = 0; i < jp2->color.jp2_cdef->n; ++i) { | 1330 for(i = 0; i < jp2->color.jp2_cdef->n; ++i) { |
1299 opj_read_bytes(p_cdef_header_data, &l_value, 2);
/* Cn^i */ | 1331 opj_read_bytes(p_cdef_header_data, &l_value, 2);
/* Cn^i */ |
1300 p_cdef_header_data +=2; | 1332 p_cdef_header_data +=2; |
1301 cdef_info[i].cn = (OPJ_UINT16) l_value; | 1333 cdef_info[i].cn = (OPJ_UINT16) l_value; |
1302 | 1334 |
1303 opj_read_bytes(p_cdef_header_data, &l_value, 2);
/* Typ^i */ | 1335 opj_read_bytes(p_cdef_header_data, &l_value, 2);
/* Typ^i */ |
1304 p_cdef_header_data +=2; | 1336 p_cdef_header_data +=2; |
1305 cdef_info[i].typ = (OPJ_UINT16) l_value; | 1337 cdef_info[i].typ = (OPJ_UINT16) l_value; |
1306 | 1338 |
1307 opj_read_bytes(p_cdef_header_data, &l_value, 2);
/* Asoc^i */ | 1339 opj_read_bytes(p_cdef_header_data, &l_value, 2);
/* Asoc^i */ |
1308 p_cdef_header_data +=2; | 1340 p_cdef_header_data +=2; |
1309 cdef_info[i].asoc = (OPJ_UINT16) l_value; | 1341 cdef_info[i].asoc = (OPJ_UINT16) l_value; |
1310 } | 1342 } |
1311 | 1343 |
1312 return OPJ_TRUE; | 1344 return OPJ_TRUE; |
1313 } | 1345 } |
1314 | 1346 |
1315 OPJ_BOOL opj_jp2_read_colr( opj_jp2_t *jp2, | 1347 static OPJ_BOOL opj_jp2_read_colr( opj_jp2_t *jp2, |
1316 OPJ_BYTE * p_colr_header_data, | 1348 OPJ_BYTE * p_colr_header_data, |
1317 OPJ_UINT32 p_colr_header_size, | 1349 OPJ_UINT32 p_colr_header_size, |
1318 opj_event_mgr_t * p_manager | 1350 opj_event_mgr_t * p_manager |
1319 ) | 1351 ) |
1320 { | 1352 { |
1321 OPJ_UINT32 l_value; | 1353 OPJ_UINT32 l_value; |
1322 | 1354 |
1323 /* preconditions */ | 1355 /* preconditions */ |
1324 assert(jp2 != 00); | 1356 assert(jp2 != 00); |
1325 assert(p_colr_header_data != 00); | 1357 assert(p_colr_header_data != 00); |
(...skipping 20 matching lines...) Expand all Loading... |
1346 ++p_colr_header_data; | 1378 ++p_colr_header_data; |
1347 | 1379 |
1348 opj_read_bytes(p_colr_header_data,&jp2->approx ,1);
/* APPROX */ | 1380 opj_read_bytes(p_colr_header_data,&jp2->approx ,1);
/* APPROX */ |
1349 ++p_colr_header_data; | 1381 ++p_colr_header_data; |
1350 | 1382 |
1351 if (jp2->meth == 1) { | 1383 if (jp2->meth == 1) { |
1352 if (p_colr_header_size < 7) { | 1384 if (p_colr_header_size < 7) { |
1353 opj_event_msg(p_manager, EVT_ERROR, "Bad COLR header box
(bad size: %d)\n", p_colr_header_size); | 1385 opj_event_msg(p_manager, EVT_ERROR, "Bad COLR header box
(bad size: %d)\n", p_colr_header_size); |
1354 return OPJ_FALSE; | 1386 return OPJ_FALSE; |
1355 } | 1387 } |
1356 » » if (p_colr_header_size > 7) { | 1388 » » if ((p_colr_header_size > 7) && (jp2->enumcs != 14)) { /* handle
d below for CIELab) */ |
1357 /* testcase Altona_Technical_v20_x4.pdf */ | 1389 /* testcase Altona_Technical_v20_x4.pdf */ |
1358 opj_event_msg(p_manager, EVT_WARNING, "Bad COLR header b
ox (bad size: %d)\n", p_colr_header_size); | 1390 opj_event_msg(p_manager, EVT_WARNING, "Bad COLR header b
ox (bad size: %d)\n", p_colr_header_size); |
1359 } | 1391 } |
1360 | 1392 |
1361 opj_read_bytes(p_colr_header_data,&jp2->enumcs ,4);
/* EnumCS */ | 1393 opj_read_bytes(p_colr_header_data,&jp2->enumcs ,4);
/* EnumCS */ |
1362 | 1394 |
1363 jp2->color.jp2_has_colr = 1; | 1395 » » p_colr_header_data += 4; |
| 1396 |
| 1397 » » if(jp2->enumcs == 14)/* CIELab */ |
| 1398 » » { |
| 1399 » » » OPJ_UINT32 *cielab; |
| 1400 » » » OPJ_UINT32 rl, ol, ra, oa, rb, ob, il; |
| 1401 |
| 1402 » » » cielab = (OPJ_UINT32*)opj_malloc(9 * sizeof(OPJ_UINT32))
; |
| 1403 » » » cielab[0] = 14; /* enumcs */ |
| 1404 » » » |
| 1405 » » » /* default values */ |
| 1406 » » » rl = ra = rb = ol = oa = ob = 0; |
| 1407 » » » il = 0x00443530; /* D50 */ |
| 1408 » » » cielab[1] = 0x44454600;/* DEF */ |
| 1409 |
| 1410 » » » if(p_colr_header_size == 35) |
| 1411 » » » { |
| 1412 » » » » opj_read_bytes(p_colr_header_data, &rl, 4); |
| 1413 » » » » p_colr_header_data += 4; |
| 1414 » » » » opj_read_bytes(p_colr_header_data, &ol, 4); |
| 1415 » » » » p_colr_header_data += 4; |
| 1416 » » » » opj_read_bytes(p_colr_header_data, &ra, 4); |
| 1417 » » » » p_colr_header_data += 4; |
| 1418 » » » » opj_read_bytes(p_colr_header_data, &oa, 4); |
| 1419 » » » » p_colr_header_data += 4; |
| 1420 » » » » opj_read_bytes(p_colr_header_data, &rb, 4); |
| 1421 » » » » p_colr_header_data += 4; |
| 1422 » » » » opj_read_bytes(p_colr_header_data, &ob, 4); |
| 1423 » » » » p_colr_header_data += 4; |
| 1424 » » » » opj_read_bytes(p_colr_header_data, &il, 4); |
| 1425 » » » » p_colr_header_data += 4; |
| 1426 » » » » |
| 1427 » » » » cielab[1] = 0; |
| 1428 » » » } |
| 1429 » » » else if(p_colr_header_size != 7) |
| 1430 » » » { |
| 1431 » » » » opj_event_msg(p_manager, EVT_WARNING, "Bad COLR
header box (CIELab, bad size: %d)\n", p_colr_header_size); |
| 1432 » » » } |
| 1433 » » » cielab[2] = rl; cielab[4] = ra; cielab[6] = rb; |
| 1434 » » » cielab[3] = ol; cielab[5] = oa; cielab[7] = ob; |
| 1435 » » » cielab[8] = il; |
| 1436 |
| 1437 » » » jp2->color.icc_profile_buf = (OPJ_BYTE*)cielab; |
| 1438 » » » jp2->color.icc_profile_len = 0; |
| 1439 » » } |
| 1440 » » jp2->color.jp2_has_colr = 1; |
1364 } | 1441 } |
1365 else if (jp2->meth == 2) { | 1442 else if (jp2->meth == 2) { |
1366 /* ICC profile */ | 1443 /* ICC profile */ |
1367 OPJ_INT32 it_icc_value = 0; | 1444 OPJ_INT32 it_icc_value = 0; |
1368 OPJ_INT32 icc_len = (OPJ_INT32)p_colr_header_size - 3; | 1445 OPJ_INT32 icc_len = (OPJ_INT32)p_colr_header_size - 3; |
1369 | 1446 |
1370 jp2->color.icc_profile_len = (OPJ_UINT32)icc_len; | 1447 jp2->color.icc_profile_len = (OPJ_UINT32)icc_len; |
1371 jp2->color.icc_profile_buf = (OPJ_BYTE*) opj_calloc(1,(size_t)ic
c_len); | 1448 jp2->color.icc_profile_buf = (OPJ_BYTE*) opj_calloc(1,(size_t)ic
c_len); |
1372 if (!jp2->color.icc_profile_buf) | 1449 » » if (!jp2->color.icc_profile_buf) |
1373 { | 1450 » » { |
1374 jp2->color.icc_profile_len = 0; | 1451 » » » jp2->color.icc_profile_len = 0; |
1375 return OPJ_FALSE; | 1452 » » » return OPJ_FALSE; |
1376 } | 1453 » » } |
1377 | 1454 |
1378 for (it_icc_value = 0; it_icc_value < icc_len; ++it_icc_value) | 1455 for (it_icc_value = 0; it_icc_value < icc_len; ++it_icc_value) |
1379 { | 1456 { |
1380 opj_read_bytes(p_colr_header_data,&l_value,1);
/* icc values */ | 1457 opj_read_bytes(p_colr_header_data,&l_value,1);
/* icc values */ |
1381 ++p_colr_header_data; | 1458 ++p_colr_header_data; |
1382 jp2->color.icc_profile_buf[it_icc_value] = (OPJ_BYTE) l_
value; | 1459 jp2->color.icc_profile_buf[it_icc_value] = (OPJ_BYTE) l_
value; |
1383 } | 1460 } |
1384 | 1461 |
1385 jp2->color.jp2_has_colr = 1; | 1462 » » jp2->color.jp2_has_colr = 1; |
1386 } | 1463 } |
1387 else if (jp2->meth > 2) | 1464 else if (jp2->meth > 2) |
1388 { | 1465 » { |
1389 /*» ISO/IEC 15444-1:2004 (E), Table I.9 Legal METH values: | 1466 » » /*» ISO/IEC 15444-1:2004 (E), Table I.9 Legal METH values: |
1390 conforming JP2 reader shall ignore the entire Colour Specification box.*
/ | 1467 » » conforming JP2 reader shall ignore the entire Colour Specificati
on box.*/ |
1391 opj_event_msg(p_manager, EVT_INFO, "COLR BOX meth value is not a regular
value (%d), " | 1468 » » opj_event_msg(p_manager, EVT_INFO, "COLR BOX meth value is not a
regular value (%d), " |
1392 "so we will ignore the entire Colour Specification box. \n", jp2->me
th); | 1469 » » » "so we will ignore the entire Colour Specification box.
\n", jp2->meth); |
1393 } | 1470 » } |
1394 return OPJ_TRUE; | 1471 » return OPJ_TRUE; |
1395 } | 1472 } |
1396 | 1473 |
1397 OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2, | 1474 OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2, |
1398 opj_stream_private_t *p_stream, | 1475 opj_stream_private_t *p_stream, |
1399 opj_image_t* p_image, | 1476 opj_image_t* p_image, |
1400 opj_event_mgr_t * p_manager) | 1477 opj_event_mgr_t * p_manager) |
1401 { | 1478 { |
1402 if (!p_image) | 1479 if (!p_image) |
1403 return OPJ_FALSE; | 1480 return OPJ_FALSE; |
1404 | 1481 |
1405 /* J2K decoding */ | 1482 /* J2K decoding */ |
1406 if( ! opj_j2k_decode(jp2->j2k, p_stream, p_image, p_manager) ) { | 1483 if( ! opj_j2k_decode(jp2->j2k, p_stream, p_image, p_manager) ) { |
1407 opj_event_msg(p_manager, EVT_ERROR, "Failed to decode the codest
ream in the JP2 file\n"); | 1484 opj_event_msg(p_manager, EVT_ERROR, "Failed to decode the codest
ream in the JP2 file\n"); |
1408 return OPJ_FALSE; | 1485 return OPJ_FALSE; |
1409 } | 1486 } |
1410 | 1487 |
1411 if (!jp2->ignore_pclr_cmap_cdef){ | 1488 » if (!jp2->ignore_pclr_cmap_cdef){ |
1412 » if (!opj_jp2_check_color(p_image, &(jp2->color), p_manager)) { | 1489 » » if (!opj_jp2_check_color(p_image, &(jp2->color), p_manager)) { |
1413 » » return OPJ_FALSE; | 1490 » » » return OPJ_FALSE; |
1414 » } | 1491 » » } |
1415 | 1492 |
1416 » /* Set Image Color Space */ | 1493 » » /* Set Image Color Space */ |
1417 » if (jp2->enumcs == 16) | 1494 » » if (jp2->enumcs == 16) |
1418 » » p_image->color_space = OPJ_CLRSPC_SRGB; | 1495 » » » p_image->color_space = OPJ_CLRSPC_SRGB; |
1419 » else if (jp2->enumcs == 17) | 1496 » » else if (jp2->enumcs == 17) |
1420 » » p_image->color_space = OPJ_CLRSPC_GRAY; | 1497 » » » p_image->color_space = OPJ_CLRSPC_GRAY; |
1421 » else if (jp2->enumcs == 18) | 1498 » » else if (jp2->enumcs == 18) |
1422 » » p_image->color_space = OPJ_CLRSPC_SYCC; | 1499 » » » p_image->color_space = OPJ_CLRSPC_SYCC; |
1423 else if (jp2->enumcs == 24) | 1500 » » else if (jp2->enumcs == 24) |
1424 p_image->color_space = OPJ_CLRSPC_EYCC; | 1501 » » » p_image->color_space = OPJ_CLRSPC_EYCC; |
1425 » else | 1502 » » else if (jp2->enumcs == 12) |
1426 » » p_image->color_space = OPJ_CLRSPC_UNKNOWN; | 1503 » » » p_image->color_space = OPJ_CLRSPC_CMYK; |
| 1504 » » else |
| 1505 » » » p_image->color_space = OPJ_CLRSPC_UNKNOWN; |
1427 | 1506 |
1428 » if(jp2->color.jp2_pclr) { | 1507 » » if(jp2->color.jp2_pclr) { |
1429 » » /* Part 1, I.5.3.4: Either both or none : */ | 1508 » » » /* Part 1, I.5.3.4: Either both or none : */ |
1430 » » if( !jp2->color.jp2_pclr->cmap) | 1509 » » » if( !jp2->color.jp2_pclr->cmap) |
1431 » » » opj_jp2_free_pclr(&(jp2->color)); | 1510 » » » » opj_jp2_free_pclr(&(jp2->color)); |
1432 » » else if (p_image->pdfium_use_colorspace) | 1511 » » » else if (p_image->pdfium_use_colorspace) |
1433 » » » opj_jp2_apply_pclr(p_image, &(jp2->color)); | 1512 » » » » opj_jp2_apply_pclr(p_image, &(jp2->color)); |
1434 » } | 1513 » » } |
1435 | 1514 |
1436 » /* Apply the color space if needed */ | 1515 » » /* Apply the color space if needed */ |
1437 » if(jp2->color.jp2_cdef) { | 1516 » » if(jp2->color.jp2_cdef) { |
1438 » » opj_jp2_apply_cdef(p_image, &(jp2->color)); | 1517 » » » opj_jp2_apply_cdef(p_image, &(jp2->color), p_manager); |
1439 » } | 1518 » » } |
1440 | 1519 |
1441 » if(jp2->color.icc_profile_buf) { | 1520 » » if(jp2->color.icc_profile_buf) { |
1442 » » p_image->icc_profile_buf = jp2->color.icc_profile_buf; | 1521 » » » p_image->icc_profile_buf = jp2->color.icc_profile_buf; |
1443 » » p_image->icc_profile_len = jp2->color.icc_profile_len; | 1522 » » » p_image->icc_profile_len = jp2->color.icc_profile_len; |
1444 » » jp2->color.icc_profile_buf = NULL; | 1523 » » » jp2->color.icc_profile_buf = NULL; |
1445 » } | 1524 » » } |
1446 } | 1525 » } |
1447 | 1526 |
1448 return OPJ_TRUE; | 1527 return OPJ_TRUE; |
1449 } | 1528 } |
1450 | 1529 |
1451 OPJ_BOOL opj_jp2_write_jp2h(opj_jp2_t *jp2, | 1530 static OPJ_BOOL opj_jp2_write_jp2h(opj_jp2_t *jp2, |
1452 opj_stream_private_t *stream, | 1531 opj_stream_private_t *stream, |
1453 opj_event_mgr_t * p_manager | 1532 opj_event_mgr_t * p_manager |
1454 ) | 1533 ) |
1455 { | 1534 { |
1456 opj_jp2_img_header_writer_handler_t l_writers [4]; | 1535 opj_jp2_img_header_writer_handler_t l_writers [4]; |
1457 opj_jp2_img_header_writer_handler_t * l_current_writer; | 1536 opj_jp2_img_header_writer_handler_t * l_current_writer; |
1458 | 1537 |
1459 OPJ_INT32 i, l_nb_pass; | 1538 OPJ_INT32 i, l_nb_pass; |
1460 /* size of data for super box*/ | 1539 /* size of data for super box*/ |
1461 OPJ_UINT32 l_jp2h_size = 8; | 1540 OPJ_UINT32 l_jp2h_size = 8; |
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1544 for (i=0;i<l_nb_pass;++i) { | 1623 for (i=0;i<l_nb_pass;++i) { |
1545 if (l_current_writer->m_data != 00) { | 1624 if (l_current_writer->m_data != 00) { |
1546 opj_free(l_current_writer->m_data ); | 1625 opj_free(l_current_writer->m_data ); |
1547 } | 1626 } |
1548 ++l_current_writer; | 1627 ++l_current_writer; |
1549 } | 1628 } |
1550 | 1629 |
1551 return l_result; | 1630 return l_result; |
1552 } | 1631 } |
1553 | 1632 |
1554 OPJ_BOOL opj_jp2_write_ftyp(opj_jp2_t *jp2, | 1633 static OPJ_BOOL opj_jp2_write_ftyp(opj_jp2_t *jp2, |
1555 opj_stream_private_t *ci
o, | 1634 opj_stream_private_t *ci
o, |
1556 opj_event_mgr_t * p_mana
ger ) | 1635 opj_event_mgr_t * p_mana
ger ) |
1557 { | 1636 { |
1558 OPJ_UINT32 i; | 1637 OPJ_UINT32 i; |
1559 OPJ_UINT32 l_ftyp_size = 16 + 4 * jp2->numcl; | 1638 OPJ_UINT32 l_ftyp_size = 16 + 4 * jp2->numcl; |
1560 OPJ_BYTE * l_ftyp_data, * l_current_data_ptr; | 1639 OPJ_BYTE * l_ftyp_data, * l_current_data_ptr; |
1561 OPJ_BOOL l_result; | 1640 OPJ_BOOL l_result; |
1562 | 1641 |
1563 /* preconditions */ | 1642 /* preconditions */ |
1564 assert(cio != 00); | 1643 assert(cio != 00); |
(...skipping 29 matching lines...) Expand all Loading... |
1594 if (! l_result) | 1673 if (! l_result) |
1595 { | 1674 { |
1596 opj_event_msg(p_manager, EVT_ERROR, "Error while writing ftyp da
ta to stream\n"); | 1675 opj_event_msg(p_manager, EVT_ERROR, "Error while writing ftyp da
ta to stream\n"); |
1597 } | 1676 } |
1598 | 1677 |
1599 opj_free(l_ftyp_data); | 1678 opj_free(l_ftyp_data); |
1600 | 1679 |
1601 return l_result; | 1680 return l_result; |
1602 } | 1681 } |
1603 | 1682 |
1604 OPJ_BOOL opj_jp2_write_jp2c(opj_jp2_t *jp2, | 1683 static OPJ_BOOL opj_jp2_write_jp2c(opj_jp2_t *jp2, |
1605 opj_stream_private_t *ci
o, | 1684 opj_stream_private_t *ci
o, |
1606 opj_event_mgr_t * p_mana
ger ) | 1685 opj_event_mgr_t * p_mana
ger ) |
1607 { | 1686 { |
1608 OPJ_OFF_T j2k_codestream_exit; | 1687 OPJ_OFF_T j2k_codestream_exit; |
1609 OPJ_BYTE l_data_header [8]; | 1688 OPJ_BYTE l_data_header [8]; |
1610 | 1689 |
1611 /* preconditions */ | 1690 /* preconditions */ |
1612 assert(jp2 != 00); | 1691 assert(jp2 != 00); |
1613 assert(cio != 00); | 1692 assert(cio != 00); |
1614 assert(p_manager != 00); | 1693 assert(p_manager != 00); |
(...skipping 16 matching lines...) Expand all Loading... |
1631 } | 1710 } |
1632 | 1711 |
1633 if (! opj_stream_seek(cio,j2k_codestream_exit,p_manager)) { | 1712 if (! opj_stream_seek(cio,j2k_codestream_exit,p_manager)) { |
1634 opj_event_msg(p_manager, EVT_ERROR, "Failed to seek in the strea
m.\n"); | 1713 opj_event_msg(p_manager, EVT_ERROR, "Failed to seek in the strea
m.\n"); |
1635 return OPJ_FALSE; | 1714 return OPJ_FALSE; |
1636 } | 1715 } |
1637 | 1716 |
1638 return OPJ_TRUE; | 1717 return OPJ_TRUE; |
1639 } | 1718 } |
1640 | 1719 |
1641 OPJ_BOOL opj_jp2_write_jp(» opj_jp2_t *jp2, | 1720 static OPJ_BOOL opj_jp2_write_jp(» opj_jp2_t *jp2, |
1642 opj_stream_private_t *cio, | 1721 opj_stream_private_t *cio, |
1643 opj_event_mgr_t * p_manager ) | 1722 opj_event_mgr_t * p_manager ) |
1644 { | 1723 { |
1645 /* 12 bytes will be read */ | 1724 /* 12 bytes will be read */ |
1646 OPJ_BYTE l_signature_data [12]; | 1725 OPJ_BYTE l_signature_data [12]; |
1647 | 1726 |
1648 /* preconditions */ | 1727 /* preconditions */ |
1649 assert(cio != 00); | 1728 assert(cio != 00); |
1650 assert(jp2 != 00); | 1729 assert(jp2 != 00); |
1651 assert(p_manager != 00); | 1730 assert(p_manager != 00); |
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1862 opj_stream_private_t *cio, | 1941 opj_stream_private_t *cio, |
1863 opj_event_mgr_t * p_manager | 1942 opj_event_mgr_t * p_manager |
1864 ) | 1943 ) |
1865 { | 1944 { |
1866 /* preconditions */ | 1945 /* preconditions */ |
1867 assert(jp2 != 00); | 1946 assert(jp2 != 00); |
1868 assert(cio != 00); | 1947 assert(cio != 00); |
1869 assert(p_manager != 00); | 1948 assert(p_manager != 00); |
1870 | 1949 |
1871 /* customization of the end encoding */ | 1950 /* customization of the end encoding */ |
1872 » opj_jp2_setup_end_header_reading(jp2); | 1951 » if (! opj_jp2_setup_end_header_reading(jp2, p_manager)) { |
| 1952 » » return OPJ_FALSE; |
| 1953 » } |
1873 | 1954 |
1874 /* write header */ | 1955 /* write header */ |
1875 if (! opj_jp2_exec (jp2,jp2->m_procedure_list,cio,p_manager)) { | 1956 if (! opj_jp2_exec (jp2,jp2->m_procedure_list,cio,p_manager)) { |
1876 return OPJ_FALSE; | 1957 return OPJ_FALSE; |
1877 } | 1958 } |
1878 | 1959 |
1879 return opj_j2k_end_decompress(jp2->j2k, cio, p_manager); | 1960 return opj_j2k_end_decompress(jp2->j2k, cio, p_manager); |
1880 } | 1961 } |
1881 | 1962 |
1882 OPJ_BOOL opj_jp2_end_compress( opj_jp2_t *jp2, | 1963 OPJ_BOOL opj_jp2_end_compress( opj_jp2_t *jp2, |
1883 opj_stream_private_t
*cio, | 1964 opj_stream_private_t
*cio, |
1884 opj_event_mgr_t * p_
manager | 1965 opj_event_mgr_t * p_
manager |
1885 ) | 1966 ) |
1886 { | 1967 { |
1887 /* preconditions */ | 1968 /* preconditions */ |
1888 assert(jp2 != 00); | 1969 assert(jp2 != 00); |
1889 assert(cio != 00); | 1970 assert(cio != 00); |
1890 assert(p_manager != 00); | 1971 assert(p_manager != 00); |
1891 | 1972 |
1892 /* customization of the end encoding */ | 1973 /* customization of the end encoding */ |
1893 » opj_jp2_setup_end_header_writing(jp2); | 1974 » if (! opj_jp2_setup_end_header_writing(jp2, p_manager)) { |
| 1975 » » return OPJ_FALSE; |
| 1976 » } |
1894 | 1977 |
1895 if (! opj_j2k_end_compress(jp2->j2k,cio,p_manager)) { | 1978 if (! opj_j2k_end_compress(jp2->j2k,cio,p_manager)) { |
1896 return OPJ_FALSE; | 1979 return OPJ_FALSE; |
1897 } | 1980 } |
1898 | 1981 |
1899 /* write header */ | 1982 /* write header */ |
1900 return opj_jp2_exec(jp2,jp2->m_procedure_list,cio,p_manager); | 1983 return opj_jp2_exec(jp2,jp2->m_procedure_list,cio,p_manager); |
1901 } | 1984 } |
1902 | 1985 |
1903 void opj_jp2_setup_end_header_writing (opj_jp2_t *jp2) | 1986 static OPJ_BOOL opj_jp2_setup_end_header_writing (opj_jp2_t *jp2, opj_event_mgr_
t * p_manager) |
1904 { | 1987 { |
1905 /* preconditions */ | 1988 /* preconditions */ |
1906 assert(jp2 != 00); | 1989 assert(jp2 != 00); |
| 1990 assert(p_manager != 00); |
1907 | 1991 |
1908 #ifdef USE_JPIP | 1992 #ifdef USE_JPIP |
1909 if( jp2->jpip_on ) | 1993 » if( jp2->jpip_on ) { |
1910 opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jp
ip_write_iptr ); | 1994 » » if (! opj_procedure_list_add_procedure(jp2->m_procedure_list,(op
j_procedure)opj_jpip_write_iptr, p_manager)) { |
| 1995 » » » return OPJ_FALSE; |
| 1996 » » } |
| 1997 » } |
1911 #endif | 1998 #endif |
1912 » opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)op
j_jp2_write_jp2c ); | 1999 » if (! opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_proced
ure)opj_jp2_write_jp2c, p_manager)) { |
| 2000 » » return OPJ_FALSE; |
| 2001 » } |
1913 /* DEVELOPER CORNER, add your custom procedures */ | 2002 /* DEVELOPER CORNER, add your custom procedures */ |
1914 #ifdef USE_JPIP | 2003 #ifdef USE_JPIP |
1915 if( jp2->jpip_on ) | 2004 if( jp2->jpip_on ) |
1916 { | 2005 » { |
1917 opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jp
ip_write_cidx ); | 2006 » » if (! opj_procedure_list_add_procedure(jp2->m_procedure_list,(op
j_procedure)opj_jpip_write_cidx, p_manager)) { |
1918 opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jp
ip_write_fidx ); | 2007 » » » return OPJ_FALSE; |
1919 } | 2008 » » } |
| 2009 » » if (! opj_procedure_list_add_procedure(jp2->m_procedure_list,(op
j_procedure)opj_jpip_write_fidx, p_manager)) { |
| 2010 » » » return OPJ_FALSE; |
| 2011 » » } |
| 2012 » } |
1920 #endif | 2013 #endif |
| 2014 return OPJ_TRUE; |
1921 } | 2015 } |
1922 | 2016 |
1923 void opj_jp2_setup_end_header_reading (opj_jp2_t *jp2) | 2017 static OPJ_BOOL opj_jp2_setup_end_header_reading (opj_jp2_t *jp2, opj_event_mgr_
t * p_manager) |
1924 { | 2018 { |
1925 /* preconditions */ | 2019 /* preconditions */ |
1926 assert(jp2 != 00); | 2020 assert(jp2 != 00); |
1927 » opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)op
j_jp2_read_header_procedure ); | 2021 » assert(p_manager != 00); |
| 2022 » |
| 2023 » if (! opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_proced
ure)opj_jp2_read_header_procedure, p_manager)) { |
| 2024 » » return OPJ_FALSE; |
| 2025 » } |
1928 /* DEVELOPER CORNER, add your custom procedures */ | 2026 /* DEVELOPER CORNER, add your custom procedures */ |
| 2027 |
| 2028 return OPJ_TRUE; |
1929 } | 2029 } |
1930 | 2030 |
1931 OPJ_BOOL opj_jp2_default_validation (» opj_jp2_t * jp2, | 2031 static OPJ_BOOL opj_jp2_default_validation (» opj_jp2_t * jp2, |
1932 opj_stream_private_t *cio, | 2032 opj_stream_private_t *cio, |
1933 opj_event_mgr_t * p_manager | 2033 opj_event_mgr_t * p_manager |
1934 ) | 2034 ) |
1935 { | 2035 { |
1936 OPJ_BOOL l_is_valid = OPJ_TRUE; | 2036 OPJ_BOOL l_is_valid = OPJ_TRUE; |
1937 OPJ_UINT32 i; | 2037 OPJ_UINT32 i; |
1938 | 2038 |
1939 /* preconditions */ | 2039 /* preconditions */ |
1940 assert(jp2 != 00); | 2040 assert(jp2 != 00); |
1941 assert(cio != 00); | 2041 assert(cio != 00); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1975 /* METH */ | 2075 /* METH */ |
1976 l_is_valid &= ((jp2->meth > 0) && (jp2->meth < 3)); | 2076 l_is_valid &= ((jp2->meth > 0) && (jp2->meth < 3)); |
1977 | 2077 |
1978 /* stream validation */ | 2078 /* stream validation */ |
1979 /* back and forth is needed */ | 2079 /* back and forth is needed */ |
1980 l_is_valid &= opj_stream_has_seek(cio); | 2080 l_is_valid &= opj_stream_has_seek(cio); |
1981 | 2081 |
1982 return l_is_valid; | 2082 return l_is_valid; |
1983 } | 2083 } |
1984 | 2084 |
1985 OPJ_BOOL opj_jp2_read_header_procedure( opj_jp2_t *jp2, | 2085 static OPJ_BOOL opj_jp2_read_header_procedure( opj_jp2_t *jp2, |
1986 opj_stream_private_t *stream, | 2086 opj_stream_private_t *stream, |
1987 opj_event_mgr_t * p_manager | 2087 opj_event_mgr_t * p_manager |
1988 ) | 2088 ) |
1989 { | 2089 { |
1990 opj_jp2_box_t box; | 2090 opj_jp2_box_t box; |
1991 OPJ_UINT32 l_nb_bytes_read; | 2091 OPJ_UINT32 l_nb_bytes_read; |
1992 const opj_jp2_header_handler_t * l_current_handler; | 2092 const opj_jp2_header_handler_t * l_current_handler; |
| 2093 const opj_jp2_header_handler_t * l_current_handler_misplaced; |
1993 OPJ_UINT32 l_last_data_size = OPJ_BOX_SIZE; | 2094 OPJ_UINT32 l_last_data_size = OPJ_BOX_SIZE; |
1994 OPJ_UINT32 l_current_data_size; | 2095 OPJ_UINT32 l_current_data_size; |
1995 OPJ_BYTE * l_current_data = 00; | 2096 OPJ_BYTE * l_current_data = 00; |
1996 | 2097 |
1997 /* preconditions */ | 2098 /* preconditions */ |
1998 assert(stream != 00); | 2099 assert(stream != 00); |
1999 assert(jp2 != 00); | 2100 assert(jp2 != 00); |
2000 assert(p_manager != 00); | 2101 assert(p_manager != 00); |
2001 | 2102 |
2002 l_current_data = (OPJ_BYTE*)opj_calloc(1,l_last_data_size); | 2103 l_current_data = (OPJ_BYTE*)opj_calloc(1,l_last_data_size); |
(...skipping 23 matching lines...) Expand all Loading... |
2026 return OPJ_FALSE; | 2127 return OPJ_FALSE; |
2027 } | 2128 } |
2028 /* testcase 1851.pdf.SIGSEGV.ce9.948 */ | 2129 /* testcase 1851.pdf.SIGSEGV.ce9.948 */ |
2029 else if (box.length < l_nb_bytes_read) { | 2130 else if (box.length < l_nb_bytes_read) { |
2030 opj_event_msg(p_manager, EVT_ERROR, "invalid box size %d
(%x)\n", box.length, box.type); | 2131 opj_event_msg(p_manager, EVT_ERROR, "invalid box size %d
(%x)\n", box.length, box.type); |
2031 opj_free(l_current_data); | 2132 opj_free(l_current_data); |
2032 return OPJ_FALSE; | 2133 return OPJ_FALSE; |
2033 } | 2134 } |
2034 | 2135 |
2035 l_current_handler = opj_jp2_find_handler(box.type); | 2136 l_current_handler = opj_jp2_find_handler(box.type); |
| 2137 l_current_handler_misplaced = opj_jp2_img_find_handler(box.type)
; |
2036 l_current_data_size = box.length - l_nb_bytes_read; | 2138 l_current_data_size = box.length - l_nb_bytes_read; |
2037 | 2139 |
2038 » » if (l_current_handler != 00) { | 2140 » » if ((l_current_handler != 00) || (l_current_handler_misplaced !=
00)) { |
| 2141 » » » if (l_current_handler == 00) { |
| 2142 » » » » opj_event_msg(p_manager, EVT_WARNING, "Found a m
isplaced '%c%c%c%c' box outside jp2h box\n", (OPJ_BYTE)(box.type>>24), (OPJ_BYTE
)(box.type>>16), (OPJ_BYTE)(box.type>>8), (OPJ_BYTE)(box.type>>0)); |
| 2143 » » » » if (jp2->jp2_state & JP2_STATE_HEADER) { |
| 2144 » » » » » /* read anyway, we already have jp2h */ |
| 2145 » » » » » l_current_handler = l_current_handler_mi
splaced; |
| 2146 » » » » } else { |
| 2147 » » » » » opj_event_msg(p_manager, EVT_WARNING, "J
PEG2000 Header box not read yet, '%c%c%c%c' box will be ignored\n", (OPJ_BYTE)(b
ox.type>>24), (OPJ_BYTE)(box.type>>16), (OPJ_BYTE)(box.type>>8), (OPJ_BYTE)(box.
type>>0)); |
| 2148 » » » » » jp2->jp2_state |= JP2_STATE_UNKNOWN; |
| 2149 » » » » » if (opj_stream_skip(stream,l_current_dat
a_size,p_manager) != l_current_data_size) { |
| 2150 » » » » » » » opj_event_msg(p_manager,
EVT_ERROR, "Problem with skipping JPEG2000 box, stream error\n"); |
| 2151 » » » » » » » opj_free(l_current_data)
; |
| 2152 » » » » » » » return OPJ_FALSE; |
| 2153 » » » » » } |
| 2154 » » » » » continue; |
| 2155 » » » » } |
| 2156 » » » } |
2039 if ((OPJ_OFF_T)l_current_data_size > opj_stream_get_numb
er_byte_left(stream)) { | 2157 if ((OPJ_OFF_T)l_current_data_size > opj_stream_get_numb
er_byte_left(stream)) { |
2040 /* do not even try to malloc if we can't read */ | 2158 /* do not even try to malloc if we can't read */ |
2041 opj_event_msg(p_manager, EVT_ERROR, "Invalid box
size %d for box '%c%c%c%c'. Need %d bytes, %d bytes remaining \n", box.length,
(OPJ_BYTE)(box.type>>24), (OPJ_BYTE)(box.type>>16), (OPJ_BYTE)(box.type>>8), (OP
J_BYTE)(box.type>>0), l_current_data_size, (OPJ_UINT32)opj_stream_get_number_byt
e_left(stream)); | 2159 opj_event_msg(p_manager, EVT_ERROR, "Invalid box
size %d for box '%c%c%c%c'. Need %d bytes, %d bytes remaining \n", box.length,
(OPJ_BYTE)(box.type>>24), (OPJ_BYTE)(box.type>>16), (OPJ_BYTE)(box.type>>8), (OP
J_BYTE)(box.type>>0), l_current_data_size, (OPJ_UINT32)opj_stream_get_number_byt
e_left(stream)); |
2042 opj_free(l_current_data); | 2160 opj_free(l_current_data); |
2043 return OPJ_FALSE; | 2161 return OPJ_FALSE; |
2044 } | 2162 } |
2045 if (l_current_data_size > l_last_data_size) { | 2163 if (l_current_data_size > l_last_data_size) { |
2046 OPJ_BYTE* new_current_data = (OPJ_BYTE*)opj_real
loc(l_current_data,l_current_data_size); | 2164 OPJ_BYTE* new_current_data = (OPJ_BYTE*)opj_real
loc(l_current_data,l_current_data_size); |
2047 if (!new_current_data) { | 2165 if (!new_current_data) { |
2048 opj_free(l_current_data); | 2166 opj_free(l_current_data); |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2135 opj_image_t * p_image, | 2253 opj_image_t * p_image, |
2136 opj_event_mgr_t * p_manager | 2254 opj_event_mgr_t * p_manager |
2137 ) | 2255 ) |
2138 { | 2256 { |
2139 /* preconditions */ | 2257 /* preconditions */ |
2140 assert(jp2 != 00); | 2258 assert(jp2 != 00); |
2141 assert(stream != 00); | 2259 assert(stream != 00); |
2142 assert(p_manager != 00); | 2260 assert(p_manager != 00); |
2143 | 2261 |
2144 /* customization of the validation */ | 2262 /* customization of the validation */ |
2145 » opj_jp2_setup_encoding_validation (jp2); | 2263 » if (! opj_jp2_setup_encoding_validation (jp2, p_manager)) { |
| 2264 » » return OPJ_FALSE; |
| 2265 » } |
2146 | 2266 |
2147 /* validation of the parameters codec */ | 2267 /* validation of the parameters codec */ |
2148 if (! opj_jp2_exec(jp2,jp2->m_validation_list,stream,p_manager)) { | 2268 if (! opj_jp2_exec(jp2,jp2->m_validation_list,stream,p_manager)) { |
2149 return OPJ_FALSE; | 2269 return OPJ_FALSE; |
2150 } | 2270 } |
2151 | 2271 |
2152 /* customization of the encoding */ | 2272 /* customization of the encoding */ |
2153 » opj_jp2_setup_header_writing(jp2); | 2273 » if (! opj_jp2_setup_header_writing(jp2, p_manager)) { |
| 2274 » » return OPJ_FALSE; |
| 2275 » } |
2154 | 2276 |
2155 /* write header */ | 2277 /* write header */ |
2156 if (! opj_jp2_exec (jp2,jp2->m_procedure_list,stream,p_manager)) { | 2278 if (! opj_jp2_exec (jp2,jp2->m_procedure_list,stream,p_manager)) { |
2157 return OPJ_FALSE; | 2279 return OPJ_FALSE; |
2158 } | 2280 } |
2159 | 2281 |
2160 return opj_j2k_start_compress(jp2->j2k,stream,p_image,p_manager); | 2282 return opj_j2k_start_compress(jp2->j2k,stream,p_image,p_manager); |
2161 } | 2283 } |
2162 | 2284 |
2163 const opj_jp2_header_handler_t * opj_jp2_find_handler (OPJ_UINT32 p_id) | 2285 static const opj_jp2_header_handler_t * opj_jp2_find_handler (OPJ_UINT32 p_id) |
2164 { | 2286 { |
2165 OPJ_UINT32 i, l_handler_size = sizeof(jp2_header) / sizeof(opj_jp2_heade
r_handler_t); | 2287 OPJ_UINT32 i, l_handler_size = sizeof(jp2_header) / sizeof(opj_jp2_heade
r_handler_t); |
2166 | 2288 |
2167 for (i=0;i<l_handler_size;++i) { | 2289 for (i=0;i<l_handler_size;++i) { |
2168 if (jp2_header[i].id == p_id) { | 2290 if (jp2_header[i].id == p_id) { |
2169 return &jp2_header[i]; | 2291 return &jp2_header[i]; |
2170 } | 2292 } |
2171 } | 2293 } |
2172 return NULL; | 2294 return NULL; |
2173 } | 2295 } |
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2301 { | 2423 { |
2302 opj_read_bytes(p_header_data,&jp2->cl[i],4); /* CLi *
/ | 2424 opj_read_bytes(p_header_data,&jp2->cl[i],4); /* CLi *
/ |
2303 p_header_data += 4; | 2425 p_header_data += 4; |
2304 } | 2426 } |
2305 | 2427 |
2306 jp2->jp2_state |= JP2_STATE_FILE_TYPE; | 2428 jp2->jp2_state |= JP2_STATE_FILE_TYPE; |
2307 | 2429 |
2308 return OPJ_TRUE; | 2430 return OPJ_TRUE; |
2309 } | 2431 } |
2310 | 2432 |
2311 OPJ_BOOL opj_jp2_skip_jp2c(» opj_jp2_t *jp2, | 2433 static OPJ_BOOL opj_jp2_skip_jp2c(» opj_jp2_t *jp2, |
2312 opj_stream_private_t *stream, | 2434 opj_stream_private_t *stream, |
2313 opj_event_mgr_t * p_manager ) | 2435 opj_event_mgr_t * p_manager ) |
2314 { | 2436 { |
2315 /* preconditions */ | 2437 /* preconditions */ |
2316 assert(jp2 != 00); | 2438 assert(jp2 != 00); |
2317 assert(stream != 00); | 2439 assert(stream != 00); |
2318 assert(p_manager != 00); | 2440 assert(p_manager != 00); |
2319 | 2441 |
2320 jp2->j2k_codestream_offset = opj_stream_tell(stream); | 2442 jp2->j2k_codestream_offset = opj_stream_tell(stream); |
2321 | 2443 |
(...skipping 23 matching lines...) Expand all Loading... |
2345 } | 2467 } |
2346 | 2468 |
2347 /** | 2469 /** |
2348 * Reads the Jpeg2000 file Header box - JP2 Header box (warning, this is a super
box). | 2470 * Reads the Jpeg2000 file Header box - JP2 Header box (warning, this is a super
box). |
2349 * | 2471 * |
2350 * @param p_header_data the data contained in the file header box. | 2472 * @param p_header_data the data contained in the file header box. |
2351 * @param jp2 the jpeg2000 file codec. | 2473 * @param jp2 the jpeg2000 file codec. |
2352 * @param p_header_size the size of the data contained in the file heade
r box. | 2474 * @param p_header_size the size of the data contained in the file heade
r box. |
2353 * @param p_manager the user event manager. | 2475 * @param p_manager the user event manager. |
2354 * | 2476 * |
2355 * @return true if the JP2 Header box was successfully reconized. | 2477 * @return true if the JP2 Header box was successfully recognized. |
2356 */ | 2478 */ |
2357 static OPJ_BOOL opj_jp2_read_jp2h( opj_jp2_t *jp2, | 2479 static OPJ_BOOL opj_jp2_read_jp2h( opj_jp2_t *jp2, |
2358 OPJ_BYTE *p_header_data, | 2480 OPJ_BYTE *p_header_data, |
2359 OPJ_UINT32 p_header_size, | 2481 OPJ_UINT32 p_header_size, |
2360 opj_event_mgr_t * p_manager | 2482 opj_event_mgr_t * p_manager |
2361 ) | 2483 ) |
2362 { | 2484 { |
2363 OPJ_UINT32 l_box_size=0, l_current_data_size = 0; | 2485 OPJ_UINT32 l_box_size=0, l_current_data_size = 0; |
2364 opj_jp2_box_t box; | 2486 opj_jp2_box_t box; |
2365 const opj_jp2_header_handler_t * l_current_handler; | 2487 const opj_jp2_header_handler_t * l_current_handler; |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2415 if (l_has_ihdr == 0) { | 2537 if (l_has_ihdr == 0) { |
2416 opj_event_msg(p_manager, EVT_ERROR, "Stream error while reading
JP2 Header box: no 'ihdr' box.\n"); | 2538 opj_event_msg(p_manager, EVT_ERROR, "Stream error while reading
JP2 Header box: no 'ihdr' box.\n"); |
2417 return OPJ_FALSE; | 2539 return OPJ_FALSE; |
2418 } | 2540 } |
2419 | 2541 |
2420 jp2->jp2_state |= JP2_STATE_HEADER; | 2542 jp2->jp2_state |= JP2_STATE_HEADER; |
2421 | 2543 |
2422 return OPJ_TRUE; | 2544 return OPJ_TRUE; |
2423 } | 2545 } |
2424 | 2546 |
2425 OPJ_BOOL opj_jp2_read_boxhdr_char( opj_jp2_box_t *box, | 2547 static OPJ_BOOL opj_jp2_read_boxhdr_char( opj_jp2_box_t *box, |
2426 OPJ_BYTE * p_data, | 2548 OPJ_BYTE * p_data, |
2427 OPJ_UINT32 * p_number_bytes_read, | 2549 OPJ_UINT32 * p_number_bytes_read, |
2428 OPJ_UINT32 p_box_max_size, | 2550 OPJ_UINT32 p_box_max_size, |
2429 opj_event_mgr_t * p_manager | 2551 opj_event_mgr_t * p_manager |
2430 ) | 2552 ) |
2431 { | 2553 { |
2432 OPJ_UINT32 l_value; | 2554 OPJ_UINT32 l_value; |
2433 | 2555 |
2434 /* preconditions */ | 2556 /* preconditions */ |
2435 assert(p_data != 00); | 2557 assert(p_data != 00); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2497 opj_image_t ** p_image, | 2619 opj_image_t ** p_image, |
2498 opj_event_mgr_t * p_manager | 2620 opj_event_mgr_t * p_manager |
2499 ) | 2621 ) |
2500 { | 2622 { |
2501 /* preconditions */ | 2623 /* preconditions */ |
2502 assert(jp2 != 00); | 2624 assert(jp2 != 00); |
2503 assert(p_stream != 00); | 2625 assert(p_stream != 00); |
2504 assert(p_manager != 00); | 2626 assert(p_manager != 00); |
2505 | 2627 |
2506 /* customization of the validation */ | 2628 /* customization of the validation */ |
2507 » opj_jp2_setup_decoding_validation (jp2); | 2629 » if (! opj_jp2_setup_decoding_validation (jp2, p_manager)) { |
| 2630 » » return OPJ_FALSE; |
| 2631 » } |
2508 | 2632 |
2509 /* customization of the encoding */ | 2633 /* customization of the encoding */ |
2510 » opj_jp2_setup_header_reading(jp2); | 2634 » if (! opj_jp2_setup_header_reading(jp2, p_manager)) { |
| 2635 » » return OPJ_FALSE; |
| 2636 » } |
2511 | 2637 |
2512 /* validation of the parameters codec */ | 2638 /* validation of the parameters codec */ |
2513 if (! opj_jp2_exec(jp2,jp2->m_validation_list,p_stream,p_manager)) { | 2639 if (! opj_jp2_exec(jp2,jp2->m_validation_list,p_stream,p_manager)) { |
2514 return OPJ_FALSE; | 2640 return OPJ_FALSE; |
2515 } | 2641 } |
2516 | 2642 |
2517 /* read header */ | 2643 /* read header */ |
2518 if (! opj_jp2_exec (jp2,jp2->m_procedure_list,p_stream,p_manager)) { | 2644 if (! opj_jp2_exec (jp2,jp2->m_procedure_list,p_stream,p_manager)) { |
2519 return OPJ_FALSE; | 2645 return OPJ_FALSE; |
2520 } | 2646 } |
2521 | 2647 |
2522 return opj_j2k_read_header( p_stream, | 2648 return opj_j2k_read_header( p_stream, |
2523 jp2->j2k, | 2649 jp2->j2k, |
2524 p_image, | 2650 p_image, |
2525 p_manager); | 2651 p_manager); |
2526 } | 2652 } |
2527 | 2653 |
2528 void opj_jp2_setup_encoding_validation (opj_jp2_t *jp2) | 2654 static OPJ_BOOL opj_jp2_setup_encoding_validation (opj_jp2_t *jp2, opj_event_mgr
_t * p_manager) |
2529 { | 2655 { |
2530 /* preconditions */ | 2656 /* preconditions */ |
2531 assert(jp2 != 00); | 2657 assert(jp2 != 00); |
| 2658 assert(p_manager != 00); |
2532 | 2659 |
2533 » opj_procedure_list_add_procedure(jp2->m_validation_list, (opj_procedure)
opj_jp2_default_validation); | 2660 » if (! opj_procedure_list_add_procedure(jp2->m_validation_list, (opj_proc
edure)opj_jp2_default_validation, p_manager)) { |
| 2661 » » return OPJ_FALSE; |
| 2662 » } |
2534 /* DEVELOPER CORNER, add your custom validation procedure */ | 2663 /* DEVELOPER CORNER, add your custom validation procedure */ |
| 2664 |
| 2665 return OPJ_TRUE; |
2535 } | 2666 } |
2536 | 2667 |
2537 void opj_jp2_setup_decoding_validation (opj_jp2_t *jp2) | 2668 static OPJ_BOOL opj_jp2_setup_decoding_validation (opj_jp2_t *jp2, opj_event_mgr
_t * p_manager) |
2538 { | 2669 { |
2539 /* preconditions */ | 2670 /* preconditions */ |
2540 assert(jp2 != 00); | 2671 assert(jp2 != 00); |
| 2672 assert(p_manager != 00); |
| 2673 |
2541 /* DEVELOPER CORNER, add your custom validation procedure */ | 2674 /* DEVELOPER CORNER, add your custom validation procedure */ |
| 2675 |
| 2676 return OPJ_TRUE; |
2542 } | 2677 } |
2543 | 2678 |
2544 void opj_jp2_setup_header_writing (opj_jp2_t *jp2) | 2679 static OPJ_BOOL opj_jp2_setup_header_writing (opj_jp2_t *jp2, opj_event_mgr_t *
p_manager) |
2545 { | 2680 { |
2546 /* preconditions */ | 2681 /* preconditions */ |
2547 assert(jp2 != 00); | 2682 assert(jp2 != 00); |
| 2683 assert(p_manager != 00); |
2548 | 2684 |
2549 » opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)op
j_jp2_write_jp ); | 2685 » if (! opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_proced
ure)opj_jp2_write_jp, p_manager)) { |
2550 » opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)op
j_jp2_write_ftyp ); | 2686 » » return OPJ_FALSE; |
2551 » opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)op
j_jp2_write_jp2h ); | 2687 » } |
2552 if( jp2->jpip_on ) | 2688 » if (! opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_proced
ure)opj_jp2_write_ftyp, p_manager)) { |
2553 opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)opj_jp
ip_skip_iptr ); | 2689 » » return OPJ_FALSE; |
2554 » opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)op
j_jp2_skip_jp2c ); | 2690 » } |
| 2691 » if (! opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_proced
ure)opj_jp2_write_jp2h, p_manager)) { |
| 2692 » » return OPJ_FALSE; |
| 2693 » } |
| 2694 » if( jp2->jpip_on ) { |
| 2695 » » if (! opj_procedure_list_add_procedure(jp2->m_procedure_list,(op
j_procedure)opj_jpip_skip_iptr, p_manager)) { |
| 2696 » » » return OPJ_FALSE; |
| 2697 » » } |
| 2698 » } |
| 2699 » if (! opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_proced
ure)opj_jp2_skip_jp2c,p_manager)) { |
| 2700 » » return OPJ_FALSE; |
| 2701 » } |
2555 | 2702 |
2556 /* DEVELOPER CORNER, insert your custom procedures */ | 2703 /* DEVELOPER CORNER, insert your custom procedures */ |
2557 | 2704 |
| 2705 return OPJ_TRUE; |
2558 } | 2706 } |
2559 | 2707 |
2560 void opj_jp2_setup_header_reading (opj_jp2_t *jp2) | 2708 static OPJ_BOOL opj_jp2_setup_header_reading (opj_jp2_t *jp2, opj_event_mgr_t *
p_manager) |
2561 { | 2709 { |
2562 /* preconditions */ | 2710 /* preconditions */ |
2563 assert(jp2 != 00); | 2711 assert(jp2 != 00); |
| 2712 assert(p_manager != 00); |
2564 | 2713 |
2565 » opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_procedure)op
j_jp2_read_header_procedure ); | 2714 » if (! opj_procedure_list_add_procedure(jp2->m_procedure_list,(opj_proced
ure)opj_jp2_read_header_procedure, p_manager)) { |
| 2715 » » return OPJ_FALSE; |
| 2716 » } |
| 2717 » |
2566 /* DEVELOPER CORNER, add your custom procedures */ | 2718 /* DEVELOPER CORNER, add your custom procedures */ |
| 2719 |
| 2720 return OPJ_TRUE; |
2567 } | 2721 } |
2568 | 2722 |
2569 OPJ_BOOL opj_jp2_read_tile_header ( opj_jp2_t * p_jp2, | 2723 OPJ_BOOL opj_jp2_read_tile_header ( opj_jp2_t * p_jp2, |
2570 OPJ_UINT32 * p_tile_index, | 2724 OPJ_UINT32 * p_tile_index, |
2571 OPJ_UINT32 * p_data_size, | 2725 OPJ_UINT32 * p_data_size, |
2572 OPJ_INT32 * p_tile_x0, | 2726 OPJ_INT32 * p_tile_x0, |
2573 OPJ_INT32 * p_tile_y0, | 2727 OPJ_INT32 * p_tile_y0, |
2574 OPJ_INT32 * p_tile_x1, | 2728 OPJ_INT32 * p_tile_x1, |
2575 OPJ_INT32 * p_tile_y1, | 2729 OPJ_INT32 * p_tile_y1, |
2576 OPJ_UINT32 * p_nb_comps, | 2730 OPJ_UINT32 * p_nb_comps, |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2712 return OPJ_FALSE; | 2866 return OPJ_FALSE; |
2713 } | 2867 } |
2714 | 2868 |
2715 /* Set Image Color Space */ | 2869 /* Set Image Color Space */ |
2716 if (p_jp2->enumcs == 16) | 2870 if (p_jp2->enumcs == 16) |
2717 p_image->color_space = OPJ_CLRSPC_SRGB; | 2871 p_image->color_space = OPJ_CLRSPC_SRGB; |
2718 else if (p_jp2->enumcs == 17) | 2872 else if (p_jp2->enumcs == 17) |
2719 p_image->color_space = OPJ_CLRSPC_GRAY; | 2873 p_image->color_space = OPJ_CLRSPC_GRAY; |
2720 else if (p_jp2->enumcs == 18) | 2874 else if (p_jp2->enumcs == 18) |
2721 p_image->color_space = OPJ_CLRSPC_SYCC; | 2875 p_image->color_space = OPJ_CLRSPC_SYCC; |
| 2876 else if (p_jp2->enumcs == 24) |
| 2877 p_image->color_space = OPJ_CLRSPC_EYCC; |
| 2878 else if (p_jp2->enumcs == 12) |
| 2879 p_image->color_space = OPJ_CLRSPC_CMYK; |
2722 else | 2880 else |
2723 p_image->color_space = OPJ_CLRSPC_UNKNOWN; | 2881 p_image->color_space = OPJ_CLRSPC_UNKNOWN; |
2724 | 2882 |
2725 if(p_jp2->color.jp2_pclr) { | 2883 if(p_jp2->color.jp2_pclr) { |
2726 /* Part 1, I.5.3.4: Either both or none : */ | 2884 /* Part 1, I.5.3.4: Either both or none : */ |
2727 if( !p_jp2->color.jp2_pclr->cmap) | 2885 if( !p_jp2->color.jp2_pclr->cmap) |
2728 opj_jp2_free_pclr(&(p_jp2->color)); | 2886 opj_jp2_free_pclr(&(p_jp2->color)); |
2729 else | 2887 else |
2730 opj_jp2_apply_pclr(p_image, &(p_jp2->color)); | 2888 opj_jp2_apply_pclr(p_image, &(p_jp2->color)); |
2731 } | 2889 } |
2732 | 2890 |
2733 /* Apply the color space if needed */ | 2891 /* Apply the color space if needed */ |
2734 if(p_jp2->color.jp2_cdef) { | 2892 if(p_jp2->color.jp2_cdef) { |
2735 » » opj_jp2_apply_cdef(p_image, &(p_jp2->color)); | 2893 » » opj_jp2_apply_cdef(p_image, &(p_jp2->color), p_manager); |
2736 } | 2894 } |
2737 | 2895 |
2738 if(p_jp2->color.icc_profile_buf) { | 2896 if(p_jp2->color.icc_profile_buf) { |
2739 p_image->icc_profile_buf = p_jp2->color.icc_profile_buf; | 2897 p_image->icc_profile_buf = p_jp2->color.icc_profile_buf; |
2740 p_image->icc_profile_len = p_jp2->color.icc_profile_len; | 2898 p_image->icc_profile_len = p_jp2->color.icc_profile_len; |
2741 p_jp2->color.icc_profile_buf = NULL; | 2899 p_jp2->color.icc_profile_buf = NULL; |
2742 } | 2900 } |
2743 | 2901 |
2744 return OPJ_TRUE; | 2902 return OPJ_TRUE; |
2745 } | 2903 } |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2991 len = opj_stream_tell(cio)-lenp; | 3149 len = opj_stream_tell(cio)-lenp; |
2992 opj_stream_skip(cio, lenp, p_manager); | 3150 opj_stream_skip(cio, lenp, p_manager); |
2993 opj_write_bytes(l_data_header,len,4);/* L */ | 3151 opj_write_bytes(l_data_header,len,4);/* L */ |
2994 opj_stream_write_data(cio,l_data_header,4,p_manager); | 3152 opj_stream_write_data(cio,l_data_header,4,p_manager); |
2995 opj_stream_seek(cio, lenp+len,p_manager); | 3153 opj_stream_seek(cio, lenp+len,p_manager); |
2996 | 3154 |
2997 return len; | 3155 return len; |
2998 } | 3156 } |
2999 #endif | 3157 #endif |
3000 #endif /* USE_JPIP */ | 3158 #endif /* USE_JPIP */ |
OLD | NEW |