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