From patchwork Tue Jun 20 14:29:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jacopo Mondi X-Patchwork-Id: 18752 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 741C2C3292 for ; Tue, 20 Jun 2023 14:29:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3F9C3628C8; Tue, 20 Jun 2023 16:29:20 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org; s=mail; t=1687271360; bh=isx0kpb7PaWO8SQy8nMzry65L0CBhbgORYCCL5eWRR4=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:Cc: From; b=sC0q5z5waHJlStRkMrzkLkopUzs1E0Reb2R9wXKwpkxztjhgfZ7iME4Ny7FTCmGX9 hRCxFmEYlAp8L7Hj9gA8ugzTCC79shdecDDF9G+bQY9eKMAa13/q4NvFVZWv2HfPlC qlexOWDbSO7GnUwUYria8H2p+YLxN7NEdT1Km3NsniZijZy0LBbsaEWPKPSMN8WN+e xeeUAz35yjREGtZaOoc7OZXXBQlXJFqutkPR3UZUleS7KqtneMeFKw1K9Q8wQe7FKq Mn1Wwy44Zi+kpLdCHaSzmjIdMz1OohXen6r+xSds1xajrgPIsgEVlbrbWcEOYiIQlD f0XoHKv/bW7Bw== 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 52B5F617B2 for ; Tue, 20 Jun 2023 16:29:18 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="SGDGEqhL"; 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 2DFCB10FE; Tue, 20 Jun 2023 16:28:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1687271323; bh=isx0kpb7PaWO8SQy8nMzry65L0CBhbgORYCCL5eWRR4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SGDGEqhL0Y2+qW3Lc14yhenyFDVn1rTGJtd4udWsCpHl85a95rC+rBICN9l2FT3HE iWhXbnlr8d5thgJprZn99qm81Y1nqWd0XqL54U38cM9mMOwr0zV104tJx2STHnJ/aY +tOqzfJ9CqerDh8CQ49CvlpXoPhA8czGrIHf1ZU0= To: libcamera-devel@lists.libcamera.org Date: Tue, 20 Jun 2023 16:29:01 +0200 Message-Id: <20230620142904.72600-2-jacopo.mondi@ideasonboard.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20230620142904.72600-1-jacopo.mondi@ideasonboard.com> References: <20230620142904.72600-1-jacopo.mondi@ideasonboard.com> MIME-Version: 1.0 Subject: [libcamera-devel] [RFC 1/4] libcamera: camera_sensor: Cache rotationTransform_ 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" The rotationTransform_ depends on a V4L2 control whose value does not change for the whole lifetime of the camera. Instead of re-calculating it everytime the camera is configured, cache it at properties initialization time. Signed-off-by: Jacopo Mondi Reviewed-by: Umang Jain Reviewed-by: Laurent Pinchart --- include/libcamera/internal/camera_sensor.h | 1 + src/libcamera/camera_sensor.cpp | 54 +++++++++++++--------- 2 files changed, 32 insertions(+), 23 deletions(-) diff --git a/include/libcamera/internal/camera_sensor.h b/include/libcamera/internal/camera_sensor.h index 02c77ab037da..02b4b4d25e6d 100644 --- a/include/libcamera/internal/camera_sensor.h +++ b/include/libcamera/internal/camera_sensor.h @@ -107,6 +107,7 @@ private: Rectangle activeArea_; const BayerFormat *bayerFormat_; bool supportFlips_; + Transform rotationTransform_; ControlList properties_; diff --git a/src/libcamera/camera_sensor.cpp b/src/libcamera/camera_sensor.cpp index f3a5aa37149f..a15a6c89c5c8 100644 --- a/src/libcamera/camera_sensor.cpp +++ b/src/libcamera/camera_sensor.cpp @@ -461,18 +461,36 @@ int CameraSensor::initProperties() const auto &rotationControl = controls.find(V4L2_CID_CAMERA_SENSOR_ROTATION); if (rotationControl != controls.end()) { + propertyValue = rotationControl->second.def().get(); + /* - * 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. + * Cache the Transform associated with the camera mounting + * rotation for later use in validateTransform(). + */ + bool success; + rotationTransform_ = transformFromRotation(propertyValue, &success); + if (!success) { + LOG(CameraSensor, Warning) + << "Invalid rotation of " << propertyValue + << " degrees - ignoring"; + rotationTransform_ = Transform::Identity; + } + + /* + * Adjust property::Rotation as 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); + } else { + LOG(CameraSensor, Warning) + << "Rotation control not available, default to 0 degreees"; + rotationTransform_ = Transform::Identity; } properties_.set(properties::PixelArraySize, pixelArraySize_); @@ -1038,21 +1056,11 @@ void CameraSensor::updateControlInfo() */ Transform CameraSensor::validateTransform(Transform *transform) const { - /* 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 - << " degrees - ignoring"; - - Transform combined = *transform * rotationTransform; + /* + * Combine the requested transform to compensate the sensor mounting + * rotation. + */ + Transform combined = *transform * rotationTransform_; /* * We combine the platform and user transform, but must "adjust away" @@ -1083,7 +1091,7 @@ Transform CameraSensor::validateTransform(Transform *transform) const * rise to this is the inverse of the rotation. (Recall that * combined = transform * rotationTransform.) */ - *transform = -rotationTransform; + *transform = -rotationTransform_; combined = Transform::Identity; }