From patchwork Fri Oct 17 10:05:37 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 24698 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 75054C3259 for ; Fri, 17 Oct 2025 10:27:13 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id B7220606BD; Fri, 17 Oct 2025 12:27:10 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="g1kpg2R1"; 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 6EDB960697 for ; Fri, 17 Oct 2025 12:27:09 +0200 (CEST) Received: by mail-wr1-x429.google.com with SMTP id ffacd0b85a97d-421851bcb25so962873f8f.2 for ; Fri, 17 Oct 2025 03:27:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1760696829; x=1761301629; 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=/2QN7fWMQGXqIpyN9QKsxBjaJCwKW5I0LT90q69/hIo=; b=g1kpg2R13+qemDB6Dpclo3E9YDWN/UXB6vvTP7d79sEKzuUOMklh/Sdov/7r+oeXHo xF5uAIrCN2+Sse9II7vV6uNzhJD8vHnVJmc6XuzVkYTiVPmyzXzBgmRFv6n0Ia3hU/d8 SlBPaIFXJT972QXCGD64u+yQYX3M1b2f42IfRpCNEeDCboTdPPja2v6xIMKke9ifQmpp BxxJrvtjZzz7/3kf0p7w5ScQt4rP/9zP/OrV47YUoiEIvJu9egB7vZoze1h6yfDDTnc2 ZKxoPM7sLgaahNm/ixB7Hm8ri5zBfVsBArupv9QN8CJ6VLynU5BSppXvquXEdL80bgk/ F+2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760696829; x=1761301629; 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=/2QN7fWMQGXqIpyN9QKsxBjaJCwKW5I0LT90q69/hIo=; b=B2xZF3V71GFIIF7mSltnPkQ4X66mFEhGvoBoSO+G3gBOhtLtuTNCNBfad6CuX53xx4 qTTgZ7gDf1IU3HjcjXm2CD1WQayNF75FPMSkRADezncMj3kiN4zF6/UoRcU5R5KOeCZ3 JloDc5AKgh5z8AsdTY0YOnngnLiDaguWkD8aUjAknWeF/yIfBg/FogKmULU5An2yWekW JdNQ3l8w8PhCLzTPH2dcgExEUqU5rnOxIVTdOwti8UTEhcDF8z1GNFZUZCWBogdP11up e9xNEqXvQnD6HoEbev4IiGzo2I4Kib74spKRU6c7L+IDjyQXUz3cZEX/qfFOsAPksUU9 /ZUg== X-Gm-Message-State: AOJu0YyL1af2dOIVmalZC+rhYUuGD2fgK0HNopxflrKIMOyFln88IiZG IXkWyAj4rSWDqy3ZbRrAE5fO4wBCP27OFbyJ7zWp6eQk8vKj0lqUha4l68b/JeialnLiYKLBo1Z n68z4Jys= X-Gm-Gg: ASbGncvN3+/YAsArEVgD8nH91e84NDo/Vc72LG1TGgRfMr8KW/a3exLTiR+gUtJ8CDT lhtedf22nsQwyu5/Kc+5ZKDgRAjE/nqNJ8R3Ov1PNqu3QjaNjj58RPHubwXXWApq2V5gg6jRM6h lPHGXf4cxZpUhm5DEGAUIelOS2RQxl8mw/cGN/CPMUh4WcGwves5vx4hYWGlDP0573oRCqEjq57 GazhAjeaELFpzm5ltR54o7W0SBe2pU0T3MlCSg6h+Vp3VckvfATYGJP2DMvn5eix6Hy1oM7+R0r psrorR43rQ31Kjv7Vlf1HanswBfhTQu7SLqdGIal6K/eZpWJ6kzd4mpjpreDJEwtpMUY+amszIu bTiDd3n0bxzEv4BYCqQ+3rG6KnoS8nLSBJ2UC9kPmAPvQRdaF4iPBAKm81eKUwLmJP/qrXdeYF0 e1uAHBbVEzx5jJDSaBE9FvuMTUASGhzEmC/+QvsDJPwGXClSa4MqLVR31P25f54I5rqty1sQu4p WgQvjgCrD+M9cg= X-Google-Smtp-Source: AGHT+IFxLIgTn9cS09Wodb0g/3DTznwGYvtHMoRgIaXgKcXOwl71mJaiRWdjKofwZQ9aShP52NDyHQ== X-Received: by 2002:a05:6000:200f:b0:401:5ad1:682 with SMTP id ffacd0b85a97d-42704d521e8mr2130346f8f.14.1760696828656; Fri, 17 Oct 2025 03:27:08 -0700 (PDT) Received: from localhost.localdomain ([2a06:61c0:f337:0:8aba:2a85:b765:a23e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47114428dedsm73811905e9.7.2025.10.17.03.27.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Oct 2025 03:27:07 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: David Plowman Subject: [PATCH 1/5] ipa: rpi: Fix the set function for floating statistics regions Date: Fri, 17 Oct 2025 11:05:37 +0100 Message-ID: <20251017102704.3887-2-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 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 Fri Oct 17 10:05:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 24699 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 35746C3259 for ; Fri, 17 Oct 2025 10:27:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F277A606CF; Fri, 17 Oct 2025 12:27:13 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="A1WenaEw"; dkim-atps=neutral Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id B3B08606BC for ; Fri, 17 Oct 2025 12:27:10 +0200 (CEST) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-471076f819bso14051735e9.3 for ; Fri, 17 Oct 2025 03:27:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1760696830; x=1761301630; 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=pKNNxUkSF8/sGRxUgmWP5MlL22UtXQN5k0cv1bzA+DA=; b=A1WenaEw2ctVXVA5ZOwHnTRT/f2ecTiCMFr9/FHhZ0WHptTPPoVosR+5VovVQi6gm2 jSVyH8PyS9qM8KZHHh6x/T83Bf8QtTyuhti2F2wQwW7c/DPNm2szijrSLL50wxWIG1bQ eL0tDJoHoFFKs/nZKLmAarnIipU/rKwP5G9R+kvYgmlJv4zBTB79/esafkGPUnkHPAPV z0TNv85gF2NVIbzkw61Pf16dI+Hf0IGB+pwhOCp2M6MZ9fEieLZBiVJLatbnA1zZ7qJB Eyh6ZI/W+k9SAODsOwCC5lfamsE9fVc//RjfIi4yuHtS4FJa0jddwgz5OkvN39UpjIHv VFog== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760696830; x=1761301630; 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=pKNNxUkSF8/sGRxUgmWP5MlL22UtXQN5k0cv1bzA+DA=; b=kWPCVW6qv5Gkw4+R96RgznCnMHkmm2JoPEf7vlCtaYzg0UNm+mZ4xS96CwTrm4SVUg 1yUayPr4hZwSHvkzmYZzbz57dBxYeQ4yiMiYZMQ94UiqWmAgDGJtiGHvy/Sh2GgNftzc FRhKV1RE3mP22g7sflifDQHz6hj2eEmDfX2s6oxdMCtElWp9CvGw84Np8HlkRTexUqO7 G2OhO+IFjr1YFJG9z4CVvWBYTGzTnVPZTlChMZpj1IL2dXcc1kn1ZPA2aFKrTZhLBqXD Ss5t9GCoccfuOQd4BkwCRn5zS8jvnxd9ZWqJuxArb7B9Qu+JA2Lz6oTf/xZ4klWtmf9a OITA== X-Gm-Message-State: AOJu0YyrZnR1vl50e4NpjREl/kse0iJcm99oOvRclhar6oLDoDjyaGx/ Gib5/tIYD06b+n5Ii/VAJK5BzyLffTIqnXMiaTKLuGm1k9Wvwm5se9f9p3Urj0WJyWZ2mNMUT3y IskrgQH0= X-Gm-Gg: ASbGncsffl6/0ceDv9Q4cEiN2Km3Eipm7wl9tRXuHIefWhRVow1S27LCGMl4QhpG2Jo 5NMhV8MXMClwshGvwbAWDkC4qGY0V6yXokGN9cgrxjnh7+IkYAlrKBMcFi6NBzzKjLhUPynk44V kqkyKK82ahVj+bFTT4FZ0C9Iigg9tWdmcr/x88SsM/2ydER191SHqmd0YGcLvDQd4OMdNzllnHv wioOnD2o/K3NtbYC9cAQk09Sf233u8BkfadT0SrgRAkm5SNn2z27cLQk8TOsKTeVnS3WTmaonB0 GUG1YmgBQUbJZZ7eow2D7dL1fKDo5G0gkf/2044JGh1cvmg5j4ZXATcW/mvIurHvVEMmF9a7ztp 4owA8+kj+7QsTDNJk3WUAsRFPPdH7bH4LVxyb7k4caFkt+p/wvDMVJjCJkRTSW2ay2w76AZrnt/ pVBEfZiSGHqXlh//kthOcc8vmxKhokLFbminKPfY6QB07CID/m/cWd5ynLOH9tnJtJmtrdFu+2b rKoSNhDMm8TtEYG8ofx6CakWA== X-Google-Smtp-Source: AGHT+IFfYc1mqR4NiLC709TaAhNKT3kJ+Otw0BEw+UfcqttmE2hwaeNBPquditJDc7txpmengn/Yzw== X-Received: by 2002:a05:600c:444d:b0:46e:1f86:aeba with SMTP id 5b1f17b1804b1-471178ad982mr20822585e9.17.1760696829626; Fri, 17 Oct 2025 03:27:09 -0700 (PDT) Received: from localhost.localdomain ([2a06:61c0:f337:0:8aba:2a85:b765:a23e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47114428dedsm73811905e9.7.2025.10.17.03.27.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Oct 2025 03:27:08 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: David Plowman Subject: [PATCH 2/5] ipa: rpi: lux: Handle camera mode sensitivity correctly Date: Fri, 17 Oct 2025 11:05:38 +0100 Message-ID: <20251017102704.3887-3-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 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 Fri Oct 17 10:05:39 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 24700 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 1BCA1C32CE for ; Fri, 17 Oct 2025 10:27:16 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 134E9606CC; Fri, 17 Oct 2025 12:27:15 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="mzQs1u8L"; dkim-atps=neutral Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 44763606BF for ; Fri, 17 Oct 2025 12:27:11 +0200 (CEST) Received: by mail-wm1-x336.google.com with SMTP id 5b1f17b1804b1-47112edf9f7so9879155e9.0 for ; Fri, 17 Oct 2025 03:27:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1760696830; x=1761301630; 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=zFHEnXvv4SPgv/9pwKCAUWV8dxbTetTQUiCP8syXNJc=; b=mzQs1u8LfoiHRsu1TJL++S/4h21hw7stSdFrugnoPN/nyqUxiL73uNa2YYXrunNC+R Rc+tbLghf3Ck1M8s3xd/CXs6PsiOcV5f71a519DWty9UCLpoOVjDz2SpecvAiAeF/c2z SL/QYg0HSWLBVloeRW+TbIhHk1lRlimDB3qDttldrrjFX28o4en6gsUCwM6/ZxWcicD0 ycimiq/kT5D2SZYETQ/OOVGDq+OTq/6sXdK1EKDaPD29r0m6WdWtBC8d8iS5w3uWZ498 W6PIPxVJCj5tAwzmA7B3ICnu+2u2P5x1RPJrvgRZeCU0f81atZr+0Py5SA34ogxu+LuT wMRQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760696830; x=1761301630; 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=zFHEnXvv4SPgv/9pwKCAUWV8dxbTetTQUiCP8syXNJc=; b=Oq21fbPOYnY6zm/X0j4Vy0oASUKbx0G05hO13vDHqp46y8aKvIhO6zorW/VNjcdwWj 3pfT3Q59RqG9LSBWb/biB1n0EuZUSFP91rMNXJkWA7jwPU5lxnv7VtllYDwLS6N9Lgn6 oJPloO+ZuRfgoFMl8Zr0L9YtHSqN6qSLY4cnIgxPj3yOkFxXoypyNBLOaRY5Wa9L/8/y K2R8MEYcHSz/xHXSL6MBsXyJ87f7fs856PV3numSY/+RwS6SrXEIwFB9IIWicI6wL863 Dcu8Dxy8g8JZgZDq2lFStnFLob5tyE/xCL3lBjUxVM5NKVVn36WusNrlTzNTPJI9hHtn BGuw== X-Gm-Message-State: AOJu0YzhOskNAzVTp5UkKyzV7VcewpdGY9tdBqQM1LiXDeBop736iTu2 Zie2+yOpGrv0xcxsi0L9cVW7C+JiBhWbDNLtPQUA4wg95YBbaKRsCxEno0VoJS/uiuDQl5YRYST xB2r5ZBc= X-Gm-Gg: ASbGncsseYRY1aiKwDa+uFHZdxEemJ8/ZoYdUleogsXDxvviVHwzPtV2472foV4l1gH iUOc3lHEre7yMLXPXNqIEO7Ogncgg4Rfl2Q2z50ReCN2LeGQwyKE/aEkDbkzMwN86BhPEvTf4k8 umdiggFtkNxu8T/zOeyFmuTihP1B6QGF9KZddGMhk4epN5fbYJ65ENrkZ55ZQOw1ZMGk268g00v gopObaiyxRpuMOTLbBSeLxgWZKq6eWJE82D67TSTraW035w33XDajOX0k76tJfxGPpMxlXnkA9/ D/QYqTLeaISY9GB342EKgj78cV/BfX1iKE+irJ2WjOoVu50F5juv9fsZhsrvp/mL0ZbgiQmi9x/ rHUbbaXbEmkiOfn7wAsQjnu60B9m35EjC0ppPuVYyY6PxQIyo/xYCj3PBPZ7osnDQfd98D/KsLC Qboi4yAwXlTKm9PuYL1VK8ynOPd5Pj5Pcsd+H+k473JsXhucCvdihbKCjJaQNo5dp4GFz/tdC4H aU3KTwpJ0DjMKa0StrZJ5JhELIvgqvlP3un X-Google-Smtp-Source: AGHT+IEelgMGpovmxCuGbCTupR1pQCmaKO4nG1sHaa779TmgnMA1Lc/2ZWmOA53lOIJ1ENsGacVxIw== X-Received: by 2002:a05:600c:5026:b0:46e:477a:f3dd with SMTP id 5b1f17b1804b1-4711792a680mr25593295e9.36.1760696830319; Fri, 17 Oct 2025 03:27:10 -0700 (PDT) Received: from localhost.localdomain ([2a06:61c0:f337:0:8aba:2a85:b765:a23e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47114428dedsm73811905e9.7.2025.10.17.03.27.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Oct 2025 03:27:09 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: David Plowman Subject: [PATCH 3/5] ipa: rpi: pisp: Use a floating region to get whole image Y statistics Date: Fri, 17 Oct 2025 11:05:39 +0100 Message-ID: <20251017102704.3887-4-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 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" 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 Fri Oct 17 10:05:40 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 24701 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 232E9C3259 for ; Fri, 17 Oct 2025 10:27:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id E47BA606D6; Fri, 17 Oct 2025 12:27:15 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="LNxNB66I"; dkim-atps=neutral Received: from mail-wm1-x333.google.com (mail-wm1-x333.google.com [IPv6:2a00:1450:4864:20::333]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id EA7B5606AA for ; Fri, 17 Oct 2025 12:27:11 +0200 (CEST) Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-46e542196c7so18941235e9.0 for ; Fri, 17 Oct 2025 03:27:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1760696831; x=1761301631; 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=5WgHdFl1AJENoxSlexdPAxRBVpUNyl02PN8mna4Wtas=; b=LNxNB66IoUl3qoje+ZHg+1aGz8z9WoBo6awbK2Krs/U20Sdj397cPsdi5QtHa2PmHR 3bpcxVUUvgTogc61QvBBxlj6ip4LE8dq43ii84EXKY+076lyUVUPiZmqEYIvpmGaotlJ Y6705HtcFoANM9lgtdEsjK1P1+eM39MEcioXgUzVEJgUstftMei+fGpNGyhMJE0i1ayc DUwmOfDLcX7uYokF4tC0airwcItkG03p4FL4bMFyfdBKf7gkDzJgYAtXeRZkPJhCma9M K7XYNY1T7KkjwaAlhtX94zLZztKDbMng7rybAccm7c/hw9GgWim89zVHwUBpS8uYW8Yw If1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760696831; x=1761301631; 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=5WgHdFl1AJENoxSlexdPAxRBVpUNyl02PN8mna4Wtas=; b=PN3iILvFXDTh6fxsb4gs5PBBnSnDzF8mekYuHyfeb4GRyJveZEAhq7Vk3zDGtFa7/0 SSeTEIyDGMC2j5canzp6rjQcL5iBJLS015XZqvlHarAAEd8ZvFgy1Ens0SG8v84CToQH Wck545ufcfuH0uImQHLgu4U5WYgv4xRoqrQhXGqdOYy0hfHc3qT+L7ywRsjTPOMswGd2 i5Gx9QuXqYkkBp5f8Ap2ONvHsL/vbP2BiOmRT3rEhpSAmFE2l4gIqzNJkuO1q3SeGdFs aMlrr1utteM+QEXqrYNTV3DUSwh2wcf5g4xlnd0NF3gV/e9uhDX9CXW73BzG4Q/rzFJs K5ng== X-Gm-Message-State: AOJu0Yxc3E/zXPyquSw9EWhGfy5UyhztohsvwneU436VDi4AUG9Od54b x7tQVFdDa4bp6z9f8dM02008mNOf1fbccV/HNgMi6NuaEnxyE/BdmiE3RcF3r5SMoHdTNmYyh9e F7MrQCPg= X-Gm-Gg: ASbGncsxekbQcEJ68hPoqV/4ITqEA7vxer5UY2az1AM9VM1qjIJRg0djaZlGT1UDPaV dbXIYP+gs6w1bC8evl+VQelQXrN0u9QkTQmQjxZiwqWjbBA3e1UYLUXkjWweuOiQsKjmdM9kmnB acXguXt3elPQRf5p19evGgWKm8+z5hpZv9fWbe7S5C1wxoUwK4dpl8FFj9qYR7LRbw4kiNluxd1 WmICK/oFDzHny2WPV3obcEZKTeGVxzZIYDvNaalGG6metZ2cxKJ3bobUFFq4e6HZgzGKDXih50u bNtm6z3HgEwjCL1Yux0HjFijxuLYNQ+zRQRXcZRVwHX82iPhWlMkgjnw5r+gdAo03A132FmHtQZ h9n8zAbh9fRezCOmdxSbKFi77o9fv9NYK/+6UnBYQQ7+04CGAnuT2RsyPYFxBnwtm4mB2BPJZuO 5IrA4GtNSLx1UkoCj3zvlMTp3t9ZSoNR9AieltBwEIN+3PpO7f673VG3EAOnQmfN2IbG8HStmPJ +5BCgeVatCz04d2ZPbv2DEs6g== X-Google-Smtp-Source: AGHT+IG07nhaHBJClLuB6nlo9gTfbqjmYZC+ddGWKUPdh6q+C0rs+L9kID7KWmJsHjRnLTtI4zRWJg== X-Received: by 2002:a05:600c:548c:b0:45d:5c71:769d with SMTP id 5b1f17b1804b1-4711726289cmr30154785e9.8.1760696831044; Fri, 17 Oct 2025 03:27:11 -0700 (PDT) Received: from localhost.localdomain ([2a06:61c0:f337:0:8aba:2a85:b765:a23e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47114428dedsm73811905e9.7.2025.10.17.03.27.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Oct 2025 03:27:10 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: David Plowman Subject: [PATCH 4/5] ipa: rpi: vc4: Use a floating statistics region for a full image Y sum Date: Fri, 17 Oct 2025 11:05:40 +0100 Message-ID: <20251017102704.3887-5-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 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" 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 | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/src/ipa/rpi/vc4/vc4.cpp b/src/ipa/rpi/vc4/vc4.cpp index ba43e474..fe754ace 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,15 @@ 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); + uint64_t sumR = 0; + uint64_t sumG = 0; + uint64_t sumB = 0; + 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 +253,20 @@ RPiController::StatisticsPtr IpaVc4::platformProcessStats(Span mem) statistics->agcRegions.set(i, { { rSum, gSum, bSum }, counted, notcounted }); + + /* Accumulate values for the full image Y sum. */ + sumR += stats->agc_stats[i].r_sum << scale; + sumG += stats->agc_stats[i].g_sum << scale; + sumB += 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. */ + uint64_t sumY = sumR * lastAwbStatus_.gainR * 0.299 + sumG * lastAwbStatus_.gainG * 0.587 + + sumB * lastAwbStatus_.gainB * 0.114; + statistics->agcRegions.setFloating(0, { { sumR, sumG, sumB, sumY }, + countedSum, notCountedSum }); } statistics->focusRegions.init(hw.focusRegions); From patchwork Fri Oct 17 10:05:41 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: David Plowman X-Patchwork-Id: 24702 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 A2EEFC3331 for ; Fri, 17 Oct 2025 10:27:17 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 42FA3606B9; Fri, 17 Oct 2025 12:27:17 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=raspberrypi.com header.i=@raspberrypi.com header.b="M8zxcATJ"; dkim-atps=neutral Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 79C33606B6 for ; Fri, 17 Oct 2025 12:27:12 +0200 (CEST) Received: by mail-wm1-x32a.google.com with SMTP id 5b1f17b1804b1-47112edf9f7so9879285e9.0 for ; Fri, 17 Oct 2025 03:27:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=raspberrypi.com; s=google; t=1760696832; x=1761301632; 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=bUnSu+t3RNrIrvdREwuVjIn3DN+DaH8m2uKMtTtAbCk=; b=M8zxcATJWRM4HEh2Pt14805Ie6WnEbtGWhj65u9je4kJe8KoKXWWCt1XuoqwWArBG6 dVCB/o4m3Azv8KIh3Kbvr0DHb2d9q2vnrd/khXv+d60me2pQlHODgTTW1VjMd1AL+pzh LFy8mXXG34I80ndyAPqpAzmJQD0MBiShwTTt+ZmyDXmWLZENtkrTuXouOie3Ncg8RvNL UqK/m6KKb+A4ZkK6JpeqbQBWuhdQBZCn5D7LiEm8UV0ZcNh/PYizHRmtJQtd/wO8gfjQ sMnEl+bEgplDZ5NyU9H4MLChPUqEMrXf+5oAcrkjlPZjeK7tBR3k52pVJogOeqnsf7CV exDQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1760696832; x=1761301632; 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=bUnSu+t3RNrIrvdREwuVjIn3DN+DaH8m2uKMtTtAbCk=; b=qlJuN/KK1yMCwWyCGS6FWYYyGPtKJ0lZBMT6cO7/lOY9iuh5qzeWu38fQlZa4F/y94 4rf962QZy40gtpfwI+jtx7KyIDLH+Y1drmyQe7jsLHJ8cE/mF0Pku6gYrskiE63rBODy qqJ55tREQZl25L5x8VNJDxaPztP38FSzUAbQoeNPSdByzSXg6MJsAwhsGCqq44Pm3bQV zOMhZye44PYrZI+G4m487LQa6GHOO1evFTkZwD5e6NjnkDxiJeBYHUe8e6nWZzZPgEtA JBWM6YK5i9v8tUUv13f+SCeSNXDvnsVLALmTY6dJCnjV40GPdIEHAKdGTgXnaI1Vbkvx cWJA== X-Gm-Message-State: AOJu0YwQ2rg0lyHSm8N1dhIC6dpER2hqDFkGTSg9MD+1gxGyUKgv0FMR bFqaHPfP4v2djRiQ2uJuZzFPl2vI7tKoGR6U9K1EtXYUqAqgp/3rn4EyaRL5RufSN6GCWsZPDX/ R9qhGEEw= X-Gm-Gg: ASbGncs5uHOJSYf3s9wpfS6SieejrA32h+qJkZzKNIP17OaQmTw+yKtin7rG/ReXwy6 gOhQk0LqY5EcoFpi9R9OP3I7Ixr5RuwgEf3mCcbQvbR9geN75jal6uK4ZC6r1zTu9SxT3lJ890F kD/1gb7nOE/TgWMGg8/+ZhoBcOMWe+EjhtnSVEvUKTfaCp56Mz+Xx6nxcjlSaSHJpKKBZWSQShD 4FKEPDzbMD7PIpoQQLo+6f31ud5JntqgeFySibAMHE5Y+bizmpYwJwacFnq64xFxluu9PfSc79t RFHc7FU3dPWIYY/EIiM2Uidru1M6ixua+0quEU3nlhBJkj2cU05xkuuh6Cd2/KXoJJM1fnbgtWw beISEI+oMP5cTiEHmbmVd2afFa9wnikp4tMpZH1t4INpoq9uAG/j7y/qv67GF6uAhBd/IvCsXSp u3Te8m2pPuFESRxo0sIohj5hmOJ6kmid44wwgg0yvPV72ARDc3Cbsc6Krm8xlPcT36tRqW0IOe4 0IBp/sJQ5Bydk4= X-Google-Smtp-Source: AGHT+IHc96dZvnIy+ivIhioPBXE3tpIxyPyg3KKo7qoUUI3emrSZZbZjf1o8yBMqtqmtPiO65UIuVg== X-Received: by 2002:a05:600c:1994:b0:471:a73:9c49 with SMTP id 5b1f17b1804b1-471178745fdmr26924515e9.2.1760696831741; Fri, 17 Oct 2025 03:27:11 -0700 (PDT) Received: from localhost.localdomain ([2a06:61c0:f337:0:8aba:2a85:b765:a23e]) by smtp.gmail.com with ESMTPSA id 5b1f17b1804b1-47114428dedsm73811905e9.7.2025.10.17.03.27.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 17 Oct 2025 03:27:11 -0700 (PDT) From: David Plowman To: libcamera-devel@lists.libcamera.org Cc: David Plowman Subject: [PATCH 5/5] ipa: rpi: lux: Use floating statistics region to obtain the 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 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 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_;