From d5a897c8428b38053df4b427a4277b1a0722bfa0 Mon Sep 17 00:00:00 2001 From: Benoit Parrot Date: Mon, 7 Oct 2019 12:10:07 -0300 Subject: media: v4l2-common: add pixel encoding support It is often useful to figure out if a pixel_format is either YUV or RGB especially for driver who can perform the pixel encoding conversion. Instead of having each driver implement its own "is_this_yuv/rgb" function based on a restricted set of pixel value, it is better to do this in centralized manner. We therefore add a pixel_enc member to the v4l2_format_info structure to quickly identify the related pixel encoding. And add helper functions to check pixel encoding. Signed-off-by: Benoit Parrot Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- include/media/v4l2-common.h | 33 ++++++++++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) (limited to 'include/media') diff --git a/include/media/v4l2-common.h b/include/media/v4l2-common.h index c070d8ae11e5..d8c29e089000 100644 --- a/include/media/v4l2-common.h +++ b/include/media/v4l2-common.h @@ -456,9 +456,25 @@ int v4l2_s_parm_cap(struct video_device *vdev, /* Pixel format and FourCC helpers */ +/** + * enum v4l2_pixel_encoding - specifies the pixel encoding value + * + * @V4L2_PIXEL_ENC_UNKNOWN: Pixel encoding is unknown/un-initialized + * @V4L2_PIXEL_ENC_YUV: Pixel encoding is YUV + * @V4L2_PIXEL_ENC_RGB: Pixel encoding is RGB + * @V4L2_PIXEL_ENC_BAYER: Pixel encoding is Bayer + */ +enum v4l2_pixel_encoding { + V4L2_PIXEL_ENC_UNKNOWN = 0, + V4L2_PIXEL_ENC_YUV = 1, + V4L2_PIXEL_ENC_RGB = 2, + V4L2_PIXEL_ENC_BAYER = 3, +}; + /** * struct v4l2_format_info - information about a V4L2 format * @format: 4CC format identifier (V4L2_PIX_FMT_*) + * @pixel_enc: Pixel encoding (see enum v4l2_pixel_encoding above) * @mem_planes: Number of memory planes, which includes the alpha plane (1 to 4). * @comp_planes: Number of component planes, which includes the alpha plane (1 to 4). * @bpp: Array of per-plane bytes per pixel @@ -469,6 +485,7 @@ int v4l2_s_parm_cap(struct video_device *vdev, */ struct v4l2_format_info { u32 format; + u8 pixel_enc; u8 mem_planes; u8 comp_planes; u8 bpp[4]; @@ -478,8 +495,22 @@ struct v4l2_format_info { u8 block_h[4]; }; -const struct v4l2_format_info *v4l2_format_info(u32 format); +static inline bool v4l2_is_format_rgb(const struct v4l2_format_info *f) +{ + return f && f->pixel_enc == V4L2_PIXEL_ENC_RGB; +} +static inline bool v4l2_is_format_yuv(const struct v4l2_format_info *f) +{ + return f && f->pixel_enc == V4L2_PIXEL_ENC_YUV; +} + +static inline bool v4l2_is_format_bayer(const struct v4l2_format_info *f) +{ + return f && f->pixel_enc == V4L2_PIXEL_ENC_BAYER; +} + +const struct v4l2_format_info *v4l2_format_info(u32 format); void v4l2_apply_frmsize_constraints(u32 *width, u32 *height, const struct v4l2_frmsize_stepwise *frmsize); int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, -- cgit