[v6,09/15] ipa: rkisp1: lsc: Handle quantization locally
diff mbox series

Message ID 20260128-sklug-lsc-resampling-v2-dev-v6-9-af7d95f03d22@ideasonboard.com
State Accepted
Headers show
Series
  • Add resampling support for polynomial LSC data
Related show

Commit Message

Stefan Klug Jan. 28, 2026, 4 p.m. UTC
The quantization functionality in the Interpolator type hinders in
writing nice code. Don't use it and implement the functionality directly
in the algorithm.

While at it, reduce the threshold to half of the quantization step size,
otherwise it might happen that we skip a full quantization step. Rename
the kColourTemperatureChangeThreshhold to kColourTemperatureQuantization
to better express the usecase.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Reviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>

---

Changes in v4:
- Small fix in commit message
- Replaced manual std::abs(signed diff) by utils::abs_diff()
- Collected tag

Changes in v3:
- Reduce threshold to quantization step/2
- Drop unnecessary static modifier
- Collected tag

Changes in v2:
- Added this patch
---
 src/ipa/rkisp1/algorithms/lsc.cpp | 24 +++++++++++++++++-------
 1 file changed, 17 insertions(+), 7 deletions(-)

Patch
diff mbox series

diff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp
index 99e1e05f1d8b8157c2bbb8ee2f94cedb152009ca..daf5c9a9b8fddf290a55471c4dce608f1b8ec82a 100644
--- a/src/ipa/rkisp1/algorithms/lsc.cpp
+++ b/src/ipa/rkisp1/algorithms/lsc.cpp
@@ -70,7 +70,7 @@  LOG_DEFINE_CATEGORY(RkISP1Lsc)
 
 namespace {
 
-constexpr int kColourTemperatureChangeThreshhold = 10;
+constexpr int kColourTemperatureQuantization = 10;
 
 class LscPolynomialLoader
 {
@@ -308,12 +308,16 @@  std::vector<double> parseSizes(const YamlObject &tuningData,
 	return sizes;
 }
 
+unsigned int quantize(unsigned int value, unsigned int step)
+{
+	return std::lround(value / static_cast<double>(step)) * step;
+}
+
 } /* namespace */
 
 LensShadingCorrection::LensShadingCorrection()
 	: lastAppliedCt_(0), lastAppliedQuantizedCt_(0)
 {
-	sets_.setQuantization(kColourTemperatureChangeThreshhold);
 }
 
 /**
@@ -426,17 +430,23 @@  void LensShadingCorrection::prepare([[maybe_unused]] IPAContext &context,
 				    RkISP1Params *params)
 {
 	uint32_t ct = frameContext.awb.temperatureK;
-	if (std::abs(static_cast<int>(ct) - static_cast<int>(lastAppliedCt_)) <
-	    kColourTemperatureChangeThreshhold)
+	unsigned int quantizedCt = quantize(ct, kColourTemperatureQuantization);
+
+	/*
+	 * Add a threshold so that oscillations around a quantization step don't
+	 * lead to constant changes.
+	 */
+	if (utils::abs_diff(ct, lastAppliedCt_) < kColourTemperatureQuantization / 2)
 		return;
-	unsigned int quantizedCt;
-	const Components &set = sets_.getInterpolated(ct, &quantizedCt);
-	if (lastAppliedQuantizedCt_ == quantizedCt)
+
+	if (quantizedCt == lastAppliedQuantizedCt_)
 		return;
 
 	auto config = params->block<BlockType::Lsc>();
 	config.setEnabled(true);
 	setParameters(*config);
+
+	const Components &set = sets_.getInterpolated(quantizedCt);
 	copyTable(*config, set);
 
 	lastAppliedCt_ = ct;