summaryrefslogtreecommitdiff
path: root/src/libcamera/formats.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libcamera/formats.cpp')
-rw-r--r--src/libcamera/formats.cpp126
1 files changed, 126 insertions, 0 deletions
diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp
index 5f6552a4..4a351020 100644
--- a/src/libcamera/formats.cpp
+++ b/src/libcamera/formats.cpp
@@ -9,6 +9,8 @@
#include <errno.h>
+#include "log.h"
+
/**
* \file formats.h
* \brief Types and helper methods to handle libcamera image formats
@@ -16,6 +18,8 @@
namespace libcamera {
+LOG_DEFINE_CATEGORY(Formats)
+
/**
* \class ImageFormats
* \brief Describe V4L2Device and V4L2SubDevice image formats
@@ -104,4 +108,126 @@ const std::map<unsigned int, std::vector<SizeRange>> &ImageFormats::data() const
return data_;
}
+/**
+ * \class PixelFormatInfo
+ * \brief Information about pixel formats
+ *
+ * The PixelFormatInfo class groups together information describing a pixel
+ * format. It facilitates handling of pixel formats by providing data commonly
+ * used in pipeline handlers.
+ *
+ * \var PixelFormatInfo::format
+ * \brief The PixelFormat described by this instance
+ *
+ * \var PixelFormatInfo::v4l2Format
+ * \brief The V4L2 pixel format corresponding to the PixelFormat
+ */
+
+namespace {
+
+const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
+ /* RGB formats. */
+ { PixelFormat(DRM_FORMAT_BGR888), {
+ .format = PixelFormat(DRM_FORMAT_BGR888),
+ .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_RGB24),
+ } },
+ { PixelFormat(DRM_FORMAT_RGB888), {
+ .format = PixelFormat(DRM_FORMAT_RGB888),
+ .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_BGR24),
+ } },
+ { PixelFormat(DRM_FORMAT_ABGR8888), {
+ .format = PixelFormat(DRM_FORMAT_ABGR8888),
+ .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_RGBA32),
+ } },
+ { PixelFormat(DRM_FORMAT_ARGB8888), {
+ .format = PixelFormat(DRM_FORMAT_ARGB8888),
+ .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_ABGR32),
+ } },
+ { PixelFormat(DRM_FORMAT_BGRA8888), {
+ .format = PixelFormat(DRM_FORMAT_BGRA8888),
+ .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_ARGB32),
+ } },
+ { PixelFormat(DRM_FORMAT_RGBA8888), {
+ .format = PixelFormat(DRM_FORMAT_RGBA8888),
+ .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_BGRA32),
+ } },
+
+ /* YUV packed formats. */
+ { PixelFormat(DRM_FORMAT_YUYV), {
+ .format = PixelFormat(DRM_FORMAT_YUYV),
+ .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YUYV),
+ } },
+ { PixelFormat(DRM_FORMAT_YVYU), {
+ .format = PixelFormat(DRM_FORMAT_YVYU),
+ .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YVYU),
+ } },
+ { PixelFormat(DRM_FORMAT_UYVY), {
+ .format = PixelFormat(DRM_FORMAT_UYVY),
+ .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_UYVY),
+ } },
+ { PixelFormat(DRM_FORMAT_VYUY), {
+ .format = PixelFormat(DRM_FORMAT_VYUY),
+ .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_VYUY),
+ } },
+
+ /* YUV planar formats. */
+ { PixelFormat(DRM_FORMAT_NV16), {
+ .format = PixelFormat(DRM_FORMAT_NV16),
+ .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV16),
+ } },
+ { PixelFormat(DRM_FORMAT_NV61), {
+ .format = PixelFormat(DRM_FORMAT_NV61),
+ .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV61),
+ } },
+ { PixelFormat(DRM_FORMAT_NV12), {
+ .format = PixelFormat(DRM_FORMAT_NV12),
+ .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV12),
+ } },
+ { PixelFormat(DRM_FORMAT_NV21), {
+ .format = PixelFormat(DRM_FORMAT_NV21),
+ .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_NV21),
+ } },
+
+ /* Greyscale formats. */
+ { PixelFormat(DRM_FORMAT_R8), {
+ .format = PixelFormat(DRM_FORMAT_R8),
+ .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_GREY),
+ } },
+
+ /* Compressed formats. */
+ { PixelFormat(DRM_FORMAT_MJPEG), {
+ .format = PixelFormat(DRM_FORMAT_MJPEG),
+ .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_MJPEG),
+ } },
+};
+
+} /* namespace */
+
+/**
+ * \fn bool PixelFormatInfo::isValid() const
+ * \brief Check if the pixel format info is valid
+ * \return True if the pixel format info is valid, false otherwise
+ */
+
+/**
+ * \brief Retrieve information about a pixel format
+ * \param[in] format The pixel format
+ * \return The PixelFormatInfo describing the \a format if known, or an invalid
+ * PixelFormatInfo otherwise
+ */
+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 "
+ << format.toString();
+ return invalid;
+ }
+
+ return iter->second;
+}
+
} /* namespace libcamera */