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 wingdi.h
, the COLORREF
data type, and the way colors are typically expressed in CSS: #RRGGBB
.
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.
RGB | Name | 240-based | 252-based |
---|---|---|---|
FF0000 | red | 0 | 0 |
FF8000 | orange | 20 | 21 |
FFFF00 | yellow | 40 | 42 | 80FF00 | chartreuse | 60 | 63 |
00FF00 | green | 80 | 84 |
00FF80 | spring green | 100 | 105 |
00FFFF | cyan | 120 | 126 |
0080FF | dodger blue | 140 | 147 |
0000FF | blue | 160 | 168 |
8000FF | electric indigo | 180 | 189 |
FF00FF | fuchsia | 200 | 210 |
FF0080 | deep pink | 220 | 231 |
(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.
0 comments