From patchwork Fri Apr 11 13:04:14 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 23174 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 74799C3213 for ; Fri, 11 Apr 2025 13:04:48 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 27B3868AB7; Fri, 11 Apr 2025 15:04:48 +0200 (CEST) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="q6CmMme1"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [213.167.242.64]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id 07A6D68AB7 for ; Fri, 11 Apr 2025 15:04:47 +0200 (CEST) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:5b21:2ad5:1023:7179]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id A3FFF735; Fri, 11 Apr 2025 15:02:47 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1744376567; bh=QRn+OoNJ58tmeeS9trxG0Oy1XFt/JcK3eLm7mqaQQn0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=q6CmMme1ltj1It/O3HWqQPRcBP5YB14wPKKIW+AlA3C7COri/p5bShhN8ZimJdvlv /uOgirQoBYv1kePIwNim3Q04/kPjRigJlCXMrTiHqxdKZpxaCXeh+8eInT1JimkE/1 hpg9L31ODKTD/MPIZbsRdWN4t+kivi6LQ0sEvNZA= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH 7/8] libcamera: vector: Add explicit cast and data accessor Date: Fri, 11 Apr 2025 15:04:14 +0200 Message-ID: <20250411130423.2164577-8-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250411130423.2164577-1-stefan.klug@ideasonboard.com> References: <20250411130423.2164577-1-stefan.klug@ideasonboard.com> MIME-Version: 1.0 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" When dealing with Vectors it is useful to be able to cast the to a different underlying type or to access the underlying data. Add functions for that. Signed-off-by: Stefan Klug --- include/libcamera/internal/vector.h | 11 +++++++++++ src/libcamera/vector.cpp | 18 ++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/include/libcamera/internal/vector.h b/include/libcamera/internal/vector.h index 16b6aef0b38f..63da55019aef 100644 --- a/include/libcamera/internal/vector.h +++ b/include/libcamera/internal/vector.h @@ -63,6 +63,17 @@ public: return data_[i]; } + template + explicit operator Vector() const + { + Vector ret; + for (unsigned int i = 0; i < Rows; i++) + ret[i] = static_cast(data_[i]); + return ret; + } + + constexpr Span data() const { return data_; } + constexpr Vector operator-() const { Vector ret; diff --git a/src/libcamera/vector.cpp b/src/libcamera/vector.cpp index 4dad1b9001c5..bb89f0de7c4f 100644 --- a/src/libcamera/vector.cpp +++ b/src/libcamera/vector.cpp @@ -64,6 +64,24 @@ LOG_DEFINE_CATEGORY(Vector) * \copydoc Vector::operator[](size_t i) const */ +/** + * \fn Vector::data() + * \brief Access the vector data + * + * Access the contents of the vector as linear array of values. + * + * \return A span referencing the vector data as a linear array + */ + +/** + * \fn Vector::operator Vector() + * \brief Cast to a different underlying type + * + * Cast the vector to a different underlying type using static_cast(). + * + * \return A vector of type T2 + */ + /** * \fn Vector::operator-() const * \brief Negate a Vector by negating both all of its coordinates