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

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

Commit Message

Rui Wang Dec. 14, 2025, 6:16 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>
---

changelog :
 - Add blank line into code
 - removing  frameContext.dpf.denoise = false in prepareDisabledMode
 
 src/ipa/rkisp1/algorithms/dpf.cpp | 80 ++++++++++++++++++++-----------
 src/ipa/rkisp1/algorithms/dpf.h   |  7 +++
 2 files changed, 58 insertions(+), 29 deletions(-)

Comments

Jacopo Mondi Dec. 16, 2025, 5:01 p.m. UTC | #1
Hi Rui

On Sun, Dec 14, 2025 at 01:16:43PM -0500, Rui Wang wrote:
> 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>

Please remember to collect tags
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>

if you intentially leave them out, because you think the patch has
changed and you want reviewers to have a full review again, please
mention it, otherwise carry the tags over to the next version!

Thanks
  j
> ---
>
> changelog :
>  - Add blank line into code
>  - removing  frameContext.dpf.denoise = false in prepareDisabledMode
>
>  src/ipa/rkisp1/algorithms/dpf.cpp | 80 ++++++++++++++++++++-----------
>  src/ipa/rkisp1/algorithms/dpf.h   |  7 +++
>  2 files changed, 58 insertions(+), 29 deletions(-)
>
> diff --git a/src/ipa/rkisp1/algorithms/dpf.cpp b/src/ipa/rkisp1/algorithms/dpf.cpp
> index 392edda1..677239ca 100644
> --- a/src/ipa/rkisp1/algorithms/dpf.cpp
> +++ b/src/ipa/rkisp1/algorithms/dpf.cpp
> @@ -325,38 +325,60 @@ void Dpf::prepare(IPAContext &context, const uint32_t frame,
>  	if (!frameContext.dpf.update && frame > 0)
>  		return;
>
> +	if (!frameContext.dpf.denoise) {
> +		prepareDisabledMode(context, frame, frameContext, params);
> +		return;
> +	}
> +
> +	prepareEnabledMode(context, frame, frameContext, params);
> +}
> +
> +void Dpf::prepareDisabledMode([[maybe_unused]] IPAContext &context,
> +			      [[maybe_unused]] const uint32_t frame,
> +			      [[maybe_unused]] IPAFrameContext &frameContext,
> +			      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, [[maybe_unused]] const uint32_t frame,
> +			     [[maybe_unused]] IPAFrameContext &frameContext,
> +			     RkISP1Params *params)
> +{
>  	auto config = params->block<BlockType::Dpf>();
> -	config.setEnabled(frameContext.dpf.denoise);
> +	config.setEnabled(true);
> +	*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;
> +
> +	config_.gain.mode = mode;
>
>  	auto strengthConfig = params->block<BlockType::DpfStrength>();
> -	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;
> -	}
> +	strengthConfig.setEnabled(true);
> +	*strengthConfig = strengthConfig_;
>  }
>
>  REGISTER_IPA_ALGORITHM(Dpf, "Dpf")
> diff --git a/src/ipa/rkisp1/algorithms/dpf.h b/src/ipa/rkisp1/algorithms/dpf.h
> index 2a2c7052..fcf121cb 100644
> --- a/src/ipa/rkisp1/algorithms/dpf.h
> +++ b/src/ipa/rkisp1/algorithms/dpf.h
> @@ -44,6 +44,13 @@ private:
>
>  	bool loadReductionConfig(int32_t mode);
>
> +	void prepareDisabledMode(IPAContext &context, const uint32_t frame,
> +				 IPAFrameContext &frameContext,
> +				 RkISP1Params *params);
> +	void prepareEnabledMode(IPAContext &context, const uint32_t frame,
> +				IPAFrameContext &frameContext,
> +				RkISP1Params *params);
> +
>  	struct rkisp1_cif_isp_dpf_config config_;
>  	struct rkisp1_cif_isp_dpf_strength_config strengthConfig_;
>  	std::vector<ModeConfig> noiseReductionModes_;
> --
> 2.43.0
>
Rui Wang Dec. 18, 2025, 4:23 p.m. UTC | #2
Thanks Jacopo,

Quoting Jacopo Mondi (2025-12-16 12:01:07)
> Hi Rui
> 
> On Sun, Dec 14, 2025 at 01:16:43PM -0500, Rui Wang wrote:
> > 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>
> 
> Please remember to collect tags
> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
> 
> if you intentially leave them out, because you think the patch has
> changed and you want reviewers to have a full review again, please
> mention it, otherwise carry the tags over to the next version!
> 
> Thanks
>   j

Yes , I will add those reviewed tag into change log in next series.

