[PATCH 3/4] libcamera: matrix: Use Span instead of vector for construction
Stefan Klug
stefan.klug at ideasonboard.com
Mon Nov 18 16:05:06 CET 2024
Use a Span for construction to be more flexible. Additionally add an
assert for the correct size of the span.
Signed-off-by: Stefan Klug <stefan.klug at ideasonboard.com>
---
include/libcamera/internal/matrix.h | 3 ++-
src/libcamera/matrix.cpp | 10 ++++++++++
2 files changed, 12 insertions(+), 1 deletion(-)
diff --git a/include/libcamera/internal/matrix.h b/include/libcamera/internal/matrix.h
index b82d33f98658..28ea68a55af9 100644
--- a/include/libcamera/internal/matrix.h
+++ b/include/libcamera/internal/matrix.h
@@ -39,8 +39,9 @@ public:
std::copy(data.begin(), data.end(), data_.begin());
}
- Matrix(const std::vector<T> &data)
+ Matrix(const Span<T> &data)
{
+ ASSERT(data.size() == Rows * Cols);
std::copy(data.begin(), data.end(), data_.begin());
}
diff --git a/src/libcamera/matrix.cpp b/src/libcamera/matrix.cpp
index c3ed54895b22..bb9fd3003996 100644
--- a/src/libcamera/matrix.cpp
+++ b/src/libcamera/matrix.cpp
@@ -31,6 +31,16 @@ LOG_DEFINE_CATEGORY(Matrix)
* \brief Construct a zero matrix
*/
+/**
+ * \fn Matrix::Matrix(std::initializer_list<T> data)
+ * \brief Construct a matrix from supplied data
+ * \param[in] data Data from which to construct a matrix
+ *
+ * \a data is a one-dimensional vector and will be turned into a matrix in
+ * row-major order. The size of \a data must be equal to the product of the
+ * number of rows and columns of the matrix (Rows x Cols).
+ */
+
/**
* \fn Matrix::Matrix(const Span<T> &data)
* \brief Construct a matrix from supplied data
--
2.43.0
More information about the libcamera-devel
mailing list