Coverage Report

Created: 2025-06-22 08:04

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