mini_inflate.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 2 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program; if not, write to the Free Software
  22. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  23. *
  24. */
  25. typedef __SIZE_TYPE__ size;
  26. #define NO_ERROR 0
  27. #define COMP_UNKNOWN 1 /* The specififed bytype is invalid */
  28. #define CODE_NOT_FOUND 2 /* a huffman code in the stream could not be decoded */
  29. #define TOO_MANY_BITS 3 /* pull_bits was passed an argument that is too
  30. * large */
  31. /* This struct represents an entire huffman code set. It has various lookup
  32. * tables to speed decoding */
  33. struct huffman_set {
  34. int bits; /* maximum bit length */
  35. int num_symbols; /* Number of symbols this code can represent */
  36. int *lengths; /* The bit length of symbols */
  37. int *symbols; /* All of the symbols, sorted by the huffman code */
  38. int *count; /* the number of codes of this bit length */
  39. int *first; /* the first code of this bit length */
  40. int *pos; /* the symbol that first represents (in the symbols
  41. * array) */
  42. };
  43. struct bitstream {
  44. unsigned char *data; /* increments as we move from byte to byte */
  45. unsigned char bit; /* 0 to 7 */
  46. void *(*memcpy)(void *, const void *, size);
  47. unsigned long decoded; /* The number of bytes decoded */
  48. int error;
  49. int distance_count[16];
  50. int distance_first[16];
  51. int distance_pos[16];
  52. int distance_lengths[32];
  53. int distance_symbols[32];
  54. int code_count[8];
  55. int code_first[8];
  56. int code_pos[8];
  57. int code_lengths[19];
  58. int code_symbols[19];
  59. int length_count[16];
  60. int length_first[16];
  61. int length_pos[16];
  62. int length_lengths[288];
  63. int length_symbols[288];
  64. struct huffman_set codes;
  65. struct huffman_set lengths;
  66. struct huffman_set distance;
  67. };
  68. #define NO_COMP 0
  69. #define FIXED_COMP 1
  70. #define DYNAMIC_COMP 2
  71. long decompress_block(unsigned char *dest, unsigned char *source,
  72. void *(*inflate_memcpy)(void *dest, const void *src, size n));