From patchwork Wed Jun 14 10:59:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 18734 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 64DE0BD78E for ; Wed, 14 Jun 2023 11:00:09 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B01DC61E4D; Wed, 14 Jun 2023 13:00:08 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1686740408; bh=eQROTdT7ZMJSPQdwWt73f6ycgzTO5ppoxUmme3gpSds=; h=To:Date:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=2TZAKoyeBXmI3INHPVJM705e0MjwcEFALqGp/Z2HMzB4sRcC6IPQH+PaXw+aRlDn3 8qzmn7x1VWf6wLiyg5fHYSQP9o4NQNFrqp6D5E8TtHkiYxf2ErjFLKRaDgWz4TrW84 HrmIRONTDYDyFhNR4N3Ck/kiGH+LXhX5U+Ob9SDB8azL4lnQZZ7MXNKumnQWQbJDp0 OCDpU4nWIdS1xDE6hIKsTrcS4VoMHAJweYOJdzhKnu933cfD8KXOFCZugCZod/OiOK 7KZu8de+sgN4vBff9pgw5QfsYj4MAfwDdirULE9LdJjtLffnfMWbzX3G1v7p6mTdnC YLgRnuIfDqgsA== Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9556161E4A for ; Wed, 14 Jun 2023 13:00:06 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="FqrwsLGR"; dkim-atps=neutral Received: from uno.lan (unknown [IPv6:2001:b07:5d2e:52c9:72c3:346:a663:c82d]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 8C576BC; Wed, 14 Jun 2023 12:59:35 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1686740375; bh=eQROTdT7ZMJSPQdwWt73f6ycgzTO5ppoxUmme3gpSds=; h=From:To:Cc:Subject:Date:From; b=FqrwsLGRSZ+Up17v4FP1iGOlDSIvYLgcPDRw5EEk0TaDKvPkmNV+fv0uh+8b4LK8B KUbj5tue9Z7s4eh+5Bbeu7de2uhJIBjt2pJOmDE/ZxaTvvSDlSQ1aEzdeYzw30R1p3 8Dj75np/bz83IBQZkj6bpfc0nndjVfOGMJcWYOVE= To: libcamera-devel@lists.libcamera.org Date: Wed, 14 Jun 2023 12:59:57 +0200 Message-Id: <20230614105957.15651-1-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Subject: [libcamera-devel] [PATCH] libcamera: camera_sensor: Adjust properties::Rotation 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: , X-Patchwork-Original-From: Jacopo Mondi via libcamera-devel From: Jacopo Mondi Reply-To: Jacopo Mondi Cc: Jacopo Mondi Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" As the CameraSensor::validateTransform() function compensate for the sensor's mounting rotation, the properties::Rotation value should be adjusted to make sure application that receive already "corrected" images do not get confused by Rotation still reporting a value. However, as an image sensor can only compensate rotations by applying H/V flips, only correct Rotation when the mounting rotation is 180 degrees. Signed-off-by: Jacopo Mondi Reviewed-by: Naushir Patuck Reviewed-by: Umang Jain --- src/libcamera/camera.cpp | 3 +-- src/libcamera/camera_sensor.cpp | 21 ++++++++++++++++++--- 2 files changed, 19 insertions(+), 5 deletions(-) -- 2.40.1 diff --git a/src/libcamera/camera.cpp b/src/libcamera/camera.cpp index 99683e498697..3e252f3b8f8d 100644 --- a/src/libcamera/camera.cpp +++ b/src/libcamera/camera.cpp @@ -397,8 +397,7 @@ CameraConfiguration::Status CameraConfiguration::validateColorSpaces(ColorSpaceF * * The transform is a user-specified 2D plane transform that will be applied * to the camera images by the processing pipeline before being handed to - * the application. This is subsequent to any transform that is already - * required to fix up any platform-defined rotation. + * the application. * * The usual 2D plane transforms are allowed here (horizontal/vertical * flips, multiple of 90-degree rotations etc.), but the validate() function diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index 60bf87b49e6e..f3a5aa37149f 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -461,7 +461,17 @@ int CameraSensor::initProperties() const auto &rotationControl = controls.find(V4L2_CID_CAMERA_SENSOR_ROTATION); if (rotationControl != controls.end()) { + /* + * validateTransform() compensates for the mounting rotation. + * However, as a camera sensor can only compensate rotations + * by applying H/VFlips, only rotation of 180 degrees are + * automatically compensated. The other valid rotations (Rot90 + * and Rot270) require transposition, which the camera sensor + * cannot perform, so leave them untouched. + */ propertyValue = rotationControl->second.def().get(); + if (propertyValue == 180 && supportFlips_) + propertyValue = 0; properties_.set(properties::Rotation, propertyValue); } @@ -1028,10 +1038,15 @@ void CameraSensor::updateControlInfo() */ Transform CameraSensor::validateTransform(Transform *transform) const { - /* Adjust the requested transform to compensate the sensor rotation. */ - int32_t rotation = properties().get(properties::Rotation).value_or(0); - bool success; + /* Adjust the requested transform to compensate the sensor mounting rotation. */ + const ControlInfoMap &controls = subdev_->controls(); + int rotation = 0; + const auto &rotationControl = controls.find(V4L2_CID_CAMERA_SENSOR_ROTATION); + if (rotationControl != controls.end()) + rotation = rotationControl->second.def().get(); + + bool success; Transform rotationTransform = transformFromRotation(rotation, &success); if (!success) LOG(CameraSensor, Warning) << "Invalid rotation of " << rotation