From patchwork Tue Sep 30 12:26:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 24528 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 D1EABC328C for ; Tue, 30 Sep 2025 13:34:18 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E7CE76B5F0; Tue, 30 Sep 2025 15:34:17 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="lovTQ5pR"; dkim-atps=neutral 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 1967C62C35 for ; Tue, 30 Sep 2025 15:34:15 +0200 (CEST) Received: from ideasonboard.com (unknown [94.31.94.171]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id BEA7E16A; Tue, 30 Sep 2025 15:32:46 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1759239166; bh=eauvXfNddQH20Q9V/RZ1gG3g7AsZ7qaeEL4sbl+f9T0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=lovTQ5pRrtX7I7HetqOL6HI6jeqGhizq8S+e2ck2MItTYqaFraqLuWY2XDOhzf7Uy WELGZ48gckYOas5/db7Lk61ac5RfxdCVCEdO7M4ugPJ7KduaW2/svR1JvCNA0RKIUT DuOT+GmrAuElMKoFVHwxV4d98Bn5f6CMD1Je2PLU= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH v1 29/33] pipeline: rkisp1: Enable the dewarper based on the tuning file Date: Tue, 30 Sep 2025 14:26:50 +0200 Message-ID: <20250930122726.1837524-30-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20250930122726.1837524-1-stefan.klug@ideasonboard.com> References: <20250930122726.1837524-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" algorithm in the tuning file. Todo: 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. If it should be in the algorithms section or in a different one is open for debate. Signed-off-by: Stefan Klug --- src/ipa/libipa/module.h | 4 ++ src/libcamera/pipeline/rkisp1/rkisp1.cpp | 51 +++++++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/src/ipa/libipa/module.h b/src/ipa/libipa/module.h index 0fb51916fff6..84386f901534 100644 --- a/src/ipa/libipa/module.h +++ b/src/ipa/libipa/module.h @@ -74,6 +74,10 @@ private: int createAlgorithm(Context &context, const YamlObject &data) { const auto &[name, algoData] = *data.asDict().begin(); + + if (name == "Dewarp") + return 0; + std::unique_ptr> algo = createAlgorithm(name); if (!algo) { LOG(IPAModuleAlgo, Error) diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 1046930857e1..07dd5dc8d99a 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -16,6 +16,7 @@ #include #include +#include #include #include @@ -47,6 +48,7 @@ #include "libcamera/internal/v4l2_request.h" #include "libcamera/internal/v4l2_subdevice.h" #include "libcamera/internal/v4l2_videodevice.h" +#include "libcamera/internal/yaml_parser.h" #include "rkisp1_path.h" @@ -123,6 +125,7 @@ public: */ MediaPipeline pipe_; + bool canUseDewarper_; bool usesDewarper_; private: @@ -131,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 @@ -416,6 +420,51 @@ 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) +{ + 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)) { + int 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("algorithms")) { + LOG(RkISP1, Error) + << "Tuning file doesn't contain any algorithm"; + return -EINVAL; + } + + const auto &algos = (*data)["algorithms"].asList(); + for (const auto &algo : algos) { + if (algo.contains("Dewarp")) { + const auto ¶ms = algo["Dewarp"]; + + canUseDewarper_ = true; + } + } + return 0; } @@ -572,7 +621,7 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate() */ bool transposeAfterIsp = false; bool useDewarper = false; - if (pipe->dewarper_) { + if (data_->canUseDewarper_) { /* * Platforms with dewarper support, such as i.MX8MP, support * only a single stream. We can inspect config_[0] only here.