d11d89cde70b1dd192b2b3d155de76f69d43240a
[openwrt/staging/blocktrron.git] /
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
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 .../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
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-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
242 - Cr\ :sub:`11`
243
244
245 +V4L2_PIX_FMT_NV12_COL128
246 +------------------------
247 +
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.
255 +
256 +
257 Fully Planar YUV Formats
258 ========================
259
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.
263 pixfmt-y8i
264 pixfmt-y12i
265 pixfmt-uv8
266 + pixfmt-yuyv
267 + pixfmt-uyvy
268 + pixfmt-yvyu
269 + pixfmt-vyuy
270 + pixfmt-y41p
271 + pixfmt-yuv420
272 + pixfmt-yuv420m
273 + pixfmt-yuv422m
274 + pixfmt-yuv444m
275 + pixfmt-yuv410
276 + pixfmt-yuv422p
277 + pixfmt-yuv411p
278 + pixfmt-nv12
279 + pixfmt-nv12m
280 + pixfmt-nv12mt
281 + pixfmt-nv12-col128
282 + pixfmt-nv16
283 + pixfmt-nv16m
284 + pixfmt-nv24
285 pixfmt-m420
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 */
307
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 */