add hyperion light support
This commit is contained in:
1 parent
91a1fb0240
commit
e3304caf06
3 files changed
+176
No files matched your search
@@ -39,3 +39,43 @@ def color_RGB_to_xy(R, G, B):
|
||||
|
||||
# Convert XYZ to xy, see CIE 1931 color space on wikipedia
|
||||
return X / (X + Y + Z), Y / (X + Y + Z)
|
||||
|
||||
|
||||
# taken from
|
||||
# https://github.com/benknight/hue-python-rgb-converter/blob/master/rgb_cie.py
|
||||
# pylint: disable=bad-builtin
|
||||
def color_xy_brightness_to_RGB(vX, vY, brightness):
|
||||
'''
|
||||
Convert from XYZ to RGB.
|
||||
'''
|
||||
brightness /= 255.
|
||||
if brightness == 0:
|
||||
return (0, 0, 0)
|
||||
|
||||
Y = brightness
|
||||
X = (Y / vY) * vX
|
||||
Z = (Y / vY) * (1 - vX - vY)
|
||||
|
||||
# Convert to RGB using Wide RGB D65 conversion.
|
||||
r = X * 1.612 - Y * 0.203 - Z * 0.302
|
||||
g = -X * 0.509 + Y * 1.412 + Z * 0.066
|
||||
b = X * 0.026 - Y * 0.072 + Z * 0.962
|
||||
|
||||
# Apply reverse gamma correction.
|
||||
r, g, b = map(
|
||||
lambda x: (12.92 * x) if (x <= 0.0031308) else
|
||||
((1.0 + 0.055) * pow(x, (1.0 / 2.4)) - 0.055),
|
||||
[r, g, b]
|
||||
)
|
||||
|
||||
# Bring all negative components to zero.
|
||||
r, g, b = map(lambda x: max(0, x), [r, g, b])
|
||||
|
||||
# If one component is greater than 1, weight components by that value.
|
||||
max_component = max(r, g, b)
|
||||
if max_component > 1:
|
||||
r, g, b = map(lambda x: x / max_component, [r, g, b])
|
||||
|
||||
r, g, b = map(lambda x: int(x * 255), [r, g, b])
|
||||
|
||||
return (r, g, b)
|
||||
Reference in new issue
Block a user