From patchwork Mon Feb 17 10:01:42 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Klug X-Patchwork-Id: 22787 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 73177C327D for ; Mon, 17 Feb 2025 10:02:15 +0000 (UTC) Received: from lancelot.ideasonboard.com (localhost [IPv6:::1]) by lancelot.ideasonboard.com (Postfix) with ESMTP id 42D9768663; Mon, 17 Feb 2025 11:02:14 +0100 (CET) Authentication-Results: lancelot.ideasonboard.com; dkim=pass (1024-bit key; unprotected) header.d=ideasonboard.com header.i=@ideasonboard.com header.b="TmLzEGyF"; dkim-atps=neutral Received: from perceval.ideasonboard.com (perceval.ideasonboard.com [IPv6:2001:4b98:dc2:55:216:3eff:fef7:d647]) by lancelot.ideasonboard.com (Postfix) with ESMTPS id A2B306865D for ; Mon, 17 Feb 2025 11:02:10 +0100 (CET) Received: from ideasonboard.com (unknown [IPv6:2a00:6020:448c:6c00:b47f:e20a:c4c7:ece1]) by perceval.ideasonboard.com (Postfix) with ESMTPSA id 6A2DD842; Mon, 17 Feb 2025 11:00:49 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ideasonboard.com; s=mail; t=1739786449; bh=WCk5oVZh9C/d253FiUEnwgsIeMWChDAfaXQvY65px74=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=TmLzEGyFX7ofZ7BiQknRM3Sqok5VFt01EcnOgpJ1OuG669u5ZdbI2VarxcXDqGOZY H20UNXIXlzvyogmV65bScuQJUB+c5kMVVYdJCyNSC11A37vepz+Ck6bjc0Gj+UFxQq UBkUHpwhy1jD6B+AlTGDKDKdTADqtPyr/j9tzR48= From: Stefan Klug To: libcamera-devel@lists.libcamera.org Cc: Stefan Klug Subject: [PATCH 01/10] libcamera: matrix: Add cast function Date: Mon, 17 Feb 2025 11:01:42 +0100 Message-ID: <20250217100203.297894-2-stefan.klug@ideasonboard.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250217100203.297894-1-stefan.klug@ideasonboard.com> References: <20250217100203.297894-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" The libcamera code base uses matrices and vectors of type float and double. Add a cast function to easily convert between different underlying types. Signed-off-by: Stefan Klug --- include/libcamera/internal/matrix.h | 11 +++++++++++ src/libcamera/matrix.cpp | 10 ++++++++++ 2 files changed, 21 insertions(+) diff --git a/include/libcamera/internal/matrix.h b/include/libcamera/internal/matrix.h index a055e6926c94..ca81dcda93c4 100644 --- a/include/libcamera/internal/matrix.h +++ b/include/libcamera/internal/matrix.h @@ -90,6 +90,17 @@ public: return *this; } + template + Matrix cast() const + { + Matrix ret; + for (unsigned int i = 0; i < Rows; i++) + for (unsigned int j = 0; j < Cols; j++) + ret[i][j] = static_cast((*this)[i][j]); + + return ret; + } + private: std::array data_; }; diff --git a/src/libcamera/matrix.cpp b/src/libcamera/matrix.cpp index e7e027225666..91a3f16405a3 100644 --- a/src/libcamera/matrix.cpp +++ b/src/libcamera/matrix.cpp @@ -77,6 +77,16 @@ LOG_DEFINE_CATEGORY(Matrix) * \return Row \a i from the matrix, as a Span */ +/** + * \fn template Matrix Matrix::cast() const + * \brief Cast the matrix to a different type + * + * This function returns a new matrix with the same size and values but a + * different type. + * + * \return The new matrix + */ + /** * \fn Matrix::operator[](size_t i) * \copydoc Matrix::operator[](size_t i) const