[libcamera-devel] [PATCH v5 32/33] ipa: rkisp1: awb: Freeze AWB when means are too small

Laurent Pinchart laurent.pinchart at ideasonboard.com
Tue Sep 27 04:36:41 CEST 2022


When the RGB means are too small, gains and color temperature can't be
meaningfully calculated. Freeze the AWB in that case, using the
previously calculated values.

Signed-off-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
---
 src/ipa/rkisp1/algorithms/awb.cpp | 17 ++++++++++++++++-
 src/ipa/rkisp1/ipa_context.cpp    |  3 +++
 src/ipa/rkisp1/ipa_context.h      |  1 +
 3 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/src/ipa/rkisp1/algorithms/awb.cpp b/src/ipa/rkisp1/algorithms/awb.cpp
index a3066fbb1994..eb32cd722071 100644
--- a/src/ipa/rkisp1/algorithms/awb.cpp
+++ b/src/ipa/rkisp1/algorithms/awb.cpp
@@ -31,6 +31,9 @@ namespace ipa::rkisp1::algorithms {
 
 LOG_DEFINE_CATEGORY(RkISP1Awb)
 
+/* Minimum mean value below which AWB can't operate. */
+constexpr double kMeanMinThreshold = 2.0;
+
 Awb::Awb()
 	: rgbMode_(false)
 {
@@ -263,7 +266,17 @@ void Awb::process(IPAContext &context,
 	greenMean /= frameContext.awb.gains.green;
 	blueMean /= frameContext.awb.gains.blue;
 
-	frameContext.awb.temperatureK = estimateCCT(redMean, greenMean, blueMean);
+	/*
+	 * If the means are too small we don't have enough information to
+	 * meaningfully calculate gains. Freeze the algorithm in that case.
+	 */
+	if (redMean < kMeanMinThreshold && greenMean < kMeanMinThreshold &&
+	    blueMean < kMeanMinThreshold) {
+		frameContext.awb.temperatureK = activeState.awb.temperatureK;
+		return;
+	}
+
+	activeState.awb.temperatureK = estimateCCT(redMean, greenMean, blueMean);
 
 	/*
 	 * Estimate the red and blue gains to apply in a grey world. The green
@@ -290,6 +303,8 @@ void Awb::process(IPAContext &context,
 	activeState.awb.gains.automatic.blue = blueGain;
 	activeState.awb.gains.automatic.green = 1.0;
 
+	frameContext.awb.temperatureK = activeState.awb.temperatureK;
+
 	LOG(RkISP1Awb, Debug) << std::showpoint
 		<< "Means [" << redMean << ", " << greenMean << ", " << blueMean
 		<< "], gains [" << activeState.awb.gains.automatic.red << ", "
diff --git a/src/ipa/rkisp1/ipa_context.cpp b/src/ipa/rkisp1/ipa_context.cpp
index 2126ed1d0acb..b00dc29c1713 100644
--- a/src/ipa/rkisp1/ipa_context.cpp
+++ b/src/ipa/rkisp1/ipa_context.cpp
@@ -156,6 +156,9 @@ namespace libcamera::ipa::rkisp1 {
  * \var IPAActiveState::awb.gains.automatic.blue
  * \brief Automatic white balance gain for B channel
  *
+ * \var IPAActiveState::awb.temperatureK
+ * \brief Estimated color temperature
+ *
  * \var IPAActiveState::awb.autoEnabled
  * \brief Whether the Auto White Balance algorithm is enabled
  */
diff --git a/src/ipa/rkisp1/ipa_context.h b/src/ipa/rkisp1/ipa_context.h
index d0692f872960..0677c8c35d73 100644
--- a/src/ipa/rkisp1/ipa_context.h
+++ b/src/ipa/rkisp1/ipa_context.h
@@ -69,6 +69,7 @@ struct IPAActiveState {
 			} automatic;
 		} gains;
 
+		unsigned int temperatureK;
 		bool autoEnabled;
 	} awb;
 
-- 
Regards,

Laurent Pinchart



More information about the libcamera-devel mailing list