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