From patchwork Tue Oct 28 21:17:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rui Wang X-Patchwork-Id: 24883 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 5A9F1BE080 for ; Tue, 28 Oct 2025 21:18:55 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id C9AFA6086F; Tue, 28 Oct 2025 22:18:54 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="RQexXYOe"; 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 AB71960887 for ; Tue, 28 Oct 2025 22:18:52 +0100 (CET) Received: from rui-Precision-7560.local (unknown [209.216.122.90]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 5E88B1864; Tue, 28 Oct 2025 22:17:03 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761686224; bh=UayJ33sCZKLJm8XhFu0HRt1O7AxezNxr4NJvV45GOW8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=RQexXYOeeHqmwDJq8FKzANap7RyzFf10DGE0mWy5g1YkB48v9n934aaXctQRD4Ybq TQbE0tu15qbkp9XmnNANvA2FPz7Iq38uYBfpNW3ETZDH3yMVoEOvHHtX6Fk/Qkf9Zh Z8h59DYv4+96D3uymkr7DrtEdvs6E6Z8cWSLaiCI= From: Rui Wang To: libcamera-devel@lists.libcamera.org Cc: Rui Wang Subject: [PATCH v1 13/17] ipa: rkisp1: algorithms: dpf: apply DPF overrides Date: Tue, 28 Oct 2025 17:17:46 -0400 Message-ID: <20251028211751.2761420-13-rui.wang@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251028211751.2761420-1-rui.wang@ideasonboard.com> References: <20251028211751.2761420-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 */