Skip to content

Commit 4a0f238

Browse files
6by9popcornmix
authored andcommitted
media: videodev2.h: Add a format for column YUV4:2:0 modes
Some of the Broadcom codec blocks use a column based YUV4:2:0 image format, so add the documentation and defines for both 8 and 10 bit versions. Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
1 parent 56a810d commit 4a0f238

5 files changed

Lines changed: 233 additions & 3 deletions

File tree

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
.. Permission is granted to copy, distribute and/or modify this
2+
.. document under the terms of the GNU Free Documentation License,
3+
.. Version 1.1 or any later version published by the Free Software
4+
.. Foundation, with no Invariant Sections, no Front-Cover Texts
5+
.. and no Back-Cover Texts. A copy of the license is included at
6+
.. Documentation/media/uapi/fdl-appendix.rst.
7+
..
8+
.. TODO: replace it to GFDL-1.1-or-later WITH no-invariant-sections
9+
10+
.. _V4L2_PIX_FMT_NV12_COL128:
11+
.. _V4L2_PIX_FMT_NV12_10_COL128:
12+
13+
********************************************************************************
14+
V4L2_PIX_FMT_NV12_COL128, V4L2_PIX_FMT_NV12_10_COL128
15+
********************************************************************************
16+
17+
18+
V4L2_PIX_FMT_NV21_COL128
19+
Formats with ½ horizontal and vertical chroma resolution. This format
20+
has two planes - one for luminance and one for chrominance. Chroma
21+
samples are interleaved. The difference to ``V4L2_PIX_FMT_NV12`` is the
22+
memory layout. The image is split into columns of 128 bytes wide rather than
23+
being in raster order.
24+
25+
V4L2_PIX_FMT_NV12_10_COL128
26+
Follows the same pattern as ``V4L2_PIX_FMT_NV21_COL128`` with 128 byte, but is
27+
a 10bit format with 3 10-bit samples being packed into 4 bytes. Each 128 byte
28+
wide column therefore contains 96 samples.
29+
30+
31+
Description
32+
===========
33+
34+
This is the two-plane versions of the YUV 4:2:0 format where data is
35+
grouped into 128 byte wide columns. The three components are separated into
36+
two sub-images or planes. The Y plane has one byte per pixel and pixels
37+
are grouped into 128 byte wide columns. The CbCr plane has the same width,
38+
in bytes, as the Y plane (and the image), but is half as tall in pixels.
39+
The chroma plane is also in 128 byte columns, reflecting 64 Cb and 64 Cr
40+
samples.
41+
42+
The chroma samples for a column follow the luma samples. If there is any
43+
paddding, then that will be reflected via the selection API.
44+
The luma height must be a multiple of 2 lines.
45+
46+
The normal bytesperline is effectively fixed at 128. However the format
47+
requires knowledge of the stride between columns, therefore the bytesperline
48+
value has been repurposed to denote the number of 128 byte long lines between
49+
the start of each column.
50+
51+
**Byte Order.**
52+
53+
54+
.. flat-table::
55+
:header-rows: 0
56+
:stub-columns: 0
57+
:widths: 12 12 12 12 12 4 12 12 12 12
58+
59+
* - start + 0:
60+
- Y'\ :sub:`0,0`
61+
- Y'\ :sub:`0,1`
62+
- Y'\ :sub:`0,2`
63+
- Y'\ :sub:`0,3`
64+
- ...
65+
- Y'\ :sub:`0,124`
66+
- Y'\ :sub:`0,125`
67+
- Y'\ :sub:`0,126`
68+
- Y'\ :sub:`0,127`
69+
* - start + 128:
70+
- Y'\ :sub:`1,0`
71+
- Y'\ :sub:`1,1`
72+
- Y'\ :sub:`1,2`
73+
- Y'\ :sub:`1,3`
74+
- ...
75+
- Y'\ :sub:`1,124`
76+
- Y'\ :sub:`1,125`
77+
- Y'\ :sub:`1,126`
78+
- Y'\ :sub:`1,127`
79+
* - start + 256:
80+
- Y'\ :sub:`2,0`
81+
- Y'\ :sub:`2,1`
82+
- Y'\ :sub:`2,2`
83+
- Y'\ :sub:`2,3`
84+
- ...
85+
- Y'\ :sub:`2,124`
86+
- Y'\ :sub:`2,125`
87+
- Y'\ :sub:`2,126`
88+
- Y'\ :sub:`2,127`
89+
* - ...
90+
- ...
91+
- ...
92+
- ...
93+
- ...
94+
- ...
95+
- ...
96+
- ...
97+
* - start + ((height-1) * 128):
98+
- Y'\ :sub:`height-1,0`
99+
- Y'\ :sub:`height-1,1`
100+
- Y'\ :sub:`height-1,2`
101+
- Y'\ :sub:`height-1,3`
102+
- ...
103+
- Y'\ :sub:`height-1,124`
104+
- Y'\ :sub:`height-1,125`
105+
- Y'\ :sub:`height-1,126`
106+
- Y'\ :sub:`height-1,127`
107+
* - start + ((height) * 128):
108+
- Cb\ :sub:`0,0`
109+
- Cr\ :sub:`0,0`
110+
- Cb\ :sub:`0,1`
111+
- Cr\ :sub:`0,1`
112+
- ...
113+
- Cb\ :sub:`0,62`
114+
- Cr\ :sub:`0,62`
115+
- Cb\ :sub:`0,63`
116+
- Cr\ :sub:`0,63`
117+
* - start + ((height+1) * 128):
118+
- Cb\ :sub:`1,0`
119+
- Cr\ :sub:`1,0`
120+
- Cb\ :sub:`1,1`
121+
- Cr\ :sub:`1,1`
122+
- ...
123+
- Cb\ :sub:`1,62`
124+
- Cr\ :sub:`1,62`
125+
- Cb\ :sub:`1,63`
126+
- Cr\ :sub:`1,63`
127+
* - ...
128+
- ...
129+
- ...
130+
- ...
131+
- ...
132+
- ...
133+
- ...
134+
- ...
135+
* - start + ((height+(height/2)-1) * 128):
136+
- Cb\ :sub:`(height/2)-1,0`
137+
- Cr\ :sub:`(height/2)-1,0`
138+
- Cb\ :sub:`(height/2)-1,1`
139+
- Cr\ :sub:`(height/2)-1,1`
140+
- ...
141+
- Cb\ :sub:`(height/2)-1,62`
142+
- Cr\ :sub:`(height/2)-1,62`
143+
- Cb\ :sub:`(height/2)-1,63`
144+
- Cr\ :sub:`(height/2)-1,63`
145+
* - start + (bytesperline * 128):
146+
- Y'\ :sub:`0,128`
147+
- Y'\ :sub:`0,129`
148+
- Y'\ :sub:`0,130`
149+
- Y'\ :sub:`0,131`
150+
- ...
151+
- Y'\ :sub:`0,252`
152+
- Y'\ :sub:`0,253`
153+
- Y'\ :sub:`0,254`
154+
- Y'\ :sub:`0,255`
155+
* - ...
156+
- ...
157+
- ...
158+
- ...
159+
- ...
160+
- ...
161+
- ...
162+
- ...
163+
164+
V4L2_PIX_FMT_NV12_10_COL128 uses the same 128 byte column structure, but
165+
encodes 10-bit YUV.
166+
3 10-bit values are packed into 4 bytes as bits 9:0, 19:10, and 29:20, with
167+
bits 30 & 31 unused. For the luma plane, bits 9:0 are Y0, 19:10 are Y1, and
168+
29:20 are Y2. For the chroma plane the samples always come in pairs of Cr
169+
and Cb, so it needs to be considered 6 values packed in 8 bytes.
170+
171+
Bit-packed representation.
172+
173+
.. raw:: latex
174+
175+
\small
176+
177+
.. tabularcolumns:: |p{1.2cm}||p{1.2cm}||p{1.2cm}||p{1.2cm}|p{3.2cm}|p{3.2cm}|
178+
179+
.. flat-table::
180+
:header-rows: 0
181+
:stub-columns: 0
182+
:widths: 8 8 8 8
183+
184+
* - Y'\ :sub:`00[7:0]`
185+
- Y'\ :sub:`01[5:0] (bits 7--2)` Y'\ :sub:`00[9:8]`\ (bits 1--0)
186+
- Y'\ :sub:`02[3:0] (bits 7--4)` Y'\ :sub:`01[9:6]`\ (bits 3--0)
187+
- unused (bits 7--6)` Y'\ :sub:`02[9:4]`\ (bits 5--0)
188+
189+
.. raw:: latex
190+
191+
\small
192+
193+
.. tabularcolumns:: |p{1.2cm}||p{1.2cm}||p{1.2cm}||p{1.2cm}|p{3.2cm}|p{3.2cm}|
194+
195+
.. flat-table::
196+
:header-rows: 0
197+
:stub-columns: 0
198+
:widths: 12 12 12 12 12 12 12 12
199+
200+
* - Cb\ :sub:`00[7:0]`
201+
- Cr\ :sub:`00[5:0]`\ (bits 7--2) Cb\ :sub:`00[9:8]`\ (bits 1--0)
202+
- Cb\ :sub:`01[3:0]`\ (bits 7--4) Cr\ :sub:`00[9:6]`\ (bits 3--0)
203+
- unused (bits 7--6) Cb\ :sub:`02[9:4]`\ (bits 5--0)
204+
- Cr\ :sub:`01[7:0]`
205+
- Cb\ :sub:`02[5:0]`\ (bits 7--2) Cr\ :sub:`01[9:8]`\ (bits 1--0)
206+
- Cr\ :sub:`02[3:0]`\ (bits 7--4) Cb\ :sub:`02[9:6]`\ (bits 3--0)
207+
- unused (bits 7--6) Cr\ :sub:`02[9:4]`\ (bits 5--0)
208+
209+
.. raw:: latex
210+
211+
\normalsize
212+
213+
214+
215+

‎Documentation/userspace-api/media/v4l/pixfmt-nv12.rst‎

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
.. _V4L2-PIX-FMT-NV12:
1111
.. _V4L2-PIX-FMT-NV21:
1212

13-
******************************************************
14-
V4L2_PIX_FMT_NV12 ('NV12'), V4L2_PIX_FMT_NV21 ('NV21')
15-
******************************************************
13+
********************************************************************************
14+
V4L2_PIX_FMT_NV12 ('NV12'), V4L2_PIX_FMT_NV21 ('NV21'), V4L2_PIX_FMT_NV12_COL128
15+
********************************************************************************
1616

1717

1818
V4L2_PIX_FMT_NV21
@@ -38,6 +38,14 @@ with a Cr byte.
3838
If the Y plane has pad bytes after each row, then the CbCr plane has as
3939
many pad bytes after its rows.
4040

41+
``V4L2_PIX_FMT_NV12_COL128`` is the tiled version of
42+
``V4L2_PIX_FMT_NV12`` with the image broken down into 128 pixel wide columns of
43+
Y followed by the associated combined CbCr plane.
44+
The normal bytesperline is effectively fixed at 128. However the format
45+
requires knowledge of the stride between columns, therefore the bytesperline
46+
value has been repurposed to denote the number of 128 byte long lines between
47+
the start of each column.
48+
4149
**Byte Order.**
4250
Each cell is one byte.
4351

‎Documentation/userspace-api/media/v4l/yuv-formats.rst‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ to brightness information.
5858
pixfmt-nv12
5959
pixfmt-nv12m
6060
pixfmt-nv12mt
61+
pixfmt-nv12-col128
6162
pixfmt-nv16
6263
pixfmt-nv16m
6364
pixfmt-nv24

‎drivers/media/v4l2-core/v4l2-ioctl.c‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,6 +1321,8 @@ static void v4l_fill_fmtdesc(struct v4l2_fmtdesc *fmt)
13211321
case V4L2_PIX_FMT_NV61M: descr = "Y/CrCb 4:2:2 (N-C)"; break;
13221322
case V4L2_PIX_FMT_NV12MT: descr = "Y/CbCr 4:2:0 (64x32 MB, N-C)"; break;
13231323
case V4L2_PIX_FMT_NV12MT_16X16: descr = "Y/CbCr 4:2:0 (16x16 MB, N-C)"; break;
1324+
case V4L2_PIX_FMT_NV12_COL128: descr = "Y/CbCr 4:2:0 (128b cols)"; break;
1325+
case V4L2_PIX_FMT_NV12_10_COL128: descr = "10-bit Y/CbCr 4:2:0 (128b cols)"; break;
13241326
case V4L2_PIX_FMT_YUV420M: descr = "Planar YUV 4:2:0 (N-C)"; break;
13251327
case V4L2_PIX_FMT_YVU420M: descr = "Planar YVU 4:2:0 (N-C)"; break;
13261328
case V4L2_PIX_FMT_YUV422M: descr = "Planar YUV 4:2:2 (N-C)"; break;

‎include/uapi/linux/videodev2.h‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,10 @@ struct v4l2_pix_format {
744744
#define V4L2_PIX_FMT_INZI v4l2_fourcc('I', 'N', 'Z', 'I') /* Intel Planar Greyscale 10-bit and Depth 16-bit */
745745
#define V4L2_PIX_FMT_SUNXI_TILED_NV12 v4l2_fourcc('S', 'T', '1', '2') /* Sunxi Tiled NV12 Format */
746746
#define V4L2_PIX_FMT_CNF4 v4l2_fourcc('C', 'N', 'F', '4') /* Intel 4-bit packed depth confidence information */
747+
#define V4L2_PIX_FMT_NV12_COL128 v4l2_fourcc('N', 'C', '1', '2') /* 12 Y/CbCr 4:2:0 128 pixel wide column */
748+
#define V4L2_PIX_FMT_NV12_10_COL128 v4l2_fourcc('N', 'C', '3', '0')
749+
/* Y/CbCr 4:2:0 10bpc, 3x10 packed as 4 bytes in
750+
* a 128 bytes / 96 pixel wide column */
747751

748752
/* 10bit raw bayer packed, 32 bytes for every 25 pixels, last LSB 6 bits unused */
749753
#define V4L2_PIX_FMT_IPU3_SBGGR10 v4l2_fourcc('i', 'p', '3', 'b') /* IPU3 packed 10-bit BGGR bayer */

0 commit comments

Comments
 (0)