| 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 Decoder |
| 115 |
* |
| 116 |
* $Id$ |
| 117 |
*/ |
| 118 |
|
| 119 |
#ifndef JPC_DEC_H |
| 120 |
#define JPC_DEC_H |
| 121 |
|
| 122 |
/******************************************************************************\ |
| 123 |
* Includes. |
| 124 |
\******************************************************************************/ |
| 125 |
|
| 126 |
#include "jasper/jas_stream.h" |
| 127 |
|
| 128 |
#include "jpc_tsfb.h" |
| 129 |
#include "jpc_bs.h" |
| 130 |
#include "jpc_tagtree.h" |
| 131 |
#include "jpc_cs.h" |
| 132 |
#include "jpc_cod.h" |
| 133 |
#include "jpc_mqdec.h" |
| 134 |
#include "jpc_t2cod.h" |
| 135 |
|
| 136 |
/******************************************************************************\ |
| 137 |
* Below are some ugly warts necessary to support packed packet headers. |
| 138 |
\******************************************************************************/ |
| 139 |
|
| 140 |
/* PPM/PPT marker segment table entry. */ |
| 141 |
|
| 142 |
typedef struct { |
| 143 |
|
| 144 |
/* The index for this entry. */ |
| 145 |
uint_fast16_t ind; |
| 146 |
|
| 147 |
/* The data length. */ |
| 148 |
uint_fast32_t len; |
| 149 |
|
| 150 |
/* The data. */ |
| 151 |
unsigned char *data; |
| 152 |
|
| 153 |
} jpc_ppxstabent_t; |
| 154 |
|
| 155 |
/* PPM/PPT marker segment table. */ |
| 156 |
|
| 157 |
typedef struct { |
| 158 |
|
| 159 |
/* The number of entries. */ |
| 160 |
int numents; |
| 161 |
|
| 162 |
/* The maximum number of entries (i.e., the allocated size of the array |
| 163 |
below). */ |
| 164 |
int maxents; |
| 165 |
|
| 166 |
/* The table entries. */ |
| 167 |
jpc_ppxstabent_t **ents; |
| 168 |
|
| 169 |
} jpc_ppxstab_t; |
| 170 |
|
| 171 |
/* Stream list class. */ |
| 172 |
|
| 173 |
typedef struct { |
| 174 |
|
| 175 |
/* The number of streams in this list. */ |
| 176 |
int numstreams; |
| 177 |
|
| 178 |
/* The maximum number of streams that can be accommodated without |
| 179 |
growing the streams array. */ |
| 180 |
int maxstreams; |
| 181 |
|
| 182 |
/* The streams. */ |
| 183 |
jas_stream_t **streams; |
| 184 |
|
| 185 |
} jpc_streamlist_t; |
| 186 |
|
| 187 |
/******************************************************************************\ |
| 188 |
* Coding parameters class. |
| 189 |
\******************************************************************************/ |
| 190 |
|
| 191 |
/* Per-component coding parameters. */ |
| 192 |
|
| 193 |
typedef struct { |
| 194 |
|
| 195 |
/* How were various coding parameters set? */ |
| 196 |
int flags; |
| 197 |
|
| 198 |
/* Per-component coding style parameters (e.g., explicit precinct sizes) */ |
| 199 |
uint_fast8_t csty; |
| 200 |
|
| 201 |
/* The number of resolution levels. */ |
| 202 |
uint_fast8_t numrlvls; |
| 203 |
|
| 204 |
/* The code block width exponent. */ |
| 205 |
uint_fast8_t cblkwidthexpn; |
| 206 |
|
| 207 |
/* The code block height exponent. */ |
| 208 |
uint_fast8_t cblkheightexpn; |
| 209 |
|
| 210 |
/* The QMFB ID. */ |
| 211 |
uint_fast8_t qmfbid; |
| 212 |
|
| 213 |
/* The quantization style. */ |
| 214 |
uint_fast8_t qsty; |
| 215 |
|
| 216 |
/* The number of quantizer step sizes. */ |
| 217 |
uint_fast16_t numstepsizes; |
| 218 |
|
| 219 |
/* The step sizes. */ |
| 220 |
uint_fast16_t stepsizes[3 * JPC_MAXRLVLS + 1]; |
| 221 |
|
| 222 |
/* The number of guard bits. */ |
| 223 |
uint_fast8_t numguardbits; |
| 224 |
|
| 225 |
/* The ROI shift value. */ |
| 226 |
uint_fast8_t roishift; |
| 227 |
|
| 228 |
/* The code block parameters. */ |
| 229 |
uint_fast8_t cblkctx; |
| 230 |
|
| 231 |
/* The precinct width exponents. */ |
| 232 |
uint_fast8_t prcwidthexpns[JPC_MAXRLVLS]; |
| 233 |
|
| 234 |
/* The precinct height exponents. */ |
| 235 |
uint_fast8_t prcheightexpns[JPC_MAXRLVLS]; |
| 236 |
|
| 237 |
} jpc_dec_ccp_t; |
| 238 |
|
| 239 |
/* Coding parameters. */ |
| 240 |
|
| 241 |
typedef struct { |
| 242 |
|
| 243 |
/* How were these coding parameters set? */ |
| 244 |
int flags; |
| 245 |
|
| 246 |
/* Progression change list. */ |
| 247 |
jpc_pchglist_t *pchglist; |
| 248 |
|
| 249 |
/* Progression order. */ |
| 250 |
uint_fast8_t prgord; |
| 251 |
|
| 252 |
/* The number of layers. */ |
| 253 |
uint_fast16_t numlyrs; |
| 254 |
|
| 255 |
/* The MCT ID. */ |
| 256 |
uint_fast8_t mctid; |
| 257 |
|
| 258 |
/* The coding style parameters (e.g., SOP, EPH). */ |
| 259 |
uint_fast8_t csty; |
| 260 |
|
| 261 |
/* The number of components. */ |
| 262 |
uint_fast16_t numcomps; |
| 263 |
|
| 264 |
/* The per-component coding parameters. */ |
| 265 |
jpc_dec_ccp_t *ccps; |
| 266 |
|
| 267 |
} jpc_dec_cp_t; |
| 268 |
|
| 269 |
/******************************************************************************\ |
| 270 |
* Decoder class. |
| 271 |
\******************************************************************************/ |
| 272 |
|
| 273 |
/* Decoder per-segment state information. */ |
| 274 |
|
| 275 |
typedef struct jpc_dec_seg_s { |
| 276 |
|
| 277 |
/* The next segment in the list. */ |
| 278 |
struct jpc_dec_seg_s *next; |
| 279 |
|
| 280 |
/* The previous segment in the list. */ |
| 281 |
struct jpc_dec_seg_s *prev; |
| 282 |
|
| 283 |
/* The starting pass number for this segment. */ |
| 284 |
int passno; |
| 285 |
|
| 286 |
/* The number of passes in this segment. */ |
| 287 |
int numpasses; |
| 288 |
|
| 289 |
/* The maximum number of passes in this segment. */ |
| 290 |
int maxpasses; |
| 291 |
|
| 292 |
/* The type of data in this segment (i.e., MQ or raw). */ |
| 293 |
int type; |
| 294 |
|
| 295 |
/* A stream containing the data for this segment. */ |
| 296 |
jas_stream_t *stream; |
| 297 |
|
| 298 |
/* The number of bytes destined for this segment from the packet |
| 299 |
currently being decoded. */ |
| 300 |
int cnt; |
| 301 |
|
| 302 |
/* A flag indicating if this segment has been terminated. */ |
| 303 |
int complete; |
| 304 |
|
| 305 |
/* The layer number to which this segment belongs. */ |
| 306 |
/* If the segment spans multiple layers, then the largest layer number |
| 307 |
spanned by the segment is used. */ |
| 308 |
int lyrno; |
| 309 |
|
| 310 |
} jpc_dec_seg_t; |
| 311 |
|
| 312 |
/* Decoder segment list. */ |
| 313 |
|
| 314 |
typedef struct { |
| 315 |
|
| 316 |
/* The first entry in the list. */ |
| 317 |
jpc_dec_seg_t *head; |
| 318 |
|
| 319 |
/* The last entry in the list. */ |
| 320 |
jpc_dec_seg_t *tail; |
| 321 |
|
| 322 |
} jpc_dec_seglist_t; |
| 323 |
|
| 324 |
/* Decoder per-code-block state information. */ |
| 325 |
|
| 326 |
typedef struct { |
| 327 |
|
| 328 |
/* The number of passes. */ |
| 329 |
int numpasses; |
| 330 |
|
| 331 |
/* A list of segments that still need to be decoded. */ |
| 332 |
jpc_dec_seglist_t segs; |
| 333 |
|
| 334 |
/* The first incomplete/partial segment. */ |
| 335 |
jpc_dec_seg_t *curseg; |
| 336 |
|
| 337 |
/* The number of leading insignificant bit planes for this code block. */ |
| 338 |
int numimsbs; |
| 339 |
|
| 340 |
/* The number of bits used to encode pass data lengths. */ |
| 341 |
int numlenbits; |
| 342 |
|
| 343 |
/* The first pass number containing data for this code block. */ |
| 344 |
int firstpassno; |
| 345 |
|
| 346 |
/* The MQ decoder. */ |
| 347 |
jpc_mqdec_t *mqdec; |
| 348 |
|
| 349 |
/* The raw bit stream decoder. */ |
| 350 |
jpc_bitstream_t *nulldec; |
| 351 |
|
| 352 |
/* The per-sample state information for this code block. */ |
| 353 |
jas_matrix_t *flags; |
| 354 |
|
| 355 |
/* The sample data associated with this code block. */ |
| 356 |
jas_matrix_t *data; |
| 357 |
|
| 358 |
} jpc_dec_cblk_t; |
| 359 |
|
| 360 |
/* Decoder per-code-block-group state information. */ |
| 361 |
|
| 362 |
typedef struct { |
| 363 |
|
| 364 |
/* The x-coordinate of the top-left corner of the precinct. */ |
| 365 |
uint_fast32_t xstart; |
| 366 |
|
| 367 |
/* The y-coordinate of the top-left corner of the precinct. */ |
| 368 |
uint_fast32_t ystart; |
| 369 |
|
| 370 |
/* The x-coordinate of the bottom-right corner of the precinct |
| 371 |
(plus one). */ |
| 372 |
uint_fast32_t xend; |
| 373 |
|
| 374 |
/* The y-coordinate of the bottom-right corner of the precinct |
| 375 |
(plus one). */ |
| 376 |
uint_fast32_t yend; |
| 377 |
|
| 378 |
/* The number of code blocks spanning this precinct in the horizontal |
| 379 |
direction. */ |
| 380 |
int numhcblks; |
| 381 |
|
| 382 |
/* The number of code blocks spanning this precinct in the vertical |
| 383 |
direction. */ |
| 384 |
int numvcblks; |
| 385 |
|
| 386 |
/* The total number of code blocks in this precinct. */ |
| 387 |
int numcblks; |
| 388 |
|
| 389 |
/* The per code block information. */ |
| 390 |
jpc_dec_cblk_t *cblks; |
| 391 |
|
| 392 |
/* The inclusion tag tree. */ |
| 393 |
jpc_tagtree_t *incltagtree; |
| 394 |
|
| 395 |
/* The insignificant MSBs tag tree. */ |
| 396 |
jpc_tagtree_t *numimsbstagtree; |
| 397 |
|
| 398 |
} jpc_dec_prc_t; |
| 399 |
|
| 400 |
/* Decoder per-band state information. */ |
| 401 |
|
| 402 |
typedef struct { |
| 403 |
|
| 404 |
/* The per-code-block-group state information. */ |
| 405 |
jpc_dec_prc_t *prcs; |
| 406 |
|
| 407 |
/* The sample data associated with this band. */ |
| 408 |
jas_matrix_t *data; |
| 409 |
|
| 410 |
/* The orientation of this band (i.e., LL, LH, HL, or HH). */ |
| 411 |
int orient; |
| 412 |
|
| 413 |
/* The encoded quantizer step size. */ |
| 414 |
int stepsize; |
| 415 |
|
| 416 |
/* The absolute quantizer step size. */ |
| 417 |
jpc_fix_t absstepsize; |
| 418 |
|
| 419 |
/* The number of bit planes for this band. */ |
| 420 |
int numbps; |
| 421 |
|
| 422 |
/* The analysis gain associated with this band. */ |
| 423 |
int analgain; |
| 424 |
|
| 425 |
/* The ROI shift value for this band. */ |
| 426 |
int roishift; |
| 427 |
|
| 428 |
} jpc_dec_band_t; |
| 429 |
|
| 430 |
/* Decoder per-resolution-level state information. */ |
| 431 |
|
| 432 |
typedef struct { |
| 433 |
|
| 434 |
/* The number of bands associated with this resolution level. */ |
| 435 |
int numbands; |
| 436 |
|
| 437 |
/* The per-band information. */ |
| 438 |
jpc_dec_band_t *bands; |
| 439 |
|
| 440 |
/* The x-coordinate of the top-left corner of the tile-component |
| 441 |
at this resolution. */ |
| 442 |
uint_fast32_t xstart; |
| 443 |
|
| 444 |
/* The y-coordinate of the top-left corner of the tile-component |
| 445 |
at this resolution. */ |
| 446 |
uint_fast32_t ystart; |
| 447 |
|
| 448 |
/* The x-coordinate of the bottom-right corner of the tile-component |
| 449 |
at this resolution (plus one). */ |
| 450 |
uint_fast32_t xend; |
| 451 |
|
| 452 |
/* The y-coordinate of the bottom-right corner of the tile-component |
| 453 |
at this resolution (plus one). */ |
| 454 |
uint_fast32_t yend; |
| 455 |
|
| 456 |
/* The exponent value for the nominal precinct width measured |
| 457 |
relative to the associated LL band. */ |
| 458 |
int prcwidthexpn; |
| 459 |
|
| 460 |
/* The exponent value for the nominal precinct height measured |
| 461 |
relative to the associated LL band. */ |
| 462 |
int prcheightexpn; |
| 463 |
|
| 464 |
/* The number of precincts in the horizontal direction. */ |
| 465 |
int numhprcs; |
| 466 |
|
| 467 |
/* The number of precincts in the vertical direction. */ |
| 468 |
int numvprcs; |
| 469 |
|
| 470 |
/* The total number of precincts. */ |
| 471 |
int numprcs; |
| 472 |
|
| 473 |
/* The exponent value for the nominal code block group width. |
| 474 |
This quantity is associated with the next lower resolution level |
| 475 |
(assuming that there is one). */ |
| 476 |
int cbgwidthexpn; |
| 477 |
|
| 478 |
/* The exponent value for the nominal code block group height |
| 479 |
This quantity is associated with the next lower resolution level |
| 480 |
(assuming that there is one). */ |
| 481 |
int cbgheightexpn; |
| 482 |
|
| 483 |
/* The exponent value for the code block width. */ |
| 484 |
uint_fast16_t cblkwidthexpn; |
| 485 |
|
| 486 |
/* The exponent value for the code block height. */ |
| 487 |
uint_fast16_t cblkheightexpn; |
| 488 |
|
| 489 |
} jpc_dec_rlvl_t; |
| 490 |
|
| 491 |
/* Decoder per-tile-component state information. */ |
| 492 |
|
| 493 |
typedef struct { |
| 494 |
|
| 495 |
/* The x-coordinate of the top-left corner of the tile-component |
| 496 |
in the coordinate system of the tile-component. */ |
| 497 |
uint_fast32_t xstart; |
| 498 |
|
| 499 |
/* The y-coordinate of the top-left corner of the tile-component |
| 500 |
in the coordinate system of the tile-component. */ |
| 501 |
uint_fast32_t ystart; |
| 502 |
|
| 503 |
/* The x-coordinate of the bottom-right corner of the tile-component |
| 504 |
in the coordinate system of the tile-component (plus one). */ |
| 505 |
uint_fast32_t xend; |
| 506 |
|
| 507 |
/* The y-coordinate of the bottom-right corner of the tile-component |
| 508 |
in the coordinate system of the tile-component (plus one). */ |
| 509 |
uint_fast32_t yend; |
| 510 |
|
| 511 |
/* The component data for the current tile. */ |
| 512 |
jas_matrix_t *data; |
| 513 |
|
| 514 |
/* The number of resolution levels. */ |
| 515 |
uint_fast16_t numrlvls; |
| 516 |
|
| 517 |
/* The per resolution level information. */ |
| 518 |
jpc_dec_rlvl_t *rlvls; |
| 519 |
|
| 520 |
/* The TSFB. */ |
| 521 |
jpc_tsfb_t *tsfb; |
| 522 |
|
| 523 |
} jpc_dec_tcomp_t; |
| 524 |
|
| 525 |
/* |
| 526 |
* Tile states. |
| 527 |
*/ |
| 528 |
|
| 529 |
#define JPC_TILE_INIT 0 |
| 530 |
#define JPC_TILE_ACTIVE 1 |
| 531 |
#define JPC_TILE_ACTIVELAST 2 |
| 532 |
#define JPC_TILE_DONE 3 |
| 533 |
|
| 534 |
/* Decoder per-tile state information. */ |
| 535 |
|
| 536 |
typedef struct { |
| 537 |
|
| 538 |
/* The processing state for this tile. */ |
| 539 |
int state; |
| 540 |
|
| 541 |
/* The x-coordinate of the top-left corner of the tile on the reference |
| 542 |
grid. */ |
| 543 |
uint_fast32_t xstart; |
| 544 |
|
| 545 |
/* The y-coordinate of the top-left corner of the tile on the reference |
| 546 |
grid. */ |
| 547 |
uint_fast32_t ystart; |
| 548 |
|
| 549 |
/* The x-coordinate of the bottom-right corner of the tile on the |
| 550 |
reference grid (plus one). */ |
| 551 |
uint_fast32_t xend; |
| 552 |
|
| 553 |
/* The y-coordinate of the bottom-right corner of the tile on the |
| 554 |
reference grid (plus one). */ |
| 555 |
uint_fast32_t yend; |
| 556 |
|
| 557 |
/* The packed packet header data for this tile. */ |
| 558 |
jpc_ppxstab_t *pptstab; |
| 559 |
|
| 560 |
/* A stream containing the packed packet header data for this tile. */ |
| 561 |
jas_stream_t *pkthdrstream; |
| 562 |
|
| 563 |
/* The current position within the packed packet header stream. */ |
| 564 |
long pkthdrstreampos; |
| 565 |
|
| 566 |
/* The coding parameters for this tile. */ |
| 567 |
jpc_dec_cp_t *cp; |
| 568 |
|
| 569 |
/* The per tile-component information. */ |
| 570 |
jpc_dec_tcomp_t *tcomps; |
| 571 |
|
| 572 |
/* The next expected tile-part number. */ |
| 573 |
int partno; |
| 574 |
|
| 575 |
/* The number of tile-parts. */ |
| 576 |
int numparts; |
| 577 |
|
| 578 |
/* The coding mode. */ |
| 579 |
int realmode; |
| 580 |
|
| 581 |
/* The packet iterator for this tile. */ |
| 582 |
jpc_pi_t *pi; |
| 583 |
|
| 584 |
} jpc_dec_tile_t; |
| 585 |
|
| 586 |
/* Decoder per-component state information. */ |
| 587 |
|
| 588 |
typedef struct { |
| 589 |
|
| 590 |
/* The horizontal sampling period. */ |
| 591 |
uint_fast32_t hstep; |
| 592 |
|
| 593 |
/* The vertical sampling period. */ |
| 594 |
uint_fast32_t vstep; |
| 595 |
|
| 596 |
/* The number of samples in the horizontal direction. */ |
| 597 |
uint_fast32_t width; |
| 598 |
|
| 599 |
/* The number of samples in the vertical direction. */ |
| 600 |
uint_fast32_t height; |
| 601 |
|
| 602 |
/* The precision of the sample data. */ |
| 603 |
uint_fast16_t prec; |
| 604 |
|
| 605 |
/* The signedness of the sample data. */ |
| 606 |
bool sgnd; |
| 607 |
|
| 608 |
/* The sample alignment horizontal offset. */ |
| 609 |
uint_fast32_t hsubstep; |
| 610 |
|
| 611 |
/* The sample alignment vertical offset. */ |
| 612 |
uint_fast32_t vsubstep; |
| 613 |
|
| 614 |
} jpc_dec_cmpt_t; |
| 615 |
|
| 616 |
/* Decoder state information. */ |
| 617 |
|
| 618 |
typedef struct { |
| 619 |
|
| 620 |
/* The decoded image. */ |
| 621 |
jas_image_t *image; |
| 622 |
|
| 623 |
/* The x-coordinate of the top-left corner of the image area on |
| 624 |
the reference grid. */ |
| 625 |
uint_fast32_t xstart; |
| 626 |
|
| 627 |
/* The y-coordinate of the top-left corner of the image area on |
| 628 |
the reference grid. */ |
| 629 |
uint_fast32_t ystart; |
| 630 |
|
| 631 |
/* The x-coordinate of the bottom-right corner of the image area on |
| 632 |
the reference grid (plus one). */ |
| 633 |
uint_fast32_t xend; |
| 634 |
|
| 635 |
/* The y-coordinate of the bottom-right corner of the image area on |
| 636 |
the reference grid (plus one). */ |
| 637 |
uint_fast32_t yend; |
| 638 |
|
| 639 |
/* The nominal tile width in units of the image reference grid. */ |
| 640 |
uint_fast32_t tilewidth; |
| 641 |
|
| 642 |
/* The nominal tile height in units of the image reference grid. */ |
| 643 |
uint_fast32_t tileheight; |
| 644 |
|
| 645 |
/* The horizontal offset from the origin of the reference grid to the |
| 646 |
left side of the first tile. */ |
| 647 |
uint_fast32_t tilexoff; |
| 648 |
|
| 649 |
/* The vertical offset from the origin of the reference grid to the |
| 650 |
top side of the first tile. */ |
| 651 |
uint_fast32_t tileyoff; |
| 652 |
|
| 653 |
/* The number of tiles spanning the image area in the vertical |
| 654 |
direction. */ |
| 655 |
int numhtiles; |
| 656 |
|
| 657 |
/* The number of tiles spanning the image area in the horizontal |
| 658 |
direction. */ |
| 659 |
int numvtiles; |
| 660 |
|
| 661 |
/* The total number of tiles. */ |
| 662 |
int numtiles; |
| 663 |
|
| 664 |
/* The per-tile information. */ |
| 665 |
jpc_dec_tile_t *tiles; |
| 666 |
|
| 667 |
/* The tile currently being processed. */ |
| 668 |
jpc_dec_tile_t *curtile; |
| 669 |
|
| 670 |
/* The number of components. */ |
| 671 |
int numcomps; |
| 672 |
|
| 673 |
/* The stream containing the input JPEG-2000 code stream data. */ |
| 674 |
jas_stream_t *in; |
| 675 |
|
| 676 |
/* The default coding parameters for all tiles. */ |
| 677 |
jpc_dec_cp_t *cp; |
| 678 |
|
| 679 |
/* The maximum number of layers that may be decoded. */ |
| 680 |
int maxlyrs; |
| 681 |
|
| 682 |
/* The maximum number of packets that may be decoded. */ |
| 683 |
int maxpkts; |
| 684 |
|
| 685 |
/* The number of packets decoded so far in the processing of the entire |
| 686 |
code stream. */ |
| 687 |
int numpkts; |
| 688 |
|
| 689 |
/* The next expected PPM marker segment sequence number. */ |
| 690 |
int ppmseqno; |
| 691 |
|
| 692 |
/* The current state for code stream processing. */ |
| 693 |
int state; |
| 694 |
|
| 695 |
/* The per-component information. */ |
| 696 |
jpc_dec_cmpt_t *cmpts; |
| 697 |
|
| 698 |
/* The information from PPM marker segments. */ |
| 699 |
jpc_ppxstab_t *ppmstab; |
| 700 |
|
| 701 |
/* A list of streams containing packet header data from PPM marker |
| 702 |
segments. */ |
| 703 |
jpc_streamlist_t *pkthdrstreams; |
| 704 |
|
| 705 |
/* The expected ending offset for a tile-part. */ |
| 706 |
long curtileendoff; |
| 707 |
|
| 708 |
/* This is required by the tier-2 decoder. */ |
| 709 |
jpc_cstate_t *cstate; |
| 710 |
|
| 711 |
} jpc_dec_t; |
| 712 |
|
| 713 |
/* Decoder options. */ |
| 714 |
|
| 715 |
typedef struct { |
| 716 |
|
| 717 |
/* The debug level for the decoder. */ |
| 718 |
int debug; |
| 719 |
|
| 720 |
/* The maximum number of layers to decode. */ |
| 721 |
int maxlyrs; |
| 722 |
|
| 723 |
/* The maximum number of packets to decode. */ |
| 724 |
int maxpkts; |
| 725 |
|
| 726 |
} jpc_dec_importopts_t; |
| 727 |
|
| 728 |
/******************************************************************************\ |
| 729 |
* Functions. |
| 730 |
\******************************************************************************/ |
| 731 |
|
| 732 |
/* Create a decoder segment object. */ |
| 733 |
jpc_dec_seg_t *jpc_seg_alloc(void); |
| 734 |
|
| 735 |
/* Destroy a decoder segment object. */ |
| 736 |
void jpc_seg_destroy(jpc_dec_seg_t *seg); |
| 737 |
|
| 738 |
/* Remove a segment from a segment list. */ |
| 739 |
void jpc_seglist_remove(jpc_dec_seglist_t *list, jpc_dec_seg_t *node); |
| 740 |
|
| 741 |
/* Insert a segment into a segment list. */ |
| 742 |
void jpc_seglist_insert(jpc_dec_seglist_t *list, jpc_dec_seg_t *ins, |
| 743 |
jpc_dec_seg_t *node); |
| 744 |
|
| 745 |
#endif |