From patchwork Tue Oct 28 21:17:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Rui Wang X-Patchwork-Id: 24884 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 CAE96BE080 for ; Tue, 28 Oct 2025 21:18:57 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7DAFC6089B; Tue, 28 Oct 2025 22:18:57 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="cdL9ZeCA"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 999A760887 for ; Tue, 28 Oct 2025 22:18:53 +0100 (CET) Received: from rui-Precision-7560.local (unknown [209.216.122.90]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 712861864; Tue, 28 Oct 2025 22:17:04 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1761686225; bh=1nrA08DwgiY3jQFsCGYM5LlwqCP9ZaNyZYYHOzYXTe4=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cdL9ZeCA3W3v4kTd132T1dE5gfRW8xKIwLAut7cJ7+5cYhzQIV82FBF4yasAGFM3O oZ3zVQkFpBgS33Ib/QPwDC/mnhNkImz5TXeSZ08YogeZ09lMchr57nHlmATuy+ibih XEmiev+4J5jgfhLb+4XwztAcTC9eyqOfVN48MyaM= From: Rui Wang To: libcamera-devel@lists.libcamera.org Cc: Rui Wang Subject: [PATCH v1 14/17] ipa: rkisp1: algorithms: dpf: refactor DPF prepare flow Date: Tue, 28 Oct 2025 17:17:47 -0400 Message-ID: <20251028211751.2761420-14-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" Split prepare() into explicit auto and manual mode branches. The auto path selects ISO bands and disables processing at high light levels, while the manual path applies user overrides before programming hardware. Key changes: - prepare() now branches to prepareAutoMode or prepareManualMode - prepareAutoMode(): Handles ISO band selection, disables DPF at ISO≤100, programs hardware with selected config - prepareManualMode(): Programs base config then applies manual overrides via applyOverridesTo() - Both modes call logConfigIfChanged() for visibility - Added debug logging to queueRequest() The refactor removes the old AWB/LSC gain mode logic, now relying on gain_mode from tuning configuration. Signed-off-by: Rui Wang --- src/ipa/rkisp1/algorithms/denoise.h | 6 ++ src/ipa/rkisp1/algorithms/dpf.cpp | 113 ++++++++++++++++++++-------- src/ipa/rkisp1/algorithms/dpf.h | 6 ++ 3 files changed, 92 insertions(+), 33 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/denoise.h b/src/ipa/rkisp1/algorithms/denoise.h index c4b5b0af..e2bedc41 100644 --- a/src/ipa/rkisp1/algorithms/denoise.h +++ b/src/ipa/rkisp1/algorithms/denoise.h @@ -54,6 +54,12 @@ protected: virtual void restoreAutoConfig(IPAContext &context, IPAFrameContext &frameContext) = 0; + virtual void prepareAutoMode(IPAContext &context, const uint32_t frame, + IPAFrameContext &frameContext, RkISP1Params *params) = 0; + + virtual void prepareManualMode(IPAContext &context, const uint32_t frame, + IPAFrameContext &frameContext, RkISP1Params *params) = 0; + private: bool manualMode_ = false; /**< Current manual/auto mode state */ bool devMode_ = false; /**< Developer mode state for advanced controls */ diff --git a/src/ipa/rkisp1/algorithms/dpf.cpp b/src/ipa/rkisp1/algorithms/dpf.cpp index 75e083eb..c4597932 100644 --- a/src/ipa/rkisp1/algorithms/dpf.cpp +++ b/src/ipa/rkisp1/algorithms/dpf.cpp @@ -542,6 +542,11 @@ void Dpf::queueRequest(IPAContext &context, frameContext.dpf.update = true; } } + + LOG(RkISP1Dpf, Debug) << "queueRequest: denoise=" << frameContext.dpf.denoise + << ", update=" << frameContext.dpf.update + << (enableDpf_ ? "" : " (DPF disabled)") + << (modeChanged ? " (mode change)" : ""); } /** @@ -550,42 +555,84 @@ void Dpf::queueRequest(IPAContext &context, void Dpf::prepare(IPAContext &context, const uint32_t frame, IPAFrameContext &frameContext, RkISP1Params *params) { + // check if master denoise toggle on + if (!frameContext.dpf.denoise) { + auto cfg = params->block(); + cfg.setEnabled(false); + auto str = params->block(); + str.setEnabled(false); + return; + } + + if (isManualMode()) + prepareManualMode(context, frame, frameContext, params); + else + prepareAutoMode(context, frame, frameContext, params); +} + +void Dpf::prepareAutoMode(IPAContext &context, const uint32_t frame, + IPAFrameContext &frameContext, RkISP1Params *params) +{ + unsigned iso = computeIso(context, frameContext); + bool baseIsoSkip = iso <= 100; + + // Select different dpf config determined by iso Level + if (useIsoLevels_) { + int idx = DenoiseBaseAlgorithm::selectIsoBand(iso, isoLevels_); + if (idx >= 0 && idx != lastIsoIndex_) { + config_ = isoLevels_[idx].dpf; + strengthConfig_ = isoLevels_[idx].strength; + frameContext.dpf.update = true; + lastIsoIndex_ = idx; + } + } + // Disable dpf denoise due to high light + if (baseIsoSkip) { + auto cfg = params->block(); + cfg.setEnabled(false); + auto str = params->block(); + str.setEnabled(false); + return; + } + if (!frameContext.dpf.update && frame > 0) return; - auto config = params->block(); - config.setEnabled(frameContext.dpf.denoise); - - if (frameContext.dpf.denoise) { - *config = config_; - - const auto &awb = context.configuration.awb; - const auto &lsc = context.configuration.lsc; - - auto &mode = config->gain.mode; - - /* - * The DPF needs to take into account the total amount of - * digital gain, which comes from the AWB and LSC modules. The - * DPF hardware can be programmed with a digital gain value - * manually, but can also use the gains supplied by the AWB and - * LSC modules automatically when they are enabled. Use that - * mode of operation as it simplifies control of the DPF. - */ - if (awb.enabled && lsc.enabled) - mode = RKISP1_CIF_ISP_DPF_GAIN_USAGE_AWB_LSC_GAINS; - else if (awb.enabled) - mode = RKISP1_CIF_ISP_DPF_GAIN_USAGE_AWB_GAINS; - else if (lsc.enabled) - mode = RKISP1_CIF_ISP_DPF_GAIN_USAGE_LSC_GAINS; - else - mode = RKISP1_CIF_ISP_DPF_GAIN_USAGE_DISABLED; - } - - if (frame == 0) { - auto strengthConfig = params->block(); - strengthConfig.setEnabled(true); - *strengthConfig = strengthConfig_; + auto cfgBlock = params->block(); + cfgBlock.setEnabled(true); + *cfgBlock = config_; + + cfgBlock->gain.mode = config_.gain.mode; + + if (frameContext.dpf.update) { + auto strBlock = params->block(); + strBlock.setEnabled(true); + *strBlock = strengthConfig_; + logConfigIfChanged(iso, lastIsoIndex_, false, frameContext); + } +} + +void Dpf::prepareManualMode(IPAContext &context, const uint32_t frame, + IPAFrameContext &frameContext, RkISP1Params *params) +{ + unsigned iso = computeIso(context, frameContext); + + if (!frameContext.dpf.update && frame > 0) + return; + + auto cfgBlock = params->block(); + cfgBlock.setEnabled(true); + *cfgBlock = config_; + + cfgBlock->gain.mode = config_.gain.mode; + + if (frame == 0 || frameContext.dpf.update) { + auto strBlock = params->block(); + strBlock.setEnabled(true); + *strBlock = strengthConfig_; + bool anyOverride = false; + applyOverridesTo(*cfgBlock, *strBlock, anyOverride); + logConfigIfChanged(iso, lastIsoIndex_, anyOverride, frameContext); } } diff --git a/src/ipa/rkisp1/algorithms/dpf.h b/src/ipa/rkisp1/algorithms/dpf.h index 8c34abcf..d84ba45f 100644 --- a/src/ipa/rkisp1/algorithms/dpf.h +++ b/src/ipa/rkisp1/algorithms/dpf.h @@ -105,6 +105,12 @@ private: 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); + + void prepareAutoMode(IPAContext &context, const uint32_t frame, + IPAFrameContext &frameContext, RkISP1Params *params) override; + + void prepareManualMode(IPAContext &context, const uint32_t frame, + IPAFrameContext &frameContext, RkISP1Params *params) override; }; } /* namespace ipa::rkisp1::algorithms */