mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 21:17:44 +00:00
LibWeb: Move color interpolation into a helper function
This will be needed for other interpolations
This commit is contained in:
parent
8502b7ee9f
commit
3c21dd4d2b
1 changed files with 17 additions and 16 deletions
|
@ -1061,6 +1061,21 @@ static ErrorOr<NonnullRefPtr<StyleValue const>> interpolate_transform(DOM::Eleme
|
||||||
return StyleValueList::create({ TransformationStyleValue::create(TransformFunction::Matrix3d, move(values)) }, StyleValueList::Separator::Comma);
|
return StyleValueList::create({ TransformationStyleValue::create(TransformFunction::Matrix3d, move(values)) }, StyleValueList::Separator::Comma);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Color interpolate_color(Color from, Color to, float delta)
|
||||||
|
{
|
||||||
|
// https://drafts.csswg.org/css-color/#interpolation-space
|
||||||
|
// If the host syntax does not define what color space interpolation should take place in, it defaults to Oklab.
|
||||||
|
auto from_oklab = from.to_oklab();
|
||||||
|
auto to_oklab = to.to_oklab();
|
||||||
|
|
||||||
|
auto color = Color::from_oklab(
|
||||||
|
interpolate_raw(from_oklab.L, to_oklab.L, delta),
|
||||||
|
interpolate_raw(from_oklab.a, to_oklab.a, delta),
|
||||||
|
interpolate_raw(from_oklab.b, to_oklab.b, delta));
|
||||||
|
color.set_alpha(interpolate_raw(from.alpha(), to.alpha(), delta));
|
||||||
|
return color;
|
||||||
|
}
|
||||||
|
|
||||||
static ErrorOr<NonnullRefPtr<StyleValue const>> interpolate_value(DOM::Element& element, StyleValue const& from, StyleValue const& to, float delta)
|
static ErrorOr<NonnullRefPtr<StyleValue const>> interpolate_value(DOM::Element& element, StyleValue const& from, StyleValue const& to, float delta)
|
||||||
{
|
{
|
||||||
if (from.type() != to.type())
|
if (from.type() != to.type())
|
||||||
|
@ -1069,22 +1084,8 @@ static ErrorOr<NonnullRefPtr<StyleValue const>> interpolate_value(DOM::Element&
|
||||||
switch (from.type()) {
|
switch (from.type()) {
|
||||||
case StyleValue::Type::Angle:
|
case StyleValue::Type::Angle:
|
||||||
return AngleStyleValue::create(Angle::make_degrees(interpolate_raw(from.as_angle().angle().to_degrees(), to.as_angle().angle().to_degrees(), delta)));
|
return AngleStyleValue::create(Angle::make_degrees(interpolate_raw(from.as_angle().angle().to_degrees(), to.as_angle().angle().to_degrees(), delta)));
|
||||||
case StyleValue::Type::Color: {
|
case StyleValue::Type::Color:
|
||||||
// https://drafts.csswg.org/css-color/#interpolation-space
|
return ColorStyleValue::create(interpolate_color(from.as_color().color(), to.as_color().color(), delta));
|
||||||
// If the host syntax does not define what color space interpolation should take place in, it defaults to Oklab.
|
|
||||||
auto from_color = from.as_color().color();
|
|
||||||
auto to_color = to.as_color().color();
|
|
||||||
auto from_oklab = from_color.to_oklab();
|
|
||||||
auto to_oklab = to_color.to_oklab();
|
|
||||||
|
|
||||||
auto color = Color::from_oklab(
|
|
||||||
interpolate_raw(from_oklab.L, to_oklab.L, delta),
|
|
||||||
interpolate_raw(from_oklab.a, to_oklab.a, delta),
|
|
||||||
interpolate_raw(from_oklab.b, to_oklab.b, delta));
|
|
||||||
color.set_alpha(interpolate_raw(from_color.alpha(), to_color.alpha(), delta));
|
|
||||||
|
|
||||||
return ColorStyleValue::create(color);
|
|
||||||
}
|
|
||||||
case StyleValue::Type::Integer:
|
case StyleValue::Type::Integer:
|
||||||
return IntegerStyleValue::create(interpolate_raw(from.as_integer().integer(), to.as_integer().integer(), delta));
|
return IntegerStyleValue::create(interpolate_raw(from.as_integer().integer(), to.as_integer().integer(), delta));
|
||||||
case StyleValue::Type::Length: {
|
case StyleValue::Type::Length: {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue