[v11,04/24] qcam: viewfinder_gl: Set no-op Bayer shader values
diff mbox series

Message ID 20260106170059.56193-5-bryan.odonoghue@linaro.org
State Accepted
Commit 76973876b8b593352c10b766c50daaa3d575c96b
Headers show
Series
  • Add GLES 2.0 GPUISP to libcamera
Related show

Commit Message

Bryan O'Donoghue Jan. 6, 2026, 5 p.m. UTC
Populate qcam viewfinder_gl to set default Bayer values so that the
shaders can be used in their original mode without conditional compilation.

Set an identity CCM, identity Black Level and set Gamma and Contrast to
1.0f respectively.

Once this change is made we can use the Bayer shaders in their original
format in qcam with raw streams.

Reviewed-by: Milan Zamazal <mzamazal@redhat.com>
Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
---
 src/apps/qcam/viewfinder_gl.cpp | 26 ++++++++++++++++++++++++++
 src/apps/qcam/viewfinder_gl.h   | 12 ++++++++++++
 2 files changed, 38 insertions(+)

Comments

Kieran Bingham Jan. 7, 2026, 9:58 a.m. UTC | #1
Quoting Bryan O'Donoghue (2026-01-06 17:00:39)
> Populate qcam viewfinder_gl to set default Bayer values so that the
> shaders can be used in their original mode without conditional compilation.
> 
> Set an identity CCM, identity Black Level and set Gamma and Contrast to
> 1.0f respectively.
> 
> Once this change is made we can use the Bayer shaders in their original
> format in qcam with raw streams.
> 
> Reviewed-by: Milan Zamazal <mzamazal@redhat.com>

