]>
Commit | Line | Data |
---|---|---|
36ff6d80 SB |
1 | /* Copyright 2013 Google Inc. All Rights Reserved.\r |
2 | \r | |
3 | Distributed under MIT license.\r | |
4 | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT\r | |
5 | */\r | |
6 | \r | |
7 | /* Utilities for building Huffman decoding tables. */\r | |
8 | \r | |
9 | #ifndef BROTLI_DEC_HUFFMAN_H_\r | |
10 | #define BROTLI_DEC_HUFFMAN_H_\r | |
11 | \r | |
2730470f LG |
12 | #include "../common/platform.h"\r |
13 | #include <brotli/types.h>\r | |
36ff6d80 SB |
14 | \r |
15 | #if defined(__cplusplus) || defined(c_plusplus)\r | |
16 | extern "C" {\r | |
17 | #endif\r | |
18 | \r | |
19 | #define BROTLI_HUFFMAN_MAX_CODE_LENGTH 15\r | |
20 | \r | |
21 | /* Maximum possible Huffman table size for an alphabet size of (index * 32),\r | |
2730470f | 22 | max code length 15 and root table bits 8. */\r |
36ff6d80 SB |
23 | static const uint16_t kMaxHuffmanTableSize[] = {\r |
24 | 256, 402, 436, 468, 500, 534, 566, 598, 630, 662, 694, 726, 758, 790, 822,\r | |
2730470f LG |
25 | 854, 886, 920, 952, 984, 1016, 1048, 1080, 1112, 1144, 1176, 1208, 1240, 1272,\r |
26 | 1304, 1336, 1368, 1400, 1432, 1464, 1496, 1528};\r | |
36ff6d80 SB |
27 | /* BROTLI_NUM_BLOCK_LEN_SYMBOLS == 26 */\r |
28 | #define BROTLI_HUFFMAN_MAX_SIZE_26 396\r | |
29 | /* BROTLI_MAX_BLOCK_TYPE_SYMBOLS == 258 */\r | |
30 | #define BROTLI_HUFFMAN_MAX_SIZE_258 632\r | |
31 | /* BROTLI_MAX_CONTEXT_MAP_SYMBOLS == 272 */\r | |
32 | #define BROTLI_HUFFMAN_MAX_SIZE_272 646\r | |
33 | \r | |
34 | #define BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH 5\r | |
35 | \r | |
36 | typedef struct {\r | |
37 | uint8_t bits; /* number of bits used for this symbol */\r | |
38 | uint16_t value; /* symbol value or table offset */\r | |
39 | } HuffmanCode;\r | |
40 | \r | |
41 | /* Builds Huffman lookup table assuming code lengths are in symbol order. */\r | |
42 | BROTLI_INTERNAL void BrotliBuildCodeLengthsHuffmanTable(HuffmanCode* root_table,\r | |
43 | const uint8_t* const code_lengths, uint16_t* count);\r | |
44 | \r | |
2730470f LG |
45 | /* Builds Huffman lookup table assuming code lengths are in symbol order.\r |
46 | Returns size of resulting table. */\r | |
36ff6d80 SB |
47 | BROTLI_INTERNAL uint32_t BrotliBuildHuffmanTable(HuffmanCode* root_table,\r |
48 | int root_bits, const uint16_t* const symbol_lists, uint16_t* count_arg);\r | |
49 | \r | |
2730470f LG |
50 | /* Builds a simple Huffman table. The |num_symbols| parameter is to be\r |
51 | interpreted as follows: 0 means 1 symbol, 1 means 2 symbols,\r | |
52 | 2 means 3 symbols, 3 means 4 symbols with lengths [2, 2, 2, 2],\r | |
53 | 4 means 4 symbols with lengths [1, 2, 3, 3]. */\r | |
36ff6d80 SB |
54 | BROTLI_INTERNAL uint32_t BrotliBuildSimpleHuffmanTable(HuffmanCode* table,\r |
55 | int root_bits, uint16_t* symbols, uint32_t num_symbols);\r | |
56 | \r | |
57 | /* Contains a collection of Huffman trees with the same alphabet size. */\r | |
2730470f LG |
58 | /* max_symbol is needed due to simple codes since log2(alphabet_size) could be\r |
59 | greater than log2(max_symbol). */\r | |
36ff6d80 SB |
60 | typedef struct {\r |
61 | HuffmanCode** htrees;\r | |
62 | HuffmanCode* codes;\r | |
63 | uint16_t alphabet_size;\r | |
2730470f | 64 | uint16_t max_symbol;\r |
36ff6d80 SB |
65 | uint16_t num_htrees;\r |
66 | } HuffmanTreeGroup;\r | |
67 | \r | |
68 | #if defined(__cplusplus) || defined(c_plusplus)\r | |
69 | } /* extern "C" */\r | |
70 | #endif\r | |
71 | \r | |
72 | #endif /* BROTLI_DEC_HUFFMAN_H_ */\r |