gbadev.org forum archive

This is a read-only mirror of the content originally found on forum.gbadev.org (now offline), salvaged from Wayback machine copies. A new forum can be found here.

Coding > RGB to HSL Conversion

#4229 - Vortex - Mon Mar 24, 2003 8:09 pm

Hello !

I am looking for a way to convert RGB (Red/Green/Blue) color value into HSL (Hue/Saturation/Light) and vice versa. A perfect algorithm should not include any trig functions and/or divisions.

I need this to implement a smooth fade in/fade out effect.

Any help will be appreciated.

Thank you

#4232 - tepples - Mon Mar 24, 2003 10:10 pm

Vortex wrote:
I am looking for a way to convert RGB (Red/Green/Blue) color value into HSL (Hue/Saturation/Light) and vice versa. A perfect algorithm should not include any trig functions and/or divisions.

Calculating the hue coordinate requires "normalizing" the saturation and lightness, and normalization necessarily involves division. You'll have to use a lookup table.

Quote:
I need this to implement a smooth fade in/fade out effect.

Fades can be done without HSL: just use the blend registers to fade your image toward black or white, or use the alpha registers to fade your image toward any "color 0" that you want.
_________________
-- Where is he?
-- Who?
-- You know, the human.
-- I think he moved to Tilwick.

#4233 - Vortex - Mon Mar 24, 2003 10:37 pm

Quote:
I need this to implement a smooth fade in/fade out effect.
Fades can be done without HSL: just use the blend registers to fade your image toward black or white, or use the alpha registers to fade your image toward any "color 0" that you want.


tepples,

Thank you for the excellent advice. I was not aware BLDCNT can be used with only one target.

#4234 - DekuTree64 - Mon Mar 24, 2003 11:14 pm

Or if you need the HW alpha for something else (I use it for shadows) you can just separate each color into red, green and blue, multiply by a number, shift and put them back together. Kinda slow, but it works, and it's a heck of a lot faster than converting to HSL and back. But if you're fading in/out, you probably don't need to be doing much else at the same time anyway, so as long as it doesn't take the whole VBlank it's probably ok.