From patchwork Tue Jan 20 15:30:54 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rui Wang X-Patchwork-Id: 25894 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 0C9B9BDCBF for ; Tue, 20 Jan 2026 15:31:29 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 8FABC61FC0; Tue, 20 Jan 2026 16:31:27 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="gj5uEwIc"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id BA7C661FC4 for ; Tue, 20 Jan 2026 16:31:19 +0100 (CET) Received: from rui-Precision-7560.local (unknown [209.216.103.65]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id CF0962147; Tue, 20 Jan 2026 16:30:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1768923048; bh=kidW2pGy0cE/9z0Q0icVTy7rVOnQrPu4siusLgmZ29E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gj5uEwIcAeBBCly2sC9kwO8KHIVNVjPk94vmCAJi27FUj0IhwnK4ibhPPQCT5sb+p yUoOPoI+gD6uRy+w6+wn/OxhUXb6YWzIAPc0p90qj+N2rZXkEnGyXjc566PT4x9UBt hTWnG6v5J4Pdzk1VgrDFzalqCf/pEoX4Aopa+1KI= From: Rui Wang To: libcamera-devel@lists.libcamera.org Cc: Rui Wang , Jacopo Mondi Subject: [PATCH v10 4/7] ipa: rkisp1: algorithms: dpf: Refactor prepare() into helpers Date: Tue, 20 Jan 2026 10:30:54 -0500 Message-ID: <20260120153057.1703714-5-rui.wang@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260120153057.1703714-1-rui.wang@ideasonboard.com> References: <20260120153057.1703714-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 the prepare() function into prepareDisabledMode() and prepareEnabledMode() to improve readability and maintainability. This separates the logic for disabling and enabling the DPF, making the main prepare() function cleaner and easier to follow. Signed-off-by: Rui Wang Reviewed-by: Jacopo Mondi --- changelog since v5/v6: Nothing changed changelog since v8 : - remove [[maybe_unused] for prepareEnable and prepareDisable Reviewed-by tags from v5 are carried over (no code changes). --- src/ipa/rkisp1/algorithms/dpf.cpp | 80 +++++++++++++++++++------------ src/ipa/rkisp1/algorithms/dpf.h | 3 ++ 2 files changed, 52 insertions(+), 31 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/dpf.cpp b/src/ipa/rkisp1/algorithms/dpf.cpp index 21ce8ace..ff2cbc28 100644 --- a/src/ipa/rkisp1/algorithms/dpf.cpp +++ b/src/ipa/rkisp1/algorithms/dpf.cpp @@ -358,40 +358,58 @@ void Dpf::prepare(IPAContext &context, const uint32_t frame, if (!frameContext.dpf.update && frame > 0) return; + if (!frameContext.dpf.denoise) { + prepareDisabledMode(params); + return; + } + + prepareEnabledMode(context, params); +} + +void Dpf::prepareDisabledMode(RkISP1Params *params) +{ + auto dpfConfig = params->block(); + dpfConfig.setEnabled(false); + auto dpfStrength = params->block(); + dpfStrength.setEnabled(false); +} + +void Dpf::prepareEnabledMode(IPAContext &context, RkISP1Params *params) +{ + if (activeMode_ == noiseReductionModes_.end()) + return; + + const ModeConfig &modeConfig = *activeMode_; + auto config = params->block(); - config.setEnabled(frameContext.dpf.denoise); + config.setEnabled(true); + *config = modeConfig.dpf; + + 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; auto strengthConfig = params->block(); - strengthConfig.setEnabled(frameContext.dpf.denoise); - - if (frameContext.dpf.denoise) { - const ModeConfig &modeConfig = *activeMode_; - - *config = modeConfig.dpf; - *strengthConfig = modeConfig.strength; - - 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; - } + strengthConfig.setEnabled(true); + *strengthConfig = modeConfig.strength; } REGISTER_IPA_ALGORITHM(Dpf, "Dpf") diff --git a/src/ipa/rkisp1/algorithms/dpf.h b/src/ipa/rkisp1/algorithms/dpf.h index 43effcbe..208d8fe9 100644 --- a/src/ipa/rkisp1/algorithms/dpf.h +++ b/src/ipa/rkisp1/algorithms/dpf.h @@ -44,6 +44,9 @@ private: bool loadConfig(int32_t mode); + void prepareDisabledMode(RkISP1Params *params); + void prepareEnabledMode(IPAContext &context, RkISP1Params *params); + std::vector noiseReductionModes_; std::vector::const_iterator activeMode_; };