@@ -9,6 +9,7 @@
#include <algorithm>
#include <cmath>
+#include <optional>
#include <libcamera/base/log.h>
#include <libcamera/control_ids.h>
@@ -171,11 +172,10 @@ static constexpr double kMaxRelativeLuminanceTarget = 0.95;
* IPA modules that want to use this class to implement their AEGC algorithm
* should derive it and provide an overriding estimateLuminance() function for
* this class to use. They must call parseTuningData() in init(), and must also
- * call setLimits() and resetFrameCounter() in configure(). They may then use
- * calculateNewEv() in process(). If the limits passed to setLimits() change for
- * any reason (for example, in response to a FrameDurationLimit control being
- * passed in queueRequest()) then setLimits() must be called again with the new
- * values.
+ * call resetFrameCounter() in configure(). They may then use calculateNewEv()
+ * in process(). To update the algorithm limits for example, in response to a
+ * FrameDurationLimit control being passed in queueRequest()) then
+ * setExposureLimits() must be called with the new values.
*/
AgcMeanLuminance::AgcMeanLuminance()
@@ -459,25 +459,21 @@ int AgcMeanLuminance::parseTuningData(const YamlObject &tuningData)
/**
* \brief Set the ExposureModeHelper limits for this class
- * \param[in] minExposureTime Minimum exposure time to allow
- * \param[in] maxExposureTime Maximum ewposure time to allow
+ * \param[in] shutterTime The (optional) fixed shutter time
+ * \param[in] gain The (optional) analogue gain value
* \param[in] maxFrameDuration Maximum frame duration
- * \param[in] minGain Minimum gain to allow
- * \param[in] maxGain Maximum gain to allow
* \param[in] constraints Additional constraints to apply
*
- * This function calls \ref ExposureModeHelper::setLimits() for each
+ * This function calls \ref ExposureModeHelper::setExposureLimits() for each
* ExposureModeHelper that has been created for this class.
*/
-void AgcMeanLuminance::setLimits(utils::Duration minExposureTime,
- utils::Duration maxExposureTime,
- utils::Duration maxFrameDuration,
- double minGain, double maxGain,
- std::vector<AgcMeanLuminance::AgcConstraint> constraints)
+void AgcMeanLuminance::setExposureLimits(std::optional<utils::Duration> shutterTime,
+ std::optional<double> gain,
+ utils::Duration maxFrameDuration,
+ std::vector<AgcMeanLuminance::AgcConstraint> constraints)
{
for (auto &[id, helper] : exposureModeHelpers_)
- helper->setLimits(minExposureTime, maxExposureTime, maxFrameDuration,
- minGain, maxGain);
+ helper->setExposureLimits(shutterTime, gain, maxFrameDuration);
additionalConstraints_ = std::move(constraints);
}
@@ -61,9 +61,10 @@ public:
exposureCompensation_ = gain;
}
- void setLimits(utils::Duration minExposureTime, utils::Duration maxExposureTime,
- utils::Duration maxFrameDuration, double minGain, double maxGain,
- std::vector<AgcConstraint> constraints);
+ void setExposureLimits(std::optional<utils::Duration> shutterTime,
+ std::optional<double> gain,
+ utils::Duration maxFrameDuration,
+ std::vector<AgcConstraint> constraints);
const std::map<int32_t, std::vector<AgcConstraint>> &constraintModes() const
{
@@ -109,25 +109,33 @@ ExposureModeHelper::ExposureModeHelper(const Span<std::pair<utils::Duration, dou
}
}
-void ExposureModeHelper::setMaxExposure(utils::Duration minExposureTime,
- utils::Duration maxExposureTime,
- utils::Duration maxFrameDuration)
+void ExposureModeHelper::setShutterLimits(std::optional<utils::Duration> shutterTime,
+ utils::Duration maxFrameDuration)
{
- minExposureTime_ = minExposureTime;
-
/*
- * Compute the maximum shutter time.
- *
- * If maxExposureTime is equal to minExposureTime then we use them
- * to fix the exposure time.
+ * If shutterTime is populated we use it to to fix the shutter time.
*
- * Otherwise, if the exposure can range between a min and max delegate
- * the maximum shutter time calculation to the sensor helper.
+ * Otherwise, if the exposure is not fixed delegate the maximum shutter
+ * time calculation to the sensor helper and restore the min exposure
+ * time to the sensor's default value.
*/
- maxExposureTime_ = minExposureTime != maxExposureTime
- ? sensorHelper_->maxShutterTime(maxFrameDuration,
- sensor_.lineDuration_)
- : minExposureTime;
+
+ maxExposureTime_ = shutterTime.has_value()
+ ? shutterTime.value()
+ : sensorHelper_->maxShutterTime(maxFrameDuration,
+ sensor_.lineDuration_);
+ minExposureTime_ = shutterTime.has_value()
+ ? shutterTime.value() : sensor_.minExposureTime_;
+}
+
+void ExposureModeHelper::setGainLimits(std::optional<double> gain)
+{
+ /*
+ * Use the fixed value as limits if populated, otherwise use the
+ * sensor's default ones.
+ */
+ minGain_ = gain.has_value() ? gain.value() : sensor_.minGain_;
+ maxGain_ = gain.has_value() ? gain.value() : sensor_.maxGain_;
}
/**
@@ -154,42 +162,37 @@ void ExposureModeHelper::configure(const SensorConfiguration &sensorConfig,
sensorHelper_ = sensorHelper;
/* Initialize run-time limits with sensor's default. */
- minGain_ = sensor_.minGain_;
- maxGain_ = sensor_.maxGain_;
-
- setMaxExposure(sensorConfig.minExposureTime_, sensorConfig.maxExposureTime_,
- sensorConfig.maxFrameDuration_);
+ setShutterLimits({}, sensorConfig.maxFrameDuration_);
+ setGainLimits({});
}
/**
* \brief Set the exposure time and gain limits
- * \param[in] minExposureTime The minimum exposure time supported
- * \param[in] maxExposureTime The maximum exposure time supported
+ * \param[in] shutterTime The (optional) fixed shutter time
+ * \param[in] gain The (optional) fixed gain
* \param[in] maxFrameDuration The maximum frame duration
- * \param[in] minGain The minimum analogue gain supported
- * \param[in] maxGain The maximum analogue gain supported
*
- * This function configures the exposure time and analogue gain limits that need
+ * This function configures the shutter time and analogue gain limits that need
* to be adhered to as the helper divides up exposure. Note that this function
* *must* be called whenever those limits change and before splitExposure() is
* used.
*
- * If the algorithm using the helpers needs to indicate that either exposure time
- * or analogue gain or both should be fixed it can do so by setting both the
- * minima and maxima to the same value.
+ * If the algorithm using the helpers needs to indicate that the shutter time
+ * should be fixed it should populate the optional \a shutterTime argument.
+ * If the shutter time is not fixed, the maximum achievable shutter time is
+ * calculated using \a maxFrameDuration as the upper bound while the minimum
+ * exposure time is reset to the sensor's default.
*
- * The exposure time limits are calculated using \a maxFrameDuration as the
- * upper bound, the \a maxExposureTime paramter effectivelly only serves
- * to indicate that the caller wants a fixed exposure value.
+ * If the analogue gain should be fixed the optional \a gain argument should
+ * be populated. If the analogue gain is not fixed its min and max values are
+ * reset to the sensor's default.
*/
-void ExposureModeHelper::setLimits(utils::Duration minExposureTime,
- utils::Duration maxExposureTime,
- utils::Duration maxFrameDuration,
- double minGain, double maxGain)
+void ExposureModeHelper::setExposureLimits(std::optional<utils::Duration> shutterTime,
+ std::optional<double> gain,
+ utils::Duration maxFrameDuration)
{
- minGain_ = minGain;
- maxGain_ = maxGain;
- setMaxExposure(minExposureTime, maxExposureTime, maxFrameDuration);
+ setShutterLimits(shutterTime, maxFrameDuration);
+ setGainLimits(gain);
}
utils::Duration ExposureModeHelper::clampExposureTime(utils::Duration exposureTime,
@@ -7,6 +7,7 @@
#pragma once
+#include <optional>
#include <tuple>
#include <utility>
#include <vector>
@@ -40,16 +41,18 @@ public:
void configure(const SensorConfiguration &sensorConfig,
const CameraSensorHelper *sensorHelper);
- void setLimits(utils::Duration minExposureTime, utils::Duration maxExposureTime,
- utils::Duration maxFrameDuration, double minGain, double maxGain);
+ void setExposureLimits(std::optional<utils::Duration> shutterTime,
+ std::optional<double> gain,
+ utils::Duration maxFrameDuration);
std::tuple<utils::Duration, double, double, double>
splitExposure(utils::Duration exposure) const;
private:
- void setMaxExposure(utils::Duration minExposureTime,
- utils::Duration maxExposureTime,
- utils::Duration maxFrameDuration);
+ void setShutterLimits(std::optional<utils::Duration> shutterTime,
+ utils::Duration maxFrameDuration);
+ void setGainLimits(std::optional<double> gain);
+
utils::Duration clampExposureTime(utils::Duration exposureTime,
double *quantizationGain = nullptr) const;
double clampGain(double gain, double *quantizationGain = nullptr) const;
@@ -573,34 +573,23 @@ void Agc::process(IPAContext &context, [[maybe_unused]] const uint32_t frame,
* Set the AGC limits using the fixed exposure time and/or gain in
* manual mode, or the sensor limits in auto mode.
*/
- utils::Duration minExposureTime;
- utils::Duration maxExposureTime;
- double minAnalogueGain;
- double maxAnalogueGain;
+ std::optional<utils::Duration> shutterTime;
+ std::optional<double> gain;
- if (frameContext.agc.autoExposureEnabled) {
- minExposureTime = context.configuration.sensor.minExposureTime;
- maxExposureTime = context.configuration.sensor.maxExposureTime;
- } else {
- minExposureTime = context.configuration.sensor.lineDuration
- * frameContext.agc.exposure;
- maxExposureTime = minExposureTime;
+ if (!frameContext.agc.autoExposureEnabled) {
+ shutterTime = context.configuration.sensor.lineDuration
+ * frameContext.agc.exposure;
}
- if (frameContext.agc.autoGainEnabled) {
- minAnalogueGain = context.configuration.sensor.minAnalogueGain;
- maxAnalogueGain = context.configuration.sensor.maxAnalogueGain;
- } else {
- minAnalogueGain = frameContext.agc.gain;
- maxAnalogueGain = frameContext.agc.gain;
- }
+ if (!frameContext.agc.autoGainEnabled)
+ gain = frameContext.agc.gain;
std::vector<AgcMeanLuminance::AgcConstraint> additionalConstraints;
if (context.activeState.wdr.mode != controls::WdrOff)
additionalConstraints.push_back(context.activeState.wdr.constraint);
- setLimits(minExposureTime, maxExposureTime, frameContext.agc.maxFrameDuration,
- minAnalogueGain, maxAnalogueGain, std::move(additionalConstraints));
+ setExposureLimits(shutterTime, gain, frameContext.agc.maxFrameDuration,
+ std::move(additionalConstraints));
/*
* The Agc algorithm needs to know the effective exposure value that was
The setLimits() interface accepts a min/max exposure and gains and detect a request for a fixed value if min == max. For the shutter time, the concept of max exposure is ill-formed as the maximum achievable exposure is determinate by the frame duration, while the min frame duration is a sensor's default parameter. For gains instead either we want a fixed value or it can range in the sensor's min and max values. As we now store the sensor's default in the exposure mode helper, rework the interface of setLimits() both in AgcMeanLuminance and ExposureModeHelper so that it receives - an optional fixed shutter time - an optional fixed gain - the current maximum frame duration If the optional fixed values are populated they are used to fix either the shutter time or the exposure. If they are not set instead the algorithm is free to range in the: - shutterTime = [minExposure, frameDuration - margin] - gain = [minGain, maxGain] Signed-off-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com> --- src/ipa/libipa/agc_mean_luminance.cpp | 30 ++++++------- src/ipa/libipa/agc_mean_luminance.h | 7 +-- src/ipa/libipa/exposure_mode_helper.cpp | 79 +++++++++++++++++---------------- src/ipa/libipa/exposure_mode_helper.h | 13 +++--- src/ipa/rkisp1/algorithms/agc.cpp | 29 ++++-------- 5 files changed, 75 insertions(+), 83 deletions(-)