dfltcc_common.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. #ifndef DFLTCC_COMMON_H
  2. #define DFLTCC_COMMON_H
  3. #include "zutil.h"
  4. /*
  5. Parameter Block for Query Available Functions.
  6. */
  7. struct dfltcc_qaf_param {
  8. char fns[16];
  9. char reserved1[8];
  10. char fmts[2];
  11. char reserved2[6];
  12. } ALIGNED_(8);
  13. /*
  14. Parameter Block for Generate Dynamic-Huffman Table, Compress and Expand.
  15. */
  16. struct dfltcc_param_v0 {
  17. uint16_t pbvn; /* Parameter-Block-Version Number */
  18. uint8_t mvn; /* Model-Version Number */
  19. uint8_t ribm; /* Reserved for IBM use */
  20. uint32_t reserved32 : 31;
  21. uint32_t cf : 1; /* Continuation Flag */
  22. uint8_t reserved64[8];
  23. uint32_t nt : 1; /* New Task */
  24. uint32_t reserved129 : 1;
  25. uint32_t cvt : 1; /* Check Value Type */
  26. uint32_t reserved131 : 1;
  27. uint32_t htt : 1; /* Huffman-Table Type */
  28. uint32_t bcf : 1; /* Block-Continuation Flag */
  29. uint32_t bcc : 1; /* Block Closing Control */
  30. uint32_t bhf : 1; /* Block Header Final */
  31. uint32_t reserved136 : 1;
  32. uint32_t reserved137 : 1;
  33. uint32_t dhtgc : 1; /* DHT Generation Control */
  34. uint32_t reserved139 : 5;
  35. uint32_t reserved144 : 5;
  36. uint32_t sbb : 3; /* Sub-Byte Boundary */
  37. uint8_t oesc; /* Operation-Ending-Supplemental Code */
  38. uint32_t reserved160 : 12;
  39. uint32_t ifs : 4; /* Incomplete-Function Status */
  40. uint16_t ifl; /* Incomplete-Function Length */
  41. uint8_t reserved192[8];
  42. uint8_t reserved256[8];
  43. uint8_t reserved320[4];
  44. uint16_t hl; /* History Length */
  45. uint32_t reserved368 : 1;
  46. uint16_t ho : 15; /* History Offset */
  47. uint32_t cv; /* Check Value */
  48. uint32_t eobs : 15; /* End-of-block Symbol */
  49. uint32_t reserved431: 1;
  50. uint8_t eobl : 4; /* End-of-block Length */
  51. uint32_t reserved436 : 12;
  52. uint32_t reserved448 : 4;
  53. uint16_t cdhtl : 12; /* Compressed-Dynamic-Huffman Table
  54. Length */
  55. uint8_t reserved464[6];
  56. uint8_t cdht[288]; /* Compressed-Dynamic-Huffman Table */
  57. uint8_t reserved[24];
  58. uint8_t ribm2[8]; /* Reserved for IBM use */
  59. uint8_t csb[1152]; /* Continuation-State Buffer */
  60. } ALIGNED_(8);
  61. /*
  62. Extension of inflate_state and deflate_state.
  63. */
  64. struct dfltcc_state {
  65. struct dfltcc_param_v0 param; /* Parameter block. */
  66. struct dfltcc_qaf_param af; /* Available functions. */
  67. char msg[64]; /* Buffer for strm->msg */
  68. };
  69. typedef struct {
  70. struct dfltcc_state common;
  71. uint16_t level_mask; /* Levels on which to use DFLTCC */
  72. uint32_t block_size; /* New block each X bytes */
  73. size_t block_threshold; /* New block after total_in > X */
  74. uint32_t dht_threshold; /* New block only if avail_in >= X */
  75. } arch_deflate_state;
  76. typedef struct {
  77. struct dfltcc_state common;
  78. } arch_inflate_state;
  79. /*
  80. History buffer size.
  81. */
  82. #define HB_BITS 15
  83. #define HB_SIZE (1 << HB_BITS)
  84. /*
  85. Sizes of deflate block parts.
  86. */
  87. #define DFLTCC_BLOCK_HEADER_BITS 3
  88. #define DFLTCC_HLITS_COUNT_BITS 5
  89. #define DFLTCC_HDISTS_COUNT_BITS 5
  90. #define DFLTCC_HCLENS_COUNT_BITS 4
  91. #define DFLTCC_MAX_HCLENS 19
  92. #define DFLTCC_HCLEN_BITS 3
  93. #define DFLTCC_MAX_HLITS 286
  94. #define DFLTCC_MAX_HDISTS 30
  95. #define DFLTCC_MAX_HLIT_HDIST_BITS 7
  96. #define DFLTCC_MAX_SYMBOL_BITS 16
  97. #define DFLTCC_MAX_EOBS_BITS 15
  98. #define DFLTCC_MAX_PADDING_BITS 7
  99. #define DEFLATE_BOUND_COMPLEN(source_len) \
  100. ((DFLTCC_BLOCK_HEADER_BITS + \
  101. DFLTCC_HLITS_COUNT_BITS + \
  102. DFLTCC_HDISTS_COUNT_BITS + \
  103. DFLTCC_HCLENS_COUNT_BITS + \
  104. DFLTCC_MAX_HCLENS * DFLTCC_HCLEN_BITS + \
  105. (DFLTCC_MAX_HLITS + DFLTCC_MAX_HDISTS) * DFLTCC_MAX_HLIT_HDIST_BITS + \
  106. (source_len) * DFLTCC_MAX_SYMBOL_BITS + \
  107. DFLTCC_MAX_EOBS_BITS + \
  108. DFLTCC_MAX_PADDING_BITS) >> 3)
  109. #endif