From 4a4a3e715b8314c56a2a32788d92fdec464af7b7 Mon Sep 17 00:00:00 2001 From: Show Liu Date: Fri, 11 Sep 2020 16:55:11 +0800 Subject: 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 Reviewed-by: Laurent Pinchart Signed-off-by: Laurent Pinchart --- src/qcam/assets/shader/NV_2_planes_UV_f.glsl | 32 +++++++++++++++++++++++++++ src/qcam/assets/shader/NV_2_planes_VU_f.glsl | 32 +++++++++++++++++++++++++++ src/qcam/assets/shader/NV_3_planes_f.glsl | 33 ++++++++++++++++++++++++++++ src/qcam/assets/shader/NV_vertex_shader.glsl | 16 ++++++++++++++ src/qcam/assets/shader/shaders.qrc | 9 ++++++++ src/qcam/meson.build | 1 + 6 files changed, 123 insertions(+) create mode 100644 src/qcam/assets/shader/NV_2_planes_UV_f.glsl create mode 100644 src/qcam/assets/shader/NV_2_planes_VU_f.glsl create mode 100644 src/qcam/assets/shader/NV_3_planes_f.glsl create mode 100644 src/qcam/assets/shader/NV_vertex_shader.glsl create mode 100644 src/qcam/assets/shader/shaders.qrc (limited to 'src') diff --git a/src/qcam/assets/shader/NV_2_planes_UV_f.glsl b/src/qcam/assets/shader/NV_2_planes_UV_f.glsl new file mode 100644 index 00000000..67633a11 --- /dev/null +++ b/src/qcam/assets/shader/NV_2_planes_UV_f.glsl @@ -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); +} diff --git a/src/qcam/assets/shader/NV_2_planes_VU_f.glsl b/src/qcam/assets/shader/NV_2_planes_VU_f.glsl new file mode 100644 index 00000000..086c5b6d --- /dev/null +++ b/src/qcam/assets/shader/NV_2_planes_VU_f.glsl @@ -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); +} diff --git a/src/qcam/assets/shader/NV_3_planes_f.glsl b/src/qcam/assets/shader/NV_3_planes_f.glsl new file mode 100644 index 00000000..4bc94184 --- /dev/null +++ b/src/qcam/assets/shader/NV_3_planes_f.glsl @@ -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); +} diff --git a/src/qcam/assets/shader/NV_vertex_shader.glsl b/src/qcam/assets/shader/NV_vertex_shader.glsl new file mode 100644 index 00000000..12e791e3 --- /dev/null +++ b/src/qcam/assets/shader/NV_vertex_shader.glsl @@ -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; +} diff --git a/src/qcam/assets/shader/shaders.qrc b/src/qcam/assets/shader/shaders.qrc new file mode 100644 index 00000000..33eab278 --- /dev/null +++ b/src/qcam/assets/shader/shaders.qrc @@ -0,0 +1,9 @@ + + + +./NV_vertex_shader.glsl +./NV_2_planes_UV_f.glsl +./NV_2_planes_VU_f.glsl +./NV_3_planes_f.glsl + + diff --git a/src/qcam/meson.build b/src/qcam/meson.build index 6ea886a3..e0c6f26d 100644 --- a/src/qcam/meson.build +++ b/src/qcam/meson.build @@ -16,6 +16,7 @@ qcam_moc_headers = files([ qcam_resources = files([ 'assets/feathericons/feathericons.qrc', + 'assets/shader/shaders.qrc' ]) qt5 = import('qt5') -- cgit v1.2.1