I don't really fully understand the magic of shaders here - but
everything looks sensible, and once tested I'm fine with this being
merged so:

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
> ---
>  src/apps/qcam/viewfinder_gl.cpp | 26 ++++++++++++++++++++++++++
>  src/apps/qcam/viewfinder_gl.h   | 12 ++++++++++++
>  2 files changed, 38 insertions(+)
> 
> diff --git a/src/apps/qcam/viewfinder_gl.cpp b/src/apps/qcam/viewfinder_gl.cpp
> index 1554c94d5..0d06122f6 100644
> --- a/src/apps/qcam/viewfinder_gl.cpp
> +++ b/src/apps/qcam/viewfinder_gl.cpp
> @@ -473,6 +473,10 @@ bool ViewFinderGL::createFragmentShader()
>         textureUniformSize_ = shaderProgram_.uniformLocation("tex_size");
>         textureUniformStrideFactor_ = shaderProgram_.uniformLocation("stride_factor");
>         textureUniformBayerFirstRed_ = shaderProgram_.uniformLocation("tex_bayer_first_red");
> +       ccmUniformDataIn_ = shaderProgram_.uniformLocation("ccm");
> +       blackLevelUniformDataIn_ = shaderProgram_.uniformLocation("blacklevel");
> +       gammaUniformDataIn_ = shaderProgram_.uniformLocation("gamma");
> +       contrastExpUniformDataIn_ = shaderProgram_.uniformLocation("contrastExp");
>  
>         /* Create the textures. */
>         for (std::unique_ptr<QOpenGLTexture> &texture : textures_) {
> @@ -542,6 +546,16 @@ void ViewFinderGL::doRender()
>         /* Stride of the first plane, in pixels. */
>         unsigned int stridePixels;
>  
> +       /* Identity CCM */
> +       float ccm[] = { 1.0f, 0.0f, 0.0f,
> +                       0.0f, 1.0f, 0.0f,
> +                       0.0f, 0.0f, 1.0f };
> +
> +       QMatrix3x3 qCcmMat(ccm);
> +
> +       /* Black Level */
> +       QVector3D qBlackLevelVec(0.0f, 0.0f, 0.0f);
> +
>         switch (format_) {
>         case libcamera::formats::NV12:
>         case libcamera::formats::NV21:
> @@ -788,6 +802,18 @@ void ViewFinderGL::doRender()
>                  * the generic stride factor to 1.0.
>                  */
>                 stridePixels = size_.width();
> +
> +               /* Colour Correction Matrix */
> +               shaderProgram_.setUniformValue(ccmUniformDataIn_, qCcmMat);
> +
> +               /* Black Level */
> +               shaderProgram_.setUniformValue(blackLevelUniformDataIn_, qBlackLevelVec);
> +
> +               /* Gamma */
> +               shaderProgram_.setUniformValue(gammaUniformDataIn_, 1.0f);
> +
> +               /* Contrast */
> +               shaderProgram_.setUniformValue(contrastExpUniformDataIn_, 1.0f);
>                 break;
>  
>         default:
> diff --git a/src/apps/qcam/viewfinder_gl.h b/src/apps/qcam/viewfinder_gl.h
> index 23c657bcf..1aa85e4fc 100644
> --- a/src/apps/qcam/viewfinder_gl.h
> +++ b/src/apps/qcam/viewfinder_gl.h
> @@ -103,5 +103,17 @@ private:
>         GLuint textureUniformBayerFirstRed_;
>         QPointF firstRed_;
>  
> +       /* Represent per-frame CCM as a uniform vector of floats 3 x 3 */
> +       GLint ccmUniformDataIn_;
> +
> +       /* Black Level compensation */
> +       GLint blackLevelUniformDataIn_;
> +
> +       /* Gamma */
> +       GLint gammaUniformDataIn_;
> +
> +       /* Contrast */
> +       GLint contrastExpUniformDataIn_;
> +
>         QMutex mutex_; /* Prevent concurrent access to image_ */
>  };
> -- 
> 2.52.0
>

Patch
diff mbox series

diff --git a/src/apps/qcam/viewfinder_gl.cpp b/src/apps/qcam/viewfinder_gl.cpp
index 1554c94d5..0d06122f6 100644
--- a/src/apps/qcam/viewfinder_gl.cpp
+++ b/src/apps/qcam/viewfinder_gl.cpp
@@ -473,6 +473,10 @@  bool ViewFinderGL::createFragmentShader()
 	textureUniformSize_ = shaderProgram_.uniformLocation("tex_size");
 	textureUniformStrideFactor_ = shaderProgram_.uniformLocation("stride_factor");
 	textureUniformBayerFirstRed_ = shaderProgram_.uniformLocation("tex_bayer_first_red");
+	ccmUniformDataIn_ = shaderProgram_.uniformLocation("ccm");
+	blackLevelUniformDataIn_ = shaderProgram_.uniformLocation("blacklevel");
+	gammaUniformDataIn_ = shaderProgram_.uniformLocation("gamma");
+	contrastExpUniformDataIn_ = shaderProgram_.uniformLocation("contrastExp");
 
 	/* Create the textures. */
 	for (std::unique_ptr<QOpenGLTexture> &texture : textures_) {
@@ -542,6 +546,16 @@  void ViewFinderGL::doRender()
 	/* Stride of the first plane, in pixels. */
 	unsigned int stridePixels;
 
+	/* Identity CCM */
+	float ccm[] = { 1.0f, 0.0f, 0.0f,
+			0.0f, 1.0f, 0.0f,
+			0.0f, 0.0f, 1.0f };
+
+	QMatrix3x3 qCcmMat(ccm);
+
+	/* Black Level */
+	QVector3D qBlackLevelVec(0.0f, 0.0f, 0.0f);
+
 	switch (format_) {
 	case libcamera::formats::NV12:
 	case libcamera::formats::NV21:
@@ -788,6 +802,18 @@  void ViewFinderGL::doRender()
 		 * the generic stride factor to 1.0.
 		 */
 		stridePixels = size_.width();
+
+		/* Colour Correction Matrix */
+		shaderProgram_.setUniformValue(ccmUniformDataIn_, qCcmMat);
+
+		/* Black Level */
+		shaderProgram_.setUniformValue(blackLevelUniformDataIn_, qBlackLevelVec);
+
+		/* Gamma */
+		shaderProgram_.setUniformValue(gammaUniformDataIn_, 1.0f);
+
+		/* Contrast */
+		shaderProgram_.setUniformValue(contrastExpUniformDataIn_, 1.0f);
 		break;
 
 	default:
diff --git a/src/apps/qcam/viewfinder_gl.h b/src/apps/qcam/viewfinder_gl.h
index 23c657bcf..1aa85e4fc 100644
--- a/src/apps/qcam/viewfinder_gl.h
+++ b/src/apps/qcam/viewfinder_gl.h
@@ -103,5 +103,17 @@  private:
 	GLuint textureUniformBayerFirstRed_;
 	QPointF firstRed_;
 
+	/* Represent per-frame CCM as a uniform vector of floats 3 x 3 */
+	GLint ccmUniformDataIn_;
+
+	/* Black Level compensation */
+	GLint blackLevelUniformDataIn_;
+
+	/* Gamma */
+	GLint gammaUniformDataIn_;
+
+	/* Contrast */
+	GLint contrastExpUniformDataIn_;
+
 	QMutex mutex_; /* Prevent concurrent access to image_ */
 };