From 5df35d030fce99ea0926d773630cc5d3e9c40752 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Tue, 11 Apr 2023 08:53:28 -0400 Subject: [PATCH] LibGfx/ICC: Extract sRGB_curve() function This returns just the tone reproduction curve of the sRGB profile. --- Userland/Libraries/LibGfx/ICC/WellKnownProfiles.cpp | 11 ++++++++--- Userland/Libraries/LibGfx/ICC/WellKnownProfiles.h | 2 ++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/Userland/Libraries/LibGfx/ICC/WellKnownProfiles.cpp b/Userland/Libraries/LibGfx/ICC/WellKnownProfiles.cpp index 3300aac428..26d04870f0 100644 --- a/Userland/Libraries/LibGfx/ICC/WellKnownProfiles.cpp +++ b/Userland/Libraries/LibGfx/ICC/WellKnownProfiles.cpp @@ -38,6 +38,13 @@ static ErrorOr> XYZ_data(XYZ xyz) return try_make_ref_counted(0, 0, move(xyzs)); } +ErrorOr> sRGB_curve() +{ + // Numbers from https://en.wikipedia.org/wiki/SRGB#From_sRGB_to_CIE_XYZ + Array curve_parameters = { 2.4, 1 / 1.055, 0.055 / 1.055, 1 / 12.92, 0.04045 }; + return try_make_ref_counted(0, 0, ParametricCurveTagData::FunctionType::sRGB, curve_parameters); +} + ErrorOr> sRGB() { // Returns an sRGB profile. @@ -54,9 +61,7 @@ ErrorOr> sRGB() TRY(tag_table.try_set(copyrightTag, TRY(en_US("Public Domain"sv)))); // Transfer function. - // Numbers from https://en.wikipedia.org/wiki/SRGB#From_sRGB_to_CIE_XYZ - Array curve_parameters = { 2.4, 1 / 1.055, 0.055 / 1.055, 1 / 12.92, 0.04045 }; - auto curve = TRY(try_make_ref_counted(0, 0, ParametricCurveTagData::FunctionType::sRGB, curve_parameters)); + auto curve = TRY(sRGB_curve()); TRY(tag_table.try_set(redTRCTag, curve)); TRY(tag_table.try_set(greenTRCTag, curve)); TRY(tag_table.try_set(blueTRCTag, curve)); diff --git a/Userland/Libraries/LibGfx/ICC/WellKnownProfiles.h b/Userland/Libraries/LibGfx/ICC/WellKnownProfiles.h index aedbc14973..40cb7f6427 100644 --- a/Userland/Libraries/LibGfx/ICC/WellKnownProfiles.h +++ b/Userland/Libraries/LibGfx/ICC/WellKnownProfiles.h @@ -15,4 +15,6 @@ class Profile; ErrorOr> sRGB(); +ErrorOr> sRGB_curve(); + }