[PATCH 1/2] libcamera: pixel_format: Add isRaw() helper

Umang Jain umang.jain at ideasonboard.com
Mon Sep 30 17:20:38 CEST 2024


Add a isRaw() helper to the PixelFormat class, to know whether the
pixel format has RAW encoding.

This will used by validation and configuration code paths in pipeline
handlers, to know whether a pixel format is a raw format or not.

Signed-off-by: Umang Jain <umang.jain at ideasonboard.com>
---
 include/libcamera/pixel_format.h |  1 +
 src/libcamera/pixel_format.cpp   | 11 +++++++++++
 2 files changed, 12 insertions(+)

diff --git a/include/libcamera/pixel_format.h b/include/libcamera/pixel_format.h
index 1b4d8c7c..aed53ea6 100644
--- a/include/libcamera/pixel_format.h
+++ b/include/libcamera/pixel_format.h
@@ -37,6 +37,7 @@ public:
 	constexpr uint64_t modifier() const { return modifier_; }
 
 	std::string toString() const;
+	bool isRaw() const;
 
 	static PixelFormat fromString(const std::string &name);
 
diff --git a/src/libcamera/pixel_format.cpp b/src/libcamera/pixel_format.cpp
index 314179a8..436ef5fb 100644
--- a/src/libcamera/pixel_format.cpp
+++ b/src/libcamera/pixel_format.cpp
@@ -100,6 +100,17 @@ bool PixelFormat::operator<(const PixelFormat &other) const
  * \return DRM modifier
  */
 
+/**
+ * \brief Checks if \a this is a RAW pixel format
+ * \return True if \a this is a RAW pixel format, false otherwise
+ */
+bool PixelFormat::isRaw() const
+{
+	const PixelFormatInfo &info = PixelFormatInfo::info(*this);
+
+	return info.colourEncoding == PixelFormatInfo::ColourEncodingRAW;
+}
+
 /**
  * \brief Assemble and return a string describing the pixel format
  * \return A string describing the pixel format
-- 
2.45.2



More information about the libcamera-devel mailing list