michielpost / Q42.HueApi

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

RGB->HSB Conversion Issue #238

Closed Exergist closed 2 years ago

Exergist commented 3 years ago

Within GetRGB of Q42.HueApi.ColorConverters.HSB is the following:

//Convert Hue into degrees for HSB
hue = hue / 182.04;
//Bri and Sat must be values from 0-1 (~percentage)
brightness = brightness / 255.0;
saturation = saturation / 255.0;

Note that both brightness and saturation are divided by 255. However the Philips Hue documentation states that both these values have maximums of 254. So shouldn't the above calculation divide by 254 instead of 255?

If so, then this logic applies throughout the ColorConverters.

michielpost commented 3 years ago

This code was contributed by @CharlyTheKid in 2016 https://github.com/Q42/Q42.HueApi/issues/70 So not sure, sometimes the documentation is wrong and you can get a 255 value back even it the docs says you don't.

Exergist commented 3 years ago

If I set a color via the official Philips Hue app and force the brightness slider to 100%, the reported brightness value is 254.

Based on my testing if I send #FF0000 (pure 'red' at RGB = 255,0,0) to the Hue lights (mine are Gamut C), the color reported back by the lights is #FE0000 (almost pure 'red' at RGB = 254,0,0). I don't think it is possible to convert HSB to RGB and get RGB = 255,0,0 without being able to hit 255 brightness.

After re-reading the API docs I found that brightness is 1-254, and saturation is 0-254. Here's the info (inside the light state object):

image image

I thought I read somewhere that Philips made a conscious decision to make certain values NOT range from 0-255 for rounding simplification. Though that doesn't seem to make a ton of sense considering the above 1-254 and 0-254 ranges exist.

Any additional thoughts @CharlyTheKid?