gl-renderer: move magic constants into yuva2rgba()

These same magic constants were used in all cases, so move them into a
common place.

While we are touching all these lines, also change from the four floats
into a vec4. This allows further clean-up in the next patch.

This makes the code easier to read.

Behavior and results are unchanged.

Signed-off-by: Pekka Paalanen <pekka.paalanen@collabora.com>
dev
Pekka Paalanen 4 years ago
parent 054ba37084
commit a88144f9e1
  1. 57
      libweston/renderer-gl/fragment.glsl

@ -1,6 +1,6 @@
/* /*
* Copyright 2012 Intel Corporation * Copyright 2012 Intel Corporation
* Copyright 2015,2019 Collabora, Ltd. * Copyright 2015,2019,2021 Collabora, Ltd.
* Copyright 2016 NVIDIA Corporation * Copyright 2016 NVIDIA Corporation
* *
* Permission is hereby granted, free of charge, to any person obtaining * Permission is hereby granted, free of charge, to any person obtaining
@ -53,16 +53,21 @@ const int c_variant = DEF_VARIANT;
const bool c_green_tint = DEF_GREEN_TINT; const bool c_green_tint = DEF_GREEN_TINT;
vec4 vec4
yuva2rgba(float y, float u, float v, float a) yuva2rgba(vec4 yuva)
{ {
vec4 color_out; vec4 color_out;
float Y, su, sv;
color_out.r = y + 1.59602678 * v; Y = 1.16438356 * (yuva.x - 0.0625);
color_out.g = y - 0.39176229 * u - 0.81296764 * v; su = yuva.y - 0.5;
color_out.b = y + 2.01723214 * u; sv = yuva.z - 0.5;
color_out.rgb *= a; color_out.r = Y + 1.59602678 * sv;
color_out.a = a; color_out.g = Y - 0.39176229 * su - 0.81296764 * sv;
color_out.b = Y + 2.01723214 * su;
color_out.rgb *= yuva.w;
color_out.a = yuva.w;
return color_out; return color_out;
} }
@ -82,7 +87,7 @@ uniform vec4 unicolor;
void void
main() main()
{ {
float y, u, v; vec4 yuva;
if (c_variant == SHADER_VARIANT_RGBA || if (c_variant == SHADER_VARIANT_RGBA ||
c_variant == SHADER_VARIANT_EXTERNAL) { c_variant == SHADER_VARIANT_EXTERNAL) {
@ -93,28 +98,32 @@ main()
gl_FragColor.a = alpha; gl_FragColor.a = alpha;
} else if (c_variant == SHADER_VARIANT_Y_U_V) { } else if (c_variant == SHADER_VARIANT_Y_U_V) {
y = 1.16438356 * (texture2D(tex, v_texcoord).x - 0.0625); yuva.x = texture2D(tex, v_texcoord).x;
u = texture2D(tex1, v_texcoord).x - 0.5; yuva.y = texture2D(tex1, v_texcoord).x;
v = texture2D(tex2, v_texcoord).x - 0.5; yuva.z = texture2D(tex2, v_texcoord).x;
gl_FragColor = yuva2rgba(y, u, v, alpha); yuva.w = alpha;
gl_FragColor = yuva2rgba(yuva);
} else if (c_variant == SHADER_VARIANT_Y_UV) { } else if (c_variant == SHADER_VARIANT_Y_UV) {
y = 1.16438356 * (texture2D(tex, v_texcoord).x - 0.0625); yuva.x = texture2D(tex, v_texcoord).x;
u = texture2D(tex1, v_texcoord).r - 0.5; yuva.y = texture2D(tex1, v_texcoord).r;
v = texture2D(tex1, v_texcoord).g - 0.5; yuva.z = texture2D(tex1, v_texcoord).g;
gl_FragColor = yuva2rgba(y, u, v, alpha); yuva.w = alpha;
gl_FragColor = yuva2rgba(yuva);
} else if (c_variant == SHADER_VARIANT_Y_XUXV) { } else if (c_variant == SHADER_VARIANT_Y_XUXV) {
y = 1.16438356 * (texture2D(tex, v_texcoord).x - 0.0625); yuva.x = texture2D(tex, v_texcoord).x;
u = texture2D(tex1, v_texcoord).g - 0.5; yuva.y = texture2D(tex1, v_texcoord).g;
v = texture2D(tex1, v_texcoord).a - 0.5; yuva.z = texture2D(tex1, v_texcoord).a;
gl_FragColor = yuva2rgba(y, u, v, alpha); yuva.w = alpha;
gl_FragColor = yuva2rgba(yuva);
} else if (c_variant == SHADER_VARIANT_XYUV) { } else if (c_variant == SHADER_VARIANT_XYUV) {
y = 1.16438356 * (texture2D(tex, v_texcoord).b - 0.0625); yuva.x = texture2D(tex, v_texcoord).b;
u = texture2D(tex, v_texcoord).g - 0.5; yuva.y = texture2D(tex, v_texcoord).g;
v = texture2D(tex, v_texcoord).r - 0.5; yuva.z = texture2D(tex, v_texcoord).r;
gl_FragColor = yuva2rgba(y, u, v, alpha); yuva.w = alpha;
gl_FragColor = yuva2rgba(yuva);
} else if (c_variant == SHADER_VARIANT_SOLID) { } else if (c_variant == SHADER_VARIANT_SOLID) {
gl_FragColor = alpha * unicolor; gl_FragColor = alpha * unicolor;

Loading…
Cancel
Save