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