OpenJPEG 2.1.0
|
00001 /* 00002 * The copyright in this software is being made available under the 2-clauses 00003 * BSD License, included below. This software may be subject to other third 00004 * party and contributor rights, including patent rights, and no such rights 00005 * are granted under this license. 00006 * 00007 * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium 00008 * Copyright (c) 2002-2014, Professor Benoit Macq 00009 * Copyright (c) 2001-2003, David Janssens 00010 * Copyright (c) 2002-2003, Yannick Verschueren 00011 * Copyright (c) 2003-2007, Francois-Olivier Devaux 00012 * Copyright (c) 2003-2014, Antonin Descampe 00013 * Copyright (c) 2005, Herve Drolon, FreeImage Team 00014 * Copyright (c) 2006-2007, Parvatha Elangovan 00015 * Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr> 00016 * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France 00017 * Copyright (c) 2012, CS Systemes d'Information, France 00018 * 00019 * All rights reserved. 00020 * 00021 * Redistribution and use in source and binary forms, with or without 00022 * modification, are permitted provided that the following conditions 00023 * are met: 00024 * 1. Redistributions of source code must retain the above copyright 00025 * notice, this list of conditions and the following disclaimer. 00026 * 2. Redistributions in binary form must reproduce the above copyright 00027 * notice, this list of conditions and the following disclaimer in the 00028 * documentation and/or other materials provided with the distribution. 00029 * 00030 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS' 00031 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 00032 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 00033 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 00034 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 00035 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 00036 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 00037 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 00038 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 00039 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 00040 * POSSIBILITY OF SUCH DAMAGE. 00041 */ 00042 #ifndef __J2K_H 00043 #define __J2K_H 00044 00053 00054 #define J2K_CP_CSTY_PRT 0x01 00055 #define J2K_CP_CSTY_SOP 0x02 00056 #define J2K_CP_CSTY_EPH 0x04 00057 #define J2K_CCP_CSTY_PRT 0x01 00058 #define J2K_CCP_CBLKSTY_LAZY 0x01 00059 #define J2K_CCP_CBLKSTY_RESET 0x02 00060 #define J2K_CCP_CBLKSTY_TERMALL 0x04 00061 #define J2K_CCP_CBLKSTY_VSC 0x08 00062 #define J2K_CCP_CBLKSTY_PTERM 0x10 00063 #define J2K_CCP_CBLKSTY_SEGSYM 0x20 00064 #define J2K_CCP_QNTSTY_NOQNT 0 00065 #define J2K_CCP_QNTSTY_SIQNT 1 00066 #define J2K_CCP_QNTSTY_SEQNT 2 00067 00068 #define OPJ_J2K_DEFAULT_CBLK_DATA_SIZE 8192 00069 00070 /* ----------------------------------------------------------------------- */ 00071 00072 #define J2K_MS_SOC 0xff4f 00073 #define J2K_MS_SOT 0xff90 00074 #define J2K_MS_SOD 0xff93 00075 #define J2K_MS_EOC 0xffd9 00076 #define J2K_MS_SIZ 0xff51 00077 #define J2K_MS_COD 0xff52 00078 #define J2K_MS_COC 0xff53 00079 #define J2K_MS_RGN 0xff5e 00080 #define J2K_MS_QCD 0xff5c 00081 #define J2K_MS_QCC 0xff5d 00082 #define J2K_MS_POC 0xff5f 00083 #define J2K_MS_TLM 0xff55 00084 #define J2K_MS_PLM 0xff57 00085 #define J2K_MS_PLT 0xff58 00086 #define J2K_MS_PPM 0xff60 00087 #define J2K_MS_PPT 0xff61 00088 #define J2K_MS_SOP 0xff91 00089 #define J2K_MS_EPH 0xff92 00090 #define J2K_MS_CRG 0xff63 00091 #define J2K_MS_COM 0xff64 00092 #define J2K_MS_CBD 0xff78 00093 #define J2K_MS_MCC 0xff75 00094 #define J2K_MS_MCT 0xff74 00095 #define J2K_MS_MCO 0xff77 00097 #define J2K_MS_UNK 0 00099 /* UniPG>> */ 00100 #ifdef USE_JPWL 00101 #define J2K_MS_EPC 0xff68 00102 #define J2K_MS_EPB 0xff66 00103 #define J2K_MS_ESD 0xff67 00104 #define J2K_MS_RED 0xff69 00105 #endif /* USE_JPWL */ 00106 #ifdef USE_JPSEC 00107 #define J2K_MS_SEC 0xff65 00108 #define J2K_MS_INSEC 0xff94 00109 #endif /* USE_JPSEC */ 00110 /* <<UniPG */ 00111 00112 /* ----------------------------------------------------------------------- */ 00113 00118 typedef enum J2K_STATUS { 00119 J2K_STATE_NONE = 0x0000, 00120 J2K_STATE_MHSOC = 0x0001, 00121 J2K_STATE_MHSIZ = 0x0002, 00122 J2K_STATE_MH = 0x0004, 00123 J2K_STATE_TPHSOT = 0x0008, 00124 J2K_STATE_TPH = 0x0010, 00125 J2K_STATE_MT = 0x0020, 00126 J2K_STATE_NEOC = 0x0040, 00128 J2K_STATE_EOC = 0x0100, 00129 J2K_STATE_ERR = 0x8000 00130 } J2K_STATUS; 00131 00135 typedef enum MCT_ELEMENT_TYPE 00136 { 00137 MCT_TYPE_INT16 = 0, 00138 MCT_TYPE_INT32 = 1, 00139 MCT_TYPE_FLOAT = 2, 00140 MCT_TYPE_DOUBLE = 3 00141 } J2K_MCT_ELEMENT_TYPE; 00142 00146 typedef enum MCT_ARRAY_TYPE 00147 { 00148 MCT_TYPE_DEPENDENCY = 0, 00149 MCT_TYPE_DECORRELATION = 1, 00150 MCT_TYPE_OFFSET = 2 00151 } J2K_MCT_ARRAY_TYPE; 00152 00153 /* ----------------------------------------------------------------------- */ 00154 00158 typedef enum T2_MODE { 00159 THRESH_CALC = 0, 00160 FINAL_PASS = 1 00161 }J2K_T2_MODE; 00162 00166 typedef struct opj_stepsize { 00168 OPJ_INT32 expn; 00170 OPJ_INT32 mant; 00171 } opj_stepsize_t; 00172 00176 typedef struct opj_tccp 00177 { 00179 OPJ_UINT32 csty; 00181 OPJ_UINT32 numresolutions; 00183 OPJ_UINT32 cblkw; 00185 OPJ_UINT32 cblkh; 00187 OPJ_UINT32 cblksty; 00189 OPJ_UINT32 qmfbid; 00191 OPJ_UINT32 qntsty; 00193 opj_stepsize_t stepsizes[OPJ_J2K_MAXBANDS]; 00195 OPJ_UINT32 numgbits; 00197 OPJ_INT32 roishift; 00199 OPJ_UINT32 prcw[OPJ_J2K_MAXRLVLS]; 00201 OPJ_UINT32 prch[OPJ_J2K_MAXRLVLS]; 00203 OPJ_INT32 m_dc_level_shift; 00204 } 00205 opj_tccp_t; 00206 00207 00208 00212 typedef struct opj_mct_data 00213 { 00214 J2K_MCT_ELEMENT_TYPE m_element_type; 00215 J2K_MCT_ARRAY_TYPE m_array_type; 00216 OPJ_UINT32 m_index; 00217 OPJ_BYTE * m_data; 00218 OPJ_UINT32 m_data_size; 00219 } 00220 opj_mct_data_t; 00221 00225 typedef struct opj_simple_mcc_decorrelation_data 00226 { 00227 OPJ_UINT32 m_index; 00228 OPJ_UINT32 m_nb_comps; 00229 opj_mct_data_t * m_decorrelation_array; 00230 opj_mct_data_t * m_offset_array; 00231 OPJ_UINT32 m_is_irreversible : 1; 00232 } 00233 opj_simple_mcc_decorrelation_data_t; 00234 00240 typedef struct opj_tcp 00241 { 00243 OPJ_UINT32 csty; 00245 OPJ_PROG_ORDER prg; 00247 OPJ_UINT32 numlayers; 00248 OPJ_UINT32 num_layers_to_decode; 00250 OPJ_UINT32 mct; 00252 OPJ_FLOAT32 rates[100]; 00254 OPJ_UINT32 numpocs; 00256 opj_poc_t pocs[32]; 00258 OPJ_BYTE *ppt_data; 00260 OPJ_BYTE *ppt_buffer; 00262 OPJ_UINT32 ppt_data_size; 00264 OPJ_UINT32 ppt_len; 00266 OPJ_FLOAT32 distoratio[100]; 00268 opj_tccp_t *tccps; 00270 OPJ_UINT32 m_nb_tile_parts; 00272 OPJ_BYTE * m_data; 00274 OPJ_UINT32 m_data_size; 00276 OPJ_FLOAT64 * mct_norms; 00278 OPJ_FLOAT32 * m_mct_decoding_matrix; 00280 OPJ_FLOAT32 * m_mct_coding_matrix; 00282 opj_mct_data_t * m_mct_records; 00284 OPJ_UINT32 m_nb_mct_records; 00286 OPJ_UINT32 m_nb_max_mct_records; 00288 opj_simple_mcc_decorrelation_data_t * m_mcc_records; 00290 OPJ_UINT32 m_nb_mcc_records; 00292 OPJ_UINT32 m_nb_max_mcc_records; 00293 00294 00295 /***** FLAGS *******/ 00297 OPJ_UINT32 ppt : 1; 00299 OPJ_UINT32 POC : 1; 00300 } opj_tcp_t; 00301 00302 00303 00304 00305 typedef struct opj_encoding_param 00306 { 00308 OPJ_UINT32 m_max_comp_size; 00310 OPJ_INT32 m_tp_pos; 00312 OPJ_INT32 *m_matrice; 00314 OPJ_BYTE m_tp_flag; 00316 OPJ_UINT32 m_disto_alloc : 1; 00318 OPJ_UINT32 m_fixed_alloc : 1; 00320 OPJ_UINT32 m_fixed_quality : 1; 00322 OPJ_UINT32 m_tp_on : 1; 00323 } 00324 opj_encoding_param_t; 00325 00326 typedef struct opj_decoding_param 00327 { 00329 OPJ_UINT32 m_reduce; 00331 OPJ_UINT32 m_layer; 00332 } 00333 opj_decoding_param_t; 00334 00335 00339 typedef struct opj_cp 00340 { 00342 /*int img_size;*/ 00344 OPJ_UINT16 rsiz; 00346 OPJ_UINT32 tx0; /* MSD see norm */ 00348 OPJ_UINT32 ty0; /* MSD see norm */ 00350 OPJ_UINT32 tdx; 00352 OPJ_UINT32 tdy; 00354 OPJ_CHAR *comment; 00356 OPJ_UINT32 tw; 00358 OPJ_UINT32 th; 00359 00361 OPJ_BYTE *ppm_data; 00363 OPJ_UINT32 ppm_len; 00365 OPJ_UINT32 ppm_data_read; 00366 00367 OPJ_BYTE *ppm_data_current; 00368 00370 OPJ_BYTE *ppm_buffer; 00372 OPJ_BYTE *ppm_data_first; 00374 OPJ_UINT32 ppm_data_size; 00376 OPJ_INT32 ppm_store; 00378 OPJ_INT32 ppm_previous; 00379 00381 opj_tcp_t *tcps; 00382 00383 union 00384 { 00385 opj_decoding_param_t m_dec; 00386 opj_encoding_param_t m_enc; 00387 } 00388 m_specific_param; 00389 00390 00391 /* UniPG>> */ 00392 #ifdef USE_JPWL 00393 00394 OPJ_BOOL epc_on; 00396 OPJ_BOOL epb_on; 00398 OPJ_BOOL esd_on; 00400 OPJ_BOOL info_on; 00402 OPJ_BOOL red_on; 00404 int hprot_MH; 00406 int hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS]; 00408 int hprot_TPH[JPWL_MAX_NO_TILESPECS]; 00410 int pprot_tileno[JPWL_MAX_NO_PACKSPECS]; 00412 int pprot_packno[JPWL_MAX_NO_PACKSPECS]; 00414 int pprot[JPWL_MAX_NO_PACKSPECS]; 00416 int sens_size; 00418 int sens_addr; 00420 int sens_range; 00422 int sens_MH; 00424 int sens_TPH_tileno[JPWL_MAX_NO_TILESPECS]; 00426 int sens_TPH[JPWL_MAX_NO_TILESPECS]; 00428 OPJ_BOOL correct; 00430 int exp_comps; 00432 OPJ_UINT32 max_tiles; 00433 #endif /* USE_JPWL */ 00434 00435 /******** FLAGS *********/ 00437 OPJ_UINT32 ppm : 1; 00439 OPJ_UINT32 m_is_decoder : 1; 00440 /* <<UniPG */ 00441 } opj_cp_t; 00442 00443 00444 typedef struct opj_j2k_dec 00445 { 00447 OPJ_UINT32 m_state; 00451 opj_tcp_t *m_default_tcp; 00452 OPJ_BYTE *m_header_data; 00453 OPJ_UINT32 m_header_data_size; 00455 OPJ_UINT32 m_sot_length; 00457 OPJ_UINT32 m_start_tile_x; 00458 OPJ_UINT32 m_start_tile_y; 00459 OPJ_UINT32 m_end_tile_x; 00460 OPJ_UINT32 m_end_tile_y; 00464 OPJ_UINT32 m_DA_x0; 00465 OPJ_UINT32 m_DA_y0; 00466 OPJ_UINT32 m_DA_x1; 00467 OPJ_UINT32 m_DA_y1; 00468 00470 OPJ_INT32 m_tile_ind_to_dec; 00472 OPJ_OFF_T m_last_sot_read_pos; 00473 00479 OPJ_BOOL m_last_tile_part; 00481 OPJ_UINT32 m_can_decode : 1; 00482 OPJ_UINT32 m_discard_tiles : 1; 00483 OPJ_UINT32 m_skip_data : 1; 00484 00485 } opj_j2k_dec_t; 00486 00487 typedef struct opj_j2k_enc 00488 { 00490 OPJ_UINT32 m_current_poc_tile_part_number; /* tp_num */ 00491 00493 OPJ_UINT32 m_current_tile_part_number; /*cur_tp_num */ 00494 00499 OPJ_OFF_T m_tlm_start; 00503 OPJ_BYTE * m_tlm_sot_offsets_buffer; 00507 OPJ_BYTE * m_tlm_sot_offsets_current; 00508 00511 OPJ_UINT32 m_total_tile_parts; /* totnum_tp */ 00512 00513 /* encoded data for a tile */ 00514 OPJ_BYTE * m_encoded_tile_data; 00515 00516 /* size of the encoded_data */ 00517 OPJ_UINT32 m_encoded_tile_size; 00518 00519 /* encoded data for a tile */ 00520 OPJ_BYTE * m_header_tile_data; 00521 00522 /* size of the encoded_data */ 00523 OPJ_UINT32 m_header_tile_data_size; 00524 00525 00526 } opj_j2k_enc_t; 00527 00528 00529 00530 struct opj_tcd; 00534 typedef struct opj_j2k 00535 { 00536 /* J2K codestream is decoded*/ 00537 OPJ_BOOL m_is_decoder; 00538 00539 /* FIXME DOC*/ 00540 union 00541 { 00542 opj_j2k_dec_t m_decoder; 00543 opj_j2k_enc_t m_encoder; 00544 } 00545 m_specific_param; 00546 00548 opj_image_t* m_private_image; 00549 00550 /* pointer to the output image (decoded)*/ 00551 opj_image_t* m_output_image; 00552 00554 opj_cp_t m_cp; 00555 00557 opj_procedure_list_t * m_procedure_list; 00558 00560 opj_procedure_list_t * m_validation_list; 00561 00563 opj_codestream_index_t *cstr_index; 00564 00566 OPJ_UINT32 m_current_tile_number; 00567 00569 struct opj_tcd * m_tcd; 00570 00571 } 00572 opj_j2k_t; 00573 00574 00575 00576 00579 /* ----------------------------------------------------------------------- */ 00580 00587 void opj_j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters); 00588 00594 opj_j2k_t* opj_j2k_create_compress(void); 00595 00596 00597 void opj_j2k_setup_encoder( opj_j2k_t *p_j2k, 00598 opj_cparameters_t *parameters, 00599 opj_image_t *image, 00600 opj_event_mgr_t * p_manager); 00601 00605 char *opj_j2k_convert_progression_order(OPJ_PROG_ORDER prg_order); 00606 00607 /* ----------------------------------------------------------------------- */ 00611 00616 OPJ_BOOL opj_j2k_end_decompress(opj_j2k_t *j2k, 00617 opj_stream_private_t *p_stream, 00618 opj_event_mgr_t * p_manager); 00619 00630 OPJ_BOOL opj_j2k_read_header( opj_stream_private_t *p_stream, 00631 opj_j2k_t* p_j2k, 00632 opj_image_t** p_image, 00633 opj_event_mgr_t* p_manager ); 00634 00635 00641 void opj_j2k_destroy (opj_j2k_t *p_j2k); 00642 00648 void j2k_destroy_cstr_index (opj_codestream_index_t *p_cstr_ind); 00649 00659 OPJ_BOOL opj_j2k_decode_tile ( opj_j2k_t * p_j2k, 00660 OPJ_UINT32 p_tile_index, 00661 OPJ_BYTE * p_data, 00662 OPJ_UINT32 p_data_size, 00663 opj_stream_private_t *p_stream, 00664 opj_event_mgr_t * p_manager ); 00665 00680 OPJ_BOOL opj_j2k_read_tile_header ( opj_j2k_t * p_j2k, 00681 OPJ_UINT32 * p_tile_index, 00682 OPJ_UINT32 * p_data_size, 00683 OPJ_INT32 * p_tile_x0, 00684 OPJ_INT32 * p_tile_y0, 00685 OPJ_INT32 * p_tile_x1, 00686 OPJ_INT32 * p_tile_y1, 00687 OPJ_UINT32 * p_nb_comps, 00688 OPJ_BOOL * p_go_on, 00689 opj_stream_private_t *p_stream, 00690 opj_event_mgr_t * p_manager ); 00691 00692 00706 OPJ_BOOL opj_j2k_set_decode_area( opj_j2k_t *p_j2k, 00707 opj_image_t* p_image, 00708 OPJ_INT32 p_start_x, OPJ_INT32 p_start_y, 00709 OPJ_INT32 p_end_x, OPJ_INT32 p_end_y, 00710 opj_event_mgr_t * p_manager ); 00711 00717 opj_j2k_t* opj_j2k_create_decompress(void); 00718 00719 00728 void j2k_dump (opj_j2k_t* p_j2k, OPJ_INT32 flag, FILE* out_stream); 00729 00730 00731 00739 void j2k_dump_image_header(opj_image_t* image, OPJ_BOOL dev_dump_flag, FILE* out_stream); 00740 00748 void j2k_dump_image_comp_header(opj_image_comp_t* comp, OPJ_BOOL dev_dump_flag, FILE* out_stream); 00749 00757 opj_codestream_info_v2_t* j2k_get_cstr_info(opj_j2k_t* p_j2k); 00758 00766 opj_codestream_index_t* j2k_get_cstr_index(opj_j2k_t* p_j2k); 00767 00776 OPJ_BOOL opj_j2k_decode(opj_j2k_t *j2k, 00777 opj_stream_private_t *p_stream, 00778 opj_image_t *p_image, 00779 opj_event_mgr_t *p_manager); 00780 00781 00782 OPJ_BOOL opj_j2k_get_tile( opj_j2k_t *p_j2k, 00783 opj_stream_private_t *p_stream, 00784 opj_image_t* p_image, 00785 opj_event_mgr_t * p_manager, 00786 OPJ_UINT32 tile_index ); 00787 00788 OPJ_BOOL opj_j2k_set_decoded_resolution_factor(opj_j2k_t *p_j2k, 00789 OPJ_UINT32 res_factor, 00790 opj_event_mgr_t * p_manager); 00791 00792 00802 OPJ_BOOL opj_j2k_write_tile ( opj_j2k_t * p_j2k, 00803 OPJ_UINT32 p_tile_index, 00804 OPJ_BYTE * p_data, 00805 OPJ_UINT32 p_data_size, 00806 opj_stream_private_t *p_stream, 00807 opj_event_mgr_t * p_manager ); 00808 00812 OPJ_BOOL opj_j2k_encode( opj_j2k_t * p_j2k, 00813 opj_stream_private_t *cio, 00814 opj_event_mgr_t * p_manager ); 00815 00826 OPJ_BOOL opj_j2k_start_compress(opj_j2k_t *p_j2k, 00827 opj_stream_private_t *p_stream, 00828 opj_image_t * p_image, 00829 opj_event_mgr_t * p_manager); 00830 00835 OPJ_BOOL opj_j2k_end_compress( opj_j2k_t *p_j2k, 00836 opj_stream_private_t *cio, 00837 opj_event_mgr_t * p_manager); 00838 00839 OPJ_BOOL opj_j2k_setup_mct_encoding (opj_tcp_t * p_tcp, opj_image_t * p_image); 00840 00841 00842 #endif /* __J2K_H */