From 5ff2a824ccc3977e9547100454bb4d71d29df885 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Mon, 8 Jan 2024 20:25:43 -0500 Subject: [PATCH] LibGfx/ICC: Move MatrixMatrixConversion::map() inline According to ministat, a bit faster to render page 3 of 0000849.pdf: ``` N Min Max Median Avg Stddev x 50 1.000875 1.0427601 1.0208509 1.0201902 0.01066116 + 50 0.99707389 1.03614 1.0084391 1.0107864 0.010002724 Difference at 95.0% confidence -0.00940384 +/- 0.0041018 -0.921773% +/- 0.402062% (Student's t, pooled s = 0.0103372) ``` --- Userland/Libraries/LibGfx/ICC/Profile.cpp | 35 ----------------------- Userland/Libraries/LibGfx/ICC/Profile.h | 35 +++++++++++++++++++++++ 2 files changed, 35 insertions(+), 35 deletions(-) diff --git a/Userland/Libraries/LibGfx/ICC/Profile.cpp b/Userland/Libraries/LibGfx/ICC/Profile.cpp index 04902a12552..c38716d844c 100644 --- a/Userland/Libraries/LibGfx/ICC/Profile.cpp +++ b/Userland/Libraries/LibGfx/ICC/Profile.cpp @@ -1588,41 +1588,6 @@ MatrixMatrixConversion::MatrixMatrixConversion(LutCurveType source_red_TRC, { } -Color MatrixMatrixConversion::map(FloatVector3 in_rgb) const -{ - auto evaluate_curve = [](TagData const& trc, float f) { - VERIFY(trc.type() == CurveTagData::Type || trc.type() == ParametricCurveTagData::Type); - if (trc.type() == CurveTagData::Type) - return static_cast(trc).evaluate(f); - return static_cast(trc).evaluate(f); - }; - - auto evaluate_curve_inverse = [](TagData const& trc, float f) { - VERIFY(trc.type() == CurveTagData::Type || trc.type() == ParametricCurveTagData::Type); - if (trc.type() == CurveTagData::Type) - return static_cast(trc).evaluate_inverse(f); - return static_cast(trc).evaluate_inverse(f); - }; - - FloatVector3 linear_rgb = { - evaluate_curve(m_source_red_TRC, in_rgb[0]), - evaluate_curve(m_source_green_TRC, in_rgb[1]), - evaluate_curve(m_source_blue_TRC, in_rgb[2]), - }; - linear_rgb = m_matrix * linear_rgb; - - linear_rgb.clamp(0.f, 1.f); - float device_r = evaluate_curve_inverse(m_destination_red_TRC, linear_rgb[0]); - float device_g = evaluate_curve_inverse(m_destination_green_TRC, linear_rgb[1]); - float device_b = evaluate_curve_inverse(m_destination_blue_TRC, linear_rgb[2]); - - u8 out_r = round(255 * device_r); - u8 out_g = round(255 * device_g); - u8 out_b = round(255 * device_b); - - return Color(out_r, out_g, out_b); -} - Optional Profile::matrix_matrix_conversion(Profile const& source_profile) const { auto has_normal_device_class = [](DeviceClass device) { diff --git a/Userland/Libraries/LibGfx/ICC/Profile.h b/Userland/Libraries/LibGfx/ICC/Profile.h index 66e35a74695..52321df3d79 100644 --- a/Userland/Libraries/LibGfx/ICC/Profile.h +++ b/Userland/Libraries/LibGfx/ICC/Profile.h @@ -172,6 +172,41 @@ private: LutCurveType m_destination_blue_TRC; }; +inline Color MatrixMatrixConversion::map(FloatVector3 in_rgb) const +{ + auto evaluate_curve = [](TagData const& trc, float f) { + VERIFY(trc.type() == CurveTagData::Type || trc.type() == ParametricCurveTagData::Type); + if (trc.type() == CurveTagData::Type) + return static_cast(trc).evaluate(f); + return static_cast(trc).evaluate(f); + }; + + auto evaluate_curve_inverse = [](TagData const& trc, float f) { + VERIFY(trc.type() == CurveTagData::Type || trc.type() == ParametricCurveTagData::Type); + if (trc.type() == CurveTagData::Type) + return static_cast(trc).evaluate_inverse(f); + return static_cast(trc).evaluate_inverse(f); + }; + + FloatVector3 linear_rgb = { + evaluate_curve(m_source_red_TRC, in_rgb[0]), + evaluate_curve(m_source_green_TRC, in_rgb[1]), + evaluate_curve(m_source_blue_TRC, in_rgb[2]), + }; + linear_rgb = m_matrix * linear_rgb; + + linear_rgb.clamp(0.f, 1.f); + float device_r = evaluate_curve_inverse(m_destination_red_TRC, linear_rgb[0]); + float device_g = evaluate_curve_inverse(m_destination_green_TRC, linear_rgb[1]); + float device_b = evaluate_curve_inverse(m_destination_blue_TRC, linear_rgb[2]); + + u8 out_r = round(255 * device_r); + u8 out_g = round(255 * device_g); + u8 out_b = round(255 * device_b); + + return Color(out_r, out_g, out_b); +} + class Profile : public RefCounted { public: static ErrorOr> try_load_from_externally_owned_memory(ReadonlyBytes);