1 /* Copyright (C) 2001-2019 Artifex Software, Inc. 2 All Rights Reserved. 3 4 This software is provided AS-IS with no warranty, either express or 5 implied. 6 7 This software is distributed under license and may not be copied, 8 modified or distributed except as expressly authorized under the terms 9 of the license contained in the file LICENSE in this distribution. 10 11 Refer to licensing information at http://www.artifex.com or contact 12 Artifex Software, Inc., 1305 Grant Avenue - Suite 200, Novato, 13 CA 94945, U.S.A., +1(415)492-9861, for further information. 14 */ 15 16 17 /* Definitions for LZW filters */ 18 /* Requires strimpl.h */ 19 20 #ifndef slzwx_INCLUDED 21 # define slzwx_INCLUDED 22 23 #include "scommon.h" 24 25 typedef struct lzw_decode_s lzw_decode; 26 typedef struct lzw_encode_table_s lzw_encode_table; 27 typedef struct stream_LZW_state_s { 28 stream_state_common; 29 /* The following are set before initialization. */ 30 int InitialCodeLength; /* decoding only */ 31 /* 32 * Adobe calls FirstBitLowOrder LowBitFirst. Either one will work 33 * in PostScript code. 34 */ 35 bool FirstBitLowOrder; /* decoding only */ 36 bool BlockData; /* decoding only */ 37 bool EarlyChange; /* decoding only */ 38 bool OldTiff; /* decoding only */ 39 /* The following are updated dynamically. */ 40 uint bits; /* buffer for input bits */ 41 int bits_left; /* Decode: # of valid bits left, [0..7] */ 42 /* (low-order bits if !FirstBitLowOrder, */ 43 /* high-order bits if FirstBitLowOrder) */ 44 int bytes_left; /* # of bytes left in current block */ 45 /* (arbitrary large # if not GIF) */ 46 union _lzt { 47 lzw_decode *decode; 48 lzw_encode_table *encode; 49 } table; 50 uint next_code; /* next code to be assigned */ 51 int code_size; /* current # of bits per code */ 52 int prev_code; /* previous code recognized or assigned */ 53 uint prev_len; /* length of prev_code */ 54 int copy_code; /* code whose string is being */ 55 /* copied, -1 if none */ 56 uint copy_len; /* length of copy_code */ 57 int copy_left; /* amount of string left to copy */ 58 bool first; /* true if no output yet */ 59 } stream_LZW_state; 60 61 extern_st(st_LZW_state); 62 #define public_st_LZW_state() /* in slzwc.c */\ 63 gs_public_st_ptrs1(st_LZW_state, stream_LZW_state,\ 64 "LZWDecode state", lzwd_enum_ptrs, lzwd_reloc_ptrs, table.decode) 65 #define s_LZW_set_defaults_inline(ss)\ 66 ((ss)->InitialCodeLength = 8,\ 67 (ss)->FirstBitLowOrder = false,\ 68 (ss)->BlockData = false,\ 69 (ss)->EarlyChange = 1,\ 70 (ss)->OldTiff = 0,\ 71 /* Clear pointers */\ 72 (ss)->table.decode /*=encode*/ = 0) 73 extern const stream_template s_LZWD_template; 74 extern const stream_template s_LZWE_template; 75 76 /* Shared procedures */ 77 void s_LZW_set_defaults(stream_state *); 78 void s_LZW_release(stream_state *); 79 80 #endif /* slzwx_INCLUDED */ 81