From 4feba883276502f5603c158c541bb7fabc6a01aa Mon Sep 17 00:00:00 2001 From: Sally Coolatta Date: Thu, 15 Dec 2022 22:08:29 -0500 Subject: [PATCH] Slightly improve colorize's luminance method Before I was using coefficents from another formula I forget the source of, but over time I've stopped liking how it looked -- just considers greens far too bright. Here I'm trying out BT.601 coefficents instead (https://en.wikipedia.org/wiki/Rec._601). These are also the coefficients Doom itself used for invulnerability's invert effect (if you ignore the typo Carmack made :p), so this checks out. --- src/k_color.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/k_color.c b/src/k_color.c index ac1a2e6c8..5f58441e0 100644 --- a/src/k_color.c +++ b/src/k_color.c @@ -24,11 +24,12 @@ --------------------------------------------------*/ UINT8 K_ColorRelativeLuminance(UINT8 r, UINT8 g, UINT8 b) { - UINT32 redweight = 1063 * r; - UINT32 greenweight = 3576 * g; - UINT32 blueweight = 361 * b; - UINT32 brightness = (redweight + greenweight + blueweight) / 5000; - return min(brightness, UINT8_MAX); + // These are the BT.601 coefficents + // See also: https://en.wikipedia.org/wiki/Rec._601 + UINT32 redweight = 299 * r; + UINT32 greenweight = 587 * g; + UINT32 blueweight = 114 * b; + return min((redweight + greenweight + blueweight) / 1000, UINT8_MAX); } /*--------------------------------------------------