[05/10] ipa: rkisp: ccm/lsc: Fix CCM/LSC based on manual color temperature
diff mbox series

Message ID 20250217100203.297894-6-stefan.klug@ideasonboard.com
State New
Headers show
Series
  • Some rkisp1 awb improvements
Related show

Commit Message

Stefan Klug Feb. 17, 2025, 10:01 a.m. UTC
In RkISP1Awb::process(), the color temperature in the active state is
updated unconditionally.  The CCM/LSC algorithms use that value in
prepare() to update the CCM/LSC which is not correct if the color
temperature was specified manually and leads to visible flicker even
when AwbEnable is set to false.

To fix that, track the auto and manual color temperature separately in
active state. In Awb::prepare() the current frame context is updated
with the corresponding value from active state. Change the algorithms to
fetch the color temperature from the frame context instead of the active
state in prepare().

Fixes: 02308809548d ("ipa: rkisp1: awb: Implement ColourTemperature control")
Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
---
 src/ipa/rkisp1/algorithms/awb.cpp | 16 +++++++++-------
 src/ipa/rkisp1/algorithms/ccm.cpp |  2 +-
 src/ipa/rkisp1/algorithms/lsc.cpp |  6 +++---
 src/ipa/rkisp1/ipa_context.h      |  3 ++-
 4 files changed, 15 insertions(+), 12 deletions(-)

Patch
diff mbox series

diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp
index 147277c98bb2..683a08c943fa 100644
--- a/src/ipa/rkisp1/algorithms/awb.cpp
+++ b/src/ipa/rkisp1/algorithms/awb.cpp
@@ -77,7 +77,8 @@  int Awb::configure(IPAContext &context,
 	context.activeState.awb.manual.gains = RGB<double>{ 1.0 };
 	context.activeState.awb.automatic.gains = RGB<double>{ 1.0 };
 	context.activeState.awb.autoEnabled = true;
-	context.activeState.awb.temperatureK = kDefaultColourTemperature;
+	context.activeState.awb.manual.temperatureK = kDefaultColourTemperature;
+	context.activeState.awb.automatic.temperatureK = kDefaultColourTemperature;
 
 	/*
 	 * Define the measurement window for AWB as a centered rectangle
@@ -132,7 +133,7 @@  void Awb::queueRequest(IPAContext &context,
 		const auto &gains = colourGainCurve_->getInterpolated(*colourTemperature);
 		awb.manual.gains.r() = gains[0];
 		awb.manual.gains.b() = gains[1];
-		awb.temperatureK = *colourTemperature;
+		awb.manual.temperatureK = *colourTemperature;
 		update = true;
 	}
 
@@ -141,7 +142,7 @@  void Awb::queueRequest(IPAContext &context,
 			<< "Set colour gains to " << awb.manual.gains;
 
 	frameContext.awb.gains = awb.manual.gains;
-	frameContext.awb.temperatureK = awb.temperatureK;
+	frameContext.awb.temperatureK = awb.manual.temperatureK;
 }
 
 /**
@@ -155,8 +156,9 @@  void Awb::prepare(IPAContext &context, const uint32_t frame,
 	 * most up-to-date automatic values we can read.
 	 */
 	if (frameContext.awb.autoEnabled) {
-		frameContext.awb.gains = context.activeState.awb.automatic.gains;
-		frameContext.awb.temperatureK = context.activeState.awb.temperatureK;
+		auto &awb = context.activeState.awb;
+		frameContext.awb.gains = awb.automatic.gains;
+		frameContext.awb.temperatureK = awb.automatic.temperatureK;
 	}
 
 	auto gainConfig = params->block<BlockType::AwbGain>();
@@ -309,7 +311,7 @@  void Awb::process(IPAContext &context,
 	    rgbMeans.b() < kMeanMinThreshold)
 		return;
 
-	activeState.awb.temperatureK = estimateCCT(rgbMeans);
+	activeState.awb.automatic.temperatureK = estimateCCT(rgbMeans);
 
 	/*
 	 * Estimate the red and blue gains to apply in a grey world. The green
@@ -340,7 +342,7 @@  void Awb::process(IPAContext &context,
 		<< std::showpoint
 		<< "Means " << rgbMeans << ", gains "
 		<< activeState.awb.automatic.gains << ", temp "
-		<< activeState.awb.temperatureK << "K";
+		<< activeState.awb.automatic.temperatureK << "K";
 }
 
 REGISTER_IPA_ALGORITHM(Awb, "Awb")
diff --git a/src/ipa/rkisp1/algorithms/ccm.cpp b/src/ipa/rkisp1/algorithms/ccm.cpp
index eb8ca39e56a8..2e5e91006b55 100644
--- a/src/ipa/rkisp1/algorithms/ccm.cpp
+++ b/src/ipa/rkisp1/algorithms/ccm.cpp
@@ -88,7 +88,7 @@  void Ccm::setParameters(struct rkisp1_cif_isp_ctk_config &config,
 void Ccm::prepare(IPAContext &context, const uint32_t frame,
 		  IPAFrameContext &frameContext, RkISP1Params *params)
 {
-	uint32_t ct = context.activeState.awb.temperatureK;
+	uint32_t ct = frameContext.awb.temperatureK;
 
 	/*
 	 * \todo The colour temperature will likely be noisy, add filtering to
diff --git a/src/ipa/rkisp1/algorithms/lsc.cpp b/src/ipa/rkisp1/algorithms/lsc.cpp
index e47aa2f0727e..e7301bfec863 100644
--- a/src/ipa/rkisp1/algorithms/lsc.cpp
+++ b/src/ipa/rkisp1/algorithms/lsc.cpp
@@ -404,12 +404,12 @@  void LensShadingCorrection::copyTable(rkisp1_cif_isp_lsc_config &config,
 /**
  * \copydoc libcamera::ipa::Algorithm::prepare
  */
-void LensShadingCorrection::prepare(IPAContext &context,
+void LensShadingCorrection::prepare([[maybe_unused]] IPAContext &context,
 				    [[maybe_unused]] const uint32_t frame,
-				    [[maybe_unused]] IPAFrameContext &frameContext,
+				    IPAFrameContext &frameContext,
 				    RkISP1Params *params)
 {
-	uint32_t ct = context.activeState.awb.temperatureK;
+	uint32_t ct = frameContext.awb.temperatureK;
 	if (std::abs(static_cast<int>(ct) - static_cast<int>(lastAppliedCt_)) <
 	    kColourTemperatureChangeThreshhold)
 		return;
diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h
index 1a374c96cd1a..b50370cd9daa 100644
--- a/src/ipa/rkisp1/ipa_context.h
+++ b/src/ipa/rkisp1/ipa_context.h
@@ -90,13 +90,14 @@  struct IPAActiveState {
 	struct {
 		struct {
 			RGB<double> gains;
+			unsigned int temperatureK;
 		} manual;
 
 		struct {
 			RGB<double> gains;
+			unsigned int temperatureK;
 		} automatic;
 
-		unsigned int temperatureK;
 		bool autoEnabled;
 	} awb;