pixfmt-002.rst 6.2 KB
Newer Older
1 2 3 4 5 6 7 8 9
.. -*- coding: utf-8; mode: rst -*-

******************************
Single-planar format structure
******************************


.. _v4l2-pix-format:

10 11 12
.. tabularcolumns:: |p{4.0cm}|p{2.5cm}|p{11.0cm}|

.. cssclass:: longtable
13

14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
.. flat-table:: struct v4l2_pix_format
    :header-rows:  0
    :stub-columns: 0
    :widths:       1 1 2


    -  .. row 1

       -  __u32

       -  ``width``

       -  Image width in pixels.

    -  .. row 2

       -  __u32

       -  ``height``

       -  Image height in pixels. If ``field`` is one of ``V4L2_FIELD_TOP``,
35 36 37 38
	  ``V4L2_FIELD_BOTTOM`` or ``V4L2_FIELD_ALTERNATE`` then height
	  refers to the number of lines in the field, otherwise it refers to
	  the number of lines in the frame (which is twice the field height
	  for interlaced formats).
39 40 41 42

    -  .. row 3

       -  :cspan:`2` Applications set these fields to request an image
43 44 45 46 47 48
	  size, drivers return the closest possible values. In case of
	  planar formats the ``width`` and ``height`` applies to the largest
	  plane. To avoid ambiguities drivers must return values rounded up
	  to a multiple of the scale factor of any smaller planes. For
	  example when the image format is YUV 4:2:0, ``width`` and
	  ``height`` must be multiples of two.
49 50 51 52 53 54 55 56

    -  .. row 4

       -  __u32

       -  ``pixelformat``

       -  The pixel format or type of compression, set by the application.
57 58 59 60 61
	  This is a little endian
	  :ref:`four character code <v4l2-fourcc>`. V4L2 defines standard
	  RGB formats in :ref:`rgb-formats`, YUV formats in
	  :ref:`yuv-formats`, and reserved codes in
	  :ref:`reserved-formats`
62 63 64 65 66 67 68 69

    -  .. row 5

       -  enum :ref:`v4l2_field <v4l2-field>`

       -  ``field``

       -  Video images are typically interlaced. Applications can request to
70 71 72 73
	  capture or output only the top or bottom field, or both fields
	  interlaced or sequentially stored in one buffer or alternating in
	  separate buffers. Drivers return the actual field order selected.
	  For more details on fields see :ref:`field-order`.
74 75 76 77 78 79 80 81

    -  .. row 6

       -  __u32

       -  ``bytesperline``

       -  Distance in bytes between the leftmost pixels in two adjacent
82
	  lines.
83 84 85 86 87

    -  .. row 7

       -  :cspan:`2`

88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
	  Both applications and drivers can set this field to request
	  padding bytes at the end of each line. Drivers however may ignore
	  the value requested by the application, returning ``width`` times
	  bytes per pixel or a larger value required by the hardware. That
	  implies applications can just set this field to zero to get a
	  reasonable default.

	  Video hardware may access padding bytes, therefore they must
	  reside in accessible memory. Consider cases where padding bytes
	  after the last line of an image cross a system page boundary.
	  Input devices may write padding bytes, the value is undefined.
	  Output devices ignore the contents of padding bytes.

	  When the image format is planar the ``bytesperline`` value applies
	  to the first plane and is divided by the same factor as the
	  ``width`` field for the other planes. For example the Cb and Cr
	  planes of a YUV 4:2:0 image have half as many padding bytes
	  following each line as the Y plane. To avoid ambiguities drivers
	  must return a ``bytesperline`` value rounded up to a multiple of
	  the scale factor.

	  For compressed formats the ``bytesperline`` value makes no sense.
	  Applications and drivers must set this to 0 in that case.
111 112 113 114 115 116 117 118

    -  .. row 8

       -  __u32

       -  ``sizeimage``

       -  Size in bytes of the buffer to hold a complete image, set by the
119 120 121
	  driver. Usually this is ``bytesperline`` times ``height``. When
	  the image consists of variable length compressed data this is the
	  maximum number of bytes required to hold an image.
122 123 124 125 126 127 128 129

    -  .. row 9

       -  enum :ref:`v4l2_colorspace <v4l2-colorspace>`

       -  ``colorspace``

       -  This information supplements the ``pixelformat`` and must be set
130 131
	  by the driver for capture streams and by the application for
	  output streams, see :ref:`colorspaces`.
132 133 134 135 136 137 138 139

    -  .. row 10

       -  __u32

       -  ``priv``

       -  This field indicates whether the remaining fields of the
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162
	  :ref:`struct v4l2_pix_format <v4l2-pix-format>` structure, also called the
	  extended fields, are valid. When set to
	  ``V4L2_PIX_FMT_PRIV_MAGIC``, it indicates that the extended fields
	  have been correctly initialized. When set to any other value it
	  indicates that the extended fields contain undefined values.

	  Applications that wish to use the pixel format extended fields
	  must first ensure that the feature is supported by querying the
	  device for the :ref:`V4L2_CAP_EXT_PIX_FORMAT <querycap>`
	  capability. If the capability isn't set the pixel format extended
	  fields are not supported and using the extended fields will lead
	  to undefined results.

	  To use the extended fields, applications must set the ``priv``
	  field to ``V4L2_PIX_FMT_PRIV_MAGIC``, initialize all the extended
	  fields and zero the unused bytes of the
	  :ref:`struct v4l2_format <v4l2-format>` ``raw_data`` field.

	  When the ``priv`` field isn't set to ``V4L2_PIX_FMT_PRIV_MAGIC``
	  drivers must act as if all the extended fields were set to zero.
	  On return drivers must set the ``priv`` field to
	  ``V4L2_PIX_FMT_PRIV_MAGIC`` and all the extended fields to
	  applicable values.
163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178

    -  .. row 11

       -  __u32

       -  ``flags``

       -  Flags set by the application or driver, see :ref:`format-flags`.

    -  .. row 12

       -  enum :ref:`v4l2_ycbcr_encoding <v4l2-ycbcr-encoding>`

       -  ``ycbcr_enc``

       -  This information supplements the ``colorspace`` and must be set by
179 180
	  the driver for capture streams and by the application for output
	  streams, see :ref:`colorspaces`.
181 182 183 184 185 186 187 188

    -  .. row 13

       -  enum :ref:`v4l2_quantization <v4l2-quantization>`

       -  ``quantization``

       -  This information supplements the ``colorspace`` and must be set by
189 190
	  the driver for capture streams and by the application for output
	  streams, see :ref:`colorspaces`.
191 192 193 194 195 196 197 198

    -  .. row 14

       -  enum :ref:`v4l2_xfer_func <v4l2-xfer-func>`

       -  ``xfer_func``

       -  This information supplements the ``colorspace`` and must be set by
199 200
	  the driver for capture streams and by the application for output
	  streams, see :ref:`colorspaces`.