From patchwork Mon Jan 5 13:57:44 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasiliy Doylov X-Patchwork-Id: 25625 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 80EF1BDCBF for ; Mon, 5 Jan 2026 13:57:50 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 7AE5661F9F; Mon, 5 Jan 2026 14:57:49 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=mainlining.org header.i=@mainlining.org header.b="Z4BfCbKt"; dkim=permerror (0-bit key) header.d=mainlining.org header.i=@mainlining.org header.b="cROYHTk8"; dkim-atps=neutral Received: from mail.mainlining.org (mail.mainlining.org [5.75.144.95]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9B55761F35 for ; Mon, 5 Jan 2026 14:57:47 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; s=202507r; d=mainlining.org; c=relaxed/relaxed; h=To:Message-Id:Subject:Date:From; t=1767621466; bh=P6aC8/wJfDc3eZbabp7oMGX hXk1z3n/2GtV14rcaiuo=; b=Z4BfCbKt/tPOdMmv1UiVDes8qhS4oFJI/bC+HgexWKedSOTaer 0yhyvw45wh3IbLEZ3UZ8YWSNG00qvPGtyrjT+HpOeF+O45NNmZ0kfIFDBOJWlk00I8NWzg+mKVR kCJ4pwphT8qaqSfnun26A7FPZT9T1V0g/qXWnhgrv2yw3LGES6nRstFZyxKTYbJElh1pPtMtcfE dz77z00GZ+f5wrO6dL8Whx/BYfruVQ6cAalnZxIWTN9XBhtQfYJZQM9Ix9KKf7PFTyWbLScK9Zi ACePFwZiJjsGLs0K5lrWrvDAOkrUuMDfjXenPtnpR/hjl+ocyyEuXDw7PlzZvbP3cug==; DKIM-Signature: v=1; a=ed25519-sha256; s=202507e; d=mainlining.org; c=relaxed/relaxed; h=To:Message-Id:Subject:Date:From; t=1767621466; bh=P6aC8/wJfDc3eZbabp7oMGX hXk1z3n/2GtV14rcaiuo=; b=cROYHTk83khw3tq98snCwVNxguihUEmDUXE05qZopDKVbDwU+H cOnO5Lz+icW5fNZKds3eBmy9KLlG9dCnuhBA==; From: Vasiliy Doylov Date: Mon, 05 Jan 2026 16:57:44 +0300 Subject: [PATCH v3] ipa: simple: fix minimal analog gain init MIME-Version: 1.0 Message-Id: <20260105-softisp-agc-v3-1-434f2053c549@mainlining.org> X-B4-Tracking: v=1; b=H4sIAFfDW2kC/33MSwrCMBSF4a2UOzaSh0ltR+5DHMTm0QualKQEp XTvpp0qDv8D51sg24Q2Q98skGzBjDHUEIcGhlEHbwma2sApV5RRSXJ0M+aJaD8Qpgxlw10Yfeq gPqZkHb527XqrPWKeY3rveGHb+tspjDDStoorSeVZCn15agwPDBj8MSYPG1b4H4BXoKNMWNUJ5 4z8AtZ1/QDK3NxC7AAAAA== X-Change-ID: 20260105-softisp-agc-16d01cb3da49 To: libcamera-devel@lists.libcamera.org Cc: Vasiliy Doylov X-Mailer: b4 0.14.3 X-Developer-Signature: v=1; a=openpgp-sha256; l=2700; i=nekocwd@mainlining.org; h=from:subject:message-id; bh=s0qQ1gzIuIiwsI8h3KTDHwEJsYF25Y1Uk//f/fs9mRU=; b=owGbwMvMwCXGd//xporA/cmMp9WSGDKjD0fN0L1+5Xu6nqUXc77tn6mLNZW7N6nmxvpYVulF9 xtejS3sKGVhEONikBVTZPlvuEjuwA1lz7rc1Gcwc1iZQIYwcHEKwESyvzD8L8hP6do+p/7p2t18 S48W8MUteXawnNfi/U/9NTmlXhrfMxn+R0/8MMmihz1Oit9JrUNx7dv/Nd9vJZ41iXVZ4rX8qud SdgA= X-Developer-Key: i=nekocwd@mainlining.org; a=openpgp; fpr=FF31A21EC0D823497E6D65E60EDFE3B27851BF63 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" 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 then 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 --- Changes in v3: - Expanded commit message - Link to v2: https://lists.libcamera.org/pipermail/libcamera-devel/2026-January/056068.html Changes in v2: - Drop old solution - Fix minimal analog gain initialisation - Link to v1: https://lists.libcamera.org/pipermail/libcamera-devel/2026-January/056045.html --- src/ipa/simple/soft_simple.cpp | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) --- base-commit: 2861817f09c96a0660b88783eff159631e42030f change-id: 20260105-softisp-agc-16d01cb3da49 Best regards, 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; }