From 882d57326c39a0268587c75009a45ffeeb14b36f Mon Sep 17 00:00:00 2001 From: Mustafa Quraish Date: Thu, 2 Sep 2021 17:50:06 -0400 Subject: LibGfx/Color: Use luminosity to compute grayscale value Issue #9758 discusses this. --- Userland/Libraries/LibGfx/Color.h | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'Userland/Libraries') 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()); } -- cgit v1.2.3