Skip to content

Commit b287812

Browse files
nathanlucasgregkh
authored andcommitted
drm/amd/display: fix BT.2020 YCbCr limited output CSC matrix
[ Upstream commit 2f9a5c0 ] COLOR_SPACE_YCBCR2020_TYPE, which is selected for COLOR_SPACE_2020_YCBCR_LIMITED color_space, has coefficients that are incorrect for limited-range output. Its luma and chroma scaling is full-range so output is too bright and colors are incorrect. COLOR_SPACE_YCBCR2020_TYPE is closer to a full-range conversion matrix with incorrect luma offset, so correct the luma offset for full-range and rename it to COLOR_SPACE_YCBCR2020_FULL_TYPE. Add COLOR_SPACE_YCBCR2020_LIMITED_TYPE with correct scaling and range for limited-range output. Fix related functions so COLOR_SPACE_YCBCR2020_LIMITED_TYPE and COLOR_SPACE_YCBCR2020_FULL_TYPE are correctly selected based on dc_color_space. Derivation of both matrices follows ITU-T H.273: Table 4, MatrixCoefficients 9, BT.2020-NCL weights: KR = 0.2627, KB = 0.0593, KG = 1 - KR - KB = 0.6780. Equations 45-47 in matrix form: [ KR KG KB 0 ] M2020_NCL = [ -KR/(2(1-KB)) -KG/(2(1-KB)) 1/2 0 ] [ 1/2 -KG/(2(1-KR)) -KB/(2(1-KR)) 0 ] [ 0 0 0 1 ] Limited and Full transforms based on equations 30-32 and 36-38 with bit depth 10, normalized by 1023: [ 876/1023 0 0 64/1023 ] MLimited = [ 0 896/1023 0 512/1023 ] [ 0 0 896/1023 512/1023 ] [ 0 0 0 1 ] [ 1023/1023 0 0 0 ] MFull = [ 0 1023/1023 0 512/1023 ] [ 0 0 1023/1023 512/1023 ] [ 0 0 0 1 ] M2020_NCL_Limited = MLimited x M2020_NCL M2020_NCL_Full = MFull x M2020_NCL The upper three rows of M2020_NCL_* are stored in CR, Y, CB order. Each M2020_NCL_* value is stored as Round(value * 8192) in its 16-bit two's-complement representation. Fixes: 973a9c8 ("drm/amd/display: Fix COLOR_SPACE_YCBCR2020_TYPE matrix") Assisted-by: OpenAI-Codex:GPT-5.6-Sol Tested-by: Igor Paunovic <royalnet026@gmail.com> Tested-by: Satyajit Roy <sroy14@alum.utk.edu> Signed-off-by: Nathan Lucas <nlucasgit@gmail.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> (cherry picked from commit 3b906e1) Cc: stable@vger.kernel.org Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 874d1bd commit b287812

1 file changed

Lines changed: 20 additions & 11 deletions

File tree

drivers/gpu/drm/amd/display/dc/core/dc_hw_sequencer.c

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ enum dc_color_space_type {
4747
COLOR_SPACE_RGB_LIMITED_TYPE,
4848
COLOR_SPACE_YCBCR601_TYPE,
4949
COLOR_SPACE_YCBCR709_TYPE,
50-
COLOR_SPACE_YCBCR2020_TYPE,
50+
COLOR_SPACE_YCBCR2020_LIMITED_TYPE,
51+
COLOR_SPACE_YCBCR2020_FULL_TYPE,
5152
COLOR_SPACE_YCBCR601_LIMITED_TYPE,
5253
COLOR_SPACE_YCBCR709_LIMITED_TYPE,
5354
COLOR_SPACE_YCBCR709_BLACK_TYPE,
@@ -99,9 +100,15 @@ static const struct out_csc_color_matrix_type output_csc_matrix[] = {
99100
{ 0xE00, 0xF349, 0xFEB7, 0x1000,
100101
0x6CE, 0x16E3, 0x24F, 0x200,
101102
0xFCCB, 0xF535, 0xE00, 0x1000} },
102-
{ COLOR_SPACE_YCBCR2020_TYPE,
103+
/* Corrected. Not included in the TODO above. */
104+
{ COLOR_SPACE_YCBCR2020_LIMITED_TYPE,
105+
{ 0x0E04, 0xF31D, 0xFEDF, 0x1004,
106+
0x0733, 0x1294, 0x01A0, 0x0201,
107+
0xFC16, 0xF5E6, 0x0E04, 0x1004} },
108+
/* Corrected. Not included in the TODO above. */
109+
{ COLOR_SPACE_YCBCR2020_FULL_TYPE,
103110
{ 0x1000, 0xF149, 0xFEB7, 0x1004,
104-
0x0868, 0x15B2, 0x01E6, 0x201,
111+
0x0868, 0x15B2, 0x01E6, 0,
105112
0xFB88, 0xF478, 0x1000, 0x1004} },
106113
{ COLOR_SPACE_YCBCR709_BLACK_TYPE,
107114
{ 0x0000, 0x0000, 0x0000, 0x1000,
@@ -168,14 +175,14 @@ static bool is_ycbcr709_type(
168175
return ret;
169176
}
170177

171-
static bool is_ycbcr2020_type(
172-
enum dc_color_space color_space)
178+
static bool is_ycbcr2020_limited_type(enum dc_color_space color_space)
173179
{
174-
bool ret = false;
180+
return color_space == COLOR_SPACE_2020_YCBCR_LIMITED;
181+
}
175182

176-
if (color_space == COLOR_SPACE_2020_YCBCR_LIMITED || color_space == COLOR_SPACE_2020_YCBCR_FULL)
177-
ret = true;
178-
return ret;
183+
static bool is_ycbcr2020_full_type(enum dc_color_space color_space)
184+
{
185+
return color_space == COLOR_SPACE_2020_YCBCR_FULL;
179186
}
180187

181188
static bool is_ycbcr709_limited_type(
@@ -204,8 +211,10 @@ static enum dc_color_space_type get_color_space_type(enum dc_color_space color_s
204211
type = COLOR_SPACE_YCBCR601_LIMITED_TYPE;
205212
else if (is_ycbcr709_limited_type(color_space))
206213
type = COLOR_SPACE_YCBCR709_LIMITED_TYPE;
207-
else if (is_ycbcr2020_type(color_space))
208-
type = COLOR_SPACE_YCBCR2020_TYPE;
214+
else if (is_ycbcr2020_limited_type(color_space))
215+
type = COLOR_SPACE_YCBCR2020_LIMITED_TYPE;
216+
else if (is_ycbcr2020_full_type(color_space))
217+
type = COLOR_SPACE_YCBCR2020_FULL_TYPE;
209218
else if (color_space == COLOR_SPACE_YCBCR709)
210219
type = COLOR_SPACE_YCBCR709_BLACK_TYPE;
211220
else if (color_space == COLOR_SPACE_YCBCR709_BLACK)

0 commit comments

Comments
 (0)