Re: [PATCH v2 04/10] media: Add YUV24_12 video format

From: Nicolas Dufresne
Date: Fri Feb 10 2023 - 10:20:44 EST


Le mercredi 01 février 2023 à 14:02 +0800, Ming Qian a écrit :
> YUV24_12 is a YUV format with 12-bits per component like YUV24,
> expanded to 16bits.
> Data in the 12 high bits, zeros in the 4 low bits,
> arranged in little endian order.

In YUV24, 24 is derived from 8x3, but here we have 16x3. So if naming is meant
to be accurate, shouldn't this be YUV48_12 ?

>
> Signed-off-by: Ming Qian <ming.qian@xxxxxxx>
> ---
> .../media/v4l/pixfmt-packed-yuv.rst | 28 +++++++++++++++++++
> drivers/media/v4l2-core/v4l2-common.c | 1 +
> drivers/media/v4l2-core/v4l2-ioctl.c | 1 +
> include/uapi/linux/videodev2.h | 1 +
> 4 files changed, 31 insertions(+)
>
> diff --git a/Documentation/userspace-api/media/v4l/pixfmt-packed-yuv.rst b/Documentation/userspace-api/media/v4l/pixfmt-packed-yuv.rst
> index bb7169b2cc8d..a098c5e8e609 100644
> --- a/Documentation/userspace-api/media/v4l/pixfmt-packed-yuv.rst
> +++ b/Documentation/userspace-api/media/v4l/pixfmt-packed-yuv.rst
> @@ -257,6 +257,34 @@ the second byte and Y'\ :sub:`7-0` in the third byte.
> - The padding bits contain undefined values that must be ignored by all
> applications and drivers.
>
> +The next lists the packed YUV 4:4:4 formats with more than 8 bits per component.
> +expand the bits per component to 16 bits, data in the high bits, zeros in the low bits,
> +arranged in little endian order. storing 1 pixels in 6 bytes.
> +
> +.. flat-table:: Packed YUV 4:4:4 Image Formats (more than 8bpc)
> + :header-rows: 1
> + :stub-columns: 0
> +
> + * - Identifier
> + - Code
> + - Byte 1-0
> + - Byte 3-2
> + - Byte 5-4
> + - Byte 7-6
> + - Byte 9-8
> + - Byte 11-10
> +
> + * .. _V4L2-PIX-FMT-YUV24-12:
> +
> + - ``V4L2_PIX_FMT_YUV24_12``
> + - 'Y312'
> +
> + - Y'\ :sub:`0`
> + - Cb\ :sub:`0`
> + - Cr\ :sub:`0`
> + - Y'\ :sub:`1`
> + - Cb\ :sub:`1`
> + - Cr\ :sub:`1`
>
> 4:2:2 Subsampling
> =================
> diff --git a/drivers/media/v4l2-core/v4l2-common.c b/drivers/media/v4l2-core/v4l2-common.c
> index 3a882fb71227..b3ad02f8cf11 100644
> --- a/drivers/media/v4l2-core/v4l2-common.c
> +++ b/drivers/media/v4l2-core/v4l2-common.c
> @@ -259,6 +259,7 @@ const struct v4l2_format_info *v4l2_format_info(u32 format)
> { .format = V4L2_PIX_FMT_UYVY, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .hdiv = 2, .vdiv = 1 },
> { .format = V4L2_PIX_FMT_VYUY, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 1, .bpp = { 2, 0, 0, 0 }, .hdiv = 2, .vdiv = 1 },
> { .format = V4L2_PIX_FMT_YUYV_12, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 1, .bpp = { 4, 0, 0, 0 }, .hdiv = 2, .vdiv = 1 },
> + { .format = V4L2_PIX_FMT_YUV24_12, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 1, .bpp = { 6, 0, 0, 0 }, .hdiv = 1, .vdiv = 1 },
>
> /* YUV planar formats */
> { .format = V4L2_PIX_FMT_NV12, .pixel_enc = V4L2_PIXEL_ENC_YUV, .mem_planes = 1, .comp_planes = 2, .bpp = { 1, 2, 0, 0 }, .hdiv = 2, .vdiv = 2 },
> diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
> index 928acb9d13ec..711d1b0a8184 100644
> --- a/drivers/media/v4l2-core/v4l2-ioctl.c
> +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
> @@ -1343,6 +1343,7 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
> case V4L2_PIX_FMT_HI240: descr = "8-bit Dithered RGB (BTTV)"; break;
> case V4L2_PIX_FMT_M420: descr = "YUV 4:2:0 (M420)"; break;
> case V4L2_PIX_FMT_YUYV_12: descr = "12-bit Depth YUYV 4:2:2"; break;
> + case V4L2_PIX_FMT_YUV24_12: descr = "12-bit Depth YUV 4:4:4"; break;
> case V4L2_PIX_FMT_NV12: descr = "Y/UV 4:2:0"; break;
> case V4L2_PIX_FMT_NV21: descr = "Y/VU 4:2:0"; break;
> case V4L2_PIX_FMT_NV16: descr = "Y/UV 4:2:2"; break;
> diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
> index 01fd233ff681..3eb188581b83 100644
> --- a/include/uapi/linux/videodev2.h
> +++ b/include/uapi/linux/videodev2.h
> @@ -619,6 +619,7 @@ struct v4l2_pix_format {
> #define V4L2_PIX_FMT_YUVX32 v4l2_fourcc('Y', 'U', 'V', 'X') /* 32 YUVX-8-8-8-8 */
> #define V4L2_PIX_FMT_M420 v4l2_fourcc('M', '4', '2', '0') /* 12 YUV 4:2:0 2 lines y, 1 line uv interleaved */
> #define V4L2_PIX_FMT_YUYV_12 v4l2_fourcc('Y', '2', '1', '2') /* 32 YUYV 12-bit per component */
> +#define V4L2_PIX_FMT_YUV24_12 v4l2_fourcc('Y', '3', '1', '2') /* 48 YUV 4:4:4 12-bit per component */
>
> /* two planes -- one Y, one Cr + Cb interleaved */
> #define V4L2_PIX_FMT_NV12 v4l2_fourcc('N', 'V', '1', '2') /* 12 Y/CbCr 4:2:0 */