tor-browser

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

splines_gbench.cc (2364B)


      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 <cstddef>
      7 #include <vector>
      8 
      9 #include "benchmark/benchmark.h"
     10 #include "lib/jxl/base/rect.h"
     11 #include "lib/jxl/base/status.h"
     12 #include "lib/jxl/chroma_from_luma.h"
     13 #include "lib/jxl/image_ops.h"
     14 #include "lib/jxl/splines.h"
     15 #include "tools/no_memory_manager.h"
     16 
     17 namespace jxl {
     18 namespace {
     19 
     20 #define QUIT(M)           \
     21  state.SkipWithError(M); \
     22  return;
     23 
     24 #define BM_CHECK(C) \
     25  if (!(C)) {       \
     26    QUIT(#C)        \
     27  }
     28 
     29 constexpr int kQuantizationAdjustment = 0;
     30 const ColorCorrelation color_correlation{};
     31 const float kYToX = color_correlation.YtoXRatio(0);
     32 const float kYToB = color_correlation.YtoBRatio(0);
     33 
     34 void BM_Splines(benchmark::State& state) {
     35  const size_t n = state.range();
     36 
     37  Spline spline1{
     38      /*control_points=*/{
     39          {9, 54}, {118, 159}, {97, 3}, {10, 40}, {150, 25}, {120, 300}},
     40      /*color_dct=*/
     41      {Dct32{0.03125f, 0.00625f, 0.003125f}, Dct32{1.f, 0.321875f},
     42       Dct32{1.f, 0.24375f}},
     43      /*sigma_dct=*/{0.3125f, 0.f, 0.f, 0.0625f}};
     44  std::vector<Spline> spline_data = {spline1};
     45  std::vector<QuantizedSpline> quantized_splines;
     46  std::vector<Spline::Point> starting_points;
     47  for (const Spline& spline : spline_data) {
     48    JXL_ASSIGN_OR_QUIT(
     49        QuantizedSpline qspline,
     50        QuantizedSpline::Create(spline, kQuantizationAdjustment, kYToX, kYToB),
     51        "Failed to create spline.");
     52    quantized_splines.emplace_back(std::move(qspline));
     53    starting_points.push_back(spline.control_points.front());
     54  }
     55  Splines splines(kQuantizationAdjustment, std::move(quantized_splines),
     56                  std::move(starting_points));
     57 
     58  JXL_ASSIGN_OR_QUIT(
     59      Image3F drawing_area,
     60      Image3F::Create(jpegxl::tools::NoMemoryManager(), 320, 320),
     61      "Failed to allocate drawing plane.");
     62  ZeroFillImage(&drawing_area);
     63  for (auto _ : state) {
     64    (void)_;
     65    for (size_t i = 0; i < n; ++i) {
     66      BM_CHECK(splines.InitializeDrawCache(
     67          drawing_area.xsize(), drawing_area.ysize(), color_correlation));
     68      splines.AddTo(&drawing_area, Rect(drawing_area));
     69    }
     70  }
     71 
     72  state.SetItemsProcessed(n * state.iterations());
     73 }
     74 
     75 BENCHMARK(BM_Splines)->Range(1, 1 << 10);
     76 
     77 }  // namespace
     78 }  // namespace jxl