Coverage Report

Created: 2026-01-09 07:02

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/guetzli/guetzli/entropy_encode.h
Line
Count
Source
1
/*
2
 * Copyright 2016 Google Inc.
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
17
// Entropy encoding (Huffman) utilities.
18
19
#ifndef GUETZLI_ENTROPY_ENCODE_H_
20
#define GUETZLI_ENTROPY_ENCODE_H_
21
22
#include <stddef.h>
23
#include <stdint.h>
24
25
namespace guetzli {
26
27
// A node of a Huffman tree.
28
struct HuffmanTree {
29
1.17G
  HuffmanTree() {}
30
  HuffmanTree(uint32_t count, int16_t left, int16_t right)
31
29.5M
      : total_count_(count),
32
29.5M
        index_left_(left),
33
29.5M
        index_right_or_value_(right) {
34
29.5M
  }
35
  uint32_t total_count_;
36
  int16_t index_left_;
37
  int16_t index_right_or_value_;
38
};
39
40
bool SetDepth(int p, HuffmanTree *pool, uint8_t *depth, int max_depth);
41
42
// This function will create a Huffman tree.
43
//
44
// The (data,length) contains the population counts.
45
// The tree_limit is the maximum bit depth of the Huffman codes.
46
//
47
// The depth contains the tree, i.e., how many bits are used for
48
// the symbol.
49
//
50
// The actual Huffman tree is constructed in the tree[] array, which has to
51
// be at least 2 * length + 1 long.
52
//
53
// See http://en.wikipedia.org/wiki/Huffman_coding
54
void CreateHuffmanTree(const uint32_t *data,
55
                       const size_t length,
56
                       const int tree_limit,
57
                       HuffmanTree* tree,
58
                       uint8_t *depth);
59
60
}  // namespace guetzli
61
62
#endif  // GUETZLI_ENTROPY_ENCODE_H_