tinf.h 2.9 KB

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