From patchwork Mon Jan 5 12:41:35 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vasiliy Doylov X-Patchwork-Id: 25624 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 0BA68BDCBF for ; Mon, 5 Jan 2026 12:41:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id D94FA61FBF; Mon, 5 Jan 2026 13:41:37 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=mainlining.org header.i=@mainlining.org header.b="gxdN1j6R"; dkim=permerror (0-bit key) header.d=mainlining.org header.i=@mainlining.org header.b="LJG+v2d+"; dkim-atps=neutral Received: from mail.mainlining.org (mail.mainlining.org [5.75.144.95]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 437EA61F35 for ; Mon, 5 Jan 2026 13:41:36 +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=1767616895; bh=YHjvv4w3CRFhovlni3IRLXD OklS5XYPkV8hcn+7u9ug=; b=gxdN1j6RRdj0pLpP1PlH+47V6VIfXuuKD+O8xt5YFWkchsC/uA b7NAnWWYCZK9mVJ057VO1u9SpBnqGCLdBrX5VzDDH/AFPDYOWT9KohqmWAlYEDQRQOCADLtYIKZ 6YuRySTvCm3o3xBan7RXpylsi36JFGfxs2SSiCBnhxk0Bv9I2LxNuAt7O4L3oWAahIoTGdNziou krK0TuTWaAThSIMDAk10recOP+Q34QcLJ1fILAjYiVKbV3D9gY0a0JcDzo6up3XgONsEuEaWMtc nY+aTyEUSeUuuqRaWNZtrgoRvpDlwasiDFefenuN84ywCIQ1PJQjmDrpeSISykOMFJA==; DKIM-Signature: v=1; a=ed25519-sha256; s=202507e; d=mainlining.org; c=relaxed/relaxed; h=To:Message-Id:Subject:Date:From; t=1767616895; bh=YHjvv4w3CRFhovlni3IRLXD OklS5XYPkV8hcn+7u9ug=; b=LJG+v2d+0s2/1ibRPtx6GJCtCNwTn5C4a6tQEu3S4QHau/Q4cs u/gfhKNjvp4b3oNn/HUdVjISTtQsMPyYT7Bw==; From: Vasiliy Doylov Date: Mon, 05 Jan 2026 15:41:35 +0300 Subject: [PATCH v2] ipa: simple: fix minimal analog gain init MIME-Version: 1.0 Message-Id: <20260105-softisp-agc-v2-1-9013e693ffd5@mainlining.org> X-B4-Tracking: v=1; b=H4sIAH6xW2kC/23MQQ7CIBCF4as0s3YMUKHqynuYLhAonUShgYZoG u4udu3yf8n7Nsgukctw7TZIrlCmGFqIQwdm1sE7JNsaBBOKcSYxx2mlvKD2BrmyjJtHb/XpAu2 xJDfRe9fuY+uZ8hrTZ8cL/63/ncKR4zAooSSTZ9nr20tTeFKg4I8xeRhrrV8dsD6DqwAAAA== 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=2204; i=nekocwd@mainlining.org; h=from:subject:message-id; bh=s8L2NzmuwKOGjyJ/vr3euP0ERdEOlXZdojkxgKWJNDA=; b=owGbwMvMwCXGd//xporA/cmMp9WSGDKjN9YH6K7/r/DDO/LT59jOiApelutOXg95A/5on8+p4 fzJXXeho5SFQYyLQVZMkeW/4SK5AzeUPetyU5/BzGFlAhnCwMUpABPJC2T4H11vuVZt28yXzLYT yoJ39hiI5p/TeK/Cp+R4NN/SKHLxSYb//g4SSzXUJtQHJKt+PXtA4nnGsfmJrVpzNi3uTbjds/4 zDwA= 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 default 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 max sensor gain. Signed-off-by: Vasiliy Doylov --- 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; }