This is how you should do it:
- You pick a Y value. This is going to be the luminance of your diagram.
- For each pixel inside the area bounded by the spectral locus (and the line of purples - the line connecting the two endpoints of the locus) you take its x, y coordinates.
- Together these 3 values specify your color in the CIE xyY color space. Converting from xyY to XYZ is trivial: X = Y / y * x, Y = Y, Z = Y / y * (1 - x - y)
- You map these XYZ values into your output image's color space (e.g. sRGB). If a given XYZ value maps outside the [0,1] interval in sRGB, then it's outside the sRGB gamut, and you may clip the values to the closest valid value inside the gamut.