sRGB is a standard RGB (red, green, blue) color space that HP and Microsoft created cooperatively in 1996 to use on monitors, printers, and the Web. It was subsequently standardized by the IEC as IEC 61966-2-1:1999. Its predecessor NIF RGB was used in FlashPix and was almost the same. It is often the “default” color space for images that contain no color space information, especially if the images’ pixels are stored in 8-bit integers per color channel.
sRGB uses the ITU-R BT.709 primaries, the same as in studio monitors and HDTV, a transfer function (gamma) typical of CRTs, and a viewing environment designed to match typical home and office viewing conditions. This specification allowed sRGB to be directly displayed on typical CRT monitors of the time, which greatly aided its acceptance.
The sRGB gamut
sRGB 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. As with any RGB color space, for non-negative values of R, G, and B it is not possible to represent colors outside this triangle, which is well inside the range of colors visible to a human with normal trichromatic vision.
The primaries come from HDTV (Rec. 709), which in turn is based on Color TV (Rec. 601). These values reflect the approximate color of consumer CRT phosphors.
The sRGB transfer function (“gamma”)
Plot of the sRGB intensities versus sRGB numerical values (red), and this function’s slope in log-log space (blue), which is the effective gamma at each point. Below a compressed value of 0.04045 or a linear intensity of 0.00313, the curve is linear so the gamma is 1. Behind the red curve is a dashed black curve showing an exact gamma = 2.2 power law.On an sRGB display, each solid bar should look as bright as the surrounding striped dither. (Note: must be viewed at original, 100% size)
sRGB also defines a nonlinear transfer function between the intensity of these primaries and the actual number stored. The curve is similar to the gamma response of a CRT display. This nonlinear conversion means that sRGB is a reasonably efficient use of the values in an integer-based image file to display human-discernible light levels.
Unlike most other RGB color spaces, the sRGB gamma cannot be expressed as a single numerical value. The overall gamma is approximately 2.2, consisting of a linear (gamma 1.0) section near black, and a non-linear section elsewhere involving a 2.4 exponent and a gamma (slope of log output versus log input) changing from 1.0 through about 2.3. The purpose of the linear section is so the curve does not have an infinite slope at zero, which could cause numerical problems.
Specification of the transformation
The forward transformation (CIE XYZ to sRGB)
The CIE XYZ values must be scaled so that the Y of D65 (“white”) is 1.0 (X, Y, Z = 0.9505, 1.0000, 1.0890). This is usually true but some color spaces use 100 or other values (such as in CIELAB, when using specified white points).
The first step in the calculation of sRGB from CIE XYZ is a linear transformation, which may be carried out by a matrix multiplication. (The numerical values below match those in the official sRGB specification, which corrected small rounding errors in the original publication by sRGB’s creators, and assume the 2° standard colorimetric observer for CIE XYZ.)
These linear RGB values are not the final result; gamma correction must still be applied. The following formula transforms the linear values into sRGB:
These gamma-compressed values (sometimes called “non-linear values”) are usually clipped to the 0 to 1 range. This clipping can be done before or after the gamma calculation, or done as part of converting to 8 bits. If values in the range 0 to 255 are required, e.g. for video display or 8-bit graphics, the usual technique is to multiply by 255 and round to an integer.
The reverse transformation
Again the sRGB component values are in the range 0 to 1. (Values in the range of 0 to 255 can simply be divided by 255.0).
These gamma-expanded values (sometimes called “linear values” or “linear-light values”) are multiplied by a matrix to obtain CIE XYZ:
Theory of the transformation
It is often casually stated that the decoding gamma for sRGB data is 2.2, yet the above transform shows an exponent of 2.4. This is because the net effect of the piecewise decomposition is necessarily a changing instantaneous gamma at each point in the range: it goes from gamma = 1 at zero to a gamma of 2.4 at maximum intensity with a median value being close to 2.2. The transformation was designed to approximate a gamma of about 2.2, but with a linear portion near zero to avoid having an infinite slope at K = 0, which can cause numerical problems.