XYZ to xyY

Given an XYZ color:

$$x = {{X} \over {X + Y + Z}}$$ $$y = {{Y} \over {X + Y + Z}}$$ $$Y = Y$$

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.