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 companded RGB is done in two steps.
1. XYZ to Linear RGB

This gives linear RGB, [rgb].
2. Companding
The linear RGB channels (denoted with lower case [rgb], or generically v) are made nonlinear (denoted with upper case [RGB], or generically V).
The same operation is performed on all three channels, but the operation depends on the companding function associated with the RGB color system.
Gamma Companding

sRGB Companding

L* Companding


Implementation Notes:
- The transformation matrix [M] is calculated from the RGB reference primaries as discussed here.
- γ is the gamma value of the RGB color system used. Many common ones may be found here.
- 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.
- 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.
- Sometimes the more complicated special case of sRGB shown above is replaced by a "simplified" version using a straight gamma function with γ = 2.2.