def luminance(color: ColorType) -> float:
"""
Calculate the relative luminance (as defined by WCAG 2.0) of
the given color.
:param color: a color
:return: the calculated relative luminance between 0.0 and 10
"""
rgb = color.rgb
vals = []
for c in rgb:
if c <= 0.03928:
c /= 12.92
else:
c = math.pow((c + 0.055) / 1.055, 2.4)
vals.append(c)
L = 0.2126 * vals[0] + 0.7152 * vals[1] + 0.0722 * vals[2]
return L
评论列表
文章目录