From 06f7b1d4ec414a631010a9a3e2ef20a335523bc6 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 4 Jun 2021 14:46:05 +0400 Subject: [PATCH] Fix YUV->RGB shader (YCbCr->RGB really). WebRTC SDK got it wrong. See https://web.archive.org/web/20180421030430/ http://www.equasys.de/colorconversion.html --- ui/gl/gl_shader.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/ui/gl/gl_shader.cpp b/ui/gl/gl_shader.cpp index aa374768..5e5d7f18 100644 --- a/ui/gl/gl_shader.cpp +++ b/ui/gl/gl_shader.cpp @@ -74,10 +74,16 @@ uniform sampler2D u_texture; uniform sampler2D v_texture; )", .body = R"( - float y = texture2D(y_texture, v_texcoord).r; +// float y = texture2D(y_texture, v_texcoord).r; + float y = texture2D(y_texture, v_texcoord).r - 0.0625; float u = texture2D(u_texture, v_texcoord).r - 0.5; float v = texture2D(v_texture, v_texcoord).r - 0.5; - result = vec4(y + 1.403 * v, y - 0.344 * u - 0.714 * v, y + 1.77 * u, 1); +// result = vec4(y + 1.403 * v, y - 0.344 * u - 0.714 * v, y + 1.77 * u, 1); + result = vec4( + 1.164 * y + 1.596 * v, + 1.164 * y - 0.392 * u - 0.813 * v, + 1.164 * y + 2.17 * u, + 1.); )", }; }