[v2,3/5] ipa: simple: Report the ColourGains in metadata
diff mbox series

Message ID 20241219211010.103310-4-mzamazal@redhat.com
State New
Headers show
Series
  • ipa: simple: Introduce metadata reporting
Related show

Commit Message

Milan Zamazal Dec. 19, 2024, 9:10 p.m. UTC
From: Kieran Bingham <kieran.bingham@ideasonboard.com>

Provide the determined colour gains back into the metadata
to add to completed requests.

Metadata must be set before computing the new gain values in order to
report the metadata used to process the image rather than the metadata
determined from the image (and to be used for processing the next
image).

Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
---
 src/ipa/simple/algorithms/awb.cpp | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Patch
diff mbox series

diff --git a/src/ipa/simple/algorithms/awb.cpp b/src/ipa/simple/algorithms/awb.cpp
index 195de41d..95ff4434 100644
--- a/src/ipa/simple/algorithms/awb.cpp
+++ b/src/ipa/simple/algorithms/awb.cpp
@@ -14,6 +14,8 @@ 
 
 #include "simple/ipa_context.h"
 
+#include "control_ids.h"
+
 namespace libcamera {
 
 LOG_DEFINE_CATEGORY(IPASoftAwb)
@@ -33,10 +35,16 @@  void Awb::process(IPAContext &context,
 		  [[maybe_unused]] const uint32_t frame,
 		  [[maybe_unused]] IPAFrameContext &frameContext,
 		  const SwIspStats *stats,
-		  [[maybe_unused]] ControlList &metadata)
+		  ControlList &metadata)
 {
 	const SwIspStats::Histogram &histogram = stats->yHistogram;
 	const uint8_t blackLevel = context.activeState.blc.level;
+	auto &gains = context.activeState.gains;
+
+	const float maxGain = 1024.0;
+	const float mdGains[] = { static_cast<float>(gains.red / maxGain),
+				  static_cast<float>(gains.blue / maxGain) };
+	metadata.set(controls::ColourGains, mdGains);
 
 	/*
 	 * Black level must be subtracted to get the correct AWB ratios, they
@@ -54,7 +62,6 @@  void Awb::process(IPAContext &context,
 	 * Calculate red and blue gains for AWB.
 	 * Clamp max gain at 4.0, this also avoids 0 division.
 	 */
-	auto &gains = context.activeState.gains;
 	gains.red = sumR <= sumG / 4 ? 4.0 : static_cast<double>(sumG) / sumR;
 	gains.blue = sumB <= sumG / 4 ? 4.0 : static_cast<double>(sumG) / sumB;
 	/* Green gain is fixed to 1.0 */