mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-23 00:25:07 +03:00
qcam: viewfinder_gl: Add support for RGB formats
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 <laurent.pinchart@ideasonboard.com> Reviewed-by: Andrey Konovalov <andrey.konovalov@linaro.org> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>
This commit is contained in:
parent
3badc5c4be
commit
9e10811bb5
3 changed files with 91 additions and 3 deletions
22
src/qcam/assets/shader/RGB.frag
Normal file
22
src/qcam/assets/shader/RGB.frag
Normal file
|
@ -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);
|
||||
}
|
|
@ -1,6 +1,7 @@
|
|||
<!-- SPDX-License-Identifier: LGPL-2.1-or-later -->
|
||||
<!DOCTYPE RCC><RCC version="1.0">
|
||||
<qresource>
|
||||
<file>RGB.frag</file>
|
||||
<file>YUV_2_planes.frag</file>
|
||||
<file>YUV_3_planes.frag</file>
|
||||
<file>YUV_packed.frag</file>
|
||||
|
|
|
@ -14,21 +14,28 @@
|
|||
#include <libcamera/formats.h>
|
||||
|
||||
static const QList<libcamera::PixelFormat> supportedFormats{
|
||||
/* Packed (single plane) */
|
||||
/* YUV - packed (single plane) */
|
||||
libcamera::formats::UYVY,
|
||||
libcamera::formats::VYUY,
|
||||
libcamera::formats::YUYV,
|
||||
libcamera::formats::YVYU,
|
||||
/* Semi planar (two planes) */
|
||||
/* YUV - semi planar (two planes) */
|
||||
libcamera::formats::NV12,
|
||||
libcamera::formats::NV21,
|
||||
libcamera::formats::NV16,
|
||||
libcamera::formats::NV61,
|
||||
libcamera::formats::NV24,
|
||||
libcamera::formats::NV42,
|
||||
/* Fully planar (three planes) */
|
||||
/* YUV - fully planar (three planes) */
|
||||
libcamera::formats::YUV420,
|
||||
libcamera::formats::YVU420,
|
||||
/* RGB */
|
||||
libcamera::formats::ABGR8888,
|
||||
libcamera::formats::ARGB8888,
|
||||
libcamera::formats::BGRA8888,
|
||||
libcamera::formats::RGBA8888,
|
||||
libcamera::formats::BGR888,
|
||||
libcamera::formats::RGB888,
|
||||
};
|
||||
|
||||
ViewFinderGL::ViewFinderGL(QWidget *parent)
|
||||
|
@ -172,6 +179,30 @@ bool ViewFinderGL::selectFormat(const libcamera::PixelFormat &format)
|
|||
fragmentShaderDefines_.append("#define YUV_PATTERN_YVYU");
|
||||
fragmentShaderFile_ = ":YUV_packed.frag";
|
||||
break;
|
||||
case libcamera::formats::ABGR8888:
|
||||
fragmentShaderDefines_.append("#define RGB_PATTERN rgb");
|
||||
fragmentShaderFile_ = ":RGB.frag";
|
||||
break;
|
||||
case libcamera::formats::ARGB8888:
|
||||
fragmentShaderDefines_.append("#define RGB_PATTERN bgr");
|
||||
fragmentShaderFile_ = ":RGB.frag";
|
||||
break;
|
||||
case libcamera::formats::BGRA8888:
|
||||
fragmentShaderDefines_.append("#define RGB_PATTERN gba");
|
||||
fragmentShaderFile_ = ":RGB.frag";
|
||||
break;
|
||||
case libcamera::formats::RGBA8888:
|
||||
fragmentShaderDefines_.append("#define RGB_PATTERN abg");
|
||||
fragmentShaderFile_ = ":RGB.frag";
|
||||
break;
|
||||
case libcamera::formats::BGR888:
|
||||
fragmentShaderDefines_.append("#define RGB_PATTERN rgb");
|
||||
fragmentShaderFile_ = ":RGB.frag";
|
||||
break;
|
||||
case libcamera::formats::RGB888:
|
||||
fragmentShaderDefines_.append("#define RGB_PATTERN bgr");
|
||||
fragmentShaderFile_ = ":RGB.frag";
|
||||
break;
|
||||
default:
|
||||
ret = false;
|
||||
qWarning() << "[ViewFinderGL]:"
|
||||
|
@ -481,6 +512,40 @@ void ViewFinderGL::doRender()
|
|||
1.0f / (size_.width() / 2 - 1));
|
||||
break;
|
||||
|
||||
case libcamera::formats::ABGR8888:
|
||||
case libcamera::formats::ARGB8888:
|
||||
case libcamera::formats::BGRA8888:
|
||||
case libcamera::formats::RGBA8888:
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
configureTexture(*textures_[0]);
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGBA,
|
||||
size_.width(),
|
||||
size_.height(),
|
||||
0,
|
||||
GL_RGBA,
|
||||
GL_UNSIGNED_BYTE,
|
||||
data_);
|
||||
shaderProgram_.setUniformValue(textureUniformY_, 0);
|
||||
break;
|
||||
|
||||
case libcamera::formats::BGR888:
|
||||
case libcamera::formats::RGB888:
|
||||
glActiveTexture(GL_TEXTURE0);
|
||||
configureTexture(*textures_[0]);
|
||||
glTexImage2D(GL_TEXTURE_2D,
|
||||
0,
|
||||
GL_RGB,
|
||||
size_.width(),
|
||||
size_.height(),
|
||||
0,
|
||||
GL_RGB,
|
||||
GL_UNSIGNED_BYTE,
|
||||
data_);
|
||||
shaderProgram_.setUniformValue(textureUniformY_, 0);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue