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