drm: bridge: dw-hdmi: Fix RGB to YUV color space conversion
Subsystems (3)
PATCH 1/1 drm: bridge: dw-hdmi: Fix RGB to YUV color space conversion
As per CEA-861 quantization range is always limited in case of YUV output - indepentently which CEA mode it is or if it is an DMT mode.
This is already correctly setup in HDMI AVI inforame, but we always do a RGB to YUV conversion which doesn't consider that RGB input can be full range as well.
That leads to incorrect colors for all CEA modes except mode 1 for HDMI and always for DVI.
To fix this, provide additional csc coefficents for converting from RGB full range to EITU601/EITU709 limited range and rename the existing arrays to clarify their meaning.
--- drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 24 +++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-)
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +20 -4
@@ -80,13 +80,25 @@ static const u16 csc_coeff_rgb_out_eitu709[3][4] = { { 0x2000, 0x0000, 0x3b61, 0x7e25 } }; -static const u16 csc_coeff_rgb_in_eitu601[3 ][4 ] = { +static const u16 csc_coeff_rgb_full_in_eitu601[3 ][4 ] = { + {0x2044 ,0x106f ,0x0644 ,0x0040 }, + {0xe677 ,0x1c1c ,0xfd46 ,0x0200 }, + {0xed60 ,0xf685 ,0x1c1c ,0x0200 } +}; + +static const u16 csc_coeff_rgb_limited_in_eitu601[3 ][4 ] = { {0x2591 ,0x1322 ,0x074b ,0x0000 }, {0x6535 ,0x2000 ,0x7acc ,0x0200 }, {0x6acd ,0x7534 ,0x2000 ,0x0200 } }; -static const u16 csc_coeff_rgb_in_eitu709[3 ][4 ] = { +static const u16 csc_coeff_rgb_full_in_eitu709[3 ][4 ] = { + {0x2750 ,0x0baf ,0x03f8 ,0x0040 }, + {0xe677 ,0x1c1c ,0xfd6d ,0x0200 }, + {0xea55 ,0xf98f ,0x1c1c ,0x0200 } +}; + +static const u16 csc_coeff_rgb_limted_in_eitu709[3 ][4 ] = { {0x2dc5 ,0x0d9b ,0x049e ,0x0000 }, {0x62f0 ,0x2000 ,0x7d11 ,0x0200 }, {0x6756 ,0x78ab ,0x2000 ,0x0200 }
@@ -1023,9 +1035,13 @@ static void dw_hdmi_update_csc_coeffs(struct dw_hdmi *hdmi) csc_coeff = &csc_coeff_rgb_out_eitu709; }else if (is_input_rgb && !is_output_rgb) {if (hdmi->hdmi_data.enc_out_encoding ==V4L2_YCBCR_ENC_601 ) - csc_coeff = &csc_coeff_rgb_in_eitu601; + csc_coeff = hdmi->hdmi_data.rgb_limited_range + ? &csc_coeff_rgb_limited_in_eitu601 + : &csc_coeff_rgb_full_in_eitu601;else - csc_coeff = &csc_coeff_rgb_in_eitu709; + csc_coeff = hdmi->hdmi_data.rgb_limited_range + ? &csc_coeff_rgb_limted_in_eitu709 + : &csc_coeff_rgb_full_in_eitu709; csc_scale =0 ; }else if (is_input_rgb && is_output_rgb && hdmi->hdmi_data.rgb_limited_range) {
base-commit: 89636a06fa2ee7826a19c39c19a9bc99ab9340a9
Signature · 1 line
2.30.2
Jernej Škrabec
reviewerHi Alex,
Dne sobota, 06. november 2021 ob 14:00:44 CET je Alex Bee napisal(a):
drivers/gpu/drm/
Quoted 19 lines
As per CEA-861 quantization range is always limited in case of YUV output - indepentently which CEA mode it is or if it is an DMT mode.
This is already correctly setup in HDMI AVI inforame, but we always do a RGB to YUV conversion which doesn't consider that RGB input can be full range as well.
That leads to incorrect colors for all CEA modes except mode 1 for HDMI and always for DVI.To fix this, provide additional csc coefficents for converting from RGB full range to EITU601/EITU709 limited range and rename the existing arrays to clarify their meaning.
Signed-off-by Alex Bee <[email protected]>--- drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 24 +++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-)drivers/gpu/drm/ renamed from drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +0
-0
bridge/synopsys/dw-hdmi.c
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c static const u16 csc_coeff_rgb_out_eitu709[3][4] = { · line 83
Quoted 9 lines
index
62ae63565d3a..1cba08b70091100644drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +1
-1@@ -80,13 +80,25 @@ static const u16 csc_coeff_rgb_out_eitu709[3][4] = { { 0x2000, 0x0000, 0x3b61, 0x7e25 } }; -static const u16 csc_coeff_rgb_in_eitu601[3 ][4 ] = { +static const u16 csc_coeff_rgb_full_in_eitu601[3 ][4 ] = {
I would rather move "full" and "limited" to the end, since RGB always has full range and we want YUV to have full or limited range.
Just one observation - no other matrix sets bit 15 in any coefficient, but yours do. I can't see anywhere documented if bit 15 is ignored or not. Can you try with it set to 0? If it still works, I would set it to 0 for consistency.
Best regards,
Jernej
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c static void dw_hdmi_update_csc_coeffs(struct dw_hdmi
Quoted 23 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +13
-1+ { 0x2044, 0x106f, 0x0644, 0x0040 }, + { 0xe677, 0x1c1c, 0xfd46, 0x0200 }, + { 0xed60, 0xf685, 0x1c1c, 0x0200 } +}; + +static const u16 csc_coeff_rgb_limited_in_eitu601[3 ][4 ] = { {0x2591 ,0x1322 ,0x074b ,0x0000 }, {0x6535 ,0x2000 ,0x7acc ,0x0200 }, {0x6acd ,0x7534 ,0x2000 ,0x0200 } }; -static const u16 csc_coeff_rgb_in_eitu709[3 ][4 ] = { +static const u16 csc_coeff_rgb_full_in_eitu709[3 ][4 ] = { + {0x2750 ,0x0baf ,0x03f8 ,0x0040 }, + {0xe677 ,0x1c1c ,0xfd6d ,0x0200 }, + {0xea55 ,0xf98f ,0x1c1c ,0x0200 } +}; + +static const u16 csc_coeff_rgb_limted_in_eitu709[3 ][4 ] = { {0x2dc5 ,0x0d9b ,0x049e ,0x0000 }, {0x62f0 ,0x2000 ,0x7d11 ,0x0200 }, { 0x6756, 0x78ab, 0x2000, 0x0200 }@@ -1023,9 +1035,13 @@ static void dw_hdmi_update_csc_coeffs(struct dw_hdmi
*hdmi)
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c static void dw_hdmi_update_csc_coeffs(struct dw_hdmi *hdmi)
Quoted 3 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +0
-0csc_coeff = &csc_coeff_rgb_out_eitu709; }else if (is_input_rgb && !is_output_rgb) { if (hdmi->hdmi_data.enc_out_encoding ==
V4L2_YCBCR_ENC_601)
Quoted 18 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +6
-2- csc_coeff = &csc_coeff_rgb_in_eitu601; + csc_coeff = hdmi->hdmi_data.rgb_limited_range + ? &csc_coeff_rgb_limited_in_eitu601 + : &csc_coeff_rgb_full_in_eitu601; else - csc_coeff = &csc_coeff_rgb_in_eitu709; + csc_coeff = hdmi->hdmi_data.rgb_limited_range + ? &csc_coeff_rgb_limted_in_eitu709 + : &csc_coeff_rgb_full_in_eitu709; csc_scale =0 ; }else if (is_input_rgb && is_output_rgb && hdmi->hdmi_data.rgb_limited_range) {base-commit:
89636a06fa2ee7826a19c39c19a9bc99ab9340a9Signature · 1 line
2.30.2
Jernej Škrabec
reviewerDne sreda, 10. november 2021 ob 21:20:46 CET je Jernej Škrabec napisal(a):
Quoted 46 lines
Hi Alex,
Dne sobota, 06. november 2021 ob 14:00:44 CET je Alex Bee napisal(a):
drivers/gpu/drm/
Quoted 20 lines
As per CEA-861 quantization range is always limited in case of YUV output - indepentently which CEA mode it is or if it is an DMT mode.
This is already correctly setup in HDMI AVI inforame, but we always do a RGB to YUV conversion which doesn't consider that RGB input can be full range as well.
That leads to incorrect colors for all CEA modes except mode 1 for HDMI and always for DVI.To fix this, provide additional csc coefficents for converting from RGB full range to EITU601/EITU709 limited range and rename the existing arrays to clarify their meaning.
Signed-off-by Alex Bee <[email protected]>---
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c | 24 +++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-)drivers/gpu/drm/ renamed from drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +0
-0
bridge/synopsys/dw-hdmi.cdrivers/gpu/drm/bridge/synopsys/dw-hdmi.c static const u16 csc_coeff_rgb_out_eitu709[3][4] = { · line 85
Quoted 11 lines
index
62ae63565d3a..1cba08b70091100644drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +1
-1@@ -80,13 +80,25 @@ static const u16 csc_coeff_rgb_out_eitu709[3][4] = { { 0x2000, 0x0000, 0x3b61, 0x7e25 } }; -static const u16 csc_coeff_rgb_in_eitu601[3 ][4 ] = { +static const u16 csc_coeff_rgb_full_in_eitu601[3 ][4 ] = {I would rather move "full" and "limited" to the end, since RGB always has full range and we want YUV to have full or limited range.
Just one observation - no other matrix sets bit 15 in any coefficient, but yours do. I can't see anywhere documented if bit 15 is ignored or not. Can you try with it set to 0? If it still works, I would set it to 0 for consistency.
Quoted 5 lines
Best regards,
Jernejdrivers/gpu/drm/bridge/synopsys/dw-hdmi.c static const u16 csc_coeff_rgb_out_eitu709[3][4] = { · line 85
Quoted 2 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +2
-0+ { 0x2044, 0x106f, 0x0644, 0x0040 }, + { 0xe677, 0x1c1c, 0xfd46, 0x0200 },
By my calculations, above line should be:
{ 0xe876, 0x1c1c, 0xfb6e, 0x0200}
Can you check again?
Quoted 33 lines
Quoted 25 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +11
-1+ { 0xed60, 0xf685, 0x1c1c, 0x0200 } +}; + +static const u16 csc_coeff_rgb_limited_in_eitu601[3 ][4 ] = { {0x2591 ,0x1322 ,0x074b ,0x0000 }, {0x6535 ,0x2000 ,0x7acc ,0x0200 }, {0x6acd ,0x7534 ,0x2000 ,0x0200 } }; -static const u16 csc_coeff_rgb_in_eitu709[3 ][4 ] = { +static const u16 csc_coeff_rgb_full_in_eitu709[3 ][4 ] = { + {0x2750 ,0x0baf ,0x03f8 ,0x0040 }, + {0xe677 ,0x1c1c ,0xfd6d ,0x0200 }, + {0xea55 ,0xf98f ,0x1c1c ,0x0200 } +}; + +static const u16 csc_coeff_rgb_limted_in_eitu709[3 ][4 ] = { {0x2dc5 ,0x0d9b ,0x049e ,0x0000 }, {0x62f0 ,0x2000 ,0x7d11 ,0x0200 }, {0x6756 ,0x78ab ,0x2000 ,0x0200 }@@ -1023,9 +1035,13 @@ static void dw_hdmi_update_csc_coeffs(structQuoted 1 line
dw_hdmi*hdmi)
Quoted 4 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +0
-0csc_coeff = &csc_coeff_rgb_out_eitu709; }else if (is_input_rgb && !is_output_rgb) {
Quoted 7 lines
Quoted 1 line
if (
hdmi->hdmi_data.enc_out_encoding==
V4L2_YCBCR_ENC_601)drivers/gpu/drm/bridge/synopsys/dw-hdmi.c static void dw_hdmi_update_csc_coeffs(struct dw_hdmi *hdmi)
Quoted 3 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +2
-1- csc_coeff = &csc_coeff_rgb_in_eitu601; + csc_coeff = hdmi->hdmi_data.rgb_limited_range + ?
&csc_coeff_rgb_limited_in_eitu601
Quoted 16 lines
Quoted 16 lines
drivers/gpu/drm/bridge/synopsys/dw-hdmi.c +4
-1+ : &csc_coeff_rgb_full_in_eitu601; else - csc_coeff = &csc_coeff_rgb_in_eitu709; + csc_coeff = hdmi->hdmi_data.rgb_limited_range + ? &csc_coeff_rgb_limted_in_eitu709 + : &csc_coeff_rgb_full_in_eitu709; csc_scale =0 ; }else if (is_input_rgb && is_output_rgb && hdmi->hdmi_data.rgb_limited_range) {base-commit:
89636a06fa2ee7826a19c39c19a9bc99ab9340a9