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