[RFC,v3,05/19] ipa: libipa: exposure_mode_helper: Handle no stages
diff mbox series

Message ID 20261019184526.252977-6-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. 19, 2026, 6:45 p.m. UTC
Make the handling of the "no stage" explicit.

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

Comments

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

On Mon, Oct 19, 2026 at 08:45:12PM +0200, Barnabás Pőcze wrote:
> Make the handling of the "no stage" explicit.
>
> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
> ---
>  src/ipa/libipa/exposure_mode_helper.cpp | 21 +++++++++++++++++----
>  1 file changed, 17 insertions(+), 4 deletions(-)
>
> diff --git a/src/ipa/libipa/exposure_mode_helper.cpp b/src/ipa/libipa/exposure_mode_helper.cpp
> index 51f4be98e2..7a810a3673 100644
> --- a/src/ipa/libipa/exposure_mode_helper.cpp
> +++ b/src/ipa/libipa/exposure_mode_helper.cpp
> @@ -240,7 +240,22 @@ ExposureModeHelper::splitExposure(utils::Duration exposure) const
>  			 exposure / (exposureTime * gain * quantGain) };
>  	}
>
> -	double lastStageGain = clampGain(1.0);
> +	const double unitGain = clampGain(1.0);
> +
> +	/*
> +	 * If no stages are present, max out the exposure time, then the
> +	 * analogue gain, and use digital gain for the rest.
> +	 */
> +	if (stages_.empty()) {
> +		exposureTime = clampExposureTime(exposure / unitGain, &quantGain);
> +		gain = clampGain(exposure / exposureTime, &quantGain2);
> +		quantGain *= quantGain2;
> +
> +		return { exposureTime, gain, quantGain,
> +			 exposure / (exposureTime * gain * quantGain) };
> +	}

Isn't this exactly what happens at the end of the function ?

if stages_.empty() we never enter the for() loop and end up doing what
you're doing here if I'm not mistaken ?

> +
> +	double lastStageGain = unitGain;
>
>  	for (const auto &stage : stages_) {
>  		utils::Duration stageExposureTime = clampExposureTime(stage.exposureTime,
> @@ -282,9 +297,7 @@ 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 gain of 1.0 is used so that exposure
> -	 * time is maxed before gain is touched at all.
> +	 * the rest of the exposure time to digital gain.
>  	 */
>  	exposureTime = clampExposureTime(exposure / lastStageGain, &quantGain);
>  	gain = clampGain(exposure / exposureTime, &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 51f4be98e2..7a810a3673 100644
--- a/src/ipa/libipa/exposure_mode_helper.cpp
+++ b/src/ipa/libipa/exposure_mode_helper.cpp
@@ -240,7 +240,22 @@  ExposureModeHelper::splitExposure(utils::Duration exposure) const
 			 exposure / (exposureTime * gain * quantGain) };
 	}
 
-	double lastStageGain = clampGain(1.0);
+	const double unitGain = clampGain(1.0);
+
+	/*
+	 * If no stages are present, max out the exposure time, then the
+	 * analogue gain, and use digital gain for the rest.
+	 */
+	if (stages_.empty()) {
+		exposureTime = clampExposureTime(exposure / unitGain, &quantGain);
+		gain = clampGain(exposure / exposureTime, &quantGain2);
+		quantGain *= quantGain2;
+
+		return { exposureTime, gain, quantGain,
+			 exposure / (exposureTime * gain * quantGain) };
+	}
+
+	double lastStageGain = unitGain;
 
 	for (const auto &stage : stages_) {
 		utils::Duration stageExposureTime = clampExposureTime(stage.exposureTime,
@@ -282,9 +297,7 @@  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 gain of 1.0 is used so that exposure
-	 * time is maxed before gain is touched at all.
+	 * the rest of the exposure time to digital gain.
 	 */
 	exposureTime = clampExposureTime(exposure / lastStageGain, &quantGain);
 	gain = clampGain(exposure / exposureTime, &quantGain2);