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