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