tor-browser

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

tone_mapping_gbench.cc (1957B)


      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 <jxl/memory_manager.h>
      7 
      8 #include "benchmark/benchmark.h"
      9 #include "lib/extras/tone_mapping.h"
     10 #include "lib/jxl/base/status.h"
     11 #include "lib/jxl/image.h"
     12 #include "tools/no_memory_manager.h"
     13 
     14 namespace jxl {
     15 
     16 #define QUIT(M)           \
     17  state.SkipWithError(M); \
     18  return;
     19 
     20 #define BM_CHECK(C) \
     21  if (!(C)) {       \
     22    QUIT(#C)        \
     23  }
     24 
     25 static void BM_ToneMapping(benchmark::State& state) {
     26  JxlMemoryManager* memory_manager = jpegxl::tools::NoMemoryManager();
     27  JXL_ASSIGN_OR_QUIT(Image3F color, Image3F::Create(memory_manager, 2268, 1512),
     28                     "Failed to allocate color plane");
     29  FillImage(0.5f, &color);
     30 
     31  // Use linear Rec. 2020 so that `ToneMapTo` doesn't have to convert to it and
     32  // we mainly measure the tone mapping itself.
     33  ColorEncoding linear_rec2020;
     34  linear_rec2020.SetColorSpace(ColorSpace::kRGB);
     35  BM_CHECK(linear_rec2020.SetPrimariesType(Primaries::k2100));
     36  BM_CHECK(linear_rec2020.SetWhitePointType(WhitePoint::kD65));
     37  linear_rec2020.Tf().SetTransferFunction(TransferFunction::kLinear);
     38  BM_CHECK(linear_rec2020.CreateICC());
     39 
     40  for (auto _ : state) {
     41    (void)_;
     42    state.PauseTiming();
     43    CodecInOut tone_mapping_input{memory_manager};
     44    JXL_ASSIGN_OR_QUIT(
     45        Image3F color2,
     46        Image3F::Create(memory_manager, color.xsize(), color.ysize()),
     47        "Failed to allocate color plane");
     48    BM_CHECK(CopyImageTo(color, &color2));
     49    BM_CHECK(
     50        tone_mapping_input.SetFromImage(std::move(color2), linear_rec2020));
     51    tone_mapping_input.metadata.m.SetIntensityTarget(255);
     52    state.ResumeTiming();
     53 
     54    BM_CHECK(ToneMapTo({0.1, 100}, &tone_mapping_input));
     55  }
     56 
     57  state.SetItemsProcessed(state.iterations() * color.xsize() * color.ysize());
     58 }
     59 BENCHMARK(BM_ToneMapping);
     60 
     61 }  // namespace jxl