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