[v1,2/4] pa: rkisp1: algorithms: filter: Add helper fun and sharpness presets
diff mbox series

Message ID 20260118202953.1554892-3-rui.wang@ideasonboard.com
State New
Headers show
Series
  • Filter algorithm refactoring and mode switching
Related show

Commit Message

Rui Wang Jan. 18, 2026, 8:29 p.m. UTC
Refactor the Filter algorithm to improve code organization and prepare
for future sharpness control implementation.

Add helper functions to separate concerns:
- prepareDisabledMode(): Handle filter disable state
- prepareEnabledMode(): Handle filter enable state with logging
- logConfig(): Provide detailed filter configuration logging

Introduce sharpness preset table (kSharpnessPresets) with 11 levels
(0-10) defining sharpness factor combinations. These presets will be
used in future commits to implement user-controllable sharpness levels.

Move class documentation to follow the anonymous namespace for better
code organization and consistency with other algorithms.

No functional changes in this commit.

Signed-off-by: Rui Wang <rui.wang@ideasonboard.com>
---
 src/ipa/rkisp1/algorithms/filter.cpp | 85 +++++++++++++++++++++++-----
 src/ipa/rkisp1/algorithms/filter.h   |  7 +++
 2 files changed, 79 insertions(+), 13 deletions(-)

Patch
diff mbox series

diff --git a/src/ipa/rkisp1/algorithms/filter.cpp b/src/ipa/rkisp1/algorithms/filter.cpp
index 321e4122..eb4049fd 100644
--- a/src/ipa/rkisp1/algorithms/filter.cpp
+++ b/src/ipa/rkisp1/algorithms/filter.cpp
@@ -27,19 +27,6 @@  namespace libcamera {
 
 namespace ipa::rkisp1::algorithms {
 
-/**
- * \class Filter
- * \brief RkISP1 Filter control
- *
- * Denoise and Sharpness filters will be applied by RkISP1 during the
- * demosaicing step. The denoise filter is responsible for removing noise from
- * the image, while the sharpness filter will enhance its acutance.
- *
- * \todo In current version the denoise and sharpness control is based on user
- * controls. In a future version it should be controlled automatically by the
- * algorithm.
- */
-
 LOG_DEFINE_CATEGORY(RkISP1Filter)
 
 namespace {
@@ -67,8 +54,44 @@  std::string modeName(int32_t mode)
 
 	return "ReductionUnknown";
 }
+
+struct SharpnessPreset {
+	uint32_t fac_sh0;
+	uint32_t fac_sh1;
+	uint32_t fac_mid;
+	uint32_t fac_bl0;
+	uint32_t fac_bl1;
+};
+
+/*
+ * Sharpness presets
+ * The presets are based on the following table.
+ */
+static constexpr SharpnessPreset kSharpnessPresets[] = {
+	{ 0x04, 0x04, 0x04, 0x02, 0x00 }, /* Level 0 */
+	{ 0x07, 0x08, 0x06, 0x02, 0x00 }, /* Level 1 */
+	{ 0x0a, 0x0c, 0x08, 0x04, 0x00 }, /* Level 2 */
+	{ 0x0c, 0x10, 0x0a, 0x06, 0x02 }, /* Level 3 */
+	{ 0x10, 0x16, 0x0c, 0x08, 0x04 }, /* Level 4 */
+	{ 0x14, 0x1b, 0x10, 0x0a, 0x04 }, /* Level 5 */
+	{ 0x1a, 0x20, 0x13, 0x0c, 0x06 }, /* Level 6 */
+	{ 0x1e, 0x26, 0x17, 0x10, 0x08 }, /* Level 7 */
+	{ 0x24, 0x2c, 0x1d, 0x15, 0x0d }, /* Level 8 */
+	{ 0x2a, 0x30, 0x22, 0x1a, 0x14 }, /* Level 9 */
+	{ 0x30, 0x3f, 0x28, 0x24, 0x20 }, /* Level 10 */
+};
 } /* namespace */
 
+
+/**
+ * \class Filter
+ * \brief RkISP1 Filter control
+ *
+ * Denoise and Sharpness filters will be applied by RkISP1 during the
+ * demosaicing step. The denoise filter is responsible for removing noise from
+ * the image, while the sharpness filter will enhance its acutance.
+ */
+
 Filter::Filter()
 	: noiseReductionModes_({}),
 	  activeMode_(noiseReductionModes_.end())
@@ -365,6 +388,42 @@  void Filter::prepare([[maybe_unused]] IPAContext &context,
 	}
 }
 
+void Filter::prepareDisabledMode(RkISP1Params *params)
+{
+	auto config = params->block<BlockType::Flt>();
+	config.setEnabled(false);
+}
+
+void Filter::prepareEnabledMode(const uint32_t frame,
+				IPAFrameContext &frameContext,
+				RkISP1Params *params)
+{
+	auto config = params->block<BlockType::Flt>();
+	config.setEnabled(true);
+
+	if (frameContext.filter.update || frame == 0)
+		logConfig(*config);
+}
+
+void Filter::logConfig(const struct rkisp1_cif_isp_flt_config &config)
+{
+	LOG(RkISP1Filter, Debug)
+		<< "Filter config: mode=" << config.mode
+		<< " lum_weight=" << config.lum_weight
+		<< " grn_stage1=" << (int)config.grn_stage1
+		<< " chr_h_mode=" << (int)config.chr_h_mode
+		<< " chr_v_mode=" << (int)config.chr_v_mode
+		<< " thresh_bl0=" << config.thresh_bl0
+		<< " thresh_bl1=" << config.thresh_bl1
+		<< " thresh_sh0=" << config.thresh_sh0
+		<< " thresh_sh1=" << config.thresh_sh1
+		<< " fac_sh1=" << config.fac_sh1
+		<< " fac_sh0=" << config.fac_sh0
+		<< " fac_mid=" << config.fac_mid
+		<< " fac_bl0=" << config.fac_bl0
+		<< " fac_bl1=" << config.fac_bl1;
+}
+
 REGISTER_IPA_ALGORITHM(Filter, "Filter")
 
 } /* namespace ipa::rkisp1::algorithms */
diff --git a/src/ipa/rkisp1/algorithms/filter.h b/src/ipa/rkisp1/algorithms/filter.h
index 3860adfd..19cf76d0 100644
--- a/src/ipa/rkisp1/algorithms/filter.h
+++ b/src/ipa/rkisp1/algorithms/filter.h
@@ -40,6 +40,13 @@  private:
 			      struct rkisp1_cif_isp_flt_config &config);
 
 	bool loadConfig(int32_t mode);
+
+	void logConfig(const struct rkisp1_cif_isp_flt_config &config);
+	void prepareDisabledMode(RkISP1Params *params);
+	void prepareEnabledMode(const uint32_t frame,
+				IPAFrameContext &frameContext,
+				RkISP1Params *params);
+
 	std::vector<ModeConfig> noiseReductionModes_;
 	std::vector<ModeConfig>::const_iterator activeMode_;
 };