LibGfx/Color: Use luminosity to compute grayscale value

Issue #9758 discusses this.
This commit is contained in:
Mustafa Quraish 2021-09-02 17:50:06 -04:00 committed by Andreas Kling
parent ca6c9be94c
commit 882d57326c
Notes: sideshowbarker 2024-07-18 04:50:55 +09:00

View file

@ -221,9 +221,14 @@ public:
alpha() * other.alpha() / 255);
}
constexpr u8 luminosity() const
{
return (red() * 0.2126f + green() * 0.7152f + blue() * 0.0722f);
}
constexpr Color to_grayscale() const
{
int gray = (red() + green() + blue()) / 3;
auto gray = luminosity();
return Color(gray, gray, gray, alpha());
}