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