[libcamera-devel,06/22] ipa: ipu3: agc: Refactor ev gain calculation and testing
diff mbox series

Message ID 20211108131350.130665-7-jeanmichel.hautbois@ideasonboard.com
State Superseded
Headers show
Series
  • IPA: IPU3: Introduce per-frame controls
Related show

Commit Message

Jean-Michel Hautbois Nov. 8, 2021, 1:13 p.m. UTC
When we compute the new gain, we use the iqMean_ and estimate an
exposure value gain to apply. Return early when the gain is less than
1%.

Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
---
 src/ipa/ipu3/algorithms/agc.cpp | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

Comments

Kieran Bingham Nov. 8, 2021, 2:38 p.m. UTC | #1
Quoting Jean-Michel Hautbois (2021-11-08 13:13:34)
> When we compute the new gain, we use the iqMean_ and estimate an
> exposure value gain to apply. Return early when the gain is less than
> 1%.
> 
> Signed-off-by: Jean-Michel Hautbois <jeanmichel.hautbois@ideasonboard.com>
> ---
>  src/ipa/ipu3/algorithms/agc.cpp | 8 +++-----
>  1 file changed, 3 insertions(+), 5 deletions(-)
> 
> diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp
> index 133f5931..119a7938 100644
> --- a/src/ipa/ipu3/algorithms/agc.cpp
> +++ b/src/ipa/ipu3/algorithms/agc.cpp
> @@ -189,17 +189,15 @@ void Agc::filterExposure()
>   */
>  void Agc::computeExposure(uint32_t &exposure, double &analogueGain)
>  {
> +       /* Estimate the gain needed to have the proportion wanted */

Proportion? As we're in computeExposure, do you mean exposure? or
something else?

Otherwise - proportion of what? It doesn't quite make sense (to me) on
the small sentence on its own.

> +       double evGain = kEvGainTarget * knumHistogramBins / iqMean_;
>  
> -       /* Are we correctly exposed ? */

I guess this is redundant?

> -       if (std::abs(iqMean_ - kEvGainTarget * knumHistogramBins) <= 1) {
> +       if (std::abs(evGain - 1.0) < 0.01) {

This reads better, but while it can be inferred that the 0.01 is 1%, I'd be
tempted to put something explicit:
	/* Consider within 1% of the target as correctly exposed */

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

>                 LOG(IPU3Agc, Debug) << "We are well exposed (iqMean = "
>                                     << iqMean_ << ")";
>                 return;
>         }
>  
> -       /* Estimate the gain needed to have the proportion wanted */

I see it was already in like that though. Still if you can expand upon
it, it might help.


> -       double evGain = kEvGainTarget * knumHistogramBins / iqMean_;
> -
>         /* extracted from Rpi::Agc::computeTargetExposure */
>         /* Calculate the shutter time in seconds */
>         utils::Duration currentShutter = exposure * lineDuration_;
> -- 
> 2.32.0
>

Patch
diff mbox series

diff --git a/src/ipa/ipu3/algorithms/agc.cpp b/src/ipa/ipu3/algorithms/agc.cpp
index 133f5931..119a7938 100644
--- a/src/ipa/ipu3/algorithms/agc.cpp
+++ b/src/ipa/ipu3/algorithms/agc.cpp
@@ -189,17 +189,15 @@  void Agc::filterExposure()
  */
 void Agc::computeExposure(uint32_t &exposure, double &analogueGain)
 {
+	/* Estimate the gain needed to have the proportion wanted */
+	double evGain = kEvGainTarget * knumHistogramBins / iqMean_;
 
-	/* Are we correctly exposed ? */
-	if (std::abs(iqMean_ - kEvGainTarget * knumHistogramBins) <= 1) {
+	if (std::abs(evGain - 1.0) < 0.01) {
 		LOG(IPU3Agc, Debug) << "We are well exposed (iqMean = "
 				    << iqMean_ << ")";
 		return;
 	}
 
-	/* Estimate the gain needed to have the proportion wanted */
-	double evGain = kEvGainTarget * knumHistogramBins / iqMean_;
-
 	/* extracted from Rpi::Agc::computeTargetExposure */
 	/* Calculate the shutter time in seconds */
 	utils::Duration currentShutter = exposure * lineDuration_;