Show a patch.

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

{
    "id": 21530,
    "url": "https://patchwork.libcamera.org/api/patches/21530/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/21530/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/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": "<20241007095425.211158-8-stefan.klug@ideasonboard.com>",
    "date": "2024-10-07T09:54:11",
    "name": "[v2,7/7,DNI] ipa: Add debug controls to the agc algorithm",
    "commit_ref": null,
    "pull_url": null,
    "state": "superseded",
    "archived": false,
    "hash": "cda7de63a0d1aac640c0e0f8ced82eba2423d94c",
    "submitter": {
        "id": 184,
        "url": "https://patchwork.libcamera.org/api/people/184/?format=api",
        "name": "Stefan Klug",
        "email": "stefan.klug@ideasonboard.com"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/21530/mbox/",
    "series": [
        {
            "id": 4661,
            "url": "https://patchwork.libcamera.org/api/series/4661/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=4661",
            "date": "2024-10-07T09:54:04",
            "name": "Add support for IPA debugging metadata",
            "version": 2,
            "mbox": "https://patchwork.libcamera.org/series/4661/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/21530/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/21530/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 5B53DC32E0\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon,  7 Oct 2024 09:54:55 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 704416536B;\n\tMon,  7 Oct 2024 11:54:54 +0200 (CEST)",
            "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3012F6353A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon,  7 Oct 2024 11:54:52 +0200 (CEST)",
            "from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:ba12:1296:516b:1122])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 4EB8F152D;\n\tMon,  7 Oct 2024 11:53:16 +0200 (CEST)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"Hy+KnJ9w\"; dkim-atps=neutral",
        "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1728294796;\n\tbh=Kmp6hb9ta58J+9nDgsycbnef6xSPpW1OuToVI6pvP8w=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=Hy+KnJ9wM1l+DCGZUys8omX+DxspS7SIUysg4z7hCNe8APlH8tqMx1ywASOcpnrXi\n\tcq683lMsiej4cMhp4sPDz1dz1B0KKzjhRmSgh8iu5O7DP7/N7D855DkeOum/ONjyG5\n\tBPrv38vJuc54dbgxOK63zeU5XtjGf6o4ehf8aw/c=",
        "From": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "To": "libcamera-devel@lists.libcamera.org",
        "Cc": "Stefan Klug <stefan.klug@ideasonboard.com>",
        "Subject": "[PATCH v2 7/7] [DNI] ipa: Add debug controls to the agc algorithm",
        "Date": "Mon,  7 Oct 2024 11:54:11 +0200",
        "Message-ID": "<20241007095425.211158-8-stefan.klug@ideasonboard.com>",
        "X-Mailer": "git-send-email 2.43.0",
        "In-Reply-To": "<20241007095425.211158-1-stefan.klug@ideasonboard.com>",
        "References": "<20241007095425.211158-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": "Add a few (arbitrary) debug metadata to the agc algorithm. This shows\nhow easy it is to add debug metadata to an ipa even for classes that\ndon't have direct access to the metadata list or the context like\nAgcMeanLuminance. The control_ids_debug.yaml was autogenerated by\ncalling utils/gen-debug-controls.py\n\nSigned-off-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\n---\nUpdate in v2:\n- Break too long line in agc.cpp\n---\n src/ipa/libipa/agc_mean_luminance.cpp |  8 ++++++++\n src/ipa/libipa/agc_mean_luminance.h   |  4 ++++\n src/ipa/rkisp1/algorithms/agc.cpp     | 10 ++++++++++\n src/libcamera/control_ids_debug.yaml  | 21 ++++++++++++++++++++-\n 4 files changed, 42 insertions(+), 1 deletion(-)",
    "diff": "diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp\nindex f97ef11771c4..bd0f85afcd2e 100644\n--- a/src/ipa/libipa/agc_mean_luminance.cpp\n+++ b/src/ipa/libipa/agc_mean_luminance.cpp\n@@ -133,6 +133,11 @@ static constexpr double kDefaultRelativeLuminanceTarget = 0.16;\n  * values.\n  */\n \n+/**\n+ * \\var AgcMeanLuminance::debugMeta_\n+ * \\brief DebugMetadata helper\n+ */\n+\n AgcMeanLuminance::AgcMeanLuminance()\n \t: frameCount_(0), filteredExposure_(0s), relativeLuminanceTarget_(0)\n {\n@@ -541,8 +546,11 @@ AgcMeanLuminance::calculateNewEv(uint32_t constraintModeIndex,\n \t\texposureModeHelpers_.at(exposureModeIndex);\n \n \tdouble gain = estimateInitialGain();\n+\tdebugMeta_.set<float>(controls::debug::AgcInitialGain, static_cast<float>(gain));\n \tgain = constraintClampGain(constraintModeIndex, yHist, gain);\n \n+\tdebugMeta_.set<float>(controls::debug::AgcNewGain, static_cast<float>(gain));\n+\n \t/*\n \t * We don't check whether we're already close to the target, because\n \t * even if the effective exposure value is the same as the last frame's\ndiff --git a/src/ipa/libipa/agc_mean_luminance.h b/src/ipa/libipa/agc_mean_luminance.h\nindex 576d28be8eb0..428465a11a36 100644\n--- a/src/ipa/libipa/agc_mean_luminance.h\n+++ b/src/ipa/libipa/agc_mean_luminance.h\n@@ -16,6 +16,7 @@\n \n #include <libcamera/controls.h>\n \n+#include \"libcamera/internal/debug_controls.h\"\n #include \"libcamera/internal/yaml_parser.h\"\n \n #include \"exposure_mode_helper.h\"\n@@ -71,6 +72,9 @@ public:\n \t\tframeCount_ = 0;\n \t}\n \n+protected:\n+\tDebugMetadata debugMeta_;\n+\n private:\n \tvirtual double estimateLuminance(const double gain) const = 0;\n \ndiff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp\nindex 17d074d9c03e..6668db942042 100644\n--- a/src/ipa/rkisp1/algorithms/agc.cpp\n+++ b/src/ipa/rkisp1/algorithms/agc.cpp\n@@ -139,6 +139,8 @@ int Agc::init(IPAContext &context, const YamlObject &tuningData)\n {\n \tint ret;\n \n+\tdebugMeta_.setParent(&context.debugMetadata);\n+\n \tret = parseTuningData(tuningData);\n \tif (ret)\n \t\treturn ret;\n@@ -444,6 +446,14 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,\n \t\t\t       frameContext.agc.exposureMode,\n \t\t\t       hist, effectiveExposureValue);\n \n+\tdebugMeta_.set<float>(controls::debug::AgcAnalogGain, aGain);\n+\tdebugMeta_.set<float>(controls::debug::AgcDigitalGain, dGain);\n+\n+\tconst Span<const uint64_t> orig = hist.data();\n+\tconst Span<const int64_t> data{ reinterpret_cast<const int64_t *>(&orig[0]),\n+\t\t\t\t\torig.size() };\n+\tdebugMeta_.set<Span<const int64_t>>(controls::debug::AgcHistogram, data);\n+\n \tLOG(RkISP1Agc, Debug)\n \t\t<< \"Divided up shutter, analogue gain and digital gain are \"\n \t\t<< shutterTime << \", \" << aGain << \" and \" << dGain;\ndiff --git a/src/libcamera/control_ids_debug.yaml b/src/libcamera/control_ids_debug.yaml\nindex 797532712099..61ea2d17b553 100644\n--- a/src/libcamera/control_ids_debug.yaml\n+++ b/src/libcamera/control_ids_debug.yaml\n@@ -1,6 +1,25 @@\n # SPDX-License-Identifier: LGPL-2.1-or-later\n #\n+# This file is generated by utils/gen-debug-controls.py\n+#\n %YAML 1.1\n ---\n vendor: debug\n-controls: []\n+controls:\n+- AgcAnalogGain:\n+    type: float\n+    description: Debug control AgcAnalogGain found in src/ipa/rkisp1/algorithms/agc.cpp:448\n+- AgcDigitalGain:\n+    type: float\n+    description: Debug control AgcDigitalGain found in src/ipa/rkisp1/algorithms/agc.cpp:449\n+- AgcHistogram:\n+    type: int64_t\n+    description: Debug control AgcHistogram found in src/ipa/rkisp1/algorithms/agc.cpp:454\n+    size: '[n]'\n+- AgcInitialGain:\n+    type: float\n+    description: Debug control AgcInitialGain found in src/ipa/libipa/agc_mean_luminance.cpp:548\n+- AgcNewGain:\n+    type: float\n+    description: Debug control AgcNewGain found in src/ipa/libipa/agc_mean_luminance.cpp:551\n+\n",
    "prefixes": [
        "v2",
        "7/7",
        "DNI"
    ]
}