/src/ghostpdl/brotli/c/enc/bit_cost.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* Copyright 2013 Google Inc. All Rights Reserved. |
2 | | |
3 | | Distributed under MIT license. |
4 | | See file LICENSE for detail or copy at https://opensource.org/licenses/MIT |
5 | | */ |
6 | | |
7 | | /* Functions to estimate the bit cost of Huffman trees. */ |
8 | | |
9 | | #ifndef BROTLI_ENC_BIT_COST_H_ |
10 | | #define BROTLI_ENC_BIT_COST_H_ |
11 | | |
12 | | #include <brotli/types.h> |
13 | | |
14 | | #include "../common/platform.h" |
15 | | #include "fast_log.h" |
16 | | #include "histogram.h" |
17 | | |
18 | | #if defined(__cplusplus) || defined(c_plusplus) |
19 | | extern "C" { |
20 | | #endif |
21 | | |
22 | | static BROTLI_INLINE double ShannonEntropy( |
23 | 0 | const uint32_t* population, size_t size, size_t* total) { |
24 | 0 | size_t sum = 0; |
25 | 0 | double retval = 0; |
26 | 0 | const uint32_t* population_end = population + size; |
27 | 0 | size_t p; |
28 | 0 | if (size & 1) { |
29 | 0 | goto odd_number_of_elements_left; |
30 | 0 | } |
31 | 0 | while (population < population_end) { |
32 | 0 | p = *population++; |
33 | 0 | sum += p; |
34 | 0 | retval -= (double)p * FastLog2(p); |
35 | 0 | odd_number_of_elements_left: |
36 | 0 | p = *population++; |
37 | 0 | sum += p; |
38 | 0 | retval -= (double)p * FastLog2(p); |
39 | 0 | } |
40 | 0 | if (sum) retval += (double)sum * FastLog2(sum); |
41 | 0 | *total = sum; |
42 | 0 | return retval; |
43 | 0 | } Unexecuted instantiation: encode.c:ShannonEntropy Unexecuted instantiation: metablock.c:ShannonEntropy Unexecuted instantiation: bit_cost.c:ShannonEntropy Unexecuted instantiation: block_splitter.c:ShannonEntropy Unexecuted instantiation: cluster.c:ShannonEntropy Unexecuted instantiation: compress_fragment_two_pass.c:ShannonEntropy |
44 | | |
45 | | static BROTLI_INLINE double BitsEntropy( |
46 | 0 | const uint32_t* population, size_t size) { |
47 | 0 | size_t sum; |
48 | 0 | double retval = ShannonEntropy(population, size, &sum); |
49 | 0 | if (retval < (double)sum) { |
50 | | /* At least one bit per literal is needed. */ |
51 | 0 | retval = (double)sum; |
52 | 0 | } |
53 | 0 | return retval; |
54 | 0 | } Unexecuted instantiation: encode.c:BitsEntropy Unexecuted instantiation: metablock.c:BitsEntropy Unexecuted instantiation: bit_cost.c:BitsEntropy Unexecuted instantiation: block_splitter.c:BitsEntropy Unexecuted instantiation: cluster.c:BitsEntropy Unexecuted instantiation: compress_fragment_two_pass.c:BitsEntropy |
55 | | |
56 | | BROTLI_INTERNAL double BrotliPopulationCostLiteral(const HistogramLiteral*); |
57 | | BROTLI_INTERNAL double BrotliPopulationCostCommand(const HistogramCommand*); |
58 | | BROTLI_INTERNAL double BrotliPopulationCostDistance(const HistogramDistance*); |
59 | | |
60 | | #if defined(__cplusplus) || defined(c_plusplus) |
61 | | } /* extern "C" */ |
62 | | #endif |
63 | | |
64 | | #endif /* BROTLI_ENC_BIT_COST_H_ */ |