[1/2] qcam: viewfinder_gl: Take the stride into account for unpacked Bayer
diff mbox series

Message ID 20260830115120.255815-1-christian@themurphys.eu
State New
Headers show
Series
  • [1/2] qcam: viewfinder_gl: Take the stride into account for unpacked Bayer
Related show

Commit Message

Christian Murphy Aug. 30, 2026, 11:51 a.m. UTC
The unpacked Bayer formats upload the frame to a GL_LUMINANCE texture
whose width is the stride, but compute the generic stride factor from
stridePixels = width, yielding 1.0. The bayer_unpacked shaders then
stretch the full stride width across the image width whenever stride
!= width. Commit 5b609e7a44f1 ("libcamera: shaders: Fix input
sampling when width != stride") makes the equivalent correction for
the software ISP GPU debayer path.

Compute the stride factor from the texture width for the unpacked
formats. The packed formats keep stridePixels = width: their fragment
shader samples in byte units and handles the stride via tex_step.

Compile-tested only. No 8-bit Bayer source was available to exercise
qcam's unpacked raw path.

Assisted by Claude Code (claude-fable-5).

Signed-off-by: Christian Murphy <christian@themurphys.eu>
---
 src/apps/qcam/viewfinder_gl.cpp | 11 ++++++++---
 1 file changed, 8 insertions(+), 3 deletions(-)

Comments

Bryan O'Donoghue Aug. 31, 2026, 8:36 a.m. UTC | #1
On 30/08/2026 12:51, Christian Murphy wrote:
> The unpacked Bayer formats upload the frame to a GL_LUMINANCE texture
> whose width is the stride, but compute the generic stride factor from
> stridePixels = width, yielding 1.0. The bayer_unpacked shaders then
> stretch the full stride width across the image width whenever stride
> != width. 


Commit 5b609e7a44f1 ("libcamera: shaders: Fix input
> sampling when width != stride") makes the equivalent correction for
> the software ISP GPU debayer path.

git show 5b609e7a44f1

That commit makes a fix to the unpacked shader, which is not GPUISP 
specific.

If the LLM produced this commit log - it hallucinated this part.
> Compute the stride factor from the texture width for the unpacked
> formats. The packed formats keep stridePixels = width: their fragment
> shader samples in byte units and handles the stride via tex_step.
> 
> Compile-tested only. No 8-bit Bayer source was available to exercise
> qcam's unpacked raw path.
> 
> Assisted by Claude Code (claude-fable-5).

Assisted-by:

> 
> Signed-off-by: Christian Murphy <christian@themurphys.eu>
> ---
>   src/apps/qcam/viewfinder_gl.cpp | 11 ++++++++---
>   1 file changed, 8 insertions(+), 3 deletions(-)
> 
> diff --git a/src/apps/qcam/viewfinder_gl.cpp b/src/apps/qcam/viewfinder_gl.cpp
> index 1d3f48917..138f259f0 100644
> --- a/src/apps/qcam/viewfinder_gl.cpp
> +++ b/src/apps/qcam/viewfinder_gl.cpp
> @@ -546,6 +546,9 @@ void ViewFinderGL::doRender()
>   	/* Stride of the first plane, in pixels. */
>   	unsigned int stridePixels;
>   
> +	/* Whether the raw Bayer format is unpacked. */
> +	bool unpacked = false;
> +
>   	/* Identity CCM */
>   	float ccm[] = { 1.0f, 0.0f, 0.0f,
>   			0.0f, 1.0f, 0.0f,
> @@ -763,6 +766,8 @@ void ViewFinderGL::doRender()
>   	case libcamera::formats::SGBRG8:
>   	case libcamera::formats::SGRBG8:
>   	case libcamera::formats::SRGGB8:
> +		unpacked = true;
> +		[[fallthrough]];
>   	case libcamera::formats::SBGGR10_CSI2P:
>   	case libcamera::formats::SGBRG10_CSI2P:
>   	case libcamera::formats::SGRBG10_CSI2P:
> @@ -798,10 +803,10 @@ void ViewFinderGL::doRender()
>   					       1.0f / (size_.height() - 1));
>   
>   		/*
> -		 * The stride is already taken into account in the shaders, set
> -		 * the generic stride factor to 1.0.
> +		 * The packed shaders handle the stride themselves through
> +		 * tex_step; only the unpacked shaders need the stride factor.
>   		 */
> -		stridePixels = size_.width();
> +		stridePixels = unpacked ? stride_ : size_.width();
>   
>   		/* Colour Correction Matrix */
>   		shaderProgram_.setUniformValue(ccmUniformDataIn_, qCcmMat);

Patch
diff mbox series

diff --git a/src/apps/qcam/viewfinder_gl.cpp b/src/apps/qcam/viewfinder_gl.cpp
index 1d3f48917..138f259f0 100644
--- a/src/apps/qcam/viewfinder_gl.cpp
+++ b/src/apps/qcam/viewfinder_gl.cpp
@@ -546,6 +546,9 @@  void ViewFinderGL::doRender()
 	/* Stride of the first plane, in pixels. */
 	unsigned int stridePixels;
 
+	/* Whether the raw Bayer format is unpacked. */
+	bool unpacked = false;
+
 	/* Identity CCM */
 	float ccm[] = { 1.0f, 0.0f, 0.0f,
 			0.0f, 1.0f, 0.0f,
@@ -763,6 +766,8 @@  void ViewFinderGL::doRender()
 	case libcamera::formats::SGBRG8:
 	case libcamera::formats::SGRBG8:
 	case libcamera::formats::SRGGB8:
+		unpacked = true;
+		[[fallthrough]];
 	case libcamera::formats::SBGGR10_CSI2P:
 	case libcamera::formats::SGBRG10_CSI2P:
 	case libcamera::formats::SGRBG10_CSI2P:
@@ -798,10 +803,10 @@  void ViewFinderGL::doRender()
 					       1.0f / (size_.height() - 1));
 
 		/*
-		 * The stride is already taken into account in the shaders, set
-		 * the generic stride factor to 1.0.
+		 * The packed shaders handle the stride themselves through
+		 * tex_step; only the unpacked shaders need the stride factor.
 		 */
-		stridePixels = size_.width();
+		stridePixels = unpacked ? stride_ : size_.width();
 
 		/* Colour Correction Matrix */
 		shaderProgram_.setUniformValue(ccmUniformDataIn_, qCcmMat);