From patchwork Thu Oct 23 11:49:13 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 24726 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id C213CC32CE for ; Thu, 23 Oct 2025 11:50:44 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AE18960763; Thu, 23 Oct 2025 13:50:42 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="L2VxCyfj"; dkim-atps=neutral Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 9F708606E0 for ; Thu, 23 Oct 2025 13:50:40 +0200 (CEST) Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-4270a0127e1so476435f8f.3 for ; Thu, 23 Oct 2025 04:50:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1761220240; x=1761825040; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=PSNl1fKNYqqrXL9+8+lTPsK2c3rNasItZ3vGAP/DQ3Q=; b=L2VxCyfjCa9x+W9X8kOXsI1mWQTTbYtvmk3+shC/vCV2Pp5x6JJBiuAdJ5dUVTinTQ 02Ua/k06WLIxdy9TvFrOW2aaaZFPPNeZufjwnmJHkHlT7BURMcAWJQycMnQdXxIQwiaP E2EmlSIVg1xuEdttM0reZYvXb2cCevxvwPTcu08eezmHXIXb8BaJ8DJaEePAev9+xZgi TIBnO9x0bo7nNEfntF+lQlMLJjV1rvLJvHX4zpQRwAysab4Z15rNn+9mc5RWKBbRKcwL zk4QqecGP1faFet1t9Ad+DnD4MThu6cpKRrXOK/Myh8v1gd4RiBvFMpXRp9xw5+i61sA xslw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761220240; x=1761825040; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=PSNl1fKNYqqrXL9+8+lTPsK2c3rNasItZ3vGAP/DQ3Q=; b=pDriTIV/E9hOV+GlCgtV3KuegblllczJclKOdpt6ieThgLUUkD4psuHcGPDYi4vAL5 OIxNoR2uMApYI6FtCqGxc4btVNEbhgfGUAfUhB7Jkmn0VXM+SDVAhGh5yvc+u53F9HF5 HP1cnH1Lby1NxT4wbbkIcO0RSAvIszCwg/PrmYm4GZnEIUjNLlbJjv0UcaiKc1Bdcs6O tli7PEkKcxO3jaDZfjSRG59255gAgZINKugXTwbU50KUj1FEHC3EeU9PxM+FC6+Zlf3I KNcMMwiVc3yNRgJ830ZuOi6ZoOmgP7/JRIefDNbK7QHFGLVn3RloiJ8ewyzneW56uADC qfLA== X-Gm-Message-State: AOJu0YwTU9158QKwJ52k/Yj4zwIYrrO/5Ax8kzomJ2lHzq3KYrhi7bTW dIGQ8X8JXth3cupAghSuTQ0rey/GC0mJzqdMsvytRofwzvCpj8y9eAlu5q20vYKO9nrsZ9Ypslr uPGQHvSA= X-Gm-Gg: ASbGncubCzowtAYSYAOFjoXoXtGMX6CBYmnKcBpM8zfg1ijsdmWay87LxDSGABZ+/7a AMo+zr9DTt2alzLzOnpyuIeOFKaJetqFjyLc+vlTxkZlo93lJC9W7pkqOS/BT0l+XwbaUu2SHeh 81meA4yCVzkHMAEGD4aXtIfV1Pi+jzcyLbgLKo4Zu9NjRy+xsfDoH5H/3rRl0sGSUEvgJuYmFLJ XUQhhyu5CEJYLEOunj8cX84isFpSNdgn8ZAI0x3+reIiPgfzssdAAcL3D/qDb2ZmKWcsejH1Vmu oc/B4JphjevGLwqTULn+Zld67JTQEmkS3f8Mb8cr5r18k/3gSa5IG/Rw4xBeKhFG9fS0074qtNN GCsuO4v6WqE5rDAW0iCRw9AXox7v/yIac22YULE22LJj0Uk5/nlEBifUOIAP1j2r/6Nn9jt6JiV 2RDX8NylAOiseN+/RkTPPwur3YDzt3ftjQmrYtyc9yCEX/g2YNg1FC8QB3a74uaefJzHwhx0eu2 uBiEEIGK6VC5+AidUlxir7s8Hnl X-Google-Smtp-Source: AGHT+IGbhRN+qq3Z9z6JiQW0ZVh8wg7+9uOnfl74KhmEkABF5sdfWdNBSEp9ZMlNcFK25UnndBzsRQ== X-Received: by 2002:a05:6000:612:b0:3fe:efa8:7f1d with SMTP id ffacd0b85a97d-42704d4431cmr14886080f8f.7.1761220239833; Thu, 23 Oct 2025 04:50:39 -0700 (PDT) Received: from davidp-pi.pitowers.org ([2a00:1098:3142:1f:f75f:a9a5:3eb7:34d4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4298b996aaasm1900760f8f.3.2025.10.23.04.50.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Oct 2025 04:50:39 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: David Plowman , Stefan Klug , Naushir Patuck Subject: [PATCH v2 1/5] ipa: rpi: Fix the set function for floating statistics regions Date: Thu, 23 Oct 2025 12:49:13 +0100 Message-ID: <20251023115034.2207-2-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 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" Previously it was calling the wrong internal function which would do nothing. Signed-off-by: David Plowman Reviewed-by: Stefan Klug Reviewed-by: Naushir Patuck --- src/ipa/rpi/controller/region_stats.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ipa/rpi/controller/region_stats.h b/src/ipa/rpi/controller/region_stats.h index c60f7d9a..0f8c276a 100644 --- a/src/ipa/rpi/controller/region_stats.h +++ b/src/ipa/rpi/controller/region_stats.h @@ -76,7 +76,7 @@ public: { if (index >= numFloatingRegions()) return; - set(numRegions() + index, region); + set_(numRegions() + index, region); } const Region &get(unsigned int index) const From patchwork Thu Oct 23 11:49:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 24727 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by patchwork.libcamera.org (Postfix) with ESMTPS id 71B63C3331 for ; Thu, 23 Oct 2025 11:50:46 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 6BC6A607E5; Thu, 23 Oct 2025 13:50:45 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="Iq+MKu92"; dkim-atps=neutral Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 1691A607CA for ; Thu, 23 Oct 2025 13:50:41 +0200 (CEST) Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-4270a3464bcso557403f8f.2 for ; Thu, 23 Oct 2025 04:50:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1761220241; x=1761825041; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=SVMDCIFmjD7WxzZUSX69iF9RZaDZQ5KpDvQNG78nIu8=; b=Iq+MKu92uISuNesYSDo06xiSn1BJGhMamOWNErTSXh0duAD2mKgFU63Ydd/pSYhExp NSporsK5hdb0F7c1ummC6GeWKionBG2U4ahSIX91lsuE+/WsW6nAwyNGnLkXf6iSm/ZZ vbNzntOwBIlkz48QqSgBTuuJ6MaQGKCH17jutQZyRjHUojHwFxlaEUpDnnpqaLK9IlKk P1QtZYxhXhNAug3W7NN3LFfwZSW2nW2fZpW3pjtST/ZCxCxjE4DHwxUFngkEMiZON7OU akm8PPYeamxXJcUraMxTC7CV0w6o7bniOuCKfAjmKMoerQ3nz+qYrgcVjnRH2wB5pRXJ /aAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761220241; x=1761825041; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=SVMDCIFmjD7WxzZUSX69iF9RZaDZQ5KpDvQNG78nIu8=; b=Pe1uroAcZFSv2nljSRno3yrjQk0r+024DgQl+3SHUeAQMr78fokrEw/EQQ9JW1vabL S41grTSUJdqhr3+o/yNo6VZ4sAvH7pG3encvG7pPxw1R83lk7OTFTHnlMYzY3/w3qWKF s8Tc04GdNVp2yyxXhMa9jkR9hEXTalrRbkflVy4AY7WHuL5m51Gn7cVhJyNRzB9fymzq D/myCDkHQ2bbhPj2bWjhjUbTCX+aE3pEq7tapk/uLBnURC5Uq+pNMyHTqwkXMF691RLH g189swVEkp8ZduDTU+X6/P85IkogWqMChnBBwDxK6lg576BAReW33ZBYDjL+LMrH95Y2 Og0w== X-Gm-Message-State: AOJu0YxTmfUbT1qyUCvVY9CFI6xzxfYoHtxsvbOllW/cBy9YXqn+zzbK /4SUAg6/198C8dbWvThaV+p9H5FIiIxHGpb1goTPZGLVIR/1Zyb2RWMyShKEW1pKYeJWxcXKnID Cjr8i0ZM= X-Gm-Gg: ASbGnct69EXG2JK6W9Q+nKoS5HccA/OhY1gYGwVEIvpwUzZfj+oxqabxmw7Lc0eWrZd BnZwwt6mW0rOANBCM52fD03X5ygUq2hzuPn4+bZxkHtlnNwK1FQL55EFQ998SbqeJ6Nqd4iMYbc GF93Atr0NL8MYEvF1uX2HUn476LuLTh6wRnh0/YEJhXVbY80ZEtd+aDLUIoXUa18XKkygG/KtGt gbIarJJcRrQNl41tz8pHyzyKGJSd1zuR1w65pCNuwHs64ciic1jdNa9l2VkgWeEJZTG27ilwtdO M97AufWunWw54WU+WRkT6MBS+fF4OI6fsizl/AKYoaDA/bwrVphnaiTftwPKyuZvt1i1uIWl9oQ rT3SjX+DbCxc/ktWMXShXFrlnt9HFTE9+HKGpSqX6CAdJ/zYy3q5SEXUsQkZs1RCDV4UjqwWtDs UDOx10hHWnrXI+Zj8Gbk78IBQnQ4i0APVg5+E/CniZf/Lf8TugV8dWiIp1sy+hGQv+ja2C2psEV N0qPxrix7ZPU8pa+A== X-Google-Smtp-Source: AGHT+IEh2jDPJUwmqChoV8H5GQ51WNy79xQP2n67V5xeX0gJtKHGRFEtZKkUiBhEKaMYC1ZwNlNlNQ== X-Received: by 2002:a5d:5f82:0:b0:3eb:5245:7c1f with SMTP id ffacd0b85a97d-42704d7ea04mr13991409f8f.2.1761220240957; Thu, 23 Oct 2025 04:50:40 -0700 (PDT) Received: from davidp-pi.pitowers.org ([2a00:1098:3142:1f:f75f:a9a5:3eb7:34d4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4298b996aaasm1900760f8f.3.2025.10.23.04.50.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Oct 2025 04:50:40 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: David Plowman , Stefan Klug , Naushir Patuck Subject: [PATCH v2 2/5] ipa: rpi: lux: Handle camera mode sensitivity correctly Date: Thu, 23 Oct 2025 12:49:14 +0100 Message-ID: <20251023115034.2207-3-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 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" The camera mode sensitivity needs to be taken into account for the lux calculation. For example, the IMX708 binned mode (with a sensitivity of 2.0) would otherwise show double the correct lux value. Signed-off-by: David Plowman Reviewed-by: Stefan Klug Reviewed-by: Naushir Patuck --- src/ipa/rpi/controller/rpi/lux.cpp | 13 +++++++++++-- src/ipa/rpi/controller/rpi/lux.h | 3 +++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/src/ipa/rpi/controller/rpi/lux.cpp b/src/ipa/rpi/controller/rpi/lux.cpp index 27b89a8f..acaa6e57 100644 --- a/src/ipa/rpi/controller/rpi/lux.cpp +++ b/src/ipa/rpi/controller/rpi/lux.cpp @@ -20,7 +20,7 @@ LOG_DEFINE_CATEGORY(RPiLux) #define NAME "rpi.lux" Lux::Lux(Controller *controller) - : Algorithm(controller) + : Algorithm(controller), sensitivity_(1.0) { /* * Put in some defaults as there will be no meaningful values until @@ -68,6 +68,13 @@ void Lux::setCurrentAperture(double aperture) currentAperture_ = aperture; } +void Lux::switchMode(CameraMode const &cameraMode, [[maybe_unused]] Metadata *metadata) +{ + /* We will need to compensate for the camera sensitivity. */ + ASSERT(cameraMode.sensitivity); + sensitivity_ = cameraMode.sensitivity; +} + void Lux::prepare(Metadata *imageMetadata) { std::unique_lock lock(mutex_); @@ -88,10 +95,12 @@ void Lux::process(StatisticsPtr &stats, Metadata *imageMetadata) double yRatio = currentY * (65536 / stats->yHist.bins()) / referenceY_; double estimatedLux = exposureTimeRatio * gainRatio * apertureRatio * apertureRatio * - yRatio * referenceLux_; + yRatio * referenceLux_ / sensitivity_; + LuxStatus status; status.lux = estimatedLux; status.aperture = currentAperture; + LOG(RPiLux, Debug) << ": estimated lux " << estimatedLux; { std::unique_lock lock(mutex_); diff --git a/src/ipa/rpi/controller/rpi/lux.h b/src/ipa/rpi/controller/rpi/lux.h index da007fe9..db2227e4 100644 --- a/src/ipa/rpi/controller/rpi/lux.h +++ b/src/ipa/rpi/controller/rpi/lux.h @@ -10,6 +10,7 @@ #include +#include "../camera_mode.h" #include "../lux_status.h" #include "../algorithm.h" @@ -23,6 +24,7 @@ public: Lux(Controller *controller); char const *name() const override; int read(const libcamera::YamlObject ¶ms) override; + void switchMode(CameraMode const &cameraMode, Metadata *metadata) override; void prepare(Metadata *imageMetadata) override; void process(StatisticsPtr &stats, Metadata *imageMetadata) override; void setCurrentAperture(double aperture); @@ -40,6 +42,7 @@ private: double currentAperture_; LuxStatus status_; std::mutex mutex_; + double sensitivity_; }; } /* namespace RPiController */ From patchwork Thu Oct 23 11:49:15 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 24830 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by patchwork.libcamera.org (Postfix) with ESMTPS id AFFBCBE080 for ; Sun, 26 Oct 2025 23:32:02 +0000 (UTC) Received: from pendragon.ideasonboard.com (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 13F58AB4 for ; Mon, 27 Oct 2025 00:30:15 +0100 (CET) Authentication-Results: perceval.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.a=rsa-sha256 header.s=google header.b=E72KPq++; dkim-atps=neutral Delivered-To: kbingham@ideasonboard.com Received: from perceval.ideasonboard.com by perceval.ideasonboard.com with LMTP id OK0VGTUW+mgSUhcA4E0KoQ (envelope-from ) for ; Thu, 23 Oct 2025 13:49:09 +0200 Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by perceval.ideasonboard.com (Postfix) with ESMTPS id 1103E1AA6; Thu, 23 Oct 2025 13:49:03 +0200 (CEST) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 0BE7C607DB; Thu, 23 Oct 2025 13:50:47 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="E72KPq++"; dkim-atps=neutral Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id D87E4607D9 for ; Thu, 23 Oct 2025 13:50:42 +0200 (CEST) Received: by mail-wr1-x42b.google.com with SMTP id ffacd0b85a97d-3ee64bc6b90so596154f8f.0 for ; Thu, 23 Oct 2025 04:50:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1761220242; x=1761825042; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=i2AVjQETpTL9rS5lEaiFVmW3N5s72qqdEqXQEPC35yg=; b=E72KPq++0rE7gwL62Fts6J6UvQWan0C205Yt3/XfmWQy3YarPo6PEZ2bs37jY2NRJM I3ustot0UJbj9mY9IxZfkQokwPg/IQStJdJulHUrWpXmQn6bhT5CuFIsSINu9C/8Q+2q xtCQVwNSEqPalsxf5PD/01nL4l2y9zS0+/Hjd+yCosBTWSJFPcWYD4dWF1iD6gkHRafo AqelM7faN9nVxBGZ2Cy+3Buf2EiCmtAc40mqXRESpyQz8teimy39fRdYCaS2OhY6Ezsz smuPf4OQHnQGxyoS93yRMS2WFE1f2rhv5dFYNzkUnZpsDQ1yE7N79Qg2Gja0EGv7/86L 79Gw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761220242; x=1761825042; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=i2AVjQETpTL9rS5lEaiFVmW3N5s72qqdEqXQEPC35yg=; b=R8m8PHElI1T1oersVMT+1D6UBF/2mi72Zmp6M2Mr32cnptQDywHlliincPvVZ/TES0 dgA3kKqI3cu7XAXVttOE1LdHLcXKUCDqGz3XH4kVTS7bEbsbDi1jMoVOSgnm8dKk4Oyt sDRhimeO2zabR+y9Dj3BYbJNzMNhdD0wcXxDl2PdJlWirO+dRC39tzzFya3TvIDhYZtk mfx+RnhpWk5e/qpiTkPfWPd4T/GgEnjqV6GxGvhYNcjxWKBjkxpTAE2e/3NDLTcJir7i zJ9x7Cad2JPE0BDU/V7/tYquOjOp5RE8peO3F/Wux6emiF7Ksn2tO3t2MsiauaI2WKAk iplA== X-Gm-Message-State: AOJu0YwN10DPqzFEzjq/CY7jJjFR3XccV7iQw+Qn6C1vqYvsEgwQMjQs hrR9+FQrZQwWY7hYMyNccKZHPc0gVEzx0F1Io55ncvqgEr8khCeTOKYQMjRLh1PTGubA4tBsXnW 1DvumziA= X-Gm-Gg: ASbGncu3B/xZx+3yERLuiirYcXD064jmkWADFDqsNTMArasVkJuMeGMgN1EHT+ATy4F fhDUhHUamfWOjevjYWEbNe8+bkHmPhkQnevNzWl0MNWm1ZDwxeodrXHoa+feFgtfrHAKBkVcPk8 ud4761jYRF/YQpqA9frDhTYQb1ogLHoT/aZiMjcv3ZY16eS6ub6BFsTr8VDfRrKrUpo7CwsqUtn P7KH8WLGGPve8WLtzUCWFFREx9fCRcaDRWXkQ5U8tmqG/1WdRx9u8qA5X+Zfh6h1aCLi7pWZONq xhS48VBmKMPESY8wvqV+5jEPZA5smqRATIxLiD1iw2zH4fDWsFiPVW9gb9dNNG4fr0FzZfphaT0 vJRR/y/0FPwmaCjV2WTxrHVEXVHKKDlvGO7qqinnqD7LxSXGONgp0PYzIsFXhTQ68d0IbH3x/Az iNfKlQzvsWple9paVruPAMoqhmB6x56dkAMWS71XLMsh5mLcO9c3zUVAsh+EeWuwGsR1Z9Xgu+I /R6lKtyVc58Z3Zp7FP8MDNLYaif X-Google-Smtp-Source: =?utf-8?q?AGHT+IGpfspp7BvS4ewcfI448Jgmchg2yWKZoSNOF?= =?utf-8?q?ZLBZ/Ohdlp7blPSVldPxLaUns4HMK2VbuB+xg=3D=3D?= X-Received: by 2002:a05:6000:420e:b0:3ec:db8b:cbf1 with SMTP id ffacd0b85a97d-42704d900a9mr16829375f8f.24.1761220241989; Thu, 23 Oct 2025 04:50:41 -0700 (PDT) Received: from davidp-pi.pitowers.org ([2a00:1098:3142:1f:f75f:a9a5:3eb7:34d4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4298b996aaasm1900760f8f.3.2025.10.23.04.50.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Oct 2025 04:50:41 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: David Plowman , Stefan Klug , Naushir Patuck Subject: [PATCH v2 3/5] ipa: rpi: pisp: Use a floating region to get whole image Y statistics Date: Thu, 23 Oct 2025 12:49:15 +0100 Message-ID: <20251023115034.2207-4-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 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" X-TUID: t1/H0G7Fme3r Resent-From: Kieran Bingham Resent-To: parsemail@patchwork.libcamera.org Floating regions are currently unused on the PiSP platform, so we can use one of them to get an average Y value for the whole image. If an algorithm (such as the "lux" algorithm) wants a scene-referred estimate of absolute brightness, then this would be a better choice than a value from Y histogram as the latter is not invariant to the metering mode (e.g. centre-weighted, spot etc.). (So note that for the AGC/AEC algorithm, where the metering mode is relevant, the Y histogram is the appropriate choice.) We also fix the loop that copies the hardware's floating region values into our statistics structure; it was using the wrong limit which was causing it not to do anything. A future commit will update the lux algorithm to use this feature. Signed-off-by: David Plowman Reviewed-by: Stefan Klug Reviewed-by: Naushir Patuck --- src/ipa/rpi/pisp/pisp.cpp | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/ipa/rpi/pisp/pisp.cpp b/src/ipa/rpi/pisp/pisp.cpp index bb50a9e0..2ba879c1 100644 --- a/src/ipa/rpi/pisp/pisp.cpp +++ b/src/ipa/rpi/pisp/pisp.cpp @@ -467,7 +467,7 @@ RPiController::StatisticsPtr IpaPiSP::platformProcessStats(Span mem) /* AGC region sums only get collected on floating zones. */ statistics->agcRegions.init({ 0, 0 }, PISP_FLOATING_STATS_NUM_ZONES); - for (i = 0; i < statistics->agcRegions.numRegions(); i++) + for (i = 0; i < PISP_FLOATING_STATS_NUM_ZONES; i++) statistics->agcRegions.setFloating(i, { { 0, 0, 0, stats->agc.floating[i].Y_sum }, stats->agc.floating[i].counted, 0 }); @@ -985,6 +985,12 @@ void IpaPiSP::setStatsAndDebin() */ setHistogramWeights(); + /* Configure the first AGC floating region to cover the whole image, for the lux algo. */ + pisp_fe_floating_stats_config floatingStatsConfig = {}; + floatingStatsConfig.regions[0].size_x = mode_.width; + floatingStatsConfig.regions[0].size_y = mode_.height; + fe_->SetFloatingStats(floatingStatsConfig); + pisp_be_global_config beGlobal; be_->GetGlobal(beGlobal); From patchwork Thu Oct 23 11:49:16 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 24831 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by patchwork.libcamera.org (Postfix) with ESMTPS id D37E2BE080 for ; Sun, 26 Oct 2025 23:32:10 +0000 (UTC) Received: from pendragon.ideasonboard.com (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 77B98AB4 for ; Mon, 27 Oct 2025 00:30:23 +0100 (CET) Authentication-Results: perceval.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.a=rsa-sha256 header.s=google header.b=ttBM8ABS; dkim-atps=neutral Delivered-To: kbingham@ideasonboard.com Received: from perceval.ideasonboard.com by perceval.ideasonboard.com with LMTP id WNtiFDcW+mhDUhcA4E0KoQ (envelope-from ) for ; Thu, 23 Oct 2025 13:49:11 +0200 Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by perceval.ideasonboard.com (Postfix) with ESMTPS id 7B7761D2B; Thu, 23 Oct 2025 13:49:04 +0200 (CEST) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 11D81607BE; Thu, 23 Oct 2025 13:50:48 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="ttBM8ABS"; dkim-atps=neutral Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 0B66E607BE for ; Thu, 23 Oct 2025 13:50:44 +0200 (CEST) Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-428564f8d16so368484f8f.1 for ; Thu, 23 Oct 2025 04:50:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1761220243; x=1761825043; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=MT+p1j+p/DveVI+kn0QiagoZ5EXuJnmCwmRZyRj4aXA=; b=ttBM8ABS2gj2I4AmuLSIPCZ6sJgLWGG7sNDlySGR6chfJyE/gzOp0/x2rQQtc9qzRk GmPeaXqc56TAgB/nVeTbI84jlq3W7TpFdggODx8w7iOxe7YBqKcArTwbkeyoR7o4bc2V AdurNiHmoShRwnrxhN5zE3rOsNERWgIKVv/Tt1HL7mpgBa3nbv9Sdza5KI4Hpv/RZ01F O8nCmRQTzmHLQCUcVAwROm+bf83xRAORCpJAsmPsk+5bBuIGgkkAo/Ma9w4YJCAt2hhU 7NQrT6Jiac1tJTo1nG6OMbON83y/l7v8yvB5Ex/3gbd13uIdyT9Cd+4r+x2oi7mu20t2 AxhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761220243; x=1761825043; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MT+p1j+p/DveVI+kn0QiagoZ5EXuJnmCwmRZyRj4aXA=; b=ck2WDHdkKm6Kn6arkXqJi9KBFLyjGgbblcEEL5CTbajFQ+WfqMrjEGVMcZ+qj0atwe oDNButMXvZsUEkGjYlkK1jlDDXaas4qORVdysjYShJP5I5uRSzAGo7rWUD4VzzmdZFO0 8tWrlSxt792pcjciPWZefNcTOvKjB2BCe+rbZV7CCtsiIQeugXWoHWV7wEXgezZ2gT8M ue10ZWYO5KmcxCfj5V7JICwrP76H3zsNTduqLxUWkQEmE+bGGeO5ZPcolH519BxuRX9q raoG9QL3MIQH6UilzcARVJL2hRnjruSv1Cx5mWNRay21qTt/25Ttrydgb6MHBaeIn1bJ cZyw== X-Gm-Message-State: AOJu0Yy/MDizx/oB80vU7nzRac3JDy+mmWS4zN8xmO+7JE0dMz+JHTHH FdzC6SznQPwfCm014qzDQHlE4LQfqxR1QBc3be1KfoXCLe7Msk4LFo0V6amy7aQ5LbNyjFrRJag MpzOTR6w= X-Gm-Gg: ASbGncsOKkJ4DfoQ/KH33QQsMIft0i0+x1QZu5Dj4mfSBkb4iPM4kVu7Czat8Ngb+B5 Ocaal6+ZIseHiCetU/se5NxiVld1o4iWssOhjV4oy3zKeK0mEluR8XAT8Huz8we9n7lVt1nnZhx s4HzTp3VJ15MChRmYk4ZSc+mHiLxBg+cOovnG8R1U6b98rBu9uKc/cc9CeGjQm7cHGEwphec51C cH7XHDZkVv4ot9nIbXyan3opKF3G87FIrJYLq/tq4JC9Qg9UzVdFPxZKhSygEliS0JbzF/FWPzx r289Gv+gMPmyhKR/ACLIk4CZa3wL/CTBhpr9QWnMFYY/7NnjcdFFhDd0ugOGE8HGU8tzTr2muab +8X4LNAqarPjJ9QmqK77eyGdEa9txhwicfYWAUyB8KPrbT4cL2XQKdrKQuRi/jLlwwMCmlEX5C1 FKcDyQBmtnTedo98UaPLLbf+OZpFyP1HuBL1M2mPomswV7GoxWZ+vH96trM9WJGqDjI0hgXl+Be XFTdTNOnx0FuEupgw== X-Google-Smtp-Source: =?utf-8?q?AGHT+IFFHOrG209SMiJEKUxtd+91iRl5RdS9mZ5yD?= =?utf-8?q?2WE/IG+0rrfKmIiFl9zQnQUQOmteaueaQjufA=3D=3D?= X-Received: by 2002:a05:6000:40dd:b0:427:548:6e3b with SMTP id ffacd0b85a97d-42853264540mr5156729f8f.13.1761220243149; Thu, 23 Oct 2025 04:50:43 -0700 (PDT) Received: from davidp-pi.pitowers.org ([2a00:1098:3142:1f:f75f:a9a5:3eb7:34d4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4298b996aaasm1900760f8f.3.2025.10.23.04.50.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Oct 2025 04:50:42 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: David Plowman , Stefan Klug , Naushir Patuck Subject: [PATCH v2 4/5] ipa: rpi: vc4: Use a floating statistics region for a full 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 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" X-TUID: 56uNb2kcEtX5 Resent-From: Kieran Bingham Resent-To: parsemail@patchwork.libcamera.org We're going to use a "floating statistics region" to store a full image Y sum. The VC4 platform actually has no floating region for this, but we can synthesize such a region as follows in software. We know that the 15 AGC regions that we do have are arranged to cover the whole image, and they cannot be changed. Adding up the R, G and B values here will get us most of the way to Y. But we do also need to know the most recent colour gains, so code must also be added to remember the last AWB status. With this change, algorithms can now look at the first floating region on both VC4 and PiSP platforms to get a full image Y average value. Signed-off-by: David Plowman Reviewed-by: Stefan Klug Reviewed-by: Naushir Patuck --- src/ipa/rpi/vc4/vc4.cpp | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/src/ipa/rpi/vc4/vc4.cpp b/src/ipa/rpi/vc4/vc4.cpp index ba43e474..19d7b9d8 100644 --- a/src/ipa/rpi/vc4/vc4.cpp +++ b/src/ipa/rpi/vc4/vc4.cpp @@ -43,6 +43,9 @@ public: IpaVc4() : IpaBase(), lsTable_(nullptr) { + lastAwbStatus_.gainR = 1.0; + lastAwbStatus_.gainG = 1.0; + lastAwbStatus_.gainB = 1.0; } ~IpaVc4() @@ -81,6 +84,9 @@ private: /* LS table allocation passed in from the pipeline handler. */ SharedFD lsTableHandle_; void *lsTable_; + + /* Remember the most recent AWB values. */ + AwbStatus lastAwbStatus_; }; int32_t IpaVc4::platformInit([[maybe_unused]] const InitParams ¶ms, [[maybe_unused]] InitResult *result) @@ -144,8 +150,10 @@ void IpaVc4::platformPrepareIsp([[maybe_unused]] const PrepareParams ¶ms, std::unique_lock lock(rpiMetadata); AwbStatus *awbStatus = rpiMetadata.getLocked("awb.status"); - if (awbStatus) + if (awbStatus) { applyAWB(awbStatus, ctrls); + lastAwbStatus_ = *awbStatus; + } CcmStatus *ccmStatus = rpiMetadata.getLocked("ccm.status"); if (ccmStatus) @@ -226,7 +234,13 @@ RPiController::StatisticsPtr IpaVc4::platformProcessStats(Span mem) LOG(IPARPI, Debug) << "No AGC algorithm - not copying statistics"; statistics->agcRegions.init(0); } else { - statistics->agcRegions.init(hw.agcRegions); + RgbySums fullImage; + uint32_t countedSum = 0; + uint32_t notCountedSum = 0; + /* We're going to pretend there's a floating region where we will put a full image Y sum. */ + const unsigned int numFloating = 1; + + statistics->agcRegions.init(hw.agcRegions, numFloating); const std::vector &weights = agc->getWeights(); for (i = 0; i < statistics->agcRegions.numRegions(); i++) { uint64_t rSum = (stats->agc_stats[i].r_sum << scale) * weights[i]; @@ -237,7 +251,20 @@ RPiController::StatisticsPtr IpaVc4::platformProcessStats(Span mem) statistics->agcRegions.set(i, { { rSum, gSum, bSum }, counted, notcounted }); + + /* Accumulate values for the full image Y sum. */ + fullImage.rSum += stats->agc_stats[i].r_sum << scale; + fullImage.gSum += stats->agc_stats[i].g_sum << scale; + fullImage.bSum += stats->agc_stats[i].b_sum << scale; + countedSum += stats->agc_stats[i].counted; + notCountedSum += stats->agc_stats[i].notcounted; } + + /* The "floating" region has the Y sum for the entire image. */ + fullImage.ySum = fullImage.rSum * lastAwbStatus_.gainR * 0.299 + + fullImage.gSum * lastAwbStatus_.gainG * 0.587 + + fullImage.bSum * lastAwbStatus_.gainB * 0.114; + statistics->agcRegions.setFloating(0, { fullImage, countedSum, notCountedSum }); } statistics->focusRegions.init(hw.focusRegions); From patchwork Thu Oct 23 11:49:17 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 24832 Return-Path: X-Original-To: parsemail@patchwork.libcamera.org Delivered-To: parsemail@patchwork.libcamera.org Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by patchwork.libcamera.org (Postfix) with ESMTPS id D12D9BE080 for ; Sun, 26 Oct 2025 23:32:18 +0000 (UTC) Received: from pendragon.ideasonboard.com (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 78721AB4 for ; Mon, 27 Oct 2025 00:30:31 +0100 (CET) Authentication-Results: perceval.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.a=rsa-sha256 header.s=google header.b=FTNSb55g; dkim-atps=neutral Delivered-To: kbingham@ideasonboard.com Received: from perceval.ideasonboard.com by perceval.ideasonboard.com with LMTP id gNKrEDgW+mgSUhcA4E0KoQ (envelope-from ) for ; Thu, 23 Oct 2025 13:49:12 +0200 Received: from lancelot.ideasonboard.com (lancelot.ideasonboard.com [92.243.16.209]) by perceval.ideasonboard.com (Postfix) with ESMTPS id A29EB195E; Thu, 23 Oct 2025 13:49:05 +0200 (CEST) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B5619607D9; Thu, 23 Oct 2025 13:50:49 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="FTNSb55g"; dkim-atps=neutral Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 3BEC5607E2 for ; Thu, 23 Oct 2025 13:50:45 +0200 (CEST) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-4270a3464bcso557449f8f.2 for ; Thu, 23 Oct 2025 04:50:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1761220244; x=1761825044; darn=lists.libcamera.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=as/dlgHutMADg0GvxNPvuAiya+JaZBMlt2Qk/YuhrOQ=; b=FTNSb55gRUZgNYQVZ+DzC0qA9igfIH0qiQM35xLZc67hH3W0Y63yTi3/RHlR1GG8rE yBjafNhdc48mPK+VqDOMdO/GsbKeXXgvWL/qc2S2efSckM+BnxDWW4xtbAgf7IlWAOIc caV9kz6kfB+Ryp6fFsyI0wyFW4NI638pfUtli4qZEbKVVA5nKgxr9MbQt2RRR+0wQF2V Krn1j464KBx6S/h/3rCORMlCdmxoQs7CiQJPfZxJmBVy2L7aQh8sREAZrGCfeAH/WSVO OQJyCX295aac16bS5VDuETY6jA8BrzNKT6eluIuV2CddnJPtvtzPHn8QSLdZM3Mk0++/ g/zw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1761220244; x=1761825044; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=as/dlgHutMADg0GvxNPvuAiya+JaZBMlt2Qk/YuhrOQ=; b=xD4b+wtESAjORcPzPxVQGSomLUW1hBB+Fa1ubP6LCnR7XioALv2ooblYg/OL8nqRvP 6Pr1/JggoBUdkL+eUjt5wadTIZo8INlqPoE6d/SleNf9BcpZoiO7Th1vi2Vk04REb2VT sNo6xOubWyQqcKDqDPjfh2Bt//leEK1j2G7evGoCf0RnOX4hrbGjaLVlj84OXiMPsRdY khR4MU7P6J5f63Ur/ojavUm3zSPIw9EAwSXuWkdeNvaAJrpUjnLAPqroFgwQJ6HV6H6A I+OyHahWooHnljWCRiC0/4H2k0mBvtCWDFzP3dVmIJ4jGK1o6+SCHcq5vSB5xwL7kRFX dqgw== X-Gm-Message-State: AOJu0Yyg6ZhWWOo32cVwdehsxIBs/wRlK8zH9AEzcxdZ7p5QwTQnoD/J QtsUk2LAkU1+Pz3milJo7mB0Lyb6uhtRq4bur/KK1c3p01HXxM8N84QORmSQLdyjDCzZ8qn/+E+ D4JS0zDg= X-Gm-Gg: ASbGnct3JBpkBpKtr8c/ozz0MxQmyTuX4tKJE+2CdiJ5nc8rR3lmKJIMkExb//rvvIv EHHwH68rLRSt9+4ejlyIxlRWTqVqY46r4t9a9xb/ArogiOu1mN/2QSty5w7OvbAI+mUsw2dylSj i5+K9ewj+lJxjJiT8jEmD45SgqOJh+zJyBixQvdsfqvOfAQ7tWtoR2O1WCO4ELPX7i3lk7QF48r GC4AgH5wgiKhxxaKiXA3t8csmPXoMwMJk/JJhKwg+JetyJWMpdTH57QzZpx+xjej9/DhlfGOvEp Cd26Z6X1r5XCcCMkG5X4gbkIuHyzdnflFoKpifRAWTSfHU4k8d3sII4oIJxUdNXF7HtwCNP4YCd Z2+wHT3jBIKqwx2nyJsFvbgFSwpRX0YiSWra2mQ5S67rcZfxaJkcLfCGChIm39QQjAZOZbd2LoP 0ZjhpbP6Qm1bJmq4mekWUQeGop7LTXhtYLscjIfBIw69AiNVsFa8zQ9rg5YFdlyVJsWswVQkk5O y5JP9gTOftsWMqXnquxqra6vCil X-Google-Smtp-Source: =?utf-8?q?AGHT+IHohmDJnA4cG775UG4vnQLI6IKSUKZlFnOoT?= =?utf-8?q?KKTnjUanYm60oP/gwFBf6sUZJYPZmqan5jOlw=3D=3D?= X-Received: by 2002:a05:6000:22c5:b0:3f2:b077:94bc with SMTP id ffacd0b85a97d-42704d7e9c4mr14986826f8f.4.1761220244381; Thu, 23 Oct 2025 04:50:44 -0700 (PDT) Received: from davidp-pi.pitowers.org ([2a00:1098:3142:1f:f75f:a9a5:3eb7:34d4]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4298b996aaasm1900760f8f.3.2025.10.23.04.50.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Oct 2025 04:50:43 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: David Plowman , Stefan Klug , Naushir Patuck Subject: [PATCH v2 5/5] ipa: rpi: lux: Use floating statistics region to obtain 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 X-BeenThere: libcamera-devel@lists.libcamera.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: libcamera-devel-bounces@lists.libcamera.org Sender: "libcamera-devel" X-TUID: ndbV0lihDIXp Resent-From: Kieran Bingham Resent-To: parsemail@patchwork.libcamera.org The Y value from the first floating region is now a better choice for a Y value that is invariant to (for example) the metering mode. Both VC4 and PiSP platforms store full image Y statistics here. Signed-off-by: David Plowman Reviewed-by: Stefan Klug Reviewed-by: Naushir Patuck --- src/ipa/rpi/controller/rpi/lux.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/ipa/rpi/controller/rpi/lux.cpp b/src/ipa/rpi/controller/rpi/lux.cpp index acaa6e57..7dab27cc 100644 --- a/src/ipa/rpi/controller/rpi/lux.cpp +++ b/src/ipa/rpi/controller/rpi/lux.cpp @@ -85,14 +85,21 @@ void Lux::process(StatisticsPtr &stats, Metadata *imageMetadata) { DeviceStatus deviceStatus; if (imageMetadata->get("device.status", deviceStatus) == 0) { + /* + * We've set up the first floating AGC region to collect full image stats. This + * is a better choice than the Y-histogram, for example, because it's invariant + * to the metering mode (and cheaper to evaluate). + */ + auto const &fullImageStats = stats->agcRegions.getFloating(0); + double currentY = static_cast(fullImageStats.val.ySum) / fullImageStats.counted; + double currentGain = deviceStatus.analogueGain; double currentAperture = deviceStatus.aperture.value_or(currentAperture_); - double currentY = stats->yHist.interQuantileMean(0, 1); double gainRatio = referenceGain_ / currentGain; double exposureTimeRatio = referenceExposureTime_ / deviceStatus.exposureTime; double apertureRatio = referenceAperture_ / currentAperture; - double yRatio = currentY * (65536 / stats->yHist.bins()) / referenceY_; + double yRatio = currentY / referenceY_; double estimatedLux = exposureTimeRatio * gainRatio * apertureRatio * apertureRatio * yRatio * referenceLux_ / sensitivity_;