Home Top Engage OWL Index What's New About

CheckLst ] Hyperlink ] BmpMenu ] TipOfDay ] CtxHelp ] DockingEx ] Buttons ] [ ColorHLS ]


classes ColorHLS

Screenshot ColorHLS

TColorHLS is a freeware OWL class that represents a color in the HLS modell. It is a stand alone class without inheritance, but it has mostly the same interface as the original TColor class.

The HLS modell is widely used by artists. Its color components are hue, lightness, and saturation.

Hue has the same meaning as the HSV model, except that a hue angle of 0° corresponds to blue in this model. Magenta is at 60°, red is at 120°. As with the HSV model, complementary colors are 180° apart.
Lightness (Luminance) is the amount of black or white in a color. Increasing lightness adds white to the hue. Decreasing lightness adds black to the hue.
Saturation in the HLS model is a measure of the "purity" of a hue. As saturation is decreased, the hue becomes more gray. A saturation value of zero results in a grayscale value.

The HLS modell makes it very easy, to draw such things as color gradients between any color:

void DrawGradient(CDC& dc, int x, int y, TColorHLS c1, TColorHLS c2,
  int width, int height)
{
  PRECONDITION(width > 0);
  float dh = (c2.GetHue() - c1.GetHue()) / width;
  float dl = (c2.GetLuminance() - c1.GetLuminance()) / width;
  float ds = (c2.GetSaturation() - c1.GetSaturation()) / width;
  for (int i = 0; i < width; ++i)
  {
    TPen pen(TColor(c1.GetValue()));
    dc.SelectObject(pen);
    dc.MoveTo(x + i, y);
    dc.LineTo(x + i, y + height);
    dc.RestorePen();
    c1.SetHue(c1.GetHue() + dh);
    c1.SetLuminance(c1.GetLuminance() + dl);
    c1.SetSaturation(c1.GetSaturation() + ds);
  }
}

Perhaps NT 5.0 will support the HLS (or the similary HSB) color modell.

Portions of code are based on MFC class CColor written by Christian Rodemeyer. Very special thanks.

The code was tested using Microsoft Visual C++ 6.0 SR2 with OWL6 patch 5 and Borland C++ 5.02 with OWL 5.02. Both under Windows NT 4.0 SP4.

Please send me bug reports, bug fixes, enhancements, requests, etc., and I'll try to keep this in next versions:
EMail: dieter.windau@usa.net

Happy coding

Download

Ver File Description
1.0 colorhls.zip 04/11/99, 7 KB Only the source of TColorHLS class and this HTML-Document
- colhlsap.zip 04/11/99, 39 KB The sample application demonstrates the use of the TColorHLS class.
Under VC++ the debug version of the sample don't work correct.

History

Ver Date Description
1.0 04/11/99 Basic version
 

Back to top of Page CheckLst ] Hyperlink ] BmpMenu ] TipOfDay ] CtxHelp ] DockingEx ] Buttons ] [ ColorHLS ]

E-Mail: SoftEngage@aol.com
Copyright © 1998 M. Engelbert, D. Windau
Updated: 11.04.99