λ(nm)x̅(λ)y̅(λ)z̅(λ) RGBlinear luminance RGBmin-max RGB≥0 R+G+B clippedscaled@1scaled@lum
**

Begin with physically measurable data, namely the wavelengths of visible light (λ). The visible spectrum ranges from 390nm, perceived as violet, through indigo, blue, cyan, green, yellow, orange and red, at 830nm. All human perceivable colors are a mixture of lights from each wavelength. Quantification of human color perception of visual stimuli is carried out by measurement of XYZ tristimulus values, X(λ), Y(λ), Z(λ). These are obtained by asking observers to "mix" 3 imaginary primary colors (X, Y and Z) to match pure (one wavelength) colors on the spectrum. The XYZ primaries are mathematically derived, not physical, colors with the following properties: Color matching functions (CMFs), x̅y̅z̅, are derived by XYZ tristimulus values for the monochromatic radiation at each wavelength, scaling Ymax such that y̅max = 1, and then scaling x̅ and z̅ such that:

There are various CMFs, each of which produces a slightly different set of tristimulus values. Many are available at http://cvrl.ioo.ucl.ac.uk/cmfs.htm

Real world visual output is rendered by the additive mixture of physically realizable RGB primaries, not imaginary XYZ primaries. With specification of RGB primaries and whitepoint in XYZ coordinates, any set of XYZ values can be transformed into a set of RGB values via matrix multiplication. For computer monitor screens, the RGB primaries are specified by ITU-R Recommendation BT.709. This specification sets forth X,Y and Z values for each of these RGB primaries, as well as an XYZ white point, D65 in this case. That recommendation refers to studio monitors and HDTV; the same primaries are specified for sRGB, the color space that is used by Windows, the Web and most image formats including JPEG. The matrix for transforming XYZ to sRGB is:

The columns headed by RGBlinear display this transformation. Note that the transformation matrix has negative terms, so negative RGB values are possible. In fact, for reasons beyond the scope of this discussion, all spectral colors have at least 1 negative RGB value. Since a negative amount of light cannot be visually supplied, these values must be further transformed. Here, this is accomplished by finding the minimum value of RGBlinear, and subtracting it from each of the values so that the minimum transformed value is now zero. Results are shown in RGB≥0.

For linear RGB, the minimum amount of a primary that can be present is 0, and the maximum is 1. So the RGB≥0 must be normalized. Three possibilities come to mind:

Note that the coefficients of the above add to 1, corresponding to lum(1,1,1) = 1 for white

Human perception of brightness is not a linear function of the intensity of the light stimulus. Rather, it is a power function. The transformation of perceived brightness to signal brightness is called gamma compensation (the exponent of the power function is designated gamma). The slope of a power function with gamma less than one approaches infinity at very low values. Therefore, the sRGB specification modifies gamma compensation with a spline at low RGB values:

Finally, sRGB values are encoded as 8 bits, so the normalized RGB values are multiplied by 255 and rounded.

The results of the 3 scaling methods are displayed in the 3 right-hand columns.