From 7e8c274d18a77540e11d4565406fd72c0194e775 Mon Sep 17 00:00:00 2001 From: Umang Jain Date: Tue, 12 Aug 2025 13:00:55 +0530 Subject: [PATCH] libcamera: simple: Detect Bayer pattern change during configure() 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 Reviewed-by: Milan Zamazal Tested-by: Milan Zamazal Signed-off-by: Kieran Bingham --- src/libcamera/pipeline/simple/simple.cpp | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/src/libcamera/pipeline/simple/simple.cpp b/src/libcamera/pipeline/simple/simple.cpp index c0d938cf..97009fbc 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -1423,8 +1423,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; @@ -1466,7 +1478,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;