summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/libcamera/pixel_format.h2
-rw-r--r--src/libcamera/pixel_format.cpp11
2 files changed, 13 insertions, 0 deletions
diff --git a/include/libcamera/pixel_format.h b/include/libcamera/pixel_format.h
index 6727315a..c4ae0883 100644
--- a/include/libcamera/pixel_format.h
+++ b/include/libcamera/pixel_format.h
@@ -38,6 +38,8 @@ public:
std::string toString() const;
+ static PixelFormat fromString(const std::string &name);
+
private:
uint32_t fourcc_;
uint64_t modifier_;
diff --git a/src/libcamera/pixel_format.cpp b/src/libcamera/pixel_format.cpp
index 14addb51..54763fbf 100644
--- a/src/libcamera/pixel_format.cpp
+++ b/src/libcamera/pixel_format.cpp
@@ -130,4 +130,15 @@ std::string PixelFormat::toString() const
return info.name;
}
+/**
+ * \brief Create a PixelFormat from a string
+ * \return Pixel format
+ * \return The PixelFormat represented by the \a name if known, or an
+ * invalid pixel format otherwise.
+ */
+PixelFormat PixelFormat::fromString(const std::string &name)
+{
+ return PixelFormatInfo::info(name).format;
+}
+
} /* namespace libcamera */