]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
drm/format-helper: Normalize BT.601 factors to 256
authorThomas Zimmermann <tzimmermann@suse.de>
Tue, 3 Jun 2025 16:11:50 +0000 (18:11 +0200)
committerThomas Zimmermann <tzimmermann@suse.de>
Fri, 13 Jun 2025 06:52:29 +0000 (08:52 +0200)
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.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Acked-by: Javier Martinez Canillas <javierm@redhat.com>
Link: https://lore.kernel.org/r/20250603161158.423962-1-tzimmermann@suse.de
drivers/gpu/drm/drm_format_internal.h

index 9f857bfa368d10d4a8155c7d0828d38c4f23e6b7..3020ff267513fc22e169aa6e11aba66890f42242 100644 (file)
@@ -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)