1*4882a593Smuzhiyun.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later 2*4882a593Smuzhiyun 3*4882a593Smuzhiyun.. _field-order: 4*4882a593Smuzhiyun 5*4882a593Smuzhiyun*********** 6*4882a593SmuzhiyunField Order 7*4882a593Smuzhiyun*********** 8*4882a593Smuzhiyun 9*4882a593SmuzhiyunWe have to distinguish between progressive and interlaced video. 10*4882a593SmuzhiyunProgressive video transmits all lines of a video image sequentially. 11*4882a593SmuzhiyunInterlaced video divides an image into two fields, containing only the 12*4882a593Smuzhiyunodd and even lines of the image, respectively. Alternating the so called 13*4882a593Smuzhiyunodd and even field are transmitted, and due to a small delay between 14*4882a593Smuzhiyunfields a cathode ray TV displays the lines interleaved, yielding the 15*4882a593Smuzhiyunoriginal frame. This curious technique was invented because at refresh 16*4882a593Smuzhiyunrates similar to film the image would fade out too quickly. Transmitting 17*4882a593Smuzhiyunfields reduces the flicker without the necessity of doubling the frame 18*4882a593Smuzhiyunrate and with it the bandwidth required for each channel. 19*4882a593Smuzhiyun 20*4882a593SmuzhiyunIt is important to understand a video camera does not expose one frame 21*4882a593Smuzhiyunat a time, merely transmitting the frames separated into fields. The 22*4882a593Smuzhiyunfields are in fact captured at two different instances in time. An 23*4882a593Smuzhiyunobject on screen may well move between one field and the next. For 24*4882a593Smuzhiyunapplications analysing motion it is of paramount importance to recognize 25*4882a593Smuzhiyunwhich field of a frame is older, the *temporal order*. 26*4882a593Smuzhiyun 27*4882a593SmuzhiyunWhen the driver provides or accepts images field by field rather than 28*4882a593Smuzhiyuninterleaved, it is also important applications understand how the fields 29*4882a593Smuzhiyuncombine to frames. We distinguish between top (aka odd) and bottom (aka 30*4882a593Smuzhiyuneven) fields, the *spatial order*: The first line of the top field is 31*4882a593Smuzhiyunthe first line of an interlaced frame, the first line of the bottom 32*4882a593Smuzhiyunfield is the second line of that frame. 33*4882a593Smuzhiyun 34*4882a593SmuzhiyunHowever because fields were captured one after the other, arguing 35*4882a593Smuzhiyunwhether a frame commences with the top or bottom field is pointless. Any 36*4882a593Smuzhiyuntwo successive top and bottom, or bottom and top fields yield a valid 37*4882a593Smuzhiyunframe. Only when the source was progressive to begin with, e. g. when 38*4882a593Smuzhiyuntransferring film to video, two fields may come from the same frame, 39*4882a593Smuzhiyuncreating a natural order. 40*4882a593Smuzhiyun 41*4882a593SmuzhiyunCounter to intuition the top field is not necessarily the older field. 42*4882a593SmuzhiyunWhether the older field contains the top or bottom lines is a convention 43*4882a593Smuzhiyundetermined by the video standard. Hence the distinction between temporal 44*4882a593Smuzhiyunand spatial order of fields. The diagrams below should make this 45*4882a593Smuzhiyunclearer. 46*4882a593Smuzhiyun 47*4882a593SmuzhiyunIn V4L it is assumed that all video cameras transmit fields on the media 48*4882a593Smuzhiyunbus in the same order they were captured, so if the top field was 49*4882a593Smuzhiyuncaptured first (is the older field), the top field is also transmitted 50*4882a593Smuzhiyunfirst on the bus. 51*4882a593Smuzhiyun 52*4882a593SmuzhiyunAll video capture and output devices must report the current field 53*4882a593Smuzhiyunorder. Some drivers may permit the selection of a different order, to 54*4882a593Smuzhiyunthis end applications initialize the ``field`` field of struct 55*4882a593Smuzhiyun:c:type:`v4l2_pix_format` before calling the 56*4882a593Smuzhiyun:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl. If this is not desired it 57*4882a593Smuzhiyunshould have the value ``V4L2_FIELD_ANY`` (0). 58*4882a593Smuzhiyun 59*4882a593Smuzhiyun 60*4882a593Smuzhiyunenum v4l2_field 61*4882a593Smuzhiyun=============== 62*4882a593Smuzhiyun 63*4882a593Smuzhiyun.. c:type:: v4l2_field 64*4882a593Smuzhiyun 65*4882a593Smuzhiyun.. tabularcolumns:: |p{5.8cm}|p{0.6cm}|p{11.1cm}| 66*4882a593Smuzhiyun 67*4882a593Smuzhiyun.. cssclass:: longtable 68*4882a593Smuzhiyun 69*4882a593Smuzhiyun.. flat-table:: 70*4882a593Smuzhiyun :header-rows: 0 71*4882a593Smuzhiyun :stub-columns: 0 72*4882a593Smuzhiyun :widths: 3 1 4 73*4882a593Smuzhiyun 74*4882a593Smuzhiyun * - ``V4L2_FIELD_ANY`` 75*4882a593Smuzhiyun - 0 76*4882a593Smuzhiyun - Applications request this field order when any field format 77*4882a593Smuzhiyun is acceptable. Drivers choose depending on hardware capabilities or 78*4882a593Smuzhiyun e.g. the requested image size, and return the actual field order. 79*4882a593Smuzhiyun Drivers must never return ``V4L2_FIELD_ANY``. 80*4882a593Smuzhiyun If multiple field orders are possible the 81*4882a593Smuzhiyun driver must choose one of the possible field orders during 82*4882a593Smuzhiyun :ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` or 83*4882a593Smuzhiyun :ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>`. struct 84*4882a593Smuzhiyun :c:type:`v4l2_buffer` ``field`` can never be 85*4882a593Smuzhiyun ``V4L2_FIELD_ANY``. 86*4882a593Smuzhiyun * - ``V4L2_FIELD_NONE`` 87*4882a593Smuzhiyun - 1 88*4882a593Smuzhiyun - Images are in progressive (frame-based) format, not interlaced 89*4882a593Smuzhiyun (field-based). 90*4882a593Smuzhiyun * - ``V4L2_FIELD_TOP`` 91*4882a593Smuzhiyun - 2 92*4882a593Smuzhiyun - Images consist of the top (aka odd) field only. 93*4882a593Smuzhiyun * - ``V4L2_FIELD_BOTTOM`` 94*4882a593Smuzhiyun - 3 95*4882a593Smuzhiyun - Images consist of the bottom (aka even) field only. Applications 96*4882a593Smuzhiyun may wish to prevent a device from capturing interlaced images 97*4882a593Smuzhiyun because they will have "comb" or "feathering" artefacts around 98*4882a593Smuzhiyun moving objects. 99*4882a593Smuzhiyun * - ``V4L2_FIELD_INTERLACED`` 100*4882a593Smuzhiyun - 4 101*4882a593Smuzhiyun - Images contain both fields, interleaved line by line. The temporal 102*4882a593Smuzhiyun order of the fields (whether the top or bottom field is older) 103*4882a593Smuzhiyun depends on the current video standard. In M/NTSC the bottom 104*4882a593Smuzhiyun field is the older field. In all other standards the top field 105*4882a593Smuzhiyun is the older field. 106*4882a593Smuzhiyun * - ``V4L2_FIELD_SEQ_TB`` 107*4882a593Smuzhiyun - 5 108*4882a593Smuzhiyun - Images contain both fields, the top field lines are stored first 109*4882a593Smuzhiyun in memory, immediately followed by the bottom field lines. Fields 110*4882a593Smuzhiyun are always stored in temporal order, the older one first in 111*4882a593Smuzhiyun memory. Image sizes refer to the frame, not fields. 112*4882a593Smuzhiyun * - ``V4L2_FIELD_SEQ_BT`` 113*4882a593Smuzhiyun - 6 114*4882a593Smuzhiyun - Images contain both fields, the bottom field lines are stored 115*4882a593Smuzhiyun first in memory, immediately followed by the top field lines. 116*4882a593Smuzhiyun Fields are always stored in temporal order, the older one first in 117*4882a593Smuzhiyun memory. Image sizes refer to the frame, not fields. 118*4882a593Smuzhiyun * - ``V4L2_FIELD_ALTERNATE`` 119*4882a593Smuzhiyun - 7 120*4882a593Smuzhiyun - The two fields of a frame are passed in separate buffers, in 121*4882a593Smuzhiyun temporal order, i. e. the older one first. To indicate the field 122*4882a593Smuzhiyun parity (whether the current field is a top or bottom field) the 123*4882a593Smuzhiyun driver or application, depending on data direction, must set 124*4882a593Smuzhiyun struct :c:type:`v4l2_buffer` ``field`` to 125*4882a593Smuzhiyun ``V4L2_FIELD_TOP`` or ``V4L2_FIELD_BOTTOM``. Any two successive 126*4882a593Smuzhiyun fields pair to build a frame. If fields are successive, without 127*4882a593Smuzhiyun any dropped fields between them (fields can drop individually), 128*4882a593Smuzhiyun can be determined from the struct 129*4882a593Smuzhiyun :c:type:`v4l2_buffer` ``sequence`` field. This 130*4882a593Smuzhiyun format cannot be selected when using the read/write I/O method 131*4882a593Smuzhiyun since there is no way to communicate if a field was a top or 132*4882a593Smuzhiyun bottom field. 133*4882a593Smuzhiyun * - ``V4L2_FIELD_INTERLACED_TB`` 134*4882a593Smuzhiyun - 8 135*4882a593Smuzhiyun - Images contain both fields, interleaved line by line, top field 136*4882a593Smuzhiyun first. The top field is the older field. 137*4882a593Smuzhiyun * - ``V4L2_FIELD_INTERLACED_BT`` 138*4882a593Smuzhiyun - 9 139*4882a593Smuzhiyun - Images contain both fields, interleaved line by line, top field 140*4882a593Smuzhiyun first. The bottom field is the older field. 141*4882a593Smuzhiyun 142*4882a593Smuzhiyun 143*4882a593Smuzhiyun 144*4882a593Smuzhiyun.. _fieldseq-tb: 145*4882a593Smuzhiyun 146*4882a593SmuzhiyunField Order, Top Field First Transmitted 147*4882a593Smuzhiyun======================================== 148*4882a593Smuzhiyun 149*4882a593Smuzhiyun.. kernel-figure:: fieldseq_tb.svg 150*4882a593Smuzhiyun :alt: fieldseq_tb.svg 151*4882a593Smuzhiyun :align: center 152*4882a593Smuzhiyun 153*4882a593Smuzhiyun Field Order, Top Field First Transmitted 154*4882a593Smuzhiyun 155*4882a593Smuzhiyun 156*4882a593Smuzhiyun.. _fieldseq-bt: 157*4882a593Smuzhiyun 158*4882a593SmuzhiyunField Order, Bottom Field First Transmitted 159*4882a593Smuzhiyun=========================================== 160*4882a593Smuzhiyun 161*4882a593Smuzhiyun.. kernel-figure:: fieldseq_bt.svg 162*4882a593Smuzhiyun :alt: fieldseq_bt.svg 163*4882a593Smuzhiyun :align: center 164*4882a593Smuzhiyun 165*4882a593Smuzhiyun Field Order, Bottom Field First Transmitted 166