Patch Detail
Show a patch.
GET /api/1.1/patches/24831/?format=api
{ "id": 24831, "url": "https://patchwork.libcamera.org/api/1.1/patches/24831/?format=api", "web_url": "https://patchwork.libcamera.org/patch/24831/", "project": { "id": 1, "url": "https://patchwork.libcamera.org/api/1.1/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": "<20251023115034.2207-5-david.plowman@raspberrypi.com>", "date": "2025-10-23T11:49:16", "name": "[v2,4/5] ipa: rpi: vc4: Use a floating statistics region for a full image Y sum", "commit_ref": "0810b8a70a1f4f05327c8e938b0669dcefdc26cc", "pull_url": null, "state": "accepted", "archived": false, "hash": "302a467600759409041def9fd62cc09b9e7310a1", "submitter": { "id": 42, "url": "https://patchwork.libcamera.org/api/1.1/people/42/?format=api", "name": "David Plowman", "email": "david.plowman@raspberrypi.com" }, "delegate": null, "mbox": "https://patchwork.libcamera.org/patch/24831/mbox/", "series": [ { "id": 5519, "url": "https://patchwork.libcamera.org/api/1.1/series/5519/?format=api", "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5519", "date": "2025-10-23T11:49:12", "name": "Fix and improve full image Y statistics", "version": 2, "mbox": "https://patchwork.libcamera.org/series/5519/mbox/" } ], "comments": "https://patchwork.libcamera.org/api/patches/24831/comments/", "check": "pending", "checks": "https://patchwork.libcamera.org/api/patches/24831/checks/", "tags": {}, "headers": { "Return-Path": "<kieran.bingham@ideasonboard.com>", "X-Original-To": "parsemail@patchwork.libcamera.org", "Delivered-To": [ "parsemail@patchwork.libcamera.org", "kbingham@ideasonboard.com" ], "Received": [ "from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id D37E2BE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 26 Oct 2025 23:32:10 +0000 (UTC)", "from pendragon.ideasonboard.com\n\t(cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net\n\t[86.31.185.195])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 77B98AB4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 27 Oct 2025 00:30:23 +0100 (CET)", "from perceval.ideasonboard.com\n\tby perceval.ideasonboard.com with LMTP id WNtiFDcW+mhDUhcA4E0KoQ\n\t(envelope-from <libcamera-devel-bounces@lists.libcamera.org>)\n\tfor <kbingham@ideasonboard.com>; Thu, 23 Oct 2025 13:49:11 +0200", "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\tby perceval.ideasonboard.com (Postfix) with ESMTPS\n\tid 7B7761D2B;\tThu, 23 Oct 2025 13:49:04 +0200 (CEST)", "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 11D81607BE;\n\tThu, 23 Oct 2025 13:50:48 +0200 (CEST)", "from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com\n\t[IPv6:2a00:1450:4864:20::42a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 0B66E607BE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Oct 2025 13:50:44 +0200 (CEST)", "by mail-wr1-x42a.google.com with SMTP id\n\tffacd0b85a97d-428564f8d16so368484f8f.1\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Oct 2025 04:50:44 -0700 (PDT)", "from davidp-pi.pitowers.org\n\t([2a00:1098:3142:1f:f75f:a9a5:3eb7:34d4]) by smtp.gmail.com with\n\tESMTPSA id\n\tffacd0b85a97d-4298b996aaasm1900760f8f.3.2025.10.23.04.50.42\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 23 Oct 2025 04:50:42 -0700 (PDT)" ], "Authentication-Results": [ "perceval.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.a=rsa-sha256 header.s=google header.b=ttBM8ABS; \n\tdkim-atps=neutral", "lancelot.ideasonboard.com; dkim=pass (2048-bit key; \n\tunprotected) header.d=raspberrypi.com\n\theader.i=@raspberrypi.com\n\theader.b=\"ttBM8ABS\";\tdkim-atps=neutral" ], "DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1761220243; x=1761825043;\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=MT+p1j+p/DveVI+kn0QiagoZ5EXuJnmCwmRZyRj4aXA=;\n\tb=ttBM8ABS2gj2I4AmuLSIPCZ6sJgLWGG7sNDlySGR6chfJyE/gzOp0/x2rQQtc9qzRk\n\tGmPeaXqc56TAgB/nVeTbI84jlq3W7TpFdggODx8w7iOxe7YBqKcArTwbkeyoR7o4bc2V\n\tAdurNiHmoShRwnrxhN5zE3rOsNERWgIKVv/Tt1HL7mpgBa3nbv9Sdza5KI4Hpv/RZ01F\n\tO8nCmRQTzmHLQCUcVAwROm+bf83xRAORCpJAsmPsk+5bBuIGgkkAo/Ma9w4YJCAt2hhU\n\t7NQrT6Jiac1tJTo1nG6OMbON83y/l7v8yvB5Ex/3gbd13uIdyT9Cd+4r+x2oi7mu20t2\n\tAxhA==", "X-Google-DKIM-Signature": "v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1761220243; x=1761825043;\n\th=content-transfer-encoding:mime-version:references:in-reply-to\n\t:message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc\n\t:subject:date:message-id:reply-to;\n\tbh=MT+p1j+p/DveVI+kn0QiagoZ5EXuJnmCwmRZyRj4aXA=;\n\tb=ck2WDHdkKm6Kn6arkXqJi9KBFLyjGgbblcEEL5CTbajFQ+WfqMrjEGVMcZ+qj0atwe\n\toDNButMXvZsUEkGjYlkK1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=?utf-8?q?2WE/IG+0rrfKmIiFl9zQnQUQOmteaueaQjufA=3D=3D?=", "X-Received": "by 2002:a05:6000:40dd:b0:427:548:6e3b with SMTP id\n\tffacd0b85a97d-42853264540mr5156729f8f.13.1761220243149; \n\tThu, 23 Oct 2025 04:50:43 -0700 (PDT)", "From": "David Plowman <david.plowman@raspberrypi.com>", "To": "libcamera-devel@lists.libcamera.org", "Cc": "David Plowman <david.plowman@raspberrypi.com>,\n\tStefan Klug <stefan.klug@ideasonboard.com>,\n\tNaushir Patuck <naush@raspberrypi.com>", "Subject": "[PATCH v2 4/5] ipa: rpi: vc4: Use a floating statistics region for a\n\tfull image Y sum", "Date": "Thu, 23 Oct 2025 12:49:16 +0100", "Message-ID": "<20251023115034.2207-5-david.plowman@raspberrypi.com>", "X-Mailer": "git-send-email 2.47.3", "In-Reply-To": "<20251023115034.2207-1-david.plowman@raspberrypi.com>", "References": "<20251023115034.2207-1-david.plowman@raspberrypi.com>", "MIME-Version": "1.0", "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>", "X-TUID": "56uNb2kcEtX5", "Resent-From": "Kieran Bingham <kieran.bingham@ideasonboard.com>", "Resent-To": "parsemail@patchwork.libcamera.org" }, "content": "We're going to use a \"floating statistics region\" to store a full\nimage Y sum. The VC4 platform actually has no floating region for\nthis, but we can synthesize such a region as follows in software.\n\nWe know that the 15 AGC regions that we do have are arranged to cover\nthe whole image, and they cannot be changed. Adding up the R, G and B\nvalues here will get us most of the way to Y. But we do also need to\nknow the most recent colour gains, so code must also be added to\nremember the last AWB status.\n\nWith this change, algorithms can now look at the first floating region\non both VC4 and PiSP platforms to get a full image Y average value.\n\nSigned-off-by: David Plowman <david.plowman@raspberrypi.com>\nReviewed-by: Stefan Klug <stefan.klug@ideasonboard.com>\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\n---\n src/ipa/rpi/vc4/vc4.cpp | 31 +++++++++++++++++++++++++++++--\n 1 file changed, 29 insertions(+), 2 deletions(-)", "diff": "diff --git a/src/ipa/rpi/vc4/vc4.cpp b/src/ipa/rpi/vc4/vc4.cpp\nindex ba43e474..19d7b9d8 100644\n--- a/src/ipa/rpi/vc4/vc4.cpp\n+++ b/src/ipa/rpi/vc4/vc4.cpp\n@@ -43,6 +43,9 @@ public:\n \tIpaVc4()\n \t\t: IpaBase(), lsTable_(nullptr)\n \t{\n+\t\tlastAwbStatus_.gainR = 1.0;\n+\t\tlastAwbStatus_.gainG = 1.0;\n+\t\tlastAwbStatus_.gainB = 1.0;\n \t}\n \n \t~IpaVc4()\n@@ -81,6 +84,9 @@ private:\n \t/* LS table allocation passed in from the pipeline handler. */\n \tSharedFD lsTableHandle_;\n \tvoid *lsTable_;\n+\n+\t/* Remember the most recent AWB values. */\n+\tAwbStatus lastAwbStatus_;\n };\n \n int32_t IpaVc4::platformInit([[maybe_unused]] const InitParams ¶ms, [[maybe_unused]] InitResult *result)\n@@ -144,8 +150,10 @@ void IpaVc4::platformPrepareIsp([[maybe_unused]] const PrepareParams ¶ms,\n \tstd::unique_lock<RPiController::Metadata> lock(rpiMetadata);\n \n \tAwbStatus *awbStatus = rpiMetadata.getLocked<AwbStatus>(\"awb.status\");\n-\tif (awbStatus)\n+\tif (awbStatus) {\n \t\tapplyAWB(awbStatus, ctrls);\n+\t\tlastAwbStatus_ = *awbStatus;\n+\t}\n \n \tCcmStatus *ccmStatus = rpiMetadata.getLocked<CcmStatus>(\"ccm.status\");\n \tif (ccmStatus)\n@@ -226,7 +234,13 @@ RPiController::StatisticsPtr IpaVc4::platformProcessStats(Span<uint8_t> mem)\n \t\tLOG(IPARPI, Debug) << \"No AGC algorithm - not copying statistics\";\n \t\tstatistics->agcRegions.init(0);\n \t} else {\n-\t\tstatistics->agcRegions.init(hw.agcRegions);\n+\t\tRgbySums fullImage;\n+\t\tuint32_t countedSum = 0;\n+\t\tuint32_t notCountedSum = 0;\n+\t\t/* We're going to pretend there's a floating region where we will put a full image Y sum. */\n+\t\tconst unsigned int numFloating = 1;\n+\n+\t\tstatistics->agcRegions.init(hw.agcRegions, numFloating);\n \t\tconst std::vector<double> &weights = agc->getWeights();\n \t\tfor (i = 0; i < statistics->agcRegions.numRegions(); i++) {\n \t\t\tuint64_t rSum = (stats->agc_stats[i].r_sum << scale) * weights[i];\n@@ -237,7 +251,20 @@ RPiController::StatisticsPtr IpaVc4::platformProcessStats(Span<uint8_t> mem)\n \t\t\tstatistics->agcRegions.set(i, { { rSum, gSum, bSum },\n \t\t\t\t\t\t\tcounted,\n \t\t\t\t\t\t\tnotcounted });\n+\n+\t\t\t/* Accumulate values for the full image Y sum. */\n+\t\t\tfullImage.rSum += stats->agc_stats[i].r_sum << scale;\n+\t\t\tfullImage.gSum += stats->agc_stats[i].g_sum << scale;\n+\t\t\tfullImage.bSum += stats->agc_stats[i].b_sum << scale;\n+\t\t\tcountedSum += stats->agc_stats[i].counted;\n+\t\t\tnotCountedSum += stats->agc_stats[i].notcounted;\n \t\t}\n+\n+\t\t/* The \"floating\" region has the Y sum for the entire image. */\n+\t\tfullImage.ySum = fullImage.rSum * lastAwbStatus_.gainR * 0.299 +\n+\t\t\t\t fullImage.gSum * lastAwbStatus_.gainG * 0.587 +\n+\t\t\t\t fullImage.bSum * lastAwbStatus_.gainB * 0.114;\n+\t\tstatistics->agcRegions.setFloating(0, { fullImage, countedSum, notCountedSum });\n \t}\n \n \tstatistics->focusRegions.init(hw.focusRegions);\n", "prefixes": [ "v2", "4/5" ] }