{"id":21545,"url":"https://patchwork.libcamera.org/api/1.1/patches/21545/?format=json","web_url":"https://patchwork.libcamera.org/patch/21545/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/1.1/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":"<20241008153031.429906-8-stefan.klug@ideasonboard.com>","date":"2024-10-08T15:29:45","name":"[v3,7/7,DNI] ipa: Add debug controls to the agc algorithm","commit_ref":null,"pull_url":null,"state":"accepted","archived":false,"hash":"c1daccf968b9d161cc11fb72aa50229ad2d55045","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/1.1/people/184/?format=json","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/21545/mbox/","series":[{"id":4667,"url":"https://patchwork.libcamera.org/api/1.1/series/4667/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=4667","date":"2024-10-08T15:29:38","name":"Add support for IPA debugging metadata","version":3,"mbox":"https://patchwork.libcamera.org/series/4667/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/21545/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/21545/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 87FF0BE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tTue,  8 Oct 2024 15:30:57 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3DA1365372;\n\tTue,  8 Oct 2024 17:30:57 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8FB636536A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tTue,  8 Oct 2024 17:30:55 +0200 (CEST)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:d:f30b:aa60:fabf])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id D3EF1DB2;\n\tTue,  8 Oct 2024 17:29:18 +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=\"qQUhZkQk\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1728401359;\n\tbh=xXC1lV3srrMK+FRTgwh3EhB+5Y4Y/P6sCYisSUXpgPo=;\n\th=From:To:Cc:Subject:Date:In-Reply-To:References:From;\n\tb=qQUhZkQkIHgO/WxOWKAVxI0k2hgXas7TgySH7zco8Mjz8jwrAvICJS91pbc858Qko\n\txjOsvEMaQH3evUEKSU0Y7cTF84K2pY9dGMqawiOnVBn0RPQXWlXuSc8aX1q6IN8Fxc\n\twMQY9JfL5pB3MRVntyK/oIbugXHC198Na7sHGdcQ=","From":"Stefan Klug <stefan.klug@ideasonboard.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"Stefan Klug <stefan.klug@ideasonboard.com>","Subject":"[PATCH v3 7/7] [DNI] ipa: Add debug controls to the agc algorithm","Date":"Tue,  8 Oct 2024 17:29:45 +0200","Message-ID":"<20241008153031.429906-8-stefan.klug@ideasonboard.com>","X-Mailer":"git-send-email 2.43.0","In-Reply-To":"<20241008153031.429906-1-stefan.klug@ideasonboard.com>","References":"<20241008153031.429906-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..356eea627f0f 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 was 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":["v3","7/7","DNI"]}