From: Hans Verkuil Date: Thu, 27 Nov 2014 13:16:08 +0000 (-0300) Subject: [media] DocBook media: rewrite the Colorspace chapter X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=1afed88381bb332040f2cb80ab1fa1d70506d593;p=linux-beck.git [media] DocBook media: rewrite the Colorspace chapter The colorspace chapter in the V4L2 Specification was always poorly written. This patch rewrites it, documenting the new Y'CbCr encoding and quantization defines and going into much more detail with respect to how colorspaces are used and what it all means. Signed-off-by: Hans Verkuil Signed-off-by: Mauro Carvalho Chehab --- diff --git a/Documentation/DocBook/media/v4l/biblio.xml b/Documentation/DocBook/media/v4l/biblio.xml index d2eb79e41a01..7ff01a23c2fe 100644 --- a/Documentation/DocBook/media/v4l/biblio.xml +++ b/Documentation/DocBook/media/v4l/biblio.xml @@ -178,6 +178,75 @@ Signal - NTSC for Studio Applications" 1125-Line High-Definition Production" + + sRGB + + International Electrotechnical Commission +(http://www.iec.ch) + + IEC 61966-2-1 ed1.0 "Multimedia systems and equipment - Colour measurement +and management - Part 2-1: Colour management - Default RGB colour space - sRGB" + + + + sYCC + + International Electrotechnical Commission +(http://www.iec.ch) + + IEC 61966-2-1-am1 ed1.0 "Amendment 1 - Multimedia systems and equipment - Colour measurement +and management - Part 2-1: Colour management - Default RGB colour space - sRGB" + + + + xvYCC + + International Electrotechnical Commission +(http://www.iec.ch) + + IEC 61966-2-4 ed1.0 "Multimedia systems and equipment - Colour measurement +and management - Part 2-4: Colour management - Extended-gamut YCC colour space for video +applications - xvYCC" + + + + AdobeRGB + + Adobe Systems Incorporated (http://www.adobe.com) + + Adobe© RGB (1998) Color Image Encoding Version 2005-05 + + + + opRGB + + International Electrotechnical Commission +(http://www.iec.ch) + + IEC 61966-2-5 "Multimedia systems and equipment - Colour measurement +and management - Part 2-5: Colour management - Optional RGB colour space - opRGB" + + + + ITU BT.2020 + + International Telecommunication Union (http://www.itu.ch) + + ITU-R Recommendation BT.2020 (08/2012) "Parameter values for ultra-high +definition television systems for production and international programme exchange" + + + + + EBU Tech 3213 + + European Broadcast Union (http://www.ebu.ch) + + E.B.U. Standard for Chromaticity Tolerances for Studio Monitors" + + IEC 62106 @@ -266,4 +335,20 @@ in the frequency range from 87,5 to 108,0 MHz Version 1, Revision 2 + + poynton + + Charles Poynton + + Digital Video and HDTV, Algorithms and Interfaces + + + + colimg + + Erik Reinhard et al. + + Color Imaging: Fundamentals and Applications + + diff --git a/Documentation/DocBook/media/v4l/pixfmt.xml b/Documentation/DocBook/media/v4l/pixfmt.xml index df5b23d46552..ccf6053c1ae4 100644 --- a/Documentation/DocBook/media/v4l/pixfmt.xml +++ b/Documentation/DocBook/media/v4l/pixfmt.xml @@ -296,343 +296,1003 @@ in the 2-planar version or with each component in its own buffer in the
Colorspaces - [intro] + 'Color' is a very complex concept and depends on physics, chemistry and +biology. Just because you have three numbers that describe the 'red', 'green' +and 'blue' components of the color of a pixel does not mean that you can accurately +display that color. A colorspace defines what it actually means +to have an RGB value of e.g. (255, 0, 0). That is, which color should be +reproduced on the screen in a perfectly calibrated environment. - + In order to do that we first need to have a good definition of +color, i.e. some way to uniquely and unambiguously define a color so that someone +else can reproduce it. Human color vision is trichromatic since the human eye has +color receptors that are sensitive to three different wavelengths of light. Hence +the need to use three numbers to describe color. Be glad you are not a mantis shrimp +as those are sensitive to 12 different wavelengths, so instead of RGB we would be +using the ABCDEFGHIJKL colorspace... - - - - Gamma Correction - - [to do] - E'R = f(R) - E'G = f(G) - E'B = f(B) - - - - Construction of luminance and color-difference -signals - - [to do] - E'Y = -CoeffR E'R -+ CoeffG E'G -+ CoeffB E'B - (E'R - E'Y) = E'R -- CoeffR E'R -- CoeffG E'G -- CoeffB E'B - (E'B - E'Y) = E'B -- CoeffR E'R -- CoeffG E'G -- CoeffB E'B - - - - Re-normalized color-difference signals - - The color-difference signals are scaled back to unity -range [-0.5;+0.5]: - KB = 0.5 / (1 - CoeffB) - KR = 0.5 / (1 - CoeffR) - PB = -KB (E'B - E'Y) = - 0.5 (CoeffR / CoeffB) E'R -+ 0.5 (CoeffG / CoeffB) E'G -+ 0.5 E'B - PR = -KR (E'R - E'Y) = - 0.5 E'R -+ 0.5 (CoeffG / CoeffR) E'G -+ 0.5 (CoeffB / CoeffR) E'B - - - - Quantization - - [to do] - Y' = (Lum. Levels - 1) · E'Y + Lum. Offset - CB = (Chrom. Levels - 1) -· PB + Chrom. Offset - CR = (Chrom. Levels - 1) -· PR + Chrom. Offset - Rounding to the nearest integer and clamping to the range -[0;255] finally yields the digital color components Y'CbCr -stored in YUV images. - - - - - - - ITU-R Rec. BT.601 color conversion - - Forward Transformation - - -int ER, EG, EB; /* gamma corrected RGB input [0;255] */ -int Y1, Cb, Cr; /* output [0;255] */ - -double r, g, b; /* temporaries */ -double y1, pb, pr; - -int -clamp (double x) -{ - int r = x; /* round to nearest */ - - if (r < 0) return 0; - else if (r > 255) return 255; - else return r; -} - -r = ER / 255.0; -g = EG / 255.0; -b = EB / 255.0; - -y1 = 0.299 * r + 0.587 * g + 0.114 * b; -pb = -0.169 * r - 0.331 * g + 0.5 * b; -pr = 0.5 * r - 0.419 * g - 0.081 * b; - -Y1 = clamp (219 * y1 + 16); -Cb = clamp (224 * pb + 128); -Cr = clamp (224 * pr + 128); - -/* or shorter */ - -y1 = 0.299 * ER + 0.587 * EG + 0.114 * EB; - -Y1 = clamp ( (219 / 255.0) * y1 + 16); -Cb = clamp (((224 / 255.0) / (2 - 2 * 0.114)) * (EB - y1) + 128); -Cr = clamp (((224 / 255.0) / (2 - 2 * 0.299)) * (ER - y1) + 128); - - - Inverse Transformation - - -int Y1, Cb, Cr; /* gamma pre-corrected input [0;255] */ -int ER, EG, EB; /* output [0;255] */ - -double r, g, b; /* temporaries */ -double y1, pb, pr; - -int -clamp (double x) -{ - int r = x; /* round to nearest */ - - if (r < 0) return 0; - else if (r > 255) return 255; - else return r; -} - -y1 = (Y1 - 16) / 219.0; -pb = (Cb - 128) / 224.0; -pr = (Cr - 128) / 224.0; - -r = 1.0 * y1 + 0 * pb + 1.402 * pr; -g = 1.0 * y1 - 0.344 * pb - 0.714 * pr; -b = 1.0 * y1 + 1.772 * pb + 0 * pr; - -ER = clamp (r * 255); /* [ok? one should prob. limit y1,pb,pr] */ -EG = clamp (g * 255); -EB = clamp (b * 255); - - - - - enum v4l2_colorspace - - - - - - - - - - - - - - - + Color exists only in the eye and brain and is the result of how strongly +color receptors are stimulated. This is based on the Spectral +Power Distribution (SPD) which is a graph showing the intensity (radiant power) +of the light at wavelengths covering the visible spectrum as it enters the eye. +The science of colorimetry is about the relationship between the SPD and color as +perceived by the human brain. + + Since the human eye has only three color receptors it is perfectly +possible that different SPDs will result in the same stimulation of those receptors +and are perceived as the same color, even though the SPD of the light is +different. + + In the 1920s experiments were devised to determine the relationship +between SPDs and the perceived color and that resulted in the CIE 1931 standard +that defines spectral weighting functions that model the perception of color. +Specifically that standard defines functions that can take an SPD and calculate +the stimulus for each color receptor. After some further mathematical transforms +these stimuli are known as the CIE XYZ tristimulus values +and these X, Y and Z values describe a color as perceived by a human unambiguously. +These X, Y and Z values are all in the range [0…1]. + + The Y value in the CIE XYZ colorspace corresponds to luminance. Often +the CIE XYZ colorspace is transformed to the normalized CIE xyY colorspace: + + x = X / (X + Y + Z) + y = Y / (X + Y + Z) + + The x and y values are the chromaticity coordinates and can be used to +define a color without the luminance component Y. It is very confusing to +have such similar names for these colorspaces. Just be aware that if colors +are specified with lower case 'x' and 'y', then the CIE xyY colorspace is +used. Upper case 'X' and 'Y' refer to the CIE XYZ colorspace. Also, y has nothing +to do with luminance. Together x and y specify a color, and Y the luminance. +That is really all you need to remember from a practical point of view. At +the end of this section you will find reading resources that go into much more +detail if you are interested. + + + A monitor or TV will reproduce colors by emitting light at three +different wavelengths, the combination of which will stimulate the color receptors +in the eye and thus cause the perception of color. Historically these wavelengths +were defined by the red, green and blue phosphors used in the displays. These +color primaries are part of what defines a colorspace. + + Different display devices will have different primaries and some +primaries are more suitable for some display technologies than others. This has +resulted in a variety of colorspaces that are used for different display +technologies or uses. To define a colorspace you need to define the three +color primaries (these are typically defined as x, y chromaticity coordinates +from the CIE xyY colorspace) but also the white reference: that is the color obtained +when all three primaries are at maximum power. This determines the relative power +or energy of the primaries. This is usually chosen to be close to daylight which has +been defined as the CIE D65 Illuminant. + + To recapitulate: the CIE XYZ colorspace uniquely identifies colors. +Other colorspaces are defined by three chromaticity coordinates defined in the +CIE xyY colorspace. Based on those a 3x3 matrix can be constructed that +transforms CIE XYZ colors to colors in the new colorspace. + + + Both the CIE XYZ and the RGB colorspace that are derived from the +specific chromaticity primaries are linear colorspaces. But neither the eye, +nor display technology is linear. Doubling the values of all components in +the linear colorspace will not be perceived as twice the intensity of the color. +So each colorspace also defines a transfer function that takes a linear color +component value and transforms it to the non-linear component value, which is a +closer match to the non-linear performance of both the eye and displays. Linear +component values are denoted RGB, non-linear are denoted as R'G'B'. In general +colors used in graphics are all R'G'B', except in openGL which uses linear RGB. +Special care should be taken when dealing with openGL to provide linear RGB colors +or to use the built-in openGL support to apply the inverse transfer function. + + The final piece that defines a colorspace is a function that +transforms non-linear R'G'B' to non-linear Y'CbCr. This function is determined +by the so-called luma coefficients. There may be multiple possible Y'CbCr +encodings allowed for the same colorspace. Many encodings of color +prefer to use luma (Y') and chroma (CbCr) instead of R'G'B'. Since the human +eye is more sensitive to differences in luminance than in color this encoding +allows one to reduce the amount of color information compared to the luma +data. Note that the luma (Y') is unrelated to the Y in the CIE XYZ colorspace. +Also note that Y'CbCr is often called YCbCr or YUV even though these are +strictly speaking wrong. + + Sometimes people confuse Y'CbCr as being a colorspace. This is not +correct, it is just an encoding of an R'G'B' color into luma and chroma +values. The underlying colorspace that is associated with the R'G'B' color +is also associated with the Y'CbCr color. + + The final step is how the RGB, R'G'B' or Y'CbCr values are +quantized. The CIE XYZ colorspace where X, Y and Z are in the range +[0…1] describes all colors that humans can perceive, but the transform to +another colorspace will produce colors that are outside the [0…1] range. +Once clamped to the [0…1] range those colors can no longer be reproduced +in that colorspace. This clamping is what reduces the extent or gamut of the +colorspace. How the range of [0…1] is translated to integer values in the +range of [0…255] (or higher, depending on the color depth) is called the +quantization. This is not part of the colorspace +definition. In practice RGB or R'G'B' values are full range, i.e. they +use the full [0…255] range. Y'CbCr values on the other hand are limited +range with Y' using [16…235] and Cb and Cr using [16…240]. + + Unfortunately, in some cases limited range RGB is also used +where the components use the range [16…235]. And full range Y'CbCr also exists +using the [0…255] range. + + In order to correctly interpret a color you need to know the +quantization range, whether it is R'G'B' or Y'CbCr, the used Y'CbCr encoding +and the colorspace. +From that information you can calculate the corresponding CIE XYZ color +and map that again to whatever colorspace your display device uses. + + The colorspace definition itself consists of the three +chromaticity primaries, the white reference chromaticity, a transfer +function and the luma coefficients needed to transform R'G'B' to Y'CbCr. While +some colorspace standards correctly define all four, quite often the colorspace +standard only defines some, and you have to rely on other standards for +the missing pieces. The fact that colorspaces are often a mix of different +standards also led to very confusing naming conventions where the name of +a standard was used to name a colorspace when in fact that standard was +part of various other colorspaces as well. + + If you want to read more about colors and colorspaces, then the +following resources are useful: is a good practical +book for video engineers, has a much broader scope and +describes many more aspects of color (physics, chemistry, biology, etc.). +The http://www.brucelindbloom.com +website is an excellent resource, especially with respect to the mathematics behind +colorspace conversions. The wikipedia CIE 1931 colorspace article +is also very useful. + + +
+ Defining Colorspaces in V4L2 + In V4L2 colorspaces are defined by three values. The first is the colorspace +identifier (&v4l2-colorspace;) which defines the chromaticities, the transfer +function, the default Y'CbCr encoding and the default quantization method. The second +is the Y'CbCr encoding identifier (&v4l2-ycbcr-encoding;) to specify non-standard +Y'CbCr encodings and the third is the quantization identifier (&v4l2-quantization;) +to specify non-standard quantization methods. Most of the time only the colorspace +field of &v4l2-pix-format; or &v4l2-pix-format-mplane; needs to be filled in. Note +that the default R'G'B' quantization is always full range for all colorspaces, +so this won't be mentioned explicitly for each colorspace description. + +
+ V4L2 Colorspaces + + &cs-def; - Identifier - Value - Description - Chromaticities - The coordinates of the color primaries are -given in the CIE system (1931) - - White Point - Gamma Correction - Luminance E'Y - Quantization - - - Red - Green - Blue - Y' - Cb, Cr + Identifier + Details V4L2_COLORSPACE_SMPTE170M - 1 - NTSC/PAL according to , - - x = 0.630, y = 0.340 - x = 0.310, y = 0.595 - x = 0.155, y = 0.070 - x = 0.3127, y = 0.3290, - Illuminant D65 - E' = 4.5 I for I ≤0.018, -1.099 I0.45 - 0.099 for 0.018 < I - 0.299 E'R -+ 0.587 E'G -+ 0.114 E'B - 219 E'Y + 16 - 224 PB,R + 128 + See . - V4L2_COLORSPACE_SMPTE240M - 2 - 1125-Line (US) HDTV, see - x = 0.630, y = 0.340 - x = 0.310, y = 0.595 - x = 0.155, y = 0.070 - x = 0.3127, y = 0.3290, - Illuminant D65 - E' = 4 I for I ≤0.0228, -1.1115 I0.45 - 0.1115 for 0.0228 < I - 0.212 E'R -+ 0.701 E'G -+ 0.087 E'B - 219 E'Y + 16 - 224 PB,R + 128 + V4L2_COLORSPACE_REC709 + See . - V4L2_COLORSPACE_REC709 - 3 - HDTV and modern devices, see - x = 0.640, y = 0.330 - x = 0.300, y = 0.600 - x = 0.150, y = 0.060 - x = 0.3127, y = 0.3290, - Illuminant D65 - E' = 4.5 I for I ≤0.018, -1.099 I0.45 - 0.099 for 0.018 < I - 0.2125 E'R -+ 0.7154 E'G -+ 0.0721 E'B - 219 E'Y + 16 - 224 PB,R + 128 + V4L2_COLORSPACE_SRGB + See . - V4L2_COLORSPACE_BT878 - 4 - Broken Bt878 extents - The ubiquitous Bt878 video capture chip -quantizes E'Y to 238 levels, yielding a range -of Y' = 16 … 253, unlike Rec. 601 Y' = 16 … -235. This is not a typo in the Bt878 documentation, it has been -implemented in silicon. The chroma extents are unclear. - , - ? - ? - ? - ? - ? - 0.299 E'R -+ 0.587 E'G -+ 0.114 E'B - 237 E'Y + 16 - 224 PB,R + 128 (probably) + V4L2_COLORSPACE_ADOBERGB + See . + + + V4L2_COLORSPACE_BT2020 + See . + + + V4L2_COLORSPACE_SMPTE240M + See . V4L2_COLORSPACE_470_SYSTEM_M - 5 - M/NTSC - No identifier exists for M/PAL which uses -the chromaticities of M/NTSC, the remaining parameters are equal to B and -G/PAL. - according to , - x = 0.67, y = 0.33 - x = 0.21, y = 0.71 - x = 0.14, y = 0.08 - x = 0.310, y = 0.316, Illuminant C - ? - 0.299 E'R -+ 0.587 E'G -+ 0.114 E'B - 219 E'Y + 16 - 224 PB,R + 128 + See . V4L2_COLORSPACE_470_SYSTEM_BG - 6 - 625-line PAL and SECAM systems according to , - x = 0.64, y = 0.33 - x = 0.29, y = 0.60 - x = 0.15, y = 0.06 - x = 0.313, y = 0.329, -Illuminant D65 - ? - 0.299 E'R -+ 0.587 E'G -+ 0.114 E'B - 219 E'Y + 16 - 224 PB,R + 128 + See . V4L2_COLORSPACE_JPEG - 7 - JPEG Y'CbCr, see , - ? - ? - ? - ? - ? - 0.299 E'R -+ 0.587 E'G -+ 0.114 E'B - 256 E'Y + 16 - Note JFIF quantizes -Y'PBPR in range [0;+1] and -[-0.5;+0.5] to 257 levels, however Y'CbCr signals -are still clamped to [0;255]. - - 256 PB,R + 128 + See . + + + +
+ + + V4L2 Y'CbCr Encodings + + &cs-def; + + + Identifier + Details + + - V4L2_COLORSPACE_SRGB - 8 - [?] - x = 0.640, y = 0.330 - x = 0.300, y = 0.600 - x = 0.150, y = 0.060 - x = 0.3127, y = 0.3290, - Illuminant D65 - E' = 4.5 I for I ≤0.018, -1.099 I0.45 - 0.099 for 0.018 < I - n/a + V4L2_YCBCR_ENC_DEFAULT + Use the default Y'CbCr encoding as defined by the colorspace. + + + V4L2_YCBCR_ENC_601 + Use the BT.601 Y'CbCr encoding. + + + V4L2_YCBCR_ENC_709 + Use the Rec. 709 Y'CbCr encoding. + + + V4L2_YCBCR_ENC_XV601 + Use the extended gamut xvYCC BT.601 encoding. + + + V4L2_YCBCR_ENC_XV709 + Use the extended gamut xvYCC Rec. 709 encoding. + + + V4L2_YCBCR_ENC_SYCC + Use the extended gamut sYCC encoding. + + + V4L2_YCBCR_ENC_BT2020 + Use the default non-constant luminance BT.2020 Y'CbCr encoding. + + + V4L2_YCBCR_ENC_BT2020_CONST_LUM + Use the constant luminance BT.2020 Yc'CbcCrc encoding.
+ + + V4L2 Quantization Methods + + &cs-def; + + + Identifier + Details + + + + + V4L2_QUANTIZATION_DEFAULT + Use the default quantization encoding as defined by the colorspace. +This is always full range for R'G'B' and usually limited range for Y'CbCr. + + + V4L2_QUANTIZATION_FULL_RANGE + Use the full range quantization encoding. I.e. the range [0…1] +is mapped to [0…255] (with possible clipping to [1…254] to avoid the +0x00 and 0xff values). Cb and Cr are mapped from [-0.5…0.5] to [0…255] +(with possible clipping to [1…254] to avoid the 0x00 and 0xff values). + + + V4L2_QUANTIZATION_LIM_RANGE + Use the limited range quantization encoding. I.e. the range [0…1] +is mapped to [16…235]. Cb and Cr are mapped from [-0.5…0.5] to [16…240]. + + + + +
+
+ +
+ Detailed Colorspace Descriptions +
+ Colorspace SMPTE 170M (<constant>V4L2_COLORSPACE_SMPTE170M</constant>) + The standard defines the colorspace used by NTSC and PAL and by SDTV +in general. The default Y'CbCr encoding is V4L2_YCBCR_ENC_601. +The default Y'CbCr quantization is limited range. The chromaticities of the primary colors and +the white reference are: + + SMPTE 170M Chromaticities + + &cs-str; + + + Color + x + y + + + + + Red + 0.630 + 0.340 + + + Green + 0.310 + 0.595 + + + Blue + 0.155 + 0.070 + + + White Reference (D65) + 0.3127 + 0.3290 + + + +
+ The red, green and blue chromaticities are also often referred to +as the SMPTE C set, so this colorspace is sometimes called SMPTE C as well. + + + The transfer function defined for SMPTE 170M is the same as the +one defined in Rec. 709. Normally L is in the range [0…1], but for the extended +gamut xvYCC encoding values outside that range are allowed. + + L' = -1.099(-L)0.45 + 0.099 for L ≤ -0.018 + L' = 4.5L for -0.018 < L < 0.018 + L' = 1.099L0.45 - 0.099 for L ≥ 0.018 + + + + + + Inverse Transfer function: + + L = -((L' - 0.099) / -1.099)1/0.45 for L' ≤ -0.081 + L = L' / 4.5 for -0.081 < L' < 0.081 + L = ((L' + 0.099) / 1.099)1/0.45 for L' ≥ 0.081 + + + + + + The luminance (Y') and color difference (Cb and Cr) are obtained with +the following V4L2_YCBCR_ENC_601 encoding: + + Y' = 0.299R' + 0.587G' + 0.114B' + Cb = -0.169R' - 0.331G' + 0.5B' + Cr = 0.5R' - 0.419G' - 0.081B' + + + + Y' is clamped to the range [0…1] and Cb and Cr are +clamped to the range [-0.5…0.5]. This conversion to Y'CbCr is identical to the one +defined in the standard and this colorspace is sometimes called BT.601 as well, even +though BT.601 does not mention any color primaries. + The default quantization is limited range, but full range is possible although +rarely seen. + The V4L2_YCBCR_ENC_601 encoding as described above is the +default for this colorspace, but it can be overridden with V4L2_YCBCR_ENC_709, +in which case the Rec. 709 Y'CbCr encoding is used. + + + The xvYCC 601 encoding (V4L2_YCBCR_ENC_XV601, ) is similar +to the BT.601 encoding, but it allows for R', G' and B' values that are outside the range +[0…1]. The resulting Y', Cb and Cr values are scaled and offset: + + Y' = (219 / 255) * (0.299R' + 0.587G' + 0.114B') + (16 / 255) + Cb = (224 / 255) * (-0.169R' - 0.331G' + 0.5B') + Cr = (224 / 255) * (0.5R' - 0.419G' - 0.081B') + + + + Y' is clamped to the range [0…1] and Cb and Cr are clamped +to the range [-0.5…0.5]. The non-standard xvYCC 709 encoding can also be used by selecting +V4L2_YCBCR_ENC_XV709. The xvYCC encodings always use full range +quantization. +
+ +
+ Colorspace Rec. 709 (<constant>V4L2_COLORSPACE_REC709</constant>) + The standard defines the colorspace used by HDTV in general. The default +Y'CbCr encoding is V4L2_YCBCR_ENC_709. The default Y'CbCr quantization is +limited range. The chromaticities of the primary colors and the white reference are: + + Rec. 709 Chromaticities + + &cs-str; + + + Color + x + y + + + + + Red + 0.640 + 0.330 + + + Green + 0.300 + 0.600 + + + Blue + 0.150 + 0.060 + + + White Reference (D65) + 0.3127 + 0.3290 + + + +
+ The full name of this standard is Rec. ITU-R BT.709-5. + + + Transfer function. Normally L is in the range [0…1], but for the extended +gamut xvYCC encoding values outside that range are allowed. + + L' = -1.099(-L)0.45 + 0.099 for L ≤ -0.018 + L' = 4.5L for -0.018 < L < 0.018 + L' = 1.099L0.45 - 0.099 for L ≥ 0.018 + + + + + + Inverse Transfer function: + + L = -((L' - 0.099) / -1.099)1/0.45 for L' ≤ -0.081 + L = L' / 4.5 for -0.081 < L' < 0.081 + L = ((L' + 0.099) / 1.099)1/0.45 for L' ≥ 0.081 + + + + + + The luminance (Y') and color difference (Cb and Cr) are obtained with the following +V4L2_YCBCR_ENC_709 encoding: + + Y' = 0.2126R' + 0.7152G' + 0.0722B' + Cb = -0.1146R' - 0.3854G' + 0.5B' + Cr = 0.5R' - 0.4542G' - 0.0458B' + + + + Y' is clamped to the range [0…1] and Cb and Cr are +clamped to the range [-0.5…0.5]. + The default quantization is limited range, but full range is possible although +rarely seen. + The V4L2_YCBCR_ENC_709 encoding described above is the default +for this colorspace, but it can be overridden with V4L2_YCBCR_ENC_601, in which +case the BT.601 Y'CbCr encoding is used. + + + The xvYCC 709 encoding (V4L2_YCBCR_ENC_XV709, ) +is similar to the Rec. 709 encoding, but it allows for R', G' and B' values that are outside the range +[0…1]. The resulting Y', Cb and Cr values are scaled and offset: + + Y' = (219 / 255) * (0.2126R' + 0.7152G' + 0.0722B') + (16 / 255) + Cb = (224 / 255) * (-0.1146R' - 0.3854G' + 0.5B') + Cr = (224 / 255) * (0.5R' - 0.4542G' - 0.0458B') + + + + Y' is clamped to the range [0…1] and Cb and Cr are clamped +to the range [-0.5…0.5]. The non-standard xvYCC 601 encoding can also be used by +selecting V4L2_YCBCR_ENC_XV601. The xvYCC encodings always use full +range quantization. +
+ +
+ Colorspace sRGB (<constant>V4L2_COLORSPACE_SRGB</constant>) + The standard defines the colorspace used by most webcams and computer graphics. The +default Y'CbCr encoding is V4L2_YCBCR_ENC_SYCC. The default Y'CbCr quantization +is full range. The chromaticities of the primary colors and the white reference are: + + sRGB Chromaticities + + &cs-str; + + + Color + x + y + + + + + Red + 0.640 + 0.330 + + + Green + 0.300 + 0.600 + + + Blue + 0.150 + 0.060 + + + White Reference (D65) + 0.3127 + 0.3290 + + + +
+ These chromaticities are identical to the Rec. 709 colorspace. + + + Transfer function. Note that negative values for L are only used by the Y'CbCr conversion. + + L' = -1.055(-L)1/2.4 + 0.055 for L < -0.0031308 + L' = 12.92L for -0.0031308 ≤ L ≤ 0.0031308 + L' = 1.055L1/2.4 - 0.055 for 0.0031308 < L ≤ 1 + + + + Inverse Transfer function: + + L = -((-L' + 0.055) / 1.055)2.4 for L' < -0.04045 + L = L' / 12.92 for -0.04045 ≤ L' ≤ 0.04045 + L = ((L' + 0.055) / 1.055)2.4 for L' > 0.04045 + + + + + + The luminance (Y') and color difference (Cb and Cr) are obtained with the following +V4L2_YCBCR_ENC_SYCC encoding as defined by : + + Y' = 0.2990R' + 0.5870G' + 0.1140B' + Cb = -0.1687R' - 0.3313G' + 0.5B' + Cr = 0.5R' - 0.4187G' - 0.0813B' + + + + Y' is clamped to the range [0…1] and Cb and Cr are clamped +to the range [-0.5…0.5]. The V4L2_YCBCR_ENC_SYCC quantization is always +full range. Although this Y'CbCr encoding looks very similar to the V4L2_YCBCR_ENC_XV601 +encoding, it is not. The V4L2_YCBCR_ENC_XV601 scales and offsets the Y'CbCr +values before quantization, but this encoding does not do that. +
+ +
+ Colorspace Adobe RGB (<constant>V4L2_COLORSPACE_ADOBERGB</constant>) + The standard defines the colorspace used by computer graphics +that use the AdobeRGB colorspace. This is also known as the standard. +The default Y'CbCr encoding is V4L2_YCBCR_ENC_601. The default Y'CbCr +quantization is limited range. The chromaticities of the primary colors and the white reference +are: + + Adobe RGB Chromaticities + + &cs-str; + + + Color + x + y + + + + + Red + 0.6400 + 0.3300 + + + Green + 0.2100 + 0.7100 + + + Blue + 0.1500 + 0.0600 + + + White Reference (D65) + 0.3127 + 0.3290 + + + +
+ + + Transfer function: + + L' = L1/2.19921875 + + + + Inverse Transfer function: + + L = L'2.19921875 + + + + + + The luminance (Y') and color difference (Cb and Cr) are obtained with the +following V4L2_YCBCR_ENC_601 encoding: + + Y' = 0.299R' + 0.587G' + 0.114B' + Cb = -0.169R' - 0.331G' + 0.5B' + Cr = 0.5R' - 0.419G' - 0.081B' + + + + Y' is clamped to the range [0…1] and Cb and Cr are +clamped to the range [-0.5…0.5]. This transform is identical to one defined in +SMPTE 170M/BT.601. The Y'CbCr quantization is limited range. +
+ +
+ Colorspace BT.2020 (<constant>V4L2_COLORSPACE_BT2020</constant>) + The standard defines the colorspace used by Ultra-high definition +television (UHDTV). The default Y'CbCr encoding is V4L2_YCBCR_ENC_BT2020. +The default Y'CbCr quantization is limited range. The chromaticities of the primary colors and +the white reference are: + + BT.2020 Chromaticities + + &cs-str; + + + Color + x + y + + + + + Red + 0.708 + 0.292 + + + Green + 0.170 + 0.797 + + + Blue + 0.131 + 0.046 + + + White Reference (D65) + 0.3127 + 0.3290 + + + +
+ + + Transfer function (same as Rec. 709): + + L' = 4.5L for 0 ≤ L < 0.018 + L' = 1.099L0.45 - 0.099 for 0.018 ≤ L ≤ 1 + + + + Inverse Transfer function: + + L = L' / 4.5 for L' < 0.081 + L = ((L' + 0.099) / 1.099)1/0.45 for L' ≥ 0.081 + + + + + + The luminance (Y') and color difference (Cb and Cr) are obtained with the +following V4L2_YCBCR_ENC_BT2020 encoding: + + Y' = 0.2627R' + 0.6789G' + 0.0593B' + Cb = -0.1396R' - 0.3604G' + 0.5B' + Cr = 0.5R' - 0.4598G' - 0.0402B' + + + + Y' is clamped to the range [0…1] and Cb and Cr are +clamped to the range [-0.5…0.5]. The Y'CbCr quantization is limited range. + There is also an alternate constant luminance R'G'B' to Yc'CbcCrc +(V4L2_YCBCR_ENC_BT2020_CONST_LUM) encoding: + + + Luma: + + Yc' = (0.2627R + 0.6789G + 0.0593B)' + + + + + + B' - Yc' ≤ 0: + + Cbc = (B' - Y') / 1.9404 + + + + + + B' - Yc' > 0: + + Cbc = (B' - Y') / 1.5816 + + + + + + R' - Yc' ≤ 0: + + Crc = (R' - Y') / 1.7184 + + + + + + R' - Yc' > 0: + + Crc = (R' - Y') / 0.9936 + + + + Yc' is clamped to the range [0…1] and Cbc and Crc are +clamped to the range [-0.5…0.5]. The Yc'CbcCrc quantization is limited range. +
+ +
+ Colorspace SMPTE 240M (<constant>V4L2_COLORSPACE_SMPTE240M</constant>) + The standard was an interim standard used during the early days of HDTV (1988-1998). +It has been superseded by Rec. 709. The default Y'CbCr encoding is V4L2_YCBCR_ENC_SMPTE240M. +The default Y'CbCr quantization is limited range. The chromaticities of the primary colors and the +white reference are: + + SMPTE 240M Chromaticities + + &cs-str; + + + Color + x + y + + + + + Red + 0.630 + 0.340 + + + Green + 0.310 + 0.595 + + + Blue + 0.155 + 0.070 + + + White Reference (D65) + 0.3127 + 0.3290 + + + +
+ These chromaticities are identical to the SMPTE 170M colorspace. + + + Transfer function: + + L' = 4L for 0 ≤ L < 0.0228 + L' = 1.1115L0.45 - 0.1115 for 0.0228 ≤ L ≤ 1 + + + + Inverse Transfer function: + + L = L' / 4 for 0 ≤ L' < 0.0913 + L = ((L' + 0.1115) / 1.1115)1/0.45 for L' ≥ 0.0913 + + + + + + The luminance (Y') and color difference (Cb and Cr) are obtained with the +following V4L2_YCBCR_ENC_SMPTE240M encoding: + + Y' = 0.2122R' + 0.7013G' + 0.0865B' + Cb = -0.1161R' - 0.3839G' + 0.5B' + Cr = 0.5R' - 0.4451G' - 0.0549B' + + + + Yc' is clamped to the range [0…1] and Cbc and Crc are +clamped to the range [-0.5…0.5]. The Y'CbCr quantization is limited range. +
+ +
+ Colorspace NTSC 1953 (<constant>V4L2_COLORSPACE_470_SYSTEM_M</constant>) + This standard defines the colorspace used by NTSC in 1953. In practice this +colorspace is obsolete and SMPTE 170M should be used instead. The default Y'CbCr encoding +is V4L2_YCBCR_ENC_601. The default Y'CbCr quantization is limited range. +The chromaticities of the primary colors and the white reference are: + + NTSC 1953 Chromaticities + + &cs-str; + + + Color + x + y + + + + + Red + 0.67 + 0.33 + + + Green + 0.21 + 0.71 + + + Blue + 0.14 + 0.08 + + + White Reference (C) + 0.310 + 0.316 + + + +
+ Note that this colorspace uses Illuminant C instead of D65 as the +white reference. To correctly convert an image in this colorspace to another +that uses D65 you need to apply a chromatic adaptation algorithm such as the +Bradford method. + + + The transfer function was never properly defined for NTSC 1953. The +Rec. 709 transfer function is recommended in the literature: + + L' = 4.5L for 0 ≤ L < 0.018 + L' = 1.099L0.45 - 0.099 for 0.018 ≤ L ≤ 1 + + + + Inverse Transfer function: + + L = L' / 4.5 for L' < 0.081 + L = ((L' + 0.099) / 1.099)1/0.45 for L' ≥ 0.081 + + + + + + The luminance (Y') and color difference (Cb and Cr) are obtained with the +following V4L2_YCBCR_ENC_601 encoding: + + Y' = 0.299R' + 0.587G' + 0.114B' + Cb = -0.169R' - 0.331G' + 0.5B' + Cr = 0.5R' - 0.419G' - 0.081B' + + + + Y' is clamped to the range [0…1] and Cb and Cr are +clamped to the range [-0.5…0.5]. The Y'CbCr quantization is limited range. +This transform is identical to one defined in SMPTE 170M/BT.601. +
+ +
+ Colorspace EBU Tech. 3213 (<constant>V4L2_COLORSPACE_470_SYSTEM_BG</constant>) + The standard defines the colorspace used by PAL/SECAM in 1975. In practice this +colorspace is obsolete and SMPTE 170M should be used instead. The default Y'CbCr encoding +is V4L2_YCBCR_ENC_601. The default Y'CbCr quantization is limited range. +The chromaticities of the primary colors and the white reference are: + + EBU Tech. 3213 Chromaticities + + &cs-str; + + + Color + x + y + + + + + Red + 0.64 + 0.33 + + + Green + 0.29 + 0.60 + + + Blue + 0.15 + 0.06 + + + White Reference (D65) + 0.3127 + 0.3290 + + + +
+ + + The transfer function was never properly defined for this colorspace. +The Rec. 709 transfer function is recommended in the literature: + + L' = 4.5L for 0 ≤ L < 0.018 + L' = 1.099L0.45 - 0.099 for 0.018 ≤ L ≤ 1 + + + + Inverse Transfer function: + + L = L' / 4.5 for L' < 0.081 + L = ((L' + 0.099) / 1.099)1/0.45 for L' ≥ 0.081 + + + + + + The luminance (Y') and color difference (Cb and Cr) are obtained with the +following V4L2_YCBCR_ENC_601 encoding: + + Y' = 0.299R' + 0.587G' + 0.114B' + Cb = -0.169R' - 0.331G' + 0.5B' + Cr = 0.5R' - 0.419G' - 0.081B' + + + + Y' is clamped to the range [0…1] and Cb and Cr are +clamped to the range [-0.5…0.5]. The Y'CbCr quantization is limited range. +This transform is identical to one defined in SMPTE 170M/BT.601. +
+ +
+ Colorspace JPEG (<constant>V4L2_COLORSPACE_JPEG</constant>) + This colorspace defines the colorspace used by most (Motion-)JPEG formats. The chromaticities +of the primary colors and the white reference are identical to sRGB. The Y'CbCr encoding is +V4L2_YCBCR_ENC_601 with full range quantization where +Y' is scaled to [0…255] and Cb/Cr are scaled to [-128…128] and +then clipped to [-128…127]. + Note that the JPEG standard does not actually store colorspace information. +So if something other than sRGB is used, then the driver will have to set that information +explicitly. Effectively V4L2_COLORSPACE_JPEG can be considered to be +an abbreviation for V4L2_COLORSPACE_SRGB, V4L2_YCBCR_ENC_601 +and V4L2_QUANTIZATION_FULL_RANGE. +
+