| 1 |
/* |
| 2 |
* Copyright (c) 1999-2000 Image Power, Inc. and the University of |
| 3 |
* British Columbia. |
| 4 |
* Copyright (c) 2001-2002 Michael David Adams. |
| 5 |
* All rights reserved. |
| 6 |
*/ |
| 7 |
|
| 8 |
/* __START_OF_JASPER_LICENSE__ |
| 9 |
* |
| 10 |
* JasPer Software License |
| 11 |
* |
| 12 |
* IMAGE POWER JPEG-2000 PUBLIC LICENSE |
| 13 |
* ************************************ |
| 14 |
* |
| 15 |
* GRANT: |
| 16 |
* |
| 17 |
* Permission is hereby granted, free of charge, to any person (the "User") |
| 18 |
* obtaining a copy of this software and associated documentation, to deal |
| 19 |
* in the JasPer Software without restriction, including without limitation |
| 20 |
* the right to use, copy, modify, merge, publish, distribute, sublicense, |
| 21 |
* and/or sell copies of the JasPer Software (in source and binary forms), |
| 22 |
* and to permit persons to whom the JasPer Software is furnished to do so, |
| 23 |
* provided further that the License Conditions below are met. |
| 24 |
* |
| 25 |
* License Conditions |
| 26 |
* ****************** |
| 27 |
* |
| 28 |
* A. Redistributions of source code must retain the above copyright notice, |
| 29 |
* and this list of conditions, and the following disclaimer. |
| 30 |
* |
| 31 |
* B. Redistributions in binary form must reproduce the above copyright |
| 32 |
* notice, and this list of conditions, and the following disclaimer in |
| 33 |
* the documentation and/or other materials provided with the distribution. |
| 34 |
* |
| 35 |
* C. Neither the name of Image Power, Inc. nor any other contributor |
| 36 |
* (including, but not limited to, the University of British Columbia and |
| 37 |
* Michael David Adams) may be used to endorse or promote products derived |
| 38 |
* from this software without specific prior written permission. |
| 39 |
* |
| 40 |
* D. User agrees that it shall not commence any action against Image Power, |
| 41 |
* Inc., the University of British Columbia, Michael David Adams, or any |
| 42 |
* other contributors (collectively "Licensors") for infringement of any |
| 43 |
* intellectual property rights ("IPR") held by the User in respect of any |
| 44 |
* technology that User owns or has a right to license or sublicense and |
| 45 |
* which is an element required in order to claim compliance with ISO/IEC |
| 46 |
* 15444-1 (i.e., JPEG-2000 Part 1). "IPR" means all intellectual property |
| 47 |
* rights worldwide arising under statutory or common law, and whether |
| 48 |
* or not perfected, including, without limitation, all (i) patents and |
| 49 |
* patent applications owned or licensable by User; (ii) rights associated |
| 50 |
* with works of authorship including copyrights, copyright applications, |
| 51 |
* copyright registrations, mask work rights, mask work applications, |
| 52 |
* mask work registrations; (iii) rights relating to the protection of |
| 53 |
* trade secrets and confidential information; (iv) any right analogous |
| 54 |
* to those set forth in subsections (i), (ii), or (iii) and any other |
| 55 |
* proprietary rights relating to intangible property (other than trademark, |
| 56 |
* trade dress, or service mark rights); and (v) divisions, continuations, |
| 57 |
* renewals, reissues and extensions of the foregoing (as and to the extent |
| 58 |
* applicable) now existing, hereafter filed, issued or acquired. |
| 59 |
* |
| 60 |
* E. If User commences an infringement action against any Licensor(s) then |
| 61 |
* such Licensor(s) shall have the right to terminate User's license and |
| 62 |
* all sublicenses that have been granted hereunder by User to other parties. |
| 63 |
* |
| 64 |
* F. This software is for use only in hardware or software products that |
| 65 |
* are compliant with ISO/IEC 15444-1 (i.e., JPEG-2000 Part 1). No license |
| 66 |
* or right to this Software is granted for products that do not comply |
| 67 |
* with ISO/IEC 15444-1. The JPEG-2000 Part 1 standard can be purchased |
| 68 |
* from the ISO. |
| 69 |
* |
| 70 |
* THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. |
| 71 |
* NO USE OF THE JASPER SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER |
| 72 |
* THIS DISCLAIMER. THE JASPER SOFTWARE IS PROVIDED BY THE LICENSORS AND |
| 73 |
* CONTRIBUTORS UNDER THIS LICENSE ON AN ``AS-IS'' BASIS, WITHOUT WARRANTY |
| 74 |
* OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, |
| 75 |
* WARRANTIES THAT THE JASPER SOFTWARE IS FREE OF DEFECTS, IS MERCHANTABLE, |
| 76 |
* IS FIT FOR A PARTICULAR PURPOSE OR IS NON-INFRINGING. THOSE INTENDING |
| 77 |
* TO USE THE JASPER SOFTWARE OR MODIFICATIONS THEREOF FOR USE IN HARDWARE |
| 78 |
* OR SOFTWARE PRODUCTS ARE ADVISED THAT THEIR USE MAY INFRINGE EXISTING |
| 79 |
* PATENTS, COPYRIGHTS, TRADEMARKS, OR OTHER INTELLECTUAL PROPERTY RIGHTS. |
| 80 |
* THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE JASPER SOFTWARE |
| 81 |
* IS WITH THE USER. SHOULD ANY PART OF THE JASPER SOFTWARE PROVE DEFECTIVE |
| 82 |
* IN ANY RESPECT, THE USER (AND NOT THE INITIAL DEVELOPERS, THE UNIVERSITY |
| 83 |
* OF BRITISH COLUMBIA, IMAGE POWER, INC., MICHAEL DAVID ADAMS, OR ANY |
| 84 |
* OTHER CONTRIBUTOR) SHALL ASSUME THE COST OF ANY NECESSARY SERVICING, |
| 85 |
* REPAIR OR CORRECTION. UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, |
| 86 |
* WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL THE |
| 87 |
* INITIAL DEVELOPER, THE UNIVERSITY OF BRITISH COLUMBIA, IMAGE POWER, INC., |
| 88 |
* MICHAEL DAVID ADAMS, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF THE |
| 89 |
* JASPER SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO |
| 90 |
* THE USER OR ANY OTHER PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR |
| 91 |
* CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, |
| 92 |
* DAMAGES FOR LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR |
| 93 |
* MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF |
| 94 |
* SUCH PARTY HAD BEEN INFORMED, OR OUGHT TO HAVE KNOWN, OF THE POSSIBILITY |
| 95 |
* OF SUCH DAMAGES. THE JASPER SOFTWARE AND UNDERLYING TECHNOLOGY ARE NOT |
| 96 |
* FAULT-TOLERANT AND ARE NOT DESIGNED, MANUFACTURED OR INTENDED FOR USE OR |
| 97 |
* RESALE AS ON-LINE CONTROL EQUIPMENT IN HAZARDOUS ENVIRONMENTS REQUIRING |
| 98 |
* FAIL-SAFE PERFORMANCE, SUCH AS IN THE OPERATION OF NUCLEAR FACILITIES, |
| 99 |
* AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL, DIRECT |
| 100 |
* LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH THE FAILURE OF THE |
| 101 |
* JASPER SOFTWARE OR UNDERLYING TECHNOLOGY OR PRODUCT COULD LEAD DIRECTLY |
| 102 |
* TO DEATH, PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE |
| 103 |
* ("HIGH RISK ACTIVITIES"). LICENSOR SPECIFICALLY DISCLAIMS ANY EXPRESS |
| 104 |
* OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES. USER WILL NOT |
| 105 |
* KNOWINGLY USE, DISTRIBUTE OR RESELL THE JASPER SOFTWARE OR UNDERLYING |
| 106 |
* TECHNOLOGY OR PRODUCTS FOR HIGH RISK ACTIVITIES AND WILL ENSURE THAT ITS |
| 107 |
* CUSTOMERS AND END-USERS OF ITS PRODUCTS ARE PROVIDED WITH A COPY OF THE |
| 108 |
* NOTICE SPECIFIED IN THIS SECTION. |
| 109 |
* |
| 110 |
* __END_OF_JASPER_LICENSE__ |
| 111 |
*/ |
| 112 |
|
| 113 |
/* |
| 114 |
* JPEG-2000 Code Stream Library |
| 115 |
* |
| 116 |
* $Id$ |
| 117 |
*/ |
| 118 |
|
| 119 |
#ifndef JPC_CS_H |
| 120 |
#define JPC_CS_H |
| 121 |
|
| 122 |
/******************************************************************************\ |
| 123 |
* Includes. |
| 124 |
\******************************************************************************/ |
| 125 |
|
| 126 |
#include "jasper/jas_image.h" |
| 127 |
#include "jasper/jas_stream.h" |
| 128 |
|
| 129 |
#include "jpc_cod.h" |
| 130 |
|
| 131 |
/******************************************************************************\ |
| 132 |
* Constants and Types. |
| 133 |
\******************************************************************************/ |
| 134 |
|
| 135 |
/* The maximum number of resolution levels. */ |
| 136 |
#define JPC_MAXRLVLS 33 |
| 137 |
|
| 138 |
/* The maximum number of bands. */ |
| 139 |
#define JPC_MAXBANDS (3 * JPC_MAXRLVLS + 1) |
| 140 |
|
| 141 |
/* The maximum number of layers. */ |
| 142 |
#define JPC_MAXLYRS 16384 |
| 143 |
|
| 144 |
/**************************************\ |
| 145 |
* Code stream. |
| 146 |
\**************************************/ |
| 147 |
|
| 148 |
/* |
| 149 |
* Code stream states. |
| 150 |
*/ |
| 151 |
|
| 152 |
/* Initial. */ |
| 153 |
#define JPC_CS_INIT 0 |
| 154 |
/* Main header. */ |
| 155 |
#define JPC_CS_MHDR 1 |
| 156 |
/* Tile-part header. */ |
| 157 |
#define JPC_CS_THDR 2 |
| 158 |
/* Main trailer. */ |
| 159 |
#define JPC_CS_MTLR 3 |
| 160 |
/* Tile-part data. */ |
| 161 |
#define JPC_CS_TDATA 4 |
| 162 |
|
| 163 |
/* |
| 164 |
* Unfortunately, the code stream syntax was not designed in such a way that |
| 165 |
* any given marker segment can be correctly decoded without additional state |
| 166 |
* derived from previously decoded marker segments. |
| 167 |
* For example, a RGN/COC/QCC marker segment cannot be decoded unless the |
| 168 |
* number of components is known. |
| 169 |
*/ |
| 170 |
|
| 171 |
/* |
| 172 |
* Code stream state information. |
| 173 |
*/ |
| 174 |
|
| 175 |
typedef struct { |
| 176 |
|
| 177 |
/* The number of components. */ |
| 178 |
int numcomps; |
| 179 |
|
| 180 |
} jpc_cstate_t; |
| 181 |
|
| 182 |
/**************************************\ |
| 183 |
* SOT marker segment parameters. |
| 184 |
\**************************************/ |
| 185 |
|
| 186 |
typedef struct { |
| 187 |
|
| 188 |
/* The tile number. */ |
| 189 |
uint_fast16_t tileno; |
| 190 |
|
| 191 |
/* The combined length of the marker segment and its auxiliary data |
| 192 |
(i.e., packet data). */ |
| 193 |
uint_fast32_t len; |
| 194 |
|
| 195 |
/* The tile-part instance. */ |
| 196 |
uint_fast8_t partno; |
| 197 |
|
| 198 |
/* The number of tile-parts. */ |
| 199 |
uint_fast8_t numparts; |
| 200 |
|
| 201 |
} jpc_sot_t; |
| 202 |
|
| 203 |
/**************************************\ |
| 204 |
* SIZ marker segment parameters. |
| 205 |
\**************************************/ |
| 206 |
|
| 207 |
/* Per component information. */ |
| 208 |
|
| 209 |
typedef struct { |
| 210 |
|
| 211 |
/* The precision of the samples. */ |
| 212 |
uint_fast8_t prec; |
| 213 |
|
| 214 |
/* The signedness of the samples. */ |
| 215 |
uint_fast8_t sgnd; |
| 216 |
|
| 217 |
/* The horizontal separation of samples with respect to the reference |
| 218 |
grid. */ |
| 219 |
uint_fast8_t hsamp; |
| 220 |
|
| 221 |
/* The vertical separation of samples with respect to the reference |
| 222 |
grid. */ |
| 223 |
uint_fast8_t vsamp; |
| 224 |
|
| 225 |
} jpc_sizcomp_t; |
| 226 |
|
| 227 |
/* SIZ marker segment parameters. */ |
| 228 |
|
| 229 |
typedef struct { |
| 230 |
|
| 231 |
/* The code stream capabilities. */ |
| 232 |
uint_fast16_t caps; |
| 233 |
|
| 234 |
/* The width of the image in units of the reference grid. */ |
| 235 |
uint_fast32_t width; |
| 236 |
|
| 237 |
/* The height of the image in units of the reference grid. */ |
| 238 |
uint_fast32_t height; |
| 239 |
|
| 240 |
/* The horizontal offset from the origin of the reference grid to the |
| 241 |
left side of the image area. */ |
| 242 |
uint_fast32_t xoff; |
| 243 |
|
| 244 |
/* The vertical offset from the origin of the reference grid to the |
| 245 |
top side of the image area. */ |
| 246 |
uint_fast32_t yoff; |
| 247 |
|
| 248 |
/* The nominal width of a tile in units of the reference grid. */ |
| 249 |
uint_fast32_t tilewidth; |
| 250 |
|
| 251 |
/* The nominal height of a tile in units of the reference grid. */ |
| 252 |
uint_fast32_t tileheight; |
| 253 |
|
| 254 |
/* The horizontal offset from the origin of the reference grid to the |
| 255 |
left side of the first tile. */ |
| 256 |
uint_fast32_t tilexoff; |
| 257 |
|
| 258 |
/* The vertical offset from the origin of the reference grid to the |
| 259 |
top side of the first tile. */ |
| 260 |
uint_fast32_t tileyoff; |
| 261 |
|
| 262 |
/* The number of components. */ |
| 263 |
uint_fast16_t numcomps; |
| 264 |
|
| 265 |
/* The per-component information. */ |
| 266 |
jpc_sizcomp_t *comps; |
| 267 |
|
| 268 |
} jpc_siz_t; |
| 269 |
|
| 270 |
/**************************************\ |
| 271 |
* COD marker segment parameters. |
| 272 |
\**************************************/ |
| 273 |
|
| 274 |
/* |
| 275 |
* Coding style constants. |
| 276 |
*/ |
| 277 |
|
| 278 |
/* Precincts may be used. */ |
| 279 |
#define JPC_COX_PRT 0x01 |
| 280 |
/* SOP marker segments may be used. */ |
| 281 |
#define JPC_COD_SOP 0x02 |
| 282 |
/* EPH marker segments may be used. */ |
| 283 |
#define JPC_COD_EPH 0x04 |
| 284 |
|
| 285 |
/* |
| 286 |
* Progression order constants. |
| 287 |
*/ |
| 288 |
|
| 289 |
/* Layer-resolution-component-precinct progressive |
| 290 |
(i.e., progressive by fidelity). */ |
| 291 |
#define JPC_COD_LRCPPRG 0 |
| 292 |
/* Resolution-layer-component-precinct progressive |
| 293 |
(i.e., progressive by resolution). */ |
| 294 |
#define JPC_COD_RLCPPRG 1 |
| 295 |
/* Resolution-precinct-component-layer progressive. */ |
| 296 |
#define JPC_COD_RPCLPRG 2 |
| 297 |
/* Precinct-component-resolution-layer progressive. */ |
| 298 |
#define JPC_COD_PCRLPRG 3 |
| 299 |
/* Component-position-resolution-layer progressive. */ |
| 300 |
#define JPC_COD_CPRLPRG 4 |
| 301 |
|
| 302 |
/* |
| 303 |
* Code block style constants. |
| 304 |
*/ |
| 305 |
|
| 306 |
#define JPC_COX_LAZY 0x01 /* Selective arithmetic coding bypass. */ |
| 307 |
#define JPC_COX_RESET 0x02 /* Reset context probabilities. */ |
| 308 |
#define JPC_COX_TERMALL 0x04 /* Terminate all coding passes. */ |
| 309 |
#define JPC_COX_VSC 0x08 /* Vertical stripe causal context formation. */ |
| 310 |
#define JPC_COX_PTERM 0x10 /* Predictable termination. */ |
| 311 |
#define JPC_COX_SEGSYM 0x20 /* Use segmentation symbols. */ |
| 312 |
|
| 313 |
/* Transform constants. */ |
| 314 |
#define JPC_COX_INS 0x00 /* Irreversible 9/7. */ |
| 315 |
#define JPC_COX_RFT 0x01 /* Reversible 5/3. */ |
| 316 |
|
| 317 |
/* Multicomponent transform constants. */ |
| 318 |
#define JPC_COD_NOMCT 0x00 /* No multicomponent transform. */ |
| 319 |
#define JPC_COD_MCT 0x01 /* Multicomponent transform. */ |
| 320 |
|
| 321 |
/* Get the code block size value from the code block size exponent. */ |
| 322 |
#define JPC_COX_CBLKSIZEEXPN(x) ((x) - 2) |
| 323 |
/* Get the code block size exponent from the code block size value. */ |
| 324 |
#define JPC_COX_GETCBLKSIZEEXPN(x) ((x) + 2) |
| 325 |
|
| 326 |
/* Per resolution-level information. */ |
| 327 |
|
| 328 |
typedef struct { |
| 329 |
|
| 330 |
/* The packet partition width. */ |
| 331 |
uint_fast8_t parwidthval; |
| 332 |
|
| 333 |
/* The packet partition height. */ |
| 334 |
uint_fast8_t parheightval; |
| 335 |
|
| 336 |
} jpc_coxrlvl_t; |
| 337 |
|
| 338 |
/* Per component information. */ |
| 339 |
|
| 340 |
typedef struct { |
| 341 |
|
| 342 |
/* The coding style. */ |
| 343 |
uint_fast8_t csty; |
| 344 |
|
| 345 |
/* The number of decomposition levels. */ |
| 346 |
uint_fast8_t numdlvls; |
| 347 |
|
| 348 |
/* The nominal code block width specifier. */ |
| 349 |
uint_fast8_t cblkwidthval; |
| 350 |
|
| 351 |
/* The nominal code block height specifier. */ |
| 352 |
uint_fast8_t cblkheightval; |
| 353 |
|
| 354 |
/* The style of coding passes. */ |
| 355 |
uint_fast8_t cblksty; |
| 356 |
|
| 357 |
/* The QMFB employed. */ |
| 358 |
uint_fast8_t qmfbid; |
| 359 |
|
| 360 |
/* The number of resolution levels. */ |
| 361 |
int numrlvls; |
| 362 |
|
| 363 |
/* The per-resolution-level information. */ |
| 364 |
jpc_coxrlvl_t rlvls[JPC_MAXRLVLS]; |
| 365 |
|
| 366 |
} jpc_coxcp_t; |
| 367 |
|
| 368 |
/* COD marker segment parameters. */ |
| 369 |
|
| 370 |
typedef struct { |
| 371 |
|
| 372 |
/* The general coding style. */ |
| 373 |
uint_fast8_t csty; |
| 374 |
|
| 375 |
/* The progression order. */ |
| 376 |
uint_fast8_t prg; |
| 377 |
|
| 378 |
/* The number of layers. */ |
| 379 |
uint_fast16_t numlyrs; |
| 380 |
|
| 381 |
/* The multicomponent transform. */ |
| 382 |
uint_fast8_t mctrans; |
| 383 |
|
| 384 |
/* Component-related parameters. */ |
| 385 |
jpc_coxcp_t compparms; |
| 386 |
|
| 387 |
} jpc_cod_t; |
| 388 |
|
| 389 |
/* COC marker segment parameters. */ |
| 390 |
|
| 391 |
typedef struct { |
| 392 |
|
| 393 |
/* The component number. */ |
| 394 |
uint_fast16_t compno; |
| 395 |
|
| 396 |
/* Component-related parameters. */ |
| 397 |
jpc_coxcp_t compparms; |
| 398 |
|
| 399 |
} jpc_coc_t; |
| 400 |
|
| 401 |
/**************************************\ |
| 402 |
* RGN marker segment parameters. |
| 403 |
\**************************************/ |
| 404 |
|
| 405 |
/* The maxshift ROI style. */ |
| 406 |
#define JPC_RGN_MAXSHIFT 0x00 |
| 407 |
|
| 408 |
typedef struct { |
| 409 |
|
| 410 |
/* The component to which the marker applies. */ |
| 411 |
uint_fast16_t compno; |
| 412 |
|
| 413 |
/* The ROI style. */ |
| 414 |
uint_fast8_t roisty; |
| 415 |
|
| 416 |
/* The ROI shift value. */ |
| 417 |
uint_fast8_t roishift; |
| 418 |
|
| 419 |
} jpc_rgn_t; |
| 420 |
|
| 421 |
/**************************************\ |
| 422 |
* QCD/QCC marker segment parameters. |
| 423 |
\**************************************/ |
| 424 |
|
| 425 |
/* |
| 426 |
* Quantization style constants. |
| 427 |
*/ |
| 428 |
|
| 429 |
#define JPC_QCX_NOQNT 0 /* No quantization. */ |
| 430 |
#define JPC_QCX_SIQNT 1 /* Scalar quantization, implicit. */ |
| 431 |
#define JPC_QCX_SEQNT 2 /* Scalar quantization, explicit. */ |
| 432 |
|
| 433 |
/* |
| 434 |
* Stepsize manipulation macros. |
| 435 |
*/ |
| 436 |
|
| 437 |
#define JPC_QCX_GETEXPN(x) ((x) >> 11) |
| 438 |
#define JPC_QCX_GETMANT(x) ((x) & 0x07ff) |
| 439 |
#define JPC_QCX_EXPN(x) (assert(!((x) & (~0x1f))), (((x) & 0x1f) << 11)) |
| 440 |
#define JPC_QCX_MANT(x) (assert(!((x) & (~0x7ff))), ((x) & 0x7ff)) |
| 441 |
|
| 442 |
/* Per component information. */ |
| 443 |
|
| 444 |
typedef struct { |
| 445 |
|
| 446 |
/* The quantization style. */ |
| 447 |
uint_fast8_t qntsty; |
| 448 |
|
| 449 |
/* The number of step sizes. */ |
| 450 |
int numstepsizes; |
| 451 |
|
| 452 |
/* The step sizes. */ |
| 453 |
uint_fast16_t *stepsizes; |
| 454 |
|
| 455 |
/* The number of guard bits. */ |
| 456 |
uint_fast8_t numguard; |
| 457 |
|
| 458 |
} jpc_qcxcp_t; |
| 459 |
|
| 460 |
/* QCC marker segment parameters. */ |
| 461 |
|
| 462 |
typedef struct { |
| 463 |
|
| 464 |
/* The component associated with this marker segment. */ |
| 465 |
uint_fast16_t compno; |
| 466 |
|
| 467 |
/* The parameters. */ |
| 468 |
jpc_qcxcp_t compparms; |
| 469 |
|
| 470 |
} jpc_qcc_t; |
| 471 |
|
| 472 |
/* QCD marker segment parameters. */ |
| 473 |
|
| 474 |
typedef struct { |
| 475 |
|
| 476 |
/* The parameters. */ |
| 477 |
jpc_qcxcp_t compparms; |
| 478 |
|
| 479 |
} jpc_qcd_t; |
| 480 |
|
| 481 |
/**************************************\ |
| 482 |
* POD marker segment parameters. |
| 483 |
\**************************************/ |
| 484 |
|
| 485 |
typedef struct { |
| 486 |
|
| 487 |
/* The progression order. */ |
| 488 |
uint_fast8_t prgord; |
| 489 |
|
| 490 |
/* The lower bound (inclusive) on the resolution level for the |
| 491 |
progression order volume. */ |
| 492 |
uint_fast8_t rlvlnostart; |
| 493 |
|
| 494 |
/* The upper bound (exclusive) on the resolution level for the |
| 495 |
progression order volume. */ |
| 496 |
uint_fast8_t rlvlnoend; |
| 497 |
|
| 498 |
/* The lower bound (inclusive) on the component for the progression |
| 499 |
order volume. */ |
| 500 |
uint_fast16_t compnostart; |
| 501 |
|
| 502 |
/* The upper bound (exclusive) on the component for the progression |
| 503 |
order volume. */ |
| 504 |
uint_fast16_t compnoend; |
| 505 |
|
| 506 |
/* The upper bound (exclusive) on the layer for the progression |
| 507 |
order volume. */ |
| 508 |
uint_fast16_t lyrnoend; |
| 509 |
|
| 510 |
} jpc_pocpchg_t; |
| 511 |
|
| 512 |
/* An alias for the above type. */ |
| 513 |
typedef jpc_pocpchg_t jpc_pchg_t; |
| 514 |
|
| 515 |
/* POC marker segment parameters. */ |
| 516 |
|
| 517 |
typedef struct { |
| 518 |
|
| 519 |
/* The number of progression order changes. */ |
| 520 |
int numpchgs; |
| 521 |
|
| 522 |
/* The per-progression-order-change information. */ |
| 523 |
jpc_pocpchg_t *pchgs; |
| 524 |
|
| 525 |
} jpc_poc_t; |
| 526 |
|
| 527 |
/**************************************\ |
| 528 |
* PPM/PPT marker segment parameters. |
| 529 |
\**************************************/ |
| 530 |
|
| 531 |
/* PPM marker segment parameters. */ |
| 532 |
|
| 533 |
typedef struct { |
| 534 |
|
| 535 |
/* The index. */ |
| 536 |
uint_fast8_t ind; |
| 537 |
|
| 538 |
/* The length. */ |
| 539 |
uint_fast16_t len; |
| 540 |
|
| 541 |
/* The data. */ |
| 542 |
unsigned char *data; |
| 543 |
|
| 544 |
} jpc_ppm_t; |
| 545 |
|
| 546 |
/* PPT marker segment parameters. */ |
| 547 |
|
| 548 |
typedef struct { |
| 549 |
|
| 550 |
/* The index. */ |
| 551 |
uint_fast8_t ind; |
| 552 |
|
| 553 |
/* The length. */ |
| 554 |
uint_fast32_t len; |
| 555 |
|
| 556 |
/* The data. */ |
| 557 |
unsigned char *data; |
| 558 |
|
| 559 |
} jpc_ppt_t; |
| 560 |
|
| 561 |
/**************************************\ |
| 562 |
* COM marker segment parameters. |
| 563 |
\**************************************/ |
| 564 |
|
| 565 |
/* |
| 566 |
* Registration IDs. |
| 567 |
*/ |
| 568 |
|
| 569 |
#define JPC_COM_BIN 0x00 |
| 570 |
#define JPC_COM_LATIN 0x01 |
| 571 |
|
| 572 |
typedef struct { |
| 573 |
|
| 574 |
/* The registration ID. */ |
| 575 |
uint_fast16_t regid; |
| 576 |
|
| 577 |
/* The length of the data in bytes. */ |
| 578 |
uint_fast16_t len; |
| 579 |
|
| 580 |
/* The data. */ |
| 581 |
unsigned char *data; |
| 582 |
|
| 583 |
} jpc_com_t; |
| 584 |
|
| 585 |
/**************************************\ |
| 586 |
* SOP marker segment parameters. |
| 587 |
\**************************************/ |
| 588 |
|
| 589 |
typedef struct { |
| 590 |
|
| 591 |
/* The sequence number. */ |
| 592 |
uint_fast16_t seqno; |
| 593 |
|
| 594 |
} jpc_sop_t; |
| 595 |
|
| 596 |
/**************************************\ |
| 597 |
* CRG marker segment parameters. |
| 598 |
\**************************************/ |
| 599 |
|
| 600 |
/* Per component information. */ |
| 601 |
|
| 602 |
typedef struct { |
| 603 |
|
| 604 |
/* The horizontal offset. */ |
| 605 |
uint_fast16_t hoff; |
| 606 |
|
| 607 |
/* The vertical offset. */ |
| 608 |
uint_fast16_t voff; |
| 609 |
|
| 610 |
} jpc_crgcomp_t; |
| 611 |
|
| 612 |
typedef struct { |
| 613 |
|
| 614 |
/* The number of components. */ |
| 615 |
int numcomps; |
| 616 |
|
| 617 |
/* Per component information. */ |
| 618 |
jpc_crgcomp_t *comps; |
| 619 |
|
| 620 |
} jpc_crg_t; |
| 621 |
|
| 622 |
/**************************************\ |
| 623 |
* Marker segment parameters for unknown marker type. |
| 624 |
\**************************************/ |
| 625 |
|
| 626 |
typedef struct { |
| 627 |
|
| 628 |
/* The data. */ |
| 629 |
unsigned char *data; |
| 630 |
|
| 631 |
/* The length. */ |
| 632 |
uint_fast16_t len; |
| 633 |
|
| 634 |
} jpc_unk_t; |
| 635 |
|
| 636 |
/**************************************\ |
| 637 |
* Generic marker segment parameters. |
| 638 |
\**************************************/ |
| 639 |
|
| 640 |
typedef union { |
| 641 |
int soc; /* unused */ |
| 642 |
jpc_sot_t sot; |
| 643 |
int sod; /* unused */ |
| 644 |
int eoc; /* unused */ |
| 645 |
jpc_siz_t siz; |
| 646 |
jpc_cod_t cod; |
| 647 |
jpc_coc_t coc; |
| 648 |
jpc_rgn_t rgn; |
| 649 |
jpc_qcd_t qcd; |
| 650 |
jpc_qcc_t qcc; |
| 651 |
jpc_poc_t poc; |
| 652 |
/* jpc_plm_t plm; */ |
| 653 |
/* jpc_plt_t plt; */ |
| 654 |
jpc_ppm_t ppm; |
| 655 |
jpc_ppt_t ppt; |
| 656 |
jpc_sop_t sop; |
| 657 |
int eph; /* unused */ |
| 658 |
jpc_com_t com; |
| 659 |
jpc_crg_t crg; |
| 660 |
jpc_unk_t unk; |
| 661 |
} jpc_msparms_t; |
| 662 |
|
| 663 |
/**************************************\ |
| 664 |
* Marker segment. |
| 665 |
\**************************************/ |
| 666 |
|
| 667 |
/* Marker segment IDs. */ |
| 668 |
|
| 669 |
/* The smallest valid marker value. */ |
| 670 |
#define JPC_MS_MIN 0xff00 |
| 671 |
|
| 672 |
/* The largest valid marker value. */ |
| 673 |
#define JPC_MS_MAX 0xffff |
| 674 |
|
| 675 |
/* The minimum marker value that cannot occur within packet data. */ |
| 676 |
#define JPC_MS_INMIN 0xff80 |
| 677 |
/* The maximum marker value that cannot occur within packet data. */ |
| 678 |
#define JPC_MS_INMAX 0xffff |
| 679 |
|
| 680 |
/* Delimiting marker segments. */ |
| 681 |
#define JPC_MS_SOC 0xff4f /* Start of code stream (SOC). */ |
| 682 |
#define JPC_MS_SOT 0xff90 /* Start of tile-part (SOT). */ |
| 683 |
#define JPC_MS_SOD 0xff93 /* Start of data (SOD). */ |
| 684 |
#define JPC_MS_EOC 0xffd9 /* End of code stream (EOC). */ |
| 685 |
|
| 686 |
/* Fixed information marker segments. */ |
| 687 |
#define JPC_MS_SIZ 0xff51 /* Image and tile size (SIZ). */ |
| 688 |
|
| 689 |
/* Functional marker segments. */ |
| 690 |
#define JPC_MS_COD 0xff52 /* Coding style default (COD). */ |
| 691 |
#define JPC_MS_COC 0xff53 /* Coding style component (COC). */ |
| 692 |
#define JPC_MS_RGN 0xff5e /* Region of interest (RGN). */ |
| 693 |
#define JPC_MS_QCD 0xff5c /* Quantization default (QCD). */ |
| 694 |
#define JPC_MS_QCC 0xff5d /* Quantization component (QCC). */ |
| 695 |
#define JPC_MS_POC 0xff5f /* Progression order default (POC). */ |
| 696 |
|
| 697 |
/* Pointer marker segments. */ |
| 698 |
#define JPC_MS_TLM 0xff55 /* Tile-part lengths, main header (TLM). */ |
| 699 |
#define JPC_MS_PLM 0xff57 /* Packet length, main header (PLM). */ |
| 700 |
#define JPC_MS_PLT 0xff58 /* Packet length, tile-part header (PLT). */ |
| 701 |
#define JPC_MS_PPM 0xff60 /* Packed packet headers, main header (PPM). */ |
| 702 |
#define JPC_MS_PPT 0xff61 /* Packet packet headers, tile-part header (PPT). */ |
| 703 |
|
| 704 |
/* In bit stream marker segments. */ |
| 705 |
#define JPC_MS_SOP 0xff91 /* Start of packet (SOP). */ |
| 706 |
#define JPC_MS_EPH 0xff92 /* End of packet header (EPH). */ |
| 707 |
|
| 708 |
/* Informational marker segments. */ |
| 709 |
#define JPC_MS_CRG 0xff63 /* Component registration (CRG). */ |
| 710 |
#define JPC_MS_COM 0xff64 /* Comment (COM). */ |
| 711 |
|
| 712 |
/* Forward declaration. */ |
| 713 |
struct jpc_msops_s; |
| 714 |
|
| 715 |
/* Generic marker segment class. */ |
| 716 |
|
| 717 |
typedef struct { |
| 718 |
|
| 719 |
/* The type of marker segment. */ |
| 720 |
uint_fast16_t id; |
| 721 |
|
| 722 |
/* The length of the marker segment. */ |
| 723 |
uint_fast16_t len; |
| 724 |
|
| 725 |
/* The starting offset within the stream. */ |
| 726 |
uint_fast32_t off; |
| 727 |
|
| 728 |
/* The parameters of the marker segment. */ |
| 729 |
jpc_msparms_t parms; |
| 730 |
|
| 731 |
/* The marker segment operations. */ |
| 732 |
struct jpc_msops_s *ops; |
| 733 |
|
| 734 |
} jpc_ms_t; |
| 735 |
|
| 736 |
/* Marker segment operations (which depend on the marker segment type). */ |
| 737 |
|
| 738 |
typedef struct jpc_msops_s { |
| 739 |
|
| 740 |
/* Destroy the marker segment parameters. */ |
| 741 |
void (*destroyparms)(jpc_ms_t *ms); |
| 742 |
|
| 743 |
/* Get the marker segment parameters from a stream. */ |
| 744 |
int (*getparms)(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in); |
| 745 |
|
| 746 |
/* Put the marker segment parameters to a stream. */ |
| 747 |
int (*putparms)(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out); |
| 748 |
|
| 749 |
/* Dump the marker segment parameters (for debugging). */ |
| 750 |
int (*dumpparms)(jpc_ms_t *ms, FILE *out); |
| 751 |
|
| 752 |
} jpc_msops_t; |
| 753 |
|
| 754 |
/******************************************************************************\ |
| 755 |
* Macros/Functions. |
| 756 |
\******************************************************************************/ |
| 757 |
|
| 758 |
/* Create a code-stream state object. */ |
| 759 |
jpc_cstate_t *jpc_cstate_create(void); |
| 760 |
|
| 761 |
/* Destroy a code-stream state object. */ |
| 762 |
void jpc_cstate_destroy(jpc_cstate_t *cstate); |
| 763 |
|
| 764 |
/* Create a marker segment. */ |
| 765 |
jpc_ms_t *jpc_ms_create(int type); |
| 766 |
|
| 767 |
/* Destroy a marker segment. */ |
| 768 |
void jpc_ms_destroy(jpc_ms_t *ms); |
| 769 |
|
| 770 |
/* Does a marker segment have parameters? */ |
| 771 |
#define JPC_MS_HASPARMS(x) \ |
| 772 |
(!((x) == JPC_MS_SOC || (x) == JPC_MS_SOD || (x) == JPC_MS_EOC || \ |
| 773 |
(x) == JPC_MS_EPH || ((x) >= 0xff30 && (x) <= 0xff3f))) |
| 774 |
|
| 775 |
/* Get the marker segment type. */ |
| 776 |
#define jpc_ms_gettype(ms) \ |
| 777 |
((ms)->id) |
| 778 |
|
| 779 |
/* Read a marker segment from a stream. */ |
| 780 |
jpc_ms_t *jpc_getms(jas_stream_t *in, jpc_cstate_t *cstate); |
| 781 |
|
| 782 |
/* Write a marker segment to a stream. */ |
| 783 |
int jpc_putms(jas_stream_t *out, jpc_cstate_t *cstate, jpc_ms_t *ms); |
| 784 |
|
| 785 |
/* Copy code stream data from one stream to another. */ |
| 786 |
int jpc_getdata(jas_stream_t *in, jas_stream_t *out, long n); |
| 787 |
|
| 788 |
/* Copy code stream data from one stream to another. */ |
| 789 |
int jpc_putdata(jas_stream_t *out, jas_stream_t *in, long n); |
| 790 |
|
| 791 |
/* Dump a marker segment (for debugging). */ |
| 792 |
void jpc_ms_dump(jpc_ms_t *ms, FILE *out); |
| 793 |
|
| 794 |
/* Read a 8-bit unsigned integer from a stream. */ |
| 795 |
int jpc_getuint8(jas_stream_t *in, uint_fast8_t *val); |
| 796 |
|
| 797 |
/* Read a 16-bit unsigned integer from a stream. */ |
| 798 |
int jpc_getuint16(jas_stream_t *in, uint_fast16_t *val); |
| 799 |
|
| 800 |
/* Read a 32-bit unsigned integer from a stream. */ |
| 801 |
int jpc_getuint32(jas_stream_t *in, uint_fast32_t *val); |
| 802 |
|
| 803 |
/* Write a 8-bit unsigned integer to a stream. */ |
| 804 |
int jpc_putuint8(jas_stream_t *out, uint_fast8_t val); |
| 805 |
|
| 806 |
/* Write a 16-bit unsigned integer to a stream. */ |
| 807 |
int jpc_putuint16(jas_stream_t *out, uint_fast16_t val); |
| 808 |
|
| 809 |
/* Write a 32-bit unsigned integer to a stream. */ |
| 810 |
int jpc_putuint32(jas_stream_t *out, uint_fast32_t val); |
| 811 |
|
| 812 |
#endif |