Update Formulas in Convert XY to RGB (#6322)
* Update to Current RGB D65 Conversion As per Philips Hue https://developers.meethue.com/documentation/color-conversions-rgb-xy * Update the source of the XYZ to RGB formulas * Fix Whitespace * Update Whitespace * Update Tests for new Formulas * Update Tests * Update XY_Brightness_to_hsv tests * Update test_color.py
This commit is contained in:
parent
e14d6f11c6
commit
edd5db296d
3 changed files with 12 additions and 13 deletions
|
@ -217,9 +217,8 @@ def color_RGB_to_xy(iR: int, iG: int, iB: int) -> Tuple[float, float, int]:
|
|||
return round(x, 3), round(y, 3), brightness
|
||||
|
||||
|
||||
# taken from
|
||||
# https://github.com/benknight/hue-python-rgb-converter/blob/master/rgb_cie.py
|
||||
# Copyright (c) 2014 Benjamin Knight / MIT License.
|
||||
# Converted to Python from Obj-C, original source from:
|
||||
# http://www.developers.meethue.com/documentation/color-conversions-rgb-xy
|
||||
def color_xy_brightness_to_RGB(vX: float, vY: float,
|
||||
ibrightness: int) -> Tuple[int, int, int]:
|
||||
"""Convert from XYZ to RGB."""
|
||||
|
@ -236,9 +235,9 @@ def color_xy_brightness_to_RGB(vX: float, vY: float,
|
|||
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
|
||||
r = X * 1.656492 - Y * 0.354851 - Z * 0.255038
|
||||
g = -X * 0.707196 + Y * 1.655397 + Z * 0.036152
|
||||
b = X * 0.051713 - Y * 0.121364 + Z * 1.011530
|
||||
|
||||
# Apply reverse gamma correction.
|
||||
r, g, b = map(
|
||||
|
|
|
@ -39,7 +39,7 @@ class TestDemoLight(unittest.TestCase):
|
|||
self.assertEqual((.4, .6), state.attributes.get(light.ATTR_XY_COLOR))
|
||||
self.assertEqual(25, state.attributes.get(light.ATTR_BRIGHTNESS))
|
||||
self.assertEqual(
|
||||
(82, 91, 0), state.attributes.get(light.ATTR_RGB_COLOR))
|
||||
(76, 95, 0), state.attributes.get(light.ATTR_RGB_COLOR))
|
||||
self.assertEqual('rainbow', state.attributes.get(light.ATTR_EFFECT))
|
||||
light.turn_on(
|
||||
self.hass, ENTITY_LIGHT, rgb_color=(251, 252, 253),
|
||||
|
|
|
@ -27,16 +27,16 @@ class TestColorUtil(unittest.TestCase):
|
|||
self.assertEqual((0, 0, 0),
|
||||
color_util.color_xy_brightness_to_RGB(1, 1, 0))
|
||||
|
||||
self.assertEqual((255, 235, 214),
|
||||
self.assertEqual((255, 243, 222),
|
||||
color_util.color_xy_brightness_to_RGB(.35, .35, 255))
|
||||
|
||||
self.assertEqual((255, 0, 45),
|
||||
self.assertEqual((255, 0, 60),
|
||||
color_util.color_xy_brightness_to_RGB(1, 0, 255))
|
||||
|
||||
self.assertEqual((0, 255, 0),
|
||||
color_util.color_xy_brightness_to_RGB(0, 1, 255))
|
||||
|
||||
self.assertEqual((0, 83, 255),
|
||||
self.assertEqual((0, 63, 255),
|
||||
color_util.color_xy_brightness_to_RGB(0, 0, 255))
|
||||
|
||||
def test_color_RGB_to_hsv(self):
|
||||
|
@ -61,16 +61,16 @@ class TestColorUtil(unittest.TestCase):
|
|||
self.assertEqual(color_util.color_RGB_to_hsv(0, 0, 0),
|
||||
color_util.color_xy_brightness_to_hsv(1, 1, 0))
|
||||
|
||||
self.assertEqual(color_util.color_RGB_to_hsv(255, 235, 214),
|
||||
self.assertEqual(color_util.color_RGB_to_hsv(255, 243, 222),
|
||||
color_util.color_xy_brightness_to_hsv(.35, .35, 255))
|
||||
|
||||
self.assertEqual(color_util.color_RGB_to_hsv(255, 0, 45),
|
||||
self.assertEqual(color_util.color_RGB_to_hsv(255, 0, 60),
|
||||
color_util.color_xy_brightness_to_hsv(1, 0, 255))
|
||||
|
||||
self.assertEqual(color_util.color_RGB_to_hsv(0, 255, 0),
|
||||
color_util.color_xy_brightness_to_hsv(0, 1, 255))
|
||||
|
||||
self.assertEqual(color_util.color_RGB_to_hsv(0, 83, 255),
|
||||
self.assertEqual(color_util.color_RGB_to_hsv(0, 63, 255),
|
||||
color_util.color_xy_brightness_to_hsv(0, 0, 255))
|
||||
|
||||
def test_rgb_hex_to_rgb_list(self):
|
||||
|
|
Loading…
Add table
Reference in a new issue