1059b1c5bSMauro Carvalho Chehab.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 254f38fcaSMauro Carvalho Chehab 354f38fcaSMauro Carvalho Chehab****************************** 454f38fcaSMauro Carvalho ChehabSingle-planar format structure 554f38fcaSMauro Carvalho Chehab****************************** 654f38fcaSMauro Carvalho Chehab 7*fea13a69SMauro Carvalho Chehab.. tabularcolumns:: |p{4.0cm}|p{2.6cm}|p{10.7cm}| 854f38fcaSMauro Carvalho Chehab 954f38fcaSMauro Carvalho Chehab.. c:type:: v4l2_pix_format 1054f38fcaSMauro Carvalho Chehab 1154f38fcaSMauro Carvalho Chehab.. cssclass:: longtable 1254f38fcaSMauro Carvalho Chehab 1354f38fcaSMauro Carvalho Chehab.. flat-table:: struct v4l2_pix_format 1454f38fcaSMauro Carvalho Chehab :header-rows: 0 1554f38fcaSMauro Carvalho Chehab :stub-columns: 0 1654f38fcaSMauro Carvalho Chehab :widths: 1 1 2 1754f38fcaSMauro Carvalho Chehab 1854f38fcaSMauro Carvalho Chehab * - __u32 1954f38fcaSMauro Carvalho Chehab - ``width`` 2054f38fcaSMauro Carvalho Chehab - Image width in pixels. 2154f38fcaSMauro Carvalho Chehab * - __u32 2254f38fcaSMauro Carvalho Chehab - ``height`` 2354f38fcaSMauro Carvalho Chehab - Image height in pixels. If ``field`` is one of ``V4L2_FIELD_TOP``, 2454f38fcaSMauro Carvalho Chehab ``V4L2_FIELD_BOTTOM`` or ``V4L2_FIELD_ALTERNATE`` then height 2554f38fcaSMauro Carvalho Chehab refers to the number of lines in the field, otherwise it refers to 2654f38fcaSMauro Carvalho Chehab the number of lines in the frame (which is twice the field height 2754f38fcaSMauro Carvalho Chehab for interlaced formats). 2854f38fcaSMauro Carvalho Chehab * - :cspan:`2` Applications set these fields to request an image 2954f38fcaSMauro Carvalho Chehab size, drivers return the closest possible values. In case of 3054f38fcaSMauro Carvalho Chehab planar formats the ``width`` and ``height`` applies to the largest 3154f38fcaSMauro Carvalho Chehab plane. To avoid ambiguities drivers must return values rounded up 3254f38fcaSMauro Carvalho Chehab to a multiple of the scale factor of any smaller planes. For 3354f38fcaSMauro Carvalho Chehab example when the image format is YUV 4:2:0, ``width`` and 3454f38fcaSMauro Carvalho Chehab ``height`` must be multiples of two. 3554f38fcaSMauro Carvalho Chehab 3654f38fcaSMauro Carvalho Chehab For compressed formats that contain the resolution information encoded 3754f38fcaSMauro Carvalho Chehab inside the stream, when fed to a stateful mem2mem decoder, the fields 3854f38fcaSMauro Carvalho Chehab may be zero to rely on the decoder to detect the right values. For more 3954f38fcaSMauro Carvalho Chehab details see :ref:`decoder` and format descriptions. 409ec656cfSTomasz Figa 419ec656cfSTomasz Figa For compressed formats on the CAPTURE side of a stateful mem2mem 429ec656cfSTomasz Figa encoder, the fields must be zero, since the coded size is expected to 439ec656cfSTomasz Figa be calculated internally by the encoder itself, based on the OUTPUT 449ec656cfSTomasz Figa side. For more details see :ref:`encoder` and format descriptions. 4554f38fcaSMauro Carvalho Chehab * - __u32 4654f38fcaSMauro Carvalho Chehab - ``pixelformat`` 4754f38fcaSMauro Carvalho Chehab - The pixel format or type of compression, set by the application. 4854f38fcaSMauro Carvalho Chehab This is a little endian 4954f38fcaSMauro Carvalho Chehab :ref:`four character code <v4l2-fourcc>`. V4L2 defines standard 5054f38fcaSMauro Carvalho Chehab RGB formats in :ref:`pixfmt-rgb`, YUV formats in 5154f38fcaSMauro Carvalho Chehab :ref:`yuv-formats`, and reserved codes in 5254f38fcaSMauro Carvalho Chehab :ref:`reserved-formats` 5354f38fcaSMauro Carvalho Chehab * - __u32 5454f38fcaSMauro Carvalho Chehab - ``field`` 5554f38fcaSMauro Carvalho Chehab - Field order, from enum :c:type:`v4l2_field`. 5654f38fcaSMauro Carvalho Chehab Video images are typically interlaced. Applications can request to 5754f38fcaSMauro Carvalho Chehab capture or output only the top or bottom field, or both fields 5854f38fcaSMauro Carvalho Chehab interlaced or sequentially stored in one buffer or alternating in 5954f38fcaSMauro Carvalho Chehab separate buffers. Drivers return the actual field order selected. 6054f38fcaSMauro Carvalho Chehab For more details on fields see :ref:`field-order`. 6154f38fcaSMauro Carvalho Chehab * - __u32 6254f38fcaSMauro Carvalho Chehab - ``bytesperline`` 6354f38fcaSMauro Carvalho Chehab - Distance in bytes between the leftmost pixels in two adjacent 6454f38fcaSMauro Carvalho Chehab lines. 6554f38fcaSMauro Carvalho Chehab * - :cspan:`2` 6654f38fcaSMauro Carvalho Chehab 6754f38fcaSMauro Carvalho Chehab Both applications and drivers can set this field to request 6854f38fcaSMauro Carvalho Chehab padding bytes at the end of each line. Drivers however may ignore 6954f38fcaSMauro Carvalho Chehab the value requested by the application, returning ``width`` times 7054f38fcaSMauro Carvalho Chehab bytes per pixel or a larger value required by the hardware. That 7154f38fcaSMauro Carvalho Chehab implies applications can just set this field to zero to get a 7254f38fcaSMauro Carvalho Chehab reasonable default. 7354f38fcaSMauro Carvalho Chehab 7454f38fcaSMauro Carvalho Chehab Video hardware may access padding bytes, therefore they must 7554f38fcaSMauro Carvalho Chehab reside in accessible memory. Consider cases where padding bytes 7654f38fcaSMauro Carvalho Chehab after the last line of an image cross a system page boundary. 7754f38fcaSMauro Carvalho Chehab Input devices may write padding bytes, the value is undefined. 7854f38fcaSMauro Carvalho Chehab Output devices ignore the contents of padding bytes. 7954f38fcaSMauro Carvalho Chehab 8054f38fcaSMauro Carvalho Chehab When the image format is planar the ``bytesperline`` value applies 8154f38fcaSMauro Carvalho Chehab to the first plane and is divided by the same factor as the 8254f38fcaSMauro Carvalho Chehab ``width`` field for the other planes. For example the Cb and Cr 8354f38fcaSMauro Carvalho Chehab planes of a YUV 4:2:0 image have half as many padding bytes 8454f38fcaSMauro Carvalho Chehab following each line as the Y plane. To avoid ambiguities drivers 8554f38fcaSMauro Carvalho Chehab must return a ``bytesperline`` value rounded up to a multiple of 8654f38fcaSMauro Carvalho Chehab the scale factor. 8754f38fcaSMauro Carvalho Chehab 8854f38fcaSMauro Carvalho Chehab For compressed formats the ``bytesperline`` value makes no sense. 8954f38fcaSMauro Carvalho Chehab Applications and drivers must set this to 0 in that case. 9054f38fcaSMauro Carvalho Chehab * - __u32 9154f38fcaSMauro Carvalho Chehab - ``sizeimage`` 9254f38fcaSMauro Carvalho Chehab - Size in bytes of the buffer to hold a complete image, set by the 9354f38fcaSMauro Carvalho Chehab driver. Usually this is ``bytesperline`` times ``height``. When 9454f38fcaSMauro Carvalho Chehab the image consists of variable length compressed data this is the 9554f38fcaSMauro Carvalho Chehab number of bytes required by the codec to support the worst-case 9654f38fcaSMauro Carvalho Chehab compression scenario. 9754f38fcaSMauro Carvalho Chehab 9854f38fcaSMauro Carvalho Chehab The driver will set the value for uncompressed images. 9954f38fcaSMauro Carvalho Chehab 10054f38fcaSMauro Carvalho Chehab Clients are allowed to set the sizeimage field for variable length 10154f38fcaSMauro Carvalho Chehab compressed data flagged with ``V4L2_FMT_FLAG_COMPRESSED`` at 10254f38fcaSMauro Carvalho Chehab :ref:`VIDIOC_ENUM_FMT`, but the driver may ignore it and set the 10354f38fcaSMauro Carvalho Chehab value itself, or it may modify the provided value based on 10454f38fcaSMauro Carvalho Chehab alignment requirements or minimum/maximum size requirements. 10554f38fcaSMauro Carvalho Chehab If the client wants to leave this to the driver, then it should 10654f38fcaSMauro Carvalho Chehab set sizeimage to 0. 10754f38fcaSMauro Carvalho Chehab * - __u32 10854f38fcaSMauro Carvalho Chehab - ``colorspace`` 10954f38fcaSMauro Carvalho Chehab - Image colorspace, from enum :c:type:`v4l2_colorspace`. 11054f38fcaSMauro Carvalho Chehab This information supplements the ``pixelformat`` and must be set 11154f38fcaSMauro Carvalho Chehab by the driver for capture streams and by the application for 112b38c73caSDafna Hirschfeld output streams, see :ref:`colorspaces`. If the application sets the 113b38c73caSDafna Hirschfeld flag ``V4L2_PIX_FMT_FLAG_SET_CSC`` then the application can set 114b38c73caSDafna Hirschfeld this field for a capture stream to request a specific colorspace 115b38c73caSDafna Hirschfeld for the captured image data. If the driver cannot handle requested 116b38c73caSDafna Hirschfeld conversion, it will return another supported colorspace. 117b38c73caSDafna Hirschfeld The driver indicates that colorspace conversion is supported by setting 118b38c73caSDafna Hirschfeld the flag V4L2_FMT_FLAG_CSC_COLORSPACE in the corresponding struct 119b38c73caSDafna Hirschfeld :c:type:`v4l2_fmtdesc` during enumeration. See :ref:`fmtdesc-flags`. 12054f38fcaSMauro Carvalho Chehab * - __u32 12154f38fcaSMauro Carvalho Chehab - ``priv`` 12254f38fcaSMauro Carvalho Chehab - This field indicates whether the remaining fields of the 12354f38fcaSMauro Carvalho Chehab struct :c:type:`v4l2_pix_format`, also called the 12454f38fcaSMauro Carvalho Chehab extended fields, are valid. When set to 12554f38fcaSMauro Carvalho Chehab ``V4L2_PIX_FMT_PRIV_MAGIC``, it indicates that the extended fields 12654f38fcaSMauro Carvalho Chehab have been correctly initialized. When set to any other value it 12754f38fcaSMauro Carvalho Chehab indicates that the extended fields contain undefined values. 12854f38fcaSMauro Carvalho Chehab 12954f38fcaSMauro Carvalho Chehab Applications that wish to use the pixel format extended fields 13054f38fcaSMauro Carvalho Chehab must first ensure that the feature is supported by querying the 13154f38fcaSMauro Carvalho Chehab device for the :ref:`V4L2_CAP_EXT_PIX_FORMAT <querycap>` 13254f38fcaSMauro Carvalho Chehab capability. If the capability isn't set the pixel format extended 13354f38fcaSMauro Carvalho Chehab fields are not supported and using the extended fields will lead 13454f38fcaSMauro Carvalho Chehab to undefined results. 13554f38fcaSMauro Carvalho Chehab 13654f38fcaSMauro Carvalho Chehab To use the extended fields, applications must set the ``priv`` 13754f38fcaSMauro Carvalho Chehab field to ``V4L2_PIX_FMT_PRIV_MAGIC``, initialize all the extended 13854f38fcaSMauro Carvalho Chehab fields and zero the unused bytes of the 13954f38fcaSMauro Carvalho Chehab struct :c:type:`v4l2_format` ``raw_data`` field. 14054f38fcaSMauro Carvalho Chehab 14154f38fcaSMauro Carvalho Chehab When the ``priv`` field isn't set to ``V4L2_PIX_FMT_PRIV_MAGIC`` 14254f38fcaSMauro Carvalho Chehab drivers must act as if all the extended fields were set to zero. 14354f38fcaSMauro Carvalho Chehab On return drivers must set the ``priv`` field to 14454f38fcaSMauro Carvalho Chehab ``V4L2_PIX_FMT_PRIV_MAGIC`` and all the extended fields to 14554f38fcaSMauro Carvalho Chehab applicable values. 14654f38fcaSMauro Carvalho Chehab * - __u32 14754f38fcaSMauro Carvalho Chehab - ``flags`` 14854f38fcaSMauro Carvalho Chehab - Flags set by the application or driver, see :ref:`format-flags`. 14954f38fcaSMauro Carvalho Chehab * - union { 15054f38fcaSMauro Carvalho Chehab - (anonymous) 15154f38fcaSMauro Carvalho Chehab * - __u32 15254f38fcaSMauro Carvalho Chehab - ``ycbcr_enc`` 15354f38fcaSMauro Carvalho Chehab - Y'CbCr encoding, from enum :c:type:`v4l2_ycbcr_encoding`. 15454f38fcaSMauro Carvalho Chehab This information supplements the ``colorspace`` and must be set by 15554f38fcaSMauro Carvalho Chehab the driver for capture streams and by the application for output 156b38c73caSDafna Hirschfeld streams, see :ref:`colorspaces`. If the application sets the 157b38c73caSDafna Hirschfeld flag ``V4L2_PIX_FMT_FLAG_SET_CSC`` then the application can set 158b38c73caSDafna Hirschfeld this field for a capture stream to request a specific Y'CbCr encoding 159b38c73caSDafna Hirschfeld for the captured image data. If the driver cannot handle requested 160b38c73caSDafna Hirschfeld conversion, it will return another supported encoding. 161b38c73caSDafna Hirschfeld This field is ignored for HSV pixelformats. The driver indicates that 162b38c73caSDafna Hirschfeld ycbcr_enc conversion is supported by setting the flag 163b38c73caSDafna Hirschfeld V4L2_FMT_FLAG_CSC_YCBCR_ENC in the corresponding struct 164b38c73caSDafna Hirschfeld :c:type:`v4l2_fmtdesc` during enumeration. See :ref:`fmtdesc-flags`. 16554f38fcaSMauro Carvalho Chehab * - __u32 16654f38fcaSMauro Carvalho Chehab - ``hsv_enc`` 16754f38fcaSMauro Carvalho Chehab - HSV encoding, from enum :c:type:`v4l2_hsv_encoding`. 16854f38fcaSMauro Carvalho Chehab This information supplements the ``colorspace`` and must be set by 16954f38fcaSMauro Carvalho Chehab the driver for capture streams and by the application for output 170b38c73caSDafna Hirschfeld streams, see :ref:`colorspaces`. If the application sets the flag 171b38c73caSDafna Hirschfeld ``V4L2_PIX_FMT_FLAG_SET_CSC`` then the application can set this 172b38c73caSDafna Hirschfeld field for a capture stream to request a specific HSV encoding for the 173b38c73caSDafna Hirschfeld captured image data. If the driver cannot handle requested 174b38c73caSDafna Hirschfeld conversion, it will return another supported encoding. 175b38c73caSDafna Hirschfeld This field is ignored for non-HSV pixelformats. The driver indicates 176b38c73caSDafna Hirschfeld that hsv_enc conversion is supported by setting the flag 177b38c73caSDafna Hirschfeld V4L2_FMT_FLAG_CSC_HSV_ENC in the corresponding struct 178b38c73caSDafna Hirschfeld :c:type:`v4l2_fmtdesc` during enumeration. See :ref:`fmtdesc-flags`. 17954f38fcaSMauro Carvalho Chehab * - } 18054f38fcaSMauro Carvalho Chehab - 18154f38fcaSMauro Carvalho Chehab * - __u32 18254f38fcaSMauro Carvalho Chehab - ``quantization`` 18354f38fcaSMauro Carvalho Chehab - Quantization range, from enum :c:type:`v4l2_quantization`. 18454f38fcaSMauro Carvalho Chehab This information supplements the ``colorspace`` and must be set by 18554f38fcaSMauro Carvalho Chehab the driver for capture streams and by the application for output 186b38c73caSDafna Hirschfeld streams, see :ref:`colorspaces`. If the application sets the flag 187b38c73caSDafna Hirschfeld ``V4L2_PIX_FMT_FLAG_SET_CSC`` then the application can set 188b38c73caSDafna Hirschfeld this field for a capture stream to request a specific quantization 189b38c73caSDafna Hirschfeld range for the captured image data. If the driver cannot handle requested 190b38c73caSDafna Hirschfeld conversion, it will return another supported quantization. 191b38c73caSDafna Hirschfeld The driver indicates that quantization conversion is supported by setting 192b38c73caSDafna Hirschfeld the flag V4L2_FMT_FLAG_CSC_QUANTIZATION in the corresponding struct 193b38c73caSDafna Hirschfeld :c:type:`v4l2_fmtdesc` during enumeration. See :ref:`fmtdesc-flags`. 19454f38fcaSMauro Carvalho Chehab * - __u32 19554f38fcaSMauro Carvalho Chehab - ``xfer_func`` 19654f38fcaSMauro Carvalho Chehab - Transfer function, from enum :c:type:`v4l2_xfer_func`. 19754f38fcaSMauro Carvalho Chehab This information supplements the ``colorspace`` and must be set by 19854f38fcaSMauro Carvalho Chehab the driver for capture streams and by the application for output 199b38c73caSDafna Hirschfeld streams, see :ref:`colorspaces`. If the application sets the flag 200b38c73caSDafna Hirschfeld ``V4L2_PIX_FMT_FLAG_SET_CSC`` then the application can set 201b38c73caSDafna Hirschfeld this field for a capture stream to request a specific transfer function 202b38c73caSDafna Hirschfeld for the captured image data. If the driver cannot handle requested 203b38c73caSDafna Hirschfeld conversion, it will return another supported transfer function. 204b38c73caSDafna Hirschfeld The driver indicates that xfer_func conversion is supported by setting 205b38c73caSDafna Hirschfeld the flag V4L2_FMT_FLAG_CSC_XFER_FUNC in the corresponding struct 206b38c73caSDafna Hirschfeld :c:type:`v4l2_fmtdesc` during enumeration. See :ref:`fmtdesc-flags`. 20747ad02d1SDafna Hirschfeld 208*fea13a69SMauro Carvalho Chehab.. tabularcolumns:: |p{6.8cm}|p{2.3cm}|p{8.2cm}| 20947ad02d1SDafna Hirschfeld 21047ad02d1SDafna Hirschfeld.. _format-flags: 21147ad02d1SDafna Hirschfeld 21247ad02d1SDafna Hirschfeld.. flat-table:: Format Flags 21347ad02d1SDafna Hirschfeld :header-rows: 0 21447ad02d1SDafna Hirschfeld :stub-columns: 0 21547ad02d1SDafna Hirschfeld :widths: 3 1 4 21647ad02d1SDafna Hirschfeld 21747ad02d1SDafna Hirschfeld * - ``V4L2_PIX_FMT_FLAG_PREMUL_ALPHA`` 21847ad02d1SDafna Hirschfeld - 0x00000001 21947ad02d1SDafna Hirschfeld - The color values are premultiplied by the alpha channel value. For 22047ad02d1SDafna Hirschfeld example, if a light blue pixel with 50% transparency was described 22147ad02d1SDafna Hirschfeld by RGBA values (128, 192, 255, 128), the same pixel described with 22247ad02d1SDafna Hirschfeld premultiplied colors would be described by RGBA values (64, 96, 22347ad02d1SDafna Hirschfeld 128, 128) 224b38c73caSDafna Hirschfeld * .. _`v4l2-pix-fmt-flag-set-csc`: 225b38c73caSDafna Hirschfeld 226b38c73caSDafna Hirschfeld - ``V4L2_PIX_FMT_FLAG_SET_CSC`` 227b38c73caSDafna Hirschfeld - 0x00000002 228b38c73caSDafna Hirschfeld - Set by the application. It is only used for capture and is 229b38c73caSDafna Hirschfeld ignored for output streams. If set, then request the device to do 230b38c73caSDafna Hirschfeld colorspace conversion from the received colorspace to the requested 231b38c73caSDafna Hirschfeld colorspace values. If the colorimetry field (``colorspace``, ``xfer_func``, 232b38c73caSDafna Hirschfeld ``ycbcr_enc``, ``hsv_enc`` or ``quantization``) is set to ``*_DEFAULT``, 233b38c73caSDafna Hirschfeld then that colorimetry setting will remain unchanged from what was received. 234b38c73caSDafna Hirschfeld So in order to change the quantization, only the ``quantization`` field shall 235b38c73caSDafna Hirschfeld be set to non default value (``V4L2_QUANTIZATION_FULL_RANGE`` or 236b38c73caSDafna Hirschfeld ``V4L2_QUANTIZATION_LIM_RANGE``) and all other colorimetry fields shall 237b38c73caSDafna Hirschfeld be set to ``*_DEFAULT``. 238b38c73caSDafna Hirschfeld 239b38c73caSDafna Hirschfeld To check which conversions are supported by the hardware for the current 240b38c73caSDafna Hirschfeld pixel format, see :ref:`fmtdesc-flags`. 241