How does HSLuv work?

HSLuv is defined as a conversion to and from CIELUV LCh. For both HSLuv and HPLuv, the first step is to find the chroma bounds for a given lightness. These are lines, crossing which will push the color out of the RGB gamut. We define a function, getBounds(L) which returns 6 straight lines in slope-intercept format. Each of them represents one of three RGB channels being pushed either below 0 or above 1.

HSLuv:

  1. Given a hue (angle), build a ray starting from (0, 0) and find the point where it first intersects with one of the bounding lines.
  2. The distance from (0, 0) to this point is the maximum chroma for given L and H. Scale saturation to be a percentage of this distance.

HPLuv:

  1. Use perpendiculars to find the shortest distance from (0, 0) to one of the bounding lines.
  2. This distance is the lowest common chroma. For the given L and any H let saturation span this distance.

The equations were built and solved using Maxima, and the Maxima files are bundled with the code explaining how to get the bounding lines. The rest is simple geometry you can see in the reference implementation.