summaryrefslogtreecommitdiff
path: root/Userland
diff options
context:
space:
mode:
authorMustafa Quraish <mustafaq9@gmail.com>2021-09-02 17:50:06 -0400
committerAndreas Kling <kling@serenityos.org>2021-09-03 01:51:05 +0200
commit882d57326c39a0268587c75009a45ffeeb14b36f (patch)
tree602132a05cc03a5c14fd61956302c0dd5904b7ae /Userland
parentca6c9be94cd1e62467803c108aba81fa98e9bf97 (diff)
downloadserenity-882d57326c39a0268587c75009a45ffeeb14b36f.zip
LibGfx/Color: Use luminosity to compute grayscale value
Issue #9758 discusses this.
Diffstat (limited to 'Userland')
-rw-r--r--Userland/Libraries/LibGfx/Color.h7
1 files changed, 6 insertions, 1 deletions
diff --git a/Userland/Libraries/LibGfx/Color.h b/Userland/Libraries/LibGfx/Color.h
index ab459e6284..ba9d52feec 100644
--- a/Userland/Libraries/LibGfx/Color.h
+++ b/Userland/Libraries/LibGfx/Color.h
@@ -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());
}