From 9e10811bb5ec1cdace2041714f3235e94446738c Mon Sep 17 00:00:00 2001 From: Laurent Pinchart Date: Mon, 12 Oct 2020 22:02:10 +0300 Subject: qcam: viewfinder_gl: Add support for RGB formats MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Add support for 24-bit and 32-bit RGB formats. The fragment samples the texture and reorders the components, using a pattern set through the RGB_PATTERN macro. The pattern stores the shader vec4 element indices (named {r, g, b, a} by convention, for elements 0 to 3) to be extracted from the texture samples, when interpreted by OpenGL as RGBA. Note that, as textures are created with GL_UNSIGNED_BYTE, the RGBA order corresponds to bytes in memory, while the libcamera formats are named based on the components order in a 32-bit word stored in memory in little endian format. An alternative to manual reordering in the shader would be to set the texture swizzling mask. This is however not available in OpenGL ES before version 3.0, which we don't mandate at the moment. Only the BGR888 and RGB888 formats have been tested, with the vimc pipeline handler. Signed-off-by: Laurent Pinchart Reviewed-by: Andrey Konovalov Reviewed-by: Kieran Bingham Reviewed-by: Niklas Söderlund --- src/qcam/assets/shader/RGB.frag | 22 ++++++++++++++++++++++ src/qcam/assets/shader/shaders.qrc | 1 + 2 files changed, 23 insertions(+) create mode 100644 src/qcam/assets/shader/RGB.frag (limited to 'src/qcam/assets/shader') diff --git a/src/qcam/assets/shader/RGB.frag b/src/qcam/assets/shader/RGB.frag new file mode 100644 index 00000000..4c374ac9 --- /dev/null +++ b/src/qcam/assets/shader/RGB.frag @@ -0,0 +1,22 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * Copyright (C) 2020, Laurent Pinchart + * + * RGB.frag - Fragment shader code for RGB formats + */ + +#ifdef GL_ES +precision mediump float; +#endif + +varying vec2 textureOut; +uniform sampler2D tex_y; + +void main(void) +{ + vec3 rgb; + + rgb = texture2D(tex_y, textureOut).RGB_PATTERN; + + gl_FragColor = vec4(rgb, 1.0); +} diff --git a/src/qcam/assets/shader/shaders.qrc b/src/qcam/assets/shader/shaders.qrc index 86310914..8a8f9de1 100644 --- a/src/qcam/assets/shader/shaders.qrc +++ b/src/qcam/assets/shader/shaders.qrc @@ -1,6 +1,7 @@ + RGB.frag YUV_2_planes.frag YUV_3_planes.frag YUV_packed.frag -- cgit v1.2.1