[trunk] update documentation of new functions _v3 and mark deprecated related functions
[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 OPJ_DEPRECATED(func) __declspec(deprecated) func
51 #else
52         #pragma message("WARNING: You need to implement DEPRECATED for this compiler")
53         #define OPJ_DEPRECATED(func) func
54 #endif
55
56 #if defined(OPJ_STATIC) || !defined(_WIN32)
57 /* http://gcc.gnu.org/wiki/Visibility */
58 #if __GNUC__ >= 4
59 #define OPJ_API    __attribute__ ((visibility ("default")))
60 #define OPJ_LOCAL  __attribute__ ((visibility ("hidden")))
61 #else
62 #define OPJ_API
63 #define OPJ_LOCAL
64 #endif
65 #define OPJ_CALLCONV
66 #else
67 #define OPJ_CALLCONV __stdcall
68 /*
69 The following ifdef block is the standard way of creating macros which make exporting 
70 from a DLL simpler. All files within this DLL are compiled with the OPJ_EXPORTS
71 symbol defined on the command line. this symbol should not be defined on any project
72 that uses this DLL. This way any other project whose source files include this file see 
73 OPJ_API functions as being imported from a DLL, wheras this DLL sees symbols
74 defined with this macro as being exported.
75 */
76 #if defined(OPJ_EXPORTS) || defined(DLL_EXPORT)
77 #define OPJ_API __declspec(dllexport)
78 #else
79 #define OPJ_API __declspec(dllimport)
80 #endif /* OPJ_EXPORTS */
81 #endif /* !OPJ_STATIC || !_WIN32 */
82
83 typedef int OPJ_BOOL;
84 #define OPJ_TRUE 1
85 #define OPJ_FALSE 0
86
87 typedef char          OPJ_CHAR;
88 typedef float         OPJ_FLOAT32;
89 typedef double        OPJ_FLOAT64;
90 typedef unsigned char OPJ_BYTE;
91
92 #include "opj_stdint.h"
93
94 typedef int8_t   OPJ_INT8;
95 typedef uint8_t  OPJ_UINT8;
96 typedef int16_t  OPJ_INT16;
97 typedef uint16_t OPJ_UINT16;
98 typedef int32_t  OPJ_INT32;
99 typedef uint32_t OPJ_UINT32;
100 typedef int64_t  OPJ_INT64;
101 typedef uint64_t OPJ_UINT64;
102
103 typedef int64_t  OPJ_OFF_T; /* 64-bit file offset type */
104
105 #include <stdio.h>
106 typedef size_t   OPJ_SIZE_T;
107
108 /* Avoid compile-time warning because parameter is not used */
109 #define OPJ_ARG_NOT_USED(x) (void)(x)
110
111 /* 
112 ==========================================================
113    Useful constant definitions
114 ==========================================================
115 */
116
117 #define OPJ_PATH_LEN 4096 /**< Maximum allowed size for filenames */
118
119 #define OPJ_J2K_MAXRLVLS 33                                     /**< Number of maximum resolution level authorized */
120 #define OPJ_J2K_MAXBANDS (3*OPJ_J2K_MAXRLVLS-2) /**< Number of maximum sub-band linked to number of resolution level */
121
122 #define OPJ_J2K_DEFAULT_NB_SEGS                         10
123 #define OPJ_J2K_STREAM_CHUNK_SIZE                       0x100000 /** 1 mega by default */
124 #define OPJ_J2K_DEFAULT_HEADER_SIZE                     1000
125 #define OPJ_J2K_MCC_DEFAULT_NB_RECORDS          10
126 #define OPJ_J2K_MCT_DEFAULT_NB_RECORDS          10
127
128 /* UniPG>> */ /* NOT YET USED IN THE V2 VERSION OF OPENJPEG */
129 #define JPWL_MAX_NO_TILESPECS   16 /**< Maximum number of tile parts expected by JPWL: increase at your will */
130 #define JPWL_MAX_NO_PACKSPECS   16 /**< Maximum number of packet parts expected by JPWL: increase at your will */
131 #define JPWL_MAX_NO_MARKERS     512 /**< Maximum number of JPWL markers: increase at your will */
132 #define JPWL_PRIVATEINDEX_NAME "jpwl_index_privatefilename" /**< index file name used when JPWL is on */
133 #define JPWL_EXPECTED_COMPONENTS 3 /**< Expect this number of components, so you'll find better the first EPB */
134 #define JPWL_MAXIMUM_TILES 8192 /**< Expect this maximum number of tiles, to avoid some crashes */
135 #define JPWL_MAXIMUM_HAMMING 2 /**< Expect this maximum number of bit errors in marker id's */
136 #define JPWL_MAXIMUM_EPB_ROOM 65450 /**< Expect this maximum number of bytes for composition of EPBs */
137 /* <<UniPG */
138
139 /**
140  * EXPERIMENTAL FOR THE MOMENT
141  * Supported options about file information used only in j2k_dump
142 */
143 #define OPJ_IMG_INFO            1       /**< Basic image information provided to the user */
144 #define OPJ_J2K_MH_INFO         2       /**< Codestream information based only on the main header */
145 #define OPJ_J2K_TH_INFO         4       /**< Tile information based on the current tile header */
146 /*FIXME #define OPJ_J2K_CSTR_INFO       6*/     /**<  */
147 #define OPJ_J2K_MH_IND          16      /**< Codestream index based only on the main header */
148 #define OPJ_J2K_TH_IND          32      /**< Tile index based on the current tile */
149 /*FIXME #define OPJ_J2K_CSTR_IND        48*/    /**<  */
150 #define OPJ_JP2_INFO            128     /**< JP2 file information */
151 #define OPJ_JP2_IND                     256     /**< JP2 file index */
152
153
154 /* 
155 ==========================================================
156    enum definitions
157 ==========================================================
158 */
159 /** 
160  * Rsiz Capabilities
161  * */
162 typedef enum RSIZ_CAPABILITIES {
163         OPJ_STD_RSIZ = 0,               /** Standard JPEG2000 profile*/
164         OPJ_CINEMA2K = 3,               /** Profile name for a 2K image*/
165         OPJ_CINEMA4K = 4,               /** Profile name for a 4K image*/
166         OPJ_MCT = 0x8100
167 } OPJ_RSIZ_CAPABILITIES;
168
169 /** 
170  * Digital cinema operation mode
171  * */
172 typedef enum CINEMA_MODE {
173         OPJ_OFF = 0,                    /** Not Digital Cinema*/
174         OPJ_CINEMA2K_24 = 1,    /** 2K Digital Cinema at 24 fps*/
175         OPJ_CINEMA2K_48 = 2,    /** 2K Digital Cinema at 48 fps*/
176         OPJ_CINEMA4K_24 = 3             /** 4K Digital Cinema at 24 fps*/
177 }OPJ_CINEMA_MODE;
178
179 /** 
180  * Progression order
181  * */
182 typedef enum PROG_ORDER {
183         OPJ_PROG_UNKNOWN = -1,  /**< place-holder */
184         OPJ_LRCP = 0,                   /**< layer-resolution-component-precinct order */
185         OPJ_RLCP = 1,                   /**< resolution-layer-component-precinct order */
186         OPJ_RPCL = 2,                   /**< resolution-precinct-component-layer order */
187         OPJ_PCRL = 3,                   /**< precinct-component-resolution-layer order */
188         OPJ_CPRL = 4                    /**< component-precinct-resolution-layer order */
189 } OPJ_PROG_ORDER;
190
191 /**
192  * Supported image color spaces
193 */
194 typedef enum COLOR_SPACE {
195         OPJ_CLRSPC_UNKNOWN = -1,        /**< not supported by the library */
196         OPJ_CLRSPC_UNSPECIFIED = 0, /**< not specified in the codestream */ 
197         OPJ_CLRSPC_SRGB = 1,            /**< sRGB */
198         OPJ_CLRSPC_GRAY = 2,            /**< grayscale */
199         OPJ_CLRSPC_SYCC = 3                     /**< YUV */
200 } OPJ_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 
391         encoding without offset concerning all the components. */
392         void * mct_data;
393 } opj_cparameters_t;  
394
395 #define OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG      0x0001
396
397 /**
398  * Decompression parameters
399  * */
400 typedef struct opj_dparameters {
401         /** 
402         Set the number of highest resolution levels to be discarded. 
403         The image resolution is effectively divided by 2 to the power of the number of discarded levels. 
404         The reduce factor is limited by the smallest total number of decomposition levels among tiles.
405         if != 0, then original dimension divided by 2^(reduce); 
406         if == 0 or not used, image is decoded to the full resolution 
407         */
408         OPJ_UINT32 cp_reduce;
409         /** 
410         Set the maximum number of quality layers to decode. 
411         If there are less quality layers than the specified number, all the quality layers are decoded.
412         if != 0, then only the first "layer" layers are decoded; 
413         if == 0 or not used, all the quality layers are decoded 
414         */
415         OPJ_UINT32 cp_layer;
416
417         /**@name command line decoder parameters (not used inside the library) */
418         /*@{*/
419         /** input file name */
420         char infile[OPJ_PATH_LEN];
421         /** output file name */
422         char outfile[OPJ_PATH_LEN];
423         /** input file format 0: J2K, 1: JP2, 2: JPT */
424         int decod_format;
425         /** output file format 0: PGX, 1: PxM, 2: BMP */
426         int cod_format;
427
428         /** Decoding area left boundary */
429         OPJ_UINT32 DA_x0;
430         /** Decoding area right boundary */
431         OPJ_UINT32 DA_x1;
432         /** Decoding area up boundary */
433         OPJ_UINT32 DA_y0;
434         /** Decoding area bottom boundary */
435         OPJ_UINT32 DA_y1;
436         /** Verbose mode */
437         OPJ_BOOL m_verbose;
438
439         /** tile number ot the decoded tile*/
440         OPJ_UINT32 tile_index;
441         /** Nb of tile to decode */
442         OPJ_UINT32 nb_tile_to_decode;
443
444         /*@}*/
445
446 /* UniPG>> */ /* NOT YET USED IN THE V2 VERSION OF OPENJPEG */
447         /**@name JPWL decoding parameters */
448         /*@{*/
449         /** activates the JPWL correction capabilities */
450         OPJ_BOOL jpwl_correct;
451         /** expected number of components */
452         int jpwl_exp_comps;
453         /** maximum number of tiles */
454         int jpwl_max_tiles;
455         /*@}*/
456 /* <<UniPG */
457
458         unsigned int flags;
459
460 } opj_dparameters_t;
461
462
463 /**
464  * JPEG2000 codec V2.
465  * */
466 typedef void * opj_codec_t;
467
468 /* 
469 ==========================================================
470    I/O stream typedef definitions
471 ==========================================================
472 */
473
474 /**
475  * Stream open flags.
476  * */
477 /** The stream was opened for reading. */
478 #define OPJ_STREAM_READ OPJ_TRUE
479 /** The stream was opened for writing. */
480 #define OPJ_STREAM_WRITE OPJ_FALSE
481
482 /*
483  * Callback function prototype for read function
484  */
485 typedef OPJ_SIZE_T (* opj_stream_read_fn) (void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data) ;
486
487 /*
488  * Callback function prototype for write function
489  */
490 typedef OPJ_SIZE_T (* opj_stream_write_fn) (void * p_buffer, OPJ_SIZE_T p_nb_bytes, void * p_user_data) ;
491
492 /*
493  * Callback function prototype for skip function
494  */
495 typedef OPJ_OFF_T (* opj_stream_skip_fn) (OPJ_OFF_T p_nb_bytes, void * p_user_data) ;
496
497 /*
498  * Callback function prototype for seek function
499  */
500 typedef OPJ_BOOL (* opj_stream_seek_fn) (OPJ_OFF_T p_nb_bytes, void * p_user_data) ;
501
502 /*
503  * JPEG2000 Stream.
504  */
505 typedef void * opj_stream_t;
506
507 /* 
508 ==========================================================
509    image typedef definitions
510 ==========================================================
511 */
512
513 /**
514  * Defines a single image component
515  * */
516 typedef struct opj_image_comp {
517         /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
518         OPJ_UINT32 dx;
519         /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
520         OPJ_UINT32 dy;
521         /** data width */
522         OPJ_UINT32 w;
523         /** data height */
524         OPJ_UINT32 h;
525         /** x component offset compared to the whole image */
526         OPJ_UINT32 x0;
527         /** y component offset compared to the whole image */
528         OPJ_UINT32 y0;
529         /** precision */
530         OPJ_UINT32 prec;
531         /** image depth in bits */
532         OPJ_UINT32 bpp;
533         /** signed (1) / unsigned (0) */
534         OPJ_UINT32 sgnd;
535         /** number of decoded resolution */
536         OPJ_UINT32 resno_decoded;
537         /** number of division by 2 of the out image compared to the original size of image */
538         OPJ_UINT32 factor;
539         /** image component data */
540         OPJ_INT32 *data;
541 } opj_image_comp_t;
542
543 /** 
544  * Defines image data and characteristics
545  * */
546 typedef struct opj_image {
547         /** XOsiz: horizontal offset from the origin of the reference grid to the left side of the image area */
548         OPJ_UINT32 x0;
549         /** YOsiz: vertical offset from the origin of the reference grid to the top side of the image area */
550         OPJ_UINT32 y0;
551         /** Xsiz: width of the reference grid */
552         OPJ_UINT32 x1;
553         /** Ysiz: height of the reference grid */
554         OPJ_UINT32 y1;
555         /** number of components in the image */
556         OPJ_UINT32 numcomps;
557         /** color space: sRGB, Greyscale or YUV */
558         OPJ_COLOR_SPACE color_space;
559         /** image components */
560         opj_image_comp_t *comps;
561         /** 'restricted' ICC profile */
562         OPJ_BYTE *icc_profile_buf;
563         /** size of ICC profile */
564         OPJ_UINT32 icc_profile_len;
565 } opj_image_t;
566
567
568 /**
569  * Component parameters structure used by the opj_image_create function
570  * */
571 typedef struct opj_image_comptparm {
572         /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
573         OPJ_UINT32 dx;
574         /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
575         OPJ_UINT32 dy;
576         /** data width */
577         OPJ_UINT32 w;
578         /** data height */
579         OPJ_UINT32 h;
580         /** x component offset compared to the whole image */
581         OPJ_UINT32 x0;
582         /** y component offset compared to the whole image */
583         OPJ_UINT32 y0;
584         /** precision */
585         OPJ_UINT32 prec;
586         /** image depth in bits */
587         OPJ_UINT32 bpp;
588         /** signed (1) / unsigned (0) */
589         OPJ_UINT32 sgnd;
590 } opj_image_cmptparm_t;
591
592
593 /* 
594 ==========================================================
595    Information on the JPEG 2000 codestream
596 ==========================================================
597 */
598 /* QUITE EXPERIMENTAL FOR THE MOMENT */
599
600 /**
601  * Index structure : Information concerning a packet inside tile
602  * */
603 typedef struct opj_packet_info {
604         /** packet start position (including SOP marker if it exists) */
605         OPJ_OFF_T start_pos;
606         /** end of packet header position (including EPH marker if it exists)*/
607         OPJ_OFF_T end_ph_pos;
608         /** packet end position */
609         OPJ_OFF_T end_pos;
610         /** packet distorsion */
611         double disto;
612 } opj_packet_info_t;
613
614
615 /* UniPG>> */
616 /**
617  * Marker structure
618  * */
619 typedef struct opj_marker_info {
620         /** marker type */
621         unsigned short int type;
622         /** position in codestream */
623         OPJ_OFF_T pos;
624         /** length, marker val included */
625         int len;
626 } opj_marker_info_t;
627 /* <<UniPG */
628
629 /**
630  * Index structure : Information concerning tile-parts
631 */
632 typedef struct opj_tp_info {
633         /** start position of tile part */
634         int tp_start_pos;
635         /** end position of tile part header */
636         int tp_end_header;
637         /** end position of tile part */
638         int tp_end_pos;
639         /** start packet of tile part */
640         int tp_start_pack;
641         /** number of packets of tile part */
642         int tp_numpacks;
643 } opj_tp_info_t;
644
645 /**
646  * Index structure : information regarding tiles
647 */
648 typedef struct opj_tile_info {
649         /** value of thresh for each layer by tile cfr. Marcela   */
650         double *thresh;
651         /** number of tile */
652         int tileno;
653         /** start position */
654         int start_pos;
655         /** end position of the header */
656         int end_header;
657         /** end position */
658         int end_pos;
659         /** precinct number for each resolution level (width) */
660         int pw[33];
661         /** precinct number for each resolution level (height) */
662         int ph[33];
663         /** precinct size (in power of 2), in X for each resolution level */
664         int pdx[33];
665         /** precinct size (in power of 2), in Y for each resolution level */
666         int pdy[33];
667         /** information concerning packets inside tile */
668         opj_packet_info_t *packet;
669         /** add fixed_quality */
670         int numpix;
671         /** add fixed_quality */
672         double distotile;
673         /** number of markers */
674         int marknum;
675         /** list of markers */
676         opj_marker_info_t *marker;
677         /** actual size of markers array */
678         int maxmarknum;
679         /** number of tile parts */
680         int num_tps;
681         /** information concerning tile parts */
682         opj_tp_info_t *tp;
683 } opj_tile_info_t;
684
685 /**
686  * Index structure of the codestream
687 */
688 typedef struct opj_codestream_info {
689         /** maximum distortion reduction on the whole image (add for Marcela) */
690         double D_max;
691         /** packet number */
692         int packno;
693         /** writing the packet in the index with t2_encode_packets */
694         int index_write;
695         /** image width */
696         int image_w;
697         /** image height */
698         int image_h;
699         /** progression order */
700         OPJ_PROG_ORDER prog;
701         /** tile size in x */
702         int tile_x;
703         /** tile size in y */
704         int tile_y;
705         /** */
706         int tile_Ox;
707         /** */
708         int tile_Oy;
709         /** number of tiles in X */
710         int tw;
711         /** number of tiles in Y */
712         int th;
713         /** component numbers */
714         int numcomps;
715         /** number of layer */
716         int numlayers;
717         /** number of decomposition for each component */
718         int *numdecompos;
719 /* UniPG>> */
720         /** number of markers */
721         int marknum;
722         /** list of markers */
723         opj_marker_info_t *marker;
724         /** actual size of markers array */
725         int maxmarknum;
726 /* <<UniPG */
727         /** main header position */
728         int main_head_start;
729         /** main header position */
730         int main_head_end;
731         /** codestream's size */
732         int codestream_size;
733         /** information regarding tiles inside image */
734         opj_tile_info_t *tile;
735 } opj_codestream_info_t;
736
737 /* <----------------------------------------------------------- */
738 /* new output managment of the codestream information and index */
739
740 /**
741  * Tile-component coding parameters information
742  */
743 typedef struct opj_tccp_info
744 {
745         /** component index */
746         OPJ_UINT32 compno;
747         /** coding style */
748         OPJ_UINT32 csty;
749         /** number of resolutions */
750         OPJ_UINT32 numresolutions;
751         /** code-blocks width */
752         OPJ_UINT32 cblkw;
753         /** code-blocks height */
754         OPJ_UINT32 cblkh;
755         /** code-block coding style */
756         OPJ_UINT32 cblksty;
757         /** discrete wavelet transform identifier */
758         OPJ_UINT32 qmfbid;
759         /** quantisation style */
760         OPJ_UINT32 qntsty;
761         /** stepsizes used for quantization */
762         OPJ_UINT32 stepsizes_mant[OPJ_J2K_MAXBANDS];
763         /** stepsizes used for quantization */
764         OPJ_UINT32 stepsizes_expn[OPJ_J2K_MAXBANDS];
765         /** number of guard bits */
766         OPJ_UINT32 numgbits;
767         /** Region Of Interest shift */
768         OPJ_INT32 roishift;
769         /** precinct width */
770         OPJ_UINT32 prcw[OPJ_J2K_MAXRLVLS];
771         /** precinct height */
772         OPJ_UINT32 prch[OPJ_J2K_MAXRLVLS];
773 }
774 opj_tccp_info_t;
775
776 /**
777  * Tile coding parameters information
778  */
779 typedef struct opj_tile_v2_info {
780
781         /** number (index) of tile */
782         int tileno;
783         /** coding style */
784         OPJ_UINT32 csty;
785         /** progression order */
786         OPJ_PROG_ORDER prg;
787         /** number of layers */
788         OPJ_UINT32 numlayers;
789         /** multi-component transform identifier */
790         OPJ_UINT32 mct;
791
792         /** information concerning tile component parameters*/
793         opj_tccp_info_t *tccp_info;
794
795 } opj_tile_info_v2_t;
796
797 /**
798  * Information structure about the codestream (FIXME should be expand and enhance)
799  */
800 typedef struct opj_codestream_info_v2 {
801         /* Tile info */
802         /** tile origin in x = XTOsiz */
803         OPJ_UINT32 tx0;
804         /** tile origin in y = YTOsiz */
805         OPJ_UINT32 ty0;
806         /** tile size in x = XTsiz */
807         OPJ_UINT32 tdx;
808         /** tile size in y = YTsiz */
809         OPJ_UINT32 tdy;
810         /** number of tiles in X */
811         OPJ_UINT32 tw;
812         /** number of tiles in Y */
813         OPJ_UINT32 th;
814
815         /** number of components*/
816         OPJ_UINT32 nbcomps;
817
818         /** Default information regarding tiles inside image */
819         opj_tile_info_v2_t m_default_tile_info;
820
821         /** information regarding tiles inside image */
822         opj_tile_info_v2_t *tile_info; /* FIXME not used for the moment */
823
824 } opj_codestream_info_v2_t;
825
826
827 /**
828  * Index structure about a tile part
829  */
830 typedef struct opj_tp_index {
831         /** start position */
832         OPJ_OFF_T start_pos;
833         /** end position of the header */
834         OPJ_OFF_T end_header;
835         /** end position */
836         OPJ_OFF_T end_pos;
837
838 } opj_tp_index_t;
839
840 /**
841  * Index structure about a tile
842  */
843 typedef struct opj_tile_index {
844         /** tile index */
845         OPJ_UINT32 tileno;
846
847         /** number of tile parts */
848         OPJ_UINT32 nb_tps;
849         /** current nb of tile part (allocated)*/
850         OPJ_UINT32 current_nb_tps;
851         /** current tile-part index */
852         OPJ_UINT32 current_tpsno;
853         /** information concerning tile parts */
854         opj_tp_index_t *tp_index;
855
856         /* UniPG>> */ /* NOT USED FOR THE MOMENT IN THE V2 VERSION */
857                 /** number of markers */
858                 OPJ_UINT32 marknum;
859                 /** list of markers */
860                 opj_marker_info_t *marker;
861                 /** actual size of markers array */
862                 OPJ_UINT32 maxmarknum;
863         /* <<UniPG */
864
865         /** packet number */
866         OPJ_UINT32 nb_packet;
867         /** information concerning packets inside tile */
868         opj_packet_info_t *packet_index;
869
870 } opj_tile_index_t;
871
872 /**
873  * Index structure of the codestream (FIXME should be expand and enhance)
874  */
875 typedef struct opj_codestream_index {
876         /** main header start position (SOC position) */
877         OPJ_OFF_T main_head_start;
878         /** main header end position (first SOT position) */
879         OPJ_OFF_T main_head_end;
880
881         /** codestream's size */
882         OPJ_UINT64 codestream_size;
883
884 /* UniPG>> */ /* NOT USED FOR THE MOMENT IN THE V2 VERSION */
885         /** number of markers */
886         OPJ_UINT32 marknum;
887         /** list of markers */
888         opj_marker_info_t *marker;
889         /** actual size of markers array */
890         OPJ_UINT32 maxmarknum;
891 /* <<UniPG */
892
893         /** */
894         OPJ_UINT32 nb_of_tiles;
895         /** */
896         opj_tile_index_t *tile_index; /* FIXME not used for the moment */
897
898 }opj_codestream_index_t;
899 /* -----------------------------------------------------------> */
900
901 /*
902 ==========================================================
903    Metadata from the JP2file
904 ==========================================================
905 */
906
907 /**
908  * Info structure of the JP2 file
909  * EXPERIMENTAL FOR THE MOMENT
910  */
911 typedef struct opj_jp2_metadata {
912         /** */
913         OPJ_INT32       not_used;
914
915 } opj_jp2_metadata_t;
916
917 /**
918  * Index structure of the JP2 file
919  * EXPERIMENTAL FOR THE MOMENT
920  */
921 typedef struct opj_jp2_index {
922         /** */
923         OPJ_INT32       not_used;
924
925 } opj_jp2_index_t;
926
927
928 #ifdef __cplusplus
929 extern "C" {
930 #endif
931
932
933 /* 
934 ==========================================================
935    openjpeg version
936 ==========================================================
937 */
938
939 /* Get the version of the openjpeg library*/
940 OPJ_API const char * OPJ_CALLCONV opj_version(void);
941
942 /* 
943 ==========================================================
944    image functions definitions
945 ==========================================================
946 */
947
948 /**
949  * Create an image
950  *
951  * @param numcmpts      number of components
952  * @param cmptparms     components parameters
953  * @param clrspc        image color space
954  * @return returns      a new image structure if successful, returns NULL otherwise
955  * */
956 OPJ_API opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
957
958 /**
959  * Deallocate any resources associated with an image
960  *
961  * @param image         image to be destroyed
962  */
963 OPJ_API void OPJ_CALLCONV opj_image_destroy(opj_image_t *image);
964
965 /**
966  * Creates an image without allocating memory for the image (used in the new version of the library).
967  *
968  * @param       numcmpts    the number of components
969  * @param       cmptparms   the components parameters
970  * @param       clrspc      the image color space
971  *
972  * @return      a new image structure if successful, NULL otherwise.
973 */
974 OPJ_API opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts, opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
975
976 /* 
977 ==========================================================
978    stream functions definitions
979 ==========================================================
980 */
981
982 /**
983  * Creates an abstract stream. This function does nothing except allocating memory and initializing the abstract stream.
984  *
985  * @param       p_is_input              if set to true then the stream will be an input stream, an output stream else.
986  *
987  * @return      a stream object.
988 */
989 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_default_create(OPJ_BOOL p_is_input);
990
991 /**
992  * Creates an abstract stream. This function does nothing except allocating memory and initializing the abstract stream.
993  *
994  * @param       p_buffer_size  FIXME DOC
995  * @param       p_is_input              if set to true then the stream will be an input stream, an output stream else.
996  *
997  * @return      a stream object.
998 */
999 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size, OPJ_BOOL p_is_input);
1000
1001 /**
1002  * Destroys a stream created by opj_create_stream. This function does NOT close the abstract stream. If needed the user must
1003  * close its own implementation of the stream.
1004  *
1005  * @param       p_stream        the stream to destroy.
1006  */
1007 OPJ_DEPRECATED(OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream));
1008
1009 /**
1010  * Destroys a stream created by opj_create_stream. This function does NOT close the abstract stream. 
1011  * If needed the user must close its own implementation of the stream.
1012  *
1013  * @param       p_stream        the stream to destroy.
1014  */
1015 OPJ_API void OPJ_CALLCONV opj_stream_destroy_v3(opj_stream_t* p_stream);
1016  
1017 /**
1018  * Sets the given function to be used as a read function.
1019  * @param               p_stream        the stream to modify
1020  * @param               p_function      the function to use a read function.
1021 */
1022 OPJ_API void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream, opj_stream_read_fn p_function);
1023
1024 /**
1025  * Sets the given function to be used as a write function.
1026  * @param               p_stream        the stream to modify
1027  * @param               p_function      the function to use a write function.
1028 */
1029 OPJ_API void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream, opj_stream_write_fn p_function);
1030
1031 /**
1032  * Sets the given function to be used as a skip function.
1033  * @param               p_stream        the stream to modify
1034  * @param               p_function      the function to use a skip function.
1035 */
1036 OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream, opj_stream_skip_fn p_function);
1037
1038 /**
1039  * Sets the given function to be used as a seek function, the stream is then seekable.
1040  * @param               p_stream        the stream to modify
1041  * @param               p_function      the function to use a skip function.
1042 */
1043 OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream, opj_stream_seek_fn p_function);
1044
1045 /**
1046  * Sets the given data to be used as a user data for the stream.
1047  * @param               p_stream        the stream to modify
1048  * @param               p_data          the data to set.
1049 */
1050 OPJ_API void OPJ_CALLCONV opj_stream_set_user_data (opj_stream_t* p_stream, void * p_data);
1051
1052 /**
1053  * Sets the length of the user data for the stream.
1054  *
1055  * @param p_stream    the stream to modify
1056  * @param data_length length of the user_data.
1057 */
1058 OPJ_API void OPJ_CALLCONV opj_stream_set_user_data_length(opj_stream_t* p_stream, OPJ_UINT64 data_length);
1059
1060 /**
1061  * Helper function.
1062  * Sets the stream to be a file stream. The FILE must have been open previously.
1063  * @param p_file            the file stream to operate on
1064  * @param p_is_read_stream  whether the stream is a read stream (true) or not (false)
1065 */
1066 OPJ_DEPRECATED(OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream (FILE * p_file, OPJ_BOOL p_is_read_stream));
1067
1068 /**
1069  * Create a stream from a file identified with its filename with default parameters (helper function)
1070  * @param fname             the filename of the file to stream
1071  * @param p_is_read_stream  whether the stream is a read stream (true) or not (false)
1072 */
1073 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream_v3 (const char *fname, OPJ_BOOL p_is_read_stream);
1074  
1075 /**
1076  * FIXME DOC
1077  * @param p_file            the file stream to operate on
1078  * @param p_buffer_size     size of the chunk used to stream
1079  * @param p_is_read_stream  whether the stream is a read stream (true) or not (false)
1080 */
1081 OPJ_DEPRECATED(OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream (FILE * p_file, 
1082                                                                   OPJ_SIZE_T p_buffer_size,
1083                                                                   OPJ_BOOL p_is_read_stream));
1084
1085 /** Create a stream from a file identified with its filename with a specific buffer size
1086  * @param fname             the filename of the file to stream
1087  * @param p_buffer_size     size of the chunk used to stream
1088  * @param p_is_read_stream  whether the stream is a read stream (true) or not (false)
1089 */
1090 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream_v3 (const char *fname, 
1091                                                                      OPJ_SIZE_T p_buffer_size,
1092                                                                      OPJ_BOOL p_is_read_stream);
1093  
1094 /* 
1095 ==========================================================
1096    event manager functions definitions
1097 ==========================================================
1098 */
1099 /**
1100  * Set the info handler use by openjpeg.
1101  * @param p_codec       the codec previously initialise
1102  * @param p_callback    the callback function which will be used
1103  * @param p_user_data   client object where will be returned the message
1104 */
1105 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_info_handler(opj_codec_t * p_codec, 
1106                                                    opj_msg_callback p_callback,
1107                                                    void * p_user_data);
1108 /**
1109  * Set the warning handler use by openjpeg.
1110  * @param p_codec       the codec previously initialise
1111  * @param p_callback    the callback function which will be used
1112  * @param p_user_data   client object where will be returned the message
1113 */
1114 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_warning_handler(opj_codec_t * p_codec,
1115                                                       opj_msg_callback p_callback,
1116                                                       void * p_user_data);
1117 /**
1118  * Set the error handler use by openjpeg.
1119  * @param p_codec       the codec previously initialise
1120  * @param p_callback    the callback function which will be used
1121  * @param p_user_data   client object where will be returned the message
1122 */
1123 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_error_handler(opj_codec_t * p_codec, 
1124                                                     opj_msg_callback p_callback,
1125                                                     void * p_user_data);
1126
1127 /* 
1128 ==========================================================
1129    codec functions definitions
1130 ==========================================================
1131 */
1132
1133 /**
1134  * Creates a J2K/JP2 decompression structure
1135  * @param format                Decoder to select
1136  *
1137  * @return Returns a handle to a decompressor if successful, returns NULL otherwise
1138  * */
1139 OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_decompress(OPJ_CODEC_FORMAT format);
1140
1141 /**
1142  * Destroy a decompressor handle
1143  *
1144  * @param       p_codec                 decompressor handle to destroy
1145  */
1146 OPJ_API void OPJ_CALLCONV opj_destroy_codec(opj_codec_t * p_codec);
1147
1148 /**
1149  * Read after the codestream if necessary
1150  * @param       p_codec                 the JPEG2000 codec to read.
1151  * @param       p_stream                the JPEG2000 stream.
1152  */
1153 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_end_decompress (      opj_codec_t *p_codec,
1154                                                                                                         opj_stream_t *p_stream);
1155
1156
1157 /**
1158  * Set decoding parameters to default values
1159  * @param parameters Decompression parameters
1160  */
1161 OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters(opj_dparameters_t *parameters);
1162
1163 /**
1164  * Setup the decoder with decompression parameters provided by the user and with the message handler
1165  * provided by the user.
1166  *
1167  * @param p_codec               decompressor handler
1168  * @param parameters    decompression parameters
1169  *
1170  * @return true                 if the decoder is correctly set
1171  */
1172 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_setup_decoder(opj_codec_t *p_codec,
1173                                                                                                 opj_dparameters_t *parameters );
1174
1175 /**
1176  * Decodes an image header.
1177  *
1178  * @param       p_stream                the jpeg2000 stream.
1179  * @param       p_codec                 the jpeg2000 codec to read.
1180  * @param       p_image                 the image structure initialized with the characteristics of encoded image.
1181  *
1182  * @return true                         if the main header of the codestream and the JP2 header is correctly read.
1183  */
1184 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_read_header ( opj_stream_t *p_stream,
1185                                                                                                 opj_codec_t *p_codec,
1186                                                                                                 opj_image_t **p_image);
1187
1188 /**
1189  * Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading.
1190  *
1191  * @param       p_codec                 the jpeg2000 codec.
1192  * @param       p_image         the decoded image previously setted by opj_read_header
1193  * @param       p_start_x               the left position of the rectangle to decode (in image coordinates).
1194  * @param       p_end_x                 the right position of the rectangle to decode (in image coordinates).
1195  * @param       p_start_y               the up position of the rectangle to decode (in image coordinates).
1196  * @param       p_end_y                 the bottom position of the rectangle to decode (in image coordinates).
1197  *
1198  * @return      true                    if the area could be set.
1199  */
1200 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_decode_area(      opj_codec_t *p_codec,
1201                                                                                                         opj_image_t* p_image,
1202                                                                                                         OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
1203                                                                                                         OPJ_INT32 p_end_x, OPJ_INT32 p_end_y );
1204
1205 /**
1206  * Decode an image from a JPEG-2000 codestream
1207  *
1208  * @param p_decompressor        decompressor handle
1209  * @param p_stream                      Input buffer stream
1210  * @param p_image                       the decoded image
1211  * @return                                      true if success, otherwise false
1212  * */
1213 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decode(   opj_codec_t *p_decompressor,
1214                                             opj_stream_t *p_stream,
1215                                             opj_image_t *p_image);
1216
1217 /**
1218  * Get the decoded tile from the codec
1219  *
1220  * @param       p_codec                 the jpeg2000 codec.
1221  * @param       p_stream                input streamm
1222  * @param       p_image                 output image
1223  * @param       tile_index              index of the tile which will be decode
1224  *
1225  * @return                                      true if success, otherwise false
1226  */
1227 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_get_decoded_tile(     opj_codec_t *p_codec,
1228                                                                                                         opj_stream_t *p_stream,
1229                                                                                                         opj_image_t *p_image,
1230                                                                                                         OPJ_UINT32 tile_index);
1231
1232 /**
1233  * Set the resolution factor of the decoded image
1234  * @param       p_codec                 the jpeg2000 codec.
1235  * @param       res_factor              resolution factor to set
1236  *
1237  * @return                                      true if success, otherwise false
1238  */
1239 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_decoded_resolution_factor(opj_codec_t *p_codec, OPJ_UINT32 res_factor);
1240
1241 /**
1242  * Writes a tile with the given data.
1243  *
1244  * @param       p_codec                 the jpeg2000 codec.
1245  * @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.
1246  * @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.
1247  * @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 
1248  *                              tile_width * tile_height * component_size. component_size can be 1,2 or 4 bytes, depending on the precision of the given component.
1249  * @param       p_stream                        the stream to write data to.
1250  *
1251  * @return      true if the data could be written.
1252  */
1253 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_write_tile (  opj_codec_t *p_codec,
1254                                                                                                 OPJ_UINT32 p_tile_index,
1255                                                                                                 OPJ_BYTE * p_data,
1256                                                                                                 OPJ_UINT32 p_data_size,
1257                                                                                                 opj_stream_t *p_stream );
1258
1259 /**
1260  * Reads a tile header. This function is compulsory and allows one to know the size of the tile thta will be decoded.
1261  * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
1262  *
1263  * @param       p_codec                 the jpeg2000 codec.
1264  * @param       p_tile_index    pointer to a value that will hold the index of the tile being decoded, in case of success.
1265  * @param       p_data_size             pointer to a value that will hold the maximum size of the decoded data, in case of success. In case
1266  *                                                      of truncated codestreams, the actual number of bytes decoded may be lower. The computation of the size is the same
1267  *                                                      as depicted in opj_write_tile.
1268  * @param       p_tile_x0               pointer to a value that will hold the x0 pos of the tile (in the image).
1269  * @param       p_tile_y0               pointer to a value that will hold the y0 pos of the tile (in the image).
1270  * @param       p_tile_x1               pointer to a value that will hold the x1 pos of the tile (in the image).
1271  * @param       p_tile_y1               pointer to a value that will hold the y1 pos of the tile (in the image).
1272  * @param       p_nb_comps              pointer to a value that will hold the number of components in the tile.
1273  * @param       p_should_go_on  pointer to a boolean that will hold the fact that the decoding should go on. In case the
1274  *                                                      codestream is over at the time of the call, the value will be set to false. The user should then stop
1275  *                                                      the decoding.
1276  * @param       p_stream                the stream to decode.
1277  * @return      true                    if the tile header could be decoded. In case the decoding should end, the returned value is still true.
1278  *                                                      returning false may be the result of a shortage of memory or an internal error.
1279  */
1280 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_read_tile_header(     opj_codec_t *p_codec,
1281                                                                                                 opj_stream_t * p_stream,
1282                                                                                                 OPJ_UINT32 * p_tile_index,
1283                                                                                                 OPJ_UINT32 * p_data_size,
1284                                                                                                 OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0,
1285                                                                                                 OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1,
1286                                                                                                 OPJ_UINT32 * p_nb_comps,
1287                                                                                                 OPJ_BOOL * p_should_go_on );
1288
1289 /**
1290  * Reads a tile data. This function is compulsory and allows one to decode tile data. opj_read_tile_header should be called before.
1291  * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
1292  *
1293  * @param       p_codec                 the jpeg2000 codec.
1294  * @param       p_tile_index    the index of the tile being decoded, this should be the value set by opj_read_tile_header.
1295  * @param       p_data                  pointer to a memory block that will hold the decoded data.
1296  * @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.
1297  * @param       p_stream                the stream to decode.
1298  *
1299  * @return      true                    if the data could be decoded.
1300  */
1301 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decode_tile_data(     opj_codec_t *p_codec,
1302                                                                                                         OPJ_UINT32 p_tile_index,
1303                                                                                                         OPJ_BYTE * p_data,
1304                                                                                                         OPJ_UINT32 p_data_size,
1305                                                                                                         opj_stream_t *p_stream );
1306
1307 /* COMPRESSION FUNCTIONS*/
1308
1309 /**
1310  * Creates a J2K/JP2 compression structure
1311  * @param       format          Coder to select
1312  * @return                              Returns a handle to a compressor if successful, returns NULL otherwise
1313  */
1314 OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format);
1315
1316 /**
1317 Set encoding parameters to default values, that means : 
1318 <ul>
1319 <li>Lossless
1320 <li>1 tile
1321 <li>Size of precinct : 2^15 x 2^15 (means 1 precinct)
1322 <li>Size of code-block : 64 x 64
1323 <li>Number of resolutions: 6
1324 <li>No SOP marker in the codestream
1325 <li>No EPH marker in the codestream
1326 <li>No sub-sampling in x or y direction
1327 <li>No mode switch activated
1328 <li>Progression order: LRCP
1329 <li>No index file
1330 <li>No ROI upshifted
1331 <li>No offset of the origin of the image
1332 <li>No offset of the origin of the tiles
1333 <li>Reversible DWT 5-3
1334 </ul>
1335 @param parameters Compression parameters
1336 */
1337 OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(opj_cparameters_t *parameters);
1338
1339 /**
1340  * Setup the encoder parameters using the current image and using user parameters.
1341  * @param p_codec               Compressor handle
1342  * @param parameters    Compression parameters
1343  * @param image                 Input filled image
1344  */
1345 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_setup_encoder(opj_codec_t *p_codec, 
1346                                                                                                 opj_cparameters_t *parameters, 
1347                                                                                                 opj_image_t *image);
1348
1349 /**
1350  * Start to compress the current image.
1351  * @param p_codec               Compressor handle
1352  * @param image             Input filled image
1353  * @param p_stream              Input stgream
1354  */
1355 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_start_compress (      opj_codec_t *p_codec,
1356                                                                                                         opj_image_t * p_image,
1357                                                                                                         opj_stream_t *p_stream);
1358
1359 /**
1360  * End to compress the current image.
1361  * @param p_codec               Compressor handle
1362  * @param p_stream              Input stgream
1363  */
1364 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_end_compress (opj_codec_t *p_codec,
1365                                                                                                 opj_stream_t *p_stream);
1366
1367 /**
1368  * Encode an image into a JPEG-2000 codestream
1369  * @param p_codec               compressor handle
1370  * @param p_stream              Output buffer stream
1371  *
1372  * @return                              Returns true if successful, returns false otherwise
1373  */
1374 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_encode(opj_codec_t *p_codec,
1375                                          opj_stream_t *p_stream);
1376 /*
1377 ==========================================================
1378    codec output functions definitions
1379 ==========================================================
1380 */
1381 /* EXPERIMENTAL FUNCTIONS FOR NOW, USED ONLY IN J2K_DUMP*/
1382
1383 /**
1384 Destroy Codestream information after compression or decompression
1385 @param cstr_info Codestream information structure
1386 */
1387 OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_v2_t **cstr_info);
1388
1389
1390 /**
1391  * Dump the codec information into the output stream
1392  *
1393  * @param       p_codec                 the jpeg2000 codec.
1394  * @param       info_flag               type of information dump.
1395  * @param       output_stream   output stream where dump the informations get from the codec.
1396  *
1397  */
1398 OPJ_API void OPJ_CALLCONV opj_dump_codec(       opj_codec_t *p_codec,
1399                                                                                         OPJ_INT32 info_flag,
1400                                                                                         FILE* output_stream);
1401
1402 /**
1403  * Get the codestream information from the codec
1404  *
1405  * @param       p_codec                 the jpeg2000 codec.
1406  *
1407  * @return                                      a pointer to a codestream information structure.
1408  *
1409  */
1410 OPJ_API opj_codestream_info_v2_t* OPJ_CALLCONV opj_get_cstr_info(opj_codec_t *p_codec);
1411
1412 /**
1413  * Get the codestream index from the codec
1414  *
1415  * @param       p_codec                 the jpeg2000 codec.
1416  *
1417  * @return                                      a pointer to a codestream index structure.
1418  *
1419  */
1420 OPJ_API opj_codestream_index_t * OPJ_CALLCONV opj_get_cstr_index(opj_codec_t *p_codec);
1421
1422 OPJ_API void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t **p_cstr_index);
1423
1424
1425 /**
1426  * Get the JP2 file information from the codec FIXME
1427  *
1428  * @param       p_codec                 the jpeg2000 codec.
1429  *
1430  * @return                                      a pointer to a JP2 metadata structure.
1431  *
1432  */
1433 OPJ_API opj_jp2_metadata_t* OPJ_CALLCONV opj_get_jp2_metadata(opj_codec_t *p_codec);
1434
1435 /**
1436  * Get the JP2 file index from the codec FIXME
1437  *
1438  * @param       p_codec                 the jpeg2000 codec.
1439  *
1440  * @return                                      a pointer to a JP2 index structure.
1441  *
1442  */
1443 OPJ_API opj_jp2_index_t* OPJ_CALLCONV opj_get_jp2_index(opj_codec_t *p_codec);
1444
1445
1446 /*
1447 ==========================================================
1448    MCT functions
1449 ==========================================================
1450 */
1451
1452 /**
1453  * Sets the MCT matrix to use.
1454  *
1455  * @param       parameters              the parameters to change.
1456  * @param       pEncodingMatrix the encoding matrix.
1457  * @param       p_dc_shift              the dc shift coefficients to use.
1458  * @param       pNbComp                 the number of components of the image.
1459  *
1460  * @return      true if the parameters could be set.
1461  */
1462 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_MCT( opj_cparameters_t *parameters,
1463                                                    OPJ_FLOAT32 * pEncodingMatrix,
1464                                                    OPJ_INT32 * p_dc_shift,
1465                                                    OPJ_UINT32 pNbComp);
1466
1467
1468
1469 #ifdef __cplusplus
1470 }
1471 #endif
1472
1473 #endif /* OPENJPEG_H */