Show a patch.

GET /api/patches/26718/?format=api
HTTP 200 OK
Allow: GET, PUT, PATCH, HEAD, OPTIONS
Content-Type: application/json
Vary: Accept

{
    "id": 26718,
    "url": "https://patchwork.libcamera.org/api/patches/26718/?format=api",
    "web_url": "https://patchwork.libcamera.org/patch/26718/",
    "project": {
        "id": 1,
        "url": "https://patchwork.libcamera.org/api/projects/1/?format=api",
        "name": "libcamera",
        "link_name": "libcamera",
        "list_id": "libcamera_core",
        "list_email": "libcamera-devel@lists.libcamera.org",
        "web_url": "",
        "scm_url": "",
        "webscm_url": ""
    },
    "msgid": "<20260511-libipa-vector-rshift-v3-1-a275f6e87ec4@jetm.me>",
    "date": "2026-05-11T20:23:28",
    "name": "[v3,1/2] libcamera: libipa: Add right-shift operators to Vector",
    "commit_ref": null,
    "pull_url": null,
    "state": "accepted",
    "archived": false,
    "hash": "b1568dc1491395862ed11267e5e26b698ff4ccf8",
    "submitter": {
        "id": 261,
        "url": "https://patchwork.libcamera.org/api/people/261/?format=api",
        "name": "Javier Tia",
        "email": "floss@jetm.me"
    },
    "delegate": null,
    "mbox": "https://patchwork.libcamera.org/patch/26718/mbox/",
    "series": [
        {
            "id": 5934,
            "url": "https://patchwork.libcamera.org/api/series/5934/?format=api",
            "web_url": "https://patchwork.libcamera.org/project/libcamera/list/?series=5934",
            "date": "2026-05-11T20:23:27",
            "name": "libcamera: Vector right-shift operators and SwStatsCpu use site",
            "version": 3,
            "mbox": "https://patchwork.libcamera.org/series/5934/mbox/"
        }
    ],
    "comments": "https://patchwork.libcamera.org/api/patches/26718/comments/",
    "check": "pending",
    "checks": "https://patchwork.libcamera.org/api/patches/26718/checks/",
    "tags": {},
    "headers": {
        "Return-Path": "<libcamera-devel-bounces@lists.libcamera.org>",
        "X-Original-To": "parsemail@patchwork.libcamera.org",
        "Delivered-To": "parsemail@patchwork.libcamera.org",
        "Received": [
            "from lancelot.ideasonboard.com (lancelot.ideasonboard.com\n\t[92.243.16.209])\n\tby patchwork.libcamera.org (Postfix) with ESMTPS id 9F07FBDCBD\n\tfor <parsemail@patchwork.libcamera.org>;\n\tMon, 11 May 2026 20:23:36 +0000 (UTC)",
            "from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id AECBA63021;\n\tMon, 11 May 2026 22:23:34 +0200 (CEST)",
            "from fhigh-b2-smtp.messagingengine.com\n\t(fhigh-b2-smtp.messagingengine.com [202.12.124.153])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 8124D62E9D\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tMon, 11 May 2026 22:23:32 +0200 (CEST)",
            "from phl-compute-02.internal (phl-compute-02.internal\n\t[10.202.2.42])\n\tby mailfhigh.stl.internal (Postfix) with ESMTP id 933307A0081;\n\tMon, 11 May 2026 16:23:31 -0400 (EDT)",
            "from phl-imap-07 ([10.202.2.97])\n\tby phl-compute-02.internal (MEProxy); Mon, 11 May 2026 16:23:31 -0400",
            "by mailuser.phl.internal (Postfix, from userid 501)\n\tid 574EF1EA0070; Mon, 11 May 2026 16:23:31 -0400 (EDT)"
        ],
        "Authentication-Results": "lancelot.ideasonboard.com; dkim=pass (2048-bit key;\n\tunprotected) header.d=jetm.me header.i=@jetm.me header.b=\"mwMJUmEv\";\n\tdkim=pass (2048-bit key;\n\tunprotected) header.d=messagingengine.com\n\theader.i=@messagingengine.com header.b=\"nI1/HHVX\"; \n\tdkim-atps=neutral",
        "DKIM-Signature": [
            "v=1; a=rsa-sha256; c=relaxed/relaxed; d=jetm.me; h=cc:cc\n\t:content-transfer-encoding:content-type:content-type:date:date\n\t:from:from:in-reply-to:in-reply-to:message-id:mime-version\n\t:references:reply-to:subject:subject:to:to; s=fm2; t=1778531011;\n\tx=1778617411; bh=ngtRot1spR1XomwaiLpsDsXkMgoYsJyGBfCUEmdxQXY=; b=\n\tmwMJUmEvkrq/F5vuqE3UQIzaOs1wEmjTxKJg5icmChhFzPvo//PrVwn7H0sFsOl6\n\tv4dIeAN/y+rVBkE/3yfDDUoHRtVevzCn5n9/m2+2DZQSxW/y3IyakIsdV/b8Xt2c\n\t3lFnp6Hbuk2UwSQYKiFhvy/bPUYFKhL+XqxwhOZgQqbo6EZrFkKbKTH44QaeBcxB\n\tyDervM4Lxp6rNw0u30KlV5zQfiCreITab1ejXG0S3YpUaY0fmxxUdvkpsqJusZrK\n\tcFnUcaw54I6j6JV+QQpFjv++LTUkkRhxvGbARg1NWkv0gYVbPbEISa7WFxHT8e4D\n\tnuocz83/xhC6g5yUAcNDfw==",
            "v=1; a=rsa-sha256; c=relaxed/relaxed; d=\n\tmessagingengine.com; h=cc:cc:content-transfer-encoding\n\t:content-type:content-type:date:date:feedback-id:feedback-id\n\t:from:from:in-reply-to:in-reply-to:message-id:mime-version\n\t:references:reply-to:subject:subject:to:to:x-me-proxy\n\t:x-me-sender:x-me-sender:x-sasl-enc; s=fm3; t=1778531011; x=\n\t1778617411; bh=ngtRot1spR1XomwaiLpsDsXkMgoYsJyGBfCUEmdxQXY=; b=n\n\tI1/HHVXL2jrO+4wu0M4QZrQoBHGEP2ophb3lbl++DEgWY8tO7qltPZ5OyNCy0S91\n\tprxh5d/msby0EVBLry40a3JXlKksDruEmsm2C3re+iR09u8mvxC6HYMIyWujdrSp\n\thDu4IMZBQpFjALY5k9lVbp8z15EB7lPY9TdDTNdRnfzuZSQlBVLZgU5j1WkecTxZ\n\thNpaR7ScpmW84tDxlUCu/j4L6NZ6dBvRk+t9TfbC34ivMfl4s16hzKwklFFtyZoM\n\tIV69pQq8Iw7536Q4q8D5lDHLxA+jdjgVQyVbarrntehHr63OK+FQClC9JHUN0J4I\n\toOsI/npMsx/QIyQ5zoO0Q=="
        ],
        "X-ME-Sender": "<xms:wzoCap0jepGqxhuYka67ejmfrAoW7kjDU1cvmyEhu_mAys5UEiZ8EQ>\n\t<xme:wzoCaq4LS4MkxLv6QOrvM_PtJk_kHxSgVxSY65uBIxVkRvacdzx2sW4r8adChkTnh\n\t9y3BeI6iHwV25ILqHpaUAKlCg8JPxepznlrN0MhuGD6SDNwHzHyxuo>",
        "X-ME-Proxy-Cause": "gggruggvucftvghtrhhoucdtuddrgeefhedrtddtgdduudelkeejucetufdoteggodetrf\n\tdotffvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfurfetoffkrfgpnffqhgenuceu\n\trghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmnecujf\n\tgurhepoffhfffugggtgffkvfevofgjfhesthekredtredtjeenucfhrhhomheplfgrvhhi\n\tvghrucfvihgruceofhhlohhsshesjhgvthhmrdhmvgeqnecuggftrfgrthhtvghrnhepve\n\tektdfhffevuddtgfetieevtddvheduhfeggfekveejlefhleefieevueefiefhnecuvehl\n\tuhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhepfhhlohhsshesjh\n\tgvthhmrdhmvgdpnhgspghrtghpthhtohepfedpmhhouggvpehsmhhtphhouhhtpdhrtghp\n\tthhtohepsggrrhhnrggsrghsrdhpohgtiigvsehiuggvrghsohhnsghorghrugdrtghomh\n\tdprhgtphhtthhopehlrghurhgvnhhtrdhpihhntghhrghrthesihguvggrshhonhgsohgr\n\trhgurdgtohhmpdhrtghpthhtoheplhhisggtrghmvghrrgdquggvvhgvlheslhhishhtsh\n\tdrlhhisggtrghmvghrrgdrohhrgh",
        "X-ME-Proxy": "<xmx:wzoCakyTljCrvNA8j2VCKMkLDiqpClEHMrkBQ0dPUVYdmEL5A7V2kw>\n\t<xmx:wzoCagCDTZNWlqQlzYcXVIsGM8BTE8gLqCoZcLcqjHIOT2QtLAs-uA>\n\t<xmx:wzoCapZCFIqQ9N2a1IJYEFM9Q8pXOkTtnl3RCQLM-TmeQbsyIVexxQ>\n\t<xmx:wzoCagifTH_NXGW5QhNPaEobYVh-aKagejBjXep3WHGfTUbzIKLvgA>\n\t<xmx:wzoCaha8uduRv6ZCDxcFr9jgODaAHN15wJPHMjsp3aimK4d9HU7f12A1>",
        "Feedback-ID": "i9dde48b3:Fastmail",
        "X-Mailer": [
            "MessagingEngine.com Webmail Interface",
            "b4 0.15.2"
        ],
        "From": "Javier Tia <floss@jetm.me>",
        "Date": "Mon, 11 May 2026 14:23:28 -0600",
        "Subject": "[PATCH v3 1/2] libcamera: libipa: Add right-shift operators to\n\tVector",
        "MIME-Version": "1.0",
        "Content-Type": "text/plain; charset=\"utf-8\"",
        "Content-Transfer-Encoding": "8bit",
        "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?= <barnabas.pocze@ideasonboard.com>,\n\tLaurent Pinchart <laurent.pinchart@ideasonboard.com>",
        "X-Developer-Signature": "v=1; a=openpgp-sha256; l=4550; i=floss@jetm.me;\n\th=from:subject:message-id;\n\tbh=ofQLSaGclfdIwbb2SwinFaJzbTmyc9ph2VywRC17YMU=; \n\tb=owEB7QES/pANAwAKAbXuwwuoZ3cfAcsmYgBqAjq/dIGqIVheaYjakOCA/YNfIS+Ms2Jlff+sc\n\tdZGkxBnWO6JAbMEAAEKAB0WIQSbE7ILzw7eI0VKk8m17sMLqGd3HwUCagI6vwAKCRC17sMLqGd3\n\tHyAFC/9N4TLFkWSljvlVGg4cYZWeJdT02g80Kzrj/U13vpAVrnMWrAp9V+UPmAc2nNsz1w0n69o\n\tTyI14HKslumrmpDw1iOcUhrxPjj+KmVu35hncGcXGBhXg2iPTQSTuFOzxAnMTKYGjZ08wq1Oklq\n\tWT+6HHg4iKLb948SBqX2Jb4NjR/104GEc2HzKtt4zWqNRkX6AnLRnF+4YlIYrIwJJLv93jA17RK\n\tKycVI8O6cPebJq2qutlQbrzmiWvVmAYEslzh7vyy1op9W4eC6zTcu6EHbZ0Kr6P0cuZIYHdkEJR\n\tZraU6AlBxsZSpOAxG1G/hsl4KW0JUhAde4abhua+HE658+qSUhOJ1ItRYXqgnAveN8lSUijxRUB\n\tKA1m1bPPyMVAT4LYxdAsW5L0fYotKlY/x9j4spboFp54xaxZCcJWkCaN2Q39FvfGvz8KI8SIx0o\n\tarAF8x5+WReAJ4L2yzbsDhPm0GrrK4axmPDAHXCMGXs20Xyu0y92Hp9+00/ieV2Hkx6dI=",
        "X-Developer-Key": "i=floss@jetm.me; a=openpgp;\n\tfpr=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": "<libcamera-devel.lists.libcamera.org>",
        "List-Unsubscribe": "<https://lists.libcamera.org/options/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=unsubscribe>",
        "List-Archive": "<https://lists.libcamera.org/pipermail/libcamera-devel/>",
        "List-Post": "<mailto:libcamera-devel@lists.libcamera.org>",
        "List-Help": "<mailto:libcamera-devel-request@lists.libcamera.org?subject=help>",
        "List-Subscribe": "<https://lists.libcamera.org/listinfo/libcamera-devel>,\n\t<mailto:libcamera-devel-request@lists.libcamera.org?subject=subscribe>",
        "Errors-To": "libcamera-devel-bounces@lists.libcamera.org",
        "Sender": "\"libcamera-devel\" <libcamera-devel-bounces@lists.libcamera.org>"
    },
    "content": "Add operator>> and operator>>= for right-shifting all elements by a\nscalar shift amount. Both operate element-wise: operator>> returns a\nnew Vector with each element shifted, operator>>= shifts in place and\nreturns a reference to *this.\n\nThe motivating use case is SwStatsCpu::finishFrame(), which right-shifts\nthree individual components of the RGB sum by the same sumShift_ value.\nWith these operators that becomes a single sum_ >>= sumShift_ expression.\n\nThe private apply() helpers for non-mutating and mutating scalar\noperations are templated on the scalar type so the existing operators\nkeep working with T while shift can pass an unsigned int. A\nstatic_assert in each shift operator restricts them to integer element\ntypes since right-shift is undefined on floating-point Vectors.\n\nSuggested-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\nSuggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\nSigned-off-by: Javier Tia <floss@jetm.me>\nReviewed-by: Barnabás Pőcze <barnabas.pocze@ideasonboard.com>\n---\n include/libcamera/internal/vector.h | 22 ++++++++++++++++++----\n src/libcamera/vector.cpp            | 14 ++++++++++++++\n test/vector.cpp                     |  5 +++++\n 3 files changed, 37 insertions(+), 4 deletions(-)",
    "diff": "diff --git a/include/libcamera/internal/vector.h b/include/libcamera/internal/vector.h\nindex ed7490e1..e3ea723d 100644\n--- a/include/libcamera/internal/vector.h\n+++ b/include/libcamera/internal/vector.h\n@@ -111,6 +111,13 @@ public:\n \t\treturn apply(*this, scalar, std::divides<>{});\n \t}\n \n+\tconstexpr Vector operator>>(unsigned int shift) const\n+\t{\n+\t\tstatic_assert(std::is_integral_v<T>,\n+\t\t\t      \"Vector::operator>> requires an integer element type\");\n+\t\treturn apply(*this, shift, [](T a, unsigned int b) { return a >> b; });\n+\t}\n+\n \tVector &operator+=(const Vector &other)\n \t{\n \t\treturn apply(other, [](T a, T b) { return a + b; });\n@@ -151,6 +158,13 @@ public:\n \t\treturn apply(scalar, [](T a, T b) { return a / b; });\n \t}\n \n+\tVector &operator>>=(unsigned int shift)\n+\t{\n+\t\tstatic_assert(std::is_integral_v<T>,\n+\t\t\t      \"Vector::operator>>= requires an integer element type\");\n+\t\treturn apply(shift, [](T a, unsigned int b) { return a >> b; });\n+\t}\n+\n \tconstexpr Vector min(const Vector &other) const\n \t{\n \t\treturn apply(*this, other, [](T a, T b) { return std::min(a, b); });\n@@ -260,8 +274,8 @@ private:\n \t\treturn result;\n \t}\n \n-\ttemplate<class BinaryOp>\n-\tstatic constexpr Vector apply(const Vector &lhs, T rhs, BinaryOp op)\n+\ttemplate<class U, class BinaryOp>\n+\tstatic constexpr Vector apply(const Vector &lhs, U rhs, BinaryOp op)\n \t{\n \t\tVector result;\n \t\tstd::transform(lhs.data_.begin(), lhs.data_.end(),\n@@ -281,8 +295,8 @@ private:\n \t\treturn *this;\n \t}\n \n-\ttemplate<class BinaryOp>\n-\tVector &apply(T scalar, BinaryOp op)\n+\ttemplate<class U, class BinaryOp>\n+\tVector &apply(U scalar, BinaryOp op)\n \t{\n \t\tstd::for_each(data_.begin(), data_.end(),\n \t\t\t      [&op, scalar](T &v) { v = op(v, scalar); });\ndiff --git a/src/libcamera/vector.cpp b/src/libcamera/vector.cpp\nindex 86b9f9bb..94fbf61e 100644\n--- a/src/libcamera/vector.cpp\n+++ b/src/libcamera/vector.cpp\n@@ -126,6 +126,13 @@ LOG_DEFINE_CATEGORY(Vector)\n  * \\return The element-wise division of this vector by \\a scalar\n  */\n \n+/**\n+ * \\fn Vector::operator>>(unsigned int shift) const\n+ * \\brief Right-shift each element of this vector by \\a shift bits\n+ * \\param[in] shift The shift amount\n+ * \\return A new vector with each element right-shifted by \\a shift\n+ */\n+\n /**\n  * \\fn Vector::operator+=(Vector const &other)\n  * \\brief Add \\a other element-wise to this vector\n@@ -182,6 +189,13 @@ LOG_DEFINE_CATEGORY(Vector)\n  * \\return This vector\n  */\n \n+/**\n+ * \\fn Vector::operator>>=(unsigned int shift)\n+ * \\brief Right-shift each element of this vector by \\a shift bits in place\n+ * \\param[in] shift The shift amount\n+ * \\return This vector\n+ */\n+\n /**\n  * \\fn Vector::min(const Vector &other) const\n  * \\brief Calculate the minimum of this vector and \\a other element-wise\ndiff --git a/test/vector.cpp b/test/vector.cpp\nindex 4fae960d..4ff908e8 100644\n--- a/test/vector.cpp\n+++ b/test/vector.cpp\n@@ -93,6 +93,11 @@ protected:\n \t\tv2 /= 4.0;\n \t\tASSERT_EQ(v2, (Vector<double, 3>{{ 1.0, 4.0, 8.0 }}));\n \n+\t\tVector<int, 3> vi{{ 8, 16, 32 }};\n+\t\tASSERT_EQ(vi >> 2, (Vector<int, 3>{{ 2, 4, 8 }}));\n+\t\tvi >>= 1;\n+\t\tASSERT_EQ(vi, (Vector<int, 3>{{ 4, 8, 16 }}));\n+\n \t\treturn TestPass;\n \t}\n };\n",
    "prefixes": [
        "v3",
        "1/2"
    ]
}