From 98e5e561502bdff0da6e58fe265846906bf72816 Mon Sep 17 00:00:00 2001 From: Vasiliy Doylov Date: Mon, 5 Jan 2026 16:57:44 +0300 Subject: [PATCH] ipa: simple: fix minimal analog gain init On most imx sensors the formula seems to be: again_float = 512.0 / (512.0 - again_ctrl_value) So the minimum again of 0 makes sense and actually translates to a gain of 1.0. And the max gain of 400 leads to 512.0 / 112.0 = 4.57 which is about typical for a maximum again. Since a minimum again value of 0 is actually normal, the special handling of againMin == 0 is undesirable and this is actually causing problems on these IMX sensors. again10 correctly gets set to 0 which is less than the adjusted againMin which causes the AGC code to not work properly. Fix this by dropping the special handling of againMin == 0. Signed-off-by: Vasiliy Doylov Reviewed-by: Hans de Goede Reviewed-by: Milan Zamazal Signed-off-by: Kieran Bingham --- src/ipa/simple/soft_simple.cpp | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) diff --git a/src/ipa/simple/soft_simple.cpp b/src/ipa/simple/soft_simple.cpp index b147aca2..dde11666 100644 --- a/src/ipa/simple/soft_simple.cpp +++ b/src/ipa/simple/soft_simple.cpp @@ -237,26 +237,9 @@ int IPASoftSimple::configure(const IPAConfigInfo &configInfo) camHelper_->blackLevel().value() / 256; } } else { - /* - * The camera sensor gain (g) is usually not equal to the value written - * into the gain register (x). But the way how the AGC algorithm changes - * the gain value to make the total exposure closer to the optimum - * assumes that g(x) is not too far from linear function. If the minimal - * gain is 0, the g(x) is likely to be far from the linear, like - * g(x) = a / (b * x + c). To avoid unexpected changes to the gain by - * the AGC algorithm (abrupt near one edge, and very small near the - * other) we limit the range of the gain values used. - */ context_.configuration.agc.againMax = againMax; context_.configuration.agc.again10 = againDef; - if (againMin) { - context_.configuration.agc.againMin = againMin; - } else { - LOG(IPASoft, Warning) - << "Minimum gain is zero, that can't be linear"; - context_.configuration.agc.againMin = - std::min(100, againMin / 2 + againMax / 2); - } + context_.configuration.agc.againMin = againMin; context_.configuration.agc.againMinStep = 1.0; }