From patchwork Fri May 8 21:35:46 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Javier Tia X-Patchwork-Id: 26706 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 E1C3ABE173 for ; Fri, 8 May 2026 22:37:39 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 4697B63021; Sat, 9 May 2026 00:37:37 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=jetm.me header.i=@jetm.me header.b="EJZo4LTP"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="QxhAvqVF"; dkim-atps=neutral Received: from fhigh-a5-smtp.messagingengine.com (fhigh-a5-smtp.messagingengine.com [103.168.172.156]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id AE18362010 for ; Sat, 9 May 2026 00:37:34 +0200 (CEST) Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfhigh.phl.internal (Postfix) with ESMTP id 088481400105; Fri, 8 May 2026 18:37:34 -0400 (EDT) Received: from phl-imap-07 ([10.202.2.97]) by phl-compute-02.internal (MEProxy); Fri, 08 May 2026 18:37:34 -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=1778279854; x=1778366254; bh=LYgKNhBmw3BUeU2oSK8zFiAHchHx5V+6HJB/+afKJhM=; b= EJZo4LTP8VtGEBQKBVmoPXk8HJqCPrvuefXCuZsqpXlXqsrmheSX+5FXqff2Jsje hUOUR9Mo6pMS8wv88O7D7yx+iiO/4KLLiqTfWvYtp6PBaUQ4j4al8e21o1aH+xW2 /A2Hj2FCRdTpYBu18vv66+5zerb3xJIrFj0B281uasYr/UBKmg1Wm6sfzubhMxM1 1JcIdVpb5lYpbpIHmwdRz8MPYLnu+FPcDmk7mkSeGPhmdFQBwTbvC58wigOWYxOs nnBlMi+BoiWy3mpOsfLxkh7XxHkDXX2umDorOPU9lpoUqbsGqZ/UVuvHgHvA4QW7 XYTZFLtRh96i0NzDEcc/fA== 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=1778279854; x= 1778366254; bh=LYgKNhBmw3BUeU2oSK8zFiAHchHx5V+6HJB/+afKJhM=; b=Q xhAvqVFeoWF0EhHMiUwTY1R9UDvd6ew++qXwmr5tOpOAyx3Wv+TL/hMFRRlRvIz3 K0vMKBrWOLc9hIOOc1nMZGWWaKd7O8JC/I1oL3TrvxqPO8jerCqmpqAv1u0q+7rz Bi/Li4+wn9zKsKK7VdJSSTEQbelQXYanbvqzJpdmjHO10vq9+tabqF1U1aSSyhCt y84pi/zJs7qR0rxOkuBnuv0mNsobwrxJ9aurkE0OS13GA0jBT7Qzca7SuW/Tu5IB C2UDj6D3Zo1InCNeJ04DCZ2WPDWcQYEh3QqFH3apCilsgz37k55U7xQqQ67LeP/R zQEC/hRF87ehXe7a6Wsag== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdduudduheejucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucgopfhokfffucdluddtmdenucfjughrpefotggggffhvf ffufevjghfsehtkedttdertdejnecuhfhrohhmpeflrghvihgvrhcuvfhirgcuoehflhho shhssehjvghtmhdrmhgvqeenucggtffrrghtthgvrhhnpedtudejffejkeekteelueefvd ejvdeuhfefteehkeevtddvleduteekleetvdelhfenucevlhhushhtvghrufhiiigvpedt necurfgrrhgrmhepmhgrihhlfhhrohhmpehflhhoshhssehjvghtmhdrmhgvpdhnsggprh gtphhtthhopeejpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehrohgsvghrthdr mhgruggvrhestgholhhlrggsohhrrgdrtghomhdprhgtphhtthhopegsrghrnhgrsggrsh drphhotgiivgesihguvggrshhonhgsohgrrhgurdgtohhmpdhrtghpthhtohepkhhivghr rghnrdgsihhnghhhrghmsehiuggvrghsohhnsghorghrugdrtghomhdprhgtphhtthhope hlrghurhgvnhhtrdhpihhntghhrghrthesihguvggrshhonhgsohgrrhgurdgtohhmpdhr tghpthhtohepfhhlohhsshesjhgvthhmrdhmvgdprhgtphhtthhopehlihgstggrmhgvrh grqdguvghvvghlsehlihhsthhsrdhlihgstggrmhgvrhgrrdhorhhgpdhrtghpthhtohep mhiirghmrgiirghlsehrvgguhhgrthdrtghomh X-ME-Proxy: Feedback-ID: i9dde48b3:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id DA0831EA006C; Fri, 8 May 2026 18:37:33 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface MIME-Version: 1.0 From: Javier Tia To: libcamera-devel@lists.libcamera.org Date: Fri, 08 May 2026 15:35:46 -0600 Subject: [PATCH v2 1/2] libcamera: libipa: Add right-shift operators to Vector Cc: mzamazal@redhat.com, kieran.bingham@ideasonboard.com, laurent.pinchart@ideasonboard.com, barnabas.pocze@ideasonboard.com, robert.mader@collabora.com In-Reply-To: <177827984964.786021.2242634090011461397@jetm.me> References: <177827984964.786021.2242634090011461397@jetm.me> Message-Id: <20260508223733.DA0831EA006C@mailuser.phl.internal> 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 --- include/libcamera/internal/vector.h | 22 ++++++++++++++++++---- src/libcamera/vector.cpp | 14 ++++++++++++++ 2 files changed, 32 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..d3b7e4ab 100644 --- a/src/libcamera/vector.cpp +++ b/src/libcamera/vector.cpp @@ -126,6 +126,20 @@ 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>>=(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::operator+=(Vector const &other) * \brief Add \a other element-wise to this vector From patchwork Fri May 8 21:35:57 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Javier Tia X-Patchwork-Id: 26707 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 72C94BE173 for ; Fri, 8 May 2026 22:37:41 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id F2B5A6302E; Sat, 9 May 2026 00:37:39 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (2048-bit key; unprotected) header.d=jetm.me header.i=@jetm.me header.b="jSefRTNb"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="DXE3DUaP"; dkim-atps=neutral Received: from fhigh-a5-smtp.messagingengine.com (fhigh-a5-smtp.messagingengine.com [103.168.172.156]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 21E0E62FEA for ; Sat, 9 May 2026 00:37:37 +0200 (CEST) Received: from phl-compute-02.internal (phl-compute-02.internal [10.202.2.42]) by mailfhigh.phl.internal (Postfix) with ESMTP id 298BC1400106; Fri, 8 May 2026 18:37:36 -0400 (EDT) Received: from phl-imap-07 ([10.202.2.97]) by phl-compute-02.internal (MEProxy); Fri, 08 May 2026 18:37:36 -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=1778279856; x=1778366256; bh=rdl7FlZRDD5hPRomwZIvt+J7x8ER3CE2Z9z6Qt9njHI=; b= jSefRTNb0vkHx8JB9tQYgYSusy6CJo+dVpJTuU5A+0EAygHq31D101DTnMIhkW0T SpLbBL0DA3fgNfeQ3khNlNnEqMURsJeJsOKCU/IyNYH2JWcOl6oltMzZIJsiEGRe 3wtZdRUVR8Lwz9tn8fF6E6Y/kiovd872dPLvuveuZVrJqUr2bcXVYpFQ0JYjd0ww IUD+k9msO6cySUjdk1vS225Ewd+fU7Dr+kMTIgRib/rNtVazNY7A1FoiuUfMZ6vd 5tuZvjAW6j93jt/+uw4ZXPZ4ylFJpLqiVuW2oEsBu+aG0qJZThINWvMhvYgVv01l h+3vhbHxLOsNk2ZxjWlSDg== 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=1778279856; x= 1778366256; bh=rdl7FlZRDD5hPRomwZIvt+J7x8ER3CE2Z9z6Qt9njHI=; b=D XE3DUaPcbNJo80g3CxM7Wt9h3RHvpm0BnaXBOwb2Hn0WIDk4EKqKZUP6fb6aNl1W cxKl9tzsjrMisIwwPbFhbqPI72Ig+TldhWrgTH3xkjneIWGpqM/h12/wrgJA121+ vfq9Jo4bBvpaU51cMlPlmfBARKLzVtKSAhrDDfKDtl8GDDqIq8aKsjPSqgwlgR9e F1GdFsQAyYxVoVSkM5xauv3xFtRxnRNX80TJs97BQAQXBrvjouBvHGVoRYVvi71N rAYRc/1qhbgGFIjx7Xua+Fho3DCZyKbMLd6BUf6PHg+SoOLeWyZQNWFpd3tG+YFR Nr6r3VjzOGqnXLbDNjFVg== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdduudduheejucetufdoteggodetrf dotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu rghilhhouhhtmecufedttdenucgopfhokfffucdluddtmdenucfjughrpefotggggffhvf ffufevjghfsehtkedttdertdejnecuhfhrohhmpeflrghvihgvrhcuvfhirgcuoehflhho shhssehjvghtmhdrmhgvqeenucggtffrrghtthgvrhhnpedtudejffejkeekteelueefvd ejvdeuhfefteehkeevtddvleduteekleetvdelhfenucevlhhushhtvghrufhiiigvpedt necurfgrrhgrmhepmhgrihhlfhhrohhmpehflhhoshhssehjvghtmhdrmhgvpdhnsggprh gtphhtthhopeejpdhmohguvgepshhmthhpohhuthdprhgtphhtthhopehrohgsvghrthdr mhgruggvrhestgholhhlrggsohhrrgdrtghomhdprhgtphhtthhopegsrghrnhgrsggrsh drphhotgiivgesihguvggrshhonhgsohgrrhgurdgtohhmpdhrtghpthhtohepkhhivghr rghnrdgsihhnghhhrghmsehiuggvrghsohhnsghorghrugdrtghomhdprhgtphhtthhope hlrghurhgvnhhtrdhpihhntghhrghrthesihguvggrshhonhgsohgrrhgurdgtohhmpdhr tghpthhtohepfhhlohhsshesjhgvthhmrdhmvgdprhgtphhtthhopehlihgstggrmhgvrh grqdguvghvvghlsehlihhsthhsrdhlihgstggrmhgvrhgrrdhorhhgpdhrtghpthhtohep mhiirghmrgiirghlsehrvgguhhgrthdrtghomh X-ME-Proxy: Feedback-ID: i9dde48b3:Fastmail Received: by mailuser.phl.internal (Postfix, from userid 501) id 0B7291EA006C; Fri, 8 May 2026 18:37:36 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface MIME-Version: 1.0 From: Javier Tia To: libcamera-devel@lists.libcamera.org Date: Fri, 08 May 2026 15:35:57 -0600 Subject: [PATCH v2 2/2] libcamera: software_isp: Use Vector operator>>= in finishFrame Cc: mzamazal@redhat.com, kieran.bingham@ideasonboard.com, laurent.pinchart@ideasonboard.com, barnabas.pocze@ideasonboard.com, robert.mader@collabora.com In-Reply-To: <177827984964.786021.2242634090011461397@jetm.me> References: <177827984964.786021.2242634090011461397@jetm.me> Message-Id: <20260508223736.0B7291EA006C@mailuser.phl.internal> 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 --- 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;