[v3,10/19] ipa: libipa: agc: Make Agc::configure() set limits
diff mbox series

Message ID 20251114-exposure-limits-v3-10-b7c07feba026@ideasonboard.com
State New
Headers show
Series
  • libipa: agc: Calculate exposure limits
Related show

Commit Message

Jacopo Mondi Nov. 14, 2025, 2:17 p.m. UTC
The AgcMeanLuminance algorithm interface has a 'configure()' and
'setLimits()' API. configure() doesn't actually do much if not
initialzing a few variables, and the Mali and IPU3 IPAs do not
even call it. Configuring the AGC requires calling setLimits() at
configure() time and at run time.

In order to prepare to differentiate between configure-time settings
of the Agc and run-time handling of dynamic parameters such as the
frame duration limits, make the configure() operation initialize
the Agc limits and provide an AgcMeanLuminance::SensorConfiguration
type for IPAs to be populated with the sensor's default values.

The new type mimics the ExposureModeHelper::SensorConfiguration on
introduced in the previous patches and both will be removed once all the
information there contained will be made available from the
CameraSensorHelper.

Update all IPAs Agc implementation deriving from AgcMeanLuminance to
populate a AgcMeanLuminance::SensorConfiguration and use it in
configure().

Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
 src/ipa/ipu3/algorithms/agc.cpp         | 14 +++++++--
 src/ipa/libipa/agc_mean_luminance.cpp   | 56 ++++++++++++++++++++++++++++++---
 src/ipa/libipa/agc_mean_luminance.h     | 11 ++++++-
 src/ipa/libipa/exposure_mode_helper.cpp | 20 +++++++-----
 src/ipa/libipa/exposure_mode_helper.h   |  3 +-
 src/ipa/mali-c55/algorithms/agc.cpp     | 16 ++++++----
 src/ipa/rkisp1/algorithms/agc.cpp       | 15 ++++-----
 7 files changed, 105 insertions(+), 30 deletions(-)

Patch
diff mbox series

diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp
index 4574f3a1a9cd3f40b1b1402238809ee1a777946d..5c72806dede5f55459bde69ab8cfaebc495c7560 100644
--- a/src/ipa/ipu3/algorithms/agc.cpp
+++ b/src/ipa/ipu3/algorithms/agc.cpp
@@ -115,9 +115,17 @@  int Agc::configure(IPAContext &context,
 	context.activeState.agc.constraintMode = constraintModes().begin()->first;
 	context.activeState.agc.exposureMode = exposureModeHelpers().begin()->first;
 
-	/* \todo Run this again when FrameDurationLimits is passed in */
-	setLimits(minExposureTime_, maxExposureTime_, minAnalogueGain_,
-		  maxAnalogueGain_, {});
+	AgcMeanLuminance::SensorConfiguration sensorConfig;
+	sensorConfig.lineDuration = context.configuration.sensor.lineDuration;
+	sensorConfig.minExposureTime = minExposureTime_;
+	sensorConfig.maxExposureTime = maxExposureTime_;
+	sensorConfig.minAnalogueGain = minAnalogueGain_;
+	sensorConfig.maxAnalogueGain = maxAnalogueGain_;
+
+	AgcMeanLuminance::configure(sensorConfig, context.camHelper.get());
+
+	/* \todo Update AGC limits when FrameDurationLimits is passed in */
+
 	resetFrameCount();
 
 	return 0;
diff --git a/src/ipa/libipa/agc_mean_luminance.cpp b/src/ipa/libipa/agc_mean_luminance.cpp
index 64f36bd75dd213671b5a2e6810245096ed001f21..512e153791f5b98da01efad6675192a5358e7698 100644
--- a/src/ipa/libipa/agc_mean_luminance.cpp
+++ b/src/ipa/libipa/agc_mean_luminance.cpp
@@ -95,6 +95,35 @@  static constexpr double kMaxRelativeLuminanceTarget = 0.95;
  * \brief The luminance target for the constraint
  */
 
+/**
+ * \struct AgcMeanLuminance::SensorConfiguration
+ * \brief The sensor configuration parameters
+ *
+ * This structure collects the sensor configuration parameters which need
+ * to be provided to the AGC algorithm at configure() time.
+ *
+ * Each time configure() is called the sensor configuration need to be updated
+ * with new parameters.
+ *
+ * \todo Remove it once all the information are available from the
+ * CameraSensorHelper.
+ *
+ * \var AgcMeanLuminance::SensorConfiguration::lineDuration
+ * \brief The line duration in microseconds
+ *
+ * \var AgcMeanLuminance::SensorConfiguration::minExposureTime
+ * \brief The sensor minimum exposure time in microseconds
+ *
+ * \var AgcMeanLuminance::SensorConfiguration::maxExposureTime
+ * \brief The sensor maximum exposure time in microseconds
+ *
+ * \var AgcMeanLuminance::SensorConfiguration::minAnalogueGain
+ * \brief The sensor minimum analogue gain absolute value
+ *
+ * \var AgcMeanLuminance::SensorConfiguration::maxAnalogueGain
+ * \brief The sensor maximum analogue gain absolute value
+ */
+
 /**
  * \class AgcMeanLuminance
  * \brief A mean-based auto-exposure algorithm
@@ -314,17 +343,34 @@  int AgcMeanLuminance::parseExposureModes(const YamlObject &tuningData)
 
 /**
  * \brief Configure the exposure mode helpers
- * \param[in] lineDuration The sensor line length
+ * \param[in] config The sensor configuration
  * \param[in] sensorHelper The sensor helper
  *
- * This function configures the exposure mode helpers so they can correctly
+ * This function configures the exposure mode helpers by providing them the
+ * sensor configuration parameters and the sensor helper, so they can correctly
  * take quantization effects into account.
  */
-void AgcMeanLuminance::configure(utils::Duration lineDuration,
+void AgcMeanLuminance::configure(const SensorConfiguration &config,
 				 const CameraSensorHelper *sensorHelper)
 {
-	for (auto &[id, helper] : exposureModeHelpers_)
-		helper->configure(lineDuration, sensorHelper);
+	for (auto &[id, helper] : exposureModeHelpers_) {
+		/*
+		 * Translate from the SensorConfiguration to the
+		 * ExposureModeHelper::SensorConfiguration.
+		 *
+		 * These are just place holders before all the information are
+		 * available from the sensor helper.
+		 */
+
+		ExposureModeHelper::SensorConfiguration sensorConfig;
+		sensorConfig.lineDuration_ = config.lineDuration;
+		sensorConfig.minExposureTime_ = config.minExposureTime;
+		sensorConfig.maxExposureTime_ = config.maxExposureTime;
+		sensorConfig.minGain_ = config.minAnalogueGain;
+		sensorConfig.maxGain_ = config.maxAnalogueGain;
+
+		helper->configure(sensorConfig, sensorHelper);
+	}
 }
 
 /**
diff --git a/src/ipa/libipa/agc_mean_luminance.h b/src/ipa/libipa/agc_mean_luminance.h
index e5f164c3186b6b99cb0df5dd8dccf9026c22af20..42ead74b0cdc197bc2b27aee16918e2b42ea3d08 100644
--- a/src/ipa/libipa/agc_mean_luminance.h
+++ b/src/ipa/libipa/agc_mean_luminance.h
@@ -42,7 +42,16 @@  public:
 		double yTarget;
 	};
 
-	void configure(utils::Duration lineDuration, const CameraSensorHelper *sensorHelper);
+	struct SensorConfiguration {
+		utils::Duration lineDuration;
+		utils::Duration minExposureTime;
+		utils::Duration maxExposureTime;
+		double minAnalogueGain;
+		double maxAnalogueGain;
+	};
+
+	void configure(const SensorConfiguration &config,
+		       const CameraSensorHelper *sensorHelper);
 	int parseTuningData(const YamlObject &tuningData);
 
 	void setExposureCompensation(double gain)
diff --git a/src/ipa/libipa/exposure_mode_helper.cpp b/src/ipa/libipa/exposure_mode_helper.cpp
index c3ed1601939bd28435bbbc540d9b8c9d92b81912..f771b10a28eead2976c0000cf099ba5cfbe78e0f 100644
--- a/src/ipa/libipa/exposure_mode_helper.cpp
+++ b/src/ipa/libipa/exposure_mode_helper.cpp
@@ -111,24 +111,30 @@  ExposureModeHelper::ExposureModeHelper(const Span<std::pair<utils::Duration, dou
 
 /**
  * \brief Configure sensor details
- * \param[in] lineDuration The current line length of the sensor
+ * \param[in] sensorConfig The sensor configuration
  * \param[in] sensorHelper The sensor helper
  *
- * This function sets the line length and sensor helper. These are used in
+ * This function initializes the exposure helper settings using the sensor
+ * configuration parameters.
+ *
+ * The sensor parameters' are used to initialize the min and max limits used in
  * splitExposure() to take the quantization of the exposure and gain into
  * account.
  *
- * When this has not been called, it is assumed that exposure is in micro second
- * granularity and gain has no quantization at all.
- *
  * ExposureModeHelper keeps a pointer to the CameraSensorHelper, so the caller
  * has to ensure that sensorHelper is valid until the next call to configure().
  */
-void ExposureModeHelper::configure(utils::Duration lineDuration,
+void ExposureModeHelper::configure(const SensorConfiguration &sensorConfig,
 				   const CameraSensorHelper *sensorHelper)
 {
-	sensor_.lineDuration_ = lineDuration;
+	sensor_ = sensorConfig;
 	sensorHelper_ = sensorHelper;
+
+	/* Initialize run-time limits with sensor's default. */
+	minExposureTime_ = sensor_.minExposureTime_;
+	maxExposureTime_ = sensor_.maxExposureTime_;
+	minGain_ = sensor_.minGain_;
+	maxGain_ = sensor_.maxGain_;
 }
 
 /**
diff --git a/src/ipa/libipa/exposure_mode_helper.h b/src/ipa/libipa/exposure_mode_helper.h
index 4971cfbf5b2be9ef0e3e95a64b815902833e93a4..e41c58767eee65dd27946336beb2bc182dd4ab58 100644
--- a/src/ipa/libipa/exposure_mode_helper.h
+++ b/src/ipa/libipa/exposure_mode_helper.h
@@ -38,7 +38,8 @@  public:
 	ExposureModeHelper(const Span<std::pair<utils::Duration, double>> stages);
 	~ExposureModeHelper() = default;
 
-	void configure(utils::Duration lineLength, const CameraSensorHelper *sensorHelper);
+	void configure(const SensorConfiguration &sensorConfig,
+		       const CameraSensorHelper *sensorHelper);
 	void setLimits(utils::Duration minExposureTime, utils::Duration maxExposureTime,
 		       double minGain, double maxGain);
 
diff --git a/src/ipa/mali-c55/algorithms/agc.cpp b/src/ipa/mali-c55/algorithms/agc.cpp
index 4fa00769d201d906be357809f5af02c71201a4f1..d6a1ff5aaca136c387feb8c948053fc83bb664ee 100644
--- a/src/ipa/mali-c55/algorithms/agc.cpp
+++ b/src/ipa/mali-c55/algorithms/agc.cpp
@@ -169,12 +169,16 @@  int Agc::configure(IPAContext &context,
 	context.activeState.agc.constraintMode = constraintModes().begin()->first;
 	context.activeState.agc.exposureMode = exposureModeHelpers().begin()->first;
 
-	/* \todo Run this again when FrameDurationLimits is passed in */
-	setLimits(context.configuration.sensor.minShutterSpeed,
-		  context.configuration.sensor.maxShutterSpeed,
-		  context.configuration.sensor.minAnalogueGain,
-		  context.configuration.sensor.maxAnalogueGain,
-		  {});
+	AgcMeanLuminance::SensorConfiguration sensorConfig;
+	sensorConfig.lineDuration = context.configuration.sensor.lineDuration;
+	sensorConfig.minExposureTime = context.configuration.sensor.minShutterSpeed;
+	sensorConfig.maxExposureTime = context.configuration.sensor.maxShutterSpeed;
+	sensorConfig.minAnalogueGain = context.configuration.sensor.minAnalogueGain;
+	sensorConfig.maxAnalogueGain = context.configuration.sensor.maxAnalogueGain;
+
+	AgcMeanLuminance::configure(sensorConfig, context.camHelper.get());
+
+	/* \todo Update AGC limits when FrameDurationLimits is passed in */
 
 	resetFrameCount();
 
diff --git a/src/ipa/rkisp1/algorithms/agc.cpp b/src/ipa/rkisp1/algorithms/agc.cpp
index aa1a90daf3ca7d0041c56000c12fc4d1ab5700eb..b0c8966eea63901640bbe16af2a5d8a303c63ece 100644
--- a/src/ipa/rkisp1/algorithms/agc.cpp
+++ b/src/ipa/rkisp1/algorithms/agc.cpp
@@ -200,13 +200,14 @@  int Agc::configure(IPAContext &context, const IPACameraSensorInfo &configInfo)
 	context.configuration.agc.measureWindow.h_size = configInfo.outputSize.width;
 	context.configuration.agc.measureWindow.v_size = configInfo.outputSize.height;
 
-	AgcMeanLuminance::configure(context.configuration.sensor.lineDuration,
-				    context.camHelper.get());
-
-	setLimits(context.configuration.sensor.minExposureTime,
-		  context.configuration.sensor.maxExposureTime,
-		  context.configuration.sensor.minAnalogueGain,
-		  context.configuration.sensor.maxAnalogueGain, {});
+	AgcMeanLuminance::SensorConfiguration sensorConfig;
+	sensorConfig.lineDuration = context.configuration.sensor.lineDuration;
+	sensorConfig.minExposureTime = context.configuration.sensor.minExposureTime;
+	sensorConfig.maxExposureTime = context.configuration.sensor.maxExposureTime;
+	sensorConfig.minAnalogueGain = context.configuration.sensor.minAnalogueGain;
+	sensorConfig.maxAnalogueGain = context.configuration.sensor.maxAnalogueGain;
+
+	AgcMeanLuminance::configure(sensorConfig, context.camHelper.get());
 
 	context.activeState.agc.automatic.yTarget = effectiveYTarget();