From patchwork Tue Nov 25 00:08: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: 25176 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 65AECC32EF for ; Tue, 25 Nov 2025 00:09:22 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id EC21F60AB4; Tue, 25 Nov 2025 01:09:21 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="WNndxMjw"; 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 55BD960AAF for ; Tue, 25 Nov 2025 01:09:18 +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 6B9DD17EB; Tue, 25 Nov 2025 01:07:09 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1764029229; bh=p9snf8mTJT/16VHTZjuDYk8EWD3+ktBVRGJUPKtlsHE=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=WNndxMjwHRe+fMWKlTHY6kcXp9UUw/GjtqPqfCce8VDEj4fh2dPtKVIBGmCVu8s5X mkmguEscVGVF+ingIKZK391TBds7OV/6tAN6cOdb2QBVYeDxJZAT/jX0rkIqDZU9eG 4jNNhcKMd9z6vBefp6bHv1oYYjgcT+2olqhoznW8= From: Rui Wang To: libcamera-devel@lists.libcamera.org Cc: Rui Wang Subject: [PATCH v1 09/11] ipa: rkisp1: algorithms: dpf: refactor DPF prepare flow Date: Mon, 24 Nov 2025 19:08:46 -0500 Message-ID: <20251125000848.4103786-10-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" Split prepare() into explicit auto and manual mode branches. The auto path selects exposure index bands while the manual path applies user overrides before programming hardware. Key changes: - prepare() now branches to prepareAutoMode or prepareManualMode - Added debug logging to queueRequest() Signed-off-by: Rui Wang --- src/ipa/rkisp1/algorithms/denoise.h | 12 +++ src/ipa/rkisp1/algorithms/dpf.cpp | 127 +++++++++++++++++++++------- src/ipa/rkisp1/algorithms/dpf.h | 5 ++ 3 files changed, 113 insertions(+), 31 deletions(-) diff --git a/src/ipa/rkisp1/algorithms/denoise.h b/src/ipa/rkisp1/algorithms/denoise.h index 4c917c1a..f07c14fe 100644 --- a/src/ipa/rkisp1/algorithms/denoise.h +++ b/src/ipa/rkisp1/algorithms/denoise.h @@ -58,6 +58,18 @@ protected: } virtual int32_t getRunningMode() const { return currentRunMode_; } virtual void setRunningMode(int32_t mode) { currentRunMode_ = mode; } + virtual void prepareDisabledMode([[maybe_unused]] IPAContext &context, + [[maybe_unused]] const uint32_t frame, + [[maybe_unused]] IPAFrameContext &frameContext, + [[maybe_unused]] RkISP1Params *params) + { + } + virtual void prepareEnabledMode([[maybe_unused]] IPAContext &context, + [[maybe_unused]] const uint32_t frame, + [[maybe_unused]] IPAFrameContext &frameContext, + [[maybe_unused]] RkISP1Params *params) + { + } private: /**< Developer mode state for advanced controls */ bool devMode_ = false; diff --git a/src/ipa/rkisp1/algorithms/dpf.cpp b/src/ipa/rkisp1/algorithms/dpf.cpp index c88f5c69..e3293241 100644 --- a/src/ipa/rkisp1/algorithms/dpf.cpp +++ b/src/ipa/rkisp1/algorithms/dpf.cpp @@ -748,41 +748,106 @@ void Dpf::prepare(IPAContext &context, const uint32_t frame, { if (!frameContext.dpf.update && frame > 0) return; + /* Check if denoise toggle off */ + if (!frameContext.dpf.denoise) { + auto cfg = params->block(); + cfg.setEnabled(false); + auto str = params->block(); + str.setEnabled(false); + setRunningMode(controls::rkisp1::DenoiseModeDisabled); + return; + } - auto config = params->block(); - config.setEnabled(frameContext.dpf.denoise); - - auto strengthConfig = params->block(); - strengthConfig.setEnabled(frameContext.dpf.denoise); - - if (frameContext.dpf.denoise) { - *config = config_; - *strengthConfig = strengthConfig_; - - 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; + switch (getRunningMode()) { + case controls::rkisp1::DenoiseModeDisabled: + prepareDisabledMode(context, frame, frameContext, params); + break; + case controls::rkisp1::DenoiseModeAuto: + case controls::rkisp1::DenoiseModeManual: + case controls::rkisp1::DenoiseModeReduction: + prepareEnabledMode(context, frame, frameContext, params); + break; + default: + LOG(RkISP1Dpf, Warning) << "DPF in unknown mode"; + break; } } +void Dpf::prepareEnabledMode(IPAContext &context, const uint32_t frame, + IPAFrameContext &frameContext, RkISP1Params *params) +{ + uint32_t exposureGainIndex = computeExposureIndex(context, frameContext); + + if (!frameContext.dpf.update && frame > 0) + return; + + /* Select different DPF config determined by exposure index level for Auto mode */ + if (getRunningMode() == controls::rkisp1::DenoiseModeAuto && useExposureIndexLevels_) { + int32_t idx = + DenoiseBaseAlgorithm::selectExposureIndexBand( + exposureGainIndex, exposureIndexLevels_); + if (idx >= 0 && idx != lastExposureGainIndex_) { + config_ = exposureIndexLevels_[idx].dpf; + strengthConfig_ = exposureIndexLevels_[idx].strength; + frameContext.dpf.update = true; + lastExposureGainIndex_ = idx; + } + } + + auto cfgBlock = params->block(); + cfgBlock.setEnabled(true); + *cfgBlock = config_; + + /* + * 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. + */ + const auto &awb = context.configuration.awb; + const auto &lsc = context.configuration.lsc; + auto &mode = cfgBlock->gain.mode; + + 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; + + config_.gain.mode = mode; + + auto strBlock = params->block(); + strBlock.setEnabled(true); + + *strBlock = strengthConfig_; + bool anyOverride = false; + if (getRunningMode() == controls::rkisp1::DenoiseModeManual) + applyOverridesTo(*cfgBlock, *strBlock, anyOverride); + + int32_t exposureGainIdx = lastExposureGainIndex_; + if (getRunningMode() == controls::rkisp1::DenoiseModeReduction) + exposureGainIdx = -1; + + logConfigIfChanged(exposureGainIndex, exposureGainIdx, anyOverride, frameContext); +} + +void Dpf::prepareDisabledMode([[maybe_unused]] IPAContext &context, + [[maybe_unused]] const uint32_t frame, + [[maybe_unused]] IPAFrameContext &frameContext, + RkISP1Params *params) +{ + frameContext.dpf.denoise = false; + auto cfg = params->block(); + cfg.setEnabled(false); + auto str = params->block(); + str.setEnabled(false); +} + REGISTER_IPA_ALGORITHM(Dpf, "Dpf") } /* namespace ipa::rkisp1::algorithms */ diff --git a/src/ipa/rkisp1/algorithms/dpf.h b/src/ipa/rkisp1/algorithms/dpf.h index abcdf8ee..86085cf9 100644 --- a/src/ipa/rkisp1/algorithms/dpf.h +++ b/src/ipa/rkisp1/algorithms/dpf.h @@ -97,6 +97,11 @@ private: int32_t exposureBandIndex, bool anyOverride, const IPAFrameContext &frameContext); + void prepareDisabledMode(IPAContext &context, const uint32_t frame, + IPAFrameContext &frameContext, + RkISP1Params *params) override; + void prepareEnabledMode(IPAContext &context, const uint32_t frame, + IPAFrameContext &frameContext, RkISP1Params *params) override; }; } /* namespace ipa::rkisp1::algorithms */