From patchwork Mon May 11 20:23:28 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Javier Tia X-Patchwork-Id: 26718 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 9F07FBDCBD for ; Mon, 11 May 2026 20:23:36 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id AECBA63021; Mon, 11 May 2026 22:23:34 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=jetm.me header.i=@jetm.me header.b="mwMJUmEv"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="nI1/HHVX"; dkim-atps=neutral Received: from fhigh-b2-smtp.messagingengine.com (fhigh-b2-smtp.messagingengine.com [202.12.124.153]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 8124D62E9D for ; Mon, 11 May 2026 22:23:32 +0200 (CEST) Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfhigh.stl.internal (Postfix) with ESMTP id 933307A0081; Mon, 11 May 2026 16:23:31 -0400 (EDT) Received: from phl-imap-07 ([10.202.2.97]) by phl-compute-02.internal (MEProxy); Mon, 11 May 2026 16:23:31 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jetm.me; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1778531011; x=1778617411; bh=ngtRot1spR1XomwaiLpsDsXkMgoYsJyGBfCUEmdxQXY=; b= mwMJUmEvkrq/F5vuqE3UQIzaOs1wEmjTxKJg5icmChhFzPvo//PrVwn7H0sFsOl6 v4dIeAN/y+rVBkE/3yfDDUoHRtVevzCn5n9/m2+2DZQSxW/y3IyakIsdV/b8Xt2c 3lFnp6Hbuk2UwSQYKiFhvy/bPUYFKhL+XqxwhOZgQqbo6EZrFkKbKTH44QaeBcxB yDervM4Lxp6rNw0u30KlV5zQfiCreITab1ejXG0S3YpUaY0fmxxUdvkpsqJusZrK cFnUcaw54I6j6JV+QQpFjv++LTUkkRhxvGbARg1NWkv0gYVbPbEISa7WFxHT8e4D nuocz83/xhC6g5yUAcNDfw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1778531011; x= 1778617411; bh=ngtRot1spR1XomwaiLpsDsXkMgoYsJyGBfCUEmdxQXY=; b=n I1/HHVXL2jrO+4wu0M4QZrQoBHGEP2ophb3lbl++DEgWY8tO7qltPZ5OyNCy0S91 prxh5d/msby0EVBLry40a3JXlKksDruEmsm2C3re+iR09u8mvxC6HYMIyWujdrSp hDu4IMZBQpFjALY5k9lVbp8z15EB7lPY9TdDTNdRnfzuZSQlBVLZgU5j1WkecTxZ hNpaR7ScpmW84tDxlUCu/j4L6NZ6dBvRk+t9TfbC34ivMfl4s16hzKwklFFtyZoM IV69pQq8Iw7536Q4q8D5lDHLxA+jdjgVQyVbarrntehHr63OK+FQClC9JHUN0J4I oOsI/npMsx/QIyQ5zoO0Q== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdduudelkeejucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepoffhfffugggtgffkvfevofgjfhesthekredtredtjeenucfhrhhomheplfgrvhhi vghrucfvihgruceofhhlohhsshesjhgvthhmrdhmvgeqnecuggftrfgrthhtvghrnhepve ektdfhffevuddtgfetieevtddvheduhfeggfekveejlefhleefieevueefiefhnecuvehl uhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepfhhlohhsshesjh gvthhmrdhmvgdpnhgspghrtghpthhtohepfedpmhhouggvpehsmhhtphhouhhtpdhrtghp thhtohepsggrrhhnrggsrghsrdhpohgtiigvsehiuggvrghsohhnsghorghrugdrtghomh dprhgtphhtthhopehlrghurhgvnhhtrdhpihhntghhrghrthesihguvggrshhonhgsohgr rhgurdgtohhmpdhrtghpthhtoheplhhisggtrghmvghrrgdquggvvhgvlheslhhishhtsh drlhhisggtrghmvghrrgdrohhrgh X-ME-Proxy: Feedback-ID: i9dde48b3:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 574EF1EA0070; Mon, 11 May 2026 16:23:31 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface From: Javier Tia Date: Mon, 11 May 2026 14:23:28 -0600 Subject: [PATCH v3 1/2] libcamera: libipa: Add right-shift operators to Vector MIME-Version: 1.0 Message-Id: <20260511-libipa-vector-rshift-v3-1-a275f6e87ec4@jetm.me> To: libcamera-devel@lists.libcamera.org Cc: =?utf-8?q?Barnab=C3=A1s_P=C5=91cze?= , Laurent Pinchart X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=4550; i=floss@jetm.me; h=from:subject:message-id; bh=ofQLSaGclfdIwbb2SwinFaJzbTmyc9ph2VywRC17YMU=; b=owEB7QES/pANAwAKAbXuwwuoZ3cfAcsmYgBqAjq/dIGqIVheaYjakOCA/YNfIS+Ms2Jlff+sc dZGkxBnWO6JAbMEAAEKAB0WIQSbE7ILzw7eI0VKk8m17sMLqGd3HwUCagI6vwAKCRC17sMLqGd3 HyAFC/9N4TLFkWSljvlVGg4cYZWeJdT02g80Kzrj/U13vpAVrnMWrAp9V+UPmAc2nNsz1w0n69o TyI14HKslumrmpDw1iOcUhrxPjj+KmVu35hncGcXGBhXg2iPTQSTuFOzxAnMTKYGjZ08wq1Oklq WT+6HHg4iKLb948SBqX2Jb4NjR/104GEc2HzKtt4zWqNRkX6AnLRnF+4YlIYrIwJJLv93jA17RK KycVI8O6cPebJq2qutlQbrzmiWvVmAYEslzh7vyy1op9W4eC6zTcu6EHbZ0Kr6P0cuZIYHdkEJR ZraU6AlBxsZSpOAxG1G/hsl4KW0JUhAde4abhua+HE658+qSUhOJ1ItRYXqgnAveN8lSUijxRUB KA1m1bPPyMVAT4LYxdAsW5L0fYotKlY/x9j4spboFp54xaxZCcJWkCaN2Q39FvfGvz8KI8SIx0o arAF8x5+WReAJ4L2yzbsDhPm0GrrK4axmPDAHXCMGXs20Xyu0y92Hp9+00/ieV2Hkx6dI= X-Developer-Key: i=floss@jetm.me; a=openpgp; fpr=9B13B20BCF0EDE23454A93C9B5EEC30BA867771F In-Reply-To: <20260511-libipa-vector-rshift-v3-0-a275f6e87ec4@jetm.me> References: <20260511-libipa-vector-rshift-v3-0-a275f6e87ec4@jetm.me> 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" Add operator>> and operator>>= for right-shifting all elements by a scalar shift amount. Both operate element-wise: operator>> returns a new Vector with each element shifted, operator>>= shifts in place and returns a reference to *this. The motivating use case is SwStatsCpu::finishFrame(), which right-shifts three individual components of the RGB sum by the same sumShift_ value. With these operators that becomes a single sum_ >>= sumShift_ expression. The private apply() helpers for non-mutating and mutating scalar operations are templated on the scalar type so the existing operators keep working with T while shift can pass an unsigned int. A static_assert in each shift operator restricts them to integer element types since right-shift is undefined on floating-point Vectors. Suggested-by: Barnabás Pőcze Suggested-by: Laurent Pinchart Signed-off-by: Javier Tia Reviewed-by: Barnabás Pőcze --- include/libcamera/internal/vector.h | 22 ++++++++++++++++++---- src/libcamera/vector.cpp | 14 ++++++++++++++ test/vector.cpp | 5 +++++ 3 files changed, 37 insertions(+), 4 deletions(-) diff --git a/include/libcamera/internal/vector.h b/include/libcamera/internal/vector.h index ed7490e1..e3ea723d 100644 --- a/include/libcamera/internal/vector.h +++ b/include/libcamera/internal/vector.h @@ -111,6 +111,13 @@ public: return apply(*this, scalar, std::divides<>{}); } + constexpr Vector operator>>(unsigned int shift) const + { + static_assert(std::is_integral_v, + "Vector::operator>> requires an integer element type"); + return apply(*this, shift, [](T a, unsigned int b) { return a >> b; }); + } + Vector &operator+=(const Vector &other) { return apply(other, [](T a, T b) { return a + b; }); @@ -151,6 +158,13 @@ public: return apply(scalar, [](T a, T b) { return a / b; }); } + Vector &operator>>=(unsigned int shift) + { + static_assert(std::is_integral_v, + "Vector::operator>>= requires an integer element type"); + return apply(shift, [](T a, unsigned int b) { return a >> b; }); + } + constexpr Vector min(const Vector &other) const { return apply(*this, other, [](T a, T b) { return std::min(a, b); }); @@ -260,8 +274,8 @@ private: return result; } - template - static constexpr Vector apply(const Vector &lhs, T rhs, BinaryOp op) + template + static constexpr Vector apply(const Vector &lhs, U rhs, BinaryOp op) { Vector result; std::transform(lhs.data_.begin(), lhs.data_.end(), @@ -281,8 +295,8 @@ private: return *this; } - template - Vector &apply(T scalar, BinaryOp op) + template + Vector &apply(U scalar, BinaryOp op) { std::for_each(data_.begin(), data_.end(), [&op, scalar](T &v) { v = op(v, scalar); }); diff --git a/src/libcamera/vector.cpp b/src/libcamera/vector.cpp index 86b9f9bb..94fbf61e 100644 --- a/src/libcamera/vector.cpp +++ b/src/libcamera/vector.cpp @@ -126,6 +126,13 @@ LOG_DEFINE_CATEGORY(Vector) * \return The element-wise division of this vector by \a scalar */ +/** + * \fn Vector::operator>>(unsigned int shift) const + * \brief Right-shift each element of this vector by \a shift bits + * \param[in] shift The shift amount + * \return A new vector with each element right-shifted by \a shift + */ + /** * \fn Vector::operator+=(Vector const &other) * \brief Add \a other element-wise to this vector @@ -182,6 +189,13 @@ LOG_DEFINE_CATEGORY(Vector) * \return This vector */ +/** + * \fn Vector::operator>>=(unsigned int shift) + * \brief Right-shift each element of this vector by \a shift bits in place + * \param[in] shift The shift amount + * \return This vector + */ + /** * \fn Vector::min(const Vector &other) const * \brief Calculate the minimum of this vector and \a other element-wise diff --git a/test/vector.cpp b/test/vector.cpp index 4fae960d..4ff908e8 100644 --- a/test/vector.cpp +++ b/test/vector.cpp @@ -93,6 +93,11 @@ protected: v2 /= 4.0; ASSERT_EQ(v2, (Vector{{ 1.0, 4.0, 8.0 }})); + Vector vi{{ 8, 16, 32 }}; + ASSERT_EQ(vi >> 2, (Vector{{ 2, 4, 8 }})); + vi >>= 1; + ASSERT_EQ(vi, (Vector{{ 4, 8, 16 }})); + return TestPass; } }; From patchwork Mon May 11 20:23:29 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Javier Tia X-Patchwork-Id: 26719 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 27FADC32F7 for ; Mon, 11 May 2026 20:23:38 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 3D87F62E9D; Mon, 11 May 2026 22:23:37 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=jetm.me header.i=@jetm.me header.b="UMP6fuHy"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="PgnD6qYH"; dkim-atps=neutral Received: from fhigh-b2-smtp.messagingengine.com (fhigh-b2-smtp.messagingengine.com [202.12.124.153]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 6766A62E9D for ; Mon, 11 May 2026 22:23:34 +0200 (CEST) Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfhigh.stl.internal (Postfix) with ESMTP id 6243D7A0057; Mon, 11 May 2026 16:23:33 -0400 (EDT) Received: from phl-imap-07 ([10.202.2.97]) by phl-compute-02.internal (MEProxy); Mon, 11 May 2026 16:23:33 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=jetm.me; h=cc:cc :content-transfer-encoding:content-type:content-type:date:date :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to; s=fm2; t=1778531013; x=1778617413; bh=dtz2UrpL/ptITL8RY4B77zQklBI3B1hKmo+zo82NB3c=; b= UMP6fuHyAcyGExHwJZtf22BuUFvilKbh/yagcS0jtIWxDJZzhquHLSh09j6rXDWK wB1ptfupKZbvdQhlqEPDrwstUj+RNl6Xn0eHC9FryxYrQBAL1Ydst0K9EFqq3Vtf gUtKlAzxf0sAXKKj9aaWgJ5FUmOAD4vIUSDQVlaLI9qL3vntilr5bYKKsNAC6EJp 0e0FXqv15CTaPtcSadTD/5nlCJ9aWygIs+hKE0RkG9JV683flIyCrbReX9f01m7I SwQ0vBxqIYeWLzvIaYfqNHAnR6yiuB8il4MRLoXjQ1vXSmSUxLoGFsHGti7oR/s0 wQuwkZrLrglNMeQW6QxmYQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:cc:content-transfer-encoding :content-type:content-type:date:date:feedback-id:feedback-id :from:from:in-reply-to:in-reply-to:message-id:mime-version :references:reply-to:subject:subject:to:to:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1778531013; x= 1778617413; bh=dtz2UrpL/ptITL8RY4B77zQklBI3B1hKmo+zo82NB3c=; b=P gnD6qYHYQs6G0cvBUssJ5mc65ROgb2xdl8afXS1XKuVLN4xJR6VrXzwdL+pu9FYP 6zgSmUXRMaj/XeHJdIdSvHZ3aMa4tG1xuT3GHHewMV9YIx3Qgc2Z/iyxHqhbLZZb dagV4JWywdKWVv1n1qAq5y50RSE602alCgYg/Ugbhg5kuaj24SzHUdfI8UEBqZ1x b07Tizg7cDKy87cHEYjYkppauc9vYgWH8Wv003kGFGbZPuMUPnKwasyB4d+1t0EO KvuaaRb1x1/nwRRkiGUUfG6NhTS7sEHzwhiIZUEhhnrVay9btsdR6hpGVL/PlHCZ YJ8ZS3k9bg1FPTbaw7/VQ== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdduudelkeejucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf gurhepoffhfffugggtgffkvfevofgjfhesthekredtredtjeenucfhrhhomheplfgrvhhi vghrucfvihgruceofhhlohhsshesjhgvthhmrdhmvgeqnecuggftrfgrthhtvghrnhepve ektdfhffevuddtgfetieevtddvheduhfeggfekveejlefhleefieevueefiefhnecuvehl uhhsthgvrhfuihiivgepudenucfrrghrrghmpehmrghilhhfrhhomhepfhhlohhsshesjh gvthhmrdhmvgdpnhgspghrtghpthhtohepfedpmhhouggvpehsmhhtphhouhhtpdhrtghp thhtohepsggrrhhnrggsrghsrdhpohgtiigvsehiuggvrghsohhnsghorghrugdrtghomh dprhgtphhtthhopehlrghurhgvnhhtrdhpihhntghhrghrthesihguvggrshhonhgsohgr rhgurdgtohhmpdhrtghpthhtoheplhhisggtrghmvghrrgdquggvvhgvlheslhhishhtsh drlhhisggtrghmvghrrgdrohhrgh X-ME-Proxy: Feedback-ID: i9dde48b3:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 26BE01EA006B; Mon, 11 May 2026 16:23:33 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface From: Javier Tia Date: Mon, 11 May 2026 14:23:29 -0600 Subject: [PATCH v3 2/2] libcamera: software_isp: Use Vector operator>>= in finishFrame MIME-Version: 1.0 Message-Id: <20260511-libipa-vector-rshift-v3-2-a275f6e87ec4@jetm.me> To: libcamera-devel@lists.libcamera.org Cc: Laurent Pinchart , =?utf-8?q?Barnab?= =?utf-8?b?w6FzIFDFkWN6ZQ==?= X-Mailer: b4 0.15.2 X-Developer-Signature: v=1; a=openpgp-sha256; l=1024; i=floss@jetm.me; h=from:subject:message-id; bh=qa0MXKJoTMnIInZTz92a7r8y1F8xv2mxBKFbYifPdbE=; b=owEB7QES/pANAwAKAbXuwwuoZ3cfAcsmYgBqAjq/2moivWq38VddAFQVJjCTNTUyXYDHOMfbN JMLoYRalRuJAbMEAAEKAB0WIQSbE7ILzw7eI0VKk8m17sMLqGd3HwUCagI6vwAKCRC17sMLqGd3 H/9qC/wK4+VyrxizAoknSHvyFKy7Y0TEMhscnRoudqXAAFeAW2Hberr/HY+k1bNrFrZevzmBWa8 ZV8yrfJbqhOuOtrXDHOzVNHvmQ0i8YGgIZ78il0zDiAsppTwzaUveChBaHUiB+CXFBTgRk/qRg+ L5RH6Z5xlzdQkTLyklW5xsE31BDh0z580dB4B+puleLXQTmGq7Wfyn7+O0dJqtUJnM6jOuZNNqf Mhq4Ir+DvilxixWjdL7HuUDYXIsjbLLWQsvU7gUwMGLnIM8ZS+hlnM7I3i19cjGxQF2z9xHwyxM QSWxd8A/UrpBrfm1DX+si5NLOsslQacf//OgQqmHS96h/2aPaFTdZdiaPd0LNQHtdYiWMzsXZsR UuL9LelfW4MsBuASxn+qYPHrZlc6tC6BuJ5RWTBbShb4wcRlZbr+FiHc8yM/ER2zmrzKSNsn9/v JRPCV/EaRhBjIr/EkvLvLVG3QA0myNn4kMphpZOmlkiUdxGjw2lmUIGa3wVSmsPrV1Nh4= X-Developer-Key: i=floss@jetm.me; a=openpgp; fpr=9B13B20BCF0EDE23454A93C9B5EEC30BA867771F In-Reply-To: <20260511-libipa-vector-rshift-v3-0-a275f6e87ec4@jetm.me> References: <20260511-libipa-vector-rshift-v3-0-a275f6e87ec4@jetm.me> 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" Replace the three per-component right-shift assignments with a single sum_ >>= sumShift_ call now that Vector provides the operator. Signed-off-by: Javier Tia Reviewed-by: Laurent Pinchart Reviewed-by: Barnabás Pőcze --- src/libcamera/software_isp/swstats_cpu.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/libcamera/software_isp/swstats_cpu.cpp b/src/libcamera/software_isp/swstats_cpu.cpp index 2e020e62..0815ec9a 100644 --- a/src/libcamera/software_isp/swstats_cpu.cpp +++ b/src/libcamera/software_isp/swstats_cpu.cpp @@ -363,9 +363,7 @@ void SwStatsCpu::finishFrame(uint32_t frame, uint32_t bufferId) sharedStats_->yHistogram[j] += s.yHistogram[j]; } - sharedStats_->sum_.r() >>= sumShift_; - sharedStats_->sum_.g() >>= sumShift_; - sharedStats_->sum_.b() >>= sumShift_; + sharedStats_->sum_ >>= sumShift_; } sharedStats_->valid = valid;