def rgb_to_xy(rgb):
    """ convert rgb tuple to xy tuple """
    red, green, blue = rgb
    r = ((red + 0.055) / (1.0 + 0.055)
        ) ** 2.4 if red > 0.04045 else red / 12.92
    g = ((green + 0.055) / (1.0 + 0.055)
        ) ** 2.4 if green > 0.04045 else green / 12.92
    b = ((blue + 0.055) / (1.0 + 0.055)
        ) ** 2.4 if blue > 0.04045 else blue / 12.92
    X = r * 0.664511 + g * 0.154324 + b * 0.162028
    Y = r * 0.283881 + g * 0.668433 + b * 0.047685
    Z = r * 8.8e-05 + g * 0.07231 + b * 0.986039
    cx = 0
    cy = 0
    if X + Y + Z != 0:
        cx = X / (X + Y + Z)
        cy = Y / (X + Y + Z)
    return cx, cy
