enc_aux_out.h (2361B)
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 <stddef.h> 12 13 #include <array> 14 #include <functional> 15 #include <string> 16 17 namespace jxl { 18 19 struct ColorEncoding; 20 21 // For LayerName and AuxOut::layers[] index. Order does not matter. 22 enum { 23 kLayerHeader = 0, 24 kLayerTOC, 25 kLayerDictionary, 26 kLayerSplines, 27 kLayerNoise, 28 kLayerQuant, 29 kLayerModularTree, 30 kLayerModularGlobal, 31 kLayerDC, 32 kLayerModularDcGroup, 33 kLayerControlFields, 34 kLayerOrder, 35 kLayerAC, 36 kLayerACTokens, 37 kLayerModularAcGroup, 38 kNumImageLayers 39 }; 40 41 const char* LayerName(size_t 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 size_t num_blocks = 0; 84 85 // Number of blocks that use larger DCT (set by ac_strategy). 86 size_t num_small_blocks = 0; 87 size_t num_dct4x8_blocks = 0; 88 size_t num_afv_blocks = 0; 89 size_t num_dct8_blocks = 0; 90 size_t num_dct8x16_blocks = 0; 91 size_t num_dct8x32_blocks = 0; 92 size_t num_dct16_blocks = 0; 93 size_t num_dct16x32_blocks = 0; 94 size_t num_dct32_blocks = 0; 95 size_t num_dct32x64_blocks = 0; 96 size_t num_dct64_blocks = 0; 97 98 int num_butteraugli_iters = 0; 99 }; 100 } // namespace jxl 101 102 #endif // LIB_JXL_AUX_OUT_H_