[libcamera-devel,v1,3/6] ipa: rpi: agc: Allow AGC channels to avoid using "fast desaturation"
diff mbox series

Message ID 20231020084002.30665-4-naush@raspberrypi.com
State Accepted
Commit edb48a1337114e0b92caa54598397ce69c63a528
Headers show
Series
  • Raspberry Pi: Preliminary PiSP support (round 2)
Related show

Commit Message

Naushir Patuck Oct. 20, 2023, 8:39 a.m. UTC
From: David Plowman <david.plowman@raspberrypi.com>

"Fast desaturation" is a technique that can help the AGC algorithm to
desaturate images more quickly when they are very
over-exposed. However, it uses digital gain to do this which can
confuse our HDR techniques. Therefore make it optional.

Signed-off-by: David Plowman <david.plowman@raspberrypi.com>
Reviewed-by: Naushir Patuck <naush@raspberrypi.com>
---
 src/ipa/rpi/controller/rpi/agc_channel.cpp | 8 ++++++--
 src/ipa/rpi/controller/rpi/agc_channel.h   | 1 +
 2 files changed, 7 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 1e7eae06d425..3efb6482b67f 100644
--- a/src/ipa/rpi/controller/rpi/agc_channel.cpp
+++ b/src/ipa/rpi/controller/rpi/agc_channel.cpp
@@ -253,6 +253,8 @@  int AgcConfig::read(const libcamera::YamlObject &params)
 
 	stableRegion = params["stable_region"].get<double>(0.02);
 
+	desaturate = params["desaturate"].get<int>(1);
+
 	return 0;
 }
 
@@ -860,8 +862,10 @@  bool AgcChannel::applyDigitalGain(double gain, double targetY, bool channelBound
 	 * quickly (and we then approach the correct value more quickly from
 	 * below).
 	 */
-	bool desaturate = !channelBound &&
-			  targetY > config_.fastReduceThreshold && gain < sqrt(targetY);
+	bool desaturate = false;
+	if (config_.desaturate)
+		desaturate = !channelBound &&
+			     targetY > config_.fastReduceThreshold && gain < sqrt(targetY);
 	if (desaturate)
 		dg /= config_.fastReduceThreshold;
 	LOG(RPiAgc, Debug) << "Digital gain " << dg << " desaturate? " << desaturate;
diff --git a/src/ipa/rpi/controller/rpi/agc_channel.h b/src/ipa/rpi/controller/rpi/agc_channel.h
index c1808422498a..4cf7233eef25 100644
--- a/src/ipa/rpi/controller/rpi/agc_channel.h
+++ b/src/ipa/rpi/controller/rpi/agc_channel.h
@@ -76,6 +76,7 @@  struct AgcConfig {
 	libcamera::utils::Duration defaultExposureTime;
 	double defaultAnalogueGain;
 	double stableRegion;
+	bool desaturate;
 };
 
 class AgcChannel