1 // Copyright (c) the JPEG XL Project Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style
4 // license that can be found in the LICENSE file.
6 #ifndef LIB_JPEGLI_HUFFMAN_H_
7 #define LIB_JPEGLI_HUFFMAN_H_
12 #include "lib/jpegli/common_internal.h"
16 constexpr int kJpegHuffmanRootTableBits = 8;
17 // Maximum huffman lookup table size.
18 // According to zlib/examples/enough.c, 758 entries are always enough for
19 // an alphabet of 257 symbols (256 + 1 special symbol for the all 1s code) and
20 // max bit length 16 if the root table has 8 bits.
21 constexpr int kJpegHuffmanLutSize = 758;
23 struct HuffmanTableEntry {
24 uint8_t bits; // number of bits used for this symbol
25 uint16_t value; // symbol value or table offset
28 void BuildJpegHuffmanTable(const uint32_t* count, const uint32_t* symbols,
29 HuffmanTableEntry* lut);
31 // This function will create a Huffman tree.
33 // The (data,length) contains the population counts.
34 // The tree_limit is the maximum bit depth of the Huffman codes.
36 // The depth contains the tree, i.e., how many bits are used for
39 // See http://en.wikipedia.org/wiki/Huffman_coding
40 void CreateHuffmanTree(const uint32_t* data, size_t length, int tree_limit,
43 void ValidateHuffmanTable(j_common_ptr cinfo, const JHUFF_TBL* table,
46 void AddStandardHuffmanTables(j_common_ptr cinfo, bool is_dc);
50 #endif // LIB_JPEGLI_HUFFMAN_H_