mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 23:57:34 +00:00
LibGfx/Color: Use luminosity to compute grayscale value
Issue #9758 discusses this.
This commit is contained in:
parent
ca6c9be94c
commit
882d57326c
1 changed files with 6 additions and 1 deletions
|
@ -221,9 +221,14 @@ public:
|
||||||
alpha() * other.alpha() / 255);
|
alpha() * other.alpha() / 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
constexpr u8 luminosity() const
|
||||||
|
{
|
||||||
|
return (red() * 0.2126f + green() * 0.7152f + blue() * 0.0722f);
|
||||||
|
}
|
||||||
|
|
||||||
constexpr Color to_grayscale() const
|
constexpr Color to_grayscale() const
|
||||||
{
|
{
|
||||||
int gray = (red() + green() + blue()) / 3;
|
auto gray = luminosity();
|
||||||
return Color(gray, gray, gray, alpha());
|
return Color(gray, gray, gray, alpha());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue