18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci******************************
48c2ecf20Sopenharmony_ciSingle-planar format structure
58c2ecf20Sopenharmony_ci******************************
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci.. tabularcolumns:: |p{4.0cm}|p{2.5cm}|p{11.0cm}|
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci.. c:type:: v4l2_pix_format
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ci.. cssclass:: longtable
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci.. flat-table:: struct v4l2_pix_format
148c2ecf20Sopenharmony_ci    :header-rows:  0
158c2ecf20Sopenharmony_ci    :stub-columns: 0
168c2ecf20Sopenharmony_ci    :widths:       1 1 2
178c2ecf20Sopenharmony_ci
188c2ecf20Sopenharmony_ci    * - __u32
198c2ecf20Sopenharmony_ci      - ``width``
208c2ecf20Sopenharmony_ci      - Image width in pixels.
218c2ecf20Sopenharmony_ci    * - __u32
228c2ecf20Sopenharmony_ci      - ``height``
238c2ecf20Sopenharmony_ci      - Image height in pixels. If ``field`` is one of ``V4L2_FIELD_TOP``,
248c2ecf20Sopenharmony_ci	``V4L2_FIELD_BOTTOM`` or ``V4L2_FIELD_ALTERNATE`` then height
258c2ecf20Sopenharmony_ci	refers to the number of lines in the field, otherwise it refers to
268c2ecf20Sopenharmony_ci	the number of lines in the frame (which is twice the field height
278c2ecf20Sopenharmony_ci	for interlaced formats).
288c2ecf20Sopenharmony_ci    * - :cspan:`2` Applications set these fields to request an image
298c2ecf20Sopenharmony_ci	size, drivers return the closest possible values. In case of
308c2ecf20Sopenharmony_ci	planar formats the ``width`` and ``height`` applies to the largest
318c2ecf20Sopenharmony_ci	plane. To avoid ambiguities drivers must return values rounded up
328c2ecf20Sopenharmony_ci	to a multiple of the scale factor of any smaller planes. For
338c2ecf20Sopenharmony_ci	example when the image format is YUV 4:2:0, ``width`` and
348c2ecf20Sopenharmony_ci	``height`` must be multiples of two.
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci	For compressed formats that contain the resolution information encoded
378c2ecf20Sopenharmony_ci	inside the stream, when fed to a stateful mem2mem decoder, the fields
388c2ecf20Sopenharmony_ci	may be zero to rely on the decoder to detect the right values. For more
398c2ecf20Sopenharmony_ci	details see :ref:`decoder` and format descriptions.
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci	For compressed formats on the CAPTURE side of a stateful mem2mem
428c2ecf20Sopenharmony_ci	encoder, the fields must be zero, since the coded size is expected to
438c2ecf20Sopenharmony_ci	be calculated internally by the encoder itself, based on the OUTPUT
448c2ecf20Sopenharmony_ci	side. For more details see :ref:`encoder` and format descriptions.
458c2ecf20Sopenharmony_ci    * - __u32
468c2ecf20Sopenharmony_ci      - ``pixelformat``
478c2ecf20Sopenharmony_ci      - The pixel format or type of compression, set by the application.
488c2ecf20Sopenharmony_ci	This is a little endian
498c2ecf20Sopenharmony_ci	:ref:`four character code <v4l2-fourcc>`. V4L2 defines standard
508c2ecf20Sopenharmony_ci	RGB formats in :ref:`pixfmt-rgb`, YUV formats in
518c2ecf20Sopenharmony_ci	:ref:`yuv-formats`, and reserved codes in
528c2ecf20Sopenharmony_ci	:ref:`reserved-formats`
538c2ecf20Sopenharmony_ci    * - __u32
548c2ecf20Sopenharmony_ci      - ``field``
558c2ecf20Sopenharmony_ci      - Field order, from enum :c:type:`v4l2_field`.
568c2ecf20Sopenharmony_ci        Video images are typically interlaced. Applications can request to
578c2ecf20Sopenharmony_ci	capture or output only the top or bottom field, or both fields
588c2ecf20Sopenharmony_ci	interlaced or sequentially stored in one buffer or alternating in
598c2ecf20Sopenharmony_ci	separate buffers. Drivers return the actual field order selected.
608c2ecf20Sopenharmony_ci	For more details on fields see :ref:`field-order`.
618c2ecf20Sopenharmony_ci    * - __u32
628c2ecf20Sopenharmony_ci      - ``bytesperline``
638c2ecf20Sopenharmony_ci      - Distance in bytes between the leftmost pixels in two adjacent
648c2ecf20Sopenharmony_ci	lines.
658c2ecf20Sopenharmony_ci    * - :cspan:`2`
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci	Both applications and drivers can set this field to request
688c2ecf20Sopenharmony_ci	padding bytes at the end of each line. Drivers however may ignore
698c2ecf20Sopenharmony_ci	the value requested by the application, returning ``width`` times
708c2ecf20Sopenharmony_ci	bytes per pixel or a larger value required by the hardware. That
718c2ecf20Sopenharmony_ci	implies applications can just set this field to zero to get a
728c2ecf20Sopenharmony_ci	reasonable default.
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci	Video hardware may access padding bytes, therefore they must
758c2ecf20Sopenharmony_ci	reside in accessible memory. Consider cases where padding bytes
768c2ecf20Sopenharmony_ci	after the last line of an image cross a system page boundary.
778c2ecf20Sopenharmony_ci	Input devices may write padding bytes, the value is undefined.
788c2ecf20Sopenharmony_ci	Output devices ignore the contents of padding bytes.
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_ci	When the image format is planar the ``bytesperline`` value applies
818c2ecf20Sopenharmony_ci	to the first plane and is divided by the same factor as the
828c2ecf20Sopenharmony_ci	``width`` field for the other planes. For example the Cb and Cr
838c2ecf20Sopenharmony_ci	planes of a YUV 4:2:0 image have half as many padding bytes
848c2ecf20Sopenharmony_ci	following each line as the Y plane. To avoid ambiguities drivers
858c2ecf20Sopenharmony_ci	must return a ``bytesperline`` value rounded up to a multiple of
868c2ecf20Sopenharmony_ci	the scale factor.
878c2ecf20Sopenharmony_ci
888c2ecf20Sopenharmony_ci	For compressed formats the ``bytesperline`` value makes no sense.
898c2ecf20Sopenharmony_ci	Applications and drivers must set this to 0 in that case.
908c2ecf20Sopenharmony_ci    * - __u32
918c2ecf20Sopenharmony_ci      - ``sizeimage``
928c2ecf20Sopenharmony_ci      - Size in bytes of the buffer to hold a complete image, set by the
938c2ecf20Sopenharmony_ci	driver. Usually this is ``bytesperline`` times ``height``. When
948c2ecf20Sopenharmony_ci	the image consists of variable length compressed data this is the
958c2ecf20Sopenharmony_ci	number of bytes required by the codec to support the worst-case
968c2ecf20Sopenharmony_ci	compression scenario.
978c2ecf20Sopenharmony_ci
988c2ecf20Sopenharmony_ci	The driver will set the value for uncompressed images.
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_ci	Clients are allowed to set the sizeimage field for variable length
1018c2ecf20Sopenharmony_ci	compressed data flagged with ``V4L2_FMT_FLAG_COMPRESSED`` at
1028c2ecf20Sopenharmony_ci	:ref:`VIDIOC_ENUM_FMT`, but the driver may ignore it and set the
1038c2ecf20Sopenharmony_ci	value itself, or it may modify the provided value based on
1048c2ecf20Sopenharmony_ci	alignment requirements or minimum/maximum size requirements.
1058c2ecf20Sopenharmony_ci	If the client wants to leave this to the driver, then it should
1068c2ecf20Sopenharmony_ci	set sizeimage to 0.
1078c2ecf20Sopenharmony_ci    * - __u32
1088c2ecf20Sopenharmony_ci      - ``colorspace``
1098c2ecf20Sopenharmony_ci      - Image colorspace, from enum :c:type:`v4l2_colorspace`.
1108c2ecf20Sopenharmony_ci        This information supplements the ``pixelformat`` and must be set
1118c2ecf20Sopenharmony_ci	by the driver for capture streams and by the application for
1128c2ecf20Sopenharmony_ci	output streams, see :ref:`colorspaces`. If the application sets the
1138c2ecf20Sopenharmony_ci	flag ``V4L2_PIX_FMT_FLAG_SET_CSC`` then the application can set
1148c2ecf20Sopenharmony_ci	this field for a capture stream to request a specific colorspace
1158c2ecf20Sopenharmony_ci	for the captured image data. If the driver cannot handle requested
1168c2ecf20Sopenharmony_ci	conversion, it will return another supported colorspace.
1178c2ecf20Sopenharmony_ci	The driver indicates that colorspace conversion is supported by setting
1188c2ecf20Sopenharmony_ci	the flag V4L2_FMT_FLAG_CSC_COLORSPACE in the corresponding struct
1198c2ecf20Sopenharmony_ci	:c:type:`v4l2_fmtdesc` during enumeration. See :ref:`fmtdesc-flags`.
1208c2ecf20Sopenharmony_ci    * - __u32
1218c2ecf20Sopenharmony_ci      - ``priv``
1228c2ecf20Sopenharmony_ci      - This field indicates whether the remaining fields of the
1238c2ecf20Sopenharmony_ci	struct :c:type:`v4l2_pix_format`, also called the
1248c2ecf20Sopenharmony_ci	extended fields, are valid. When set to
1258c2ecf20Sopenharmony_ci	``V4L2_PIX_FMT_PRIV_MAGIC``, it indicates that the extended fields
1268c2ecf20Sopenharmony_ci	have been correctly initialized. When set to any other value it
1278c2ecf20Sopenharmony_ci	indicates that the extended fields contain undefined values.
1288c2ecf20Sopenharmony_ci
1298c2ecf20Sopenharmony_ci	Applications that wish to use the pixel format extended fields
1308c2ecf20Sopenharmony_ci	must first ensure that the feature is supported by querying the
1318c2ecf20Sopenharmony_ci	device for the :ref:`V4L2_CAP_EXT_PIX_FORMAT <querycap>`
1328c2ecf20Sopenharmony_ci	capability. If the capability isn't set the pixel format extended
1338c2ecf20Sopenharmony_ci	fields are not supported and using the extended fields will lead
1348c2ecf20Sopenharmony_ci	to undefined results.
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci	To use the extended fields, applications must set the ``priv``
1378c2ecf20Sopenharmony_ci	field to ``V4L2_PIX_FMT_PRIV_MAGIC``, initialize all the extended
1388c2ecf20Sopenharmony_ci	fields and zero the unused bytes of the
1398c2ecf20Sopenharmony_ci	struct :c:type:`v4l2_format` ``raw_data`` field.
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ci	When the ``priv`` field isn't set to ``V4L2_PIX_FMT_PRIV_MAGIC``
1428c2ecf20Sopenharmony_ci	drivers must act as if all the extended fields were set to zero.
1438c2ecf20Sopenharmony_ci	On return drivers must set the ``priv`` field to
1448c2ecf20Sopenharmony_ci	``V4L2_PIX_FMT_PRIV_MAGIC`` and all the extended fields to
1458c2ecf20Sopenharmony_ci	applicable values.
1468c2ecf20Sopenharmony_ci    * - __u32
1478c2ecf20Sopenharmony_ci      - ``flags``
1488c2ecf20Sopenharmony_ci      - Flags set by the application or driver, see :ref:`format-flags`.
1498c2ecf20Sopenharmony_ci    * - union {
1508c2ecf20Sopenharmony_ci      - (anonymous)
1518c2ecf20Sopenharmony_ci    * - __u32
1528c2ecf20Sopenharmony_ci      - ``ycbcr_enc``
1538c2ecf20Sopenharmony_ci      - Y'CbCr encoding, from enum :c:type:`v4l2_ycbcr_encoding`.
1548c2ecf20Sopenharmony_ci        This information supplements the ``colorspace`` and must be set by
1558c2ecf20Sopenharmony_ci	the driver for capture streams and by the application for output
1568c2ecf20Sopenharmony_ci	streams, see :ref:`colorspaces`. If the application sets the
1578c2ecf20Sopenharmony_ci	flag ``V4L2_PIX_FMT_FLAG_SET_CSC`` then the application can set
1588c2ecf20Sopenharmony_ci	this field for a capture stream to request a specific Y'CbCr encoding
1598c2ecf20Sopenharmony_ci	for the captured image data. If the driver cannot handle requested
1608c2ecf20Sopenharmony_ci	conversion, it will return another supported encoding.
1618c2ecf20Sopenharmony_ci	This field is ignored for HSV pixelformats. The driver indicates that
1628c2ecf20Sopenharmony_ci	ycbcr_enc conversion is supported by setting the flag
1638c2ecf20Sopenharmony_ci	V4L2_FMT_FLAG_CSC_YCBCR_ENC in the corresponding struct
1648c2ecf20Sopenharmony_ci	:c:type:`v4l2_fmtdesc` during enumeration. See :ref:`fmtdesc-flags`.
1658c2ecf20Sopenharmony_ci    * - __u32
1668c2ecf20Sopenharmony_ci      - ``hsv_enc``
1678c2ecf20Sopenharmony_ci      - HSV encoding, from enum :c:type:`v4l2_hsv_encoding`.
1688c2ecf20Sopenharmony_ci        This information supplements the ``colorspace`` and must be set by
1698c2ecf20Sopenharmony_ci	the driver for capture streams and by the application for output
1708c2ecf20Sopenharmony_ci	streams, see :ref:`colorspaces`. If the application sets the flag
1718c2ecf20Sopenharmony_ci	``V4L2_PIX_FMT_FLAG_SET_CSC`` then the application can set this
1728c2ecf20Sopenharmony_ci	field for a capture stream to request a specific HSV encoding for the
1738c2ecf20Sopenharmony_ci	captured image data. If the driver cannot handle requested
1748c2ecf20Sopenharmony_ci	conversion, it will return another supported encoding.
1758c2ecf20Sopenharmony_ci	This field is ignored for non-HSV pixelformats. The driver indicates
1768c2ecf20Sopenharmony_ci	that hsv_enc conversion is supported by setting the flag
1778c2ecf20Sopenharmony_ci	V4L2_FMT_FLAG_CSC_HSV_ENC in the corresponding struct
1788c2ecf20Sopenharmony_ci	:c:type:`v4l2_fmtdesc` during enumeration. See :ref:`fmtdesc-flags`.
1798c2ecf20Sopenharmony_ci    * - }
1808c2ecf20Sopenharmony_ci      -
1818c2ecf20Sopenharmony_ci    * - __u32
1828c2ecf20Sopenharmony_ci      - ``quantization``
1838c2ecf20Sopenharmony_ci      - Quantization range, from enum :c:type:`v4l2_quantization`.
1848c2ecf20Sopenharmony_ci        This information supplements the ``colorspace`` and must be set by
1858c2ecf20Sopenharmony_ci	the driver for capture streams and by the application for output
1868c2ecf20Sopenharmony_ci	streams, see :ref:`colorspaces`. If the application sets the flag
1878c2ecf20Sopenharmony_ci	``V4L2_PIX_FMT_FLAG_SET_CSC`` then the application can set
1888c2ecf20Sopenharmony_ci	this field for a capture stream to request a specific quantization
1898c2ecf20Sopenharmony_ci	range for the captured image data. If the driver cannot handle requested
1908c2ecf20Sopenharmony_ci	conversion, it will return another supported quantization.
1918c2ecf20Sopenharmony_ci	The driver indicates that quantization conversion is supported by setting
1928c2ecf20Sopenharmony_ci	the flag V4L2_FMT_FLAG_CSC_QUANTIZATION in the corresponding struct
1938c2ecf20Sopenharmony_ci	:c:type:`v4l2_fmtdesc` during enumeration. See :ref:`fmtdesc-flags`.
1948c2ecf20Sopenharmony_ci    * - __u32
1958c2ecf20Sopenharmony_ci      - ``xfer_func``
1968c2ecf20Sopenharmony_ci      - Transfer function, from enum :c:type:`v4l2_xfer_func`.
1978c2ecf20Sopenharmony_ci        This information supplements the ``colorspace`` and must be set by
1988c2ecf20Sopenharmony_ci	the driver for capture streams and by the application for output
1998c2ecf20Sopenharmony_ci	streams, see :ref:`colorspaces`. If the application sets the flag
2008c2ecf20Sopenharmony_ci	``V4L2_PIX_FMT_FLAG_SET_CSC`` then the application can set
2018c2ecf20Sopenharmony_ci	this field for a capture stream to request a specific transfer function
2028c2ecf20Sopenharmony_ci	for the captured image data. If the driver cannot handle requested
2038c2ecf20Sopenharmony_ci	conversion, it will return another supported transfer function.
2048c2ecf20Sopenharmony_ci	The driver indicates that xfer_func conversion is supported by setting
2058c2ecf20Sopenharmony_ci	the flag V4L2_FMT_FLAG_CSC_XFER_FUNC in the corresponding struct
2068c2ecf20Sopenharmony_ci	:c:type:`v4l2_fmtdesc` during enumeration. See :ref:`fmtdesc-flags`.
2078c2ecf20Sopenharmony_ci
2088c2ecf20Sopenharmony_ci.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
2098c2ecf20Sopenharmony_ci
2108c2ecf20Sopenharmony_ci.. _format-flags:
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_ci.. flat-table:: Format Flags
2138c2ecf20Sopenharmony_ci    :header-rows:  0
2148c2ecf20Sopenharmony_ci    :stub-columns: 0
2158c2ecf20Sopenharmony_ci    :widths:       3 1 4
2168c2ecf20Sopenharmony_ci
2178c2ecf20Sopenharmony_ci    * - ``V4L2_PIX_FMT_FLAG_PREMUL_ALPHA``
2188c2ecf20Sopenharmony_ci      - 0x00000001
2198c2ecf20Sopenharmony_ci      - The color values are premultiplied by the alpha channel value. For
2208c2ecf20Sopenharmony_ci        example, if a light blue pixel with 50% transparency was described
2218c2ecf20Sopenharmony_ci	by RGBA values (128, 192, 255, 128), the same pixel described with
2228c2ecf20Sopenharmony_ci	premultiplied colors would be described by RGBA values (64, 96,
2238c2ecf20Sopenharmony_ci	128, 128)
2248c2ecf20Sopenharmony_ci    * .. _`v4l2-pix-fmt-flag-set-csc`:
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ci      - ``V4L2_PIX_FMT_FLAG_SET_CSC``
2278c2ecf20Sopenharmony_ci      - 0x00000002
2288c2ecf20Sopenharmony_ci      - Set by the application. It is only used for capture and is
2298c2ecf20Sopenharmony_ci        ignored for output streams. If set, then request the device to do
2308c2ecf20Sopenharmony_ci	colorspace conversion from the received colorspace to the requested
2318c2ecf20Sopenharmony_ci	colorspace values. If the colorimetry field (``colorspace``, ``xfer_func``,
2328c2ecf20Sopenharmony_ci	``ycbcr_enc``, ``hsv_enc`` or ``quantization``) is set to ``*_DEFAULT``,
2338c2ecf20Sopenharmony_ci	then that colorimetry setting will remain unchanged from what was received.
2348c2ecf20Sopenharmony_ci	So in order to change the quantization, only the ``quantization`` field shall
2358c2ecf20Sopenharmony_ci	be set to non default value (``V4L2_QUANTIZATION_FULL_RANGE`` or
2368c2ecf20Sopenharmony_ci	``V4L2_QUANTIZATION_LIM_RANGE``) and all other colorimetry fields shall
2378c2ecf20Sopenharmony_ci	be set to ``*_DEFAULT``.
2388c2ecf20Sopenharmony_ci
2398c2ecf20Sopenharmony_ci	To check which conversions are supported by the hardware for the current
2408c2ecf20Sopenharmony_ci	pixel format, see :ref:`fmtdesc-flags`.
241