OpenJPEG 2.1.0

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 
00247 OPJ_BOOL opj_jp2_write_jp2h(opj_jp2_t *jp2,
00248                             opj_stream_private_t *stream,
00249                             opj_event_mgr_t * p_manager );
00250 
00257 void opj_jp2_setup_decoder(opj_jp2_t *jp2, opj_dparameters_t *parameters);
00258 
00268 OPJ_BOOL opj_jp2_decode(opj_jp2_t *jp2,
00269                         opj_stream_private_t *p_stream,
00270             opj_image_t* p_image,
00271             opj_event_mgr_t * p_manager);
00272 
00282 void opj_jp2_setup_encoder(  opj_jp2_t *jp2, 
00283                             opj_cparameters_t *parameters, 
00284                             opj_image_t *image, 
00285                             opj_event_mgr_t * p_manager);
00286 
00294 OPJ_BOOL opj_jp2_encode(  opj_jp2_t *jp2, 
00295               opj_stream_private_t *stream, 
00296               opj_event_mgr_t * p_manager);
00297 
00298 
00309 OPJ_BOOL opj_jp2_start_compress(opj_jp2_t *jp2,
00310                                 opj_stream_private_t *stream,
00311                                 opj_image_t * p_image,
00312                                 opj_event_mgr_t * p_manager);
00313 
00314 
00319 OPJ_BOOL opj_jp2_end_compress(  opj_jp2_t *jp2,
00320                   opj_stream_private_t *cio,
00321                   opj_event_mgr_t * p_manager);
00322 
00323 /* ----------------------------------------------------------------------- */
00324 
00329 OPJ_BOOL opj_jp2_end_decompress(opj_jp2_t *jp2, 
00330                                 opj_stream_private_t *cio,
00331                                 opj_event_mgr_t * p_manager);
00332 
00343 OPJ_BOOL opj_jp2_read_header(  opj_stream_private_t *p_stream,
00344                                 opj_jp2_t *jp2,
00345                                 opj_image_t ** p_image,
00346                                 opj_event_mgr_t * p_manager );
00347 
00362 OPJ_BOOL opj_jp2_read_tile_header ( opj_jp2_t * p_jp2,
00363                                     OPJ_UINT32 * p_tile_index,
00364                                     OPJ_UINT32 * p_data_size,
00365                                     OPJ_INT32 * p_tile_x0,
00366                                     OPJ_INT32 * p_tile_y0,
00367                                     OPJ_INT32 * p_tile_x1,
00368                                     OPJ_INT32 * p_tile_y1,
00369                                     OPJ_UINT32 * p_nb_comps,
00370                                     OPJ_BOOL * p_go_on,
00371                                     opj_stream_private_t *p_stream,
00372                                     opj_event_mgr_t * p_manager );
00373 
00384 OPJ_BOOL opj_jp2_write_tile (  opj_jp2_t *p_jp2,
00385                     OPJ_UINT32 p_tile_index,
00386                     OPJ_BYTE * p_data,
00387                     OPJ_UINT32 p_data_size,
00388                     opj_stream_private_t *p_stream,
00389                     opj_event_mgr_t * p_manager );
00390 
00402 OPJ_BOOL opj_jp2_decode_tile (  opj_jp2_t * p_jp2,
00403                                 OPJ_UINT32 p_tile_index,
00404                                 OPJ_BYTE * p_data,
00405                                 OPJ_UINT32 p_data_size,
00406                                 opj_stream_private_t *p_stream,
00407                                 opj_event_mgr_t * p_manager );
00408 
00414 opj_jp2_t* opj_jp2_create (OPJ_BOOL p_is_decoder);
00415 
00420 void opj_jp2_destroy(opj_jp2_t *jp2);
00421 
00422 
00436 OPJ_BOOL opj_jp2_set_decode_area(  opj_jp2_t *p_jp2,
00437                     opj_image_t* p_image,
00438                     OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
00439                     OPJ_INT32 p_end_x, OPJ_INT32 p_end_y,
00440                     opj_event_mgr_t * p_manager );
00441 
00445 OPJ_BOOL opj_jp2_get_tile(  opj_jp2_t *p_jp2,
00446                             opj_stream_private_t *p_stream,
00447                             opj_image_t* p_image,
00448                             opj_event_mgr_t * p_manager,
00449                             OPJ_UINT32 tile_index );
00450 
00451 
00455 OPJ_BOOL opj_jp2_set_decoded_resolution_factor(opj_jp2_t *p_jp2, 
00456                                                OPJ_UINT32 res_factor, 
00457                                                opj_event_mgr_t * p_manager);
00458 
00459 
00460 /* TODO MSD: clean these 3 functions */
00469 void jp2_dump (opj_jp2_t* p_jp2, OPJ_INT32 flag, FILE* out_stream);
00470 
00478 opj_codestream_info_v2_t* jp2_get_cstr_info(opj_jp2_t* p_jp2);
00479 
00487 opj_codestream_index_t* jp2_get_cstr_index(opj_jp2_t* p_jp2);
00488 
00489 
00493 
00494 #endif /* __JP2_H */
00495