162306a36Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci**********************
462306a36Sopenharmony_ciStandard Image Formats
562306a36Sopenharmony_ci**********************
662306a36Sopenharmony_ci
762306a36Sopenharmony_ciIn order to exchange images between drivers and applications, it is
862306a36Sopenharmony_cinecessary to have standard image data formats which both sides will
962306a36Sopenharmony_ciinterpret the same way. V4L2 includes several such formats, and this
1062306a36Sopenharmony_cisection is intended to be an unambiguous specification of the standard
1162306a36Sopenharmony_ciimage data formats in V4L2.
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ciV4L2 drivers are not limited to these formats, however. Driver-specific
1462306a36Sopenharmony_ciformats are possible. In that case the application may depend on a codec
1562306a36Sopenharmony_cito convert images to one of the standard formats when needed. But the
1662306a36Sopenharmony_cidata can still be stored and retrieved in the proprietary format. For
1762306a36Sopenharmony_ciexample, a device may support a proprietary compressed format.
1862306a36Sopenharmony_ciApplications can still capture and save the data in the compressed
1962306a36Sopenharmony_ciformat, saving much disk space, and later use a codec to convert the
2062306a36Sopenharmony_ciimages to the X Windows screen format when the video is to be displayed.
2162306a36Sopenharmony_ci
2262306a36Sopenharmony_ciEven so, ultimately, some standard formats are needed, so the V4L2
2362306a36Sopenharmony_cispecification would not be complete without well-defined standard
2462306a36Sopenharmony_ciformats.
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ciThe V4L2 standard formats are mainly uncompressed formats. The pixels
2762306a36Sopenharmony_ciare always arranged in memory from left to right, and from top to
2862306a36Sopenharmony_cibottom. The first byte of data in the image buffer is always for the
2962306a36Sopenharmony_cileftmost pixel of the topmost row. Following that is the pixel
3062306a36Sopenharmony_ciimmediately to its right, and so on until the end of the top row of
3162306a36Sopenharmony_cipixels. Following the rightmost pixel of the row there may be zero or
3262306a36Sopenharmony_cimore bytes of padding to guarantee that each row of pixel data has a
3362306a36Sopenharmony_cicertain alignment. Following the pad bytes, if any, is data for the
3462306a36Sopenharmony_cileftmost pixel of the second row from the top, and so on. The last row
3562306a36Sopenharmony_cihas just as many pad bytes after it as the other rows.
3662306a36Sopenharmony_ci
3762306a36Sopenharmony_ciIn V4L2 each format has an identifier which looks like ``PIX_FMT_XXX``,
3862306a36Sopenharmony_cidefined in the :ref:`videodev2.h <videodev>` header file. These
3962306a36Sopenharmony_ciidentifiers represent
4062306a36Sopenharmony_ci:ref:`four character (FourCC) codes <v4l2-fourcc>` which are also
4162306a36Sopenharmony_cilisted below, however they are not the same as those used in the Windows
4262306a36Sopenharmony_ciworld.
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ciFor some formats, data is stored in separate, discontiguous memory
4562306a36Sopenharmony_cibuffers. Those formats are identified by a separate set of FourCC codes
4662306a36Sopenharmony_ciand are referred to as "multi-planar formats". For example, a
4762306a36Sopenharmony_ci:ref:`YUV422 <V4L2-PIX-FMT-YUV422M>` frame is normally stored in one
4862306a36Sopenharmony_cimemory buffer, but it can also be placed in two or three separate
4962306a36Sopenharmony_cibuffers, with Y component in one buffer and CbCr components in another
5062306a36Sopenharmony_ciin the 2-planar version or with each component in its own buffer in the
5162306a36Sopenharmony_ci3-planar case. Those sub-buffers are referred to as "*planes*".
52