{"id":24702,"url":"https://patchwork.libcamera.org/api/patches/24702/?format=json","web_url":"https://patchwork.libcamera.org/patch/24702/","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":"<20251017102704.3887-6-david.plowman@raspberrypi.com>","date":"2025-10-17T10:05:41","name":"[5/5] ipa: rpi: lux: Use floating statistics region to obtain the current Y value","commit_ref":null,"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/24702/mbox/","series":[{"id":5509,"url":"https://patchwork.libcamera.org/api/series/5509/?format=json","web_url":"https://patchwork.libcamera.org/project/libcamera/list/?series=5509","date":"2025-10-17T10:05:36","name":"Fix and improve full image Y statistics","version":1,"mbox":"https://patchwork.libcamera.org/series/5509/mbox/"}],"comments":"https://patchwork.libcamera.org/api/patches/24702/comments/","check":"pending","checks":"https://patchwork.libcamera.org/api/patches/24702/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 A2EEFC3331\n\tfor <parsemail@patchwork.libcamera.org>;\n\tFri, 17 Oct 2025 10:27:17 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id 42FA3606B9;\n\tFri, 17 Oct 2025 12:27:17 +0200 (CEST)","from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com\n\t[IPv6:2a00:1450:4864:20::32a])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 79C33606B6\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 17 Oct 2025 12:27:12 +0200 (CEST)","by mail-wm1-x32a.google.com with SMTP id\n\t5b1f17b1804b1-47112edf9f7so9879285e9.0\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tFri, 17 Oct 2025 03:27:12 -0700 (PDT)","from localhost.localdomain ([2a06:61c0:f337:0:8aba:2a85:b765:a23e])\n\tby smtp.gmail.com with ESMTPSA id\n\t5b1f17b1804b1-47114428dedsm73811905e9.7.2025.10.17.03.27.11\n\t(version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256);\n\tFri, 17 Oct 2025 03:27:11 -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=\"M8zxcATJ\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=raspberrypi.com; s=google; t=1760696832; x=1761301632;\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=bUnSu+t3RNrIrvdREwuVjIn3DN+DaH8m2uKMtTtAbCk=;\n\tb=M8zxcATJWRM4HEh2Pt14805Ie6WnEbtGWhj65u9je4kJe8KoKXWWCt1XuoqwWArBG6\n\tdVCB/o4m3Azv8KIh3Kbvr0DHb2d9q2vnrd/khXv+d60me2pQlHODgTTW1VjMd1AL+pzh\n\tLFy8mXXG34I80ndyAPqpAzmJQD0MBiShwTTt+ZmyDXmWLZENtkrTuXouOie3Ncg8RvNL\n\tUqK/m6KKb+A4ZkK6JpeqbQBWuhdQBZCn5D7LiEm8UV0ZcNh/PYizHRmtJQtd/wO8gfjQ\n\tsMnEl+bEgplDZ5NyU9H4MLChPUqEMrXf+5oAcrkjlPZjeK7tBR3k52pVJogOeqnsf7CV\n\texDQ==","X-Google-DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/relaxed;\n\td=1e100.net; s=20230601; t=1760696832; x=1761301632;\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=bUnSu+t3RNrIrvdREwuVjIn3DN+DaH8m2uKMtTtAbCk=;\n\tb=qlJuN/KK1yMCwWyCGS6FWYYyGPtKJ0lZBMT6cO7/lOY9iuh5qzeWu38fQlZa4F/y94\n\t4rf962QZy40gtpfwI+jtx7KyIDLH+Y1drmyQe7jsLHJ8cE/mF0Pku6gYrskiE63rBODy\n\tqqJ55tREQZl25L5x8VNJDxaPztP38FSzUAbQoeNPSdByzSXg6MJsAwhsGCqq44Pm3bQV\n\tzOMhZye44PYrZI+G4m487LQa6GHOO1evFTkZwD5e6NjnkDxiJeBYHUe8e6nWZzZPgEtA\n\tJBWM6YK5i9v8tUUv13f+SCeSNXDvnsVLALmTY6dJCnjV40GPdIEHAKdGTgXnaI1Vbkvx\n\tcWJA==","X-Gm-Message-State":"AOJu0YwQ2rg0lyHSm8N1dhIC6dpER2hqDFkGTSg9MD+1gxGyUKgv0FMR\n\tbFqaHPfP4v2djRiQ2uJuZzFPl2vI7tKoGR6U9K1EtXYUqAqgp/3rn4EyaRL5RufSN6GCWsZPDX/\n\tR9qhGEEw=","X-Gm-Gg":"ASbGncs5uHOJSYf3s9wpfS6SieejrA32h+qJkZzKNIP17OaQmTw+yKtin7rG/ReXwy6\n\tgOhQk0LqY5EcoFpi9R9OP3I7Ixr5RuwgEf3mCcbQvbR9geN75jal6uK4ZC6r1zTu9SxT3lJ890F\n\tkD/1gb7nOE/TgWMGg8/+ZhoBcOMWe+EjhtnSVEvUKTfaCp56Mz+Xx6nxcjlSaSHJpKKBZWSQShD\n\t4FKEPDzbMD7PIpoQQLo+6f31ud5JntqgeFySibAMHE5Y+bizmpYwJwacFnq64xFxluu9PfSc79t\n\tRFHc7FU3dPWIYY/EIiM2Uidru1M6ixua+0quEU3nlhBJkj2cU05xkuuh6Cd2/KXoJJM1fnbgtWw\n\tbeISEI+oMP5cTiEHmbmVd2afFa9wnikp4tMpZH1t4INpoq9uAG/j7y/qv67GF6uAhBd/IvCsXSp\n\tu3Te8m2pPuFESRxo0sIohj5hmOJ6kmid44wwgg0yvPV72ARDc3Cbsc6Krm8xlPcT36tRqW0IOe4\n\t0IBp/sJQ5Bydk4=","X-Google-Smtp-Source":"AGHT+IHc96dZvnIy+ivIhioPBXE3tpIxyPyg3KKo7qoUUI3emrSZZbZjf1o8yBMqtqmtPiO65UIuVg==","X-Received":"by 2002:a05:600c:1994:b0:471:a73:9c49 with SMTP id\n\t5b1f17b1804b1-471178745fdmr26924515e9.2.1760696831741; \n\tFri, 17 Oct 2025 03:27:11 -0700 (PDT)","From":"David Plowman <david.plowman@raspberrypi.com>","To":"libcamera-devel@lists.libcamera.org","Cc":"David Plowman <david.plowman@raspberrypi.com>","Subject":"[PATCH 5/5] ipa: rpi: lux: Use floating statistics region to obtain\n\tthe current Y value","Date":"Fri, 17 Oct 2025 11:05:41 +0100","Message-ID":"<20251017102704.3887-6-david.plowman@raspberrypi.com>","X-Mailer":"git-send-email 2.47.3","In-Reply-To":"<20251017102704.3887-1-david.plowman@raspberrypi.com>","References":"<20251017102704.3887-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>"},"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>\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":["5/5"]}