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/userspace-api/media/fdl-appendix.rst.
7..
8.. TODO: replace it to GFDL-1.1-or-later WITH no-invariant-sections
9
10**********************
11Standard Image Formats
12**********************
13
14In order to exchange images between drivers and applications, it is
15necessary to have standard image data formats which both sides will
16interpret the same way. V4L2 includes several such formats, and this
17section is intended to be an unambiguous specification of the standard
18image data formats in V4L2.
19
20V4L2 drivers are not limited to these formats, however. Driver-specific
21formats are possible. In that case the application may depend on a codec
22to convert images to one of the standard formats when needed. But the
23data can still be stored and retrieved in the proprietary format. For
24example, a device may support a proprietary compressed format.
25Applications can still capture and save the data in the compressed
26format, saving much disk space, and later use a codec to convert the
27images to the X Windows screen format when the video is to be displayed.
28
29Even so, ultimately, some standard formats are needed, so the V4L2
30specification would not be complete without well-defined standard
31formats.
32
33The V4L2 standard formats are mainly uncompressed formats. The pixels
34are always arranged in memory from left to right, and from top to
35bottom. The first byte of data in the image buffer is always for the
36leftmost pixel of the topmost row. Following that is the pixel
37immediately to its right, and so on until the end of the top row of
38pixels. Following the rightmost pixel of the row there may be zero or
39more bytes of padding to guarantee that each row of pixel data has a
40certain alignment. Following the pad bytes, if any, is data for the
41leftmost pixel of the second row from the top, and so on. The last row
42has just as many pad bytes after it as the other rows.
43
44In V4L2 each format has an identifier which looks like ``PIX_FMT_XXX``,
45defined in the :ref:`videodev2.h <videodev>` header file. These
46identifiers represent
47:ref:`four character (FourCC) codes <v4l2-fourcc>` which are also
48listed below, however they are not the same as those used in the Windows
49world.
50
51For some formats, data is stored in separate, discontiguous memory
52buffers. Those formats are identified by a separate set of FourCC codes
53and are referred to as "multi-planar formats". For example, a
54:ref:`YUV422 <V4L2-PIX-FMT-YUV422M>` frame is normally stored in one
55memory buffer, but it can also be placed in two or three separate
56buffers, with Y component in one buffer and CbCr components in another
57in the 2-planar version or with each component in its own buffer in the
583-planar case. Those sub-buffers are referred to as "*planes*".
59