[v3,06/19] libipa: exposure_mode_helper: Remove unnecessary clamp calls
diff mbox series

Message ID 20250815102945.1602071-7-stefan.klug@ideasonboard.com
State New
Headers show
Series
  • Implement WDR algorithm
Related show

Commit Message

Stefan Klug Aug. 15, 2025, 10:29 a.m. UTC
Except for the first iteration of the loop and in the case of an empty
gains_ vector, the values were run through clamp two times which is
unnecessary. Remove that by clamping the initial value.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
Reviewed-by: Isaac Scott <isaac.scott@ideasonboard.com>
Reviewed-by: Daniel Scally <dan.scally@ideasonboard.com>

---

Changes in v3:
- Collected tags
---
 src/ipa/libipa/exposure_mode_helper.cpp | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

Patch
diff mbox series

diff --git a/src/ipa/libipa/exposure_mode_helper.cpp b/src/ipa/libipa/exposure_mode_helper.cpp
index cd81503e07d6..21efc4356afa 100644
--- a/src/ipa/libipa/exposure_mode_helper.cpp
+++ b/src/ipa/libipa/exposure_mode_helper.cpp
@@ -197,8 +197,8 @@  ExposureModeHelper::splitExposure(utils::Duration exposure) const
 		return { minExposureTime_, minGain_, exposure / (minExposureTime_ * minGain_) };
 
 	utils::Duration exposureTime;
-	double stageGain = 1.0;
-	double lastStageGain = 1.0;
+	double stageGain = clampGain(1.0);
+	double lastStageGain = stageGain;
 	double gain;
 
 	for (unsigned int stage = 0; stage < gains_.size(); stage++) {
@@ -215,7 +215,7 @@  ExposureModeHelper::splitExposure(utils::Duration exposure) const
 
 		/* Clamp the gain to lastStageGain and regulate exposureTime. */
 		if (stageExposureTime * lastStageGain >= exposure) {
-			exposureTime = clampExposureTime(exposure / clampGain(lastStageGain));
+			exposureTime = clampExposureTime(exposure / lastStageGain);
 			gain = clampGain(exposure / exposureTime);
 
 			return { exposureTime, gain, exposure / (exposureTime * gain) };
@@ -223,7 +223,7 @@  ExposureModeHelper::splitExposure(utils::Duration exposure) const
 
 		/* Clamp the exposureTime to stageExposureTime and regulate gain. */
 		if (stageExposureTime * stageGain >= exposure) {
-			exposureTime = clampExposureTime(stageExposureTime);
+			exposureTime = stageExposureTime;
 			gain = clampGain(exposure / exposureTime);
 
 			return { exposureTime, gain, exposure / (exposureTime * gain) };
@@ -239,7 +239,7 @@  ExposureModeHelper::splitExposure(utils::Duration exposure) const
 	 * stages to use then the default stageGain of 1.0 is used so that
 	 * exposure time is maxed before gain is touched at all.
 	 */
-	exposureTime = clampExposureTime(exposure / clampGain(stageGain));
+	exposureTime = clampExposureTime(exposure / stageGain);
 	gain = clampGain(exposure / exposureTime);
 
 	return { exposureTime, gain, exposure / (exposureTime * gain) };