mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-09-26 11:18:59 +00:00
LibGfx: Add Color::contrast_ratio()
This commit is contained in:
parent
8e441d402b
commit
73b05364e8
Notes:
sideshowbarker
2024-07-17 14:36:19 +09:00
Author: https://github.com/MacDue
Commit: 73b05364e8
Pull-request: https://github.com/SerenityOS/serenity/pull/13989
Issue: https://github.com/SerenityOS/serenity/issues/13978
Reviewed-by: https://github.com/Hendiadyoin1
Reviewed-by: https://github.com/linusg
1 changed files with 9 additions and 0 deletions
|
@ -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();
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue