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.
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.
21 * Redistribution and use in source and binary forms, with or without
22 * modification, are permitted provided that the following conditions
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.
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.
47 ==========================================================
49 ==========================================================
53 The inline keyword is supported by C99 but not by C90.
54 Most compilers implement their own version of this keyword ...
58 #define INLINE __forceinline
59 #elif defined(__GNUC__)
60 #define INLINE __inline__
61 #elif defined(__MWERKS__)
64 /* add other compilers here ... */
66 #endif /* defined(<Compiler>) */
69 /* deprecated attribute */
71 #define OPJ_DEPRECATED(func) func __attribute__ ((deprecated))
72 #elif defined(_MSC_VER)
73 #define OPJ_DEPRECATED(func) __declspec(deprecated) func
75 #pragma message("WARNING: You need to implement DEPRECATED for this compiler")
76 #define OPJ_DEPRECATED(func) func
79 #if defined(__GNUC__) && __GNUC__ >= 6
80 #define OPJ_DEPRECATED_STRUCT_MEMBER(memb, msg) __attribute__ ((deprecated(msg))) memb
82 #define OPJ_DEPRECATED_STRUCT_MEMBER(memb, msg) memb
85 #if defined(OPJ_STATIC) || !defined(_WIN32)
86 /* http://gcc.gnu.org/wiki/Visibility */
87 # if !defined(_WIN32) && __GNUC__ >= 4
88 # if defined(OPJ_STATIC) /* static library uses "hidden" */
89 # define OPJ_API __attribute__ ((visibility ("hidden")))
91 # define OPJ_API __attribute__ ((visibility ("default")))
93 # define OPJ_LOCAL __attribute__ ((visibility ("hidden")))
100 # define OPJ_CALLCONV __stdcall
102 The following ifdef block is the standard way of creating macros which make exporting
103 from a DLL simpler. All files within this DLL are compiled with the OPJ_EXPORTS
104 symbol defined on the command line. this symbol should not be defined on any project
105 that uses this DLL. This way any other project whose source files include this file see
106 OPJ_API functions as being imported from a DLL, whereas this DLL sees symbols
107 defined with this macro as being exported.
109 # if defined(OPJ_EXPORTS) || defined(DLL_EXPORT)
110 # define OPJ_API __declspec(dllexport)
112 # define OPJ_API __declspec(dllimport)
113 # endif /* OPJ_EXPORTS */
114 #endif /* !OPJ_STATIC || !_WIN32 */
116 typedef int OPJ_BOOL;
120 typedef char OPJ_CHAR;
121 typedef float OPJ_FLOAT32;
122 typedef double OPJ_FLOAT64;
123 typedef unsigned char OPJ_BYTE;
127 typedef int8_t OPJ_INT8;
128 typedef uint8_t OPJ_UINT8;
129 typedef int16_t OPJ_INT16;
130 typedef uint16_t OPJ_UINT16;
131 typedef int32_t OPJ_INT32;
132 typedef uint32_t OPJ_UINT32;
133 typedef int64_t OPJ_INT64;
134 typedef uint64_t OPJ_UINT64;
136 typedef int64_t OPJ_OFF_T; /* 64-bit file offset type */
139 typedef size_t OPJ_SIZE_T;
141 #include "opj_config.h"
143 /* Avoid compile-time warning because parameter is not used */
144 #define OPJ_ARG_NOT_USED(x) (void)(x)
147 ==========================================================
148 Useful constant definitions
149 ==========================================================
152 #define OPJ_PATH_LEN 4096 /**< Maximum allowed size for filenames */
154 #define OPJ_J2K_MAXRLVLS 33 /**< Number of maximum resolution level authorized */
155 #define OPJ_J2K_MAXBANDS (3*OPJ_J2K_MAXRLVLS-2) /**< Number of maximum sub-band linked to number of resolution level */
157 #define OPJ_J2K_DEFAULT_NB_SEGS 10
158 #define OPJ_J2K_STREAM_CHUNK_SIZE 0x100000 /** 1 mega by default */
159 #define OPJ_J2K_DEFAULT_HEADER_SIZE 1000
160 #define OPJ_J2K_MCC_DEFAULT_NB_RECORDS 10
161 #define OPJ_J2K_MCT_DEFAULT_NB_RECORDS 10
163 /* UniPG>> */ /* NOT YET USED IN THE V2 VERSION OF OPENJPEG */
164 #define JPWL_MAX_NO_TILESPECS 16 /**< Maximum number of tile parts expected by JPWL: increase at your will */
165 #define JPWL_MAX_NO_PACKSPECS 16 /**< Maximum number of packet parts expected by JPWL: increase at your will */
166 #define JPWL_MAX_NO_MARKERS 512 /**< Maximum number of JPWL markers: increase at your will */
167 #define JPWL_PRIVATEINDEX_NAME "jpwl_index_privatefilename" /**< index file name used when JPWL is on */
168 #define JPWL_EXPECTED_COMPONENTS 3 /**< Expect this number of components, so you'll find better the first EPB */
169 #define JPWL_MAXIMUM_TILES 8192 /**< Expect this maximum number of tiles, to avoid some crashes */
170 #define JPWL_MAXIMUM_HAMMING 2 /**< Expect this maximum number of bit errors in marker id's */
171 #define JPWL_MAXIMUM_EPB_ROOM 65450 /**< Expect this maximum number of bytes for composition of EPBs */
175 * EXPERIMENTAL FOR THE MOMENT
176 * Supported options about file information used only in j2k_dump
178 #define OPJ_IMG_INFO 1 /**< Basic image information provided to the user */
179 #define OPJ_J2K_MH_INFO 2 /**< Codestream information based only on the main header */
180 #define OPJ_J2K_TH_INFO 4 /**< Tile information based on the current tile header */
181 #define OPJ_J2K_TCH_INFO 8 /**< Tile/Component information of all tiles */
182 #define OPJ_J2K_MH_IND 16 /**< Codestream index based only on the main header */
183 #define OPJ_J2K_TH_IND 32 /**< Tile index based on the current tile */
184 /*FIXME #define OPJ_J2K_CSTR_IND 48*/ /**< */
185 #define OPJ_JP2_INFO 128 /**< JP2 file information */
186 #define OPJ_JP2_IND 256 /**< JP2 file index */
189 * JPEG 2000 Profiles, see Table A.10 from 15444-1 (updated in various AMD)
190 * These values help choosing the RSIZ value for the J2K codestream.
191 * The RSIZ value triggers various encoding options, as detailed in Table A.10.
192 * If OPJ_PROFILE_PART2 is chosen, it has to be combined with one or more extensions
193 * described hereunder.
194 * Example: rsiz = OPJ_PROFILE_PART2 | OPJ_EXTENSION_MCT;
195 * For broadcast profiles, the OPJ_PROFILE value has to be combined with the targeted
196 * mainlevel (3-0 LSB, value between 0 and 11):
197 * Example: rsiz = OPJ_PROFILE_BC_MULTI | 0x0005; (here mainlevel 5)
198 * For IMF profiles, the OPJ_PROFILE value has to be combined with the targeted mainlevel
199 * (3-0 LSB, value between 0 and 11) and sublevel (7-4 LSB, value between 0 and 9):
200 * Example: rsiz = OPJ_PROFILE_IMF_2K | 0x0040 | 0x0005; (here main 5 and sublevel 4)
202 #define OPJ_PROFILE_NONE 0x0000 /** no profile, conform to 15444-1 */
203 #define OPJ_PROFILE_0 0x0001 /** Profile 0 as described in 15444-1,Table A.45 */
204 #define OPJ_PROFILE_1 0x0002 /** Profile 1 as described in 15444-1,Table A.45 */
205 #define OPJ_PROFILE_PART2 0x8000 /** At least 1 extension defined in 15444-2 (Part-2) */
206 #define OPJ_PROFILE_CINEMA_2K 0x0003 /** 2K cinema profile defined in 15444-1 AMD1 */
207 #define OPJ_PROFILE_CINEMA_4K 0x0004 /** 4K cinema profile defined in 15444-1 AMD1 */
208 #define OPJ_PROFILE_CINEMA_S2K 0x0005 /** Scalable 2K cinema profile defined in 15444-1 AMD2 */
209 #define OPJ_PROFILE_CINEMA_S4K 0x0006 /** Scalable 4K cinema profile defined in 15444-1 AMD2 */
210 #define OPJ_PROFILE_CINEMA_LTS 0x0007 /** Long term storage cinema profile defined in 15444-1 AMD2 */
211 #define OPJ_PROFILE_BC_SINGLE 0x0100 /** Single Tile Broadcast profile defined in 15444-1 AMD3 */
212 #define OPJ_PROFILE_BC_MULTI 0x0200 /** Multi Tile Broadcast profile defined in 15444-1 AMD3 */
213 #define OPJ_PROFILE_BC_MULTI_R 0x0300 /** Multi Tile Reversible Broadcast profile defined in 15444-1 AMD3 */
214 #define OPJ_PROFILE_IMF_2K 0x0400 /** 2K Single Tile Lossy IMF profile defined in 15444-1 AMD 8 */
215 #define OPJ_PROFILE_IMF_4K 0x0500 /** 4K Single Tile Lossy IMF profile defined in 15444-1 AMD 8 */
216 #define OPJ_PROFILE_IMF_8K 0x0600 /** 8K Single Tile Lossy IMF profile defined in 15444-1 AMD 8 */
217 #define OPJ_PROFILE_IMF_2K_R 0x0700 /** 2K Single/Multi Tile Reversible IMF profile defined in 15444-1 AMD 8 */
218 #define OPJ_PROFILE_IMF_4K_R 0x0800 /** 4K Single/Multi Tile Reversible IMF profile defined in 15444-1 AMD 8 */
219 #define OPJ_PROFILE_IMF_8K_R 0x0900 /** 8K Single/Multi Tile Reversible IMF profile defined in 15444-1 AMD 8 */
222 * JPEG 2000 Part-2 extensions
224 #define OPJ_EXTENSION_NONE 0x0000 /** No Part-2 extension */
225 #define OPJ_EXTENSION_MCT 0x0100 /** Custom MCT support */
228 * JPEG 2000 profile macros
230 #define OPJ_IS_CINEMA(v) (((v) >= OPJ_PROFILE_CINEMA_2K)&&((v) <= OPJ_PROFILE_CINEMA_S4K))
231 #define OPJ_IS_STORAGE(v) ((v) == OPJ_PROFILE_CINEMA_LTS)
232 #define OPJ_IS_BROADCAST(v) (((v) >= OPJ_PROFILE_BC_SINGLE)&&((v) <= ((OPJ_PROFILE_BC_MULTI_R) | (0x000b))))
233 #define OPJ_IS_IMF(v) (((v) >= OPJ_PROFILE_IMF_2K)&&((v) <= ((OPJ_PROFILE_IMF_8K_R) | (0x009b))))
234 #define OPJ_IS_PART2(v) ((v) & OPJ_PROFILE_PART2)
236 #define OPJ_GET_IMF_PROFILE(v) ((v) & 0xff00) /** Extract IMF profile without mainlevel/sublevel */
237 #define OPJ_GET_IMF_MAINLEVEL(v) ((v) & 0xf) /** Extract IMF main level */
238 #define OPJ_GET_IMF_SUBLEVEL(v) (((v) >> 4) & 0xf) /** Extract IMF sub level */
240 #define OPJ_IMF_MAINLEVEL_MAX 11 /** Maximum main level */
242 /** Max. Components Sampling Rate (MSamples/sec) per IMF main level */
243 #define OPJ_IMF_MAINLEVEL_1_MSAMPLESEC 65 /** MSamples/sec for IMF main level 1 */
244 #define OPJ_IMF_MAINLEVEL_2_MSAMPLESEC 130 /** MSamples/sec for IMF main level 2 */
245 #define OPJ_IMF_MAINLEVEL_3_MSAMPLESEC 195 /** MSamples/sec for IMF main level 3 */
246 #define OPJ_IMF_MAINLEVEL_4_MSAMPLESEC 260 /** MSamples/sec for IMF main level 4 */
247 #define OPJ_IMF_MAINLEVEL_5_MSAMPLESEC 520 /** MSamples/sec for IMF main level 5 */
248 #define OPJ_IMF_MAINLEVEL_6_MSAMPLESEC 1200 /** MSamples/sec for IMF main level 6 */
249 #define OPJ_IMF_MAINLEVEL_7_MSAMPLESEC 2400 /** MSamples/sec for IMF main level 7 */
250 #define OPJ_IMF_MAINLEVEL_8_MSAMPLESEC 4800 /** MSamples/sec for IMF main level 8 */
251 #define OPJ_IMF_MAINLEVEL_9_MSAMPLESEC 9600 /** MSamples/sec for IMF main level 9 */
252 #define OPJ_IMF_MAINLEVEL_10_MSAMPLESEC 19200 /** MSamples/sec for IMF main level 10 */
253 #define OPJ_IMF_MAINLEVEL_11_MSAMPLESEC 38400 /** MSamples/sec for IMF main level 11 */
255 /** Max. compressed Bit Rate (Mbits/s) per IMF sub level */
256 #define OPJ_IMF_SUBLEVEL_1_MBITSSEC 200 /** Mbits/s for IMF sub level 1 */
257 #define OPJ_IMF_SUBLEVEL_2_MBITSSEC 400 /** Mbits/s for IMF sub level 2 */
258 #define OPJ_IMF_SUBLEVEL_3_MBITSSEC 800 /** Mbits/s for IMF sub level 3 */
259 #define OPJ_IMF_SUBLEVEL_4_MBITSSEC 1600 /** Mbits/s for IMF sub level 4 */
260 #define OPJ_IMF_SUBLEVEL_5_MBITSSEC 3200 /** Mbits/s for IMF sub level 5 */
261 #define OPJ_IMF_SUBLEVEL_6_MBITSSEC 6400 /** Mbits/s for IMF sub level 6 */
262 #define OPJ_IMF_SUBLEVEL_7_MBITSSEC 12800 /** Mbits/s for IMF sub level 7 */
263 #define OPJ_IMF_SUBLEVEL_8_MBITSSEC 25600 /** Mbits/s for IMF sub level 8 */
264 #define OPJ_IMF_SUBLEVEL_9_MBITSSEC 51200 /** Mbits/s for IMF sub level 9 */
267 * JPEG 2000 codestream and component size limits in cinema profiles
269 #define OPJ_CINEMA_24_CS 1302083 /** Maximum codestream length for 24fps */
270 #define OPJ_CINEMA_48_CS 651041 /** Maximum codestream length for 48fps */
271 #define OPJ_CINEMA_24_COMP 1041666 /** Maximum size per color component for 2K & 4K @ 24fps */
272 #define OPJ_CINEMA_48_COMP 520833 /** Maximum size per color component for 2K @ 48fps */
275 ==========================================================
277 ==========================================================
281 * DEPRECATED: use RSIZ, OPJ_PROFILE_* and OPJ_EXTENSION_* instead
284 typedef enum RSIZ_CAPABILITIES {
285 OPJ_STD_RSIZ = 0, /** Standard JPEG2000 profile*/
286 OPJ_CINEMA2K = 3, /** Profile name for a 2K image*/
287 OPJ_CINEMA4K = 4, /** Profile name for a 4K image*/
289 } OPJ_RSIZ_CAPABILITIES;
292 * DEPRECATED: use RSIZ, OPJ_PROFILE_* and OPJ_EXTENSION_* instead
293 * Digital cinema operation mode
295 typedef enum CINEMA_MODE {
296 OPJ_OFF = 0, /** Not Digital Cinema*/
297 OPJ_CINEMA2K_24 = 1, /** 2K Digital Cinema at 24 fps*/
298 OPJ_CINEMA2K_48 = 2, /** 2K Digital Cinema at 48 fps*/
299 OPJ_CINEMA4K_24 = 3 /** 4K Digital Cinema at 24 fps*/
305 typedef enum PROG_ORDER {
306 OPJ_PROG_UNKNOWN = -1, /**< place-holder */
307 OPJ_LRCP = 0, /**< layer-resolution-component-precinct order */
308 OPJ_RLCP = 1, /**< resolution-layer-component-precinct order */
309 OPJ_RPCL = 2, /**< resolution-precinct-component-layer order */
310 OPJ_PCRL = 3, /**< precinct-component-resolution-layer order */
311 OPJ_CPRL = 4 /**< component-precinct-resolution-layer order */
315 * Supported image color spaces
317 typedef enum COLOR_SPACE {
318 OPJ_CLRSPC_UNKNOWN = -1, /**< not supported by the library */
319 OPJ_CLRSPC_UNSPECIFIED = 0, /**< not specified in the codestream */
320 OPJ_CLRSPC_SRGB = 1, /**< sRGB */
321 OPJ_CLRSPC_GRAY = 2, /**< grayscale */
322 OPJ_CLRSPC_SYCC = 3, /**< YUV */
323 OPJ_CLRSPC_EYCC = 4, /**< e-YCC */
324 OPJ_CLRSPC_CMYK = 5 /**< CMYK */
330 typedef enum CODEC_FORMAT {
331 OPJ_CODEC_UNKNOWN = -1, /**< place-holder */
332 OPJ_CODEC_J2K = 0, /**< JPEG-2000 codestream : read/write */
333 OPJ_CODEC_JPT = 1, /**< JPT-stream (JPEG 2000, JPIP) : read only */
334 OPJ_CODEC_JP2 = 2, /**< JP2 file format : read/write */
335 OPJ_CODEC_JPP = 3, /**< JPP-stream (JPEG 2000, JPIP) : to be coded */
336 OPJ_CODEC_JPX = 4 /**< JPX file format (JPEG 2000 Part-2) : to be coded */
341 ==========================================================
342 event manager typedef definitions
343 ==========================================================
347 * Callback function prototype for events
348 * @param msg Event message
349 * @param client_data Client object where will be return the event message
351 typedef void (*opj_msg_callback)(const char *msg, void *client_data);
354 ==========================================================
355 codec typedef definitions
356 ==========================================================
359 #ifndef OPJ_UINT32_SEMANTICALLY_BUT_INT32
360 #define OPJ_UINT32_SEMANTICALLY_BUT_INT32 OPJ_INT32
364 * Progression order changes
367 typedef struct opj_poc {
368 /** Resolution num start, Component num start, given by POC */
369 OPJ_UINT32 resno0, compno0;
370 /** Layer num end,Resolution num end, Component num end, given by POC */
371 OPJ_UINT32 layno1, resno1, compno1;
372 /** Layer num start,Precinct num start, Precinct num end */
373 OPJ_UINT32 layno0, precno0, precno1;
374 /** Progression order enum*/
375 OPJ_PROG_ORDER prg1, prg;
376 /** Progression order string*/
377 OPJ_CHAR progorder[5];
378 /** Tile number (starting at 1) */
380 /** Start and end values for Tile width and height*/
381 OPJ_UINT32_SEMANTICALLY_BUT_INT32 tx0, tx1, ty0, ty1;
382 /** Start value, initialised in pi_initialise_encode*/
383 OPJ_UINT32 layS, resS, compS, prcS;
384 /** End value, initialised in pi_initialise_encode */
385 OPJ_UINT32 layE, resE, compE, prcE;
386 /** Start and end values of Tile width and height, initialised in pi_initialise_encode*/
387 OPJ_UINT32 txS, txE, tyS, tyE, dx, dy;
388 /** Temporary values for Tile parts, initialised in pi_create_encode */
389 OPJ_UINT32 lay_t, res_t, comp_t, prc_t, tx0_t, ty0_t;
393 * Compression parameters
395 typedef struct opj_cparameters {
396 /** size of tile: tile_size_on = false (not in argument) or = true (in argument) */
397 OPJ_BOOL tile_size_on;
406 /** allocation by rate/distortion */
408 /** allocation by fixed layer */
410 /** allocation by fixed quality (PSNR) */
411 int cp_fixed_quality;
414 /** comment for coding */
416 /** csty : coding style */
418 /** progression order (default OPJ_LRCP) */
419 OPJ_PROG_ORDER prog_order;
420 /** progression order changes */
422 /** number of progression order changes (POC), default to 0 */
424 /** number of layers */
426 /** rates of layers - might be subsequently limited by the max_cs_size field.
427 * Should be decreasing. 1 can be
428 * used as last value to indicate the last layer is lossless. */
429 float tcp_rates[100];
430 /** different psnr for successive layers. Should be increasing. 0 can be
431 * used as last value to indicate the last layer is lossless. */
432 float tcp_distoratio[100];
433 /** number of resolutions */
435 /** initial code block width, default to 64 */
437 /** initial code block height, default to 64 */
439 /** mode switch (cblk_style) */
441 /** 1 : use the irreversible DWT 9-7, 0 : use lossless compression (default) */
443 /** region of interest: affected component in [0..3], -1 means no ROI */
445 /** region of interest: upshift value */
447 /* number of precinct size specifications */
449 /** initial precinct width */
450 int prcw_init[OPJ_J2K_MAXRLVLS];
451 /** initial precinct height */
452 int prch_init[OPJ_J2K_MAXRLVLS];
454 /**@name command line encoder parameters (not used inside the library) */
456 /** input file name */
457 char infile[OPJ_PATH_LEN];
458 /** output file name */
459 char outfile[OPJ_PATH_LEN];
460 /** DEPRECATED. Index generation is now handled with the opj_encode_with_info() function. Set to NULL */
462 /** DEPRECATED. Index generation is now handled with the opj_encode_with_info() function. Set to NULL */
463 char index[OPJ_PATH_LEN];
464 /** subimage encoding: origin image offset in x direction */
466 /** subimage encoding: origin image offset in y direction */
468 /** subsampling value for dx */
470 /** subsampling value for dy */
472 /** input file format 0: PGX, 1: PxM, 2: BMP 3:TIF*/
474 /** output file format 0: J2K, 1: JP2, 2: JPT */
478 /* UniPG>> */ /* NOT YET USED IN THE V2 VERSION OF OPENJPEG */
479 /**@name JPWL encoding parameters */
481 /** enables writing of EPC in MH, thus activating JPWL */
482 OPJ_BOOL jpwl_epc_on;
483 /** error protection method for MH (0,1,16,32,37-128) */
485 /** tile number of header protection specification (>=0) */
486 int jpwl_hprot_TPH_tileno[JPWL_MAX_NO_TILESPECS];
487 /** error protection methods for TPHs (0,1,16,32,37-128) */
488 int jpwl_hprot_TPH[JPWL_MAX_NO_TILESPECS];
489 /** tile number of packet protection specification (>=0) */
490 int jpwl_pprot_tileno[JPWL_MAX_NO_PACKSPECS];
491 /** packet number of packet protection specification (>=0) */
492 int jpwl_pprot_packno[JPWL_MAX_NO_PACKSPECS];
493 /** error protection methods for packets (0,1,16,32,37-128) */
494 int jpwl_pprot[JPWL_MAX_NO_PACKSPECS];
495 /** enables writing of ESD, (0=no/1/2 bytes) */
497 /** sensitivity addressing size (0=auto/2/4 bytes) */
499 /** sensitivity range (0-3) */
501 /** sensitivity method for MH (-1=no,0-7) */
503 /** tile number of sensitivity specification (>=0) */
504 int jpwl_sens_TPH_tileno[JPWL_MAX_NO_TILESPECS];
505 /** sensitivity methods for TPHs (-1=no,0-7) */
506 int jpwl_sens_TPH[JPWL_MAX_NO_TILESPECS];
511 * DEPRECATED: use RSIZ, OPJ_PROFILE_* and MAX_COMP_SIZE instead
512 * Digital Cinema compliance 0-not compliant, 1-compliant
514 OPJ_CINEMA_MODE cp_cinema;
516 * Maximum size (in bytes) for each component.
517 * If == 0, component size limitation is not considered
521 * DEPRECATED: use RSIZ, OPJ_PROFILE_* and OPJ_EXTENSION_* instead
524 OPJ_RSIZ_CAPABILITIES cp_rsiz;
525 /** Tile part generation*/
527 /** Flag for Tile part generation*/
529 /** MCT (multiple component transform) */
531 /** Enable JPIP indexing*/
533 /** Naive implementation of MCT restricted to a single reversible array based
534 encoding without offset concerning all the components. */
537 * Maximum size (in bytes) for the whole codestream.
538 * If == 0, codestream size limitation is not considered
539 * If it does not comply with tcp_rates, max_cs_size prevails
540 * and a warning is issued.
544 To be used to combine OPJ_PROFILE_*, OPJ_EXTENSION_* and (sub)levels values. */
548 #define OPJ_DPARAMETERS_IGNORE_PCLR_CMAP_CDEF_FLAG 0x0001
549 #define OPJ_DPARAMETERS_DUMP_FLAG 0x0002
552 * Decompression parameters
554 typedef struct opj_dparameters {
556 Set the number of highest resolution levels to be discarded.
557 The image resolution is effectively divided by 2 to the power of the number of discarded levels.
558 The reduce factor is limited by the smallest total number of decomposition levels among tiles.
559 if != 0, then original dimension divided by 2^(reduce);
560 if == 0 or not used, image is decoded to the full resolution
562 OPJ_UINT32 cp_reduce;
564 Set the maximum number of quality layers to decode.
565 If there are less quality layers than the specified number, all the quality layers are decoded.
566 if != 0, then only the first "layer" layers are decoded;
567 if == 0 or not used, all the quality layers are decoded
571 /**@name command line decoder parameters (not used inside the library) */
573 /** input file name */
574 char infile[OPJ_PATH_LEN];
575 /** output file name */
576 char outfile[OPJ_PATH_LEN];
577 /** input file format 0: J2K, 1: JP2, 2: JPT */
579 /** output file format 0: PGX, 1: PxM, 2: BMP */
582 /** Decoding area left boundary */
584 /** Decoding area right boundary */
586 /** Decoding area up boundary */
588 /** Decoding area bottom boundary */
593 /** tile number of the decoded tile */
594 OPJ_UINT32 tile_index;
595 /** Nb of tile to decode */
596 OPJ_UINT32 nb_tile_to_decode;
600 /* UniPG>> */ /* NOT YET USED IN THE V2 VERSION OF OPENJPEG */
601 /**@name JPWL decoding parameters */
603 /** activates the JPWL correction capabilities */
604 OPJ_BOOL jpwl_correct;
605 /** expected number of components */
607 /** maximum number of tiles */
620 typedef void * opj_codec_t;
623 ==========================================================
624 I/O stream typedef definitions
625 ==========================================================
631 /** The stream was opened for reading. */
632 #define OPJ_STREAM_READ OPJ_TRUE
633 /** The stream was opened for writing. */
634 #define OPJ_STREAM_WRITE OPJ_FALSE
637 * Callback function prototype for read function
639 typedef OPJ_SIZE_T(* opj_stream_read_fn)(void * p_buffer, OPJ_SIZE_T p_nb_bytes,
640 void * p_user_data) ;
643 * Callback function prototype for write function
645 typedef OPJ_SIZE_T(* opj_stream_write_fn)(void * p_buffer,
646 OPJ_SIZE_T p_nb_bytes, void * p_user_data) ;
649 * Callback function prototype for skip function
651 typedef OPJ_OFF_T(* opj_stream_skip_fn)(OPJ_OFF_T p_nb_bytes,
652 void * p_user_data) ;
655 * Callback function prototype for seek function
657 typedef OPJ_BOOL(* opj_stream_seek_fn)(OPJ_OFF_T p_nb_bytes,
658 void * p_user_data) ;
661 * Callback function prototype for free user data function
663 typedef void (* opj_stream_free_user_data_fn)(void * p_user_data) ;
668 typedef void * opj_stream_t;
671 ==========================================================
672 image typedef definitions
673 ==========================================================
677 * Defines a single image component
679 typedef struct opj_image_comp {
680 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
682 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
688 /** x component offset compared to the whole image */
690 /** y component offset compared to the whole image */
692 /** precision: number of bits per component per pixel */
694 /** obsolete: use prec instead */
695 OPJ_DEPRECATED_STRUCT_MEMBER(OPJ_UINT32 bpp, "Use prec instead");
696 /** signed (1) / unsigned (0) */
698 /** number of decoded resolution */
699 OPJ_UINT32 resno_decoded;
700 /** number of division by 2 of the out image compared to the original size of image */
702 /** image component data */
709 * Defines image data and characteristics
711 typedef struct opj_image {
712 /** XOsiz: horizontal offset from the origin of the reference grid to the left side of the image area */
714 /** YOsiz: vertical offset from the origin of the reference grid to the top side of the image area */
716 /** Xsiz: width of the reference grid */
718 /** Ysiz: height of the reference grid */
720 /** number of components in the image */
722 /** color space: sRGB, Greyscale or YUV */
723 OPJ_COLOR_SPACE color_space;
724 /** image components */
725 opj_image_comp_t *comps;
726 /** 'restricted' ICC profile */
727 OPJ_BYTE *icc_profile_buf;
728 /** size of ICC profile */
729 OPJ_UINT32 icc_profile_len;
734 * Component parameters structure used by the opj_image_create function
736 typedef struct opj_image_comptparm {
737 /** XRsiz: horizontal separation of a sample of ith component with respect to the reference grid */
739 /** YRsiz: vertical separation of a sample of ith component with respect to the reference grid */
745 /** x component offset compared to the whole image */
747 /** y component offset compared to the whole image */
749 /** precision: number of bits per component per pixel */
751 /** obsolete: use prec instead */
752 OPJ_DEPRECATED_STRUCT_MEMBER(OPJ_UINT32 bpp, "Use prec instead");
753 /** signed (1) / unsigned (0) */
755 } opj_image_cmptparm_t;
759 ==========================================================
760 Information on the JPEG 2000 codestream
761 ==========================================================
763 /* QUITE EXPERIMENTAL FOR THE MOMENT */
766 * Index structure : Information concerning a packet inside tile
768 typedef struct opj_packet_info {
769 /** packet start position (including SOP marker if it exists) */
771 /** end of packet header position (including EPH marker if it exists)*/
772 OPJ_OFF_T end_ph_pos;
773 /** packet end position */
775 /** packet distortion */
784 typedef struct opj_marker_info {
786 unsigned short int type;
787 /** position in codestream */
789 /** length, marker val included */
795 * Index structure : Information concerning tile-parts
797 typedef struct opj_tp_info {
798 /** start position of tile part */
800 /** end position of tile part header */
802 /** end position of tile part */
804 /** start packet of tile part */
806 /** number of packets of tile part */
811 * Index structure : information regarding tiles
813 typedef struct opj_tile_info {
814 /** value of thresh for each layer by tile cfr. Marcela */
816 /** number of tile */
818 /** start position */
820 /** end position of the header */
824 /** precinct number for each resolution level (width) */
826 /** precinct number for each resolution level (height) */
828 /** precinct size (in power of 2), in X for each resolution level */
830 /** precinct size (in power of 2), in Y for each resolution level */
832 /** information concerning packets inside tile */
833 opj_packet_info_t *packet;
834 /** number of pixels of the tile */
836 /** distortion of the tile */
838 /** number of markers */
840 /** list of markers */
841 opj_marker_info_t *marker;
842 /** actual size of markers array */
844 /** number of tile parts */
846 /** information concerning tile parts */
851 * Index structure of the codestream
853 typedef struct opj_codestream_info {
854 /** maximum distortion reduction on the whole image (add for Marcela) */
858 /** writing the packet in the index with t2_encode_packets */
864 /** progression order */
866 /** tile size in x */
868 /** tile size in y */
874 /** number of tiles in X */
876 /** number of tiles in Y */
878 /** component numbers */
880 /** number of layer */
882 /** number of decomposition for each component */
885 /** number of markers */
887 /** list of markers */
888 opj_marker_info_t *marker;
889 /** actual size of markers array */
892 /** main header position */
894 /** main header position */
896 /** codestream's size */
898 /** information regarding tiles inside image */
899 opj_tile_info_t *tile;
900 } opj_codestream_info_t;
902 /* <----------------------------------------------------------- */
903 /* new output management of the codestream information and index */
906 * Tile-component coding parameters information
908 typedef struct opj_tccp_info {
909 /** component index */
913 /** number of resolutions */
914 OPJ_UINT32 numresolutions;
915 /** log2 of code-blocks width */
917 /** log2 of code-blocks height */
919 /** code-block coding style */
921 /** discrete wavelet transform identifier: 0 = 9-7 irreversible, 1 = 5-3 reversible */
923 /** quantisation style */
925 /** stepsizes used for quantization */
926 OPJ_UINT32 stepsizes_mant[OPJ_J2K_MAXBANDS];
927 /** stepsizes used for quantization */
928 OPJ_UINT32 stepsizes_expn[OPJ_J2K_MAXBANDS];
929 /** number of guard bits */
931 /** Region Of Interest shift */
933 /** precinct width */
934 OPJ_UINT32 prcw[OPJ_J2K_MAXRLVLS];
935 /** precinct height */
936 OPJ_UINT32 prch[OPJ_J2K_MAXRLVLS];
941 * Tile coding parameters information
943 typedef struct opj_tile_v2_info {
945 /** number (index) of tile */
949 /** progression order */
951 /** number of layers */
952 OPJ_UINT32 numlayers;
953 /** multi-component transform identifier */
956 /** information concerning tile component parameters*/
957 opj_tccp_info_t *tccp_info;
959 } opj_tile_info_v2_t;
962 * Information structure about the codestream (FIXME should be expand and enhance)
964 typedef struct opj_codestream_info_v2 {
966 /** tile origin in x = XTOsiz */
968 /** tile origin in y = YTOsiz */
970 /** tile size in x = XTsiz */
972 /** tile size in y = YTsiz */
974 /** number of tiles in X */
976 /** number of tiles in Y */
979 /** number of components*/
982 /** Default information regarding tiles inside image */
983 opj_tile_info_v2_t m_default_tile_info;
985 /** information regarding tiles inside image */
986 opj_tile_info_v2_t *tile_info; /* FIXME not used for the moment */
988 } opj_codestream_info_v2_t;
992 * Index structure about a tile part
994 typedef struct opj_tp_index {
995 /** start position */
997 /** end position of the header */
998 OPJ_OFF_T end_header;
1005 * Index structure about a tile
1007 typedef struct opj_tile_index {
1011 /** number of tile parts */
1013 /** current nb of tile part (allocated)*/
1014 OPJ_UINT32 current_nb_tps;
1015 /** current tile-part index */
1016 OPJ_UINT32 current_tpsno;
1017 /** information concerning tile parts */
1018 opj_tp_index_t *tp_index;
1020 /* UniPG>> */ /* NOT USED FOR THE MOMENT IN THE V2 VERSION */
1021 /** number of markers */
1023 /** list of markers */
1024 opj_marker_info_t *marker;
1025 /** actual size of markers array */
1026 OPJ_UINT32 maxmarknum;
1029 /** packet number */
1030 OPJ_UINT32 nb_packet;
1031 /** information concerning packets inside tile */
1032 opj_packet_info_t *packet_index;
1037 * Index structure of the codestream (FIXME should be expand and enhance)
1039 typedef struct opj_codestream_index {
1040 /** main header start position (SOC position) */
1041 OPJ_OFF_T main_head_start;
1042 /** main header end position (first SOT position) */
1043 OPJ_OFF_T main_head_end;
1045 /** codestream's size */
1046 OPJ_UINT64 codestream_size;
1048 /* UniPG>> */ /* NOT USED FOR THE MOMENT IN THE V2 VERSION */
1049 /** number of markers */
1051 /** list of markers */
1052 opj_marker_info_t *marker;
1053 /** actual size of markers array */
1054 OPJ_UINT32 maxmarknum;
1058 OPJ_UINT32 nb_of_tiles;
1060 opj_tile_index_t *tile_index; /* FIXME not used for the moment */
1062 } opj_codestream_index_t;
1063 /* -----------------------------------------------------------> */
1066 ==========================================================
1067 Metadata from the JP2file
1068 ==========================================================
1072 * Info structure of the JP2 file
1073 * EXPERIMENTAL FOR THE MOMENT
1075 typedef struct opj_jp2_metadata {
1079 } opj_jp2_metadata_t;
1082 * Index structure of the JP2 file
1083 * EXPERIMENTAL FOR THE MOMENT
1085 typedef struct opj_jp2_index {
1098 ==========================================================
1100 ==========================================================
1103 /* Get the version of the openjpeg library*/
1104 OPJ_API const char * OPJ_CALLCONV opj_version(void);
1107 ==========================================================
1108 image functions definitions
1109 ==========================================================
1115 * @param numcmpts number of components
1116 * @param cmptparms components parameters
1117 * @param clrspc image color space
1118 * @return returns a new image structure if successful, returns NULL otherwise
1120 OPJ_API opj_image_t* OPJ_CALLCONV opj_image_create(OPJ_UINT32 numcmpts,
1121 opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
1124 * Deallocate any resources associated with an image
1126 * @param image image to be destroyed
1128 OPJ_API void OPJ_CALLCONV opj_image_destroy(opj_image_t *image);
1131 * Creates an image without allocating memory for the image (used in the new version of the library).
1133 * @param numcmpts the number of components
1134 * @param cmptparms the components parameters
1135 * @param clrspc the image color space
1137 * @return a new image structure if successful, NULL otherwise.
1139 OPJ_API opj_image_t* OPJ_CALLCONV opj_image_tile_create(OPJ_UINT32 numcmpts,
1140 opj_image_cmptparm_t *cmptparms, OPJ_COLOR_SPACE clrspc);
1143 * Allocator for opj_image_t->comps[].data
1144 * To be paired with opj_image_data_free.
1146 * @param size number of bytes to allocate
1148 * @return a new pointer if successful, NULL otherwise.
1151 OPJ_API void* OPJ_CALLCONV opj_image_data_alloc(OPJ_SIZE_T size);
1154 * Destructor for opj_image_t->comps[].data
1155 * To be paired with opj_image_data_alloc.
1157 * @param ptr Pointer to free
1161 OPJ_API void OPJ_CALLCONV opj_image_data_free(void* ptr);
1164 ==========================================================
1165 stream functions definitions
1166 ==========================================================
1170 * Creates an abstract stream. This function does nothing except allocating memory and initializing the abstract stream.
1172 * @param p_is_input if set to true then the stream will be an input stream, an output stream else.
1174 * @return a stream object.
1176 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_default_create(
1177 OPJ_BOOL p_is_input);
1180 * Creates an abstract stream. This function does nothing except allocating memory and initializing the abstract stream.
1182 * @param p_buffer_size FIXME DOC
1183 * @param p_is_input if set to true then the stream will be an input stream, an output stream else.
1185 * @return a stream object.
1187 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create(OPJ_SIZE_T p_buffer_size,
1188 OPJ_BOOL p_is_input);
1191 * Destroys a stream created by opj_create_stream. This function does NOT close the abstract stream. If needed the user must
1192 * close its own implementation of the stream.
1194 * @param p_stream the stream to destroy.
1196 OPJ_API void OPJ_CALLCONV opj_stream_destroy(opj_stream_t* p_stream);
1199 * Sets the given function to be used as a read function.
1200 * @param p_stream the stream to modify
1201 * @param p_function the function to use a read function.
1203 OPJ_API void OPJ_CALLCONV opj_stream_set_read_function(opj_stream_t* p_stream,
1204 opj_stream_read_fn p_function);
1207 * Sets the given function to be used as a write function.
1208 * @param p_stream the stream to modify
1209 * @param p_function the function to use a write function.
1211 OPJ_API void OPJ_CALLCONV opj_stream_set_write_function(opj_stream_t* p_stream,
1212 opj_stream_write_fn p_function);
1215 * Sets the given function to be used as a skip function.
1216 * @param p_stream the stream to modify
1217 * @param p_function the function to use a skip function.
1219 OPJ_API void OPJ_CALLCONV opj_stream_set_skip_function(opj_stream_t* p_stream,
1220 opj_stream_skip_fn p_function);
1223 * Sets the given function to be used as a seek function, the stream is then seekable,
1224 * using SEEK_SET behavior.
1225 * @param p_stream the stream to modify
1226 * @param p_function the function to use a skip function.
1228 OPJ_API void OPJ_CALLCONV opj_stream_set_seek_function(opj_stream_t* p_stream,
1229 opj_stream_seek_fn p_function);
1232 * Sets the given data to be used as a user data for the stream.
1233 * @param p_stream the stream to modify
1234 * @param p_data the data to set.
1235 * @param p_function the function to free p_data when opj_stream_destroy() is called.
1237 OPJ_API void OPJ_CALLCONV opj_stream_set_user_data(opj_stream_t* p_stream,
1238 void * p_data, opj_stream_free_user_data_fn p_function);
1241 * Sets the length of the user data for the stream.
1243 * @param p_stream the stream to modify
1244 * @param data_length length of the user_data.
1246 OPJ_API void OPJ_CALLCONV opj_stream_set_user_data_length(
1247 opj_stream_t* p_stream, OPJ_UINT64 data_length);
1250 * Create a stream from a file identified with its filename with default parameters (helper function)
1251 * @param fname the filename of the file to stream
1252 * @param p_is_read_stream whether the stream is a read stream (true) or not (false)
1254 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_default_file_stream(
1255 const char *fname, OPJ_BOOL p_is_read_stream);
1257 /** Create a stream from a file identified with its filename with a specific buffer size
1258 * @param fname the filename of the file to stream
1259 * @param p_buffer_size size of the chunk used to stream
1260 * @param p_is_read_stream whether the stream is a read stream (true) or not (false)
1262 OPJ_API opj_stream_t* OPJ_CALLCONV opj_stream_create_file_stream(
1264 OPJ_SIZE_T p_buffer_size,
1265 OPJ_BOOL p_is_read_stream);
1268 ==========================================================
1269 event manager functions definitions
1270 ==========================================================
1273 * Set the info handler use by openjpeg.
1274 * @param p_codec the codec previously initialise
1275 * @param p_callback the callback function which will be used
1276 * @param p_user_data client object where will be returned the message
1278 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_info_handler(opj_codec_t * p_codec,
1279 opj_msg_callback p_callback,
1280 void * p_user_data);
1282 * Set the warning handler use by openjpeg.
1283 * @param p_codec the codec previously initialise
1284 * @param p_callback the callback function which will be used
1285 * @param p_user_data client object where will be returned the message
1287 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_warning_handler(opj_codec_t * p_codec,
1288 opj_msg_callback p_callback,
1289 void * p_user_data);
1291 * Set the error handler use by openjpeg.
1292 * @param p_codec the codec previously initialise
1293 * @param p_callback the callback function which will be used
1294 * @param p_user_data client object where will be returned the message
1296 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_error_handler(opj_codec_t * p_codec,
1297 opj_msg_callback p_callback,
1298 void * p_user_data);
1301 ==========================================================
1302 codec functions definitions
1303 ==========================================================
1307 * Creates a J2K/JP2 decompression structure
1308 * @param format Decoder to select
1310 * @return Returns a handle to a decompressor if successful, returns NULL otherwise
1312 OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_decompress(
1313 OPJ_CODEC_FORMAT format);
1316 * Destroy a decompressor handle
1318 * @param p_codec decompressor handle to destroy
1320 OPJ_API void OPJ_CALLCONV opj_destroy_codec(opj_codec_t * p_codec);
1323 * Read after the codestream if necessary
1324 * @param p_codec the JPEG2000 codec to read.
1325 * @param p_stream the JPEG2000 stream.
1327 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_end_decompress(opj_codec_t *p_codec,
1328 opj_stream_t *p_stream);
1332 * Set decoding parameters to default values
1333 * @param parameters Decompression parameters
1335 OPJ_API void OPJ_CALLCONV opj_set_default_decoder_parameters(
1336 opj_dparameters_t *parameters);
1339 * Setup the decoder with decompression parameters provided by the user and with the message handler
1340 * provided by the user.
1342 * @param p_codec decompressor handler
1343 * @param parameters decompression parameters
1345 * @return true if the decoder is correctly set
1347 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_setup_decoder(opj_codec_t *p_codec,
1348 opj_dparameters_t *parameters);
1351 * Set strict decoding parameter for this decoder. If strict decoding is enabled, partial bit
1352 * streams will fail to decode. If strict decoding is disabled, the decoder will decode partial
1353 * bitstreams as much as possible without erroring
1355 * @param p_codec decompressor handler
1356 * @param strict OPJ_TRUE to enable strict decoding, OPJ_FALSE to disable
1358 * @return true if the decoder is correctly set
1361 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decoder_set_strict_mode(opj_codec_t *p_codec,
1365 * Allocates worker threads for the compressor/decompressor.
1367 * By default, only the main thread is used. If this function is not used,
1368 * but the OPJ_NUM_THREADS environment variable is set, its value will be
1369 * used to initialize the number of threads. The value can be either an integer
1370 * number, or "ALL_CPUS". If OPJ_NUM_THREADS is set and this function is called,
1371 * this function will override the behaviour of the environment variable.
1373 * This function must be called after opj_setup_decoder() and
1374 * before opj_read_header() for the decoding side, or after opj_setup_encoder()
1375 * and before opj_start_compress() for the encoding side.
1377 * @param p_codec decompressor or compressor handler
1378 * @param num_threads number of threads.
1380 * @return OPJ_TRUE if the function is successful.
1382 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_codec_set_threads(opj_codec_t *p_codec,
1386 * Decodes an image header.
1388 * @param p_stream the jpeg2000 stream.
1389 * @param p_codec the jpeg2000 codec to read.
1390 * @param p_image the image structure initialized with the characteristics of encoded image.
1392 * @return true if the main header of the codestream and the JP2 header is correctly read.
1394 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_read_header(opj_stream_t *p_stream,
1395 opj_codec_t *p_codec,
1396 opj_image_t **p_image);
1399 /** Restrict the number of components to decode.
1401 * This function should be called after opj_read_header().
1403 * This function enables to restrict the set of decoded components to the
1404 * specified indices.
1405 * Note that the current implementation (apply_color_transforms == OPJ_FALSE)
1406 * is such that neither the multi-component transform at codestream level,
1407 * nor JP2 channel transformations will be applied.
1408 * Consequently the indices are relative to the codestream.
1410 * Note: opj_decode_tile_data() should not be used together with opj_set_decoded_components().
1412 * @param p_codec the jpeg2000 codec to read.
1413 * @param numcomps Size of the comps_indices array.
1414 * @param comps_indices Array of numcomps values representing the indices
1415 * of the components to decode (relative to the
1416 * codestream, starting at 0)
1417 * @param apply_color_transforms Whether multi-component transform at codestream level
1418 * or JP2 channel transformations should be applied.
1419 * Currently this parameter should be set to OPJ_FALSE.
1420 * Setting it to OPJ_TRUE will result in an error.
1422 * @return OPJ_TRUE in case of success.
1424 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_decoded_components(opj_codec_t *p_codec,
1425 OPJ_UINT32 numcomps,
1426 const OPJ_UINT32* comps_indices,
1427 OPJ_BOOL apply_color_transforms);
1430 * Sets the given area to be decoded. This function should be called right after opj_read_header and before any tile header reading.
1432 * The coordinates passed to this function should be expressed in the reference grid,
1433 * that is to say at the highest resolution level, even if requesting the image at lower
1434 * resolution levels.
1436 * Generally opj_set_decode_area() should be followed by opj_decode(), and the
1437 * codec cannot be re-used.
1438 * In the particular case of an image made of a single tile, several sequences of
1439 * calls to opoj_set_decode_area() and opj_decode() are allowed, and will bring
1440 * performance improvements when reading an image by chunks.
1442 * @param p_codec the jpeg2000 codec.
1443 * @param p_image the decoded image previously set by opj_read_header
1444 * @param p_start_x the left position of the rectangle to decode (in image coordinates).
1445 * @param p_end_x the right position of the rectangle to decode (in image coordinates).
1446 * @param p_start_y the up position of the rectangle to decode (in image coordinates).
1447 * @param p_end_y the bottom position of the rectangle to decode (in image coordinates).
1449 * @return true if the area could be set.
1451 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_decode_area(opj_codec_t *p_codec,
1452 opj_image_t* p_image,
1453 OPJ_INT32 p_start_x, OPJ_INT32 p_start_y,
1454 OPJ_INT32 p_end_x, OPJ_INT32 p_end_y);
1457 * Decode an image from a JPEG-2000 codestream
1459 * @param p_decompressor decompressor handle
1460 * @param p_stream Input buffer stream
1461 * @param p_image the decoded image
1462 * @return true if success, otherwise false
1464 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decode(opj_codec_t *p_decompressor,
1465 opj_stream_t *p_stream,
1466 opj_image_t *p_image);
1469 * Get the decoded tile from the codec
1471 * @param p_codec the jpeg2000 codec.
1472 * @param p_stream input stream
1473 * @param p_image output image
1474 * @param tile_index index of the tile which will be decode
1476 * @return true if success, otherwise false
1478 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_get_decoded_tile(opj_codec_t *p_codec,
1479 opj_stream_t *p_stream,
1480 opj_image_t *p_image,
1481 OPJ_UINT32 tile_index);
1484 * Set the resolution factor of the decoded image
1485 * @param p_codec the jpeg2000 codec.
1486 * @param res_factor resolution factor to set
1488 * @return true if success, otherwise false
1490 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_decoded_resolution_factor(
1491 opj_codec_t *p_codec, OPJ_UINT32 res_factor);
1494 * Writes a tile with the given data.
1496 * @param p_codec the jpeg2000 codec.
1497 * @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.
1498 * @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.
1499 * @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
1500 * tile_width * tile_height * component_size. component_size can be 1,2 or 4 bytes, depending on the precision of the given component.
1501 * @param p_stream the stream to write data to.
1503 * @return true if the data could be written.
1505 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_write_tile(opj_codec_t *p_codec,
1506 OPJ_UINT32 p_tile_index,
1508 OPJ_UINT32 p_data_size,
1509 opj_stream_t *p_stream);
1512 * Reads a tile header. This function is compulsory and allows one to know the size of the tile that will be decoded.
1513 * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
1515 * @param p_codec the jpeg2000 codec.
1516 * @param p_tile_index pointer to a value that will hold the index of the tile being decoded, in case of success.
1517 * @param p_data_size pointer to a value that will hold the maximum size of the decoded data, in case of success. In case
1518 * of truncated codestreams, the actual number of bytes decoded may be lower. The computation of the size is the same
1519 * as depicted in opj_write_tile.
1520 * @param p_tile_x0 pointer to a value that will hold the x0 pos of the tile (in the image).
1521 * @param p_tile_y0 pointer to a value that will hold the y0 pos of the tile (in the image).
1522 * @param p_tile_x1 pointer to a value that will hold the x1 pos of the tile (in the image).
1523 * @param p_tile_y1 pointer to a value that will hold the y1 pos of the tile (in the image).
1524 * @param p_nb_comps pointer to a value that will hold the number of components in the tile.
1525 * @param p_should_go_on pointer to a boolean that will hold the fact that the decoding should go on. In case the
1526 * codestream is over at the time of the call, the value will be set to false. The user should then stop
1528 * @param p_stream the stream to decode.
1529 * @return true if the tile header could be decoded. In case the decoding should end, the returned value is still true.
1530 * returning false may be the result of a shortage of memory or an internal error.
1532 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_read_tile_header(opj_codec_t *p_codec,
1533 opj_stream_t * p_stream,
1534 OPJ_UINT32 * p_tile_index,
1535 OPJ_UINT32 * p_data_size,
1536 OPJ_INT32 * p_tile_x0, OPJ_INT32 * p_tile_y0,
1537 OPJ_INT32 * p_tile_x1, OPJ_INT32 * p_tile_y1,
1538 OPJ_UINT32 * p_nb_comps,
1539 OPJ_BOOL * p_should_go_on);
1542 * Reads a tile data. This function is compulsory and allows one to decode tile data. opj_read_tile_header should be called before.
1543 * The user may need to refer to the image got by opj_read_header to understand the size being taken by the tile.
1545 * Note: opj_decode_tile_data() should not be used together with opj_set_decoded_components().
1547 * @param p_codec the jpeg2000 codec.
1548 * @param p_tile_index the index of the tile being decoded, this should be the value set by opj_read_tile_header.
1549 * @param p_data pointer to a memory block that will hold the decoded data.
1550 * @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.
1551 * @param p_stream the stream to decode.
1553 * @return true if the data could be decoded.
1555 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_decode_tile_data(opj_codec_t *p_codec,
1556 OPJ_UINT32 p_tile_index,
1558 OPJ_UINT32 p_data_size,
1559 opj_stream_t *p_stream);
1561 /* COMPRESSION FUNCTIONS*/
1564 * Creates a J2K/JP2 compression structure
1565 * @param format Coder to select
1566 * @return Returns a handle to a compressor if successful, returns NULL otherwise
1568 OPJ_API opj_codec_t* OPJ_CALLCONV opj_create_compress(OPJ_CODEC_FORMAT format);
1571 Set encoding parameters to default values, that means :
1575 <li>Size of precinct : 2^15 x 2^15 (means 1 precinct)
1576 <li>Size of code-block : 64 x 64
1577 <li>Number of resolutions: 6
1578 <li>No SOP marker in the codestream
1579 <li>No EPH marker in the codestream
1580 <li>No sub-sampling in x or y direction
1581 <li>No mode switch activated
1582 <li>Progression order: LRCP
1584 <li>No ROI upshifted
1585 <li>No offset of the origin of the image
1586 <li>No offset of the origin of the tiles
1587 <li>Reversible DWT 5-3
1589 @param parameters Compression parameters
1591 OPJ_API void OPJ_CALLCONV opj_set_default_encoder_parameters(
1592 opj_cparameters_t *parameters);
1595 * Setup the encoder parameters using the current image and using user parameters.
1596 * @param p_codec Compressor handle
1597 * @param parameters Compression parameters
1598 * @param image Input filled image
1600 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_setup_encoder(opj_codec_t *p_codec,
1601 opj_cparameters_t *parameters,
1602 opj_image_t *image);
1606 * Specify extra options for the encoder.
1608 * This may be called after opj_setup_encoder() and before opj_start_compress()
1610 * This is the way to add new options in a fully ABI compatible way, without
1611 * extending the opj_cparameters_t structure.
1613 * Currently supported options are:
1615 * <li>PLT=YES/NO. Defaults to NO. If set to YES, PLT marker segments,
1616 * indicating the length of each packet in the tile-part header, will be
1617 * written. Since 2.4.0</li>
1618 * <li>TLM=YES/NO. Defaults to NO (except for Cinema and IMF profiles).
1619 * If set to YES, TLM marker segments, indicating the length of each
1620 * tile-part part will be written. Since 2.4.0</li>
1621 * <li>GUARD_BITS=value. Number of guard bits in [0,7] range. Default value is 2.
1622 * 1 may be used sometimes (like in SMPTE DCP Bv2.1 Application Profile for 2K images).
1626 * @param p_codec Compressor handle
1627 * @param p_options Compression options. This should be a NULL terminated
1628 * array of strings. Each string is of the form KEY=VALUE.
1630 * @return OPJ_TRUE in case of success.
1633 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_encoder_set_extra_options(
1634 opj_codec_t *p_codec,
1635 const char* const* p_options);
1638 * Start to compress the current image.
1639 * @param p_codec Compressor handle
1640 * @param p_image Input filled image
1641 * @param p_stream Input stgream
1643 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_start_compress(opj_codec_t *p_codec,
1644 opj_image_t * p_image,
1645 opj_stream_t *p_stream);
1648 * End to compress the current image.
1649 * @param p_codec Compressor handle
1650 * @param p_stream Input stgream
1652 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_end_compress(opj_codec_t *p_codec,
1653 opj_stream_t *p_stream);
1656 * Encode an image into a JPEG-2000 codestream
1657 * @param p_codec compressor handle
1658 * @param p_stream Output buffer stream
1660 * @return Returns true if successful, returns false otherwise
1662 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_encode(opj_codec_t *p_codec,
1663 opj_stream_t *p_stream);
1665 ==========================================================
1666 codec output functions definitions
1667 ==========================================================
1669 /* EXPERIMENTAL FUNCTIONS FOR NOW, USED ONLY IN J2K_DUMP*/
1672 Destroy Codestream information after compression or decompression
1673 @param cstr_info Codestream information structure
1675 OPJ_API void OPJ_CALLCONV opj_destroy_cstr_info(opj_codestream_info_v2_t
1680 * Dump the codec information into the output stream
1682 * @param p_codec the jpeg2000 codec.
1683 * @param info_flag type of information dump.
1684 * @param output_stream output stream where dump the information gotten from the codec.
1687 OPJ_API void OPJ_CALLCONV opj_dump_codec(opj_codec_t *p_codec,
1688 OPJ_INT32 info_flag,
1689 FILE* output_stream);
1692 * Get the codestream information from the codec
1694 * @param p_codec the jpeg2000 codec.
1696 * @return a pointer to a codestream information structure.
1699 OPJ_API opj_codestream_info_v2_t* OPJ_CALLCONV opj_get_cstr_info(
1700 opj_codec_t *p_codec);
1703 * Get the codestream index from the codec
1705 * @param p_codec the jpeg2000 codec.
1707 * @return a pointer to a codestream index structure.
1710 OPJ_API opj_codestream_index_t * OPJ_CALLCONV opj_get_cstr_index(
1711 opj_codec_t *p_codec);
1713 OPJ_API void OPJ_CALLCONV opj_destroy_cstr_index(opj_codestream_index_t
1718 * Get the JP2 file information from the codec FIXME
1720 * @param p_codec the jpeg2000 codec.
1722 * @return a pointer to a JP2 metadata structure.
1725 OPJ_API opj_jp2_metadata_t* OPJ_CALLCONV opj_get_jp2_metadata(
1726 opj_codec_t *p_codec);
1729 * Get the JP2 file index from the codec FIXME
1731 * @param p_codec the jpeg2000 codec.
1733 * @return a pointer to a JP2 index structure.
1736 OPJ_API opj_jp2_index_t* OPJ_CALLCONV opj_get_jp2_index(opj_codec_t *p_codec);
1740 ==========================================================
1742 ==========================================================
1746 * Sets the MCT matrix to use.
1748 * @param parameters the parameters to change.
1749 * @param pEncodingMatrix the encoding matrix.
1750 * @param p_dc_shift the dc shift coefficients to use.
1751 * @param pNbComp the number of components of the image.
1753 * @return true if the parameters could be set.
1755 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_set_MCT(opj_cparameters_t *parameters,
1756 OPJ_FLOAT32 * pEncodingMatrix,
1757 OPJ_INT32 * p_dc_shift,
1758 OPJ_UINT32 pNbComp);
1761 ==========================================================
1763 ==========================================================
1766 /** Returns if the library is built with thread support.
1767 * OPJ_TRUE if mutex, condition, thread, thread pool are available.
1769 OPJ_API OPJ_BOOL OPJ_CALLCONV opj_has_thread_support(void);
1771 /** Return the number of virtual CPUs */
1772 OPJ_API int OPJ_CALLCONV opj_get_num_cpus(void);
1779 #endif /* OPENJPEG_H */