[libcamera-devel] [PATCH v4 05/21] libcamera: formats: PixelFormatInfo: Add v4l2 lookup function
Paul Elder
paul.elder at ideasonboard.com
Wed Jul 8 15:44:01 CEST 2020
Add a lookup function for PixelFormatInfo that takes a V4L2PixelFormat.
Signed-off-by: Paul Elder <paul.elder at ideasonboard.com>
Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
---
No change in v4
Changes in v3:
- rename invalid PixelFormatInfo
- make info const in PixelFormatInfo::info()
Changes in v2:
- move invalid PixelFormatInfo instance to anonymous namespace
- add documentation
---
include/libcamera/internal/formats.h | 1 +
src/libcamera/formats.cpp | 25 ++++++++++++++++++++++---
2 files changed, 23 insertions(+), 3 deletions(-)
diff --git a/include/libcamera/internal/formats.h b/include/libcamera/internal/formats.h
index 61e5ff5..054be37 100644
--- a/include/libcamera/internal/formats.h
+++ b/include/libcamera/internal/formats.h
@@ -50,6 +50,7 @@ public:
bool isValid() const { return format.isValid(); }
static const PixelFormatInfo &info(const PixelFormat &format);
+ static const PixelFormatInfo &info(const V4L2PixelFormat &format);
/* \todo Add support for non-contiguous memory planes */
const char *name;
diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp
index e6d3d3b..6d96055 100644
--- a/src/libcamera/formats.cpp
+++ b/src/libcamera/formats.cpp
@@ -7,6 +7,7 @@
#include "libcamera/internal/formats.h"
+#include <algorithm>
#include <errno.h>
#include <libcamera/formats.h>
@@ -229,6 +230,8 @@ const std::map<unsigned int, std::vector<SizeRange>> &ImageFormats::data() const
namespace {
+const PixelFormatInfo pixelFormatInfoInvalid{};
+
const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
/* RGB formats. */
{ formats::BGR888, {
@@ -700,17 +703,33 @@ 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)
<< "Unsupported pixel format 0x"
<< utils::hex(format.fourcc());
- return invalid;
+ return pixelFormatInfoInvalid;
}
return iter->second;
}
+/**
+ * \brief Retrieve information about a pixel format
+ * \param[in] format The V4L2 pixel format
+ * \return The PixelFormatInfo describing the V4L2 \a format if known, or an
+ * invalid PixelFormatInfo otherwise
+ */
+const PixelFormatInfo &PixelFormatInfo::info(const V4L2PixelFormat &format)
+{
+ const auto &info = std::find_if(pixelFormatInfo.begin(), pixelFormatInfo.end(),
+ [format](auto pair) {
+ return pair.second.v4l2Format == format;
+ });
+ if (info == pixelFormatInfo.end())
+ return pixelFormatInfoInvalid;
+
+ return info->second;
+}
+
} /* namespace libcamera */
--
2.27.0
More information about the libcamera-devel
mailing list