I think this is a question about numeric programming
and not so much about colors:
I want to be able to convert Red, Green and Blue
(each having a value from 0 to 255) to
Hue, Saturation and Luminance (the HSL/HSB model),
(each having a value from 0 to 240), and back.
The delphi (WINAPI) help has the C code for this
(search help on RGBtoHSL).
I tried to port this C code to Delphi. It worked
for most cases but sometimes there is a slight difference
I mean: when I put use RGBtoHSL on some legal RGB values
and convert it back with HSLtoRGB the RGB values in rare
cases are slighty different (e.g. R=R, G=G+1, B=B-1).
First, I used TRUNC() for the real to integer conversions,
and then I only used reals instead of integers and
rounded off later. The result is about the same, the
latter being a little worse.
Has any one ported this functions such that you
can convert back and forth as many times as you please
without this slight differences?
To be explicit suppose R=x, G=y, B=z
I want to be able to call RGBtoHSL and then HSLtoRGB and repeat this process a 1000 times,
and still the result must be R=x, G=y and B=z.
Please give the code.