[v5,09/24] ipa: libipa: exposure_mode_helper: Remove `lastStageGain`
diff mbox series

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

Commit Message

Barnabás Pőcze Oct. 29, 2026, 12:58 p.m. UTC
There is no need for a separate variable, `stageGain` already contains
the previous stage's gain at the beginning of the loop. Moving the
assignment to a later point removes the need for a separate variable.

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

Comments

Jacopo Mondi Oct. 29, 2026, 3:43 p.m. UTC | #1
Hi Barnabás

On Thu, Oct 29, 2026 at 01:58:29PM +0100, Barnabás Pőcze wrote:
> There is no need for a separate variable, `stageGain` already contains
> the previous stage's gain at the beginning of the loop. Moving the
> assignment to a later point removes the need for a separate variable.
>
> 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 | 14 ++++++--------
>  1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/src/ipa/libipa/exposure_mode_helper.cpp b/src/ipa/libipa/exposure_mode_helper.cpp
> index 4ec31f54c3..4076d6f385 100644
> --- a/src/ipa/libipa/exposure_mode_helper.cpp
> +++ b/src/ipa/libipa/exposure_mode_helper.cpp
> @@ -241,12 +241,10 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const
>  	}
>
>  	double stageGain = clampGain(1.0);
> -	double lastStageGain = stageGain;
>
>  	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
> @@ -256,9 +254,9 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const
>  		 * the stage limits are initialised.
>  		 */
>
> -		/* Clamp the gain to lastStageGain and regulate exposureTime. */
> -		if (stageExposureTime * lastStageGain >= exposure) {
> -			exposureTime = clampExposureTime(exposure / lastStageGain, &quantGain);
> +		/* Clamp the gain to that of the last stage and regulate exposure time. */
> +		if (stageExposureTime * stageGain >= exposure) {
> +			exposureTime = clampExposureTime(exposure / stageGain, &quantGain);
>  			gain = clampGain(exposure / exposureTime, &quantGain2);
>  			quantGain *= quantGain2;
>
> @@ -266,7 +264,9 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const
>  				 exposure / (exposureTime * gain * quantGain) };
>  		}
>
> -		/* Clamp the exposureTime to stageExposureTime and regulate gain. */
> +		/* Clamp the exposure time to stageExposureTime and regulate gain. */
> +		stageGain = clampGain(stage.gain);
> +
>  		if (stageExposureTime * stageGain >= exposure) {
>  			exposureTime = stageExposureTime;
>  			gain = clampGain(exposure / exposureTime, &quantGain2);
> @@ -275,8 +275,6 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const
>  			return { exposureTime, gain, quantGain,
>  				 exposure / (exposureTime * gain * quantGain) };
>  		}
> -
> -		lastStageGain = stageGain;
>  	}
>
>  	/*
> --
> 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 4ec31f54c3..4076d6f385 100644
--- a/src/ipa/libipa/exposure_mode_helper.cpp
+++ b/src/ipa/libipa/exposure_mode_helper.cpp
@@ -241,12 +241,10 @@  ExposureModeHelper::splitExposure(utils::Duration exposure) const
 	}
 
 	double stageGain = clampGain(1.0);
-	double lastStageGain = stageGain;
 
 	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
@@ -256,9 +254,9 @@  ExposureModeHelper::splitExposure(utils::Duration exposure) const
 		 * the stage limits are initialised.
 		 */
 
-		/* Clamp the gain to lastStageGain and regulate exposureTime. */
-		if (stageExposureTime * lastStageGain >= exposure) {
-			exposureTime = clampExposureTime(exposure / lastStageGain, &quantGain);
+		/* Clamp the gain to that of the last stage and regulate exposure time. */
+		if (stageExposureTime * stageGain >= exposure) {
+			exposureTime = clampExposureTime(exposure / stageGain, &quantGain);
 			gain = clampGain(exposure / exposureTime, &quantGain2);
 			quantGain *= quantGain2;
 
@@ -266,7 +264,9 @@  ExposureModeHelper::splitExposure(utils::Duration exposure) const
 				 exposure / (exposureTime * gain * quantGain) };
 		}
 
-		/* Clamp the exposureTime to stageExposureTime and regulate gain. */
+		/* Clamp the exposure time to stageExposureTime and regulate gain. */
+		stageGain = clampGain(stage.gain);
+
 		if (stageExposureTime * stageGain >= exposure) {
 			exposureTime = stageExposureTime;
 			gain = clampGain(exposure / exposureTime, &quantGain2);
@@ -275,8 +275,6 @@  ExposureModeHelper::splitExposure(utils::Duration exposure) const
 			return { exposureTime, gain, quantGain,
 				 exposure / (exposureTime * gain * quantGain) };
 		}
-
-		lastStageGain = stageGain;
 	}
 
 	/*