XYZ to RGB

Given an XYZ color whose components are in the nominal range [0.0, 1.0] and whose reference white is the same as that of the RGB system, the conversion to RGB is as follows:

If the RGB system is not sRGB:

Equation 1

and if it is sRGB:

Equation 2

where, in either of the above cases:

Equation 3

Implementation Notes:

  1. The transformation matrix [M] is calculated from the RGB reference primaries as discussed here.
  2. γ is the gamma value of the RGB color system used. Many common ones may be found here.
  3. The output RGB values are in the nominal range [0.0, 1.0]. You may wish to scale them to some other range. For example, if you want RGB in the range [0, 255], you must multiply each component by 255.0.
  4. If the input XYZ color is not relative to the same reference white as the RGB system, you must first apply a chromatic adaptation transform to the XYZ color to convert it from its own reference white to the reference white of the RGB system.
  5. Sometimes the more complicated special case of sRGB shown above is replaced by a "simplified" version using a straight gamma function with γ = 2.2.