[v2,1/2] libcamera: simple: Detect Bayer pattern change during configure()
diff mbox series

Message ID 20250718094048.59162-2-uajain@igalia.com
State New
Headers show
Series
  • libcamera: simple: Support RPi's unicam CSI-2 receiver
Related show

Commit Message

Umang Jain July 18, 2025, 9:40 a.m. UTC
Bayer pattern on the sensor can change while configuring it with the
intended capture format. This is due to the transform being applied on
the sensor which supports [v/h]flips.

During configure(), the simple pipeline handler does not detect any
bayer pattern changes that can arise due to the transformations being
applied via SimpleCameraData:setupFormats(). In such cases, the video
node will be configured in-correctly, without realising the bayer
pattern has changed on the sensor, for the given capture format.

This patch detects the bayer pattern change after the sensor has
been configured and retrieves the corresponding V4L2 pixel format
to correctly configure the video node and the input to converter or
Soft-ISP.

Signed-off-by: Umang Jain <uajain@igalia.com>
---
 src/libcamera/pipeline/simple/simple.cpp | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

Patch
diff mbox series

diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp
index efb07051..11d56873 100644
--- a/src/libcamera/pipeline/simple/simple.cpp
+++ b/src/libcamera/pipeline/simple/simple.cpp
@@ -1353,8 +1353,20 @@  int SimplePipelineHandler::configure(Camera *camera, CameraConfiguration *c)
 	if (ret < 0)
 		return ret;
 
-	/* Configure the video node. */
-	V4L2PixelFormat videoFormat = video->toV4L2PixelFormat(pipeConfig->captureFormat);
+	/* Configure the video node, taking into account any Bayer pattern change. */
+	V4L2PixelFormat videoFormat;
+	if (format.code == pipeConfig->code) {
+		videoFormat = video->toV4L2PixelFormat(pipeConfig->captureFormat);
+	} else {
+		/*
+		 * Bayer pattern has changed because of the transform that was applied on
+		 * the sensor. Get the V4L2PixelFormat corresponding to the configured Bayer
+		 * pattern.
+		 */
+		BayerFormat cfgBayer = BayerFormat::fromPixelFormat(pipeConfig->captureFormat);
+		cfgBayer.order = data->sensor_->bayerOrder(config->combinedTransform());
+		videoFormat = cfgBayer.toV4L2PixelFormat();
+	}
 
 	V4L2DeviceFormat captureFormat;
 	captureFormat.fourcc = videoFormat;
@@ -1396,7 +1408,7 @@  int SimplePipelineHandler::configure(Camera *camera, CameraConfiguration *c)
 		return 0;
 
 	StreamConfiguration inputCfg;
-	inputCfg.pixelFormat = pipeConfig->captureFormat;
+	inputCfg.pixelFormat = videoFormat.toPixelFormat();
 	inputCfg.size = pipeConfig->captureSize;
 	inputCfg.stride = captureFormat.planes[0].bpl;
 	inputCfg.bufferCount = kNumInternalBuffers;