[{"id":37060,"web_url":"https://patchwork.libcamera.org/comment/37060/","msgid":"<176409256709.567526.14744278223985015890@ping.linuxembedded.co.uk>","date":"2025-11-25T17:42:47","subject":"Re: [PATCH v3 20/29] pipeline: rkisp1: Enable the dewarper based on\n\tthe tuning file","submitter":{"id":4,"url":"https://patchwork.libcamera.org/api/people/4/","name":"Kieran Bingham","email":"kieran.bingham@ideasonboard.com"},"content":"Quoting Stefan Klug (2025-11-25 16:28:32)\n> To do actual lens dewarping, the dewarper will be configured based on\n> the tuning file.\n> \n> As a first step implement the basic loading of the\n> tuning file and enable/disable the dewarper for the given camera based\n> on the existence of the \"Dewarp\" entry under a new top level element\n> 'modules' in the tuning file.\n> \n> Note: This is an backwards incompatible change in that the dewarper is\n> currently included in the chain unconditionally. Some users may want to\n> not use the dewarper, so it is sensible to make that configurable.\n> \n> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>\n> \n> ---\n> \n> Changes in v3:\n> - Collected tag\n> - The config is now looked up under the toplevel key 'modules' instead\n>   of 'algorithms'\n> - Properly initialize canUseDewarper_ and usesDewarper() so that it\n>   still works if there is no dewarper or it is not contained in the\n> tuning file.\n> \n> Changes in v2:\n> - Drop unused params variable\n> - Moved patch a bit earlier so canUseDewarper is available for handling\n>   the orientation\n> ---\n>  src/libcamera/pipeline/rkisp1/rkisp1.cpp | 52 +++++++++++++++++++++++-\n>  1 file changed, 50 insertions(+), 2 deletions(-)\n> \n> diff --git a/src/libcamera/pipeline/rkisp1/rkisp1.cpp b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> index 2972d6e1cbd1..e3dca8b837e8 100644\n> --- a/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> +++ b/src/libcamera/pipeline/rkisp1/rkisp1.cpp\n> @@ -16,6 +16,7 @@\n>  #include <linux/media-bus-format.h>\n>  #include <linux/rkisp1-config.h>\n>  \n> +#include <libcamera/base/file.h>\n>  #include <libcamera/base/log.h>\n>  #include <libcamera/base/utils.h>\n>  \n> @@ -46,6 +47,7 @@\n>  #include \"libcamera/internal/pipeline_handler.h\"\n>  #include \"libcamera/internal/v4l2_subdevice.h\"\n>  #include \"libcamera/internal/v4l2_videodevice.h\"\n> +#include \"libcamera/internal/yaml_parser.h\"\n>  \n>  #include \"rkisp1_path.h\"\n>  \n> @@ -94,7 +96,8 @@ public:\n>         RkISP1CameraData(PipelineHandler *pipe, RkISP1MainPath *mainPath,\n>                          RkISP1SelfPath *selfPath)\n>                 : Camera::Private(pipe), frame_(0), frameInfo_(pipe),\n> -                 mainPath_(mainPath), selfPath_(selfPath)\n> +                 mainPath_(mainPath), selfPath_(selfPath),\n> +                 canUseDewarper_(false), usesDewarper_(false)\n>         {\n>         }\n>  \n> @@ -122,6 +125,7 @@ public:\n>          */\n>         MediaPipeline pipe_;\n>  \n> +       bool canUseDewarper_;\n>         bool usesDewarper_;\n>  \n>  private:\n> @@ -130,6 +134,7 @@ private:\n>                                const ControlList &sensorControls);\n>  \n>         void metadataReady(unsigned int frame, const ControlList &metadata);\n> +       int loadTuningFile(const std::string &file);\n>  };\n>  \n>  class RkISP1CameraConfiguration : public CameraConfiguration\n> @@ -411,6 +416,49 @@ int RkISP1CameraData::loadIPA(unsigned int hwRevision, uint32_t supportedBlocks)\n>                 return ret;\n>         }\n>  \n> +       ret = loadTuningFile(ipaTuningFile);\n> +       if (ret < 0) {\n> +               LOG(RkISP1, Error) << \"Failed to load tuning file\";\n> +               return ret;\n> +       }\n> +\n> +       return 0;\n> +}\n> +\n> +int RkISP1CameraData::loadTuningFile(const std::string &path)\n> +{\n> +       int ret;\n> +\n> +       if (!pipe()->dewarper_)\n> +               /* Nothing to do without dewarper */\n> +               return 0;\n> +\n> +       LOG(RkISP1, Debug) << \"Load tuning file \" << path;\n> +\n> +       File file(path);\n> +       if (!file.open(File::OpenModeFlag::ReadOnly)) {\n> +               ret = file.error();\n> +               LOG(RkISP1, Error)\n> +                       << \"Failed to open tuning file \"\n> +                       << path << \": \" << strerror(-ret);\n> +               return ret;\n> +       }\n> +\n> +       std::unique_ptr<libcamera::YamlObject> data = YamlParser::parse(file);\n> +       if (!data)\n> +               return -EINVAL;\n> +\n> +       if (!data->contains(\"modules\"))\n> +               return 0;\n> +\n> +       const auto &modules = (*data)[\"modules\"].asList();\n> +       for (const auto &module : modules) {\n> +               if (module.contains(\"Dewarp\")) {\n> +                       canUseDewarper_ = true;\n> +                       break;\n> +               }\n> +       }\n> +\n>         return 0;\n>  }\n>  \n> @@ -574,7 +622,7 @@ CameraConfiguration::Status RkISP1CameraConfiguration::validate()\n>                 }\n>         }\n>  \n> -       bool useDewarper = (pipe->dewarper_ && !isRaw);\n> +       bool useDewarper = (data_->canUseDewarper_ && !isRaw);\n\nAha, right  - pipe->dewarper_ is guarded in\nRkISP1CameraData::loadTuningFile() already so this works.\n\n\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n\n>  \n>         /*\n>          * If there are more than one stream in the configuration figure out the\n> -- \n> 2.51.0\n>","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 B10D2C32DE\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue, 25 Nov 2025 17:42:53 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AB2AE60A9E;\n\tTue, 25 Nov 2025 18:42:52 +0100 (CET)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 5ADB2609D8\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue, 25 Nov 2025 18:42:50 +0100 (CET)","from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 29BF343;\n\tTue, 25 Nov 2025 18:40:41 +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=\"Cbq8BZn+\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1764092441;\n\tbh=q36hA8jdARvq+bwYQeXPSgtAYueFNXLYjGKSOlAzVHI=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=Cbq8BZn+Nb0S3r0v9uXIAPxG05aY1VGwjWnezxwX/tsowLq24LbXDIPAc+MR1plu2\n\t80KutW/n1/381SGl0depRTTEZRJxOryeT/DSHZj/7/otJXaKTgYj3qStZTc8adid1B\n\t0nunC+GMYrsc1phiWyQOjRccs3qGjNkM6655hKDE=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20251125162851.2301793-21-stefan.klug@ideasonboard.com>","References":"<20251125162851.2301793-1-stefan.klug@ideasonboard.com>\n\t<20251125162851.2301793-21-stefan.klug@ideasonboard.com>","Subject":"Re: [PATCH v3 20/29] pipeline: rkisp1: Enable the dewarper based on\n\tthe tuning file","From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tPaul Elder <paul.elder@ideasonboard.com>","To":"Stefan Klug <stefan.klug@ideasonboard.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Tue, 25 Nov 2025 17:42:47 +0000","Message-ID":"<176409256709.567526.14744278223985015890@ping.linuxembedded.co.uk>","User-Agent":"alot/0.9.1","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>"}}]