From patchwork Tue Nov 25 16:28:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 25204 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 D6B8CC333C for ; Tue, 25 Nov 2025 16:30:11 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 825A760AA0; Tue, 25 Nov 2025 17:30:11 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="r2JmcIAu"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DCB6D60BE2 for ; Tue, 25 Nov 2025 17:30:08 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:bae1:340c:573c:570b]) by perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id D416518CB; Tue, 25 Nov 2025 17:27:59 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1764088079; bh=ACx7tn6eBPa89EDefqk8pqGvSoIt/yXeJOr5V5kNolg=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=r2JmcIAuIDjBKCepPXnYSEObT/6CQD//qM9stFLDDq3shRrh97H0kCwI8ofZTd7ZF ksTtfzk1zMdYbKEcDykPMjsNAxKexL5zrHr4enrs2pZv6/J4oVCI0PC2hIIxlzAcIB cwzAtJJzFlakYmp5CCQKy++VCpMc941h1FBOrRnY= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH v3 25/29] pipeline: rkisp1: Load dewarp parameters from tuning file Date: Tue, 25 Nov 2025 17:28:37 +0100 Message-ID: <20251125162851.2301793-26-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" Load the dewarp parameters from the tuning file. Signed-off-by: Stefan Klug Reviewed-by: Kieran Bingham --- Changes in v3: - Moved code into converter module - Added more documentation Changes in v2: - Dropped unused variable --- .../internal/converter/converter_dw100.h | 8 +++ src/libcamera/converter/converter_dw100.cpp | 71 +++++++++++++++++++ src/libcamera/pipeline/rkisp1/rkisp1.cpp | 16 +++-- 3 files changed, 91 insertions(+), 4 deletions(-) diff --git a/include/libcamera/internal/converter/converter_dw100.h b/include/libcamera/internal/converter/converter_dw100.h index 8dd21a6228f1..f0c858689e27 100644 --- a/include/libcamera/internal/converter/converter_dw100.h +++ b/include/libcamera/internal/converter/converter_dw100.h @@ -31,6 +31,8 @@ public: static std::unique_ptr createModule(DeviceEnumerator *enumerator); + int init(const YamlObject ¶ms); + int configure(const StreamConfiguration &inputCfg, const std::vector> &outputCfg); @@ -67,12 +69,18 @@ private: int applyControls(const Stream *stream, const V4L2Request *request); void reinitRequest(V4L2Request *request); + struct DewarpParms { + Matrix cm; + std::vector coeffs; + }; + struct VertexMapInfo { Dw100VertexMap map; bool update; }; std::map vertexMaps_; + std::optional dewarpParams_; unsigned int inputBufferCount_; V4L2M2MConverter converter_; Rectangle sensorCrop_; diff --git a/src/libcamera/converter/converter_dw100.cpp b/src/libcamera/converter/converter_dw100.cpp index cba7cc9f709b..03ffd939dc63 100644 --- a/src/libcamera/converter/converter_dw100.cpp +++ b/src/libcamera/converter/converter_dw100.cpp @@ -70,6 +70,74 @@ ConverterDW100Module::createModule(DeviceEnumerator *enumerator) return {}; } +/** + * \brief Initialize the module with configuration data + * \param[in] params The config parameters + * + * This function shall be called from the pipeline handler to initialize the + * module with the provided parameters. + * + * A typical tuning file entry for the dewarper looks like this: + * \code{.unparsed} + * modules: + * - Dewarp: + * cm: [ + * 1.0, 0.0, 0.0, + * 0.0, 1.0, 0.0, + * 0.0, 0.0, 1.0, + * ] + * coefficients: [ + * 0,0,0,0,0, + * ] + * \endcode + * + * The \a cm and \a coefficients parameters are documented in + * Dw100VertexMap::setDewarpParams() + * + * \sa Dw100VertexMap::setDewarpParams() + * \return 0 if successful, an error code otherwise + */ +int ConverterDW100Module::init(const YamlObject ¶ms) +{ + DewarpParms dp; + + auto &cm = params["cm"]; + auto &coefficients = params["coefficients"]; + + /* If nothing is provided, the dewarper is still functional */ + if (!cm && !coefficients) + return 0; + + if (!cm) { + LOG(Converter, Error) << "Dewarp parameters are missing 'cm' value"; + return -EINVAL; + } + + auto matrix = cm.get>(); + if (!matrix) { + LOG(Converter, Error) << "Failed to load 'cm' value"; + return -EINVAL; + } + + dp.cm = *matrix; + + if (!coefficients) { + LOG(Converter, Error) << "Dewarp parameters are missing 'coefficients' value"; + return -EINVAL; + } + + const auto coeffs = coefficients.getList(); + if (!coeffs) { + LOG(Converter, Error) << "Dewarp parameters 'coefficients' value is not a list"; + return -EINVAL; + } + dp.coeffs = std::move(*coeffs); + + dewarpParams_ = dp; + + return 0; +} + /** * \copydoc libcamera::V4L2M2MConverter::configure */ @@ -93,6 +161,9 @@ int ConverterDW100Module::configure(const StreamConfiguration &inputCfg, vertexMap.setInputSize(inputCfg.size); vertexMap.setOutputSize(outputCfg.size); vertexMap.setSensorCrop(sensorCrop_); + + if (dewarpParams_) + vertexMap.setDewarpParams(dewarpParams_->cm, dewarpParams_->coeffs); info.update = true; } diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp index 746eeffab207..adce1de35263 100644 --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp @@ -453,10 +453,18 @@ int RkISP1CameraData::loadTuningFile(const std::string &path) const auto &modules = (*data)["modules"].asList(); for (const auto &module : modules) { - if (module.contains("Dewarp")) { - canUseDewarper_ = true; - break; - } + const auto ¶ms = module["Dewarp"]; + if (!params) + continue; + + ret = pipe()->dewarper_->init(params); + if (ret) + return ret; + + LOG(RkISP1, Info) << "Dw100 dewarper initialized"; + + canUseDewarper_ = true; + return 0; } return 0;