michielpost / Q42.HueApi

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

ColorFromXY inconsistency #240

Closed Exergist closed 3 years ago

Exergist commented 3 years ago

I noticed that one section of the code within the ColorFromXYmethod within Q42.HueApi.ColorConverters.Original->HueColorConverter does not quite match the code shown in the HueAPI docs.

Here is the Q42 code:

float x = (float)xy.x;
float y = (float)xy.y;
float z = 1.0f - x - y;
float Y = 1.0f;
float X = (Y / y) * x;
float Z = (Y / y) * z;

...and here is the code from the HueAPI docs:

float x = x; // the given x value
float y = y; // the given y value
float z = 1.0f - x - y;
float Y = brightness; // The given brightness value
float X = (Y / y) * x;
float Z = (Y / y) * z;

Notice that the Q42 code sets Y to 1f, but HueAPI indicates it should be set to the target brightness.

Though the HueAPI docs are unclear about how to properly handle Y relative to a Hue light brightness value.

michielpost commented 3 years ago

Closing this. It's easy to create a new color converter that's based on the original with different calculations if it fits your usecase.