Open sticilface opened 9 years ago
Afaik, @me-no-dev has been working on this topic. Pull requests welcome!
I wrote this code mode than a year ago. If I remember right it is not an 1:1 mapping but its pretty close.
`
def rgbToXY(self):
red = self.lw12.red / 255.0
green = self.lw12.green / 255.0
blue = self.lw12.blue / 255.0
if red == 0 and green == 0 and blue == 0:
red = 52
blue = 23
green = 15
print red, green, blue
if red > 0.04045:
r = math.pow((red + 0.055) / (1.0 + 0.055), 2.4)
else:
r = red / 12.92
if green > 0.04045:
g = math.pow((green + 0.055) / (1.0 + 0.055), 2.4)
else:
g = green / 12.92
if blue > 0.04045:
b = math.pow((blue + 0.055) / (1.0 + 0.055), 2.4)
else:
b = blue / 12.92
X = r * 0.649926 + g * 0.103455 + b * 0.197109
Y = r * 0.234327 + g * 0.743075 + b * 0.022598
Z = r * 0.0000000 + g * 0.053077 + b * 1.035763
try:
cx = X / (X + Y + Z)
except:
cx = 0.0
try:
cy = Y / (X + Y + Z)
except:
cy = 0.0
print cx, cy
if math.isnan(cx):
cx = 0.0
if math.isnan(cy):
cy = 0.0
self.state.xy[0] = cx
self.state.xy[1] = cy`
@Schischu thanks for this code, would you mind sending a pull request?
@Schischu still around?
I've just spent several hours on this particular problem and have not solved it, its a bit out of my area.
For the iOS Hue app to work, I require xy colour space numbers.
your equation for rgb to xy works.
I cannot derive one that converts RGB back to xy!
can you help?