XYZ to xyY

Given an XYZ color whose components are in the nominal range [0.0, 1.0]:

Equation 1

Implementation Notes:

  1. Watch out for black, where X = Y = Z = 0. In that case, you may want to set x and y to the chromaticity coordinates of your reference white.
  2. The output Y value is in the nominal range [0.0, 1.0].