[RFC,v4,3/7] ipa: simple: Introduce default temperature value
diff mbox series

Message ID 20260504182658.590233-4-mzamazal@redhat.com
State New
Headers show
Series
  • LSC for SoftISP simple pipeline
Related show

Commit Message

Milan Zamazal May 4, 2026, 6:26 p.m. UTC
Some algorithms use interpolated values based on temperature.
Temperature is computed in the AWB algorithm.  Technically, the AWB
algorithm can be disabled and then no temperature is computed.  Let's
avoid implicit assumptions and introduce a constant for a default
temperature value and make the temperature value optional.

This is currently used by the CCM algorithm.  It will be used also by
the LSC algorithm in the followup patch.

The default temperature value of 6500 is just a common value, there is
no special reason to use this or another value.

Signed-off-by: Milan Zamazal <mzamazal@redhat.com>
---
 src/ipa/simple/algorithms/awb.cpp | 4 ++--
 src/ipa/simple/algorithms/awb.h   | 4 +++-
 src/ipa/simple/algorithms/ccm.cpp | 5 ++++-
 src/ipa/simple/ipa_context.h      | 2 +-
 4 files changed, 10 insertions(+), 5 deletions(-)

Patch
diff mbox series

diff --git a/src/ipa/simple/algorithms/awb.cpp b/src/ipa/simple/algorithms/awb.cpp
index f5c88ea6f..961126c0d 100644
--- a/src/ipa/simple/algorithms/awb.cpp
+++ b/src/ipa/simple/algorithms/awb.cpp
@@ -96,11 +96,11 @@  void Awb::process(IPAContext &context,
 
 	RGB<double> rgbGains{ { 1 / gains.r(), 1 / gains.g(), 1 / gains.b() } };
 	context.activeState.awb.temperatureK = estimateCCT(rgbGains);
-	metadata.set(controls::ColourTemperature, context.activeState.awb.temperatureK);
+	metadata.set(controls::ColourTemperature, context.activeState.awb.temperatureK.value_or(0));
 
 	LOG(IPASoftAwb, Debug)
 		<< "gain R/B: " << gains << "; temperature: "
-		<< context.activeState.awb.temperatureK;
+		<< context.activeState.awb.temperatureK.value_or(0);
 }
 
 REGISTER_IPA_ALGORITHM(Awb, "Awb")
diff --git a/src/ipa/simple/algorithms/awb.h b/src/ipa/simple/algorithms/awb.h
index ad993f39c..df46baee4 100644
--- a/src/ipa/simple/algorithms/awb.h
+++ b/src/ipa/simple/algorithms/awb.h
@@ -1,6 +1,6 @@ 
 /* SPDX-License-Identifier: LGPL-2.1-or-later */
 /*
- * Copyright (C) 2024-2025 Red Hat Inc.
+ * Copyright (C) 2024-2026 Red Hat Inc.
  *
  * Auto white balance
  */
@@ -13,6 +13,8 @@  namespace libcamera {
 
 namespace ipa::soft::algorithms {
 
+constexpr unsigned int kDefaultTemperature = 6500;
+
 class Awb : public Algorithm
 {
 public:
diff --git a/src/ipa/simple/algorithms/ccm.cpp b/src/ipa/simple/algorithms/ccm.cpp
index ace9c35dc..6f566ccdc 100644
--- a/src/ipa/simple/algorithms/ccm.cpp
+++ b/src/ipa/simple/algorithms/ccm.cpp
@@ -15,6 +15,8 @@ 
 
 #include "libcamera/internal/matrix.h"
 
+#include "awb.h"
+
 namespace {
 
 constexpr unsigned int kTemperatureThreshold = 100;
@@ -44,7 +46,8 @@  int Ccm::init([[maybe_unused]] IPAContext &context, const ValueNode &tuningData)
 void Ccm::prepare(IPAContext &context, [[maybe_unused]] const uint32_t frame,
 		  IPAFrameContext &frameContext, [[maybe_unused]] DebayerParams *params)
 {
-	const unsigned int ct = context.activeState.awb.temperatureK;
+	const unsigned int ct =
+		context.activeState.awb.temperatureK.value_or(kDefaultTemperature);
 
 	/* Change CCM only on bigger temperature changes. */
 	if (!currentCcm_ ||
diff --git a/src/ipa/simple/ipa_context.h b/src/ipa/simple/ipa_context.h
index 34f7403a4..c4bd91bb0 100644
--- a/src/ipa/simple/ipa_context.h
+++ b/src/ipa/simple/ipa_context.h
@@ -50,7 +50,7 @@  struct IPAActiveState {
 
 	struct {
 		RGB<float> gains;
-		unsigned int temperatureK;
+		std::optional<unsigned int> temperatureK;
 	} awb;
 
 	Matrix<float, 3, 3> combinedMatrix;