[libcamera-devel] [PATCH 3/6] libcamera: formats: PixelFormatInfo: Add v4l2 constructor
Paul Elder
paul.elder at ideasonboard.com
Mon Jun 29 17:14:08 CEST 2020
Add a constructor for PixelFormatInfo that takes a V4L2PixelFormat.
Signed-off-by: Paul Elder <paul.elder at ideasonboard.com>
---
include/libcamera/internal/formats.h | 1 +
src/libcamera/formats.cpp | 16 ++++++++++++++--
2 files changed, 15 insertions(+), 2 deletions(-)
diff --git a/include/libcamera/internal/formats.h b/include/libcamera/internal/formats.h
index dc19492..3c7440a 100644
--- a/include/libcamera/internal/formats.h
+++ b/include/libcamera/internal/formats.h
@@ -44,6 +44,7 @@ public:
bool isValid() const { return format.isValid(); }
static const PixelFormatInfo &info(const PixelFormat &format);
+ static const PixelFormatInfo &info(const V4L2PixelFormat &format);
const char *name;
PixelFormat format;
diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp
index 88b5168..7029a94 100644
--- a/src/libcamera/formats.cpp
+++ b/src/libcamera/formats.cpp
@@ -631,6 +631,8 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
} /* namespace */
+static const PixelFormatInfo invalid{};
+
/**
* \fn bool PixelFormatInfo::isValid() const
* \brief Check if the pixel format info is valid
@@ -645,8 +647,6 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
*/
const PixelFormatInfo &PixelFormatInfo::info(const PixelFormat &format)
{
- static const PixelFormatInfo invalid{};
-
const auto iter = pixelFormatInfo.find(format);
if (iter == pixelFormatInfo.end()) {
LOG(Formats, Warning)
@@ -658,4 +658,16 @@ const PixelFormatInfo &PixelFormatInfo::info(const PixelFormat &format)
return iter->second;
}
+const PixelFormatInfo &PixelFormatInfo::info(const V4L2PixelFormat &format)
+{
+ auto info = std::find_if(pixelFormatInfo.begin(), pixelFormatInfo.end(),
+ [format](auto pair) {
+ return pair.second.v4l2Format == format;
+ });
+ if (info == pixelFormatInfo.end())
+ return invalid;
+
+ return info->second;
+}
+
} /* namespace libcamera */
--
2.27.0
More information about the libcamera-devel
mailing list