1.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
2
3.. _packed-yuv:
4
5******************
6Packed YUV formats
7******************
8
9Similarly to the packed RGB formats, the packed YUV formats store the Y, Cb and
10Cr components consecutively in memory. They may apply subsampling to the chroma
11components and thus differ in how they interlave the three components.
12
13.. note::
14
15   - In all the tables that follow, bit 7 is the most significant bit in a byte.
16   - 'Y', 'Cb' and 'Cr' denote bits of the luma, blue chroma (also known as
17     'U') and red chroma (also known as 'V') components respectively. 'A'
18     denotes bits of the alpha component (if supported by the format), and 'X'
19     denotes padding bits.
20
21
224:4:4 Subsampling
23=================
24
25These formats do not subsample the chroma components and store each pixels as a
26full triplet of Y, Cb and Cr values.
27
28The next table lists the packed YUV 4:4:4 formats with less than 8 bits per
29component. They are named based on the order of the Y, Cb and Cr components as
30seen in a 16-bit word, which is then stored in memory in little endian byte
31order, and on the number of bits for each component. For instance the YUV565
32format stores a pixel in a 16-bit word [15:0] laid out at as [Y'\ :sub:`4-0`
33Cb\ :sub:`5-0` Cr\ :sub:`4-0`], and stored in memory in two bytes,
34[Cb\ :sub:`2-0` Cr\ :sub:`4-0`] followed by [Y'\ :sub:`4-0` Cb\ :sub:`5-3`].
35
36.. raw:: latex
37
38    \begingroup
39    \scriptsize
40    \setlength{\tabcolsep}{2pt}
41
42.. tabularcolumns:: |p{3.5cm}|p{0.96cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}|p{0.52cm}|
43
44.. flat-table:: Packed YUV 4:4:4 Image Formats (less than 8bpc)
45    :header-rows:  2
46    :stub-columns: 0
47
48    * - Identifier
49      - Code
50
51      - :cspan:`7` Byte 0 in memory
52
53      - :cspan:`7` Byte 1
54
55    * -
56      -
57      - 7
58      - 6
59      - 5
60      - 4
61      - 3
62      - 2
63      - 1
64      - 0
65
66      - 7
67      - 6
68      - 5
69      - 4
70      - 3
71      - 2
72      - 1
73      - 0
74
75    * .. _V4L2-PIX-FMT-YUV444:
76
77      - ``V4L2_PIX_FMT_YUV444``
78      - 'Y444'
79
80      - Cb\ :sub:`3`
81      - Cb\ :sub:`2`
82      - Cb\ :sub:`1`
83      - Cb\ :sub:`0`
84      - Cr\ :sub:`3`
85      - Cr\ :sub:`2`
86      - Cr\ :sub:`1`
87      - Cr\ :sub:`0`
88
89      - a\ :sub:`3`
90      - a\ :sub:`2`
91      - a\ :sub:`1`
92      - a\ :sub:`0`
93      - Y'\ :sub:`3`
94      - Y'\ :sub:`2`
95      - Y'\ :sub:`1`
96      - Y'\ :sub:`0`
97
98    * .. _V4L2-PIX-FMT-YUV555:
99
100      - ``V4L2_PIX_FMT_YUV555``
101      - 'YUVO'
102
103      - Cb\ :sub:`2`
104      - Cb\ :sub:`1`
105      - Cb\ :sub:`0`
106      - Cr\ :sub:`4`
107      - Cr\ :sub:`3`
108      - Cr\ :sub:`2`
109      - Cr\ :sub:`1`
110      - Cr\ :sub:`0`
111
112      - a
113      - Y'\ :sub:`4`
114      - Y'\ :sub:`3`
115      - Y'\ :sub:`2`
116      - Y'\ :sub:`1`
117      - Y'\ :sub:`0`
118      - Cb\ :sub:`4`
119      - Cb\ :sub:`3`
120
121    * .. _V4L2-PIX-FMT-YUV565:
122
123      - ``V4L2_PIX_FMT_YUV565``
124      - 'YUVP'
125
126      - Cb\ :sub:`2`
127      - Cb\ :sub:`1`
128      - Cb\ :sub:`0`
129      - Cr\ :sub:`4`
130      - Cr\ :sub:`3`
131      - Cr\ :sub:`2`
132      - Cr\ :sub:`1`
133      - Cr\ :sub:`0`
134
135      - Y'\ :sub:`4`
136      - Y'\ :sub:`3`
137      - Y'\ :sub:`2`
138      - Y'\ :sub:`1`
139      - Y'\ :sub:`0`
140      - Cb\ :sub:`5`
141      - Cb\ :sub:`4`
142      - Cb\ :sub:`3`
143
144.. raw:: latex
145
146    \endgroup
147
148.. note::
149
150    For the YUV444 and YUV555 formats, the value of alpha bits is undefined
151    when reading from the driver, ignored when writing to the driver, except
152    when alpha blending has been negotiated for a :ref:`Video Overlay
153    <overlay>` or :ref:`Video Output Overlay <osd>`.
154
155
156The next table lists the packed YUV 4:4:4 formats with 8 bits per component.
157They are named based on the order of the Y, Cb and Cr components as stored in
158memory, and on the total number of bits per pixel. For instance, the VUYX32
159format stores a pixel with Cr\ :sub:`7-0` in the first byte, Cb\ :sub:`7-0` in
160the second byte and Y'\ :sub:`7-0` in the third byte.
161
162.. flat-table:: Packed YUV Image Formats (8bpc)
163    :header-rows: 1
164    :stub-columns: 0
165
166    * - Identifier
167      - Code
168      - Byte 0
169      - Byte 1
170      - Byte 2
171      - Byte 3
172
173    * .. _V4L2-PIX-FMT-YUV32:
174
175      - ``V4L2_PIX_FMT_YUV32``
176      - 'YUV4'
177
178      - A\ :sub:`7-0`
179      - Y'\ :sub:`7-0`
180      - Cb\ :sub:`7-0`
181      - Cr\ :sub:`7-0`
182
183    * .. _V4L2-PIX-FMT-AYUV32:
184
185      - ``V4L2_PIX_FMT_AYUV32``
186      - 'AYUV'
187
188      - A\ :sub:`7-0`
189      - Y'\ :sub:`7-0`
190      - Cb\ :sub:`7-0`
191      - Cr\ :sub:`7-0`
192
193    * .. _V4L2-PIX-FMT-XYUV32:
194
195      - ``V4L2_PIX_FMT_XYUV32``
196      - 'XYUV'
197
198      - X\ :sub:`7-0`
199      - Y'\ :sub:`7-0`
200      - Cb\ :sub:`7-0`
201      - Cr\ :sub:`7-0`
202
203    * .. _V4L2-PIX-FMT-VUYA32:
204
205      - ``V4L2_PIX_FMT_VUYA32``
206      - 'VUYA'
207
208      - Cr\ :sub:`7-0`
209      - Cb\ :sub:`7-0`
210      - Y'\ :sub:`7-0`
211      - A\ :sub:`7-0`
212
213    * .. _V4L2-PIX-FMT-VUYX32:
214
215      - ``V4L2_PIX_FMT_VUYX32``
216      - 'VUYX'
217
218      - Cr\ :sub:`7-0`
219      - Cb\ :sub:`7-0`
220      - Y'\ :sub:`7-0`
221      - X\ :sub:`7-0`
222
223    * .. _V4L2-PIX-FMT-YUVA32:
224
225      - ``V4L2_PIX_FMT_YUVA32``
226      - 'YUVA'
227
228      - Y'\ :sub:`7-0`
229      - Cb\ :sub:`7-0`
230      - Cr\ :sub:`7-0`
231      - A\ :sub:`7-0`
232
233    * .. _V4L2-PIX-FMT-YUVX32:
234
235      - ``V4L2_PIX_FMT_YUVX32``
236      - 'YUVX'
237
238      - Y'\ :sub:`7-0`
239      - Cb\ :sub:`7-0`
240      - Cr\ :sub:`7-0`
241      - X\ :sub:`7-0`
242
243    * .. _V4L2-PIX-FMT-YUV24:
244
245      - ``V4L2_PIX_FMT_YUV24``
246      - 'YUV3'
247
248      - Y'\ :sub:`7-0`
249      - Cb\ :sub:`7-0`
250      - Cr\ :sub:`7-0`
251      - -\
252
253.. note::
254
255    - The alpha component is expected to contain a meaningful value that can be
256      used by drivers and applications.
257    - The padding bits contain undefined values that must be ignored by all
258      applications and drivers.
259
260The next table lists the packed YUV 4:4:4 formats with 12 bits per component.
261Expand the bits per component to 16 bits, data in the high bits, zeros in the low bits,
262arranged in little endian order, storing 1 pixel in 6 bytes.
263
264.. flat-table:: Packed YUV 4:4:4 Image Formats (12bpc)
265    :header-rows: 1
266    :stub-columns: 0
267
268    * - Identifier
269      - Code
270      - Byte 1-0
271      - Byte 3-2
272      - Byte 5-4
273      - Byte 7-6
274      - Byte 9-8
275      - Byte 11-10
276
277    * .. _V4L2-PIX-FMT-YUV48-12:
278
279      - ``V4L2_PIX_FMT_YUV48_12``
280      - 'Y312'
281
282      - Y'\ :sub:`0`
283      - Cb\ :sub:`0`
284      - Cr\ :sub:`0`
285      - Y'\ :sub:`1`
286      - Cb\ :sub:`1`
287      - Cr\ :sub:`1`
288
2894:2:2 Subsampling
290=================
291
292These formats, commonly referred to as YUYV or YUY2, subsample the chroma
293components horizontally by 2, storing 2 pixels in a container. The container
294is 32-bits for 8-bit formats, and 64-bits for 10+-bit formats.
295
296The packed YUYV formats with more than 8 bits per component are stored as four
29716-bit little-endian words. Each word's most significant bits contain one
298component, and the least significant bits are zero padding.
299
300.. raw:: latex
301
302    \footnotesize
303
304.. tabularcolumns:: |p{3.4cm}|p{1.2cm}|p{0.8cm}|p{0.8cm}|p{0.8cm}|p{0.8cm}|p{0.8cm}|p{0.8cm}|p{0.8cm}|p{0.8cm}|
305
306.. flat-table:: Packed YUV 4:2:2 Formats in 32-bit container
307    :header-rows: 1
308    :stub-columns: 0
309
310    * - Identifier
311      - Code
312      - Byte 0
313      - Byte 1
314      - Byte 2
315      - Byte 3
316      - Byte 4
317      - Byte 5
318      - Byte 6
319      - Byte 7
320    * .. _V4L2-PIX-FMT-UYVY:
321
322      - ``V4L2_PIX_FMT_UYVY``
323      - 'UYVY'
324
325      - Cb\ :sub:`0`
326      - Y'\ :sub:`0`
327      - Cr\ :sub:`0`
328      - Y'\ :sub:`1`
329      - Cb\ :sub:`2`
330      - Y'\ :sub:`2`
331      - Cr\ :sub:`2`
332      - Y'\ :sub:`3`
333    * .. _V4L2-PIX-FMT-VYUY:
334
335      - ``V4L2_PIX_FMT_VYUY``
336      - 'VYUY'
337
338      - Cr\ :sub:`0`
339      - Y'\ :sub:`0`
340      - Cb\ :sub:`0`
341      - Y'\ :sub:`1`
342      - Cr\ :sub:`2`
343      - Y'\ :sub:`2`
344      - Cb\ :sub:`2`
345      - Y'\ :sub:`3`
346    * .. _V4L2-PIX-FMT-YUYV:
347
348      - ``V4L2_PIX_FMT_YUYV``
349      - 'YUYV'
350
351      - Y'\ :sub:`0`
352      - Cb\ :sub:`0`
353      - Y'\ :sub:`1`
354      - Cr\ :sub:`0`
355      - Y'\ :sub:`2`
356      - Cb\ :sub:`2`
357      - Y'\ :sub:`3`
358      - Cr\ :sub:`2`
359    * .. _V4L2-PIX-FMT-YVYU:
360
361      - ``V4L2_PIX_FMT_YVYU``
362      - 'YVYU'
363
364      - Y'\ :sub:`0`
365      - Cr\ :sub:`0`
366      - Y'\ :sub:`1`
367      - Cb\ :sub:`0`
368      - Y'\ :sub:`2`
369      - Cr\ :sub:`2`
370      - Y'\ :sub:`3`
371      - Cb\ :sub:`2`
372
373.. tabularcolumns:: |p{3.4cm}|p{1.2cm}|p{0.8cm}|p{0.8cm}|p{0.8cm}|p{0.8cm}|p{0.8cm}|p{0.8cm}|p{0.8cm}|p{0.8cm}|
374
375.. flat-table:: Packed YUV 4:2:2 Formats in 64-bit container
376    :header-rows: 1
377    :stub-columns: 0
378
379    * - Identifier
380      - Code
381      - Word 0
382      - Word 1
383      - Word 2
384      - Word 3
385    * .. _V4L2-PIX-FMT-Y210:
386
387      - ``V4L2_PIX_FMT_Y210``
388      - 'Y210'
389
390      - Y'\ :sub:`0` (bits 15-6)
391      - Cb\ :sub:`0` (bits 15-6)
392      - Y'\ :sub:`1` (bits 15-6)
393      - Cr\ :sub:`0` (bits 15-6)
394    * .. _V4L2-PIX-FMT-Y212:
395
396      - ``V4L2_PIX_FMT_Y212``
397      - 'Y212'
398
399      - Y'\ :sub:`0` (bits 15-4)
400      - Cb\ :sub:`0` (bits 15-4)
401      - Y'\ :sub:`1` (bits 15-4)
402      - Cr\ :sub:`0` (bits 15-4)
403    * .. _V4L2-PIX-FMT-Y216:
404
405      - ``V4L2_PIX_FMT_Y216``
406      - 'Y216'
407
408      - Y'\ :sub:`0` (bits 15-0)
409      - Cb\ :sub:`0` (bits 15-0)
410      - Y'\ :sub:`1` (bits 15-0)
411      - Cr\ :sub:`0` (bits 15-0)
412
413.. raw:: latex
414
415    \normalsize
416
417**Color Sample Location:**
418Chroma samples are :ref:`interstitially sited<yuv-chroma-centered>`
419horizontally.
420
421
4224:1:1 Subsampling
423=================
424
425This format subsamples the chroma components horizontally by 4, storing 8
426pixels in 12 bytes.
427
428.. raw:: latex
429
430    \scriptsize
431
432.. tabularcolumns:: |p{2.9cm}|p{0.8cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|p{0.5cm}|
433
434.. flat-table:: Packed YUV 4:1:1 Formats
435    :header-rows: 1
436    :stub-columns: 0
437
438    * - Identifier
439      - Code
440      - Byte 0
441      - Byte 1
442      - Byte 2
443      - Byte 3
444      - Byte 4
445      - Byte 5
446      - Byte 6
447      - Byte 7
448      - Byte 8
449      - Byte 9
450      - Byte 10
451      - Byte 11
452    * .. _V4L2-PIX-FMT-Y41P:
453
454      - ``V4L2_PIX_FMT_Y41P``
455      - 'Y41P'
456
457      - Cb\ :sub:`0`
458      - Y'\ :sub:`0`
459      - Cr\ :sub:`0`
460      - Y'\ :sub:`1`
461      - Cb\ :sub:`4`
462      - Y'\ :sub:`2`
463      - Cr\ :sub:`4`
464      - Y'\ :sub:`3`
465      - Y'\ :sub:`4`
466      - Y'\ :sub:`5`
467      - Y'\ :sub:`6`
468      - Y'\ :sub:`7`
469
470.. raw:: latex
471
472    \normalsize
473
474.. note::
475
476    Do not confuse ``V4L2_PIX_FMT_Y41P`` with
477    :ref:`V4L2_PIX_FMT_YUV411P <V4L2-PIX-FMT-YUV411P>`. Y41P is derived from
478    "YUV 4:1:1 **packed**", while YUV411P stands for "YUV 4:1:1 **planar**".
479
480**Color Sample Location:**
481Chroma samples are :ref:`interstitially sited<yuv-chroma-centered>`
482horizontally.
483