From 8700c2223ab60db994376b39e4e74a6309d5154a Mon Sep 17 00:00:00 2001 From: John Preston Date: Tue, 22 Mar 2022 19:45:56 +0400 Subject: [PATCH] Add NV12 -> RGB shader. --- ui/gl/gl_shader.cpp | 31 ++++++++++++++++++++++++++----- ui/gl/gl_shader.h | 1 + 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/ui/gl/gl_shader.cpp b/ui/gl/gl_shader.cpp index 2f47edd..e28bfed 100644 --- a/ui/gl/gl_shader.cpp +++ b/ui/gl/gl_shader.cpp @@ -80,6 +80,16 @@ uniform sampler2D s_texture; }; } +QString FragmentYUV2RGB() { + return R"( + result = vec4( + 1.164 * y + 1.596 * v, + 1.164 * y - 0.392 * u - 0.813 * v, + 1.164 * y + 2.17 * u, + 1.); +)"; +} + ShaderPart FragmentSampleYUV420Texture() { return { .header = R"( @@ -92,12 +102,23 @@ uniform sampler2D v_texture; float y = texture2D(y_texture, v_texcoord).a - 0.0625; float u = texture2D(u_texture, v_texcoord).a - 0.5; float v = texture2D(v_texture, v_texcoord).a - 0.5; - result = vec4( - 1.164 * y + 1.596 * v, - 1.164 * y - 0.392 * u - 0.813 * v, - 1.164 * y + 2.17 * u, - 1.); +)" + FragmentYUV2RGB(), + }; +} + +ShaderPart FragmentSampleNV12Texture() { + return { + .header = R"( +varying vec2 v_texcoord; +uniform sampler2D y_texture; +uniform sampler2D uv_texture; )", + .body = R"( + float y = texture2D(y_texture, v_texcoord).a - 0.0625; + vec2 uv = texture2D(uv_texture, v_texcoord).rg - vec2(0.5, 0.5); + float u = uv.x; + float v = uv.y; +)" + FragmentYUV2RGB(), }; } diff --git a/ui/gl/gl_shader.h b/ui/gl/gl_shader.h index 5dce379..521b311 100644 --- a/ui/gl/gl_shader.h +++ b/ui/gl/gl_shader.h @@ -24,6 +24,7 @@ struct ShaderPart { [[nodiscard]] ShaderPart VertexPassTextureCoord(char prefix = 'v'); [[nodiscard]] ShaderPart FragmentSampleARGB32Texture(); [[nodiscard]] ShaderPart FragmentSampleYUV420Texture(); +[[nodiscard]] ShaderPart FragmentSampleNV12Texture(); [[nodiscard]] ShaderPart FragmentGlobalOpacity(); [[nodiscard]] ShaderPart VertexViewportTransform(); [[nodiscard]] ShaderPart FragmentRoundCorners();