[trunk] Prevent a leak when reading PPT markers
[openjpeg.git] / src / lib / openjp2 / opj_codec.h
1 /*
2  * Copyright (c) 2002-2007, Communications and Remote Sensing Laboratory, Universite catholique de Louvain (UCL), Belgium
3  * Copyright (c) 2002-2007, Professor Benoit Macq
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
16  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
19  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
20  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
21  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
22  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
23  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
24  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25  * POSSIBILITY OF SUCH DAMAGE.
26  */
27 #ifndef __OPJ_CODEC_H
28 #define __OPJ_CODEC_H
29 /**
30 @file opj_codec.h
31 */
32
33
34 /**
35  * Main codec handler used for compression or decompression.
36  */
37 typedef struct opj_codec_private
38 {
39     /** FIXME DOC */
40     union
41     {
42         /**
43          * Decompression handler.
44          */
45         struct opj_decompression
46         {
47             /** Main header reading function handler */
48             OPJ_BOOL (*opj_read_header) ( struct opj_stream_private * cio,
49                                           void * p_codec,
50                                           opj_image_t **p_image,
51                                           struct opj_event_mgr * p_manager);
52
53             /** Decoding function */
54             OPJ_BOOL (*opj_decode) ( void * p_codec,
55                                      struct opj_stream_private * p_cio,
56                                      opj_image_t * p_image,
57                                      struct opj_event_mgr * p_manager);
58
59             /** FIXME DOC */
60             OPJ_BOOL (*opj_read_tile_header)( void * p_codec,
61                                               OPJ_UINT32 * p_tile_index,
62                                               OPJ_UINT32 * p_data_size,
63                                               OPJ_INT32 * p_tile_x0,
64                                               OPJ_INT32 * p_tile_y0,
65                                               OPJ_INT32 * p_tile_x1,
66                                               OPJ_INT32 * p_tile_y1,
67                                               OPJ_UINT32 * p_nb_comps,
68                                               OPJ_BOOL * p_should_go_on,
69                                               struct opj_stream_private * p_cio,
70                                               struct opj_event_mgr * p_manager);
71
72             /** FIXME DOC */
73             OPJ_BOOL (*opj_decode_tile_data)( void * p_codec,
74                                               OPJ_UINT32 p_tile_index,
75                                               OPJ_BYTE * p_data,
76                                               OPJ_UINT32 p_data_size,
77                                               struct opj_stream_private * p_cio,
78                                               struct opj_event_mgr * p_manager);
79
80             /** Reading function used after codestream if necessary */
81             OPJ_BOOL (* opj_end_decompress) ( void *p_codec,
82                                               struct opj_stream_private * cio,
83                                               struct opj_event_mgr * p_manager);
84
85             /** Codec destroy function handler */
86             void (*opj_destroy) (void * p_codec);
87
88             /** Setup decoder function handler */
89             void (*opj_setup_decoder) ( void * p_codec, opj_dparameters_t * p_param);
90
91             /** Set decode area function handler */
92             OPJ_BOOL (*opj_set_decode_area) ( void * p_codec,
93                                               opj_image_t * p_image,
94                                               OPJ_INT32 p_start_x,
95                                               OPJ_INT32 p_end_x,
96                                               OPJ_INT32 p_start_y,
97                                               OPJ_INT32 p_end_y,
98                                               struct opj_event_mgr * p_manager);
99
100             /** Get tile function */
101             OPJ_BOOL (*opj_get_decoded_tile) ( void *p_codec,
102                                                opj_stream_private_t * p_cio,
103                                                opj_image_t *p_image,
104                                                struct opj_event_mgr * p_manager,
105                                                OPJ_UINT32 tile_index);
106
107             /** Set the decoded resolution factor */
108             OPJ_BOOL (*opj_set_decoded_resolution_factor) ( void * p_codec,
109                                                             OPJ_UINT32 res_factor,
110                                                             opj_event_mgr_t * p_manager);
111         } m_decompression;
112
113         /**
114          * Compression handler. FIXME DOC
115          */
116         struct opj_compression
117         {
118             OPJ_BOOL (* opj_start_compress) ( void *p_codec,
119                                               struct opj_stream_private * cio,
120                                               struct opj_image * p_image,
121                                               struct opj_event_mgr * p_manager);
122
123             OPJ_BOOL (* opj_encode) ( void * p_codec,
124                                       struct opj_stream_private *p_cio,
125                                       struct opj_event_mgr * p_manager);
126
127             OPJ_BOOL (* opj_write_tile) ( void * p_codec,
128                                           OPJ_UINT32 p_tile_index,
129                                           OPJ_BYTE * p_data,
130                                           OPJ_UINT32 p_data_size,
131                                           struct opj_stream_private * p_cio,
132                                           struct opj_event_mgr * p_manager);
133
134             OPJ_BOOL (* opj_end_compress) (     void * p_codec,
135                                             struct opj_stream_private * p_cio,
136                                             struct opj_event_mgr * p_manager);
137
138             void (* opj_destroy) (void * p_codec);
139
140             void (* opj_setup_encoder) ( void * p_codec,
141                                          opj_cparameters_t * p_param,
142                                          struct opj_image * p_image,
143                                          struct opj_event_mgr * p_manager);
144         } m_compression;
145     } m_codec_data;
146     /** FIXME DOC*/
147     void * m_codec;
148     /** Event handler */
149     opj_event_mgr_t m_event_mgr;
150     /** Flag to indicate if the codec is used to decode or encode*/
151     OPJ_BOOL is_decompressor;
152     void (*opj_dump_codec) (void * p_codec, OPJ_INT32 info_flag, FILE* output_stream);
153     opj_codestream_info_v2_t* (*opj_get_codec_info)(void* p_codec);
154     opj_codestream_index_t* (*opj_get_codec_index)(void* p_codec);
155 }
156 opj_codec_private_t;
157
158
159 #endif /* __OPJ_CODEC_H */
160