xref: /plan9/sys/src/cmd/gs/src/srlx.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1994, 1995, 1996, 1997 Aladdin Enterprises.  All rights reserved.
2 
3   This software is provided AS-IS with no warranty, either express or
4   implied.
5 
6   This software is distributed under license and may not be copied,
7   modified or distributed except as expressly authorized under the terms
8   of the license contained in the file LICENSE in this distribution.
9 
10   For more information about licensing, please refer to
11   http://www.ghostscript.com/licensing/. For information on
12   commercial licensing, go to http://www.artifex.com/licensing/ or
13   contact Artifex Software, Inc., 101 Lucas Valley Road #110,
14   San Rafael, CA  94903, U.S.A., +1(415)492-9861.
15 */
16 
17 /* $Id: srlx.h,v 1.5 2002/02/21 22:24:54 giles Exp $ */
18 /* Definitions for RunLength filters */
19 /* Requires scommon.h; strimpl.h if any templates are referenced */
20 
21 #ifndef srlx_INCLUDED
22 #  define srlx_INCLUDED
23 
24 /* Common state */
25 #define stream_RL_state_common\
26 	stream_state_common;\
27 	bool EndOfData		/* true if 128 = EOD */
28 
29 /* RunLengthEncode */
30 typedef struct stream_RLE_state_s {
31     stream_RL_state_common;
32     /* The following parameters are set by the client. */
33     ulong record_size;
34     /* The following change dynamically. */
35     ulong record_left;		/* bytes left in current record */
36     int copy_left;		/* # of bytes waiting to be copied */
37 } stream_RLE_state;
38 
39 #define private_st_RLE_state()	/* in srle.c */\
40   gs_private_st_simple(st_RLE_state, stream_RLE_state, "RunLengthEncode state")
41 /* We define the initialization procedure here, so that clients */
42 /* can avoid a procedure call. */
43 #define s_RLE_set_defaults_inline(ss)\
44   ((ss)->EndOfData = true, (ss)->record_size = 0)
45 #define s_RLE_init_inline(ss)\
46   ((ss)->record_left =\
47    ((ss)->record_size == 0 ? ((ss)->record_size = max_uint) :\
48     (ss)->record_size),\
49    (ss)->copy_left = 0)
50 extern const stream_template s_RLE_template;
51 
52 /* RunLengthDecode */
53 typedef struct stream_RLD_state_s {
54     stream_RL_state_common;
55     /* The following change dynamically. */
56     int copy_left;		/* # of output bytes waiting to be produced */
57     int copy_data;		/* -1 if copying, repeated byte if repeating */
58 } stream_RLD_state;
59 
60 #define private_st_RLD_state()	/* in srld.c */\
61   gs_private_st_simple(st_RLD_state, stream_RLD_state, "RunLengthDecode state")
62 /* We define the initialization procedure here, so that clients */
63 /* can avoid a procedure call. */
64 #define s_RLD_set_defaults_inline(ss)\
65   ((ss)->EndOfData = true)
66 #define s_RLD_init_inline(ss)\
67   ((ss)->min_left = ((ss)->EndOfData ? 1 : 0), (ss)->copy_left = 0)
68 extern const stream_template s_RLD_template;
69 
70 #endif /* srlx_INCLUDED */
71