[v2,03/17] libcamera: matrix: Add a Span based constructor
diff mbox series

Message ID 20250319161152.63625-4-stefan.klug@ideasonboard.com
State Superseded
Headers show
Series
  • Some rkisp1 awb improvements
Related show

Commit Message

Stefan Klug March 19, 2025, 4:11 p.m. UTC
When one wants to create a Matrix from existing data, currently the only
way is via std::array. Add a Span based constructor to allow creation
from vectors and alike.

Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>

---

Changes in v2:
- Added this patch
---
 include/libcamera/internal/matrix.h |  5 +++++
 src/libcamera/matrix.cpp            | 10 ++++++++++
 2 files changed, 15 insertions(+)

Comments

Kieran Bingham March 31, 2025, 5:02 p.m. UTC | #1
Quoting Stefan Klug (2025-03-19 16:11:08)
> When one wants to create a Matrix from existing data, currently the only
> way is via std::array. Add a Span based constructor to allow creation
> from vectors and alike.
> 
> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
> 
Seems fine to me.

Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>

> ---
> 
> Changes in v2:
> - Added this patch
> ---
>  include/libcamera/internal/matrix.h |  5 +++++
>  src/libcamera/matrix.cpp            | 10 ++++++++++
>  2 files changed, 15 insertions(+)
> 
> diff --git a/include/libcamera/internal/matrix.h b/include/libcamera/internal/matrix.h
> index 2e7929e9060c..9b80521e3cb0 100644
> --- a/include/libcamera/internal/matrix.h
> +++ b/include/libcamera/internal/matrix.h
> @@ -34,6 +34,11 @@ public:
>                 std::copy(data.begin(), data.end(), data_.begin());
>         }
>  
> +       Matrix(const Span<const T, Rows * Cols> &data)
> +       {
> +               std::copy(data.begin(), data.end(), data_.begin());
> +       }
> +
>         static constexpr Matrix identity()
>         {
>                 Matrix ret;
> diff --git a/src/libcamera/matrix.cpp b/src/libcamera/matrix.cpp
> index e7e027225666..6dca7498cab3 100644
> --- a/src/libcamera/matrix.cpp
> +++ b/src/libcamera/matrix.cpp
> @@ -41,6 +41,16 @@ LOG_DEFINE_CATEGORY(Matrix)
>   * number of rows and columns of the matrix (Rows x Cols).
>   */
>  
> +/**
> + * \fn Matrix::Matrix(const Span<const T, Rows * Cols> &data)
> + * \brief Construct a matrix from supplied data
> + * \param[in] data Data from which to construct a matrix
> + *
> + * \a data is a one-dimensional Span 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::identity()
>   * \brief Construct an identity matrix
> -- 
> 2.43.0
>
Laurent Pinchart April 1, 2025, 1:01 a.m. UTC | #2
Hi Stefan,

Thank you for the patch.

On Wed, Mar 19, 2025 at 05:11:08PM +0100, Stefan Klug wrote:
> When one wants to create a Matrix from existing data, currently the only
> way is via std::array. Add a Span based constructor to allow creation
> from vectors and alike.
> 
> Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com>
> 
> ---
> 
> Changes in v2:
> - Added this patch
> ---
>  include/libcamera/internal/matrix.h |  5 +++++
>  src/libcamera/matrix.cpp            | 10 ++++++++++
>  2 files changed, 15 insertions(+)
> 
> diff --git a/include/libcamera/internal/matrix.h b/include/libcamera/internal/matrix.h
> index 2e7929e9060c..9b80521e3cb0 100644
> --- a/include/libcamera/internal/matrix.h
> +++ b/include/libcamera/internal/matrix.h
> @@ -34,6 +34,11 @@ public:
>  		std::copy(data.begin(), data.end(), data_.begin());
>  	}
>  
> +	Matrix(const Span<const T, Rows * Cols> &data)

You can pass the span by value.

Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

> +	{
> +		std::copy(data.begin(), data.end(), data_.begin());
> +	}
> +
>  	static constexpr Matrix identity()
>  	{
>  		Matrix ret;
> diff --git a/src/libcamera/matrix.cpp b/src/libcamera/matrix.cpp
> index e7e027225666..6dca7498cab3 100644
> --- a/src/libcamera/matrix.cpp
> +++ b/src/libcamera/matrix.cpp
> @@ -41,6 +41,16 @@ LOG_DEFINE_CATEGORY(Matrix)
>   * number of rows and columns of the matrix (Rows x Cols).
>   */
>  
> +/**
> + * \fn Matrix::Matrix(const Span<const T, Rows * Cols> &data)
> + * \brief Construct a matrix from supplied data
> + * \param[in] data Data from which to construct a matrix
> + *
> + * \a data is a one-dimensional Span 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::identity()
>   * \brief Construct an identity matrix

Patch
diff mbox series

diff --git a/include/libcamera/internal/matrix.h b/include/libcamera/internal/matrix.h
index 2e7929e9060c..9b80521e3cb0 100644
--- a/include/libcamera/internal/matrix.h
+++ b/include/libcamera/internal/matrix.h
@@ -34,6 +34,11 @@  public:
 		std::copy(data.begin(), data.end(), data_.begin());
 	}
 
+	Matrix(const Span<const T, Rows * Cols> &data)
+	{
+		std::copy(data.begin(), data.end(), data_.begin());
+	}
+
 	static constexpr Matrix identity()
 	{
 		Matrix ret;
diff --git a/src/libcamera/matrix.cpp b/src/libcamera/matrix.cpp
index e7e027225666..6dca7498cab3 100644
--- a/src/libcamera/matrix.cpp
+++ b/src/libcamera/matrix.cpp
@@ -41,6 +41,16 @@  LOG_DEFINE_CATEGORY(Matrix)
  * number of rows and columns of the matrix (Rows x Cols).
  */
 
+/**
+ * \fn Matrix::Matrix(const Span<const T, Rows * Cols> &data)
+ * \brief Construct a matrix from supplied data
+ * \param[in] data Data from which to construct a matrix
+ *
+ * \a data is a one-dimensional Span 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::identity()
  * \brief Construct an identity matrix