Patch Detail
Show a patch.
GET /api/patches/26592/?format=api
{ "id": 26592, "url": "https://patchwork.libcamera.org/api/patches/26592/?format=api", "web_url": "https://patchwork.libcamera.org/patch/26592/", "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": "<20260501191400.985920-1-devve.3@gmail.com>", "date": "2026-05-01T19:13:09", "name": "ipa: simple: awb: Add temporal smoothing and per-channel gain limits", "commit_ref": null, "pull_url": null, "state": "new", "archived": false, "hash": "cdd6097ed272d57d810ba672ad69b5f9ba4b551b", "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/26592/mbox/", "series": [ { "id": 5893, "url": "https://patchwork.libcamera.org/api/series/5893/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5893", "date": "2026-05-01T19:13:09", "name": "ipa: simple: awb: Add temporal smoothing and per-channel gain limits", "version": 1, "mbox": "https://patchwork.libcamera.org/series/5893/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/26592/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/26592/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 63AF9BDCB5\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 1 May 2026 19:55:27 +0000 (UTC)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 3863063025;\n\tFri, 1 May 2026 21:55:26 +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 579B162FB1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 1 May 2026 21:14:21 +0200 (CEST)", "by mail-wm1-x332.google.com with SMTP id\n\t5b1f17b1804b1-48984d29fe3so32435505e9.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 01 May 2026 12:14:21 -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.20\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 01 May 2026 12:14:20 -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=\"GC2oKlUA\"; dkim-atps=neutral", "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=gmail.com; s=20251104; t=1777662861; x=1778267661;\n\tdarn=lists.libcamera.org; \n\th=content-transfer-encoding:mime-version:message-id:date:subject:cc\n\t:to:from:from:to:cc:subject:date:message-id:reply-to;\n\tbh=rzGFobzzw+DDdH/ZpLcVh6y/sbzTr3KV2kFj73Dff/E=;\n\tb=GC2oKlUArFjGWZxqpQeuq52Dh1Mf4GKeNeCI+TJdY8QBtepPgHZZEf8NXNxDG5IaVn\n\tW7GtFhuVc7HmR1gwloMX+uxi9z1x0QF08ZUK2Vx+c2PvQV0HhtrsJJf3EzsGuOLAZTXF\n\tlv1FRjgyprdxSyyZ3IZ2EqwA0ee4fBGsACtq3xF3f5dMK0YFNNfsD4oD7TdD8M1PxijS\n\t0mMceNoavD6tyZAhjGd+a3mZc2rn75lzflZiNvY3h4NLuBmJ2kFKSIYc+m9F/9jryTRw\n\t0Lz5KsuXBOi/a/F23kL7q7IdSXaK7jVgElsECr4nDRYFZXz0zg8fPvVd+3yq05H65eoL\n\t8ceg==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20251104; t=1777662861; x=1778267661;\n\th=content-transfer-encoding:mime-version:message-id:date:subject:cc\n\t:to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date\n\t:message-id:reply-to;\n\tbh=rzGFobzzw+DDdH/ZpLcVh6y/sbzTr3KV2kFj73Dff/E=;\n\tb=YYyb3SllZuEpMJM1Z0QpyNhdX7bVw3rjIjDLRVa6L0U2ymO42z+iHBf8ZUPbL4YOVN\n\t4K1B3ki99s7icCkDkfUeuOevKliDZHF47rP+3ZG6pCKBPdLywFkkdY9zC5IUYfV9N4Ai\n\tyCM5NB1rhj8oO7EI+oFiweadgTyDyJT95rhKtNzND+8Wsg5DHKcAjVDsZ4m9rA/hLv2W\n\tB0qwxn8nUF0r6hDXvY5k9gicZ0lOeNODl3T8qQTUhNDBKgV20aL/BDo3iVebHbGahLt2\n\tfOTvY7ZUqasc5j7beTLD52UZi9bWBhq9/SuRbkqBFrKQeKTZ/xiFgp7hphX5FBq84euj\n\tbxig==", "X-Gm-Message-State": "AOJu0Yy+gPH96f17W4WxfwFIGkAG87Urtj4rsXn1RHph3im+xWuAg/Lc\n\tIHHGDURbLrwLuIwmTbCpX/kz5lpPxeIFP9Al7W0PetAA1b2DwR82Hq6kc892zA==", "X-Gm-Gg": "AeBDieuxhq1AcmFZwPw+0o7u8GnYbdyGln5vmceV0kFSoAL/dSaAfyUK3atEHY6QMgW\n\tnJuiR6yc2hC6EcxLTg7lYtntdZSr6PMbqPjWAjPsbniDOkVJAVrjljKS86W0yW8MB82uZsWW0nh\n\tuzol2E90E4rImnQubKweUCGB5DC3DCtANjtNX7zwK9CePWsSrBfFnt/ED4zmNH37wC1OaitQwzT\n\trONOgq2DmysriE4zLDYMSJ8viRQ2pZBdWAxxqGJ3+FsyI/Hy5B9tBN0D5WM9owm/STfN0of8FLu\n\t1fkFoiGKE57s6O3tpWRp8qZpU6RqapFaqQEzNOxEAhtOrdmDfcvMxsRwCiNpWtvEdXaf7PJtjCt\n\t9yx8N3FFDqs7NCjw8IK6Yhq1s1a9VXYGuos4SQ6QMpEfOP5Oy5LRRpPoBNj2bJX2W6Dd2l/B426\n\t0AVTpXhXVJGSsbkOsGq5wUh9sOwIEN6B2l92yvyBmDDJLmGe6yVO9SnLP8Ke29u2h5OWxrfzOIe\n\tsMZuynplxJSAECqaSMOFvCajg1pOhGx", "X-Received": "by 2002:a05:600c:a404:b0:488:9fb7:376d with SMTP id\n\t5b1f17b1804b1-48a9867710cmr5101955e9.28.1777662860569; \n\tFri, 01 May 2026 12:14:20 -0700 (PDT)", "From": "d3vv3 <devve.3@gmail.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "d3vv3 <devve.3@gmail.com>", "Subject": "[PATCH] ipa: simple: awb: Add temporal smoothing and per-channel\n\tgain limits", "Date": "Fri, 1 May 2026 21:13:09 +0200", "Message-ID": "<20260501191400.985920-1-devve.3@gmail.com>", "X-Mailer": "git-send-email 2.54.0", "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": "Add configurable YAML parameters maxGainR, maxGainB, and speed to AWB.\nReplace the single hardcoded max gain (4.0x) with per-channel limits,\nand apply exponential moving average smoothing to reduce colour\ntemperature oscillation between frames.\n\nSigned-off-by: d3vv3 <devve.3@gmail.com>\n---\n src/ipa/simple/algorithms/awb.cpp | 34 ++++++++++++++++++++++++++-----\n src/ipa/simple/algorithms/awb.h | 6 ++++++\n 2 files changed, 35 insertions(+), 5 deletions(-)", "diff": "diff --git a/src/ipa/simple/algorithms/awb.cpp b/src/ipa/simple/algorithms/awb.cpp\nindex f5c88ea6..0f9964a4 100644\n--- a/src/ipa/simple/algorithms/awb.cpp\n+++ b/src/ipa/simple/algorithms/awb.cpp\n@@ -14,6 +14,8 @@\n \n #include <libcamera/control_ids.h>\n \n+#include \"libcamera/internal/yaml_parser.h\"\n+\n #include \"libipa/colours.h\"\n #include \"simple/ipa_context.h\"\n \n@@ -23,6 +25,21 @@ LOG_DEFINE_CATEGORY(IPASoftAwb)\n \n namespace ipa::soft::algorithms {\n \n+int Awb::init([[maybe_unused]] IPAContext &context,\n+\t const ValueNode &tuningData)\n+{\n+\tmaxGainR_ = tuningData[\"maxGainR\"].get<float>().value_or(4.0f);\n+\tmaxGainB_ = tuningData[\"maxGainB\"].get<float>().value_or(4.0f);\n+\tspeed_ = tuningData[\"speed\"].get<float>().value_or(1.0f);\n+\n+\tLOG(IPASoftAwb, Info)\n+\t\t<< \"AWB: maxGainR \" << maxGainR_\n+\t\t<< \", maxGainB \" << maxGainB_\n+\t\t<< \", speed \" << speed_;\n+\n+\treturn 0;\n+}\n+\n int Awb::configure(IPAContext &context,\n \t\t [[maybe_unused]] const IPAConfigInfo &configInfo)\n {\n@@ -84,14 +101,21 @@ void Awb::process(IPAContext &context,\n \tconst RGB<uint64_t> sum = stats->sum_.max(offset + minValid) - offset;\n \n \t/*\n-\t * Calculate red and blue gains for AWB.\n-\t * Clamp max gain at 4.0, this also avoids 0 division.\n+\t * Calculate red and blue gains for AWB. Clamp max gain to avoid\n+\t * division by zero and extreme color casts.\n \t */\n \tauto &gains = context.activeState.awb.gains;\n+\tfloat rawRGain = sum.r() <= sum.g() / maxGainR_ ? maxGainR_ :\n+\t\t\t\tstatic_cast<float>(sum.g()) / sum.r();\n+\tfloat rawBGain = sum.b() <= sum.g() / maxGainB_ ? maxGainB_ :\n+\t\t\t\tstatic_cast<float>(sum.g()) / sum.b();\n+\n+\t/* Apply temporal smoothing to avoid rapid white balance changes. */\n+\tfloat alpha = std::clamp(speed_, 0.01f, 1.0f);\n \tgains = { {\n-\t\tsum.r() <= sum.g() / 4 ? 4.0f : static_cast<float>(sum.g()) / sum.r(),\n-\t\t1.0,\n-\t\tsum.b() <= sum.g() / 4 ? 4.0f : static_cast<float>(sum.g()) / sum.b(),\n+\t\tgains.r() * (1.0f - alpha) + rawRGain * alpha,\n+\t\t1.0f,\n+\t\tgains.b() * (1.0f - alpha) + rawBGain * alpha,\n \t} };\n \n \tRGB<double> rgbGains{ { 1 / gains.r(), 1 / gains.g(), 1 / gains.b() } };\ndiff --git a/src/ipa/simple/algorithms/awb.h b/src/ipa/simple/algorithms/awb.h\nindex ad993f39..0aedc1d1 100644\n--- a/src/ipa/simple/algorithms/awb.h\n+++ b/src/ipa/simple/algorithms/awb.h\n@@ -19,6 +19,7 @@ public:\n \tAwb() = default;\n \t~Awb() = default;\n \n+\tint init(IPAContext &context, const ValueNode &tuningData) override;\n \tint configure(IPAContext &context, const IPAConfigInfo &configInfo) override;\n \tvoid prepare(IPAContext &context,\n \t\t const uint32_t frame,\n@@ -29,6 +30,11 @@ public:\n \t\t IPAFrameContext &frameContext,\n \t\t const SwIspStats *stats,\n \t\t ControlList &metadata) override;\n+\n+private:\n+\tfloat maxGainR_;\n+\tfloat maxGainB_;\n+\tfloat speed_;\n };\n \n } /* namespace ipa::soft::algorithms */\n", "prefixes": [] }