{"id":26595,"url":"https://patchwork.libcamera.org/api/patches/26595/?format=json","web_url":"https://patchwork.libcamera.org/patch/26595/","project":{"id":1,"url":"https://patchwork.libcamera.org/api/projects/1/?format=json","name":"libcamera","link_name":"libcamera","list_id":"libcamera_core","list_email":"libcamera-devel@lists.libcamera.org","web_url":"","scm_url":"","webscm_url":""},"msgid":"<20260501191400.985920-4-devve.3@gmail.com>","date":"2026-05-01T19:13:12","name":"ipa: simple: agc: Read exposure target and gain from YAML","commit_ref":null,"pull_url":null,"state":"new","archived":false,"hash":"f36406881a44b7ff9b571f3833512455d8eac4f1","submitter":{"id":271,"url":"https://patchwork.libcamera.org/api/people/271/?format=json","name":"devve","email":"devve.3@gmail.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/26595/mbox/","series":[{"id":5896,"url":"https://patchwork.libcamera.org/api/series/5896/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5896","date":"2026-05-01T19:13:12","name":"ipa: simple: agc: Read exposure target and gain from YAML","version":1,"mbox":"https://patchwork.libcamera.org/series/5896/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/26595/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/26595/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 47B7AC32F7\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri,  1 May 2026 19:55:31 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 7B8BC63020;\n\tFri,  1 May 2026 21:55:28 +0200 (CEST)","from mail-wm1-x332.google.com (mail-wm1-x332.google.com\n\t[IPv6:2a00:1450:4864:20::332])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id E5A106301A\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri,  1 May 2026 21:14:24 +0200 (CEST)","by mail-wm1-x332.google.com with SMTP id\n\t5b1f17b1804b1-488ab2db91aso25729605e9.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 01 May 2026 12:14:24 -0700 (PDT)","from dexps.speedport.ip\n\t(p200300eda74453f7a35e44f7d2f0427a.dip0.t-ipconnect.de.\n\t[2003:ed:a744:53f7:a35e:44f7:d2f0:427a])\n\tby smtp.gmail.com with ESMTPSA id\n\t5b1f17b1804b1-48a8eb69698sm139146305e9.1.2026.05.01.12.14.23\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 01 May 2026 12:14:24 -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=\"nOS10SpO\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=gmail.com; s=20251104; t=1777662864; x=1778267664;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=Np2KpHav7jquUv7l8lhExD9bUwRg7NkVkFY4AMLAGpQ=;\n\tb=nOS10SpO4bJao0IGdtIucVXodVS7Jla+wbAWjZjo+JEdJkdTaAlcKdL2OE3HFZlrpX\n\ttu5C/yLj34jKmuias+w2v9rGRmJdf7C2WYFEKaBWjHzDFsLB7hwwEV6/ycsHw3VdhMKp\n\t17NJbnwqrdGL7Waxss1sfwMJ9Fe/+oDnXETBiGQB+7GF/F4yrSu6rltPbwUEJjranrkT\n\tVjq9YHauVOmStgW+PCaCb+xpHZ/gLJZUePrcSv93NgOkD9CDRV7G3n/vPFtBNIJ56rj1\n\t0PIMTegRcq+x5StGj2bso/mGDCuyY4K26XHbjgALLK80mBCjKQT296yfIY5U949xnY4O\n\tLx6Q==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20251104; t=1777662864; x=1778267664;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from\n\t:to:cc:subject:date:message-id:reply-to;\n\tbh=Np2KpHav7jquUv7l8lhExD9bUwRg7NkVkFY4AMLAGpQ=;\n\tb=I9ljDs92ULszzROXmAnzhfu/BIfGxuUyTcq+j2RJu3UTfTt7x1K5fvpn3bfApxLzrT\n\tQ1nb/mrsE4vTHJKs+VLwUht4TvYoUmSMnRLmssXQQIxp5aEgEj8nNWjuQ4pLcQ3+/6Nq\n\tPTUQej+l0UawVzRjmd29DY90fLgckokF3ehIY4zOorPLSdv0FuFLRswKRDRC25J9XHQa\n\tygrnZ8vcxnZNdONXY4yxZOMUOz+QROUx7ewydHqVc6vJbeHU/+UxhvywFM2e8q12szba\n\tS4tsyQN0F/Aa8qCjlVb3Fp5CwQdI9JU0B0RHXzHthpdDLc2GstlSCoPdFlMiY0RyD9ZW\n\t80vg==","X-Gm-Message-State":"AOJu0YxgQNJVp082QP4JblJFAVw8e/fqTJtZ8Q4pHb3S372Z3ehR36Ho\n\tUltY9sgU8hkDuu/YnrRnqJ2eWC+hIMRFKgD7GqPEP1zDGdIOSGuNhsSfSHVV5Q==","X-Gm-Gg":"AeBDiesf/Jy+e4pYIjwxzeAXGMrpbJ2WCWVul/wqHph374pDIyhvjUHJUjQJGMcyzCE\n\tnPSUkAUC4Yfay/kmUULWxDappyEXnR9R/jtgGjD7inorBcE+2Td2hhWL1/ILQLLzFDkUnlbN2v6\n\tSIBh5fr27zCOXGC1IqQ+wRHpXeKBXX23TN6oymAE2jsdiXcGKSn+Roj7fVj0G87wCJFYezgfX3V\n\teiCKkRsYfc93/mKOAVhBff+05nujM2cmS8QDVl9/+SeGNx/XzURxOEtyU5S9H/N4b9OU8E2DvbF\n\tfMZDkVrz2IXB2zDp3MYmNtmXNBBoXRxDwxHlxSZo09Zn/SOP4959B5NytmkLsyBcYiwcA3PRM3D\n\triY/RaplODtJxiNhme6MiCuUWZQus3WDoOiN/9P4JPpqromV0tnzG1gtUFqPP1vuvDz4to6tiPa\n\tYfNqIN9hKZd2c6sHKY+p6ZvbrLWzq23coLi0OeWZ1eiUuD1S2+/YBTQKoUZSsRKFX1WjYh0rNYe\n\tyopzoax+cUZ+VDV+Z72z7NUhqLrgqd5gY3OT8rI928=","X-Received":"by 2002:a05:600c:a402:b0:486:fba7:b150 with SMTP id\n\t5b1f17b1804b1-48a9865f7c3mr4466595e9.15.1777662864353; \n\tFri, 01 May 2026 12:14:24 -0700 (PDT)","From":"d3vv3 <devve.3@gmail.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"d3vv3 <devve.3@gmail.com>","Subject":"[PATCH] ipa: simple: agc: Read exposure target and gain from YAML","Date":"Fri,  1 May 2026 21:13:12 +0200","Message-ID":"<20260501191400.985920-4-devve.3@gmail.com>","X-Mailer":"git-send-email 2.54.0","In-Reply-To":"<20260501191400.985920-1-devve.3@gmail.com>","References":"<20260501191400.985920-1-devve.3@gmail.com>","MIME-Version":"1.0","Content-Transfer-Encoding":"8bit","X-Mailman-Approved-At":"Fri, 01 May 2026 21:55:24 +0200","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":"Replace the hardcoded kExposureOptimal, kExposureSatisfactory, and\nkExpProportionalGain constants with member variables read from the\ntuning file as exposureTarget, hysteresis, and proportionalGain.\nDefaults match the previous values (2.5, 0.2, 0.04).\n\nSigned-off-by: d3vv3 <devve.3@gmail.com>\n---\n src/ipa/simple/algorithms/agc.cpp | 33 ++++++++++++++++++++-----------\n src/ipa/simple/algorithms/agc.h   |  8 ++++++++\n 2 files changed, 30 insertions(+), 11 deletions(-)","diff":"diff --git a/src/ipa/simple/algorithms/agc.cpp b/src/ipa/simple/algorithms/agc.cpp\nindex ac977d5f..66618d0f 100644\n--- a/src/ipa/simple/algorithms/agc.cpp\n+++ b/src/ipa/simple/algorithms/agc.cpp\n@@ -28,45 +28,56 @@ static constexpr unsigned int kExposureBinsCount = 5;\n \n /*\n  * The exposure is optimal when the mean sample value of the histogram is\n- * in the middle of the range.\n+ * in the middle of the range. Overridable via YAML exposureTarget.\n  */\n-static constexpr float kExposureOptimal = kExposureBinsCount / 2.0;\n+static constexpr float kExposureTargetDefault = kExposureBinsCount / 2.0;\n \n /*\n  * This implements the hysteresis for the exposure adjustment.\n  * It is small enough to have the exposure close to the optimal, and is big\n  * enough to prevent the exposure from wobbling around the optimal value.\n  */\n-static constexpr float kExposureSatisfactory = 0.2;\n+static constexpr float kHysteresisDefault = 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+ *   factor = 1.0 + proportionalGain_ * error\n  *\n- * With kExpProportionalGain = 0.04:\n+ * With proportionalGain_ = 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+ * Overridable via YAML proportionalGain.\n  */\n-static constexpr float kExpProportionalGain = 0.04;\n+static constexpr float kProportionalGainDefault = 0.04;\n \n Agc::Agc()\n {\n }\n \n+int Agc::init([[maybe_unused]] IPAContext &context, const ValueNode &tuningData)\n+{\n+\texposureTarget_ = tuningData[\"exposureTarget\"].get<float>()\n+\t\t.value_or(kExposureTargetDefault);\n+\thysteresis_ = tuningData[\"hysteresis\"].get<float>()\n+\t\t.value_or(kHysteresisDefault);\n+\tproportionalGain_ = tuningData[\"proportionalGain\"].get<float>()\n+\t\t.value_or(kProportionalGainDefault);\n+\n+\treturn 0;\n+}\n+\n void Agc::updateExposure(IPAContext &context, IPAFrameContext &frameContext, double exposureMSV)\n {\n \tint32_t &exposure = frameContext.sensor.exposure;\n \tdouble &again = frameContext.sensor.gain;\n \n-\tdouble error = kExposureOptimal - exposureMSV;\n+\tdouble error = exposureTarget_ - exposureMSV;\n \n-\tif (std::abs(error) <= kExposureSatisfactory)\n+\tif (std::abs(error) <= hysteresis_)\n \t\treturn;\n \n \t/*\n@@ -74,7 +85,7 @@ void Agc::updateExposure(IPAContext &context, IPAFrameContext &frameContext, dou\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+\tfloat factor = 1.0f + static_cast<float>(error) * proportionalGain_;\n \n \tif (factor > 1.0f) {\n \t\t/* Scene too dark: increase exposure first, then gain. */\ndiff --git a/src/ipa/simple/algorithms/agc.h b/src/ipa/simple/algorithms/agc.h\nindex 112d9f5a..b8ed542b 100644\n--- a/src/ipa/simple/algorithms/agc.h\n+++ b/src/ipa/simple/algorithms/agc.h\n@@ -7,6 +7,8 @@\n \n #pragma once\n \n+#include <libcamera/internal/yaml_parser.h>\n+\n #include \"algorithm.h\"\n \n namespace libcamera {\n@@ -19,6 +21,8 @@ public:\n \tAgc();\n \t~Agc() = default;\n \n+\tint init(IPAContext &context, const ValueNode &tuningData) override;\n+\n \tvoid process(IPAContext &context, const uint32_t frame,\n \t\t     IPAFrameContext &frameContext,\n \t\t     const SwIspStats *stats,\n@@ -26,6 +30,10 @@ public:\n \n private:\n \tvoid updateExposure(IPAContext &context, IPAFrameContext &frameContext, double exposureMSV);\n+\n+\tfloat exposureTarget_;\n+\tfloat hysteresis_;\n+\tfloat proportionalGain_;\n };\n \n } /* namespace ipa::soft::algorithms */\n","prefixes":[]}