xref: /plan9/sys/src/cmd/gs/src/slzwx.h (revision 593dc095aefb2a85c828727bbfa9da139a49bdf4)
1 /* Copyright (C) 1993, 1995, 1998, 1999 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: slzwx.h,v 1.5 2002/06/16 05:00:54 lpd Exp $ */
18 /* Definitions for LZW filters */
19 /* Requires strimpl.h */
20 
21 #ifndef slzwx_INCLUDED
22 #  define slzwx_INCLUDED
23 
24 typedef struct lzw_decode_s lzw_decode;
25 typedef struct lzw_encode_table_s lzw_encode_table;
26 typedef struct stream_LZW_state_s {
27     stream_state_common;
28     /* The following are set before initialization. */
29     int InitialCodeLength;	/* decoding only */
30     /*
31      * Adobe calls FirstBitLowOrder LowBitFirst.  Either one will work
32      * in PostScript code.
33      */
34     bool FirstBitLowOrder;	/* decoding only */
35     bool BlockData;		/* decoding only */
36     int EarlyChange;		/* decoding only */
37     /* The following are updated dynamically. */
38     uint bits;			/* buffer for input bits */
39     int bits_left;		/* Decode: # of valid bits left, [0..7] */
40 				/* (low-order bits if !FirstBitLowOrder, */
41 				/* high-order bits if FirstBitLowOrder) */
42     int bytes_left;		/* # of bytes left in current block */
43 				/* (arbitrary large # if not GIF) */
44     union _lzt {
45 	lzw_decode *decode;
46 	lzw_encode_table *encode;
47     } table;
48     uint next_code;		/* next code to be assigned */
49     int code_size;		/* current # of bits per code */
50     int prev_code;		/* previous code recognized or assigned */
51     uint prev_len;		/* length of prev_code */
52     int copy_code;		/* code whose string is being */
53 				/* copied, -1 if none */
54     uint copy_len;		/* length of copy_code */
55     int copy_left;		/* amount of string left to copy */
56     bool first;			/* true if no output yet */
57 } stream_LZW_state;
58 
59 extern_st(st_LZW_state);
60 #define public_st_LZW_state()	/* in slzwc.c */\
61   gs_public_st_ptrs1(st_LZW_state, stream_LZW_state,\
62     "LZWDecode state", lzwd_enum_ptrs, lzwd_reloc_ptrs, table.decode)
63 #define s_LZW_set_defaults_inline(ss)\
64   ((ss)->InitialCodeLength = 8,\
65    (ss)->FirstBitLowOrder = false,\
66    (ss)->BlockData = false,\
67    (ss)->EarlyChange = 1,\
68    /* Clear pointers */\
69    (ss)->table.decode /*=encode*/ = 0)
70 extern const stream_template s_LZWD_template;
71 extern const stream_template s_LZWE_template;
72 
73 /* Shared procedures */
74 void s_LZW_set_defaults(stream_state *);
75 void s_LZW_release(stream_state *);
76 
77 #endif /* slzwx_INCLUDED */
78