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_image.h"
78 #include "jasper/jas_stream.h"
79 
80 #include "jpc_cod.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 #define	JPC_COX_CBLKSIZEEXPN(x)		((x) - 2)
274 /* Get the code block size exponent from the code block size value. */
275 #define	JPC_COX_GETCBLKSIZEEXPN(x)	((x) + 2)
276 
277 /* Per resolution-level information. */
278 
279 typedef struct {
280 
281 	/* The packet partition width. */
282 	uint_fast8_t parwidthval;
283 
284 	/* The packet partition height. */
285 	uint_fast8_t parheightval;
286 
287 } jpc_coxrlvl_t;
288 
289 /* Per component information. */
290 
291 typedef struct {
292 
293 	/* The coding style. */
294 	uint_fast8_t csty;
295 
296 	/* The number of decomposition levels. */
297 	uint_fast8_t numdlvls;
298 
299 	/* The nominal code block width specifier. */
300 	uint_fast8_t cblkwidthval;
301 
302 	/* The nominal code block height specifier. */
303 	uint_fast8_t cblkheightval;
304 
305 	/* The style of coding passes. */
306 	uint_fast8_t cblksty;
307 
308 	/* The QMFB employed. */
309 	uint_fast8_t qmfbid;
310 
311 	/* The number of resolution levels. */
312 	int numrlvls;
313 
314 	/* The per-resolution-level information. */
315 	jpc_coxrlvl_t rlvls[JPC_MAXRLVLS];
316 
317 } jpc_coxcp_t;
318 
319 /* COD marker segment parameters. */
320 
321 typedef struct {
322 
323 	/* The general coding style. */
324 	uint_fast8_t csty;
325 
326 	/* The progression order. */
327 	uint_fast8_t prg;
328 
329 	/* The number of layers. */
330 	uint_fast16_t numlyrs;
331 
332 	/* The multicomponent transform. */
333 	uint_fast8_t mctrans;
334 
335 	/* Component-related parameters. */
336 	jpc_coxcp_t compparms;
337 
338 } jpc_cod_t;
339 
340 /* COC marker segment parameters. */
341 
342 typedef struct {
343 
344 	/* The component number. */
345 	uint_fast16_t compno;
346 
347 	/* Component-related parameters. */
348 	jpc_coxcp_t compparms;
349 
350 } jpc_coc_t;
351 
352 /**************************************\
353 * RGN marker segment parameters.
354 \**************************************/
355 
356 /* The maxshift ROI style. */
357 #define	JPC_RGN_MAXSHIFT	0x00
358 
359 typedef struct {
360 
361 	/* The component to which the marker applies. */
362 	uint_fast16_t compno;
363 
364 	/* The ROI style. */
365 	uint_fast8_t roisty;
366 
367 	/* The ROI shift value. */
368 	uint_fast8_t roishift;
369 
370 } jpc_rgn_t;
371 
372 /**************************************\
373 * QCD/QCC marker segment parameters.
374 \**************************************/
375 
376 /*
377  * Quantization style constants.
378  */
379 
380 #define	JPC_QCX_NOQNT	0 /* No quantization. */
381 #define	JPC_QCX_SIQNT	1 /* Scalar quantization, implicit. */
382 #define	JPC_QCX_SEQNT	2 /* Scalar quantization, explicit. */
383 
384 /*
385  * Stepsize manipulation macros.
386  */
387 
388 #define	JPC_QCX_GETEXPN(x)	((x) >> 11)
389 #define	JPC_QCX_GETMANT(x)	((x) & 0x07ff)
390 #define JPC_QCX_ASSERT_EXPN(x) assert(!((x) & (~0x1f)))
391 #define	JPC_QCX_EXPN(x)		(((x) & 0x1f) << 11)
392 #define JPC_QCX_ASSERT_MANT(x) assert(!((x) & (~0x7ff)))
393 #define	JPC_QCX_MANT(x)		((x) & 0x7ff)
394 
395 /* Per component information. */
396 
397 typedef struct {
398 
399 	/* The quantization style. */
400 	uint_fast8_t qntsty;
401 
402 	/* The number of step sizes. */
403 	int numstepsizes;
404 
405 	/* The step sizes. */
406 	uint_fast16_t *stepsizes;
407 
408 	/* The number of guard bits. */
409 	uint_fast8_t numguard;
410 
411 } jpc_qcxcp_t;
412 
413 /* QCC marker segment parameters. */
414 
415 typedef struct {
416 
417 	/* The component associated with this marker segment. */
418 	uint_fast16_t compno;
419 
420 	/* The parameters. */
421 	jpc_qcxcp_t compparms;
422 
423 } jpc_qcc_t;
424 
425 /* QCD marker segment parameters. */
426 
427 typedef struct {
428 
429 	/* The parameters. */
430 	jpc_qcxcp_t compparms;
431 
432 } jpc_qcd_t;
433 
434 /**************************************\
435 * POD marker segment parameters.
436 \**************************************/
437 
438 typedef struct {
439 
440 	/* The progression order. */
441 	uint_fast8_t prgord;
442 
443 	/* The lower bound (inclusive) on the resolution level for the
444 	  progression order volume. */
445 	uint_fast8_t rlvlnostart;
446 
447 	/* The upper bound (exclusive) on the resolution level for the
448 	  progression order volume. */
449 	uint_fast8_t rlvlnoend;
450 
451 	/* The lower bound (inclusive) on the component for the progression
452 	  order volume. */
453 	uint_fast16_t compnostart;
454 
455 	/* The upper bound (exclusive) on the component for the progression
456 	  order volume. */
457 	uint_fast16_t compnoend;
458 
459 	/* The upper bound (exclusive) on the layer for the progression
460 	  order volume. */
461 	uint_fast16_t lyrnoend;
462 
463 } jpc_pocpchg_t;
464 
465 /* An alias for the above type. */
466 typedef jpc_pocpchg_t jpc_pchg_t;
467 
468 /* POC marker segment parameters. */
469 
470 typedef struct {
471 
472 	/* The number of progression order changes. */
473 	int numpchgs;
474 
475 	/* The per-progression-order-change information. */
476 	jpc_pocpchg_t *pchgs;
477 
478 } jpc_poc_t;
479 
480 /**************************************\
481 * PPM/PPT marker segment parameters.
482 \**************************************/
483 
484 /* PPM marker segment parameters. */
485 
486 typedef struct {
487 
488 	/* The index. */
489 	uint_fast8_t ind;
490 
491 	/* The length. */
492 	uint_fast16_t len;
493 
494 	/* The data. */
495 	uchar *data;
496 
497 } jpc_ppm_t;
498 
499 /* PPT marker segment parameters. */
500 
501 typedef struct {
502 
503 	/* The index. */
504 	uint_fast8_t ind;
505 
506 	/* The length. */
507 	uint_fast32_t len;
508 
509 	/* The data. */
510 	unsigned char *data;
511 
512 } jpc_ppt_t;
513 
514 /**************************************\
515 * COM marker segment parameters.
516 \**************************************/
517 
518 /*
519  * Registration IDs.
520  */
521 
522 #define	JPC_COM_BIN		0x00
523 #define	JPC_COM_LATIN	0x01
524 
525 typedef struct {
526 
527 	/* The registration ID. */
528 	uint_fast16_t regid;
529 
530 	/* The length of the data in bytes. */
531 	uint_fast16_t len;
532 
533 	/* The data. */
534 	uchar *data;
535 
536 } jpc_com_t;
537 
538 /**************************************\
539 * SOP marker segment parameters.
540 \**************************************/
541 
542 typedef struct {
543 
544 	/* The sequence number. */
545 	uint_fast16_t seqno;
546 
547 } jpc_sop_t;
548 
549 /**************************************\
550 * CRG marker segment parameters.
551 \**************************************/
552 
553 /* Per component information. */
554 
555 typedef struct {
556 
557 	/* The horizontal offset. */
558 	uint_fast16_t hoff;
559 
560 	/* The vertical offset. */
561 	uint_fast16_t voff;
562 
563 } jpc_crgcomp_t;
564 
565 typedef struct {
566 
567 	/* The number of components. */
568 	int numcomps;
569 
570 	/* Per component information. */
571 	jpc_crgcomp_t *comps;
572 
573 } jpc_crg_t;
574 
575 /**************************************\
576 * Marker segment parameters for unknown marker type.
577 \**************************************/
578 
579 typedef struct {
580 
581 	/* The data. */
582 	uchar *data;
583 
584 	/* The length. */
585 	uint_fast16_t len;
586 
587 } jpc_unk_t;
588 
589 /**************************************\
590 * Generic marker segment parameters.
591 \**************************************/
592 
593 typedef union {
594 	int soc;	/* unused */
595 	jpc_sot_t sot;
596 	int sod;	/* unused */
597 	int eoc;	/* unused */
598 	jpc_siz_t siz;
599 	jpc_cod_t cod;
600 	jpc_coc_t coc;
601 	jpc_rgn_t rgn;
602 	jpc_qcd_t qcd;
603 	jpc_qcc_t qcc;
604 	jpc_poc_t poc;
605 	/* jpc_plm_t plm; */
606 	/* jpc_plt_t plt; */
607 	jpc_ppm_t ppm;
608 	jpc_ppt_t ppt;
609 	jpc_sop_t sop;
610 	int eph;	/* unused */
611 	jpc_com_t com;
612 	jpc_crg_t crg;
613 	jpc_unk_t unk;
614 } jpc_msparms_t;
615 
616 /**************************************\
617 * Marker segment.
618 \**************************************/
619 
620 /* Marker segment IDs. */
621 
622 /* The smallest valid marker value. */
623 #define	JPC_MS_MIN	0xff00
624 
625 /* The largest valid marker value. */
626 #define	JPC_MS_MAX	0xffff
627 
628 /* The minimum marker value that cannot occur within packet data. */
629 #define	JPC_MS_INMIN	0xff80
630 /* The maximum marker value that cannot occur within packet data. */
631 #define	JPC_MS_INMAX	0xffff
632 
633 /* Delimiting marker segments. */
634 #define	JPC_MS_SOC	0xff4f /* Start of code stream (SOC). */
635 #define	JPC_MS_SOT	0xff90 /* Start of tile-part (SOT). */
636 #define	JPC_MS_SOD	0xff93 /* Start of data (SOD). */
637 #define	JPC_MS_EOC	0xffd9 /* End of code stream (EOC). */
638 
639 /* Fixed information marker segments. */
640 #define	JPC_MS_SIZ	0xff51 /* Image and tile size (SIZ). */
641 
642 /* Functional marker segments. */
643 #define	JPC_MS_COD	0xff52 /* Coding style default (COD). */
644 #define JPC_MS_COC	0xff53 /* Coding style component (COC). */
645 #define	JPC_MS_RGN	0xff5e /* Region of interest (RGN). */
646 #define JPC_MS_QCD	0xff5c /* Quantization default (QCD). */
647 #define JPC_MS_QCC	0xff5d /* Quantization component (QCC). */
648 #define JPC_MS_POC	0xff5f /* Progression order default (POC). */
649 
650 /* Pointer marker segments. */
651 #define	JPC_MS_TLM	0xff55 /* Tile-part lengths, main header (TLM). */
652 #define	JPC_MS_PLM	0xff57 /* Packet length, main header (PLM). */
653 #define	JPC_MS_PLT	0xff58 /* Packet length, tile-part header (PLT). */
654 #define	JPC_MS_PPM	0xff60 /* Packed packet headers, main header (PPM). */
655 #define	JPC_MS_PPT	0xff61 /* Packet packet headers, tile-part header (PPT). */
656 
657 /* In bit stream marker segments. */
658 #define	JPC_MS_SOP	0xff91	/* Start of packet (SOP). */
659 #define	JPC_MS_EPH	0xff92	/* End of packet header (EPH). */
660 
661 /* Informational marker segments. */
662 #define	JPC_MS_CRG	0xff63 /* Component registration (CRG). */
663 #define JPC_MS_COM	0xff64 /* Comment (COM). */
664 
665 /* Forward declaration. */
666 struct jpc_msops_s;
667 
668 /* Generic marker segment class. */
669 
670 typedef struct {
671 
672 	/* The type of marker segment. */
673 	uint_fast16_t id;
674 
675 	/* The length of the marker segment. */
676 	uint_fast16_t len;
677 
678 	/* The starting offset within the stream. */
679 	uint_fast32_t off;
680 
681 	/* The parameters of the marker segment. */
682 	jpc_msparms_t parms;
683 
684 	/* The marker segment operations. */
685 	struct jpc_msops_s *ops;
686 
687 } jpc_ms_t;
688 
689 /* Marker segment operations (which depend on the marker segment type). */
690 
691 typedef struct jpc_msops_s {
692 
693 	/* Destroy the marker segment parameters. */
694 	void (*destroyparms)(jpc_ms_t *ms);
695 
696 	/* Get the marker segment parameters from a stream. */
697 	int (*getparms)(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *in);
698 
699 	/* Put the marker segment parameters to a stream. */
700 	int (*putparms)(jpc_ms_t *ms, jpc_cstate_t *cstate, jas_stream_t *out);
701 
702 	/* Dump the marker segment parameters (for debugging). */
703 	int (*dumpparms)(jpc_ms_t *ms, FILE *out);
704 
705 } jpc_msops_t;
706 
707 /******************************************************************************\
708 * Macros/Functions.
709 \******************************************************************************/
710 
711 /* Create a code-stream state object. */
712 jpc_cstate_t *jpc_cstate_create(void);
713 
714 /* Destroy a code-stream state object. */
715 void jpc_cstate_destroy(jpc_cstate_t *cstate);
716 
717 /* Create a marker segment. */
718 jpc_ms_t *jpc_ms_create(int type);
719 
720 /* Destroy a marker segment. */
721 void jpc_ms_destroy(jpc_ms_t *ms);
722 
723 /* Does a marker segment have parameters? */
724 #define	JPC_MS_HASPARMS(x) \
725 	(!((x) == JPC_MS_SOC || (x) == JPC_MS_SOD || (x) == JPC_MS_EOC || \
726 	  (x) == JPC_MS_EPH || ((x) >= 0xff30 && (x) <= 0xff3f)))
727 
728 /* Get the marker segment type. */
729 #define	jpc_ms_gettype(ms) \
730 	((ms)->id)
731 
732 /* Read a marker segment from a stream. */
733 jpc_ms_t *jpc_getms(jas_stream_t *in, jpc_cstate_t *cstate);
734 
735 /* Write a marker segment to a stream. */
736 int jpc_putms(jas_stream_t *out, jpc_cstate_t *cstate, jpc_ms_t *ms);
737 
738 /* Copy code stream data from one stream to another. */
739 int jpc_getdata(jas_stream_t *in, jas_stream_t *out, long n);
740 
741 /* Copy code stream data from one stream to another. */
742 int jpc_putdata(jas_stream_t *out, jas_stream_t *in, long n);
743 
744 /* Dump a marker segment (for debugging). */
745 void jpc_ms_dump(jpc_ms_t *ms, FILE *out);
746 
747 /* Read a 8-bit unsigned integer from a stream. */
748 int jpc_getuint8(jas_stream_t *in, uint_fast8_t *val);
749 
750 /* Read a 16-bit unsigned integer from a stream. */
751 int jpc_getuint16(jas_stream_t *in, uint_fast16_t *val);
752 
753 /* Read a 32-bit unsigned integer from a stream. */
754 int jpc_getuint32(jas_stream_t *in, uint_fast32_t *val);
755 
756 /* Write a 8-bit unsigned integer to a stream. */
757 int jpc_putuint8(jas_stream_t *out, uint_fast8_t val);
758 
759 /* Write a 16-bit unsigned integer to a stream. */
760 int jpc_putuint16(jas_stream_t *out, uint_fast16_t val);
761 
762 /* Write a 32-bit unsigned integer to a stream. */
763 int jpc_putuint32(jas_stream_t *out, uint_fast32_t val);
764 
765 #endif
766