1059b1c5bSMauro Carvalho Chehab.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 254f38fcaSMauro Carvalho Chehab 354f38fcaSMauro Carvalho Chehab.. _field-order: 454f38fcaSMauro Carvalho Chehab 554f38fcaSMauro Carvalho Chehab*********** 654f38fcaSMauro Carvalho ChehabField Order 754f38fcaSMauro Carvalho Chehab*********** 854f38fcaSMauro Carvalho Chehab 954f38fcaSMauro Carvalho ChehabWe have to distinguish between progressive and interlaced video. 1054f38fcaSMauro Carvalho ChehabProgressive video transmits all lines of a video image sequentially. 1154f38fcaSMauro Carvalho ChehabInterlaced video divides an image into two fields, containing only the 1254f38fcaSMauro Carvalho Chehabodd and even lines of the image, respectively. Alternating the so called 1354f38fcaSMauro Carvalho Chehabodd and even field are transmitted, and due to a small delay between 1454f38fcaSMauro Carvalho Chehabfields a cathode ray TV displays the lines interleaved, yielding the 1554f38fcaSMauro Carvalho Chehaboriginal frame. This curious technique was invented because at refresh 1654f38fcaSMauro Carvalho Chehabrates similar to film the image would fade out too quickly. Transmitting 1754f38fcaSMauro Carvalho Chehabfields reduces the flicker without the necessity of doubling the frame 1854f38fcaSMauro Carvalho Chehabrate and with it the bandwidth required for each channel. 1954f38fcaSMauro Carvalho Chehab 2054f38fcaSMauro Carvalho ChehabIt is important to understand a video camera does not expose one frame 2154f38fcaSMauro Carvalho Chehabat a time, merely transmitting the frames separated into fields. The 2254f38fcaSMauro Carvalho Chehabfields are in fact captured at two different instances in time. An 2354f38fcaSMauro Carvalho Chehabobject on screen may well move between one field and the next. For 2454f38fcaSMauro Carvalho Chehabapplications analysing motion it is of paramount importance to recognize 2554f38fcaSMauro Carvalho Chehabwhich field of a frame is older, the *temporal order*. 2654f38fcaSMauro Carvalho Chehab 2754f38fcaSMauro Carvalho ChehabWhen the driver provides or accepts images field by field rather than 2854f38fcaSMauro Carvalho Chehabinterleaved, it is also important applications understand how the fields 2954f38fcaSMauro Carvalho Chehabcombine to frames. We distinguish between top (aka odd) and bottom (aka 3054f38fcaSMauro Carvalho Chehabeven) fields, the *spatial order*: The first line of the top field is 3154f38fcaSMauro Carvalho Chehabthe first line of an interlaced frame, the first line of the bottom 3254f38fcaSMauro Carvalho Chehabfield is the second line of that frame. 3354f38fcaSMauro Carvalho Chehab 3454f38fcaSMauro Carvalho ChehabHowever because fields were captured one after the other, arguing 3554f38fcaSMauro Carvalho Chehabwhether a frame commences with the top or bottom field is pointless. Any 3654f38fcaSMauro Carvalho Chehabtwo successive top and bottom, or bottom and top fields yield a valid 3754f38fcaSMauro Carvalho Chehabframe. Only when the source was progressive to begin with, e. g. when 3854f38fcaSMauro Carvalho Chehabtransferring film to video, two fields may come from the same frame, 3954f38fcaSMauro Carvalho Chehabcreating a natural order. 4054f38fcaSMauro Carvalho Chehab 4154f38fcaSMauro Carvalho ChehabCounter to intuition the top field is not necessarily the older field. 4254f38fcaSMauro Carvalho ChehabWhether the older field contains the top or bottom lines is a convention 4354f38fcaSMauro Carvalho Chehabdetermined by the video standard. Hence the distinction between temporal 4454f38fcaSMauro Carvalho Chehaband spatial order of fields. The diagrams below should make this 4554f38fcaSMauro Carvalho Chehabclearer. 4654f38fcaSMauro Carvalho Chehab 4754f38fcaSMauro Carvalho ChehabIn V4L it is assumed that all video cameras transmit fields on the media 4854f38fcaSMauro Carvalho Chehabbus in the same order they were captured, so if the top field was 4954f38fcaSMauro Carvalho Chehabcaptured first (is the older field), the top field is also transmitted 5054f38fcaSMauro Carvalho Chehabfirst on the bus. 5154f38fcaSMauro Carvalho Chehab 5254f38fcaSMauro Carvalho ChehabAll video capture and output devices must report the current field 5354f38fcaSMauro Carvalho Chehaborder. Some drivers may permit the selection of a different order, to 5454f38fcaSMauro Carvalho Chehabthis end applications initialize the ``field`` field of struct 5554f38fcaSMauro Carvalho Chehab:c:type:`v4l2_pix_format` before calling the 5654f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl. If this is not desired it 5754f38fcaSMauro Carvalho Chehabshould have the value ``V4L2_FIELD_ANY`` (0). 5854f38fcaSMauro Carvalho Chehab 5954f38fcaSMauro Carvalho Chehab 6054f38fcaSMauro Carvalho Chehabenum v4l2_field 6154f38fcaSMauro Carvalho Chehab=============== 6254f38fcaSMauro Carvalho Chehab 6354f38fcaSMauro Carvalho Chehab.. c:type:: v4l2_field 6454f38fcaSMauro Carvalho Chehab 65*fea13a69SMauro Carvalho Chehab.. tabularcolumns:: |p{5.8cm}|p{0.6cm}|p{10.9cm}| 6654f38fcaSMauro Carvalho Chehab 6754f38fcaSMauro Carvalho Chehab.. cssclass:: longtable 6854f38fcaSMauro Carvalho Chehab 6954f38fcaSMauro Carvalho Chehab.. flat-table:: 7054f38fcaSMauro Carvalho Chehab :header-rows: 0 7154f38fcaSMauro Carvalho Chehab :stub-columns: 0 7254f38fcaSMauro Carvalho Chehab :widths: 3 1 4 7354f38fcaSMauro Carvalho Chehab 7454f38fcaSMauro Carvalho Chehab * - ``V4L2_FIELD_ANY`` 7554f38fcaSMauro Carvalho Chehab - 0 7654f38fcaSMauro Carvalho Chehab - Applications request this field order when any field format 7754f38fcaSMauro Carvalho Chehab is acceptable. Drivers choose depending on hardware capabilities or 7854f38fcaSMauro Carvalho Chehab e.g. the requested image size, and return the actual field order. 7954f38fcaSMauro Carvalho Chehab Drivers must never return ``V4L2_FIELD_ANY``. 8054f38fcaSMauro Carvalho Chehab If multiple field orders are possible the 8154f38fcaSMauro Carvalho Chehab driver must choose one of the possible field orders during 8254f38fcaSMauro Carvalho Chehab :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` or 8354f38fcaSMauro Carvalho Chehab :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>`. struct 8454f38fcaSMauro Carvalho Chehab :c:type:`v4l2_buffer` ``field`` can never be 8554f38fcaSMauro Carvalho Chehab ``V4L2_FIELD_ANY``. 8654f38fcaSMauro Carvalho Chehab * - ``V4L2_FIELD_NONE`` 8754f38fcaSMauro Carvalho Chehab - 1 8854f38fcaSMauro Carvalho Chehab - Images are in progressive (frame-based) format, not interlaced 8954f38fcaSMauro Carvalho Chehab (field-based). 9054f38fcaSMauro Carvalho Chehab * - ``V4L2_FIELD_TOP`` 9154f38fcaSMauro Carvalho Chehab - 2 9254f38fcaSMauro Carvalho Chehab - Images consist of the top (aka odd) field only. 9354f38fcaSMauro Carvalho Chehab * - ``V4L2_FIELD_BOTTOM`` 9454f38fcaSMauro Carvalho Chehab - 3 9554f38fcaSMauro Carvalho Chehab - Images consist of the bottom (aka even) field only. Applications 9654f38fcaSMauro Carvalho Chehab may wish to prevent a device from capturing interlaced images 9754f38fcaSMauro Carvalho Chehab because they will have "comb" or "feathering" artefacts around 9854f38fcaSMauro Carvalho Chehab moving objects. 9954f38fcaSMauro Carvalho Chehab * - ``V4L2_FIELD_INTERLACED`` 10054f38fcaSMauro Carvalho Chehab - 4 10154f38fcaSMauro Carvalho Chehab - Images contain both fields, interleaved line by line. The temporal 10254f38fcaSMauro Carvalho Chehab order of the fields (whether the top or bottom field is older) 10354f38fcaSMauro Carvalho Chehab depends on the current video standard. In M/NTSC the bottom 10454f38fcaSMauro Carvalho Chehab field is the older field. In all other standards the top field 10554f38fcaSMauro Carvalho Chehab is the older field. 10654f38fcaSMauro Carvalho Chehab * - ``V4L2_FIELD_SEQ_TB`` 10754f38fcaSMauro Carvalho Chehab - 5 10854f38fcaSMauro Carvalho Chehab - Images contain both fields, the top field lines are stored first 10954f38fcaSMauro Carvalho Chehab in memory, immediately followed by the bottom field lines. Fields 11054f38fcaSMauro Carvalho Chehab are always stored in temporal order, the older one first in 11154f38fcaSMauro Carvalho Chehab memory. Image sizes refer to the frame, not fields. 11254f38fcaSMauro Carvalho Chehab * - ``V4L2_FIELD_SEQ_BT`` 11354f38fcaSMauro Carvalho Chehab - 6 11454f38fcaSMauro Carvalho Chehab - Images contain both fields, the bottom field lines are stored 11554f38fcaSMauro Carvalho Chehab first in memory, immediately followed by the top field lines. 11654f38fcaSMauro Carvalho Chehab Fields are always stored in temporal order, the older one first in 11754f38fcaSMauro Carvalho Chehab memory. Image sizes refer to the frame, not fields. 11854f38fcaSMauro Carvalho Chehab * - ``V4L2_FIELD_ALTERNATE`` 11954f38fcaSMauro Carvalho Chehab - 7 12054f38fcaSMauro Carvalho Chehab - The two fields of a frame are passed in separate buffers, in 12154f38fcaSMauro Carvalho Chehab temporal order, i. e. the older one first. To indicate the field 12254f38fcaSMauro Carvalho Chehab parity (whether the current field is a top or bottom field) the 12354f38fcaSMauro Carvalho Chehab driver or application, depending on data direction, must set 12454f38fcaSMauro Carvalho Chehab struct :c:type:`v4l2_buffer` ``field`` to 12554f38fcaSMauro Carvalho Chehab ``V4L2_FIELD_TOP`` or ``V4L2_FIELD_BOTTOM``. Any two successive 12654f38fcaSMauro Carvalho Chehab fields pair to build a frame. If fields are successive, without 12754f38fcaSMauro Carvalho Chehab any dropped fields between them (fields can drop individually), 12854f38fcaSMauro Carvalho Chehab can be determined from the struct 12954f38fcaSMauro Carvalho Chehab :c:type:`v4l2_buffer` ``sequence`` field. This 13054f38fcaSMauro Carvalho Chehab format cannot be selected when using the read/write I/O method 13154f38fcaSMauro Carvalho Chehab since there is no way to communicate if a field was a top or 13254f38fcaSMauro Carvalho Chehab bottom field. 13354f38fcaSMauro Carvalho Chehab * - ``V4L2_FIELD_INTERLACED_TB`` 13454f38fcaSMauro Carvalho Chehab - 8 13554f38fcaSMauro Carvalho Chehab - Images contain both fields, interleaved line by line, top field 13654f38fcaSMauro Carvalho Chehab first. The top field is the older field. 13754f38fcaSMauro Carvalho Chehab * - ``V4L2_FIELD_INTERLACED_BT`` 13854f38fcaSMauro Carvalho Chehab - 9 13954f38fcaSMauro Carvalho Chehab - Images contain both fields, interleaved line by line, top field 14054f38fcaSMauro Carvalho Chehab first. The bottom field is the older field. 14154f38fcaSMauro Carvalho Chehab 14254f38fcaSMauro Carvalho Chehab 14354f38fcaSMauro Carvalho Chehab 14454f38fcaSMauro Carvalho Chehab.. _fieldseq-tb: 14554f38fcaSMauro Carvalho Chehab 14654f38fcaSMauro Carvalho ChehabField Order, Top Field First Transmitted 14754f38fcaSMauro Carvalho Chehab======================================== 14854f38fcaSMauro Carvalho Chehab 14954f38fcaSMauro Carvalho Chehab.. kernel-figure:: fieldseq_tb.svg 15054f38fcaSMauro Carvalho Chehab :alt: fieldseq_tb.svg 15154f38fcaSMauro Carvalho Chehab :align: center 15254f38fcaSMauro Carvalho Chehab 15354f38fcaSMauro Carvalho Chehab Field Order, Top Field First Transmitted 15454f38fcaSMauro Carvalho Chehab 15554f38fcaSMauro Carvalho Chehab 15654f38fcaSMauro Carvalho Chehab.. _fieldseq-bt: 15754f38fcaSMauro Carvalho Chehab 15854f38fcaSMauro Carvalho ChehabField Order, Bottom Field First Transmitted 15954f38fcaSMauro Carvalho Chehab=========================================== 16054f38fcaSMauro Carvalho Chehab 16154f38fcaSMauro Carvalho Chehab.. kernel-figure:: fieldseq_bt.svg 16254f38fcaSMauro Carvalho Chehab :alt: fieldseq_bt.svg 16354f38fcaSMauro Carvalho Chehab :align: center 16454f38fcaSMauro Carvalho Chehab 16554f38fcaSMauro Carvalho Chehab Field Order, Bottom Field First Transmitted 166