1.. SPDX-License-Identifier: GFDL-1.1-no-invariants-or-later
2
3****************************
4Defining Colorspaces in V4L2
5****************************
6
7In V4L2 colorspaces are defined by four values. The first is the
8colorspace identifier (enum :c:type:`v4l2_colorspace`)
9which defines the chromaticities, the default transfer function, the
10default Y'CbCr encoding and the default quantization method. The second
11is the transfer function identifier (enum
12:c:type:`v4l2_xfer_func`) to specify non-standard
13transfer functions. The third is the Y'CbCr encoding identifier (enum
14:c:type:`v4l2_ycbcr_encoding`) to specify
15non-standard Y'CbCr encodings and the fourth is the quantization
16identifier (enum :c:type:`v4l2_quantization`) to
17specify non-standard quantization methods. Most of the time only the
18colorspace field of struct :c:type:`v4l2_pix_format`
19or struct :c:type:`v4l2_pix_format_mplane`
20needs to be filled in.
21
22.. _hsv-colorspace:
23
24On :ref:`HSV formats <hsv-formats>` the *Hue* is defined as the angle on
25the cylindrical color representation. Usually this angle is measured in
26degrees, i.e. 0-360. When we map this angle value into 8 bits, there are
27two basic ways to do it: Divide the angular value by 2 (0-179), or use the
28whole range, 0-255, dividing the angular value by 1.41. The enum
29:c:type:`v4l2_hsv_encoding` specifies which encoding is used.
30
31.. note:: The default R'G'B' quantization is full range for all
32   colorspaces. HSV formats are always full range.
33
34.. tabularcolumns:: |p{6.7cm}|p{10.8cm}|
35
36.. c:type:: v4l2_colorspace
37
38.. flat-table:: V4L2 Colorspaces
39    :header-rows:  1
40    :stub-columns: 0
41
42    * - Identifier
43      - Details
44    * - ``V4L2_COLORSPACE_DEFAULT``
45      - The default colorspace. This can be used by applications to let
46	the driver fill in the colorspace.
47    * - ``V4L2_COLORSPACE_SMPTE170M``
48      - See :ref:`col-smpte-170m`.
49    * - ``V4L2_COLORSPACE_REC709``
50      - See :ref:`col-rec709`.
51    * - ``V4L2_COLORSPACE_SRGB``
52      - See :ref:`col-srgb`.
53    * - ``V4L2_COLORSPACE_OPRGB``
54      - See :ref:`col-oprgb`.
55    * - ``V4L2_COLORSPACE_BT2020``
56      - See :ref:`col-bt2020`.
57    * - ``V4L2_COLORSPACE_DCI_P3``
58      - See :ref:`col-dcip3`.
59    * - ``V4L2_COLORSPACE_SMPTE240M``
60      - See :ref:`col-smpte-240m`.
61    * - ``V4L2_COLORSPACE_470_SYSTEM_M``
62      - See :ref:`col-sysm`.
63    * - ``V4L2_COLORSPACE_470_SYSTEM_BG``
64      - See :ref:`col-sysbg`.
65    * - ``V4L2_COLORSPACE_JPEG``
66      - See :ref:`col-jpeg`.
67    * - ``V4L2_COLORSPACE_RAW``
68      - The raw colorspace. This is used for raw image capture where the
69	image is minimally processed and is using the internal colorspace
70	of the device. The software that processes an image using this
71	'colorspace' will have to know the internals of the capture
72	device.
73
74
75
76.. c:type:: v4l2_xfer_func
77
78.. tabularcolumns:: |p{5.5cm}|p{12.0cm}|
79
80.. flat-table:: V4L2 Transfer Function
81    :header-rows:  1
82    :stub-columns: 0
83
84    * - Identifier
85      - Details
86    * - ``V4L2_XFER_FUNC_DEFAULT``
87      - Use the default transfer function as defined by the colorspace.
88    * - ``V4L2_XFER_FUNC_709``
89      - Use the Rec. 709 transfer function.
90    * - ``V4L2_XFER_FUNC_SRGB``
91      - Use the sRGB transfer function.
92    * - ``V4L2_XFER_FUNC_OPRGB``
93      - Use the opRGB transfer function.
94    * - ``V4L2_XFER_FUNC_SMPTE240M``
95      - Use the SMPTE 240M transfer function.
96    * - ``V4L2_XFER_FUNC_NONE``
97      - Do not use a transfer function (i.e. use linear RGB values).
98    * - ``V4L2_XFER_FUNC_DCI_P3``
99      - Use the DCI-P3 transfer function.
100    * - ``V4L2_XFER_FUNC_SMPTE2084``
101      - Use the SMPTE 2084 transfer function. See :ref:`xf-smpte-2084`.
102
103
104
105.. c:type:: v4l2_ycbcr_encoding
106
107.. tabularcolumns:: |p{7.2cm}|p{10.3cm}|
108
109.. flat-table:: V4L2 Y'CbCr Encodings
110    :header-rows:  1
111    :stub-columns: 0
112
113    * - Identifier
114      - Details
115    * - ``V4L2_YCBCR_ENC_DEFAULT``
116      - Use the default Y'CbCr encoding as defined by the colorspace.
117    * - ``V4L2_YCBCR_ENC_601``
118      - Use the BT.601 Y'CbCr encoding.
119    * - ``V4L2_YCBCR_ENC_709``
120      - Use the Rec. 709 Y'CbCr encoding.
121    * - ``V4L2_YCBCR_ENC_XV601``
122      - Use the extended gamut xvYCC BT.601 encoding.
123    * - ``V4L2_YCBCR_ENC_XV709``
124      - Use the extended gamut xvYCC Rec. 709 encoding.
125    * - ``V4L2_YCBCR_ENC_BT2020``
126      - Use the default non-constant luminance BT.2020 Y'CbCr encoding.
127    * - ``V4L2_YCBCR_ENC_BT2020_CONST_LUM``
128      - Use the constant luminance BT.2020 Yc'CbcCrc encoding.
129    * - ``V4L2_YCBCR_ENC_SMPTE_240M``
130      - Use the SMPTE 240M Y'CbCr encoding.
131
132
133
134.. c:type:: v4l2_hsv_encoding
135
136.. tabularcolumns:: |p{6.5cm}|p{11.0cm}|
137
138.. flat-table:: V4L2 HSV Encodings
139    :header-rows:  1
140    :stub-columns: 0
141
142    * - Identifier
143      - Details
144    * - ``V4L2_HSV_ENC_180``
145      - For the Hue, each LSB is two degrees.
146    * - ``V4L2_HSV_ENC_256``
147      - For the Hue, the 360 degrees are mapped into 8 bits, i.e. each
148	LSB is roughly 1.41 degrees.
149
150
151
152.. c:type:: v4l2_quantization
153
154.. tabularcolumns:: |p{6.5cm}|p{11.0cm}|
155
156.. flat-table:: V4L2 Quantization Methods
157    :header-rows:  1
158    :stub-columns: 0
159
160    * - Identifier
161      - Details
162    * - ``V4L2_QUANTIZATION_DEFAULT``
163      - Use the default quantization encoding as defined by the
164	colorspace. This is always full range for R'G'B' and HSV.
165	It is usually limited range for Y'CbCr.
166    * - ``V4L2_QUANTIZATION_FULL_RANGE``
167      - Use the full range quantization encoding. I.e. the range [0…1] is
168	mapped to [0…255] (with possible clipping to [1…254] to avoid the
169	0x00 and 0xff values). Cb and Cr are mapped from [-0.5…0.5] to
170	[0…255] (with possible clipping to [1…254] to avoid the 0x00 and
171	0xff values).
172    * - ``V4L2_QUANTIZATION_LIM_RANGE``
173      - Use the limited range quantization encoding. I.e. the range [0…1]
174	is mapped to [16…235]. Cb and Cr are mapped from [-0.5…0.5] to
175	[16…240]. Limited Range cannot be used with HSV.
176