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