From patchwork Sat Jun 20 23:00:28 2026 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kieran Bingham X-Patchwork-Id: 26998 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 CEA73C3303 for ; Sat, 20 Jun 2026 23:00:45 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 1142365702; Sun, 21 Jun 2026 01:00:40 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="i7vb/rGr"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 13AD2656D6 for ; Sun, 21 Jun 2026 01:00:36 +0200 (CEST) Received: from [192.168.0.240] (cpc89244-aztw30-2-0-cust6594.18-1.cable.virginm.net [86.31.185.195]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id B875CB8B; Sun, 21 Jun 2026 00:59:58 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1781996398; bh=9qKWrXCM3qnZu1o6pRQj8bxGCCmlSd/kEaWHYvvQaPo=; h=From:Date:Subject:References:In-Reply-To:To:Cc:From; b=i7vb/rGrMja1RtZGp5eo+td7S0iFW/w3JAF13Um4Phw0FPoZoL2/LgXPn5fkqQRcQ yTJCJXio+vxhhkZhGkrRk/eiOF+nsYeB4fRrVD7BKazHHBL2ZWEJ+WQOFJZFGA4fP1 gBQShtIMI0xT3r6cZX4tQVpaKYoThHboBNPbTAlM= From: Kieran Bingham Date: Sun, 21 Jun 2026 00:00:28 +0100 Subject: [PATCH 1/7] libcamera: vector: Add clamp operation MIME-Version: 1.0 Message-Id: <20260621-kbingham-awb-saturation-v1-1-b91ea59c6cfb@ideasonboard.com> References: <20260621-kbingham-awb-saturation-v1-0-b91ea59c6cfb@ideasonboard.com> In-Reply-To: <20260621-kbingham-awb-saturation-v1-0-b91ea59c6cfb@ideasonboard.com> To: libcamera-devel@lists.libcamera.org Cc: Kieran Bingham , Laurent Pinchart X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1781996434; l=2357; i=kieran.bingham@ideasonboard.com; s=20260204; h=from:subject:message-id; bh=9qKWrXCM3qnZu1o6pRQj8bxGCCmlSd/kEaWHYvvQaPo=; b=wcBL9tQXhGZHKwNGQKtPeZHXRoIGu923Cnic5hspX+2KXHKq3qEsZuk8o5ZsteAFQocNOrEz2 8z2hFZ33oHaBw6T0s41gPtPE8kKvyb3F6OmpbrqGcoA4tB+VWE9ieeR X-Developer-Key: i=kieran.bingham@ideasonboard.com; a=ed25519; pk=IOxS2C6nWHNjLfkDR71Iesk904i6wJDfEERqV7hDBdY= 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" Provide a helper that will perform a std::clamp given a scaler high and low value to clamp to. Suggested-by: Laurent Pinchart Signed-off-by: Kieran Bingham --- include/libcamera/internal/vector.h | 8 ++++++++ src/libcamera/vector.cpp | 8 ++++++++ test/vector.cpp | 1 + 3 files changed, 17 insertions(+) diff --git a/include/libcamera/internal/vector.h b/include/libcamera/internal/vector.h index 093efafa8982fe553a953316ac794bef46eec5d4..17ecbda50f2dc4363548a4a29639a751a187dac6 100644 --- a/include/libcamera/internal/vector.h +++ b/include/libcamera/internal/vector.h @@ -185,6 +185,14 @@ public: return apply(*this, scalar, [](T a, T b) -> T { return std::max(a, b); }); } + constexpr Vector clamp(T low, T high) const + { + Vector result; + for (unsigned int i = 0; i < Rows; i++) + result[i] = std::clamp(data_[i], low, high); + return result; + } + constexpr T dot(const Vector &other) const { T ret = 0; diff --git a/src/libcamera/vector.cpp b/src/libcamera/vector.cpp index 47b3d1af36d90f9719c527b8458fbfe07412239e..a135ab498e17149b9dc54de7204e8a34262a2da9 100644 --- a/src/libcamera/vector.cpp +++ b/src/libcamera/vector.cpp @@ -224,6 +224,14 @@ LOG_DEFINE_CATEGORY(Vector) * \return The element-wise maximum of this vector and \a scalar */ +/** + * \fn Vector::clamp(T low, T high) const + * \brief Clamp the vector element-wise between \a low and \a high + * \param[in] low The lower limit + * \param[in] high The upper limit + * \return A vector with each element clamped between \a low and \a high + */ + /** * \fn Vector::dot(const Vector &other) const * \brief Compute the dot product diff --git a/test/vector.cpp b/test/vector.cpp index 4ff908e8f682f19d65c55d071fcd300071cf90ac..2f3d97d93dccbe153f2d1cf536423f7446a22aab 100644 --- a/test/vector.cpp +++ b/test/vector.cpp @@ -72,6 +72,7 @@ protected: ASSERT_EQ(v2.min(4.0), (Vector{{ 1.0, 4.0, 4.0 }})); ASSERT_EQ(v2.max(v3), (Vector{{ 4.0, 4.0, 8.0 }})); ASSERT_EQ(v2.max(4.0), (Vector{{ 4.0, 4.0, 8.0 }})); + ASSERT_EQ(v2.clamp(2.0, 6.0), (Vector{{ 2.0, 4.0, 6.0 }})); ASSERT_EQ(v2.dot(v3), 52.0);