michielpost / Q42.HueApi

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

Color converter problem #74

Closed freeubi closed 8 years ago

freeubi commented 8 years ago

I think i found a bug in the LightCommandExtension. Currently, i'm using like this:

  LightCommand lightCommand = new LightCommand();
                lightCommand.Brightness = (byte)Brightness;
                lightCommand.On = true;

                lightCommand.SetColor(new Q42.HueApi.ColorConverters.RGBColor(r, g, b), "LCT001");

                Color myColor = Color.FromArgb(255, (byte)r, (byte)g, (byte)b);

                string hexBefore = myColor.A.ToString("X2") + myColor.R.ToString("X2") + myColor.G.ToString("X2") + myColor.B.ToString("X2");

                var rgbColorFromLight = Q42.HueApi.ColorConverters.OriginalWithModel.LightCommandExtensions.XYToRGB(
                 lightCommand.ColorCoordinates.First(),
                 lightCommand.ColorCoordinates.Last(),
                 "LCT001");

                Save(rgbColorFromLight.ToHex());

I'm givin an input rgb value (0,0,48), set it to a lightCommand, convert it with the extension and save the converted value.

The problem i found: if i save the (0,0,48) rgb value as a converted hex(#4600FF) and try to iput this again, then its become a different value= (70,0,255) as (#4D00FF)

michielpost commented 8 years ago

Yes, this is expected. The Lights don't work with HEX or RGB, and the color converter does it best to find a value that matches closest to your input. You can read more about the CIE Color Space the Hue lights use here: http://www.developers.meethue.com/documentation/core-concepts

If you download the latest NuGet packages you can choose between 3 different colorconverters and use the one you like most.

freeubi commented 8 years ago

Yeah, but i save what the converter give back. Why converting its returned value again?

michielpost commented 8 years ago

In your code sample you're using two different colorconverters, that might cause it: