1 /*
2 Copyright 2011 Google Inc. All Rights Reserved.
3 
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7 
8     http://www.apache.org/licenses/LICENSE-2.0
9 
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an "AS IS" BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 
16 Author: lode.vandevenne@gmail.com (Lode Vandevenne)
17 Author: jyrki.alakuijala@gmail.com (Jyrki Alakuijala)
18 */
19 
20 /*
21 Utilities for creating and using Huffman trees.
22 */
23 
24 #ifndef ZOPFLI_TREE_H_
25 #define ZOPFLI_TREE_H_
26 
27 #include <string.h>
28 
29 /*
30 Calculates the bitlengths for the Huffman tree, based on the counts of each
31 symbol.
32 */
33 void ZopfliCalculateBitLengths(const size_t* count, size_t n, int maxbits,
34                                unsigned *bitlengths);
35 
36 /*
37 Converts a series of Huffman tree bitlengths, to the bit values of the symbols.
38 */
39 void ZopfliLengthsToSymbols(const unsigned* lengths, size_t n, unsigned maxbits,
40                             unsigned* symbols);
41 
42 /*
43 Calculates the entropy of each symbol, based on the counts of each symbol. The
44 result is similar to the result of ZopfliCalculateBitLengths, but with the
45 actual theoritical bit lengths according to the entropy. Since the resulting
46 values are fractional, they cannot be used to encode the tree specified by
47 DEFLATE.
48 */
49 void ZopfliCalculateEntropy(const size_t* count, size_t n, double* bitlengths);
50 
51 #endif  /* ZOPFLI_TREE_H_ */
52