libjxl

FORK: libjxl patches used on blog
git clone https://git.neptards.moe/blog/libjxl.git
Log | Files | Refs | Submodules | README | LICENSE

enc_aux_out.cc (3606B)


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