From patchwork Tue Nov 25 00:08:45 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rui Wang X-Patchwork-Id: 25175 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 373E9C3257 for ; Tue, 25 Nov 2025 00:09:21 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0C87B60AB5; Tue, 25 Nov 2025 01:09:20 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="gPIAQ+jE"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D2C13608CF for ; Tue, 25 Nov 2025 01:09:16 +0100 (CET) Received: from rui-Precision-7560.local (unknown [IPv6:2607:fea8:935b:7220:cb34:a7b8:53d:5466]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 097E41785; Tue, 25 Nov 2025 01:07:07 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1764029228; bh=VJCQePz+9Lhqe9GTyMtTSklznvMT0HOuuL/2HWrfeb0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gPIAQ+jEIytSkbJHJnmZBG7Q6mznviTKWWg7QjvCDvoyKq3gbDuWNSKYkzwacfEHe 9peEkrCLB9cvy9KFbAtaFZwYNkO77hHE2umbEfnX3HoAWzQuZEi2SxiQQRQJk16Tu7 HDmotj3EDnfNmdmhyO+bgN513/qu4+SqwOFhTgfQ= From: Rui Wang To: libcamera-devel@lists.libcamera.org Cc: Rui Wang Subject: [PATCH v1 08/11] ipa: rkisp1: algorithms: dpf: apply DPF overrides Date: Mon, 24 Nov 2025 19:08:45 -0500 Message-ID: <20251125000848.4103786-9-rui.wang@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251125000848.4103786-1-rui.wang@ideasonboard.com> References: <20251125000848.4103786-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, gain band selection, and control mode. Uses static state tracking to log only when changes occur. Signed-off-by: Rui Wang --- src/ipa/rkisp1/algorithms/dpf.cpp | 135 ++++++++++++++++++++++++++++++ src/ipa/rkisp1/algorithms/dpf.h | 9 +- 2 files changed, 142 insertions(+), 2 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/dpf.cpp b/src/ipa/rkisp1/algorithms/dpf.cpp index 91bcd503..c88f5c69 100644 --- a/src/ipa/rkisp1/algorithms/dpf.cpp +++ b/src/ipa/rkisp1/algorithms/dpf.cpp @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -555,6 +556,140 @@ bool Dpf::processModeChange(const ControlList &controls, [[maybe_unused]] uint32 return (currentMode != getRunningMode()); } +void Dpf::applyOverridesTo(rkisp1_cif_isp_dpf_config &config, + rkisp1_cif_isp_dpf_strength_config &strengthConfig, + bool &anyOverride) +{ + if (getRunningMode() != controls::rkisp1::DenoiseModeManual) + return; + /* only apply overrides in manual mode */ + if (overrides_.strength) { + strengthConfig.r = overrides_.strength->r; + strengthConfig.g = overrides_.strength->g; + strengthConfig.b = overrides_.strength->b; + anyOverride = true; + } + if (overrides_.spatialGreen) { + std::copy(overrides_.spatialGreen->coeffs.begin(), overrides_.spatialGreen->coeffs.end(), + config.g_flt.spatial_coeff); + anyOverride = true; + } + if (overrides_.spatialRb) { + std::copy(overrides_.spatialRb->coeffs.begin(), overrides_.spatialRb->coeffs.end(), + config.rb_flt.spatial_coeff); + anyOverride = true; + config.rb_flt.fltsize = *overrides_.rbSize + ? RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_13x9 + : RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_9x9; + anyOverride = true; + } + if (overrides_.nll) { + std::copy(overrides_.nll->coeffs.begin(), overrides_.nll->coeffs.end(), + config.nll.coeff); + config.nll.scale_mode = overrides_.nll->scaleMode + ? RKISP1_CIF_ISP_NLL_SCALE_LOGARITHMIC + : RKISP1_CIF_ISP_NLL_SCALE_LINEAR; + anyOverride = true; + } + if (!anyOverride) + return; + /* Log applied overrides */ + config_ = config; + strengthConfig_ = strengthConfig; + 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(uint32_t exposureGainIndex, + int32_t exposureBandIndex, + bool anyOverride, + const IPAFrameContext &frameContext) +{ + static rkisp1_cif_isp_dpf_config lastCfg{}; + static rkisp1_cif_isp_dpf_strength_config lastStr{}; + static bool haveLast = false; + + /* Check if the DPF configuration or strength settings have changed since the last log */ + /* Use memcmp for byte-wise comparison of the C structs (no operator== defined) */ + bool cfgChanged = !haveLast || memcmp(&lastCfg, &config_, sizeof(config_)) != 0; + bool strChanged = !haveLast || memcmp(&lastStr, &strengthConfig_, sizeof(strengthConfig_)) != 0; + + if (!cfgChanged && !strChanged) + return; + + std::string gCoeffsStr = "["; + for (size_t i = 0; i < RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS; ++i) { + if (i > 0) + gCoeffsStr += ","; + gCoeffsStr += std::to_string(static_cast(config_.g_flt.spatial_coeff[i])); + } + gCoeffsStr += "]"; + + std::string rbCoeffsStr = "["; + for (size_t i = 0; i < RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS; ++i) { + if (i > 0) + rbCoeffsStr += ","; + rbCoeffsStr += std::to_string(static_cast(config_.rb_flt.spatial_coeff[i])); + } + rbCoeffsStr += "]"; + + std::string nllCoeffsStr = "["; + for (size_t i = 0; i < RKISP1_CIF_ISP_DPF_MAX_NLF_COEFFS; ++i) { + if (i > 0) + nllCoeffsStr += ","; + nllCoeffsStr += std::to_string(config_.nll.coeff[i]); + } + nllCoeffsStr += "]"; + + std::string rbFilterSizeStr = + config_.rb_flt.fltsize == RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_13x9 + ? "13x9" + : "9x9"; + std::string nllScaleStr = + config_.nll.scale_mode == RKISP1_CIF_ISP_NLL_SCALE_LOGARITHMIC + ? "log" + : "linear"; + std::string denoiseStr = (frameContext.dpf.denoise ? "enabled" : "disabled"); + std::string overrideStr = (anyOverride ? " (overrides applied)" : ""); + + std::string exposureIndexBandStr; + if (useExposureIndexLevels_ && exposureBandIndex >= 0) { + exposureIndexBandStr = + ", exposureIndex_band=" + std::to_string(exposureBandIndex); + if (lastExposureGainIndex_ != exposureBandIndex) { + exposureIndexBandStr += "(new)"; + } + } + + LOG(RkISP1Dpf, Info) + << "DPF config update: rb_fltsize=" << rbFilterSizeStr + << ", nll_scale=" << nllScaleStr + << ", gain_mode=" << config_.gain.mode + << ", strength=" << (int)strengthConfig_.r << "," + << (int)strengthConfig_.g << "," + << (int)strengthConfig_.b + << ", g=" << gCoeffsStr + << ", rb=" << rbCoeffsStr + << ", nll=" << nllCoeffsStr + << ", exposureIndex=" << exposureGainIndex + << exposureIndexBandStr + << ", control mode=" << static_cast(getRunningMode()) + << ", reduction mode=" << static_cast(currentReductionMode_) + << ", denoise=" << denoiseStr + << overrideStr; + + 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 c63d1558..abcdf8ee 100644 --- a/src/ipa/rkisp1/algorithms/dpf.h +++ b/src/ipa/rkisp1/algorithms/dpf.h @@ -88,10 +88,15 @@ private: rkisp1_cif_isp_dpf_strength_config &strengthConfig); bool processModeChange(const ControlList &controls, uint32_t currentFrame) override; - void snapshotCurrentToOverrides() override; - void restoreAutoConfig(IPAContext &context, IPAFrameContext &frameContext) override; + void applyOverridesTo(rkisp1_cif_isp_dpf_config &config, + rkisp1_cif_isp_dpf_strength_config &strengthConfig, + bool &anyOverride); + void logConfigIfChanged(uint32_t exposureGainIndex, + int32_t exposureBandIndex, + bool anyOverride, + const IPAFrameContext &frameContext); }; } /* namespace ipa::rkisp1::algorithms */