{"id":25204,"url":"https://patchwork.libcamera.org/api/patches/25204/?format=json","web_url":"https://patchwork.libcamera.org/patch/25204/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20251125162851.2301793-26-stefan.klug@ideasonboard.com>","date":"2025-11-25T16:28:37","name":"[v3,25/29] pipeline: rkisp1: Load dewarp parameters from tuning file","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"9e2acc98b075a9cd4a7f57df217a09e8de165d67","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/people/184/?format=json","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/25204/mbox/","series":[{"id":5613,"url":"https://patchwork.libcamera.org/api/series/5613/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5613","date":"2025-11-25T16:28:12","name":"Full dewarper support on imx8mp","version":3,"mbox":"https://patchwork.libcamera.org/series/5613/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/25204/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/25204/checks/","tags":{},"headers":{"Return-Path":"<libcamera-devel-bounces@lists.libcamera.org>","X-Original-To":"parsemail@patchwork.libcamera.org","Delivered-To":"parsemail@patchwork.libcamera.org","Received":["from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id D6B8CC333C\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 25 Nov 2025 16:30:11 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 825A760AA0;\n\tTue, 25 Nov 2025 17:30:11 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id DCB6D60BE2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 25 Nov 2025 17:30:08 +0100 (CET)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:bae1:340c:573c:570b])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id D416518CB; \n\tTue, 25 Nov 2025 17:27:59 +0100 (CET)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"r2JmcIAu\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1764088079;\n\tbh=ACx7tn6eBPa89EDefqk8pqGvSoIt/yXeJOr5V5kNolg=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=r2JmcIAuIDjBKCepPXnYSEObT/6CQD//qM9stFLDDq3shRrh97H0kCwI8ofZTd7ZF\n\tksTtfzk1zMdYbKEcDykPMjsNAxKexL5zrHr4enrs2pZv6/J4oVCI0PC2hIIxlzAcIB\n\tcwzAtJJzFlakYmp5CCQKy++VCpMc941h1FBOrRnY=","From":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>","Subject":"[PATCH v3 25/29] pipeline: rkisp1: Load dewarp parameters from\n\ttuning 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","Content-Transfer-Encoding":"8bit","X-BeenThere":"libcamera-devel@lists.libcamera.org","X-Mailman-Version":"2.1.29","Precedence":"list","List-Id":"<libcamera-devel.lists.libcamera.org>","List-Unsubscribe":"<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>","List-Archive":"<https://lists.libcamera.org/pipermail/libcamera-devel/>","List-Post":"<mailto:libcamera-devel@lists.libcamera.org>","List-Help":"<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>","List-Subscribe":"<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>","Errors-To":"libcamera-devel-bounces@lists.libcamera.org","Sender":"\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"},"content":"Load the dewarp parameters from the tuning file.\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\n---\n\nChanges in v3:\n- Moved code into converter module\n- Added more documentation\n\nChanges in v2:\n- Dropped unused variable\n---\n .../internal/converter/converter_dw100.h      |  8 +++\n src/libcamera/converter/converter_dw100.cpp   | 71 +++++++++++++++++++\n src/libcamera/pipeline/rkisp1/rkisp1.cpp      | 16 +++--\n 3 files changed, 91 insertions(+), 4 deletions(-)","diff":"diff --git a/include/libcamera/internal/converter/converter_dw100.h b/include/libcamera/internal/converter/converter_dw100.h\nindex 8dd21a6228f1..f0c858689e27 100644\n--- a/include/libcamera/internal/converter/converter_dw100.h\n+++ b/include/libcamera/internal/converter/converter_dw100.h\n@@ -31,6 +31,8 @@ public:\n \n \tstatic std::unique_ptr<ConverterDW100Module> createModule(DeviceEnumerator *enumerator);\n \n+\tint init(const YamlObject &params);\n+\n \tint configure(const StreamConfiguration &inputCfg,\n \t\t      const std::vector<std::reference_wrapper<StreamConfiguration>>\n \t\t\t      &outputCfg);\n@@ -67,12 +69,18 @@ private:\n \tint applyControls(const Stream *stream, const V4L2Request *request);\n \tvoid reinitRequest(V4L2Request *request);\n \n+\tstruct DewarpParms {\n+\t\tMatrix<double, 3, 3> cm;\n+\t\tstd::vector<double> coeffs;\n+\t};\n+\n \tstruct VertexMapInfo {\n \t\tDw100VertexMap map;\n \t\tbool update;\n \t};\n \n \tstd::map<const Stream *, VertexMapInfo> vertexMaps_;\n+\tstd::optional<DewarpParms> dewarpParams_;\n \tunsigned int inputBufferCount_;\n \tV4L2M2MConverter converter_;\n \tRectangle sensorCrop_;\ndiff --git a/src/libcamera/converter/converter_dw100.cpp b/src/libcamera/converter/converter_dw100.cpp\nindex cba7cc9f709b..03ffd939dc63 100644\n--- a/src/libcamera/converter/converter_dw100.cpp\n+++ b/src/libcamera/converter/converter_dw100.cpp\n@@ -70,6 +70,74 @@ ConverterDW100Module::createModule(DeviceEnumerator *enumerator)\n \treturn {};\n }\n \n+/**\n+ * \\brief Initialize the module with configuration data\n+ * \\param[in] params The config parameters\n+ *\n+ * This function shall be called from the pipeline handler to initialize the\n+ * module with the provided parameters.\n+ *\n+ * A typical tuning file entry for the dewarper looks like this:\n+ * \\code{.unparsed}\n+ * modules:\n+ * - Dewarp:\n+ *    cm: [\n+ *      1.0, 0.0, 0.0,\n+ *      0.0, 1.0, 0.0,\n+ *      0.0, 0.0, 1.0,\n+ *    ]\n+ *    coefficients: [\n+ *      0,0,0,0,0,\n+ *    ]\n+ * \\endcode\n+ *\n+ * The \\a cm and \\a coefficients parameters are documented in\n+ * Dw100VertexMap::setDewarpParams()\n+ *\n+ * \\sa Dw100VertexMap::setDewarpParams()\n+ * \\return 0 if successful, an error code otherwise\n+ */\n+int ConverterDW100Module::init(const YamlObject &params)\n+{\n+\tDewarpParms dp;\n+\n+\tauto &cm = params[\"cm\"];\n+\tauto &coefficients = params[\"coefficients\"];\n+\n+\t/* If nothing is provided, the dewarper is still functional */\n+\tif (!cm && !coefficients)\n+\t\treturn 0;\n+\n+\tif (!cm) {\n+\t\tLOG(Converter, Error) << \"Dewarp parameters are missing 'cm' value\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tauto matrix = cm.get<Matrix<double, 3, 3>>();\n+\tif (!matrix) {\n+\t\tLOG(Converter, Error) << \"Failed to load 'cm' value\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tdp.cm = *matrix;\n+\n+\tif (!coefficients) {\n+\t\tLOG(Converter, Error) << \"Dewarp parameters are missing 'coefficients' value\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tconst auto coeffs = coefficients.getList<double>();\n+\tif (!coeffs) {\n+\t\tLOG(Converter, Error) << \"Dewarp parameters 'coefficients' value is not a list\";\n+\t\treturn -EINVAL;\n+\t}\n+\tdp.coeffs = std::move(*coeffs);\n+\n+\tdewarpParams_ = dp;\n+\n+\treturn 0;\n+}\n+\n /**\n  * \\copydoc libcamera::V4L2M2MConverter::configure\n  */\n@@ -93,6 +161,9 @@ int ConverterDW100Module::configure(const StreamConfiguration &inputCfg,\n \t\tvertexMap.setInputSize(inputCfg.size);\n \t\tvertexMap.setOutputSize(outputCfg.size);\n \t\tvertexMap.setSensorCrop(sensorCrop_);\n+\n+\t\tif (dewarpParams_)\n+\t\t\tvertexMap.setDewarpParams(dewarpParams_->cm, dewarpParams_->coeffs);\n \t\tinfo.update = true;\n \t}\n \ndiff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\nindex 746eeffab207..adce1de35263 100644\n--- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n+++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n@@ -453,10 +453,18 @@ int RkISP1CameraData::loadTuningFile(const std::string &path)\n \n \tconst auto &modules = (*data)[\"modules\"].asList();\n \tfor (const auto &module : modules) {\n-\t\tif (module.contains(\"Dewarp\")) {\n-\t\t\tcanUseDewarper_ = true;\n-\t\t\tbreak;\n-\t\t}\n+\t\tconst auto &params = module[\"Dewarp\"];\n+\t\tif (!params)\n+\t\t\tcontinue;\n+\n+\t\tret = pipe()->dewarper_->init(params);\n+\t\tif (ret)\n+\t\t\treturn ret;\n+\n+\t\tLOG(RkISP1, Info) << \"Dw100 dewarper initialized\";\n+\n+\t\tcanUseDewarper_ = true;\n+\t\treturn 0;\n \t}\n \n \treturn 0;\n","prefixes":["v3","25/29"]}