ipa: ipu3: Use sensor limits for analogue gain

Instead of using constants for the analogue gains limits, use the
minimum and maximum from the configured sensor.

Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
This commit is contained in:
Jean-Michel Hautbois 2021-10-21 18:23:37 +02:00
parent 58486847f0
commit 43d098ce5f
2 changed files with 13 additions and 9 deletions

View file

@ -30,10 +30,9 @@ static constexpr uint32_t kInitialFrameMinAECount = 4;
/* Number of frames to wait between new gain/exposure estimations */ /* Number of frames to wait between new gain/exposure estimations */
static constexpr uint32_t kFrameSkipCount = 6; static constexpr uint32_t kFrameSkipCount = 6;
/* Maximum analogue gain value /* Limits for analogue gain values */
* \todo grab it from a camera helper */ static constexpr double kMinAnalogueGain = 1.0;
static constexpr double kMinGain = 1.0; static constexpr double kMaxAnalogueGain = 8.0;
static constexpr double kMaxGain = 8.0;
/* Histogram constants */ /* Histogram constants */
static constexpr uint32_t knumHistogramBins = 256; static constexpr uint32_t knumHistogramBins = 256;
@ -57,9 +56,11 @@ int Agc::configure(IPAContext &context, const IPAConfigInfo &configInfo)
minExposureLines_ = context.configuration.agc.minShutterSpeed / lineDuration_; minExposureLines_ = context.configuration.agc.minShutterSpeed / lineDuration_;
maxExposureLines_ = context.configuration.agc.maxShutterSpeed / lineDuration_; maxExposureLines_ = context.configuration.agc.maxShutterSpeed / lineDuration_;
minAnalogueGain_ = std::max(context.configuration.agc.minAnalogueGain, kMinAnalogueGain);
maxAnalogueGain_ = std::min(context.configuration.agc.maxAnalogueGain, kMaxAnalogueGain);
/* Configure the default exposure and gain. */ /* Configure the default exposure and gain. */
context.frameContext.agc.gain = context.frameContext.agc.gain = minAnalogueGain_;
context.configuration.agc.minAnalogueGain;
context.frameContext.agc.exposure = minExposureLines_; context.frameContext.agc.exposure = minExposureLines_;
prevExposureValue_ = context.frameContext.agc.gain prevExposureValue_ = context.frameContext.agc.gain
@ -148,7 +149,7 @@ void Agc::lockExposureGain(uint32_t &exposure, double &analogueGain)
utils::Duration minShutterSpeed = minExposureLines_ * lineDuration_; utils::Duration minShutterSpeed = minExposureLines_ * lineDuration_;
utils::Duration maxShutterSpeed = maxExposureLines_ * lineDuration_; utils::Duration maxShutterSpeed = maxExposureLines_ * lineDuration_;
utils::Duration maxTotalExposure = maxShutterSpeed * kMaxGain; utils::Duration maxTotalExposure = maxShutterSpeed * maxAnalogueGain_;
currentExposure_ = std::min(currentExposure_, maxTotalExposure); currentExposure_ = std::min(currentExposure_, maxTotalExposure);
LOG(IPU3Agc, Debug) << "Target total exposure " << currentExposure_ LOG(IPU3Agc, Debug) << "Target total exposure " << currentExposure_
<< ", maximum is " << maxTotalExposure; << ", maximum is " << maxTotalExposure;
@ -163,10 +164,10 @@ void Agc::lockExposureGain(uint32_t &exposure, double &analogueGain)
* Push the shutter time up to the maximum first, and only then * Push the shutter time up to the maximum first, and only then
* increase the gain. * increase the gain.
*/ */
shutterTime = std::clamp<utils::Duration>(exposureValue / kMinGain, shutterTime = std::clamp<utils::Duration>(exposureValue / minAnalogueGain_,
minShutterSpeed, maxShutterSpeed); minShutterSpeed, maxShutterSpeed);
double stepGain = std::clamp(exposureValue / shutterTime, double stepGain = std::clamp(exposureValue / shutterTime,
kMinGain, kMaxGain); minAnalogueGain_, maxAnalogueGain_);
LOG(IPU3Agc, Debug) << "Divided up shutter and gain are " LOG(IPU3Agc, Debug) << "Divided up shutter and gain are "
<< shutterTime << " and " << shutterTime << " and "
<< stepGain; << stepGain;

View file

@ -45,6 +45,9 @@ private:
uint32_t minExposureLines_; uint32_t minExposureLines_;
uint32_t maxExposureLines_; uint32_t maxExposureLines_;
double minAnalogueGain_;
double maxAnalogueGain_;
utils::Duration filteredExposure_; utils::Duration filteredExposure_;
utils::Duration currentExposure_; utils::Duration currentExposure_;
utils::Duration prevExposureValue_; utils::Duration prevExposureValue_;