1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 03:57:43 +00:00

LibGfx: Add Oklab support to Gfx::Color

Interpolation of color on the web is done via the oklab colorspace
This commit is contained in:
Matthew Olsson 2024-02-11 18:07:38 -07:00 committed by Andreas Kling
parent 71a784741f
commit 70ded2ef42
2 changed files with 64 additions and 6 deletions

View file

@ -771,13 +771,13 @@ static ErrorOr<NonnullRefPtr<StyleValue>> interpolate_property(StyleValue const&
case StyleValue::Type::Color: {
auto from_color = from.as_color().color();
auto to_color = to.as_color().color();
auto from_hsv = from_color.to_hsv();
auto to_hsv = to_color.to_hsv();
auto from_oklab = from_color.to_oklab();
auto to_oklab = to_color.to_oklab();
auto color = Color::from_hsv(
interpolate_raw(from_hsv.hue, to_hsv.hue),
interpolate_raw(from_hsv.saturation, to_hsv.saturation),
interpolate_raw(from_hsv.value, to_hsv.value));
auto color = Color::from_oklab(
interpolate_raw(from_oklab.L, to_oklab.L),
interpolate_raw(from_oklab.a, to_oklab.a),
interpolate_raw(from_oklab.b, to_oklab.b));
color.set_alpha(interpolate_raw(from_color.alpha(), to_color.alpha()));
return ColorStyleValue::create(color);