[RFC,v4,06/23] ipa: libipa: exposure_mode_helper: Move `stageGain` variable
diff mbox series

Message ID 20261026132045.269007-7-barnabas.pocze@ideasonboard.com
State Superseded
Headers show
Series
  • ipa: libipa: agc: Take exposure margin into account
Related show

Commit Message

Barnabás Pőcze Oct. 26, 2026, 1:20 p.m. UTC
After the loop, `stageGain == lastStageGain`, so use `lastStageGain` in the
later calculation instead, and make `stageGain` "local" to the loop, just like
`stageExposure` already is.

And with that, also move the calculation a bit later, just before the value
is actually used.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
---
 src/ipa/libipa/exposure_mode_helper.cpp | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

Comments

Kieran Bingham Oct. 26, 2026, 7:50 p.m. UTC | #1
Quoting Barnabás Pőcze (2026-10-26 13:20:28)
> After the loop, `stageGain == lastStageGain`, so use `lastStageGain` in the
> later calculation instead, and make `stageGain` "local" to the loop, just like
> `stageExposure` already is.
> 
> And with that, also move the calculation a bit later, just before the value
> is actually used.
> 
> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>


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

> ---
>  src/ipa/libipa/exposure_mode_helper.cpp | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/src/ipa/libipa/exposure_mode_helper.cpp b/src/ipa/libipa/exposure_mode_helper.cpp
> index 3e600a5c76..8a712c6da9 100644
> --- a/src/ipa/libipa/exposure_mode_helper.cpp
> +++ b/src/ipa/libipa/exposure_mode_helper.cpp
> @@ -240,13 +240,11 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const
>                          exposure / (exposureTime * gain * quantGain) };
>         }
>  
> -       double stageGain = clampGain(1.0);
> -       double lastStageGain = stageGain;
> +       double lastStageGain = clampGain(1.0);
>  
>         for (const auto &stage : stages_) {
>                 utils::Duration stageExposureTime = clampExposureTime(stage.exposureTime,
>                                                                       &quantGain);
> -               stageGain = clampGain(stage.gain);
>  
>                 /*
>                  * We perform the clamping on both exposure time and gain in
> @@ -267,6 +265,8 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const
>                 }
>  
>                 /* Clamp the exposureTime to stageExposureTime and regulate gain. */
> +               const double stageGain = clampGain(stage.gain);
> +
>                 if (stageExposureTime * stageGain >= exposure) {
>                         exposureTime = stageExposureTime;
>                         gain = clampGain(exposure / exposureTime, &quantGain2);
> @@ -283,10 +283,10 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const
>          * From here on all we can do is max out the exposure time, followed by
>          * the analogue gain. If we still haven't achieved the target we send
>          * the rest of the exposure time to digital gain. If we were given no
> -        * stages to use then the default stageGain of 1.0 is used so that
> -        * exposure time is maxed before gain is touched at all.
> +        * stages to use then the default gain of 1.0 is used so that exposure
> +        * time is maxed before gain is touched at all.
>          */
> -       exposureTime = clampExposureTime(exposure / stageGain, &quantGain);
> +       exposureTime = clampExposureTime(exposure / lastStageGain, &quantGain);
>         gain = clampGain(exposure / exposureTime, &quantGain2);
>         quantGain *= quantGain2;
>  
> -- 
> 2.56.0
>

Patch
diff mbox series

diff --git a/src/ipa/libipa/exposure_mode_helper.cpp b/src/ipa/libipa/exposure_mode_helper.cpp
index 3e600a5c76..8a712c6da9 100644
--- a/src/ipa/libipa/exposure_mode_helper.cpp
+++ b/src/ipa/libipa/exposure_mode_helper.cpp
@@ -240,13 +240,11 @@  ExposureModeHelper::splitExposure(utils::Duration exposure) const
 			 exposure / (exposureTime * gain * quantGain) };
 	}
 
-	double stageGain = clampGain(1.0);
-	double lastStageGain = stageGain;
+	double lastStageGain = clampGain(1.0);
 
 	for (const auto &stage : stages_) {
 		utils::Duration stageExposureTime = clampExposureTime(stage.exposureTime,
 								      &quantGain);
-		stageGain = clampGain(stage.gain);
 
 		/*
 		 * We perform the clamping on both exposure time and gain in
@@ -267,6 +265,8 @@  ExposureModeHelper::splitExposure(utils::Duration exposure) const
 		}
 
 		/* Clamp the exposureTime to stageExposureTime and regulate gain. */
+		const double stageGain = clampGain(stage.gain);
+
 		if (stageExposureTime * stageGain >= exposure) {
 			exposureTime = stageExposureTime;
 			gain = clampGain(exposure / exposureTime, &quantGain2);
@@ -283,10 +283,10 @@  ExposureModeHelper::splitExposure(utils::Duration exposure) const
 	 * From here on all we can do is max out the exposure time, followed by
 	 * the analogue gain. If we still haven't achieved the target we send
 	 * the rest of the exposure time to digital gain. If we were given no
-	 * stages to use then the default stageGain of 1.0 is used so that
-	 * exposure time is maxed before gain is touched at all.
+	 * stages to use then the default gain of 1.0 is used so that exposure
+	 * time is maxed before gain is touched at all.
 	 */
-	exposureTime = clampExposureTime(exposure / stageGain, &quantGain);
+	exposureTime = clampExposureTime(exposure / lastStageGain, &quantGain);
 	gain = clampGain(exposure / exposureTime, &quantGain2);
 	quantGain *= quantGain2;