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