{"id":24832,"url":"https://patchwork.libcamera.org/api/patches/24832/?format=json","web_url":"https://patchwork.libcamera.org/patch/24832/","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":"<20251023115034.2207-6-david.plowman@raspberrypi.com>","date":"2025-10-23T11:49:17","name":"[v2,5/5] ipa: rpi: lux: Use floating statistics region to obtain the current Y value","commit_ref":"36f9cdcdb4a3c69e10b7da8a3de8354421cdcb56","pull_url":null,"state":"accepted","archived":false,"hash":"62fc64c7a11edcf6ab09e4a1c2e9d35cd217031c","submitter":{"id":42,"url":"https://patchwork.libcamera.org/api/people/42/?format=json","name":"David Plowman","email":"david.plowman@raspberrypi.com"},"delegate":null,"mbox":"https://patchwork.libcamera.org/patch/24832/mbox/","series":[{"id":5519,"url":"https://patchwork.libcamera.org/api/series/5519/?format=json","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/24832/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/24832/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 D12D9BE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 26 Oct 2025 23:32:18 +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 78721AB4\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 27 Oct 2025 00:30:31 +0100 (CET)","from perceval.ideasonboard.com\n\tby perceval.ideasonboard.com with LMTP id gNKrEDgW+mgSUhcA4E0KoQ\n\t(envelope-from <libcamera-devel-bounces@lists.libcamera.org>)\n\tfor <kbingham@ideasonboard.com>; Thu, 23 Oct 2025 13:49:12 +0200","from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\tby perceval.ideasonboard.com (Postfix) with ESMTPS\n\tid A29EB195E;\tThu, 23 Oct 2025 13:49:05 +0200 (CEST)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id B5619607D9;\n\tThu, 23 Oct 2025 13:50:49 +0200 (CEST)","from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com\n\t[IPv6:2a00:1450:4864:20::42c])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 3BEC5607E2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Oct 2025 13:50:45 +0200 (CEST)","by mail-wr1-x42c.google.com with SMTP id\n\tffacd0b85a97d-4270a3464bcso557449f8f.2\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Oct 2025 04:50:45 -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.43\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tThu, 23 Oct 2025 04:50:43 -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=FTNSb55g; \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=\"FTNSb55g\";\tdkim-atps=neutral"],"DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1761220244; x=1761825044;\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=as/dlgHutMADg0GvxNPvuAiya+JaZBMlt2Qk/YuhrOQ=;\n\tb=FTNSb55gRUZgNYQVZ+DzC0qA9igfIH0qiQM35xLZc67hH3W0Y63yTi3/RHlR1GG8rE\n\tyBjafNhdc48mPK+VqDOMdO/GsbKeXXgvWL/qc2S2efSckM+BnxDWW4xtbAgf7IlWAOIc\n\tcaV9kz6kfB+Ryp6fFsyI0wyFW4NI638pfUtli4qZEbKVVA5nKgxr9MbQt2RRR+0wQF2V\n\tKrn1j464KBx6S/h/3rCORMlCdmxoQs7CiQJPfZxJmBVy2L7aQh8sREAZrGCfeAH/WSVO\n\tOQJyCX295aac16bS5VDuETY6jA8BrzNKT6eluIuV2CddnJPtvtzPHn8QSLdZM3Mk0++/\n\tg/zw==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1761220244; x=1761825044;\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=as/dlgHutMADg0GvxNPvuAiya+JaZBMlt2Qk/YuhrOQ=;\n\tb=xD4b+wtESAjORcPzPxVQGSomLUW1hBB+Fa1ubP6LCnR7XioALv2ooblYg/OL8nqRvP\n\t6Pr1/JggoBUdkL+eUjt5wadTIZo8INlqPoE6d/SleNf9BcpZoiO7Th1vi2Vk04REb2VT\n\tsNo6xOubWyQqcKDqDPjfh2Bt//leEK1j2G7evGoCf0RnOX4hrbGjaLVlj84OXiMPsRdY\n\t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id\n\tffacd0b85a97d-42704d7e9c4mr14986826f8f.4.1761220244381; \n\tThu, 23 Oct 2025 04:50:44 -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 5/5] ipa: rpi: lux: Use floating statistics region to\n\tobtain the current Y value","Date":"Thu, 23 Oct 2025 12:49:17 +0100","Message-ID":"<20251023115034.2207-6-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":"ndbV0lihDIXp","Resent-From":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Resent-To":"parsemail@patchwork.libcamera.org"},"content":"The Y value from the first floating region is now a better choice for\na Y value that is invariant to (for example) the metering mode.\n\nBoth VC4 and PiSP platforms store full image Y statistics here.\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/controller/rpi/lux.cpp | 11 +++++++++--\n 1 file changed, 9 insertions(+), 2 deletions(-)","diff":"diff --git a/src/ipa/rpi/controller/rpi/lux.cpp b/src/ipa/rpi/controller/rpi/lux.cpp\nindex acaa6e57..7dab27cc 100644\n--- a/src/ipa/rpi/controller/rpi/lux.cpp\n+++ b/src/ipa/rpi/controller/rpi/lux.cpp\n@@ -85,14 +85,21 @@ void Lux::process(StatisticsPtr &stats, Metadata *imageMetadata)\n {\n \tDeviceStatus deviceStatus;\n \tif (imageMetadata->get(\"device.status\", deviceStatus) == 0) {\n+\t\t/*\n+\t\t * We've set up the first floating AGC region to collect full image stats. This\n+\t\t * is a better choice than the Y-histogram, for example, because it's invariant\n+\t\t * to the metering mode (and cheaper to evaluate).\n+\t\t */\n+\t\tauto const &fullImageStats = stats->agcRegions.getFloating(0);\n+\t\tdouble currentY = static_cast<double>(fullImageStats.val.ySum) / fullImageStats.counted;\n+\n \t\tdouble currentGain = deviceStatus.analogueGain;\n \t\tdouble currentAperture = deviceStatus.aperture.value_or(currentAperture_);\n-\t\tdouble currentY = stats->yHist.interQuantileMean(0, 1);\n \t\tdouble gainRatio = referenceGain_ / currentGain;\n \t\tdouble exposureTimeRatio =\n \t\t\treferenceExposureTime_ / deviceStatus.exposureTime;\n \t\tdouble apertureRatio = referenceAperture_ / currentAperture;\n-\t\tdouble yRatio = currentY * (65536 / stats->yHist.bins()) / referenceY_;\n+\t\tdouble yRatio = currentY / referenceY_;\n \t\tdouble estimatedLux = exposureTimeRatio * gainRatio *\n \t\t\t\t      apertureRatio * apertureRatio *\n \t\t\t\t      yRatio * referenceLux_ / sensitivity_;\n","prefixes":["v2","5/5"]}