diff mbox series

[8/9] drm/vc4: hdmi: Add BT.601 Support

Message ID 20221207-rpi-hdmi-improvements-v1-8-6b15f774c13a@cerno.tech (mailing list archive)
State New, archived
Headers show
Series drm/vc4: hdmi: Broadcast RGB, BT601, BT2020 | expand

Commit Message

Maxime Ripard Dec. 7, 2022, 4:07 p.m. UTC
From: Dave Stevenson <dave.stevenson@raspberrypi.com>

Even though we report that we support the BT601 Colorspace, we were
always using the BT.709 conversion matrices. Let's add the BT601 ones.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
---
 drivers/gpu/drm/vc4/vc4_hdmi.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

Comments

Thomas Zimmermann Jan. 11, 2023, 3:16 p.m. UTC | #1
Am 07.12.22 um 17:07 schrieb Maxime Ripard:
> From: Dave Stevenson <dave.stevenson@raspberrypi.com>
> 
> Even though we report that we support the BT601 Colorspace, we were
> always using the BT.709 conversion matrices. Let's add the BT601 ones.
> 
> Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
> Signed-off-by: Maxime Ripard <maxime@cerno.tech>

Reviewed-by: Thomas Zimmermann <tzimmermann@suse.de>

> ---
>   drivers/gpu/drm/vc4/vc4_hdmi.c | 38 ++++++++++++++++++++++++++++++++++++++
>   1 file changed, 38 insertions(+)
> 
> diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c
> index cd6775429b5e..e3428fb2c22d 100644
> --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
> +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
> @@ -1214,6 +1214,37 @@ static const u16 vc5_hdmi_csc_full_rgb_to_rgb[2][3][4] = {
>   	},
>   };
>   
> +/*
> + * Conversion between Full Range RGB and YUV using the BT.601 Colorspace
> + *
> + * Matrices are signed 2p13 fixed point, with signed 9p6 offsets
> + */
> +static const u16 vc5_hdmi_csc_full_rgb_to_yuv_bt601[2][3][4] = {
> +	{
> +		/*
> +		 * Full Range
> +		 *
> +		 * [  0.299000  0.587000  0.114000  0   ]
> +		 * [ -0.168736 -0.331264  0.500000  128 ]
> +		 * [  0.500000 -0.418688 -0.081312  128 ]
> +		 */
> +		{ 0x0991, 0x12c9, 0x03a6, 0x0000 },
> +		{ 0xfa9b, 0xf567, 0x1000, 0x2000 },
> +		{ 0x1000, 0xf29b, 0xfd67, 0x2000 },
> +	},
> +	{
> +		/* Limited Range
> +		 *
> +		 * [  0.255785  0.502160  0.097523  16  ]
> +		 * [ -0.147644 -0.289856  0.437500  128 ]
> +		 * [  0.437500 -0.366352 -0.071148  128 ]
> +		 */
> +		{ 0x082f, 0x1012, 0x031f, 0x0400 },
> +		{ 0xfb48, 0xf6ba, 0x0e00, 0x2000 },
> +		{ 0x0e00, 0xf448, 0xfdba, 0x2000 },
> +	},
> +};
> +
>   /*
>    * Conversion between Full Range RGB and YUV using the BT.709 Colorspace
>    *
> @@ -1277,6 +1308,13 @@ static const u16
>   (*vc5_hdmi_get_yuv_csc_coeffs(struct vc4_hdmi *vc4_hdmi, u32 colorspace, bool limited))[4]
>   {
>   	switch (colorspace) {
> +	case DRM_MODE_COLORIMETRY_SMPTE_170M_YCC:
> +	case DRM_MODE_COLORIMETRY_XVYCC_601:
> +	case DRM_MODE_COLORIMETRY_SYCC_601:
> +	case DRM_MODE_COLORIMETRY_OPYCC_601:
> +	case DRM_MODE_COLORIMETRY_BT601_YCC:
> +		return vc5_hdmi_csc_full_rgb_to_yuv_bt601[limited];
> +
>   	default:
>   	case DRM_MODE_COLORIMETRY_NO_DATA:
>   	case DRM_MODE_COLORIMETRY_BT709_YCC:
>
diff mbox series

Patch

diff --git a/drivers/gpu/drm/vc4/vc4_hdmi.c b/drivers/gpu/drm/vc4/vc4_hdmi.c
index cd6775429b5e..e3428fb2c22d 100644
--- a/drivers/gpu/drm/vc4/vc4_hdmi.c
+++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
@@ -1214,6 +1214,37 @@  static const u16 vc5_hdmi_csc_full_rgb_to_rgb[2][3][4] = {
 	},
 };
 
+/*
+ * Conversion between Full Range RGB and YUV using the BT.601 Colorspace
+ *
+ * Matrices are signed 2p13 fixed point, with signed 9p6 offsets
+ */
+static const u16 vc5_hdmi_csc_full_rgb_to_yuv_bt601[2][3][4] = {
+	{
+		/*
+		 * Full Range
+		 *
+		 * [  0.299000  0.587000  0.114000  0   ]
+		 * [ -0.168736 -0.331264  0.500000  128 ]
+		 * [  0.500000 -0.418688 -0.081312  128 ]
+		 */
+		{ 0x0991, 0x12c9, 0x03a6, 0x0000 },
+		{ 0xfa9b, 0xf567, 0x1000, 0x2000 },
+		{ 0x1000, 0xf29b, 0xfd67, 0x2000 },
+	},
+	{
+		/* Limited Range
+		 *
+		 * [  0.255785  0.502160  0.097523  16  ]
+		 * [ -0.147644 -0.289856  0.437500  128 ]
+		 * [  0.437500 -0.366352 -0.071148  128 ]
+		 */
+		{ 0x082f, 0x1012, 0x031f, 0x0400 },
+		{ 0xfb48, 0xf6ba, 0x0e00, 0x2000 },
+		{ 0x0e00, 0xf448, 0xfdba, 0x2000 },
+	},
+};
+
 /*
  * Conversion between Full Range RGB and YUV using the BT.709 Colorspace
  *
@@ -1277,6 +1308,13 @@  static const u16
 (*vc5_hdmi_get_yuv_csc_coeffs(struct vc4_hdmi *vc4_hdmi, u32 colorspace, bool limited))[4]
 {
 	switch (colorspace) {
+	case DRM_MODE_COLORIMETRY_SMPTE_170M_YCC:
+	case DRM_MODE_COLORIMETRY_XVYCC_601:
+	case DRM_MODE_COLORIMETRY_SYCC_601:
+	case DRM_MODE_COLORIMETRY_OPYCC_601:
+	case DRM_MODE_COLORIMETRY_BT601_YCC:
+		return vc5_hdmi_csc_full_rgb_to_yuv_bt601[limited];
+
 	default:
 	case DRM_MODE_COLORIMETRY_NO_DATA:
 	case DRM_MODE_COLORIMETRY_BT709_YCC: