xref: /openbmc/linux/Documentation/userspace-api/media/v4l/field-order.rst (revision 54f38fcae536ea202ce7d6a359521492fba30c1f)
1*54f38fcaSMauro Carvalho Chehab.. Permission is granted to copy, distribute and/or modify this
2*54f38fcaSMauro Carvalho Chehab.. document under the terms of the GNU Free Documentation License,
3*54f38fcaSMauro Carvalho Chehab.. Version 1.1 or any later version published by the Free Software
4*54f38fcaSMauro Carvalho Chehab.. Foundation, with no Invariant Sections, no Front-Cover Texts
5*54f38fcaSMauro Carvalho Chehab.. and no Back-Cover Texts. A copy of the license is included at
6*54f38fcaSMauro Carvalho Chehab.. Documentation/userspace-api/media/fdl-appendix.rst.
7*54f38fcaSMauro Carvalho Chehab..
8*54f38fcaSMauro Carvalho Chehab.. TODO: replace it to GFDL-1.1-or-later WITH no-invariant-sections
9*54f38fcaSMauro Carvalho Chehab
10*54f38fcaSMauro Carvalho Chehab.. _field-order:
11*54f38fcaSMauro Carvalho Chehab
12*54f38fcaSMauro Carvalho Chehab***********
13*54f38fcaSMauro Carvalho ChehabField Order
14*54f38fcaSMauro Carvalho Chehab***********
15*54f38fcaSMauro Carvalho Chehab
16*54f38fcaSMauro Carvalho ChehabWe have to distinguish between progressive and interlaced video.
17*54f38fcaSMauro Carvalho ChehabProgressive video transmits all lines of a video image sequentially.
18*54f38fcaSMauro Carvalho ChehabInterlaced video divides an image into two fields, containing only the
19*54f38fcaSMauro Carvalho Chehabodd and even lines of the image, respectively. Alternating the so called
20*54f38fcaSMauro Carvalho Chehabodd and even field are transmitted, and due to a small delay between
21*54f38fcaSMauro Carvalho Chehabfields a cathode ray TV displays the lines interleaved, yielding the
22*54f38fcaSMauro Carvalho Chehaboriginal frame. This curious technique was invented because at refresh
23*54f38fcaSMauro Carvalho Chehabrates similar to film the image would fade out too quickly. Transmitting
24*54f38fcaSMauro Carvalho Chehabfields reduces the flicker without the necessity of doubling the frame
25*54f38fcaSMauro Carvalho Chehabrate and with it the bandwidth required for each channel.
26*54f38fcaSMauro Carvalho Chehab
27*54f38fcaSMauro Carvalho ChehabIt is important to understand a video camera does not expose one frame
28*54f38fcaSMauro Carvalho Chehabat a time, merely transmitting the frames separated into fields. The
29*54f38fcaSMauro Carvalho Chehabfields are in fact captured at two different instances in time. An
30*54f38fcaSMauro Carvalho Chehabobject on screen may well move between one field and the next. For
31*54f38fcaSMauro Carvalho Chehabapplications analysing motion it is of paramount importance to recognize
32*54f38fcaSMauro Carvalho Chehabwhich field of a frame is older, the *temporal order*.
33*54f38fcaSMauro Carvalho Chehab
34*54f38fcaSMauro Carvalho ChehabWhen the driver provides or accepts images field by field rather than
35*54f38fcaSMauro Carvalho Chehabinterleaved, it is also important applications understand how the fields
36*54f38fcaSMauro Carvalho Chehabcombine to frames. We distinguish between top (aka odd) and bottom (aka
37*54f38fcaSMauro Carvalho Chehabeven) fields, the *spatial order*: The first line of the top field is
38*54f38fcaSMauro Carvalho Chehabthe first line of an interlaced frame, the first line of the bottom
39*54f38fcaSMauro Carvalho Chehabfield is the second line of that frame.
40*54f38fcaSMauro Carvalho Chehab
41*54f38fcaSMauro Carvalho ChehabHowever because fields were captured one after the other, arguing
42*54f38fcaSMauro Carvalho Chehabwhether a frame commences with the top or bottom field is pointless. Any
43*54f38fcaSMauro Carvalho Chehabtwo successive top and bottom, or bottom and top fields yield a valid
44*54f38fcaSMauro Carvalho Chehabframe. Only when the source was progressive to begin with, e. g. when
45*54f38fcaSMauro Carvalho Chehabtransferring film to video, two fields may come from the same frame,
46*54f38fcaSMauro Carvalho Chehabcreating a natural order.
47*54f38fcaSMauro Carvalho Chehab
48*54f38fcaSMauro Carvalho ChehabCounter to intuition the top field is not necessarily the older field.
49*54f38fcaSMauro Carvalho ChehabWhether the older field contains the top or bottom lines is a convention
50*54f38fcaSMauro Carvalho Chehabdetermined by the video standard. Hence the distinction between temporal
51*54f38fcaSMauro Carvalho Chehaband spatial order of fields. The diagrams below should make this
52*54f38fcaSMauro Carvalho Chehabclearer.
53*54f38fcaSMauro Carvalho Chehab
54*54f38fcaSMauro Carvalho ChehabIn V4L it is assumed that all video cameras transmit fields on the media
55*54f38fcaSMauro Carvalho Chehabbus in the same order they were captured, so if the top field was
56*54f38fcaSMauro Carvalho Chehabcaptured first (is the older field), the top field is also transmitted
57*54f38fcaSMauro Carvalho Chehabfirst on the bus.
58*54f38fcaSMauro Carvalho Chehab
59*54f38fcaSMauro Carvalho ChehabAll video capture and output devices must report the current field
60*54f38fcaSMauro Carvalho Chehaborder. Some drivers may permit the selection of a different order, to
61*54f38fcaSMauro Carvalho Chehabthis end applications initialize the ``field`` field of struct
62*54f38fcaSMauro Carvalho Chehab:c:type:`v4l2_pix_format` before calling the
63*54f38fcaSMauro Carvalho Chehab:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` ioctl. If this is not desired it
64*54f38fcaSMauro Carvalho Chehabshould have the value ``V4L2_FIELD_ANY`` (0).
65*54f38fcaSMauro Carvalho Chehab
66*54f38fcaSMauro Carvalho Chehab
67*54f38fcaSMauro Carvalho Chehabenum v4l2_field
68*54f38fcaSMauro Carvalho Chehab===============
69*54f38fcaSMauro Carvalho Chehab
70*54f38fcaSMauro Carvalho Chehab.. c:type:: v4l2_field
71*54f38fcaSMauro Carvalho Chehab
72*54f38fcaSMauro Carvalho Chehab.. tabularcolumns:: |p{5.8cm}|p{0.6cm}|p{11.1cm}|
73*54f38fcaSMauro Carvalho Chehab
74*54f38fcaSMauro Carvalho Chehab.. cssclass:: longtable
75*54f38fcaSMauro Carvalho Chehab
76*54f38fcaSMauro Carvalho Chehab.. flat-table::
77*54f38fcaSMauro Carvalho Chehab    :header-rows:  0
78*54f38fcaSMauro Carvalho Chehab    :stub-columns: 0
79*54f38fcaSMauro Carvalho Chehab    :widths:       3 1 4
80*54f38fcaSMauro Carvalho Chehab
81*54f38fcaSMauro Carvalho Chehab    * - ``V4L2_FIELD_ANY``
82*54f38fcaSMauro Carvalho Chehab      - 0
83*54f38fcaSMauro Carvalho Chehab      - Applications request this field order when any field format
84*54f38fcaSMauro Carvalho Chehab	is acceptable. Drivers choose depending on hardware capabilities or
85*54f38fcaSMauro Carvalho Chehab	e.g. the requested image size, and return the actual field order.
86*54f38fcaSMauro Carvalho Chehab	Drivers must never return ``V4L2_FIELD_ANY``.
87*54f38fcaSMauro Carvalho Chehab	If multiple field orders are possible the
88*54f38fcaSMauro Carvalho Chehab	driver must choose one of the possible field orders during
89*54f38fcaSMauro Carvalho Chehab	:ref:`VIDIOC_S_FMT <VIDIOC_G_FMT>` or
90*54f38fcaSMauro Carvalho Chehab	:ref:`VIDIOC_TRY_FMT <VIDIOC_G_FMT>`. struct
91*54f38fcaSMauro Carvalho Chehab	:c:type:`v4l2_buffer` ``field`` can never be
92*54f38fcaSMauro Carvalho Chehab	``V4L2_FIELD_ANY``.
93*54f38fcaSMauro Carvalho Chehab    * - ``V4L2_FIELD_NONE``
94*54f38fcaSMauro Carvalho Chehab      - 1
95*54f38fcaSMauro Carvalho Chehab      - Images are in progressive (frame-based) format, not interlaced
96*54f38fcaSMauro Carvalho Chehab        (field-based).
97*54f38fcaSMauro Carvalho Chehab    * - ``V4L2_FIELD_TOP``
98*54f38fcaSMauro Carvalho Chehab      - 2
99*54f38fcaSMauro Carvalho Chehab      - Images consist of the top (aka odd) field only.
100*54f38fcaSMauro Carvalho Chehab    * - ``V4L2_FIELD_BOTTOM``
101*54f38fcaSMauro Carvalho Chehab      - 3
102*54f38fcaSMauro Carvalho Chehab      - Images consist of the bottom (aka even) field only. Applications
103*54f38fcaSMauro Carvalho Chehab	may wish to prevent a device from capturing interlaced images
104*54f38fcaSMauro Carvalho Chehab	because they will have "comb" or "feathering" artefacts around
105*54f38fcaSMauro Carvalho Chehab	moving objects.
106*54f38fcaSMauro Carvalho Chehab    * - ``V4L2_FIELD_INTERLACED``
107*54f38fcaSMauro Carvalho Chehab      - 4
108*54f38fcaSMauro Carvalho Chehab      - Images contain both fields, interleaved line by line. The temporal
109*54f38fcaSMauro Carvalho Chehab	order of the fields (whether the top or bottom field is older)
110*54f38fcaSMauro Carvalho Chehab	depends on the current video standard. In M/NTSC the bottom
111*54f38fcaSMauro Carvalho Chehab	field is the older field. In all other standards the top field
112*54f38fcaSMauro Carvalho Chehab	is the older field.
113*54f38fcaSMauro Carvalho Chehab    * - ``V4L2_FIELD_SEQ_TB``
114*54f38fcaSMauro Carvalho Chehab      - 5
115*54f38fcaSMauro Carvalho Chehab      - Images contain both fields, the top field lines are stored first
116*54f38fcaSMauro Carvalho Chehab	in memory, immediately followed by the bottom field lines. Fields
117*54f38fcaSMauro Carvalho Chehab	are always stored in temporal order, the older one first in
118*54f38fcaSMauro Carvalho Chehab	memory. Image sizes refer to the frame, not fields.
119*54f38fcaSMauro Carvalho Chehab    * - ``V4L2_FIELD_SEQ_BT``
120*54f38fcaSMauro Carvalho Chehab      - 6
121*54f38fcaSMauro Carvalho Chehab      - Images contain both fields, the bottom field lines are stored
122*54f38fcaSMauro Carvalho Chehab	first in memory, immediately followed by the top field lines.
123*54f38fcaSMauro Carvalho Chehab	Fields are always stored in temporal order, the older one first in
124*54f38fcaSMauro Carvalho Chehab	memory. Image sizes refer to the frame, not fields.
125*54f38fcaSMauro Carvalho Chehab    * - ``V4L2_FIELD_ALTERNATE``
126*54f38fcaSMauro Carvalho Chehab      - 7
127*54f38fcaSMauro Carvalho Chehab      - The two fields of a frame are passed in separate buffers, in
128*54f38fcaSMauro Carvalho Chehab	temporal order, i. e. the older one first. To indicate the field
129*54f38fcaSMauro Carvalho Chehab	parity (whether the current field is a top or bottom field) the
130*54f38fcaSMauro Carvalho Chehab	driver or application, depending on data direction, must set
131*54f38fcaSMauro Carvalho Chehab	struct :c:type:`v4l2_buffer` ``field`` to
132*54f38fcaSMauro Carvalho Chehab	``V4L2_FIELD_TOP`` or ``V4L2_FIELD_BOTTOM``. Any two successive
133*54f38fcaSMauro Carvalho Chehab	fields pair to build a frame. If fields are successive, without
134*54f38fcaSMauro Carvalho Chehab	any dropped fields between them (fields can drop individually),
135*54f38fcaSMauro Carvalho Chehab	can be determined from the struct
136*54f38fcaSMauro Carvalho Chehab	:c:type:`v4l2_buffer` ``sequence`` field. This
137*54f38fcaSMauro Carvalho Chehab	format cannot be selected when using the read/write I/O method
138*54f38fcaSMauro Carvalho Chehab	since there is no way to communicate if a field was a top or
139*54f38fcaSMauro Carvalho Chehab	bottom field.
140*54f38fcaSMauro Carvalho Chehab    * - ``V4L2_FIELD_INTERLACED_TB``
141*54f38fcaSMauro Carvalho Chehab      - 8
142*54f38fcaSMauro Carvalho Chehab      - Images contain both fields, interleaved line by line, top field
143*54f38fcaSMauro Carvalho Chehab	first. The top field is the older field.
144*54f38fcaSMauro Carvalho Chehab    * - ``V4L2_FIELD_INTERLACED_BT``
145*54f38fcaSMauro Carvalho Chehab      - 9
146*54f38fcaSMauro Carvalho Chehab      - Images contain both fields, interleaved line by line, top field
147*54f38fcaSMauro Carvalho Chehab	first. The bottom field is the older field.
148*54f38fcaSMauro Carvalho Chehab
149*54f38fcaSMauro Carvalho Chehab
150*54f38fcaSMauro Carvalho Chehab
151*54f38fcaSMauro Carvalho Chehab.. _fieldseq-tb:
152*54f38fcaSMauro Carvalho Chehab
153*54f38fcaSMauro Carvalho ChehabField Order, Top Field First Transmitted
154*54f38fcaSMauro Carvalho Chehab========================================
155*54f38fcaSMauro Carvalho Chehab
156*54f38fcaSMauro Carvalho Chehab.. kernel-figure:: fieldseq_tb.svg
157*54f38fcaSMauro Carvalho Chehab    :alt:    fieldseq_tb.svg
158*54f38fcaSMauro Carvalho Chehab    :align:  center
159*54f38fcaSMauro Carvalho Chehab
160*54f38fcaSMauro Carvalho Chehab    Field Order, Top Field First Transmitted
161*54f38fcaSMauro Carvalho Chehab
162*54f38fcaSMauro Carvalho Chehab
163*54f38fcaSMauro Carvalho Chehab.. _fieldseq-bt:
164*54f38fcaSMauro Carvalho Chehab
165*54f38fcaSMauro Carvalho ChehabField Order, Bottom Field First Transmitted
166*54f38fcaSMauro Carvalho Chehab===========================================
167*54f38fcaSMauro Carvalho Chehab
168*54f38fcaSMauro Carvalho Chehab.. kernel-figure:: fieldseq_bt.svg
169*54f38fcaSMauro Carvalho Chehab    :alt:    fieldseq_bt.svg
170*54f38fcaSMauro Carvalho Chehab    :align:  center
171*54f38fcaSMauro Carvalho Chehab
172*54f38fcaSMauro Carvalho Chehab    Field Order, Bottom Field First Transmitted
173