[libcamera-devel,v4,08/11] libcamera: v4l2_videodevice: Map V4L2_PIX_FMT_GREY to DRM FourCC

Message ID 20200404004438.17992-9-laurent.pinchart@ideasonboard.com
State Superseded
Headers show
Series
  • Simple pipeline handler
Related show

Commit Message

Laurent Pinchart April 4, 2020, 12:44 a.m. UTC
DRM has a format for 8-bit greyscale data, DRM_FORMAT_R8. Despite the
'R' name, which comes from GL/Vulkan to mean single-channel data, the
format maps to greyscale for display. We can thus map it to
V4L2_PIX_FMT_GREY.

Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
---
Changes since v2:

- Rebase on top of PixelFormat class
---
 src/libcamera/v4l2_videodevice.cpp | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

Comments

Niklas Söderlund April 7, 2020, 11:40 p.m. UTC | #1
Hi Laurent,

Thanks for your work.

On 2020-04-04 03:44:35 +0300, Laurent Pinchart wrote:
> DRM has a format for 8-bit greyscale data, DRM_FORMAT_R8. Despite the
> 'R' name, which comes from GL/Vulkan to mean single-channel data, the
> format maps to greyscale for display. We can thus map it to
> V4L2_PIX_FMT_GREY.
> 
> Signed-off-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com>

Reviewed-by: Niklas Söderlund <niklas.soderlund@ragnatech.se>

> ---
> Changes since v2:
> 
> - Rebase on top of PixelFormat class
> ---
>  src/libcamera/v4l2_videodevice.cpp | 9 ++++++++-
>  1 file changed, 8 insertions(+), 1 deletion(-)
> 
> diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
> index 5208e5a47148..437e771d7fe4 100644
> --- a/src/libcamera/v4l2_videodevice.cpp
> +++ b/src/libcamera/v4l2_videodevice.cpp
> @@ -1699,12 +1699,15 @@ PixelFormat V4L2VideoDevice::toPixelFormat(V4L2PixelFormat v4l2Fourcc)
>  	case V4L2_PIX_FMT_NV21M:
>  		return PixelFormat(DRM_FORMAT_NV21);
>  
> +	/* Greyscale formats. */
> +	case V4L2_PIX_FMT_GREY:
> +		return PixelFormat(DRM_FORMAT_R8);
> +
>  	/* Compressed formats. */
>  	case V4L2_PIX_FMT_MJPEG:
>  		return PixelFormat(DRM_FORMAT_MJPEG);
>  
>  	/* V4L2 formats not yet supported by DRM. */
> -	case V4L2_PIX_FMT_GREY:
>  	default:
>  		/*
>  		 * \todo We can't use LOG() in a static method of a Loggable
> @@ -1790,6 +1793,10 @@ V4L2PixelFormat V4L2VideoDevice::toV4L2PixelFormat(const PixelFormat &pixelForma
>  	case DRM_FORMAT_NV21:
>  		return V4L2PixelFormat(V4L2_PIX_FMT_NV21);
>  
> +	/* Greyscale formats. */
> +	case DRM_FORMAT_R8:
> +		return V4L2PixelFormat(V4L2_PIX_FMT_GREY);
> +
>  	/* Compressed formats. */
>  	case DRM_FORMAT_MJPEG:
>  		return V4L2PixelFormat(V4L2_PIX_FMT_MJPEG);
> -- 
> Regards,
> 
> Laurent Pinchart
> 
> _______________________________________________
> libcamera-devel mailing list
> libcamera-devel@lists.libcamera.org
> https://lists.libcamera.org/listinfo/libcamera-devel

Patch

diff --git a/src/libcamera/v4l2_videodevice.cpp b/src/libcamera/v4l2_videodevice.cpp
index 5208e5a47148..437e771d7fe4 100644
--- a/src/libcamera/v4l2_videodevice.cpp
+++ b/src/libcamera/v4l2_videodevice.cpp
@@ -1699,12 +1699,15 @@  PixelFormat V4L2VideoDevice::toPixelFormat(V4L2PixelFormat v4l2Fourcc)
 	case V4L2_PIX_FMT_NV21M:
 		return PixelFormat(DRM_FORMAT_NV21);
 
+	/* Greyscale formats. */
+	case V4L2_PIX_FMT_GREY:
+		return PixelFormat(DRM_FORMAT_R8);
+
 	/* Compressed formats. */
 	case V4L2_PIX_FMT_MJPEG:
 		return PixelFormat(DRM_FORMAT_MJPEG);
 
 	/* V4L2 formats not yet supported by DRM. */
-	case V4L2_PIX_FMT_GREY:
 	default:
 		/*
 		 * \todo We can't use LOG() in a static method of a Loggable
@@ -1790,6 +1793,10 @@  V4L2PixelFormat V4L2VideoDevice::toV4L2PixelFormat(const PixelFormat &pixelForma
 	case DRM_FORMAT_NV21:
 		return V4L2PixelFormat(V4L2_PIX_FMT_NV21);
 
+	/* Greyscale formats. */
+	case DRM_FORMAT_R8:
+		return V4L2PixelFormat(V4L2_PIX_FMT_GREY);
+
 	/* Compressed formats. */
 	case DRM_FORMAT_MJPEG:
 		return V4L2PixelFormat(V4L2_PIX_FMT_MJPEG);