ipa: ipu3: agc: Simplify division of exposure/gain

Until now, the algorithm makes complex assumptions when dividing the
exposure and analogue gain values. Instead, use a simpler clamping of
the shutter speed first, and then of the analogue gain, based on the
limits configured.

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-12 16:52:44 +02:00
parent f1cf01d13b
commit 17dbae2325

View file

@ -147,7 +147,9 @@ void Agc::lockExposureGain(uint32_t &exposure, double &gain)
<< " Gain " << gain; << " Gain " << gain;
currentExposure_ = currentExposureNoDg_ * newGain; currentExposure_ = currentExposureNoDg_ * newGain;
utils::Duration minShutterSpeed = minExposureLines_ * lineDuration_;
utils::Duration maxShutterSpeed = maxExposureLines_ * lineDuration_; utils::Duration maxShutterSpeed = maxExposureLines_ * lineDuration_;
utils::Duration maxTotalExposure = maxShutterSpeed * kMaxGain; utils::Duration maxTotalExposure = maxShutterSpeed * kMaxGain;
currentExposure_ = std::min(currentExposure_, maxTotalExposure); currentExposure_ = std::min(currentExposure_, maxTotalExposure);
LOG(IPU3Agc, Debug) << "Target total exposure " << currentExposure_ LOG(IPU3Agc, Debug) << "Target total exposure " << currentExposure_
@ -156,23 +158,23 @@ void Agc::lockExposureGain(uint32_t &exposure, double &gain)
/* \todo: estimate if we need to desaturate */ /* \todo: estimate if we need to desaturate */
filterExposure(); filterExposure();
utils::Duration newExposure = 0.0s; utils::Duration exposureValue = filteredExposure_;
if (currentShutter < maxShutterSpeed) { utils::Duration shutterTime = minShutterSpeed;
exposure = std::clamp<uint32_t>(exposure * filteredExposure_ / currentExposureNoDg_,
minExposureLines_, /*
maxExposureLines_); * Push the shutter time up to the maximum first, and only then
newExposure = filteredExposure_ / exposure; * increase the gain.
gain = std::clamp(gain * filteredExposure_ / newExposure, */
shutterTime = std::clamp<utils::Duration>(exposureValue / kMinGain,
minShutterSpeed, maxShutterSpeed);
double stepGain = std::clamp(exposureValue / shutterTime,
kMinGain, kMaxGain); kMinGain, kMaxGain);
} else { LOG(IPU3Agc, Debug) << "Divided up shutter and gain are "
gain = std::clamp(gain * filteredExposure_ / currentExposureNoDg_, << shutterTime << " and "
kMinGain, kMaxGain); << stepGain;
newExposure = filteredExposure_ / gain;
exposure = std::clamp<uint32_t>(exposure * filteredExposure_ / newExposure, exposure = shutterTime / lineDuration_;
minExposureLines_, gain = stepGain;
maxExposureLines_);
}
LOG(IPU3Agc, Debug) << "Adjust exposure " << exposure * lineDuration_ << " and gain " << gain;
} }
lastFrame_ = frameCount_; lastFrame_ = frameCount_;
} }