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