[{"id":36358,"web_url":"https://patchwork.libcamera.org/comment/36358/","msgid":"<176095520201.336133.2889016243009646600@localhost>","date":"2025-10-20T10:13:22","subject":"Re: [PATCH 5/5] ipa: rpi: lux: Use floating statistics region to\n\tobtain the current Y value","submitter":{"id":184,"url":"https://patchwork.libcamera.org/api/people/184/","name":"Stefan Klug","email":"stefan.klug@ideasonboard.com"},"content":"Hi David,\n\nQuoting David Plowman (2025-10-17 12:05:41)\n> The Y value from the first floating region is now a better choice for\n> a Y value that is invariant to (for example) the metering mode.\n> \n> Both VC4 and PiSP platforms store full image Y statistics here.\n> \n> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n\nLooks good to me.\n\nReviewed-by: Stefan Klug <stefan.klug@ideasonboard.com>\n\nCheers,\nStefan\n\n> ---\n>  src/ipa/rpi/controller/rpi/lux.cpp | 11 +++++++++--\n>  1 file changed, 9 insertions(+), 2 deletions(-)\n> \n> diff --git a/src/ipa/rpi/controller/rpi/lux.cpp b/src/ipa/rpi/controller/rpi/lux.cpp\n> index 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>         DeviceStatus deviceStatus;\n>         if (imageMetadata->get(\"device.status\", deviceStatus) == 0) {\n> +               /*\n> +                * We've set up the first floating AGC region to collect full image stats. This\n> +                * is a better choice than the Y-histogram, for example, because it's invariant\n> +                * to the metering mode (and cheaper to evaluate).\n> +                */\n> +               auto const &fullImageStats = stats->agcRegions.getFloating(0);\n> +               double currentY = static_cast<double>(fullImageStats.val.ySum) / fullImageStats.counted;\n> +\n>                 double currentGain = deviceStatus.analogueGain;\n>                 double currentAperture = deviceStatus.aperture.value_or(currentAperture_);\n> -               double currentY = stats->yHist.interQuantileMean(0, 1);\n>                 double gainRatio = referenceGain_ / currentGain;\n>                 double exposureTimeRatio =\n>                         referenceExposureTime_ / deviceStatus.exposureTime;\n>                 double apertureRatio = referenceAperture_ / currentAperture;\n> -               double yRatio = currentY * (65536 / stats->yHist.bins()) / referenceY_;\n> +               double yRatio = currentY / referenceY_;\n>                 double estimatedLux = exposureTimeRatio * gainRatio *\n>                                       apertureRatio * apertureRatio *\n>                                       yRatio * referenceLux_ / sensitivity_;\n> -- \n> 2.47.3\n>","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 42ACBC3259\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 20 Oct 2025 10:13:27 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 639E960713;\n\tMon, 20 Oct 2025 12:13:26 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 179CF60706\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 20 Oct 2025 12:13:25 +0200 (CEST)","from ideasonboard.com (unknown\n\t[IPv6:2a00:6020:448c:6c00:9f50:5b33:d3ec:e1ea])\n\tby perceval.ideasonboard.com (Postfix) with UTF8SMTPSA id 3D239F52;\n\tMon, 20 Oct 2025 12:11:42 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"ZVdfLXhI\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1760955102;\n\tbh=UmOFibJYXOS0uLNtltTjMoI2Wgy9F+wHF2AOLJPYjbU=;\n\th=In-Reply-To:References:Subject:From:Cc:To:Date:From;\n\tb=ZVdfLXhI6fINk6wnoAZWXeynvEvsxtpj+anPE9F3H5UqutPXTTEjM3C0R4uCvUljS\n\tUYaIQ/rb6arE72lPFW1hiWVIyLA2YtmJzxy2DrSU1sz9XwBD6VGHpETR+s2pFJptVA\n\tU9J3X6yQwWaSFYI3bVeRJLfea9Fp0JFNxln/ngTo=","Content-Type":"text/plain; charset=\"utf-8\"","MIME-Version":"1.0","Content-Transfer-Encoding":"quoted-printable","In-Reply-To":"<20251017102704.3887-6-david.plowman@raspberrypi.com>","References":"<20251017102704.3887-1-david.plowman@raspberrypi.com>\n\t<20251017102704.3887-6-david.plowman@raspberrypi.com>","Subject":"Re: [PATCH 5/5] ipa: rpi: lux: Use floating statistics region to\n\tobtain the current Y value","From":"Stefan Klug <stefan.klug@ideasonboard.com>","Cc":"David Plowman <david.plowman@raspberrypi.com>","To":"David Plowman <david.plowman@raspberrypi.com>,\n\tlibcamera-devel@lists.libcamera.org","Date":"Mon, 20 Oct 2025 12:13:22 +0200","Message-ID":"<176095520201.336133.2889016243009646600@localhost>","User-Agent":"alot/0.12.dev8+g2c003385c862.d20250602","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>"}},{"id":36398,"web_url":"https://patchwork.libcamera.org/comment/36398/","msgid":"<CAEmqJPod+pZK1sKQ4tzjFzF4HepnpwXkBT5MLFcBUTVcDRNeMw@mail.gmail.com>","date":"2025-10-23T07:40:36","subject":"Re: [PATCH 5/5] ipa: rpi: lux: Use floating statistics region to\n\tobtain the current Y value","submitter":{"id":34,"url":"https://patchwork.libcamera.org/api/people/34/","name":"Naushir Patuck","email":"naush@raspberrypi.com"},"content":"Hi David,\n\n\nOn Fri, 17 Oct 2025 at 11:27, David Plowman <david.plowman@raspberrypi.com>\nwrote:\n\n> The Y value from the first floating region is now a better choice for\n> a Y value that is invariant to (for example) the metering mode.\n>\n> Both VC4 and PiSP platforms store full image Y statistics here.\n>\n> Signed-off-by: David Plowman <david.plowman@raspberrypi.com>\n>\n\nReviewed-by: Naushir Patuck <naush@raspberrypi.com>\n\n\n> ---\n>  src/ipa/rpi/controller/rpi/lux.cpp | 11 +++++++++--\n>  1 file changed, 9 insertions(+), 2 deletions(-)\n>\n> diff --git a/src/ipa/rpi/controller/rpi/lux.cpp\n> b/src/ipa/rpi/controller/rpi/lux.cpp\n> index 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\n> *imageMetadata)\n>  {\n>         DeviceStatus deviceStatus;\n>         if (imageMetadata->get(\"device.status\", deviceStatus) == 0) {\n> +               /*\n> +                * We've set up the first floating AGC region to collect\n> full image stats. This\n> +                * is a better choice than the Y-histogram, for example,\n> because it's invariant\n> +                * to the metering mode (and cheaper to evaluate).\n> +                */\n> +               auto const &fullImageStats =\n> stats->agcRegions.getFloating(0);\n> +               double currentY =\n> static_cast<double>(fullImageStats.val.ySum) / fullImageStats.counted;\n> +\n>                 double currentGain = deviceStatus.analogueGain;\n>                 double currentAperture =\n> deviceStatus.aperture.value_or(currentAperture_);\n> -               double currentY = stats->yHist.interQuantileMean(0, 1);\n>                 double gainRatio = referenceGain_ / currentGain;\n>                 double exposureTimeRatio =\n>                         referenceExposureTime_ / deviceStatus.exposureTime;\n>                 double apertureRatio = referenceAperture_ /\n> currentAperture;\n> -               double yRatio = currentY * (65536 / stats->yHist.bins()) /\n> referenceY_;\n> +               double yRatio = currentY / referenceY_;\n>                 double estimatedLux = exposureTimeRatio * gainRatio *\n>                                       apertureRatio * apertureRatio *\n>                                       yRatio * referenceLux_ /\n> sensitivity_;\n> --\n> 2.47.3\n>\n>","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 25B44BE080\n\tfor <parsemail@patchwork.libcamera.org>;\n\tThu, 23 Oct 2025 07:41:16 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 41C78607AE;\n\tThu, 23 Oct 2025 09:41:15 +0200 (CEST)","from mail-vs1-xe32.google.com (mail-vs1-xe32.google.com\n\t[IPv6:2607:f8b0:4864:20::e32])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id CA5F5607A6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Oct 2025 09:41:13 +0200 (CEST)","by mail-vs1-xe32.google.com with SMTP id\n\tada2fe7eead31-5db1b920a3aso34561137.3\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tThu, 23 Oct 2025 00:41:13 -0700 (PDT)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=raspberrypi.com header.i=@raspberrypi.com\n\theader.b=\"Qd85wVPB\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1761205273; x=1761810073;\n\tdarn=lists.libcamera.org; \n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:from:to:cc:subject:date:message-id:reply-to;\n\tbh=tBC3jWmf5fa1ZtBRtjRnh3FgsFysHm7bGxwG2nuS5o4=;\n\tb=Qd85wVPB6JkZMpmPRS1ecYdUfQB3cNEFqQdVA5busNw/IylkrPImkJnmOhxOn1Yff4\n\tzpF70gwa5pWXDsmnOMw7mj2qsMZlyjMnYjbbduZGLYJuycghXMx0ZDusHGVrXwpWuLLE\n\t3+LpiAW1HcJSDnf3Mm+Bhi6HBJf3WwWbqfrBKY02PGdNLShE9sBsdRSex/4seXoDT0el\n\tjwqeJ4fsRzeBrRhiBLLJjYr88YcBtFUw9z9Hbx4FGC/SPihU8L6/7nkMQDirC0jlDoiz\n\tkne2m0wVwLDXO6PEEOX8ZRLSAt7klhGroeNq7J+TGWLZiw95pprDlUvPErv9/z/vZuj9\n\tuDTA==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1761205273; x=1761810073;\n\th=cc:to:subject:message-id:date:from:in-reply-to:references\n\t:mime-version:x-gm-message-state:from:to:cc:subject:date:message-id\n\t:reply-to;\n\tbh=tBC3jWmf5fa1ZtBRtjRnh3FgsFysHm7bGxwG2nuS5o4=;\n\tb=eB3zH+W9z/F5g+amMRR9XTm+dlNTY+NJp/T7dxdftrauurUIN9qxYii4+pFntFV+ZZ\n\tVzeDr16MhpGq6rRxRUCPRsHb8noUcXn6JMm00x2XqhS2NekYIb08pGaYXcx0GRFTQaHq\n\t2PXOSJH2h7aMR5xF3d6FecHiwml0se441+cv7OmYiuysp7kVBAqJEAhsVcuZBZH9j01X\n\tlFVqG2jDOuZSvtaZhyvZ74rHaAfBMPPexx/rS2h+bO/1qnaPyx4X2NpcYeaiFS8ijvwZ\n\tOuCuVdSpqt0r6bBUt2XcDzoWAEtYBOP7PINwY9A5PTW+doPHfmmdsniICL7pBbA1iFYd\n\tV4GQ==","X-Gm-Message-State":"AOJu0YxDeP4vtR/49hkcPYKDdaaZ8+isN0lRtgExuW0a7CL4hyhNpYx6\n\tIoYhHz3aZ2UAzYxZXkphR/egV3Y2bdm218ZOEz9dOnCWYfz8crw0Lw5ThM8B/PmZv36AeuHqP/K\n\t6hWZH613AGCQyZPzKR8rmiM73GbccXYK94DTIcZifbhQX25da+dZOgl0=","X-Gm-Gg":"ASbGncvYqN7gnbc4fwcnl+Qk/7bwaLIpKpKEmNWj/Oviv4S/FpTvewNbUcKBMtx66cV\n\tnzHw7jr0QqUeHwO2Uy2RcAczqQn2RuUOgHS7ZB7PfdiLwKl8q2hH5mHXUHHVbhzdOZXwJ+Tlrou\n\tbd+pHknd0kXHpj4bwvI3Gql2pjhsGqbxIcxFS1FrJsJRH8UDigIaqynZOXHGXBPB5RuOwlROO+V\n\t9gOxyghcf1kz1zUrIDXQGuZ0zQyNegPt545WIumHCXY6emQtggm3YoKi/iW7xps8PmKREu8X1TI\n\tYtAI7DP3kT7p/XTOZu1ZpGlumw==","X-Google-Smtp-Source":"AGHT+IFKHrb+pdiZKIA7TmuF88cmz2zjNKFA3NYZE6D3ic2i0Qt9bNiybX/8mdKjombCSTHnqm2WLvO0Fq7FVMNYY9Q=","X-Received":"by 2002:a05:6102:3a08:b0:5db:25d3:28b4 with SMTP id\n\tada2fe7eead31-5db25d32992mr672496137.5.1761205272558; Thu, 23 Oct 2025\n\t00:41:12 -0700 (PDT)","MIME-Version":"1.0","References":"<20251017102704.3887-1-david.plowman@raspberrypi.com>\n\t<20251017102704.3887-6-david.plowman@raspberrypi.com>","In-Reply-To":"<20251017102704.3887-6-david.plowman@raspberrypi.com>","From":"Naushir Patuck <naush@raspberrypi.com>","Date":"Thu, 23 Oct 2025 08:40:36 +0100","X-Gm-Features":"AWmQ_bkuM5NF9SWt6gpiTTbTcpWKsLzhHfWn0ggkJCMs1mZF8A5aJcGEWbZ1qqg","Message-ID":"<CAEmqJPod+pZK1sKQ4tzjFzF4HepnpwXkBT5MLFcBUTVcDRNeMw@mail.gmail.com>","Subject":"Re: [PATCH 5/5] ipa: rpi: lux: Use floating statistics region to\n\tobtain the current Y value","To":"David Plowman <david.plowman@raspberrypi.com>","Cc":"libcamera-devel@lists.libcamera.org","Content-Type":"multipart/alternative; boundary=\"000000000000a5d3280641ce8e1d\"","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>"}}]