2 * Copyright (c) 1999-2000 Image Power, Inc. and the University of
4 * Copyright (c) 2001-2002 Michael David Adams.
8 /* __START_OF_JASPER_LICENSE__
10 * JasPer License Version 2.0
12 * Copyright (c) 1999-2000 Image Power, Inc.
13 * Copyright (c) 1999-2000 The University of British Columbia
14 * Copyright (c) 2001-2003 Michael David Adams
16 * All rights reserved.
18 * Permission is hereby granted, free of charge, to any person (the
19 * "User") obtaining a copy of this software and associated documentation
20 * files (the "Software"), to deal in the Software without restriction,
21 * including without limitation the rights to use, copy, modify, merge,
22 * publish, distribute, and/or sell copies of the Software, and to permit
23 * persons to whom the Software is furnished to do so, subject to the
24 * following conditions:
26 * 1. The above copyright notices and this permission notice (which
27 * includes the disclaimer below) shall be included in all copies or
28 * substantial portions of the Software.
30 * 2. The name of a copyright holder shall not be used to endorse or
31 * promote products derived from the Software without specific prior
34 * THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS
35 * LICENSE. NO USE OF THE SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER
36 * THIS DISCLAIMER. THE SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
37 * "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
38 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
39 * PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS. IN NO
40 * EVENT SHALL THE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL
41 * INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING
42 * FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
43 * NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
44 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. NO ASSURANCES ARE
45 * PROVIDED BY THE COPYRIGHT HOLDERS THAT THE SOFTWARE DOES NOT INFRINGE
46 * THE PATENT OR OTHER INTELLECTUAL PROPERTY RIGHTS OF ANY OTHER ENTITY.
47 * EACH COPYRIGHT HOLDER DISCLAIMS ANY LIABILITY TO THE USER FOR CLAIMS
48 * BROUGHT BY ANY OTHER ENTITY BASED ON INFRINGEMENT OF INTELLECTUAL
49 * PROPERTY RIGHTS OR OTHERWISE. AS A CONDITION TO EXERCISING THE RIGHTS
50 * GRANTED HEREUNDER, EACH USER HEREBY ASSUMES SOLE RESPONSIBILITY TO SECURE
51 * ANY OTHER INTELLECTUAL PROPERTY RIGHTS NEEDED, IF ANY. THE SOFTWARE
52 * IS NOT FAULT-TOLERANT AND IS NOT INTENDED FOR USE IN MISSION-CRITICAL
53 * SYSTEMS, SUCH AS THOSE USED IN THE OPERATION OF NUCLEAR FACILITIES,
54 * AIRCRAFT NAVIGATION OR COMMUNICATION SYSTEMS, AIR TRAFFIC CONTROL
55 * SYSTEMS, DIRECT LIFE SUPPORT MACHINES, OR WEAPONS SYSTEMS, IN WHICH
56 * THE FAILURE OF THE SOFTWARE OR SYSTEM COULD LEAD DIRECTLY TO DEATH,
57 * PERSONAL INJURY, OR SEVERE PHYSICAL OR ENVIRONMENTAL DAMAGE ("HIGH
58 * RISK ACTIVITIES"). THE COPYRIGHT HOLDERS SPECIFICALLY DISCLAIM ANY
59 * EXPRESS OR IMPLIED WARRANTY OF FITNESS FOR HIGH RISK ACTIVITIES.
61 * __END_OF_JASPER_LICENSE__
67 * $Id: jpc_dec.h,v 1.1 2005/05/22 18:33:04 malaterre Exp $
73 /******************************************************************************\
75 \******************************************************************************/
77 #include "jasper/jas_stream.h"
81 #include "jpc_tagtree.h"
84 #include "jpc_mqdec.h"
85 #include "jpc_t2cod.h"
87 /******************************************************************************\
88 * Below are some ugly warts necessary to support packed packet headers.
89 \******************************************************************************/
91 /* PPM/PPT marker segment table entry. */
95 /* The index for this entry. */
98 /* The data length. */
106 /* PPM/PPT marker segment table. */
110 /* The number of entries. */
113 /* The maximum number of entries (i.e., the allocated size of the array
117 /* The table entries. */
118 jpc_ppxstabent_t **ents;
122 /* Stream list class. */
126 /* The number of streams in this list. */
129 /* The maximum number of streams that can be accomodated without
130 growing the streams array. */
134 jas_stream_t **streams;
138 /******************************************************************************\
139 * Coding parameters class.
140 \******************************************************************************/
142 /* Per-component coding parameters. */
146 /* How were various coding parameters set? */
149 /* Per-component coding style parameters (e.g., explicit precinct sizes) */
152 /* The number of resolution levels. */
153 uint_fast8_t numrlvls;
155 /* The code block width exponent. */
156 uint_fast8_t cblkwidthexpn;
158 /* The code block height exponent. */
159 uint_fast8_t cblkheightexpn;
164 /* The quantization style. */
167 /* The number of quantizer step sizes. */
168 uint_fast16_t numstepsizes;
170 /* The step sizes. */
171 uint_fast16_t stepsizes[3 * JPC_MAXRLVLS + 1];
173 /* The number of guard bits. */
174 uint_fast8_t numguardbits;
176 /* The ROI shift value. */
177 uint_fast8_t roishift;
179 /* The code block parameters. */
180 uint_fast8_t cblkctx;
182 /* The precinct width exponents. */
183 uint_fast8_t prcwidthexpns[JPC_MAXRLVLS];
185 /* The precinct height exponents. */
186 uint_fast8_t prcheightexpns[JPC_MAXRLVLS];
190 /* Coding paramters. */
194 /* How were these coding parameters set? */
197 /* Progression change list. */
198 jpc_pchglist_t *pchglist;
200 /* Progression order. */
203 /* The number of layers. */
204 uint_fast16_t numlyrs;
209 /* The coding style parameters (e.g., SOP, EPH). */
212 /* The number of components. */
215 /* The per-component coding parameters. */
220 /******************************************************************************\
222 \******************************************************************************/
224 /* Decoder per-segment state information. */
226 typedef struct jpc_dec_seg_s {
228 /* The next segment in the list. */
229 struct jpc_dec_seg_s *next;
231 /* The previous segment in the list. */
232 struct jpc_dec_seg_s *prev;
234 /* The starting pass number for this segment. */
237 /* The number of passes in this segment. */
240 /* The maximum number of passes in this segment. */
243 /* The type of data in this segment (i.e., MQ or raw). */
246 /* A stream containing the data for this segment. */
247 jas_stream_t *stream;
249 /* The number of bytes destined for this segment from the packet
250 currently being decoded. */
253 /* A flag indicating if this segment has been terminated. */
256 /* The layer number to which this segment belongs. */
257 /* If the segment spans multiple layers, then the largest layer number
258 spanned by the segment is used. */
263 /* Decoder segment list. */
267 /* The first entry in the list. */
270 /* The last entry in the list. */
275 /* Decoder per-code-block state information. */
279 /* The number of passes. */
282 /* A list of segments that still need to be decoded. */
283 jpc_dec_seglist_t segs;
285 /* The first incomplete/partial segment. */
286 jpc_dec_seg_t *curseg;
288 /* The number of leading insignificant bit planes for this code block. */
291 /* The number of bits used to encode pass data lengths. */
294 /* The first pass number containing data for this code block. */
297 /* The MQ decoder. */
300 /* The raw bit stream decoder. */
301 jpc_bitstream_t *nulldec;
303 /* The per-sample state information for this code block. */
306 /* The sample data associated with this code block. */
311 /* Decoder per-code-block-group state information. */
315 /* The x-coordinate of the top-left corner of the precinct. */
316 uint_fast32_t xstart;
318 /* The y-coordinate of the top-left corner of the precinct. */
319 uint_fast32_t ystart;
321 /* The x-coordinate of the bottom-right corner of the precinct
325 /* The y-coordinate of the bottom-right corner of the precinct
329 /* The number of code blocks spanning this precinct in the horizontal
333 /* The number of code blocks spanning this precinct in the vertical
337 /* The total number of code blocks in this precinct. */
340 /* The per code block information. */
341 jpc_dec_cblk_t *cblks;
343 /* The inclusion tag tree. */
344 jpc_tagtree_t *incltagtree;
346 /* The insignificant MSBs tag tree. */
347 jpc_tagtree_t *numimsbstagtree;
351 /* Decoder per-band state information. */
355 /* The per-code-block-group state information. */
358 /* The sample data associated with this band. */
361 /* The orientation of this band (i.e., LL, LH, HL, or HH). */
364 /* The encoded quantizer step size. */
367 /* The absolute quantizer step size. */
368 jpc_fix_t absstepsize;
370 /* The number of bit planes for this band. */
373 /* The analysis gain associated with this band. */
376 /* The ROI shift value for this band. */
381 /* Decoder per-resolution-level state information. */
385 /* The number of bands associated with this resolution level. */
388 /* The per-band information. */
389 jpc_dec_band_t *bands;
391 /* The x-coordinate of the top-left corner of the tile-component
392 at this resolution. */
393 uint_fast32_t xstart;
395 /* The y-coordinate of the top-left corner of the tile-component
396 at this resolution. */
397 uint_fast32_t ystart;
399 /* The x-coordinate of the bottom-right corner of the tile-component
400 at this resolution (plus one). */
403 /* The y-coordinate of the bottom-right corner of the tile-component
404 at this resolution (plus one). */
407 /* The exponent value for the nominal precinct width measured
408 relative to the associated LL band. */
411 /* The exponent value for the nominal precinct height measured
412 relative to the associated LL band. */
415 /* The number of precincts in the horizontal direction. */
418 /* The number of precincts in the vertical direction. */
421 /* The total number of precincts. */
424 /* The exponent value for the nominal code block group width.
425 This quantity is associated with the next lower resolution level
426 (assuming that there is one). */
429 /* The exponent value for the nominal code block group height
430 This quantity is associated with the next lower resolution level
431 (assuming that there is one). */
434 /* The exponent value for the code block width. */
435 uint_fast16_t cblkwidthexpn;
437 /* The exponent value for the code block height. */
438 uint_fast16_t cblkheightexpn;
442 /* Decoder per-tile-component state information. */
446 /* The x-coordinate of the top-left corner of the tile-component
447 in the coordinate system of the tile-component. */
448 uint_fast32_t xstart;
450 /* The y-coordinate of the top-left corner of the tile-component
451 in the coordinate system of the tile-component. */
452 uint_fast32_t ystart;
454 /* The x-coordinate of the bottom-right corner of the tile-component
455 in the coordinate system of the tile-component (plus one). */
458 /* The y-coordinate of the bottom-right corner of the tile-component
459 in the coordinate system of the tile-component (plus one). */
462 /* The component data for the current tile. */
465 /* The number of resolution levels. */
468 /* The per resolution level information. */
469 jpc_dec_rlvl_t *rlvls;
480 #define JPC_TILE_INIT 0
481 #define JPC_TILE_ACTIVE 1
482 #define JPC_TILE_ACTIVELAST 2
483 #define JPC_TILE_DONE 3
485 /* Decoder per-tile state information. */
489 /* The processing state for this tile. */
492 /* The x-coordinate of the top-left corner of the tile on the reference
494 uint_fast32_t xstart;
496 /* The y-coordinate of the top-left corner of the tile on the reference
498 uint_fast32_t ystart;
500 /* The x-coordinate of the bottom-right corner of the tile on the
501 reference grid (plus one). */
504 /* The y-coordinate of the bottom-right corner of the tile on the
505 reference grid (plus one). */
508 /* The packed packet header data for this tile. */
509 jpc_ppxstab_t *pptstab;
511 /* A stream containing the packed packet header data for this tile. */
512 jas_stream_t *pkthdrstream;
514 /* The current position within the packed packet header stream. */
515 long pkthdrstreampos;
517 /* The coding parameters for this tile. */
520 /* The per tile-component information. */
521 jpc_dec_tcomp_t *tcomps;
523 /* The next expected tile-part number. */
526 /* The number of tile-parts. */
529 /* The coding mode. */
532 /* The packet iterator for this tile. */
537 /* Decoder per-component state information. */
541 /* The horizontal sampling period. */
544 /* The vertical sampling period. */
547 /* The number of samples in the horizontal direction. */
550 /* The number of samples in the vertical direction. */
551 uint_fast32_t height;
553 /* The precision of the sample data. */
556 /* The signedness of the sample data. */
559 /* The sample alignment horizontal offset. */
560 uint_fast32_t hsubstep;
562 /* The sample alignment vertical offset. */
563 uint_fast32_t vsubstep;
567 /* Decoder state information. */
571 /* The decoded image. */
574 /* The x-coordinate of the top-left corner of the image area on
575 the reference grid. */
576 uint_fast32_t xstart;
578 /* The y-coordinate of the top-left corner of the image area on
579 the reference grid. */
580 uint_fast32_t ystart;
582 /* The x-coordinate of the bottom-right corner of the image area on
583 the reference grid (plus one). */
586 /* The y-coordinate of the bottom-right corner of the image area on
587 the reference grid (plus one). */
590 /* The nominal tile width in units of the image reference grid. */
591 uint_fast32_t tilewidth;
593 /* The nominal tile height in units of the image reference grid. */
594 uint_fast32_t tileheight;
596 /* The horizontal offset from the origin of the reference grid to the
597 left side of the first tile. */
598 uint_fast32_t tilexoff;
600 /* The vertical offset from the origin of the reference grid to the
601 top side of the first tile. */
602 uint_fast32_t tileyoff;
604 /* The number of tiles spanning the image area in the vertical
608 /* The number of tiles spanning the image area in the horizontal
612 /* The total number of tiles. */
615 /* The per-tile information. */
616 jpc_dec_tile_t *tiles;
618 /* The tile currently being processed. */
619 jpc_dec_tile_t *curtile;
621 /* The number of components. */
624 /* The stream containing the input JPEG-2000 code stream data. */
627 /* The default coding parameters for all tiles. */
630 /* The maximum number of layers that may be decoded. */
633 /* The maximum number of packets that may be decoded. */
636 /* The number of packets decoded so far in the processing of the entire
640 /* The next expected PPM marker segment sequence number. */
643 /* The current state for code stream processing. */
646 /* The per-component information. */
647 jpc_dec_cmpt_t *cmpts;
649 /* The information from PPM marker segments. */
650 jpc_ppxstab_t *ppmstab;
652 /* A list of streams containing packet header data from PPM marker
654 jpc_streamlist_t *pkthdrstreams;
656 /* The expected ending offset for a tile-part. */
659 /* This is required by the tier-2 decoder. */
660 jpc_cstate_t *cstate;
664 /* Decoder options. */
668 /* The debug level for the decoder. */
671 /* The maximum number of layers to decode. */
674 /* The maximum number of packets to decode. */
677 } jpc_dec_importopts_t;
679 /******************************************************************************\
681 \******************************************************************************/
683 /* Create a decoder segment object. */
684 jpc_dec_seg_t *jpc_seg_alloc(void);
686 /* Destroy a decoder segment object. */
687 void jpc_seg_destroy(jpc_dec_seg_t *seg);
689 /* Remove a segment from a segment list. */
690 void jpc_seglist_remove(jpc_dec_seglist_t *list, jpc_dec_seg_t *node);
692 /* Insert a segment into a segment list. */
693 void jpc_seglist_insert(jpc_dec_seglist_t *list, jpc_dec_seg_t *ins,
694 jpc_dec_seg_t *node);