Patch Detail
Show a patch.
GET /api/patches/26662/?format=api
{ "id": 26662, "url": "https://patchwork.libcamera.org/api/patches/26662/?format=api", "web_url": "https://patchwork.libcamera.org/patch/26662/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/projects/1/?format=api", "name": "libcamera", "link_name": "libcamera", "list_id": "libcamera_core", "list_email": "libcamera-devel@lists.libcamera.org", "web_url": "", "scm_url": "", "webscm_url": "" }, "msgid": "<20260506230722.1041596-6-devve.3@gmail.com>", "date": "2026-05-06T23:07:17", "name": "[v2,05/10] ipa: simple: agc: Replace bang-bang controller with proportional", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "8e09025b9bdfc16583bc382925ac04380776d389", "submitter": { "id": 271, "url": "https://patchwork.libcamera.org/api/people/271/?format=api", "name": "devve", "email": "devve.3@gmail.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/26662/mbox/", "series": [ { "id": 5915, "url": "https://patchwork.libcamera.org/api/series/5915/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5915", "date": "2026-05-06T23:07:12", "name": "OV01A10 sensor support and simple IPA improvements", "version": 2, "mbox": "https://patchwork.libcamera.org/series/5915/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/26662/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/26662/checks/", "tags": {}, "headers": { "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": "parsemail@patchwork.libcamera.org", "Received": [ "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id BEC95C3302\n\tfor <parsemail@patchwork.libcamera.org>;\n\tWed, 6 May 2026 23:07:36 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 0DC83630A2;\n\tThu, 7 May 2026 01:07:35 +0200 (CEST)", "from mail-qk1-x732.google.com (mail-qk1-x732.google.com\n\t[IPv6:2607:f8b0:4864:20::732])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 81AA663024\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 7 May 2026 01:07:32 +0200 (CEST)", "by mail-qk1-x732.google.com with SMTP id\n\taf79cd13be357-8cb5c9ba82bso35301085a.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tWed, 06 May 2026 16:07:32 -0700 (PDT)", "from dexps.speedport.ip\n\t(p200300eda74453cf3cf3f7929e513b94.dip0.t-ipconnect.de.\n\t[2003:ed:a744:53cf:3cf3:f792:9e51:3b94])\n\tby smtp.gmail.com with ESMTPSA id\n\taf79cd13be357-8fc2c25324esm2035266385a.23.2026.05.06.16.07.30\n\tfor <libcamera-devel@lists.libcamera.org>\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tWed, 06 May 2026 16:07:31 -0700 (PDT)" ], "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=gmail.com header.i=@gmail.com\n\theader.b=\"Bss7U651\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=gmail.com; s=20251104; t=1778108851; x=1778713651;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:to:from:from:to:cc:subject:date:message-id\n\t:reply-to; bh=dZKZKTCGEv+ghBeM3aBja4SAmlWxPm+UsMadpqZ8y88=;\n\tb=Bss7U651ES8BR2TAsK9IFD3L63Hi+kNbOknapBlmcSRxojqI0nVpgjuGxYMUckclI/\n\tk8+7zH2Y6nUiBORJQclnoey7zcYBs2ky0a9ygfhPuCIVXBsxORPya0q6JZqg3/4+M9mj\n\twjAUm+PxtzsOGaJusAuDLylLxD5k4Tu9qKicuu5MYd+Mk7ofaOKCgc8pXgpQ7qc2nBhm\n\tL4KVrnTGEP7QDqq/aZJjfbc5xY1FFXeq0POxk6cR6Df6Dq01i7XiwVmi8rVZtQ5KakIy\n\tACptZd4TnzpOgr5/h016f8k3ONUHBTGvCtWhIFfMNilXe7HK4V9oDH2slVIQuOosx/0+\n\t5DyA==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20251104; t=1778108851; x=1778713651;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:to:from:x-gm-gg:x-gm-message-state:from:to\n\t:cc:subject:date:message-id:reply-to;\n\tbh=dZKZKTCGEv+ghBeM3aBja4SAmlWxPm+UsMadpqZ8y88=;\n\tb=HhxVHqzDpGJgqzwq5RsRvMZCx8Khcvfl0E3HjJNpLId4JD0qLwHQ7TNQe4KNZi5cy0\n\t4R5h22LgQkrS6DFV731+zlFVzdbVH6or3DybakKA+R4eQ9U+ONbtq8JZn5KrdxqtGPBu\n\thh2IKinDh6OhVT2GG7rgCgZaFauy+ns0uzw6eWMhg7OCQGpP6Z6qjezSgBnoCqJvPU48\n\tGSVD7C2WTb4gz0VA4mZTkIFJcNAGB382TqEGOkHHdwbbmMwSnGha3zUCAP0VmKv6PFIC\n\txjb4EfzXxtt/BaDF37lAR0SD/R/9XKnEu8rU3KIJ/s+B1E7dg+oJzKzFTbtF+uRb4CZb\n\tFBbw==", "X-Gm-Message-State": "AOJu0YwyoOBy8gLRVYDR3vuzSGg1zFHzPftypWNlncunNpbNxWqFA048\n\tiJxzjpYhjhKEFMVyq96cc41+kP3yGn1Av4WVNgB0iIUZz/f8txH8+42HTQdM/w==", "X-Gm-Gg": "AeBDietTPOvH2i0b8MMGIqp2NDH+Uxpnzh3VMr8VOZ4cuP0t4b+pHrVrApvE05vC5Gb\n\tDbxXfCtWFi+biayHkMkXYaSKPbTQ9jhJQRaWJRVQApd3UdRc3tk25pbTXVc/YtsHXU0ophdQ77m\n\tCsIc1CEBYgCoABi2/quU7Mk0MXV4k2YB7MWglLDkKvT2ppA6JYVIpodFnEswcc4UdPyqSTNfBy2\n\t/EYb3gUnvhNAMpGaebL6Ej0R9o+zDECzueD7CXfVzV16tZ+JlnD/TJO3NKxcFOpTzu++bIcoFN+\n\tUmiPhc50MjnVrOXxwjaoMGxxbPCFjhpOQqdT9LvJtRIGGLn2XVPWUXEtRkdNlv+6FNYzyCniIgp\n\tyu1t8BW2loZziF7E0hRZrsXqz9qee01syM9SYvxBuqHifhF53KDUSmAxwChpn3OsBJEdAJi0TUy\n\tUg6Thx6cNH6fCPMy1AboBkY8+1c6LgTxcyS8EoXwm8c2RTugwYCyFOu4HBqCroMgmRSIlJIznMR\n\trSR/h309T9ovCW7O3jdudOU/M4fkFaJ", "X-Received": "by 2002:a05:620a:4451:b0:8fb:e57e:9e0b with SMTP id\n\taf79cd13be357-904d69d8df5mr819540385a.46.1778108851410; \n\tWed, 06 May 2026 16:07:31 -0700 (PDT)", "From": "d3vv3 <devve.3@gmail.com>", "To": "libcamera-devel@lists.libcamera.org", "Subject": "[PATCH v2 05/10] ipa: simple: agc: Replace bang-bang controller with\n\tproportional", "Date": "Thu, 7 May 2026 01:07:17 +0200", "Message-ID": "<20260506230722.1041596-6-devve.3@gmail.com>", "X-Mailer": "git-send-email 2.54.0", "In-Reply-To": "<20260506230722.1041596-1-devve.3@gmail.com>", "References": "<20260506230722.1041596-1-devve.3@gmail.com>", "MIME-Version": "1.0", "Content-Type": "text/plain; charset=UTF-8", "Content-Transfer-Encoding": "8bit", "X-BeenThere": "libcamera-devel@lists.libcamera.org", "X-Mailman-Version": "2.1.29", "Precedence": "list", "List-Id": "<libcamera-devel.lists.libcamera.org>", "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>", "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>", "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>", "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>", "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>", "Errors-To": "libcamera-devel-bounces@lists.libcamera.org", "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>" }, "content": "From: Javier Tia <floss@jetm.me>\n\nThe AGC's updateExposure() uses a fixed ~10% step per frame regardless\nof how far the current exposure is from optimal. With a hysteresis dead\nband of only +/-4%, the controller overshoots when the correct value\nfalls within one step, causing visible brightness oscillation (flicker).\n\nReplace the fixed-step bang-bang controller with a proportional one\nwhere the correction factor scales linearly with the MSV error:\n\n factor = 1.0 + error * 0.04\n\nAt maximum error (~2.5), this gives the same ~10% step as before. Near\nthe target, steps shrink to <1%, eliminating overshoot. The existing\nhysteresis (kExposureSatisfactory) still prevents hunting on noise.\n\nTested on OV2740 behind Intel IPU6 ISYS (ThinkPad X1 Carbon Gen 10)\nwhere the old controller produced continuous brightness flicker. The\nproportional controller converges in ~3 seconds from cold start with\nno visible oscillation.\n\nSigned-off-by: Javier Tia <floss@jetm.me>\nReviewed-by: Milan Zamazal <mzamazal@redhat.com>\nTested-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\nSigned-off-by: d3vv3 <devve.3@gmail.com>\n---\n src/ipa/simple/algorithms/agc.cpp | 65 +++++++++++++++++++------------\n 1 file changed, 41 insertions(+), 24 deletions(-)", "diff": "diff --git a/src/ipa/simple/algorithms/agc.cpp b/src/ipa/simple/algorithms/agc.cpp\nindex 2f7e040c..ac977d5f 100644\n--- a/src/ipa/simple/algorithms/agc.cpp\n+++ b/src/ipa/simple/algorithms/agc.cpp\n@@ -7,6 +7,8 @@\n \n #include \"agc.h\"\n \n+#include <algorithm>\n+#include <cmath>\n #include <stdint.h>\n \n #include <libcamera/base/log.h>\n@@ -37,52 +39,66 @@ static constexpr float kExposureOptimal = kExposureBinsCount / 2.0;\n */\n static constexpr float kExposureSatisfactory = 0.2;\n \n+/*\n+ * Proportional gain for exposure/gain adjustment. Maps the MSV error to a\n+ * multiplicative correction factor:\n+ *\n+ * factor = 1.0 + kExpProportionalGain * error\n+ *\n+ * With kExpProportionalGain = 0.04:\n+ * - max error ~2.5 -> factor 1.10 (~10% step, same as before)\n+ * - error 1.0 -> factor 1.04 (~4% step)\n+ * - error 0.3 -> factor 1.012 (~1.2% step)\n+ *\n+ * This replaces the fixed 10% bang-bang step with a proportional correction\n+ * that converges smoothly and avoids overshooting near the target.\n+ */\n+static constexpr float kExpProportionalGain = 0.04;\n+\n Agc::Agc()\n {\n }\n \n void Agc::updateExposure(IPAContext &context, IPAFrameContext &frameContext, double exposureMSV)\n {\n-\t/*\n-\t * kExpDenominator of 10 gives ~10% increment/decrement;\n-\t * kExpDenominator of 5 - about ~20%\n-\t */\n-\tstatic constexpr uint8_t kExpDenominator = 10;\n-\tstatic constexpr uint8_t kExpNumeratorUp = kExpDenominator + 1;\n-\tstatic constexpr uint8_t kExpNumeratorDown = kExpDenominator - 1;\n-\n \tint32_t &exposure = frameContext.sensor.exposure;\n \tdouble &again = frameContext.sensor.gain;\n \n-\tif (exposureMSV < kExposureOptimal - kExposureSatisfactory) {\n+\tdouble error = kExposureOptimal - exposureMSV;\n+\n+\tif (std::abs(error) <= kExposureSatisfactory)\n+\t\treturn;\n+\n+\t/*\n+\t * Compute a proportional correction factor. The sign of the error\n+\t * determines the direction: positive error means too dark (increase),\n+\t * negative means too bright (decrease).\n+\t */\n+\tfloat factor = 1.0f + static_cast<float>(error) * kExpProportionalGain;\n+\n+\tif (factor > 1.0f) {\n+\t\t/* Scene too dark: increase exposure first, then gain. */\n \t\tif (exposure < context.configuration.agc.exposureMax) {\n-\t\t\tint32_t next = exposure * kExpNumeratorUp / kExpDenominator;\n-\t\t\tif (next - exposure < 1)\n-\t\t\t\texposure += 1;\n-\t\t\telse\n-\t\t\t\texposure = next;\n+\t\t\tint32_t next = static_cast<int32_t>(exposure * factor);\n+\t\t\texposure = std::max(next, exposure + 1);\n \t\t} else {\n-\t\t\tdouble next = again * kExpNumeratorUp / kExpDenominator;\n+\t\t\tdouble next = again * factor;\n \t\t\tif (next - again < context.configuration.agc.againMinStep)\n \t\t\t\tagain += context.configuration.agc.againMinStep;\n \t\t\telse\n \t\t\t\tagain = next;\n \t\t}\n-\t}\n-\n-\tif (exposureMSV > kExposureOptimal + kExposureSatisfactory) {\n+\t} else {\n+\t\t/* Scene too bright: decrease gain first, then exposure. */\n \t\tif (again > context.configuration.agc.again10) {\n-\t\t\tdouble next = again * kExpNumeratorDown / kExpDenominator;\n+\t\t\tdouble next = again * factor;\n \t\t\tif (again - next < context.configuration.agc.againMinStep)\n \t\t\t\tagain -= context.configuration.agc.againMinStep;\n \t\t\telse\n \t\t\t\tagain = next;\n \t\t} else {\n-\t\t\tint32_t next = exposure * kExpNumeratorDown / kExpDenominator;\n-\t\t\tif (exposure - next < 1)\n-\t\t\t\texposure -= 1;\n-\t\t\telse\n-\t\t\t\texposure = next;\n+\t\t\tint32_t next = static_cast<int32_t>(exposure * factor);\n+\t\t\texposure = std::min(next, exposure - 1);\n \t\t}\n \t}\n \n@@ -96,6 +112,7 @@ void Agc::updateExposure(IPAContext &context, IPAFrameContext &frameContext, dou\n \n \tLOG(IPASoftExposure, Debug)\n \t\t<< \"exposureMSV \" << exposureMSV\n+\t\t<< \" error \" << error << \" factor \" << factor\n \t\t<< \" exp \" << exposure << \" again \" << again;\n }\n \n", "prefixes": [ "v2", "05/10" ] }