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