xref: /OK3568_Linux_fs/kernel/Documentation/userspace-api/media/v4l/pixfmt-v4l2.rst (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
2*4882a593Smuzhiyun
3*4882a593Smuzhiyun******************************
4*4882a593SmuzhiyunSingle-planar format structure
5*4882a593Smuzhiyun******************************
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun.. tabularcolumns:: |p{4.0cm}|p{2.5cm}|p{11.0cm}|
8*4882a593Smuzhiyun
9*4882a593Smuzhiyun.. c:type:: v4l2_pix_format
10*4882a593Smuzhiyun
11*4882a593Smuzhiyun.. cssclass:: longtable
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun.. flat-table:: struct v4l2_pix_format
14*4882a593Smuzhiyun    :header-rows:  0
15*4882a593Smuzhiyun    :stub-columns: 0
16*4882a593Smuzhiyun    :widths:       1 1 2
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun    * - __u32
19*4882a593Smuzhiyun      - ``width``
20*4882a593Smuzhiyun      - Image width in pixels.
21*4882a593Smuzhiyun    * - __u32
22*4882a593Smuzhiyun      - ``height``
23*4882a593Smuzhiyun      - Image height in pixels. If ``field`` is one of ``V4L2_FIELD_TOP``,
24*4882a593Smuzhiyun	``V4L2_FIELD_BOTTOM`` or ``V4L2_FIELD_ALTERNATE`` then height
25*4882a593Smuzhiyun	refers to the number of lines in the field, otherwise it refers to
26*4882a593Smuzhiyun	the number of lines in the frame (which is twice the field height
27*4882a593Smuzhiyun	for interlaced formats).
28*4882a593Smuzhiyun    * - :cspan:`2` Applications set these fields to request an image
29*4882a593Smuzhiyun	size, drivers return the closest possible values. In case of
30*4882a593Smuzhiyun	planar formats the ``width`` and ``height`` applies to the largest
31*4882a593Smuzhiyun	plane. To avoid ambiguities drivers must return values rounded up
32*4882a593Smuzhiyun	to a multiple of the scale factor of any smaller planes. For
33*4882a593Smuzhiyun	example when the image format is YUV 4:2:0, ``width`` and
34*4882a593Smuzhiyun	``height`` must be multiples of two.
35*4882a593Smuzhiyun
36*4882a593Smuzhiyun	For compressed formats that contain the resolution information encoded
37*4882a593Smuzhiyun	inside the stream, when fed to a stateful mem2mem decoder, the fields
38*4882a593Smuzhiyun	may be zero to rely on the decoder to detect the right values. For more
39*4882a593Smuzhiyun	details see :ref:`decoder` and format descriptions.
40*4882a593Smuzhiyun
41*4882a593Smuzhiyun	For compressed formats on the CAPTURE side of a stateful mem2mem
42*4882a593Smuzhiyun	encoder, the fields must be zero, since the coded size is expected to
43*4882a593Smuzhiyun	be calculated internally by the encoder itself, based on the OUTPUT
44*4882a593Smuzhiyun	side. For more details see :ref:`encoder` and format descriptions.
45*4882a593Smuzhiyun    * - __u32
46*4882a593Smuzhiyun      - ``pixelformat``
47*4882a593Smuzhiyun      - The pixel format or type of compression, set by the application.
48*4882a593Smuzhiyun	This is a little endian
49*4882a593Smuzhiyun	:ref:`four character code <v4l2-fourcc>`. V4L2 defines standard
50*4882a593Smuzhiyun	RGB formats in :ref:`pixfmt-rgb`, YUV formats in
51*4882a593Smuzhiyun	:ref:`yuv-formats`, and reserved codes in
52*4882a593Smuzhiyun	:ref:`reserved-formats`
53*4882a593Smuzhiyun    * - __u32
54*4882a593Smuzhiyun      - ``field``
55*4882a593Smuzhiyun      - Field order, from enum :c:type:`v4l2_field`.
56*4882a593Smuzhiyun        Video images are typically interlaced. Applications can request to
57*4882a593Smuzhiyun	capture or output only the top or bottom field, or both fields
58*4882a593Smuzhiyun	interlaced or sequentially stored in one buffer or alternating in
59*4882a593Smuzhiyun	separate buffers. Drivers return the actual field order selected.
60*4882a593Smuzhiyun	For more details on fields see :ref:`field-order`.
61*4882a593Smuzhiyun    * - __u32
62*4882a593Smuzhiyun      - ``bytesperline``
63*4882a593Smuzhiyun      - Distance in bytes between the leftmost pixels in two adjacent
64*4882a593Smuzhiyun	lines.
65*4882a593Smuzhiyun    * - :cspan:`2`
66*4882a593Smuzhiyun
67*4882a593Smuzhiyun	Both applications and drivers can set this field to request
68*4882a593Smuzhiyun	padding bytes at the end of each line. Drivers however may ignore
69*4882a593Smuzhiyun	the value requested by the application, returning ``width`` times
70*4882a593Smuzhiyun	bytes per pixel or a larger value required by the hardware. That
71*4882a593Smuzhiyun	implies applications can just set this field to zero to get a
72*4882a593Smuzhiyun	reasonable default.
73*4882a593Smuzhiyun
74*4882a593Smuzhiyun	Video hardware may access padding bytes, therefore they must
75*4882a593Smuzhiyun	reside in accessible memory. Consider cases where padding bytes
76*4882a593Smuzhiyun	after the last line of an image cross a system page boundary.
77*4882a593Smuzhiyun	Input devices may write padding bytes, the value is undefined.
78*4882a593Smuzhiyun	Output devices ignore the contents of padding bytes.
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun	When the image format is planar the ``bytesperline`` value applies
81*4882a593Smuzhiyun	to the first plane and is divided by the same factor as the
82*4882a593Smuzhiyun	``width`` field for the other planes. For example the Cb and Cr
83*4882a593Smuzhiyun	planes of a YUV 4:2:0 image have half as many padding bytes
84*4882a593Smuzhiyun	following each line as the Y plane. To avoid ambiguities drivers
85*4882a593Smuzhiyun	must return a ``bytesperline`` value rounded up to a multiple of
86*4882a593Smuzhiyun	the scale factor.
87*4882a593Smuzhiyun
88*4882a593Smuzhiyun	For compressed formats the ``bytesperline`` value makes no sense.
89*4882a593Smuzhiyun	Applications and drivers must set this to 0 in that case.
90*4882a593Smuzhiyun    * - __u32
91*4882a593Smuzhiyun      - ``sizeimage``
92*4882a593Smuzhiyun      - Size in bytes of the buffer to hold a complete image, set by the
93*4882a593Smuzhiyun	driver. Usually this is ``bytesperline`` times ``height``. When
94*4882a593Smuzhiyun	the image consists of variable length compressed data this is the
95*4882a593Smuzhiyun	number of bytes required by the codec to support the worst-case
96*4882a593Smuzhiyun	compression scenario.
97*4882a593Smuzhiyun
98*4882a593Smuzhiyun	The driver will set the value for uncompressed images.
99*4882a593Smuzhiyun
100*4882a593Smuzhiyun	Clients are allowed to set the sizeimage field for variable length
101*4882a593Smuzhiyun	compressed data flagged with ``V4L2_FMT_FLAG_COMPRESSED`` at
102*4882a593Smuzhiyun	:ref:`VIDIOC_ENUM_FMT`, but the driver may ignore it and set the
103*4882a593Smuzhiyun	value itself, or it may modify the provided value based on
104*4882a593Smuzhiyun	alignment requirements or minimum/maximum size requirements.
105*4882a593Smuzhiyun	If the client wants to leave this to the driver, then it should
106*4882a593Smuzhiyun	set sizeimage to 0.
107*4882a593Smuzhiyun    * - __u32
108*4882a593Smuzhiyun      - ``colorspace``
109*4882a593Smuzhiyun      - Image colorspace, from enum :c:type:`v4l2_colorspace`.
110*4882a593Smuzhiyun        This information supplements the ``pixelformat`` and must be set
111*4882a593Smuzhiyun	by the driver for capture streams and by the application for
112*4882a593Smuzhiyun	output streams, see :ref:`colorspaces`. If the application sets the
113*4882a593Smuzhiyun	flag ``V4L2_PIX_FMT_FLAG_SET_CSC`` then the application can set
114*4882a593Smuzhiyun	this field for a capture stream to request a specific colorspace
115*4882a593Smuzhiyun	for the captured image data. If the driver cannot handle requested
116*4882a593Smuzhiyun	conversion, it will return another supported colorspace.
117*4882a593Smuzhiyun	The driver indicates that colorspace conversion is supported by setting
118*4882a593Smuzhiyun	the flag V4L2_FMT_FLAG_CSC_COLORSPACE in the corresponding struct
119*4882a593Smuzhiyun	:c:type:`v4l2_fmtdesc` during enumeration. See :ref:`fmtdesc-flags`.
120*4882a593Smuzhiyun    * - __u32
121*4882a593Smuzhiyun      - ``priv``
122*4882a593Smuzhiyun      - This field indicates whether the remaining fields of the
123*4882a593Smuzhiyun	struct :c:type:`v4l2_pix_format`, also called the
124*4882a593Smuzhiyun	extended fields, are valid. When set to
125*4882a593Smuzhiyun	``V4L2_PIX_FMT_PRIV_MAGIC``, it indicates that the extended fields
126*4882a593Smuzhiyun	have been correctly initialized. When set to any other value it
127*4882a593Smuzhiyun	indicates that the extended fields contain undefined values.
128*4882a593Smuzhiyun
129*4882a593Smuzhiyun	Applications that wish to use the pixel format extended fields
130*4882a593Smuzhiyun	must first ensure that the feature is supported by querying the
131*4882a593Smuzhiyun	device for the :ref:`V4L2_CAP_EXT_PIX_FORMAT <querycap>`
132*4882a593Smuzhiyun	capability. If the capability isn't set the pixel format extended
133*4882a593Smuzhiyun	fields are not supported and using the extended fields will lead
134*4882a593Smuzhiyun	to undefined results.
135*4882a593Smuzhiyun
136*4882a593Smuzhiyun	To use the extended fields, applications must set the ``priv``
137*4882a593Smuzhiyun	field to ``V4L2_PIX_FMT_PRIV_MAGIC``, initialize all the extended
138*4882a593Smuzhiyun	fields and zero the unused bytes of the
139*4882a593Smuzhiyun	struct :c:type:`v4l2_format` ``raw_data`` field.
140*4882a593Smuzhiyun
141*4882a593Smuzhiyun	When the ``priv`` field isn't set to ``V4L2_PIX_FMT_PRIV_MAGIC``
142*4882a593Smuzhiyun	drivers must act as if all the extended fields were set to zero.
143*4882a593Smuzhiyun	On return drivers must set the ``priv`` field to
144*4882a593Smuzhiyun	``V4L2_PIX_FMT_PRIV_MAGIC`` and all the extended fields to
145*4882a593Smuzhiyun	applicable values.
146*4882a593Smuzhiyun    * - __u32
147*4882a593Smuzhiyun      - ``flags``
148*4882a593Smuzhiyun      - Flags set by the application or driver, see :ref:`format-flags`.
149*4882a593Smuzhiyun    * - union {
150*4882a593Smuzhiyun      - (anonymous)
151*4882a593Smuzhiyun    * - __u32
152*4882a593Smuzhiyun      - ``ycbcr_enc``
153*4882a593Smuzhiyun      - Y'CbCr encoding, from enum :c:type:`v4l2_ycbcr_encoding`.
154*4882a593Smuzhiyun        This information supplements the ``colorspace`` and must be set by
155*4882a593Smuzhiyun	the driver for capture streams and by the application for output
156*4882a593Smuzhiyun	streams, see :ref:`colorspaces`. If the application sets the
157*4882a593Smuzhiyun	flag ``V4L2_PIX_FMT_FLAG_SET_CSC`` then the application can set
158*4882a593Smuzhiyun	this field for a capture stream to request a specific Y'CbCr encoding
159*4882a593Smuzhiyun	for the captured image data. If the driver cannot handle requested
160*4882a593Smuzhiyun	conversion, it will return another supported encoding.
161*4882a593Smuzhiyun	This field is ignored for HSV pixelformats. The driver indicates that
162*4882a593Smuzhiyun	ycbcr_enc conversion is supported by setting the flag
163*4882a593Smuzhiyun	V4L2_FMT_FLAG_CSC_YCBCR_ENC in the corresponding struct
164*4882a593Smuzhiyun	:c:type:`v4l2_fmtdesc` during enumeration. See :ref:`fmtdesc-flags`.
165*4882a593Smuzhiyun    * - __u32
166*4882a593Smuzhiyun      - ``hsv_enc``
167*4882a593Smuzhiyun      - HSV encoding, from enum :c:type:`v4l2_hsv_encoding`.
168*4882a593Smuzhiyun        This information supplements the ``colorspace`` and must be set by
169*4882a593Smuzhiyun	the driver for capture streams and by the application for output
170*4882a593Smuzhiyun	streams, see :ref:`colorspaces`. If the application sets the flag
171*4882a593Smuzhiyun	``V4L2_PIX_FMT_FLAG_SET_CSC`` then the application can set this
172*4882a593Smuzhiyun	field for a capture stream to request a specific HSV encoding for the
173*4882a593Smuzhiyun	captured image data. If the driver cannot handle requested
174*4882a593Smuzhiyun	conversion, it will return another supported encoding.
175*4882a593Smuzhiyun	This field is ignored for non-HSV pixelformats. The driver indicates
176*4882a593Smuzhiyun	that hsv_enc conversion is supported by setting the flag
177*4882a593Smuzhiyun	V4L2_FMT_FLAG_CSC_HSV_ENC in the corresponding struct
178*4882a593Smuzhiyun	:c:type:`v4l2_fmtdesc` during enumeration. See :ref:`fmtdesc-flags`.
179*4882a593Smuzhiyun    * - }
180*4882a593Smuzhiyun      -
181*4882a593Smuzhiyun    * - __u32
182*4882a593Smuzhiyun      - ``quantization``
183*4882a593Smuzhiyun      - Quantization range, from enum :c:type:`v4l2_quantization`.
184*4882a593Smuzhiyun        This information supplements the ``colorspace`` and must be set by
185*4882a593Smuzhiyun	the driver for capture streams and by the application for output
186*4882a593Smuzhiyun	streams, see :ref:`colorspaces`. If the application sets the flag
187*4882a593Smuzhiyun	``V4L2_PIX_FMT_FLAG_SET_CSC`` then the application can set
188*4882a593Smuzhiyun	this field for a capture stream to request a specific quantization
189*4882a593Smuzhiyun	range for the captured image data. If the driver cannot handle requested
190*4882a593Smuzhiyun	conversion, it will return another supported quantization.
191*4882a593Smuzhiyun	The driver indicates that quantization conversion is supported by setting
192*4882a593Smuzhiyun	the flag V4L2_FMT_FLAG_CSC_QUANTIZATION in the corresponding struct
193*4882a593Smuzhiyun	:c:type:`v4l2_fmtdesc` during enumeration. See :ref:`fmtdesc-flags`.
194*4882a593Smuzhiyun    * - __u32
195*4882a593Smuzhiyun      - ``xfer_func``
196*4882a593Smuzhiyun      - Transfer function, from enum :c:type:`v4l2_xfer_func`.
197*4882a593Smuzhiyun        This information supplements the ``colorspace`` and must be set by
198*4882a593Smuzhiyun	the driver for capture streams and by the application for output
199*4882a593Smuzhiyun	streams, see :ref:`colorspaces`. If the application sets the flag
200*4882a593Smuzhiyun	``V4L2_PIX_FMT_FLAG_SET_CSC`` then the application can set
201*4882a593Smuzhiyun	this field for a capture stream to request a specific transfer function
202*4882a593Smuzhiyun	for the captured image data. If the driver cannot handle requested
203*4882a593Smuzhiyun	conversion, it will return another supported transfer function.
204*4882a593Smuzhiyun	The driver indicates that xfer_func conversion is supported by setting
205*4882a593Smuzhiyun	the flag V4L2_FMT_FLAG_CSC_XFER_FUNC in the corresponding struct
206*4882a593Smuzhiyun	:c:type:`v4l2_fmtdesc` during enumeration. See :ref:`fmtdesc-flags`.
207*4882a593Smuzhiyun
208*4882a593Smuzhiyun.. tabularcolumns:: |p{6.6cm}|p{2.2cm}|p{8.7cm}|
209*4882a593Smuzhiyun
210*4882a593Smuzhiyun.. _format-flags:
211*4882a593Smuzhiyun
212*4882a593Smuzhiyun.. flat-table:: Format Flags
213*4882a593Smuzhiyun    :header-rows:  0
214*4882a593Smuzhiyun    :stub-columns: 0
215*4882a593Smuzhiyun    :widths:       3 1 4
216*4882a593Smuzhiyun
217*4882a593Smuzhiyun    * - ``V4L2_PIX_FMT_FLAG_PREMUL_ALPHA``
218*4882a593Smuzhiyun      - 0x00000001
219*4882a593Smuzhiyun      - The color values are premultiplied by the alpha channel value. For
220*4882a593Smuzhiyun        example, if a light blue pixel with 50% transparency was described
221*4882a593Smuzhiyun	by RGBA values (128, 192, 255, 128), the same pixel described with
222*4882a593Smuzhiyun	premultiplied colors would be described by RGBA values (64, 96,
223*4882a593Smuzhiyun	128, 128)
224*4882a593Smuzhiyun    * .. _`v4l2-pix-fmt-flag-set-csc`:
225*4882a593Smuzhiyun
226*4882a593Smuzhiyun      - ``V4L2_PIX_FMT_FLAG_SET_CSC``
227*4882a593Smuzhiyun      - 0x00000002
228*4882a593Smuzhiyun      - Set by the application. It is only used for capture and is
229*4882a593Smuzhiyun        ignored for output streams. If set, then request the device to do
230*4882a593Smuzhiyun	colorspace conversion from the received colorspace to the requested
231*4882a593Smuzhiyun	colorspace values. If the colorimetry field (``colorspace``, ``xfer_func``,
232*4882a593Smuzhiyun	``ycbcr_enc``, ``hsv_enc`` or ``quantization``) is set to ``*_DEFAULT``,
233*4882a593Smuzhiyun	then that colorimetry setting will remain unchanged from what was received.
234*4882a593Smuzhiyun	So in order to change the quantization, only the ``quantization`` field shall
235*4882a593Smuzhiyun	be set to non default value (``V4L2_QUANTIZATION_FULL_RANGE`` or
236*4882a593Smuzhiyun	``V4L2_QUANTIZATION_LIM_RANGE``) and all other colorimetry fields shall
237*4882a593Smuzhiyun	be set to ``*_DEFAULT``.
238*4882a593Smuzhiyun
239*4882a593Smuzhiyun	To check which conversions are supported by the hardware for the current
240*4882a593Smuzhiyun	pixel format, see :ref:`fmtdesc-flags`.
241