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