2014-10-04 13:02:21 +04:00
|
|
|
/* Copyright 2013 Google Inc. All Rights Reserved.
|
|
|
|
|
2016-02-08 14:01:21 +03:00
|
|
|
Distributed under MIT license.
|
|
|
|
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
2014-10-04 13:02:21 +04:00
|
|
|
*/
|
|
|
|
|
2015-09-19 01:40:05 +03:00
|
|
|
/* Utilities for building Huffman decoding tables. */
|
|
|
|
|
2014-10-04 13:02:21 +04:00
|
|
|
#ifndef BROTLI_DEC_HUFFMAN_H_
|
|
|
|
#define BROTLI_DEC_HUFFMAN_H_
|
|
|
|
|
2018-05-31 19:49:40 +03:00
|
|
|
#include "../common/platform.h"
|
2017-08-09 13:45:39 +03:00
|
|
|
#include <brotli/types.h>
|
2014-10-04 13:02:21 +04:00
|
|
|
|
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-09-19 01:40:05 +03:00
|
|
|
#define BROTLI_HUFFMAN_MAX_CODE_LENGTH 15
|
|
|
|
|
2016-02-08 14:01:21 +03:00
|
|
|
/* Maximum possible Huffman table size for an alphabet size of (index * 32),
|
2018-05-31 19:49:40 +03:00
|
|
|
max code length 15 and root table bits 8. */
|
2016-02-08 14:01:21 +03:00
|
|
|
static const uint16_t kMaxHuffmanTableSize[] = {
|
|
|
|
256, 402, 436, 468, 500, 534, 566, 598, 630, 662, 694, 726, 758, 790, 822,
|
2018-05-31 19:49:40 +03:00
|
|
|
854, 886, 920, 952, 984, 1016, 1048, 1080, 1112, 1144, 1176, 1208, 1240, 1272,
|
|
|
|
1304, 1336, 1368, 1400, 1432, 1464, 1496, 1528};
|
2017-08-09 13:45:39 +03:00
|
|
|
/* BROTLI_NUM_BLOCK_LEN_SYMBOLS == 26 */
|
2016-02-08 14:01:21 +03:00
|
|
|
#define BROTLI_HUFFMAN_MAX_SIZE_26 396
|
2017-08-09 13:45:39 +03:00
|
|
|
/* BROTLI_MAX_BLOCK_TYPE_SYMBOLS == 258 */
|
2016-02-08 14:01:21 +03:00
|
|
|
#define BROTLI_HUFFMAN_MAX_SIZE_258 632
|
2017-08-09 13:45:39 +03:00
|
|
|
/* BROTLI_MAX_CONTEXT_MAP_SYMBOLS == 272 */
|
2016-02-08 14:01:21 +03:00
|
|
|
#define BROTLI_HUFFMAN_MAX_SIZE_272 646
|
2015-09-19 01:40:05 +03:00
|
|
|
|
|
|
|
#define BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH 5
|
|
|
|
|
2014-10-04 13:02:21 +04:00
|
|
|
typedef struct {
|
2016-06-18 13:06:00 +03:00
|
|
|
uint8_t bits; /* number of bits used for this symbol */
|
|
|
|
uint16_t value; /* symbol value or table offset */
|
2014-10-04 13:02:21 +04:00
|
|
|
} HuffmanCode;
|
|
|
|
|
|
|
|
/* Builds Huffman lookup table assuming code lengths are in symbol order. */
|
2016-06-18 13:06:00 +03:00
|
|
|
BROTLI_INTERNAL void BrotliBuildCodeLengthsHuffmanTable(HuffmanCode* root_table,
|
|
|
|
const uint8_t* const code_lengths, uint16_t* count);
|
2015-09-19 01:40:05 +03:00
|
|
|
|
2018-05-31 19:49:40 +03:00
|
|
|
/* Builds Huffman lookup table assuming code lengths are in symbol order.
|
|
|
|
Returns size of resulting table. */
|
2016-06-18 13:06:00 +03:00
|
|
|
BROTLI_INTERNAL uint32_t BrotliBuildHuffmanTable(HuffmanCode* root_table,
|
|
|
|
int root_bits, const uint16_t* const symbol_lists, uint16_t* count_arg);
|
2015-09-19 01:40:05 +03:00
|
|
|
|
2018-05-31 19:49:40 +03:00
|
|
|
/* Builds a simple Huffman table. The |num_symbols| parameter is to be
|
|
|
|
interpreted as follows: 0 means 1 symbol, 1 means 2 symbols,
|
|
|
|
2 means 3 symbols, 3 means 4 symbols with lengths [2, 2, 2, 2],
|
|
|
|
4 means 4 symbols with lengths [1, 2, 3, 3]. */
|
2016-06-18 13:06:00 +03:00
|
|
|
BROTLI_INTERNAL uint32_t BrotliBuildSimpleHuffmanTable(HuffmanCode* table,
|
|
|
|
int root_bits, uint16_t* symbols, uint32_t num_symbols);
|
2015-09-19 01:40:05 +03:00
|
|
|
|
2015-09-28 20:10:09 +03:00
|
|
|
/* Contains a collection of Huffman trees with the same alphabet size. */
|
2018-05-31 19:49:40 +03:00
|
|
|
/* max_symbol is needed due to simple codes since log2(alphabet_size) could be
|
|
|
|
greater than log2(max_symbol). */
|
2015-09-19 01:40:05 +03:00
|
|
|
typedef struct {
|
|
|
|
HuffmanCode** htrees;
|
|
|
|
HuffmanCode* codes;
|
2016-02-08 14:01:21 +03:00
|
|
|
uint16_t alphabet_size;
|
2018-05-31 19:49:40 +03:00
|
|
|
uint16_t max_symbol;
|
2016-02-08 14:01:21 +03:00
|
|
|
uint16_t num_htrees;
|
2015-09-19 01:40:05 +03:00
|
|
|
} HuffmanTreeGroup;
|
|
|
|
|
2014-10-04 13:02:21 +04:00
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
2016-06-18 13:06:00 +03:00
|
|
|
} /* extern "C" */
|
2014-10-04 13:02:21 +04:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif /* BROTLI_DEC_HUFFMAN_H_ */
|