From patchwork Tue Nov 25 16:28:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 25199 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 4F038C333C for ; Tue, 25 Nov 2025 16:29:56 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1323060AA9; Tue, 25 Nov 2025 17:29:56 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="iH8MQHEF"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9CCA160A9E for ; Tue, 25 Nov 2025 17:29:54 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:bae1:340c:573c:570b]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id B3515FDB; Tue, 25 Nov 2025 17:27:45 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1764088065; bh=SD7cz3jxHVqUE3yKJ+8BYwHqczjKFQHHlcGigHlrdN0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iH8MQHEFGqw6eFDDs86z/nlfnVAmUXICrN1vNFtH0vx4xKcOtVkhg0BCVVw9RP/KQ bF4AcCm+mcMsw7P7MYYlEFG1RmdvDUL0CVARQP5Joqml29HTTQozui4WGr9cW6rSVf GrSEzlRzIepMMhEDGEkNtJbhG8l2V+Bdnd+FXlXY= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug , Paul Elder Subject: [PATCH v3 20/29] pipeline: rkisp1: Enable the dewarper based on the tuning file Date: Tue, 25 Nov 2025 17:28:32 +0100 Message-ID: <20251125162851.2301793-21-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.51.0 In-Reply-To: <20251125162851.2301793-1-stefan.klug@ideasonboard.com> References: <20251125162851.2301793-1-stefan.klug@ideasonboard.com> 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" To do actual lens dewarping, the dewarper will be configured based on the tuning file. As a first step implement the basic loading of the tuning file and enable/disable the dewarper for the given camera based on the existence of the "Dewarp" entry under a new top level element 'modules' in the tuning file. Note: This is an backwards incompatible change in that the dewarper is currently included in the chain unconditionally. Some users may want to not use the dewarper, so it is sensible to make that configurable. Signed-off-by: Stefan Klug Reviewed-by: Paul Elder Reviewed-by: Kieran Bingham --- Changes in v3: - Collected tag - The config is now looked up under the toplevel key 'modules' instead of 'algorithms' - Properly initialize canUseDewarper_ and usesDewarper() so that it still works if there is no dewarper or it is not contained in the tuning file. Changes in v2: - Drop unused params variable - Moved patch a bit earlier so canUseDewarper is available for handling the orientation --- src/libcamera/pipeline/rkisp1/rkisp1.cpp | 52 +++++++++++++++++++++++- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 2972d6e1cbd1..e3dca8b837e8 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -46,6 +47,7 @@ #include "libcamera/internal/pipeline_handler.h" #include "libcamera/internal/v4l2_subdevice.h" #include "libcamera/internal/v4l2_videodevice.h" +#include "libcamera/internal/yaml_parser.h" #include "rkisp1_path.h" @@ -94,7 +96,8 @@ public: RkISP1CameraData(PipelineHandler *pipe, RkISP1MainPath *mainPath, RkISP1SelfPath *selfPath) : Camera::Private(pipe), frame_(0), frameInfo_(pipe), - mainPath_(mainPath), selfPath_(selfPath) + mainPath_(mainPath), selfPath_(selfPath), + canUseDewarper_(false), usesDewarper_(false) { } @@ -122,6 +125,7 @@ public: */ MediaPipeline pipe_; + bool canUseDewarper_; bool usesDewarper_; private: @@ -130,6 +134,7 @@ private: const ControlList &sensorControls); void metadataReady(unsigned int frame, const ControlList &metadata); + int loadTuningFile(const std::string &file); }; class RkISP1CameraConfiguration : public CameraConfiguration @@ -411,6 +416,49 @@ int RkISP1CameraData::loadIPA(unsigned int hwRevision, uint32_t supportedBlocks) return ret; } + ret = loadTuningFile(ipaTuningFile); + if (ret < 0) { + LOG(RkISP1, Error) << "Failed to load tuning file"; + return ret; + } + + return 0; +} + +int RkISP1CameraData::loadTuningFile(const std::string &path) +{ + int ret; + + if (!pipe()->dewarper_) + /* Nothing to do without dewarper */ + return 0; + + LOG(RkISP1, Debug) << "Load tuning file " << path; + + File file(path); + if (!file.open(File::OpenModeFlag::ReadOnly)) { + ret = file.error(); + LOG(RkISP1, Error) + << "Failed to open tuning file " + << path << ": " << strerror(-ret); + return ret; + } + + std::unique_ptr data = YamlParser::parse(file); + if (!data) + return -EINVAL; + + if (!data->contains("modules")) + return 0; + + const auto &modules = (*data)["modules"].asList(); + for (const auto &module : modules) { + if (module.contains("Dewarp")) { + canUseDewarper_ = true; + break; + } + } + return 0; } @@ -574,7 +622,7 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate() } } - bool useDewarper = (pipe->dewarper_ && !isRaw); + bool useDewarper = (data_->canUseDewarper_ && !isRaw); /* * If there are more than one stream in the configuration figure out the