webkit  2cdf99a9e3038c7e01b3c37e8ad903ecbe5eecf1
https://github.com/WebKit/webkit
huffman.h
Go to the documentation of this file.
1 /* Copyright 2013 Google Inc. All Rights Reserved.
2 
3  Distributed under MIT license.
4  See file LICENSE for detail or copy at https://opensource.org/licenses/MIT
5 */
6 
7 /* Utilities for building Huffman decoding tables. */
8 
9 #ifndef BROTLI_DEC_HUFFMAN_H_
10 #define BROTLI_DEC_HUFFMAN_H_
11 
12 #include "./types.h"
13 #include "./port.h"
14 
15 #if defined(__cplusplus) || defined(c_plusplus)
16 extern "C" {
17 #endif
18 
19 #define BROTLI_HUFFMAN_MAX_CODE_LENGTH 15
20 
21 /* For current format this constant equals to kNumInsertAndCopyCodes */
22 #define BROTLI_HUFFMAN_MAX_CODE_LENGTHS_SIZE 704
23 
24 /* Maximum possible Huffman table size for an alphabet size of (index * 32),
25  * max code length 15 and root table bits 8. */
26 static const uint16_t kMaxHuffmanTableSize[] = {
27  256, 402, 436, 468, 500, 534, 566, 598, 630, 662, 694, 726, 758, 790, 822,
28  854, 886, 920, 952, 984, 1016, 1048, 1080};
29 #define BROTLI_HUFFMAN_MAX_SIZE_26 396
30 #define BROTLI_HUFFMAN_MAX_SIZE_258 632
31 #define BROTLI_HUFFMAN_MAX_SIZE_272 646
32 
33 #define BROTLI_HUFFMAN_MAX_CODE_LENGTH_CODE_LENGTH 5
34 
35 typedef struct {
36  uint8_t bits; /* number of bits used for this symbol */
37  uint16_t value; /* symbol value or table offset */
38 } HuffmanCode;
39 
40 /* Builds Huffman lookup table assuming code lengths are in symbol order. */
42  const uint8_t* const code_lengths, uint16_t* count);
43 
44 /* Builds Huffman lookup table assuming code lengths are in symbol order. */
45 /* Returns size of resulting table. */
47  int root_bits, const uint16_t* const symbol_lists, uint16_t* count_arg);
48 
49 /* Builds a simple Huffman table. The num_symbols parameter is to be */
50 /* interpreted as follows: 0 means 1 symbol, 1 means 2 symbols, 2 means 3 */
51 /* symbols, 3 means 4 symbols with lengths 2,2,2,2, 4 means 4 symbols with */
52 /* lengths 1,2,3,3. */
54  int root_bits, uint16_t* symbols, uint32_t num_symbols);
55 
56 /* Contains a collection of Huffman trees with the same alphabet size. */
57 typedef struct {
63 
64 #if defined(__cplusplus) || defined(c_plusplus)
65 } /* extern "C" */
66 #endif
67 
68 #endif /* BROTLI_DEC_HUFFMAN_H_ */
GLint GLsizei count
Definition: gl2.h:421
#define BROTLI_INTERNAL
Definition: port.h:146
BROTLI_INTERNAL uint32_t BrotliBuildHuffmanTable(HuffmanCode *root_table, int root_bits, const uint16_t *const symbol_lists, uint16_t *count_arg)
Definition: huffman.c:169
unsigned int uint32_t
Definition: ptypes.h:105
BROTLI_INTERNAL void BrotliBuildCodeLengthsHuffmanTable(HuffmanCode *root_table, const uint8_t *const code_lengths, uint16_t *count)
Definition: huffman.c:102
HuffmanCode * codes
Definition: huffman.h:59
uint16_t alphabet_size
Definition: huffman.h:60
BROTLI_INTERNAL uint32_t BrotliBuildSimpleHuffmanTable(HuffmanCode *table, int root_bits, uint16_t *symbols, uint32_t num_symbols)
Definition: huffman.c:265
uint16_t value
Definition: huffman.h:37
uint8_t bits
Definition: huffman.h:36
Definition: huffman.h:57
unsigned char uint8_t
Definition: ptypes.h:89
unsigned short uint16_t
Definition: ptypes.h:97
uint16_t num_htrees
Definition: huffman.h:61
HuffmanCode ** htrees
Definition: huffman.h:58
Definition: huffman.h:35