libjxl

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

splines_gbench.cc (1829B)


      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 "benchmark/benchmark.h"
      7 #include "lib/jxl/image_ops.h"
      8 #include "lib/jxl/splines.h"
      9 
     10 namespace jxl {
     11 namespace {
     12 
     13 constexpr int kQuantizationAdjustment = 0;
     14 const ColorCorrelationMap* const cmap = new ColorCorrelationMap;
     15 const float kYToX = cmap->YtoXRatio(0);
     16 const float kYToB = cmap->YtoBRatio(0);
     17 
     18 void BM_Splines(benchmark::State& state) {
     19   const size_t n = state.range();
     20 
     21   std::vector<Spline> spline_data = {
     22       {/*control_points=*/{
     23            {9, 54}, {118, 159}, {97, 3}, {10, 40}, {150, 25}, {120, 300}},
     24        /*color_dct=*/
     25        {{0.03125f, 0.00625f, 0.003125f}, {1.f, 0.321875f}, {1.f, 0.24375f}},
     26        /*sigma_dct=*/{0.3125f, 0.f, 0.f, 0.0625f}}};
     27   std::vector<QuantizedSpline> quantized_splines;
     28   std::vector<Spline::Point> starting_points;
     29   for (const Spline& spline : spline_data) {
     30     quantized_splines.emplace_back(spline, kQuantizationAdjustment, kYToX,
     31                                    kYToB);
     32     starting_points.push_back(spline.control_points.front());
     33   }
     34   Splines splines(kQuantizationAdjustment, std::move(quantized_splines),
     35                   std::move(starting_points));
     36 
     37   JXL_ASSIGN_OR_DIE(Image3F drawing_area, Image3F::Create(320, 320));
     38   ZeroFillImage(&drawing_area);
     39   for (auto _ : state) {
     40     for (size_t i = 0; i < n; ++i) {
     41       JXL_CHECK(splines.InitializeDrawCache(drawing_area.xsize(),
     42                                             drawing_area.ysize(), *cmap));
     43       splines.AddTo(&drawing_area, Rect(drawing_area), Rect(drawing_area));
     44     }
     45   }
     46 
     47   state.SetItemsProcessed(n * state.iterations());
     48 }
     49 
     50 BENCHMARK(BM_Splines)->Range(1, 1 << 10);
     51 
     52 }  // namespace
     53 }  // namespace jxl