From patchwork Tue Aug 12 07:30:55 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Umang Jain X-Patchwork-Id: 24092 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id DF0B3BEFBE for ; Tue, 12 Aug 2025 07:30:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8628961462; Tue, 12 Aug 2025 09:30:47 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=igalia.com header.i=@igalia.com header.b="d7CD1NqG"; dkim-atps=neutral Received: from fanzine2.igalia.com (fanzine2.igalia.com [213.97.179.56]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B123261462 for ; Tue, 12 Aug 2025 09:30:44 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=igalia.com; s=20170329; h=Content-Transfer-Encoding:MIME-Version:Message-ID:Date:Subject: Cc:To:From:Sender:Reply-To:Content-Type:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: In-Reply-To:References:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=Aw6v+kyy1745CUgmI5r21i1Vr8wdv4G0U57PfWZxLoY=; b=d7CD1NqG0cBOzP03R+jAqCmXUi c30oxgsjG1StzAot9iH63LTA1QhJnmdjq+bKkIMn8OWIXPaUyij0/RTo/YQvOG/uqQZUjIX3igai3 Qqs3A/TF/41wmcaqYMMURbh64MwwYkXlkBL/Bxr8oyaZtSePKY8mSWcG7SR3wL+bsLn0Rq+1Go/Zw mc3Zif5Hxn64lXDAuAPrF2jp8dZWrHcNKfRB0pENgUFjsv2J++kEaXHWxmjyQ4RiPcxLj/xpBvfU3 bWf4DIHeZRolR/daeEMajAhSlI0hlnFWpyBSNSHpD+Lj7QrtSiML8foQO+tJ0aH6q8pITsM8UzxJS B3FJQkGA==; Received: from [49.36.71.143] (helo=uajain) by fanzine2.igalia.com with esmtpsa (Cipher TLS1.3:ECDHE_X25519__RSA_PSS_RSAE_SHA256__AES_256_GCM:256) (Exim) id 1uljT1-00D89M-L4; Tue, 12 Aug 2025 09:30:44 +0200 From: Umang Jain To: libcamera-devel@lists.libcamera.org Cc: Umang Jain Subject: [PATCH v4] libcamera: simple: Detect Bayer pattern change during configure() Date: Tue, 12 Aug 2025 13:00:55 +0530 Message-ID: <20250812073055.5579-1-uajain@igalia.com> X-Mailer: git-send-email 2.50.0 MIME-Version: 1.0 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 --- changes in v4: - Just rebase over new release v0.6.2 test and resend Changes in v3: - Drop addition of 'unicam' in supportedDevices[]. This could be enabled through a global configuration file. Changes in v2: - Pass the updated format(Bayer applied with transforms) to the converter/SoftISP input configuration as well to configure them correctly. --- 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 4323472e..66606a41 100644 --- a/src/libcamera/pipeline/simple/simple.cpp +++ b/src/libcamera/pipeline/simple/simple.cpp @@ -1356,8 +1356,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; @@ -1399,7 +1411,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;