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