Why do Saturation and Luminance go all the way to 240, but Hue goes only to 239? And why 239 anyway?
If you open the common Color Picker dialog, the custom color picker lets you specify the color in one of three ways.
- Graphically, by clicking a color in the rainbow and using the slider to change the brightness.
- Numerically by specifying Hue, Saturation, and Luminance.
- Numerically by specifying Red, Green, and Blue.
Let’s look at the Red, Green, and Blue values first. Theoretically, color channels are expressed as floating point values between 0.0 and 1.0 (inclusive). In Windows, it is common to change the scale to integers 0 to 255 (inclusive), since that corresponds to the color values in a 24-bit color space. This is the color space you’ve probably spent a good amount of time dealing with, since it corresponds to the
RGB macro in
COLORREF data type, and the way colors are typically expressed in CSS:
The Hue, Saturation, and Luminance is a bit tricker. The theoretical range for Hue is an angle, normalized to be greater than or equal to 0° and strictly less than 360°. The upper value of the range is not reached because Hue is cyclical, so a value of 360° is equivalent to 0°. On the other hand, Saturation and Luminance are floating point values between 0.0 and 1.0 (inclusive).
In Windows, the Hue, Saturation, and Luminance ranges are rescaled so that they go from 0 to 240. Hue is endpoint-exclusive (because 360° = 0°) whereas Saturation and Luminance are endpoint-inclusive (because 1.0 is achievable).
Okay, but why rescaled to 240? Why not rescale to 255?
The Hue value works out best when the range can be equally divided into 12 segments, because the important points of the Hue occur every 30°. The highest multiple of 12 that is still less than 256 is 252, but 240 makes for prettier values.
(Color names taken from Colblindor.)
Saturation and Luminance could have gone up to 255, but I guess they used 240 out of solidarity. The original code was written in the 1980’s for a now-defunct program called Chart, and it has been carried forward ever since.