1 From ab5dc4b4c5b36da38adae79ebbc2b9d8e997f49a Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Fri, 24 Jan 2020 14:28:21 +0000
4 Subject: [PATCH] media: videodev2.h: Add a format for column YUV4:2:0
7 Some of the Broadcom codec blocks use a column based YUV4:2:0 image
8 format, so add the documentation and defines for both 8 and 10 bit
11 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
13 .../media/v4l/pixfmt-nv12-col128.rst | 215 ++++++++++++++++++
14 .../media/v4l/pixfmt-yuv-planar.rst | 12 +
15 .../userspace-api/media/v4l/yuv-formats.rst | 19 ++
16 drivers/media/v4l2-core/v4l2-ioctl.c | 2 +
17 include/uapi/linux/videodev2.h | 4 +
18 5 files changed, 252 insertions(+)
19 create mode 100644 Documentation/userspace-api/media/v4l/pixfmt-nv12-col128.rst
22 +++ b/Documentation/userspace-api/media/v4l/pixfmt-nv12-col128.rst
24 +.. Permission is granted to copy, distribute and/or modify this
25 +.. document under the terms of the GNU Free Documentation License,
26 +.. Version 1.1 or any later version published by the Free Software
27 +.. Foundation, with no Invariant Sections, no Front-Cover Texts
28 +.. and no Back-Cover Texts. A copy of the license is included at
29 +.. Documentation/media/uapi/fdl-appendix.rst.
31 +.. TODO: replace it to GFDL-1.1-or-later WITH no-invariant-sections
33 +.. _V4L2_PIX_FMT_NV12_COL128:
34 +.. _V4L2_PIX_FMT_NV12_10_COL128:
36 +********************************************************************************
37 +V4L2_PIX_FMT_NV12_COL128, V4L2_PIX_FMT_NV12_10_COL128
38 +********************************************************************************
41 +V4L2_PIX_FMT_NV21_COL128
42 +Formats with ½ horizontal and vertical chroma resolution. This format
43 +has two planes - one for luminance and one for chrominance. Chroma
44 +samples are interleaved. The difference to ``V4L2_PIX_FMT_NV12`` is the
45 +memory layout. The image is split into columns of 128 bytes wide rather than
46 +being in raster order.
48 +V4L2_PIX_FMT_NV12_10_COL128
49 +Follows the same pattern as ``V4L2_PIX_FMT_NV21_COL128`` with 128 byte, but is
50 +a 10bit format with 3 10-bit samples being packed into 4 bytes. Each 128 byte
51 +wide column therefore contains 96 samples.
57 +This is the two-plane versions of the YUV 4:2:0 format where data is
58 +grouped into 128 byte wide columns. The three components are separated into
59 +two sub-images or planes. The Y plane has one byte per pixel and pixels
60 +are grouped into 128 byte wide columns. The CbCr plane has the same width,
61 +in bytes, as the Y plane (and the image), but is half as tall in pixels.
62 +The chroma plane is also in 128 byte columns, reflecting 64 Cb and 64 Cr
65 +The chroma samples for a column follow the luma samples. If there is any
66 +paddding, then that will be reflected via the selection API.
67 +The luma height must be a multiple of 2 lines.
69 +The normal bytesperline is effectively fixed at 128. However the format
70 +requires knowledge of the stride between columns, therefore the bytesperline
71 +value has been repurposed to denote the number of 128 byte long lines between
72 +the start of each column.
80 + :widths: 12 12 12 12 12 4 12 12 12 12
120 + * - start + ((height-1) * 128):
121 + - Y'\ :sub:`height-1,0`
122 + - Y'\ :sub:`height-1,1`
123 + - Y'\ :sub:`height-1,2`
124 + - Y'\ :sub:`height-1,3`
126 + - Y'\ :sub:`height-1,124`
127 + - Y'\ :sub:`height-1,125`
128 + - Y'\ :sub:`height-1,126`
129 + - Y'\ :sub:`height-1,127`
130 + * - start + ((height) * 128):
140 + * - start + ((height+1) * 128):
158 + * - start + ((height+(height/2)-1) * 128):
159 + - Cb\ :sub:`(height/2)-1,0`
160 + - Cr\ :sub:`(height/2)-1,0`
161 + - Cb\ :sub:`(height/2)-1,1`
162 + - Cr\ :sub:`(height/2)-1,1`
164 + - Cb\ :sub:`(height/2)-1,62`
165 + - Cr\ :sub:`(height/2)-1,62`
166 + - Cb\ :sub:`(height/2)-1,63`
167 + - Cr\ :sub:`(height/2)-1,63`
168 + * - start + (bytesperline * 128):
187 +V4L2_PIX_FMT_NV12_10_COL128 uses the same 128 byte column structure, but
189 +3 10-bit values are packed into 4 bytes as bits 9:0, 19:10, and 29:20, with
190 +bits 30 & 31 unused. For the luma plane, bits 9:0 are Y0, 19:10 are Y1, and
191 +29:20 are Y2. For the chroma plane the samples always come in pairs of Cr
192 +and Cb, so it needs to be considered 6 values packed in 8 bytes.
194 +Bit-packed representation.
200 +.. tabularcolumns:: |p{1.2cm}||p{1.2cm}||p{1.2cm}||p{1.2cm}|p{3.2cm}|p{3.2cm}|
207 + * - Y'\ :sub:`00[7:0]`
208 + - Y'\ :sub:`01[5:0] (bits 7--2)` Y'\ :sub:`00[9:8]`\ (bits 1--0)
209 + - Y'\ :sub:`02[3:0] (bits 7--4)` Y'\ :sub:`01[9:6]`\ (bits 3--0)
210 + - unused (bits 7--6)` Y'\ :sub:`02[9:4]`\ (bits 5--0)
216 +.. tabularcolumns:: |p{1.2cm}||p{1.2cm}||p{1.2cm}||p{1.2cm}|p{3.2cm}|p{3.2cm}|
221 + :widths: 12 12 12 12 12 12 12 12
223 + * - Cb\ :sub:`00[7:0]`
224 + - Cr\ :sub:`00[5:0]`\ (bits 7--2) Cb\ :sub:`00[9:8]`\ (bits 1--0)
225 + - Cb\ :sub:`01[3:0]`\ (bits 7--4) Cr\ :sub:`00[9:6]`\ (bits 3--0)
226 + - unused (bits 7--6) Cb\ :sub:`02[9:4]`\ (bits 5--0)
227 + - Cr\ :sub:`01[7:0]`
228 + - Cb\ :sub:`02[5:0]`\ (bits 7--2) Cr\ :sub:`01[9:8]`\ (bits 1--0)
229 + - Cr\ :sub:`02[3:0]`\ (bits 7--4) Cb\ :sub:`02[9:6]`\ (bits 3--0)
230 + - unused (bits 7--6) Cr\ :sub:`02[9:4]`\ (bits 5--0)
239 --- a/Documentation/userspace-api/media/v4l/pixfmt-yuv-planar.rst
240 +++ b/Documentation/userspace-api/media/v4l/pixfmt-yuv-planar.rst
241 @@ -579,6 +579,18 @@ Data in the 10 high bits, zeros in the 6
245 +V4L2_PIX_FMT_NV12_COL128
246 +------------------------
248 +``V4L2_PIX_FMT_NV12_COL128`` is the tiled version of
249 +``V4L2_PIX_FMT_NV12`` with the image broken down into 128 pixel wide columns of
250 +Y followed by the associated combined CbCr plane.
251 +The normal bytesperline is effectively fixed at 128. However the format
252 +requires knowledge of the stride between columns, therefore the bytesperline
253 +value has been repurposed to denote the number of 128 byte long lines between
254 +the start of each column.
257 Fully Planar YUV Formats
258 ========================
260 --- a/Documentation/userspace-api/media/v4l/yuv-formats.rst
261 +++ b/Documentation/userspace-api/media/v4l/yuv-formats.rst
262 @@ -270,4 +270,23 @@ image.
286 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
287 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
288 @@ -1364,6 +1364,8 @@ static void v4l_fill_fmtdesc(struct v4l2
289 case V4L2_PIX_FMT_NV61M: descr = "Y/VU 4:2:2 (N-C)"; break;
290 case V4L2_PIX_FMT_NV12MT: descr = "Y/UV 4:2:0 (64x32 MB, N-C)"; break;
291 case V4L2_PIX_FMT_NV12MT_16X16: descr = "Y/UV 4:2:0 (16x16 MB, N-C)"; break;
292 + case V4L2_PIX_FMT_NV12_COL128: descr = "Y/CbCr 4:2:0 (128b cols)"; break;
293 + case V4L2_PIX_FMT_NV12_10_COL128: descr = "10-bit Y/CbCr 4:2:0 (128b cols)"; break;
294 case V4L2_PIX_FMT_YUV420M: descr = "Planar YUV 4:2:0 (N-C)"; break;
295 case V4L2_PIX_FMT_YVU420M: descr = "Planar YVU 4:2:0 (N-C)"; break;
296 case V4L2_PIX_FMT_YUV422M: descr = "Planar YUV 4:2:2 (N-C)"; break;
297 --- a/include/uapi/linux/videodev2.h
298 +++ b/include/uapi/linux/videodev2.h
299 @@ -780,6 +780,10 @@ struct v4l2_pix_format {
300 #define V4L2_PIX_FMT_HI240 v4l2_fourcc('H', 'I', '2', '4') /* BTTV 8-bit dithered RGB */
301 #define V4L2_PIX_FMT_QC08C v4l2_fourcc('Q', '0', '8', 'C') /* Qualcomm 8-bit compressed */
302 #define V4L2_PIX_FMT_QC10C v4l2_fourcc('Q', '1', '0', 'C') /* Qualcomm 10-bit compressed */
303 +#define V4L2_PIX_FMT_NV12_COL128 v4l2_fourcc('N', 'C', '1', '2') /* 12 Y/CbCr 4:2:0 128 pixel wide column */
304 +#define V4L2_PIX_FMT_NV12_10_COL128 v4l2_fourcc('N', 'C', '3', '0')
305 + /* Y/CbCr 4:2:0 10bpc, 3x10 packed as 4 bytes in
306 + * a 128 bytes / 96 pixel wide column */
308 /* 10bit raw packed, 32 bytes for every 25 pixels, last LSB 6 bits unused */
309 #define V4L2_PIX_FMT_IPU3_SBGGR10 v4l2_fourcc('i', 'p', '3', 'b') /* IPU3 packed 10-bit BGGR bayer */