From patchwork Tue Oct 8 15:29:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 21545 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 87FF0BE080 for ; Tue, 8 Oct 2024 15:30:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3DA1365372; Tue, 8 Oct 2024 17:30:57 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="qQUhZkQk"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8FB636536A for ; Tue, 8 Oct 2024 17:30:55 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:d:f30b:aa60:fabf]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id D3EF1DB2; Tue, 8 Oct 2024 17:29:18 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1728401359; bh=xXC1lV3srrMK+FRTgwh3EhB+5Y4Y/P6sCYisSUXpgPo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=qQUhZkQkIHgO/WxOWKAVxI0k2hgXas7TgySH7zco8Mjz8jwrAvICJS91pbc858Qko xjOsvEMaQH3evUEKSU0Y7cTF84K2pY9dGMqawiOnVBn0RPQXWlXuSc8aX1q6IN8Fxc wMQY9JfL5pB3MRVntyK/oIbugXHC198Na7sHGdcQ= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug 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 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Add a few (arbitrary) debug metadata to the agc algorithm. This shows how easy it is to add debug metadata to an ipa even for classes that don't have direct access to the metadata list or the context like AgcMeanLuminance. The control_ids_debug.yaml was autogenerated by calling utils/gen-debug-controls.py Signed-off-by: Stefan Klug --- Update in v2: - Break too long line in agc.cpp --- src/ipa/libipa/agc_mean_luminance.cpp | 8 ++++++++ src/ipa/libipa/agc_mean_luminance.h | 4 ++++ src/ipa/rkisp1/algorithms/agc.cpp | 10 ++++++++++ src/libcamera/control_ids_debug.yaml | 21 ++++++++++++++++++++- 4 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp index f97ef11771c4..bd0f85afcd2e 100644 --- a/src/ipa/libipa/agc_mean_luminance.cpp +++ b/src/ipa/libipa/agc_mean_luminance.cpp @@ -133,6 +133,11 @@ static constexpr double kDefaultRelativeLuminanceTarget = 0.16; * values. */ +/** + * \var AgcMeanLuminance::debugMeta_ + * \brief DebugMetadata helper + */ + AgcMeanLuminance::AgcMeanLuminance() : frameCount_(0), filteredExposure_(0s), relativeLuminanceTarget_(0) { @@ -541,8 +546,11 @@ AgcMeanLuminance::calculateNewEv(uint32_t constraintModeIndex, exposureModeHelpers_.at(exposureModeIndex); double gain = estimateInitialGain(); + debugMeta_.set(controls::debug::AgcInitialGain, static_cast(gain)); gain = constraintClampGain(constraintModeIndex, yHist, gain); + debugMeta_.set(controls::debug::AgcNewGain, static_cast(gain)); + /* * We don't check whether we're already close to the target, because * even if the effective exposure value is the same as the last frame's diff --git a/src/ipa/libipa/agc_mean_luminance.h b/src/ipa/libipa/agc_mean_luminance.h index 576d28be8eb0..428465a11a36 100644 --- a/src/ipa/libipa/agc_mean_luminance.h +++ b/src/ipa/libipa/agc_mean_luminance.h @@ -16,6 +16,7 @@ #include +#include "libcamera/internal/debug_controls.h" #include "libcamera/internal/yaml_parser.h" #include "exposure_mode_helper.h" @@ -71,6 +72,9 @@ public: frameCount_ = 0; } +protected: + DebugMetadata debugMeta_; + private: virtual double estimateLuminance(const double gain) const = 0; diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp index 17d074d9c03e..6668db942042 100644 --- a/src/ipa/rkisp1/algorithms/agc.cpp +++ b/src/ipa/rkisp1/algorithms/agc.cpp @@ -139,6 +139,8 @@ int Agc::init(IPAContext &context, const YamlObject &tuningData) { int ret; + debugMeta_.setParent(&context.debugMetadata); + ret = parseTuningData(tuningData); if (ret) return ret; @@ -444,6 +446,14 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame, frameContext.agc.exposureMode, hist, effectiveExposureValue); + debugMeta_.set(controls::debug::AgcAnalogGain, aGain); + debugMeta_.set(controls::debug::AgcDigitalGain, dGain); + + const Span orig = hist.data(); + const Span data{ reinterpret_cast(&orig[0]), + orig.size() }; + debugMeta_.set>(controls::debug::AgcHistogram, data); + LOG(RkISP1Agc, Debug) << "Divided up shutter, analogue gain and digital gain are " << shutterTime << ", " << aGain << " and " << dGain; diff --git a/src/libcamera/control_ids_debug.yaml b/src/libcamera/control_ids_debug.yaml index 797532712099..356eea627f0f 100644 --- a/src/libcamera/control_ids_debug.yaml +++ b/src/libcamera/control_ids_debug.yaml @@ -1,6 +1,25 @@ # SPDX-License-Identifier: LGPL-2.1-or-later # +# This file was generated by utils/gen-debug-controls.py +# %YAML 1.1 --- vendor: debug -controls: [] +controls: +- AgcAnalogGain: + type: float + description: Debug control AgcAnalogGain found in src/ipa/rkisp1/algorithms/agc.cpp:448 +- AgcDigitalGain: + type: float + description: Debug control AgcDigitalGain found in src/ipa/rkisp1/algorithms/agc.cpp:449 +- AgcHistogram: + type: int64_t + description: Debug control AgcHistogram found in src/ipa/rkisp1/algorithms/agc.cpp:454 + size: '[n]' +- AgcInitialGain: + type: float + description: Debug control AgcInitialGain found in src/ipa/libipa/agc_mean_luminance.cpp:548 +- AgcNewGain: + type: float + description: Debug control AgcNewGain found in src/ipa/libipa/agc_mean_luminance.cpp:551 +