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_
|
|
|
|
|
|
|
|
#include "./types.h"
|
|
|
|
|
|
|
|
#if defined(__cplusplus) || defined(c_plusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2015-08-28 13:20:24 +00:00
|
|
|
#define BROTLI_HUFFMAN_MAX_CODE_LENGTH 15
|
|
|
|
|
|
|
|
/* For current format this constant equals to kNumInsertAndCopyCodes */
|
|
|
|
#define BROTLI_HUFFMAN_MAX_CODE_LENGTHS_SIZE 704
|
|
|
|
|
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};
|
|
|
|
#define BROTLI_HUFFMAN_MAX_SIZE_26 396
|
|
|
|
#define BROTLI_HUFFMAN_MAX_SIZE_258 632
|
|
|
|
#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. */
|
|
|
|
void BrotliBuildCodeLengthsHuffmanTable(HuffmanCode* root_table,
|
|
|
|
const uint8_t* const code_lengths,
|
2016-02-18 14:03:44 +00:00
|
|
|
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. */
|
2015-10-05 08:23:32 +00:00
|
|
|
uint32_t BrotliBuildHuffmanTable(HuffmanCode* root_table,
|
|
|
|
int root_bits,
|
|
|
|
const uint16_t* const symbol_lists,
|
2016-02-18 14:03:44 +00:00
|
|
|
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. */
|
2015-10-05 08:23:32 +00:00
|
|
|
uint32_t BrotliBuildSimpleHuffmanTable(HuffmanCode* table,
|
|
|
|
int root_bits,
|
2016-02-18 14:03:44 +00:00
|
|
|
uint16_t* symbols,
|
2015-10-05 08:23:32 +00:00
|
|
|
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_ */
|