[libcamera-devel] [PATCH] libcamera: formats: add planeCount helper
Kieran Bingham
kieran.bingham at ideasonboard.com
Wed Jul 29 13:25:24 CEST 2020
Determine the number of planes used by a format by counting the number
of PxielFormatPlaneInfo entries with a valid entry.
Signed-off-by: Kieran Bingham <kieran.bingham at ideasonboard.com>
---
include/libcamera/internal/formats.h | 2 ++
src/libcamera/formats.cpp | 22 ++++++++++++++++++++++
2 files changed, 24 insertions(+)
diff --git a/include/libcamera/internal/formats.h b/include/libcamera/internal/formats.h
index 0bb151044294..beeaab1ae2f5 100644
--- a/include/libcamera/internal/formats.h
+++ b/include/libcamera/internal/formats.h
@@ -45,6 +45,8 @@ public:
unsigned int frameSize(const Size &size,
const std::array<unsigned int, 3> &strides) const;
+ unsigned int planeCount() const;
+
/* \todo Add support for non-contiguous memory planes */
const char *name;
PixelFormat format;
diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp
index cd63c15cb926..70d31fb36c37 100644
--- a/src/libcamera/formats.cpp
+++ b/src/libcamera/formats.cpp
@@ -805,4 +805,26 @@ PixelFormatInfo::frameSize(const Size &size,
return sum;
}
+/**
+ * \brief Identify the number of planes represented by the format
+ *
+ * This function counts the number of planes which have a valid configuration
+ * and uses that to determine the number of planes used by the format.
+ *
+ * \return The number of planes used by the format
+ */
+unsigned int PixelFormatInfo::planeCount() const
+{
+ unsigned int count = 0;
+
+ for (const PixelFormatPlaneInfo &p : planes) {
+ if (p.bytesPerGroup == 0)
+ break;
+
+ count++;
+ }
+
+ return count;
+}
+
} /* namespace libcamera */
--
2.25.1
More information about the libcamera-devel
mailing list