/src/libjxl/lib/jxl/enc_aux_out.cc
Line | Count | Source (jump to first uncovered line) |
1 | | // Copyright (c) the JPEG XL Project Authors. All rights reserved. |
2 | | // |
3 | | // Use of this source code is governed by a BSD-style |
4 | | // license that can be found in the LICENSE file. |
5 | | |
6 | | #include "lib/jxl/enc_aux_out.h" |
7 | | |
8 | | #include <cstddef> |
9 | | #include <cstdio> |
10 | | |
11 | | #include "lib/jxl/base/printf_macros.h" |
12 | | #include "lib/jxl/base/status.h" |
13 | | |
14 | | namespace jxl { |
15 | | |
16 | 0 | const char* LayerName(LayerType layer) { |
17 | 0 | switch (layer) { |
18 | 0 | case LayerType::Header: |
19 | 0 | return "Headers"; |
20 | 0 | case LayerType::Toc: |
21 | 0 | return "TOC"; |
22 | 0 | case LayerType::Dictionary: |
23 | 0 | return "Patches"; |
24 | 0 | case LayerType::Splines: |
25 | 0 | return "Splines"; |
26 | 0 | case LayerType::Noise: |
27 | 0 | return "Noise"; |
28 | 0 | case LayerType::Quant: |
29 | 0 | return "Quantizer"; |
30 | 0 | case LayerType::ModularTree: |
31 | 0 | return "ModularTree"; |
32 | 0 | case LayerType::ModularGlobal: |
33 | 0 | return "ModularGlobal"; |
34 | 0 | case LayerType::Dc: |
35 | 0 | return "DC"; |
36 | 0 | case LayerType::ModularDcGroup: |
37 | 0 | return "ModularDcGroup"; |
38 | 0 | case LayerType::ControlFields: |
39 | 0 | return "ControlFields"; |
40 | 0 | case LayerType::Order: |
41 | 0 | return "CoeffOrder"; |
42 | 0 | case LayerType::Ac: |
43 | 0 | return "ACHistograms"; |
44 | 0 | case LayerType::AcTokens: |
45 | 0 | return "ACTokens"; |
46 | 0 | case LayerType::ModularAcGroup: |
47 | 0 | return "ModularAcGroup"; |
48 | 0 | } |
49 | 0 | JXL_DEBUG_ABORT("internal: unexpected LayerType: %d", |
50 | 0 | static_cast<int>(layer)); |
51 | 0 | return "Invalid"; |
52 | 0 | } |
53 | | |
54 | 0 | void AuxOut::LayerTotals::Print(size_t num_inputs) const { |
55 | 0 | if (JXL_DEBUG_V_LEVEL > 0) { |
56 | 0 | printf("%10" PRIuS, total_bits); |
57 | 0 | if (histogram_bits != 0) { |
58 | 0 | printf(" [c/i:%6.2f | hst:%8" PRIuS " | ex:%8" PRIuS " | h+c+e:%12.3f", |
59 | 0 | num_clustered_histograms * 1.0 / num_inputs, histogram_bits >> 3, |
60 | 0 | extra_bits >> 3, |
61 | 0 | (histogram_bits + clustered_entropy + extra_bits) / 8.0); |
62 | 0 | printf("]"); |
63 | 0 | } |
64 | 0 | printf("\n"); |
65 | 0 | } |
66 | 0 | } |
67 | | |
68 | 0 | void AuxOut::Assimilate(const AuxOut& victim) { |
69 | 0 | for (size_t i = 0; i < kNumImageLayers; ++i) { |
70 | 0 | LayerType l = static_cast<LayerType>(i); |
71 | 0 | layer(l).Assimilate(victim.layer(l)); |
72 | 0 | } |
73 | 0 | num_blocks += victim.num_blocks; |
74 | 0 | num_small_blocks += victim.num_small_blocks; |
75 | 0 | num_dct4x8_blocks += victim.num_dct4x8_blocks; |
76 | 0 | num_afv_blocks += victim.num_afv_blocks; |
77 | 0 | num_dct8_blocks += victim.num_dct8_blocks; |
78 | 0 | num_dct8x16_blocks += victim.num_dct8x16_blocks; |
79 | 0 | num_dct8x32_blocks += victim.num_dct8x32_blocks; |
80 | 0 | num_dct16_blocks += victim.num_dct16_blocks; |
81 | 0 | num_dct16x32_blocks += victim.num_dct16x32_blocks; |
82 | 0 | num_dct32_blocks += victim.num_dct32_blocks; |
83 | 0 | num_dct32x64_blocks += victim.num_dct32x64_blocks; |
84 | 0 | num_dct64_blocks += victim.num_dct64_blocks; |
85 | 0 | num_butteraugli_iters += victim.num_butteraugli_iters; |
86 | 0 | } |
87 | | |
88 | 0 | void AuxOut::Print(size_t num_inputs) const { |
89 | 0 | if (JXL_DEBUG_V_LEVEL > 0) { |
90 | 0 | if (num_inputs == 0) return; |
91 | | |
92 | 0 | LayerTotals all_layers; |
93 | 0 | for (const auto& layer : layers) { |
94 | 0 | all_layers.Assimilate(layer); |
95 | 0 | } |
96 | |
|
97 | 0 | printf("Average butteraugli iters: %10.2f\n", |
98 | 0 | num_butteraugli_iters * 1.0 / num_inputs); |
99 | |
|
100 | 0 | for (size_t i = 0; i < kNumImageLayers; ++i) { |
101 | 0 | LayerType l = static_cast<LayerType>(i); |
102 | 0 | if (layer(l).total_bits != 0) { |
103 | 0 | printf("Total layer bits %-10s\t", LayerName(l)); |
104 | 0 | printf("%10f%%", 100.0 * layer(l).total_bits / all_layers.total_bits); |
105 | 0 | layer(l).Print(num_inputs); |
106 | 0 | } |
107 | 0 | } |
108 | 0 | printf("Total image size "); |
109 | 0 | all_layers.Print(num_inputs); |
110 | |
|
111 | 0 | size_t total_blocks = 0; |
112 | 0 | size_t total_positions = 0; |
113 | 0 | if (total_blocks != 0 && total_positions != 0) { |
114 | 0 | printf("\n\t\t Blocks\t\tPositions\t\t\tBlocks/Position\n"); |
115 | 0 | printf(" Total:\t\t %7" PRIuS "\t\t %7" PRIuS " \t\t\t%10f%%\n\n", |
116 | 0 | total_blocks, total_positions, |
117 | 0 | 100.0 * total_blocks / total_positions); |
118 | 0 | } |
119 | 0 | } |
120 | 0 | } |
121 | | |
122 | | } // namespace jxl |