1 /* Copyright (C) 1994 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: sbhc.h,v 1.4 2002/02/21 22:24:53 giles Exp $ */ 18 /* Definitions for BoundedHuffman filters */ 19 /* Requires strimpl.h */ 20 21 #ifndef sbhc_INCLUDED 22 # define sbhc_INCLUDED 23 24 #include "shc.h" 25 26 /* 27 * The BoundedHuffman filters extend the basic Huffman coding model by 28 * providing the ability to encode runs of zeros as a single data item, 29 * and by providing an end-of-data (EOD) marker. 30 */ 31 #define max_zero_run 100 32 33 /* Common state */ 34 #define stream_BHC_state_common\ 35 stream_hc_state_common;\ 36 hc_definition definition;\ 37 /* The client sets the following before initialization. */\ 38 bool EndOfData;\ 39 uint EncodeZeroRuns;\ 40 /* The following are updated dynamically. */\ 41 int zeros /* # of zeros scanned or left to output */ 42 typedef struct stream_BHC_state_s { 43 stream_BHC_state_common; 44 } stream_BHC_state; 45 46 /* BoundedHuffmanEncode */ 47 typedef struct stream_BHCE_state_s { 48 stream_BHC_state_common; 49 hce_table encode; 50 } stream_BHCE_state; 51 52 #define private_st_BHCE_state() /* in sbhc.c */\ 53 gs_private_st_ptrs3(st_BHCE_state, stream_BHCE_state,\ 54 "BoundedHuffmanEncode state", bhce_enum_ptrs, bhce_reloc_ptrs,\ 55 definition.counts, definition.values, encode.codes) 56 extern const stream_template s_BHCE_template; 57 58 #define s_bhce_init_inline(ss)\ 59 (s_hce_init_inline(ss), (ss)->zeros = 0) 60 61 /* BoundedHuffmanDecode */ 62 typedef struct stream_BHCD_state_s { 63 stream_BHC_state_common; 64 hcd_table decode; 65 } stream_BHCD_state; 66 67 #define private_st_BHCD_state() /* in sbhc.c */\ 68 gs_private_st_ptrs3(st_BHCD_state, stream_BHCD_state,\ 69 "BoundedHuffmanDecode state", bhcd_enum_ptrs, bhcd_reloc_ptrs,\ 70 definition.counts, definition.values, decode.codes) 71 extern const stream_template s_BHCD_template; 72 73 #define s_bhcd_init_inline(ss)\ 74 (s_hcd_init_inline(ss), (ss)->zeros = 0) 75 76 /* Declare variables that hold the decoder state. */ 77 #define bhcd_declare_state\ 78 hcd_declare_state;\ 79 int zeros 80 81 /* Load the state from the stream. */ 82 /* Free variables: pr, ss, p, rlimit, bits, bits_left, zeros. */ 83 #define bhcd_load_state()\ 84 hcd_load_state(), zeros = ss->zeros 85 86 /* Store the state back in the stream. */ 87 /* Free variables: pr, ss, p, bits, bits_left, zeros. */ 88 #define bhcd_store_state()\ 89 hcd_store_state(), ss->zeros = zeros 90 91 #endif /* sbhc_INCLUDED */ 92