Coverage Report

Created: 2025-10-10 06:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/guetzli/guetzli/jpeg_huffman_decode.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
// Utility function for building a Huffman lookup table for the jpeg decoder.
18
19
#ifndef GUETZLI_JPEG_HUFFMAN_DECODE_H_
20
#define GUETZLI_JPEG_HUFFMAN_DECODE_H_
21
22
#include <inttypes.h>
23
24
namespace guetzli {
25
26
static const int kJpegHuffmanRootTableBits = 8;
27
// Maximum huffman lookup table size.
28
// According to zlib/examples/enough.c, 758 entries are always enough for
29
// an alphabet of 257 symbols (256 + 1 special symbol for the all 1s code) and
30
// max bit length 16 if the root table has 8 bits.
31
static const int kJpegHuffmanLutSize = 758;
32
33
struct HuffmanTableEntry {
34
  // Initialize the value to an invalid symbol so that we can recognize it
35
  // when reading the bit stream using a Huffman code with space > 0.
36
56.0M
  HuffmanTableEntry() : bits(0), value(0xffff) {}
37
38
  uint8_t bits;     // number of bits used for this symbol
39
  uint16_t value;   // symbol value or table offset
40
};
41
42
// Builds jpeg-style Huffman lookup table from the given symbols.
43
// The symbols are in order of increasing bit lengths. The number of symbols
44
// with bit length n is given in counts[n] for each n >= 1.
45
// Returns the size of the lookup table.
46
int BuildJpegHuffmanTable(const int* counts, const int* symbols,
47
                          HuffmanTableEntry* lut);
48
49
}  // namespace guetzli
50
51
#endif  // GUETZLI_JPEG_HUFFMAN_DECODE_H_