summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorStefan Klug <stefan.klug@ideasonboard.com>2025-04-03 17:49:10 +0200
committerStefan Klug <stefan.klug@ideasonboard.com>2025-05-20 09:46:12 +0200
commit6287ceff5aba1e8207aafdae9f967c70d9aad19f (patch)
treeaabe46b7af6fd57ade931ba151ec7824b3678047 /include
parentbcba580546807c4b6e138300a410f1dc63fb02b9 (diff)
libcamera: matrix: Add inverse() function
For calculations in upcoming algorithm patches, the inverse of a matrix is required. Add an implementation of the inverse() function for square matrices. Signed-off-by: Stefan Klug <stefan.klug@ideasonboard.com> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com> Reviewed-by: Paul Elder <paul.elder@ideasonboard.com>
Diffstat (limited to 'include')
-rw-r--r--include/libcamera/internal/matrix.h23
1 files changed, 23 insertions, 0 deletions
diff --git a/include/libcamera/internal/matrix.h b/include/libcamera/internal/matrix.h
index 6d40567a..a07a4770 100644
--- a/include/libcamera/internal/matrix.h
+++ b/include/libcamera/internal/matrix.h
@@ -19,6 +19,12 @@ namespace libcamera {
LOG_DECLARE_CATEGORY(Matrix)
+#ifndef __DOXYGEN__
+template<typename T>
+bool matrixInvert(Span<const T> dataIn, Span<T> dataOut, unsigned int dim,
+ Span<T> scratchBuffer, Span<unsigned int> swapBuffer);
+#endif /* __DOXYGEN__ */
+
template<typename T, unsigned int Rows, unsigned int Cols>
class Matrix
{
@@ -91,6 +97,23 @@ public:
return *this;
}
+ Matrix<T, Rows, Cols> inverse(bool *ok = nullptr) const
+ {
+ static_assert(Rows == Cols, "Matrix must be square");
+
+ Matrix<T, Rows, Cols> inverse;
+ std::array<T, Rows * Cols * 2> scratchBuffer;
+ std::array<unsigned int, Rows> swapBuffer;
+ bool res = matrixInvert(Span<const T>(data_),
+ Span<T>(inverse.data_),
+ Rows,
+ Span<T>(scratchBuffer),
+ Span<unsigned int>(swapBuffer));
+ if (ok)
+ *ok = res;
+ return inverse;
+ }
+
private:
/*
* \todo The initializer is only necessary for the constructor to be