[v4,38/49] ipa: simple: agc: Simplify min gain step handling
diff mbox series

Message ID 20260810103846.1075936-39-barnabas.pocze@ideasonboard.com
State New
Headers show
Series
  • ipa: libipa: agc rework
Related show

Commit Message

Barnabás Pőcze Aug. 10, 2026, 10:38 a.m. UTC
Use `std::{min,max}()` just like it is done for the exposure.

Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>
---
 src/ipa/simple/algorithms/agc.cpp | 10 ++--------
 1 file changed, 2 insertions(+), 8 deletions(-)

Comments

Jacopo Mondi Aug. 10, 2026, 1:45 p.m. UTC | #1
Hi Barnabás

On Mon, Aug 10, 2026 at 12:38:34PM +0200, Barnabás Pőcze wrote:
> Use `std::{min,max}()` just like it is done for the exposure.
>
> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>

I've not really put effort in validating the logic, but this matches
what's done for exposure

Acked-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>

> ---
>  src/ipa/simple/algorithms/agc.cpp | 10 ++--------
>  1 file changed, 2 insertions(+), 8 deletions(-)
>
> diff --git a/src/ipa/simple/algorithms/agc.cpp b/src/ipa/simple/algorithms/agc.cpp
> index f959abeba5..5307fda953 100644
> --- a/src/ipa/simple/algorithms/agc.cpp
> +++ b/src/ipa/simple/algorithms/agc.cpp
> @@ -130,19 +130,13 @@ void Agc::updateExposure(IPAContext &context, IPAFrameContext &frameContext, dou
>  			exposure = std::max(next, exposure + 1);
>  		} else {
>  			double next = again * factor;
> -			if (next - again < context.configuration.agc.againMinStep)
> -				again += context.configuration.agc.againMinStep;
> -			else
> -				again = next;
> +			again = std::max(next, again + context.configuration.agc.againMinStep);
>  		}
>  	} else {
>  		/* Scene too bright: decrease gain first, then exposure. */
>  		if (again > context.configuration.agc.again10) {
>  			double next = again * factor;
> -			if (again - next < context.configuration.agc.againMinStep)
> -				again -= context.configuration.agc.againMinStep;
> -			else
> -				again = next;
> +			again = std::min(next, again - context.configuration.agc.againMinStep);
>  		} else {
>  			uint32_t next = exposure * factor;
>  			exposure = std::min(next, exposure - 1);
> --
> 2.55.0
>
Milan Zamazal Aug. 10, 2026, 3:05 p.m. UTC | #2
Barnabás Pőcze <barnabas.pocze@ideasonboard.com> writes:

> Use `std::{min,max}()` just like it is done for the exposure.
>
> Signed-off-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>

Reviewed-by: Milan Zamazal <mzamazal@redhat.com>

> ---
>  src/ipa/simple/algorithms/agc.cpp | 10 ++--------
>  1 file changed, 2 insertions(+), 8 deletions(-)
>
> diff --git a/src/ipa/simple/algorithms/agc.cpp b/src/ipa/simple/algorithms/agc.cpp
> index f959abeba5..5307fda953 100644
> --- a/src/ipa/simple/algorithms/agc.cpp
> +++ b/src/ipa/simple/algorithms/agc.cpp
> @@ -130,19 +130,13 @@ void Agc::updateExposure(IPAContext &context, IPAFrameContext &frameContext, dou
>  			exposure = std::max(next, exposure + 1);
>  		} else {
>  			double next = again * factor;
> -			if (next - again < context.configuration.agc.againMinStep)
> -				again += context.configuration.agc.againMinStep;
> -			else
> -				again = next;
> +			again = std::max(next, again + context.configuration.agc.againMinStep);
>  		}
>  	} else {
>  		/* Scene too bright: decrease gain first, then exposure. */
>  		if (again > context.configuration.agc.again10) {
>  			double next = again * factor;
> -			if (again - next < context.configuration.agc.againMinStep)
> -				again -= context.configuration.agc.againMinStep;
> -			else
> -				again = next;
> +			again = std::min(next, again - context.configuration.agc.againMinStep);
>  		} else {
>  			uint32_t next = exposure * factor;
>  			exposure = std::min(next, exposure - 1);

Patch
diff mbox series

diff --git a/src/ipa/simple/algorithms/agc.cpp b/src/ipa/simple/algorithms/agc.cpp
index f959abeba5..5307fda953 100644
--- a/src/ipa/simple/algorithms/agc.cpp
+++ b/src/ipa/simple/algorithms/agc.cpp
@@ -130,19 +130,13 @@  void Agc::updateExposure(IPAContext &context, IPAFrameContext &frameContext, dou
 			exposure = std::max(next, exposure + 1);
 		} else {
 			double next = again * factor;
-			if (next - again < context.configuration.agc.againMinStep)
-				again += context.configuration.agc.againMinStep;
-			else
-				again = next;
+			again = std::max(next, again + context.configuration.agc.againMinStep);
 		}
 	} else {
 		/* Scene too bright: decrease gain first, then exposure. */
 		if (again > context.configuration.agc.again10) {
 			double next = again * factor;
-			if (again - next < context.configuration.agc.againMinStep)
-				again -= context.configuration.agc.againMinStep;
-			else
-				again = next;
+			again = std::min(next, again - context.configuration.agc.againMinStep);
 		} else {
 			uint32_t next = exposure * factor;
 			exposure = std::min(next, exposure - 1);