[RFC,v3,38/50] ipa: simple: agc: Simplify min gain step handling
diff mbox series

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

Commit Message

Barnabás Pőcze Aug. 3, 2026, 1:14 p.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

Milan Zamazal Aug. 4, 2026, 10:10 a.m. UTC | #1
Hi Barnabás,

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>
> ---
>  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..b25c303835 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::max(next, again - context.configuration.agc.againMinStep);

Should be std::min, right?

>  		} else {
>  			uint32_t next = exposure * factor;
>  			exposure = std::min(next, exposure - 1);
Barnabás Pőcze Aug. 4, 2026, 10:26 a.m. UTC | #2
Hi

2026. 08. 04. 12:10 keltezéssel, Milan Zamazal írta:
> Hi Barnabás,
> 
> 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>
>> ---
>>   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..b25c303835 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::max(next, again - context.configuration.agc.againMinStep);
> 
> Should be std::min, right?

I could've sworn I had already fixed exactly this error... And as I turns out I did,
only it was in "ipa: simple: agc: Move to libipa". Thanks, now it's fixed here as well.


> 
>>   		} 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..b25c303835 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::max(next, again - context.configuration.agc.againMinStep);
 		} else {
 			uint32_t next = exposure * factor;
 			exposure = std::min(next, exposure - 1);