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