Show a patch.

GET /api/1.1/patches/17046/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 17046,
    "url": "https://patchwork.libcamera.org/api/1.1/patches/17046/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/17046/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/1.1/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20220809144617.27983-5-laurent.pinchart@ideasonboard.com>",
    "date": "2022-08-09T14:46:17",
    "name": "[libcamera-devel,v2,4/4] ipa: ipu3: Add YAML tuning file support",
    "commit_ref": "e1ca213609abb99cc1b6e6f16214bf5a0936f3b7",
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "5e71705db2043368df89381d8898ebcf5c825563",
    "submitter": {
        "id": 2,
        "url": "https://patchwork.libcamera.org/api/1.1/people/2/?format=api",
        "name": "Laurent Pinchart",
        "email": "laurent.pinchart@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/17046/mbox/",
    "series": [
        {
            "id": 3397,
            "url": "https://patchwork.libcamera.org/api/1.1/series/3397/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=3397",
            "date": "2022-08-09T14:46:13",
            "name": "Add tuning data file support to the IPU3 IPA modul",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/3397/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/17046/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/17046/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 49261C3275\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  9 Aug 2022 14:46:36 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0726E63328;\n\tTue,  9 Aug 2022 16:46:36 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 921CA63328\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  9 Aug 2022 16:46:34 +0200 (CEST)",
            "from pendragon.ideasonboard.com (62-78-145-57.bb.dnainternet.fi\n\t[62.78.145.57])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 2B822481\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  9 Aug 2022 16:46:34 +0200 (CEST)"
        ],
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/simple; d=libcamera.org;\n\ts=mail; t=1660056396;\n\tbh=5tLNzpV1RqRYJ0NUMR8N1xeVEQv0hHXKB2bxVhlVEoo=;\n\th=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe:\n\tList-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To:\n\tFrom;\n\tb=RjdJaX3K5F83/QpvPDRE9PP1Fp3RKI2w19lng8c9PfTpD9zCEPmwcurtMxKap3nKg\n\t8WU+MW9PtJyvaYB04xvW0MXXOW8abz0W1IkRYmUq1/yTPGUxFRgEHwRO5Dg8PMivJs\n\tA5JMUf5O/budkdQm3rRNKHQKa/7crHTD+pkiEh5Hm7mODmwhShskMoJMP4m86Pr9w9\n\teQU7Rw1ARIYyy1Yck0NOY/EJdzvpieUk3sOuPBJPCYZRBq6D/yySyk7JDb1/uXbIch\n\tOZ4xOUmt04ebOV1Oru0mEu9dyDX8Zg42ZxZySTu0awHWbsGlvt5L9LVixdNohbPVlS\n\t8xRHBESOOx30w==",
            "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1660056394;\n\tbh=5tLNzpV1RqRYJ0NUMR8N1xeVEQv0hHXKB2bxVhlVEoo=;\n\th=From:To:Subject:Date:In-Reply-To:References:From;\n\tb=idyZ9tMUdEbv6xHDTbsFvmeFbVYw+5pMPpB4UrouycjS3rhto+eoG/78IXDBHjrZv\n\tuxwoWpsQtD6BMNt6pRm0DliKkppbZXdvX8xLAGP5CWdYNSrhHLp+KPU+S5VjlOOAOf\n\tf3CtQ/dKAMzp5/i7owPtITa9h9Oh/ZCoiHze+aa8="
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key; \n\tunprotected) header.d=ideasonboard.com\n\theader.i=@ideasonboard.com\n\theader.b=\"idyZ9tMU\"; dkim-atps=neutral",
        "To": "libcamera-devel@lists.libcamera.org",
        "Date": "Tue,  9 Aug 2022 17:46:17 +0300",
        "Message-Id": "<20220809144617.27983-5-laurent.pinchart@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.35.1",
        "In-Reply-To": "<20220809144617.27983-1-laurent.pinchart@ideasonboard.com>",
        "References": "<20220809144617.27983-1-laurent.pinchart@ideasonboard.com>",
        "MIME-Version": "1.0",
        "Content-Transfer-Encoding": "8bit",
        "Subject": "[libcamera-devel] [PATCH v2 4/4] ipa: ipu3: Add YAML tuning file\n\tsupport",
        "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>",
        "From": "Laurent Pinchart via libcamera-devel\n\t<libcamera-devel@lists.libcamera.org>",
        "Reply-To": "Laurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Replace the manual instantiation of algorithms with an automatic\nmechanism based on a tuning data file, provided by the Module base\nclass. This brings the IPU3 IPA module in line with the RkISP1 IPA\nmodule.\n\nSigned-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nReviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n---\n src/ipa/ipu3/ipu3.cpp | 70 ++++++++++++++++++++++++++++++++-----------\n 1 file changed, 52 insertions(+), 18 deletions(-)",
    "diff": "diff --git a/src/ipa/ipu3/ipu3.cpp b/src/ipa/ipu3/ipu3.cpp\nindex 2f6bb672f7bb..e37b2fa0f30e 100644\n--- a/src/ipa/ipu3/ipu3.cpp\n+++ b/src/ipa/ipu3/ipu3.cpp\n@@ -18,6 +18,7 @@\n #include <linux/intel-ipu3.h>\n #include <linux/v4l2-controls.h>\n \n+#include <libcamera/base/file.h>\n #include <libcamera/base/log.h>\n #include <libcamera/base/utils.h>\n \n@@ -29,6 +30,7 @@\n #include <libcamera/request.h>\n \n #include \"libcamera/internal/mapped_framebuffer.h\"\n+#include \"libcamera/internal/yaml_parser.h\"\n \n #include \"algorithms/af.h\"\n #include \"algorithms/agc.h\"\n@@ -71,7 +73,7 @@ namespace ipa::ipu3 {\n  *\n  * At initialisation time, a CameraSensorHelper is instantiated to support\n  * camera-specific calculations, while the default controls are computed, and\n- * the algorithms are constructed and placed in an ordered list.\n+ * the algorithms are instantiated from the tuning data file.\n  *\n  * The IPU3 ImgU operates with a grid layout to divide the overall frame into\n  * rectangular cells of pixels. When the IPA is configured, we determine the\n@@ -92,12 +94,14 @@ namespace ipa::ipu3 {\n  * fillParamsBuffer() call.\n  *\n  * The individual algorithms are split into modular components that are called\n- * iteratively to allow them to process statistics from the ImgU in a defined\n- * order.\n+ * iteratively to allow them to process statistics from the ImgU in the order\n+ * defined in the tuning data file.\n  *\n- * The current implementation supports three core algorithms:\n- * - Automatic white balance (AWB)\n+ * The current implementation supports five core algorithms:\n+ *\n+ * - Auto focus (AF)\n  * - Automatic gain and exposure control (AGC)\n+ * - Automatic white balance (AWB)\n  * - Black level correction (BLC)\n  * - Tone mapping (Gamma)\n  *\n@@ -128,7 +132,7 @@ namespace ipa::ipu3 {\n  * sensor-specific tuning to adapt for Black Level compensation (BLC), Lens\n  * shading correction (SHD) and Color correction (CCM).\n  */\n-class IPAIPU3 : public IPAIPU3Interface\n+class IPAIPU3 : public IPAIPU3Interface, public Module\n {\n public:\n \tint init(const IPASettings &settings,\n@@ -150,6 +154,10 @@ public:\n \tvoid processStatsBuffer(const uint32_t frame, const int64_t frameTimestamp,\n \t\t\t\tconst uint32_t bufferId,\n \t\t\t\tconst ControlList &sensorControls) override;\n+\n+protected:\n+\tstd::string logPrefix() const override;\n+\n private:\n \tvoid updateControls(const IPACameraSensorInfo &sensorInfo,\n \t\t\t    const ControlInfoMap &sensorControls,\n@@ -171,13 +179,15 @@ private:\n \t/* Interface to the Camera Helper */\n \tstd::unique_ptr<CameraSensorHelper> camHelper_;\n \n-\t/* Maintain the algorithms used by the IPA */\n-\tstd::list<std::unique_ptr<ipa::ipu3::Algorithm>> algorithms_;\n-\n \t/* Local parameter storage */\n \tstruct IPAContext context_;\n };\n \n+std::string IPAIPU3::logPrefix() const\n+{\n+\treturn \"ipu3\";\n+}\n+\n /**\n  * \\brief Compute IPASessionConfiguration using the sensor information and the\n  * sensor V4L2 controls\n@@ -316,12 +326,36 @@ int IPAIPU3::init(const IPASettings &settings,\n \tcontext_.configuration = {};\n \tcontext_.configuration.sensor.lineDuration = sensorInfo.lineLength * 1.0s / sensorInfo.pixelRate;\n \n-\t/* Construct our Algorithms */\n-\talgorithms_.push_back(std::make_unique<algorithms::Af>());\n-\talgorithms_.push_back(std::make_unique<algorithms::Agc>());\n-\talgorithms_.push_back(std::make_unique<algorithms::Awb>());\n-\talgorithms_.push_back(std::make_unique<algorithms::BlackLevelCorrection>());\n-\talgorithms_.push_back(std::make_unique<algorithms::ToneMapping>());\n+\t/* Load the tuning data file. */\n+\tFile file(settings.configurationFile.c_str());\n+\tif (!file.open(File::OpenModeFlag::ReadOnly)) {\n+\t\tint ret = file.error();\n+\t\tLOG(IPAIPU3, Error)\n+\t\t\t<< \"Failed to open configuration file \"\n+\t\t\t<< settings.configurationFile << \": \" << strerror(-ret);\n+\t\treturn ret;\n+\t}\n+\n+\tstd::unique_ptr<libcamera::YamlObject> data = YamlParser::parse(file);\n+\tif (!data)\n+\t\treturn -EINVAL;\n+\n+\tunsigned int version = (*data)[\"version\"].get<uint32_t>(0);\n+\tif (version != 1) {\n+\t\tLOG(IPAIPU3, Error)\n+\t\t\t<< \"Invalid tuning file version \" << version;\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tif (!data->contains(\"algorithms\")) {\n+\t\tLOG(IPAIPU3, Error)\n+\t\t\t<< \"Tuning file doesn't contain any algorithm\";\n+\t\treturn -EINVAL;\n+\t}\n+\n+\tint ret = createAlgorithms(context_, (*data)[\"algorithms\"]);\n+\tif (ret)\n+\t\treturn ret;\n \n \t/* Initialize controls. */\n \tupdateControls(sensorInfo, sensorControls, ipaControls);\n@@ -470,7 +504,7 @@ int IPAIPU3::configure(const IPAConfigInfo &configInfo,\n \t/* Update the IPASessionConfiguration using the sensor settings. */\n \tupdateSessionConfiguration(sensorCtrls_);\n \n-\tfor (auto const &algo : algorithms_) {\n+\tfor (auto const &algo : algorithms()) {\n \t\tint ret = algo->configure(context_, configInfo);\n \t\tif (ret)\n \t\t\treturn ret;\n@@ -538,7 +572,7 @@ void IPAIPU3::fillParamsBuffer(const uint32_t frame, const uint32_t bufferId)\n \t */\n \tparams->use = {};\n \n-\tfor (auto const &algo : algorithms_)\n+\tfor (auto const &algo : algorithms())\n \t\talgo->prepare(context_, params);\n \n \tparamsBufferReady.emit(frame);\n@@ -581,7 +615,7 @@ void IPAIPU3::processStatsBuffer(const uint32_t frame,\n \tint32_t vBlank = context_.configuration.sensor.defVBlank;\n \tControlList ctrls(controls::controls);\n \n-\tfor (auto const &algo : algorithms_)\n+\tfor (auto const &algo : algorithms())\n \t\talgo->process(context_, &frameContext, stats);\n \n \tsetControls(frame);\n",
    "prefixes": [
        "libcamera-devel",
        "v2",
        "4/4"
    ]
}