mini_inflate.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. /*-------------------------------------------------------------------------
  2. * Filename: mini_inflate.h
  3. * Version: $Id: mini_inflate.h,v 1.2 2002/01/17 00:53:20 nyet Exp $
  4. * Copyright: Copyright (C) 2001, Russ Dill
  5. * Author: Russ Dill <Russ.Dill@asu.edu>
  6. * Description: Mini deflate implementation
  7. *-----------------------------------------------------------------------*/
  8. /*
  9. * SPDX-License-Identifier: GPL-2.0+
  10. */
  11. typedef __SIZE_TYPE__ size;
  12. #define NO_ERROR 0
  13. #define COMP_UNKNOWN 1 /* The specififed bytype is invalid */
  14. #define CODE_NOT_FOUND 2 /* a huffman code in the stream could not be decoded */
  15. #define TOO_MANY_BITS 3 /* pull_bits was passed an argument that is too
  16. * large */
  17. /* This struct represents an entire huffman code set. It has various lookup
  18. * tables to speed decoding */
  19. struct huffman_set {
  20. int bits; /* maximum bit length */
  21. int num_symbols; /* Number of symbols this code can represent */
  22. int *lengths; /* The bit length of symbols */
  23. int *symbols; /* All of the symbols, sorted by the huffman code */
  24. int *count; /* the number of codes of this bit length */
  25. int *first; /* the first code of this bit length */
  26. int *pos; /* the symbol that first represents (in the symbols
  27. * array) */
  28. };
  29. struct bitstream {
  30. unsigned char *data; /* increments as we move from byte to byte */
  31. unsigned char bit; /* 0 to 7 */
  32. void *(*memcpy)(void *, const void *, size);
  33. unsigned long decoded; /* The number of bytes decoded */
  34. int error;
  35. int distance_count[16];
  36. int distance_first[16];
  37. int distance_pos[16];
  38. int distance_lengths[32];
  39. int distance_symbols[32];
  40. int code_count[8];
  41. int code_first[8];
  42. int code_pos[8];
  43. int code_lengths[19];
  44. int code_symbols[19];
  45. int length_count[16];
  46. int length_first[16];
  47. int length_pos[16];
  48. int length_lengths[288];
  49. int length_symbols[288];
  50. struct huffman_set codes;
  51. struct huffman_set lengths;
  52. struct huffman_set distance;
  53. };
  54. #define NO_COMP 0
  55. #define FIXED_COMP 1
  56. #define DYNAMIC_COMP 2
  57. long decompress_block(unsigned char *dest, unsigned char *source,
  58. void *(*inflate_memcpy)(void *dest, const void *src, size n));