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