RGB-HSL Conversion
Site Map Feedback

Download:

Up HSL

HSL to RGB Conversion

H is the Hue (colour); S is the Saturation (greyness) and L is the Lightness (luminance).
When you want to describe a colour it's not very easy to do accurately using RGB if, for example, you have to find the RGB values of several shades of Gold as used on this site.
Using HSL you would find a single gold that you liked and then alter just one value, the Lightness, to get the shades.
If you needed to fade from some colour to some greyscale shade, you can adjust the Saturation value.
The ranges are supposed to be:
0-360 for Hue (degrees) - Red being at 0
0-240 for Saturation and Lightness...
H is undefined when S=0;
The Colour Selector in Microsoft Windows, rewrites the standards (anyone surprised?) and uses:
0-239 for Hue
0-240 for Saturation and Lightness...
H is 160 when S=0;

The class in HSL.h reproduces the conversion the Microsoft way.
HSL.zip is an MFC Project that uses the HSL class in a colour wheel/selector application:


See Also: gColor encapsulates many color manipulation methods. It holds the color in three doubles, returning HSL as intervals in the range [0,1] and also provides HSV conversion.


THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 'AS IS' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.