tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

enc_aux_out.h (2543B)


      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 #ifndef LIB_JXL_AUX_OUT_H_
      7 #define LIB_JXL_AUX_OUT_H_
      8 
      9 // Optional output information for debugging and analyzing size usage.
     10 
     11 #include <array>
     12 #include <cstddef>
     13 #include <cstdint>
     14 
     15 namespace jxl {
     16 
     17 struct ColorEncoding;
     18 
     19 // For LayerName and AuxOut::layers[] index. Order does not matter.
     20 enum class LayerType : uint8_t {
     21  Header = 0,
     22  Toc,
     23  Dictionary,
     24  Splines,
     25  Noise,
     26  Quant,
     27  ModularTree,
     28  ModularGlobal,
     29  Dc,
     30  ModularDcGroup,
     31  ControlFields,
     32  Order,
     33  Ac,
     34  AcTokens,
     35  ModularAcGroup,
     36 };
     37 
     38 constexpr uint8_t kNumImageLayers =
     39    static_cast<uint8_t>(LayerType::ModularAcGroup) + 1;
     40 
     41 const char* LayerName(LayerType layer);
     42 
     43 // Statistics gathered during compression or decompression.
     44 struct AuxOut {
     45 private:
     46  struct LayerTotals {
     47    void Assimilate(const LayerTotals& victim) {
     48      num_clustered_histograms += victim.num_clustered_histograms;
     49      histogram_bits += victim.histogram_bits;
     50      extra_bits += victim.extra_bits;
     51      total_bits += victim.total_bits;
     52      clustered_entropy += victim.clustered_entropy;
     53    }
     54    void Print(size_t num_inputs) const;
     55 
     56    size_t num_clustered_histograms = 0;
     57    size_t extra_bits = 0;
     58 
     59    // Set via BitsWritten below
     60    size_t histogram_bits = 0;
     61    size_t total_bits = 0;
     62 
     63    double clustered_entropy = 0.0;
     64  };
     65 
     66 public:
     67  AuxOut() = default;
     68  AuxOut(const AuxOut&) = default;
     69 
     70  void Assimilate(const AuxOut& victim);
     71 
     72  void Print(size_t num_inputs) const;
     73 
     74  size_t TotalBits() const {
     75    size_t total = 0;
     76    for (const auto& layer : layers) {
     77      total += layer.total_bits;
     78    }
     79    return total;
     80  }
     81 
     82  std::array<LayerTotals, kNumImageLayers> layers;
     83 
     84  const LayerTotals& layer(LayerType idx) const {
     85    return layers[static_cast<uint8_t>(idx)];
     86  }
     87  LayerTotals& layer(LayerType idx) {
     88    return layers[static_cast<uint8_t>(idx)];
     89  }
     90 
     91  size_t num_blocks = 0;
     92 
     93  // Number of blocks that use larger DCT (set by ac_strategy).
     94  size_t num_small_blocks = 0;
     95  size_t num_dct4x8_blocks = 0;
     96  size_t num_afv_blocks = 0;
     97  size_t num_dct8_blocks = 0;
     98  size_t num_dct8x16_blocks = 0;
     99  size_t num_dct8x32_blocks = 0;
    100  size_t num_dct16_blocks = 0;
    101  size_t num_dct16x32_blocks = 0;
    102  size_t num_dct32_blocks = 0;
    103  size_t num_dct32x64_blocks = 0;
    104  size_t num_dct64_blocks = 0;
    105 
    106  int num_butteraugli_iters = 0;
    107 };
    108 }  // namespace jxl
    109 
    110 #endif  // LIB_JXL_AUX_OUT_H_