qcam: Add OpenGL shader code as Qt resource

Add OpenGL fragment and vertex shaders to convert two- and tri-planar
YUV formats to RGB. This will be used to accelerate YUV image rendering.

Signed-off-by: Show Liu <show.liu@linaro.org>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
Show Liu 2020-09-11 16:55:11 +08:00 committed by Laurent Pinchart
parent e5e3bf1c71
commit 4a4a3e715b
6 changed files with 123 additions and 0 deletions

View file

@ -0,0 +1,32 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2020, Linaro
*
* NV_2_planes_UV_f.glsl - Fragment shader code for NV12, NV16 and NV24 formats
*/
#ifdef GL_ES
precision mediump float;
#endif
varying vec2 textureOut;
uniform sampler2D tex_y;
uniform sampler2D tex_u;
void main(void)
{
vec3 yuv;
vec3 rgb;
mat3 yuv2rgb_bt601_mat = mat3(
vec3(1.164, 1.164, 1.164),
vec3(0.000, -0.392, 2.017),
vec3(1.596, -0.813, 0.000)
);
yuv.x = texture2D(tex_y, textureOut).r - 0.063;
yuv.y = texture2D(tex_u, textureOut).r - 0.500;
yuv.z = texture2D(tex_u, textureOut).g - 0.500;
rgb = yuv2rgb_bt601_mat * yuv;
gl_FragColor = vec4(rgb, 1.0);
}

View file

@ -0,0 +1,32 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2020, Linaro
*
* NV_2_planes_VU_f.glsl - Fragment shader code for NV21, NV61 and NV42 formats
*/
#ifdef GL_ES
precision mediump float;
#endif
varying vec2 textureOut;
uniform sampler2D tex_y;
uniform sampler2D tex_u;
void main(void)
{
vec3 yuv;
vec3 rgb;
mat3 yuv2rgb_bt601_mat = mat3(
vec3(1.164, 1.164, 1.164),
vec3(0.000, -0.392, 2.017),
vec3(1.596, -0.813, 0.000)
);
yuv.x = texture2D(tex_y, textureOut).r - 0.063;
yuv.y = texture2D(tex_u, textureOut).g - 0.500;
yuv.z = texture2D(tex_u, textureOut).r - 0.500;
rgb = yuv2rgb_bt601_mat * yuv;
gl_FragColor = vec4(rgb, 1.0);
}

View file

@ -0,0 +1,33 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2020, Linaro
*
* NV_3_planes_UV_f.glsl - Fragment shader code for YUV420 format
*/
#ifdef GL_ES
precision mediump float;
#endif
varying vec2 textureOut;
uniform sampler2D tex_y;
uniform sampler2D tex_u;
uniform sampler2D tex_v;
void main(void)
{
vec3 yuv;
vec3 rgb;
mat3 yuv2rgb_bt601_mat = mat3(
vec3(1.164, 1.164, 1.164),
vec3(0.000, -0.392, 2.017),
vec3(1.596, -0.813, 0.000)
);
yuv.x = texture2D(tex_y, textureOut).r - 0.063;
yuv.y = texture2D(tex_u, textureOut).r - 0.500;
yuv.z = texture2D(tex_v, textureOut).r - 0.500;
rgb = yuv2rgb_bt601_mat * yuv;
gl_FragColor = vec4(rgb, 1.0);
}

View file

@ -0,0 +1,16 @@
/* SPDX-License-Identifier: LGPL-2.1-or-later */
/*
* Copyright (C) 2020, Linaro
*
* NV_vertex_shader.glsl - Vertex shader code for NV family
*/
attribute vec4 vertexIn;
attribute vec2 textureIn;
varying vec2 textureOut;
void main(void)
{
gl_Position = vertexIn;
textureOut = textureIn;
}

View file

@ -0,0 +1,9 @@
<!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>./NV_vertex_shader.glsl</file>
<file>./NV_2_planes_UV_f.glsl</file>
<file>./NV_2_planes_VU_f.glsl</file>
<file>./NV_3_planes_f.glsl</file>
</qresource>
</RCC>

View file

@ -16,6 +16,7 @@ qcam_moc_headers = files([
qcam_resources = files([
'assets/feathericons/feathericons.qrc',
'assets/shader/shaders.qrc'
])
qt5 = import('qt5')