> > ---
> >
> > changelog :
> >  - Add blank line into code
> >  - removing  frameContext.dpf.denoise = false in prepareDisabledMode
> >
> >  src/ipa/rkisp1/algorithms/dpf.cpp | 80 ++++++++++++++++++++-----------
> >  src/ipa/rkisp1/algorithms/dpf.h   |  7 +++
> >  2 files changed, 58 insertions(+), 29 deletions(-)
> >
> > diff --git a/src/ipa/rkisp1/algorithms/dpf.cpp b/src/ipa/rkisp1/algorithms/dpf.cpp
> > index 392edda1..677239ca 100644
> > --- a/src/ipa/rkisp1/algorithms/dpf.cpp
> > +++ b/src/ipa/rkisp1/algorithms/dpf.cpp
> > @@ -325,38 +325,60 @@ void Dpf::prepare(IPAContext &context, const uint32_t frame,
> >       if (!frameContext.dpf.update && frame > 0)
> >               return;
> >
> > +     if (!frameContext.dpf.denoise) {
> > +             prepareDisabledMode(context, frame, frameContext, params);
> > +             return;
> > +     }
> > +
> > +     prepareEnabledMode(context, frame, frameContext, params);
> > +}
> > +
> > +void Dpf::prepareDisabledMode([[maybe_unused]] IPAContext &context,
> > +                           [[maybe_unused]] const uint32_t frame,
> > +                           [[maybe_unused]] IPAFrameContext &frameContext,
> > +                           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, [[maybe_unused]] const uint32_t frame,
> > +                          [[maybe_unused]] IPAFrameContext &frameContext,
> > +                          RkISP1Params *params)
> > +{
> >       auto config = params->block<BlockType::Dpf>();
> > -     config.setEnabled(frameContext.dpf.denoise);
> > +     config.setEnabled(true);
> > +     *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;
> > +
> > +     config_.gain.mode = mode;
> >
> >       auto strengthConfig = params->block<BlockType::DpfStrength>();
> > -     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;
> > -     }
> > +     strengthConfig.setEnabled(true);
> > +     *strengthConfig = strengthConfig_;
> >  }
> >
> >  REGISTER_IPA_ALGORITHM(Dpf, "Dpf")
> > diff --git a/src/ipa/rkisp1/algorithms/dpf.h b/src/ipa/rkisp1/algorithms/dpf.h
> > index 2a2c7052..fcf121cb 100644
> > --- a/src/ipa/rkisp1/algorithms/dpf.h
> > +++ b/src/ipa/rkisp1/algorithms/dpf.h
> > @@ -44,6 +44,13 @@ private:
> >
> >       bool loadReductionConfig(int32_t mode);
> >
> > +     void prepareDisabledMode(IPAContext &context, const uint32_t frame,
> > +                              IPAFrameContext &frameContext,
> > +                              RkISP1Params *params);
> > +     void prepareEnabledMode(IPAContext &context, const uint32_t frame,
> > +                             IPAFrameContext &frameContext,
> > +                             RkISP1Params *params);
> > +
> >       struct rkisp1_cif_isp_dpf_config config_;
> >       struct rkisp1_cif_isp_dpf_strength_config strengthConfig_;
> >       std::vector<ModeConfig> noiseReductionModes_;
> > --
> > 2.43.0
> >

Patch
diff mbox series

diff --git a/src/ipa/rkisp1/algorithms/dpf.cpp b/src/ipa/rkisp1/algorithms/dpf.cpp
index 392edda1..677239ca 100644
--- a/src/ipa/rkisp1/algorithms/dpf.cpp
+++ b/src/ipa/rkisp1/algorithms/dpf.cpp
@@ -325,38 +325,60 @@  void Dpf::prepare(IPAContext &context, const uint32_t frame,
 	if (!frameContext.dpf.update && frame > 0)
 		return;
 
+	if (!frameContext.dpf.denoise) {
+		prepareDisabledMode(context, frame, frameContext, params);
+		return;
+	}
+
+	prepareEnabledMode(context, frame, frameContext, params);
+}
+
+void Dpf::prepareDisabledMode([[maybe_unused]] IPAContext &context,
+			      [[maybe_unused]] const uint32_t frame,
+			      [[maybe_unused]] IPAFrameContext &frameContext,
+			      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, [[maybe_unused]] const uint32_t frame,
+			     [[maybe_unused]] IPAFrameContext &frameContext,
+			     RkISP1Params *params)
+{
 	auto config = params->block<BlockType::Dpf>();
-	config.setEnabled(frameContext.dpf.denoise);
+	config.setEnabled(true);
+	*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;
+
+	config_.gain.mode = mode;
 
 	auto strengthConfig = params->block<BlockType::DpfStrength>();
-	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;
-	}
+	strengthConfig.setEnabled(true);
+	*strengthConfig = strengthConfig_;
 }
 
 REGISTER_IPA_ALGORITHM(Dpf, "Dpf")
diff --git a/src/ipa/rkisp1/algorithms/dpf.h b/src/ipa/rkisp1/algorithms/dpf.h
index 2a2c7052..fcf121cb 100644
--- a/src/ipa/rkisp1/algorithms/dpf.h
+++ b/src/ipa/rkisp1/algorithms/dpf.h
@@ -44,6 +44,13 @@  private:
 
 	bool loadReductionConfig(int32_t mode);
 
+	void prepareDisabledMode(IPAContext &context, const uint32_t frame,
+				 IPAFrameContext &frameContext,
+				 RkISP1Params *params);
+	void prepareEnabledMode(IPAContext &context, const uint32_t frame,
+				IPAFrameContext &frameContext,
+				RkISP1Params *params);
+
 	struct rkisp1_cif_isp_dpf_config config_;
 	struct rkisp1_cif_isp_dpf_strength_config strengthConfig_;
 	std::vector<ModeConfig> noiseReductionModes_;