/src/libjxl/lib/jxl/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/aux_out.h" |
7 | | |
8 | | #include <stdint.h> |
9 | | |
10 | | #include <numeric> // accumulate |
11 | | |
12 | | #include "lib/jxl/aux_out_fwd.h" |
13 | | #include "lib/jxl/base/printf_macros.h" |
14 | | #include "lib/jxl/enc_bit_writer.h" |
15 | | |
16 | | namespace jxl { |
17 | | |
18 | 0 | void AuxOut::Print(size_t num_inputs) const { |
19 | 0 | if (num_inputs == 0) return; |
20 | | |
21 | 0 | LayerTotals all_layers; |
22 | 0 | for (size_t i = 0; i < layers.size(); ++i) { |
23 | 0 | all_layers.Assimilate(layers[i]); |
24 | 0 | } |
25 | |
|
26 | 0 | printf("Average butteraugli iters: %10.2f\n", |
27 | 0 | num_butteraugli_iters * 1.0 / num_inputs); |
28 | 0 | if (min_quant_rescale != 1.0 || max_quant_rescale != 1.0) { |
29 | 0 | printf("quant rescale range: %f .. %f\n", min_quant_rescale, |
30 | 0 | max_quant_rescale); |
31 | 0 | printf("bitrate error range: %.3f%% .. %.3f%%\n", |
32 | 0 | 100.0f * min_bitrate_error, 100.0f * max_bitrate_error); |
33 | 0 | } |
34 | |
|
35 | 0 | for (size_t i = 0; i < layers.size(); ++i) { |
36 | 0 | if (layers[i].total_bits != 0) { |
37 | 0 | printf("Total layer bits %-10s\t", LayerName(i)); |
38 | 0 | printf("%10f%%", 100.0 * layers[i].total_bits / all_layers.total_bits); |
39 | 0 | layers[i].Print(num_inputs); |
40 | 0 | } |
41 | 0 | } |
42 | 0 | printf("Total image size "); |
43 | 0 | all_layers.Print(num_inputs); |
44 | |
|
45 | 0 | const uint32_t dc_pred_total = |
46 | 0 | std::accumulate(dc_pred_usage.begin(), dc_pred_usage.end(), 0u); |
47 | 0 | const uint32_t dc_pred_total_xb = |
48 | 0 | std::accumulate(dc_pred_usage_xb.begin(), dc_pred_usage_xb.end(), 0u); |
49 | 0 | if (dc_pred_total + dc_pred_total_xb != 0) { |
50 | 0 | printf("\nDC pred Y XB:\n"); |
51 | 0 | for (size_t i = 0; i < dc_pred_usage.size(); ++i) { |
52 | 0 | printf(" %6u (%5.2f%%) %6u (%5.2f%%)\n", dc_pred_usage[i], |
53 | 0 | 100.0 * dc_pred_usage[i] / dc_pred_total, dc_pred_usage_xb[i], |
54 | 0 | 100.0 * dc_pred_usage_xb[i] / dc_pred_total_xb); |
55 | 0 | } |
56 | 0 | } |
57 | |
|
58 | 0 | size_t total_blocks = 0; |
59 | 0 | size_t total_positions = 0; |
60 | 0 | if (total_blocks != 0 && total_positions != 0) { |
61 | 0 | printf("\n\t\t Blocks\t\tPositions\t\t\tBlocks/Position\n"); |
62 | 0 | printf(" Total:\t\t %7" PRIuS "\t\t %7" PRIuS " \t\t\t%10f%%\n\n", |
63 | 0 | total_blocks, total_positions, |
64 | 0 | 100.0 * total_blocks / total_positions); |
65 | 0 | } |
66 | 0 | } |
67 | | |
68 | | void ReclaimAndCharge(BitWriter* JXL_RESTRICT writer, |
69 | | BitWriter::Allotment* JXL_RESTRICT allotment, |
70 | 3.68k | size_t layer, AuxOut* JXL_RESTRICT aux_out) { |
71 | 3.68k | size_t used_bits, unused_bits; |
72 | 3.68k | allotment->PrivateReclaim(writer, &used_bits, &unused_bits); |
73 | | |
74 | | #if 0 |
75 | | printf("Layer %s bits: max %" PRIuS " used %" PRIuS " unused %" PRIuS "\n", LayerName(layer), |
76 | | allotment->MaxBits(), used_bits, unused_bits); |
77 | | #endif |
78 | | |
79 | | // This may be a nested call with aux_out == null. Whenever we know that |
80 | | // aux_out is null, we can call ReclaimUnused directly. |
81 | 3.68k | if (aux_out != nullptr) { |
82 | 0 | aux_out->layers[layer].total_bits += used_bits; |
83 | 0 | aux_out->layers[layer].histogram_bits += allotment->HistogramBits(); |
84 | 0 | } |
85 | 3.68k | } |
86 | | |
87 | | } // namespace jxl |