[trunk]Replaced deprecated opj_stream_set_user_data function from API
[openjpeg.git] / src / lib / openjp2 / openjpeg.h
1  /*
2  * The copyright in this software is being made available under the 2-clauses 
3  * BSD License, included below. This software may be subject to other third 
4  * party and contributor rights, including patent rights, and no such rights
5  * are granted under this license.
6  *
7  * Copyright (c) 2002-2014, Universite catholique de Louvain (UCL), Belgium
8  * Copyright (c) 2002-2014, Professor Benoit Macq
9  * Copyright (c) 2001-2003, David Janssens
10  * Copyright (c) 2002-2003, Yannick Verschueren
11  * Copyright (c) 2003-2007, Francois-Olivier Devaux 
12  * Copyright (c) 2003-2014, Antonin Descampe
13  * Copyright (c) 2005, Herve Drolon, FreeImage Team
14  * Copyright (c) 2006-2007, Parvatha Elangovan
15  * Copyright (c) 2008, Jerome Fimes, Communications & Systemes <jerome.fimes@c-s.fr>
16  * Copyright (c) 2010-2011, Kaori Hagihara
17  * Copyright (c) 2011-2012, Centre National d'Etudes Spatiales (CNES), France 
18  * Copyright (c) 2012, CS Systemes d'Information, France
19  * All rights reserved.
20  *
21  * Redistribution and use in source and binary forms, with or without
22  * modification, are permitted provided that the following conditions
23  * are met:
24  * 1. Redistributions of source code must retain the above copyright
25  *    notice, this list of conditions and the following disclaimer.
26  * 2. Redistributions in binary form must reproduce the above copyright
27  *    notice, this list of conditions and the following disclaimer in the
28  *    documentation and/or other materials provided with the distribution.
29  *
30  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS `AS IS'
31  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33  * ARE DISCLAIMED.  IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
34  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
35  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
36  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
37  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
38  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
39  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
40  * POSSIBILITY OF SUCH DAMAGE.
41  */
42 #ifndef OPENJPEG_H
43 #define OPENJPEG_H
44
45
46 /* 
47 ==========================================================
48    Compiler directives
49 ==========================================================
50 */
51
52 /*
53 The inline keyword is supported by C99 but not by C90. 
54 Most compilers implement their own version of this keyword ... 
55 */
56 #ifndef INLINE
57         #if defined(_MSC_VER)
58                 #define INLINE __forceinline
59         #elif defined(__GNUC__)
60                 #define INLINE __inline__
61         #elif defined(__MWERKS__)
62                 #define INLINE inline
63         #else 
64                 /* add other compilers here ... */
65                 #define INLINE 
66         #endif /* defined(<Compiler>) */
67 #endif /* INLINE */
68
69 /* deprecated attribute */
70 #ifdef __GNUC__
71         #define OPJ_DEPRECATED(func) func __attribute__ ((deprecated))
72 #elif defined(_MSC_VER)
73         #define OPJ_DEPRECATED(func) __declspec(deprecated) func
74 #else
75         #pragma message("WARNING: You need to implement DEPRECATED for this compiler")
76         #define OPJ_DEPRECATED(func) func
77 #endif
78
79 #if defined(OPJ_STATIC) || !defined(_WIN32)
80 /* http://gcc.gnu.org/wiki/Visibility */
81 #if __GNUC__ >= 4
82 #define OPJ_API    __attribute__ ((visibility ("default")))
83 #define OPJ_LOCAL  __attribute__ ((visibility ("hidden")))
84 #else
85 #define OPJ_API
86 #define OPJ_LOCAL
87 #endif
88 #define OPJ_CALLCONV
89 #else
90 #define OPJ_CALLCONV __stdcall
91 /*
92 The following ifdef block is the standard way of creating macros which make exporting 
93 from a DLL simpler. All files within this DLL are compiled with the OPJ_EXPORTS
94 symbol defined on the command line. this symbol should not be defined on any project
95 that uses this DLL. This way any other project whose source files include this file see 
96 OPJ_API functions as being imported from a DLL, wheras this DLL sees symbols
97 defined with this macro as being exported.
98 */
99 #if defined(OPJ_EXPORTS) || defined(DLL_EXPORT)
100 #define OPJ_API __declspec(dllexport)
101 #else
102 #define OPJ_API __declspec(dllimport)
103 #endif /* OPJ_EXPORTS */
104 #endif /* !OPJ_STATIC || !_WIN32 */
105
106 typedef int OPJ_BOOL;
107 #define OPJ_TRUE 1
108 #define OPJ_FALSE 0
109
110 typedef char          OPJ_CHAR;
111 typedef float         OPJ_FLOAT32;
112 typedef double        OPJ_FLOAT64;
113 typedef unsigned char OPJ_BYTE;
114
115 #include "opj_stdint.h"
116
117 typedef int8_t   OPJ_INT8;
118 typedef uint8_t  OPJ_UINT8;
119 typedef int16_t  OPJ_INT16;
120 typedef uint16_t OPJ_UINT16;
121 typedef int32_t  OPJ_INT32;
122 typedef uint32_t OPJ_UINT32;
123 typedef int64_t  OPJ_INT64;
124 typedef uint64_t OPJ_UINT64;
125
126 typedef int64_t  OPJ_OFF_T; /* 64-bit file offset type */
127
128 #include <stdio.h>
129 typedef size_t   OPJ_SIZE_T;
130
131 /* Avoid compile-time warning because parameter is not used */
132 #define OPJ_ARG_NOT_USED(x) (void)(x)
133
134 /* 
135 ==========================================================
136    Useful constant definitions
137 ==========================================================
138 */
139
140 #define OPJ_PATH_LEN 4096 /**< Maximum allowed size for filenames */
141
142 #define OPJ_J2K_MAXRLVLS 33                                     /**< Number of maximum resolution level authorized */
143 #define OPJ_J2K_MAXBANDS (3*OPJ_J2K_MAXRLVLS-2) /**< Number of maximum sub-band linked to number of resolution level */
144
145 #define OPJ_J2K_DEFAULT_NB_SEGS                         10
146 #define OPJ_J2K_STREAM_CHUNK_SIZE                       0x100000 /** 1 mega by default */
147 #define OPJ_J2K_DEFAULT_HEADER_SIZE                     1000
148 #define OPJ_J2K_MCC_DEFAULT_NB_RECORDS          10
149 #define OPJ_J2K_MCT_DEFAULT_NB_RECORDS          10
150
151 /* UniPG>> */ /* NOT YET USED IN THE V2 VERSION OF OPENJPEG */
152 #define JPWL_MAX_NO_TILESPECS   16 /**< Maximum number of tile parts expected by JPWL: increase at your will */
153 #define JPWL_MAX_NO_PACKSPECS   16 /**< Maximum number of packet parts expected by JPWL: increase at your will */
154 #define JPWL_MAX_NO_MARKERS     512 /**< Maximum number of JPWL markers: increase at your will */
155 #define JPWL_PRIVATEINDEX_NAME "jpwl_index_privatefilename" /**< index file name used when JPWL is on */
156 #define JPWL_EXPECTED_COMPONENTS 3 /**< Expect this number of components, so you'll find better the first EPB */
157 #define JPWL_MAXIMUM_TILES 8192 /**< Expect this maximum number of tiles, to avoid some crashes */
158 #define JPWL_MAXIMUM_HAMMING 2 /**< Expect this maximum number of bit errors in marker id's */
159 #define JPWL_MAXIMUM_EPB_ROOM 65450 /**< Expect this maximum number of bytes for composition of EPBs */
160 /* <<UniPG */
161
162 /**
163  * EXPERIMENTAL FOR THE MOMENT
164  * Supported options about file information used only in j2k_dump
165 */
166 #define OPJ_IMG_INFO            1       /**< Basic image information provided to the user */
167 #define OPJ_J2K_MH_INFO         2       /**< Codestream information based only on the main header */
168 #define OPJ_J2K_TH_INFO         4       /**< Tile information based on the current tile header */
169 #define OPJ_J2K_TCH_INFO        8       /**< Tile/Component information of all tiles */
170 #define OPJ_J2K_MH_IND          16      /**< Codestream index based only on the main header */
171 #define OPJ_J2K_TH_IND          32      /**< Tile index based on the current tile */
172 /*FIXME #define OPJ_J2K_CSTR_IND        48*/    /**<  */
173 #define OPJ_JP2_INFO            128     /**< JP2 file information */
174 #define OPJ_JP2_IND                     256     /**< JP2 file index */
175
176 /**
177  * JPEG 2000 Profiles, see Table A.10 from 15444-1 (updated in various AMD)
178  * These values help chosing the RSIZ value for the J2K codestream.
179  * The RSIZ value triggers various encoding options, as detailed in Table A.10.
180  * If OPJ_PROFILE_PART2 is chosen, it has to be combined with one or more extensions
181  * described hereunder.
182  *   Example: rsiz = OPJ_PROFILE_PART2 | OPJ_EXTENSION_MCT;
183  * For broadcast profiles, the OPJ_PROFILE value has to be combined with the targeted
184  * mainlevel (3-0 LSB, value between 0 and 11):
185  *   Example: rsiz = OPJ_PROFILE_BC_MULTI | 0x0005; (here mainlevel 5)
186  * For IMF profiles, the OPJ_PROFILE value has to be combined with the targeted mainlevel
187  * (3-0 LSB, value between 0 and 11) and sublevel (7-4 LSB, value between 0 and 9):
188  *   Example: rsiz = OPJ_PROFILE_IMF_2K | 0x0040 | 0x0005; (here main 5 and sublevel 4)
189  * */
190 #define OPJ_PROFILE_NONE        0x0000 /** no profile, conform to 15444-1 */
191 #define OPJ_PROFILE_0           0x0001 /** Profile 0 as described in 15444-1,Table A.45 */
192 #define OPJ_PROFILE_1           0x0002 /** Profile 1 as described in 15444-1,Table A.45 */
193 #define OPJ_PROFILE_PART2       0x8000 /** At least 1 extension defined in 15444-2 (Part-2) */
194 #define OPJ_PROFILE_CINEMA_2K   0x0003 /** 2K cinema profile defined in 15444-1 AMD1 */
195 #define OPJ_PROFILE_CINEMA_4K   0x0004 /** 4K cinema profile defined in 15444-1 AMD1 */
196 #define OPJ_PROFILE_CINEMA_S2K  0x0005 /** Scalable 2K cinema profile defined in 15444-1 AMD2 */
197 #define OPJ_PROFILE_CINEMA_S4K  0x0006 /** Scalable 4K cinema profile defined in 15444-1 AMD2 */
198 #define OPJ_PROFILE_CINEMA_LTS  0x0007 /** Long term storage cinema profile defined in 15444-1 AMD2 */
199 #define OPJ_PROFILE_BC_SINGLE   0x0100 /** Single Tile Broadcast profile defined in 15444-1 AMD3 */
200 #define OPJ_PROFILE_BC_MULTI    0x0200 /** Multi Tile Broadcast profile defined in 15444-1 AMD3 */
201 #define OPJ_PROFILE_BC_MULTI_R  0x0300 /** Multi Tile Reversible Broadcast profile defined in 15444-1 AMD3 */
202 #define OPJ_PROFILE_IMF_2K      0x0400 /** 2K Single Tile Lossy IMF profile defined in 15444-1 AMD 8 */
203 #define OPJ_PROFILE_IMF_4K      0x0401 /** 4K Single Tile Lossy IMF profile defined in 15444-1 AMD 8 */
204 #define OPJ_PROFILE_IMF_8K      0x0402 /** 8K Single Tile Lossy IMF profile defined in 15444-1 AMD 8 */
205 #define OPJ_PROFILE_IMF_2K_R    0x0403 /** 2K Single/Multi Tile Reversible IMF profile defined in 15444-1 AMD 8 */
206 #define OPJ_PROFILE_IMF_4K_R    0x0800 /** 4K Single/Multi Tile Reversible IMF profile defined in 15444-1 AMD 8 */
207 #define OPJ_PROFILE_IMF_8K_R    0x0801  /** 8K Single/Multi Tile Reversible IMF profile defined in 15444-1 AMD 8 */
208
209 /**
210  * JPEG 2000 Part-2 extensions
211  * */
212 #define OPJ_EXTENSION_NONE      0x0000 /** No Part-2 extension */
213 #define OPJ_EXTENSION_MCT       0x0100  /** Custom MCT support */
214
215 /**
216  * JPEG 2000 profile macros
217  * */
218 #define OPJ_IS_CINEMA(v)     (((v) >= OPJ_PROFILE_CINEMA_2K)&&((v) <= OPJ_PROFILE_CINEMA_S4K))
219 #define OPJ_IS_STORAGE(v)    ((v) == OPJ_PROFILE_CINEMA_LTS)
220 #define OPJ_IS_BROADCAST(v)  (((v) >= OPJ_PROFILE_BC_SINGLE)&&((v) <= ((OPJ_PROFILE_BC_MULTI_R) | (0x000b))))
221 #define OPJ_IS_IMF(v)        (((v) >= OPJ_PROFILE_IMF_2K)&&((v) <= ((OPJ_PROFILE_IMF_8K_R) | (0x009b))))
222 #define OPJ_IS_PART2(v)      ((v) & OPJ_PROFILE_PART2)
223
224 /**
225  * JPEG 2000 codestream and component size limits in cinema profiles
226  * */
227 #define OPJ_CINEMA_24_CS     1302083    /** Maximum codestream length for 24fps */
228 #define OPJ_CINEMA_48_CS     651041     /** Maximum codestream length for 48fps */
229 #define OPJ_CINEMA_24_COMP   1041666    /** Maximum size per color component for 2K & 4K @ 24fps */
230 #define OPJ_CINEMA_48_COMP   520833             /** Maximum size per color component for 2K @ 48fps */
231
232 /* 
233 ==========================================================
234    enum definitions
235 ==========================================================
236 */
237
238 /**
239  * DEPRECATED: use RSIZ, OPJ_PROFILE_* and OPJ_EXTENSION_* instead
240  * Rsiz Capabilities
241  * */
242 typedef enum RSIZ_CAPABILITIES {
243     OPJ_STD_RSIZ = 0,           /** Standard JPEG2000 profile*/
244     OPJ_CINEMA2K = 3,           /** Profile name for a 2K image*/
245     OPJ_CINEMA4K = 4,           /** Profile name for a 4K image*/
246     OPJ_MCT = 0x8100
247 } OPJ_RSIZ_CAPABILITIES;
248
249 /**
250  * DEPRECATED: use RSIZ, OPJ_PROFILE_* and OPJ_EXTENSION_* instead
251  * Digital cinema operation mode
252  * */
253 typedef enum CINEMA_MODE {
254     OPJ_OFF = 0,                        /** Not Digital Cinema*/
255     OPJ_CINEMA2K_24 = 1,        /** 2K Digital Cinema at 24 fps*/
256     OPJ_CINEMA2K_48 = 2,        /** 2K Digital Cinema at 48 fps*/
257     OPJ_CINEMA4K_24 = 3         /** 4K Digital Cinema at 24 fps*/
258 }OPJ_CINEMA_MODE;
259
260 /** 
261  * Progression order
262  * */
263 typedef enum PROG_ORDER {
264         OPJ_PROG_UNKNOWN = -1,  /**< place-holder */
265         OPJ_LRCP = 0,                   /**< layer-resolution-component-precinct order */
266         OPJ_RLCP = 1,                   /**< resolution-layer-component-precinct order */
267         OPJ_RPCL = 2,                   /**< resolution-precinct-component-layer order */
268         OPJ_PCRL = 3,                   /**< precinct-component-resolution-layer order */
269         OPJ_CPRL = 4                    /**< component-precinct-resolution-layer order */
270 } OPJ_PROG_ORDER;
271
272 /**
273  * Supported image color spaces
274 */
275 typedef enum COLOR_SPACE {
276     OPJ_CLRSPC_UNKNOWN = -1,    /**< not supported by the library */
277     OPJ_CLRSPC_UNSPECIFIED = 0, /**< not specified in the codestream */
278     OPJ_CLRSPC_SRGB = 1,                /**< sRGB */
279     OPJ_CLRSPC_GRAY = 2,                /**< grayscale */
280     OPJ_CLRSPC_SYCC = 3,                /**< YUV */
281     OPJ_CLRSPC_EYCC = 4,        /**< e-YCC */
282     OPJ_CLRSPC_CMYK = 5         /**< CMYK */
283 } OPJ_COLOR_SPACE;
284
285 /**
286  * Supported codec
287 */
288 typedef enum CODEC_FORMAT {
289         OPJ_CODEC_UNKNOWN = -1, /**< place-holder */
290         OPJ_CODEC_J2K  = 0,             /**< JPEG-2000 codestream : read/write */
291         OPJ_CODEC_JPT  = 1,             /**< JPT-stream (JPEG 2000, JPIP) : read only */
292     OPJ_CODEC_JP2  = 2,         /**< JP2 file format : read/write */
293     OPJ_CODEC_JPP  = 3,         /**< JPP-stream (JPEG 2000, JPIP) : to be coded */
294     OPJ_CODEC_JPX  = 4          /**< JPX file format (JPEG 2000 Part-2) : to be coded */
295 } OPJ_CODEC_FORMAT;
296
297
298 /* 
299 ==========================================================
300    event manager typedef definitions
301 ==========================================================
302 */
303
304 /**
305  * Callback function prototype for events
306  * @param msg               Event message
307  * @param client_data       Client object where will be return the event message 
308  * */
309 typedef void (*opj_msg_callback) (const char *msg, void *client_data);
310
311 /* 
312 ==========================================================
313    codec typedef definitions
314 ==========================================================
315 */
316
317 /**
318  * Progression order changes
319  * 
320  */
321 typedef struct opj_poc {
322         /** Resolution num start, Component num start, given by POC */
323         OPJ_UINT32 resno0, compno0;
324         /** Layer num end,Resolution num end, Component num end, given by POC */
325         OPJ_UINT32 layno1, resno1, compno1;
326         /** Layer num start,Precinct num start, Precinct num end */
327         OPJ_UINT32 layno0, precno0, precno1;
328         /** Progression order enum*/
329         OPJ_PROG_ORDER prg1,prg;
330         /** Progression order string*/
331         OPJ_CHAR progorder[5];
332         /** Tile number */
333         OPJ_UINT32 tile;
334         /** Start and end values for Tile width and height*/
335         OPJ_INT32 tx0,tx1,ty0,ty1;
336         /** Start value, initialised in pi_initialise_encode*/
337         OPJ_UINT32 layS, resS, compS, prcS;
338         /** End value, initialised in pi_initialise_encode */
339         OPJ_UINT32 layE, resE, compE, prcE;
340         /** Start and end values of Tile width and height, initialised in pi_initialise_encode*/
341         OPJ_UINT32 txS,txE,tyS,tyE,dx,dy;
342         /** Temporary values for Tile parts, initialised in pi_create_encode */
343         OPJ_UINT32 lay_t, res_t, comp_t, prc_t,tx0_t,ty0_t;
344 } opj_poc_t;
345
346 /**
347  * Compression parameters
348  * */
349 typedef struct opj_cparameters {
350         /** size of tile: tile_size_on = false (not in argument) or = true (in argument) */
351         OPJ_BOOL tile_size_on;
352         /** XTOsiz */
353         int cp_tx0;
354         /** YTOsiz */
355         int cp_ty0;
356         /** XTsiz */
357         int cp_tdx;
358         /** YTsiz */
359         int cp_tdy;
360         /** allocation by rate/distortion */
361         int cp_disto_alloc;
362         /** allocation by fixed layer */
363         int cp_fixed_alloc;
364         /** add fixed_quality */
365         int cp_fixed_quality;
366         /** fixed layer */
367         int *cp_matrice;
368         /** comment for coding */
369         char *cp_comment;
370         /** csty : coding style */
371         int csty;
372         /** progression order (default OPJ_LRCP) */
373         OPJ_PROG_ORDER prog_order;
374         /** progression order changes */
375         opj_poc_t POC[32];
376         /** number of progression order changes (POC), default to 0 */
377         OPJ_UINT32 numpocs;
378         /** number of layers */
379         int tcp_numlayers;
380     /** rates of layers - might be subsequently limited by the max_cs_size field */
381         float tcp_rates[100];
382         /** different psnr for successive layers */
383         float tcp_distoratio[100];
384         /** number of resolutions */
385         int numresolution;
386         /** initial code block width, default to 64 */
387         int cblockw_init;
388         /** initial code block height, default to 64 */
389         int cblockh_init;
390         /** mode switch (cblk_style) */
391         int mode;
392         /** 1 : use the irreversible DWT 9-7, 0 : use lossless compression (default) */
393         int irreversible;
394         /** region of interest: affected component in [0..3], -1 means no ROI */
395         int roi_compno;
396         /** region of interest: upshift value */
397         int roi_shift;
398         /* number of precinct size specifications */
399         int res_spec;
400         /** initial precinct width */
401         int prcw_init[OPJ_J2K_MAXRLVLS];
402         /** initial precinct height */
403         int prch_init[OPJ_J2K_MAXRLVLS];
404
405         /**@name command line encoder parameters (not used inside the library) */
406         /*@{*/
407         /** input file name */
408         char infile[OPJ_PATH_LEN];
409         /** output file name */
410         char outfile[OPJ_PATH_LEN];
411         /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */
412         int index_on;
413         /** DEPRECATED. Index generation is now handeld with the opj_encode_with_info() function. Set to NULL */
414         char index[OPJ_PATH_LEN];
415         /** subimage encoding: origin image offset in x direction */
416         int image_offset_x0;
417         /** subimage encoding: origin image offset in y direction */
418         int image_offset_y0;
419         /** subsampling value for dx */
420         int subsampling_dx;
421         /** subsampling value for dy */
422         int subsampling_dy;
423         /** input file format 0: PGX, 1: PxM, 2: BMP 3:TIF*/
424         int decod_format;
425         /** output file format 0: J2K, 1: JP2, 2: JPT */
426         int cod_format;
427         /*@}*/
428
429 /* UniPG>> */ /* NOT YET USED IN THE V2 VERSION OF OPENJPEG */
430         /**@name JPWL encoding parameters */
431         /*@{*/
432         /** enables writing of EPC in MH, thus activating JPWL */
433         OPJ_BOOL jpwl_epc_on;
434         /** error protection method for MH (0,1,16,32,37-128) */
435         int jpwl_hprot_MH;
436         /** tile number of header protection specification (>=0) */
437         int jpwl_hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS];
438         /** error protection methods for TPHs (0,1,16,32,37-128) */
439         int jpwl_hprot_TPH[JPWL_MAX_NO_TILESPECS];
440         /** tile number of packet protection specification (>=0) */
441         int jpwl_pprot_tileno[JPWL_MAX_NO_PACKSPECS];
442         /** packet number of packet protection specification (>=0) */
443         int jpwl_pprot_packno[JPWL_MAX_NO_PACKSPECS];
444         /** error protection methods for packets (0,1,16,32,37-128) */
445         int jpwl_pprot[JPWL_MAX_NO_PACKSPECS];
446         /** enables writing of ESD, (0=no/1/2 bytes) */
447         int jpwl_sens_size;
448         /** sensitivity addressing size (0=auto/2/4 bytes) */
449         int jpwl_sens_addr;
450         /** sensitivity range (0-3) */
451         int jpwl_sens_range;
452         /** sensitivity method for MH (-1=no,0-7) */
453         int jpwl_sens_MH;
454         /** tile number of sensitivity specification (>=0) */
455         int jpwl_sens_TPH_tileno[JPWL_MAX_NO_TILESPECS];
456         /** sensitivity methods for TPHs (-1=no,0-7) */
457         int jpwl_sens_TPH[JPWL_MAX_NO_TILESPECS];
458         /*@}*/
459 /* <<UniPG */
460
461     /**
462      * DEPRECATED: use RSIZ, OPJ_PROFILE_* and MAX_COMP_SIZE instead
463      * Digital Cinema compliance 0-not compliant, 1-compliant
464      * */
465     OPJ_CINEMA_MODE cp_cinema;
466     /**
467      * Maximum size (in bytes) for each component.
468      * If == 0, component size limitation is not considered
469      * */
470         int max_comp_size;
471     /**
472      * DEPRECATED: use RSIZ, OPJ_PROFILE_* and OPJ_EXTENSION_* instead
473      * Profile name
474      * */
475     OPJ_RSIZ_CAPABILITIES cp_rsiz;
476         /** Tile part generation*/
477         char tp_on;
478         /** Flag for Tile part generation*/
479         char tp_flag;
480         /** MCT (multiple component transform) */
481         char tcp_mct;
482         /** Enable JPIP indexing*/
483         OPJ_BOOL jpip_on;
484         /** Naive implementation of MCT restricted to a single reversible array based 
485         encoding without offset concerning all the components. */
486         void * mct_data;
487     /**
488      * Maximum size (in bytes) for the whole codestream.
489      * If == 0, codestream size limitation is not considered
490      * If it does not comply with tcp_rates, max_cs_size prevails
491      * and a warning is issued.
492      * */
493     int max_cs_size;
494     /** RSIZ value
495         To be used to combine OPJ_PROFILE_*, OPJ_EXTENSION_* and (sub)levels values. */
496     OPJ_UINT16 rsiz;
497 } opj_cparameters_t;  
498
499 #define OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG      0x0001
500
501 /**
502  * Decompression parameters
503  * */
504 typedef struct opj_dparameters {
505         /** 
506         Set the number of highest resolution levels to be discarded. 
507         The image resolution is effectively divided by 2 to the power of the number of discarded levels. 
508         The reduce factor is limited by the smallest total number of decomposition levels among tiles.
509         if != 0, then original dimension divided by 2^(reduce); 
510         if == 0 or not used, image is decoded to the full resolution 
511         */
512         OPJ_UINT32 cp_reduce;
513         /** 
514         Set the maximum number of quality layers to decode. 
515         If there are less quality layers than the specified number, all the quality layers are decoded.
516         if != 0, then only the first "layer" layers are decoded; 
517         if == 0 or not used, all the quality layers are decoded 
518         */
519         OPJ_UINT32 cp_layer;
520
521         /**@name command line decoder parameters (not used inside the library) */
522         /*@{*/
523         /** input file name */
524         char infile[OPJ_PATH_LEN];
525         /** output file name */
526         char outfile[OPJ_PATH_LEN];
527         /** input file format 0: J2K, 1: JP2, 2: JPT */
528         int decod_format;
529         /** output file format 0: PGX, 1: PxM, 2: BMP */
530         int cod_format;
531
532         /** Decoding area left boundary */
533         OPJ_UINT32 DA_x0;
534         /** Decoding area right boundary */
535         OPJ_UINT32 DA_x1;
536         /** Decoding area up boundary */
537         OPJ_UINT32 DA_y0;
538         /** Decoding area bottom boundary */
539         OPJ_UINT32 DA_y1;
540         /** Verbose mode */
541         OPJ_BOOL m_verbose;
542
543         /** tile number ot the decoded tile*/
544         OPJ_UINT32 tile_index;
545         /** Nb of tile to decode */
546         OPJ_UINT32 nb_tile_to_decode;
547
548         /*@}*/
549
550 /* UniPG>> */ /* NOT YET USED IN THE V2 VERSION OF OPENJPEG */
551         /**@name JPWL decoding parameters */
552         /*@{*/
553         /** activates the JPWL correction capabilities */
554         OPJ_BOOL jpwl_correct;
555         /** expected number of components */
556         int jpwl_exp_comps;
557         /** maximum number of tiles */
558         int jpwl_max_tiles;
559         /*@}*/
560 /* <<UniPG */
561
562         unsigned int flags;
563
564 } opj_dparameters_t;
565
566
567 /**
568  * JPEG2000 codec V2.
569  * */
570 typedef void * opj_codec_t;
571
572 /* 
573 ==========================================================
574    I/O stream typedef definitions
575 ==========================================================
576 */
577
578 /**
579  * Stream open flags.
580  * */
581 /** The stream was opened for reading. */
582 #define OPJ_STREAM_READ OPJ_TRUE
583 /** The stream was opened for writing. */
584 #define OPJ_STREAM_WRITE OPJ_FALSE
585
586 /*
587  * Callback function prototype for read function
588  */
589 typedef OPJ_SIZE_T (* opj_stream_read_fn) (void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data) ;
590
591 /*
592  * Callback function prototype for write function
593  */
594 typedef OPJ_SIZE_T (* opj_stream_write_fn) (void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data) ;
595
596 /*
597  * Callback function prototype for skip function
598  */
599 typedef OPJ_OFF_T (* opj_stream_skip_fn) (OPJ_OFF_T p_nb_bytes, void * p_user_data) ;
600
601 /*
602  * Callback function prototype for seek function
603  */
604 typedef OPJ_BOOL (* opj_stream_seek_fn) (OPJ_OFF_T p_nb_bytes, void * p_user_data) ;
605
606 /*
607  * Callback function prototype for free user data function
608  */
609 typedef void (* opj_stream_free_user_data_fn) (void * p_user_data) ;
610
611 /*
612  * JPEG2000 Stream.
613  */
614 typedef void * opj_stream_t;
615
616 /* 
617 ==========================================================
618    image typedef definitions
619 ==========================================================
620 */
621
622 /**
623  * Defines a single image component
624  * */
625 typedef struct opj_image_comp {
626         /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
627         OPJ_UINT32 dx;
628         /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
629         OPJ_UINT32 dy;
630         /** data width */
631         OPJ_UINT32 w;
632         /** data height */
633         OPJ_UINT32 h;
634         /** x component offset compared to the whole image */
635         OPJ_UINT32 x0;
636         /** y component offset compared to the whole image */
637         OPJ_UINT32 y0;
638         /** precision */
639         OPJ_UINT32 prec;
640         /** image depth in bits */
641         OPJ_UINT32 bpp;
642         /** signed (1) / unsigned (0) */
643         OPJ_UINT32 sgnd;
644         /** number of decoded resolution */
645         OPJ_UINT32 resno_decoded;
646         /** number of division by 2 of the out image compared to the original size of image */
647         OPJ_UINT32 factor;
648         /** image component data */
649         OPJ_INT32 *data;
650   /** alpha channel */
651   OPJ_UINT16 alpha;
652 } opj_image_comp_t;
653
654 /** 
655  * Defines image data and characteristics
656  * */
657 typedef struct opj_image {
658         /** XOsiz: horizontal offset from the origin of the reference grid to the left side of the image area */
659         OPJ_UINT32 x0;
660         /** YOsiz: vertical offset from the origin of the reference grid to the top side of the image area */
661         OPJ_UINT32 y0;
662         /** Xsiz: width of the reference grid */
663         OPJ_UINT32 x1;
664         /** Ysiz: height of the reference grid */
665         OPJ_UINT32 y1;
666         /** number of components in the image */
667         OPJ_UINT32 numcomps;
668         /** color space: sRGB, Greyscale or YUV */
669         OPJ_COLOR_SPACE color_space;
670         /** image components */
671         opj_image_comp_t *comps;
672         /** 'restricted' ICC profile */
673         OPJ_BYTE *icc_profile_buf;
674         /** size of ICC profile */
675         OPJ_UINT32 icc_profile_len;
676 } opj_image_t;
677
678
679 /**
680  * Component parameters structure used by the opj_image_create function
681  * */
682 typedef struct opj_image_comptparm {
683         /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
684         OPJ_UINT32 dx;
685         /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
686         OPJ_UINT32 dy;
687         /** data width */
688         OPJ_UINT32 w;
689         /** data height */
690         OPJ_UINT32 h;
691         /** x component offset compared to the whole image */
692         OPJ_UINT32 x0;
693         /** y component offset compared to the whole image */
694         OPJ_UINT32 y0;
695         /** precision */
696         OPJ_UINT32 prec;
697         /** image depth in bits */
698         OPJ_UINT32 bpp;
699         /** signed (1) / unsigned (0) */
700         OPJ_UINT32 sgnd;
701 } opj_image_cmptparm_t;
702
703
704 /* 
705 ==========================================================
706    Information on the JPEG 2000 codestream
707 ==========================================================
708 */
709 /* QUITE EXPERIMENTAL FOR THE MOMENT */
710
711 /**
712  * Index structure : Information concerning a packet inside tile
713  * */
714 typedef struct opj_packet_info {
715         /** packet start position (including SOP marker if it exists) */
716         OPJ_OFF_T start_pos;
717         /** end of packet header position (including EPH marker if it exists)*/
718         OPJ_OFF_T end_ph_pos;
719         /** packet end position */
720         OPJ_OFF_T end_pos;
721         /** packet distorsion */
722         double disto;
723 } opj_packet_info_t;
724
725
726 /* UniPG>> */
727 /**
728  * Marker structure
729  * */
730 typedef struct opj_marker_info {
731         /** marker type */
732         unsigned short int type;
733         /** position in codestream */
734         OPJ_OFF_T pos;
735         /** length, marker val included */
736         int len;
737 } opj_marker_info_t;
738 /* <<UniPG */
739
740 /**
741  * Index structure : Information concerning tile-parts
742 */
743 typedef struct opj_tp_info {
744         /** start position of tile part */
745         int tp_start_pos;
746         /** end position of tile part header */
747         int tp_end_header;
748         /** end position of tile part */
749         int tp_end_pos;
750         /** start packet of tile part */
751         int tp_start_pack;
752         /** number of packets of tile part */
753         int tp_numpacks;
754 } opj_tp_info_t;
755
756 /**
757  * Index structure : information regarding tiles
758 */
759 typedef struct opj_tile_info {
760         /** value of thresh for each layer by tile cfr. Marcela   */
761         double *thresh;
762         /** number of tile */
763         int tileno;
764         /** start position */
765         int start_pos;
766         /** end position of the header */
767         int end_header;
768         /** end position */
769         int end_pos;
770         /** precinct number for each resolution level (width) */
771         int pw[33];
772         /** precinct number for each resolution level (height) */
773         int ph[33];
774         /** precinct size (in power of 2), in X for each resolution level */
775         int pdx[33];
776         /** precinct size (in power of 2), in Y for each resolution level */
777         int pdy[33];
778         /** information concerning packets inside tile */
779         opj_packet_info_t *packet;
780         /** add fixed_quality */
781         int numpix;
782         /** add fixed_quality */
783         double distotile;
784         /** number of markers */
785         int marknum;
786         /** list of markers */
787         opj_marker_info_t *marker;
788         /** actual size of markers array */
789         int maxmarknum;
790         /** number of tile parts */
791         int num_tps;
792         /** information concerning tile parts */
793         opj_tp_info_t *tp;
794 } opj_tile_info_t;
795
796 /**
797  * Index structure of the codestream
798 */
799 typedef struct opj_codestream_info {
800         /** maximum distortion reduction on the whole image (add for Marcela) */
801         double D_max;
802         /** packet number */
803         int packno;
804         /** writing the packet in the index with t2_encode_packets */
805         int index_write;
806         /** image width */
807         int image_w;
808         /** image height */
809         int image_h;
810         /** progression order */
811         OPJ_PROG_ORDER prog;
812         /** tile size in x */
813         int tile_x;
814         /** tile size in y */
815         int tile_y;
816         /** */
817         int tile_Ox;
818         /** */
819         int tile_Oy;
820         /** number of tiles in X */
821         int tw;
822         /** number of tiles in Y */
823         int th;
824         /** component numbers */
825         int numcomps;
826         /** number of layer */
827         int numlayers;
828         /** number of decomposition for each component */
829         int *numdecompos;
830 /* UniPG>> */
831         /** number of markers */
832         int marknum;
833         /** list of markers */
834         opj_marker_info_t *marker;
835         /** actual size of markers array */
836         int maxmarknum;
837 /* <<UniPG */
838         /** main header position */
839         int main_head_start;
840         /** main header position */
841         int main_head_end;
842         /** codestream's size */
843         int codestream_size;
844         /** information regarding tiles inside image */
845         opj_tile_info_t *tile;
846 } opj_codestream_info_t;
847
848 /* <----------------------------------------------------------- */
849 /* new output managment of the codestream information and index */
850
851 /**
852  * Tile-component coding parameters information
853  */
854 typedef struct opj_tccp_info
855 {
856         /** component index */
857         OPJ_UINT32 compno;
858         /** coding style */
859         OPJ_UINT32 csty;
860         /** number of resolutions */
861         OPJ_UINT32 numresolutions;
862         /** code-blocks width */
863         OPJ_UINT32 cblkw;
864         /** code-blocks height */
865         OPJ_UINT32 cblkh;
866         /** code-block coding style */
867         OPJ_UINT32 cblksty;
868         /** discrete wavelet transform identifier */
869         OPJ_UINT32 qmfbid;
870         /** quantisation style */
871         OPJ_UINT32 qntsty;
872         /** stepsizes used for quantization */
873         OPJ_UINT32 stepsizes_mant[OPJ_J2K_MAXBANDS];
874         /** stepsizes used for quantization */
875         OPJ_UINT32 stepsizes_expn[OPJ_J2K_MAXBANDS];
876         /** number of guard bits */
877         OPJ_UINT32 numgbits;
878         /** Region Of Interest shift */
879         OPJ_INT32 roishift;
880         /** precinct width */
881         OPJ_UINT32 prcw[OPJ_J2K_MAXRLVLS];
882         /** precinct height */
883         OPJ_UINT32 prch[OPJ_J2K_MAXRLVLS];
884 }
885 opj_tccp_info_t;
886
887 /**
888  * Tile coding parameters information
889  */
890 typedef struct opj_tile_v2_info {
891
892         /** number (index) of tile */
893         int tileno;
894         /** coding style */
895         OPJ_UINT32 csty;
896         /** progression order */
897         OPJ_PROG_ORDER prg;
898         /** number of layers */
899         OPJ_UINT32 numlayers;
900         /** multi-component transform identifier */
901         OPJ_UINT32 mct;
902
903         /** information concerning tile component parameters*/
904         opj_tccp_info_t *tccp_info;
905
906 } opj_tile_info_v2_t;
907
908 /**
909  * Information structure about the codestream (FIXME should be expand and enhance)
910  */
911 typedef struct opj_codestream_info_v2 {
912         /* Tile info */
913         /** tile origin in x = XTOsiz */
914         OPJ_UINT32 tx0;
915         /** tile origin in y = YTOsiz */
916         OPJ_UINT32 ty0;
917         /** tile size in x = XTsiz */
918         OPJ_UINT32 tdx;
919         /** tile size in y = YTsiz */
920         OPJ_UINT32 tdy;
921         /** number of tiles in X */
922         OPJ_UINT32 tw;
923         /** number of tiles in Y */
924         OPJ_UINT32 th;
925
926         /** number of components*/
927         OPJ_UINT32 nbcomps;
928
929         /** Default information regarding tiles inside image */
930         opj_tile_info_v2_t m_default_tile_info;
931
932         /** information regarding tiles inside image */
933         opj_tile_info_v2_t *tile_info; /* FIXME not used for the moment */
934
935 } opj_codestream_info_v2_t;
936
937
938 /**
939  * Index structure about a tile part
940  */
941 typedef struct opj_tp_index {
942         /** start position */
943         OPJ_OFF_T start_pos;
944         /** end position of the header */
945         OPJ_OFF_T end_header;
946         /** end position */
947         OPJ_OFF_T end_pos;
948
949 } opj_tp_index_t;
950
951 /**
952  * Index structure about a tile
953  */
954 typedef struct opj_tile_index {
955         /** tile index */
956         OPJ_UINT32 tileno;
957
958         /** number of tile parts */
959         OPJ_UINT32 nb_tps;
960         /** current nb of tile part (allocated)*/
961         OPJ_UINT32 current_nb_tps;
962         /** current tile-part index */
963         OPJ_UINT32 current_tpsno;
964         /** information concerning tile parts */
965         opj_tp_index_t *tp_index;
966
967         /* UniPG>> */ /* NOT USED FOR THE MOMENT IN THE V2 VERSION */
968                 /** number of markers */
969                 OPJ_UINT32 marknum;
970                 /** list of markers */
971                 opj_marker_info_t *marker;
972                 /** actual size of markers array */
973                 OPJ_UINT32 maxmarknum;
974         /* <<UniPG */
975
976         /** packet number */
977         OPJ_UINT32 nb_packet;
978         /** information concerning packets inside tile */
979         opj_packet_info_t *packet_index;
980
981 } opj_tile_index_t;
982
983 /**
984  * Index structure of the codestream (FIXME should be expand and enhance)
985  */
986 typedef struct opj_codestream_index {
987         /** main header start position (SOC position) */
988         OPJ_OFF_T main_head_start;
989         /** main header end position (first SOT position) */
990         OPJ_OFF_T main_head_end;
991
992         /** codestream's size */
993         OPJ_UINT64 codestream_size;
994
995 /* UniPG>> */ /* NOT USED FOR THE MOMENT IN THE V2 VERSION */
996         /** number of markers */
997         OPJ_UINT32 marknum;
998         /** list of markers */
999         opj_marker_info_t *marker;
1000         /** actual size of markers array */
1001         OPJ_UINT32 maxmarknum;
1002 /* <<UniPG */
1003
1004         /** */
1005         OPJ_UINT32 nb_of_tiles;
1006         /** */
1007         opj_tile_index_t *tile_index; /* FIXME not used for the moment */
1008
1009 }opj_codestream_index_t;
1010 /* -----------------------------------------------------------> */
1011
1012 /*
1013 ==========================================================
1014    Metadata from the JP2file
1015 ==========================================================
1016 */
1017
1018 /**
1019  * Info structure of the JP2 file
1020  * EXPERIMENTAL FOR THE MOMENT
1021  */
1022 typedef struct opj_jp2_metadata {
1023         /** */
1024         OPJ_INT32       not_used;
1025
1026 } opj_jp2_metadata_t;
1027
1028 /**
1029  * Index structure of the JP2 file
1030  * EXPERIMENTAL FOR THE MOMENT
1031  */
1032 typedef struct opj_jp2_index {
1033         /** */
1034         OPJ_INT32       not_used;
1035
1036 } opj_jp2_index_t;
1037
1038
1039 #ifdef __cplusplus
1040 extern "C" {
1041 #endif
1042
1043
1044 /* 
1045 ==========================================================
1046    openjpeg version
1047 ==========================================================
1048 */
1049
1050 /* Get the version of the openjpeg library*/
1051 OPJ_API const char * OPJ_CALLCONV opj_version(void);
1052
1053 /* 
1054 ==========================================================
1055    image functions definitions
1056 ==========================================================
1057 */
1058
1059 /**
1060  * Create an image
1061  *
1062  * @param numcmpts      number of components
1063  * @param cmptparms     components parameters
1064  * @param clrspc        image color space
1065  * @return returns      a new image structure if successful, returns NULL otherwise
1066  * */
1067 OPJ_API opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
1068
1069 /**
1070  * Deallocate any resources associated with an image
1071  *
1072  * @param image         image to be destroyed
1073  */
1074 OPJ_API void OPJ_CALLCONV opj_image_destroy(opj_image_t *image);
1075
1076 /**
1077  * Creates an image without allocating memory for the image (used in the new version of the library).
1078  *
1079  * @param       numcmpts    the number of components
1080  * @param       cmptparms   the components parameters
1081  * @param       clrspc      the image color space
1082  *
1083  * @return      a new image structure if successful, NULL otherwise.
1084 */
1085 OPJ_API opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
1086
1087 /* 
1088 ==========================================================
1089    stream functions definitions
1090 ==========================================================
1091 */
1092
1093 /**
1094  * Creates an abstract stream. This function does nothing except allocating memory and initializing the abstract stream.
1095  *
1096  * @param       p_is_input              if set to true then the stream will be an input stream, an output stream else.
1097  *
1098  * @return      a stream object.
1099 */
1100 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_default_create(OPJ_BOOL p_is_input);
1101
1102 /**
1103  * Creates an abstract stream. This function does nothing except allocating memory and initializing the abstract stream.
1104  *
1105  * @param       p_buffer_size  FIXME DOC
1106  * @param       p_is_input              if set to true then the stream will be an input stream, an output stream else.
1107  *
1108  * @return      a stream object.
1109 */
1110 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size, OPJ_BOOL p_is_input);
1111
1112 /**
1113  * Destroys a stream created by opj_create_stream. This function does NOT close the abstract stream. If needed the user must
1114  * close its own implementation of the stream.
1115  *
1116  * @param       p_stream        the stream to destroy.
1117  */
1118 OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream);
1119  
1120 /**
1121  * Sets the given function to be used as a read function.
1122  * @param               p_stream        the stream to modify
1123  * @param               p_function      the function to use a read function.
1124 */
1125 OPJ_API void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, opj_stream_read_fn p_function);
1126
1127 /**
1128  * Sets the given function to be used as a write function.
1129  * @param               p_stream        the stream to modify
1130  * @param               p_function      the function to use a write function.
1131 */
1132 OPJ_API void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream, opj_stream_write_fn p_function);
1133
1134 /**
1135  * Sets the given function to be used as a skip function.
1136  * @param               p_stream        the stream to modify
1137  * @param               p_function      the function to use a skip function.
1138 */
1139 OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_stream_skip_fn p_function);
1140
1141 /**
1142  * Sets the given function to be used as a seek function, the stream is then seekable.
1143  * @param               p_stream        the stream to modify
1144  * @param               p_function      the function to use a skip function.
1145 */
1146 OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, opj_stream_seek_fn p_function);
1147
1148 /**
1149  * Sets the given data to be used as a user data for the stream.
1150  * @param               p_stream        the stream to modify
1151  * @param               p_data          the data to set.
1152  * @param               p_function      the function to free p_data when opj_stream_destroy() is called.
1153 */
1154 OPJ_API void OPJ_CALLCONV opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data, opj_stream_free_user_data_fn p_function);
1155
1156 /**
1157  * Sets the length of the user data for the stream.
1158  *
1159  * @param p_stream    the stream to modify
1160  * @param data_length length of the user_data.
1161 */
1162 OPJ_API void OPJ_CALLCONV opj_stream_set_user_data_length(opj_stream_t* p_stream, OPJ_UINT64 data_length);
1163
1164 /**
1165  * Create a stream from a file identified with its filename with default parameters (helper function)
1166  * @param fname             the filename of the file to stream
1167  * @param p_is_read_stream  whether the stream is a read stream (true) or not (false)
1168 */
1169 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (const char *fname, OPJ_BOOL p_is_read_stream);
1170  
1171 /** Create a stream from a file identified with its filename with a specific buffer size
1172  * @param fname             the filename of the file to stream
1173  * @param p_buffer_size     size of the chunk used to stream
1174  * @param p_is_read_stream  whether the stream is a read stream (true) or not (false)
1175 */
1176 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (const char *fname,
1177                                                                      OPJ_SIZE_T p_buffer_size,
1178                                                                      OPJ_BOOL p_is_read_stream);
1179  
1180 /* 
1181 ==========================================================
1182    event manager functions definitions
1183 ==========================================================
1184 */
1185 /**
1186  * Set the info handler use by openjpeg.
1187  * @param p_codec       the codec previously initialise
1188  * @param p_callback    the callback function which will be used
1189  * @param p_user_data   client object where will be returned the message
1190 */
1191 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_info_handler(opj_codec_t * p_codec, 
1192                                                    opj_msg_callback p_callback,
1193                                                    void * p_user_data);
1194 /**
1195  * Set the warning handler use by openjpeg.
1196  * @param p_codec       the codec previously initialise
1197  * @param p_callback    the callback function which will be used
1198  * @param p_user_data   client object where will be returned the message
1199 */
1200 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_warning_handler(opj_codec_t * p_codec,
1201                                                       opj_msg_callback p_callback,
1202                                                       void * p_user_data);
1203 /**
1204  * Set the error handler use by openjpeg.
1205  * @param p_codec       the codec previously initialise
1206  * @param p_callback    the callback function which will be used
1207  * @param p_user_data   client object where will be returned the message
1208 */
1209 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_error_handler(opj_codec_t * p_codec, 
1210                                                     opj_msg_callback p_callback,
1211                                                     void * p_user_data);
1212
1213 /* 
1214 ==========================================================
1215    codec functions definitions
1216 ==========================================================
1217 */
1218
1219 /**
1220  * Creates a J2K/JP2 decompression structure
1221  * @param format                Decoder to select
1222  *
1223  * @return Returns a handle to a decompressor if successful, returns NULL otherwise
1224  * */
1225 OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format);
1226
1227 /**
1228  * Destroy a decompressor handle
1229  *
1230  * @param       p_codec                 decompressor handle to destroy
1231  */
1232 OPJ_API void OPJ_CALLCONV opj_destroy_codec(opj_codec_t * p_codec);
1233
1234 /**
1235  * Read after the codestream if necessary
1236  * @param       p_codec                 the JPEG2000 codec to read.
1237  * @param       p_stream                the JPEG2000 stream.
1238  */
1239 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_end_decompress (      opj_codec_t *p_codec,
1240                                                                                                         opj_stream_t *p_stream);
1241
1242
1243 /**
1244  * Set decoding parameters to default values
1245  * @param parameters Decompression parameters
1246  */
1247 OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters);
1248
1249 /**
1250  * Setup the decoder with decompression parameters provided by the user and with the message handler
1251  * provided by the user.
1252  *
1253  * @param p_codec               decompressor handler
1254  * @param parameters    decompression parameters
1255  *
1256  * @return true                 if the decoder is correctly set
1257  */
1258 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_setup_decoder(opj_codec_t *p_codec,
1259                                                                                                 opj_dparameters_t *parameters );
1260
1261 /**
1262  * Decodes an image header.
1263  *
1264  * @param       p_stream                the jpeg2000 stream.
1265  * @param       p_codec                 the jpeg2000 codec to read.
1266  * @param       p_image                 the image structure initialized with the characteristics of encoded image.
1267  *
1268  * @return true                         if the main header of the codestream and the JP2 header is correctly read.
1269  */
1270 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_read_header ( opj_stream_t *p_stream,
1271                                                                                                 opj_codec_t *p_codec,
1272                                                                                                 opj_image_t **p_image);
1273
1274 /**
1275  * Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading.
1276  *
1277  * @param       p_codec                 the jpeg2000 codec.
1278  * @param       p_image         the decoded image previously setted by opj_read_header
1279  * @param       p_start_x               the left position of the rectangle to decode (in image coordinates).
1280  * @param       p_end_x                 the right position of the rectangle to decode (in image coordinates).
1281  * @param       p_start_y               the up position of the rectangle to decode (in image coordinates).
1282  * @param       p_end_y                 the bottom position of the rectangle to decode (in image coordinates).
1283  *
1284  * @return      true                    if the area could be set.
1285  */
1286 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_decode_area(      opj_codec_t *p_codec,
1287                                                                                                         opj_image_t* p_image,
1288                                                                                                         OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
1289                                                                                                         OPJ_INT32 p_end_x, OPJ_INT32 p_end_y );
1290
1291 /**
1292  * Decode an image from a JPEG-2000 codestream
1293  *
1294  * @param p_decompressor        decompressor handle
1295  * @param p_stream                      Input buffer stream
1296  * @param p_image                       the decoded image
1297  * @return                                      true if success, otherwise false
1298  * */
1299 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decode(   opj_codec_t *p_decompressor,
1300                                             opj_stream_t *p_stream,
1301                                             opj_image_t *p_image);
1302
1303 /**
1304  * Get the decoded tile from the codec
1305  *
1306  * @param       p_codec                 the jpeg2000 codec.
1307  * @param       p_stream                input streamm
1308  * @param       p_image                 output image
1309  * @param       tile_index              index of the tile which will be decode
1310  *
1311  * @return                                      true if success, otherwise false
1312  */
1313 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_get_decoded_tile(     opj_codec_t *p_codec,
1314                                                                                                         opj_stream_t *p_stream,
1315                                                                                                         opj_image_t *p_image,
1316                                                                                                         OPJ_UINT32 tile_index);
1317
1318 /**
1319  * Set the resolution factor of the decoded image
1320  * @param       p_codec                 the jpeg2000 codec.
1321  * @param       res_factor              resolution factor to set
1322  *
1323  * @return                                      true if success, otherwise false
1324  */
1325 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_decoded_resolution_factor(opj_codec_t *p_codec, OPJ_UINT32 res_factor);
1326
1327 /**
1328  * Writes a tile with the given data.
1329  *
1330  * @param       p_codec                 the jpeg2000 codec.
1331  * @param       p_tile_index            the index of the tile to write. At the moment, the tiles must be written from 0 to n-1 in sequence.
1332  * @param       p_data                          pointer to the data to write. Data is arranged in sequence, data_comp0, then data_comp1, then ... NO INTERLEAVING should be set.
1333  * @param       p_data_size                     this value os used to make sure the data being written is correct. The size must be equal to the sum for each component of 
1334  *                              tile_width * tile_height * component_size. component_size can be 1,2 or 4 bytes, depending on the precision of the given component.
1335  * @param       p_stream                        the stream to write data to.
1336  *
1337  * @return      true if the data could be written.
1338  */
1339 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_write_tile (  opj_codec_t *p_codec,
1340                                                                                                 OPJ_UINT32 p_tile_index,
1341                                                                                                 OPJ_BYTE * p_data,
1342                                                                                                 OPJ_UINT32 p_data_size,
1343                                                                                                 opj_stream_t *p_stream );
1344
1345 /**
1346  * Reads a tile header. This function is compulsory and allows one to know the size of the tile thta will be decoded.
1347  * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
1348  *
1349  * @param       p_codec                 the jpeg2000 codec.
1350  * @param       p_tile_index    pointer to a value that will hold the index of the tile being decoded, in case of success.
1351  * @param       p_data_size             pointer to a value that will hold the maximum size of the decoded data, in case of success. In case
1352  *                                                      of truncated codestreams, the actual number of bytes decoded may be lower. The computation of the size is the same
1353  *                                                      as depicted in opj_write_tile.
1354  * @param       p_tile_x0               pointer to a value that will hold the x0 pos of the tile (in the image).
1355  * @param       p_tile_y0               pointer to a value that will hold the y0 pos of the tile (in the image).
1356  * @param       p_tile_x1               pointer to a value that will hold the x1 pos of the tile (in the image).
1357  * @param       p_tile_y1               pointer to a value that will hold the y1 pos of the tile (in the image).
1358  * @param       p_nb_comps              pointer to a value that will hold the number of components in the tile.
1359  * @param       p_should_go_on  pointer to a boolean that will hold the fact that the decoding should go on. In case the
1360  *                                                      codestream is over at the time of the call, the value will be set to false. The user should then stop
1361  *                                                      the decoding.
1362  * @param       p_stream                the stream to decode.
1363  * @return      true                    if the tile header could be decoded. In case the decoding should end, the returned value is still true.
1364  *                                                      returning false may be the result of a shortage of memory or an internal error.
1365  */
1366 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_read_tile_header(     opj_codec_t *p_codec,
1367                                                                                                 opj_stream_t * p_stream,
1368                                                                                                 OPJ_UINT32 * p_tile_index,
1369                                                                                                 OPJ_UINT32 * p_data_size,
1370                                                                                                 OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0,
1371                                                                                                 OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1,
1372                                                                                                 OPJ_UINT32 * p_nb_comps,
1373                                                                                                 OPJ_BOOL * p_should_go_on );
1374
1375 /**
1376  * Reads a tile data. This function is compulsory and allows one to decode tile data. opj_read_tile_header should be called before.
1377  * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
1378  *
1379  * @param       p_codec                 the jpeg2000 codec.
1380  * @param       p_tile_index    the index of the tile being decoded, this should be the value set by opj_read_tile_header.
1381  * @param       p_data                  pointer to a memory block that will hold the decoded data.
1382  * @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.
1383  * @param       p_stream                the stream to decode.
1384  *
1385  * @return      true                    if the data could be decoded.
1386  */
1387 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decode_tile_data(     opj_codec_t *p_codec,
1388                                                                                                         OPJ_UINT32 p_tile_index,
1389                                                                                                         OPJ_BYTE * p_data,
1390                                                                                                         OPJ_UINT32 p_data_size,
1391                                                                                                         opj_stream_t *p_stream );
1392
1393 /* COMPRESSION FUNCTIONS*/
1394
1395 /**
1396  * Creates a J2K/JP2 compression structure
1397  * @param       format          Coder to select
1398  * @return                              Returns a handle to a compressor if successful, returns NULL otherwise
1399  */
1400 OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format);
1401
1402 /**
1403 Set encoding parameters to default values, that means : 
1404 <ul>
1405 <li>Lossless
1406 <li>1 tile
1407 <li>Size of precinct : 2^15 x 2^15 (means 1 precinct)
1408 <li>Size of code-block : 64 x 64
1409 <li>Number of resolutions: 6
1410 <li>No SOP marker in the codestream
1411 <li>No EPH marker in the codestream
1412 <li>No sub-sampling in x or y direction
1413 <li>No mode switch activated
1414 <li>Progression order: LRCP
1415 <li>No index file
1416 <li>No ROI upshifted
1417 <li>No offset of the origin of the image
1418 <li>No offset of the origin of the tiles
1419 <li>Reversible DWT 5-3
1420 </ul>
1421 @param parameters Compression parameters
1422 */
1423 OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters);
1424
1425 /**
1426  * Setup the encoder parameters using the current image and using user parameters.
1427  * @param p_codec               Compressor handle
1428  * @param parameters    Compression parameters
1429  * @param image                 Input filled image
1430  */
1431 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_setup_encoder(opj_codec_t *p_codec, 
1432                                                                                                 opj_cparameters_t *parameters, 
1433                                                                                                 opj_image_t *image);
1434
1435 /**
1436  * Start to compress the current image.
1437  * @param p_codec               Compressor handle
1438  * @param image             Input filled image
1439  * @param p_stream              Input stgream
1440  */
1441 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_start_compress (      opj_codec_t *p_codec,
1442                                                                                                         opj_image_t * p_image,
1443                                                                                                         opj_stream_t *p_stream);
1444
1445 /**
1446  * End to compress the current image.
1447  * @param p_codec               Compressor handle
1448  * @param p_stream              Input stgream
1449  */
1450 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_end_compress (opj_codec_t *p_codec,
1451                                                                                                 opj_stream_t *p_stream);
1452
1453 /**
1454  * Encode an image into a JPEG-2000 codestream
1455  * @param p_codec               compressor handle
1456  * @param p_stream              Output buffer stream
1457  *
1458  * @return                              Returns true if successful, returns false otherwise
1459  */
1460 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_encode(opj_codec_t *p_codec,
1461                                          opj_stream_t *p_stream);
1462 /*
1463 ==========================================================
1464    codec output functions definitions
1465 ==========================================================
1466 */
1467 /* EXPERIMENTAL FUNCTIONS FOR NOW, USED ONLY IN J2K_DUMP*/
1468
1469 /**
1470 Destroy Codestream information after compression or decompression
1471 @param cstr_info Codestream information structure
1472 */
1473 OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_v2_t **cstr_info);
1474
1475
1476 /**
1477  * Dump the codec information into the output stream
1478  *
1479  * @param       p_codec                 the jpeg2000 codec.
1480  * @param       info_flag               type of information dump.
1481  * @param       output_stream   output stream where dump the informations get from the codec.
1482  *
1483  */
1484 OPJ_API void OPJ_CALLCONV opj_dump_codec(       opj_codec_t *p_codec,
1485                                                                                         OPJ_INT32 info_flag,
1486                                                                                         FILE* output_stream);
1487
1488 /**
1489  * Get the codestream information from the codec
1490  *
1491  * @param       p_codec                 the jpeg2000 codec.
1492  *
1493  * @return                                      a pointer to a codestream information structure.
1494  *
1495  */
1496 OPJ_API opj_codestream_info_v2_t* OPJ_CALLCONV opj_get_cstr_info(opj_codec_t *p_codec);
1497
1498 /**
1499  * Get the codestream index from the codec
1500  *
1501  * @param       p_codec                 the jpeg2000 codec.
1502  *
1503  * @return                                      a pointer to a codestream index structure.
1504  *
1505  */
1506 OPJ_API opj_codestream_index_t * OPJ_CALLCONV opj_get_cstr_index(opj_codec_t *p_codec);
1507
1508 OPJ_API void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t **p_cstr_index);
1509
1510
1511 /**
1512  * Get the JP2 file information from the codec FIXME
1513  *
1514  * @param       p_codec                 the jpeg2000 codec.
1515  *
1516  * @return                                      a pointer to a JP2 metadata structure.
1517  *
1518  */
1519 OPJ_API opj_jp2_metadata_t* OPJ_CALLCONV opj_get_jp2_metadata(opj_codec_t *p_codec);
1520
1521 /**
1522  * Get the JP2 file index from the codec FIXME
1523  *
1524  * @param       p_codec                 the jpeg2000 codec.
1525  *
1526  * @return                                      a pointer to a JP2 index structure.
1527  *
1528  */
1529 OPJ_API opj_jp2_index_t* OPJ_CALLCONV opj_get_jp2_index(opj_codec_t *p_codec);
1530
1531
1532 /*
1533 ==========================================================
1534    MCT functions
1535 ==========================================================
1536 */
1537
1538 /**
1539  * Sets the MCT matrix to use.
1540  *
1541  * @param       parameters              the parameters to change.
1542  * @param       pEncodingMatrix the encoding matrix.
1543  * @param       p_dc_shift              the dc shift coefficients to use.
1544  * @param       pNbComp                 the number of components of the image.
1545  *
1546  * @return      true if the parameters could be set.
1547  */
1548 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_MCT( opj_cparameters_t *parameters,
1549                                                    OPJ_FLOAT32 * pEncodingMatrix,
1550                                                    OPJ_INT32 * p_dc_shift,
1551                                                    OPJ_UINT32 pNbComp);
1552
1553
1554
1555 #ifdef __cplusplus
1556 }
1557 #endif
1558
1559 #endif /* OPENJPEG_H */