[libcamera-devel] [PATCH] libcamera: add support for planar YUV422 and YUV420 formats
David Plowman
david.plowman at raspberrypi.com
Wed Jun 17 18:44:42 CEST 2020
These formats can be helpful when downstream applications or libraries
support them natively (avoiding a costly conversion).
Signed-off-by: David Plowman <david.plowman at raspberrypi.com>
---
src/libcamera/formats.cpp | 14 ++++++++++++++
src/libcamera/v4l2_pixelformat.cpp | 2 ++
src/v4l2/v4l2_camera_proxy.cpp | 2 ++
3 files changed, 18 insertions(+)
diff --git a/src/libcamera/formats.cpp b/src/libcamera/formats.cpp
index 2ac3b41..dcd1dcf 100644
--- a/src/libcamera/formats.cpp
+++ b/src/libcamera/formats.cpp
@@ -268,6 +268,20 @@ const std::map<PixelFormat, PixelFormatInfo> pixelFormatInfo{
.colourEncoding = PixelFormatInfo::ColourEncodingYUV,
.packed = false,
} },
+ { PixelFormat(DRM_FORMAT_YUV422), {
+ .format = PixelFormat(DRM_FORMAT_YUV422),
+ .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YUV422P),
+ .bitsPerPixel = 16,
+ .colourEncoding = PixelFormatInfo::ColourEncodingYUV,
+ .packed = false,
+ } },
+ { PixelFormat(DRM_FORMAT_YUV420), {
+ .format = PixelFormat(DRM_FORMAT_YUV420),
+ .v4l2Format = V4L2PixelFormat(V4L2_PIX_FMT_YUV420),
+ .bitsPerPixel = 12,
+ .colourEncoding = PixelFormatInfo::ColourEncodingYUV,
+ .packed = false,
+ } },
/* Greyscale formats. */
{ PixelFormat(DRM_FORMAT_R8), {
diff --git a/src/libcamera/v4l2_pixelformat.cpp b/src/libcamera/v4l2_pixelformat.cpp
index 94fae47..01778c0 100644
--- a/src/libcamera/v4l2_pixelformat.cpp
+++ b/src/libcamera/v4l2_pixelformat.cpp
@@ -64,6 +64,8 @@ const std::map<V4L2PixelFormat, PixelFormat> vpf2pf{
{ V4L2PixelFormat(V4L2_PIX_FMT_NV61), PixelFormat(DRM_FORMAT_NV61) },
{ V4L2PixelFormat(V4L2_PIX_FMT_NV12), PixelFormat(DRM_FORMAT_NV12) },
{ V4L2PixelFormat(V4L2_PIX_FMT_NV21), PixelFormat(DRM_FORMAT_NV21) },
+ { V4L2PixelFormat(V4L2_PIX_FMT_YUV422P), PixelFormat(DRM_FORMAT_YUV422) },
+ { V4L2PixelFormat(V4L2_PIX_FMT_YUV420), PixelFormat(DRM_FORMAT_YUV420) },
/* Greyscale formats. */
{ V4L2PixelFormat(V4L2_PIX_FMT_GREY), PixelFormat(DRM_FORMAT_R8) },
diff --git a/src/v4l2/v4l2_camera_proxy.cpp b/src/v4l2/v4l2_camera_proxy.cpp
index d7f14e6..a54d47e 100644
--- a/src/v4l2/v4l2_camera_proxy.cpp
+++ b/src/v4l2/v4l2_camera_proxy.cpp
@@ -576,6 +576,8 @@ static const std::array<PixelFormatInfo, 14> pixelFormatInfo = {{
{ PixelFormat(DRM_FORMAT_NV61), V4L2_PIX_FMT_NV61, 2, {{ { 8, 1, 1 }, { 16, 2, 1 }, { 0, 0, 0 } }} },
{ PixelFormat(DRM_FORMAT_NV24), V4L2_PIX_FMT_NV24, 2, {{ { 8, 1, 1 }, { 16, 1, 1 }, { 0, 0, 0 } }} },
{ PixelFormat(DRM_FORMAT_NV42), V4L2_PIX_FMT_NV42, 2, {{ { 8, 1, 1 }, { 16, 1, 1 }, { 0, 0, 0 } }} },
+ { PixelFormat(DRM_FORMAT_YUV422), V4L2_PIX_FMT_YUV422P, 2, {{ { 8, 1, 1 }, { 8, 2, 1 }, { 8, 2, 1 } }} },
+ { PixelFormat(DRM_FORMAT_YUV420), V4L2_PIX_FMT_YUV420, 2, {{ { 8, 1, 1 }, { 8, 2, 2 }, { 8, 2, 2 } }} },
/* Compressed formats. */
/*
* \todo Get a better image size estimate for MJPEG, via
--
2.20.1
More information about the libcamera-devel
mailing list