[trunk] refactoring of rsiz, profiles, and extensions management
[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      * Maximum size (in bytes) for the whole codestream.
473      * If == 0, codestream size limitation is not considered
474      * If it does not comply with tcp_rates, max_cs_size prevails
475      * and a warning is issued.
476      * */
477     int max_cs_size;
478     /**
479      * DEPRECATED: use RSIZ, OPJ_PROFILE_* and OPJ_EXTENSION_* instead
480      * Profile name
481      * */
482     OPJ_RSIZ_CAPABILITIES cp_rsiz;
483         /** Tile part generation*/
484         char tp_on;
485         /** Flag for Tile part generation*/
486         char tp_flag;
487         /** MCT (multiple component transform) */
488         char tcp_mct;
489         /** Enable JPIP indexing*/
490         OPJ_BOOL jpip_on;
491         /** Naive implementation of MCT restricted to a single reversible array based 
492         encoding without offset concerning all the components. */
493         void * mct_data;
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  * Destroys a stream created by opj_create_stream. This function does NOT close the abstract stream. 
1122  * If needed the user must close its own implementation of the stream.
1123  *
1124  * @param       p_stream        the stream to destroy.
1125  */
1126 OPJ_API void OPJ_CALLCONV opj_stream_destroy_v3(opj_stream_t* p_stream);
1127  
1128 /**
1129  * Sets the given function to be used as a read function.
1130  * @param               p_stream        the stream to modify
1131  * @param               p_function      the function to use a read function.
1132 */
1133 OPJ_API void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, opj_stream_read_fn p_function);
1134
1135 /**
1136  * Sets the given function to be used as a write function.
1137  * @param               p_stream        the stream to modify
1138  * @param               p_function      the function to use a write function.
1139 */
1140 OPJ_API void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream, opj_stream_write_fn p_function);
1141
1142 /**
1143  * Sets the given function to be used as a skip function.
1144  * @param               p_stream        the stream to modify
1145  * @param               p_function      the function to use a skip function.
1146 */
1147 OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_stream_skip_fn p_function);
1148
1149 /**
1150  * Sets the given function to be used as a seek function, the stream is then seekable.
1151  * @param               p_stream        the stream to modify
1152  * @param               p_function      the function to use a skip function.
1153 */
1154 OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, opj_stream_seek_fn p_function);
1155
1156 /**
1157  * Sets the given data to be used as a user data for the stream.
1158  * @param               p_stream        the stream to modify
1159  * @param               p_data          the data to set.
1160  * @warning depending on your source object p_stream this function may leak, use opj_stream_set_user_data_v3
1161 */
1162 OPJ_DEPRECATED(OPJ_API void OPJ_CALLCONV opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data));
1163
1164 /**
1165  * Sets the given data to be used as a user data for the stream.
1166  * @param               p_stream        the stream to modify
1167  * @param               p_data          the data to set.
1168  * @param               p_function      the function to free p_data when opj_stream_destroy() is called.
1169 */
1170 OPJ_API void OPJ_CALLCONV opj_stream_set_user_data_v3 (opj_stream_t* p_stream, void * p_data, opj_stream_free_user_data_fn p_function);
1171
1172 /**
1173  * Sets the length of the user data for the stream.
1174  *
1175  * @param p_stream    the stream to modify
1176  * @param data_length length of the user_data.
1177 */
1178 OPJ_API void OPJ_CALLCONV opj_stream_set_user_data_length(opj_stream_t* p_stream, OPJ_UINT64 data_length);
1179
1180 /**
1181  * Create a stream from a file identified with its filename with default parameters (helper function)
1182  * @param fname             the filename of the file to stream
1183  * @param p_is_read_stream  whether the stream is a read stream (true) or not (false)
1184 */
1185 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream_v3 (const char *fname, OPJ_BOOL p_is_read_stream);
1186  
1187 /** Create a stream from a file identified with its filename with a specific buffer size
1188  * @param fname             the filename of the file to stream
1189  * @param p_buffer_size     size of the chunk used to stream
1190  * @param p_is_read_stream  whether the stream is a read stream (true) or not (false)
1191 */
1192 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream_v3 (const char *fname, 
1193                                                                      OPJ_SIZE_T p_buffer_size,
1194                                                                      OPJ_BOOL p_is_read_stream);
1195  
1196 /* 
1197 ==========================================================
1198    event manager functions definitions
1199 ==========================================================
1200 */
1201 /**
1202  * Set the info handler use by openjpeg.
1203  * @param p_codec       the codec previously initialise
1204  * @param p_callback    the callback function which will be used
1205  * @param p_user_data   client object where will be returned the message
1206 */
1207 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_info_handler(opj_codec_t * p_codec, 
1208                                                    opj_msg_callback p_callback,
1209                                                    void * p_user_data);
1210 /**
1211  * Set the warning handler use by openjpeg.
1212  * @param p_codec       the codec previously initialise
1213  * @param p_callback    the callback function which will be used
1214  * @param p_user_data   client object where will be returned the message
1215 */
1216 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_warning_handler(opj_codec_t * p_codec,
1217                                                       opj_msg_callback p_callback,
1218                                                       void * p_user_data);
1219 /**
1220  * Set the error handler use by openjpeg.
1221  * @param p_codec       the codec previously initialise
1222  * @param p_callback    the callback function which will be used
1223  * @param p_user_data   client object where will be returned the message
1224 */
1225 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_error_handler(opj_codec_t * p_codec, 
1226                                                     opj_msg_callback p_callback,
1227                                                     void * p_user_data);
1228
1229 /* 
1230 ==========================================================
1231    codec functions definitions
1232 ==========================================================
1233 */
1234
1235 /**
1236  * Creates a J2K/JP2 decompression structure
1237  * @param format                Decoder to select
1238  *
1239  * @return Returns a handle to a decompressor if successful, returns NULL otherwise
1240  * */
1241 OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format);
1242
1243 /**
1244  * Destroy a decompressor handle
1245  *
1246  * @param       p_codec                 decompressor handle to destroy
1247  */
1248 OPJ_API void OPJ_CALLCONV opj_destroy_codec(opj_codec_t * p_codec);
1249
1250 /**
1251  * Read after the codestream if necessary
1252  * @param       p_codec                 the JPEG2000 codec to read.
1253  * @param       p_stream                the JPEG2000 stream.
1254  */
1255 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_end_decompress (      opj_codec_t *p_codec,
1256                                                                                                         opj_stream_t *p_stream);
1257
1258
1259 /**
1260  * Set decoding parameters to default values
1261  * @param parameters Decompression parameters
1262  */
1263 OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters);
1264
1265 /**
1266  * Setup the decoder with decompression parameters provided by the user and with the message handler
1267  * provided by the user.
1268  *
1269  * @param p_codec               decompressor handler
1270  * @param parameters    decompression parameters
1271  *
1272  * @return true                 if the decoder is correctly set
1273  */
1274 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_setup_decoder(opj_codec_t *p_codec,
1275                                                                                                 opj_dparameters_t *parameters );
1276
1277 /**
1278  * Decodes an image header.
1279  *
1280  * @param       p_stream                the jpeg2000 stream.
1281  * @param       p_codec                 the jpeg2000 codec to read.
1282  * @param       p_image                 the image structure initialized with the characteristics of encoded image.
1283  *
1284  * @return true                         if the main header of the codestream and the JP2 header is correctly read.
1285  */
1286 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_read_header ( opj_stream_t *p_stream,
1287                                                                                                 opj_codec_t *p_codec,
1288                                                                                                 opj_image_t **p_image);
1289
1290 /**
1291  * Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading.
1292  *
1293  * @param       p_codec                 the jpeg2000 codec.
1294  * @param       p_image         the decoded image previously setted by opj_read_header
1295  * @param       p_start_x               the left position of the rectangle to decode (in image coordinates).
1296  * @param       p_end_x                 the right position of the rectangle to decode (in image coordinates).
1297  * @param       p_start_y               the up position of the rectangle to decode (in image coordinates).
1298  * @param       p_end_y                 the bottom position of the rectangle to decode (in image coordinates).
1299  *
1300  * @return      true                    if the area could be set.
1301  */
1302 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_decode_area(      opj_codec_t *p_codec,
1303                                                                                                         opj_image_t* p_image,
1304                                                                                                         OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
1305                                                                                                         OPJ_INT32 p_end_x, OPJ_INT32 p_end_y );
1306
1307 /**
1308  * Decode an image from a JPEG-2000 codestream
1309  *
1310  * @param p_decompressor        decompressor handle
1311  * @param p_stream                      Input buffer stream
1312  * @param p_image                       the decoded image
1313  * @return                                      true if success, otherwise false
1314  * */
1315 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decode(   opj_codec_t *p_decompressor,
1316                                             opj_stream_t *p_stream,
1317                                             opj_image_t *p_image);
1318
1319 /**
1320  * Get the decoded tile from the codec
1321  *
1322  * @param       p_codec                 the jpeg2000 codec.
1323  * @param       p_stream                input streamm
1324  * @param       p_image                 output image
1325  * @param       tile_index              index of the tile which will be decode
1326  *
1327  * @return                                      true if success, otherwise false
1328  */
1329 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_get_decoded_tile(     opj_codec_t *p_codec,
1330                                                                                                         opj_stream_t *p_stream,
1331                                                                                                         opj_image_t *p_image,
1332                                                                                                         OPJ_UINT32 tile_index);
1333
1334 /**
1335  * Set the resolution factor of the decoded image
1336  * @param       p_codec                 the jpeg2000 codec.
1337  * @param       res_factor              resolution factor to set
1338  *
1339  * @return                                      true if success, otherwise false
1340  */
1341 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_decoded_resolution_factor(opj_codec_t *p_codec, OPJ_UINT32 res_factor);
1342
1343 /**
1344  * Writes a tile with the given data.
1345  *
1346  * @param       p_codec                 the jpeg2000 codec.
1347  * @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.
1348  * @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.
1349  * @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 
1350  *                              tile_width * tile_height * component_size. component_size can be 1,2 or 4 bytes, depending on the precision of the given component.
1351  * @param       p_stream                        the stream to write data to.
1352  *
1353  * @return      true if the data could be written.
1354  */
1355 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_write_tile (  opj_codec_t *p_codec,
1356                                                                                                 OPJ_UINT32 p_tile_index,
1357                                                                                                 OPJ_BYTE * p_data,
1358                                                                                                 OPJ_UINT32 p_data_size,
1359                                                                                                 opj_stream_t *p_stream );
1360
1361 /**
1362  * Reads a tile header. This function is compulsory and allows one to know the size of the tile thta will be decoded.
1363  * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
1364  *
1365  * @param       p_codec                 the jpeg2000 codec.
1366  * @param       p_tile_index    pointer to a value that will hold the index of the tile being decoded, in case of success.
1367  * @param       p_data_size             pointer to a value that will hold the maximum size of the decoded data, in case of success. In case
1368  *                                                      of truncated codestreams, the actual number of bytes decoded may be lower. The computation of the size is the same
1369  *                                                      as depicted in opj_write_tile.
1370  * @param       p_tile_x0               pointer to a value that will hold the x0 pos of the tile (in the image).
1371  * @param       p_tile_y0               pointer to a value that will hold the y0 pos of the tile (in the image).
1372  * @param       p_tile_x1               pointer to a value that will hold the x1 pos of the tile (in the image).
1373  * @param       p_tile_y1               pointer to a value that will hold the y1 pos of the tile (in the image).
1374  * @param       p_nb_comps              pointer to a value that will hold the number of components in the tile.
1375  * @param       p_should_go_on  pointer to a boolean that will hold the fact that the decoding should go on. In case the
1376  *                                                      codestream is over at the time of the call, the value will be set to false. The user should then stop
1377  *                                                      the decoding.
1378  * @param       p_stream                the stream to decode.
1379  * @return      true                    if the tile header could be decoded. In case the decoding should end, the returned value is still true.
1380  *                                                      returning false may be the result of a shortage of memory or an internal error.
1381  */
1382 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_read_tile_header(     opj_codec_t *p_codec,
1383                                                                                                 opj_stream_t * p_stream,
1384                                                                                                 OPJ_UINT32 * p_tile_index,
1385                                                                                                 OPJ_UINT32 * p_data_size,
1386                                                                                                 OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0,
1387                                                                                                 OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1,
1388                                                                                                 OPJ_UINT32 * p_nb_comps,
1389                                                                                                 OPJ_BOOL * p_should_go_on );
1390
1391 /**
1392  * Reads a tile data. This function is compulsory and allows one to decode tile data. opj_read_tile_header should be called before.
1393  * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
1394  *
1395  * @param       p_codec                 the jpeg2000 codec.
1396  * @param       p_tile_index    the index of the tile being decoded, this should be the value set by opj_read_tile_header.
1397  * @param       p_data                  pointer to a memory block that will hold the decoded data.
1398  * @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.
1399  * @param       p_stream                the stream to decode.
1400  *
1401  * @return      true                    if the data could be decoded.
1402  */
1403 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decode_tile_data(     opj_codec_t *p_codec,
1404                                                                                                         OPJ_UINT32 p_tile_index,
1405                                                                                                         OPJ_BYTE * p_data,
1406                                                                                                         OPJ_UINT32 p_data_size,
1407                                                                                                         opj_stream_t *p_stream );
1408
1409 /* COMPRESSION FUNCTIONS*/
1410
1411 /**
1412  * Creates a J2K/JP2 compression structure
1413  * @param       format          Coder to select
1414  * @return                              Returns a handle to a compressor if successful, returns NULL otherwise
1415  */
1416 OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format);
1417
1418 /**
1419 Set encoding parameters to default values, that means : 
1420 <ul>
1421 <li>Lossless
1422 <li>1 tile
1423 <li>Size of precinct : 2^15 x 2^15 (means 1 precinct)
1424 <li>Size of code-block : 64 x 64
1425 <li>Number of resolutions: 6
1426 <li>No SOP marker in the codestream
1427 <li>No EPH marker in the codestream
1428 <li>No sub-sampling in x or y direction
1429 <li>No mode switch activated
1430 <li>Progression order: LRCP
1431 <li>No index file
1432 <li>No ROI upshifted
1433 <li>No offset of the origin of the image
1434 <li>No offset of the origin of the tiles
1435 <li>Reversible DWT 5-3
1436 </ul>
1437 @param parameters Compression parameters
1438 */
1439 OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters);
1440
1441 /**
1442  * Setup the encoder parameters using the current image and using user parameters.
1443  * @param p_codec               Compressor handle
1444  * @param parameters    Compression parameters
1445  * @param image                 Input filled image
1446  */
1447 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_setup_encoder(opj_codec_t *p_codec, 
1448                                                                                                 opj_cparameters_t *parameters, 
1449                                                                                                 opj_image_t *image);
1450
1451 /**
1452  * Start to compress the current image.
1453  * @param p_codec               Compressor handle
1454  * @param image             Input filled image
1455  * @param p_stream              Input stgream
1456  */
1457 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_start_compress (      opj_codec_t *p_codec,
1458                                                                                                         opj_image_t * p_image,
1459                                                                                                         opj_stream_t *p_stream);
1460
1461 /**
1462  * End to compress the current image.
1463  * @param p_codec               Compressor handle
1464  * @param p_stream              Input stgream
1465  */
1466 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_end_compress (opj_codec_t *p_codec,
1467                                                                                                 opj_stream_t *p_stream);
1468
1469 /**
1470  * Encode an image into a JPEG-2000 codestream
1471  * @param p_codec               compressor handle
1472  * @param p_stream              Output buffer stream
1473  *
1474  * @return                              Returns true if successful, returns false otherwise
1475  */
1476 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_encode(opj_codec_t *p_codec,
1477                                          opj_stream_t *p_stream);
1478 /*
1479 ==========================================================
1480    codec output functions definitions
1481 ==========================================================
1482 */
1483 /* EXPERIMENTAL FUNCTIONS FOR NOW, USED ONLY IN J2K_DUMP*/
1484
1485 /**
1486 Destroy Codestream information after compression or decompression
1487 @param cstr_info Codestream information structure
1488 */
1489 OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_v2_t **cstr_info);
1490
1491
1492 /**
1493  * Dump the codec information into the output stream
1494  *
1495  * @param       p_codec                 the jpeg2000 codec.
1496  * @param       info_flag               type of information dump.
1497  * @param       output_stream   output stream where dump the informations get from the codec.
1498  *
1499  */
1500 OPJ_API void OPJ_CALLCONV opj_dump_codec(       opj_codec_t *p_codec,
1501                                                                                         OPJ_INT32 info_flag,
1502                                                                                         FILE* output_stream);
1503
1504 /**
1505  * Get the codestream information from the codec
1506  *
1507  * @param       p_codec                 the jpeg2000 codec.
1508  *
1509  * @return                                      a pointer to a codestream information structure.
1510  *
1511  */
1512 OPJ_API opj_codestream_info_v2_t* OPJ_CALLCONV opj_get_cstr_info(opj_codec_t *p_codec);
1513
1514 /**
1515  * Get the codestream index from the codec
1516  *
1517  * @param       p_codec                 the jpeg2000 codec.
1518  *
1519  * @return                                      a pointer to a codestream index structure.
1520  *
1521  */
1522 OPJ_API opj_codestream_index_t * OPJ_CALLCONV opj_get_cstr_index(opj_codec_t *p_codec);
1523
1524 OPJ_API void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t **p_cstr_index);
1525
1526
1527 /**
1528  * Get the JP2 file information from the codec FIXME
1529  *
1530  * @param       p_codec                 the jpeg2000 codec.
1531  *
1532  * @return                                      a pointer to a JP2 metadata structure.
1533  *
1534  */
1535 OPJ_API opj_jp2_metadata_t* OPJ_CALLCONV opj_get_jp2_metadata(opj_codec_t *p_codec);
1536
1537 /**
1538  * Get the JP2 file index from the codec FIXME
1539  *
1540  * @param       p_codec                 the jpeg2000 codec.
1541  *
1542  * @return                                      a pointer to a JP2 index structure.
1543  *
1544  */
1545 OPJ_API opj_jp2_index_t* OPJ_CALLCONV opj_get_jp2_index(opj_codec_t *p_codec);
1546
1547
1548 /*
1549 ==========================================================
1550    MCT functions
1551 ==========================================================
1552 */
1553
1554 /**
1555  * Sets the MCT matrix to use.
1556  *
1557  * @param       parameters              the parameters to change.
1558  * @param       pEncodingMatrix the encoding matrix.
1559  * @param       p_dc_shift              the dc shift coefficients to use.
1560  * @param       pNbComp                 the number of components of the image.
1561  *
1562  * @return      true if the parameters could be set.
1563  */
1564 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_MCT( opj_cparameters_t *parameters,
1565                                                    OPJ_FLOAT32 * pEncodingMatrix,
1566                                                    OPJ_INT32 * p_dc_shift,
1567                                                    OPJ_UINT32 pNbComp);
1568
1569
1570
1571 #ifdef __cplusplus
1572 }
1573 #endif
1574
1575 #endif /* OPENJPEG_H */