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