• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2011 Google Inc. All Rights Reserved.
2 //
3 // This code is licensed under the same terms as WebM:
4 //  Software License Agreement:  http://www.webmproject.org/license/software/
5 //  Additional IP Rights Grant:  http://www.webmproject.org/license/additional/
6 // -----------------------------------------------------------------------------
7 //
8 // Author: Jyrki Alakuijala (jyrki@google.com)
9 //
10 // Entropy encoding (Huffman) for webp lossless
11 
12 #ifndef WEBP_UTILS_HUFFMAN_ENCODE_H_
13 #define WEBP_UTILS_HUFFMAN_ENCODE_H_
14 
15 #include "webp/types.h"
16 
17 #if defined(__cplusplus) || defined(c_plusplus)
18 extern "C" {
19 #endif
20 
21 // Struct for holding the tree header in coded form.
22 typedef struct {
23   uint8_t code;         // value (0..15) or escape code (16,17,18)
24   uint8_t extra_bits;   // extra bits for escape codes
25 } HuffmanTreeToken;
26 
27 // Struct to represent the tree codes (depth and bits array).
28 typedef struct {
29   int       num_symbols;   // Number of symbols.
30   uint8_t*  code_lengths;  // Code lengths of the symbols.
31   uint16_t* codes;         // Symbol Codes.
32 } HuffmanTreeCode;
33 
34 // Turn the Huffman tree into a token sequence.
35 // Returns the number of tokens used.
36 int VP8LCreateCompressedHuffmanTree(const HuffmanTreeCode* const tree,
37                                     HuffmanTreeToken* tokens, int max_tokens);
38 
39 // Create an optimized tree, and tokenize it.
40 int VP8LCreateHuffmanTree(int* const histogram, int tree_depth_limit,
41                           HuffmanTreeCode* const tree);
42 
43 #if defined(__cplusplus) || defined(c_plusplus)
44 }
45 #endif
46 
47 #endif  // WEBP_UTILS_HUFFMAN_ENCODE_H_
48