1 From 3e25101dea3ed13e98339dffbc9410459e617d9a 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 .../userspace-api/media/v4l/pixfmt-nv12.rst | 14 +-
15 .../userspace-api/media/v4l/yuv-formats.rst | 1 +
16 drivers/media/v4l2-core/v4l2-ioctl.c | 2 +
17 include/uapi/linux/videodev2.h | 4 +
18 5 files changed, 233 insertions(+), 3 deletions(-)
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-nv12.rst
240 +++ b/Documentation/userspace-api/media/v4l/pixfmt-nv12.rst
242 .. _V4L2-PIX-FMT-NV12:
243 .. _V4L2-PIX-FMT-NV21:
245 -******************************************************
246 -V4L2_PIX_FMT_NV12 ('NV12'), V4L2_PIX_FMT_NV21 ('NV21')
247 -******************************************************
248 +********************************************************************************
249 +V4L2_PIX_FMT_NV12 ('NV12'), V4L2_PIX_FMT_NV21 ('NV21'), V4L2_PIX_FMT_NV12_COL128
250 +********************************************************************************
254 @@ -31,6 +31,14 @@ with a Cr byte.
255 If the Y plane has pad bytes after each row, then the CbCr plane has as
256 many pad bytes after its rows.
258 +``V4L2_PIX_FMT_NV12_COL128`` is the tiled version of
259 +``V4L2_PIX_FMT_NV12`` with the image broken down into 128 pixel wide columns of
260 +Y followed by the associated combined CbCr plane.
261 +The normal bytesperline is effectively fixed at 128. However the format
262 +requires knowledge of the stride between columns, therefore the bytesperline
263 +value has been repurposed to denote the number of 128 byte long lines between
264 +the start of each column.
267 Each cell is one byte.
269 --- a/Documentation/userspace-api/media/v4l/yuv-formats.rst
270 +++ b/Documentation/userspace-api/media/v4l/yuv-formats.rst
271 @@ -51,6 +51,7 @@ to brightness information.
279 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
280 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
281 @@ -1325,6 +1325,8 @@ static void v4l_fill_fmtdesc(struct v4l2
282 case V4L2_PIX_FMT_NV61M: descr = "Y/CrCb 4:2:2 (N-C)"; break;
283 case V4L2_PIX_FMT_NV12MT: descr = "Y/CbCr 4:2:0 (64x32 MB, N-C)"; break;
284 case V4L2_PIX_FMT_NV12MT_16X16: descr = "Y/CbCr 4:2:0 (16x16 MB, N-C)"; break;
285 + case V4L2_PIX_FMT_NV12_COL128: descr = "Y/CbCr 4:2:0 (128b cols)"; break;
286 + case V4L2_PIX_FMT_NV12_10_COL128: descr = "10-bit Y/CbCr 4:2:0 (128b cols)"; break;
287 case V4L2_PIX_FMT_YUV420M: descr = "Planar YUV 4:2:0 (N-C)"; break;
288 case V4L2_PIX_FMT_YVU420M: descr = "Planar YVU 4:2:0 (N-C)"; break;
289 case V4L2_PIX_FMT_YUV422M: descr = "Planar YUV 4:2:2 (N-C)"; break;
290 --- a/include/uapi/linux/videodev2.h
291 +++ b/include/uapi/linux/videodev2.h
292 @@ -745,6 +745,10 @@ struct v4l2_pix_format {
293 #define V4L2_PIX_FMT_INZI v4l2_fourcc('I', 'N', 'Z', 'I') /* Intel Planar Greyscale 10-bit and Depth 16-bit */
294 #define V4L2_PIX_FMT_SUNXI_TILED_NV12 v4l2_fourcc('S', 'T', '1', '2') /* Sunxi Tiled NV12 Format */
295 #define V4L2_PIX_FMT_CNF4 v4l2_fourcc('C', 'N', 'F', '4') /* Intel 4-bit packed depth confidence information */
296 +#define V4L2_PIX_FMT_NV12_COL128 v4l2_fourcc('N', 'C', '1', '2') /* 12 Y/CbCr 4:2:0 128 pixel wide column */
297 +#define V4L2_PIX_FMT_NV12_10_COL128 v4l2_fourcc('N', 'C', '3', '0')
298 + /* Y/CbCr 4:2:0 10bpc, 3x10 packed as 4 bytes in
299 + * a 128 bytes / 96 pixel wide column */
301 /* 10bit raw bayer packed, 32 bytes for every 25 pixels, last LSB 6 bits unused */
302 #define V4L2_PIX_FMT_IPU3_SBGGR10 v4l2_fourcc('i', 'p', '3', 'b') /* IPU3 packed 10-bit BGGR bayer */