Skip to contentSkip to conversation

drm/format-helper: Normalize BT.601 factors to 256

PATCH In review Thomas Zimmermann 2 participants 4 messages Jun 3, 2025 – Jun 13, 2025

Subsystems (2)
lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

PATCH 1/1 drm/format-helper: Normalize BT.601 factors to 256

BT.601 weights RGB components by certain factors to convert the color to grayscale. Normalize the constants to 256 instead of 10. Allows for slightly more precise rounding. The division by 256 can be compiled as an 8-bit shift, which might be faster on some hardware.

---
 drivers/gpu/drm/drm_format_internal.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_format_internal.h +1 -1
index 9f857bfa368d..3020ff267513 100644
@@ -42,7 +42,7 @@ static inline u32 drm_pixel_xrgb8888_to_r8_bt601(u32 pix)
 	u32 b =  pix & 0x000000ff;
 
 	/* ITU-R BT.601: Y = 0.299 R + 0.587 G + 0.114 B */
-	return (3 * r + 6 * g + b) / 10;
+	return (77 * r + 150 * g + 29 * b) / 256;
 }
 
 static inline u32 drm_pixel_xrgb8888_to_rgb332(u32 pix)
Signature · 1 line
2.49.0
Acked-by on v1 1/1
#1 lore raw
Quoted 7 lines · Thomas Zimmermann

BT.601 weights RGB components by certain factors to convert the color to grayscale. Normalize the constants to 256 instead of 10. Allows for slightly more precise rounding. The division by 256 can be compiled as an 8-bit shift, which might be faster on some hardware.

---

Makes sense.

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat
author maintainer
#2 lore raw
In reply to Thomas Zimmermann

This patch also requires an update to the test cases, which is available at https://patchwork.freedesktop.org/series/150218/

Am 03.06.25 um 18:11 schrieb Thomas Zimmermann:

Quoted 23 lines

BT.601 weights RGB components by certain factors to convert the color to grayscale. Normalize the constants to 256 instead of 10. Allows for slightly more precise rounding. The division by 256 can be compiled as an 8-bit shift, which might be faster on some hardware.

---
  drivers/gpu/drm/drm_format_internal.h | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/drm_format_internal.h +1 -1
index 9f857bfa368d..3020ff267513 100644
@@ -42,7 +42,7 @@ static inline u32 drm_pixel_xrgb8888_to_r8_bt601(u32 pix)
  	u32 b =  pix & 0x000000ff;
 
  	/* ITU-R BT.601: Y = 0.299 R + 0.587 G + 0.114 B */
-	return (3 * r + 6 * g + b) / 10;
+	return (77 * r + 150 * g + 29 * b) / 256;
  }
 
  static inline u32 drm_pixel_xrgb8888_to_rgb332(u32 pix)
Signature · 7 lines
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)
#3 lore raw
Quoted 3 lines · Thomas Zimmermann

This patch also requires an update to the test cases, which is available at https://patchwork.freedesktop.org/series/150218/

I was going to suggest to instead post a v2 with the test changes included but I noticed now that you already pushed this patch.

Signature · 5 lines
Best regards,

Javier Martinez Canillas
Core Platforms
Red Hat