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