[5/5] ipa: rpi: lux: Use floating statistics region to obtain the current Y value
diff mbox series

Message ID 20251017102704.3887-6-david.plowman@raspberrypi.com
State New
Headers show
Series
  • Fix and improve full image Y statistics
Related show

Commit Message

David Plowman Oct. 17, 2025, 10:05 a.m. UTC
The Y value from the first floating region is now a better choice for
a Y value that is invariant to (for example) the metering mode.

Both VC4 and PiSP platforms store full image Y statistics here.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
---
 src/ipa/rpi/controller/rpi/lux.cpp | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

Patch
diff mbox series

diff --git a/src/ipa/rpi/controller/rpi/lux.cpp b/src/ipa/rpi/controller/rpi/lux.cpp
index acaa6e57..7dab27cc 100644
--- a/src/ipa/rpi/controller/rpi/lux.cpp
+++ b/src/ipa/rpi/controller/rpi/lux.cpp
@@ -85,14 +85,21 @@  void Lux::process(StatisticsPtr &stats, Metadata *imageMetadata)
 {
 	DeviceStatus deviceStatus;
 	if (imageMetadata->get("device.status", deviceStatus) == 0) {
+		/*
+		 * We've set up the first floating AGC region to collect full image stats. This
+		 * is a better choice than the Y-histogram, for example, because it's invariant
+		 * to the metering mode (and cheaper to evaluate).
+		 */
+		auto const &fullImageStats = stats->agcRegions.getFloating(0);
+		double currentY = static_cast<double>(fullImageStats.val.ySum) / fullImageStats.counted;
+
 		double currentGain = deviceStatus.analogueGain;
 		double currentAperture = deviceStatus.aperture.value_or(currentAperture_);
-		double currentY = stats->yHist.interQuantileMean(0, 1);
 		double gainRatio = referenceGain_ / currentGain;
 		double exposureTimeRatio =
 			referenceExposureTime_ / deviceStatus.exposureTime;
 		double apertureRatio = referenceAperture_ / currentAperture;
-		double yRatio = currentY * (65536 / stats->yHist.bins()) / referenceY_;
+		double yRatio = currentY / referenceY_;
 		double estimatedLux = exposureTimeRatio * gainRatio *
 				      apertureRatio * apertureRatio *
 				      yRatio * referenceLux_ / sensitivity_;