162306a36Sopenharmony_ci.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci.. _field-order:
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci***********
662306a36Sopenharmony_ciField Order
762306a36Sopenharmony_ci***********
862306a36Sopenharmony_ci
962306a36Sopenharmony_ciWe have to distinguish between progressive and interlaced video.
1062306a36Sopenharmony_ciProgressive video transmits all lines of a video image sequentially.
1162306a36Sopenharmony_ciInterlaced video divides an image into two fields, containing only the
1262306a36Sopenharmony_ciodd and even lines of the image, respectively. Alternating the so called
1362306a36Sopenharmony_ciodd and even field are transmitted, and due to a small delay between
1462306a36Sopenharmony_cifields a cathode ray TV displays the lines interleaved, yielding the
1562306a36Sopenharmony_cioriginal frame. This curious technique was invented because at refresh
1662306a36Sopenharmony_cirates similar to film the image would fade out too quickly. Transmitting
1762306a36Sopenharmony_cifields reduces the flicker without the necessity of doubling the frame
1862306a36Sopenharmony_cirate and with it the bandwidth required for each channel.
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ciIt is important to understand a video camera does not expose one frame
2162306a36Sopenharmony_ciat a time, merely transmitting the frames separated into fields. The
2262306a36Sopenharmony_cifields are in fact captured at two different instances in time. An
2362306a36Sopenharmony_ciobject on screen may well move between one field and the next. For
2462306a36Sopenharmony_ciapplications analysing motion it is of paramount importance to recognize
2562306a36Sopenharmony_ciwhich field of a frame is older, the *temporal order*.
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ciWhen the driver provides or accepts images field by field rather than
2862306a36Sopenharmony_ciinterleaved, it is also important applications understand how the fields
2962306a36Sopenharmony_cicombine to frames. We distinguish between top (aka odd) and bottom (aka
3062306a36Sopenharmony_cieven) fields, the *spatial order*: The first line of the top field is
3162306a36Sopenharmony_cithe first line of an interlaced frame, the first line of the bottom
3262306a36Sopenharmony_cifield is the second line of that frame.
3362306a36Sopenharmony_ci
3462306a36Sopenharmony_ciHowever because fields were captured one after the other, arguing
3562306a36Sopenharmony_ciwhether a frame commences with the top or bottom field is pointless. Any
3662306a36Sopenharmony_citwo successive top and bottom, or bottom and top fields yield a valid
3762306a36Sopenharmony_ciframe. Only when the source was progressive to begin with, e. g. when
3862306a36Sopenharmony_citransferring film to video, two fields may come from the same frame,
3962306a36Sopenharmony_cicreating a natural order.
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ciCounter to intuition the top field is not necessarily the older field.
4262306a36Sopenharmony_ciWhether the older field contains the top or bottom lines is a convention
4362306a36Sopenharmony_cidetermined by the video standard. Hence the distinction between temporal
4462306a36Sopenharmony_ciand spatial order of fields. The diagrams below should make this
4562306a36Sopenharmony_ciclearer.
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ciIn V4L it is assumed that all video cameras transmit fields on the media
4862306a36Sopenharmony_cibus in the same order they were captured, so if the top field was
4962306a36Sopenharmony_cicaptured first (is the older field), the top field is also transmitted
5062306a36Sopenharmony_cifirst on the bus.
5162306a36Sopenharmony_ci
5262306a36Sopenharmony_ciAll video capture and output devices must report the current field
5362306a36Sopenharmony_ciorder. Some drivers may permit the selection of a different order, to
5462306a36Sopenharmony_cithis end applications initialize the ``field`` field of struct
5562306a36Sopenharmony_ci:c:type:`v4l2_pix_format` before calling the
5662306a36Sopenharmony_ci:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl. If this is not desired it
5762306a36Sopenharmony_cishould have the value ``V4L2_FIELD_ANY`` (0).
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_ci
6062306a36Sopenharmony_cienum v4l2_field
6162306a36Sopenharmony_ci===============
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ci.. c:type:: v4l2_field
6462306a36Sopenharmony_ci
6562306a36Sopenharmony_ci.. tabularcolumns:: |p{5.8cm}|p{0.6cm}|p{10.9cm}|
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci.. cssclass:: longtable
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ci.. flat-table::
7062306a36Sopenharmony_ci    :header-rows:  0
7162306a36Sopenharmony_ci    :stub-columns: 0
7262306a36Sopenharmony_ci    :widths:       3 1 4
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ci    * - ``V4L2_FIELD_ANY``
7562306a36Sopenharmony_ci      - 0
7662306a36Sopenharmony_ci      - Applications request this field order when any field format
7762306a36Sopenharmony_ci	is acceptable. Drivers choose depending on hardware capabilities or
7862306a36Sopenharmony_ci	e.g. the requested image size, and return the actual field order.
7962306a36Sopenharmony_ci	Drivers must never return ``V4L2_FIELD_ANY``.
8062306a36Sopenharmony_ci	If multiple field orders are possible the
8162306a36Sopenharmony_ci	driver must choose one of the possible field orders during
8262306a36Sopenharmony_ci	:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` or
8362306a36Sopenharmony_ci	:ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>`. struct
8462306a36Sopenharmony_ci	:c:type:`v4l2_buffer` ``field`` can never be
8562306a36Sopenharmony_ci	``V4L2_FIELD_ANY``.
8662306a36Sopenharmony_ci    * - ``V4L2_FIELD_NONE``
8762306a36Sopenharmony_ci      - 1
8862306a36Sopenharmony_ci      - Images are in progressive (frame-based) format, not interlaced
8962306a36Sopenharmony_ci        (field-based).
9062306a36Sopenharmony_ci    * - ``V4L2_FIELD_TOP``
9162306a36Sopenharmony_ci      - 2
9262306a36Sopenharmony_ci      - Images consist of the top (aka odd) field only.
9362306a36Sopenharmony_ci    * - ``V4L2_FIELD_BOTTOM``
9462306a36Sopenharmony_ci      - 3
9562306a36Sopenharmony_ci      - Images consist of the bottom (aka even) field only. Applications
9662306a36Sopenharmony_ci	may wish to prevent a device from capturing interlaced images
9762306a36Sopenharmony_ci	because they will have "comb" or "feathering" artefacts around
9862306a36Sopenharmony_ci	moving objects.
9962306a36Sopenharmony_ci    * - ``V4L2_FIELD_INTERLACED``
10062306a36Sopenharmony_ci      - 4
10162306a36Sopenharmony_ci      - Images contain both fields, interleaved line by line. The temporal
10262306a36Sopenharmony_ci	order of the fields (whether the top or bottom field is older)
10362306a36Sopenharmony_ci	depends on the current video standard. In M/NTSC the bottom
10462306a36Sopenharmony_ci	field is the older field. In all other standards the top field
10562306a36Sopenharmony_ci	is the older field.
10662306a36Sopenharmony_ci    * - ``V4L2_FIELD_SEQ_TB``
10762306a36Sopenharmony_ci      - 5
10862306a36Sopenharmony_ci      - Images contain both fields, the top field lines are stored first
10962306a36Sopenharmony_ci	in memory, immediately followed by the bottom field lines. Fields
11062306a36Sopenharmony_ci	are always stored in temporal order, the older one first in
11162306a36Sopenharmony_ci	memory. Image sizes refer to the frame, not fields.
11262306a36Sopenharmony_ci    * - ``V4L2_FIELD_SEQ_BT``
11362306a36Sopenharmony_ci      - 6
11462306a36Sopenharmony_ci      - Images contain both fields, the bottom field lines are stored
11562306a36Sopenharmony_ci	first in memory, immediately followed by the top field lines.
11662306a36Sopenharmony_ci	Fields are always stored in temporal order, the older one first in
11762306a36Sopenharmony_ci	memory. Image sizes refer to the frame, not fields.
11862306a36Sopenharmony_ci    * - ``V4L2_FIELD_ALTERNATE``
11962306a36Sopenharmony_ci      - 7
12062306a36Sopenharmony_ci      - The two fields of a frame are passed in separate buffers, in
12162306a36Sopenharmony_ci	temporal order, i. e. the older one first. To indicate the field
12262306a36Sopenharmony_ci	parity (whether the current field is a top or bottom field) the
12362306a36Sopenharmony_ci	driver or application, depending on data direction, must set
12462306a36Sopenharmony_ci	struct :c:type:`v4l2_buffer` ``field`` to
12562306a36Sopenharmony_ci	``V4L2_FIELD_TOP`` or ``V4L2_FIELD_BOTTOM``. Any two successive
12662306a36Sopenharmony_ci	fields pair to build a frame. If fields are successive, without
12762306a36Sopenharmony_ci	any dropped fields between them (fields can drop individually),
12862306a36Sopenharmony_ci	can be determined from the struct
12962306a36Sopenharmony_ci	:c:type:`v4l2_buffer` ``sequence`` field. This
13062306a36Sopenharmony_ci	format cannot be selected when using the read/write I/O method
13162306a36Sopenharmony_ci	since there is no way to communicate if a field was a top or
13262306a36Sopenharmony_ci	bottom field.
13362306a36Sopenharmony_ci    * - ``V4L2_FIELD_INTERLACED_TB``
13462306a36Sopenharmony_ci      - 8
13562306a36Sopenharmony_ci      - Images contain both fields, interleaved line by line, top field
13662306a36Sopenharmony_ci	first. The top field is the older field.
13762306a36Sopenharmony_ci    * - ``V4L2_FIELD_INTERLACED_BT``
13862306a36Sopenharmony_ci      - 9
13962306a36Sopenharmony_ci      - Images contain both fields, interleaved line by line, top field
14062306a36Sopenharmony_ci	first. The bottom field is the older field.
14162306a36Sopenharmony_ci
14262306a36Sopenharmony_ci
14362306a36Sopenharmony_ci
14462306a36Sopenharmony_ci.. _fieldseq-tb:
14562306a36Sopenharmony_ci
14662306a36Sopenharmony_ciField Order, Top Field First Transmitted
14762306a36Sopenharmony_ci========================================
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ci.. kernel-figure:: fieldseq_tb.svg
15062306a36Sopenharmony_ci    :alt:    fieldseq_tb.svg
15162306a36Sopenharmony_ci    :align:  center
15262306a36Sopenharmony_ci
15362306a36Sopenharmony_ci    Field Order, Top Field First Transmitted
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_ci
15662306a36Sopenharmony_ci.. _fieldseq-bt:
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_ciField Order, Bottom Field First Transmitted
15962306a36Sopenharmony_ci===========================================
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_ci.. kernel-figure:: fieldseq_bt.svg
16262306a36Sopenharmony_ci    :alt:    fieldseq_bt.svg
16362306a36Sopenharmony_ci    :align:  center
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_ci    Field Order, Bottom Field First Transmitted
166