[{"id":39202,"web_url":"https://patchwork.libcamera.org/comment/39202/","msgid":"<20260621001923.GF3552167@killaraus.ideasonboard.com>","date":"2026-06-21T00:19:23","subject":"Re: [PATCH 1/7] libcamera: vector: Add clamp operation","submitter":{"id":2,"url":"https://patchwork.libcamera.org/api/people/2/","name":"Laurent Pinchart","email":"laurent.pinchart@ideasonboard.com"},"content":"Hi Kieran,\n\nThank you for the patch.\n\nOn Sun, Jun 21, 2026 at 12:00:28AM +0100, Kieran Bingham wrote:\n> Provide a helper that will perform a std::clamp given a scaler high and\n> low value to clamp to.\n> \n> Suggested-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>\n> Signed-off-by: Kieran Bingham <kieran.bingham@ideasonboard.com>\n> ---\n>  include/libcamera/internal/vector.h | 8 ++++++++\n>  src/libcamera/vector.cpp            | 8 ++++++++\n>  test/vector.cpp                     | 1 +\n>  3 files changed, 17 insertions(+)\n> \n> diff --git a/include/libcamera/internal/vector.h b/include/libcamera/internal/vector.h\n> index 093efafa8982fe553a953316ac794bef46eec5d4..17ecbda50f2dc4363548a4a29639a751a187dac6 100644\n> --- a/include/libcamera/internal/vector.h\n> +++ b/include/libcamera/internal/vector.h\n> @@ -185,6 +185,14 @@ public:\n>  \t\treturn apply(*this, scalar, [](T a, T b) -> T { return std::max(a, b); });\n>  \t}\n>  \n> +\tconstexpr Vector clamp(T low, T high) const\n> +\t{\n> +\t\tVector result;\n> +\t\tfor (unsigned int i = 0; i < Rows; i++)\n> +\t\t\tresult[i] = std::clamp(data_[i], low, high);\n\nI toyed with the idea of replacing\n\n\ttemplate<class U, class BinaryOp>\n\tstatic constexpr Vector apply(const Vector &lhs, U rhs, BinaryOp op)\n\nwith\n\n\ttemplate<class U..., class BinaryOp>\n\tstatic constexpr Vector apply(const Vector &lhs, U... rhs, BinaryOp op)\n\nPatch series coming soon.\n\n> +\t\treturn result;\n> +\t}\n> +\n>  \tconstexpr T dot(const Vector<T, Rows> &other) const\n>  \t{\n>  \t\tT ret = 0;\n> diff --git a/src/libcamera/vector.cpp b/src/libcamera/vector.cpp\n> index 47b3d1af36d90f9719c527b8458fbfe07412239e..a135ab498e17149b9dc54de7204e8a34262a2da9 100644\n> --- a/src/libcamera/vector.cpp\n> +++ b/src/libcamera/vector.cpp\n> @@ -224,6 +224,14 @@ LOG_DEFINE_CATEGORY(Vector)\n>   * \\return The element-wise maximum of this vector and \\a scalar\n>   */\n>  \n> +/**\n> + * \\fn Vector::clamp(T low, T high) const\n> + * \\brief Clamp the vector element-wise between \\a low and \\a high\n> + * \\param[in] low The lower limit\n> + * \\param[in] high The upper limit\n> + * \\return A vector with each element clamped between \\a low and \\a high\n> + */\n> +\n>  /**\n>   * \\fn Vector::dot(const Vector<T, Rows> &other) const\n>   * \\brief Compute the dot product\n> diff --git a/test/vector.cpp b/test/vector.cpp\n> index 4ff908e8f682f19d65c55d071fcd300071cf90ac..2f3d97d93dccbe153f2d1cf536423f7446a22aab 100644\n> --- a/test/vector.cpp\n> +++ b/test/vector.cpp\n> @@ -72,6 +72,7 @@ protected:\n>  \t\tASSERT_EQ(v2.min(4.0), (Vector<double, 3>{{ 1.0, 4.0, 4.0 }}));\n>  \t\tASSERT_EQ(v2.max(v3), (Vector<double, 3>{{ 4.0, 4.0, 8.0 }}));\n>  \t\tASSERT_EQ(v2.max(4.0), (Vector<double, 3>{{ 4.0, 4.0, 8.0 }}));\n> +\t\tASSERT_EQ(v2.clamp(2.0, 6.0), (Vector<double, 3>{{ 2.0, 4.0, 6.0 }}));\n>  \n>  \t\tASSERT_EQ(v2.dot(v3), 52.0);\n>","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 BD415C3302\n\tfor <parsemail@patchwork.libcamera.org>;\n\tSun, 21 Jun 2026 00:19:27 +0000 (UTC)","from lancelot.ideasonboard.com (localhost [IPv6:::1])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTP id C0A74656E5;\n\tSun, 21 Jun 2026 02:19:26 +0200 (CEST)","from perceval.ideasonboard.com (perceval.ideasonboard.com\n\t[213.167.242.64])\n\tby lancelot.ideasonboard.com (Postfix) with ESMTPS id 405AB656DE\n\tfor <libcamera-devel@lists.libcamera.org>;\n\tSun, 21 Jun 2026 02:19:25 +0200 (CEST)","from killaraus.ideasonboard.com\n\t(2001-14ba-70f3-e800--a06.rev.dnainternet.fi\n\t[IPv6:2001:14ba:70f3:e800::a06])\n\tby perceval.ideasonboard.com (Postfix) with ESMTPSA id 1BE4B268;\n\tSun, 21 Jun 2026 02:18:48 +0200 (CEST)"],"Authentication-Results":"lancelot.ideasonboard.com; dkim=pass (1024-bit key;\n\tunprotected) header.d=ideasonboard.com header.i=@ideasonboard.com\n\theader.b=\"PcZ/r0MJ\"; dkim-atps=neutral","DKIM-Signature":"v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com;\n\ts=mail; t=1782001128;\n\tbh=e6212rCL9sgD4CRzTqyn1d+otPrL2mnTWMB/pu8e8W4=;\n\th=Date:From:To:Cc:Subject:References:In-Reply-To:From;\n\tb=PcZ/r0MJngbDCwvyzw+i/efnSavebzCRMz9W1CiKqMXfD7jE+V/tzmgzVu6QFjyHy\n\tbGJI/3unTvEv4CORVHKCk83RUPBwNs5N7Dj2fyYM96V/1MIdwu0F5oe9vBg9kU1NLc\n\tjXGWzDVxTSZQAtm/Ji7cQROcIH1vEnvyTJZSTL20=","Date":"Sun, 21 Jun 2026 03:19:23 +0300","From":"Laurent Pinchart <laurent.pinchart@ideasonboard.com>","To":"Kieran Bingham <kieran.bingham@ideasonboard.com>","Cc":"libcamera-devel@lists.libcamera.org","Subject":"Re: [PATCH 1/7] libcamera: vector: Add clamp operation","Message-ID":"<20260621001923.GF3552167@killaraus.ideasonboard.com>","References":"<20260621-kbingham-awb-saturation-v1-0-b91ea59c6cfb@ideasonboard.com>\n\t<20260621-kbingham-awb-saturation-v1-1-b91ea59c6cfb@ideasonboard.com>","MIME-Version":"1.0","Content-Type":"text/plain; charset=utf-8","Content-Disposition":"inline","In-Reply-To":"<20260621-kbingham-awb-saturation-v1-1-b91ea59c6cfb@ideasonboard.com>","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>"}}]