diff options
author | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-04-30 05:11:59 +0300 |
---|---|---|
committer | Laurent Pinchart <laurent.pinchart@ideasonboard.com> | 2020-04-30 14:54:03 +0300 |
commit | 37332ad50b4f55481b1dc4390fa436ce1ea3712d (patch) | |
tree | 5d69205baa5ebc1e84ce6b7cb06d712800cb8822 /src/libcamera/formats.cpp | |
parent | dcabb8e354ca4dd02d5c0aaec28437eacaaf88b7 (diff) |
libcamera: formats: Expose PixelFormatInfo as an internal API
To prepare for storing more information about pixel formats in
PixelFormatInfo, move the class to formats.cpp and document it. The
pixel formats database is moved to the same file, and a new static
function is added to PixelFormatInfo to retrieve a PixelFormatInfo for a
PixelFormat.
Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Reviewed-by: Kieran Bingham <kieran.bingham@ideasonboard.com>
Diffstat (limited to 'src/libcamera/formats.cpp')
-rw-r--r-- | src/libcamera/formats.cpp | 126 |
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 */ |