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