Search code examples
vb.netwinformscolors

Why are max values for saturation and hue are 240 and 239 respectively?


In ColorDialog why are the max values for saturation and hue are 240 and 239 respectively? To what do they correspond?


Solution

  • Short Answer

    The reason for a hue of 239 (240=0) is only about using one single int (8 bit integer) for the hue value, a remnant from a bygone era.

    Longer Answer

    The use of a hue with 240 values instead of 360 dates back to when computers did not have math coprocessors. Without a math coprocessor, doing anything in floating point was a significant performance bottleneck. Moreover, low CPU speed, limited RAM, etc... back then, much was done to be efficient in ways that might not make sense today.

    Remember we are talking about decades before it was possible to have a hand-held computer connected to all the world's knowledge, where said hand-held computer also happens to double as a telephone, still camera, video camera, world map with your current location, music player, television, word processor, speech to text interpreter, teletype, magnifying glass, and luminance adjustable flashlight.

    😎

    Back in the late 80s/early 90s, 8bit integer math was how almost everything was done, and doing anything other than 8bit integer math was avoided whenever practical.

    Reducing 360 to 240 keeps that value in 8bit, and has the advantage that it is exactly 2/3rds of 360. Not to mention that color does not really have an "angle" per se (see side note)—it is just a convention to make it easy for humans to adjust color to suit.

    Since there are three primaries in an RGB monitor, HSL breaks things down accordingly. If you think of sRGB as a "cube" with one corner as black, one corner as white, then you have 6 corners as the max values of full saturation, such as #f00 for red and #0ff for aqua.

    HSL is not a perceptually uniform color model — it is just a low-tech way to make color adjustments "intuitive" for the user.

    Side Note

    Color (hue) does not exist as an a "angle". Color is not actually real, it is only a perception. There are simply wavelengths of visible light, from longer than 700nm (red) to shorter than 400nm (blue). The sensation of color is a perceptual function of your brain.

    Nevertheless, encoding hue perception to a circle makes it fairly intuitive. So in any application where color values are defined as an angle, it is purely a construct of convenience.

    Note: This answer is similar to my answer at this similar question, posted here on suggestion for completeness.