Commit d5a897c8 authored by Benoit Parrot's avatar Benoit Parrot Committed by Mauro Carvalho Chehab

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: default avatarBenoit Parrot <bparrot@ti.com>
Signed-off-by: default avatarHans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: default avatarMauro Carvalho Chehab <mchehab+samsung@kernel.org>
parent 9152dc9e
This diff is collapsed.
...@@ -456,9 +456,25 @@ int v4l2_s_parm_cap(struct video_device *vdev, ...@@ -456,9 +456,25 @@ int v4l2_s_parm_cap(struct video_device *vdev,
/* Pixel format and FourCC helpers */ /* 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 * struct v4l2_format_info - information about a V4L2 format
* @format: 4CC format identifier (V4L2_PIX_FMT_*) * @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). * @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). * @comp_planes: Number of component planes, which includes the alpha plane (1 to 4).
* @bpp: Array of per-plane bytes per pixel * @bpp: Array of per-plane bytes per pixel
...@@ -469,6 +485,7 @@ int v4l2_s_parm_cap(struct video_device *vdev, ...@@ -469,6 +485,7 @@ int v4l2_s_parm_cap(struct video_device *vdev,
*/ */
struct v4l2_format_info { struct v4l2_format_info {
u32 format; u32 format;
u8 pixel_enc;
u8 mem_planes; u8 mem_planes;
u8 comp_planes; u8 comp_planes;
u8 bpp[4]; u8 bpp[4];
...@@ -478,8 +495,22 @@ struct v4l2_format_info { ...@@ -478,8 +495,22 @@ struct v4l2_format_info {
u8 block_h[4]; 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, void v4l2_apply_frmsize_constraints(u32 *width, u32 *height,
const struct v4l2_frmsize_stepwise *frmsize); const struct v4l2_frmsize_stepwise *frmsize);
int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat, int v4l2_fill_pixfmt(struct v4l2_pix_format *pixfmt, u32 pixelformat,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment