From patchwork Wed Oct 2 16:19:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 21478 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 978F3BD80A for ; Wed, 2 Oct 2024 16:20:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4CDD36352A; Wed, 2 Oct 2024 18:20:38 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="JRKcnTTP"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 4F3486352F for ; Wed, 2 Oct 2024 18:20:36 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:b246:b33f:c662:8ae1]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 569093098; Wed, 2 Oct 2024 18:19:03 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1727885943; bh=iUsHsXLqGVAZ7tiP76+J/RvkInfoITXfi1DDTtx72YA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=JRKcnTTP06dd+D9YpP/g8pQ9O2CgcJTLu8IuxdOdGY4xsOpGFkwyirTfG+CdXZ8DG EWbAjLWJbPnu9SyHt4u9EslV44N5IlknM3djYEjS9g9abLC+aHTzOCPdSx49Ix8S0p QHW0HZeK6WJyR5qjmOmTfDydn3Puuva3ko4y7vz4= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH v1 7/8] [WIP] ipa: Add debug controls to the agc algorithm Date: Wed, 2 Oct 2024 18:19:25 +0200 Message-ID: <20241002161933.247091-8-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241002161933.247091-1-stefan.klug@ideasonboard.com> References: <20241002161933.247091-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 --- src/ipa/libipa/agc_mean_luminance.cpp | 8 ++++++++ src/ipa/libipa/agc_mean_luminance.h | 4 ++++ src/ipa/rkisp1/algorithms/agc.cpp | 8 ++++++++ src/libcamera/control_ids_debug.yaml | 17 ++++++++++++++++- 4 files changed, 36 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..2dcee0ceaccf 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_.assignUpstream(&context.debugMetadata); + ret = parseTuningData(tuningData); if (ret) return ret; @@ -444,6 +446,12 @@ 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 auto &data = hist.data(); + debugMeta_.set>(controls::debug::AgcHistogram, Span(reinterpret_cast(&data[0]), data.size())); + 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 11ddfd7cc8d8..d1da5cca2364 100644 --- a/src/libcamera/control_ids_debug.yaml +++ b/src/libcamera/control_ids_debug.yaml @@ -8,4 +8,19 @@ # set through Request::controls() and returned out through Request::metadata(). vendor: debug 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:452 + size: '[n]' +- AgcInitialGain: + type: float + description: Debug control AgcInitialGain found in src/ipa/libipa/agc_mean_luminance.cpp:543 +- AgcNewGain: + type: float + description: Debug control AgcNewGain found in src/ipa/libipa/agc_mean_luminance.cpp:546