tinf.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111
  1. /*
  2. * uzlib - tiny deflate/inflate library (deflate, gzip, zlib)
  3. *
  4. * Copyright (c) 2003 by Joergen Ibsen / Jibz
  5. * All Rights Reserved
  6. * http://www.ibsensoftware.com/
  7. *
  8. * Copyright (c) 2014-2016 by Paul Sokolovsky
  9. */
  10. #ifndef TINF_H_INCLUDED
  11. #define TINF_H_INCLUDED
  12. /* calling convention */
  13. #ifndef TINFCC
  14. #ifdef __WATCOMC__
  15. #define TINFCC __cdecl
  16. #else
  17. #define TINFCC
  18. #endif
  19. #endif
  20. #ifdef __cplusplus
  21. extern "C" {
  22. #endif
  23. /* ok status, more data produced */
  24. #define TINF_OK 0
  25. /* end of compressed stream reached */
  26. #define TINF_DONE 1
  27. #define TINF_DATA_ERROR (-3)
  28. #define TINF_CHKSUM_ERROR (-4)
  29. #define TINF_DICT_ERROR (-5)
  30. /* checksum types */
  31. #define TINF_CHKSUM_NONE 0
  32. #define TINF_CHKSUM_ADLER 1
  33. #define TINF_CHKSUM_CRC 2
  34. /* data structures */
  35. typedef struct {
  36. unsigned int table[16]; /* table of code length counts */
  37. unsigned int trans[288]; /* code -> symbol translation table */
  38. } TINF_TREE;
  39. struct TINF_DATA;
  40. typedef struct TINF_DATA {
  41. TINF_TREE ltree; /* dynamic length/symbol tree */
  42. TINF_TREE dtree; /* dynamic distance tree */
  43. const unsigned char *source;
  44. /* If source above is NULL, this function will be used to read
  45. next byte from source stream */
  46. unsigned char (*readSource)(volatile struct TINF_DATA *data);
  47. unsigned int tag;
  48. unsigned int bitcount;
  49. /* Buffer start */
  50. unsigned char *destStart;
  51. /* Buffer total size */
  52. unsigned int destSize;
  53. /* Current pointer in buffer */
  54. unsigned char *dest;
  55. /* Remaining bytes in buffer */
  56. unsigned int destRemaining;
  57. /* Accumulating checksum */
  58. unsigned int checksum;
  59. unsigned int checksum_type;
  60. int btype;
  61. int bfinal;
  62. unsigned int curlen;
  63. int lzOff;
  64. } TINF_DATA;
  65. #define TINF_PUT(d, c) \
  66. { \
  67. *d->dest++ = c; \
  68. }
  69. unsigned char TINFCC uzlib_get_byte(volatile TINF_DATA *d);
  70. /* Decompression API */
  71. void TINFCC uzlib_init(void);
  72. void TINFCC uzlib_uncompress_init(TINF_DATA *d, void *dict, unsigned int dictLen);
  73. int TINFCC uzlib_uncompress(volatile TINF_DATA *d);
  74. int TINFCC uzlib_uncompress_chksum(TINF_DATA *d);
  75. int TINFCC uzlib_zlib_parse_header(TINF_DATA *d);
  76. int TINFCC uzlib_gzip_parse_header(TINF_DATA *d);
  77. /* Compression API */
  78. void TINFCC uzlib_compress(void *data, const uint8_t *src, unsigned slen);
  79. /* Checksum API */
  80. /* prev_sum is previous value for incremental computation, 1 initially */
  81. uint32_t TINFCC uzlib_adler32(const void *data, unsigned int length, uint32_t prev_sum);
  82. /* crc is previous value for incremental computation, 0xffffffff initially */
  83. uint32_t TINFCC uzlib_crc32(const void *data, unsigned int length, uint32_t crc);
  84. #ifdef __cplusplus
  85. } /* extern "C" */
  86. #endif
  87. #endif /* TINF_H_INCLUDED */