tone_mapping_gbench.cc (1495B)
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/extras/codec.h" 8 #include "lib/extras/tone_mapping.h" 9 #include "lib/jxl/image.h" 10 11 namespace jxl { 12 13 static void BM_ToneMapping(benchmark::State& state) { 14 JXL_ASSIGN_OR_DIE(Image3F color, Image3F::Create(2268, 1512)); 15 FillImage(0.5f, &color); 16 17 // Use linear Rec. 2020 so that `ToneMapTo` doesn't have to convert to it and 18 // we mainly measure the tone mapping itself. 19 ColorEncoding linear_rec2020; 20 linear_rec2020.SetColorSpace(ColorSpace::kRGB); 21 JXL_CHECK(linear_rec2020.SetPrimariesType(Primaries::k2100)); 22 JXL_CHECK(linear_rec2020.SetWhitePointType(WhitePoint::kD65)); 23 linear_rec2020.Tf().SetTransferFunction(TransferFunction::kLinear); 24 JXL_CHECK(linear_rec2020.CreateICC()); 25 26 for (auto _ : state) { 27 state.PauseTiming(); 28 CodecInOut tone_mapping_input; 29 JXL_ASSIGN_OR_DIE(Image3F color2, 30 Image3F::Create(color.xsize(), color.ysize())); 31 CopyImageTo(color, &color2); 32 tone_mapping_input.SetFromImage(std::move(color2), linear_rec2020); 33 tone_mapping_input.metadata.m.SetIntensityTarget(255); 34 state.ResumeTiming(); 35 36 JXL_CHECK(ToneMapTo({0.1, 100}, &tone_mapping_input)); 37 } 38 39 state.SetItemsProcessed(state.iterations() * color.xsize() * color.ysize()); 40 } 41 BENCHMARK(BM_ToneMapping); 42 43 } // namespace jxl