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