[v9,3/6] ipa: rkisp1: algorithms: dpf: Refactor prepare() into helpers
diff mbox series

Message ID 20260118203119.1554962-4-rui.wang@ideasonboard.com
State New
Headers show
Series
  • refactor DPF parsing and initialization
Related show

Commit Message

Rui Wang Jan. 18, 2026, 8:31 p.m. UTC
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 <rui.wang@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>

---
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(-)

Patch
diff mbox series

diff --git a/src/ipa/rkisp1/algorithms/dpf.cpp b/src/ipa/rkisp1/algorithms/dpf.cpp
index d79cc5ff..f300d0a5 100644
--- a/src/ipa/rkisp1/algorithms/dpf.cpp
+++ b/src/ipa/rkisp1/algorithms/dpf.cpp
@@ -338,40 +338,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<BlockType::Dpf>();
+	dpfConfig.setEnabled(false);
+	auto dpfStrength = params->block<BlockType::DpfStrength>();
+	dpfStrength.setEnabled(false);
+}
+
+void Dpf::prepareEnabledMode(IPAContext &context, RkISP1Params *params)
+{
+	if (activeMode_ == noiseReductionModes_.end())
+		return;
+
+	const ModeConfig &modeConfig = *activeMode_;
+
 	auto config = params->block<BlockType::Dpf>();
-	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<BlockType::DpfStrength>();
-	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 11fc88e4..df9d5746 100644
--- a/src/ipa/rkisp1/algorithms/dpf.h
+++ b/src/ipa/rkisp1/algorithms/dpf.h
@@ -43,6 +43,9 @@  private:
 
 	bool loadConfig(int32_t mode);
 
+	void prepareDisabledMode(RkISP1Params *params);
+	void prepareEnabledMode(IPAContext &context, RkISP1Params *params);
+
 	std::vector<ModeConfig> noiseReductionModes_;
 	std::vector<ModeConfig>::const_iterator activeMode_;
 };