From: Brendan McGrath bmcgrath@codeweavers.com
--- dlls/ddraw/tests/ddraw7.c | 20 -------------------- dlls/wined3d/glsl_shader.c | 23 +++++++++++++++++------ 2 files changed, 17 insertions(+), 26 deletions(-)
diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c index a8a3a1f7974..d8a4ed7c5b7 100644 --- a/dlls/ddraw/tests/ddraw7.c +++ b/dlls/ddraw/tests/ddraw7.c @@ -13696,7 +13696,6 @@ static void test_yuv_to_rgb_blt(void) BYTE u; BYTE v; UINT32 expected; - BOOL todo; /* some systems are configured for studio range */ UINT32 studio_value; /* some systems use SD values for HD. */ @@ -13712,7 +13711,6 @@ static void test_yuv_to_rgb_blt(void) .u = 0x80, .v = 0x80, .expected = 0x000000, - .todo = TRUE, .studio_value = 0x101010, },
@@ -13723,7 +13721,6 @@ static void test_yuv_to_rgb_blt(void) .u = 0x80, .v = 0x80, .expected = 0xffffff, - .todo = TRUE, .studio_value = 0xebebeb, },
@@ -13734,7 +13731,6 @@ static void test_yuv_to_rgb_blt(void) .u = 0x5a, .v = 0xf0, .expected = 0xfe0000, - .todo = TRUE, .studio_value = 0xeb1010, },
@@ -13745,7 +13741,6 @@ static void test_yuv_to_rgb_blt(void) .u = 0x36, .v = 0x22, .expected = 0x00ff01, - .todo = TRUE, .studio_value = 0x10eb11, },
@@ -13756,7 +13751,6 @@ static void test_yuv_to_rgb_blt(void) .u = 0xf0, .v = 0x6e, .expected = 0x0000ff, - .todo = TRUE, .studio_value = 0x1010eb, },
@@ -13767,7 +13761,6 @@ static void test_yuv_to_rgb_blt(void) .u = 0x80, .v = 0x80, .expected = 0x808080, - .todo = TRUE, .studio_value = 0x7e7e7e, },
@@ -13778,7 +13771,6 @@ static void test_yuv_to_rgb_blt(void) .u = 0x80, .v = 0x80, .expected = 0x000000, - .todo = FALSE, .studio_value = 0x101010, },
@@ -13789,7 +13781,6 @@ static void test_yuv_to_rgb_blt(void) .u = 0x80, .v = 0x80, .expected = 0xffffff, - .todo = FALSE, .studio_value = 0xebebeb, },
@@ -13800,7 +13791,6 @@ static void test_yuv_to_rgb_blt(void) .u = 0x00, .v = 0x00, .expected = 0x008700, - .todo = FALSE, .studio_value = 0x108410, }, /* Windows will treat anything with a height greater than 576 as HD and, @@ -13813,7 +13803,6 @@ static void test_yuv_to_rgb_blt(void) .u = 0x80, .v = 0x80, .expected = 0x000000, - .todo = TRUE, .studio_value = 0x101010, },
@@ -13824,7 +13813,6 @@ static void test_yuv_to_rgb_blt(void) .u = 0x80, .v = 0x80, .expected = 0xffffff, - .todo = TRUE, .studio_value = 0xebebeb, },
@@ -13835,7 +13823,6 @@ static void test_yuv_to_rgb_blt(void) .u = 0x66, .v = 0xf0, .expected = 0xff0100, - .todo = TRUE, .studio_value = 0xeb1110, .test_for_broken = TRUE, .broken_value = 0xe90002, @@ -13848,7 +13835,6 @@ static void test_yuv_to_rgb_blt(void) .u = 0x2a, .v = 0x1a, .expected = 0x00ff01, - .todo = TRUE, .studio_value = 0x10eb11, .test_for_broken = TRUE, .broken_value = 0x14ff09, @@ -13861,7 +13847,6 @@ static void test_yuv_to_rgb_blt(void) .u = 0xf0, .v = 0x76, .expected = 0x0100ff, - .todo = TRUE, .studio_value = 0x1110eb, .test_for_broken = TRUE, .broken_value = 0x0300f5, @@ -13874,7 +13859,6 @@ static void test_yuv_to_rgb_blt(void) .u = 0x80, .v = 0x80, .expected = 0x808080, - .todo = TRUE, .studio_value = 0x7e7e7e, },
@@ -13885,7 +13869,6 @@ static void test_yuv_to_rgb_blt(void) .u = 0x80, .v = 0x80, .expected = 0x000000, - .todo = FALSE, .studio_value= 0x101010, },
@@ -13896,7 +13879,6 @@ static void test_yuv_to_rgb_blt(void) .u = 0x80, .v = 0x80, .expected = 0xffffff, - .todo = FALSE, .studio_value = 0xebebeb, },
@@ -13907,7 +13889,6 @@ static void test_yuv_to_rgb_blt(void) .u = 0x00, .v = 0x00, .expected = 0x004d00, - .todo = TRUE, .studio_value = 0x105210, .test_for_broken = TRUE, .broken_value = 0x008700, @@ -14054,7 +14035,6 @@ static void test_yuv_to_rgb_blt(void) for (x = 0; x < 4; x++) { UINT32 color = pixel[x] & 0xffffff; - todo_wine_if(test_colors[j].todo) ok(compare_color(color, test_colors[j].expected, 1) || broken(compare_color(color, test_colors[j].expected, 4)) || broken(compare_color(color, test_colors[j].studio_value, 0x10)) || diff --git a/dlls/wined3d/glsl_shader.c b/dlls/wined3d/glsl_shader.c index df60415f062..7a1f351b2db 100644 --- a/dlls/wined3d/glsl_shader.c +++ b/dlls/wined3d/glsl_shader.c @@ -12677,10 +12677,12 @@ static void glsl_blitter_generate_yuv_shader(struct wined3d_string_buffer *buffe { enum complex_fixup complex_fixup = get_complex_fixup(args->fixup);
- shader_addline(buffer, "const vec4 yuv_coef = vec4(1.403, -0.344, -0.714, 1.770);\n"); + shader_addline(buffer, "const vec4 yuv_coef_sd = vec4(1.596, -0.392, -0.813, 2.017);\n"); + shader_addline(buffer, "const vec4 yuv_coef_hd = vec4(1.793, -0.213, -0.533, 2.112);\n"); shader_addline(buffer, "float luminance;\n"); shader_addline(buffer, "vec2 texcoord;\n"); shader_addline(buffer, "vec2 chroma;\n"); + shader_addline(buffer, "vec4 yuv_coef;\n"); shader_addline(buffer, "uniform vec2 size;\n");
shader_addline(buffer, "\nvoid main()\n{\n"); @@ -12715,11 +12717,20 @@ static void glsl_blitter_generate_yuv_shader(struct wined3d_string_buffer *buffe return; }
- /* Calculate the final result. Formula is taken from - * http://www.fourcc.org/fccyvrgb.php. Note that the chroma - * ranges from -0.5 to 0.5. */ - shader_addline(buffer, "\n chroma.xy -= 0.5;\n"); - + /* Calculate the final result. Formula is taken from: + * https://learn.microsoft.com/en-us/windows/win32/medfound/recommended-8-bit-y.... + * SD and HD textures use different coefficients. SD is anything with both width and height smaller or equal to 720x576. + * Note that input values are clamped for SD, but not HD. Luminance is clamped to [16,235] ([0.063, 0.922] when normalized). + * Chroma is clamped to [16,240] ([0.063, 0.941] when normalized). */ + shader_addline(buffer, "\n if (size.x <= 720 && size.y <= 576)\n {\n"); + shader_addline(buffer, " luminance = clamp(luminance, 0.063, 0.922);\n"); + shader_addline(buffer, " chroma.xy = clamp(chroma.xy, 0.063, 0.941);\n"); + shader_addline(buffer, " yuv_coef = yuv_coef_sd;\n"); + shader_addline(buffer, " }\n else\n {\n"); + shader_addline(buffer, " yuv_coef = yuv_coef_hd;\n"); + shader_addline(buffer, " }\n"); + shader_addline(buffer, " luminance = (luminance - 0.063) * 1.164;\n"); + shader_addline(buffer, " chroma.xy = chroma.xy - 0.5;\n"); shader_addline(buffer, " %s.x = luminance + chroma.x * yuv_coef.x;\n", output); shader_addline(buffer, " %s.y = luminance + chroma.y * yuv_coef.y + chroma.x * yuv_coef.z;\n", output); shader_addline(buffer, " %s.z = luminance + chroma.y * yuv_coef.w;\n", output);