From patchwork Tue Oct 28 17:08:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rui Wang X-Patchwork-Id: 24865 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 04F51BE080 for ; Tue, 28 Oct 2025 17:09:28 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 82FA16086D; Tue, 28 Oct 2025 18:09:27 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="STAh135q"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id DCF1B60831 for ; Tue, 28 Oct 2025 18:09:20 +0100 (CET) Received: from rui-Precision-7560.local (unknown [209.216.122.90]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 074981AED; Tue, 28 Oct 2025 18:07:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761671252; bh=UayJ33sCZKLJm8XhFu0HRt1O7AxezNxr4NJvV45GOW8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=STAh135q+Ws+ZNNbP/DigkBHg7jZugz13qIROKJR51FvpBKUFR4BwoL/XwJSglAs0 X3L3YYKl7xmCJH1EWdb4PHxOXGXx+6ypT+KlcZp+oHUxTT4oeni1SBVTf6+lL7zJcL UQ/tKxb1nDc/2GY9RIGbpyAL1YcPyfYaJ03fLauc= From: Rui Wang To: libcamera-devel@lists.libcamera.org Cc: Rui Wang Subject: [PATCH v1 13/16] ipa: rkisp1: algorithms: dpf: apply DPF overrides Date: Tue, 28 Oct 2025 13:08:42 -0400 Message-ID: <20251028170847.2673396-13-rui.wang@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251028170847.2673396-1-rui.wang@ideasonboard.com> References: <20251028170847.2673396-1-rui.wang@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" Implement applyOverridesTo() to merge manual overrides into hardware state and add logConfigIfChanged() to make configuration updates visible in logs for debugging. applyOverridesTo() applies all collected manual overrides to the DPF configuration in manual mode: - Channel strengths (R/G/B) - Spatial coefficients (green and RB) - RB filter size - NLL coefficients and scale mode logConfigIfChanged() provides detailed logging of configuration changes, including all coefficients, strength values, ISO band selection, and control mode. Uses static state tracking to log only when changes occur. Added include for ostringstream usage in logging. Signed-off-by: Rui Wang --- src/ipa/rkisp1/algorithms/dpf.cpp | 104 ++++++++++++++++++++++++++++++ src/ipa/rkisp1/algorithms/dpf.h | 4 ++ 2 files changed, 108 insertions(+) diff --git a/src/ipa/rkisp1/algorithms/dpf.cpp b/src/ipa/rkisp1/algorithms/dpf.cpp index f6bbe3e4..75e083eb 100644 --- a/src/ipa/rkisp1/algorithms/dpf.cpp +++ b/src/ipa/rkisp1/algorithms/dpf.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -403,6 +404,109 @@ bool Dpf::processModeChange(const ControlList &controls, uint32_t currentFrame) return true; } +void Dpf::applyOverridesTo(rkisp1_cif_isp_dpf_config &cfg, + rkisp1_cif_isp_dpf_strength_config &str, + bool &anyOverride) +{ + if (!isManualMode()) + return; /* only apply overrides in manual mode */ + + if (overrides_.strength) { + str.r = overrides_.strength->r; + str.g = overrides_.strength->g; + str.b = overrides_.strength->b; + anyOverride = true; + } + if (overrides_.spatialGreen) { + for (unsigned i = 0; i < RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS; ++i) { + cfg.g_flt.spatial_coeff[i] = overrides_.spatialGreen->coeffs[i]; + } + anyOverride = true; + } + if (overrides_.spatialRb) { + for (unsigned i = 0; i < RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS; ++i) { + cfg.rb_flt.spatial_coeff[i] = overrides_.spatialRb->coeffs[i]; + } + anyOverride = true; + } + if (overrides_.rbSize) { + cfg.rb_flt.fltsize = *overrides_.rbSize ? RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_13x9 + : RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_9x9; + anyOverride = true; + } + if (overrides_.nll) { + for (unsigned i = 0; i < RKISP1_CIF_ISP_DPF_MAX_NLF_COEFFS; ++i) { + cfg.nll.coeff[i] = overrides_.nll->coeffs[i]; + } + cfg.nll.scale_mode = overrides_.nll->scaleMode ? RKISP1_CIF_ISP_NLL_SCALE_LOGARITHMIC + : RKISP1_CIF_ISP_NLL_SCALE_LINEAR; + anyOverride = true; + } + if (anyOverride) { + config_ = cfg; + strengthConfig_ = str; + LOG(RkISP1Dpf, Info) + << "DPF manual overrides applied: strength=" + << (int)strengthConfig_.r << "," << (int)strengthConfig_.g << "," << (int)strengthConfig_.b + << (overrides_.spatialGreen ? " gKernel" : "") + << (overrides_.spatialRb ? " rbKernel" : "") + << (overrides_.rbSize ? " rbSize" : "") + << (overrides_.nll ? " nll" : ""); + } +} + +void Dpf::logConfigIfChanged(unsigned iso, int isoIndex, bool anyOverride, const IPAFrameContext &frameContext) +{ + static rkisp1_cif_isp_dpf_config lastCfg{}; + static rkisp1_cif_isp_dpf_strength_config lastStr{}; + static bool haveLast = false; + bool cfgChanged = !haveLast || memcmp(&lastCfg, &config_, sizeof(config_)) != 0; + bool strChanged = !haveLast || memcmp(&lastStr, &strengthConfig_, sizeof(strengthConfig_)) != 0; + if (!(cfgChanged || strChanged)) + return; + std::ostringstream gs, rbs, nll; + gs << '['; + rbs << '['; + nll << '['; + for (unsigned i = 0; i < RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS; ++i) { + if (i) { + gs << ','; + rbs << ','; + } + gs << (int)config_.g_flt.spatial_coeff[i]; + rbs << (int)config_.rb_flt.spatial_coeff[i]; + } + for (unsigned i = 0; i < RKISP1_CIF_ISP_DPF_MAX_NLF_COEFFS; ++i) { + if (i) + nll << ','; + nll << config_.nll.coeff[i]; + } + gs << ']'; + rbs << ']'; + nll << ']'; + const char *modeStr = + config_.gain.mode == RKISP1_CIF_ISP_DPF_GAIN_USAGE_AWB_LSC_GAINS ? "AWB+LSC" : config_.gain.mode == RKISP1_CIF_ISP_DPF_GAIN_USAGE_AWB_GAINS ? "AWB" + : config_.gain.mode == RKISP1_CIF_ISP_DPF_GAIN_USAGE_LSC_GAINS ? "LSC" + : config_.gain.mode == RKISP1_CIF_ISP_DPF_GAIN_USAGE_NF_GAINS ? "NF" + : config_.gain.mode == RKISP1_CIF_ISP_DPF_GAIN_USAGE_NF_LSC_GAINS ? "NF+LSC" + : "disabled"; + LOG(RkISP1Dpf, Info) << "DPF config update: rb_fltsize=" + << (config_.rb_flt.fltsize == RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_13x9 ? "13x9" : "9x9") + << ", nll_scale=" + << (config_.nll.scale_mode == RKISP1_CIF_ISP_NLL_SCALE_LOGARITHMIC ? "log" : "linear") + << ", gain_mode=" << modeStr + << ", strength=" << (int)strengthConfig_.r << "," << (int)strengthConfig_.g << "," << (int)strengthConfig_.b + << ", g=" << gs.str() << ", rb=" << rbs.str() << ", nll=" << nll.str() + << ", iso=" << iso + << (useIsoLevels_ && isoIndex >= 0 ? (", iso_band=" + std::to_string(isoIndex) + (lastIsoIndex_ == isoIndex ? "" : "(new)")) : "") + << ", control mode=" << (isManualMode() ? "manual" : "auto") + << ", denoise=" << (frameContext.dpf.denoise ? "enabled" : "disabled") + << (anyOverride ? " (overrides applied)" : ""); + lastCfg = config_; + lastStr = strengthConfig_; + haveLast = true; +} + /** * \copydoc libcamera::ipa::Algorithm::queueRequest */ diff --git a/src/ipa/rkisp1/algorithms/dpf.h b/src/ipa/rkisp1/algorithms/dpf.h index b6676203..8c34abcf 100644 --- a/src/ipa/rkisp1/algorithms/dpf.h +++ b/src/ipa/rkisp1/algorithms/dpf.h @@ -101,6 +101,10 @@ private: void snapshotCurrentToOverrides() override; void restoreAutoConfig(IPAContext &context, IPAFrameContext &frameContext) override; + + void applyOverridesTo(rkisp1_cif_isp_dpf_config &cfg, rkisp1_cif_isp_dpf_strength_config &str, bool &anyOverride); + + void logConfigIfChanged(unsigned iso, int isoIndex, bool anyOverride, const IPAFrameContext &frameContext); }; } /* namespace ipa::rkisp1::algorithms */