2013-12-16 13:45:57 +00:00
|
|
|
/* Copyright 2013 Google Inc. All Rights Reserved.
|
|
|
|
|
2015-12-11 10:11:51 +00:00
|
|
|
Distributed under MIT license.
|
2015-11-27 10:27:11 +00:00
|
|
|
See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
|
2013-12-16 13:45:57 +00:00
|
|
|
*/
|
2013-10-11 08:26:07 +00:00
|
|
|
|
2015-03-20 14:44:15 +00:00
|
|
|
/* Utilities for building Huffman decoding tables. */
|
|
|
|
|
2013-10-11 08:26:07 +00:00
|
|
|
#ifndef BROTLI_DEC_HUFFMAN_H_
|
|
|
|
#define BROTLI_DEC_HUFFMAN_H_
|
|
|
|
|
2016-06-03 08:51:04 +00:00
|
|
|
#include "../common/types.h"
|
2016-04-19 14:29:10 +00:00
|
|
|
#include "./port.h"
|
2013-10-11 08:26:07 +00:00
|
|
|
|
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-08-28 13:20:24 +00:00
|
|
|
#define BROTLI_HUFFMAN_MAX_CODE_LENGTH 15
|
|
|
|
|
2016-01-22 09:19:41 +00:00
|
|
|
/* Maximum possible Huffman table size for an alphabet size of (index * 32),
|
|
|
|
* max code length 15 and root table bits 8. */
|
|
|
|
static const uint16_t kMaxHuffmanTableSize[] = {
|
|
|
|
256, 402, 436, 468, 500, 534, 566, 598, 630, 662, 694, 726, 758, 790, 822,
|
|
|
|
854, 886, 920, 952, 984, 1016, 1048, 1080};
|
2016-06-03 08:51:04 +00:00
|
|
|
/* BROTLI_NUM_BLOCK_LEN_SYMBOLS == 26 */
|
2016-01-22 09:19:41 +00:00
|
|
|
#define BROTLI_HUFFMAN_MAX_SIZE_26 396
|
2016-06-03 08:51:04 +00:00
|
|
|
/* BROTLI_MAX_BLOCK_TYPE_SYMBOLS == 258 */
|
2016-01-22 09:19:41 +00:00
|
|
|
#define BROTLI_HUFFMAN_MAX_SIZE_258 632
|
2016-06-03 08:51:04 +00:00
|
|
|
/* BROTLI_MAX_CONTEXT_MAP_SYMBOLS == 272 */
|
2016-01-22 09:19:41 +00:00
|
|
|
#define BROTLI_HUFFMAN_MAX_SIZE_272 646
|
2015-08-28 13:20:24 +00:00
|
|
|
|
|
|
|
#define BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH 5
|
2015-03-20 15:13:15 +00:00
|
|
|
|
2013-10-11 08:26:07 +00:00
|
|
|
typedef struct {
|
2016-02-18 14:03:44 +00:00
|
|
|
uint8_t bits; /* number of bits used for this symbol */
|
|
|
|
uint16_t value; /* symbol value or table offset */
|
2014-02-14 14:04:23 +00:00
|
|
|
} HuffmanCode;
|
2013-10-11 08:26:07 +00:00
|
|
|
|
2015-08-28 13:20:24 +00:00
|
|
|
/* Builds Huffman lookup table assuming code lengths are in symbol order. */
|
2016-04-19 14:29:10 +00:00
|
|
|
BROTLI_INTERNAL void BrotliBuildCodeLengthsHuffmanTable(HuffmanCode* root_table,
|
|
|
|
const uint8_t* const code_lengths, uint16_t* count);
|
2015-08-28 13:20:24 +00:00
|
|
|
|
2014-02-14 14:04:23 +00:00
|
|
|
/* Builds Huffman lookup table assuming code lengths are in symbol order. */
|
2015-08-28 13:20:24 +00:00
|
|
|
/* Returns size of resulting table. */
|
2016-04-19 14:29:10 +00:00
|
|
|
BROTLI_INTERNAL uint32_t BrotliBuildHuffmanTable(HuffmanCode* root_table,
|
|
|
|
int root_bits, const uint16_t* const symbol_lists, uint16_t* count_arg);
|
2015-08-10 11:35:23 +00:00
|
|
|
|
2015-09-24 16:35:25 +00: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-04-19 14:29:10 +00:00
|
|
|
BROTLI_INTERNAL uint32_t BrotliBuildSimpleHuffmanTable(HuffmanCode* table,
|
|
|
|
int root_bits, uint16_t* symbols, uint32_t num_symbols);
|
2013-10-11 08:26:07 +00:00
|
|
|
|
2015-09-21 19:04:07 +00:00
|
|
|
/* Contains a collection of Huffman trees with the same alphabet size. */
|
2015-03-20 15:13:15 +00:00
|
|
|
typedef struct {
|
|
|
|
HuffmanCode** htrees;
|
2015-08-10 11:35:23 +00:00
|
|
|
HuffmanCode* codes;
|
2015-10-05 08:23:32 +00:00
|
|
|
uint16_t alphabet_size;
|
|
|
|
uint16_t num_htrees;
|
2015-03-20 15:13:15 +00:00
|
|
|
} HuffmanTreeGroup;
|
|
|
|
|
2013-10-11 08:26:07 +00:00
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
2016-02-18 14:03:44 +00:00
|
|
|
} /* extern "C" */
|
2013-10-11 08:26:07 +00:00
|
|
|
#endif
|
|
|
|
|
2013-12-16 13:45:57 +00:00
|
|
|
#endif /* BROTLI_DEC_HUFFMAN_H_ */
|