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