michielpost / Q42.HueApi

C# helper library to talk to the Philips Hue bridge
MIT License
411 stars 114 forks source link

Color conversion inconsistencies? #239

Closed Exergist closed 3 years ago

Exergist commented 3 years ago

If I set my (gamut C for reference) hue light to "Violet" (RGB = 237,130,237 or #EE82EE) and then perform the following...

RGBColor[] color = new RGBColor[6];
color[4] = light.State.ToRgb();
color[1] = Q42.HueApi.ColorConverters.Original.LightExtensions.ToRGBColor(light);
color[2] = Q42.HueApi.ColorConverters.Gamut.StateExtensions.ToRgb(light.State, light.Capabilities.Control.ColorGamut);
color[3] = Q42.HueApi.ColorConverters.Original.StateExtensions.ToRGBColor(light.State, light.ModelId);

Color[] rgb = new Color[color.Length];
for (int i = 0; i < color.Length; i++)
{
    rgb[i] = Color.FromArgb((int)(color[i].R * 255), (int)(color[i].G * 255), (int)(color[i].B * 255));
}

...then the rgb matrix is as follows:

237, 130, 238
254, 181, 227
254, 181, 227
254, 181, 227

Note that the first entry in the rgb matrix (corresponding to light.State.ToRgb()) yields the closest match to "Violet." Note that I specifically chose "Violet" in this case because it naturally exists in all gamuts and does not contain '255' as an RGB value (since Hue lights cannot reach '255' on a given color channel).

I guess I wasn't expecting this kind of discrepancy, especially since this color should be within all the gamut triangles. HOWEVER if I had to guess, I'd say the (254,181,227) RGB value LOOKS more like what my Hue light displays. Thoughts?

michielpost commented 3 years ago

There's no best way for the color conversion. There are three ColorConverters available, they are contributed by different people. Choose the one that you like. And it's possible to create your own ColorConversion if that's what you need.

Exergist commented 3 years ago

For others that may come looking, based on my testing (with Gamut C lights), I've found it useful to keep in mind the idea of Hue light TARGET vs ~ACTUAL color.

Again, this is based on my testing with Gamut C lights, and your experience might be different.

@michielpost if you have no further comments feel free to close this issue.