Transfer function ("gamma") An sRGB image file contains values for each pixel. 0.0 is "black" while 1.0 is the intensity of a color primary needed by "white". These floating-point values are derived from the file data; for a typical 8-bit-per-channel image the bytes are divided by 255.0. The mapping from these values to intensity is a non-linear
transfer function which is the combination of a
linear function at low brightness values and a displaced
power law for the rest of the range. Linear intensities are derived using (same for all channels): The inverse OETF as defined in the IEC standard is not used for EOTF: :R' = \begin{cases} 12.92 R, & R \le 0.0031308 \\[5mu] (1.055)R^{1/2.4} - 0.055, & R > 0.0031308 \end{cases} If needed by the file format, values greater than 1.0 can be used (the results will also be greater than 1.0), and values less than 0.0 can be converted as . These functions are similar to those of BT.709, but the values are noticeably different. Because of the rounding of the parameters, they have small discontinuities at the transition between the linear and non-linear part, on the order of 10−8, and they are not precise inverses of each other. These errors are too small to matter in practical situations. In practice many pieces of software use different close-by values (see below), or ignore the linear section, or use a plain gamma 2.2 function. The change in the images is almost imperceptible, however it will make noticeable seams when differently-converted images are overlapped, and mismatched translations back and forth accumulate color shifts. Many operating systems and programs send 8-bit sRGB images directly to video memory and assume this produces the correct levels.
Deriving the transfer function A shifted power law curve that passes through is y = \left(\frac{x+C}{1+C}\right)^\gamma. A straight line that passes through , is y = x/A. The transition from the linear section to the power law section should be
continuous (without a sudden step) and
smooth (without a sudden change of slope). To make it continuous when , we must have :\frac{X}{A} = \left(\frac{X+C}{1+C}\right)^\gamma To avoid a sudden change of slope where the two segments meet, the derivatives must also be equal at : :\frac{1}{A} = \gamma\left(\frac{X+C}{1+C}\right)^{\gamma-1}\left(\frac{1}{1+C}\right) Solving the two equations for and we get :X = \frac{C}{\gamma-1}\;\;\;\;\; A = \frac{(1+C)^\gamma(\gamma-1)^{\gamma-1}}{(C^{\gamma-1})(\gamma^\gamma)} The first draft of the sRGB standard chose \gamma= 2.4 and then computed C=0.055 so that the value at x=0.4 was near x^{2.2}. This produces X \approx 0.03928 and A \approx 12.92321. These values, rounded to 5 digits as shown, are still incorrectly given in some publications. However, the sRGB draft standard rounded A to 12.92, resulting in a small discontinuity in the curve. The first official version of the standard was defined and published by the IEC in 1999. In this version, the rounded value of A=12.92 was retained, but the breakpoint X was redefined as 0.04045 to make the curve approximately continuous. With these values, there is still a discontinuity in the slope, from 1/12.92 just below the intersection to 1/12.70 just above it. The final standard also corrected some small rounding errors present in the draft.
Primaries The sRGB standard defines the
chromaticities of the red, green, and blue
primaries, the colors where one of the three channels is nonzero and the other two are zero. The
gamut of chromaticities that can be represented in sRGB is the
color triangle defined by these primaries, which are set such that the range of colors inside the triangle is well within the range of colors visible to a human with normal
trichromatic vision. As with any
RGB color space, for non-negative values of , , and it is not possible to represent colors outside this triangle. The primaries come from HDTV (
Rec. 709), which are somewhat different from those for older color TV systems (
Rec. 601). These values were chosen to approximate the color of consumer CRT phosphors at that time. The sRGB standard specifies the colors by providing a matrix that converts the linear values to
CIE XYZ perceptual color coordinates with the 2°
standard colorimetric observer. This matrix is the same specified by the BT.709 standard and these 4-digit coefficients should be considered exact: : \begin{bmatrix} X \\ Y \\ Z \end{bmatrix} = \begin{bmatrix} 0.4124 & 0.3576 & 0.1805 \\ 0.2126 & 0.7152 & 0.0722 \\ 0.0193 & 0.1192 & 0.9505 \end{bmatrix} \begin{bmatrix} R \\ G \\ B \end{bmatrix} The inverse conversion, from CIE XYZ to (linear) , is obtained by inverting the matrix above to a suitable numerical accuracy. The 1999 standard provides a matrix which is accurate to 4 decimal digits (enough for 8-bit samples): : \begin{bmatrix} R \\ G \\ B \end{bmatrix} = \begin{bmatrix} +3.2406 & -1.5372 & -0.4986 \\ -0.9689 & +1.8758 & +0.0415 \\ +0.0557 & -0.2040 & +1.0570 \end{bmatrix} \begin{bmatrix} X \\ Y \\ Z \end{bmatrix} The 1999 IEC standard was amended in 2003 and updated the sample matrix to have seven decimal fraction digits, enough for 16-bit samples: : \begin{bmatrix} R \\ G \\ B \end{bmatrix} = \begin{bmatrix} +3.2406255 & -1.5372080 & -0.4986286 \\ -0.9689307 & +1.8757561 & +0.0415175 \\ +0.0557101 & -0.2040211 & +1.0569959 \end{bmatrix} \begin{bmatrix} X \\ Y \\ Z \end{bmatrix} For these formulas, the
X,
Y, and
Z values must be scaled so that the
Y of
D65 ("white") is 1.0 (
X = 0.9505,
Y = 1.0000,
Z = 1.0890). This is usually true but some color spaces use 100 or other values (such as in
CIELAB, when using specified white points).
Viewing environment showing the
gamut of the sRGB color space (the triangle). The outer curved boundary is the spectral (or monochromatic) locus, with wavelengths shown in nanometers (labeled in blue). This image is drawn using sRGB, so colors outside the triangle cannot be accurately colored and have been interpolated. The
D65 white point is shown in the center, and the
Planckian locus is shown with color temperatures labeled in
kelvins. D65 is not an ideal 6504-kelvin
black body because it is based on atmospheric filtered daylight. The sRGB specification assumes a dimly lit encoding (creation) environment with an ambient correlated color temperature (CCT) of 5003 K: The assumed ambient CCT differs from that of the BT.709 standard illuminant (
D65), which is still retained for the screen white point. Using
D50 for both would have made the white point of most photographic paper appear excessively blue. The other parameters, such as the luminance level, are representative of a typical CRT monitor. For optimal results, the
ICC recommends using the encoding viewing environment (i.e., dim, diffuse lighting) rather than the less-stringent typical viewing environment. When the sRGB values are sent over to the display, e.g. over HDMI, you don't add any glare offset or compensate it in software, the display and the viewing environment naturally produce this small flare.
Translation to integers Most file formats that use sRGB store 8-bit integers. Usually these are converted from 8 bits by dividing by 255.0, and converted to 8 bits by multiplying by 255 and rounding. However some software converts to 8 bits by multiplying by 256 and rounding down. Higher-quality software often uses
dithering when writing so that
color banding is hidden. Annex G of the 2003 amendment of the sRGB standard describes an alternative encoding of color values, called
bg-sRGB, that is recommended when the number of bits per channel is 10 or more. In this case 0.0 is mapped to a
black point and 1.0 is mapped to a
white point , with all other values interpreted linearly. For 10 bits and is specified, and for larger numbers of bits: : K = 3\times 2^{N-3}\quad\quad W = K + 255\times 2^{N-9} The 12-bit
scRGB format does something similar, with and . Allowing numbers greater than 1.0 allows
high dynamic range images, and negative numbers allows colors outside the gamut triangle. ==Usage==