sbhc.h 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* Copyright (C) 1994 Aladdin Enterprises. All rights reserved.
  2. This software is provided AS-IS with no warranty, either express or
  3. implied.
  4. This software is distributed under license and may not be copied,
  5. modified or distributed except as expressly authorized under the terms
  6. of the license contained in the file LICENSE in this distribution.
  7. For more information about licensing, please refer to
  8. http://www.ghostscript.com/licensing/. For information on
  9. commercial licensing, go to http://www.artifex.com/licensing/ or
  10. contact Artifex Software, Inc., 101 Lucas Valley Road #110,
  11. San Rafael, CA 94903, U.S.A., +1(415)492-9861.
  12. */
  13. /* $Id: sbhc.h,v 1.4 2002/02/21 22:24:53 giles Exp $ */
  14. /* Definitions for BoundedHuffman filters */
  15. /* Requires strimpl.h */
  16. #ifndef sbhc_INCLUDED
  17. # define sbhc_INCLUDED
  18. #include "shc.h"
  19. /*
  20. * The BoundedHuffman filters extend the basic Huffman coding model by
  21. * providing the ability to encode runs of zeros as a single data item,
  22. * and by providing an end-of-data (EOD) marker.
  23. */
  24. #define max_zero_run 100
  25. /* Common state */
  26. #define stream_BHC_state_common\
  27. stream_hc_state_common;\
  28. hc_definition definition;\
  29. /* The client sets the following before initialization. */\
  30. bool EndOfData;\
  31. uint EncodeZeroRuns;\
  32. /* The following are updated dynamically. */\
  33. int zeros /* # of zeros scanned or left to output */
  34. typedef struct stream_BHC_state_s {
  35. stream_BHC_state_common;
  36. } stream_BHC_state;
  37. /* BoundedHuffmanEncode */
  38. typedef struct stream_BHCE_state_s {
  39. stream_BHC_state_common;
  40. hce_table encode;
  41. } stream_BHCE_state;
  42. #define private_st_BHCE_state() /* in sbhc.c */\
  43. gs_private_st_ptrs3(st_BHCE_state, stream_BHCE_state,\
  44. "BoundedHuffmanEncode state", bhce_enum_ptrs, bhce_reloc_ptrs,\
  45. definition.counts, definition.values, encode.codes)
  46. extern const stream_template s_BHCE_template;
  47. #define s_bhce_init_inline(ss)\
  48. (s_hce_init_inline(ss), (ss)->zeros = 0)
  49. /* BoundedHuffmanDecode */
  50. typedef struct stream_BHCD_state_s {
  51. stream_BHC_state_common;
  52. hcd_table decode;
  53. } stream_BHCD_state;
  54. #define private_st_BHCD_state() /* in sbhc.c */\
  55. gs_private_st_ptrs3(st_BHCD_state, stream_BHCD_state,\
  56. "BoundedHuffmanDecode state", bhcd_enum_ptrs, bhcd_reloc_ptrs,\
  57. definition.counts, definition.values, decode.codes)
  58. extern const stream_template s_BHCD_template;
  59. #define s_bhcd_init_inline(ss)\
  60. (s_hcd_init_inline(ss), (ss)->zeros = 0)
  61. /* Declare variables that hold the decoder state. */
  62. #define bhcd_declare_state\
  63. hcd_declare_state;\
  64. int zeros
  65. /* Load the state from the stream. */
  66. /* Free variables: pr, ss, p, rlimit, bits, bits_left, zeros. */
  67. #define bhcd_load_state()\
  68. hcd_load_state(), zeros = ss->zeros
  69. /* Store the state back in the stream. */
  70. /* Free variables: pr, ss, p, bits, bits_left, zeros. */
  71. #define bhcd_store_state()\
  72. hcd_store_state(), ss->zeros = zeros
  73. #endif /* sbhc_INCLUDED */