[trunk] WIP: fix some warnings about a static function and j2k_read_unk_v2
[openjpeg.git] / libopenjpeg / openjpeg.c
index f5e4ee23ff86b04fe46de835033f1ffc63fd9f8f..be69b3e8989dfc57f2370166189f0eb4b448d933 100644 (file)
 #include "opj_config.h"
 #include "opj_includes.h"
 
+
+/**
+ * Decompression handler.
+ */
 typedef struct opj_decompression
 {
-       opj_bool (* opj_read_header) (
-                       struct opj_stream_private * cio,
-                       void * p_codec,
-                       opj_image_header_t ** image_header,
-                       opj_codestream_info_t ** cstr_info,
-                       struct opj_event_mgr * p_manager);
-       opj_image_t* (* opj_decode) (void * p_codec, struct opj_stream_private *p_cio, struct opj_event_mgr * p_manager);
-       opj_bool (*opj_read_tile_header)(
-               void * p_codec,
-               OPJ_UINT32 * p_tile_index,
-               OPJ_UINT32* p_data_size,
-               OPJ_INT32 * p_tile_x0,
-               OPJ_INT32 * p_tile_y0,
-               OPJ_INT32 * p_tile_x1,
-               OPJ_INT32 * p_tile_y1,
-               OPJ_UINT32 * p_nb_comps,
-               opj_bool * p_should_go_on,
-               struct opj_stream_private *p_cio,
-               struct opj_event_mgr * p_manager);
-               opj_bool (*opj_decode_tile_data)(void * p_codec,OPJ_UINT32 p_tile_index,OPJ_BYTE * p_data,OPJ_UINT32 p_data_size,struct opj_stream_private *p_cio,struct opj_event_mgr * p_manager);
-       opj_bool (* opj_end_decompress) (void *p_codec,struct opj_stream_private *cio,struct opj_event_mgr * p_manager);
+       /** Main header reading function handler*/
+       opj_bool (* opj_read_header) (  struct opj_stream_private * cio,
+                                                                       void * p_codec,
+                                                                       opj_image_header_t *p_img_header,
+                                                                       struct opj_event_mgr * p_manager);
+       /** FIXME DOC */
+       opj_image_t* (* opj_decode) (   void * p_codec,
+                                                                       struct opj_stream_private *p_cio,
+                                                                       struct opj_event_mgr * p_manager);
+       /** FIXME DOC */
+       opj_bool (*opj_read_tile_header)(       void * p_codec,
+                                                                               OPJ_UINT32 * p_tile_index,
+                                                                               OPJ_UINT32* p_data_size,
+                                                                               OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0,
+                                                                               OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1,
+                                                                               OPJ_UINT32 * p_nb_comps,
+                                                                               opj_bool * p_should_go_on,
+                                                                               struct opj_stream_private *p_cio,
+                                                                               struct opj_event_mgr * p_manager);
+       /** FIXME DOC */
+       opj_bool (*opj_decode_tile_data)(       void * p_codec,
+                                                                               OPJ_UINT32 p_tile_index,
+                                                                               OPJ_BYTE * p_data,
+                                                                               OPJ_UINT32 p_data_size,
+                                                                               struct opj_stream_private *p_cio,
+                                                                               struct opj_event_mgr * p_manager);
+       /** FIXME DOC */
+       opj_bool (* opj_end_decompress) (       void *p_codec,
+                                                                               struct opj_stream_private *cio,
+                                                                               struct opj_event_mgr * p_manager);
+       /** Codec destroy function handler*/
        void (* opj_destroy) (void * p_codec);
-       void (*opj_setup_decoder) (void * p_codec,opj_dparameters_t * p_param);
-       opj_bool (*opj_set_decode_area) (void * p_codec,OPJ_INT32 p_start_x,OPJ_INT32 p_end_x,OPJ_INT32 p_start_y,OPJ_INT32 p_end_y,struct opj_event_mgr * p_manager);
-
-
+       /** Setup decoder function handler */
+       void (*opj_setup_decoder) (void * p_codec, opj_dparameters_t * p_param);
+       /** Set decode area function handler */
+       opj_bool (*opj_set_decode_area) (       void * p_codec,
+                                                                               OPJ_INT32 p_start_x, OPJ_INT32 p_end_x,
+                                                                               OPJ_INT32 p_start_y, OPJ_INT32 p_end_y,
+                                                                               struct opj_event_mgr * p_manager);
 }opj_decompression_t;
 
