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