162306a36Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci******************************
462306a36Sopenharmony_ciSingle-planar format structure
562306a36Sopenharmony_ci******************************
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci.. tabularcolumns:: |p{4.0cm}|p{2.6cm}|p{10.7cm}|
862306a36Sopenharmony_ci
962306a36Sopenharmony_ci.. c:type:: v4l2_pix_format
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci.. cssclass:: longtable
1262306a36Sopenharmony_ci
1362306a36Sopenharmony_ci.. flat-table:: struct v4l2_pix_format
1462306a36Sopenharmony_ci    :header-rows:  0
1562306a36Sopenharmony_ci    :stub-columns: 0
1662306a36Sopenharmony_ci    :widths:       1 1 2
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ci    * - __u32
1962306a36Sopenharmony_ci      - ``width``
2062306a36Sopenharmony_ci      - Image width in pixels.
2162306a36Sopenharmony_ci    * - __u32
2262306a36Sopenharmony_ci      - ``height``
2362306a36Sopenharmony_ci      - Image height in pixels. If ``field`` is one of ``V4L2_FIELD_TOP``,
2462306a36Sopenharmony_ci	``V4L2_FIELD_BOTTOM`` or ``V4L2_FIELD_ALTERNATE`` then height
2562306a36Sopenharmony_ci	refers to the number of lines in the field, otherwise it refers to
2662306a36Sopenharmony_ci	the number of lines in the frame (which is twice the field height
2762306a36Sopenharmony_ci	for interlaced formats).
2862306a36Sopenharmony_ci    * - :cspan:`2` Applications set these fields to request an image
2962306a36Sopenharmony_ci	size, drivers return the closest possible values. In case of
3062306a36Sopenharmony_ci	planar formats the ``width`` and ``height`` applies to the largest
3162306a36Sopenharmony_ci	plane. To avoid ambiguities drivers must return values rounded up
3262306a36Sopenharmony_ci	to a multiple of the scale factor of any smaller planes. For
3362306a36Sopenharmony_ci	example when the image format is YUV 4:2:0, ``width`` and
3462306a36Sopenharmony_ci	``height`` must be multiples of two.
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ci	For compressed formats that contain the resolution information encoded
3762306a36Sopenharmony_ci	inside the stream, when fed to a stateful mem2mem decoder, the fields
3862306a36Sopenharmony_ci	may be zero to rely on the decoder to detect the right values. For more
3962306a36Sopenharmony_ci	details see :ref:`decoder` and format descriptions.
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci	For compressed formats on the CAPTURE side of a stateful mem2mem
4262306a36Sopenharmony_ci	encoder, the fields must be zero, since the coded size is expected to
4362306a36Sopenharmony_ci	be calculated internally by the encoder itself, based on the OUTPUT
4462306a36Sopenharmony_ci	side. For more details see :ref:`encoder` and format descriptions.
4562306a36Sopenharmony_ci    * - __u32
4662306a36Sopenharmony_ci      - ``pixelformat``
4762306a36Sopenharmony_ci      - The pixel format or type of compression, set by the application.
4862306a36Sopenharmony_ci	This is a little endian
4962306a36Sopenharmony_ci	:ref:`four character code <v4l2-fourcc>`. V4L2 defines standard
5062306a36Sopenharmony_ci	RGB formats in :ref:`pixfmt-rgb`, YUV formats in
5162306a36Sopenharmony_ci	:ref:`yuv-formats`, and reserved codes in
5262306a36Sopenharmony_ci	:ref:`reserved-formats`
5362306a36Sopenharmony_ci    * - __u32
5462306a36Sopenharmony_ci      - ``field``
5562306a36Sopenharmony_ci      - Field order, from enum :c:type:`v4l2_field`.
5662306a36Sopenharmony_ci        Video images are typically interlaced. Applications can request to
5762306a36Sopenharmony_ci	capture or output only the top or bottom field, or both fields
5862306a36Sopenharmony_ci	interlaced or sequentially stored in one buffer or alternating in
5962306a36Sopenharmony_ci	separate buffers. Drivers return the actual field order selected.
6062306a36Sopenharmony_ci	For more details on fields see :ref:`field-order`.
6162306a36Sopenharmony_ci    * - __u32
6262306a36Sopenharmony_ci      - ``bytesperline``
6362306a36Sopenharmony_ci      - Distance in bytes between the leftmost pixels in two adjacent
6462306a36Sopenharmony_ci	lines.
6562306a36Sopenharmony_ci    * - :cspan:`2`
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci	Both applications and drivers can set this field to request
6862306a36Sopenharmony_ci	padding bytes at the end of each line. Drivers however may ignore
6962306a36Sopenharmony_ci	the value requested by the application, returning ``width`` times
7062306a36Sopenharmony_ci	bytes per pixel or a larger value required by the hardware. That
7162306a36Sopenharmony_ci	implies applications can just set this field to zero to get a
7262306a36Sopenharmony_ci	reasonable default.
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci	Video hardware may access padding bytes, therefore they must
7562306a36Sopenharmony_ci	reside in accessible memory. Consider cases where padding bytes
7662306a36Sopenharmony_ci	after the last line of an image cross a system page boundary.
7762306a36Sopenharmony_ci	Input devices may write padding bytes, the value is undefined.
7862306a36Sopenharmony_ci	Output devices ignore the contents of padding bytes.
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci	When the image format is planar the ``bytesperline`` value applies
8162306a36Sopenharmony_ci	to the first plane and is divided by the same factor as the
8262306a36Sopenharmony_ci	``width`` field for the other planes. For example the Cb and Cr
8362306a36Sopenharmony_ci	planes of a YUV 4:2:0 image have half as many padding bytes
8462306a36Sopenharmony_ci	following each line as the Y plane. To avoid ambiguities drivers
8562306a36Sopenharmony_ci	must return a ``bytesperline`` value rounded up to a multiple of
8662306a36Sopenharmony_ci	the scale factor.
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci	For compressed formats the ``bytesperline`` value makes no sense.
8962306a36Sopenharmony_ci	Applications and drivers must set this to 0 in that case.
9062306a36Sopenharmony_ci    * - __u32
9162306a36Sopenharmony_ci      - ``sizeimage``
9262306a36Sopenharmony_ci      - Size in bytes of the buffer to hold a complete image, set by the
9362306a36Sopenharmony_ci	driver. Usually this is ``bytesperline`` times ``height``. When
9462306a36Sopenharmony_ci	the image consists of variable length compressed data this is the
9562306a36Sopenharmony_ci	number of bytes required by the codec to support the worst-case
9662306a36Sopenharmony_ci	compression scenario.
9762306a36Sopenharmony_ci
9862306a36Sopenharmony_ci	The driver will set the value for uncompressed images.
9962306a36Sopenharmony_ci
10062306a36Sopenharmony_ci	Clients are allowed to set the sizeimage field for variable length
10162306a36Sopenharmony_ci	compressed data flagged with ``V4L2_FMT_FLAG_COMPRESSED`` at
10262306a36Sopenharmony_ci	:ref:`VIDIOC_ENUM_FMT`, but the driver may ignore it and set the
10362306a36Sopenharmony_ci	value itself, or it may modify the provided value based on
10462306a36Sopenharmony_ci	alignment requirements or minimum/maximum size requirements.
10562306a36Sopenharmony_ci	If the client wants to leave this to the driver, then it should
10662306a36Sopenharmony_ci	set sizeimage to 0.
10762306a36Sopenharmony_ci    * - __u32
10862306a36Sopenharmony_ci      - ``colorspace``
10962306a36Sopenharmony_ci      - Image colorspace, from enum :c:type:`v4l2_colorspace`.
11062306a36Sopenharmony_ci        This information supplements the ``pixelformat`` and must be set
11162306a36Sopenharmony_ci	by the driver for capture streams and by the application for
11262306a36Sopenharmony_ci	output streams, see :ref:`colorspaces`. If the application sets the
11362306a36Sopenharmony_ci	flag ``V4L2_PIX_FMT_FLAG_SET_CSC`` then the application can set
11462306a36Sopenharmony_ci	this field for a capture stream to request a specific colorspace
11562306a36Sopenharmony_ci	for the captured image data. If the driver cannot handle requested
11662306a36Sopenharmony_ci	conversion, it will return another supported colorspace.
11762306a36Sopenharmony_ci	The driver indicates that colorspace conversion is supported by setting
11862306a36Sopenharmony_ci	the flag V4L2_FMT_FLAG_CSC_COLORSPACE in the corresponding struct
11962306a36Sopenharmony_ci	:c:type:`v4l2_fmtdesc` during enumeration. See :ref:`fmtdesc-flags`.
12062306a36Sopenharmony_ci    * - __u32
12162306a36Sopenharmony_ci      - ``priv``
12262306a36Sopenharmony_ci      - This field indicates whether the remaining fields of the
12362306a36Sopenharmony_ci	struct :c:type:`v4l2_pix_format`, also called the
12462306a36Sopenharmony_ci	extended fields, are valid. When set to
12562306a36Sopenharmony_ci	``V4L2_PIX_FMT_PRIV_MAGIC``, it indicates that the extended fields
12662306a36Sopenharmony_ci	have been correctly initialized. When set to any other value it
12762306a36Sopenharmony_ci	indicates that the extended fields contain undefined values.
12862306a36Sopenharmony_ci
12962306a36Sopenharmony_ci	Applications that wish to use the pixel format extended fields
13062306a36Sopenharmony_ci	must first ensure that the feature is supported by querying the
13162306a36Sopenharmony_ci	device for the :ref:`V4L2_CAP_EXT_PIX_FORMAT <querycap>`
13262306a36Sopenharmony_ci	capability. If the capability isn't set the pixel format extended
13362306a36Sopenharmony_ci	fields are not supported and using the extended fields will lead
13462306a36Sopenharmony_ci	to undefined results.
13562306a36Sopenharmony_ci
13662306a36Sopenharmony_ci	To use the extended fields, applications must set the ``priv``
13762306a36Sopenharmony_ci	field to ``V4L2_PIX_FMT_PRIV_MAGIC``, initialize all the extended
13862306a36Sopenharmony_ci	fields and zero the unused bytes of the
13962306a36Sopenharmony_ci	struct :c:type:`v4l2_format` ``raw_data`` field.
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_ci	When the ``priv`` field isn't set to ``V4L2_PIX_FMT_PRIV_MAGIC``
14262306a36Sopenharmony_ci	drivers must act as if all the extended fields were set to zero.
14362306a36Sopenharmony_ci	On return drivers must set the ``priv`` field to
14462306a36Sopenharmony_ci	``V4L2_PIX_FMT_PRIV_MAGIC`` and all the extended fields to
14562306a36Sopenharmony_ci	applicable values.
14662306a36Sopenharmony_ci    * - __u32
14762306a36Sopenharmony_ci      - ``flags``
14862306a36Sopenharmony_ci      - Flags set by the application or driver, see :ref:`format-flags`.
14962306a36Sopenharmony_ci    * - union {
15062306a36Sopenharmony_ci      - (anonymous)
15162306a36Sopenharmony_ci    * - __u32
15262306a36Sopenharmony_ci      - ``ycbcr_enc``
15362306a36Sopenharmony_ci      - Y'CbCr encoding, from enum :c:type:`v4l2_ycbcr_encoding`.
15462306a36Sopenharmony_ci        This information supplements the ``colorspace`` and must be set by
15562306a36Sopenharmony_ci	the driver for capture streams and by the application for output
15662306a36Sopenharmony_ci	streams, see :ref:`colorspaces`. If the application sets the
15762306a36Sopenharmony_ci	flag ``V4L2_PIX_FMT_FLAG_SET_CSC`` then the application can set
15862306a36Sopenharmony_ci	this field for a capture stream to request a specific Y'CbCr encoding
15962306a36Sopenharmony_ci	for the captured image data. If the driver cannot handle requested
16062306a36Sopenharmony_ci	conversion, it will return another supported encoding.
16162306a36Sopenharmony_ci	This field is ignored for HSV pixelformats. The driver indicates that
16262306a36Sopenharmony_ci	ycbcr_enc conversion is supported by setting the flag
16362306a36Sopenharmony_ci	V4L2_FMT_FLAG_CSC_YCBCR_ENC in the corresponding struct
16462306a36Sopenharmony_ci	:c:type:`v4l2_fmtdesc` during enumeration. See :ref:`fmtdesc-flags`.
16562306a36Sopenharmony_ci    * - __u32
16662306a36Sopenharmony_ci      - ``hsv_enc``
16762306a36Sopenharmony_ci      - HSV encoding, from enum :c:type:`v4l2_hsv_encoding`.
16862306a36Sopenharmony_ci        This information supplements the ``colorspace`` and must be set by
16962306a36Sopenharmony_ci	the driver for capture streams and by the application for output
17062306a36Sopenharmony_ci	streams, see :ref:`colorspaces`. If the application sets the flag
17162306a36Sopenharmony_ci	``V4L2_PIX_FMT_FLAG_SET_CSC`` then the application can set this
17262306a36Sopenharmony_ci	field for a capture stream to request a specific HSV encoding for the
17362306a36Sopenharmony_ci	captured image data. If the driver cannot handle requested
17462306a36Sopenharmony_ci	conversion, it will return another supported encoding.
17562306a36Sopenharmony_ci	This field is ignored for non-HSV pixelformats. The driver indicates
17662306a36Sopenharmony_ci	that hsv_enc conversion is supported by setting the flag
17762306a36Sopenharmony_ci	V4L2_FMT_FLAG_CSC_HSV_ENC in the corresponding struct
17862306a36Sopenharmony_ci	:c:type:`v4l2_fmtdesc` during enumeration. See :ref:`fmtdesc-flags`.
17962306a36Sopenharmony_ci    * - }
18062306a36Sopenharmony_ci      -
18162306a36Sopenharmony_ci    * - __u32
18262306a36Sopenharmony_ci      - ``quantization``
18362306a36Sopenharmony_ci      - Quantization range, from enum :c:type:`v4l2_quantization`.
18462306a36Sopenharmony_ci        This information supplements the ``colorspace`` and must be set by
18562306a36Sopenharmony_ci	the driver for capture streams and by the application for output
18662306a36Sopenharmony_ci	streams, see :ref:`colorspaces`. If the application sets the flag
18762306a36Sopenharmony_ci	``V4L2_PIX_FMT_FLAG_SET_CSC`` then the application can set
18862306a36Sopenharmony_ci	this field for a capture stream to request a specific quantization
18962306a36Sopenharmony_ci	range for the captured image data. If the driver cannot handle requested
19062306a36Sopenharmony_ci	conversion, it will return another supported quantization.
19162306a36Sopenharmony_ci	The driver indicates that quantization conversion is supported by setting
19262306a36Sopenharmony_ci	the flag V4L2_FMT_FLAG_CSC_QUANTIZATION in the corresponding struct
19362306a36Sopenharmony_ci	:c:type:`v4l2_fmtdesc` during enumeration. See :ref:`fmtdesc-flags`.
19462306a36Sopenharmony_ci    * - __u32
19562306a36Sopenharmony_ci      - ``xfer_func``
19662306a36Sopenharmony_ci      - Transfer function, from enum :c:type:`v4l2_xfer_func`.
19762306a36Sopenharmony_ci        This information supplements the ``colorspace`` and must be set by
19862306a36Sopenharmony_ci	the driver for capture streams and by the application for output
19962306a36Sopenharmony_ci	streams, see :ref:`colorspaces`. If the application sets the flag
20062306a36Sopenharmony_ci	``V4L2_PIX_FMT_FLAG_SET_CSC`` then the application can set
20162306a36Sopenharmony_ci	this field for a capture stream to request a specific transfer function
20262306a36Sopenharmony_ci	for the captured image data. If the driver cannot handle requested
20362306a36Sopenharmony_ci	conversion, it will return another supported transfer function.
20462306a36Sopenharmony_ci	The driver indicates that xfer_func conversion is supported by setting
20562306a36Sopenharmony_ci	the flag V4L2_FMT_FLAG_CSC_XFER_FUNC in the corresponding struct
20662306a36Sopenharmony_ci	:c:type:`v4l2_fmtdesc` during enumeration. See :ref:`fmtdesc-flags`.
20762306a36Sopenharmony_ci
20862306a36Sopenharmony_ci.. tabularcolumns:: |p{6.8cm}|p{2.3cm}|p{8.2cm}|
20962306a36Sopenharmony_ci
21062306a36Sopenharmony_ci.. _format-flags:
21162306a36Sopenharmony_ci
21262306a36Sopenharmony_ci.. flat-table:: Format Flags
21362306a36Sopenharmony_ci    :header-rows:  0
21462306a36Sopenharmony_ci    :stub-columns: 0
21562306a36Sopenharmony_ci    :widths:       3 1 4
21662306a36Sopenharmony_ci
21762306a36Sopenharmony_ci    * - ``V4L2_PIX_FMT_FLAG_PREMUL_ALPHA``
21862306a36Sopenharmony_ci      - 0x00000001
21962306a36Sopenharmony_ci      - The color values are premultiplied by the alpha channel value. For
22062306a36Sopenharmony_ci        example, if a light blue pixel with 50% transparency was described
22162306a36Sopenharmony_ci	by RGBA values (128, 192, 255, 128), the same pixel described with
22262306a36Sopenharmony_ci	premultiplied colors would be described by RGBA values (64, 96,
22362306a36Sopenharmony_ci	128, 128)
22462306a36Sopenharmony_ci    * .. _`v4l2-pix-fmt-flag-set-csc`:
22562306a36Sopenharmony_ci
22662306a36Sopenharmony_ci      - ``V4L2_PIX_FMT_FLAG_SET_CSC``
22762306a36Sopenharmony_ci      - 0x00000002
22862306a36Sopenharmony_ci      - Set by the application. It is only used for capture and is
22962306a36Sopenharmony_ci        ignored for output streams. If set, then request the device to do
23062306a36Sopenharmony_ci	colorspace conversion from the received colorspace to the requested
23162306a36Sopenharmony_ci	colorspace values. If the colorimetry field (``colorspace``, ``xfer_func``,
23262306a36Sopenharmony_ci	``ycbcr_enc``, ``hsv_enc`` or ``quantization``) is set to ``*_DEFAULT``,
23362306a36Sopenharmony_ci	then that colorimetry setting will remain unchanged from what was received.
23462306a36Sopenharmony_ci	So in order to change the quantization, only the ``quantization`` field shall
23562306a36Sopenharmony_ci	be set to non default value (``V4L2_QUANTIZATION_FULL_RANGE`` or
23662306a36Sopenharmony_ci	``V4L2_QUANTIZATION_LIM_RANGE``) and all other colorimetry fields shall
23762306a36Sopenharmony_ci	be set to ``*_DEFAULT``.
23862306a36Sopenharmony_ci
23962306a36Sopenharmony_ci	To check which conversions are supported by the hardware for the current
24062306a36Sopenharmony_ci	pixel format, see :ref:`fmtdesc-flags`.
241