1 // Copyright 2011 Google Inc. All Rights Reserved.
3 // Use of this source code is governed by a BSD-style license
4 // that can be found in the COPYING file in the root of the source
5 // tree. An additional intellectual property rights grant can be found
6 // in the file PATENTS. All contributing project authors may
7 // be found in the AUTHORS file in the root of the source tree.
8 // -----------------------------------------------------------------------------
10 // Author: Jyrki Alakuijala (jyrki@google.com)
12 // Entropy encoding (Huffman) for webp lossless
14 #ifndef WEBP_UTILS_HUFFMAN_ENCODE_H_
15 #define WEBP_UTILS_HUFFMAN_ENCODE_H_
17 #include "../webp/types.h"
23 // Struct for holding the tree header in coded form.
25 uint8_t code
; // value (0..15) or escape code (16,17,18)
26 uint8_t extra_bits
; // extra bits for escape codes
29 // Struct to represent the tree codes (depth and bits array).
31 int num_symbols
; // Number of symbols.
32 uint8_t* code_lengths
; // Code lengths of the symbols.
33 uint16_t* codes
; // Symbol Codes.
36 // Struct to represent the Huffman tree.
37 // TODO(vikasa): Add comment for the fields of the Struct.
39 uint32_t total_count_
;
41 int pool_index_left_
; // Index for the left sub-tree.
42 int pool_index_right_
; // Index for the right sub-tree.
45 // Turn the Huffman tree into a token sequence.
46 // Returns the number of tokens used.
47 int VP8LCreateCompressedHuffmanTree(const HuffmanTreeCode
* const tree
,
48 HuffmanTreeToken
* tokens
, int max_tokens
);
50 // Create an optimized tree, and tokenize it.
51 // 'buf_rle' and 'huff_tree' are pre-allocated and the 'tree' is the constructed
53 void VP8LCreateHuffmanTree(uint32_t* const histogram
, int tree_depth_limit
,
54 uint8_t* const buf_rle
, HuffmanTree
* const huff_tree
,
55 HuffmanTreeCode
* const tree
);
61 #endif // WEBP_UTILS_HUFFMAN_ENCODE_H_