POV-Ray : Newsgroups : povray.text.scene-files : HEX --> RGB : Re: HEX --> RGB Server Time
29 Jul 2024 02:20:26 EDT (-0400)
  Re: HEX --> RGB  
From: Mark Donovan
Date: 16 Oct 1998 23:34:21
Message: <36280225.C157F51E@worldnet.att.net>
Glad it's useful! I guess Josh found the HSL --> RGB conversion I posted
a few days ago. The first part of Josh's Hue, Saturation, Luminosity
problem is easy. My POV-Ray color space conversions use values between
zero and one, while color is often specified by values between 0 and
255. Just divide by 255 to fix that.

However, there's a big gotcha in all this. All color spaces are not
created equal! One problem is the hue defined at zero. The color space I
use defines red as the zero value of hue (that's the standard used by
Tektronix, HP and Apple color spaces). Yet other definitions set the
zero value to blue. It's easy to convert the zero value from blue to red.

  #declare Hue_Red_Zero = mod(Hue_Blue_Zero + 2/3, 1.0);

The term HSL can also be confusing. It can mean Hue, Saturation, and
Lightness, or it can mean Hue, Saturation, and Luminosity. My hsl2rgb
conversion is for Lightness. I included an HSB (Hue, Saturation, and
Brightness) conversion which is probably the same as Hue, Saturation,
and Luminosity. The difference is that Lightness is defined so that
black is zero, white is 1.0 and fully saturated color happens at
lightness value 0.5. Luminosity is usually defined so that black is zero
and fully saturated color happens at luminosity value 1.0.

Josh's HSL sample points out this problem with color space definitions.
Whenever you get a color value, it's important to know how the color
space is defined. Neglecting gamma correction, RGB is a well defined
standard. The various HSL, HSB, HSB, and HLS color spaces aren't so well
standardized. Josh's hue 205 converted by dividing by 255 produces a
shade of violet. I suspect the 205 hue is from color space that uses
zero for blue, or one that uses a different sequence of colors for
increasing values of hue. The standard I've used has the sequence red,
orange, yellow, green, cyan, blue, violet and back to red for hue values
zero to 1.0. Other color spaces may use other sequences. For example,
hue might be defined as blue, cyan, green, yellow, orange, red, violet
and back to blue for increasing values of hue.

If you need to convert hue color spaces, tricks like dividing by 255,
subtracting the hue from 1.0 (i.e., 1.0 - hue), or adding a value and
using the mod() function will change the hue to a value you can use with
the conversions I've written. All this confusion might explain why
POV-Ray uses the RGB color space. Good luck!

Mark Donovan
Phoenix, Arizona

Josh English wrote:
> Very cool! And very helpful. Since we're on the subject, I am working
> on some images for a friend that are set in a city. They're pretty
> relaxed about how the building are going to look, and in my sample
> scenes they didn't like the sky. I had just used some of the preset
> cloudy skies. They want the sky color to be Hue 205, Saturation 120, and
> Luminosity between 56 and 136. I don't have any way of  converting this
> color! Has anyone seen this color palette? Does anyone know where I
> could find resources too convert it?


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.