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