OpenJPEG 2.1.2

j2k.h

Go to the documentation of this file.
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 
00235 typedef struct opj_ppx_struct
00236 {
00237         OPJ_BYTE*   m_data; /* m_data == NULL => Zppx not read yet */
00238         OPJ_UINT32      m_data_size;
00239 } opj_ppx;
00240 
00246 typedef struct opj_tcp
00247 {
00249         OPJ_UINT32 csty;
00251         OPJ_PROG_ORDER prg;
00253         OPJ_UINT32 numlayers;
00254         OPJ_UINT32 num_layers_to_decode;
00256         OPJ_UINT32 mct;
00258         OPJ_FLOAT32 rates[100];
00260         OPJ_UINT32 numpocs;
00262         opj_poc_t pocs[32];
00263         
00265         OPJ_UINT32 ppt_markers_count;
00267         opj_ppx* ppt_markers;
00268         
00270         OPJ_BYTE *ppt_data;
00272         OPJ_BYTE *ppt_buffer;
00274         OPJ_UINT32 ppt_data_size;
00276         OPJ_UINT32 ppt_len;
00278         OPJ_FLOAT32 distoratio[100];
00280         opj_tccp_t *tccps;
00282         OPJ_UINT32 m_nb_tile_parts;
00284         OPJ_BYTE *              m_data;
00286         OPJ_UINT32              m_data_size;
00288         OPJ_FLOAT64 *   mct_norms;
00290         OPJ_FLOAT32 *   m_mct_decoding_matrix;
00292         OPJ_FLOAT32 *   m_mct_coding_matrix;
00294         opj_mct_data_t * m_mct_records;
00296         OPJ_UINT32 m_nb_mct_records;
00298         OPJ_UINT32 m_nb_max_mct_records;
00300         opj_simple_mcc_decorrelation_data_t * m_mcc_records;
00302         OPJ_UINT32 m_nb_mcc_records;
00304         OPJ_UINT32 m_nb_max_mcc_records;
00305 
00306 
00307         /***** FLAGS *******/
00309         OPJ_UINT32 cod : 1;
00311         OPJ_UINT32 ppt : 1;
00313         OPJ_UINT32 POC : 1;
00314 } opj_tcp_t;
00315 
00316 
00317 
00318 
00319 typedef struct opj_encoding_param
00320 {
00322         OPJ_UINT32 m_max_comp_size;
00324         OPJ_INT32 m_tp_pos;
00326         OPJ_INT32 *m_matrice;
00328         OPJ_BYTE m_tp_flag;
00330         OPJ_UINT32 m_disto_alloc : 1;
00332         OPJ_UINT32 m_fixed_alloc : 1;
00334         OPJ_UINT32 m_fixed_quality : 1;
00336         OPJ_UINT32 m_tp_on : 1;
00337 }
00338 opj_encoding_param_t;
00339 
00340 typedef struct opj_decoding_param
00341 {
00343         OPJ_UINT32 m_reduce;
00345         OPJ_UINT32 m_layer;
00346 }
00347 opj_decoding_param_t;
00348 
00349 
00353 typedef struct opj_cp
00354 {
00356         /*int img_size;*/
00358     OPJ_UINT16 rsiz;
00360         OPJ_UINT32 tx0; /* MSD see norm */
00362         OPJ_UINT32 ty0; /* MSD see norm */
00364         OPJ_UINT32 tdx;
00366         OPJ_UINT32 tdy;
00368         OPJ_CHAR *comment;
00370         OPJ_UINT32 tw;
00372         OPJ_UINT32 th;
00373 
00375         OPJ_UINT32 ppm_markers_count;
00377         opj_ppx* ppm_markers;
00378         
00380         OPJ_BYTE *ppm_data;
00382         OPJ_UINT32 ppm_len;
00384         OPJ_UINT32 ppm_data_read;
00385 
00386         OPJ_BYTE *ppm_data_current;
00387 
00389         OPJ_BYTE *ppm_buffer;
00391         OPJ_BYTE *ppm_data_first;
00393         OPJ_UINT32 ppm_data_size;
00395         OPJ_INT32 ppm_store;
00397         OPJ_INT32 ppm_previous;
00398 
00400         opj_tcp_t *tcps;
00401 
00402         union
00403         {
00404                 opj_decoding_param_t m_dec;
00405                 opj_encoding_param_t m_enc;
00406         }
00407         m_specific_param;
00408 
00409 
00410 /* UniPG>> */
00411 #ifdef USE_JPWL
00412 
00413         OPJ_BOOL epc_on;
00415         OPJ_BOOL epb_on;
00417         OPJ_BOOL esd_on;
00419         OPJ_BOOL info_on;
00421         OPJ_BOOL red_on;
00423         int hprot_MH;
00425         int hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS];
00427         int hprot_TPH[JPWL_MAX_NO_TILESPECS];
00429         int pprot_tileno[JPWL_MAX_NO_PACKSPECS];
00431         int pprot_packno[JPWL_MAX_NO_PACKSPECS];
00433         int pprot[JPWL_MAX_NO_PACKSPECS];
00435         int sens_size;
00437         int sens_addr;
00439         int sens_range;
00441         int sens_MH;
00443         int sens_TPH_tileno[JPWL_MAX_NO_TILESPECS];
00445         int sens_TPH[JPWL_MAX_NO_TILESPECS];
00447         OPJ_BOOL correct;
00449         int exp_comps;
00451         OPJ_UINT32 max_tiles;
00452 #endif /* USE_JPWL */
00453 
00454         /******** FLAGS *********/
00456         OPJ_UINT32 ppm : 1;
00458         OPJ_UINT32 m_is_decoder : 1;
00459 /* <<UniPG */
00460 } opj_cp_t;
00461 
00462 
00463 typedef struct opj_j2k_dec
00464 {
00466         OPJ_UINT32 m_state;
00470         opj_tcp_t *m_default_tcp;
00471         OPJ_BYTE  *m_header_data;
00472         OPJ_UINT32 m_header_data_size;
00474         OPJ_UINT32 m_sot_length;
00476         OPJ_UINT32 m_start_tile_x;
00477         OPJ_UINT32 m_start_tile_y;
00478         OPJ_UINT32 m_end_tile_x;
00479         OPJ_UINT32 m_end_tile_y;
00483         OPJ_UINT32 m_DA_x0;
00484         OPJ_UINT32 m_DA_y0;
00485         OPJ_UINT32 m_DA_x1;
00486         OPJ_UINT32 m_DA_y1;
00487 
00489         OPJ_INT32 m_tile_ind_to_dec;
00491         OPJ_OFF_T m_last_sot_read_pos;
00492 
00498         OPJ_BOOL   m_last_tile_part;
00500         OPJ_UINT32 m_can_decode                 : 1;
00501         OPJ_UINT32 m_discard_tiles              : 1;
00502         OPJ_UINT32 m_skip_data                  : 1;
00504         OPJ_UINT32 m_nb_tile_parts_correction_checked : 1;
00505         OPJ_UINT32 m_nb_tile_parts_correction : 1;
00506 
00507 } opj_j2k_dec_t;
00508 
00509 typedef struct opj_j2k_enc
00510 {
00512         OPJ_UINT32 m_current_poc_tile_part_number; /* tp_num */
00513 
00515         OPJ_UINT32 m_current_tile_part_number; /*cur_tp_num */
00516 
00521     OPJ_OFF_T m_tlm_start;
00525         OPJ_BYTE * m_tlm_sot_offsets_buffer;
00529         OPJ_BYTE * m_tlm_sot_offsets_current;
00530 
00533         OPJ_UINT32 m_total_tile_parts;   /* totnum_tp */
00534 
00535         /* encoded data for a tile */
00536         OPJ_BYTE * m_encoded_tile_data;
00537 
00538         /* size of the encoded_data */
00539         OPJ_UINT32 m_encoded_tile_size;
00540 
00541         /* encoded data for a tile */
00542         OPJ_BYTE * m_header_tile_data;
00543 
00544         /* size of the encoded_data */
00545         OPJ_UINT32 m_header_tile_data_size;
00546 
00547 
00548 } opj_j2k_enc_t;
00549 
00550 
00551 
00552 struct opj_tcd;
00556 typedef struct opj_j2k
00557 {
00558         /* J2K codestream is decoded*/
00559         OPJ_BOOL m_is_decoder;
00560 
00561         /* FIXME DOC*/
00562         union
00563         {
00564                 opj_j2k_dec_t m_decoder;
00565                 opj_j2k_enc_t m_encoder;
00566         }
00567         m_specific_param;
00568 
00570         opj_image_t* m_private_image;
00571 
00572         /* pointer to the output image (decoded)*/
00573         opj_image_t* m_output_image;
00574 
00576         opj_cp_t m_cp;
00577 
00579         opj_procedure_list_t *  m_procedure_list;
00580 
00582         opj_procedure_list_t *  m_validation_list;
00583 
00585         opj_codestream_index_t *cstr_index;
00586 
00588         OPJ_UINT32 m_current_tile_number;
00589 
00591         struct opj_tcd *        m_tcd;
00592 }
00593 opj_j2k_t;
00594 
00595 
00596 
00597 
00600 /* ----------------------------------------------------------------------- */
00601 
00608 void opj_j2k_setup_decoder(opj_j2k_t *j2k, opj_dparameters_t *parameters);
00609 
00615 opj_j2k_t* opj_j2k_create_compress(void);
00616 
00617 
00618 OPJ_BOOL opj_j2k_setup_encoder( opj_j2k_t *p_j2k,
00619                                                     opj_cparameters_t *parameters,
00620                                                     opj_image_t *image,
00621                                                     opj_event_mgr_t * p_manager);
00622 
00626 char *opj_j2k_convert_progression_order(OPJ_PROG_ORDER prg_order);
00627 
00628 /* ----------------------------------------------------------------------- */
00632 
00637 OPJ_BOOL opj_j2k_end_decompress(opj_j2k_t *j2k,
00638                                 opj_stream_private_t *p_stream,
00639                                 opj_event_mgr_t * p_manager);
00640 
00651 OPJ_BOOL opj_j2k_read_header(   opj_stream_private_t *p_stream,
00652                                 opj_j2k_t* p_j2k,
00653                                 opj_image_t** p_image,
00654                                 opj_event_mgr_t* p_manager );
00655 
00656 
00662 void opj_j2k_destroy (opj_j2k_t *p_j2k);
00663 
00669 void j2k_destroy_cstr_index (opj_codestream_index_t *p_cstr_ind);
00670 
00680 OPJ_BOOL opj_j2k_decode_tile (  opj_j2k_t * p_j2k,
00681                                 OPJ_UINT32 p_tile_index,
00682                                 OPJ_BYTE * p_data,
00683                                 OPJ_UINT32 p_data_size,
00684                                 opj_stream_private_t *p_stream,
00685                                 opj_event_mgr_t * p_manager );
00686 
00701 OPJ_BOOL opj_j2k_read_tile_header ( opj_j2k_t * p_j2k,
00702                                     OPJ_UINT32 * p_tile_index,
00703                                     OPJ_UINT32 * p_data_size,
00704                                     OPJ_INT32 * p_tile_x0,
00705                                     OPJ_INT32 * p_tile_y0,
00706                                     OPJ_INT32 * p_tile_x1,
00707                                     OPJ_INT32 * p_tile_y1,
00708                                     OPJ_UINT32 * p_nb_comps,
00709                                     OPJ_BOOL * p_go_on,
00710                                     opj_stream_private_t *p_stream,
00711                                     opj_event_mgr_t * p_manager );
00712 
00713 
00727 OPJ_BOOL opj_j2k_set_decode_area(       opj_j2k_t *p_j2k,
00728                                                                     opj_image_t* p_image,
00729                                                                     OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
00730                                                                     OPJ_INT32 p_end_x, OPJ_INT32 p_end_y,
00731                                                                     opj_event_mgr_t * p_manager );
00732 
00738 opj_j2k_t* opj_j2k_create_decompress(void);
00739 
00740 
00749 void j2k_dump (opj_j2k_t* p_j2k, OPJ_INT32 flag, FILE* out_stream);
00750 
00751 
00752 
00760 void j2k_dump_image_header(opj_image_t* image, OPJ_BOOL dev_dump_flag, FILE* out_stream);
00761 
00769 void j2k_dump_image_comp_header(opj_image_comp_t* comp, OPJ_BOOL dev_dump_flag, FILE* out_stream);
00770 
00778 opj_codestream_info_v2_t* j2k_get_cstr_info(opj_j2k_t* p_j2k);
00779 
00787 opj_codestream_index_t* j2k_get_cstr_index(opj_j2k_t* p_j2k);
00788 
00797 OPJ_BOOL opj_j2k_decode(opj_j2k_t *j2k,
00798                         opj_stream_private_t *p_stream,
00799                         opj_image_t *p_image,
00800                         opj_event_mgr_t *p_manager);
00801 
00802 
00803 OPJ_BOOL opj_j2k_get_tile(      opj_j2k_t *p_j2k,
00804                                                 opj_stream_private_t *p_stream,
00805                                                 opj_image_t* p_image,
00806                                                 opj_event_mgr_t * p_manager,
00807                                                     OPJ_UINT32 tile_index );
00808 
00809 OPJ_BOOL opj_j2k_set_decoded_resolution_factor(opj_j2k_t *p_j2k, 
00810                                                OPJ_UINT32 res_factor,
00811                                                opj_event_mgr_t * p_manager);
00812 
00813 
00823 OPJ_BOOL opj_j2k_write_tile (   opj_j2k_t * p_j2k,
00824                                                             OPJ_UINT32 p_tile_index,
00825                                                             OPJ_BYTE * p_data,
00826                                                             OPJ_UINT32 p_data_size,
00827                                                             opj_stream_private_t *p_stream,
00828                                                             opj_event_mgr_t * p_manager );
00829 
00833 OPJ_BOOL opj_j2k_encode(        opj_j2k_t * p_j2k,
00834                                                 opj_stream_private_t *cio,
00835                                                 opj_event_mgr_t * p_manager );
00836 
00847 OPJ_BOOL opj_j2k_start_compress(opj_j2k_t *p_j2k,
00848                                                             opj_stream_private_t *p_stream,
00849                                                             opj_image_t * p_image,
00850                                                             opj_event_mgr_t * p_manager);
00851 
00856 OPJ_BOOL opj_j2k_end_compress(  opj_j2k_t *p_j2k,
00857                                                             opj_stream_private_t *cio,
00858                                                             opj_event_mgr_t * p_manager);
00859 
00860 OPJ_BOOL opj_j2k_setup_mct_encoding (opj_tcp_t * p_tcp, opj_image_t * p_image);
00861 
00862 
00863 #endif /* __J2K_H */