Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1164)

Side by Side Diff: third_party/libopenjpeg20/j2k.c

Issue 1338973005: upgrade openjpeg to commit# cf352af (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
44 44
45 /** @defgroup J2K J2K - JPEG-2000 codestream reader/writer */ 45 /** @defgroup J2K J2K - JPEG-2000 codestream reader/writer */
46 /*@{*/ 46 /*@{*/
47 47
48 /** @name Local static functions */ 48 /** @name Local static functions */
49 /*@{*/ 49 /*@{*/
50 50
51 /** 51 /**
52 * Sets up the procedures to do on reading header. Developpers wanting to extend the library can add their own reading procedures. 52 * Sets up the procedures to do on reading header. Developpers wanting to extend the library can add their own reading procedures.
53 */ 53 */
54 static void opj_j2k_setup_header_reading (opj_j2k_t *p_j2k); 54 static OPJ_BOOL opj_j2k_setup_header_reading (opj_j2k_t *p_j2k, opj_event_mgr_t * p_manager);
55 55
56 /** 56 /**
57 * The read header procedure. 57 * The read header procedure.
58 */ 58 */
59 static OPJ_BOOL opj_j2k_read_header_procedure( opj_j2k_t *p_j2k, 59 static OPJ_BOOL opj_j2k_read_header_procedure( opj_j2k_t *p_j2k,
60 opj_stream_private_t *p_stream, 60 opj_stream_private_t *p_stream,
61 opj_event_mgr_t * p_manager); 61 opj_event_mgr_t * p_manager);
62 62
63 /** 63 /**
64 * The default encoding validation procedure without any extension. 64 * The default encoding validation procedure without any extension.
(...skipping 18 matching lines...) Expand all
83 * @return true if the parameters are correct. 83 * @return true if the parameters are correct.
84 */ 84 */
85 static OPJ_BOOL opj_j2k_decoding_validation ( opj_j2k_t * p_j2k, 85 static OPJ_BOOL opj_j2k_decoding_validation ( opj_j2k_t * p_j2k,
86 opj_stream_private_t *p_stream, 86 opj_stream_private_t *p_stream,
87 opj_event_mgr_t * p_manager ); 87 opj_event_mgr_t * p_manager );
88 88
89 /** 89 /**
90 * Sets up the validation ,i.e. adds the procedures to lauch to make sure the co dec parameters 90 * Sets up the validation ,i.e. adds the procedures to lauch to make sure the co dec parameters
91 * are valid. Developpers wanting to extend the library can add their own valida tion procedures. 91 * are valid. Developpers wanting to extend the library can add their own valida tion procedures.
92 */ 92 */
93 static void opj_j2k_setup_encoding_validation (opj_j2k_t *p_j2k); 93 static OPJ_BOOL opj_j2k_setup_encoding_validation (opj_j2k_t *p_j2k, opj_event_m gr_t * p_manager);
94 94
95 /** 95 /**
96 * Sets up the validation ,i.e. adds the procedures to lauch to make sure the co dec parameters 96 * Sets up the validation ,i.e. adds the procedures to lauch to make sure the co dec parameters
97 * are valid. Developpers wanting to extend the library can add their own valida tion procedures. 97 * are valid. Developpers wanting to extend the library can add their own valida tion procedures.
98 */ 98 */
99 static void opj_j2k_setup_decoding_validation (opj_j2k_t *p_j2k); 99 static OPJ_BOOL opj_j2k_setup_decoding_validation (opj_j2k_t *p_j2k, opj_event_m gr_t * p_manager);
100 100
101 /** 101 /**
102 * Sets up the validation ,i.e. adds the procedures to lauch to make sure the co dec parameters 102 * Sets up the validation ,i.e. adds the procedures to lauch to make sure the co dec parameters
103 * are valid. Developpers wanting to extend the library can add their own valida tion procedures. 103 * are valid. Developpers wanting to extend the library can add their own valida tion procedures.
104 */ 104 */
105 static void opj_j2k_setup_end_compress (opj_j2k_t *p_j2k); 105 static OPJ_BOOL opj_j2k_setup_end_compress (opj_j2k_t *p_j2k, opj_event_mgr_t * p_manager);
106 106
107 /** 107 /**
108 * The mct encoding validation procedure. 108 * The mct encoding validation procedure.
109 * 109 *
110 * @param p_j2k the jpeg2000 codec to validate. 110 * @param p_j2k the jpeg2000 codec to validate.
111 * @param p_stream the input stream to vali date. 111 * @param p_stream the input stream to vali date.
112 * @param p_manager the user event manager. 112 * @param p_manager the user event manager.
113 * 113 *
114 * @return true if the parameters are correct. 114 * @return true if the parameters are correct.
115 */ 115 */
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 static void opj_j2k_get_tile_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data); 353 static void opj_j2k_get_tile_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data);
354 354
355 static OPJ_BOOL opj_j2k_post_write_tile (opj_j2k_t * p_j2k, 355 static OPJ_BOOL opj_j2k_post_write_tile (opj_j2k_t * p_j2k,
356 opj _stream_private_t *p_stream, 356 opj _stream_private_t *p_stream,
357 opj _event_mgr_t * p_manager ); 357 opj _event_mgr_t * p_manager );
358 358
359 /** 359 /**
360 * Sets up the procedures to do on writing header. 360 * Sets up the procedures to do on writing header.
361 * Developers wanting to extend the library can add their own writing procedures . 361 * Developers wanting to extend the library can add their own writing procedures .
362 */ 362 */
363 static void opj_j2k_setup_header_writing (opj_j2k_t *p_j2k); 363 static OPJ_BOOL opj_j2k_setup_header_writing (opj_j2k_t *p_j2k, opj_event_mgr_t * p_manager);
364 364
365 static OPJ_BOOL opj_j2k_write_first_tile_part( opj_j2k_t *p_j2k, 365 static OPJ_BOOL opj_j2k_write_first_tile_part( opj_j2k_t *p_j2k,
366 OPJ_BYTE * p_data, 366 OPJ_BYTE * p_data,
367 OPJ_UINT32 * p_data_written, 367 OPJ_UINT32 * p_data_written,
368 OPJ_UINT32 p_total_data_size, 368 OPJ_UINT32 p_total_data_size,
369 opj_stream_private_t *p_stream, 369 opj_stream_private_t *p_stream,
370 struct opj_event_mgr * p_manager ); 370 struct opj_event_mgr * p_manager );
371 371
372 static OPJ_BOOL opj_j2k_write_all_tile_parts( opj_j2k_t *p_j2k, 372 static OPJ_BOOL opj_j2k_write_all_tile_parts( opj_j2k_t *p_j2k,
373 OPJ_BYTE * p_data, 373 OPJ_BYTE * p_data,
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
711 * @param p_header_data the data contained in the PLT box. 711 * @param p_header_data the data contained in the PLT box.
712 * @param p_j2k the jpeg2000 codec. 712 * @param p_j2k the jpeg2000 codec.
713 * @param p_header_size the size of the data contained in the PLT marker . 713 * @param p_header_size the size of the data contained in the PLT marker .
714 * @param p_manager the user event manager. 714 * @param p_manager the user event manager.
715 */ 715 */
716 static OPJ_BOOL opj_j2k_read_plt ( opj_j2k_t *p_j2k, 716 static OPJ_BOOL opj_j2k_read_plt ( opj_j2k_t *p_j2k,
717 OPJ_BYTE * p_header_data, 717 OPJ_BYTE * p_header_data,
718 OPJ_UINT32 p_header_size, 718 OPJ_UINT32 p_header_size,
719 opj_event_mgr_t * p_manager ); 719 opj_event_mgr_t * p_manager );
720 720
721 #if 0
722 /** 721 /**
723 * Reads a PPM marker (Packed packet headers, main header) 722 * Reads a PPM marker (Packed headers, main header)
724 * 723 *
725 * @param p_header_data the data contained in the POC box. 724 * @param p_header_data the data contained in the POC box.
726 * @param p_j2k the jpeg2000 codec. 725 * @param p_j2k the jpeg2000 codec.
727 * @param p_header_size the size of the data contained in the POC marker . 726 * @param p_header_size the size of the data contained in the POC marker .
728 * @param p_manager the user event manager. 727 * @param p_manager the user event manager.
729 */ 728 */
730 static OPJ_BOOL j2k_read_ppm_v2 (
731 opj_j2k_t *p_j2k,
732 OPJ_BYTE * p_header_data,
733 OPJ_UINT32 p_header_size,
734 struct opj_event_mgr * p_manager
735 );
736 #endif
737 729
738 static OPJ_BOOL j2k_read_ppm_v3 ( 730 static OPJ_BOOL opj_j2k_read_ppm (
739 opj_j2k_t *p_j2k, 731 » » » » » » » » » » » » » » » » » » opj_j2k_t *p_j2 k,
740 OPJ_BYTE * p_header_data, 732 » » » » » » » » » » » » » » » » » » OPJ_BYTE * p_he ader_data,
741 OPJ_UINT32 p_header_size, 733 » » » » » » » » » » » » » » » » » » OPJ_UINT32 p_he ader_size,
742 opj_event_mgr_t * p_manager ); 734 » » » » » » » » » » » » » » » » » » opj_event_mgr_t * p_manager );
735
736 /**
737 * Merges all PPM markers read (Packed headers, main header)
738 *
739 * @param p_cp main coding parameters.
740 * @param p_manager the user event manager.
741 */
742 static OPJ_BOOL opj_j2k_merge_ppm ( opj_cp_t *p_cp, opj_event_mgr_t * p_manager );
743 743
744 /** 744 /**
745 * Reads a PPT marker (Packed packet headers, tile-part header) 745 * Reads a PPT marker (Packed packet headers, tile-part header)
746 * 746 *
747 * @param p_header_data the data contained in the PPT box. 747 * @param p_header_data the data contained in the PPT box.
748 * @param p_j2k the jpeg2000 codec. 748 * @param p_j2k the jpeg2000 codec.
749 * @param p_header_size the size of the data contained in the PPT marker . 749 * @param p_header_size the size of the data contained in the PPT marker .
750 * @param p_manager the user event manager. 750 * @param p_manager the user event manager.
751 */ 751 */
752 static OPJ_BOOL opj_j2k_read_ppt ( opj_j2k_t *p_j2k, 752 static OPJ_BOOL opj_j2k_read_ppt ( opj_j2k_t *p_j2k,
753 OPJ_BYTE * p_header_data, 753 OPJ_BYTE * p_header_data,
754 OPJ_UINT32 p_header_size, 754 OPJ_UINT32 p_header_size,
755 opj_event_mgr_t * p_manager ); 755 opj_event_mgr_t * p_manager );
756
757 /**
758 * Merges all PPT markers read (Packed headers, tile-part header)
759 *
760 * @param p_tcp the tile.
761 * @param p_manager the user event manager.
762 */
763 static OPJ_BOOL opj_j2k_merge_ppt ( opj_tcp_t *p_tcp,
764 opj_event_mgr_t * p_m anager );
765
766
756 /** 767 /**
757 * Writes the TLM marker (Tile Length Marker) 768 * Writes the TLM marker (Tile Length Marker)
758 * 769 *
759 * @param p_stream the stream to write data to. 770 * @param p_stream the stream to write data to.
760 * @param p_j2k J2K codec. 771 * @param p_j2k J2K codec.
761 * @param p_manager the user event manager. 772 * @param p_manager the user event manager.
762 */ 773 */
763 static OPJ_BOOL opj_j2k_write_tlm( opj_j2k_t *p_j2k, 774 static OPJ_BOOL opj_j2k_write_tlm( opj_j2k_t *p_j2k,
764 opj_stre am_private_t *p_stream, 775 opj_stre am_private_t *p_stream,
765 opj_even t_mgr_t * p_manager ); 776 opj_even t_mgr_t * p_manager );
766 777
767 /** 778 /**
768 * Writes the SOT marker (Start of tile-part) 779 * Writes the SOT marker (Start of tile-part)
769 * 780 *
770 * @param p_j2k J2K codec. 781 * @param p_j2k J2K codec.
771 * @param p_data FIXME DOC 782 * @param p_data FIXME DOC
772 * @param p_data_written FIXME DOC 783 * @param p_data_written FIXME DOC
773 * @param p_stream the stream to write data to. 784 * @param p_stream the stream to write data to.
774 * @param p_manager the user event manager. 785 * @param p_manager the user event manager.
775 */ 786 */
776 static OPJ_BOOL opj_j2k_write_sot( opj_j2k_t *p_j2k, 787 static OPJ_BOOL opj_j2k_write_sot( opj_j2k_t *p_j2k,
777 OPJ_BYTE * p_data, 788 OPJ_BYTE * p_data,
778 OPJ_UINT 32 * p_data_written, 789 OPJ_UINT 32 * p_data_written,
779 const op j_stream_private_t *p_stream, 790 const op j_stream_private_t *p_stream,
780 opj_even t_mgr_t * p_manager ); 791 opj_even t_mgr_t * p_manager );
781 792
782 /** 793 /**
783 * Reads a PPT marker (Packed packet headers, tile-part header) 794 * Reads values from a SOT marker (Start of tile-part)
784 * 795 *
785 * @param p_header_data the data contained in the PPT box. 796 * the j2k decoder state is not affected. No side effects, no checks except for p_header_size.
786 * @param p_j2k the jpeg2000 codec. 797 *
798 * @param p_header_data the data contained in the SOT marker.
799 * @param p_header_size the size of the data contained in the SOT marker .
800 * @param p_tile_no Isot.
801 * @param p_tot_len Psot.
802 * @param p_current_part TPsot.
803 * @param p_num_parts TNsot.
804 * @param p_manager the user event manager.
805 */
806 static OPJ_BOOL opj_j2k_get_sot_values(OPJ_BYTE * p_header_data,
807 » » » » » » » » » » » » » » » » » » » OPJ_UIN T32 p_header_size,
808 » » » » » » » » » » » » » » » » » » » OPJ_UIN T32* p_tile_no,
809 » » » » » » » » » » » » » » » » » » » OPJ_UIN T32* p_tot_len,
810 » » » » » » » » » » » » » » » » » » » OPJ_UIN T32* p_current_part,
811 » » » » » » » » » » » » » » » » » » » OPJ_UIN T32* p_num_parts,
812 » » » » » » » » » » » » » » » » » » » opj_eve nt_mgr_t * p_manager );
813 /**
814 * Reads a SOT marker (Start of tile-part)
815 *
816 * @param p_header_data the data contained in the SOT marker.
817 * @param p_j2k the jpeg2000 codec.
787 * @param p_header_size the size of the data contained in the PPT marker . 818 * @param p_header_size the size of the data contained in the PPT marker .
788 * @param p_manager the user event manager. 819 * @param p_manager the user event manager.
789 */ 820 */
790 static OPJ_BOOL opj_j2k_read_sot ( opj_j2k_t *p_j2k, 821 static OPJ_BOOL opj_j2k_read_sot ( opj_j2k_t *p_j2k,
791 OPJ_BYTE * p_header_data, 822 OPJ_BYTE * p_header_data,
792 OPJ_UINT32 p_header_size, 823 OPJ_UINT32 p_header_size,
793 opj_event_mgr_t * p_manager ); 824 opj_event_mgr_t * p_manager );
794 /** 825 /**
795 * Writes the SOD marker (Start of data) 826 * Writes the SOD marker (Start of data)
796 * 827 *
797 * @param p_j2k J2K codec. 828 * @param p_j2k J2K codec.
798 * @param p_tile_coder FIXME DOC 829 * @param p_tile_coder FIXME DOC
(...skipping 15 matching lines...) Expand all
814 * Reads a SOD marker (Start Of Data) 845 * Reads a SOD marker (Start Of Data)
815 * 846 *
816 * @param p_j2k the jpeg2000 codec. 847 * @param p_j2k the jpeg2000 codec.
817 * @param p_stream FIXME DOC 848 * @param p_stream FIXME DOC
818 * @param p_manager the user event manager. 849 * @param p_manager the user event manager.
819 */ 850 */
820 static OPJ_BOOL opj_j2k_read_sod( opj_j2k_t *p_j2k, 851 static OPJ_BOOL opj_j2k_read_sod( opj_j2k_t *p_j2k,
821 opj_stream_private_t *p_stream, 852 opj_stream_private_t *p_stream,
822 opj_event_mgr_t * p_manager ); 853 opj_event_mgr_t * p_manager );
823 854
824 void opj_j2k_update_tlm (opj_j2k_t * p_j2k, OPJ_UINT32 p_tile_part_size ) 855 static void opj_j2k_update_tlm (opj_j2k_t * p_j2k, OPJ_UINT32 p_tile_part_size )
825 { 856 {
826 opj_write_bytes(p_j2k->m_specific_param.m_encoder.m_tlm_sot_offsets_curr ent,p_j2k->m_current_tile_number,1); /* PSOT */ 857 opj_write_bytes(p_j2k->m_specific_param.m_encoder.m_tlm_sot_offsets_curr ent,p_j2k->m_current_tile_number,1); /* PSOT */
827 ++p_j2k->m_specific_param.m_encoder.m_tlm_sot_offsets_current; 858 ++p_j2k->m_specific_param.m_encoder.m_tlm_sot_offsets_current;
828 859
829 opj_write_bytes(p_j2k->m_specific_param.m_encoder.m_tlm_sot_offsets_curr ent,p_tile_part_size,4); /* PSOT */ 860 opj_write_bytes(p_j2k->m_specific_param.m_encoder.m_tlm_sot_offsets_curr ent,p_tile_part_size,4); /* PSOT */
830 p_j2k->m_specific_param.m_encoder.m_tlm_sot_offsets_current += 4; 861 p_j2k->m_specific_param.m_encoder.m_tlm_sot_offsets_current += 4;
831 } 862 }
832 863
833 /** 864 /**
834 * Writes the RGN marker (Region Of Interest) 865 * Writes the RGN marker (Region Of Interest)
(...skipping 337 matching lines...) Expand 10 before | Expand all | Expand 10 after
1172 static OPJ_FLOAT32 opj_j2k_get_tp_stride (opj_tcp_t * p_tcp); 1203 static OPJ_FLOAT32 opj_j2k_get_tp_stride (opj_tcp_t * p_tcp);
1173 1204
1174 static OPJ_FLOAT32 opj_j2k_get_default_stride (opj_tcp_t * p_tcp); 1205 static OPJ_FLOAT32 opj_j2k_get_default_stride (opj_tcp_t * p_tcp);
1175 1206
1176 static int opj_j2k_initialise_4K_poc(opj_poc_t *POC, int numres); 1207 static int opj_j2k_initialise_4K_poc(opj_poc_t *POC, int numres);
1177 1208
1178 static void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_ima ge_t *image, opj_event_mgr_t *p_manager); 1209 static void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_ima ge_t *image, opj_event_mgr_t *p_manager);
1179 1210
1180 static OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_UINT16 rsiz, opj_event_mgr_t *p_manager); 1211 static OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_UINT16 rsiz, opj_event_mgr_t *p_manager);
1181 1212
1213 /**
1214 * Checks for invalid number of tile-parts in SOT marker (TPsot==TNsot). See iss ue 254.
1215 *
1216 * @param p_stream the stream to read data from.
1217 * @param tile_no tile number we're looking for.
1218 * @param p_correction_needed output value. if true, non conformant codest ream needs TNsot correction.
1219 * @param p_manager the user event manager.
1220 *
1221 * @return true if the function was successful, false else.
1222 */
1223 static OPJ_BOOL opj_j2k_need_nb_tile_parts_correction(opj_stream_private_t *p_st ream, OPJ_UINT32 tile_no, OPJ_BOOL* p_correction_needed, opj_event_mgr_t * p_man ager );
1224
1182 /*@}*/ 1225 /*@}*/
1183 1226
1184 /*@}*/ 1227 /*@}*/
1185 1228
1186 /* ----------------------------------------------------------------------- */ 1229 /* ----------------------------------------------------------------------- */
1187 typedef struct j2k_prog_order{ 1230 typedef struct j2k_prog_order{
1188 OPJ_PROG_ORDER enum_prog; 1231 OPJ_PROG_ORDER enum_prog;
1189 char str_prog[5]; 1232 char str_prog[5];
1190 }j2k_prog_order_t; 1233 }j2k_prog_order_t;
1191 1234
1192 j2k_prog_order_t j2k_prog_order_list[] = { 1235 static j2k_prog_order_t j2k_prog_order_list[] = {
1193 {OPJ_CPRL, "CPRL"}, 1236 {OPJ_CPRL, "CPRL"},
1194 {OPJ_LRCP, "LRCP"}, 1237 {OPJ_LRCP, "LRCP"},
1195 {OPJ_PCRL, "PCRL"}, 1238 {OPJ_PCRL, "PCRL"},
1196 {OPJ_RLCP, "RLCP"}, 1239 {OPJ_RLCP, "RLCP"},
1197 {OPJ_RPCL, "RPCL"}, 1240 {OPJ_RPCL, "RPCL"},
1198 {(OPJ_PROG_ORDER)-1, ""} 1241 {(OPJ_PROG_ORDER)-1, ""}
1199 }; 1242 };
1200 1243
1201 /** 1244 /**
1202 * FIXME DOC 1245 * FIXME DOC
1203 */ 1246 */
1204 static const OPJ_UINT32 MCT_ELEMENT_SIZE [] = 1247 static const OPJ_UINT32 MCT_ELEMENT_SIZE [] =
1205 { 1248 {
1206 2, 1249 2,
1207 4, 1250 4,
1208 4, 1251 4,
1209 8 1252 8
1210 }; 1253 };
1211 1254
1212 typedef void (* opj_j2k_mct_function) (const void * p_src_data, void * p_dest_da ta, OPJ_UINT32 p_nb_elem); 1255 typedef void (* opj_j2k_mct_function) (const void * p_src_data, void * p_dest_da ta, OPJ_UINT32 p_nb_elem);
1213 1256
1214 const opj_j2k_mct_function j2k_mct_read_functions_to_float [] = 1257 static const opj_j2k_mct_function j2k_mct_read_functions_to_float [] =
1215 { 1258 {
1216 opj_j2k_read_int16_to_float, 1259 opj_j2k_read_int16_to_float,
1217 opj_j2k_read_int32_to_float, 1260 opj_j2k_read_int32_to_float,
1218 opj_j2k_read_float32_to_float, 1261 opj_j2k_read_float32_to_float,
1219 opj_j2k_read_float64_to_float 1262 opj_j2k_read_float64_to_float
1220 }; 1263 };
1221 1264
1222 const opj_j2k_mct_function j2k_mct_read_functions_to_int32 [] = 1265 static const opj_j2k_mct_function j2k_mct_read_functions_to_int32 [] =
1223 { 1266 {
1224 opj_j2k_read_int16_to_int32, 1267 opj_j2k_read_int16_to_int32,
1225 opj_j2k_read_int32_to_int32, 1268 opj_j2k_read_int32_to_int32,
1226 opj_j2k_read_float32_to_int32, 1269 opj_j2k_read_float32_to_int32,
1227 opj_j2k_read_float64_to_int32 1270 opj_j2k_read_float64_to_int32
1228 }; 1271 };
1229 1272
1230 const opj_j2k_mct_function j2k_mct_write_functions_from_float [] = 1273 static const opj_j2k_mct_function j2k_mct_write_functions_from_float [] =
1231 { 1274 {
1232 opj_j2k_write_float_to_int16, 1275 opj_j2k_write_float_to_int16,
1233 opj_j2k_write_float_to_int32, 1276 opj_j2k_write_float_to_int32,
1234 opj_j2k_write_float_to_float, 1277 opj_j2k_write_float_to_float,
1235 opj_j2k_write_float_to_float64 1278 opj_j2k_write_float_to_float64
1236 }; 1279 };
1237 1280
1238 typedef struct opj_dec_memory_marker_handler 1281 typedef struct opj_dec_memory_marker_handler
1239 { 1282 {
1240 /** marker value */ 1283 /** marker value */
1241 OPJ_UINT32 id; 1284 OPJ_UINT32 id;
1242 /** value of the state when the marker can appear */ 1285 /** value of the state when the marker can appear */
1243 OPJ_UINT32 states; 1286 OPJ_UINT32 states;
1244 /** action linked to the marker */ 1287 /** action linked to the marker */
1245 OPJ_BOOL (*handler) ( opj_j2k_t *p_j2k, 1288 OPJ_BOOL (*handler) ( opj_j2k_t *p_j2k,
1246 OPJ_BYTE * p_header_data, 1289 OPJ_BYTE * p_header_data,
1247 OPJ_UINT32 p_header_size, 1290 OPJ_UINT32 p_header_size,
1248 opj_event_mgr_t * p_manager ); 1291 opj_event_mgr_t * p_manager );
1249 } 1292 }
1250 opj_dec_memory_marker_handler_t; 1293 opj_dec_memory_marker_handler_t;
1251 1294
1252 const opj_dec_memory_marker_handler_t j2k_memory_marker_handler_tab [] = 1295 static const opj_dec_memory_marker_handler_t j2k_memory_marker_handler_tab [] =
1253 { 1296 {
1254 {J2K_MS_SOT, J2K_STATE_MH | J2K_STATE_TPHSOT, opj_j2k_read_sot}, 1297 {J2K_MS_SOT, J2K_STATE_MH | J2K_STATE_TPHSOT, opj_j2k_read_sot},
1255 {J2K_MS_COD, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_cod}, 1298 {J2K_MS_COD, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_cod},
1256 {J2K_MS_COC, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_coc}, 1299 {J2K_MS_COC, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_coc},
1257 {J2K_MS_RGN, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_rgn}, 1300 {J2K_MS_RGN, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_rgn},
1258 {J2K_MS_QCD, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_qcd}, 1301 {J2K_MS_QCD, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_qcd},
1259 {J2K_MS_QCC, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_qcc}, 1302 {J2K_MS_QCC, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_qcc},
1260 {J2K_MS_POC, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_poc}, 1303 {J2K_MS_POC, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_poc},
1261 {J2K_MS_SIZ, J2K_STATE_MHSIZ, opj_j2k_read_siz}, 1304 {J2K_MS_SIZ, J2K_STATE_MHSIZ, opj_j2k_read_siz},
1262 {J2K_MS_TLM, J2K_STATE_MH, opj_j2k_read_tlm}, 1305 {J2K_MS_TLM, J2K_STATE_MH, opj_j2k_read_tlm},
1263 {J2K_MS_PLM, J2K_STATE_MH, opj_j2k_read_plm}, 1306 {J2K_MS_PLM, J2K_STATE_MH, opj_j2k_read_plm},
1264 {J2K_MS_PLT, J2K_STATE_TPH, opj_j2k_read_plt}, 1307 {J2K_MS_PLT, J2K_STATE_TPH, opj_j2k_read_plt},
1265 {J2K_MS_PPM, J2K_STATE_MH, j2k_read_ppm_v3}, 1308 {J2K_MS_PPM, J2K_STATE_MH, opj_j2k_read_ppm},
1266 {J2K_MS_PPT, J2K_STATE_TPH, opj_j2k_read_ppt}, 1309 {J2K_MS_PPT, J2K_STATE_TPH, opj_j2k_read_ppt},
1267 {J2K_MS_SOP, 0, 0}, 1310 {J2K_MS_SOP, 0, 0},
1268 {J2K_MS_CRG, J2K_STATE_MH, opj_j2k_read_crg}, 1311 {J2K_MS_CRG, J2K_STATE_MH, opj_j2k_read_crg},
1269 {J2K_MS_COM, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_com}, 1312 {J2K_MS_COM, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_com},
1270 {J2K_MS_MCT, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_mct}, 1313 {J2K_MS_MCT, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_mct},
1271 {J2K_MS_CBD, J2K_STATE_MH , opj_j2k_read_cbd}, 1314 {J2K_MS_CBD, J2K_STATE_MH , opj_j2k_read_cbd},
1272 {J2K_MS_MCC, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_mcc}, 1315 {J2K_MS_MCC, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_mcc},
1273 {J2K_MS_MCO, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_mco}, 1316 {J2K_MS_MCO, J2K_STATE_MH | J2K_STATE_TPH, opj_j2k_read_mco},
1274 #ifdef USE_JPWL 1317 #ifdef USE_JPWL
1275 #ifdef TODO_MS /* remove these functions which are not commpatible with the v2 A PI */ 1318 #ifdef TODO_MS /* remove these functions which are not commpatible with the v2 A PI */
1276 {J2K_MS_EPC, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_epc}, 1319 {J2K_MS_EPC, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_epc},
1277 {J2K_MS_EPB, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_epb}, 1320 {J2K_MS_EPB, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_epb},
1278 {J2K_MS_ESD, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_esd}, 1321 {J2K_MS_ESD, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_esd},
1279 {J2K_MS_RED, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_red}, 1322 {J2K_MS_RED, J2K_STATE_MH | J2K_STATE_TPH, j2k_read_red},
1280 #endif 1323 #endif
1281 #endif /* USE_JPWL */ 1324 #endif /* USE_JPWL */
1282 #ifdef USE_JPSEC 1325 #ifdef USE_JPSEC
1283 {J2K_MS_SEC, J2K_DEC_STATE_MH, j2k_read_sec}, 1326 {J2K_MS_SEC, J2K_DEC_STATE_MH, j2k_read_sec},
1284 {J2K_MS_INSEC, 0, j2k_read_insec} 1327 {J2K_MS_INSEC, 0, j2k_read_insec}
1285 #endif /* USE_JPSEC */ 1328 #endif /* USE_JPSEC */
1286 {J2K_MS_UNK, J2K_STATE_MH | J2K_STATE_TPH, 0}/*opj_j2k_read_unk is directly us ed*/ 1329 {J2K_MS_UNK, J2K_STATE_MH | J2K_STATE_TPH, 0}/*opj_j2k_read_unk is directly us ed*/
1287 }; 1330 };
1288 1331
1289 void opj_j2k_read_int16_to_float (const void * p_src_data, void * p_dest_data, OPJ_UINT32 p_nb_elem) 1332 static void opj_j2k_read_int16_to_float (const void * p_src_data, void * p_dest _data, OPJ_UINT32 p_nb_elem)
1290 { 1333 {
1291 OPJ_BYTE * l_src_data = (OPJ_BYTE *) p_src_data; 1334 OPJ_BYTE * l_src_data = (OPJ_BYTE *) p_src_data;
1292 OPJ_FLOAT32 * l_dest_data = (OPJ_FLOAT32 *) p_dest_data; 1335 OPJ_FLOAT32 * l_dest_data = (OPJ_FLOAT32 *) p_dest_data;
1293 OPJ_UINT32 i; 1336 OPJ_UINT32 i;
1294 OPJ_UINT32 l_temp; 1337 OPJ_UINT32 l_temp;
1295 1338
1296 for (i=0;i<p_nb_elem;++i) { 1339 for (i=0;i<p_nb_elem;++i) {
1297 opj_read_bytes(l_src_data,&l_temp,2); 1340 opj_read_bytes(l_src_data,&l_temp,2);
1298 1341
1299 l_src_data+=sizeof(OPJ_INT16); 1342 l_src_data+=sizeof(OPJ_INT16);
1300 1343
1301 *(l_dest_data++) = (OPJ_FLOAT32) l_temp; 1344 *(l_dest_data++) = (OPJ_FLOAT32) l_temp;
1302 } 1345 }
1303 } 1346 }
1304 1347
1305 void opj_j2k_read_int32_to_float (const void * p_src_data, void * p_dest_data, OPJ_UINT32 p_nb_elem) 1348 static void opj_j2k_read_int32_to_float (const void * p_src_data, void * p_dest _data, OPJ_UINT32 p_nb_elem)
1306 { 1349 {
1307 OPJ_BYTE * l_src_data = (OPJ_BYTE *) p_src_data; 1350 OPJ_BYTE * l_src_data = (OPJ_BYTE *) p_src_data;
1308 OPJ_FLOAT32 * l_dest_data = (OPJ_FLOAT32 *) p_dest_data; 1351 OPJ_FLOAT32 * l_dest_data = (OPJ_FLOAT32 *) p_dest_data;
1309 OPJ_UINT32 i; 1352 OPJ_UINT32 i;
1310 OPJ_UINT32 l_temp; 1353 OPJ_UINT32 l_temp;
1311 1354
1312 for (i=0;i<p_nb_elem;++i) { 1355 for (i=0;i<p_nb_elem;++i) {
1313 opj_read_bytes(l_src_data,&l_temp,4); 1356 opj_read_bytes(l_src_data,&l_temp,4);
1314 1357
1315 l_src_data+=sizeof(OPJ_INT32); 1358 l_src_data+=sizeof(OPJ_INT32);
1316 1359
1317 *(l_dest_data++) = (OPJ_FLOAT32) l_temp; 1360 *(l_dest_data++) = (OPJ_FLOAT32) l_temp;
1318 } 1361 }
1319 } 1362 }
1320 1363
1321 void opj_j2k_read_float32_to_float (const void * p_src_data, void * p_dest_data , OPJ_UINT32 p_nb_elem) 1364 static void opj_j2k_read_float32_to_float (const void * p_src_data, void * p_de st_data, OPJ_UINT32 p_nb_elem)
1322 { 1365 {
1323 OPJ_BYTE * l_src_data = (OPJ_BYTE *) p_src_data; 1366 OPJ_BYTE * l_src_data = (OPJ_BYTE *) p_src_data;
1324 OPJ_FLOAT32 * l_dest_data = (OPJ_FLOAT32 *) p_dest_data; 1367 OPJ_FLOAT32 * l_dest_data = (OPJ_FLOAT32 *) p_dest_data;
1325 OPJ_UINT32 i; 1368 OPJ_UINT32 i;
1326 OPJ_FLOAT32 l_temp; 1369 OPJ_FLOAT32 l_temp;
1327 1370
1328 for (i=0;i<p_nb_elem;++i) { 1371 for (i=0;i<p_nb_elem;++i) {
1329 opj_read_float(l_src_data,&l_temp); 1372 opj_read_float(l_src_data,&l_temp);
1330 1373
1331 l_src_data+=sizeof(OPJ_FLOAT32); 1374 l_src_data+=sizeof(OPJ_FLOAT32);
1332 1375
1333 *(l_dest_data++) = l_temp; 1376 *(l_dest_data++) = l_temp;
1334 } 1377 }
1335 } 1378 }
1336 1379
1337 void opj_j2k_read_float64_to_float (const void * p_src_data, void * p_dest_data , OPJ_UINT32 p_nb_elem) 1380 static void opj_j2k_read_float64_to_float (const void * p_src_data, void * p_de st_data, OPJ_UINT32 p_nb_elem)
1338 { 1381 {
1339 OPJ_BYTE * l_src_data = (OPJ_BYTE *) p_src_data; 1382 OPJ_BYTE * l_src_data = (OPJ_BYTE *) p_src_data;
1340 OPJ_FLOAT32 * l_dest_data = (OPJ_FLOAT32 *) p_dest_data; 1383 OPJ_FLOAT32 * l_dest_data = (OPJ_FLOAT32 *) p_dest_data;
1341 OPJ_UINT32 i; 1384 OPJ_UINT32 i;
1342 OPJ_FLOAT64 l_temp; 1385 OPJ_FLOAT64 l_temp;
1343 1386
1344 for (i=0;i<p_nb_elem;++i) { 1387 for (i=0;i<p_nb_elem;++i) {
1345 opj_read_double(l_src_data,&l_temp); 1388 opj_read_double(l_src_data,&l_temp);
1346 1389
1347 l_src_data+=sizeof(OPJ_FLOAT64); 1390 l_src_data+=sizeof(OPJ_FLOAT64);
1348 1391
1349 *(l_dest_data++) = (OPJ_FLOAT32) l_temp; 1392 *(l_dest_data++) = (OPJ_FLOAT32) l_temp;
1350 } 1393 }
1351 } 1394 }
1352 1395
1353 void opj_j2k_read_int16_to_int32 (const void * p_src_data, void * p_dest_data, OPJ_UINT32 p_nb_elem) 1396 static void opj_j2k_read_int16_to_int32 (const void * p_src_data, void * p_dest _data, OPJ_UINT32 p_nb_elem)
1354 { 1397 {
1355 OPJ_BYTE * l_src_data = (OPJ_BYTE *) p_src_data; 1398 OPJ_BYTE * l_src_data = (OPJ_BYTE *) p_src_data;
1356 OPJ_INT32 * l_dest_data = (OPJ_INT32 *) p_dest_data; 1399 OPJ_INT32 * l_dest_data = (OPJ_INT32 *) p_dest_data;
1357 OPJ_UINT32 i; 1400 OPJ_UINT32 i;
1358 OPJ_UINT32 l_temp; 1401 OPJ_UINT32 l_temp;
1359 1402
1360 for (i=0;i<p_nb_elem;++i) { 1403 for (i=0;i<p_nb_elem;++i) {
1361 opj_read_bytes(l_src_data,&l_temp,2); 1404 opj_read_bytes(l_src_data,&l_temp,2);
1362 1405
1363 l_src_data+=sizeof(OPJ_INT16); 1406 l_src_data+=sizeof(OPJ_INT16);
1364 1407
1365 *(l_dest_data++) = (OPJ_INT32) l_temp; 1408 *(l_dest_data++) = (OPJ_INT32) l_temp;
1366 } 1409 }
1367 } 1410 }
1368 1411
1369 void opj_j2k_read_int32_to_int32 (const void * p_src_data, void * p_dest_data, OPJ_UINT32 p_nb_elem) 1412 static void opj_j2k_read_int32_to_int32 (const void * p_src_data, void * p_dest _data, OPJ_UINT32 p_nb_elem)
1370 { 1413 {
1371 OPJ_BYTE * l_src_data = (OPJ_BYTE *) p_src_data; 1414 OPJ_BYTE * l_src_data = (OPJ_BYTE *) p_src_data;
1372 OPJ_INT32 * l_dest_data = (OPJ_INT32 *) p_dest_data; 1415 OPJ_INT32 * l_dest_data = (OPJ_INT32 *) p_dest_data;
1373 OPJ_UINT32 i; 1416 OPJ_UINT32 i;
1374 OPJ_UINT32 l_temp; 1417 OPJ_UINT32 l_temp;
1375 1418
1376 for (i=0;i<p_nb_elem;++i) { 1419 for (i=0;i<p_nb_elem;++i) {
1377 opj_read_bytes(l_src_data,&l_temp,4); 1420 opj_read_bytes(l_src_data,&l_temp,4);
1378 1421
1379 l_src_data+=sizeof(OPJ_INT32); 1422 l_src_data+=sizeof(OPJ_INT32);
1380 1423
1381 *(l_dest_data++) = (OPJ_INT32) l_temp; 1424 *(l_dest_data++) = (OPJ_INT32) l_temp;
1382 } 1425 }
1383 } 1426 }
1384 1427
1385 void opj_j2k_read_float32_to_int32 (const void * p_src_data, void * p_dest_data , OPJ_UINT32 p_nb_elem) 1428 static void opj_j2k_read_float32_to_int32 (const void * p_src_data, void * p_de st_data, OPJ_UINT32 p_nb_elem)
1386 { 1429 {
1387 OPJ_BYTE * l_src_data = (OPJ_BYTE *) p_src_data; 1430 OPJ_BYTE * l_src_data = (OPJ_BYTE *) p_src_data;
1388 OPJ_INT32 * l_dest_data = (OPJ_INT32 *) p_dest_data; 1431 OPJ_INT32 * l_dest_data = (OPJ_INT32 *) p_dest_data;
1389 OPJ_UINT32 i; 1432 OPJ_UINT32 i;
1390 OPJ_FLOAT32 l_temp; 1433 OPJ_FLOAT32 l_temp;
1391 1434
1392 for (i=0;i<p_nb_elem;++i) { 1435 for (i=0;i<p_nb_elem;++i) {
1393 opj_read_float(l_src_data,&l_temp); 1436 opj_read_float(l_src_data,&l_temp);
1394 1437
1395 l_src_data+=sizeof(OPJ_FLOAT32); 1438 l_src_data+=sizeof(OPJ_FLOAT32);
1396 1439
1397 *(l_dest_data++) = (OPJ_INT32) l_temp; 1440 *(l_dest_data++) = (OPJ_INT32) l_temp;
1398 } 1441 }
1399 } 1442 }
1400 1443
1401 void opj_j2k_read_float64_to_int32 (const void * p_src_data, void * p_dest_data , OPJ_UINT32 p_nb_elem) 1444 static void opj_j2k_read_float64_to_int32 (const void * p_src_data, void * p_de st_data, OPJ_UINT32 p_nb_elem)
1402 { 1445 {
1403 OPJ_BYTE * l_src_data = (OPJ_BYTE *) p_src_data; 1446 OPJ_BYTE * l_src_data = (OPJ_BYTE *) p_src_data;
1404 OPJ_INT32 * l_dest_data = (OPJ_INT32 *) p_dest_data; 1447 OPJ_INT32 * l_dest_data = (OPJ_INT32 *) p_dest_data;
1405 OPJ_UINT32 i; 1448 OPJ_UINT32 i;
1406 OPJ_FLOAT64 l_temp; 1449 OPJ_FLOAT64 l_temp;
1407 1450
1408 for (i=0;i<p_nb_elem;++i) { 1451 for (i=0;i<p_nb_elem;++i) {
1409 opj_read_double(l_src_data,&l_temp); 1452 opj_read_double(l_src_data,&l_temp);
1410 1453
1411 l_src_data+=sizeof(OPJ_FLOAT64); 1454 l_src_data+=sizeof(OPJ_FLOAT64);
1412 1455
1413 *(l_dest_data++) = (OPJ_INT32) l_temp; 1456 *(l_dest_data++) = (OPJ_INT32) l_temp;
1414 } 1457 }
1415 } 1458 }
1416 1459
1417 void opj_j2k_write_float_to_int16 (const void * p_src_data, void * p_dest_data, OPJ_UINT32 p_nb_elem) 1460 static void opj_j2k_write_float_to_int16 (const void * p_src_data, void * p_des t_data, OPJ_UINT32 p_nb_elem)
1418 { 1461 {
1419 OPJ_BYTE * l_dest_data = (OPJ_BYTE *) p_dest_data; 1462 OPJ_BYTE * l_dest_data = (OPJ_BYTE *) p_dest_data;
1420 OPJ_FLOAT32 * l_src_data = (OPJ_FLOAT32 *) p_src_data; 1463 OPJ_FLOAT32 * l_src_data = (OPJ_FLOAT32 *) p_src_data;
1421 OPJ_UINT32 i; 1464 OPJ_UINT32 i;
1422 OPJ_UINT32 l_temp; 1465 OPJ_UINT32 l_temp;
1423 1466
1424 for (i=0;i<p_nb_elem;++i) { 1467 for (i=0;i<p_nb_elem;++i) {
1425 l_temp = (OPJ_UINT32) *(l_src_data++); 1468 l_temp = (OPJ_UINT32) *(l_src_data++);
1426 1469
1427 opj_write_bytes(l_dest_data,l_temp,sizeof(OPJ_INT16)); 1470 opj_write_bytes(l_dest_data,l_temp,sizeof(OPJ_INT16));
1428 1471
1429 l_dest_data+=sizeof(OPJ_INT16); 1472 l_dest_data+=sizeof(OPJ_INT16);
1430 } 1473 }
1431 } 1474 }
1432 1475
1433 void opj_j2k_write_float_to_int32 (const void * p_src_data, void * p_dest_data, OPJ_UINT32 p_nb_elem) 1476 static void opj_j2k_write_float_to_int32 (const void * p_src_data, void * p_dest _data, OPJ_UINT32 p_nb_elem)
1434 { 1477 {
1435 OPJ_BYTE * l_dest_data = (OPJ_BYTE *) p_dest_data; 1478 OPJ_BYTE * l_dest_data = (OPJ_BYTE *) p_dest_data;
1436 OPJ_FLOAT32 * l_src_data = (OPJ_FLOAT32 *) p_src_data; 1479 OPJ_FLOAT32 * l_src_data = (OPJ_FLOAT32 *) p_src_data;
1437 OPJ_UINT32 i; 1480 OPJ_UINT32 i;
1438 OPJ_UINT32 l_temp; 1481 OPJ_UINT32 l_temp;
1439 1482
1440 for (i=0;i<p_nb_elem;++i) { 1483 for (i=0;i<p_nb_elem;++i) {
1441 l_temp = (OPJ_UINT32) *(l_src_data++); 1484 l_temp = (OPJ_UINT32) *(l_src_data++);
1442 1485
1443 opj_write_bytes(l_dest_data,l_temp,sizeof(OPJ_INT32)); 1486 opj_write_bytes(l_dest_data,l_temp,sizeof(OPJ_INT32));
1444 1487
1445 l_dest_data+=sizeof(OPJ_INT32); 1488 l_dest_data+=sizeof(OPJ_INT32);
1446 } 1489 }
1447 } 1490 }
1448 1491
1449 void opj_j2k_write_float_to_float (const void * p_src_data, void * p_dest_data, OPJ_UINT32 p_nb_elem) 1492 static void opj_j2k_write_float_to_float (const void * p_src_data, void * p_des t_data, OPJ_UINT32 p_nb_elem)
1450 { 1493 {
1451 OPJ_BYTE * l_dest_data = (OPJ_BYTE *) p_dest_data; 1494 OPJ_BYTE * l_dest_data = (OPJ_BYTE *) p_dest_data;
1452 OPJ_FLOAT32 * l_src_data = (OPJ_FLOAT32 *) p_src_data; 1495 OPJ_FLOAT32 * l_src_data = (OPJ_FLOAT32 *) p_src_data;
1453 OPJ_UINT32 i; 1496 OPJ_UINT32 i;
1454 OPJ_FLOAT32 l_temp; 1497 OPJ_FLOAT32 l_temp;
1455 1498
1456 for (i=0;i<p_nb_elem;++i) { 1499 for (i=0;i<p_nb_elem;++i) {
1457 l_temp = (OPJ_FLOAT32) *(l_src_data++); 1500 l_temp = (OPJ_FLOAT32) *(l_src_data++);
1458 1501
1459 opj_write_float(l_dest_data,l_temp); 1502 opj_write_float(l_dest_data,l_temp);
1460 1503
1461 l_dest_data+=sizeof(OPJ_FLOAT32); 1504 l_dest_data+=sizeof(OPJ_FLOAT32);
1462 } 1505 }
1463 } 1506 }
1464 1507
1465 void opj_j2k_write_float_to_float64 (const void * p_src_data, void * p_dest_dat a, OPJ_UINT32 p_nb_elem) 1508 static void opj_j2k_write_float_to_float64 (const void * p_src_data, void * p_d est_data, OPJ_UINT32 p_nb_elem)
1466 { 1509 {
1467 OPJ_BYTE * l_dest_data = (OPJ_BYTE *) p_dest_data; 1510 OPJ_BYTE * l_dest_data = (OPJ_BYTE *) p_dest_data;
1468 OPJ_FLOAT32 * l_src_data = (OPJ_FLOAT32 *) p_src_data; 1511 OPJ_FLOAT32 * l_src_data = (OPJ_FLOAT32 *) p_src_data;
1469 OPJ_UINT32 i; 1512 OPJ_UINT32 i;
1470 OPJ_FLOAT64 l_temp; 1513 OPJ_FLOAT64 l_temp;
1471 1514
1472 for (i=0;i<p_nb_elem;++i) { 1515 for (i=0;i<p_nb_elem;++i) {
1473 l_temp = (OPJ_FLOAT64) *(l_src_data++); 1516 l_temp = (OPJ_FLOAT64) *(l_src_data++);
1474 1517
1475 opj_write_double(l_dest_data,l_temp); 1518 opj_write_double(l_dest_data,l_temp);
1476 1519
1477 l_dest_data+=sizeof(OPJ_FLOAT64); 1520 l_dest_data+=sizeof(OPJ_FLOAT64);
1478 } 1521 }
1479 } 1522 }
1480 1523
1481 char *opj_j2k_convert_progression_order(OPJ_PROG_ORDER prg_order){ 1524 char *opj_j2k_convert_progression_order(OPJ_PROG_ORDER prg_order){
1482 j2k_prog_order_t *po; 1525 j2k_prog_order_t *po;
1483 for(po = j2k_prog_order_list; po->enum_prog != -1; po++ ){ 1526 for(po = j2k_prog_order_list; po->enum_prog != -1; po++ ){
1484 if(po->enum_prog == prg_order){ 1527 if(po->enum_prog == prg_order){
1485 return po->str_prog; 1528 return po->str_prog;
1486 } 1529 }
1487 } 1530 }
1488 return po->str_prog; 1531 return po->str_prog;
1489 } 1532 }
1490 1533
1491 OPJ_BOOL opj_j2k_check_poc_val( const opj_poc_t *p_pocs, 1534 static OPJ_BOOL opj_j2k_check_poc_val( const opj_poc_t *p_pocs,
1492 OPJ_UINT32 p_nb_pocs, 1535 OPJ_UINT32 p_nb_pocs,
1493 OPJ_UINT32 p_nb_resoluti ons, 1536 OPJ_UINT32 p_nb_resoluti ons,
1494 OPJ_UINT32 p_num_comps, 1537 OPJ_UINT32 p_num_comps,
1495 OPJ_UINT32 p_num_layers, 1538 OPJ_UINT32 p_num_layers,
1496 opj_event_mgr_t * p_mana ger) 1539 opj_event_mgr_t * p_mana ger)
1497 { 1540 {
1498 OPJ_UINT32* packet_array; 1541 OPJ_UINT32* packet_array;
1499 OPJ_UINT32 index , resno, compno, layno; 1542 OPJ_UINT32 index , resno, compno, layno;
1500 OPJ_UINT32 i; 1543 OPJ_UINT32 i;
1501 OPJ_UINT32 step_c = 1; 1544 OPJ_UINT32 step_c = 1;
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
1585 opj_event_msg(p_manager , EVT_ERROR, "Missing packets possible l oss of data\n"); 1628 opj_event_msg(p_manager , EVT_ERROR, "Missing packets possible l oss of data\n");
1586 } 1629 }
1587 1630
1588 opj_free(packet_array); 1631 opj_free(packet_array);
1589 1632
1590 return !loss; 1633 return !loss;
1591 } 1634 }
1592 1635
1593 /* ----------------------------------------------------------------------- */ 1636 /* ----------------------------------------------------------------------- */
1594 1637
1595 OPJ_UINT32 opj_j2k_get_num_tp(opj_cp_t *cp, OPJ_UINT32 pino, OPJ_UINT32 tileno) 1638 static OPJ_UINT32 opj_j2k_get_num_tp(opj_cp_t *cp, OPJ_UINT32 pino, OPJ_UINT32 t ileno)
1596 { 1639 {
1597 const OPJ_CHAR *prog = 00; 1640 const OPJ_CHAR *prog = 00;
1598 OPJ_INT32 i; 1641 OPJ_INT32 i;
1599 OPJ_UINT32 tpnum = 1; 1642 OPJ_UINT32 tpnum = 1;
1600 opj_tcp_t *tcp = 00; 1643 opj_tcp_t *tcp = 00;
1601 opj_poc_t * l_current_poc = 00; 1644 opj_poc_t * l_current_poc = 00;
1602 1645
1603 /* preconditions */ 1646 /* preconditions */
1604 assert(tileno < (cp->tw * cp->th)); 1647 assert(tileno < (cp->tw * cp->th));
1605 assert(pino < (cp->tcps[tileno].numpocs + 1)); 1648 assert(pino < (cp->tcps[tileno].numpocs + 1));
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1643 } 1686 }
1644 } 1687 }
1645 } 1688 }
1646 else { 1689 else {
1647 tpnum=1; 1690 tpnum=1;
1648 } 1691 }
1649 1692
1650 return tpnum; 1693 return tpnum;
1651 } 1694 }
1652 1695
1653 OPJ_BOOL opj_j2k_calculate_tp( opj_j2k_t *p_j2k, 1696 static OPJ_BOOL opj_j2k_calculate_tp( opj_j2k_t *p_j2k,
1654 opj_cp_t *cp, 1697 opj_cp_t *cp,
1655 OPJ_UINT32 * p_nb_tiles, 1698 OPJ_UINT32 * p_nb_tiles,
1656 opj_image_t *image, 1699 opj_image_t *image,
1657 opj_event_mgr_t * p_mana ger 1700 opj_event_mgr_t * p_mana ger
1658 ) 1701 )
1659 { 1702 {
1660 OPJ_UINT32 pino,tileno; 1703 OPJ_UINT32 pino,tileno;
1661 OPJ_UINT32 l_nb_tiles; 1704 OPJ_UINT32 l_nb_tiles;
1662 opj_tcp_t *tcp; 1705 opj_tcp_t *tcp;
1663 1706
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1721 } 1764 }
1722 tcp->m_nb_tile_parts = cur_totnum_tp; 1765 tcp->m_nb_tile_parts = cur_totnum_tp;
1723 1766
1724 ++tcp; 1767 ++tcp;
1725 } 1768 }
1726 } 1769 }
1727 1770
1728 return OPJ_TRUE; 1771 return OPJ_TRUE;
1729 } 1772 }
1730 1773
1731 OPJ_BOOL opj_j2k_write_soc( opj_j2k_t *p_j2k, 1774 static OPJ_BOOL opj_j2k_write_soc( opj_j2k_t *p_j2k,
1732 opj_stream_private_t *p_stream, 1775 opj_stream_private_t *p_stream,
1733 opj_event_mgr_t * p_manager ) 1776 opj_event_mgr_t * p_manager )
1734 { 1777 {
1735 /* 2 bytes will be written */ 1778 /* 2 bytes will be written */
1736 OPJ_BYTE * l_start_stream = 00; 1779 OPJ_BYTE * l_start_stream = 00;
1737 1780
1738 /* preconditions */ 1781 /* preconditions */
1739 assert(p_stream != 00); 1782 assert(p_stream != 00);
1740 assert(p_j2k != 00); 1783 assert(p_j2k != 00);
1741 assert(p_manager != 00); 1784 assert(p_manager != 00);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1799 opj_event_msg(p_manager, EVT_INFO, "Start to read j2k main header (%d).\ n", p_j2k->cstr_index->main_head_start); 1842 opj_event_msg(p_manager, EVT_INFO, "Start to read j2k main header (%d).\ n", p_j2k->cstr_index->main_head_start);
1800 1843
1801 /* Add the marker to the codestream index*/ 1844 /* Add the marker to the codestream index*/
1802 if (OPJ_FALSE == opj_j2k_add_mhmarker(p_j2k->cstr_index, J2K_MS_SOC, p_j 2k->cstr_index->main_head_start, 2)) { 1845 if (OPJ_FALSE == opj_j2k_add_mhmarker(p_j2k->cstr_index, J2K_MS_SOC, p_j 2k->cstr_index->main_head_start, 2)) {
1803 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to add mh marker\n"); 1846 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to add mh marker\n");
1804 return OPJ_FALSE; 1847 return OPJ_FALSE;
1805 } 1848 }
1806 return OPJ_TRUE; 1849 return OPJ_TRUE;
1807 } 1850 }
1808 1851
1809 OPJ_BOOL opj_j2k_write_siz( opj_j2k_t *p_j2k, 1852 static OPJ_BOOL opj_j2k_write_siz( opj_j2k_t *p_j2k,
1810 opj_stream_private_t *p_ stream, 1853 opj_stream_private_t *p_ stream,
1811 opj_event_mgr_t * p_mana ger ) 1854 opj_event_mgr_t * p_mana ger )
1812 { 1855 {
1813 OPJ_UINT32 i; 1856 OPJ_UINT32 i;
1814 OPJ_UINT32 l_size_len; 1857 OPJ_UINT32 l_size_len;
1815 OPJ_BYTE * l_current_ptr; 1858 OPJ_BYTE * l_current_ptr;
1816 opj_image_t * l_image = 00; 1859 opj_image_t * l_image = 00;
1817 opj_cp_t *cp = 00; 1860 opj_cp_t *cp = 00;
1818 opj_image_comp_t * l_img_comp = 00; 1861 opj_image_comp_t * l_img_comp = 00;
1819 1862
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
1992 return OPJ_FALSE; 2035 return OPJ_FALSE;
1993 } 2036 }
1994 2037
1995 /* testcase 1610.pdf.SIGSEGV.59c.681 */ 2038 /* testcase 1610.pdf.SIGSEGV.59c.681 */
1996 if (((OPJ_UINT64)l_image->x1) * ((OPJ_UINT64)l_image->y1) != (l_image->x 1 * l_image->y1)) { 2039 if (((OPJ_UINT64)l_image->x1) * ((OPJ_UINT64)l_image->y1) != (l_image->x 1 * l_image->y1)) {
1997 opj_event_msg(p_manager, EVT_ERROR, "Prevent buffer overflow (x1 : %d, y1: %d)\n", l_image->x1, l_image->y1); 2040 opj_event_msg(p_manager, EVT_ERROR, "Prevent buffer overflow (x1 : %d, y1: %d)\n", l_image->x1, l_image->y1);
1998 return OPJ_FALSE; 2041 return OPJ_FALSE;
1999 } 2042 }
2000 2043
2001 /* testcase issue427-illegal-tile-offset.jp2 */ 2044 /* testcase issue427-illegal-tile-offset.jp2 */
2002 l_tx1 = l_cp->tx0 + l_cp->tdx; 2045 l_tx1 = opj_uint_adds(l_cp->tx0, l_cp->tdx); /* manage overflow */
2003 if (l_tx1 < l_cp->tx0) { /* manage overflow */ 2046 l_ty1 = opj_uint_adds(l_cp->ty0, l_cp->tdy); /* manage overflow */
2004 l_tx1 = 0xFFFFFFFFU;
2005 }
2006 l_ty1 = l_cp->ty0 + l_cp->tdy;
2007 if (l_ty1 < l_cp->ty0) { /* manage overflow */
2008 l_ty1 = 0xFFFFFFFFU;
2009 }
2010 if ((l_cp->tx0 > l_image->x0) || (l_cp->ty0 > l_image->y0) || (l_tx1 <= l_image->x0) || (l_ty1 <= l_image->y0) ) { 2047 if ((l_cp->tx0 > l_image->x0) || (l_cp->ty0 > l_image->y0) || (l_tx1 <= l_image->x0) || (l_ty1 <= l_image->y0) ) {
2011 opj_event_msg(p_manager, EVT_ERROR, "Error with SIZ marker: ille gal tile offset\n"); 2048 opj_event_msg(p_manager, EVT_ERROR, "Error with SIZ marker: ille gal tile offset\n");
2012 return OPJ_FALSE; 2049 return OPJ_FALSE;
2013 } 2050 }
2014 2051
2015 #ifdef USE_JPWL 2052 #ifdef USE_JPWL
2016 if (l_cp->correct) { 2053 if (l_cp->correct) {
2017 /* if JPWL is on, we check whether TX errors have damaged 2054 /* if JPWL is on, we check whether TX errors have damaged
2018 too much the SIZ parameters */ 2055 too much the SIZ parameters */
2019 if (!(l_image->x1 * l_image->y1)) { 2056 if (!(l_image->x1 * l_image->y1)) {
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
2247 2284
2248 ++l_current_tile_param; 2285 ++l_current_tile_param;
2249 } 2286 }
2250 2287
2251 p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_MH; /* FIXME J2K_ DEC_STATE_MH; */ 2288 p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_MH; /* FIXME J2K_ DEC_STATE_MH; */
2252 opj_image_comp_header_update(l_image,l_cp); 2289 opj_image_comp_header_update(l_image,l_cp);
2253 2290
2254 return OPJ_TRUE; 2291 return OPJ_TRUE;
2255 } 2292 }
2256 2293
2257 OPJ_BOOL opj_j2k_write_com( opj_j2k_t *p_j2k, 2294 static OPJ_BOOL opj_j2k_write_com( opj_j2k_t *p_j2k,
2258 opj_stream_private_t *p_ stream, 2295 opj_stream_private_t *p_ stream,
2259 opj_event_mgr_t * p_mana ger 2296 opj_event_mgr_t * p_mana ger
2260 ) 2297 )
2261 { 2298 {
2262 OPJ_UINT32 l_comment_size; 2299 OPJ_UINT32 l_comment_size;
2263 OPJ_UINT32 l_total_com_size; 2300 OPJ_UINT32 l_total_com_size;
2264 const OPJ_CHAR *l_comment; 2301 const OPJ_CHAR *l_comment;
2265 OPJ_BYTE * l_current_ptr = 00; 2302 OPJ_BYTE * l_current_ptr = 00;
2266 2303
2267 /* preconditions */ 2304 /* preconditions */
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
2321 { 2358 {
2322 /* preconditions */ 2359 /* preconditions */
2323 assert(p_j2k != 00); 2360 assert(p_j2k != 00);
2324 assert(p_manager != 00); 2361 assert(p_manager != 00);
2325 assert(p_header_data != 00); 2362 assert(p_header_data != 00);
2326 (void)p_header_size; 2363 (void)p_header_size;
2327 2364
2328 return OPJ_TRUE; 2365 return OPJ_TRUE;
2329 } 2366 }
2330 2367
2331 OPJ_BOOL opj_j2k_write_cod( opj_j2k_t *p_j2k, 2368 static OPJ_BOOL opj_j2k_write_cod( opj_j2k_t *p_j2k,
2332 opj_stream_private_t *p_ stream, 2369 opj_stream_private_t *p_ stream,
2333 opj_event_mgr_t * p_mana ger ) 2370 opj_event_mgr_t * p_mana ger )
2334 { 2371 {
2335 opj_cp_t *l_cp = 00; 2372 opj_cp_t *l_cp = 00;
2336 opj_tcp_t *l_tcp = 00; 2373 opj_tcp_t *l_tcp = 00;
2337 OPJ_UINT32 l_code_size,l_remaining_size; 2374 OPJ_UINT32 l_code_size,l_remaining_size;
2338 OPJ_BYTE * l_current_data = 00; 2375 OPJ_BYTE * l_current_data = 00;
2339 2376
2340 /* preconditions */ 2377 /* preconditions */
2341 assert(p_j2k != 00); 2378 assert(p_j2k != 00);
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
2507 for (i = 0; i < l_image->numcomps; ++i) { 2544 for (i = 0; i < l_image->numcomps; ++i) {
2508 p_j2k->cstr_info->numdecompos[i] = l_tcp->tccps[i].numre solutions - 1; 2545 p_j2k->cstr_info->numdecompos[i] = l_tcp->tccps[i].numre solutions - 1;
2509 } 2546 }
2510 } 2547 }
2511 #endif 2548 #endif
2512 2549
2513 return OPJ_TRUE; 2550 return OPJ_TRUE;
2514 } 2551 }
2515 2552
2516 #if 0 2553 #if 0
2517 OPJ_BOOL opj_j2k_write_coc( opj_j2k_t *p_j2k, 2554 static OPJ_BOOL opj_j2k_write_coc( opj_j2k_t *p_j2k,
2518 OPJ_UINT32 p_comp_no, 2555 OPJ_UINT32 p_comp_no,
2519 opj_stream_private_t *p_stream, 2556 opj_stream_private_t *p_stream,
2520 opj_event_mgr_t * p_manager ) 2557 opj_event_mgr_t * p_manager )
2521 { 2558 {
2522 OPJ_UINT32 l_coc_size,l_remaining_size; 2559 OPJ_UINT32 l_coc_size,l_remaining_size;
2523 OPJ_UINT32 l_comp_room; 2560 OPJ_UINT32 l_comp_room;
2524 2561
2525 /* preconditions */ 2562 /* preconditions */
2526 assert(p_j2k != 00); 2563 assert(p_j2k != 00);
2527 assert(p_manager != 00); 2564 assert(p_manager != 00);
(...skipping 26 matching lines...) Expand all
2554 2591
2555 if (opj_stream_write_data(p_stream,p_j2k->m_specific_param.m_encoder.m_h eader_tile_data,l_coc_size,p_manager) != l_coc_size) { 2592 if (opj_stream_write_data(p_stream,p_j2k->m_specific_param.m_encoder.m_h eader_tile_data,l_coc_size,p_manager) != l_coc_size) {
2556 return OPJ_FALSE; 2593 return OPJ_FALSE;
2557 } 2594 }
2558 2595
2559 return OPJ_TRUE; 2596 return OPJ_TRUE;
2560 } 2597 }
2561 #endif 2598 #endif
2562 2599
2563 #if 0 2600 #if 0
2564 void opj_j2k_write_coc_in_memory( opj_j2k_t *p_j2k, 2601 static void opj_j2k_write_coc_in_memory( opj_j2k_t *p_j2k,
2565 OPJ_UINT32 p_comp_no, 2602 OPJ_UINT32 p_comp_no,
2566 OPJ_BYTE * p_data, 2603 OPJ_BYTE * p_data,
2567 OPJ_UINT32 * p_data_written, 2604 OPJ_UINT32 * p_data_written,
2568 opj_event_mgr_t * p_manager 2605 opj_event_mgr_t * p_manager
2569 ) 2606 )
2570 { 2607 {
2571 opj_cp_t *l_cp = 00; 2608 opj_cp_t *l_cp = 00;
2572 opj_tcp_t *l_tcp = 00; 2609 opj_tcp_t *l_tcp = 00;
2573 OPJ_UINT32 l_coc_size,l_remaining_size; 2610 OPJ_UINT32 l_coc_size,l_remaining_size;
2574 OPJ_BYTE * l_current_data = 00; 2611 OPJ_BYTE * l_current_data = 00;
(...skipping 25 matching lines...) Expand all
2600 2637
2601 opj_write_bytes(l_current_data, l_tcp->tccps[p_comp_no].csty, 1); /* Scoc */ 2638 opj_write_bytes(l_current_data, l_tcp->tccps[p_comp_no].csty, 1); /* Scoc */
2602 ++l_current_data; 2639 ++l_current_data;
2603 2640
2604 l_remaining_size -= (5 + l_comp_room); 2641 l_remaining_size -= (5 + l_comp_room);
2605 opj_j2k_write_SPCod_SPCoc(p_j2k,p_j2k->m_current_tile_number,0,l_current _data,&l_remaining_size,p_manager); 2642 opj_j2k_write_SPCod_SPCoc(p_j2k,p_j2k->m_current_tile_number,0,l_current _data,&l_remaining_size,p_manager);
2606 * p_data_written = l_coc_size; 2643 * p_data_written = l_coc_size;
2607 } 2644 }
2608 #endif 2645 #endif
2609 2646
2610 OPJ_UINT32 opj_j2k_get_max_coc_size(opj_j2k_t *p_j2k) 2647 static OPJ_UINT32 opj_j2k_get_max_coc_size(opj_j2k_t *p_j2k)
2611 { 2648 {
2612 OPJ_UINT32 i,j; 2649 OPJ_UINT32 i,j;
2613 OPJ_UINT32 l_nb_comp; 2650 OPJ_UINT32 l_nb_comp;
2614 OPJ_UINT32 l_nb_tiles; 2651 OPJ_UINT32 l_nb_tiles;
2615 OPJ_UINT32 l_max = 0; 2652 OPJ_UINT32 l_max = 0;
2616 2653
2617 /* preconditions */ 2654 /* preconditions */
2618 2655
2619 l_nb_tiles = p_j2k->m_cp.tw * p_j2k->m_cp.th ; 2656 l_nb_tiles = p_j2k->m_cp.tw * p_j2k->m_cp.th ;
2620 l_nb_comp = p_j2k->m_private_image->numcomps; 2657 l_nb_comp = p_j2k->m_private_image->numcomps;
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
2682 return OPJ_FALSE; 2719 return OPJ_FALSE;
2683 } 2720 }
2684 2721
2685 if (p_header_size != 0) { 2722 if (p_header_size != 0) {
2686 opj_event_msg(p_manager, EVT_ERROR, "Error reading COC marker\n" ); 2723 opj_event_msg(p_manager, EVT_ERROR, "Error reading COC marker\n" );
2687 return OPJ_FALSE; 2724 return OPJ_FALSE;
2688 } 2725 }
2689 return OPJ_TRUE; 2726 return OPJ_TRUE;
2690 } 2727 }
2691 2728
2692 OPJ_BOOL opj_j2k_write_qcd( opj_j2k_t *p_j2k, 2729 static OPJ_BOOL opj_j2k_write_qcd( opj_j2k_t *p_j2k,
2693 opj_stream_private_t *p_ stream, 2730 opj_stream_private_t *p_ stream,
2694 opj_event_mgr_t * p_mana ger 2731 opj_event_mgr_t * p_mana ger
2695 ) 2732 )
2696 { 2733 {
2697 OPJ_UINT32 l_qcd_size,l_remaining_size; 2734 OPJ_UINT32 l_qcd_size,l_remaining_size;
2698 OPJ_BYTE * l_current_data = 00; 2735 OPJ_BYTE * l_current_data = 00;
2699 2736
2700 /* preconditions */ 2737 /* preconditions */
2701 assert(p_j2k != 00); 2738 assert(p_j2k != 00);
2702 assert(p_manager != 00); 2739 assert(p_manager != 00);
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
2773 return OPJ_FALSE; 2810 return OPJ_FALSE;
2774 } 2811 }
2775 2812
2776 /* Apply the quantization parameters to other components of the current tile or the m_default_tcp */ 2813 /* Apply the quantization parameters to other components of the current tile or the m_default_tcp */
2777 opj_j2k_copy_tile_quantization_parameters(p_j2k); 2814 opj_j2k_copy_tile_quantization_parameters(p_j2k);
2778 2815
2779 return OPJ_TRUE; 2816 return OPJ_TRUE;
2780 } 2817 }
2781 2818
2782 #if 0 2819 #if 0
2783 OPJ_BOOL opj_j2k_write_qcc( opj_j2k_t *p_j2k, 2820 static OPJ_BOOL opj_j2k_write_qcc( opj_j2k_t *p_j2k,
2784 OPJ_UINT32 p_comp_no, 2821 OPJ_UINT32 p_comp_no,
2785 opj_stream_private_t *p_stream, 2822 opj_stream_private_t *p_stream,
2786 opj_event_mgr_t * p_manager 2823 opj_event_mgr_t * p_manager
2787 ) 2824 )
2788 { 2825 {
2789 OPJ_UINT32 l_qcc_size,l_remaining_size; 2826 OPJ_UINT32 l_qcc_size,l_remaining_size;
2790 2827
2791 /* preconditions */ 2828 /* preconditions */
2792 assert(p_j2k != 00); 2829 assert(p_j2k != 00);
2793 assert(p_manager != 00); 2830 assert(p_manager != 00);
(...skipping 20 matching lines...) Expand all
2814 2851
2815 if (opj_stream_write_data(p_stream,p_j2k->m_specific_param.m_encoder.m_h eader_tile_data,l_qcc_size,p_manager) != l_qcc_size) { 2852 if (opj_stream_write_data(p_stream,p_j2k->m_specific_param.m_encoder.m_h eader_tile_data,l_qcc_size,p_manager) != l_qcc_size) {
2816 return OPJ_FALSE; 2853 return OPJ_FALSE;
2817 } 2854 }
2818 2855
2819 return OPJ_TRUE; 2856 return OPJ_TRUE;
2820 } 2857 }
2821 #endif 2858 #endif
2822 2859
2823 #if 0 2860 #if 0
2824 void opj_j2k_write_qcc_in_memory( opj_j2k_t *p_j2k, 2861 static void opj_j2k_write_qcc_in_memory( opj_j2k_t *p_j2k,
2825 OPJ_UINT32 p_com p_no, 2862 OPJ_UINT32 p_com p_no,
2826 OPJ_BYTE * p_dat a, 2863 OPJ_BYTE * p_dat a,
2827 OPJ_UINT32 * p_d ata_written, 2864 OPJ_UINT32 * p_d ata_written,
2828 opj_event_mgr_t * p_manager 2865 opj_event_mgr_t * p_manager
2829 ) 2866 )
2830 { 2867 {
2831 OPJ_UINT32 l_qcc_size,l_remaining_size; 2868 OPJ_UINT32 l_qcc_size,l_remaining_size;
2832 OPJ_BYTE * l_current_data = 00; 2869 OPJ_BYTE * l_current_data = 00;
2833 2870
2834 /* preconditions */ 2871 /* preconditions */
(...skipping 29 matching lines...) Expand all
2864 2901
2865 l_remaining_size -= 6; 2902 l_remaining_size -= 6;
2866 } 2903 }
2867 2904
2868 opj_j2k_write_SQcd_SQcc(p_j2k,p_j2k->m_current_tile_number,p_comp_no,l_c urrent_data,&l_remaining_size,p_manager); 2905 opj_j2k_write_SQcd_SQcc(p_j2k,p_j2k->m_current_tile_number,p_comp_no,l_c urrent_data,&l_remaining_size,p_manager);
2869 2906
2870 *p_data_written = l_qcc_size; 2907 *p_data_written = l_qcc_size;
2871 } 2908 }
2872 #endif 2909 #endif
2873 2910
2874 OPJ_UINT32 opj_j2k_get_max_qcc_size (opj_j2k_t *p_j2k) 2911 static OPJ_UINT32 opj_j2k_get_max_qcc_size (opj_j2k_t *p_j2k)
2875 { 2912 {
2876 return opj_j2k_get_max_coc_size(p_j2k); 2913 return opj_j2k_get_max_coc_size(p_j2k);
2877 } 2914 }
2878 2915
2879 /** 2916 /**
2880 * Reads a QCC marker (Quantization component) 2917 * Reads a QCC marker (Quantization component)
2881 * @param p_header_data the data contained in the QCC box. 2918 * @param p_header_data the data contained in the QCC box.
2882 * @param p_j2k the jpeg2000 codec. 2919 * @param p_j2k the jpeg2000 codec.
2883 * @param p_header_size the size of the data contained in the QCC marker . 2920 * @param p_header_size the size of the data contained in the QCC marker .
2884 * @param p_manager the user event manager. 2921 * @param p_manager the user event manager.
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
2956 } 2993 }
2957 2994
2958 if (p_header_size != 0) { 2995 if (p_header_size != 0) {
2959 opj_event_msg(p_manager, EVT_ERROR, "Error reading QCC marker\n" ); 2996 opj_event_msg(p_manager, EVT_ERROR, "Error reading QCC marker\n" );
2960 return OPJ_FALSE; 2997 return OPJ_FALSE;
2961 } 2998 }
2962 2999
2963 return OPJ_TRUE; 3000 return OPJ_TRUE;
2964 } 3001 }
2965 3002
2966 OPJ_BOOL opj_j2k_write_poc( opj_j2k_t *p_j2k, 3003 static OPJ_BOOL opj_j2k_write_poc( opj_j2k_t *p_j2k,
2967 opj_stream_private_t *p_ stream, 3004 opj_stream_private_t *p_ stream,
2968 opj_event_mgr_t * p_mana ger 3005 opj_event_mgr_t * p_mana ger
2969 ) 3006 )
2970 { 3007 {
2971 OPJ_UINT32 l_nb_comp; 3008 OPJ_UINT32 l_nb_comp;
2972 OPJ_UINT32 l_nb_poc; 3009 OPJ_UINT32 l_nb_poc;
2973 OPJ_UINT32 l_poc_size; 3010 OPJ_UINT32 l_poc_size;
2974 OPJ_UINT32 l_written_size = 0; 3011 OPJ_UINT32 l_written_size = 0;
2975 opj_tcp_t *l_tcp = 00; 3012 opj_tcp_t *l_tcp = 00;
2976 OPJ_UINT32 l_poc_room; 3013 OPJ_UINT32 l_poc_room;
(...skipping 30 matching lines...) Expand all
3007 3044
3008 opj_j2k_write_poc_in_memory(p_j2k,p_j2k->m_specific_param.m_encoder.m_he ader_tile_data,&l_written_size,p_manager); 3045 opj_j2k_write_poc_in_memory(p_j2k,p_j2k->m_specific_param.m_encoder.m_he ader_tile_data,&l_written_size,p_manager);
3009 3046
3010 if (opj_stream_write_data(p_stream,p_j2k->m_specific_param.m_encoder.m_h eader_tile_data,l_poc_size,p_manager) != l_poc_size) { 3047 if (opj_stream_write_data(p_stream,p_j2k->m_specific_param.m_encoder.m_h eader_tile_data,l_poc_size,p_manager) != l_poc_size) {
3011 return OPJ_FALSE; 3048 return OPJ_FALSE;
3012 } 3049 }
3013 3050
3014 return OPJ_TRUE; 3051 return OPJ_TRUE;
3015 } 3052 }
3016 3053
3017 void opj_j2k_write_poc_in_memory( opj_j2k_t *p_j2k, 3054 static void opj_j2k_write_poc_in_memory( opj_j2k_t *p_j2k,
3018 OPJ_BYTE * p_dat a, 3055 OPJ_BYTE * p_dat a,
3019 OPJ_UINT32 * p_d ata_written, 3056 OPJ_UINT32 * p_d ata_written,
3020 opj_event_mgr_t * p_manager 3057 opj_event_mgr_t * p_manager
3021 ) 3058 )
3022 { 3059 {
3023 OPJ_UINT32 i; 3060 OPJ_UINT32 i;
3024 OPJ_BYTE * l_current_data = 00; 3061 OPJ_BYTE * l_current_data = 00;
3025 OPJ_UINT32 l_nb_comp; 3062 OPJ_UINT32 l_nb_comp;
3026 OPJ_UINT32 l_nb_poc; 3063 OPJ_UINT32 l_nb_poc;
3027 OPJ_UINT32 l_poc_size; 3064 OPJ_UINT32 l_poc_size;
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
3082 l_current_poc->layno1 = (OPJ_UINT32)opj_int_min((OPJ_INT32)l_cur rent_poc->layno1, (OPJ_INT32)l_tcp->numlayers); 3119 l_current_poc->layno1 = (OPJ_UINT32)opj_int_min((OPJ_INT32)l_cur rent_poc->layno1, (OPJ_INT32)l_tcp->numlayers);
3083 l_current_poc->resno1 = (OPJ_UINT32)opj_int_min((OPJ_INT32)l_cur rent_poc->resno1, (OPJ_INT32)l_tccp->numresolutions); 3120 l_current_poc->resno1 = (OPJ_UINT32)opj_int_min((OPJ_INT32)l_cur rent_poc->resno1, (OPJ_INT32)l_tccp->numresolutions);
3084 l_current_poc->compno1 = (OPJ_UINT32)opj_int_min((OPJ_INT32)l_cu rrent_poc->compno1, (OPJ_INT32)l_nb_comp); 3121 l_current_poc->compno1 = (OPJ_UINT32)opj_int_min((OPJ_INT32)l_cu rrent_poc->compno1, (OPJ_INT32)l_nb_comp);
3085 3122
3086 ++l_current_poc; 3123 ++l_current_poc;
3087 } 3124 }
3088 3125
3089 *p_data_written = l_poc_size; 3126 *p_data_written = l_poc_size;
3090 } 3127 }
3091 3128
3092 OPJ_UINT32 opj_j2k_get_max_poc_size(opj_j2k_t *p_j2k) 3129 static OPJ_UINT32 opj_j2k_get_max_poc_size(opj_j2k_t *p_j2k)
3093 { 3130 {
3094 opj_tcp_t * l_tcp = 00; 3131 opj_tcp_t * l_tcp = 00;
3095 OPJ_UINT32 l_nb_tiles = 0; 3132 OPJ_UINT32 l_nb_tiles = 0;
3096 OPJ_UINT32 l_max_poc = 0; 3133 OPJ_UINT32 l_max_poc = 0;
3097 OPJ_UINT32 i; 3134 OPJ_UINT32 i;
3098 3135
3099 l_tcp = p_j2k->m_cp.tcps; 3136 l_tcp = p_j2k->m_cp.tcps;
3100 l_nb_tiles = p_j2k->m_cp.th * p_j2k->m_cp.tw; 3137 l_nb_tiles = p_j2k->m_cp.th * p_j2k->m_cp.tw;
3101 3138
3102 for (i=0;i<l_nb_tiles;++i) { 3139 for (i=0;i<l_nb_tiles;++i) {
3103 l_max_poc = opj_uint_max(l_max_poc,l_tcp->numpocs); 3140 l_max_poc = opj_uint_max(l_max_poc,l_tcp->numpocs);
3104 ++l_tcp; 3141 ++l_tcp;
3105 } 3142 }
3106 3143
3107 ++l_max_poc; 3144 ++l_max_poc;
3108 3145
3109 return 4 + 9 * l_max_poc; 3146 return 4 + 9 * l_max_poc;
3110 } 3147 }
3111 3148
3112 OPJ_UINT32 opj_j2k_get_max_toc_size (opj_j2k_t *p_j2k) 3149 static OPJ_UINT32 opj_j2k_get_max_toc_size (opj_j2k_t *p_j2k)
3113 { 3150 {
3114 OPJ_UINT32 i; 3151 OPJ_UINT32 i;
3115 OPJ_UINT32 l_nb_tiles; 3152 OPJ_UINT32 l_nb_tiles;
3116 OPJ_UINT32 l_max = 0; 3153 OPJ_UINT32 l_max = 0;
3117 opj_tcp_t * l_tcp = 00; 3154 opj_tcp_t * l_tcp = 00;
3118 3155
3119 l_tcp = p_j2k->m_cp.tcps; 3156 l_tcp = p_j2k->m_cp.tcps;
3120 l_nb_tiles = p_j2k->m_cp.tw * p_j2k->m_cp.th ; 3157 l_nb_tiles = p_j2k->m_cp.tw * p_j2k->m_cp.th ;
3121 3158
3122 for (i=0;i<l_nb_tiles;++i) { 3159 for (i=0;i<l_nb_tiles;++i) {
3123 l_max = opj_uint_max(l_max,l_tcp->m_nb_tile_parts); 3160 l_max = opj_uint_max(l_max,l_tcp->m_nb_tile_parts);
3124 3161
3125 ++l_tcp; 3162 ++l_tcp;
3126 } 3163 }
3127 3164
3128 return 12 * l_max; 3165 return 12 * l_max;
3129 } 3166 }
3130 3167
3131 OPJ_UINT32 opj_j2k_get_specific_header_sizes(opj_j2k_t *p_j2k) 3168 static OPJ_UINT32 opj_j2k_get_specific_header_sizes(opj_j2k_t *p_j2k)
3132 { 3169 {
3133 OPJ_UINT32 l_nb_bytes = 0; 3170 OPJ_UINT32 l_nb_bytes = 0;
3134 OPJ_UINT32 l_nb_comps; 3171 OPJ_UINT32 l_nb_comps;
3135 OPJ_UINT32 l_coc_bytes,l_qcc_bytes; 3172 OPJ_UINT32 l_coc_bytes,l_qcc_bytes;
3136 3173
3137 l_nb_comps = p_j2k->m_private_image->numcomps - 1; 3174 l_nb_comps = p_j2k->m_private_image->numcomps - 1;
3138 l_nb_bytes += opj_j2k_get_max_toc_size(p_j2k); 3175 l_nb_bytes += opj_j2k_get_max_toc_size(p_j2k);
3139 3176
3140 if (!(OPJ_IS_CINEMA(p_j2k->m_cp.rsiz))) { 3177 if (!(OPJ_IS_CINEMA(p_j2k->m_cp.rsiz))) {
3141 l_coc_bytes = opj_j2k_get_max_coc_size(p_j2k); 3178 l_coc_bytes = opj_j2k_get_max_coc_size(p_j2k);
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
3451 } 3488 }
3452 3489
3453 if (l_packet_len != 0) { 3490 if (l_packet_len != 0) {
3454 opj_event_msg(p_manager, EVT_ERROR, "Error reading PLT marker\n" ); 3491 opj_event_msg(p_manager, EVT_ERROR, "Error reading PLT marker\n" );
3455 return OPJ_FALSE; 3492 return OPJ_FALSE;
3456 } 3493 }
3457 3494
3458 return OPJ_TRUE; 3495 return OPJ_TRUE;
3459 } 3496 }
3460 3497
3461 #if 0 3498 /**
3462 OPJ_BOOL j2k_read_ppm_v2 ( 3499 * Reads a PPM marker (Packed packet headers, main header)
3463 opj_j2k_t *p_j2k, 3500 *
3464 OPJ_BYTE * p_header_data, 3501 * @param p_header_data the data contained in the POC box.
3465 OPJ_UINT32 p_header_size, 3502 * @param p_j2k the jpeg2000 codec.
3466 struct opj_event_mgr * p_manager 3503 * @param p_header_size the size of the data contained in the POC marker .
3467 ) 3504 * @param p_manager the user event manager.
3505 */
3506
3507 static OPJ_BOOL opj_j2k_read_ppm (
3508 » » » » » » » » » » » » » » » » » opj_j2k_t *p_j2k,
3509 » » » » » » » » » » » » » » » » » OPJ_BYTE * p_header_data ,
3510 » » » » » » » » » » » » » » » » » OPJ_UINT32 p_header_size ,
3511 » » » » » » » » » » » » » » » » » opj_event_mgr_t * p_mana ger )
3468 { 3512 {
3469 3513 » opj_cp_t *l_cp = 00;
3470 opj_cp_t *l_cp = 00; 3514 » OPJ_UINT32 l_Z_ppm;
3471 OPJ_UINT32 l_remaining_data, l_Z_ppm, l_N_ppm; 3515 »
3472 3516 » /* preconditions */
3473 /* preconditions */ 3517 » assert(p_header_data != 00);
3474 assert(p_header_data != 00); 3518 » assert(p_j2k != 00);
3475 assert(p_j2k != 00); 3519 » assert(p_manager != 00);
3476 assert(p_manager != 00); 3520 »
3477 3521 » /* We need to have the Z_ppm element + 1 byte of Nppm/Ippm at minimum */
3478 if (p_header_size < 1) { 3522 » if (p_header_size < 2) {
3479 opj_event_msg(p_manager, EVT_ERROR, "Error reading PPM marker\n" ); 3523 » » opj_event_msg(p_manager, EVT_ERROR, "Error reading PPM marker\n" );
3480 return OPJ_FALSE; 3524 » » return OPJ_FALSE;
3481 } 3525 » }
3482 3526 »
3483 l_cp = &(p_j2k->m_cp); 3527 » l_cp = &(p_j2k->m_cp);
3484 l_cp->ppm = 1; 3528 » l_cp->ppm = 1;
3485 3529 »
3486 opj_read_bytes(p_header_data,&l_Z_ppm,1); /* Z_ppm */ 3530 » opj_read_bytes(p_header_data,&l_Z_ppm,1); /* Z_ppm */
3487 ++p_header_data; 3531 » ++p_header_data;
3488 --p_header_size; 3532 » --p_header_size;
3489 3533 »
3490 /* First PPM marker */ 3534 » /* check allocation needed */
3491 if (l_Z_ppm == 0) { 3535 » if (l_cp->ppm_markers == NULL) { /* first PPM marker */
3492 if (p_header_size < 4) { 3536 » » OPJ_UINT32 l_newCount = l_Z_ppm + 1U; /* can't overflow, l_Z_ppm is UINT8 */
3493 opj_event_msg(p_manager, EVT_ERROR, "Error reading PPM m arker\n"); 3537 » » assert(l_cp->ppm_markers_count == 0U);
3494 return OPJ_FALSE; 3538 » »
3495 } 3539 » » l_cp->ppm_markers = (opj_ppx *) opj_calloc(l_newCount, sizeof(op j_ppx));
3496 3540 » » if (l_cp->ppm_markers == NULL) {
3497 opj_read_bytes(p_header_data,&l_N_ppm,4); /* N_ppm */ 3541 » » » opj_event_msg(p_manager, EVT_ERROR, "Not enough memory t o read PPM marker\n");
3498 p_header_data+=4; 3542 » » » return OPJ_FALSE;
3499 p_header_size-=4; 3543 » » }
3500 3544 » » l_cp->ppm_markers_count = l_newCount;
3501 /* First PPM marker: Initialization */ 3545 » } else if (l_cp->ppm_markers_count <= l_Z_ppm) {
3502 l_cp->ppm_len = l_N_ppm; 3546 » » OPJ_UINT32 l_newCount = l_Z_ppm + 1U; /* can't overflow, l_Z_ppm is UINT8 */
3503 l_cp->ppm_data_size = 0; 3547 » » opj_ppx *new_ppm_markers;
3504 3548 » » new_ppm_markers = (opj_ppx *) opj_realloc(l_cp->ppm_markers, l_n ewCount * sizeof(opj_ppx));
3505 l_cp->ppm_buffer = (OPJ_BYTE *) opj_malloc(l_cp->ppm_len); 3549 » » if (new_ppm_markers == NULL) {
3506 if (l_cp->ppm_buffer == 00) { 3550 » » » /* clean up to be done on l_cp destruction */
3507 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory r eading ppm marker\n"); 3551 » » » opj_event_msg(p_manager, EVT_ERROR, "Not enough memory t o read PPM marker\n");
3508 return OPJ_FALSE; 3552 » » » return OPJ_FALSE;
3509 } 3553 » » }
3510 memset(l_cp->ppm_buffer,0,l_cp->ppm_len); 3554 » » l_cp->ppm_markers = new_ppm_markers;
3511 3555 » » memset(l_cp->ppm_markers + l_cp->ppm_markers_count, 0, (l_newCou nt - l_cp->ppm_markers_count) * sizeof(opj_ppx));
3512 l_cp->ppm_data = l_cp->ppm_buffer; 3556 » » l_cp->ppm_markers_count = l_newCount;
3513 } 3557 » }
3514 3558 »
3515 while (1) { 3559 » if (l_cp->ppm_markers[l_Z_ppm].m_data != NULL) {
3516 if (l_cp->ppm_data_size == l_cp->ppm_len) { 3560 » » /* clean up to be done on l_cp destruction */
3517 if (p_header_size >= 4) { 3561 » » opj_event_msg(p_manager, EVT_ERROR, "Zppm %u already read\n", l_ Z_ppm);
3518 /* read a N_ppm */ 3562 » » return OPJ_FALSE;
3519 opj_read_bytes(p_header_data,&l_N_ppm,4); /* N_ppm */ 3563 » }
3520 p_header_data+=4; 3564 »
3521 p_header_size-=4; 3565 » l_cp->ppm_markers[l_Z_ppm].m_data = opj_malloc(p_header_size);
3522 l_cp->ppm_len += l_N_ppm ; 3566 » if (l_cp->ppm_markers[l_Z_ppm].m_data == NULL) {
3523 3567 » » /* clean up to be done on l_cp destruction */
3524 OPJ_BYTE *new_ppm_buffer = (OPJ_BYTE *) opj_real loc(l_cp->ppm_buffer, l_cp->ppm_len); 3568 » » opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read P PM marker\n");
3525 if (! new_ppm_buffer) { 3569 » » return OPJ_FALSE;
3526 opj_free(l_cp->ppm_buffer); 3570 » }
3527 l_cp->ppm_buffer = NULL; 3571 » l_cp->ppm_markers[l_Z_ppm].m_data_size = p_header_size;
3528 l_cp->ppm_len = 0; 3572 » memcpy(l_cp->ppm_markers[l_Z_ppm].m_data, p_header_data, p_header_size);
3529 l_cp->ppm_data = NULL; 3573
3530 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory reading ppm marker\n"); 3574 » return OPJ_TRUE;
3531 return OPJ_FALSE;
3532 }
3533 l_cp->ppm_buffer = new_ppm_buffer;
3534 memset(l_cp->ppm_buffer+l_cp->ppm_data_size,0,l_ N_ppm);
3535 l_cp->ppm_data = l_cp->ppm_buffer;
3536 }
3537 else {
3538 return OPJ_FALSE;
3539 }
3540 }
3541
3542 l_remaining_data = l_cp->ppm_len - l_cp->ppm_data_size;
3543
3544 if (l_remaining_data <= p_header_size) {
3545 /* we must store less information than available in the packet */
3546 memcpy(l_cp->ppm_buffer + l_cp->ppm_data_size , p_header _data , l_remaining_data);
3547 l_cp->ppm_data_size = l_cp->ppm_len;
3548 p_header_size -= l_remaining_data;
3549 p_header_data += l_remaining_data;
3550 }
3551 else {
3552 memcpy(l_cp->ppm_buffer + l_cp->ppm_data_size , p_header _data , p_header_size);
3553 l_cp->ppm_data_size += p_header_size;
3554 p_header_data += p_header_size;
3555 p_header_size = 0;
3556 break;
3557 }
3558 }
3559
3560 return OPJ_TRUE;
3561 } 3575 }
3562 #endif 3576
3563 3577 /**
3564 OPJ_BOOL j2k_read_ppm_v3 ( 3578 * Merges all PPM markers read (Packed headers, main header)
3565 opj_j2k_t *p_j2k, 3579 *
3566 OPJ_BYTE * p_header_data, 3580 * @param p_cp main coding parameters.
3567 OPJ_UINT32 p_header_size, 3581 * @param p_manager the user event manager.
3568 struct opj_event_mgr * p_manager 3582 */
3569 ) 3583 static OPJ_BOOL opj_j2k_merge_ppm ( opj_cp_t *p_cp, opj_event_mgr_t * p_manager )
3570 { 3584 {
3571 opj_cp_t *l_cp = 00; 3585 OPJ_UINT32 i, l_ppm_data_size, l_N_ppm_remaining;
3572 OPJ_UINT32 l_remaining_data, l_Z_ppm, l_N_ppm; 3586
3573 3587 /* preconditions */
3574 /* preconditions */ 3588 assert(p_cp != 00);
3575 assert(p_header_data != 00); 3589 assert(p_manager != 00);
3576 assert(p_j2k != 00); 3590 assert(p_cp->ppm_buffer == NULL);
3577 assert(p_manager != 00); 3591
3578 3592 if (p_cp->ppm == 0U) {
3579 /* Minimum size of PPM marker is equal to the size of Zppm element */ 3593 return OPJ_TRUE;
3580 if (p_header_size < 1) { 3594 }
3581 opj_event_msg(p_manager, EVT_ERROR, "Error reading PPM marker\n" ); 3595
3582 return OPJ_FALSE; 3596 l_ppm_data_size = 0U;
3583 } 3597 l_N_ppm_remaining = 0U;
3584 3598 for (i = 0U; i < p_cp->ppm_markers_count; ++i) {
3585 l_cp = &(p_j2k->m_cp); 3599 if (p_cp->ppm_markers[i].m_data != NULL) { /* standard doesn't s eem to require contiguous Zppm */
3586 l_cp->ppm = 1; 3600 OPJ_UINT32 l_N_ppm;
3587 3601 OPJ_UINT32 l_data_size = p_cp->ppm_markers[i].m_data_siz e;
3588 opj_read_bytes(p_header_data,&l_Z_ppm,1); /* Z_ppm */ 3602 const OPJ_BYTE* l_data = p_cp->ppm_markers[i].m_data;
3589 ++p_header_data; 3603
3590 --p_header_size; 3604 if (l_N_ppm_remaining >= l_data_size) {
3591 3605 l_N_ppm_remaining -= l_data_size;
3592 /* First PPM marker */ 3606 l_data_size = 0U;
3593 if (l_Z_ppm == 0) { 3607 } else {
3594 if (l_cp->ppm_data != NULL) { 3608 l_data += l_N_ppm_remaining;
3595 opj_event_msg(p_manager, EVT_ERROR, "Zppm O already proc essed. Found twice.\n"); 3609 l_data_size -= l_N_ppm_remaining;
3596 opj_free(l_cp->ppm_data); 3610 l_N_ppm_remaining = 0U;
3597 l_cp->ppm_data = NULL; 3611 }
3598 l_cp->ppm_buffer = NULL; 3612
3599 l_cp->ppm = 0; /* do not use PPM */ 3613 if (l_data_size > 0U) {
3600 return OPJ_FALSE; 3614 do
3601 } 3615 {
3602 /* We need now at least the Nppm^0 element */ 3616 /* read Nppm */
3603 if (p_header_size < 4) { 3617 if (l_data_size < 4U) {
3604 opj_event_msg(p_manager, EVT_ERROR, "Error reading PPM m arker\n"); 3618 /* clean up to be done on l_cp d estruction */
3605 return OPJ_FALSE; 3619 opj_event_msg(p_manager, EVT_ERR OR, "Not enough bytes to read Nppm\n");
3606 } 3620 return OPJ_FALSE;
3607 3621 }
3608 opj_read_bytes(p_header_data,&l_N_ppm,4); /* First N_ppm */ 3622 opj_read_bytes(l_data, &l_N_ppm, 4);
3609 p_header_data+=4; 3623 l_data+=4;
3610 p_header_size-=4; 3624 l_data_size-=4;
3611 3625 l_ppm_data_size += l_N_ppm; /* can't ove rflow, max 256 markers of max 65536 bytes, that is when PPM markers are not corr upted which is checked elsewhere */
3612 /* sanity check: how much bytes is left for Ippm */ 3626
3613 if( p_header_size < l_N_ppm ) 3627 if (l_data_size >= l_N_ppm) {
3614 { 3628 l_data_size -= l_N_ppm;
3615 opj_event_msg(p_manager, EVT_ERROR, "Not enough bytes (%u) to hold Ippm series (%u), Index (%d)\n", p_header_size, l_N_ppm, l_Z_ppm ); 3629 l_data += l_N_ppm;
3616 opj_free(l_cp->ppm_data); 3630 } else {
3617 l_cp->ppm_data = NULL; 3631 l_N_ppm_remaining = l_N_ppm - l_ data_size;
3618 l_cp->ppm_buffer = NULL; 3632 l_data_size = 0U;
3619 l_cp->ppm = 0; /* do not use PPM */ 3633 }
3620 return OPJ_FALSE; 3634 } while (l_data_size > 0U);
3621 } 3635 }
3622 3636 }
3623 /* First PPM marker: Initialization */ 3637 }
3624 l_cp->ppm_len = l_N_ppm; 3638
3625 l_cp->ppm_data_read = 0; 3639 if (l_N_ppm_remaining != 0U) {
3626 3640 /* clean up to be done on l_cp destruction */
3627 l_cp->ppm_data = (OPJ_BYTE *) opj_calloc(1,l_cp->ppm_len); 3641 opj_event_msg(p_manager, EVT_ERROR, "Corrupted PPM markers\n");
3628 l_cp->ppm_buffer = l_cp->ppm_data; 3642 return OPJ_FALSE;
3629 if (l_cp->ppm_data == 00) { 3643 }
3630 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory t o read ppm marker\n"); 3644
3631 return OPJ_FALSE; 3645 p_cp->ppm_buffer = (OPJ_BYTE *) opj_malloc(l_ppm_data_size);
3632 } 3646 if (p_cp->ppm_buffer == 00) {
3633 3647 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read P PM marker\n");
3634 l_cp->ppm_data_current = l_cp->ppm_data; 3648 return OPJ_FALSE;
3635 3649 }
3636 /*l_cp->ppm_data = l_cp->ppm_buffer;*/ 3650 p_cp->ppm_len = l_ppm_data_size;
3637 } 3651 l_ppm_data_size = 0U;
3638 else { 3652 l_N_ppm_remaining = 0U;
3639 if (p_header_size < 4) { 3653 for (i = 0U; i < p_cp->ppm_markers_count; ++i) {
3640 opj_event_msg(p_manager, EVT_WARNING, "Empty PPM marker\ n"); 3654 if (p_cp->ppm_markers[i].m_data != NULL) { /* standard doesn't s eem to require contiguous Zppm */
3641 return OPJ_TRUE; 3655 OPJ_UINT32 l_N_ppm;
3642 } 3656 OPJ_UINT32 l_data_size = p_cp->ppm_markers[i].m_data_siz e;
3643 else { 3657 const OPJ_BYTE* l_data = p_cp->ppm_markers[i].m_data;
3644 /* Uncompleted Ippm series in the previous PPM marker?*/ 3658
3645 if (l_cp->ppm_data_read < l_cp->ppm_len) { 3659 if (l_N_ppm_remaining >= l_data_size) {
3646 /* Get the place where add the remaining Ippm se ries*/ 3660 memcpy(p_cp->ppm_buffer + l_ppm_data_size, l_dat a, l_data_size);
3647 l_cp->ppm_data_current = &(l_cp->ppm_data[l_cp-> ppm_data_read]); 3661 l_ppm_data_size += l_data_size;
3648 l_N_ppm = l_cp->ppm_len - l_cp->ppm_data_read; 3662 l_N_ppm_remaining -= l_data_size;
3649 } 3663 l_data_size = 0U;
3650 else { 3664 } else {
3651 OPJ_BYTE *new_ppm_data; 3665 memcpy(p_cp->ppm_buffer + l_ppm_data_size, l_dat a, l_N_ppm_remaining);
3652 opj_read_bytes(p_header_data,&l_N_ppm,4); /* First N_ppm */ 3666 l_ppm_data_size += l_N_ppm_remaining;
3653 p_header_data+=4; 3667 l_data += l_N_ppm_remaining;
3654 p_header_size-=4; 3668 l_data_size -= l_N_ppm_remaining;
3655 3669 l_N_ppm_remaining = 0U;
3656 /* sanity check: how much bytes is left for Ippm */ 3670 }
3657 if( p_header_size < l_N_ppm ) 3671
3658 { 3672 if (l_data_size > 0U) {
3659 opj_event_msg(p_manager, EVT_ERROR, "Not enoug h bytes (%u) to hold Ippm series (%u), Index (%d)\n", p_header_size, l_N_ppm, l_ Z_ppm ); 3673 do
3660 opj_free(l_cp->ppm_data); 3674 {
3661 l_cp->ppm_data = NULL; 3675 /* read Nppm */
3662 l_cp->ppm_buffer = NULL; 3676 if (l_data_size < 4U) {
3663 l_cp->ppm = 0; /* do not use PPM */ 3677 /* clean up to be done on l_cp d estruction */
3664 return OPJ_FALSE; 3678 opj_event_msg(p_manager, EVT_ERR OR, "Not enough bytes to read Nppm\n");
3665 } 3679 return OPJ_FALSE;
3666 /* Increase the size of ppm_data to add the new Ippm series*/ 3680 }
3667 assert(l_cp->ppm_data == l_cp->ppm_buffer && "We need ppm_data and ppm_buffer to be the same when reallocating"); 3681 opj_read_bytes(l_data, &l_N_ppm, 4);
3668 new_ppm_data = (OPJ_BYTE *) opj_realloc(l_cp->pp m_data, l_cp->ppm_len + l_N_ppm); 3682 l_data+=4;
3669 if (! new_ppm_data) { 3683 l_data_size-=4;
3670 opj_free(l_cp->ppm_data); 3684
3671 l_cp->ppm_data = NULL; 3685 if (l_data_size >= l_N_ppm) {
3672 l_cp->ppm_buffer = NULL; /* TODO: no ne ed for a new local variable: ppm_buffer and ppm_data are enough */ 3686 memcpy(p_cp->ppm_buffer + l_ppm_ data_size, l_data, l_N_ppm);
3673 l_cp->ppm_len = 0; 3687 l_ppm_data_size += l_N_ppm;
3674 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to increase the size of ppm_data to add the new Ippm series\n"); 3688 l_data_size -= l_N_ppm;
3675 return OPJ_FALSE; 3689 l_data += l_N_ppm;
3676 } 3690 } else {
3677 l_cp->ppm_data = new_ppm_data; 3691 memcpy(p_cp->ppm_buffer + l_ppm_ data_size, l_data, l_data_size);
3678 l_cp->ppm_buffer = l_cp->ppm_data; 3692 l_ppm_data_size += l_data_size;
3679 3693 l_N_ppm_remaining = l_N_ppm - l_ data_size;
3680 /* Keep the position of the place where concaten ate the new series*/ 3694 l_data_size = 0U;
3681 l_cp->ppm_data_current = &(l_cp->ppm_data[l_cp-> ppm_len]); 3695 }
3682 l_cp->ppm_len += l_N_ppm; 3696 } while (l_data_size > 0U);
3683 } 3697 }
3684 } 3698 opj_free(p_cp->ppm_markers[i].m_data);
3685 } 3699 p_cp->ppm_markers[i].m_data = NULL;
3686 3700 p_cp->ppm_markers[i].m_data_size = 0U;
3687 l_remaining_data = p_header_size; 3701 }
3688 3702 }
3689 while (l_remaining_data >= l_N_ppm) { 3703
3690 /* read a complete Ippm series*/ 3704 p_cp->ppm_data = p_cp->ppm_buffer;
3691 memcpy(l_cp->ppm_data_current, p_header_data, l_N_ppm); 3705 p_cp->ppm_data_size = p_cp->ppm_len;
3692 p_header_size -= l_N_ppm; 3706
3693 p_header_data += l_N_ppm; 3707 p_cp->ppm_markers_count = 0U;
3694 3708 opj_free(p_cp->ppm_markers);
3695 l_cp->ppm_data_read += l_N_ppm; /* Increase the number of data r ead*/ 3709 p_cp->ppm_markers = NULL;
3696 3710
3697 if (p_header_size) 3711 return OPJ_TRUE;
3698 {
3699 if (p_header_size < 4) {
3700 opj_free(l_cp->ppm_data);
3701 l_cp->ppm_data = NULL;
3702 l_cp->ppm_buffer = NULL; /* TODO: no need for a new local variable: ppm_buffer and ppm_data are enough */
3703 l_cp->ppm_len = 0;
3704 l_cp->ppm = 0;
3705 opj_event_msg(p_manager, EVT_ERROR, "Error readi ng PPM marker\n");
3706 return OPJ_FALSE;
3707 }
3708 opj_read_bytes(p_header_data,&l_N_ppm,4); /* N_ppm^i */
3709 p_header_data+=4;
3710 p_header_size-=4;
3711 }
3712 else {
3713 l_remaining_data = p_header_size;
3714 break;
3715 }
3716
3717 l_remaining_data = p_header_size;
3718
3719 /* Next Ippm series is a complete series ?*/
3720 if (l_remaining_data >= l_N_ppm) {
3721 OPJ_BYTE *new_ppm_data;
3722 /* Increase the size of ppm_data to add the new Ippm ser ies*/
3723 assert(l_cp->ppm_data == l_cp->ppm_buffer && "We need pp m_data and ppm_buffer to be the same when reallocating");
3724 /* Overflow check */
3725 if ((l_cp->ppm_len + l_N_ppm) < l_N_ppm) {
3726 opj_free(l_cp->ppm_data);
3727 l_cp->ppm_data = NULL;
3728 l_cp->ppm_buffer = NULL; /* TODO: no need for a new local variable: ppm_buffer and ppm_data are enough */
3729 l_cp->ppm_len = 0;
3730 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to increase the size of ppm_data to add the new (complete) Ippm series\n" );
3731 return OPJ_FALSE;
3732 }
3733 new_ppm_data = (OPJ_BYTE *) opj_realloc(l_cp->ppm_data, l_cp->ppm_len + l_N_ppm);
3734 if (! new_ppm_data) {
3735 opj_free(l_cp->ppm_data);
3736 l_cp->ppm_data = NULL;
3737 l_cp->ppm_buffer = NULL; /* TODO: no need for a new local variable: ppm_buffer and ppm_data are enough */
3738 l_cp->ppm_len = 0;
3739 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to increase the size of ppm_data to add the new (complete) Ippm series\n" );
3740 return OPJ_FALSE;
3741 }
3742 l_cp->ppm_data = new_ppm_data;
3743 l_cp->ppm_buffer = l_cp->ppm_data;
3744
3745 /* Keep the position of the place where concatenate the new series */
3746 l_cp->ppm_data_current = &(l_cp->ppm_data[l_cp->ppm_len] );
3747 l_cp->ppm_len += l_N_ppm;
3748 }
3749
3750 }
3751
3752 /* Need to read an incomplete Ippm series*/
3753 if (l_remaining_data) {
3754 OPJ_BYTE *new_ppm_data;
3755 assert(l_cp->ppm_data == l_cp->ppm_buffer && "We need ppm_data a nd ppm_buffer to be the same when reallocating");
3756
3757 /* Overflow check */
3758 if ((l_cp->ppm_len + l_N_ppm) < l_N_ppm) {
3759 opj_free(l_cp->ppm_data);
3760 l_cp->ppm_data = NULL;
3761 l_cp->ppm_buffer = NULL; /* TODO: no need for a new loc al variable: ppm_buffer and ppm_data are enough */
3762 l_cp->ppm_len = 0;
3763 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory t o increase the size of ppm_data to add the new (complete) Ippm series\n");
3764 return OPJ_FALSE;
3765 }
3766 new_ppm_data = (OPJ_BYTE *) opj_realloc(l_cp->ppm_data, l_cp->pp m_len + l_N_ppm);
3767 if (! new_ppm_data) {
3768 opj_free(l_cp->ppm_data);
3769 l_cp->ppm_data = NULL;
3770 l_cp->ppm_buffer = NULL; /* TODO: no need for a new loc al variable: ppm_buffer and ppm_data are enough */
3771 l_cp->ppm_len = 0;
3772 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory t o increase the size of ppm_data to add the new (incomplete) Ippm series\n");
3773 return OPJ_FALSE;
3774 }
3775 l_cp->ppm_data = new_ppm_data;
3776 l_cp->ppm_buffer = l_cp->ppm_data;
3777
3778 /* Keep the position of the place where concatenate the new seri es*/
3779 l_cp->ppm_data_current = &(l_cp->ppm_data[l_cp->ppm_len]);
3780 l_cp->ppm_len += l_N_ppm;
3781
3782 /* Read incomplete Ippm series*/
3783 memcpy(l_cp->ppm_data_current, p_header_data, l_remaining_data);
3784 p_header_size -= l_remaining_data;
3785 p_header_data += l_remaining_data;
3786
3787 l_cp->ppm_data_read += l_remaining_data; /* Increase the number of data read*/
3788 }
3789
3790 #ifdef CLEAN_MSD
3791
3792 if (l_cp->ppm_data_size == l_cp->ppm_len) {
3793 if (p_header_size >= 4) {
3794 /* read a N_ppm*/
3795 opj_read_bytes(p_header_data,&l_N_ppm,4); /* N_ppm */
3796 p_header_data+=4;
3797 p_header_size-=4;
3798 l_cp->ppm_len += l_N_ppm ;
3799
3800 OPJ_BYTE *new_ppm_buffer = (OPJ_BYTE *) opj_real loc(l_cp->ppm_buffer, l_cp->ppm_len);
3801 if (! new_ppm_buffer) {
3802 opj_free(l_cp->ppm_buffer);
3803 l_cp->ppm_buffer = NULL;
3804 l_cp->ppm_len = 0;
3805 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read ppm marker\n");
3806 return OPJ_FALSE;
3807 }
3808 l_cp->ppm_buffer = new_ppm_buffer;
3809 memset(l_cp->ppm_buffer+l_cp->ppm_data_size,0,l_ N_ppm);
3810
3811 l_cp->ppm_data = l_cp->ppm_buffer;
3812 }
3813 else {
3814 return OPJ_FALSE;
3815 }
3816 }
3817
3818 l_remaining_data = l_cp->ppm_len - l_cp->ppm_data_size;
3819
3820 if (l_remaining_data <= p_header_size) {
3821 /* we must store less information than available in the packet */
3822 memcpy(l_cp->ppm_buffer + l_cp->ppm_data_size , p_header _data , l_remaining_data);
3823 l_cp->ppm_data_size = l_cp->ppm_len;
3824 p_header_size -= l_remaining_data;
3825 p_header_data += l_remaining_data;
3826 }
3827 else {
3828 memcpy(l_cp->ppm_buffer + l_cp->ppm_data_size , p_header _data , p_header_size);
3829 l_cp->ppm_data_size += p_header_size;
3830 p_header_data += p_header_size;
3831 p_header_size = 0;
3832 break;
3833 }
3834 }
3835 #endif
3836 return OPJ_TRUE;
3837 } 3712 }
3838 3713
3839 /** 3714 /**
3840 * Reads a PPT marker (Packed packet headers, tile-part header) 3715 * Reads a PPT marker (Packed packet headers, tile-part header)
3841 * 3716 *
3842 * @param p_header_data the data contained in the PPT box. 3717 * @param p_header_data the data contained in the PPT box.
3843 * @param p_j2k the jpeg2000 codec. 3718 * @param p_j2k the jpeg2000 codec.
3844 * @param p_header_size the size of the data contained in the PPT marker . 3719 * @param p_header_size the size of the data contained in the PPT marker .
3845 * @param p_manager the user event manager. 3720 * @param p_manager the user event manager.
3846 */ 3721 */
3847 static OPJ_BOOL opj_j2k_read_ppt ( opj_j2k_t *p_j2k, 3722 static OPJ_BOOL opj_j2k_read_ppt ( opj_j2k_t *p_j2k,
3848 OPJ_BYTE * p_header_data, 3723 OPJ_BYTE * p_header_data,
3849 OPJ_UINT32 p_header_size, 3724 OPJ_UINT32 p_header_size,
3850 opj_event_mgr_t * p_manager 3725 opj_event_mgr_t * p_manager
3851 ) 3726 )
3852 { 3727 {
3853 opj_cp_t *l_cp = 00; 3728 » opj_cp_t *l_cp = 00;
3854 opj_tcp_t *l_tcp = 00; 3729 » opj_tcp_t *l_tcp = 00;
3855 OPJ_UINT32 l_Z_ppt; 3730 » OPJ_UINT32 l_Z_ppt;
3856 3731
3857 /* preconditions */ 3732 » /* preconditions */
3858 assert(p_header_data != 00); 3733 » assert(p_header_data != 00);
3859 assert(p_j2k != 00); 3734 » assert(p_j2k != 00);
3860 assert(p_manager != 00); 3735 » assert(p_manager != 00);
3861 3736
3862 /* We need to have the Z_ppt element at minimum */ 3737 » /* We need to have the Z_ppt element + 1 byte of Ippt at minimum */
3863 if (p_header_size < 1) { 3738 » if (p_header_size < 2) {
3864 opj_event_msg(p_manager, EVT_ERROR, "Error reading PPT marker\n" ); 3739 » » opj_event_msg(p_manager, EVT_ERROR, "Error reading PPT marker\n" );
3865 return OPJ_FALSE; 3740 » » return OPJ_FALSE;
3866 } 3741 » }
3867 3742
3868 l_cp = &(p_j2k->m_cp); 3743 » l_cp = &(p_j2k->m_cp);
3869 if (l_cp->ppm){ 3744 » if (l_cp->ppm){
3870 opj_event_msg(p_manager, EVT_ERROR, "Error reading PPT marker: p acket header have been previously found in the main header (PPM marker).\n"); 3745 » » opj_event_msg(p_manager, EVT_ERROR, "Error reading PPT marker: p acket header have been previously found in the main header (PPM marker).\n");
3871 return OPJ_FALSE; 3746 » » return OPJ_FALSE;
3872 } 3747 » }
3873 3748
3874 l_tcp = &(l_cp->tcps[p_j2k->m_current_tile_number]); 3749 » l_tcp = &(l_cp->tcps[p_j2k->m_current_tile_number]);
3875 l_tcp->ppt = 1; 3750 » l_tcp->ppt = 1;
3876 3751
3877 opj_read_bytes(p_header_data,&l_Z_ppt,1); /* Z_ppt */ 3752 » opj_read_bytes(p_header_data,&l_Z_ppt,1); /* Z_ppt */
3878 ++p_header_data; 3753 » ++p_header_data;
3879 --p_header_size; 3754 » --p_header_size;
3880 3755 »
3881 /* Allocate buffer to read the packet header */ 3756 » /* check allocation needed */
3882 if (l_Z_ppt == 0) { 3757 » if (l_tcp->ppt_markers == NULL) { /* first PPT marker */
3883 /* First PPT marker */ 3758 » » OPJ_UINT32 l_newCount = l_Z_ppt + 1U; /* can't overflow, l_Z_ppt is UINT8 */
3884 l_tcp->ppt_data_size = 0; 3759 » » assert(l_tcp->ppt_markers_count == 0U);
3885 l_tcp->ppt_len = p_header_size; 3760 » »
3886 3761 » » l_tcp->ppt_markers = (opj_ppx *) opj_calloc(l_newCount, sizeof(o pj_ppx));
3887 opj_free(l_tcp->ppt_buffer); 3762 » » if (l_tcp->ppt_markers == NULL) {
3888 l_tcp->ppt_buffer = (OPJ_BYTE *) opj_calloc(l_tcp->ppt_len, size of(OPJ_BYTE) ); 3763 » » » opj_event_msg(p_manager, EVT_ERROR, "Not enough memory t o read PPT marker\n");
3889 if (l_tcp->ppt_buffer == 00) { 3764 » » » return OPJ_FALSE;
3890 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory t o read PPT marker\n"); 3765 » » }
3891 return OPJ_FALSE; 3766 » » l_tcp->ppt_markers_count = l_newCount;
3892 } 3767 » } else if (l_tcp->ppt_markers_count <= l_Z_ppt) {
3893 l_tcp->ppt_data = l_tcp->ppt_buffer; 3768 » » OPJ_UINT32 l_newCount = l_Z_ppt + 1U; /* can't overflow, l_Z_ppt is UINT8 */
3894 3769 » » opj_ppx *new_ppt_markers;
3895 /* memset(l_tcp->ppt_buffer,0,l_tcp->ppt_len); */ 3770 » » new_ppt_markers = (opj_ppx *) opj_realloc(l_tcp->ppt_markers, l_ newCount * sizeof(opj_ppx));
3896 } 3771 » » if (new_ppt_markers == NULL) {
3897 else { 3772 » » » /* clean up to be done on l_tcp destruction */
3898 OPJ_BYTE *new_ppt_buffer; 3773 » » » opj_event_msg(p_manager, EVT_ERROR, "Not enough memory t o read PPT marker\n");
3899 l_tcp->ppt_len += p_header_size; 3774 » » » return OPJ_FALSE;
3900 3775 » » }
3901 new_ppt_buffer = (OPJ_BYTE *) opj_realloc(l_tcp->ppt_buffer, l_t cp->ppt_len); 3776 » » l_tcp->ppt_markers = new_ppt_markers;
3902 if (! new_ppt_buffer) { 3777 » » memset(l_tcp->ppt_markers + l_tcp->ppt_markers_count, 0, (l_newC ount - l_tcp->ppt_markers_count) * sizeof(opj_ppx));
3903 opj_free(l_tcp->ppt_buffer); 3778 » » l_tcp->ppt_markers_count = l_newCount;
3904 l_tcp->ppt_buffer = NULL; 3779 » }
3905 l_tcp->ppt_len = 0; 3780 »
3906 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory t o read PPT marker\n"); 3781 » if (l_tcp->ppt_markers[l_Z_ppt].m_data != NULL) {
3907 return OPJ_FALSE; 3782 » » /* clean up to be done on l_tcp destruction */
3908 } 3783 » » opj_event_msg(p_manager, EVT_ERROR, "Zppt %u already read\n", l_ Z_ppt);
3909 l_tcp->ppt_buffer = new_ppt_buffer; 3784 » » return OPJ_FALSE;
3910 l_tcp->ppt_data = l_tcp->ppt_buffer; 3785 » }
3911 3786 »
3912 memset(l_tcp->ppt_buffer+l_tcp->ppt_data_size,0,p_header_size); 3787 » l_tcp->ppt_markers[l_Z_ppt].m_data = opj_malloc(p_header_size);
3913 } 3788 » if (l_tcp->ppt_markers[l_Z_ppt].m_data == NULL) {
3914 3789 » » /* clean up to be done on l_tcp destruction */
3915 /* Read packet header from buffer */ 3790 » » opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read P PT marker\n");
3916 memcpy(l_tcp->ppt_buffer+l_tcp->ppt_data_size,p_header_data,p_header_siz e); 3791 » » return OPJ_FALSE;
3917 3792 » }
3918 l_tcp->ppt_data_size += p_header_size; 3793 » l_tcp->ppt_markers[l_Z_ppt].m_data_size = p_header_size;
3919 3794 » memcpy(l_tcp->ppt_markers[l_Z_ppt].m_data, p_header_data, p_header_size) ;
3920 return OPJ_TRUE; 3795 » return OPJ_TRUE;
3921 } 3796 }
3922 3797
3923 OPJ_BOOL opj_j2k_write_tlm( opj_j2k_t *p_j2k, 3798 /**
3799 * Merges all PPT markers read (Packed packet headers, tile-part header)
3800 *
3801 * @param p_tcp the tile.
3802 * @param p_manager the user event manager.
3803 */
3804 static OPJ_BOOL opj_j2k_merge_ppt(opj_tcp_t *p_tcp, opj_event_mgr_t * p_manager)
3805 {
3806 » OPJ_UINT32 i, l_ppt_data_size;
3807 » /* preconditions */
3808 » assert(p_tcp != 00);
3809 » assert(p_manager != 00);
3810 » assert(p_tcp->ppt_buffer == NULL);
3811 »
3812 » if (p_tcp->ppt == 0U) {
3813 » » return OPJ_TRUE;
3814 » }
3815 »
3816 » l_ppt_data_size = 0U;
3817 » for (i = 0U; i < p_tcp->ppt_markers_count; ++i) {
3818 » » l_ppt_data_size += p_tcp->ppt_markers[i].m_data_size; /* can't o verflow, max 256 markers of max 65536 bytes */
3819 » }
3820 »
3821 » p_tcp->ppt_buffer = (OPJ_BYTE *) opj_malloc(l_ppt_data_size);
3822 » if (p_tcp->ppt_buffer == 00) {
3823 » » opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to read P PT marker\n");
3824 » » return OPJ_FALSE;
3825 » }
3826 » p_tcp->ppt_len = l_ppt_data_size;
3827 » l_ppt_data_size = 0U;
3828 » for (i = 0U; i < p_tcp->ppt_markers_count; ++i) {
3829 » » if (p_tcp->ppt_markers[i].m_data != NULL) { /* standard doesn't seem to require contiguous Zppt */
3830 » » » memcpy(p_tcp->ppt_buffer + l_ppt_data_size, p_tcp->ppt_m arkers[i].m_data, p_tcp->ppt_markers[i].m_data_size);
3831 » » » l_ppt_data_size += p_tcp->ppt_markers[i].m_data_size; /* can't overflow, max 256 markers of max 65536 bytes */
3832 » » »
3833 » » » opj_free(p_tcp->ppt_markers[i].m_data);
3834 » » » p_tcp->ppt_markers[i].m_data = NULL;
3835 » » » p_tcp->ppt_markers[i].m_data_size = 0U;
3836 » » }
3837 » }
3838 »
3839 » p_tcp->ppt_markers_count = 0U;
3840 » opj_free(p_tcp->ppt_markers);
3841 » p_tcp->ppt_markers = NULL;
3842 »
3843 » p_tcp->ppt_data = p_tcp->ppt_buffer;
3844 » p_tcp->ppt_data_size = p_tcp->ppt_len;
3845 » return OPJ_TRUE;
3846 }
3847
3848 static OPJ_BOOL opj_j2k_write_tlm( opj_j2k_t *p_j2k,
3924 opj_stream_private_t *p_ stream, 3849 opj_stream_private_t *p_ stream,
3925 opj_event_mgr_t * p_mana ger 3850 opj_event_mgr_t * p_mana ger
3926 ) 3851 )
3927 { 3852 {
3928 OPJ_BYTE * l_current_data = 00; 3853 OPJ_BYTE * l_current_data = 00;
3929 OPJ_UINT32 l_tlm_size; 3854 OPJ_UINT32 l_tlm_size;
3930 3855
3931 /* preconditions */ 3856 /* preconditions */
3932 assert(p_j2k != 00); 3857 assert(p_j2k != 00);
3933 assert(p_manager != 00); 3858 assert(p_manager != 00);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
3967 ++l_current_data; 3892 ++l_current_data;
3968 3893
3969 /* do nothing on the 5 * l_j2k->m_specific_param.m_encoder.m_total_tile_ parts remaining data */ 3894 /* do nothing on the 5 * l_j2k->m_specific_param.m_encoder.m_total_tile_ parts remaining data */
3970 if (opj_stream_write_data(p_stream,p_j2k->m_specific_param.m_encoder.m_h eader_tile_data,l_tlm_size,p_manager) != l_tlm_size) { 3895 if (opj_stream_write_data(p_stream,p_j2k->m_specific_param.m_encoder.m_h eader_tile_data,l_tlm_size,p_manager) != l_tlm_size) {
3971 return OPJ_FALSE; 3896 return OPJ_FALSE;
3972 } 3897 }
3973 3898
3974 return OPJ_TRUE; 3899 return OPJ_TRUE;
3975 } 3900 }
3976 3901
3977 OPJ_BOOL opj_j2k_write_sot( opj_j2k_t *p_j2k, 3902 static OPJ_BOOL opj_j2k_write_sot( opj_j2k_t *p_j2k,
3978 OPJ_BYTE * p_data, 3903 OPJ_BYTE * p_data,
3979 OPJ_UINT32 * p_data_writ ten, 3904 OPJ_UINT32 * p_data_writ ten,
3980 const opj_stream_private _t *p_stream, 3905 const opj_stream_private _t *p_stream,
3981 opj_event_mgr_t * p_mana ger 3906 opj_event_mgr_t * p_mana ger
3982 ) 3907 )
3983 { 3908 {
3984 /* preconditions */ 3909 /* preconditions */
3985 assert(p_j2k != 00); 3910 assert(p_j2k != 00);
3986 assert(p_manager != 00); 3911 assert(p_manager != 00);
3987 assert(p_stream != 00); 3912 assert(p_stream != 00);
(...skipping 23 matching lines...) Expand all
4011 OPJ_BOOL res = j2k_add_marker(p_j2k->cstr_info, J2K_MS_SOT, p_j2k->sot_s tart, len + 2); 3936 OPJ_BOOL res = j2k_add_marker(p_j2k->cstr_info, J2K_MS_SOT, p_j2k->sot_s tart, len + 2);
4012 */ 3937 */
4013 assert( 0 && "TODO" ); 3938 assert( 0 && "TODO" );
4014 #endif /* USE_JPWL */ 3939 #endif /* USE_JPWL */
4015 3940
4016 * p_data_written = 12; 3941 * p_data_written = 12;
4017 3942
4018 return OPJ_TRUE; 3943 return OPJ_TRUE;
4019 } 3944 }
4020 3945
4021 OPJ_BOOL opj_j2k_read_sot ( opj_j2k_t *p_j2k, 3946 static OPJ_BOOL opj_j2k_get_sot_values(OPJ_BYTE * p_header_data,
3947 » » » » » » » » » » » » » » » » » » » OPJ_UIN T32 p_header_size,
3948 » » » » » » » » » » » » » » » » » » » OPJ_UIN T32* p_tile_no,
3949 » » » » » » » » » » » » » » » » » » » OPJ_UIN T32* p_tot_len,
3950 » » » » » » » » » » » » » » » » » » » OPJ_UIN T32* p_current_part,
3951 » » » » » » » » » » » » » » » » » » » OPJ_UIN T32* p_num_parts,
3952 » » » » » » » » » » » » » » » » » » » opj_eve nt_mgr_t * p_manager )
3953 {
3954 » /* preconditions */
3955 » assert(p_header_data != 00);
3956 » assert(p_manager != 00);
3957 »
3958 » /* Size of this marker is fixed = 12 (we have already read marker and it s size)*/
3959 » if (p_header_size != 8) {
3960 » » opj_event_msg(p_manager, EVT_ERROR, "Error reading SOT marker\n" );
3961 » » return OPJ_FALSE;
3962 » }
3963 »
3964 » opj_read_bytes(p_header_data,p_tile_no,2); /* Isot */
3965 » p_header_data+=2;
3966 » opj_read_bytes(p_header_data,p_tot_len,4); /* Psot */
3967 » p_header_data+=4;
3968 » opj_read_bytes(p_header_data,p_current_part,1); /* TPsot */
3969 » ++p_header_data;
3970 » opj_read_bytes(p_header_data,p_num_parts ,1); /* TNsot */
3971 » ++p_header_data;
3972 » return OPJ_TRUE;
3973 }
3974
3975 static OPJ_BOOL opj_j2k_read_sot ( opj_j2k_t *p_j2k,
4022 OPJ_BYTE * p_header_data, 3976 OPJ_BYTE * p_header_data,
4023 OPJ_UINT32 p_header_size, 3977 OPJ_UINT32 p_header_size,
4024 opj_event_mgr_t * p_manager ) 3978 opj_event_mgr_t * p_manager )
4025 { 3979 {
4026 opj_cp_t *l_cp = 00; 3980 opj_cp_t *l_cp = 00;
4027 opj_tcp_t *l_tcp = 00; 3981 opj_tcp_t *l_tcp = 00;
4028 OPJ_UINT32 l_tot_len, l_num_parts = 0; 3982 OPJ_UINT32 l_tot_len, l_num_parts = 0;
4029 OPJ_UINT32 l_current_part; 3983 OPJ_UINT32 l_current_part;
4030 OPJ_UINT32 l_tile_x,l_tile_y; 3984 OPJ_UINT32 l_tile_x,l_tile_y;
4031 3985
4032 /* preconditions */ 3986 /* preconditions */
4033 assert(p_header_data != 00); 3987 »
4034 assert(p_j2k != 00); 3988 assert(p_j2k != 00);
4035 assert(p_manager != 00); 3989 assert(p_manager != 00);
4036 3990 »
4037 /* Size of this marker is fixed = 12 (we have already read marker and it s size)*/ 3991 if (! opj_j2k_get_sot_values(p_header_data, p_header_size, &(p_j2k->m_cu rrent_tile_number), &l_tot_len, &l_current_part, &l_num_parts, p_manager)) {
4038 if (p_header_size != 8) {
4039 opj_event_msg(p_manager, EVT_ERROR, "Error reading SOT marker\n" ); 3992 opj_event_msg(p_manager, EVT_ERROR, "Error reading SOT marker\n" );
4040 return OPJ_FALSE; 3993 return OPJ_FALSE;
4041 } 3994 }
4042 3995
4043 l_cp = &(p_j2k->m_cp); 3996 l_cp = &(p_j2k->m_cp);
4044 opj_read_bytes(p_header_data,&(p_j2k->m_current_tile_number),2); /* Isot */
4045 p_header_data+=2;
4046 3997
4047 /* testcase 2.pdf.SIGFPE.706.1112 */ 3998 /* testcase 2.pdf.SIGFPE.706.1112 */
4048 if (p_j2k->m_current_tile_number >= l_cp->tw * l_cp->th) { 3999 if (p_j2k->m_current_tile_number >= l_cp->tw * l_cp->th) {
4049 opj_event_msg(p_manager, EVT_ERROR, "Invalid tile number %d\n", p_j2k->m_current_tile_number); 4000 opj_event_msg(p_manager, EVT_ERROR, "Invalid tile number %d\n", p_j2k->m_current_tile_number);
4050 return OPJ_FALSE; 4001 return OPJ_FALSE;
4051 } 4002 }
4052 4003
4053 l_tcp = &l_cp->tcps[p_j2k->m_current_tile_number]; 4004 l_tcp = &l_cp->tcps[p_j2k->m_current_tile_number];
4054 l_tile_x = p_j2k->m_current_tile_number % l_cp->tw; 4005 l_tile_x = p_j2k->m_current_tile_number % l_cp->tw;
4055 l_tile_y = p_j2k->m_current_tile_number / l_cp->tw; 4006 l_tile_y = p_j2k->m_current_tile_number / l_cp->tw;
(...skipping 22 matching lines...) Expand all
4078 4029
4079 /* keep your private count of tiles */ 4030 /* keep your private count of tiles */
4080 backup_tileno++; 4031 backup_tileno++;
4081 }; 4032 };
4082 #endif /* USE_JPWL */ 4033 #endif /* USE_JPWL */
4083 4034
4084 /* look for the tile in the list of already processed tile (in parts). * / 4035 /* look for the tile in the list of already processed tile (in parts). * /
4085 /* Optimization possible here with a more complex data structure and wit h the removing of tiles */ 4036 /* Optimization possible here with a more complex data structure and wit h the removing of tiles */
4086 /* since the time taken by this function can only grow at the time */ 4037 /* since the time taken by this function can only grow at the time */
4087 4038
4088 opj_read_bytes(p_header_data,&l_tot_len,4); /* Psot */
4089 p_header_data+=4;
4090
4091 /* PSot should be equal to zero or >=14 or <= 2^32-1 */ 4039 /* PSot should be equal to zero or >=14 or <= 2^32-1 */
4092 if ((l_tot_len !=0 ) && (l_tot_len < 14) ) 4040 if ((l_tot_len !=0 ) && (l_tot_len < 14) )
4093 { 4041 {
4094 if (l_tot_len == 12 ) /* MSD: Special case for the PHR data which ar e read by kakadu*/ 4042 if (l_tot_len == 12 ) /* MSD: Special case for the PHR data which ar e read by kakadu*/
4095 { 4043 {
4096 opj_event_msg(p_manager, EVT_WARNING, "Empty SOT marker detected : Psot=%d.\n", l_tot_len); 4044 opj_event_msg(p_manager, EVT_WARNING, "Empty SOT marker detected : Psot=%d.\n", l_tot_len);
4097 } 4045 }
4098 else 4046 else
4099 { 4047 {
4100 opj_event_msg(p_manager, EVT_ERROR, "Psot value is not correct r egards to the JPEG2000 norm: %d.\n", l_tot_len); 4048 opj_event_msg(p_manager, EVT_ERROR, "Psot value is not correct r egards to the JPEG2000 norm: %d.\n", l_tot_len);
(...skipping 22 matching lines...) Expand all
4123 }; 4071 };
4124 #endif /* USE_JPWL */ 4072 #endif /* USE_JPWL */
4125 4073
4126 /* Ref A.4.2: Psot could be equal zero if it is the last tile-pa rt of the codestream.*/ 4074 /* Ref A.4.2: Psot could be equal zero if it is the last tile-pa rt of the codestream.*/
4127 if (!l_tot_len) { 4075 if (!l_tot_len) {
4128 opj_event_msg(p_manager, EVT_INFO, "Psot value of the cu rrent tile-part is equal to zero, " 4076 opj_event_msg(p_manager, EVT_INFO, "Psot value of the cu rrent tile-part is equal to zero, "
4129 "we assuming it is the last tile-part of the codestream.\n"); 4077 "we assuming it is the last tile-part of the codestream.\n");
4130 p_j2k->m_specific_param.m_decoder.m_last_tile_part = 1; 4078 p_j2k->m_specific_param.m_decoder.m_last_tile_part = 1;
4131 } 4079 }
4132 4080
4133 opj_read_bytes(p_header_data,&l_current_part ,1); /* TPsot */
4134 ++p_header_data;
4135
4136 opj_read_bytes(p_header_data,&l_num_parts ,1); /* TNsot */
4137 ++p_header_data;
4138
4139 if (l_num_parts != 0) { /* Number of tile-part header is provide d by this tile-part header */ 4081 if (l_num_parts != 0) { /* Number of tile-part header is provide d by this tile-part header */
4082 l_num_parts += p_j2k->m_specific_param.m_decoder.m_nb_ti le_parts_correction;
4140 /* Useful to manage the case of textGBR.jp2 file because two values of TNSot are allowed: the correct numbers of 4083 /* Useful to manage the case of textGBR.jp2 file because two values of TNSot are allowed: the correct numbers of
4141 * tile-parts for that tile and zero (A.4.2 of 15444-1 : 2002). */ 4084 * tile-parts for that tile and zero (A.4.2 of 15444-1 : 2002). */
4142 if (l_tcp->m_nb_tile_parts) { 4085 if (l_tcp->m_nb_tile_parts) {
4143 if (l_current_part >= l_tcp->m_nb_tile_parts){ 4086 if (l_current_part >= l_tcp->m_nb_tile_parts){
4144 opj_event_msg(p_manager, EVT_ERROR, "In SOT marker, TPSot (%d) is not valid regards to the current " 4087 opj_event_msg(p_manager, EVT_ERROR, "In SOT marker, TPSot (%d) is not valid regards to the current "
4145 "number of tile-part (%d ), giving up\n", l_current_part, l_tcp->m_nb_tile_parts ); 4088 "number of tile-part (%d ), giving up\n", l_current_part, l_tcp->m_nb_tile_parts );
4146 p_j2k->m_specific_param.m_decoder.m_last _tile_part = 1; 4089 p_j2k->m_specific_param.m_decoder.m_last _tile_part = 1;
4147 return OPJ_FALSE; 4090 return OPJ_FALSE;
4148 } 4091 }
4149 } 4092 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
4279 p_j2k->cstr_info->tile[tileno].end_pos += totlen; 4222 p_j2k->cstr_info->tile[tileno].end_pos += totlen;
4280 } 4223 }
4281 4224
4282 p_j2k->cstr_info->tile[tileno].tp[partno].tp_start_pos = p_st ream_tell(p_stream) - 12; 4225 p_j2k->cstr_info->tile[tileno].tp[partno].tp_start_pos = p_st ream_tell(p_stream) - 12;
4283 p_j2k->cstr_info->tile[tileno].tp[partno].tp_end_pos = 4226 p_j2k->cstr_info->tile[tileno].tp[partno].tp_end_pos =
4284 p_j2k->cstr_info->tile[tileno].tp[partno].tp_start_pos + totl en - 1; 4227 p_j2k->cstr_info->tile[tileno].tp[partno].tp_start_pos + totl en - 1;
4285 }*/ 4228 }*/
4286 return OPJ_TRUE; 4229 return OPJ_TRUE;
4287 } 4230 }
4288 4231
4289 OPJ_BOOL opj_j2k_write_sod( opj_j2k_t *p_j2k, 4232 static OPJ_BOOL opj_j2k_write_sod( opj_j2k_t *p_j2k,
4290 opj_tcd_t * p_tile_coder , 4233 opj_tcd_t * p_tile_coder ,
4291 OPJ_BYTE * p_data, 4234 OPJ_BYTE * p_data,
4292 OPJ_UINT32 * p_data_writ ten, 4235 OPJ_UINT32 * p_data_writ ten,
4293 OPJ_UINT32 p_total_data_ size, 4236 OPJ_UINT32 p_total_data_ size,
4294 const opj_stream_private _t *p_stream, 4237 const opj_stream_private _t *p_stream,
4295 opj_event_mgr_t * p_mana ger 4238 opj_event_mgr_t * p_mana ger
4296 ) 4239 )
4297 { 4240 {
4298 opj_codestream_info_t *l_cstr_info = 00; 4241 opj_codestream_info_t *l_cstr_info = 00;
4299 OPJ_UINT32 l_remaining_data; 4242 OPJ_UINT32 l_remaining_data;
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
4353 if (! opj_tcd_encode_tile(p_tile_coder, p_j2k->m_current_tile_number, p_ data, p_data_written, l_remaining_data , l_cstr_info)) { 4296 if (! opj_tcd_encode_tile(p_tile_coder, p_j2k->m_current_tile_number, p_ data, p_data_written, l_remaining_data , l_cstr_info)) {
4354 opj_event_msg(p_manager, EVT_ERROR, "Cannot encode tile\n"); 4297 opj_event_msg(p_manager, EVT_ERROR, "Cannot encode tile\n");
4355 return OPJ_FALSE; 4298 return OPJ_FALSE;
4356 } 4299 }
4357 4300
4358 *p_data_written += 2; 4301 *p_data_written += 2;
4359 4302
4360 return OPJ_TRUE; 4303 return OPJ_TRUE;
4361 } 4304 }
4362 4305
4363 OPJ_BOOL opj_j2k_read_sod (opj_j2k_t *p_j2k, 4306 static OPJ_BOOL opj_j2k_read_sod (opj_j2k_t *p_j2k,
4364 opj_stream_private_t *p_stream, 4307 opj_stream_private_t *p_stream,
4365 opj_event_mgr_t * p_manager 4308 opj_event_mgr_t * p_manager
4366 ) 4309 )
4367 { 4310 {
4368 OPJ_SIZE_T l_current_read_size; 4311 OPJ_SIZE_T l_current_read_size;
4369 opj_codestream_index_t * l_cstr_index = 00; 4312 opj_codestream_index_t * l_cstr_index = 00;
4370 OPJ_BYTE ** l_current_data = 00; 4313 OPJ_BYTE ** l_current_data = 00;
4371 opj_tcp_t * l_tcp = 00; 4314 opj_tcp_t * l_tcp = 00;
4372 OPJ_UINT32 * l_tile_len = 00; 4315 OPJ_UINT32 * l_tile_len = 00;
4373 OPJ_BOOL l_sot_length_pb_detected = OPJ_FALSE; 4316 OPJ_BOOL l_sot_length_pb_detected = OPJ_FALSE;
(...skipping 27 matching lines...) Expand all
4401 /* Patch to support new PHR data */ 4344 /* Patch to support new PHR data */
4402 if (p_j2k->m_specific_param.m_decoder.m_sot_length) { 4345 if (p_j2k->m_specific_param.m_decoder.m_sot_length) {
4403 /* If we are here, we'll try to read the data after allocation */ 4346 /* If we are here, we'll try to read the data after allocation */
4404 /* Check enough bytes left in stream before allocation */ 4347 /* Check enough bytes left in stream before allocation */
4405 if ((OPJ_OFF_T)p_j2k->m_specific_param.m_decoder.m_sot_length > opj_ stream_get_number_byte_left(p_stream)) { 4348 if ((OPJ_OFF_T)p_j2k->m_specific_param.m_decoder.m_sot_length > opj_ stream_get_number_byte_left(p_stream)) {
4406 opj_event_msg(p_manager, EVT_ERROR, "Tile part length size incon sistent with stream length\n"); 4349 opj_event_msg(p_manager, EVT_ERROR, "Tile part length size incon sistent with stream length\n");
4407 return OPJ_FALSE; 4350 return OPJ_FALSE;
4408 } 4351 }
4409 if (! *l_current_data) { 4352 if (! *l_current_data) {
4410 /* LH: oddly enough, in this path, l_tile_len!=0. 4353 /* LH: oddly enough, in this path, l_tile_len!=0.
4411 * TODO: If this was consistant, we could simplify the code to o nly use realloc(), as realloc(0,...) default to malloc(0,...). 4354 * TODO: If this was consistent, we could simplify the code to o nly use realloc(), as realloc(0,...) default to malloc(0,...).
4412 */ 4355 */
4413 *l_current_data = (OPJ_BYTE*) opj_malloc(p_j2k->m_specific_param .m_decoder.m_sot_length); 4356 *l_current_data = (OPJ_BYTE*) opj_malloc(p_j2k->m_specific_param .m_decoder.m_sot_length);
4414 } 4357 }
4415 else { 4358 else {
4416 OPJ_BYTE *l_new_current_data = (OPJ_BYTE *) opj_realloc(*l_curre nt_data, *l_tile_len + p_j2k->m_specific_param.m_decoder.m_sot_length); 4359 OPJ_BYTE *l_new_current_data = (OPJ_BYTE *) opj_realloc(*l_curre nt_data, *l_tile_len + p_j2k->m_specific_param.m_decoder.m_sot_length);
4417 if (! l_new_current_data) { 4360 if (! l_new_current_data) {
4418 opj_free(*l_current_data); 4361 opj_free(*l_current_data);
4419 /*nothing more is done as l_current_data will be set to null, and just 4362 /*nothing more is done as l_current_data will be set to null, and just
4420 afterward we enter in the error path 4363 afterward we enter in the error path
4421 and the actual tile_len is updated (committed) at the end of the 4364 and the actual tile_len is updated (committed) at the end of the
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
4474 } 4417 }
4475 else { 4418 else {
4476 p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_TPHSOT; 4419 p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_TPHSOT;
4477 } 4420 }
4478 4421
4479 *l_tile_len += (OPJ_UINT32)l_current_read_size; 4422 *l_tile_len += (OPJ_UINT32)l_current_read_size;
4480 4423
4481 return OPJ_TRUE; 4424 return OPJ_TRUE;
4482 } 4425 }
4483 4426
4484 OPJ_BOOL opj_j2k_write_rgn(opj_j2k_t *p_j2k, 4427 static OPJ_BOOL opj_j2k_write_rgn(opj_j2k_t *p_j2k,
4485 OPJ_UINT32 p_tile_no, 4428 OPJ_UINT32 p_tile_no,
4486 OPJ_UINT32 p_comp_no, 4429 OPJ_UINT32 p_comp_no,
4487 OPJ_UINT32 nb_comps, 4430 OPJ_UINT32 nb_comps,
4488 opj_stream_private_t *p_stream, 4431 opj_stream_private_t *p_stream,
4489 opj_event_mgr_t * p_manager 4432 opj_event_mgr_t * p_manager
4490 ) 4433 )
4491 { 4434 {
4492 OPJ_BYTE * l_current_data = 00; 4435 OPJ_BYTE * l_current_data = 00;
4493 OPJ_UINT32 l_rgn_size; 4436 OPJ_UINT32 l_rgn_size;
4494 opj_cp_t *l_cp = 00; 4437 opj_cp_t *l_cp = 00;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
4531 opj_write_bytes(l_current_data, (OPJ_UINT32)l_tccp->roishift,1); /* SPrgn */ 4474 opj_write_bytes(l_current_data, (OPJ_UINT32)l_tccp->roishift,1); /* SPrgn */
4532 ++l_current_data; 4475 ++l_current_data;
4533 4476
4534 if (opj_stream_write_data(p_stream,p_j2k->m_specific_param.m_encoder.m_h eader_tile_data,l_rgn_size,p_manager) != l_rgn_size) { 4477 if (opj_stream_write_data(p_stream,p_j2k->m_specific_param.m_encoder.m_h eader_tile_data,l_rgn_size,p_manager) != l_rgn_size) {
4535 return OPJ_FALSE; 4478 return OPJ_FALSE;
4536 } 4479 }
4537 4480
4538 return OPJ_TRUE; 4481 return OPJ_TRUE;
4539 } 4482 }
4540 4483
4541 OPJ_BOOL opj_j2k_write_eoc( opj_j2k_t *p_j2k, 4484 static OPJ_BOOL opj_j2k_write_eoc( opj_j2k_t *p_j2k,
4542 opj_stream_private_t *p_stream, 4485 opj_stream_private_t *p_stream,
4543 opj_event_mgr_t * p_manager 4486 opj_event_mgr_t * p_manager
4544 ) 4487 )
4545 { 4488 {
4546 /* preconditions */ 4489 /* preconditions */
4547 assert(p_j2k != 00); 4490 assert(p_j2k != 00);
4548 assert(p_manager != 00); 4491 assert(p_manager != 00);
4549 assert(p_stream != 00); 4492 assert(p_stream != 00);
4550 4493
4551 opj_write_bytes(p_j2k->m_specific_param.m_encoder.m_header_tile_data,J2K _MS_EOC,2); /* EOC */ 4494 opj_write_bytes(p_j2k->m_specific_param.m_encoder.m_header_tile_data,J2K _MS_EOC,2); /* EOC */
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
4641 return OPJ_FALSE; 4584 return OPJ_FALSE;
4642 } 4585 }
4643 4586
4644 opj_read_bytes(p_header_data,(OPJ_UINT32 *) (&(l_tcp->tccps[l_comp_no].r oishift)),1); /* SPrgn */ 4587 opj_read_bytes(p_header_data,(OPJ_UINT32 *) (&(l_tcp->tccps[l_comp_no].r oishift)),1); /* SPrgn */
4645 ++p_header_data; 4588 ++p_header_data;
4646 4589
4647 return OPJ_TRUE; 4590 return OPJ_TRUE;
4648 4591
4649 } 4592 }
4650 4593
4651 OPJ_FLOAT32 opj_j2k_get_tp_stride (opj_tcp_t * p_tcp) 4594 static OPJ_FLOAT32 opj_j2k_get_tp_stride (opj_tcp_t * p_tcp)
4652 { 4595 {
4653 return (OPJ_FLOAT32) ((p_tcp->m_nb_tile_parts - 1) * 14); 4596 return (OPJ_FLOAT32) ((p_tcp->m_nb_tile_parts - 1) * 14);
4654 } 4597 }
4655 4598
4656 OPJ_FLOAT32 opj_j2k_get_default_stride (opj_tcp_t * p_tcp) 4599 static OPJ_FLOAT32 opj_j2k_get_default_stride (opj_tcp_t * p_tcp)
4657 { 4600 {
4658 (void)p_tcp; 4601 (void)p_tcp;
4659 return 0; 4602 return 0;
4660 } 4603 }
4661 4604
4662 OPJ_BOOL opj_j2k_update_rates( opj_j2k_t *p_j2k, 4605 static OPJ_BOOL opj_j2k_update_rates( opj_j2k_t *p_j2k,
4663 opj_stream_private_t *p_stream, 4606 opj_stream_private_t *p_stream,
4664 opj_event_mgr_t * p_ manager ) 4607 opj_event_mgr_t * p_ manager )
4665 { 4608 {
4666 opj_cp_t * l_cp = 00; 4609 opj_cp_t * l_cp = 00;
4667 opj_image_t * l_image = 00; 4610 opj_image_t * l_image = 00;
4668 opj_tcp_t * l_tcp = 00; 4611 opj_tcp_t * l_tcp = 00;
4669 opj_image_comp_t * l_img_comp = 00; 4612 opj_image_comp_t * l_img_comp = 00;
4670 4613
4671 OPJ_UINT32 i,j,k; 4614 OPJ_UINT32 i,j,k;
4672 OPJ_INT32 l_x0,l_y0,l_x1,l_y1; 4615 OPJ_INT32 l_x0,l_y0,l_x1,l_y1;
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
4815 } 4758 }
4816 4759
4817 p_j2k->m_specific_param.m_encoder.m_tlm_sot_offsets_current = 4760 p_j2k->m_specific_param.m_encoder.m_tlm_sot_offsets_current =
4818 p_j2k->m_specific_param.m_encoder.m_tlm_sot_offs ets_buffer; 4761 p_j2k->m_specific_param.m_encoder.m_tlm_sot_offs ets_buffer;
4819 } 4762 }
4820 4763
4821 return OPJ_TRUE; 4764 return OPJ_TRUE;
4822 } 4765 }
4823 4766
4824 #if 0 4767 #if 0
4825 OPJ_BOOL opj_j2k_read_eoc ( opj_j2k_t *p_j2k, 4768 static OPJ_BOOL opj_j2k_read_eoc ( opj_j2k_t *p_j2k,
4826 opj_stream_private_t *p_ stream, 4769 opj_stream_private_t *p_ stream,
4827 opj_event_mgr_t * p_mana ger ) 4770 opj_event_mgr_t * p_mana ger )
4828 { 4771 {
4829 OPJ_UINT32 i; 4772 OPJ_UINT32 i;
4830 opj_tcd_t * l_tcd = 00; 4773 opj_tcd_t * l_tcd = 00;
4831 OPJ_UINT32 l_nb_tiles; 4774 OPJ_UINT32 l_nb_tiles;
4832 opj_tcp_t * l_tcp = 00; 4775 opj_tcp_t * l_tcp = 00;
4833 OPJ_BOOL l_success; 4776 OPJ_BOOL l_success;
4834 4777
4835 /* preconditions */ 4778 /* preconditions */
(...skipping 29 matching lines...) Expand all
4865 4808
4866 opj_j2k_tcp_destroy(l_tcp); 4809 opj_j2k_tcp_destroy(l_tcp);
4867 ++l_tcp; 4810 ++l_tcp;
4868 } 4811 }
4869 4812
4870 opj_tcd_destroy(l_tcd); 4813 opj_tcd_destroy(l_tcd);
4871 return OPJ_TRUE; 4814 return OPJ_TRUE;
4872 } 4815 }
4873 #endif 4816 #endif
4874 4817
4875 OPJ_BOOL opj_j2k_get_end_header(opj_j2k_t *p_j2k, 4818 static OPJ_BOOL opj_j2k_get_end_header(opj_j2k_t *p_j2k,
4876 struct opj_stream_privat e *p_stream, 4819 struct opj_stream_privat e *p_stream,
4877 struct opj_event_mgr * p _manager ) 4820 struct opj_event_mgr * p _manager )
4878 { 4821 {
4879 /* preconditions */ 4822 /* preconditions */
4880 assert(p_j2k != 00); 4823 assert(p_j2k != 00);
4881 assert(p_manager != 00); 4824 assert(p_manager != 00);
4882 assert(p_stream != 00); 4825 assert(p_stream != 00);
4883 4826
4884 p_j2k->cstr_index->main_head_end = opj_stream_tell(p_stream); 4827 p_j2k->cstr_index->main_head_end = opj_stream_tell(p_stream);
4885 4828
4886 return OPJ_TRUE; 4829 return OPJ_TRUE;
4887 } 4830 }
4888 4831
4889 OPJ_BOOL opj_j2k_write_mct_data_group( opj_j2k_t *p_j2k, 4832 static OPJ_BOOL opj_j2k_write_mct_data_group( opj_j2k_t *p_j2k,
4890 struct o pj_stream_private *p_stream, 4833 struct o pj_stream_private *p_stream,
4891 struct o pj_event_mgr * p_manager ) 4834 struct o pj_event_mgr * p_manager )
4892 { 4835 {
4893 OPJ_UINT32 i; 4836 OPJ_UINT32 i;
4894 opj_simple_mcc_decorrelation_data_t * l_mcc_record; 4837 opj_simple_mcc_decorrelation_data_t * l_mcc_record;
4895 opj_mct_data_t * l_mct_record; 4838 opj_mct_data_t * l_mct_record;
4896 opj_tcp_t * l_tcp; 4839 opj_tcp_t * l_tcp;
4897 4840
4898 /* preconditions */ 4841 /* preconditions */
4899 assert(p_j2k != 00); 4842 assert(p_j2k != 00);
(...skipping 28 matching lines...) Expand all
4928 } 4871 }
4929 4872
4930 if (! opj_j2k_write_mco(p_j2k,p_stream,p_manager)) { 4873 if (! opj_j2k_write_mco(p_j2k,p_stream,p_manager)) {
4931 return OPJ_FALSE; 4874 return OPJ_FALSE;
4932 } 4875 }
4933 4876
4934 return OPJ_TRUE; 4877 return OPJ_TRUE;
4935 } 4878 }
4936 4879
4937 #if 0 4880 #if 0
4938 OPJ_BOOL opj_j2k_write_all_coc(opj_j2k_t *p_j2k, 4881 static OPJ_BOOL opj_j2k_write_all_coc(opj_j2k_t *p_j2k,
4939 struct o pj_stream_private *p_stream, 4882 struct o pj_stream_private *p_stream,
4940 struct o pj_event_mgr * p_manager ) 4883 struct o pj_event_mgr * p_manager )
4941 { 4884 {
4942 OPJ_UINT32 compno; 4885 OPJ_UINT32 compno;
4943 4886
4944 /* preconditions */ 4887 /* preconditions */
4945 assert(p_j2k != 00); 4888 assert(p_j2k != 00);
4946 assert(p_manager != 00); 4889 assert(p_manager != 00);
4947 assert(p_stream != 00); 4890 assert(p_stream != 00);
4948 4891
4949 for (compno = 0; compno < p_j2k->m_private_image->numcomps; ++compno) 4892 for (compno = 0; compno < p_j2k->m_private_image->numcomps; ++compno)
4950 { 4893 {
4951 if (! opj_j2k_write_coc(p_j2k,compno,p_stream, p_manager)) { 4894 if (! opj_j2k_write_coc(p_j2k,compno,p_stream, p_manager)) {
4952 return OPJ_FALSE; 4895 return OPJ_FALSE;
4953 } 4896 }
4954 } 4897 }
4955 4898
4956 return OPJ_TRUE; 4899 return OPJ_TRUE;
4957 } 4900 }
4958 #endif 4901 #endif
4959 4902
4960 #if 0 4903 #if 0
4961 OPJ_BOOL opj_j2k_write_all_qcc(opj_j2k_t *p_j2k, 4904 static OPJ_BOOL opj_j2k_write_all_qcc(opj_j2k_t *p_j2k,
4962 struct o pj_stream_private *p_stream, 4905 struct o pj_stream_private *p_stream,
4963 struct o pj_event_mgr * p_manager ) 4906 struct o pj_event_mgr * p_manager )
4964 { 4907 {
4965 OPJ_UINT32 compno; 4908 OPJ_UINT32 compno;
4966 4909
4967 /* preconditions */ 4910 /* preconditions */
4968 assert(p_j2k != 00); 4911 assert(p_j2k != 00);
4969 assert(p_manager != 00); 4912 assert(p_manager != 00);
4970 assert(p_stream != 00); 4913 assert(p_stream != 00);
4971 4914
4972 for (compno = 0; compno < p_j2k->m_private_image->numcomps; ++compno) 4915 for (compno = 0; compno < p_j2k->m_private_image->numcomps; ++compno)
4973 { 4916 {
4974 if (! opj_j2k_write_qcc(p_j2k,compno,p_stream, p_manager)) { 4917 if (! opj_j2k_write_qcc(p_j2k,compno,p_stream, p_manager)) {
4975 return OPJ_FALSE; 4918 return OPJ_FALSE;
4976 } 4919 }
4977 } 4920 }
4978 4921
4979 return OPJ_TRUE; 4922 return OPJ_TRUE;
4980 } 4923 }
4981 #endif 4924 #endif
4982 4925
4983 4926
4984 OPJ_BOOL opj_j2k_write_regions( opj_j2k_t *p_j2k, 4927 static OPJ_BOOL opj_j2k_write_regions( opj_j2k_t *p_j2k,
4985 struct opj_stream_privat e *p_stream, 4928 struct opj_stream_privat e *p_stream,
4986 struct opj_event_mgr * p _manager ) 4929 struct opj_event_mgr * p _manager )
4987 { 4930 {
4988 OPJ_UINT32 compno; 4931 OPJ_UINT32 compno;
4989 const opj_tccp_t *l_tccp = 00; 4932 const opj_tccp_t *l_tccp = 00;
4990 4933
4991 /* preconditions */ 4934 /* preconditions */
4992 assert(p_j2k != 00); 4935 assert(p_j2k != 00);
4993 assert(p_manager != 00); 4936 assert(p_manager != 00);
4994 assert(p_stream != 00); 4937 assert(p_stream != 00);
4995 4938
4996 l_tccp = p_j2k->m_cp.tcps->tccps; 4939 l_tccp = p_j2k->m_cp.tcps->tccps;
4997 4940
4998 for (compno = 0; compno < p_j2k->m_private_image->numcomps; ++compno ) { 4941 for (compno = 0; compno < p_j2k->m_private_image->numcomps; ++compno) {
4999 if (l_tccp->roishift) { 4942 if (l_tccp->roishift) {
5000 4943
5001 if (! opj_j2k_write_rgn(p_j2k,0,compno,p_j2k->m_private_ image->numcomps,p_stream,p_manager)) { 4944 if (! opj_j2k_write_rgn(p_j2k,0,compno,p_j2k->m_private_ image->numcomps,p_stream,p_manager)) {
5002 return OPJ_FALSE; 4945 return OPJ_FALSE;
5003 } 4946 }
5004 } 4947 }
5005 4948
5006 ++l_tccp; 4949 ++l_tccp;
5007 } 4950 }
5008 4951
5009 return OPJ_TRUE; 4952 return OPJ_TRUE;
5010 } 4953 }
5011 4954
5012 OPJ_BOOL opj_j2k_write_epc( opj_j2k_t *p_j2k, 4955 static OPJ_BOOL opj_j2k_write_epc( opj_j2k_t *p_j2k,
5013 struct opj_stream_private *p_str eam, 4956 struct opj_stream_private *p_str eam,
5014 struct opj_event_mgr * p_manager ) 4957 struct opj_event_mgr * p_manager )
5015 { 4958 {
5016 opj_codestream_index_t * l_cstr_index = 00; 4959 opj_codestream_index_t * l_cstr_index = 00;
5017 4960
5018 /* preconditions */ 4961 /* preconditions */
5019 assert(p_j2k != 00); 4962 assert(p_j2k != 00);
5020 assert(p_manager != 00); 4963 assert(p_manager != 00);
5021 assert(p_stream != 00); 4964 assert(p_stream != 00);
5022 4965
(...skipping 17 matching lines...) Expand all
5040 jpwl_encode(p_j2k, p_stream, image); 4983 jpwl_encode(p_j2k, p_stream, image);
5041 4984
5042 } 4985 }
5043 #endif 4986 #endif
5044 assert( 0 && "TODO" ); 4987 assert( 0 && "TODO" );
5045 #endif /* USE_JPWL */ 4988 #endif /* USE_JPWL */
5046 4989
5047 return OPJ_TRUE; 4990 return OPJ_TRUE;
5048 } 4991 }
5049 4992
5050 OPJ_BOOL opj_j2k_read_unk ( opj_j2k_t *p_j2k, 4993 static OPJ_BOOL opj_j2k_read_unk ( opj_j2k_t *p_j2k,
5051 opj_stream_private_t *p_ stream, 4994 opj_stream_private_t *p_ stream,
5052 OPJ_UINT32 *output_marke r, 4995 OPJ_UINT32 *output_marke r,
5053 opj_event_mgr_t * p_mana ger 4996 opj_event_mgr_t * p_mana ger
5054 ) 4997 )
5055 { 4998 {
5056 OPJ_UINT32 l_unknown_marker; 4999 OPJ_UINT32 l_unknown_marker;
5057 const opj_dec_memory_marker_handler_t * l_marker_handler; 5000 const opj_dec_memory_marker_handler_t * l_marker_handler;
5058 OPJ_UINT32 l_size_unk = 2; 5001 OPJ_UINT32 l_size_unk = 2;
5059 5002
5060 /* preconditions*/ 5003 /* preconditions*/
5061 assert(p_j2k != 00); 5004 assert(p_j2k != 00);
5062 assert(p_manager != 00); 5005 assert(p_manager != 00);
5063 assert(p_stream != 00); 5006 assert(p_stream != 00);
5064 5007
5065 opj_event_msg(p_manager, EVT_WARNING, "Unknown marker\n"); 5008 opj_event_msg(p_manager, EVT_WARNING, "Unknown marker\n");
5066 5009
5067 while(1) { 5010 » » for (;;) {
5068 /* Try to read 2 bytes (the next marker ID) from stream and copy them into the buffer*/ 5011 /* Try to read 2 bytes (the next marker ID) from stream and copy them into the buffer*/
5069 if (opj_stream_read_data(p_stream,p_j2k->m_specific_param.m_deco der.m_header_data,2,p_manager) != 2) { 5012 if (opj_stream_read_data(p_stream,p_j2k->m_specific_param.m_deco der.m_header_data,2,p_manager) != 2) {
5070 opj_event_msg(p_manager, EVT_ERROR, "Stream too short\n" ); 5013 opj_event_msg(p_manager, EVT_ERROR, "Stream too short\n" );
5071 return OPJ_FALSE; 5014 return OPJ_FALSE;
5072 } 5015 }
5073 5016
5074 /* read 2 bytes as the new marker ID*/ 5017 /* read 2 bytes as the new marker ID*/
5075 opj_read_bytes(p_j2k->m_specific_param.m_decoder.m_header_data,& l_unknown_marker,2); 5018 opj_read_bytes(p_j2k->m_specific_param.m_decoder.m_header_data,& l_unknown_marker,2);
5076 5019
5077 if (!(l_unknown_marker < 0xff00)) { 5020 if (!(l_unknown_marker < 0xff00)) {
(...skipping 24 matching lines...) Expand all
5102 l_size_unk += 2; 5045 l_size_unk += 2;
5103 } 5046 }
5104 } 5047 }
5105 } 5048 }
5106 5049
5107 *output_marker = l_marker_handler->id ; 5050 *output_marker = l_marker_handler->id ;
5108 5051
5109 return OPJ_TRUE; 5052 return OPJ_TRUE;
5110 } 5053 }
5111 5054
5112 OPJ_BOOL opj_j2k_write_mct_record( opj_j2k_t *p_j2k, 5055 static OPJ_BOOL opj_j2k_write_mct_record( opj_j2k_t *p_j2k,
5113 opj_mct_data_t * p_mct_record, 5056 opj_mct_data_t * p_mct_record,
5114 struct opj_strea m_private *p_stream, 5057 struct opj_strea m_private *p_stream,
5115 struct opj_event _mgr * p_manager ) 5058 struct opj_event _mgr * p_manager )
5116 { 5059 {
5117 OPJ_UINT32 l_mct_size; 5060 OPJ_UINT32 l_mct_size;
5118 OPJ_BYTE * l_current_data = 00; 5061 OPJ_BYTE * l_current_data = 00;
5119 OPJ_UINT32 l_tmp; 5062 OPJ_UINT32 l_tmp;
5120 5063
5121 /* preconditions */ 5064 /* preconditions */
5122 assert(p_j2k != 00); 5065 assert(p_j2k != 00);
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after
5274 opj_event_msg(p_manager, EVT_ERROR, "Error reading MCT marker\n" ); 5217 opj_event_msg(p_manager, EVT_ERROR, "Error reading MCT marker\n" );
5275 return OPJ_FALSE; 5218 return OPJ_FALSE;
5276 } 5219 }
5277 memcpy(l_mct_data->m_data,p_header_data,p_header_size); 5220 memcpy(l_mct_data->m_data,p_header_data,p_header_size);
5278 5221
5279 l_mct_data->m_data_size = p_header_size; 5222 l_mct_data->m_data_size = p_header_size;
5280 5223
5281 return OPJ_TRUE; 5224 return OPJ_TRUE;
5282 } 5225 }
5283 5226
5284 OPJ_BOOL opj_j2k_write_mcc_record( opj_j2k_t *p_j2k, 5227 static OPJ_BOOL opj_j2k_write_mcc_record( opj_j2k_t *p_j2k,
5285 struct opj_simpl e_mcc_decorrelation_data * p_mcc_record, 5228 struct opj_simpl e_mcc_decorrelation_data * p_mcc_record,
5286 struct opj_strea m_private *p_stream, 5229 struct opj_strea m_private *p_stream,
5287 struct opj_event _mgr * p_manager ) 5230 struct opj_event _mgr * p_manager )
5288 { 5231 {
5289 OPJ_UINT32 i; 5232 OPJ_UINT32 i;
5290 OPJ_UINT32 l_mcc_size; 5233 OPJ_UINT32 l_mcc_size;
5291 OPJ_BYTE * l_current_data = 00; 5234 OPJ_BYTE * l_current_data = 00;
5292 OPJ_UINT32 l_nb_bytes_for_comp; 5235 OPJ_UINT32 l_nb_bytes_for_comp;
5293 OPJ_UINT32 l_mask; 5236 OPJ_UINT32 l_mask;
5294 OPJ_UINT32 l_tmcc; 5237 OPJ_UINT32 l_tmcc;
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
5377 opj_write_bytes(l_current_data,l_tmcc,3); /* Tmcci : use MCT defin ed as number 1 and irreversible array based. */ 5320 opj_write_bytes(l_current_data,l_tmcc,3); /* Tmcci : use MCT defin ed as number 1 and irreversible array based. */
5378 l_current_data+=3; 5321 l_current_data+=3;
5379 5322
5380 if (opj_stream_write_data(p_stream,p_j2k->m_specific_param.m_encoder.m_h eader_tile_data,l_mcc_size,p_manager) != l_mcc_size) { 5323 if (opj_stream_write_data(p_stream,p_j2k->m_specific_param.m_encoder.m_h eader_tile_data,l_mcc_size,p_manager) != l_mcc_size) {
5381 return OPJ_FALSE; 5324 return OPJ_FALSE;
5382 } 5325 }
5383 5326
5384 return OPJ_TRUE; 5327 return OPJ_TRUE;
5385 } 5328 }
5386 5329
5387 OPJ_BOOL opj_j2k_read_mcc ( opj_j2k_t *p_j2k, 5330 static OPJ_BOOL opj_j2k_read_mcc ( opj_j2k_t *p_j2k,
5388 OPJ_BYTE * p_header_data, 5331 OPJ_BYTE * p_header_data,
5389 OPJ_UINT32 p_header_size, 5332 OPJ_UINT32 p_header_size,
5390 opj_event_mgr_t * p_manager ) 5333 opj_event_mgr_t * p_manager )
5391 { 5334 {
5392 OPJ_UINT32 i,j; 5335 OPJ_UINT32 i,j;
5393 OPJ_UINT32 l_tmp; 5336 OPJ_UINT32 l_tmp;
5394 OPJ_UINT32 l_indix; 5337 OPJ_UINT32 l_indix;
5395 opj_tcp_t * l_tcp; 5338 opj_tcp_t * l_tcp;
5396 opj_simple_mcc_decorrelation_data_t * l_mcc_record; 5339 opj_simple_mcc_decorrelation_data_t * l_mcc_record;
5397 opj_mct_data_t * l_mct_data; 5340 opj_mct_data_t * l_mct_data;
(...skipping 194 matching lines...) Expand 10 before | Expand all | Expand 10 after
5592 if (p_header_size != 0) { 5535 if (p_header_size != 0) {
5593 opj_event_msg(p_manager, EVT_ERROR, "Error reading MCC marker\n" ); 5536 opj_event_msg(p_manager, EVT_ERROR, "Error reading MCC marker\n" );
5594 return OPJ_FALSE; 5537 return OPJ_FALSE;
5595 } 5538 }
5596 5539
5597 ++l_tcp->m_nb_mcc_records; 5540 ++l_tcp->m_nb_mcc_records;
5598 5541
5599 return OPJ_TRUE; 5542 return OPJ_TRUE;
5600 } 5543 }
5601 5544
5602 OPJ_BOOL opj_j2k_write_mco( opj_j2k_t *p_j2k, 5545 static OPJ_BOOL opj_j2k_write_mco( opj_j2k_t *p_j2k,
5603 struct opj_stream_private *p_str eam, 5546 struct opj_stream_private *p_str eam,
5604 struct opj_event_mgr * p_manager 5547 struct opj_event_mgr * p_manager
5605 ) 5548 )
5606 { 5549 {
5607 OPJ_BYTE * l_current_data = 00; 5550 OPJ_BYTE * l_current_data = 00;
5608 OPJ_UINT32 l_mco_size; 5551 OPJ_UINT32 l_mco_size;
5609 opj_tcp_t * l_tcp = 00; 5552 opj_tcp_t * l_tcp = 00;
5610 opj_simple_mcc_decorrelation_data_t * l_mcc_record; 5553 opj_simple_mcc_decorrelation_data_t * l_mcc_record;
5611 OPJ_UINT32 i; 5554 OPJ_UINT32 i;
5612 5555
5613 /* preconditions */ 5556 /* preconditions */
5614 assert(p_j2k != 00); 5557 assert(p_j2k != 00);
5615 assert(p_manager != 00); 5558 assert(p_manager != 00);
5616 assert(p_stream != 00); 5559 assert(p_stream != 00);
5617 5560
5618 l_tcp =&(p_j2k->m_cp.tcps[p_j2k->m_current_tile_number]); 5561 l_tcp =&(p_j2k->m_cp.tcps[p_j2k->m_current_tile_number]);
5619 l_current_data = p_j2k->m_specific_param.m_encoder.m_header_tile_data; 5562 »
5620
5621 l_mco_size = 5 + l_tcp->m_nb_mcc_records; 5563 l_mco_size = 5 + l_tcp->m_nb_mcc_records;
5622 if (l_mco_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_si ze) { 5564 if (l_mco_size > p_j2k->m_specific_param.m_encoder.m_header_tile_data_si ze) {
5623 5565
5624 OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k- >m_specific_param.m_encoder.m_header_tile_data, l_mco_size); 5566 OPJ_BYTE *new_header_tile_data = (OPJ_BYTE *) opj_realloc(p_j2k- >m_specific_param.m_encoder.m_header_tile_data, l_mco_size);
5625 if (! new_header_tile_data) { 5567 if (! new_header_tile_data) {
5626 opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile _data); 5568 opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile _data);
5627 p_j2k->m_specific_param.m_encoder.m_header_tile_data = N ULL; 5569 p_j2k->m_specific_param.m_encoder.m_header_tile_data = N ULL;
5628 p_j2k->m_specific_param.m_encoder.m_header_tile_data_siz e = 0; 5570 p_j2k->m_specific_param.m_encoder.m_header_tile_data_siz e = 0;
5629 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory t o write MCO marker\n"); 5571 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory t o write MCO marker\n");
5630 return OPJ_FALSE; 5572 return OPJ_FALSE;
5631 } 5573 }
5632 p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_heade r_tile_data; 5574 p_j2k->m_specific_param.m_encoder.m_header_tile_data = new_heade r_tile_data;
5633 p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_mc o_size; 5575 p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = l_mc o_size;
5634 } 5576 }
5577 l_current_data = p_j2k->m_specific_param.m_encoder.m_header_tile_data;
5578
5635 5579
5636 opj_write_bytes(l_current_data,J2K_MS_MCO,2); /* MCO * / 5580 opj_write_bytes(l_current_data,J2K_MS_MCO,2); /* MCO * /
5637 l_current_data += 2; 5581 l_current_data += 2;
5638 5582
5639 opj_write_bytes(l_current_data,l_mco_size-2,2); /* Lmco */ 5583 opj_write_bytes(l_current_data,l_mco_size-2,2); /* Lmco */
5640 l_current_data += 2; 5584 l_current_data += 2;
5641 5585
5642 opj_write_bytes(l_current_data,l_tcp->m_nb_mcc_records,1); /* Nmco : only one tranform stage*/ 5586 opj_write_bytes(l_current_data,l_tcp->m_nb_mcc_records,1); /* Nmco : only one transform stage*/
5643 ++l_current_data; 5587 ++l_current_data;
5644 5588
5645 l_mcc_record = l_tcp->m_mcc_records; 5589 l_mcc_record = l_tcp->m_mcc_records;
5646 for (i=0;i<l_tcp->m_nb_mcc_records;++i) { 5590 for (i=0;i<l_tcp->m_nb_mcc_records;++i) {
5647 opj_write_bytes(l_current_data,l_mcc_record->m_index,1);/* Imco -> use the mcc indicated by 1*/ 5591 opj_write_bytes(l_current_data,l_mcc_record->m_index,1);/* Imco -> use the mcc indicated by 1*/
5648 ++l_current_data; 5592 ++l_current_data;
5649
5650 ++l_mcc_record; 5593 ++l_mcc_record;
5651 } 5594 }
5652 5595
5653 if (opj_stream_write_data(p_stream,p_j2k->m_specific_param.m_encoder.m_h eader_tile_data,l_mco_size,p_manager) != l_mco_size) { 5596 if (opj_stream_write_data(p_stream,p_j2k->m_specific_param.m_encoder.m_h eader_tile_data,l_mco_size,p_manager) != l_mco_size) {
5654 return OPJ_FALSE; 5597 return OPJ_FALSE;
5655 } 5598 }
5656 5599
5657 return OPJ_TRUE; 5600 return OPJ_TRUE;
5658 } 5601 }
5659 5602
(...skipping 25 matching lines...) Expand all
5685 l_image = p_j2k->m_private_image; 5628 l_image = p_j2k->m_private_image;
5686 l_tcp = p_j2k->m_specific_param.m_decoder.m_state == J2K_STATE_TPH ? 5629 l_tcp = p_j2k->m_specific_param.m_decoder.m_state == J2K_STATE_TPH ?
5687 &p_j2k->m_cp.tcps[p_j2k->m_current_tile_number] : 5630 &p_j2k->m_cp.tcps[p_j2k->m_current_tile_number] :
5688 p_j2k->m_specific_param.m_decoder.m_default_tcp; 5631 p_j2k->m_specific_param.m_decoder.m_default_tcp;
5689 5632
5690 if (p_header_size < 1) { 5633 if (p_header_size < 1) {
5691 opj_event_msg(p_manager, EVT_ERROR, "Error reading MCO marker\n" ); 5634 opj_event_msg(p_manager, EVT_ERROR, "Error reading MCO marker\n" );
5692 return OPJ_FALSE; 5635 return OPJ_FALSE;
5693 } 5636 }
5694 5637
5695 opj_read_bytes(p_header_data,&l_nb_stages,1); /* Nmco : only one tranform stage*/ 5638 opj_read_bytes(p_header_data,&l_nb_stages,1); /* Nmco : only one transform stage*/
5696 ++p_header_data; 5639 ++p_header_data;
5697 5640
5698 if (l_nb_stages > 1) { 5641 if (l_nb_stages > 1) {
5699 opj_event_msg(p_manager, EVT_WARNING, "Cannot take in charge mul tiple transformation stages.\n"); 5642 opj_event_msg(p_manager, EVT_WARNING, "Cannot take in charge mul tiple transformation stages.\n");
5700 return OPJ_TRUE; 5643 return OPJ_TRUE;
5701 } 5644 }
5702 5645
5703 if (p_header_size != l_nb_stages + 1) { 5646 if (p_header_size != l_nb_stages + 1) {
5704 opj_event_msg(p_manager, EVT_WARNING, "Error reading MCO marker\ n"); 5647 opj_event_msg(p_manager, EVT_WARNING, "Error reading MCO marker\ n");
5705 return OPJ_FALSE; 5648 return OPJ_FALSE;
(...skipping 16 matching lines...) Expand all
5722 ++p_header_data; 5665 ++p_header_data;
5723 5666
5724 if (! opj_j2k_add_mct(l_tcp,p_j2k->m_private_image,l_tmp)) { 5667 if (! opj_j2k_add_mct(l_tcp,p_j2k->m_private_image,l_tmp)) {
5725 return OPJ_FALSE; 5668 return OPJ_FALSE;
5726 } 5669 }
5727 } 5670 }
5728 5671
5729 return OPJ_TRUE; 5672 return OPJ_TRUE;
5730 } 5673 }
5731 5674
5732 OPJ_BOOL opj_j2k_add_mct(opj_tcp_t * p_tcp, opj_image_t * p_image, OPJ_UINT32 p_ index) 5675 static OPJ_BOOL opj_j2k_add_mct(opj_tcp_t * p_tcp, opj_image_t * p_image, OPJ_UI NT32 p_index)
5733 { 5676 {
5734 OPJ_UINT32 i; 5677 OPJ_UINT32 i;
5735 opj_simple_mcc_decorrelation_data_t * l_mcc_record; 5678 opj_simple_mcc_decorrelation_data_t * l_mcc_record;
5736 opj_mct_data_t * l_deco_array, * l_offset_array; 5679 opj_mct_data_t * l_deco_array, * l_offset_array;
5737 OPJ_UINT32 l_data_size,l_mct_size, l_offset_size; 5680 OPJ_UINT32 l_data_size,l_mct_size, l_offset_size;
5738 OPJ_UINT32 l_nb_elem; 5681 OPJ_UINT32 l_nb_elem;
5739 OPJ_UINT32 * l_offset_data, * l_current_offset_data; 5682 OPJ_UINT32 * l_offset_data, * l_current_offset_data;
5740 opj_tccp_t * l_tccp; 5683 opj_tccp_t * l_tccp;
5741 5684
5742 /* preconditions */ 5685 /* preconditions */
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
5804 l_tccp->m_dc_level_shift = (OPJ_INT32)*(l_current_offset _data++); 5747 l_tccp->m_dc_level_shift = (OPJ_INT32)*(l_current_offset _data++);
5805 ++l_tccp; 5748 ++l_tccp;
5806 } 5749 }
5807 5750
5808 opj_free(l_offset_data); 5751 opj_free(l_offset_data);
5809 } 5752 }
5810 5753
5811 return OPJ_TRUE; 5754 return OPJ_TRUE;
5812 } 5755 }
5813 5756
5814 OPJ_BOOL opj_j2k_write_cbd( opj_j2k_t *p_j2k, 5757 static OPJ_BOOL opj_j2k_write_cbd( opj_j2k_t *p_j2k,
5815 struct opj_stream_private *p_str eam, 5758 struct opj_stream_private *p_str eam,
5816 struct opj_event_mgr * p_manager ) 5759 struct opj_event_mgr * p_manager )
5817 { 5760 {
5818 OPJ_UINT32 i; 5761 OPJ_UINT32 i;
5819 OPJ_UINT32 l_cbd_size; 5762 OPJ_UINT32 l_cbd_size;
5820 OPJ_BYTE * l_current_data = 00; 5763 OPJ_BYTE * l_current_data = 00;
5821 opj_image_t *l_image = 00; 5764 opj_image_t *l_image = 00;
5822 opj_image_comp_t * l_comp = 00; 5765 opj_image_comp_t * l_comp = 00;
5823 5766
5824 /* preconditions */ 5767 /* preconditions */
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
5970 /* execution list creation*/ 5913 /* execution list creation*/
5971 l_j2k->m_procedure_list = opj_procedure_list_create(); 5914 l_j2k->m_procedure_list = opj_procedure_list_create();
5972 if (! l_j2k->m_procedure_list) { 5915 if (! l_j2k->m_procedure_list) {
5973 opj_j2k_destroy(l_j2k); 5916 opj_j2k_destroy(l_j2k);
5974 return NULL; 5917 return NULL;
5975 } 5918 }
5976 5919
5977 return l_j2k; 5920 return l_j2k;
5978 } 5921 }
5979 5922
5980 int opj_j2k_initialise_4K_poc(opj_poc_t *POC, int numres){ 5923 static int opj_j2k_initialise_4K_poc(opj_poc_t *POC, int numres){
5981 POC[0].tile = 1; 5924 POC[0].tile = 1;
5982 POC[0].resno0 = 0; 5925 POC[0].resno0 = 0;
5983 POC[0].compno0 = 0; 5926 POC[0].compno0 = 0;
5984 POC[0].layno1 = 1; 5927 POC[0].layno1 = 1;
5985 POC[0].resno1 = (OPJ_UINT32)(numres-1); 5928 POC[0].resno1 = (OPJ_UINT32)(numres-1);
5986 POC[0].compno1 = 3; 5929 POC[0].compno1 = 3;
5987 POC[0].prg1 = OPJ_CPRL; 5930 POC[0].prg1 = OPJ_CPRL;
5988 POC[1].tile = 1; 5931 POC[1].tile = 1;
5989 POC[1].resno0 = (OPJ_UINT32)(numres-1); 5932 POC[1].resno0 = (OPJ_UINT32)(numres-1);
5990 POC[1].compno0 = 0; 5933 POC[1].compno0 = 0;
5991 POC[1].layno1 = 1; 5934 POC[1].layno1 = 1;
5992 POC[1].resno1 = (OPJ_UINT32)numres; 5935 POC[1].resno1 = (OPJ_UINT32)numres;
5993 POC[1].compno1 = 3; 5936 POC[1].compno1 = 3;
5994 POC[1].prg1 = OPJ_CPRL; 5937 POC[1].prg1 = OPJ_CPRL;
5995 return 2; 5938 return 2;
5996 } 5939 }
5997 5940
5998 void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_image_t *i mage, opj_event_mgr_t *p_manager) 5941 static void opj_j2k_set_cinema_parameters(opj_cparameters_t *parameters, opj_ima ge_t *image, opj_event_mgr_t *p_manager)
5999 { 5942 {
6000 /* Configure cinema parameters */ 5943 /* Configure cinema parameters */
6001 int i; 5944 int i;
6002 5945
6003 /* No tiling */ 5946 /* No tiling */
6004 parameters->tile_size_on = OPJ_FALSE; 5947 parameters->tile_size_on = OPJ_FALSE;
6005 parameters->cp_tdx=1; 5948 parameters->cp_tdx=1;
6006 parameters->cp_tdy=1; 5949 parameters->cp_tdy=1;
6007 5950
6008 /* One tile part for each component */ 5951 /* One tile part for each component */
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after
6125 "Maximum 1041666 compressed bytes @ 24fps\n" 6068 "Maximum 1041666 compressed bytes @ 24fps\n"
6126 "-> Specified rate exceeds this limit. Rate will be forced to 1041666 bytes.\n"); 6069 "-> Specified rate exceeds this limit. Rate will be forced to 1041666 bytes.\n");
6127 parameters->max_comp_size = OPJ_CINEMA_24_COMP; 6070 parameters->max_comp_size = OPJ_CINEMA_24_COMP;
6128 } 6071 }
6129 6072
6130 parameters->tcp_rates[0] = (OPJ_FLOAT32) (image->numcomps * image->comps[0]. w * image->comps[0].h * image->comps[0].prec)/ 6073 parameters->tcp_rates[0] = (OPJ_FLOAT32) (image->numcomps * image->comps[0]. w * image->comps[0].h * image->comps[0].prec)/
6131 (OPJ_FLOAT32)(((OPJ_UINT32)parameters->max_cs_size) * 8 * image->com ps[0].dx * image->comps[0].dy); 6074 (OPJ_FLOAT32)(((OPJ_UINT32)parameters->max_cs_size) * 8 * image->com ps[0].dx * image->comps[0].dy);
6132 6075
6133 } 6076 }
6134 6077
6135 OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_UINT16 rsiz, opj_ev ent_mgr_t *p_manager) 6078 static OPJ_BOOL opj_j2k_is_cinema_compliant(opj_image_t *image, OPJ_UINT16 rsiz, opj_event_mgr_t *p_manager)
6136 { 6079 {
6137 OPJ_UINT32 i; 6080 OPJ_UINT32 i;
6138 6081
6139 /* Number of components */ 6082 /* Number of components */
6140 if (image->numcomps != 3){ 6083 if (image->numcomps != 3){
6141 opj_event_msg(p_manager, EVT_WARNING, 6084 opj_event_msg(p_manager, EVT_WARNING,
6142 "JPEG 2000 Profile-3 (2k dc profile) requires:\n" 6085 "JPEG 2000 Profile-3 (2k dc profile) requires:\n"
6143 "3 components" 6086 "3 components"
6144 "-> Number of components of input image (%d) is not compliant\n" 6087 "-> Number of components of input image (%d) is not compliant\n"
6145 "-> Non-profile-3 codestream will be generated\n", 6088 "-> Non-profile-3 codestream will be generated\n",
(...skipping 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
6790 assert(p_stream != 00); 6733 assert(p_stream != 00);
6791 assert(p_manager != 00); 6734 assert(p_manager != 00);
6792 6735
6793 /* create an empty image header */ 6736 /* create an empty image header */
6794 p_j2k->m_private_image = opj_image_create0(); 6737 p_j2k->m_private_image = opj_image_create0();
6795 if (! p_j2k->m_private_image) { 6738 if (! p_j2k->m_private_image) {
6796 return OPJ_FALSE; 6739 return OPJ_FALSE;
6797 } 6740 }
6798 6741
6799 /* customization of the validation */ 6742 /* customization of the validation */
6800 opj_j2k_setup_decoding_validation(p_j2k); 6743 if (! opj_j2k_setup_decoding_validation(p_j2k, p_manager)) {
6744 opj_image_destroy(p_j2k->m_private_image);
6745 p_j2k->m_private_image = NULL;
6746 return OPJ_FALSE;
6747 }
6801 6748
6802 /* validation of the parameters codec */ 6749 /* validation of the parameters codec */
6803 if (! opj_j2k_exec(p_j2k, p_j2k->m_validation_list, p_stream,p_manager)) { 6750 if (! opj_j2k_exec(p_j2k, p_j2k->m_validation_list, p_stream,p_manager)) {
6804 opj_image_destroy(p_j2k->m_private_image); 6751 opj_image_destroy(p_j2k->m_private_image);
6805 p_j2k->m_private_image = NULL; 6752 p_j2k->m_private_image = NULL;
6806 return OPJ_FALSE; 6753 return OPJ_FALSE;
6807 } 6754 }
6808 6755
6809 /* customization of the encoding */ 6756 /* customization of the encoding */
6810 opj_j2k_setup_header_reading(p_j2k); 6757 if (! opj_j2k_setup_header_reading(p_j2k, p_manager)) {
6758 opj_image_destroy(p_j2k->m_private_image);
6759 p_j2k->m_private_image = NULL;
6760 return OPJ_FALSE;
6761 }
6811 6762
6812 /* read header */ 6763 /* read header */
6813 if (! opj_j2k_exec (p_j2k,p_j2k->m_procedure_list,p_stream,p_manager)) { 6764 if (! opj_j2k_exec (p_j2k,p_j2k->m_procedure_list,p_stream,p_manager)) {
6814 opj_image_destroy(p_j2k->m_private_image); 6765 opj_image_destroy(p_j2k->m_private_image);
6815 p_j2k->m_private_image = NULL; 6766 p_j2k->m_private_image = NULL;
6816 return OPJ_FALSE; 6767 return OPJ_FALSE;
6817 } 6768 }
6818 6769
6819 *p_image = opj_image_create0(); 6770 *p_image = opj_image_create0();
6820 if (! (*p_image)) { 6771 if (! (*p_image)) {
6821 return OPJ_FALSE; 6772 return OPJ_FALSE;
6822 } 6773 }
6823 6774
6824 /* Copy codestream image information to the output image */ 6775 /* Copy codestream image information to the output image */
6825 opj_copy_image_header(p_j2k->m_private_image, *p_image); 6776 opj_copy_image_header(p_j2k->m_private_image, *p_image);
6826 6777
6827 /*Allocate and initialize some elements of codestrem index*/ 6778 /*Allocate and initialize some elements of codestrem index*/
6828 if (!opj_j2k_allocate_tile_element_cstr_index(p_j2k)){ 6779 if (!opj_j2k_allocate_tile_element_cstr_index(p_j2k)){
6829 return OPJ_FALSE; 6780 return OPJ_FALSE;
6830 } 6781 }
6831 6782
6832 return OPJ_TRUE; 6783 return OPJ_TRUE;
6833 } 6784 }
6834 6785
6835 void opj_j2k_setup_header_reading (opj_j2k_t *p_j2k) 6786 static OPJ_BOOL opj_j2k_setup_header_reading (opj_j2k_t *p_j2k, opj_event_mgr_t * p_manager)
6836 { 6787 {
6837 /* preconditions*/ 6788 /* preconditions*/
6838 assert(p_j2k != 00); 6789 assert(p_j2k != 00);
6790 assert(p_manager != 00);
6839 6791
6840 opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure) opj_j2k_read_header_procedure); 6792 if (! opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_proc edure)opj_j2k_read_header_procedure, p_manager)) {
6793 return OPJ_FALSE;
6794 }
6841 6795
6842 /* DEVELOPER CORNER, add your custom procedures */ 6796 /* DEVELOPER CORNER, add your custom procedures */
6843 opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure) opj_j2k_copy_default_tcp_and_create_tcd); 6797 if (! opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_proc edure)opj_j2k_copy_default_tcp_and_create_tcd, p_manager)) {
6844 6798 return OPJ_FALSE;
6799 }
6800 »
6801 return OPJ_TRUE;
6845 } 6802 }
6846 6803
6847 void opj_j2k_setup_decoding_validation (opj_j2k_t *p_j2k) 6804 static OPJ_BOOL opj_j2k_setup_decoding_validation (opj_j2k_t *p_j2k, opj_event_m gr_t * p_manager)
6848 { 6805 {
6849 /* preconditions*/ 6806 /* preconditions*/
6850 assert(p_j2k != 00); 6807 assert(p_j2k != 00);
6808 assert(p_manager != 00);
6851 6809
6852 opj_procedure_list_add_procedure(p_j2k->m_validation_list, (opj_procedur e)opj_j2k_build_decoder); 6810 if (! opj_procedure_list_add_procedure(p_j2k->m_validation_list,(opj_pro cedure)opj_j2k_build_decoder, p_manager)) {
6853 opj_procedure_list_add_procedure(p_j2k->m_validation_list, (opj_procedur e)opj_j2k_decoding_validation); 6811 return OPJ_FALSE;
6812 }
6813 if (! opj_procedure_list_add_procedure(p_j2k->m_validation_list,(opj_pro cedure)opj_j2k_decoding_validation, p_manager)) {
6814 return OPJ_FALSE;
6815 }
6816
6854 /* DEVELOPER CORNER, add your custom validation procedure */ 6817 /* DEVELOPER CORNER, add your custom validation procedure */
6855 6818 return OPJ_TRUE;
6856 } 6819 }
6857 6820
6858 OPJ_BOOL opj_j2k_mct_validation ( opj_j2k_t * p_j2k, 6821 static OPJ_BOOL opj_j2k_mct_validation ( opj_j2k_t * p_j2k,
6859 opj_stream_priva te_t *p_stream, 6822 opj_stream_priva te_t *p_stream,
6860 opj_event_mgr_t * p_manager ) 6823 opj_event_mgr_t * p_manager )
6861 { 6824 {
6862 OPJ_BOOL l_is_valid = OPJ_TRUE; 6825 OPJ_BOOL l_is_valid = OPJ_TRUE;
6863 OPJ_UINT32 i,j; 6826 OPJ_UINT32 i,j;
6864 6827
6865 /* preconditions */ 6828 /* preconditions */
6866 assert(p_j2k != 00); 6829 assert(p_j2k != 00);
6867 assert(p_stream != 00); 6830 assert(p_stream != 00);
6868 assert(p_manager != 00); 6831 assert(p_manager != 00);
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
7034 l_mcc_data->m_decorrelation_array = l_mct_deco_data; 6997 l_mcc_data->m_decorrelation_array = l_mct_deco_data;
7035 l_mcc_data->m_is_irreversible = 1; 6998 l_mcc_data->m_is_irreversible = 1;
7036 l_mcc_data->m_nb_comps = p_image->numcomps; 6999 l_mcc_data->m_nb_comps = p_image->numcomps;
7037 l_mcc_data->m_index = l_indix++; 7000 l_mcc_data->m_index = l_indix++;
7038 l_mcc_data->m_offset_array = l_mct_offset_data; 7001 l_mcc_data->m_offset_array = l_mct_offset_data;
7039 ++p_tcp->m_nb_mcc_records; 7002 ++p_tcp->m_nb_mcc_records;
7040 7003
7041 return OPJ_TRUE; 7004 return OPJ_TRUE;
7042 } 7005 }
7043 7006
7044 OPJ_BOOL opj_j2k_build_decoder (opj_j2k_t * p_j2k, 7007 static OPJ_BOOL opj_j2k_build_decoder (opj_j2k_t * p_j2k,
7045 opj_stream_private_t *p_stream, 7008 opj_stream_private_t *p_stream,
7046 opj_event_mgr_t * p_ manager ) 7009 opj_event_mgr_t * p_ manager )
7047 { 7010 {
7048 /* add here initialization of cp 7011 /* add here initialization of cp
7049 copy paste of setup_decoder */ 7012 copy paste of setup_decoder */
7050 (void)p_j2k; 7013 (void)p_j2k;
7051 (void)p_stream; 7014 (void)p_stream;
7052 (void)p_manager; 7015 (void)p_manager;
7053 return OPJ_TRUE; 7016 return OPJ_TRUE;
7054 } 7017 }
7055 7018
7056 OPJ_BOOL opj_j2k_build_encoder (opj_j2k_t * p_j2k, 7019 static OPJ_BOOL opj_j2k_build_encoder (opj_j2k_t * p_j2k,
7057 opj_stream_private_t *p_ stream, 7020 opj_stream_private_t *p_ stream,
7058 opj_event_mgr_t * p_mana ger ) 7021 opj_event_mgr_t * p_mana ger )
7059 { 7022 {
7060 /* add here initialization of cp 7023 /* add here initialization of cp
7061 copy paste of setup_encoder */ 7024 copy paste of setup_encoder */
7062 (void)p_j2k; 7025 (void)p_j2k;
7063 (void)p_stream; 7026 (void)p_stream;
7064 (void)p_manager; 7027 (void)p_manager;
7065 return OPJ_TRUE; 7028 return OPJ_TRUE;
7066 } 7029 }
7067 7030
7068 OPJ_BOOL opj_j2k_encoding_validation ( opj_j2k_t * p_j2k, 7031 static OPJ_BOOL opj_j2k_encoding_validation ( opj_j2k_t * p_j2k,
7069 opj_ stream_private_t *p_stream, 7032 opj_ stream_private_t *p_stream,
7070 opj_ event_mgr_t * p_manager ) 7033 opj_ event_mgr_t * p_manager )
7071 { 7034 {
7072 OPJ_BOOL l_is_valid = OPJ_TRUE; 7035 OPJ_BOOL l_is_valid = OPJ_TRUE;
7073 7036
7074 /* preconditions */ 7037 /* preconditions */
7075 assert(p_j2k != 00); 7038 assert(p_j2k != 00);
7076 assert(p_stream != 00); 7039 assert(p_stream != 00);
7077 assert(p_manager != 00); 7040 assert(p_manager != 00);
7078 7041
(...skipping 22 matching lines...) Expand all
7101 7064
7102 if ((p_j2k->m_cp.tdy) < (OPJ_UINT32) (1 << (p_j2k->m_cp.tcps->tccps->num resolutions - 1U))) { 7065 if ((p_j2k->m_cp.tdy) < (OPJ_UINT32) (1 << (p_j2k->m_cp.tcps->tccps->num resolutions - 1U))) {
7103 opj_event_msg(p_manager, EVT_ERROR, "Number of resolutions is to o high in comparison to the size of tiles\n"); 7066 opj_event_msg(p_manager, EVT_ERROR, "Number of resolutions is to o high in comparison to the size of tiles\n");
7104 return OPJ_FALSE; 7067 return OPJ_FALSE;
7105 } 7068 }
7106 7069
7107 /* PARAMETER VALIDATION */ 7070 /* PARAMETER VALIDATION */
7108 return l_is_valid; 7071 return l_is_valid;
7109 } 7072 }
7110 7073
7111 OPJ_BOOL opj_j2k_decoding_validation ( opj_j2k_t *p_j2k, 7074 static OPJ_BOOL opj_j2k_decoding_validation ( opj_j2k_t *p_j2k,
7112 opj_stream_private_t *p_stream, 7075 opj_stream_private_t *p_stream,
7113 opj_event_mgr_t * p_manager 7076 opj_event_mgr_t * p_manager
7114 ) 7077 )
7115 { 7078 {
7116 OPJ_BOOL l_is_valid = OPJ_TRUE; 7079 OPJ_BOOL l_is_valid = OPJ_TRUE;
7117 7080
7118 /* preconditions*/ 7081 /* preconditions*/
7119 assert(p_j2k != 00); 7082 assert(p_j2k != 00);
7120 assert(p_stream != 00); 7083 assert(p_stream != 00);
7121 assert(p_manager != 00); 7084 assert(p_manager != 00);
7122 7085
7123 /* STATE checking */ 7086 /* STATE checking */
7124 /* make sure the state is at 0 */ 7087 /* make sure the state is at 0 */
7125 #ifdef TODO_MSD 7088 #ifdef TODO_MSD
7126 l_is_valid &= (p_j2k->m_specific_param.m_decoder.m_state == J2K_DEC_STAT E_NONE); 7089 l_is_valid &= (p_j2k->m_specific_param.m_decoder.m_state == J2K_DEC_STAT E_NONE);
7127 #endif 7090 #endif
7128 l_is_valid &= (p_j2k->m_specific_param.m_decoder.m_state == 0x0000); 7091 l_is_valid &= (p_j2k->m_specific_param.m_decoder.m_state == 0x0000);
7129 7092
7130 /* POINTER validation */ 7093 /* POINTER validation */
7131 /* make sure a p_j2k codec is present */ 7094 /* make sure a p_j2k codec is present */
7132 /* make sure a procedure list is present */ 7095 /* make sure a procedure list is present */
7133 l_is_valid &= (p_j2k->m_procedure_list != 00); 7096 l_is_valid &= (p_j2k->m_procedure_list != 00);
7134 /* make sure a validation list is present */ 7097 /* make sure a validation list is present */
7135 l_is_valid &= (p_j2k->m_validation_list != 00); 7098 l_is_valid &= (p_j2k->m_validation_list != 00);
7136 7099
7137 /* PARAMETER VALIDATION */ 7100 /* PARAMETER VALIDATION */
7138 return l_is_valid; 7101 return l_is_valid;
7139 } 7102 }
7140 7103
7141 OPJ_BOOL opj_j2k_read_header_procedure( opj_j2k_t *p_j2k, 7104 static OPJ_BOOL opj_j2k_read_header_procedure( opj_j2k_t *p_j2k,
7142 opj_ stream_private_t *p_stream, 7105 opj_ stream_private_t *p_stream,
7143 opj_ event_mgr_t * p_manager) 7106 opj_ event_mgr_t * p_manager)
7144 { 7107 {
7145 OPJ_UINT32 l_current_marker; 7108 OPJ_UINT32 l_current_marker;
7146 OPJ_UINT32 l_marker_size; 7109 OPJ_UINT32 l_marker_size;
7147 const opj_dec_memory_marker_handler_t * l_marker_handler = 00; 7110 const opj_dec_memory_marker_handler_t * l_marker_handler = 00;
7148 OPJ_BOOL l_has_siz = 0; 7111 OPJ_BOOL l_has_siz = 0;
7149 OPJ_BOOL l_has_cod = 0; 7112 OPJ_BOOL l_has_cod = 0;
7150 OPJ_BOOL l_has_qcd = 0; 7113 OPJ_BOOL l_has_qcd = 0;
7151 7114
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
7277 return OPJ_FALSE; 7240 return OPJ_FALSE;
7278 } 7241 }
7279 if (l_has_cod == 0) { 7242 if (l_has_cod == 0) {
7280 opj_event_msg(p_manager, EVT_ERROR, "required COD marker not found i n main header\n"); 7243 opj_event_msg(p_manager, EVT_ERROR, "required COD marker not found i n main header\n");
7281 return OPJ_FALSE; 7244 return OPJ_FALSE;
7282 } 7245 }
7283 if (l_has_qcd == 0) { 7246 if (l_has_qcd == 0) {
7284 opj_event_msg(p_manager, EVT_ERROR, "required QCD marker not found i n main header\n"); 7247 opj_event_msg(p_manager, EVT_ERROR, "required QCD marker not found i n main header\n");
7285 return OPJ_FALSE; 7248 return OPJ_FALSE;
7286 } 7249 }
7250
7251 if (! opj_j2k_merge_ppm(&(p_j2k->m_cp), p_manager)) {
7252 opj_event_msg(p_manager, EVT_ERROR, "Failed to merge PPM data\n");
7253 return OPJ_FALSE;
7254 }
7287 7255
7288 opj_event_msg(p_manager, EVT_INFO, "Main header has been correctly decod ed.\n"); 7256 opj_event_msg(p_manager, EVT_INFO, "Main header has been correctly decod ed.\n");
7289 7257
7290 /* Position of the last element if the main header */ 7258 /* Position of the last element if the main header */
7291 p_j2k->cstr_index->main_head_end = (OPJ_UINT32) opj_stream_tell(p_stream ) - 2; 7259 p_j2k->cstr_index->main_head_end = (OPJ_UINT32) opj_stream_tell(p_stream ) - 2;
7292 7260
7293 /* Next step: read a tile-part header */ 7261 /* Next step: read a tile-part header */
7294 p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_TPHSOT; 7262 p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_TPHSOT;
7295 7263
7296 return OPJ_TRUE; 7264 return OPJ_TRUE;
7297 } 7265 }
7298 7266
7299 OPJ_BOOL opj_j2k_exec ( opj_j2k_t * p_j2k, 7267 static OPJ_BOOL opj_j2k_exec ( opj_j2k_t * p_j2k,
7300 opj_procedure_list_t * p_procedure_list, 7268 opj_procedure_list_t * p_procedure_list,
7301 opj_stream_private_t *p_stream, 7269 opj_stream_private_t *p_stream,
7302 opj_event_mgr_t * p_manager ) 7270 opj_event_mgr_t * p_manager )
7303 { 7271 {
7304 OPJ_BOOL (** l_procedure) (opj_j2k_t * ,opj_stream_private_t *,opj_event _mgr_t *) = 00; 7272 OPJ_BOOL (** l_procedure) (opj_j2k_t * ,opj_stream_private_t *,opj_event _mgr_t *) = 00;
7305 OPJ_BOOL l_result = OPJ_TRUE; 7273 OPJ_BOOL l_result = OPJ_TRUE;
7306 OPJ_UINT32 l_nb_proc, i; 7274 OPJ_UINT32 l_nb_proc, i;
7307 7275
7308 /* preconditions*/ 7276 /* preconditions*/
7309 assert(p_procedure_list != 00); 7277 assert(p_procedure_list != 00);
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after
7457 if ( !opj_tcd_init(p_j2k->m_tcd, l_image, &(p_j2k->m_cp)) ) { 7425 if ( !opj_tcd_init(p_j2k->m_tcd, l_image, &(p_j2k->m_cp)) ) {
7458 opj_tcd_destroy(p_j2k->m_tcd); 7426 opj_tcd_destroy(p_j2k->m_tcd);
7459 p_j2k->m_tcd = 00; 7427 p_j2k->m_tcd = 00;
7460 opj_event_msg(p_manager, EVT_ERROR, "Cannot decode tile, memory error\n"); 7428 opj_event_msg(p_manager, EVT_ERROR, "Cannot decode tile, memory error\n");
7461 return OPJ_FALSE; 7429 return OPJ_FALSE;
7462 } 7430 }
7463 7431
7464 return OPJ_TRUE; 7432 return OPJ_TRUE;
7465 } 7433 }
7466 7434
7467 const opj_dec_memory_marker_handler_t * opj_j2k_get_marker_handler (OPJ_UINT32 p _id) 7435 static const opj_dec_memory_marker_handler_t * opj_j2k_get_marker_handler (OPJ_U INT32 p_id)
7468 { 7436 {
7469 const opj_dec_memory_marker_handler_t *e; 7437 const opj_dec_memory_marker_handler_t *e;
7470 for (e = j2k_memory_marker_handler_tab; e->id != 0; ++e) { 7438 for (e = j2k_memory_marker_handler_tab; e->id != 0; ++e) {
7471 if (e->id == p_id) { 7439 if (e->id == p_id) {
7472 break; /* we find a handler corresponding to the marker ID*/ 7440 break; /* we find a handler corresponding to the marker ID*/
7473 } 7441 }
7474 } 7442 }
7475 return e; 7443 return e;
7476 } 7444 }
7477 7445
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
7570 } 7538 }
7571 7539
7572 opj_free( p_cstr_ind->tile_index); 7540 opj_free( p_cstr_ind->tile_index);
7573 p_cstr_ind->tile_index = NULL; 7541 p_cstr_ind->tile_index = NULL;
7574 } 7542 }
7575 7543
7576 opj_free(p_cstr_ind); 7544 opj_free(p_cstr_ind);
7577 } 7545 }
7578 } 7546 }
7579 7547
7580 void opj_j2k_tcp_destroy (opj_tcp_t *p_tcp) 7548 static void opj_j2k_tcp_destroy (opj_tcp_t *p_tcp)
7581 { 7549 {
7582 if (p_tcp == 00) { 7550 » if (p_tcp == 00) {
7583 return; 7551 » » return;
7584 } 7552 » }
7553 »
7554 » if (p_tcp->ppt_markers != 00) {
7555 » » OPJ_UINT32 i;
7556 » » for (i = 0U; i < p_tcp->ppt_markers_count; ++i) {
7557 » » » if (p_tcp->ppt_markers[i].m_data != NULL) {
7558 » » » » opj_free(p_tcp->ppt_markers[i].m_data);
7559 » » » }
7560 » » }
7561 » » p_tcp->ppt_markers_count = 0U;
7562 » » opj_free(p_tcp->ppt_markers);
7563 » » p_tcp->ppt_markers = NULL;
7564 » }
7565 »
7566 » if (p_tcp->ppt_buffer != 00) {
7567 » » opj_free(p_tcp->ppt_buffer);
7568 » » p_tcp->ppt_buffer = 00;
7569 » }
7570 »
7571 » if (p_tcp->tccps != 00) {
7572 » » opj_free(p_tcp->tccps);
7573 » » p_tcp->tccps = 00;
7574 » }
7575 »
7576 » if (p_tcp->m_mct_coding_matrix != 00) {
7577 » » opj_free(p_tcp->m_mct_coding_matrix);
7578 » » p_tcp->m_mct_coding_matrix = 00;
7579 » }
7580 »
7581 » if (p_tcp->m_mct_decoding_matrix != 00) {
7582 » » opj_free(p_tcp->m_mct_decoding_matrix);
7583 » » p_tcp->m_mct_decoding_matrix = 00;
7584 » }
7585 »
7586 » if (p_tcp->m_mcc_records) {
7587 » » opj_free(p_tcp->m_mcc_records);
7588 » » p_tcp->m_mcc_records = 00;
7589 » » p_tcp->m_nb_max_mcc_records = 0;
7590 » » p_tcp->m_nb_mcc_records = 0;
7591 » }
7592 »
7593 » if (p_tcp->m_mct_records) {
7594 » » opj_mct_data_t * l_mct_data = p_tcp->m_mct_records;
7595 » » OPJ_UINT32 i;
7596 » »
7597 » » for (i=0;i<p_tcp->m_nb_mct_records;++i) {
7598 » » » if (l_mct_data->m_data) {
7599 » » » » opj_free(l_mct_data->m_data);
7600 » » » » l_mct_data->m_data = 00;
7601 » » » }
7602 » » »
7603 » » » ++l_mct_data;
7604 » » }
7605 » »
7606 » » opj_free(p_tcp->m_mct_records);
7607 » » p_tcp->m_mct_records = 00;
7608 » }
7585 7609
7586 if (p_tcp->ppt_buffer != 00) { 7610 » if (p_tcp->mct_norms != 00) {
7587 opj_free(p_tcp->ppt_buffer); 7611 » » opj_free(p_tcp->mct_norms);
7588 p_tcp->ppt_buffer = 00; 7612 » » p_tcp->mct_norms = 00;
7589 } 7613 » }
7590 7614
7591 if (p_tcp->tccps != 00) { 7615 » opj_j2k_tcp_data_destroy(p_tcp);
7592 opj_free(p_tcp->tccps);
7593 p_tcp->tccps = 00;
7594 }
7595
7596 if (p_tcp->m_mct_coding_matrix != 00) {
7597 opj_free(p_tcp->m_mct_coding_matrix);
7598 p_tcp->m_mct_coding_matrix = 00;
7599 }
7600
7601 if (p_tcp->m_mct_decoding_matrix != 00) {
7602 opj_free(p_tcp->m_mct_decoding_matrix);
7603 p_tcp->m_mct_decoding_matrix = 00;
7604 }
7605
7606 if (p_tcp->m_mcc_records) {
7607 opj_free(p_tcp->m_mcc_records);
7608 p_tcp->m_mcc_records = 00;
7609 p_tcp->m_nb_max_mcc_records = 0;
7610 p_tcp->m_nb_mcc_records = 0;
7611 }
7612
7613 if (p_tcp->m_mct_records) {
7614 opj_mct_data_t * l_mct_data = p_tcp->m_mct_records;
7615 OPJ_UINT32 i;
7616
7617 for (i=0;i<p_tcp->m_nb_mct_records;++i) {
7618 if (l_mct_data->m_data) {
7619 opj_free(l_mct_data->m_data);
7620 l_mct_data->m_data = 00;
7621 }
7622
7623 ++l_mct_data;
7624 }
7625
7626 opj_free(p_tcp->m_mct_records);
7627 p_tcp->m_mct_records = 00;
7628 }
7629
7630 if (p_tcp->mct_norms != 00) {
7631 opj_free(p_tcp->mct_norms);
7632 p_tcp->mct_norms = 00;
7633 }
7634
7635 opj_j2k_tcp_data_destroy(p_tcp);
7636 7616
7637 } 7617 }
7638 7618
7639 void opj_j2k_tcp_data_destroy (opj_tcp_t *p_tcp) 7619 static void opj_j2k_tcp_data_destroy (opj_tcp_t *p_tcp)
7640 { 7620 {
7641 if (p_tcp->m_data) { 7621 if (p_tcp->m_data) {
7642 opj_free(p_tcp->m_data); 7622 opj_free(p_tcp->m_data);
7643 p_tcp->m_data = NULL; 7623 p_tcp->m_data = NULL;
7644 p_tcp->m_data_size = 0; 7624 p_tcp->m_data_size = 0;
7645 } 7625 }
7646 } 7626 }
7647 7627
7648 void opj_j2k_cp_destroy (opj_cp_t *p_cp) 7628 static void opj_j2k_cp_destroy (opj_cp_t *p_cp)
7649 { 7629 {
7650 OPJ_UINT32 l_nb_tiles; 7630 » OPJ_UINT32 l_nb_tiles;
7651 opj_tcp_t * l_current_tile = 00; 7631 » opj_tcp_t * l_current_tile = 00;
7652 OPJ_UINT32 i;
7653 7632
7654 if (p_cp == 00) 7633 » if (p_cp == 00)
7655 { 7634 » {
7656 return; 7635 » » return;
7657 } 7636 » }
7658 if (p_cp->tcps != 00) 7637 » if (p_cp->tcps != 00)
7659 { 7638 » {
7660 l_current_tile = p_cp->tcps; 7639 » » OPJ_UINT32 i;
7661 l_nb_tiles = p_cp->th * p_cp->tw; 7640 » » l_current_tile = p_cp->tcps;
7641 » » l_nb_tiles = p_cp->th * p_cp->tw;
7642 » »
7643 » » for (i = 0U; i < l_nb_tiles; ++i)
7644 » » {
7645 » » » opj_j2k_tcp_destroy(l_current_tile);
7646 » » » ++l_current_tile;
7647 » » }
7648 » » opj_free(p_cp->tcps);
7649 » » p_cp->tcps = 00;
7650 » }
7651 » if (p_cp->ppm_markers != 00) {
7652 » » OPJ_UINT32 i;
7653 » » for (i = 0U; i < p_cp->ppm_markers_count; ++i) {
7654 » » » if (p_cp->ppm_markers[i].m_data != NULL) {
7655 » » » » opj_free(p_cp->ppm_markers[i].m_data);
7656 » » » }
7657 » » }
7658 » » p_cp->ppm_markers_count = 0U;
7659 » » opj_free(p_cp->ppm_markers);
7660 » » p_cp->ppm_markers = NULL;
7661 » }
7662 » opj_free(p_cp->ppm_buffer);
7663 » p_cp->ppm_buffer = 00;
7664 » p_cp->ppm_data = NULL; /* ppm_data belongs to the allocated buffer point ed by ppm_buffer */
7665 » opj_free(p_cp->comment);
7666 » p_cp->comment = 00;
7667 » if (! p_cp->m_is_decoder)
7668 » {
7669 » » opj_free(p_cp->m_specific_param.m_enc.m_matrice);
7670 » » p_cp->m_specific_param.m_enc.m_matrice = 00;
7671 » }
7672 }
7662 7673
7663 for (i = 0; i < l_nb_tiles; ++i) 7674 static OPJ_BOOL opj_j2k_need_nb_tile_parts_correction(opj_stream_private_t *p_st ream, OPJ_UINT32 tile_no, OPJ_BOOL* p_correction_needed, opj_event_mgr_t * p_man ager )
7664 { 7675 {
7665 opj_j2k_tcp_destroy(l_current_tile); 7676 » OPJ_BYTE l_header_data[10];
7666 ++l_current_tile; 7677 » OPJ_OFF_T l_stream_pos_backup;
7667 } 7678 » OPJ_UINT32 l_current_marker;
7668 opj_free(p_cp->tcps); 7679 » OPJ_UINT32 l_marker_size;
7669 p_cp->tcps = 00; 7680 » OPJ_UINT32 l_tile_no, l_tot_len, l_current_part, l_num_parts;
7670 } 7681 »
7671 opj_free(p_cp->ppm_buffer); 7682 » /* initialize to no correction needed */
7672 p_cp->ppm_buffer = 00; 7683 » *p_correction_needed = OPJ_FALSE;
7673 p_cp->ppm_data = NULL; /* ppm_data belongs to the allocated buffer point ed by ppm_buffer */ 7684 »
7674 opj_free(p_cp->comment); 7685 » l_stream_pos_backup = opj_stream_tell(p_stream);
7675 p_cp->comment = 00; 7686 » if (l_stream_pos_backup == -1) {
7676 if (! p_cp->m_is_decoder) 7687 » » /* let's do nothing */
7677 { 7688 » » return OPJ_TRUE;
7678 opj_free(p_cp->m_specific_param.m_enc.m_matrice); 7689 » }
7679 p_cp->m_specific_param.m_enc.m_matrice = 00; 7690 »
7680 } 7691 » for (;;) {
7692 » » /* Try to read 2 bytes (the next marker ID) from stream and copy them into the buffer */
7693 » » if (opj_stream_read_data(p_stream,l_header_data, 2, p_manager) ! = 2) {
7694 » » » /* assume all is OK */
7695 » » » if (! opj_stream_seek(p_stream, l_stream_pos_backup, p_m anager)) {
7696 » » » » return OPJ_FALSE;
7697 » » » }
7698 » » » return OPJ_TRUE;
7699 » » }
7700 » »
7701 » » /* Read 2 bytes from buffer as the new marker ID */
7702 » » opj_read_bytes(l_header_data, &l_current_marker, 2);
7703 » »
7704 » » if (l_current_marker != J2K_MS_SOT) {
7705 » » » /* assume all is OK */
7706 » » » if (! opj_stream_seek(p_stream, l_stream_pos_backup, p_m anager)) {
7707 » » » » return OPJ_FALSE;
7708 » » » }
7709 » » » return OPJ_TRUE;
7710 » » }
7711 » »
7712 » » /* Try to read 2 bytes (the marker size) from stream and copy th em into the buffer */
7713 » » if (opj_stream_read_data(p_stream, l_header_data, 2, p_manager) != 2) {
7714 » » » opj_event_msg(p_manager, EVT_ERROR, "Stream too short\n" );
7715 » » » return OPJ_FALSE;
7716 » » }
7717 » »
7718 » » /* Read 2 bytes from the buffer as the marker size */
7719 » » opj_read_bytes(l_header_data, &l_marker_size, 2);
7720 » »
7721 » » /* Check marker size for SOT Marker */
7722 » » if (l_marker_size != 10) {
7723 » » » opj_event_msg(p_manager, EVT_ERROR, "Inconsistent marker size\n");
7724 » » » return OPJ_FALSE;
7725 » » }
7726 » » l_marker_size -= 2;
7727 » »
7728 » » if (opj_stream_read_data(p_stream, l_header_data, l_marker_size, p_manager) != l_marker_size) {
7729 » » » opj_event_msg(p_manager, EVT_ERROR, "Stream too short\n" );
7730 » » » return OPJ_FALSE;
7731 » » }
7732 » »
7733 » » if (! opj_j2k_get_sot_values(l_header_data, l_marker_size, &l_ti le_no, &l_tot_len, &l_current_part, &l_num_parts, p_manager)) {
7734 » » » return OPJ_FALSE;
7735 » » }
7736 » »
7737 » » if (l_tile_no == tile_no) {
7738 » » » /* we found what we were looking for */
7739 » » » break;
7740 » » }
7741 » »
7742 » » if ((l_tot_len == 0U) || (l_tot_len < 14U)) {
7743 » » » /* last SOT until EOC or invalid Psot value */
7744 » » » /* assume all is OK */
7745 » » » if (! opj_stream_seek(p_stream, l_stream_pos_backup, p_m anager)) {
7746 » » » » return OPJ_FALSE;
7747 » » » }
7748 » » » return OPJ_TRUE;
7749 » » }
7750 » » l_tot_len -= 12U;
7751 » » /* look for next SOT marker */
7752 » » if (opj_stream_skip(p_stream, (OPJ_OFF_T)(l_tot_len), p_manager) != (OPJ_OFF_T)(l_tot_len)) {
7753 » » » /* assume all is OK */
7754 » » » if (! opj_stream_seek(p_stream, l_stream_pos_backup, p_m anager)) {
7755 » » » » return OPJ_FALSE;
7756 » » » }
7757 » » » return OPJ_TRUE;
7758 » » }
7759 » }
7760 »
7761 » /* check for correction */
7762 » if (l_current_part == l_num_parts) {
7763 » » *p_correction_needed = OPJ_TRUE;
7764 » }
7765 »
7766 » if (! opj_stream_seek(p_stream, l_stream_pos_backup, p_manager)) {
7767 » » return OPJ_FALSE;
7768 » }
7769 » return OPJ_TRUE;
7681 } 7770 }
7682 7771
7683 OPJ_BOOL opj_j2k_read_tile_header( opj_j2k_t * p_j2k, 7772 OPJ_BOOL opj_j2k_read_tile_header( opj_j2k_t * p_j2k,
7684 OPJ_UINT32 * p_tile_index, 7773 OPJ_UINT32 * p_tile_index,
7685 OPJ_UINT32 * p_data_size, 7774 OPJ_UINT32 * p_data_size,
7686 OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0, 7775 OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0,
7687 OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1, 7776 OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1,
7688 OPJ_UINT32 * p_nb_comps, 7777 OPJ_UINT32 * p_nb_comps,
7689 OPJ_BOOL * p _go_on, 7778 OPJ_BOOL * p _go_on,
7690 opj_stream_p rivate_t *p_stream, 7779 opj_stream_p rivate_t *p_stream,
7691 opj_event_mg r_t * p_manager ) 7780 opj_event_mg r_t * p_manager )
7692 { 7781 {
7693 OPJ_UINT32 l_current_marker = J2K_MS_SOT; 7782 OPJ_UINT32 l_current_marker = J2K_MS_SOT;
7694 OPJ_UINT32 l_marker_size; 7783 OPJ_UINT32 l_marker_size;
7695 const opj_dec_memory_marker_handler_t * l_marker_handler = 00; 7784 const opj_dec_memory_marker_handler_t * l_marker_handler = 00;
7696 opj_tcp_t * l_tcp = NULL; 7785 opj_tcp_t * l_tcp = NULL;
7697 OPJ_UINT32 l_nb_tiles;
7698 7786
7699 /* preconditions */ 7787 /* preconditions */
7700 assert(p_stream != 00); 7788 assert(p_stream != 00);
7701 assert(p_j2k != 00); 7789 assert(p_j2k != 00);
7702 assert(p_manager != 00); 7790 assert(p_manager != 00);
7703 7791
7704 /* Reach the End Of Codestream ?*/ 7792 /* Reach the End Of Codestream ?*/
7705 if (p_j2k->m_specific_param.m_decoder.m_state == J2K_STATE_EOC){ 7793 if (p_j2k->m_specific_param.m_decoder.m_state == J2K_STATE_EOC){
7706 l_current_marker = J2K_MS_EOC; 7794 l_current_marker = J2K_MS_EOC;
7707 } 7795 }
(...skipping 129 matching lines...) Expand 10 before | Expand all | Expand 10 after
7837 if(opj_stream_get_number_byte_left(p_stream) == 0 7925 if(opj_stream_get_number_byte_left(p_stream) == 0
7838 && p_j2k->m_specific_param.m_decoder.m_state == J2K_STATE_NE OC) 7926 && p_j2k->m_specific_param.m_decoder.m_state == J2K_STATE_NE OC)
7839 break; 7927 break;
7840 7928
7841 /* If we didn't skip data before, we need to read the SOD marker */ 7929 /* If we didn't skip data before, we need to read the SOD marker */
7842 if (! p_j2k->m_specific_param.m_decoder.m_skip_data) { 7930 if (! p_j2k->m_specific_param.m_decoder.m_skip_data) {
7843 /* Try to read the SOD marker and skip data ? FIXME */ 7931 /* Try to read the SOD marker and skip data ? FIXME */
7844 if (! opj_j2k_read_sod(p_j2k, p_stream, p_manager)) { 7932 if (! opj_j2k_read_sod(p_j2k, p_stream, p_manager)) {
7845 return OPJ_FALSE; 7933 return OPJ_FALSE;
7846 } 7934 }
7935 if (p_j2k->m_specific_param.m_decoder.m_can_decode && !p _j2k->m_specific_param.m_decoder.m_nb_tile_parts_correction_checked) {
7936 /* Issue 254 */
7937 OPJ_BOOL l_correction_needed;
7938
7939 p_j2k->m_specific_param.m_decoder.m_nb_tile_part s_correction_checked = 1;
7940 if(!opj_j2k_need_nb_tile_parts_correction(p_stre am, p_j2k->m_current_tile_number, &l_correction_needed, p_manager)) {
7941 opj_event_msg(p_manager, EVT_ERROR, "opj _j2k_apply_nb_tile_parts_correction error\n");
7942 return OPJ_FALSE;
7943 }
7944 if (l_correction_needed) {
7945 OPJ_UINT32 l_nb_tiles = p_j2k->m_cp.tw * p_j2k->m_cp.th;
7946 OPJ_UINT32 l_tile_no;
7847 7947
7948 p_j2k->m_specific_param.m_decoder.m_can_ decode = 0;
7949 p_j2k->m_specific_param.m_decoder.m_nb_t ile_parts_correction = 1;
7950 /* correct tiles */
7951 for (l_tile_no = 0U; l_tile_no < l_nb_ti les; ++l_tile_no) {
7952 if (p_j2k->m_cp.tcps[l_tile_no]. m_nb_tile_parts != 0U) {
7953 p_j2k->m_cp.tcps[l_tile_ no].m_nb_tile_parts+=1;
7954 }
7955 }
7956 opj_event_msg(p_manager, EVT_WARNING, "N on conformant codestream TPsot==TNsot.\n");
7957 }
7958 }
7848 if (! p_j2k->m_specific_param.m_decoder.m_can_decode){ 7959 if (! p_j2k->m_specific_param.m_decoder.m_can_decode){
7849 /* Try to read 2 bytes (the next marker ID) from stream and copy them into the buffer */ 7960 /* Try to read 2 bytes (the next marker ID) from stream and copy them into the buffer */
7850 if (opj_stream_read_data(p_stream,p_j2k->m_speci fic_param.m_decoder.m_header_data,2,p_manager) != 2) { 7961 if (opj_stream_read_data(p_stream,p_j2k->m_speci fic_param.m_decoder.m_header_data,2,p_manager) != 2) {
7851 opj_event_msg(p_manager, EVT_ERROR, "Str eam too short\n"); 7962 opj_event_msg(p_manager, EVT_ERROR, "Str eam too short\n");
7852 return OPJ_FALSE; 7963 return OPJ_FALSE;
7853 } 7964 }
7854 7965
7855 /* Read 2 bytes from buffer as the new marker ID */ 7966 /* Read 2 bytes from buffer as the new marker ID */
7856 opj_read_bytes(p_j2k->m_specific_param.m_decoder .m_header_data,&l_current_marker,2); 7967 opj_read_bytes(p_j2k->m_specific_param.m_decoder .m_header_data,&l_current_marker,2);
7857 } 7968 }
(...skipping 18 matching lines...) Expand all
7876 /* Current marker is the EOC marker ?*/ 7987 /* Current marker is the EOC marker ?*/
7877 if (l_current_marker == J2K_MS_EOC) { 7988 if (l_current_marker == J2K_MS_EOC) {
7878 if (p_j2k->m_specific_param.m_decoder.m_state != J2K_STATE_EOC ) { 7989 if (p_j2k->m_specific_param.m_decoder.m_state != J2K_STATE_EOC ) {
7879 p_j2k->m_current_tile_number = 0; 7990 p_j2k->m_current_tile_number = 0;
7880 p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_EO C; 7991 p_j2k->m_specific_param.m_decoder.m_state = J2K_STATE_EO C;
7881 } 7992 }
7882 } 7993 }
7883 7994
7884 /* FIXME DOC ???*/ 7995 /* FIXME DOC ???*/
7885 if ( ! p_j2k->m_specific_param.m_decoder.m_can_decode) { 7996 if ( ! p_j2k->m_specific_param.m_decoder.m_can_decode) {
7997 OPJ_UINT32 l_nb_tiles = p_j2k->m_cp.th * p_j2k->m_cp.tw;
7886 l_tcp = p_j2k->m_cp.tcps + p_j2k->m_current_tile_number; 7998 l_tcp = p_j2k->m_cp.tcps + p_j2k->m_current_tile_number;
7887 l_nb_tiles = p_j2k->m_cp.th * p_j2k->m_cp.tw;
7888 7999
7889 while( (p_j2k->m_current_tile_number < l_nb_tiles) && (l_tcp->m_ data == 00) ) { 8000 while( (p_j2k->m_current_tile_number < l_nb_tiles) && (l_tcp->m_ data == 00) ) {
7890 ++p_j2k->m_current_tile_number; 8001 ++p_j2k->m_current_tile_number;
7891 ++l_tcp; 8002 ++l_tcp;
7892 } 8003 }
7893 8004
7894 if (p_j2k->m_current_tile_number == l_nb_tiles) { 8005 if (p_j2k->m_current_tile_number == l_nb_tiles) {
7895 *p_go_on = OPJ_FALSE; 8006 *p_go_on = OPJ_FALSE;
7896 return OPJ_TRUE; 8007 return OPJ_TRUE;
7897 } 8008 }
7898 } 8009 }
7899 8010
8011 if (! opj_j2k_merge_ppt(p_j2k->m_cp.tcps + p_j2k->m_current_tile_number, p_manager)) {
8012 opj_event_msg(p_manager, EVT_ERROR, "Failed to merge PPT data\n" );
8013 return OPJ_FALSE;
8014 }
7900 /*FIXME ???*/ 8015 /*FIXME ???*/
7901 if (! opj_tcd_init_decode_tile(p_j2k->m_tcd, p_j2k->m_current_tile_numbe r)) { 8016 if (! opj_tcd_init_decode_tile(p_j2k->m_tcd, p_j2k->m_current_tile_numbe r, p_manager)) {
7902 opj_event_msg(p_manager, EVT_ERROR, "Cannot decode tile, memory error\n"); 8017 opj_event_msg(p_manager, EVT_ERROR, "Cannot decode tile, memory error\n");
7903 return OPJ_FALSE; 8018 return OPJ_FALSE;
7904 } 8019 }
7905 8020
7906 opj_event_msg(p_manager, EVT_INFO, "Header of tile %d / %d has been read .\n", 8021 opj_event_msg(p_manager, EVT_INFO, "Header of tile %d / %d has been read .\n",
7907 p_j2k->m_current_tile_number+1, (p_j2k->m_cp.th * p_j2k- >m_cp.tw)); 8022 p_j2k->m_current_tile_number+1, (p_j2k->m_cp.th * p_j2k- >m_cp.tw));
7908 8023
7909 *p_tile_index = p_j2k->m_current_tile_number; 8024 *p_tile_index = p_j2k->m_current_tile_number;
7910 *p_go_on = OPJ_TRUE; 8025 *p_go_on = OPJ_TRUE;
7911 *p_data_size = opj_tcd_get_decoded_tile_size(p_j2k->m_tcd); 8026 *p_data_size = opj_tcd_get_decoded_tile_size(p_j2k->m_tcd);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
7944 l_tcp = &(p_j2k->m_cp.tcps[p_tile_index]); 8059 l_tcp = &(p_j2k->m_cp.tcps[p_tile_index]);
7945 if (! l_tcp->m_data) { 8060 if (! l_tcp->m_data) {
7946 opj_j2k_tcp_destroy(l_tcp); 8061 opj_j2k_tcp_destroy(l_tcp);
7947 return OPJ_FALSE; 8062 return OPJ_FALSE;
7948 } 8063 }
7949 8064
7950 if (! opj_tcd_decode_tile( p_j2k->m_tcd, 8065 if (! opj_tcd_decode_tile( p_j2k->m_tcd,
7951 l_tcp->m_data, 8066 l_tcp->m_data,
7952 l_tcp->m_data_si ze, 8067 l_tcp->m_data_si ze,
7953 p_tile_index, 8068 p_tile_index,
7954 p_j2k->cstr_inde x) ) { 8069 p_j2k->cstr_inde x, p_manager) ) {
7955 opj_j2k_tcp_destroy(l_tcp); 8070 opj_j2k_tcp_destroy(l_tcp);
7956 p_j2k->m_specific_param.m_decoder.m_state |= 0x8000;/*FIXME J2K_ DEC_STATE_ERR;*/ 8071 p_j2k->m_specific_param.m_decoder.m_state |= 0x8000;/*FIXME J2K_ DEC_STATE_ERR;*/
7957 opj_event_msg(p_manager, EVT_ERROR, "Failed to decode.\n"); 8072 opj_event_msg(p_manager, EVT_ERROR, "Failed to decode.\n");
7958 return OPJ_FALSE; 8073 return OPJ_FALSE;
7959 } 8074 }
7960 8075
7961 if (! opj_tcd_update_tile_data(p_j2k->m_tcd,p_data,p_data_size)) { 8076 if (! opj_tcd_update_tile_data(p_j2k->m_tcd,p_data,p_data_size)) {
7962 return OPJ_FALSE; 8077 return OPJ_FALSE;
7963 } 8078 }
7964 8079
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
7996 return OPJ_TRUE; 8111 return OPJ_TRUE;
7997 } 8112 }
7998 opj_event_msg(p_manager, EVT_ERROR, "Stream too short, e xpected SOT\n"); 8113 opj_event_msg(p_manager, EVT_ERROR, "Stream too short, e xpected SOT\n");
7999 return OPJ_FALSE; 8114 return OPJ_FALSE;
8000 } 8115 }
8001 } 8116 }
8002 8117
8003 return OPJ_TRUE; 8118 return OPJ_TRUE;
8004 } 8119 }
8005 8120
8006 OPJ_BOOL opj_j2k_update_image_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data, opj_im age_t* p_output_image) 8121 static OPJ_BOOL opj_j2k_update_image_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data, opj_image_t* p_output_image)
8007 { 8122 {
8008 OPJ_UINT32 i,j,k = 0; 8123 OPJ_UINT32 i,j,k = 0;
8009 OPJ_UINT32 l_width_src,l_height_src; 8124 OPJ_UINT32 l_width_src,l_height_src;
8010 OPJ_UINT32 l_width_dest,l_height_dest; 8125 OPJ_UINT32 l_width_dest,l_height_dest;
8011 OPJ_INT32 l_offset_x0_src, l_offset_y0_src, l_offset_x1_src, l_offset_y1 _src; 8126 OPJ_INT32 l_offset_x0_src, l_offset_y0_src, l_offset_x1_src, l_offset_y1 _src;
8012 OPJ_INT32 l_start_offset_src, l_line_offset_src, l_end_offset_src ; 8127 OPJ_SIZE_T l_start_offset_src, l_line_offset_src, l_end_offset_src ;
8013 OPJ_UINT32 l_start_x_dest , l_start_y_dest; 8128 OPJ_UINT32 l_start_x_dest , l_start_y_dest;
8014 OPJ_UINT32 l_x0_dest, l_y0_dest, l_x1_dest, l_y1_dest; 8129 OPJ_UINT32 l_x0_dest, l_y0_dest, l_x1_dest, l_y1_dest;
8015 OPJ_INT32 l_start_offset_dest, l_line_offset_dest; 8130 OPJ_SIZE_T l_start_offset_dest, l_line_offset_dest;
8016 8131
8017 opj_image_comp_t * l_img_comp_src = 00; 8132 opj_image_comp_t * l_img_comp_src = 00;
8018 opj_image_comp_t * l_img_comp_dest = 00; 8133 opj_image_comp_t * l_img_comp_dest = 00;
8019 8134
8020 opj_tcd_tilecomp_t * l_tilec = 00; 8135 opj_tcd_tilecomp_t * l_tilec = 00;
8021 opj_image_t * l_image_src = 00; 8136 opj_image_t * l_image_src = 00;
8022 OPJ_UINT32 l_size_comp, l_remaining; 8137 OPJ_UINT32 l_size_comp, l_remaining;
8023 OPJ_INT32 * l_dest_ptr; 8138 OPJ_INT32 * l_dest_ptr;
8024 opj_tcd_resolution_t* l_res= 00; 8139 opj_tcd_resolution_t* l_res= 00;
8025 8140
8026 l_tilec = p_tcd->tcd_image->tiles->comps; 8141 l_tilec = p_tcd->tcd_image->tiles->comps;
8027 l_image_src = p_tcd->image; 8142 l_image_src = p_tcd->image;
8028 l_img_comp_src = l_image_src->comps; 8143 l_img_comp_src = l_image_src->comps;
8029 8144
8030 l_img_comp_dest = p_output_image->comps; 8145 l_img_comp_dest = p_output_image->comps;
8031 8146
8032 for (i=0; i<l_image_src->numcomps; i++) { 8147 for (i=0; i<l_image_src->numcomps; i++) {
8033 8148
8034 /* Allocate output component buffer if necessary */ 8149 /* Allocate output component buffer if necessary */
8035 if (!l_img_comp_dest->data) { 8150 if (!l_img_comp_dest->data) {
8036 OPJ_UINT32 width = l_img_comp_dest->w; 8151 OPJ_UINT32 width = l_img_comp_dest->w;
8037 OPJ_UINT32 height = l_img_comp_dest->h; 8152 OPJ_UINT32 height = l_img_comp_dest->h;
8038 const OPJ_UINT32 MAX_SIZE = UINT32_MAX / sizeof(OPJ_INT32); 8153 const OPJ_UINT32 MAX_SIZE = UINT32_MAX / sizeof(OPJ_INT32);
8039 if (height == 0 || width > MAX_SIZE / height) { 8154 if (height == 0 || width > MAX_SIZE / height) {
8040 return OPJ_FALSE; 8155 return OPJ_FALSE;
8041 } 8156 }
8042 l_img_comp_dest->data = (OPJ_INT32*) opj_calloc(width * heig ht, sizeof(OPJ_INT32)); 8157 l_img_comp_dest->data = (OPJ_INT32*)opj_calloc(width * heigh t, sizeof(OPJ_INT32));
8043 if (!l_img_comp_dest->data) { 8158 if (!l_img_comp_dest->data) {
8044 return OPJ_FALSE; 8159 return OPJ_FALSE;
8045 } 8160 }
8046 } 8161 }
8047 8162
8048 /* Copy info from decoded comp image to output image */ 8163 /* Copy info from decoded comp image to output image */
8049 l_img_comp_dest->resno_decoded = l_img_comp_src->resno_decoded; 8164 l_img_comp_dest->resno_decoded = l_img_comp_src->resno_decoded;
8050 8165
8051 /*-----*/ 8166 /*-----*/
8052 /* Compute the precision of the output buffer */ 8167 /* Compute the precision of the output buffer */
(...skipping 13 matching lines...) Expand all
8066 /* Current tile component size*/ 8181 /* Current tile component size*/
8067 /*if (i == 0) { 8182 /*if (i == 0) {
8068 fprintf(stdout, "SRC: l_res_x0=%d, l_res_x1=%d, l_res_y0=%d, l_r es_y1=%d\n", 8183 fprintf(stdout, "SRC: l_res_x0=%d, l_res_x1=%d, l_res_y0=%d, l_r es_y1=%d\n",
8069 l_res->x0, l_res->x1, l_res->y0, l_res->y1); 8184 l_res->x0, l_res->x1, l_res->y0, l_res->y1);
8070 }*/ 8185 }*/
8071 8186
8072 l_width_src = (OPJ_UINT32)(l_res->x1 - l_res->x0); 8187 l_width_src = (OPJ_UINT32)(l_res->x1 - l_res->x0);
8073 l_height_src = (OPJ_UINT32)(l_res->y1 - l_res->y0); 8188 l_height_src = (OPJ_UINT32)(l_res->y1 - l_res->y0);
8074 8189
8075 /* Border of the current output component*/ 8190 /* Border of the current output component*/
8076 l_x0_dest = (OPJ_UINT32)opj_int_ceildivpow2((OPJ_INT32)l_img_com p_dest->x0, (OPJ_INT32)l_img_comp_dest->factor); 8191 l_x0_dest = opj_uint_ceildivpow2(l_img_comp_dest->x0, l_img_comp _dest->factor);
8077 l_y0_dest = (OPJ_UINT32)opj_int_ceildivpow2((OPJ_INT32)l_img_com p_dest->y0, (OPJ_INT32)l_img_comp_dest->factor); 8192 l_y0_dest = opj_uint_ceildivpow2(l_img_comp_dest->y0, l_img_comp _dest->factor);
8078 l_x1_dest = l_x0_dest + l_img_comp_dest->w; 8193 l_x1_dest = l_x0_dest + l_img_comp_dest->w; /* can't overflow gi ven that image->x1 is uint32 */
8079 l_y1_dest = l_y0_dest + l_img_comp_dest->h; 8194 l_y1_dest = l_y0_dest + l_img_comp_dest->h;
8080 8195
8081 /*if (i == 0) { 8196 /*if (i == 0) {
8082 fprintf(stdout, "DEST: l_x0_dest=%d, l_x1_dest=%d, l_y0_dest=%d, l_y1_dest=%d (%d)\n", 8197 fprintf(stdout, "DEST: l_x0_dest=%d, l_x1_dest=%d, l_y0_dest=%d, l_y1_dest=%d (%d)\n",
8083 l_x0_dest, l_x1_dest, l_y0_dest, l_y1_dest, l_im g_comp_dest->factor ); 8198 l_x0_dest, l_x1_dest, l_y0_dest, l_y1_dest, l_im g_comp_dest->factor );
8084 }*/ 8199 }*/
8085 8200
8086 /*-----*/ 8201 /*-----*/
8087 /* Compute the area (l_offset_x0_src, l_offset_y0_src, l_offset_ x1_src, l_offset_y1_src) 8202 /* Compute the area (l_offset_x0_src, l_offset_y0_src, l_offset_ x1_src, l_offset_y1_src)
8088 * of the input buffer (decoded tile component) which will be mo ve 8203 * of the input buffer (decoded tile component) which will be mo ve
(...skipping 10 matching lines...) Expand all
8099 if ( l_x1_dest >= (OPJ_UINT32)l_res->x1 ) { 8214 if ( l_x1_dest >= (OPJ_UINT32)l_res->x1 ) {
8100 l_width_dest = l_width_src; 8215 l_width_dest = l_width_src;
8101 l_offset_x1_src = 0; 8216 l_offset_x1_src = 0;
8102 } 8217 }
8103 else { 8218 else {
8104 l_width_dest = l_x1_dest - (OPJ_UINT32)l_res->x0 ; 8219 l_width_dest = l_x1_dest - (OPJ_UINT32)l_res->x0 ;
8105 l_offset_x1_src = (OPJ_INT32)(l_width_src - l_wi dth_dest); 8220 l_offset_x1_src = (OPJ_INT32)(l_width_src - l_wi dth_dest);
8106 } 8221 }
8107 } 8222 }
8108 else { 8223 else {
8109 l_start_x_dest = 0 ; 8224 l_start_x_dest = 0U;
8110 l_offset_x0_src = (OPJ_INT32)l_x0_dest - l_res->x0; 8225 l_offset_x0_src = (OPJ_INT32)l_x0_dest - l_res->x0;
8111 8226
8112 if ( l_x1_dest >= (OPJ_UINT32)l_res->x1 ) { 8227 if ( l_x1_dest >= (OPJ_UINT32)l_res->x1 ) {
8113 l_width_dest = l_width_src - (OPJ_UINT32)l_offse t_x0_src; 8228 l_width_dest = l_width_src - (OPJ_UINT32)l_offse t_x0_src;
8114 l_offset_x1_src = 0; 8229 l_offset_x1_src = 0;
8115 } 8230 }
8116 else { 8231 else {
8117 l_width_dest = l_img_comp_dest->w ; 8232 l_width_dest = l_img_comp_dest->w ;
8118 l_offset_x1_src = l_res->x1 - (OPJ_INT32)l_x1_de st; 8233 l_offset_x1_src = l_res->x1 - (OPJ_INT32)l_x1_de st;
8119 } 8234 }
8120 } 8235 }
8121 8236
8122 if ( l_y0_dest < (OPJ_UINT32)l_res->y0 ) { 8237 if ( l_y0_dest < (OPJ_UINT32)l_res->y0 ) {
8123 l_start_y_dest = (OPJ_UINT32)l_res->y0 - l_y0_dest; 8238 l_start_y_dest = (OPJ_UINT32)l_res->y0 - l_y0_dest;
8124 l_offset_y0_src = 0; 8239 l_offset_y0_src = 0;
8125 8240
8126 if ( l_y1_dest >= (OPJ_UINT32)l_res->y1 ) { 8241 if ( l_y1_dest >= (OPJ_UINT32)l_res->y1 ) {
8127 l_height_dest = l_height_src; 8242 l_height_dest = l_height_src;
8128 l_offset_y1_src = 0; 8243 l_offset_y1_src = 0;
8129 } 8244 }
8130 else { 8245 else {
8131 l_height_dest = l_y1_dest - (OPJ_UINT32)l_res->y 0 ; 8246 l_height_dest = l_y1_dest - (OPJ_UINT32)l_res->y 0 ;
8132 l_offset_y1_src = (OPJ_INT32)(l_height_src - l_ height_dest); 8247 l_offset_y1_src = (OPJ_INT32)(l_height_src - l_ height_dest);
8133 } 8248 }
8134 } 8249 }
8135 else { 8250 else {
8136 l_start_y_dest = 0 ; 8251 l_start_y_dest = 0U;
8137 l_offset_y0_src = (OPJ_INT32)l_y0_dest - l_res->y0; 8252 l_offset_y0_src = (OPJ_INT32)l_y0_dest - l_res->y0;
8138 8253
8139 if ( l_y1_dest >= (OPJ_UINT32)l_res->y1 ) { 8254 if ( l_y1_dest >= (OPJ_UINT32)l_res->y1 ) {
8140 l_height_dest = l_height_src - (OPJ_UINT32)l_off set_y0_src; 8255 l_height_dest = l_height_src - (OPJ_UINT32)l_off set_y0_src;
8141 l_offset_y1_src = 0; 8256 l_offset_y1_src = 0;
8142 } 8257 }
8143 else { 8258 else {
8144 l_height_dest = l_img_comp_dest->h ; 8259 l_height_dest = l_img_comp_dest->h ;
8145 l_offset_y1_src = l_res->y1 - (OPJ_INT32)l_y1_de st; 8260 l_offset_y1_src = l_res->y1 - (OPJ_INT32)l_y1_de st;
8146 } 8261 }
8147 } 8262 }
8148 8263
8149 if( (l_offset_x0_src < 0 ) || (l_offset_y0_src < 0 ) || (l_offse t_x1_src < 0 ) || (l_offset_y1_src < 0 ) ){ 8264 if( (l_offset_x0_src < 0 ) || (l_offset_y0_src < 0 ) || (l_offse t_x1_src < 0 ) || (l_offset_y1_src < 0 ) ){
8150 return OPJ_FALSE; 8265 return OPJ_FALSE;
8151 } 8266 }
8152 /* testcase 2977.pdf.asan.67.2198 */ 8267 /* testcase 2977.pdf.asan.67.2198 */
8153 if ((OPJ_INT32)l_width_dest < 0 || (OPJ_INT32)l_height_dest < 0) { 8268 if ((OPJ_INT32)l_width_dest < 0 || (OPJ_INT32)l_height_dest < 0) {
8154 return OPJ_FALSE; 8269 return OPJ_FALSE;
8155 } 8270 }
8156 /*-----*/ 8271 /*-----*/
8157 8272
8158 /* Compute the input buffer offset */ 8273 /* Compute the input buffer offset */
8159 l_start_offset_src = l_offset_x0_src + l_offset_y0_src * (OPJ_IN T32)l_width_src; 8274 l_start_offset_src = (OPJ_SIZE_T)l_offset_x0_src + (OPJ_SIZE_T)l _offset_y0_src * (OPJ_SIZE_T)l_width_src;
8160 l_line_offset_src = l_offset_x1_src + l_offset_x0_src; 8275 l_line_offset_src = (OPJ_SIZE_T)l_offset_x1_src + (OPJ_SIZE_T)l _offset_x0_src;
8161 l_end_offset_src = l_offset_y1_src * (OPJ_INT32)l_width_src - l_ offset_x0_src; 8276 l_end_offset_src = (OPJ_SIZE_T)l_offset_y1_src * (OPJ_SIZE_T)l _width_src - (OPJ_SIZE_T)l_offset_x0_src;
8162 8277
8163 /* Compute the output buffer offset */ 8278 /* Compute the output buffer offset */
8164 l_start_offset_dest = (OPJ_INT32)(l_start_x_dest + l_start_y_des t * l_img_comp_dest->w); 8279 l_start_offset_dest = (OPJ_SIZE_T)l_start_x_dest + (OPJ_SIZE_T)l _start_y_dest * (OPJ_SIZE_T)l_img_comp_dest->w;
8165 l_line_offset_dest = (OPJ_INT32)(l_img_comp_dest->w - l_width_de st); 8280 l_line_offset_dest = (OPJ_SIZE_T)l_img_comp_dest->w - (OPJ_SIZE _T)l_width_dest;
8166 8281
8167 /* Move the output buffer to the first place where we will write */ 8282 /* Move the output buffer to the first place where we will write */
8168 l_dest_ptr = l_img_comp_dest->data + l_start_offset_dest; 8283 l_dest_ptr = l_img_comp_dest->data + l_start_offset_dest;
8169 8284
8170 /*if (i == 0) { 8285 /*if (i == 0) {
8171 fprintf(stdout, "COMPO[%d]:\n",i); 8286 fprintf(stdout, "COMPO[%d]:\n",i);
8172 fprintf(stdout, "SRC: l_start_x_src=%d, l_start_y_src=%d , l_width_src=%d, l_height_src=%d\n" 8287 fprintf(stdout, "SRC: l_start_x_src=%d, l_start_y_src=%d , l_width_src=%d, l_height_src=%d\n"
8173 "\t tile offset:%d, %d, %d, %d\n" 8288 "\t tile offset:%d, %d, %d, %d\n"
8174 "\t buffer offset: %d; %d, %d\n", 8289 "\t buffer offset: %d; %d, %d\n",
8175 l_res->x0, l_res->y0, l_width_src, l_hei ght_src, 8290 l_res->x0, l_res->y0, l_width_src, l_hei ght_src,
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
8429 opj_j2k_t* opj_j2k_create_decompress(void) 8544 opj_j2k_t* opj_j2k_create_decompress(void)
8430 { 8545 {
8431 opj_j2k_t *l_j2k = (opj_j2k_t*) opj_calloc(1,sizeof(opj_j2k_t)); 8546 opj_j2k_t *l_j2k = (opj_j2k_t*) opj_calloc(1,sizeof(opj_j2k_t));
8432 if (!l_j2k) { 8547 if (!l_j2k) {
8433 return 00; 8548 return 00;
8434 } 8549 }
8435 8550
8436 l_j2k->m_is_decoder = 1; 8551 l_j2k->m_is_decoder = 1;
8437 l_j2k->m_cp.m_is_decoder = 1; 8552 l_j2k->m_cp.m_is_decoder = 1;
8438 8553
8554 #ifdef OPJ_DISABLE_TPSOT_FIX
8555 l_j2k->m_specific_param.m_decoder.m_nb_tile_parts_correction_checked = 1 ;
8556 #endif
8557
8439 l_j2k->m_specific_param.m_decoder.m_default_tcp = (opj_tcp_t*) opj_callo c(1,sizeof(opj_tcp_t)); 8558 l_j2k->m_specific_param.m_decoder.m_default_tcp = (opj_tcp_t*) opj_callo c(1,sizeof(opj_tcp_t));
8440 if (!l_j2k->m_specific_param.m_decoder.m_default_tcp) { 8559 if (!l_j2k->m_specific_param.m_decoder.m_default_tcp) {
8441 opj_j2k_destroy(l_j2k); 8560 opj_j2k_destroy(l_j2k);
8442 return 00; 8561 return 00;
8443 } 8562 }
8444 8563
8445 l_j2k->m_specific_param.m_decoder.m_header_data = (OPJ_BYTE *) opj_callo c(1,OPJ_J2K_DEFAULT_HEADER_SIZE); 8564 l_j2k->m_specific_param.m_decoder.m_header_data = (OPJ_BYTE *) opj_callo c(1,OPJ_J2K_DEFAULT_HEADER_SIZE);
8446 if (! l_j2k->m_specific_param.m_decoder.m_header_data) { 8565 if (! l_j2k->m_specific_param.m_decoder.m_header_data) {
8447 opj_j2k_destroy(l_j2k); 8566 opj_j2k_destroy(l_j2k);
8448 return 00; 8567 return 00;
(...skipping 22 matching lines...) Expand all
8471 /* execution list creation */ 8590 /* execution list creation */
8472 l_j2k->m_procedure_list = opj_procedure_list_create(); 8591 l_j2k->m_procedure_list = opj_procedure_list_create();
8473 if (! l_j2k->m_procedure_list) { 8592 if (! l_j2k->m_procedure_list) {
8474 opj_j2k_destroy(l_j2k); 8593 opj_j2k_destroy(l_j2k);
8475 return 00; 8594 return 00;
8476 } 8595 }
8477 8596
8478 return l_j2k; 8597 return l_j2k;
8479 } 8598 }
8480 8599
8481 opj_codestream_index_t* opj_j2k_create_cstr_index(void) 8600 static opj_codestream_index_t* opj_j2k_create_cstr_index(void)
8482 { 8601 {
8483 opj_codestream_index_t* cstr_index = (opj_codestream_index_t*) 8602 opj_codestream_index_t* cstr_index = (opj_codestream_index_t*)
8484 opj_calloc(1,sizeof(opj_codestream_index_t)); 8603 opj_calloc(1,sizeof(opj_codestream_index_t));
8485 if (!cstr_index) 8604 if (!cstr_index)
8486 return NULL; 8605 return NULL;
8487 8606
8488 cstr_index->maxmarknum = 100; 8607 cstr_index->maxmarknum = 100;
8489 cstr_index->marknum = 0; 8608 cstr_index->marknum = 0;
8490 cstr_index->marker = (opj_marker_info_t*) 8609 cstr_index->marker = (opj_marker_info_t*)
8491 opj_calloc(cstr_index->maxmarknum, sizeof(opj_marker_inf o_t)); 8610 opj_calloc(cstr_index->maxmarknum, sizeof(opj_marker_inf o_t));
8492 if (!cstr_index-> marker) 8611 if (!cstr_index-> marker) {
8612 opj_free(cstr_index);
8493 return NULL; 8613 return NULL;
8614 }
8494 8615
8495 cstr_index->tile_index = NULL; 8616 cstr_index->tile_index = NULL;
8496 8617
8497 return cstr_index; 8618 return cstr_index;
8498 } 8619 }
8499 8620
8500 OPJ_UINT32 opj_j2k_get_SPCod_SPCoc_size ( opj_j2k_t *p_j2k, 8621 static OPJ_UINT32 opj_j2k_get_SPCod_SPCoc_size ( opj_j2k_t *p_j2k,
8501 OPJ_UINT32 p_tile_no, 8622 OPJ_UINT32 p_tile_no,
8502 OPJ_UINT32 p_comp_no ) 8623 OPJ_UINT32 p_comp_no )
8503 { 8624 {
8504 opj_cp_t *l_cp = 00; 8625 opj_cp_t *l_cp = 00;
8505 opj_tcp_t *l_tcp = 00; 8626 opj_tcp_t *l_tcp = 00;
8506 opj_tccp_t *l_tccp = 00; 8627 opj_tccp_t *l_tccp = 00;
8507 8628
8508 /* preconditions */ 8629 /* preconditions */
8509 assert(p_j2k != 00); 8630 assert(p_j2k != 00);
8510 8631
8511 l_cp = &(p_j2k->m_cp); 8632 l_cp = &(p_j2k->m_cp);
8512 l_tcp = &l_cp->tcps[p_tile_no]; 8633 l_tcp = &l_cp->tcps[p_tile_no];
8513 l_tccp = &l_tcp->tccps[p_comp_no]; 8634 l_tccp = &l_tcp->tccps[p_comp_no];
8514 8635
8515 /* preconditions again */ 8636 /* preconditions again */
8516 assert(p_tile_no < (l_cp->tw * l_cp->th)); 8637 assert(p_tile_no < (l_cp->tw * l_cp->th));
8517 assert(p_comp_no < p_j2k->m_private_image->numcomps); 8638 assert(p_comp_no < p_j2k->m_private_image->numcomps);
8518 8639
8519 if (l_tccp->csty & J2K_CCP_CSTY_PRT) { 8640 if (l_tccp->csty & J2K_CCP_CSTY_PRT) {
8520 return 5 + l_tccp->numresolutions; 8641 return 5 + l_tccp->numresolutions;
8521 } 8642 }
8522 else { 8643 else {
8523 return 5; 8644 return 5;
8524 } 8645 }
8525 } 8646 }
8526 8647
8527 OPJ_BOOL opj_j2k_write_SPCod_SPCoc( opj_j2k_t *p_j2k, 8648 static OPJ_BOOL opj_j2k_write_SPCod_SPCoc( opj_j2k_t *p_j2k,
8528 OPJ_UINT32 p _tile_no, 8649 OPJ_UINT32 p _tile_no,
8529 OPJ_UINT32 p _comp_no, 8650 OPJ_UINT32 p _comp_no,
8530 OPJ_BYTE * p _data, 8651 OPJ_BYTE * p _data,
8531 OPJ_UINT32 * p_header_size, 8652 OPJ_UINT32 * p_header_size,
8532 struct opj_e vent_mgr * p_manager ) 8653 struct opj_e vent_mgr * p_manager )
8533 { 8654 {
8534 OPJ_UINT32 i; 8655 OPJ_UINT32 i;
8535 opj_cp_t *l_cp = 00; 8656 opj_cp_t *l_cp = 00;
8536 opj_tcp_t *l_tcp = 00; 8657 opj_tcp_t *l_tcp = 00;
8537 opj_tccp_t *l_tccp = 00; 8658 opj_tccp_t *l_tccp = 00;
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
8583 opj_write_bytes(p_data,l_tccp->prcw[i] + (l_tccp->prch[i ] << 4), 1); /* SPcoc (I_i) */ 8704 opj_write_bytes(p_data,l_tccp->prcw[i] + (l_tccp->prch[i ] << 4), 1); /* SPcoc (I_i) */
8584 ++p_data; 8705 ++p_data;
8585 } 8706 }
8586 8707
8587 *p_header_size = *p_header_size - l_tccp->numresolutions; 8708 *p_header_size = *p_header_size - l_tccp->numresolutions;
8588 } 8709 }
8589 8710
8590 return OPJ_TRUE; 8711 return OPJ_TRUE;
8591 } 8712 }
8592 8713
8593 OPJ_BOOL opj_j2k_read_SPCod_SPCoc( opj_j2k_t *p_j2k, 8714 static OPJ_BOOL opj_j2k_read_SPCod_SPCoc( opj_j2k_t *p_j2k,
8594 OPJ_UINT32 compn o, 8715 OPJ_UINT32 compn o,
8595 OPJ_BYTE * p_hea der_data, 8716 OPJ_BYTE * p_hea der_data,
8596 OPJ_UINT32 * p_h eader_size, 8717 OPJ_UINT32 * p_h eader_size,
8597 opj_event_mgr_t * p_manager) 8718 opj_event_mgr_t * p_manager)
8598 { 8719 {
8599 OPJ_UINT32 i, l_tmp; 8720 OPJ_UINT32 i, l_tmp;
8600 opj_cp_t *l_cp = NULL; 8721 opj_cp_t *l_cp = NULL;
8601 opj_tcp_t *l_tcp = NULL; 8722 opj_tcp_t *l_tcp = NULL;
8602 opj_tccp_t *l_tccp = NULL; 8723 opj_tccp_t *l_tccp = NULL;
8603 OPJ_BYTE * l_current_ptr = NULL; 8724 OPJ_BYTE * l_current_ptr = NULL;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
8706 8827
8707 memcpy(p_j2k->cstr_info->tile[p_j2k->m_current_tile_number].pdx, l_tccp->prcw, l_data_size); 8828 memcpy(p_j2k->cstr_info->tile[p_j2k->m_current_tile_number].pdx, l_tccp->prcw, l_data_size);
8708 memcpy(p_j2k->cstr_info->tile[p_j2k->m_current_tile_number].pdy, l_tccp->prch, l_data_size); 8829 memcpy(p_j2k->cstr_info->tile[p_j2k->m_current_tile_number].pdy, l_tccp->prch, l_data_size);
8709 } 8830 }
8710 /* << INDEX */ 8831 /* << INDEX */
8711 #endif 8832 #endif
8712 8833
8713 return OPJ_TRUE; 8834 return OPJ_TRUE;
8714 } 8835 }
8715 8836
8716 void opj_j2k_copy_tile_component_parameters( opj_j2k_t *p_j2k ) 8837 static void opj_j2k_copy_tile_component_parameters( opj_j2k_t *p_j2k )
8717 { 8838 {
8718 /* loop */ 8839 /* loop */
8719 OPJ_UINT32 i; 8840 OPJ_UINT32 i;
8720 opj_cp_t *l_cp = NULL; 8841 opj_cp_t *l_cp = NULL;
8721 opj_tcp_t *l_tcp = NULL; 8842 opj_tcp_t *l_tcp = NULL;
8722 opj_tccp_t *l_ref_tccp = NULL, *l_copied_tccp = NULL; 8843 opj_tccp_t *l_ref_tccp = NULL, *l_copied_tccp = NULL;
8723 OPJ_UINT32 l_prc_size; 8844 OPJ_UINT32 l_prc_size;
8724 8845
8725 /* preconditions */ 8846 /* preconditions */
8726 assert(p_j2k != 00); 8847 assert(p_j2k != 00);
(...skipping 12 matching lines...) Expand all
8739 l_copied_tccp->cblkw = l_ref_tccp->cblkw; 8860 l_copied_tccp->cblkw = l_ref_tccp->cblkw;
8740 l_copied_tccp->cblkh = l_ref_tccp->cblkh; 8861 l_copied_tccp->cblkh = l_ref_tccp->cblkh;
8741 l_copied_tccp->cblksty = l_ref_tccp->cblksty; 8862 l_copied_tccp->cblksty = l_ref_tccp->cblksty;
8742 l_copied_tccp->qmfbid = l_ref_tccp->qmfbid; 8863 l_copied_tccp->qmfbid = l_ref_tccp->qmfbid;
8743 memcpy(l_copied_tccp->prcw,l_ref_tccp->prcw,l_prc_size); 8864 memcpy(l_copied_tccp->prcw,l_ref_tccp->prcw,l_prc_size);
8744 memcpy(l_copied_tccp->prch,l_ref_tccp->prch,l_prc_size); 8865 memcpy(l_copied_tccp->prch,l_ref_tccp->prch,l_prc_size);
8745 ++l_copied_tccp; 8866 ++l_copied_tccp;
8746 } 8867 }
8747 } 8868 }
8748 8869
8749 OPJ_UINT32 opj_j2k_get_SQcd_SQcc_size ( opj_j2k_t *p_j2k, 8870 static OPJ_UINT32 opj_j2k_get_SQcd_SQcc_size ( opj_j2k_t *p_j2k,
8750 OPJ_UINT 32 p_tile_no, 8871 OPJ_UINT 32 p_tile_no,
8751 OPJ_UINT 32 p_comp_no ) 8872 OPJ_UINT 32 p_comp_no )
8752 { 8873 {
8753 OPJ_UINT32 l_num_bands; 8874 OPJ_UINT32 l_num_bands;
8754 8875
8755 opj_cp_t *l_cp = 00; 8876 opj_cp_t *l_cp = 00;
8756 opj_tcp_t *l_tcp = 00; 8877 opj_tcp_t *l_tcp = 00;
8757 opj_tccp_t *l_tccp = 00; 8878 opj_tccp_t *l_tccp = 00;
8758 8879
8759 /* preconditions */ 8880 /* preconditions */
(...skipping 10 matching lines...) Expand all
8770 l_num_bands = (l_tccp->qntsty == J2K_CCP_QNTSTY_SIQNT) ? 1 : (l_tccp->nu mresolutions * 3 - 2); 8891 l_num_bands = (l_tccp->qntsty == J2K_CCP_QNTSTY_SIQNT) ? 1 : (l_tccp->nu mresolutions * 3 - 2);
8771 8892
8772 if (l_tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) { 8893 if (l_tccp->qntsty == J2K_CCP_QNTSTY_NOQNT) {
8773 return 1 + l_num_bands; 8894 return 1 + l_num_bands;
8774 } 8895 }
8775 else { 8896 else {
8776 return 1 + 2*l_num_bands; 8897 return 1 + 2*l_num_bands;
8777 } 8898 }
8778 } 8899 }
8779 8900
8780 OPJ_BOOL opj_j2k_write_SQcd_SQcc( opj_j2k_t *p_j2k, 8901 static OPJ_BOOL opj_j2k_write_SQcd_SQcc( opj_j2k_t *p_j2k,
8781 OPJ_UINT32 p_til e_no, 8902 OPJ_UINT32 p_til e_no,
8782 OPJ_UINT32 p_com p_no, 8903 OPJ_UINT32 p_com p_no,
8783 OPJ_BYTE * p_dat a, 8904 OPJ_BYTE * p_dat a,
8784 OPJ_UINT32 * p_h eader_size, 8905 OPJ_UINT32 * p_h eader_size,
8785 struct opj_event _mgr * p_manager ) 8906 struct opj_event _mgr * p_manager )
8786 { 8907 {
8787 OPJ_UINT32 l_header_size; 8908 OPJ_UINT32 l_header_size;
8788 OPJ_UINT32 l_band_no, l_num_bands; 8909 OPJ_UINT32 l_band_no, l_num_bands;
8789 OPJ_UINT32 l_expn,l_mant; 8910 OPJ_UINT32 l_expn,l_mant;
8790 8911
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
8843 opj_write_bytes(p_data, (l_expn << 11) + l_mant, 2); /* SPqcx_i */ 8964 opj_write_bytes(p_data, (l_expn << 11) + l_mant, 2); /* SPqcx_i */
8844 p_data += 2; 8965 p_data += 2;
8845 } 8966 }
8846 } 8967 }
8847 8968
8848 *p_header_size = *p_header_size - l_header_size; 8969 *p_header_size = *p_header_size - l_header_size;
8849 8970
8850 return OPJ_TRUE; 8971 return OPJ_TRUE;
8851 } 8972 }
8852 8973
8853 OPJ_BOOL opj_j2k_read_SQcd_SQcc(opj_j2k_t *p_j2k, 8974 static OPJ_BOOL opj_j2k_read_SQcd_SQcc(opj_j2k_t *p_j2k,
8854 OPJ_UINT32 p_comp_no , 8975 OPJ_UINT32 p_comp_no ,
8855 OPJ_BYTE* p_header_d ata, 8976 OPJ_BYTE* p_header_d ata,
8856 OPJ_UINT32 * p_heade r_size, 8977 OPJ_UINT32 * p_heade r_size,
8857 opj_event_mgr_t * p_ manager 8978 opj_event_mgr_t * p_ manager
8858 ) 8979 )
8859 { 8980 {
8860 /* loop*/ 8981 /* loop*/
8861 OPJ_UINT32 l_band_no; 8982 OPJ_UINT32 l_band_no;
8862 opj_cp_t *l_cp = 00; 8983 opj_cp_t *l_cp = 00;
8863 opj_tcp_t *l_tcp = 00; 8984 opj_tcp_t *l_tcp = 00;
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
8960 l_tccp->stepsizes[l_band_no].expn = 9081 l_tccp->stepsizes[l_band_no].expn =
8961 ((OPJ_INT32)(l_tccp->stepsizes[0].expn) - (OPJ_I NT32)((l_band_no - 1) / 3) > 0) ? 9082 ((OPJ_INT32)(l_tccp->stepsizes[0].expn) - (OPJ_I NT32)((l_band_no - 1) / 3) > 0) ?
8962 (OPJ_INT32)(l_tccp->stepsizes[0].expn) - (OPJ_INT32)((l_band_no - 1) / 3) : 0; 9083 (OPJ_INT32)(l_tccp->stepsizes[0].expn) - (OPJ_INT32)((l_band_no - 1) / 3) : 0;
8963 l_tccp->stepsizes[l_band_no].mant = l_tccp->stepsizes[0] .mant; 9084 l_tccp->stepsizes[l_band_no].mant = l_tccp->stepsizes[0] .mant;
8964 } 9085 }
8965 } 9086 }
8966 9087
8967 return OPJ_TRUE; 9088 return OPJ_TRUE;
8968 } 9089 }
8969 9090
8970 void opj_j2k_copy_tile_quantization_parameters( opj_j2k_t *p_j2k ) 9091 static void opj_j2k_copy_tile_quantization_parameters( opj_j2k_t *p_j2k )
8971 { 9092 {
8972 OPJ_UINT32 i; 9093 OPJ_UINT32 i;
8973 opj_cp_t *l_cp = NULL; 9094 opj_cp_t *l_cp = NULL;
8974 opj_tcp_t *l_tcp = NULL; 9095 opj_tcp_t *l_tcp = NULL;
8975 opj_tccp_t *l_ref_tccp = NULL; 9096 opj_tccp_t *l_ref_tccp = NULL;
8976 opj_tccp_t *l_copied_tccp = NULL; 9097 opj_tccp_t *l_copied_tccp = NULL;
8977 OPJ_UINT32 l_size; 9098 OPJ_UINT32 l_size;
8978 9099
8979 /* preconditions */ 9100 /* preconditions */
8980 assert(p_j2k != 00); 9101 assert(p_j2k != 00);
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after
9087 opj_j2k_dump_MH_index(p_j2k, out_stream); 9208 opj_j2k_dump_MH_index(p_j2k, out_stream);
9088 } 9209 }
9089 9210
9090 /* Dump the codestream index of the current tile */ 9211 /* Dump the codestream index of the current tile */
9091 if (flag & OPJ_J2K_TH_IND){ 9212 if (flag & OPJ_J2K_TH_IND){
9092 9213
9093 } 9214 }
9094 9215
9095 } 9216 }
9096 9217
9097 void opj_j2k_dump_MH_index(opj_j2k_t* p_j2k, FILE* out_stream) 9218 static void opj_j2k_dump_MH_index(opj_j2k_t* p_j2k, FILE* out_stream)
9098 { 9219 {
9099 opj_codestream_index_t* cstr_index = p_j2k->cstr_index; 9220 opj_codestream_index_t* cstr_index = p_j2k->cstr_index;
9100 OPJ_UINT32 it_marker, it_tile, it_tile_part; 9221 OPJ_UINT32 it_marker, it_tile, it_tile_part;
9101 9222
9102 fprintf(out_stream, "Codestream index from main header: {\n"); 9223 fprintf(out_stream, "Codestream index from main header: {\n");
9103 9224
9104 fprintf(out_stream, "\t Main header start position=%" PRIi64 "\n" 9225 fprintf(out_stream, "\t Main header start position=%" PRIi64 "\n"
9105 "\t Main header end position=%" PRIi64 "\n", 9226 "\t Main header end position=%" PRIi64 "\n",
9106 cstr_index->main_head_start, cstr_index->main_head_end); 9227 cstr_index->main_head_start, cstr_index->main_head_end);
9107 9228
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
9156 } 9277 }
9157 fprintf(out_stream,"\t }\n"); 9278 fprintf(out_stream,"\t }\n");
9158 } 9279 }
9159 } 9280 }
9160 9281
9161 fprintf(out_stream,"}\n"); 9282 fprintf(out_stream,"}\n");
9162 9283
9163 } 9284 }
9164 9285
9165 9286
9166 void opj_j2k_dump_MH_info(opj_j2k_t* p_j2k, FILE* out_stream) 9287 static void opj_j2k_dump_MH_info(opj_j2k_t* p_j2k, FILE* out_stream)
9167 { 9288 {
9168 9289
9169 fprintf(out_stream, "Codestream info from main header: {\n"); 9290 fprintf(out_stream, "Codestream info from main header: {\n");
9170 9291
9171 fprintf(out_stream, "\t tx0=%d, ty0=%d\n", p_j2k->m_cp.tx0, p_j2k->m_cp. ty0); 9292 fprintf(out_stream, "\t tx0=%d, ty0=%d\n", p_j2k->m_cp.tx0, p_j2k->m_cp. ty0);
9172 fprintf(out_stream, "\t tdx=%d, tdy=%d\n", p_j2k->m_cp.tdx, p_j2k->m_cp. tdy); 9293 fprintf(out_stream, "\t tdx=%d, tdy=%d\n", p_j2k->m_cp.tdx, p_j2k->m_cp. tdy);
9173 fprintf(out_stream, "\t tw=%d, th=%d\n", p_j2k->m_cp.tw, p_j2k->m_cp.th) ; 9294 fprintf(out_stream, "\t tw=%d, th=%d\n", p_j2k->m_cp.tw, p_j2k->m_cp.th) ;
9174 opj_j2k_dump_tile_info(p_j2k->m_specific_param.m_decoder.m_default_tcp,( OPJ_INT32)p_j2k->m_private_image->numcomps, out_stream); 9295 opj_j2k_dump_tile_info(p_j2k->m_specific_param.m_decoder.m_default_tcp,( OPJ_INT32)p_j2k->m_private_image->numcomps, out_stream);
9175 fprintf(out_stream, "}\n"); 9296 fprintf(out_stream, "}\n");
9176 } 9297 }
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
9396 /* Packet index (NOT USED)*/ 9517 /* Packet index (NOT USED)*/
9397 l_cstr_index->tile_index[it_tile].nb_packet = 0; 9518 l_cstr_index->tile_index[it_tile].nb_packet = 0;
9398 l_cstr_index->tile_index[it_tile].packet_index = NULL; 9519 l_cstr_index->tile_index[it_tile].packet_index = NULL;
9399 9520
9400 } 9521 }
9401 } 9522 }
9402 9523
9403 return l_cstr_index; 9524 return l_cstr_index;
9404 } 9525 }
9405 9526
9406 OPJ_BOOL opj_j2k_allocate_tile_element_cstr_index(opj_j2k_t *p_j2k) 9527 static OPJ_BOOL opj_j2k_allocate_tile_element_cstr_index(opj_j2k_t *p_j2k)
9407 { 9528 {
9408 OPJ_UINT32 it_tile=0; 9529 OPJ_UINT32 it_tile=0;
9409 9530
9410 p_j2k->cstr_index->nb_of_tiles = p_j2k->m_cp.tw * p_j2k->m_cp.th; 9531 p_j2k->cstr_index->nb_of_tiles = p_j2k->m_cp.tw * p_j2k->m_cp.th;
9411 p_j2k->cstr_index->tile_index = (opj_tile_index_t*)opj_calloc(p_j2k->cst r_index->nb_of_tiles, sizeof(opj_tile_index_t)); 9532 p_j2k->cstr_index->tile_index = (opj_tile_index_t*)opj_calloc(p_j2k->cst r_index->nb_of_tiles, sizeof(opj_tile_index_t));
9412 if (!p_j2k->cstr_index->tile_index) 9533 if (!p_j2k->cstr_index->tile_index)
9413 return OPJ_FALSE; 9534 return OPJ_FALSE;
9414 9535
9415 for (it_tile=0; it_tile < p_j2k->cstr_index->nb_of_tiles; it_tile++){ 9536 for (it_tile=0; it_tile < p_j2k->cstr_index->nb_of_tiles; it_tile++){
9416 p_j2k->cstr_index->tile_index[it_tile].maxmarknum = 100; 9537 p_j2k->cstr_index->tile_index[it_tile].maxmarknum = 100;
9417 p_j2k->cstr_index->tile_index[it_tile].marknum = 0; 9538 p_j2k->cstr_index->tile_index[it_tile].marknum = 0;
9418 p_j2k->cstr_index->tile_index[it_tile].marker = (opj_marker_info _t*) 9539 p_j2k->cstr_index->tile_index[it_tile].marker = (opj_marker_info _t*)
9419 opj_calloc(p_j2k->cstr_index->tile_index[it_tile ].maxmarknum, sizeof(opj_marker_info_t)); 9540 opj_calloc(p_j2k->cstr_index->tile_index[it_tile ].maxmarknum, sizeof(opj_marker_info_t));
9420 if (!p_j2k->cstr_index->tile_index[it_tile].marker) 9541 if (!p_j2k->cstr_index->tile_index[it_tile].marker)
9421 return OPJ_FALSE; 9542 return OPJ_FALSE;
9422 } 9543 }
9423 9544
9424 return OPJ_TRUE; 9545 return OPJ_TRUE;
9425 } 9546 }
9426 9547
9427 OPJ_BOOL opj_j2k_decode_tiles ( opj_j2k_t *p_j2k, 9548 static OPJ_BOOL opj_j2k_decode_tiles ( opj_j2k_t *p_j2k,
9428 opj_stream_private_t *p_stream, 9549 opj_stream_private_t *p_stream,
9429 opj_event_mgr_t * p_ manager) 9550 opj_event_mgr_t * p_ manager)
9430 { 9551 {
9431 OPJ_BOOL l_go_on = OPJ_TRUE; 9552 OPJ_BOOL l_go_on = OPJ_TRUE;
9432 OPJ_UINT32 l_current_tile_no; 9553 OPJ_UINT32 l_current_tile_no;
9433 OPJ_UINT32 l_data_size,l_max_data_size; 9554 OPJ_UINT32 l_data_size,l_max_data_size;
9434 OPJ_INT32 l_tile_x0,l_tile_y0,l_tile_x1,l_tile_y1; 9555 OPJ_INT32 l_tile_x0,l_tile_y0,l_tile_x1,l_tile_y1;
9435 OPJ_UINT32 l_nb_comps; 9556 OPJ_UINT32 l_nb_comps;
9436 OPJ_BYTE * l_current_data; 9557 OPJ_BYTE * l_current_data;
9437 OPJ_UINT32 nr_tiles = 0; 9558 OPJ_UINT32 nr_tiles = 0;
9438 9559
9439 l_current_data = (OPJ_BYTE*)opj_malloc(1000); 9560 l_current_data = (OPJ_BYTE*)opj_malloc(1000);
9440 if (! l_current_data) { 9561 if (! l_current_data) {
9441 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to decode tiles\n"); 9562 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to decode tiles\n");
9442 return OPJ_FALSE; 9563 return OPJ_FALSE;
9443 } 9564 }
9444 l_max_data_size = 1000; 9565 l_max_data_size = 1000;
9445 9566
9446 while (OPJ_TRUE) { 9567 » » for (;;) {
9447 if (! opj_j2k_read_tile_header( p_j2k, 9568 if (! opj_j2k_read_tile_header( p_j2k,
9448 &l_current_tile_no, 9569 &l_current_tile_no,
9449 &l_data_size, 9570 &l_data_size,
9450 &l_tile_x0, &l_tile_y0, 9571 &l_tile_x0, &l_tile_y0,
9451 &l_tile_x1, &l_tile_y1, 9572 &l_tile_x1, &l_tile_y1,
9452 &l_nb_comps, 9573 &l_nb_comps,
9453 &l_go_on, 9574 &l_go_on,
9454 p_stream, 9575 p_stream,
9455 p_manager)) { 9576 p_manager)) {
9456 opj_free(l_current_data); 9577 opj_free(l_current_data);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
9493 } 9614 }
9494 9615
9495 opj_free(l_current_data); 9616 opj_free(l_current_data);
9496 9617
9497 return OPJ_TRUE; 9618 return OPJ_TRUE;
9498 } 9619 }
9499 9620
9500 /** 9621 /**
9501 * Sets up the procedures to do on decoding data. Developpers wanting to extend the library can add their own reading procedures. 9622 * Sets up the procedures to do on decoding data. Developpers wanting to extend the library can add their own reading procedures.
9502 */ 9623 */
9503 static void opj_j2k_setup_decoding (opj_j2k_t *p_j2k) 9624 static OPJ_BOOL opj_j2k_setup_decoding (opj_j2k_t *p_j2k, opj_event_mgr_t * p_ma nager)
9504 { 9625 {
9505 /* preconditions*/ 9626 /* preconditions*/
9506 assert(p_j2k != 00); 9627 assert(p_j2k != 00);
9628 assert(p_manager != 00);
9507 9629
9508 opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure) opj_j2k_decode_tiles); 9630 if (! opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_proc edure)opj_j2k_decode_tiles, p_manager)) {
9631 return OPJ_FALSE;
9632 }
9509 /* DEVELOPER CORNER, add your custom procedures */ 9633 /* DEVELOPER CORNER, add your custom procedures */
9510 9634
9635 return OPJ_TRUE;
9511 } 9636 }
9512 9637
9513 /* 9638 /*
9514 * Read and decode one tile. 9639 * Read and decode one tile.
9515 */ 9640 */
9516 static OPJ_BOOL opj_j2k_decode_one_tile ( opj_j2k_t *p_j2k, 9641 static OPJ_BOOL opj_j2k_decode_one_tile ( opj_j2k_t *p_j2k,
9517 opj_ stream_private_t *p_stream, 9642 opj_ stream_private_t *p_stream,
9518 opj_ event_mgr_t * p_manager) 9643 opj_ event_mgr_t * p_manager)
9519 { 9644 {
9520 OPJ_BOOL l_go_on = OPJ_TRUE; 9645 OPJ_BOOL l_go_on = OPJ_TRUE;
(...skipping 22 matching lines...) Expand all
9543 /* Move into the codestream to the first SOT used to decode the desired tile */ 9668 /* Move into the codestream to the first SOT used to decode the desired tile */
9544 l_tile_no_to_dec = (OPJ_UINT32)p_j2k->m_specific_param.m_decoder.m_tile_ ind_to_dec; 9669 l_tile_no_to_dec = (OPJ_UINT32)p_j2k->m_specific_param.m_decoder.m_tile_ ind_to_dec;
9545 if (p_j2k->cstr_index->tile_index) 9670 if (p_j2k->cstr_index->tile_index)
9546 if(p_j2k->cstr_index->tile_index->tp_index) 9671 if(p_j2k->cstr_index->tile_index->tp_index)
9547 { 9672 {
9548 if ( ! p_j2k->cstr_index->tile_index[l_tile_no_to_dec].n b_tps) { 9673 if ( ! p_j2k->cstr_index->tile_index[l_tile_no_to_dec].n b_tps) {
9549 /* the index for this tile has not been built, 9674 /* the index for this tile has not been built,
9550 * so move to the last SOT read */ 9675 * so move to the last SOT read */
9551 if ( !(opj_stream_read_seek(p_stream, p_j2k->m_s pecific_param.m_decoder.m_last_sot_read_pos+2, p_manager)) ){ 9676 if ( !(opj_stream_read_seek(p_stream, p_j2k->m_s pecific_param.m_decoder.m_last_sot_read_pos+2, p_manager)) ){
9552 opj_event_msg(p_manager, EVT_ERROR, "Pro blem with seek function\n"); 9677 opj_event_msg(p_manager, EVT_ERROR, "Pro blem with seek function\n");
9553 opj_free(l_current_data); 9678 opj_free(l_current_data);
9554 return OPJ_FALSE; 9679 return OPJ_FALSE;
9555 } 9680 }
9556 } 9681 }
9557 else{ 9682 else{
9558 if ( !(opj_stream_read_seek(p_stream, p_j2k->cst r_index->tile_index[l_tile_no_to_dec].tp_index[0].start_pos+2, p_manager)) ) { 9683 if ( !(opj_stream_read_seek(p_stream, p_j2k->cst r_index->tile_index[l_tile_no_to_dec].tp_index[0].start_pos+2, p_manager)) ) {
9559 opj_event_msg(p_manager, EVT_ERROR, "Pro blem with seek function\n"); 9684 opj_event_msg(p_manager, EVT_ERROR, "Pro blem with seek function\n");
9560 opj_free(l_current_data); 9685 opj_free(l_current_data);
9561 return OPJ_FALSE; 9686 return OPJ_FALSE;
9562 } 9687 }
9563 } 9688 }
9564 /* Special case if we have previously read the EOC marke r (if the previous tile getted is the last ) */ 9689 /* Special case if we have previously read the EOC marke r (if the previous tile getted is the last ) */
9565 if(p_j2k->m_specific_param.m_decoder.m_state == J2K_STAT E_EOC) 9690 if(p_j2k->m_specific_param.m_decoder.m_state == J2K_STAT E_EOC)
9566 p_j2k->m_specific_param.m_decoder.m_state = J2K_ STATE_TPHSOT; 9691 p_j2k->m_specific_param.m_decoder.m_state = J2K_ STATE_TPHSOT;
9567 } 9692 }
9568 9693
9569 while (OPJ_TRUE) { 9694 » » for (;;) {
9570 if (! opj_j2k_read_tile_header( p_j2k, 9695 if (! opj_j2k_read_tile_header( p_j2k,
9571 &l_current_tile_no, 9696 &l_current_tile_no,
9572 &l_data_size, 9697 &l_data_size,
9573 &l_tile_x0, &l_tile_y0, 9698 &l_tile_x0, &l_tile_y0,
9574 &l_tile_x1, &l_tile_y1, 9699 &l_tile_x1, &l_tile_y1,
9575 &l_nb_comps, 9700 &l_nb_comps,
9576 &l_go_on, 9701 &l_go_on,
9577 p_stream, 9702 p_stream,
9578 p_manager)) { 9703 p_manager)) {
9579 opj_free(l_current_data); 9704 opj_free(l_current_data);
(...skipping 28 matching lines...) Expand all
9608 opj_free(l_current_data); 9733 opj_free(l_current_data);
9609 return OPJ_FALSE; 9734 return OPJ_FALSE;
9610 } 9735 }
9611 opj_event_msg(p_manager, EVT_INFO, "Image data has been updated with tile %d.\n\n", l_current_tile_no); 9736 opj_event_msg(p_manager, EVT_INFO, "Image data has been updated with tile %d.\n\n", l_current_tile_no);
9612 9737
9613 if(l_current_tile_no == l_tile_no_to_dec) 9738 if(l_current_tile_no == l_tile_no_to_dec)
9614 { 9739 {
9615 /* move into the codestream to the the first SOT (FIXME or not move?)*/ 9740 /* move into the codestream to the the first SOT (FIXME or not move?)*/
9616 if (!(opj_stream_read_seek(p_stream, p_j2k->cstr_index-> main_head_end + 2, p_manager) ) ) { 9741 if (!(opj_stream_read_seek(p_stream, p_j2k->cstr_index-> main_head_end + 2, p_manager) ) ) {
9617 opj_event_msg(p_manager, EVT_ERROR, "Problem wit h seek function\n"); 9742 opj_event_msg(p_manager, EVT_ERROR, "Problem wit h seek function\n");
9743 opj_free(l_current_data);
9618 return OPJ_FALSE; 9744 return OPJ_FALSE;
9619 } 9745 }
9620 break; 9746 break;
9621 } 9747 }
9622 else { 9748 else {
9623 opj_event_msg(p_manager, EVT_WARNING, "Tile read, decode and updated is not the desired (%d vs %d).\n", l_current_tile_no, l_tile_no_to_ dec); 9749 opj_event_msg(p_manager, EVT_WARNING, "Tile read, decode and updated is not the desired (%d vs %d).\n", l_current_tile_no, l_tile_no_to_ dec);
9624 } 9750 }
9625 9751
9626 } 9752 }
9627 9753
9628 opj_free(l_current_data); 9754 opj_free(l_current_data);
9629 9755
9630 return OPJ_TRUE; 9756 return OPJ_TRUE;
9631 } 9757 }
9632 9758
9633 /** 9759 /**
9634 * Sets up the procedures to do on decoding one tile. Developpers wanting to ext end the library can add their own reading procedures. 9760 * Sets up the procedures to do on decoding one tile. Developpers wanting to ext end the library can add their own reading procedures.
9635 */ 9761 */
9636 static void opj_j2k_setup_decoding_tile (opj_j2k_t *p_j2k) 9762 static OPJ_BOOL opj_j2k_setup_decoding_tile (opj_j2k_t *p_j2k, opj_event_mgr_t * p_manager)
9637 { 9763 {
9638 /* preconditions*/ 9764 /* preconditions*/
9639 assert(p_j2k != 00); 9765 assert(p_j2k != 00);
9766 assert(p_manager != 00);
9640 9767
9641 opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure) opj_j2k_decode_one_tile); 9768 if (! opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_proc edure)opj_j2k_decode_one_tile, p_manager)) {
9769 return OPJ_FALSE;
9770 }
9642 /* DEVELOPER CORNER, add your custom procedures */ 9771 /* DEVELOPER CORNER, add your custom procedures */
9643 9772
9773 return OPJ_TRUE;
9644 } 9774 }
9645 9775
9646 OPJ_BOOL opj_j2k_decode(opj_j2k_t * p_j2k, 9776 OPJ_BOOL opj_j2k_decode(opj_j2k_t * p_j2k,
9647 opj_stream_private_t * p_stream, 9777 opj_stream_private_t * p_stream,
9648 opj_image_t * p_image, 9778 opj_image_t * p_image,
9649 opj_event_mgr_t * p_manager) 9779 opj_event_mgr_t * p_manager)
9650 { 9780 {
9651 OPJ_UINT32 compno; 9781 OPJ_UINT32 compno;
9652 9782
9653 if (!p_image) 9783 if (!p_image)
9654 return OPJ_FALSE; 9784 return OPJ_FALSE;
9655 9785 »
9656 p_j2k->m_output_image = opj_image_create0(); 9786 p_j2k->m_output_image = opj_image_create0();
9657 if (! (p_j2k->m_output_image)) { 9787 if (! (p_j2k->m_output_image)) {
9658 return OPJ_FALSE; 9788 return OPJ_FALSE;
9659 } 9789 }
9660 opj_copy_image_header(p_image, p_j2k->m_output_image); 9790 opj_copy_image_header(p_image, p_j2k->m_output_image);
9661 9791
9662 /* customization of the decoding */ 9792 /* customization of the decoding */
9663 opj_j2k_setup_decoding(p_j2k); 9793 opj_j2k_setup_decoding(p_j2k, p_manager);
9664 9794
9665 /* Decode the codestream */ 9795 /* Decode the codestream */
9666 if (! opj_j2k_exec (p_j2k,p_j2k->m_procedure_list,p_stream,p_manager)) { 9796 if (! opj_j2k_exec (p_j2k,p_j2k->m_procedure_list,p_stream,p_manager)) {
9667 opj_image_destroy(p_j2k->m_private_image); 9797 opj_image_destroy(p_j2k->m_private_image);
9668 p_j2k->m_private_image = NULL; 9798 p_j2k->m_private_image = NULL;
9669 return OPJ_FALSE; 9799 return OPJ_FALSE;
9670 } 9800 }
9671 9801
9672 /* Move data and copy one information from codec to output image*/ 9802 /* Move data and copy one information from codec to output image*/
9673 for (compno = 0; compno < p_image->numcomps; compno++) { 9803 for (compno = 0; compno < p_image->numcomps; compno++) {
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
9749 /* Create the ouput image from the information previously computed*/ 9879 /* Create the ouput image from the information previously computed*/
9750 p_j2k->m_output_image = opj_image_create0(); 9880 p_j2k->m_output_image = opj_image_create0();
9751 if (! (p_j2k->m_output_image)) { 9881 if (! (p_j2k->m_output_image)) {
9752 return OPJ_FALSE; 9882 return OPJ_FALSE;
9753 } 9883 }
9754 opj_copy_image_header(p_image, p_j2k->m_output_image); 9884 opj_copy_image_header(p_image, p_j2k->m_output_image);
9755 9885
9756 p_j2k->m_specific_param.m_decoder.m_tile_ind_to_dec = (OPJ_INT32)tile_in dex; 9886 p_j2k->m_specific_param.m_decoder.m_tile_ind_to_dec = (OPJ_INT32)tile_in dex;
9757 9887
9758 /* customization of the decoding */ 9888 /* customization of the decoding */
9759 opj_j2k_setup_decoding_tile(p_j2k); 9889 opj_j2k_setup_decoding_tile(p_j2k, p_manager);
9760 9890
9761 /* Decode the codestream */ 9891 /* Decode the codestream */
9762 if (! opj_j2k_exec (p_j2k,p_j2k->m_procedure_list,p_stream,p_manager)) { 9892 if (! opj_j2k_exec (p_j2k,p_j2k->m_procedure_list,p_stream,p_manager)) {
9763 opj_image_destroy(p_j2k->m_private_image); 9893 opj_image_destroy(p_j2k->m_private_image);
9764 p_j2k->m_private_image = NULL; 9894 p_j2k->m_private_image = NULL;
9765 return OPJ_FALSE; 9895 return OPJ_FALSE;
9766 } 9896 }
9767 9897
9768 /* Move data and copy one information from codec to output image*/ 9898 /* Move data and copy one information from codec to output image*/
9769 for (compno = 0; compno < p_image->numcomps; compno++) { 9899 for (compno = 0; compno < p_image->numcomps; compno++) {
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
9844 l_tilec->data = l_img_comp->data; 9974 l_tilec->data = l_img_comp->data;
9845 l_tilec->ownsData = OPJ_FALSE; 9975 l_tilec->ownsData = OPJ_FALSE;
9846 } else { 9976 } else {
9847 if(! opj_alloc_tile_component_data(l_tilec)) { 9977 if(! opj_alloc_tile_component_data(l_tilec)) {
9848 opj_event_msg(p_manager, EVT_ERROR, "Error alloc ating tile component data." ); 9978 opj_event_msg(p_manager, EVT_ERROR, "Error alloc ating tile component data." );
9849 if (l_current_data) { 9979 if (l_current_data) {
9850 opj_free(l_current_data); 9980 opj_free(l_current_data);
9851 } 9981 }
9852 return OPJ_FALSE; 9982 return OPJ_FALSE;
9853 } 9983 }
9854 opj_alloc_tile_component_data(l_tilec);
9855 } 9984 }
9856 } 9985 }
9857 l_current_tile_size = opj_tcd_get_encoded_tile_size(p_j2k->m_tcd ); 9986 l_current_tile_size = opj_tcd_get_encoded_tile_size(p_j2k->m_tcd );
9858 if (l_nb_tiles > 1) { 9987 if (l_nb_tiles > 1) {
9859 if (l_current_tile_size > l_max_tile_size) { 9988 if (l_current_tile_size > l_max_tile_size) {
9860 OPJ_BYTE *l_new_current_data = (OPJ_BYTE *) opj_realloc( l_current_data, l_current_tile_size); 9989 OPJ_BYTE *l_new_current_data = (OPJ_BYTE *) opj_realloc( l_current_data, l_current_tile_size);
9861 if (! l_new_current_data) { 9990 if (! l_new_current_data) {
9862 if (l_current_data) { 9991 if (l_current_data) {
9863 opj_free(l_current_data); 9992 opj_free(l_current_data);
9864 } 9993 }
9865 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to encode all tiles\n"); 9994 opj_event_msg(p_manager, EVT_ERROR, "Not enough memory to encode all tiles\n");
9866 return OPJ_FALSE; 9995 return OPJ_FALSE;
9867 } 9996 }
9868 l_current_data = l_new_current_d ata; 9997 l_current_data = l_new_current_d ata;
9869 l_max_tile_size = l_current_tile _size; 9998 l_max_tile_size = l_current_tile _size;
9870 } 9999 }
9871 10000
9872 /* copy image data (32 bit) to l_current_data as contigu ous, all-component, zero offset buffer */ 10001 /* copy image data (32 bit) to l_current_data as contigu ous, all-component, zero offset buffer */
9873 /* 32 bit components @ 8 bit precision get converted to 8 bit */ 10002 /* 32 bit components @ 8 bit precision get converted to 8 bit */
9874 /* 32 bit components @ 16 bit precision get converted to 16 bit */ 10003 /* 32 bit components @ 16 bit precision get converted to 16 bit */
9875 opj_j2k_get_tile_data(p_j2k->m_tcd,l_current_data); 10004 opj_j2k_get_tile_data(p_j2k->m_tcd,l_current_data);
9876 10005
9877 /* now copy this data into the tile component */ 10006 /* now copy this data into the tile component */
9878 if (! opj_tcd_copy_tile_data(p_j2k->m_tcd,l_current_data ,l_current_tile_size)) { 10007 if (! opj_tcd_copy_tile_data(p_j2k->m_tcd,l_current_data ,l_current_tile_size)) {
9879 opj_event_msg(p_manager, EVT_ERR OR, "Size mismatch between tile data and sent data." ); 10008 opj_event_msg(p_manager, EVT_ERR OR, "Size mismatch between tile data and sent data." );
10009 opj_free(l_current_data);
9880 return OPJ_FALSE; 10010 return OPJ_FALSE;
9881 } 10011 }
9882 } 10012 }
9883 10013
9884 if (! opj_j2k_post_write_tile (p_j2k,p_stream,p_manager)) { 10014 if (! opj_j2k_post_write_tile (p_j2k,p_stream,p_manager)) {
10015 if (l_current_data) {
10016 opj_free(l_current_data);
10017 }
9885 return OPJ_FALSE; 10018 return OPJ_FALSE;
9886 } 10019 }
9887 } 10020 }
9888 10021
9889 if (l_current_data) { 10022 if (l_current_data) {
9890 opj_free(l_current_data); 10023 opj_free(l_current_data);
9891 } 10024 }
9892 return OPJ_TRUE; 10025 return OPJ_TRUE;
9893 } 10026 }
9894 10027
9895 OPJ_BOOL opj_j2k_end_compress( opj_j2k_t *p_j2k, 10028 OPJ_BOOL opj_j2k_end_compress( opj_j2k_t *p_j2k,
9896 opj_stream_private_t *p_ stream, 10029 opj_stream_private_t *p_ stream,
9897 opj_event_mgr_t * p_mana ger) 10030 opj_event_mgr_t * p_mana ger)
9898 { 10031 {
9899 /* customization of the encoding */ 10032 /* customization of the encoding */
9900 opj_j2k_setup_end_compress(p_j2k); 10033 if (! opj_j2k_setup_end_compress(p_j2k, p_manager)) {
10034 return OPJ_FALSE;
10035 }
9901 10036
9902 if (! opj_j2k_exec (p_j2k, p_j2k->m_procedure_list, p_stream, p_manager) ) 10037 if (! opj_j2k_exec (p_j2k, p_j2k->m_procedure_list, p_stream, p_manager) )
9903 { 10038 {
9904 return OPJ_FALSE; 10039 return OPJ_FALSE;
9905 } 10040 }
9906 10041
9907 return OPJ_TRUE; 10042 return OPJ_TRUE;
9908 } 10043 }
9909 10044
9910 OPJ_BOOL opj_j2k_start_compress(opj_j2k_t *p_j2k, 10045 OPJ_BOOL opj_j2k_start_compress(opj_j2k_t *p_j2k,
(...skipping 19 matching lines...) Expand all
9930 for (it_comp = 0 ; it_comp < p_image->numcomps; it_comp++) { 10065 for (it_comp = 0 ; it_comp < p_image->numcomps; it_comp++) {
9931 if (p_image->comps[it_comp].data) { 10066 if (p_image->comps[it_comp].data) {
9932 p_j2k->m_private_image->comps[it_comp].data =p_i mage->comps[it_comp].data; 10067 p_j2k->m_private_image->comps[it_comp].data =p_i mage->comps[it_comp].data;
9933 p_image->comps[it_comp].data = NULL; 10068 p_image->comps[it_comp].data = NULL;
9934 10069
9935 } 10070 }
9936 } 10071 }
9937 } 10072 }
9938 10073
9939 /* customization of the validation */ 10074 /* customization of the validation */
9940 opj_j2k_setup_encoding_validation (p_j2k); 10075 if (! opj_j2k_setup_encoding_validation (p_j2k, p_manager)) {
10076 return OPJ_FALSE;
10077 }
9941 10078
9942 /* validation of the parameters codec */ 10079 /* validation of the parameters codec */
9943 if (! opj_j2k_exec(p_j2k,p_j2k->m_validation_list,p_stream,p_manager)) { 10080 if (! opj_j2k_exec(p_j2k,p_j2k->m_validation_list,p_stream,p_manager)) {
9944 return OPJ_FALSE; 10081 return OPJ_FALSE;
9945 } 10082 }
9946 10083
9947 /* customization of the encoding */ 10084 /* customization of the encoding */
9948 opj_j2k_setup_header_writing(p_j2k); 10085 if (! opj_j2k_setup_header_writing(p_j2k, p_manager)) {
10086 return OPJ_FALSE;
10087 }
9949 10088
9950 /* write header */ 10089 /* write header */
9951 if (! opj_j2k_exec (p_j2k,p_j2k->m_procedure_list,p_stream,p_manager)) { 10090 if (! opj_j2k_exec (p_j2k,p_j2k->m_procedure_list,p_stream,p_manager)) {
9952 return OPJ_FALSE; 10091 return OPJ_FALSE;
9953 } 10092 }
9954 10093
9955 return OPJ_TRUE; 10094 return OPJ_TRUE;
9956 } 10095 }
9957 10096
9958 OPJ_BOOL opj_j2k_pre_write_tile ( opj_j2k_t * p_j2k, 10097 static OPJ_BOOL opj_j2k_pre_write_tile ( opj_j2k_t * p_j2k,
9959 OPJ_UINT32 p_til e_index, 10098 OPJ_UINT32 p_til e_index,
9960 opj_stream_priva te_t *p_stream, 10099 opj_stream_priva te_t *p_stream,
9961 opj_event_mgr_t * p_manager ) 10100 opj_event_mgr_t * p_manager )
9962 { 10101 {
9963 (void)p_stream; 10102 (void)p_stream;
9964 if (p_tile_index != p_j2k->m_current_tile_number) { 10103 if (p_tile_index != p_j2k->m_current_tile_number) {
9965 opj_event_msg(p_manager, EVT_ERROR, "The given tile index does n ot match." ); 10104 opj_event_msg(p_manager, EVT_ERROR, "The given tile index does n ot match." );
9966 return OPJ_FALSE; 10105 return OPJ_FALSE;
9967 } 10106 }
9968 10107
9969 opj_event_msg(p_manager, EVT_INFO, "tile number %d / %d\n", p_j2k->m_cur rent_tile_number + 1, p_j2k->m_cp.tw * p_j2k->m_cp.th); 10108 opj_event_msg(p_manager, EVT_INFO, "tile number %d / %d\n", p_j2k->m_cur rent_tile_number + 1, p_j2k->m_cp.tw * p_j2k->m_cp.th);
9970 10109
9971 p_j2k->m_specific_param.m_encoder.m_current_tile_part_number = 0; 10110 p_j2k->m_specific_param.m_encoder.m_current_tile_part_number = 0;
9972 p_j2k->m_tcd->cur_totnum_tp = p_j2k->m_cp.tcps[p_tile_index].m_nb_tile_p arts; 10111 p_j2k->m_tcd->cur_totnum_tp = p_j2k->m_cp.tcps[p_tile_index].m_nb_tile_p arts;
9973 p_j2k->m_specific_param.m_encoder.m_current_poc_tile_part_number = 0; 10112 p_j2k->m_specific_param.m_encoder.m_current_poc_tile_part_number = 0;
9974 10113
9975 /* initialisation before tile encoding */ 10114 /* initialisation before tile encoding */
9976 if (! opj_tcd_init_encode_tile(p_j2k->m_tcd, p_j2k->m_current_tile_numbe r)) { 10115 if (! opj_tcd_init_encode_tile(p_j2k->m_tcd, p_j2k->m_current_tile_numbe r, p_manager)) {
9977 return OPJ_FALSE; 10116 return OPJ_FALSE;
9978 } 10117 }
9979 10118
9980 return OPJ_TRUE; 10119 return OPJ_TRUE;
9981 } 10120 }
9982 10121
9983 void opj_get_tile_dimensions(opj_image_t * l_image, 10122 static void opj_get_tile_dimensions(opj_image_t * l_image,
9984 opj_tcd_tilecomp_t * l_tilec, 10123 opj_tcd_tilecomp_t * l_tilec,
9985 opj_image_comp_t * l_img_comp, 10124 opj_image_comp_t * l_img_comp,
9986 OPJ_UINT32* l_size_comp, 10125 OPJ_UINT32* l_size_comp,
9987 OPJ_UINT32* l_width, 10126 OPJ_UINT32* l_width,
9988 OPJ_UINT32* l_height, 10127 OPJ_UINT32* l_height,
9989 OPJ_UINT32* l_offset_x, 10128 OPJ_UINT32* l_offset_x,
9990 OPJ_UINT32* l_offset_y, 10129 OPJ_UINT32* l_offset_y,
9991 OPJ_UINT32* l_image_width, 10130 OPJ_UINT32* l_image_width,
9992 OPJ_UINT32* l_stride, 10131 OPJ_UINT32* l_stride,
9993 OPJ_UINT32* l_tile_offset) { 10132 OPJ_UINT32* l_tile_offset) {
(...skipping 10 matching lines...) Expand all
10004 10143
10005 *l_width = (OPJ_UINT32)(l_tilec->x1 - l_tilec->x0); 10144 *l_width = (OPJ_UINT32)(l_tilec->x1 - l_tilec->x0);
10006 *l_height = (OPJ_UINT32)(l_tilec->y1 - l_tilec->y0); 10145 *l_height = (OPJ_UINT32)(l_tilec->y1 - l_tilec->y0);
10007 *l_offset_x = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)l_image->x0, (OPJ_I NT32)l_img_comp->dx); 10146 *l_offset_x = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)l_image->x0, (OPJ_I NT32)l_img_comp->dx);
10008 *l_offset_y = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)l_image->y0, (OPJ_I NT32)l_img_comp->dy); 10147 *l_offset_y = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)l_image->y0, (OPJ_I NT32)l_img_comp->dy);
10009 *l_image_width = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)l_image->x1 - (O PJ_INT32)l_image->x0, (OPJ_INT32)l_img_comp->dx); 10148 *l_image_width = (OPJ_UINT32)opj_int_ceildiv((OPJ_INT32)l_image->x1 - (O PJ_INT32)l_image->x0, (OPJ_INT32)l_img_comp->dx);
10010 *l_stride = *l_image_width - *l_width; 10149 *l_stride = *l_image_width - *l_width;
10011 *l_tile_offset = ((OPJ_UINT32)l_tilec->x0 - *l_offset_x) + ((OPJ_UINT32) l_tilec->y0 - *l_offset_y) * *l_image_width; 10150 *l_tile_offset = ((OPJ_UINT32)l_tilec->x0 - *l_offset_x) + ((OPJ_UINT32) l_tilec->y0 - *l_offset_y) * *l_image_width;
10012 } 10151 }
10013 10152
10014 void opj_j2k_get_tile_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data) 10153 static void opj_j2k_get_tile_data (opj_tcd_t * p_tcd, OPJ_BYTE * p_data)
10015 { 10154 {
10016 OPJ_UINT32 i,j,k = 0; 10155 OPJ_UINT32 i,j,k = 0;
10017 10156
10018 for (i=0;i<p_tcd->image->numcomps;++i) { 10157 for (i=0;i<p_tcd->image->numcomps;++i) {
10019 opj_image_t * l_image = p_tcd->image; 10158 opj_image_t * l_image = p_tcd->image;
10020 OPJ_INT32 * l_src_ptr; 10159 OPJ_INT32 * l_src_ptr;
10021 opj_tcd_tilecomp_t * l_tilec = p_tcd->tcd_image->tiles->comps + i; 10160 opj_tcd_tilecomp_t * l_tilec = p_tcd->tcd_image->tiles->comps + i;
10022 opj_image_comp_t * l_img_comp = l_image->comps + i; 10161 opj_image_comp_t * l_img_comp = l_image->comps + i;
10023 OPJ_UINT32 l_size_comp,l_width,l_height,l_offset_x,l_offset_y, l _image_width,l_stride,l_tile_offset; 10162 OPJ_UINT32 l_size_comp,l_width,l_height,l_offset_x,l_offset_y, l _image_width,l_stride,l_tile_offset;
10024 10163
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
10097 l_src_ptr += l_stride; 10236 l_src_ptr += l_stride;
10098 } 10237 }
10099 10238
10100 p_data = (OPJ_BYTE*) l_dest_ptr; 10239 p_data = (OPJ_BYTE*) l_dest_ptr;
10101 } 10240 }
10102 break; 10241 break;
10103 } 10242 }
10104 } 10243 }
10105 } 10244 }
10106 10245
10107 OPJ_BOOL opj_j2k_post_write_tile ( opj_j2k_t * p_j2k, 10246 static OPJ_BOOL opj_j2k_post_write_tile ( opj_j2k_t * p_j2k,
10108 opj_stream_priva te_t *p_stream, 10247 opj_stream_priva te_t *p_stream,
10109 opj_event_mgr_t * p_manager ) 10248 opj_event_mgr_t * p_manager )
10110 { 10249 {
10111 OPJ_UINT32 l_nb_bytes_written; 10250 OPJ_UINT32 l_nb_bytes_written;
10112 OPJ_BYTE * l_current_data = 00; 10251 OPJ_BYTE * l_current_data = 00;
10113 OPJ_UINT32 l_tile_size = 0; 10252 OPJ_UINT32 l_tile_size = 0;
10114 OPJ_UINT32 l_available_data; 10253 OPJ_UINT32 l_available_data;
10115 10254
10116 /* preconditions */ 10255 /* preconditions */
10117 assert(p_j2k->m_specific_param.m_encoder.m_encoded_tile_data); 10256 assert(p_j2k->m_specific_param.m_encoder.m_encoded_tile_data);
(...skipping 21 matching lines...) Expand all
10139 p_j2k->m_specifi c_param.m_encoder.m_encoded_tile_data, 10278 p_j2k->m_specifi c_param.m_encoder.m_encoded_tile_data,
10140 l_nb_bytes_writt en,p_manager) != l_nb_bytes_written) { 10279 l_nb_bytes_writt en,p_manager) != l_nb_bytes_written) {
10141 return OPJ_FALSE; 10280 return OPJ_FALSE;
10142 } 10281 }
10143 10282
10144 ++p_j2k->m_current_tile_number; 10283 ++p_j2k->m_current_tile_number;
10145 10284
10146 return OPJ_TRUE; 10285 return OPJ_TRUE;
10147 } 10286 }
10148 10287
10149 void opj_j2k_setup_end_compress (opj_j2k_t *p_j2k) 10288 static OPJ_BOOL opj_j2k_setup_end_compress (opj_j2k_t *p_j2k, opj_event_mgr_t * p_manager)
10150 { 10289 {
10151 /* preconditions */ 10290 /* preconditions */
10152 assert(p_j2k != 00); 10291 assert(p_j2k != 00);
10292 assert(p_manager != 00);
10153 10293
10154 /* DEVELOPER CORNER, insert your custom procedures */ 10294 /* DEVELOPER CORNER, insert your custom procedures */
10155 opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure) opj_j2k_write_eoc ); 10295 if (! opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_proc edure)opj_j2k_write_eoc, p_manager)) {
10296 return OPJ_FALSE;
10297 }
10156 10298
10157 if (OPJ_IS_CINEMA(p_j2k->m_cp.rsiz)) { 10299 if (OPJ_IS_CINEMA(p_j2k->m_cp.rsiz)) {
10158 opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_pr ocedure)opj_j2k_write_updated_tlm); 10300 if (! opj_procedure_list_add_procedure(p_j2k->m_procedure_list,( opj_procedure)opj_j2k_write_updated_tlm, p_manager)) {
10301 return OPJ_FALSE;
10302 }
10159 } 10303 }
10160 10304
10161 opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure) opj_j2k_write_epc ); 10305 if (! opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_proc edure)opj_j2k_write_epc, p_manager)) {
10162 opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure) opj_j2k_end_encoding ); 10306 return OPJ_FALSE;
10163 opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure) opj_j2k_destroy_header_memory); 10307 }
10308 if (! opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_proc edure)opj_j2k_end_encoding, p_manager)) {
10309 return OPJ_FALSE;
10310 }
10311 if (! opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_proc edure)opj_j2k_destroy_header_memory, p_manager)) {
10312 return OPJ_FALSE;
10313 }
10314 return OPJ_TRUE;
10164 } 10315 }
10165 10316
10166 void opj_j2k_setup_encoding_validation (opj_j2k_t *p_j2k) 10317 static OPJ_BOOL opj_j2k_setup_encoding_validation (opj_j2k_t *p_j2k, opj_event_m gr_t * p_manager)
10167 { 10318 {
10168 /* preconditions */ 10319 /* preconditions */
10169 assert(p_j2k != 00); 10320 assert(p_j2k != 00);
10321 assert(p_manager != 00);
10170 10322
10171 opj_procedure_list_add_procedure(p_j2k->m_validation_list, (opj_procedur e)opj_j2k_build_encoder); 10323 if (! opj_procedure_list_add_procedure(p_j2k->m_validation_list, (opj_pr ocedure)opj_j2k_build_encoder, p_manager)) {
10172 opj_procedure_list_add_procedure(p_j2k->m_validation_list, (opj_procedur e)opj_j2k_encoding_validation); 10324 return OPJ_FALSE;
10325 }
10326 if (! opj_procedure_list_add_procedure(p_j2k->m_validation_list, (opj_pr ocedure)opj_j2k_encoding_validation, p_manager)) {
10327 return OPJ_FALSE;
10328 » » » » }
10173 10329
10174 /* DEVELOPER CORNER, add your custom validation procedure */ 10330 /* DEVELOPER CORNER, add your custom validation procedure */
10175 opj_procedure_list_add_procedure(p_j2k->m_validation_list, (opj_procedur e)opj_j2k_mct_validation); 10331 if (! opj_procedure_list_add_procedure(p_j2k->m_validation_list, (opj_pr ocedure)opj_j2k_mct_validation, p_manager)) {
10332 return OPJ_FALSE;
10333 }
10334 »
10335 return OPJ_TRUE;
10176 } 10336 }
10177 10337
10178 void opj_j2k_setup_header_writing (opj_j2k_t *p_j2k) 10338 static OPJ_BOOL opj_j2k_setup_header_writing (opj_j2k_t *p_j2k, opj_event_mgr_t * p_manager)
10179 { 10339 {
10180 /* preconditions */ 10340 /* preconditions */
10181 assert(p_j2k != 00); 10341 assert(p_j2k != 00);
10342 assert(p_manager != 00);
10182 10343
10183 opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure) opj_j2k_init_info ); 10344 if (! opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_proc edure)opj_j2k_init_info, p_manager)) {
10184 opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure) opj_j2k_write_soc ); 10345 return OPJ_FALSE;
10185 opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure) opj_j2k_write_siz ); 10346 }
10186 opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure) opj_j2k_write_cod ); 10347 if (! opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_proc edure)opj_j2k_write_soc, p_manager)) {
10187 opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure) opj_j2k_write_qcd ); 10348 return OPJ_FALSE;
10349 }
10350 if (! opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_proc edure)opj_j2k_write_siz, p_manager)) {
10351 return OPJ_FALSE;
10352 }
10353 if (! opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_proc edure)opj_j2k_write_cod, p_manager)) {
10354 return OPJ_FALSE;
10355 }
10356 if (! opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_proc edure)opj_j2k_write_qcd, p_manager)) {
10357 return OPJ_FALSE;
10358 }
10188 10359
10189 if (OPJ_IS_CINEMA(p_j2k->m_cp.rsiz)) { 10360 if (OPJ_IS_CINEMA(p_j2k->m_cp.rsiz)) {
10190 /* No need for COC or QCC, QCD and COD are used 10361 /* No need for COC or QCC, QCD and COD are used
10191 opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_pr ocedure)opj_j2k_write_all_coc ); 10362 if (! opj_procedure_list_add_procedure(p_j2k->m_procedure_list,( opj_procedure)opj_j2k_write_all_coc, p_manager)) {
10192 opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_pr ocedure)opj_j2k_write_all_qcc ); 10363 return OPJ_FALSE;
10364 }
10365 if (! opj_procedure_list_add_procedure(p_j2k->m_procedure_list,( opj_procedure)opj_j2k_write_all_qcc, p_manager)) {
10366 return OPJ_FALSE;
10367 }
10193 */ 10368 */
10194 opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_pr ocedure)opj_j2k_write_tlm ); 10369 if (! opj_procedure_list_add_procedure(p_j2k->m_procedure_list,( opj_procedure)opj_j2k_write_tlm, p_manager)) {
10370 return OPJ_FALSE;
10371 }
10195 10372
10196 if (p_j2k->m_cp.rsiz == OPJ_PROFILE_CINEMA_4K) { 10373 if (p_j2k->m_cp.rsiz == OPJ_PROFILE_CINEMA_4K) {
10197 opj_procedure_list_add_procedure(p_j2k->m_procedure_list ,(opj_procedure)opj_j2k_write_poc ); 10374 if (! opj_procedure_list_add_procedure(p_j2k->m_procedur e_list,(opj_procedure)opj_j2k_write_poc, p_manager)) {
10375 return OPJ_FALSE;
10376 }
10198 } 10377 }
10199 } 10378 }
10200 10379
10201 opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure) opj_j2k_write_regions); 10380 if (! opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_proc edure)opj_j2k_write_regions, p_manager)) {
10381 return OPJ_FALSE;
10382 }
10202 10383
10203 if (p_j2k->m_cp.comment != 00) { 10384 if (p_j2k->m_cp.comment != 00) {
10204 opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_pr ocedure)opj_j2k_write_com); 10385 if (! opj_procedure_list_add_procedure(p_j2k->m_procedure_list,( opj_procedure)opj_j2k_write_com, p_manager)) {
10386 return OPJ_FALSE;
10387 }
10205 } 10388 }
10206 10389
10207 /* DEVELOPER CORNER, insert your custom procedures */ 10390 /* DEVELOPER CORNER, insert your custom procedures */
10208 if (p_j2k->m_cp.rsiz & OPJ_EXTENSION_MCT) { 10391 if (p_j2k->m_cp.rsiz & OPJ_EXTENSION_MCT) {
10209 opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_pr ocedure)opj_j2k_write_mct_data_group ); 10392 if (! opj_procedure_list_add_procedure(p_j2k->m_procedure_list,( opj_procedure)opj_j2k_write_mct_data_group, p_manager)) {
10393 return OPJ_FALSE;
10394 }
10210 } 10395 }
10211 /* End of Developer Corner */ 10396 /* End of Developer Corner */
10212 10397
10213 if (p_j2k->cstr_index) { 10398 if (p_j2k->cstr_index) {
10214 opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_pr ocedure)opj_j2k_get_end_header ); 10399 if (! opj_procedure_list_add_procedure(p_j2k->m_procedure_list,( opj_procedure)opj_j2k_get_end_header, p_manager)) {
10400 return OPJ_FALSE;
10401 }
10215 } 10402 }
10216 10403
10217 opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure) opj_j2k_create_tcd); 10404 if (! opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_proc edure)opj_j2k_create_tcd, p_manager)) {
10218 opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_procedure) opj_j2k_update_rates); 10405 return OPJ_FALSE;
10406 }
10407 if (! opj_procedure_list_add_procedure(p_j2k->m_procedure_list,(opj_proc edure)opj_j2k_update_rates, p_manager)) {
10408 return OPJ_FALSE;
10409 }
10410
10411 return OPJ_TRUE;
10219 } 10412 }
10220 10413
10221 OPJ_BOOL opj_j2k_write_first_tile_part (opj_j2k_t *p_j2k, 10414 static OPJ_BOOL opj_j2k_write_first_tile_part (opj_j2k_t *p_j2k,
10222 OPJ_BYTE * p_data, 10415 OPJ_BYTE * p_data,
10223 OPJ_UINT 32 * p_data_written, 10416 OPJ_UINT 32 * p_data_written,
10224 OPJ_UINT 32 p_total_data_size, 10417 OPJ_UINT 32 p_total_data_size,
10225 opj_stre am_private_t *p_stream, 10418 opj_stre am_private_t *p_stream,
10226 struct o pj_event_mgr * p_manager ) 10419 struct o pj_event_mgr * p_manager )
10227 { 10420 {
10228 OPJ_UINT32 l_nb_bytes_written = 0; 10421 OPJ_UINT32 l_nb_bytes_written = 0;
10229 OPJ_UINT32 l_current_nb_bytes_written; 10422 OPJ_UINT32 l_current_nb_bytes_written;
10230 OPJ_BYTE * l_begin_data = 00; 10423 OPJ_BYTE * l_begin_data = 00;
10231 10424
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
10291 /* Writing Psot in SOT marker */ 10484 /* Writing Psot in SOT marker */
10292 opj_write_bytes(l_begin_data + 6,l_nb_bytes_written,4); /* PSOT */ 10485 opj_write_bytes(l_begin_data + 6,l_nb_bytes_written,4); /* PSOT */
10293 10486
10294 if (OPJ_IS_CINEMA(l_cp->rsiz)){ 10487 if (OPJ_IS_CINEMA(l_cp->rsiz)){
10295 opj_j2k_update_tlm(p_j2k,l_nb_bytes_written); 10488 opj_j2k_update_tlm(p_j2k,l_nb_bytes_written);
10296 } 10489 }
10297 10490
10298 return OPJ_TRUE; 10491 return OPJ_TRUE;
10299 } 10492 }
10300 10493
10301 OPJ_BOOL opj_j2k_write_all_tile_parts( opj_j2k_t *p_j2k, 10494 static OPJ_BOOL opj_j2k_write_all_tile_parts( opj_j2k_t *p_j2k,
10302 OPJ_BYTE * p_data, 10495 OPJ_BYTE * p_data,
10303 OPJ_UINT 32 * p_data_written, 10496 OPJ_UINT 32 * p_data_written,
10304 OPJ_UINT 32 p_total_data_size, 10497 OPJ_UINT 32 p_total_data_size,
10305 opj_stre am_private_t *p_stream, 10498 opj_stre am_private_t *p_stream,
10306 struct o pj_event_mgr * p_manager 10499 struct o pj_event_mgr * p_manager
10307 ) 10500 )
10308 { 10501 {
10309 OPJ_UINT32 tilepartno=0; 10502 OPJ_UINT32 tilepartno=0;
10310 OPJ_UINT32 l_nb_bytes_written = 0; 10503 OPJ_UINT32 l_nb_bytes_written = 0;
10311 OPJ_UINT32 l_current_nb_bytes_written; 10504 OPJ_UINT32 l_current_nb_bytes_written;
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after
10402 10595
10403 ++p_j2k->m_specific_param.m_encoder.m_current_tile_part_ number; 10596 ++p_j2k->m_specific_param.m_encoder.m_current_tile_part_ number;
10404 } 10597 }
10405 } 10598 }
10406 10599
10407 *p_data_written = l_nb_bytes_written; 10600 *p_data_written = l_nb_bytes_written;
10408 10601
10409 return OPJ_TRUE; 10602 return OPJ_TRUE;
10410 } 10603 }
10411 10604
10412 OPJ_BOOL opj_j2k_write_updated_tlm( opj_j2k_t *p_j2k, 10605 static OPJ_BOOL opj_j2k_write_updated_tlm( opj_j2k_t *p_j2k,
10413 struct opj_s tream_private *p_stream, 10606 struct opj_s tream_private *p_stream,
10414 struct opj_e vent_mgr * p_manager ) 10607 struct opj_e vent_mgr * p_manager )
10415 { 10608 {
10416 OPJ_UINT32 l_tlm_size; 10609 OPJ_UINT32 l_tlm_size;
10417 OPJ_OFF_T l_tlm_position, l_current_position; 10610 OPJ_OFF_T l_tlm_position, l_current_position;
10418 10611
10419 /* preconditions */ 10612 /* preconditions */
10420 assert(p_j2k != 00); 10613 assert(p_j2k != 00);
10421 assert(p_manager != 00); 10614 assert(p_manager != 00);
10422 assert(p_stream != 00); 10615 assert(p_stream != 00);
(...skipping 10 matching lines...) Expand all
10433 return OPJ_FALSE; 10626 return OPJ_FALSE;
10434 } 10627 }
10435 10628
10436 if (! opj_stream_seek(p_stream,l_current_position,p_manager)) { 10629 if (! opj_stream_seek(p_stream,l_current_position,p_manager)) {
10437 return OPJ_FALSE; 10630 return OPJ_FALSE;
10438 } 10631 }
10439 10632
10440 return OPJ_TRUE; 10633 return OPJ_TRUE;
10441 } 10634 }
10442 10635
10443 OPJ_BOOL opj_j2k_end_encoding( opj_j2k_t *p_j2k, 10636 static OPJ_BOOL opj_j2k_end_encoding( opj_j2k_t *p_j2k,
10444 struct opj_stream_privat e *p_stream, 10637 struct opj_stream_privat e *p_stream,
10445 struct opj_event_mgr * p _manager ) 10638 struct opj_event_mgr * p _manager )
10446 { 10639 {
10447 /* preconditions */ 10640 /* preconditions */
10448 assert(p_j2k != 00); 10641 assert(p_j2k != 00);
10449 assert(p_manager != 00); 10642 assert(p_manager != 00);
10450 assert(p_stream != 00); 10643 assert(p_stream != 00);
10451 10644
10452 opj_tcd_destroy(p_j2k->m_tcd); 10645 opj_tcd_destroy(p_j2k->m_tcd);
10453 p_j2k->m_tcd = 00; 10646 p_j2k->m_tcd = 00;
(...skipping 30 matching lines...) Expand all
10484 if (p_j2k->m_specific_param.m_encoder.m_header_tile_data) { 10677 if (p_j2k->m_specific_param.m_encoder.m_header_tile_data) {
10485 opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data); 10678 opj_free(p_j2k->m_specific_param.m_encoder.m_header_tile_data);
10486 p_j2k->m_specific_param.m_encoder.m_header_tile_data = 0; 10679 p_j2k->m_specific_param.m_encoder.m_header_tile_data = 0;
10487 } 10680 }
10488 10681
10489 p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = 0; 10682 p_j2k->m_specific_param.m_encoder.m_header_tile_data_size = 0;
10490 10683
10491 return OPJ_TRUE; 10684 return OPJ_TRUE;
10492 } 10685 }
10493 10686
10494 OPJ_BOOL opj_j2k_init_info( opj_j2k_t *p_j2k, 10687 static OPJ_BOOL opj_j2k_init_info( opj_j2k_t *p_j2k,
10495 struct opj_stream_private *p_str eam, 10688 struct opj_stream_private *p_str eam,
10496 struct opj_event_mgr * p_manager ) 10689 struct opj_event_mgr * p_manager )
10497 { 10690 {
10498 opj_codestream_info_t * l_cstr_info = 00; 10691 opj_codestream_info_t * l_cstr_info = 00;
10499 10692
10500 /* preconditions */ 10693 /* preconditions */
10501 assert(p_j2k != 00); 10694 assert(p_j2k != 00);
10502 assert(p_manager != 00); 10695 assert(p_manager != 00);
10503 assert(p_stream != 00); 10696 assert(p_stream != 00);
10504 (void)l_cstr_info; 10697 (void)l_cstr_info;
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after
10607 return OPJ_FALSE; 10800 return OPJ_FALSE;
10608 } 10801 }
10609 if (! opj_j2k_post_write_tile(p_j2k,p_stream,p_manager)) { 10802 if (! opj_j2k_post_write_tile(p_j2k,p_stream,p_manager)) {
10610 opj_event_msg(p_manager, EVT_ERROR, "Error while opj_j2k _post_write_tile with tile index = %d\n", p_tile_index); 10803 opj_event_msg(p_manager, EVT_ERROR, "Error while opj_j2k _post_write_tile with tile index = %d\n", p_tile_index);
10611 return OPJ_FALSE; 10804 return OPJ_FALSE;
10612 } 10805 }
10613 } 10806 }
10614 10807
10615 return OPJ_TRUE; 10808 return OPJ_TRUE;
10616 } 10809 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698