+/**
+ * Compression handler. FIXME DOC
+ */
 typedef struct opj_compression
 {
        opj_bool (* opj_start_compress) (void *p_codec,struct opj_stream_private *cio,struct opj_image * p_image,       struct opj_event_mgr * p_manager);
@@ -72,38 +92,32 @@ typedef struct opj_compression
 
 }opj_compression_t;
 
+/**
+ * Main codec handler used for compression or decompression.
+ */
 typedef struct opj_codec_private
 {
-       union
-       {               /* code-blocks informations */
-         opj_decompression_t m_decompression;
-         opj_compression_t m_compression;
+       /** FIXME DOC */
+       union {
+               opj_decompression_t m_decompression;
+               opj_compression_t m_compression;
     } m_codec_data;
+    /** FIXME DOC*/
        void * m_codec;
+       /** Event handler */
        opj_event_mgr_t* m_event_mgr;
-       unsigned is_decompressor : 1;
+       /** Flag to indicate if the codec is used to decode or encode*/
+       opj_bool is_decompressor;
+       opj_bool (*opj_dump_codec) (void * p_codec, OPJ_INT32 info_flag, FILE* output_stream);
+       opj_codestream_info_v2_t* (*opj_get_codec_info)(void* p_codec);
+       opj_codestream_index_t* (*opj_get_codec_index)(void* p_codec);
 }
 opj_codec_private_t;
 
-/**
- * Default callback function.
- * Do nothing.
- */
-void opj_default_callback (const char *msg, void *client_data)
-{
-       //FIXME V2 -> V1 cf below
-}
 
-void set_default_event_handler(opj_event_mgr_t * p_manager)
-{
-       //FIXME V2 -> V1
-       //p_manager->m_error_data = 00;
-       //p_manager->m_warning_data = 00;
-       //p_manager->m_info_data = 00;
-       p_manager->error_handler = opj_default_callback;
-       p_manager->info_handler = opj_default_callback;
-       p_manager->warning_handler = opj_default_callback;
-}
+
+/* ---------------------------------------------------------------------- */
+
 
 OPJ_UINT32 opj_read_from_file (void * p_buffer, OPJ_UINT32 p_nb_bytes, FILE * p_file)
 {
@@ -118,21 +132,19 @@ OPJ_UINT32 opj_write_from_file (void * p_buffer, OPJ_UINT32 p_nb_bytes, FILE * p
 
 OPJ_SIZE_T opj_skip_from_file (OPJ_SIZE_T p_nb_bytes, FILE * p_user_data)
 {
-       if
-               (fseek(p_user_data,p_nb_bytes,SEEK_CUR))
-       {
+       if (fseek(p_user_data,p_nb_bytes,SEEK_CUR)) {
                return -1;
        }
+
        return p_nb_bytes;
 }
 
 opj_bool opj_seek_from_file (OPJ_SIZE_T p_nb_bytes, FILE * p_user_data)
 {
-       if
-               (fseek(p_user_data,p_nb_bytes,SEEK_SET))
-       {
+       if (fseek(p_user_data,p_nb_bytes,SEEK_SET)) {
                return EXIT_FAILURE;
        }
+
        return EXIT_SUCCESS;
 }
 
@@ -167,6 +179,8 @@ const char* OPJ_CALLCONV opj_version(void) {
     return PACKAGE_VERSION;
 }
 
+
+
 opj_dinfo_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format) {
        opj_dinfo_t *dinfo = (opj_dinfo_t*)opj_calloc(1, sizeof(opj_dinfo_t));
        if(!dinfo) return NULL;
@@ -212,63 +226,69 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress_v2(OPJ_CODEC_FORMAT p_format)
 
        l_info->is_decompressor = 1;
 
-       switch
-               (p_format)
-       {
+       switch (p_format) {
                case CODEC_J2K:
-                       l_info->m_codec_data.m_decompression.opj_decode = (opj_image_t* (*) (void *, struct opj_stream_private *, struct opj_event_mgr * ))j2k_decode;
-                       l_info->m_codec_data.m_decompression.opj_end_decompress =  (opj_bool (*) (void *,struct opj_stream_private *,struct opj_event_mgr *))j2k_end_decompress;
-                       l_info->m_codec_data.m_decompression.opj_read_header =  (opj_bool (*) (
-                                       struct opj_stream_private *,
-                                       void *,
-                                       opj_image_header_t **,
-                                       opj_codestream_info_t**,
-                                       struct opj_event_mgr * )) j2k_read_header;
+                       l_info->opj_dump_codec = (opj_bool (*) (void*, OPJ_INT32, FILE*)) j2k_dump;
+
+                       l_info->opj_get_codec_info = (opj_codestream_info_v2_t* (*) (void*) ) j2k_get_cstr_info;
+
+                       l_info->opj_get_codec_index = (opj_codestream_index_t* (*) (void*) ) j2k_get_cstr_index;
+
+                       l_info->m_codec_data.m_decompression.opj_decode =
+                                       (opj_image_t* (*) (void *, struct opj_stream_private *, struct opj_event_mgr * ))j2k_decode; // TODO MSD
+
+                       l_info->m_codec_data.m_decompression.opj_end_decompress =
+                                       (opj_bool (*) (void *, struct opj_stream_private *, struct opj_event_mgr *))j2k_end_decompress;
+
+                       l_info->m_codec_data.m_decompression.opj_read_header =
+                                       (opj_bool (*) ( struct opj_stream_private *,
+                                                                       void *,
+                                                                       opj_image_header_t *,
+                                                                       struct opj_event_mgr * )) j2k_read_header;
+
                        l_info->m_codec_data.m_decompression.opj_destroy = (void (*) (void *))j2k_destroy;
-                       l_info->m_codec_data.m_decompression.opj_setup_decoder = (void (*) (void * ,opj_dparameters_t * )) j2k_setup_decoder;
-                       l_info->m_codec_data.m_decompression.opj_read_tile_header = (opj_bool (*) (
-                               void *,
-                               OPJ_UINT32*,
-                               OPJ_UINT32*,
-                               OPJ_INT32 * ,
-                               OPJ_INT32 * ,
-                               OPJ_INT32 * ,
-                               OPJ_INT32 * ,
-                               OPJ_UINT32 * ,
-                               opj_bool *,
-                               struct opj_stream_private *,
-                               struct opj_event_mgr * )) j2k_read_tile_header;
-                               l_info->m_codec_data.m_decompression.opj_decode_tile_data = (opj_bool (*) (void *,OPJ_UINT32,OPJ_BYTE*,OPJ_UINT32,struct opj_stream_private *,  struct opj_event_mgr * )) j2k_decode_tile;
-                       l_info->m_codec_data.m_decompression.opj_set_decode_area = (opj_bool (*) (void *,OPJ_INT32,OPJ_INT32,OPJ_INT32,OPJ_INT32, struct opj_event_mgr * )) j2k_set_decode_area;
+
+                       l_info->m_codec_data.m_decompression.opj_setup_decoder = (void (*) (void * , opj_dparameters_t * )) j2k_setup_decoder_v2;
+
+                       l_info->m_codec_data.m_decompression.opj_read_tile_header =
+                                       (opj_bool (*) ( void *,
+                                                                       OPJ_UINT32*,
+                                                                       OPJ_UINT32*,
+                                                                       OPJ_INT32*, OPJ_INT32*,
+                                                                       OPJ_INT32*, OPJ_INT32*,
+                                                                       OPJ_UINT32*,
+                                                                       opj_bool*,
+                                                                       struct opj_stream_private *,
+                                                                       struct opj_event_mgr * )) j2k_read_tile_header;
+
+                       l_info->m_codec_data.m_decompression.opj_decode_tile_data =
+                                       (opj_bool (*) (void *, OPJ_UINT32, OPJ_BYTE*, OPJ_UINT32, struct opj_stream_private *, struct opj_event_mgr *)) j2k_decode_tile;
+
+                       l_info->m_codec_data.m_decompression.opj_set_decode_area =
+                                       (opj_bool (*) (void *, OPJ_INT32, OPJ_INT32, OPJ_INT32, OPJ_INT32, struct opj_event_mgr *)) j2k_set_decode_area;
+
                        l_info->m_codec = j2k_create_decompress_v2();
-                       if
-                               (! l_info->m_codec)
-                       {
+
+                       if (! l_info->m_codec) {
                                opj_free(l_info);
-                               return 00;
+                               return NULL;
                        }
+
                        break;
 
                case CODEC_JP2:
                        /* get a JP2 decoder handle */
-#ifdef TODO_MSD
-                       l_info->m_codec_data.m_decompression.opj_decode = (opj_image_t* (*) (void *, struct opj_stream_private *, struct opj_event_mgr * ))opj_jp2_decode;
+                       l_info->m_codec_data.m_decompression.opj_decode = (opj_image_t* (*) (void *, struct opj_stream_private *, struct opj_event_mgr * ))opj_jp2_decode; // TODO MSD
+
                        l_info->m_codec_data.m_decompression.opj_end_decompress =  (opj_bool (*) (void *,struct opj_stream_private *,struct opj_event_mgr *)) jp2_end_decompress;
+
                        l_info->m_codec_data.m_decompression.opj_read_header =  (opj_bool (*) (
-                               void *,
-                               opj_image_t **,
-
-                               OPJ_INT32 * ,
-                               OPJ_INT32 * ,
-                               OPJ_UINT32 * ,
-                               OPJ_UINT32 * ,
-                               OPJ_UINT32 * ,
-                               OPJ_UINT32 * ,
-                               struct opj_stream_private *,
-                               struct opj_event_mgr * )) jp2_read_header;
-
-                       l_info->m_codec_data.m_decompression.opj_read_tile_header = (
-                               opj_bool (*) (
+                                       struct opj_stream_private *,
+                                       void *,
+                                       opj_image_header_t *,
+                                       struct opj_event_mgr * )) jp2_read_header;
+
+                       l_info->m_codec_data.m_decompression.opj_read_tile_header = ( opj_bool (*) (
                                        void *,
                                        OPJ_UINT32*,
                                        OPJ_UINT32*,
@@ -284,18 +304,18 @@ opj_codec_t* OPJ_CALLCONV opj_create_decompress_v2(OPJ_CODEC_FORMAT p_format)
                        l_info->m_codec_data.m_decompression.opj_decode_tile_data = (opj_bool (*) (void *,OPJ_UINT32,OPJ_BYTE*,OPJ_UINT32,struct opj_stream_private *,  struct opj_event_mgr * )) opj_jp2_decode_tile;
 
                        l_info->m_codec_data.m_decompression.opj_destroy = (void (*) (void *))jp2_destroy;
-                       l_info->m_codec_data.m_decompression.opj_setup_decoder = (void (*) (void * ,opj_dparameters_t * )) jp2_setup_decoder;
-                       l_info->m_codec_data.m_decompression.opj_set_decode_area = (opj_bool (*) (void *,OPJ_INT32,OPJ_INT32,OPJ_INT32,OPJ_INT32, struct opj_event_mgr * )) jp2_set_decode_area;
 
+                       l_info->m_codec_data.m_decompression.opj_setup_decoder = (void (*) (void * ,opj_dparameters_t * )) jp2_setup_decoder_v2;
+
+                       l_info->m_codec_data.m_decompression.opj_set_decode_area = (opj_bool (*) (void *,OPJ_INT32,OPJ_INT32,OPJ_INT32,OPJ_INT32, struct opj_event_mgr * )) jp2_set_decode_area;
 
                        l_info->m_codec = jp2_create(OPJ_TRUE);
-                       if
-                               (! l_info->m_codec)
-                       {
+
+                       if (! l_info->m_codec) {
                                opj_free(l_info);
                                return 00;
                        }
-#endif
+
                        break;
                case CODEC_UNKNOWN:
                case CODEC_JPT:
@@ -368,27 +388,28 @@ void OPJ_CALLCONV opj_setup_decoder(opj_dinfo_t *dinfo, opj_dparameters_t *param
 
 opj_bool OPJ_CALLCONV opj_setup_decoder_v2(opj_codec_t *p_info, opj_dparameters_t *parameters, opj_event_mgr_t* event_mgr)
 {
-       if (p_info && parameters) {
-               opj_codec_private_t * l_info = (opj_codec_private_t *) p_info;
+       opj_codec_private_t * l_info = (opj_codec_private_t *) p_info;
 
-               if (! l_info->is_decompressor) {
-                       return OPJ_FALSE;
-               }
+       if ( !p_info || !parameters || !event_mgr ){
+               fprintf(stderr, "[ERROR] Input parameters of the setup_decoder function are incorrect.\n");
+               return OPJ_FALSE;
+       }
 
-               l_info->m_codec_data.m_decompression.opj_setup_decoder(l_info->m_codec,parameters);
+       if ( !event_mgr->error_handler || !event_mgr->warning_handler || !event_mgr->error_handler){
+               fprintf(stderr, "[ERROR] Event handler provided to the setup_decoder function is not valid.\n");
+               return OPJ_FALSE;
+       }
 
-               if (event_mgr == NULL)
-               {
-                       l_info->m_event_mgr->error_handler = opj_default_callback ;
-                       l_info->m_event_mgr->warning_handler = opj_default_callback ;
-                       l_info->m_event_mgr->info_handler = opj_default_callback ;
-                       l_info->m_event_mgr->client_data = stderr;
-               }
-               else
-                       l_info->m_event_mgr = event_mgr;
-               return OPJ_TRUE;
+       if (! l_info->is_decompressor) {
+               opj_event_msg_v2(event_mgr, EVT_ERROR, "Codec provided to the setup_decoder function is not a decompressor handler.\n");
+               return OPJ_FALSE;
        }
-       return OPJ_FALSE;
+
+       l_info->m_codec_data.m_decompression.opj_setup_decoder(l_info->m_codec, parameters);
+
+       l_info->m_event_mgr = event_mgr;
+
+       return OPJ_TRUE;
 }
 
 opj_image_t* OPJ_CALLCONV opj_decode(opj_dinfo_t *dinfo, opj_cio_t *cio) {
@@ -484,7 +505,7 @@ void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *paramete
                parameters->cod_format = -1;
                parameters->tcp_rates[0] = 0;   
                parameters->tcp_numlayers = 0;
-    parameters->cp_disto_alloc = 0;
+               parameters->cp_disto_alloc = 0;
                parameters->cp_fixed_alloc = 0;
                parameters->cp_fixed_quality = 0;
                parameters->jpip_on = OPJ_FALSE;
@@ -613,6 +634,29 @@ void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_t *cstr_info) {
        }
 }
 
+void OPJ_CALLCONV opj_destroy_cstr_info_v2(opj_codestream_info_v2_t *cstr_info) {
+       if (cstr_info) {
+               int tileno, compno;
+
+               if (cstr_info->tile_info){
+                       for (tileno = 0; tileno < cstr_info->tw * cstr_info->th; tileno++) {
+                               for (compno = 0; compno < cstr_info->nbcomps; compno++){
+                                       opj_free(cstr_info->tile_info[tileno].tccp_info);
+                               }
+                       }
+                       opj_free(cstr_info->tile_info);
+               }
+
+               if (cstr_info->m_default_tile_info.tccp_info){
+                       opj_free(cstr_info->m_default_tile_info.tccp_info);
+               }
+
+               opj_free(cstr_info);
+       }
+}
+
+
+
 #ifdef OLD_WAY_MS
 opj_bool OPJ_CALLCONV opj_read_header (
                                                                   opj_codec_t *p_codec,
@@ -651,45 +695,214 @@ opj_bool OPJ_CALLCONV opj_read_header (
 
 opj_bool OPJ_CALLCONV opj_read_header (        opj_stream_t *p_cio,
                                                                                opj_codec_t *p_codec,
-                                                                               opj_image_header_t **p_image_header,
-                                                                               opj_codestream_info_t **p_cstr_info     )
-
+                                                                               opj_image_header_t *p_img_header )
 {
        if (p_codec && p_cio) {
                opj_codec_private_t* l_info = (opj_codec_private_t*) p_codec;
                opj_stream_private_t* l_cio = (opj_stream_private_t*) p_cio;
 
                if(! l_info->is_decompressor) {
+                       opj_event_msg_v2(l_info->m_event_mgr, EVT_ERROR, "Codec provided to the read_header function is not a decompressor handler.\n");
                        return OPJ_FALSE;
                }
 
                return l_info->m_codec_data.m_decompression.opj_read_header(
                                        l_cio,
                                        l_info->m_codec,
-                                       p_image_header,
-                                       p_cstr_info,
+                                       p_img_header,
                                        l_info->m_event_mgr);
        }
+
+       fprintf(stderr, "[ERROR] Input parameters of the read_header function are incorrect.\n");
        return OPJ_FALSE;
 }
 
 
 void OPJ_CALLCONV opj_destroy_codec(opj_codec_t *p_info)
 {
-       if
-               (p_info)
-       {
+       if (p_info) {
                opj_codec_private_t * l_info = (opj_codec_private_t *) p_info;
-               if
-                       (l_info->is_decompressor)
-               {
+
+               if (l_info->is_decompressor) {
                        l_info->m_codec_data.m_decompression.opj_destroy(l_info->m_codec);
                }
-               else
-               {
+               else {
                        l_info->m_codec_data.m_compression.opj_destroy(l_info->m_codec);
                }
+
                l_info->m_codec = 00;
                opj_free(l_info);
        }
 }
+
+/**
+ * Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading.
+ *
+ * @param      p_codec                 the jpeg2000 codec.
+ * @param      p_start_x               the left position of the rectangle to decode (in image coordinates).
+ * @param      p_end_x                 the right position of the rectangle to decode (in image coordinates).
+ * @param      p_start_y               the up position of the rectangle to decode (in image coordinates).
+ * @param      p_end_y                 the bottom position of the rectangle to decode (in image coordinates).
+ *
+ * @return     true                    if the area could be set.
+ */
+opj_bool OPJ_CALLCONV opj_set_decode_area(     opj_codec_t *p_codec,
+                                                                                       OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
+                                                                                       OPJ_INT32 p_end_x, OPJ_INT32 p_end_y
+                                                                                       )
+{
+       if (p_codec) {
+               opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
+               if (! l_info->is_decompressor) {
+                       return OPJ_FALSE;
+               }
+
+               return  l_info->m_codec_data.m_decompression.opj_set_decode_area(
+                               l_info->m_codec,
+                               p_start_x,
+                               p_start_y,
+                               p_end_x,
+                               p_end_y,
+                               l_info->m_event_mgr);
+
+       }
+       return OPJ_FALSE;
+}
+
+/**
+ * Reads a tile header. This function is compulsory and allows one to know the size of the tile thta will be decoded.
+ * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
+ *
+ * @param      p_codec                 the jpeg2000 codec.
+ * @param      p_tile_index    pointer to a value that will hold the index of the tile being decoded, in case of success.
+ * @param      p_data_size             pointer to a value that will hold the maximum size of the decoded data, in case of success. In case
+ *                                                     of truncated codestreams, the actual number of bytes decoded may be lower. The computation of the size is the same
+ *                                                     as depicted in opj_write_tile.
+ * @param      p_tile_x0               pointer to a value that will hold the x0 pos of the tile (in the image).
+ * @param      p_tile_y0               pointer to a value that will hold the y0 pos of the tile (in the image).
+ * @param      p_tile_x1               pointer to a value that will hold the x1 pos of the tile (in the image).
+ * @param      p_tile_y1               pointer to a value that will hold the y1 pos of the tile (in the image).
+ * @param      p_nb_comps              pointer to a value that will hold the number of components in the tile.
+ * @param      p_should_go_on  pointer to a boolean that will hold the fact that the decoding should go on. In case the
+ *                                                     codestream is over at the time of the call, the value will be set to false. The user should then stop
+ *                                                     the decoding.
+ * @param      p_stream                the stream to decode.
+ * @return     true                    if the tile header could be decoded. In case the decoding should end, the returned value is still true.
+ *                                                     returning false may be the result of a shortage of memory or an internal error.
+ */
+opj_bool OPJ_CALLCONV opj_read_tile_header(
+                                       opj_codec_t *p_codec,
+                                       opj_stream_t * p_stream,
+                                       OPJ_UINT32 * p_tile_index,
+                                       OPJ_UINT32 * p_data_size,
+                                       OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0,
+                                       OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1,
+                                       OPJ_UINT32 * p_nb_comps,
+                                       opj_bool * p_should_go_on)
+{
+       if (p_codec && p_stream && p_data_size && p_tile_index) {
+               opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
+               opj_stream_private_t * l_cio = (opj_stream_private_t *) p_stream;
+
+               if (! l_info->is_decompressor) {
+                       return OPJ_FALSE;
+               }
+
+               return l_info->m_codec_data.m_decompression.opj_read_tile_header(
+                       l_info->m_codec,
+                       p_tile_index,
+                       p_data_size,
+                       p_tile_x0, p_tile_y0,
+                       p_tile_x1, p_tile_y1,
+                       p_nb_comps,
+                       p_should_go_on,
+                       l_cio,
+                       l_info->m_event_mgr);
+       }
+       return OPJ_FALSE;
+}
+
+/**
+ * Reads a tile data. This function is compulsory and allows one to decode tile data. opj_read_tile_header should be called before.
+ * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
+ *
+ * @param      p_codec                 the jpeg2000 codec.
+ * @param      p_tile_index    the index of the tile being decoded, this should be the value set by opj_read_tile_header.
+ * @param      p_data                  pointer to a memory block that will hold the decoded data.
+ * @param      p_data_size             size of p_data. p_data_size should be bigger or equal to the value set by opj_read_tile_header.
+ * @param      p_stream                the stream to decode.
+ *
+ * @return     true                    if the data could be decoded.
+ */
+opj_bool OPJ_CALLCONV opj_decode_tile_data(
+                                       opj_codec_t *p_codec,
+                                       OPJ_UINT32 p_tile_index,
+                                       OPJ_BYTE * p_data,
+                                       OPJ_UINT32 p_data_size,
+                                       opj_stream_t *p_stream
+                                       )
+{
+       if (p_codec && p_data && p_stream) {
+               opj_codec_private_t * l_info = (opj_codec_private_t *) p_codec;
+               opj_stream_private_t * l_cio = (opj_stream_private_t *) p_stream;
+
+               if (! l_info->is_decompressor) {
+                       return OPJ_FALSE;
+               }
+
+               return l_info->m_codec_data.m_decompression.opj_decode_tile_data(       l_info->m_codec,
+                                                                                                                                                       p_tile_index,
+                                                                                                                                                       p_data,
+                                                                                                                                                       p_data_size,
+                                                                                                                                                       l_cio,
+                                                                                                                                                       l_info->m_event_mgr);
+       }
+       return OPJ_FALSE;
+}
+
+/*
+ *
+ *
+ */
+void OPJ_CALLCONV opj_dump_codec(      opj_codec_t *p_codec,
+                                                                       OPJ_INT32 info_flag,
+                                                                       FILE* output_stream)
+{
+       if (p_codec) {
+               opj_codec_private_t* l_codec = (opj_codec_private_t*) p_codec;
+
+               l_codec->opj_dump_codec(l_codec->m_codec, info_flag, output_stream);
+       }
+
+       fprintf(stderr, "[ERROR] Input parameter of the dump_codec function are incorrect.\n");
+}
+
+/*
+ *
+ *
+ */
+opj_codestream_info_v2_t* OPJ_CALLCONV opj_get_cstr_info(opj_codec_t *p_codec)
+{
+       if (p_codec) {
+               opj_codec_private_t* l_codec = (opj_codec_private_t*) p_codec;
+
+               return l_codec->opj_get_codec_info(l_codec->m_codec);
+       }
+
+       return NULL;
+}
+
+/*
+ *
+ *
+ */
+opj_codestream_index_t * OPJ_CALLCONV opj_get_cstr_index(opj_codec_t *p_codec)
+{
+       if (p_codec) {
+               opj_codec_private_t* l_codec = (opj_codec_private_t*) p_codec;
+
+               return l_codec->opj_get_codec_index(l_codec->m_codec);
+       }
+
+       return NULL;
+}