mirror of
https://git.libcamera.org/libcamera/libcamera.git
synced 2025-07-26 01:55:51 +03:00
qcam: viewfinder_gl: Add support for RAW8 Bayer formats
This integrates the vertex and the fragment shaders by Morgan McGuire into qcam. Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
This commit is contained in:
parent
e4be72d0ca
commit
43fd7d0fc8
4 changed files with 62 additions and 16 deletions
|
@ -9,20 +9,23 @@ Morgan McGuire
|
||||||
This paper appears in issue Volume 13, Number 4.
|
This paper appears in issue Volume 13, Number 4.
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
Copyright (c) 2008, Morgan McGuire. All rights reserved.
|
Copyright (c) 2008, Morgan McGuire. All rights reserved.
|
||||||
|
|
||||||
|
Modified by Linaro Ltd to integrate it into libcamera.
|
||||||
|
Copyright (C) 2021, Linaro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//Pixel Shader
|
//Pixel Shader
|
||||||
|
|
||||||
/** Monochrome RGBA or GL_LUMINANCE Bayer encoded texture.*/
|
/** Monochrome RGBA or GL_LUMINANCE Bayer encoded texture.*/
|
||||||
uniform sampler2D source;
|
uniform sampler2D tex_y;
|
||||||
varying vec4 center;
|
varying vec4 center;
|
||||||
varying vec4 yCoord;
|
varying vec4 yCoord;
|
||||||
varying vec4 xCoord;
|
varying vec4 xCoord;
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
#define fetch(x, y) texture2D(source, vec2(x, y)).r
|
#define fetch(x, y) texture2D(tex_y, vec2(x, y)).r
|
||||||
|
|
||||||
float C = texture2D(source, center.xy).r; // ( 0, 0)
|
float C = texture2D(tex_y, center.xy).r; // ( 0, 0)
|
||||||
const vec4 kC = vec4( 4.0, 6.0, 5.0, 5.0) / 8.0;
|
const vec4 kC = vec4( 4.0, 6.0, 5.0, 5.0) / 8.0;
|
||||||
|
|
||||||
// Determine which of four types of pixels we are on.
|
// Determine which of four types of pixels we are on.
|
||||||
|
|
|
@ -9,17 +9,22 @@ Morgan McGuire
|
||||||
This paper appears in issue Volume 13, Number 4.
|
This paper appears in issue Volume 13, Number 4.
|
||||||
---------------------------------------------------------
|
---------------------------------------------------------
|
||||||
Copyright (c) 2008, Morgan McGuire. All rights reserved.
|
Copyright (c) 2008, Morgan McGuire. All rights reserved.
|
||||||
|
|
||||||
|
Modified by Linaro Ltd to integrate it into libcamera.
|
||||||
|
Copyright (C) 2021, Linaro
|
||||||
*/
|
*/
|
||||||
|
|
||||||
//Vertex Shader
|
//Vertex Shader
|
||||||
|
|
||||||
|
attribute vec4 vertexIn;
|
||||||
|
attribute vec2 textureIn;
|
||||||
|
|
||||||
/** (w,h,1/w,1/h) */
|
uniform vec2 tex_size; /* The texture size in pixels */
|
||||||
uniform vec4 sourceSize;
|
uniform vec2 tex_step;
|
||||||
|
|
||||||
/** Pixel position of the first red pixel in the */
|
/** Pixel position of the first red pixel in the */
|
||||||
/** Bayer pattern. [{0,1}, {0, 1}]*/
|
/** Bayer pattern. [{0,1}, {0, 1}]*/
|
||||||
uniform vec2 firstRed;
|
uniform vec2 tex_bayer_first_red;
|
||||||
|
|
||||||
/** .xy = Pixel being sampled in the fragment shader on the range [0, 1]
|
/** .xy = Pixel being sampled in the fragment shader on the range [0, 1]
|
||||||
.zw = ...on the range [0, sourceSize], offset by firstRed */
|
.zw = ...on the range [0, sourceSize], offset by firstRed */
|
||||||
|
@ -34,14 +39,13 @@ varying vec4 xCoord;
|
||||||
varying vec4 yCoord;
|
varying vec4 yCoord;
|
||||||
|
|
||||||
void main(void) {
|
void main(void) {
|
||||||
center.xy = gl_MultiTexCoord0.xy;
|
center.xy = textureIn;
|
||||||
center.zw = gl_MultiTexCoord0.xy * sourceSize.xy + firstRed;
|
center.zw = textureIn * tex_size + tex_bayer_first_red;
|
||||||
|
|
||||||
vec2 invSize = sourceSize.zw;
|
xCoord = center.x + vec4(-2.0 * tex_step.x,
|
||||||
xCoord = center.x + vec4(-2.0 * invSize.x,
|
-tex_step.x, tex_step.x, 2.0 * tex_step.x);
|
||||||
-invSize.x, invSize.x, 2.0 * invSize.x);
|
yCoord = center.y + vec4(-2.0 * tex_step.y,
|
||||||
yCoord = center.y + vec4(-2.0 * invSize.y,
|
-tex_step.y, tex_step.y, 2.0 * tex_step.y);
|
||||||
-invSize.y, invSize.y, 2.0 * invSize.y);
|
|
||||||
|
|
||||||
gl_Position = gl_ModelViewProjectionMatrix * gl_Vertex;
|
gl_Position = vertexIn;
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,6 +6,8 @@
|
||||||
<file>YUV_3_planes.frag</file>
|
<file>YUV_3_planes.frag</file>
|
||||||
<file>YUV_packed.frag</file>
|
<file>YUV_packed.frag</file>
|
||||||
<file>bayer_1x_packed.frag</file>
|
<file>bayer_1x_packed.frag</file>
|
||||||
|
<file>bayer_8.frag</file>
|
||||||
|
<file>bayer_8.vert</file>
|
||||||
<file>identity.vert</file>
|
<file>identity.vert</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
|
|
@ -36,6 +36,11 @@ static const QList<libcamera::PixelFormat> supportedFormats{
|
||||||
libcamera::formats::RGBA8888,
|
libcamera::formats::RGBA8888,
|
||||||
libcamera::formats::BGR888,
|
libcamera::formats::BGR888,
|
||||||
libcamera::formats::RGB888,
|
libcamera::formats::RGB888,
|
||||||
|
/* Raw Bayer 8-bit */
|
||||||
|
libcamera::formats::SBGGR8,
|
||||||
|
libcamera::formats::SGBRG8,
|
||||||
|
libcamera::formats::SGRBG8,
|
||||||
|
libcamera::formats::SRGGB8,
|
||||||
/* Raw Bayer 10-bit packed */
|
/* Raw Bayer 10-bit packed */
|
||||||
libcamera::formats::SBGGR10_CSI2P,
|
libcamera::formats::SBGGR10_CSI2P,
|
||||||
libcamera::formats::SGBRG10_CSI2P,
|
libcamera::formats::SGBRG10_CSI2P,
|
||||||
|
@ -223,6 +228,34 @@ bool ViewFinderGL::selectFormat(const libcamera::PixelFormat &format)
|
||||||
fragmentShaderDefines_.append("#define RGB_PATTERN bgr");
|
fragmentShaderDefines_.append("#define RGB_PATTERN bgr");
|
||||||
fragmentShaderFile_ = ":RGB.frag";
|
fragmentShaderFile_ = ":RGB.frag";
|
||||||
break;
|
break;
|
||||||
|
case libcamera::formats::SBGGR8:
|
||||||
|
firstRed_.setX(1.0);
|
||||||
|
firstRed_.setY(1.0);
|
||||||
|
vertexShaderFile_ = ":bayer_8.vert";
|
||||||
|
fragmentShaderFile_ = ":bayer_8.frag";
|
||||||
|
textureMinMagFilters_ = GL_NEAREST;
|
||||||
|
break;
|
||||||
|
case libcamera::formats::SGBRG8:
|
||||||
|
firstRed_.setX(0.0);
|
||||||
|
firstRed_.setY(1.0);
|
||||||
|
vertexShaderFile_ = ":bayer_8.vert";
|
||||||
|
fragmentShaderFile_ = ":bayer_8.frag";
|
||||||
|
textureMinMagFilters_ = GL_NEAREST;
|
||||||
|
break;
|
||||||
|
case libcamera::formats::SGRBG8:
|
||||||
|
firstRed_.setX(1.0);
|
||||||
|
firstRed_.setY(0.0);
|
||||||
|
vertexShaderFile_ = ":bayer_8.vert";
|
||||||
|
fragmentShaderFile_ = ":bayer_8.frag";
|
||||||
|
textureMinMagFilters_ = GL_NEAREST;
|
||||||
|
break;
|
||||||
|
case libcamera::formats::SRGGB8:
|
||||||
|
firstRed_.setX(0.0);
|
||||||
|
firstRed_.setY(0.0);
|
||||||
|
vertexShaderFile_ = ":bayer_8.vert";
|
||||||
|
fragmentShaderFile_ = ":bayer_8.frag";
|
||||||
|
textureMinMagFilters_ = GL_NEAREST;
|
||||||
|
break;
|
||||||
case libcamera::formats::SBGGR10_CSI2P:
|
case libcamera::formats::SBGGR10_CSI2P:
|
||||||
firstRed_.setX(1.0);
|
firstRed_.setX(1.0);
|
||||||
firstRed_.setY(1.0);
|
firstRed_.setY(1.0);
|
||||||
|
@ -627,6 +660,10 @@ void ViewFinderGL::doRender()
|
||||||
shaderProgram_.setUniformValue(textureUniformY_, 0);
|
shaderProgram_.setUniformValue(textureUniformY_, 0);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
case libcamera::formats::SBGGR8:
|
||||||
|
case libcamera::formats::SGBRG8:
|
||||||
|
case libcamera::formats::SGRBG8:
|
||||||
|
case libcamera::formats::SRGGB8:
|
||||||
case libcamera::formats::SBGGR10_CSI2P:
|
case libcamera::formats::SBGGR10_CSI2P:
|
||||||
case libcamera::formats::SGBRG10_CSI2P:
|
case libcamera::formats::SGBRG10_CSI2P:
|
||||||
case libcamera::formats::SGRBG10_CSI2P:
|
case libcamera::formats::SGRBG10_CSI2P:
|
||||||
|
@ -636,8 +673,8 @@ void ViewFinderGL::doRender()
|
||||||
case libcamera::formats::SGRBG12_CSI2P:
|
case libcamera::formats::SGRBG12_CSI2P:
|
||||||
case libcamera::formats::SRGGB12_CSI2P:
|
case libcamera::formats::SRGGB12_CSI2P:
|
||||||
/*
|
/*
|
||||||
* Packed raw Bayer 10-bit and 12-bit formats are stored in
|
* Raw Bayer 8-bit, and packed raw Bayer 10-bit/12-bit formats
|
||||||
* GL_RED texture.
|
* are stored in GL_RED texture.
|
||||||
* The texture width is equal to the stride.
|
* The texture width is equal to the stride.
|
||||||
*/
|
*/
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue