18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci.. _field-order:
48c2ecf20Sopenharmony_ci
58c2ecf20Sopenharmony_ci***********
68c2ecf20Sopenharmony_ciField Order
78c2ecf20Sopenharmony_ci***********
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ciWe have to distinguish between progressive and interlaced video.
108c2ecf20Sopenharmony_ciProgressive video transmits all lines of a video image sequentially.
118c2ecf20Sopenharmony_ciInterlaced video divides an image into two fields, containing only the
128c2ecf20Sopenharmony_ciodd and even lines of the image, respectively. Alternating the so called
138c2ecf20Sopenharmony_ciodd and even field are transmitted, and due to a small delay between
148c2ecf20Sopenharmony_cifields a cathode ray TV displays the lines interleaved, yielding the
158c2ecf20Sopenharmony_cioriginal frame. This curious technique was invented because at refresh
168c2ecf20Sopenharmony_cirates similar to film the image would fade out too quickly. Transmitting
178c2ecf20Sopenharmony_cifields reduces the flicker without the necessity of doubling the frame
188c2ecf20Sopenharmony_cirate and with it the bandwidth required for each channel.
198c2ecf20Sopenharmony_ci
208c2ecf20Sopenharmony_ciIt is important to understand a video camera does not expose one frame
218c2ecf20Sopenharmony_ciat a time, merely transmitting the frames separated into fields. The
228c2ecf20Sopenharmony_cifields are in fact captured at two different instances in time. An
238c2ecf20Sopenharmony_ciobject on screen may well move between one field and the next. For
248c2ecf20Sopenharmony_ciapplications analysing motion it is of paramount importance to recognize
258c2ecf20Sopenharmony_ciwhich field of a frame is older, the *temporal order*.
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ciWhen the driver provides or accepts images field by field rather than
288c2ecf20Sopenharmony_ciinterleaved, it is also important applications understand how the fields
298c2ecf20Sopenharmony_cicombine to frames. We distinguish between top (aka odd) and bottom (aka
308c2ecf20Sopenharmony_cieven) fields, the *spatial order*: The first line of the top field is
318c2ecf20Sopenharmony_cithe first line of an interlaced frame, the first line of the bottom
328c2ecf20Sopenharmony_cifield is the second line of that frame.
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ciHowever because fields were captured one after the other, arguing
358c2ecf20Sopenharmony_ciwhether a frame commences with the top or bottom field is pointless. Any
368c2ecf20Sopenharmony_citwo successive top and bottom, or bottom and top fields yield a valid
378c2ecf20Sopenharmony_ciframe. Only when the source was progressive to begin with, e. g. when
388c2ecf20Sopenharmony_citransferring film to video, two fields may come from the same frame,
398c2ecf20Sopenharmony_cicreating a natural order.
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ciCounter to intuition the top field is not necessarily the older field.
428c2ecf20Sopenharmony_ciWhether the older field contains the top or bottom lines is a convention
438c2ecf20Sopenharmony_cidetermined by the video standard. Hence the distinction between temporal
448c2ecf20Sopenharmony_ciand spatial order of fields. The diagrams below should make this
458c2ecf20Sopenharmony_ciclearer.
468c2ecf20Sopenharmony_ci
478c2ecf20Sopenharmony_ciIn V4L it is assumed that all video cameras transmit fields on the media
488c2ecf20Sopenharmony_cibus in the same order they were captured, so if the top field was
498c2ecf20Sopenharmony_cicaptured first (is the older field), the top field is also transmitted
508c2ecf20Sopenharmony_cifirst on the bus.
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_ciAll video capture and output devices must report the current field
538c2ecf20Sopenharmony_ciorder. Some drivers may permit the selection of a different order, to
548c2ecf20Sopenharmony_cithis end applications initialize the ``field`` field of struct
558c2ecf20Sopenharmony_ci:c:type:`v4l2_pix_format` before calling the
568c2ecf20Sopenharmony_ci:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl. If this is not desired it
578c2ecf20Sopenharmony_cishould have the value ``V4L2_FIELD_ANY`` (0).
588c2ecf20Sopenharmony_ci
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cienum v4l2_field
618c2ecf20Sopenharmony_ci===============
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_ci.. c:type:: v4l2_field
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_ci.. tabularcolumns:: |p{5.8cm}|p{0.6cm}|p{11.1cm}|
668c2ecf20Sopenharmony_ci
678c2ecf20Sopenharmony_ci.. cssclass:: longtable
688c2ecf20Sopenharmony_ci
698c2ecf20Sopenharmony_ci.. flat-table::
708c2ecf20Sopenharmony_ci    :header-rows:  0
718c2ecf20Sopenharmony_ci    :stub-columns: 0
728c2ecf20Sopenharmony_ci    :widths:       3 1 4
738c2ecf20Sopenharmony_ci
748c2ecf20Sopenharmony_ci    * - ``V4L2_FIELD_ANY``
758c2ecf20Sopenharmony_ci      - 0
768c2ecf20Sopenharmony_ci      - Applications request this field order when any field format
778c2ecf20Sopenharmony_ci	is acceptable. Drivers choose depending on hardware capabilities or
788c2ecf20Sopenharmony_ci	e.g. the requested image size, and return the actual field order.
798c2ecf20Sopenharmony_ci	Drivers must never return ``V4L2_FIELD_ANY``.
808c2ecf20Sopenharmony_ci	If multiple field orders are possible the
818c2ecf20Sopenharmony_ci	driver must choose one of the possible field orders during
828c2ecf20Sopenharmony_ci	:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` or
838c2ecf20Sopenharmony_ci	:ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>`. struct
848c2ecf20Sopenharmony_ci	:c:type:`v4l2_buffer` ``field`` can never be
858c2ecf20Sopenharmony_ci	``V4L2_FIELD_ANY``.
868c2ecf20Sopenharmony_ci    * - ``V4L2_FIELD_NONE``
878c2ecf20Sopenharmony_ci      - 1
888c2ecf20Sopenharmony_ci      - Images are in progressive (frame-based) format, not interlaced
898c2ecf20Sopenharmony_ci        (field-based).
908c2ecf20Sopenharmony_ci    * - ``V4L2_FIELD_TOP``
918c2ecf20Sopenharmony_ci      - 2
928c2ecf20Sopenharmony_ci      - Images consist of the top (aka odd) field only.
938c2ecf20Sopenharmony_ci    * - ``V4L2_FIELD_BOTTOM``
948c2ecf20Sopenharmony_ci      - 3
958c2ecf20Sopenharmony_ci      - Images consist of the bottom (aka even) field only. Applications
968c2ecf20Sopenharmony_ci	may wish to prevent a device from capturing interlaced images
978c2ecf20Sopenharmony_ci	because they will have "comb" or "feathering" artefacts around
988c2ecf20Sopenharmony_ci	moving objects.
998c2ecf20Sopenharmony_ci    * - ``V4L2_FIELD_INTERLACED``
1008c2ecf20Sopenharmony_ci      - 4
1018c2ecf20Sopenharmony_ci      - Images contain both fields, interleaved line by line. The temporal
1028c2ecf20Sopenharmony_ci	order of the fields (whether the top or bottom field is older)
1038c2ecf20Sopenharmony_ci	depends on the current video standard. In M/NTSC the bottom
1048c2ecf20Sopenharmony_ci	field is the older field. In all other standards the top field
1058c2ecf20Sopenharmony_ci	is the older field.
1068c2ecf20Sopenharmony_ci    * - ``V4L2_FIELD_SEQ_TB``
1078c2ecf20Sopenharmony_ci      - 5
1088c2ecf20Sopenharmony_ci      - Images contain both fields, the top field lines are stored first
1098c2ecf20Sopenharmony_ci	in memory, immediately followed by the bottom field lines. Fields
1108c2ecf20Sopenharmony_ci	are always stored in temporal order, the older one first in
1118c2ecf20Sopenharmony_ci	memory. Image sizes refer to the frame, not fields.
1128c2ecf20Sopenharmony_ci    * - ``V4L2_FIELD_SEQ_BT``
1138c2ecf20Sopenharmony_ci      - 6
1148c2ecf20Sopenharmony_ci      - Images contain both fields, the bottom field lines are stored
1158c2ecf20Sopenharmony_ci	first in memory, immediately followed by the top field lines.
1168c2ecf20Sopenharmony_ci	Fields are always stored in temporal order, the older one first in
1178c2ecf20Sopenharmony_ci	memory. Image sizes refer to the frame, not fields.
1188c2ecf20Sopenharmony_ci    * - ``V4L2_FIELD_ALTERNATE``
1198c2ecf20Sopenharmony_ci      - 7
1208c2ecf20Sopenharmony_ci      - The two fields of a frame are passed in separate buffers, in
1218c2ecf20Sopenharmony_ci	temporal order, i. e. the older one first. To indicate the field
1228c2ecf20Sopenharmony_ci	parity (whether the current field is a top or bottom field) the
1238c2ecf20Sopenharmony_ci	driver or application, depending on data direction, must set
1248c2ecf20Sopenharmony_ci	struct :c:type:`v4l2_buffer` ``field`` to
1258c2ecf20Sopenharmony_ci	``V4L2_FIELD_TOP`` or ``V4L2_FIELD_BOTTOM``. Any two successive
1268c2ecf20Sopenharmony_ci	fields pair to build a frame. If fields are successive, without
1278c2ecf20Sopenharmony_ci	any dropped fields between them (fields can drop individually),
1288c2ecf20Sopenharmony_ci	can be determined from the struct
1298c2ecf20Sopenharmony_ci	:c:type:`v4l2_buffer` ``sequence`` field. This
1308c2ecf20Sopenharmony_ci	format cannot be selected when using the read/write I/O method
1318c2ecf20Sopenharmony_ci	since there is no way to communicate if a field was a top or
1328c2ecf20Sopenharmony_ci	bottom field.
1338c2ecf20Sopenharmony_ci    * - ``V4L2_FIELD_INTERLACED_TB``
1348c2ecf20Sopenharmony_ci      - 8
1358c2ecf20Sopenharmony_ci      - Images contain both fields, interleaved line by line, top field
1368c2ecf20Sopenharmony_ci	first. The top field is the older field.
1378c2ecf20Sopenharmony_ci    * - ``V4L2_FIELD_INTERLACED_BT``
1388c2ecf20Sopenharmony_ci      - 9
1398c2ecf20Sopenharmony_ci      - Images contain both fields, interleaved line by line, top field
1408c2ecf20Sopenharmony_ci	first. The bottom field is the older field.
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci
1448c2ecf20Sopenharmony_ci.. _fieldseq-tb:
1458c2ecf20Sopenharmony_ci
1468c2ecf20Sopenharmony_ciField Order, Top Field First Transmitted
1478c2ecf20Sopenharmony_ci========================================
1488c2ecf20Sopenharmony_ci
1498c2ecf20Sopenharmony_ci.. kernel-figure:: fieldseq_tb.svg
1508c2ecf20Sopenharmony_ci    :alt:    fieldseq_tb.svg
1518c2ecf20Sopenharmony_ci    :align:  center
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci    Field Order, Top Field First Transmitted
1548c2ecf20Sopenharmony_ci
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci.. _fieldseq-bt:
1578c2ecf20Sopenharmony_ci
1588c2ecf20Sopenharmony_ciField Order, Bottom Field First Transmitted
1598c2ecf20Sopenharmony_ci===========================================
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci.. kernel-figure:: fieldseq_bt.svg
1628c2ecf20Sopenharmony_ci    :alt:    fieldseq_bt.svg
1638c2ecf20Sopenharmony_ci    :align:  center
1648c2ecf20Sopenharmony_ci
1658c2ecf20Sopenharmony_ci    Field Order, Bottom Field First Transmitted
166