tinf.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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. /* we don't have stdint.h */
  13. typedef signed char int8_t;
  14. typedef short int int16_t;
  15. typedef int int32_t;
  16. typedef long int int64_t;
  17. typedef unsigned char uint8_t;
  18. typedef unsigned short int uint16_t;
  19. typedef unsigned int uint32_t;
  20. typedef unsigned long int uint64_t;
  21. /* calling convention */
  22. #ifndef TINFCC
  23. #ifdef __WATCOMC__
  24. #define TINFCC __cdecl
  25. #else
  26. #define TINFCC
  27. #endif
  28. #endif
  29. #ifdef __cplusplus
  30. extern "C" {
  31. #endif
  32. /* ok status, more data produced */
  33. #define TINF_OK 0
  34. /* end of compressed stream reached */
  35. #define TINF_DONE 1
  36. #define TINF_DATA_ERROR (-3)
  37. #define TINF_CHKSUM_ERROR (-4)
  38. #define TINF_DICT_ERROR (-5)
  39. /* checksum types */
  40. #define TINF_CHKSUM_NONE 0
  41. #define TINF_CHKSUM_ADLER 1
  42. #define TINF_CHKSUM_CRC 2
  43. /* data structures */
  44. typedef struct {
  45. unsigned int table[16]; /* table of code length counts */
  46. unsigned int trans[288]; /* code -> symbol translation table */
  47. } TINF_TREE;
  48. struct TINF_DATA;
  49. typedef struct TINF_DATA {
  50. TINF_TREE ltree; /* dynamic length/symbol tree */
  51. TINF_TREE dtree; /* dynamic distance tree */
  52. const unsigned char *source;
  53. /* If source above is NULL, this function will be used to read
  54. next byte from source stream */
  55. unsigned char (*readSource)(volatile struct TINF_DATA *data);
  56. unsigned int tag;
  57. unsigned int bitcount;
  58. /* Buffer start */
  59. unsigned char *destStart;
  60. /* Buffer total size */
  61. unsigned int destSize;
  62. /* Current pointer in buffer */
  63. unsigned char *dest;
  64. /* Remaining bytes in buffer */
  65. unsigned int destRemaining;
  66. /* Accumulating checksum */
  67. unsigned int checksum;
  68. unsigned int checksum_type;
  69. int btype;
  70. int bfinal;
  71. unsigned int curlen;
  72. int lzOff;
  73. } TINF_DATA;
  74. #define TINF_PUT(d, c) \
  75. { \
  76. *d->dest++ = c; \
  77. }
  78. unsigned char TINFCC uzlib_get_byte(volatile TINF_DATA *d);
  79. /* Decompression API */
  80. void TINFCC uzlib_init(void);
  81. void TINFCC uzlib_uncompress_init(TINF_DATA *d, void *dict, unsigned int dictLen);
  82. int TINFCC uzlib_uncompress(volatile TINF_DATA *d);
  83. int TINFCC uzlib_uncompress_chksum(TINF_DATA *d);
  84. int TINFCC uzlib_zlib_parse_header(TINF_DATA *d);
  85. int TINFCC uzlib_gzip_parse_header(TINF_DATA *d);
  86. /* Compression API */
  87. void TINFCC uzlib_compress(void *data, const uint8_t *src, unsigned slen);
  88. /* Checksum API */
  89. /* prev_sum is previous value for incremental computation, 1 initially */
  90. uint32_t TINFCC uzlib_adler32(const void *data, unsigned int length, uint32_t prev_sum);
  91. /* crc is previous value for incremental computation, 0xffffffff initially */
  92. uint32_t TINFCC uzlib_crc32(const void *data, unsigned int length, uint32_t crc);
  93. #ifdef __cplusplus
  94. } /* extern "C" */
  95. #endif
  96. #endif /* TINF_H_INCLUDED */