OpenJPEG 2.1.2

jp2.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) 2002-2003, Yannick Verschueren
00010  * Copyright (c) 2005, Herve Drolon, FreeImage Team
00011  * Copyright (c) 2008, 2011-2012, Centre National d'Etudes Spatiales (CNES), FR 
00012  * Copyright (c) 2012, CS Systemes d'Information, France
00013  * All rights reserved.
00014  *
00015  * Redistribution and use in source and binary forms, with or without
00016  * modification, are permitted provided that the following conditions
00017  * are met:
00018  * 1. Redistributions of source code must retain the above copyright
00019  *    notice, this list of conditions and the following disclaimer.
00020  * 2. Redistributions in binary form must reproduce the above copyright
00021  *    notice, this list of conditions and the following disclaimer in the
00022  *    documentation and/or other materials provided with the distribution.
00023  *
00024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
00025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00027  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00028  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00029  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00030  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00031  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00032  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00033  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00034  * POSSIBILITY OF SUCH DAMAGE.
00035  */
00036 #ifndef __JP2_H
00037 #define __JP2_H
00038 
00046 
00047 /*#define JPIP_JPIP 0x6a706970*/
00048 
00049 #define     JP2_JP   0x6a502020    
00050 #define     JP2_FTYP 0x66747970    
00051 #define     JP2_JP2H 0x6a703268    
00052 #define     JP2_IHDR 0x69686472    
00053 #define     JP2_COLR 0x636f6c72    
00054 #define     JP2_JP2C 0x6a703263    
00055 #define     JP2_URL  0x75726c20    
00056 #define     JP2_PCLR 0x70636c72    
00057 #define     JP2_CMAP 0x636d6170    
00058 #define     JP2_CDEF 0x63646566    
00059 #define     JP2_DTBL 0x6474626c    
00060 #define     JP2_BPCC 0x62706363    
00061 #define     JP2_JP2  0x6a703220    
00063 /* For the future */
00064 /* #define JP2_RES 0x72657320 */  
00065 /* #define JP2_JP2I 0x6a703269 */  
00066 /* #define JP2_XML  0x786d6c20 */  
00067 /* #define JP2_UUID 0x75756994 */  
00068 /* #define JP2_UINF 0x75696e66 */  
00069 /* #define JP2_ULST 0x756c7374 */  
00071 /* ----------------------------------------------------------------------- */
00072 
00073 typedef enum
00074 {
00075   JP2_STATE_NONE            = 0x0,
00076   JP2_STATE_SIGNATURE       = 0x1,
00077   JP2_STATE_FILE_TYPE       = 0x2,
00078   JP2_STATE_HEADER          = 0x4,
00079   JP2_STATE_CODESTREAM      = 0x8,
00080   JP2_STATE_END_CODESTREAM  = 0x10,
00081   JP2_STATE_UNKNOWN         = 0x7fffffff /* ISO C restricts enumerator values to range of 'int' */
00082 }
00083 JP2_STATE;
00084 
00085 typedef enum
00086 {
00087   JP2_IMG_STATE_NONE        = 0x0,
00088   JP2_IMG_STATE_UNKNOWN     = 0x7fffffff
00089 }
00090 JP2_IMG_STATE;
00091 
00095 typedef struct opj_jp2_cdef_info
00096 {
00097     OPJ_UINT16 cn, typ, asoc;
00098 } opj_jp2_cdef_info_t;
00099 
00103 typedef struct opj_jp2_cdef
00104 {
00105     opj_jp2_cdef_info_t *info;
00106     OPJ_UINT16 n;
00107 } opj_jp2_cdef_t;
00108 
00112 typedef struct opj_jp2_cmap_comp
00113 {
00114     OPJ_UINT16 cmp;
00115     OPJ_BYTE mtyp, pcol;
00116 } opj_jp2_cmap_comp_t;
00117 
00121 typedef struct opj_jp2_pclr
00122 {
00123     OPJ_UINT32 *entries;
00124     OPJ_BYTE *channel_sign;
00125     OPJ_BYTE *channel_size;
00126     opj_jp2_cmap_comp_t *cmap;
00127     OPJ_UINT16 nr_entries;
00128     OPJ_BYTE nr_channels;
00129 } opj_jp2_pclr_t;
00130 
00134 typedef struct opj_jp2_color
00135 {
00136     OPJ_BYTE *icc_profile_buf;
00137     OPJ_UINT32 icc_profile_len;
00138 
00139     opj_jp2_cdef_t *jp2_cdef;
00140     opj_jp2_pclr_t *jp2_pclr;
00141     OPJ_BYTE jp2_has_colr;
00142 } opj_jp2_color_t;
00143 
00147 typedef struct opj_jp2_comps {
00148   OPJ_UINT32 depth;      
00149   OPJ_UINT32 sgnd;       
00150   OPJ_UINT32 bpcc;
00151 } opj_jp2_comps_t;
00152 
00156 typedef struct opj_jp2
00157 {
00159   opj_j2k_t *j2k;
00161   struct opj_procedure_list * m_validation_list;
00163   struct opj_procedure_list * m_procedure_list;
00164 
00165   /* width of image */
00166   OPJ_UINT32 w;
00167   /* height of image */
00168   OPJ_UINT32 h;
00169   /* number of components in the image */
00170   OPJ_UINT32 numcomps;
00171   OPJ_UINT32 bpc;
00172   OPJ_UINT32 C;
00173   OPJ_UINT32 UnkC;
00174   OPJ_UINT32 IPR;
00175   OPJ_UINT32 meth;
00176   OPJ_UINT32 approx;
00177   OPJ_UINT32 enumcs;
00178   OPJ_UINT32 precedence;
00179   OPJ_UINT32 brand;
00180   OPJ_UINT32 minversion;
00181   OPJ_UINT32 numcl;
00182   OPJ_UINT32 *cl;
00183   opj_jp2_comps_t *comps;
00184   /* FIXME: The following two variables are used to save offset
00185     as we write out a JP2 file to disk. This mecanism is not flexible
00186     as codec writers will need to extand those fields as new part
00187     of the standard are implemented.
00188   */
00189     OPJ_OFF_T j2k_codestream_offset;
00190     OPJ_OFF_T jpip_iptr_offset;
00191         OPJ_BOOL jpip_on;
00192   OPJ_UINT32 jp2_state;
00193   OPJ_UINT32 jp2_img_state;
00194 
00195   opj_jp2_color_t color;
00196     
00197     OPJ_BOOL ignore_pclr_cmap_cdef;
00198 }
00199 opj_jp2_t;
00200 
00204 typedef struct opj_jp2_box {
00205     OPJ_UINT32 length;
00206     OPJ_UINT32 type;
00207     OPJ_INT32 init_pos;
00208 } opj_jp2_box_t;
00209 
00210 typedef struct opj_jp2_header_handler
00211 {
00212   /* marker value */
00213   OPJ_UINT32 id;
00214   /* action linked to the marker */
00215   OPJ_BOOL (*handler) (     opj_jp2_t *jp2, 
00216                             OPJ_BYTE *p_header_data, 
00217                             OPJ_UINT32 p_header_size, 
00218                             opj_event_mgr_t * p_manager);
00219 }
00220 opj_jp2_header_handler_t;
00221 
00222 
00223 typedef struct opj_jp2_img_header_writer_handler 
00224 {
00225   /* action to perform */
00226   OPJ_BYTE*   (*handler) (opj_jp2_t *jp2, OPJ_UINT32 * p_data_size);
00227   /* result of the action : data */
00228   OPJ_BYTE*   m_data;
00229   /* size of data */
00230   OPJ_UINT32  m_size;
00231 } 
00232 opj_jp2_img_header_writer_handler_t;
00233 
00236 /* ----------------------------------------------------------------------- */
00237 
00244 void opj_jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters);
00245 
00255 OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2,
00256                         opj_stream_private_t *p_stream,
00257             opj_image_t* p_image,
00258             opj_event_mgr_t * p_manager);
00259 
00270 OPJ_BOOL opj_jp2_setup_encoder(  opj_jp2_t *jp2, 
00271                             opj_cparameters_t *parameters, 
00272                             opj_image_t *image, 
00273                             opj_event_mgr_t * p_manager);
00274 
00282 OPJ_BOOL opj_jp2_encode(  opj_jp2_t *jp2, 
00283               opj_stream_private_t *stream, 
00284               opj_event_mgr_t * p_manager);
00285 
00286 
00297 OPJ_BOOL opj_jp2_start_compress(opj_jp2_t *jp2,
00298                                 opj_stream_private_t *stream,
00299                                 opj_image_t * p_image,
00300                                 opj_event_mgr_t * p_manager);
00301 
00302 
00307 OPJ_BOOL opj_jp2_end_compress(  opj_jp2_t *jp2,
00308                   opj_stream_private_t *cio,
00309                   opj_event_mgr_t * p_manager);
00310 
00311 /* ----------------------------------------------------------------------- */
00312 
00317 OPJ_BOOL opj_jp2_end_decompress(opj_jp2_t *jp2, 
00318                                 opj_stream_private_t *cio,
00319                                 opj_event_mgr_t * p_manager);
00320 
00331 OPJ_BOOL opj_jp2_read_header(  opj_stream_private_t *p_stream,
00332                                 opj_jp2_t *jp2,
00333                                 opj_image_t ** p_image,
00334                                 opj_event_mgr_t * p_manager );
00335 
00350 OPJ_BOOL opj_jp2_read_tile_header ( opj_jp2_t * p_jp2,
00351                                     OPJ_UINT32 * p_tile_index,
00352                                     OPJ_UINT32 * p_data_size,
00353                                     OPJ_INT32 * p_tile_x0,
00354                                     OPJ_INT32 * p_tile_y0,
00355                                     OPJ_INT32 * p_tile_x1,
00356                                     OPJ_INT32 * p_tile_y1,
00357                                     OPJ_UINT32 * p_nb_comps,
00358                                     OPJ_BOOL * p_go_on,
00359                                     opj_stream_private_t *p_stream,
00360                                     opj_event_mgr_t * p_manager );
00361 
00372 OPJ_BOOL opj_jp2_write_tile (  opj_jp2_t *p_jp2,
00373                     OPJ_UINT32 p_tile_index,
00374                     OPJ_BYTE * p_data,
00375                     OPJ_UINT32 p_data_size,
00376                     opj_stream_private_t *p_stream,
00377                     opj_event_mgr_t * p_manager );
00378 
00390 OPJ_BOOL opj_jp2_decode_tile (  opj_jp2_t * p_jp2,
00391                                 OPJ_UINT32 p_tile_index,
00392                                 OPJ_BYTE * p_data,
00393                                 OPJ_UINT32 p_data_size,
00394                                 opj_stream_private_t *p_stream,
00395                                 opj_event_mgr_t * p_manager );
00396 
00402 opj_jp2_t* opj_jp2_create (OPJ_BOOL p_is_decoder);
00403 
00408 void opj_jp2_destroy(opj_jp2_t *jp2);
00409 
00410 
00424 OPJ_BOOL opj_jp2_set_decode_area(  opj_jp2_t *p_jp2,
00425                     opj_image_t* p_image,
00426                     OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
00427                     OPJ_INT32 p_end_x, OPJ_INT32 p_end_y,
00428                     opj_event_mgr_t * p_manager );
00429 
00433 OPJ_BOOL opj_jp2_get_tile(  opj_jp2_t *p_jp2,
00434                             opj_stream_private_t *p_stream,
00435                             opj_image_t* p_image,
00436                             opj_event_mgr_t * p_manager,
00437                             OPJ_UINT32 tile_index );
00438 
00439 
00443 OPJ_BOOL opj_jp2_set_decoded_resolution_factor(opj_jp2_t *p_jp2, 
00444                                                OPJ_UINT32 res_factor, 
00445                                                opj_event_mgr_t * p_manager);
00446 
00447 
00448 /* TODO MSD: clean these 3 functions */
00457 void jp2_dump (opj_jp2_t* p_jp2, OPJ_INT32 flag, FILE* out_stream);
00458 
00466 opj_codestream_info_v2_t* jp2_get_cstr_info(opj_jp2_t* p_jp2);
00467 
00475 opj_codestream_index_t* jp2_get_cstr_index(opj_jp2_t* p_jp2);
00476 
00477 
00481 
00482 #endif /* __JP2_H */
00483