1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 02:47:35 +00:00

LibGfx: Add Color::contrast_ratio()

This commit is contained in:
MacDue 2022-05-09 00:07:24 +01:00 committed by Linus Groh
parent 8e441d402b
commit 73b05364e8

View file

@ -221,6 +221,15 @@ public:
return (red() * 0.2126f + green() * 0.7152f + blue() * 0.0722f);
}
constexpr float contrast_ratio(Color const& other)
{
auto l1 = luminosity();
auto l2 = other.luminosity();
auto darkest = min(l1, l2) / 255.;
auto brightest = max(l1, l2) / 255.;
return (brightest + 0.05) / (darkest + 0.05);
}
constexpr Color to_grayscale() const
{
auto gray = luminosity();