abeddf9c76914e8f5ee2b80b6bb3e18b8d79fe69
[openwrt/staging/xback.git] /
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
5 modes
6
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
9 versions.
10
11 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
12 ---
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
20
21 --- /dev/null
22 +++ b/Documentation/userspace-api/media/v4l/pixfmt-nv12-col128.rst
23 @@ -0,0 +1,215 @@
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.
30 +..
31 +.. TODO: replace it to GFDL-1.1-or-later WITH no-invariant-sections
32 +
33 +.. _V4L2_PIX_FMT_NV12_COL128:
34 +.. _V4L2_PIX_FMT_NV12_10_COL128:
35 +
36 +********************************************************************************
37 +V4L2_PIX_FMT_NV12_COL128, V4L2_PIX_FMT_NV12_10_COL128
38 +********************************************************************************
39 +
40 +
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.
47 +
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.
52 +
53 +
54 +Description
55 +===========
56 +
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
63 +samples.
64 +
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.
68 +
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.
73 +
74 +**Byte Order.**
75 +
76 +
77 +.. flat-table::
78 + :header-rows: 0
79 + :stub-columns: 0
80 + :widths: 12 12 12 12 12 4 12 12 12 12
81 +
82 + * - start + 0:
83 + - Y'\ :sub:`0,0`
84 + - Y'\ :sub:`0,1`
85 + - Y'\ :sub:`0,2`
86 + - Y'\ :sub:`0,3`
87 + - ...
88 + - Y'\ :sub:`0,124`
89 + - Y'\ :sub:`0,125`
90 + - Y'\ :sub:`0,126`
91 + - Y'\ :sub:`0,127`
92 + * - start + 128:
93 + - Y'\ :sub:`1,0`
94 + - Y'\ :sub:`1,1`
95 + - Y'\ :sub:`1,2`
96 + - Y'\ :sub:`1,3`
97 + - ...
98 + - Y'\ :sub:`1,124`
99 + - Y'\ :sub:`1,125`
100 + - Y'\ :sub:`1,126`
101 + - Y'\ :sub:`1,127`
102 + * - start + 256:
103 + - Y'\ :sub:`2,0`
104 + - Y'\ :sub:`2,1`
105 + - Y'\ :sub:`2,2`
106 + - Y'\ :sub:`2,3`
107 + - ...
108 + - Y'\ :sub:`2,124`
109 + - Y'\ :sub:`2,125`
110 + - Y'\ :sub:`2,126`
111 + - Y'\ :sub:`2,127`
112 + * - ...
113 + - ...
114 + - ...
115 + - ...
116 + - ...
117 + - ...
118 + - ...
119 + - ...
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`
125 + - ...
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):
131 + - Cb\ :sub:`0,0`
132 + - Cr\ :sub:`0,0`
133 + - Cb\ :sub:`0,1`
134 + - Cr\ :sub:`0,1`
135 + - ...
136 + - Cb\ :sub:`0,62`
137 + - Cr\ :sub:`0,62`
138 + - Cb\ :sub:`0,63`
139 + - Cr\ :sub:`0,63`
140 + * - start + ((height+1) * 128):
141 + - Cb\ :sub:`1,0`
142 + - Cr\ :sub:`1,0`
143 + - Cb\ :sub:`1,1`
144 + - Cr\ :sub:`1,1`
145 + - ...
146 + - Cb\ :sub:`1,62`
147 + - Cr\ :sub:`1,62`
148 + - Cb\ :sub:`1,63`
149 + - Cr\ :sub:`1,63`
150 + * - ...
151 + - ...
152 + - ...
153 + - ...
154 + - ...
155 + - ...
156 + - ...
157 + - ...
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`
163 + - ...
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):
169 + - Y'\ :sub:`0,128`
170 + - Y'\ :sub:`0,129`
171 + - Y'\ :sub:`0,130`
172 + - Y'\ :sub:`0,131`
173 + - ...
174 + - Y'\ :sub:`0,252`
175 + - Y'\ :sub:`0,253`
176 + - Y'\ :sub:`0,254`
177 + - Y'\ :sub:`0,255`
178 + * - ...
179 + - ...
180 + - ...
181 + - ...
182 + - ...
183 + - ...
184 + - ...
185 + - ...
186 +
187 +V4L2_PIX_FMT_NV12_10_COL128 uses the same 128 byte column structure, but
188 +encodes 10-bit YUV.
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.
193 +
194 +Bit-packed representation.
195 +
196 +.. raw:: latex
197 +
198 + \small
199 +
200 +.. tabularcolumns:: |p{1.2cm}||p{1.2cm}||p{1.2cm}||p{1.2cm}|p{3.2cm}|p{3.2cm}|
201 +
202 +.. flat-table::
203 + :header-rows: 0
204 + :stub-columns: 0
205 + :widths: 8 8 8 8
206 +
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)
211 +
212 +.. raw:: latex
213 +
214 + \small
215 +
216 +.. tabularcolumns:: |p{1.2cm}||p{1.2cm}||p{1.2cm}||p{1.2cm}|p{3.2cm}|p{3.2cm}|
217 +
218 +.. flat-table::
219 + :header-rows: 0
220 + :stub-columns: 0
221 + :widths: 12 12 12 12 12 12 12 12
222 +
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)
231 +
232 +.. raw:: latex
233 +
234 + \normalsize
235 +
236 +
237 +
238 +
239 --- a/Documentation/userspace-api/media/v4l/pixfmt-nv12.rst
240 +++ b/Documentation/userspace-api/media/v4l/pixfmt-nv12.rst
241 @@ -3,9 +3,9 @@
242 .. _V4L2-PIX-FMT-NV12:
243 .. _V4L2-PIX-FMT-NV21:
244
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 +********************************************************************************
251
252
253 V4L2_PIX_FMT_NV21
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.
257
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.
265 +
266 **Byte Order.**
267 Each cell is one byte.
268
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.
272 pixfmt-nv12
273 pixfmt-nv12m
274 pixfmt-nv12mt
275 + pixfmt-nv12-col128
276 pixfmt-nv16
277 pixfmt-nv16m
278 pixfmt-nv24
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 */
300
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 */