[libcamera-devel] [RFC 1/1] libcamera: V4L2VideoDevice::to[V4L2]PixelFormat(): add Bayer formats

Andrey Konovalov andrey.konovalov at linaro.org
Sat Apr 4 23:57:30 CEST 2020


Add support for 8-bit, 10-bit, and 10-bit packed raw Bayer formats in
toPixelFormat() and toV4L2PixelFormat() methods of V4L2VideoDevice class.

Signed-off-by: Andrey Konovalov <andrey.konovalov at linaro.org>
---
 src/libcamera/v4l2_videodevice.cpp | 56 ++++++++++++++++++++++++++++++
 1 file changed, 56 insertions(+)

diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
index eb33a68..2e3aafc 100644
--- a/src/libcamera/v4l2_videodevice.cpp
+++ b/src/libcamera/v4l2_videodevice.cpp
@@ -1687,6 +1687,36 @@ PixelFormat V4L2VideoDevice::toPixelFormat(V4L2PixelFormat v4l2Fourcc)
 	case V4L2_PIX_FMT_MJPEG:
 		return PixelFormat(DRM_FORMAT_MJPEG);
 
+	/* 8-bit Bayer formats. */
+	case V4L2_PIX_FMT_SRGGB8:
+		return PixelFormat(DRM_FORMAT_SRGGB8);
+	case V4L2_PIX_FMT_SGRBG8:
+		return PixelFormat(DRM_FORMAT_SGRBG8);
+	case V4L2_PIX_FMT_SGBRG8:
+		return PixelFormat(DRM_FORMAT_SGBRG8);
+	case V4L2_PIX_FMT_SBGGR8:
+		return PixelFormat(DRM_FORMAT_SBGGR8);
+
+	/* 10-bit Bayer formats. */
+	case V4L2_PIX_FMT_SRGGB10:
+		return PixelFormat(DRM_FORMAT_SRGGB10);
+	case V4L2_PIX_FMT_SGRBG10:
+		return PixelFormat(DRM_FORMAT_SGRBG10);
+	case V4L2_PIX_FMT_SGBRG10:
+		return PixelFormat(DRM_FORMAT_SGBRG10);
+	case V4L2_PIX_FMT_SBGGR10:
+		return PixelFormat(DRM_FORMAT_SBGGR10);
+
+	/* 10-bit Bayer packed formats. */
+	case V4L2_PIX_FMT_SRGGB10P:
+		return PixelFormat(DRM_FORMAT_SRGGB10, MIPI_FORMAT_MOD_CSI2_PACKED);
+	case V4L2_PIX_FMT_SGRBG10P:
+		return PixelFormat(DRM_FORMAT_SGRBG10, MIPI_FORMAT_MOD_CSI2_PACKED);
+	case V4L2_PIX_FMT_SGBRG10P:
+		return PixelFormat(DRM_FORMAT_SGBRG10, MIPI_FORMAT_MOD_CSI2_PACKED);
+	case V4L2_PIX_FMT_SBGGR10P:
+		return PixelFormat(DRM_FORMAT_SBGGR10, MIPI_FORMAT_MOD_CSI2_PACKED);
+
 	/* V4L2 formats not yet supported by DRM. */
 	case V4L2_PIX_FMT_GREY:
 	default:
@@ -1734,6 +1764,8 @@ V4L2PixelFormat V4L2VideoDevice::toV4L2PixelFormat(const PixelFormat &pixelForma
 V4L2PixelFormat V4L2VideoDevice::toV4L2PixelFormat(const PixelFormat &pixelFormat,
 						   bool multiplanar)
 {
+	bool csi2Packed = pixelFormat.modifier() == MIPI_FORMAT_MOD_CSI2_PACKED;
+
 	switch (pixelFormat) {
 	/* RGB formats. */
 	case DRM_FORMAT_BGR888:
@@ -1777,6 +1809,30 @@ V4L2PixelFormat V4L2VideoDevice::toV4L2PixelFormat(const PixelFormat &pixelForma
 	/* Compressed formats. */
 	case DRM_FORMAT_MJPEG:
 		return V4L2PixelFormat(V4L2_PIX_FMT_MJPEG);
+
+	/* 8-bit Bayer formats. */
+	case DRM_FORMAT_SRGGB8:
+		return V4L2PixelFormat(V4L2_PIX_FMT_SRGGB8);
+	case DRM_FORMAT_SGRBG8:
+		return V4L2PixelFormat(V4L2_PIX_FMT_SGRBG8);
+	case DRM_FORMAT_SGBRG8:
+		return V4L2PixelFormat(V4L2_PIX_FMT_SGBRG8);
+	case DRM_FORMAT_SBGGR8:
+		return V4L2PixelFormat(V4L2_PIX_FMT_SBGGR8);
+
+	/* 10-bit Bayer formats, the packed ones included. */
+	case DRM_FORMAT_SRGGB10:
+		return (csi2Packed) ? V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10P)
+			: V4L2PixelFormat(V4L2_PIX_FMT_SRGGB10);
+	case DRM_FORMAT_SGRBG10:
+		return (csi2Packed) ? V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10P)
+			: V4L2PixelFormat(V4L2_PIX_FMT_SGRBG10);
+	case DRM_FORMAT_SGBRG10:
+		return (csi2Packed) ? V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10P)
+			: V4L2PixelFormat(V4L2_PIX_FMT_SGBRG10);
+	case DRM_FORMAT_SBGGR10:
+		return (csi2Packed) ? V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10P)
+			: V4L2PixelFormat(V4L2_PIX_FMT_SBGGR10);
 	}
 
 	/*
-- 
2.17.1



More information about the libcamera-devel mailing list