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