summaryrefslogtreecommitdiff
path: root/src/qcam
diff options
context:
space:
mode:
authorShow Liu <show.liu@linaro.org>2020-09-11 16:55:11 +0800
committerLaurent Pinchart <laurent.pinchart@ideasonboard.com>2020-09-15 05:10:35 +0300
commit4a4a3e715b8314c56a2a32788d92fdec464af7b7 (patch)
treea90149c3a1073c0b03aff8d8d06ef6ec61698074 /src/qcam
parente5e3bf1c711d9ddba34fc9208a4efad5b2adf329 (diff)
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>
Diffstat (limited to 'src/qcam')
-rw-r--r--src/qcam/assets/shader/NV_2_planes_UV_f.glsl32
-rw-r--r--src/qcam/assets/shader/NV_2_planes_VU_f.glsl32
-rw-r--r--src/qcam/assets/shader/NV_3_planes_f.glsl33
-rw-r--r--src/qcam/assets/shader/NV_vertex_shader.glsl16
-rw-r--r--src/qcam/assets/shader/shaders.qrc9
-rw-r--r--src/qcam/meson.build1
6 files changed, 123 insertions, 0 deletions
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 @@
+<!-- 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>
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')