[v1,10/11] ipa: rkisp1: algorithms: dpf: expose DPF control map
diff mbox series

Message ID 20251125000848.4103786-11-rui.wang@ideasonboard.com
State New
Headers show
Series
  • ipa: rkisp1: DPF refactor and tuning improvements
Related show

Commit Message

Rui Wang Nov. 25, 2025, 12:08 a.m. UTC
Implement getControlMap() to provide the RkISP1 DPF controls with tuning-
derived defaults. The map includes:
- DpfMode (auto/manual/disable/reduction mode selection)
- DpfChannelStrengths (R/G/B strength values)
- Developer mode controls when enabled:
  - Spatial coefficients (green and RB)
  - RB filter size (9x9 or 13x9)
  - NLL coefficients and scale mode
- DpfExposure (read-only exposure indicator)

This control map is registered during init() to expose DPF controls to
applications.

Signed-off-by: Rui Wang <rui.wang@ideasonboard.com>
---
 src/ipa/rkisp1/algorithms/denoise.h |  9 +++++
 src/ipa/rkisp1/algorithms/dpf.cpp   | 63 +++++++++++++++++++++++++++++
 src/ipa/rkisp1/algorithms/dpf.h     |  1 +
 3 files changed, 73 insertions(+)

Patch
diff mbox series

diff --git a/src/ipa/rkisp1/algorithms/denoise.h b/src/ipa/rkisp1/algorithms/denoise.h
index f07c14fe..c532b7eb 100644
--- a/src/ipa/rkisp1/algorithms/denoise.h
+++ b/src/ipa/rkisp1/algorithms/denoise.h
@@ -70,6 +70,7 @@  protected:
 					[[maybe_unused]] RkISP1Params *params)
 	{
 	}
+	virtual ControlInfoMap::Map getControlMap() const;
 private:
 	/**< Developer mode state for advanced controls */
 	bool devMode_ = false;
@@ -99,6 +100,14 @@  uint32_t DenoiseBaseAlgorithm::selectExposureIndexBand(unsigned exposureIndex,
 	return idx;
 }
 
+inline ControlInfoMap::Map DenoiseBaseAlgorithm::getControlMap() const
+{
+	ControlInfoMap::Map map;
+	map[&controls::rkisp1::DenoiseMode] =
+		ControlInfo(controls::rkisp1::DenoiseModeValues);
+	map[&controls::rkisp1::ExposureGainIndex] = ControlInfo(0, 6400, 0);
+	return map;
+}
 } /* namespace ipa::rkisp1::algorithms */
 
 } /* namespace libcamera */
diff --git a/src/ipa/rkisp1/algorithms/dpf.cpp b/src/ipa/rkisp1/algorithms/dpf.cpp
index e3293241..a3a8e789 100644
--- a/src/ipa/rkisp1/algorithms/dpf.cpp
+++ b/src/ipa/rkisp1/algorithms/dpf.cpp
@@ -84,6 +84,9 @@  int Dpf::init([[maybe_unused]] IPAContext &context,
 			<< " mode(s) from tuning";
 	}
 
+	/* Init controls value from YAML */
+	auto dpfMap = getControlMap();
+	context.ctrlMap.insert(dpfMap.begin(), dpfMap.end());
 	return 0;
 }
 
@@ -690,6 +693,66 @@  void Dpf::logConfigIfChanged(uint32_t exposureGainIndex,
 	haveLast = true;
 }
 
+ControlInfoMap::Map Dpf::getControlMap() const
+{
+	ControlInfoMap::Map map = DenoiseBaseAlgorithm::getControlMap();
+
+	std::array<int32_t, 3> strengthDefault = {
+		static_cast<int32_t>(baseStrengthConfig_.r),
+		static_cast<int32_t>(baseStrengthConfig_.g),
+		static_cast<int32_t>(baseStrengthConfig_.b),
+	};
+	map[&controls::rkisp1::DpfChannelStrengths] =
+		ControlInfo(0, 255, Span<const int32_t, 3>(strengthDefault));
+
+	if (!isDevMode())
+		return map;
+
+	const auto copyCoefficients = [](const auto &src, auto &dest) {
+		for (size_t i = 0; i < dest.size(); ++i)
+			dest[i] = static_cast<int32_t>(src[i]);
+	};
+
+	std::array<int32_t, RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS> greenCoeffs{};
+	copyCoefficients(baseConfig_.g_flt.spatial_coeff, greenCoeffs);
+	map[&controls::rkisp1::DpfGreenSpatialCoefficients] =
+		ControlInfo(0, 63,
+			    Span<const int32_t,
+				 RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS>(greenCoeffs));
+
+	std::array<int32_t, RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS> rbCoeffs{};
+	copyCoefficients(baseConfig_.rb_flt.spatial_coeff, rbCoeffs);
+	map[&controls::rkisp1::DpfRedBlueSpatialCoefficients] =
+		ControlInfo(0, 63,
+			    Span<const int32_t,
+				 RKISP1_CIF_ISP_DPF_MAX_SPATIAL_COEFFS>(rbCoeffs));
+
+	int32_t rbSizeDefault = baseConfig_.rb_flt.fltsize ==
+						RKISP1_CIF_ISP_DPF_RB_FILTERSIZE_13x9
+					? 1
+					: 0;
+	map[&controls::rkisp1::DpfRbFilterSize] =
+		ControlInfo(controls::rkisp1::DpfRbFilterSizeValues,
+			    ControlValue(rbSizeDefault));
+
+	std::array<int32_t, RKISP1_CIF_ISP_DPF_MAX_NLF_COEFFS> nllCoeffs{};
+	copyCoefficients(baseConfig_.nll.coeff, nllCoeffs);
+	map[&controls::rkisp1::DpfNoiseLevelLookupCoefficients] =
+		ControlInfo(0, 1023,
+			    Span<const int32_t,
+				 RKISP1_CIF_ISP_DPF_MAX_NLF_COEFFS>(nllCoeffs));
+
+	int32_t scaleModeDefault = baseConfig_.nll.scale_mode ==
+						   RKISP1_CIF_ISP_NLL_SCALE_LOGARITHMIC
+					   ? 1
+					   : 0;
+	map[&controls::rkisp1::DpfNoiseLevelLookupScaleMode] =
+		ControlInfo(controls::rkisp1::DpfNoiseLevelLookupScaleModeValues,
+			    ControlValue(scaleModeDefault));
+
+	return map;
+}
+
 /**
  * \copydoc libcamera::ipa::Algorithm::queueRequest
  */
diff --git a/src/ipa/rkisp1/algorithms/dpf.h b/src/ipa/rkisp1/algorithms/dpf.h
index 86085cf9..e62882f2 100644
--- a/src/ipa/rkisp1/algorithms/dpf.h
+++ b/src/ipa/rkisp1/algorithms/dpf.h
@@ -102,6 +102,7 @@  private:
 				 RkISP1Params *params) override;
 	void prepareEnabledMode(IPAContext &context, const uint32_t frame,
 				IPAFrameContext &frameContext, RkISP1Params *params) override;
+	ControlInfoMap::Map getControlMap() const override;
 };
 
 } /* namespace ipa::rkisp1::algorithms */