[v1] ipa: rpi: agc: Clamp digital gain to avoid saturation issues
diff mbox series

Message ID 20260520084631.3440-1-david.plowman@raspberrypi.com
State New
Headers show
Series
  • [v1] ipa: rpi: agc: Clamp digital gain to avoid saturation issues
Related show

Commit Message

David Plowman May 20, 2026, 8:44 a.m. UTC
Digital gain is used to adjust overall image exposure when the target
exposure cannot be achieved (for example, cannot go high enough). But
when the target exposure is lower than we can achieve, the digital
gain was being set to values less than unity, causing saturation
problems.

The fix is simply to clamp the digital gain at the bottom to 1.0,
resulting in images that, while "too bright", saturate correctly.

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

Patch
diff mbox series

diff --git a/src/ipa/rpi/controller/rpi/agc_channel.cpp b/src/ipa/rpi/controller/rpi/agc_channel.cpp
index cf0e77bd..c9462eed 100644
--- a/src/ipa/rpi/controller/rpi/agc_channel.cpp
+++ b/src/ipa/rpi/controller/rpi/agc_channel.cpp
@@ -941,8 +941,8 @@  void AgcChannel::divideUpExposure()
 	/* Finally work out the digital gain that we will need. */
 	filtered_.totalExposureNoDG = analogueGain * exposureTime;
 	double digitalGain = filtered_.totalExposure / filtered_.totalExposureNoDG;
-	/* Limit dg by what is allowed. */
-	digitalGain = std::min(digitalGain, config_.maxDigitalGain);
+	/* Limit dg by what is allowed (and to 1.0 to avoid saturation issues). */
+	digitalGain = std::clamp(digitalGain, 1.0, config_.maxDigitalGain);
 	/* Update total exposure, in case the dg went down. */
 	filtered_.totalExposure = filtered_.totalExposureNoDG * digitalGain;