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_;