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