diff options
-rw-r--r-- | Userland/Libraries/LibGfx/Color.h | 7 |
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()); } |