JasPer  2.0.33
jpc_cs.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 Code Stream Library
66  *
67  * $Id$
68  */
69 
70 #ifndef JPC_CS_H
71 #define JPC_CS_H
72 
73 /******************************************************************************\
74 * Includes.
75 \******************************************************************************/
76 
77 #include "jasper/jas_stream.h"
78 
79 #include <assert.h>
80 #include <stdio.h>
81 
82 /******************************************************************************\
83 * Constants and Types.
84 \******************************************************************************/
85 
86 /* The maximum number of resolution levels. */
87 #define JPC_MAXRLVLS 33
88 
89 /* The maximum number of bands. */
90 #define JPC_MAXBANDS (3 * JPC_MAXRLVLS + 1)
91 
92 /* The maximum number of layers. */
93 #define JPC_MAXLYRS 16384
94 
95 /**************************************\
96 * Code stream.
97 \**************************************/
98 
99 /*
100  * Code stream states.
101  */
102 
103 /* Initial. */
104 #define JPC_CS_INIT 0
105 /* Main header. */
106 #define JPC_CS_MHDR 1
107 /* Tile-part header. */
108 #define JPC_CS_THDR 2
109 /* Main trailer. */
110 #define JPC_CS_MTLR 3
111 /* Tile-part data. */
112 #define JPC_CS_TDATA 4
113 
114 /*
115  * Unfortunately, the code stream syntax was not designed in such a way that
116  * any given marker segment can be correctly decoded without additional state
117  * derived from previously decoded marker segments.
118  * For example, a RGN/COC/QCC marker segment cannot be decoded unless the
119  * number of components is known.
120  */
121 
122 /*
123  * Code stream state information.
124  */
125 
126 typedef struct {
127 
128  /* The number of components. */
129  uint_fast16_t numcomps;
130 
131 } jpc_cstate_t;
132 
133 /**************************************\
134 * SOT marker segment parameters.
135 \**************************************/
136 
137 typedef struct {
138 
139  /* The tile number. */
140  uint_fast16_t tileno;
141 
142  /* The combined length of the marker segment and its auxilary data
143  (i.e., packet data). */
144  uint_fast32_t len;
145 
146  /* The tile-part instance. */
147  uint_fast8_t partno;
148 
149  /* The number of tile-parts. */
150  uint_fast8_t numparts;
151 
152 } jpc_sot_t;
153 
154 /**************************************\
155 * SIZ marker segment parameters.
156 \**************************************/
157 
158 /* Per component information. */
159 
160 typedef struct {
161 
162  /* The precision of the samples. */
163  uint_fast8_t prec;
164 
165  /* The signedness of the samples. */
166  uint_fast8_t sgnd;
167 
168  /* The horizontal separation of samples with respect to the reference
169  grid. */
170  uint_fast8_t hsamp;
171 
172  /* The vertical separation of samples with respect to the reference
173  grid. */
174  uint_fast8_t vsamp;
175 
176 } jpc_sizcomp_t;
177 
178 /* SIZ marker segment parameters. */
179 
180 typedef struct {
181 
182  /* The code stream capabilities. */
183  uint_fast16_t caps;
184 
185  /* The width of the image in units of the reference grid. */
186  uint_fast32_t width;
187 
188  /* The height of the image in units of the reference grid. */
189  uint_fast32_t height;
190 
191  /* The horizontal offset from the origin of the reference grid to the
192  left side of the image area. */
193  uint_fast32_t xoff;
194 
195  /* The vertical offset from the origin of the reference grid to the
196  top side of the image area. */
197  uint_fast32_t yoff;
198 
199  /* The nominal width of a tile in units of the reference grid. */
200  uint_fast32_t tilewidth;
201 
202  /* The nominal height of a tile in units of the reference grid. */
203  uint_fast32_t tileheight;
204 
205  /* The horizontal offset from the origin of the reference grid to the
206  left side of the first tile. */
207  uint_fast32_t tilexoff;
208 
209  /* The vertical offset from the origin of the reference grid to the
210  top side of the first tile. */
211  uint_fast32_t tileyoff;
212 
213  /* The number of components. */
214  uint_fast16_t numcomps;
215 
216  /* The per-component information. */
217  jpc_sizcomp_t *comps;
218 
219 } jpc_siz_t;
220 
221 /**************************************\
222 * COD marker segment parameters.
223 \**************************************/
224 
225 /*
226  * Coding style constants.
227  */
228 
229 /* Precincts may be used. */
230 #define JPC_COX_PRT 0x01
231 /* SOP marker segments may be used. */
232 #define JPC_COD_SOP 0x02
233 /* EPH marker segments may be used. */
234 #define JPC_COD_EPH 0x04
235 
236 /*
237  * Progression order constants.
238  */
239 
240 /* Layer-resolution-component-precinct progressive
241  (i.e., progressive by fidelity). */
242 #define JPC_COD_LRCPPRG 0
243 /* Resolution-layer-component-precinct progressive
244  (i.e., progressive by resolution). */
245 #define JPC_COD_RLCPPRG 1
246 /* Resolution-precinct-component-layer progressive. */
247 #define JPC_COD_RPCLPRG 2
248 /* Precinct-component-resolution-layer progressive. */
249 #define JPC_COD_PCRLPRG 3
250 /* Component-position-resolution-layer progressive. */
251 #define JPC_COD_CPRLPRG 4
252 
253 /*
254  * Code block style constants.
255  */
256 
257 #define JPC_COX_LAZY 0x01 /* Selective arithmetic coding bypass. */
258 #define JPC_COX_RESET 0x02 /* Reset context probabilities. */
259 #define JPC_COX_TERMALL 0x04 /* Terminate all coding passes. */
260 #define JPC_COX_VSC 0x08 /* Vertical stripe causal context formation. */
261 #define JPC_COX_PTERM 0x10 /* Predictable termination. */
262 #define JPC_COX_SEGSYM 0x20 /* Use segmentation symbols. */
263 
264 /* Transform constants. */
265 #define JPC_COX_INS 0x00 /* Irreversible 9/7. */
266 #define JPC_COX_RFT 0x01 /* Reversible 5/3. */
267 
268 /* Multicomponent transform constants. */
269 #define JPC_COD_NOMCT 0x00 /* No multicomponent transform. */
270 #define JPC_COD_MCT 0x01 /* Multicomponent transform. */
271 
272 /* Get the code block size value from the code block size exponent. */
273 JAS_ATTRIBUTE_CONST
274 static inline unsigned JPC_COX_CBLKSIZEEXPN(unsigned x)
275 {
276  return x - 2;
277 }
278 
279 /* Get the code block size exponent from the code block size value. */
280 JAS_ATTRIBUTE_CONST
281 static inline unsigned JPC_COX_GETCBLKSIZEEXPN(unsigned x)
282 {
283  return x + 2;
284 }
285 
286 /* Per resolution-level information. */
287 
288 typedef struct {
289 
290  /* The packet partition width. */
291  uint_fast8_t parwidthval;
292 
293  /* The packet partition height. */
294  uint_fast8_t parheightval;
295 
296 } jpc_coxrlvl_t;
297 
298 /* Per component information. */
299 
300 typedef struct {
301 
302  /* The coding style. */
303  uint_fast8_t csty;
304 
305  /* The number of decomposition levels. */
306  uint_fast8_t numdlvls;
307 
308  /* The nominal code block width specifier. */
309  uint_fast8_t cblkwidthval;
310 
311  /* The nominal code block height specifier. */
312  uint_fast8_t cblkheightval;
313 
314  /* The style of coding passes. */
315  uint_fast8_t cblksty;
316 
317  /* The QMFB employed. */
318  uint_fast8_t qmfbid;
319 
320  /* The number of resolution levels. */
321  int numrlvls;
322 
323  /* The per-resolution-level information. */
324  jpc_coxrlvl_t rlvls[JPC_MAXRLVLS];
325 
326 } jpc_coxcp_t;
327 
328 /* COD marker segment parameters. */
329 
330 typedef struct {
331 
332  /* The general coding style. */
333  uint_fast8_t csty;
334 
335  /* The progression order. */
336  uint_fast8_t prg;
337 
338  /* The number of layers. */
339  uint_fast16_t numlyrs;
340 
341  /* The multicomponent transform. */
342  uint_fast8_t mctrans;
343 
344  /* Component-related parameters. */
345  jpc_coxcp_t compparms;
346 
347 } jpc_cod_t;
348 
349 /* COC marker segment parameters. */
350 
351 typedef struct {
352 
353  /* The component number. */
354  uint_fast16_t compno;
355 
356  /* Component-related parameters. */
357  jpc_coxcp_t compparms;
358 
359 } jpc_coc_t;
360 
361 /**************************************\
362 * RGN marker segment parameters.
363 \**************************************/
364 
365 /* The maxshift ROI style. */
366 #define JPC_RGN_MAXSHIFT 0x00
367 
368 typedef struct {
369 
370  /* The component to which the marker applies. */
371  uint_fast16_t compno;
372 
373  /* The ROI style. */
374  uint_fast8_t roisty;
375 
376  /* The ROI shift value. */
377  uint_fast8_t roishift;
378 
379 } jpc_rgn_t;
380 
381 /**************************************\
382 * QCD/QCC marker segment parameters.
383 \**************************************/
384 
385 /*
386  * Quantization style constants.
387  */
388 
389 #define JPC_QCX_NOQNT 0 /* No quantization. */
390 #define JPC_QCX_SIQNT 1 /* Scalar quantization, implicit. */
391 #define JPC_QCX_SEQNT 2 /* Scalar quantization, explicit. */
392 
393 /*
394  * Stepsize manipulation macros.
395  */
396 
397 JAS_ATTRIBUTE_CONST
398 static inline unsigned JPC_QCX_GETEXPN(unsigned x)
399 {
400  return x >> 11;
401 }
402 
403 JAS_ATTRIBUTE_CONST
404 static inline unsigned JPC_QCX_GETMANT(unsigned x)
405 {
406  return x & 0x7ff;
407 }
408 
409 JAS_ATTRIBUTE_CONST
410 static inline uint_fast16_t JPC_QCX_EXPN(unsigned x)
411 {
412  assert(!(x & (~0x1f)));
413 
414  return (x & 0x1f) << 11;
415 }
416 
417 JAS_ATTRIBUTE_CONST
418 static inline uint_fast16_t JPC_QCX_MANT(unsigned x)
419 {
420  assert(!(x & (~0x7ff)));
421 
422  return x & 0x7ff;
423 }
424 
425 /* Per component information. */
426 
427 typedef struct {
428 
429  /* The quantization style. */
430  uint_fast8_t qntsty;
431 
432  /* The number of step sizes. */
433  int numstepsizes;
434 
435  /* The step sizes. */
436  uint_fast16_t *stepsizes;
437 
438  /* The number of guard bits. */
439  uint_fast8_t numguard;
440 
441 } jpc_qcxcp_t;
442 
443 /* QCC marker segment parameters. */
444 
445 typedef struct {
446 
447  /* The component associated with this marker segment. */
448  uint_fast16_t compno;
449 
450  /* The parameters. */
451  jpc_qcxcp_t compparms;
452 
453 } jpc_qcc_t;
454 
455 /* QCD marker segment parameters. */
456 
457 typedef struct {
458 
459  /* The parameters. */
460  jpc_qcxcp_t compparms;
461 
462 } jpc_qcd_t;
463 
464 /**************************************\
465 * POD marker segment parameters.
466 \**************************************/
467 
468 typedef struct {
469 
470  /* The progression order. */
471  uint_fast8_t prgord;
472 
473  /* The lower bound (inclusive) on the resolution level for the
474  progression order volume. */
475  uint_fast8_t rlvlnostart;
476 
477  /* The upper bound (exclusive) on the resolution level for the
478  progression order volume. */
479  uint_fast8_t rlvlnoend;
480 
481  /* The lower bound (inclusive) on the component for the progression
482  order volume. */
483  uint_fast16_t compnostart;
484 
485  /* The upper bound (exclusive) on the component for the progression
486  order volume. */
487  uint_fast16_t compnoend;
488 
489  /* The upper bound (exclusive) on the layer for the progression
490  order volume. */
491  uint_fast16_t lyrnoend;
492 
493 } jpc_pocpchg_t;
494 
495 /* An alias for the above type. */
496 typedef jpc_pocpchg_t jpc_pchg_t;
497 
498 /* POC marker segment parameters. */
499 
500 typedef struct {
501 
502  /* The number of progression order changes. */
503  int numpchgs;
504 
505  /* The per-progression-order-change information. */
506  jpc_pocpchg_t *pchgs;
507 
508 } jpc_poc_t;
509 
510 /**************************************\
511 * PPM/PPT marker segment parameters.
512 \**************************************/
513 
514 /* PPM marker segment parameters. */
515 
516 typedef struct {
517 
518  /* The index. */
519  uint_fast8_t ind;
520 
521  /* The length. */
522  uint_fast16_t len;
523 
524  /* The data. */
525  jas_uchar *data;
526 
527 } jpc_ppm_t;
528 
529 /* PPT marker segment parameters. */
530 
531 typedef struct {
532 
533  /* The index. */
534  uint_fast8_t ind;
535 
536  /* The length. */
537  uint_fast32_t len;
538 
539  /* The data. */
540  unsigned char *data;
541 
542 } jpc_ppt_t;
543 
544 /**************************************\
545 * COM marker segment parameters.
546 \**************************************/
547 
548 /*
549  * Registration IDs.
550  */
551 
552 #define JPC_COM_BIN 0x00
553 #define JPC_COM_LATIN 0x01
554 
555 typedef struct {
556 
557  /* The registration ID. */
558  uint_fast16_t regid;
559 
560  /* The length of the data in bytes. */
561  uint_fast16_t len;
562 
563  /* The data. */
564  jas_uchar *data;
565 
566 } jpc_com_t;
567 
568 /**************************************\
569 * SOP marker segment parameters.
570 \**************************************/
571 
572 typedef struct {
573 
574  /* The sequence number. */
575  uint_fast16_t seqno;
576 
577 } jpc_sop_t;
578 
579 /**************************************\
580 * CRG marker segment parameters.
581 \**************************************/
582 
583 /* Per component information. */
584 
585 typedef struct {
586 
587  /* The horizontal offset. */
588  uint_fast16_t hoff;
589 
590  /* The vertical offset. */
591  uint_fast16_t voff;
592 
593 } jpc_crgcomp_t;
594 
595 typedef struct {
596 
597  /* The number of components. */
598  int numcomps;
599 
600  /* Per component information. */
601  jpc_crgcomp_t *comps;
602 
603 } jpc_crg_t;
604 
605 /**************************************\
606 * Marker segment parameters for unknown marker type.
607 \**************************************/
608 
609 typedef struct {
610 
611  /* The data. */
612  jas_uchar *data;
613 
614  /* The length. */
615  uint_fast16_t len;
616 
617 } jpc_unk_t;
618 
619 /**************************************\
620 * Generic marker segment parameters.
621 \**************************************/
622 
623 typedef union {
624  int soc; /* unused */
625  jpc_sot_t sot;
626  int sod; /* unused */
627  int eoc; /* unused */
628  jpc_siz_t siz;
629  jpc_cod_t cod;
630  jpc_coc_t coc;
631  jpc_rgn_t rgn;
632  jpc_qcd_t qcd;
633  jpc_qcc_t qcc;
634  jpc_poc_t poc;
635  /* jpc_plm_t plm; */
636  /* jpc_plt_t plt; */
637  jpc_ppm_t ppm;
638  jpc_ppt_t ppt;
639  jpc_sop_t sop;
640  int eph; /* unused */
641  jpc_com_t com;
642  jpc_crg_t crg;
643  jpc_unk_t unk;
644 } jpc_msparms_t;
645 
646 /**************************************\
647 * Marker segment.
648 \**************************************/
649 
650 /* Marker segment IDs. */
651 
652 /* The smallest valid marker value. */
653 #define JPC_MS_MIN 0xff00
654 
655 /* The largest valid marker value. */
656 #define JPC_MS_MAX 0xffff
657 
658 /* The minimum marker value that cannot occur within packet data. */
659 #define JPC_MS_INMIN 0xff80
660 /* The maximum marker value that cannot occur within packet data. */
661 #define JPC_MS_INMAX 0xffff
662 
663 /* Delimiting marker segments. */
664 #define JPC_MS_SOC 0xff4f /* Start of code stream (SOC). */
665 #define JPC_MS_SOT 0xff90 /* Start of tile-part (SOT). */
666 #define JPC_MS_SOD 0xff93 /* Start of data (SOD). */
667 #define JPC_MS_EOC 0xffd9 /* End of code stream (EOC). */
668 
669 /* Fixed information marker segments. */
670 #define JPC_MS_SIZ 0xff51 /* Image and tile size (SIZ). */
671 
672 /* Functional marker segments. */
673 #define JPC_MS_COD 0xff52 /* Coding style default (COD). */
674 #define JPC_MS_COC 0xff53 /* Coding style component (COC). */
675 #define JPC_MS_RGN 0xff5e /* Region of interest (RGN). */
676 #define JPC_MS_QCD 0xff5c /* Quantization default (QCD). */
677 #define JPC_MS_QCC 0xff5d /* Quantization component (QCC). */
678 #define JPC_MS_POC 0xff5f /* Progression order default (POC). */
679 
680 /* Pointer marker segments. */
681 #define JPC_MS_TLM 0xff55 /* Tile-part lengths, main header (TLM). */
682 #define JPC_MS_PLM 0xff57 /* Packet length, main header (PLM). */
683 #define JPC_MS_PLT 0xff58 /* Packet length, tile-part header (PLT). */
684 #define JPC_MS_PPM 0xff60 /* Packed packet headers, main header (PPM). */
685 #define JPC_MS_PPT 0xff61 /* Packet packet headers, tile-part header (PPT). */
686 
687 /* In bit stream marker segments. */
688 #define JPC_MS_SOP 0xff91 /* Start of packet (SOP). */
689 #define JPC_MS_EPH 0xff92 /* End of packet header (EPH). */
690 
691 /* Informational marker segments. */
692 #define JPC_MS_CRG 0xff63 /* Component registration (CRG). */
693 #define JPC_MS_COM 0xff64 /* Comment (COM). */
694 
695 /* Forward declaration. */
696 struct jpc_msops_s;
697 
698 /* Generic marker segment class. */
699 
700 typedef struct {
701 
702  /* The type of marker segment. */
703  uint_fast16_t id;
704 
705  /* The length of the marker segment. */
706  uint_fast16_t len;
707 
708  /* The starting offset within the stream. */
709  uint_fast32_t off;
710 
711  /* The parameters of the marker segment. */
712  jpc_msparms_t parms;
713 
714  /* The marker segment operations. */
715  const struct jpc_msops_s *ops;
716 
717 } jpc_ms_t;
718 
719 /* Marker segment operations (which depend on the marker segment type). */
720 
721 typedef struct jpc_msops_s {
722 
723  /* Destroy the marker segment parameters. */
724  void (*destroyparms)(jpc_ms_t *ms);
725 
726  /* Get the marker segment parameters from a stream. */
727  int (*getparms)(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in);
728 
729  /* Put the marker segment parameters to a stream. */
730  int (*putparms)(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out);
731 
732  /* Dump the marker segment parameters (for debugging). */
733  int (*dumpparms)(jpc_ms_t *ms, FILE *out);
734 
735 } jpc_msops_t;
736 
737 /******************************************************************************\
738 * Macros/Functions.
739 \******************************************************************************/
740 
741 /* Create a code-stream state object. */
742 jpc_cstate_t *jpc_cstate_create(void);
743 
744 /* Destroy a code-stream state object. */
745 void jpc_cstate_destroy(jpc_cstate_t *cstate);
746 
747 /* Create a marker segment. */
748 jpc_ms_t *jpc_ms_create(int type);
749 
750 /* Destroy a marker segment. */
751 void jpc_ms_destroy(jpc_ms_t *ms);
752 
753 /* Does a marker segment have parameters? */
754 JAS_ATTRIBUTE_CONST
755 static inline bool JPC_MS_HASPARMS(unsigned x)
756 {
757  return !(x == JPC_MS_SOC || x == JPC_MS_SOD || x == JPC_MS_EOC ||
758  x == JPC_MS_EPH || (x >= 0xff30 && x <= 0xff3f));
759 }
760 
761 /* Get the marker segment type. */
762 JAS_ATTRIBUTE_PURE
763 static inline unsigned jpc_ms_gettype(const jpc_ms_t *ms)
764 {
765  return ms->id;
766 }
767 
768 /* Read a marker segment from a stream. */
769 jpc_ms_t *jpc_getms(jas_stream_t *in, jpc_cstate_t *cstate);
770 
771 /* Write a marker segment to a stream. */
772 int jpc_putms(jas_stream_t *out, jpc_cstate_t *cstate, jpc_ms_t *ms);
773 
774 /* Copy code stream data from one stream to another. */
775 int jpc_getdata(jas_stream_t *in, jas_stream_t *out, long n);
776 
777 /* Copy code stream data from one stream to another. */
778 int jpc_putdata(jas_stream_t *out, jas_stream_t *in, long n);
779 
780 /* Dump a marker segment (for debugging). */
781 void jpc_ms_dump(jpc_ms_t *ms, FILE *out);
782 
783 /* Read a 8-bit unsigned integer from a stream. */
784 int jpc_getuint8(jas_stream_t *in, uint_fast8_t *val);
785 
786 /* Read a 16-bit unsigned integer from a stream. */
787 int jpc_getuint16(jas_stream_t *in, uint_fast16_t *val);
788 
789 /* Read a 32-bit unsigned integer from a stream. */
790 int jpc_getuint32(jas_stream_t *in, uint_fast32_t *val);
791 
792 /* Write a 8-bit unsigned integer to a stream. */
793 int jpc_putuint8(jas_stream_t *out, uint_fast8_t val);
794 
795 /* Write a 16-bit unsigned integer to a stream. */
796 int jpc_putuint16(jas_stream_t *out, uint_fast16_t val);
797 
798 /* Write a 32-bit unsigned integer to a stream. */
799 int jpc_putuint32(jas_stream_t *out, uint_fast32_t val);
800 
801 #endif
I/O Stream Class.