[v7,03/26] qcam: viewfinder_gl: Set no-op Bayer shader values
diff mbox series

Message ID 20251210005354.44726-4-bryan.odonoghue@linaro.org
State New
Headers show
Series
  • Add GLES 2.0 GPUISP to libcamera
Related show

Commit Message

Bryan O'Donoghue Dec. 10, 2025, 12:53 a.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.

Signed-off-by: Bryan O'Donoghue <bryan.odonoghue@linaro.org>
---
 src/apps/qcam/viewfinder_gl.cpp | 25 +++++++++++++++++++++++++
 src/apps/qcam/viewfinder_gl.h   | 12 ++++++++++++
 2 files changed, 37 insertions(+)

Patch
diff mbox series

diff --git a/src/apps/qcam/viewfinder_gl.cpp b/src/apps/qcam/viewfinder_gl.cpp
index 1554c94d5..69b7c6e59 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");
+	contrastUniformDataIn_ = shaderProgram_.uniformLocation("contrast");
 
 	/* Create the textures. */
 	for (std::unique_ptr<QOpenGLTexture> &texture : textures_) {
@@ -542,6 +546,15 @@  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 +801,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(contrastUniformDataIn_, 1.0f);
 		break;
 
 	default:
diff --git a/src/apps/qcam/viewfinder_gl.h b/src/apps/qcam/viewfinder_gl.h
index 23c657bcf..c1b2d9d51 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 contrastUniformDataIn_;
+
 	QMutex mutex_; /* Prevent concurrent access to image_ */
 };