@@ -54,13 +54,49 @@ def color(self, src):
5454 black = (0 , 0 , 0 )
5555 white = (255 , 255 , 255 )
5656 fg = foreground (bg , black , white )
57+ # fg = text_color(*bg)
5758 return bg , fg
5859
5960 def __str__ (self ): # pragma: nocover
6061 import pprint
6162 return pprint .pformat (self .colors )
6263
6364
65+ # def linear_rgb_value(csrgb):
66+ # # ref.: https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests
67+ # if csrgb > 0.03928:
68+ # return ((csrgb + 0.055) / 1.055) ** 2.4
69+ # else:
70+ # return csrgb / 12.92
71+ #
72+ #
73+ # def relative_luminance(r, g, b):
74+ # # ref.: https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests
75+ # return (
76+ # 0.2126 * linear_rgb_value(r / 255)
77+ # + 0.7152 * linear_rgb_value(g / 255)
78+ # + 0.0722 * linear_rgb_value(b / 255)
79+ # )
80+ #
81+ #
82+ # def contrast_ratio(a, b):
83+ # # ref.: https://www.w3.org/TR/WCAG20-TECHS/G17.html#G17-tests
84+ # rla = relative_luminance(*a)
85+ # rlb = relative_luminance(*b)
86+ # L1 = max(rla, rlb)
87+ # L2 = min(rla, rlb)
88+ # return (L1 + 0.05) / (L2 + 0.05)
89+ #
90+ #
91+ # def text_color(r, g, b):
92+ # """Return black (0,0,0) or white (255, 255, 255) depending on which of
93+ # them has highest contrast ratio with the color (r, b, b).
94+ # """
95+ # cr_white = contrast_ratio((r, g, b), (255, 255, 255))
96+ # cr_black = contrast_ratio((r, b, b), (0, 0, 0))
97+ # return (0, 0, 0) if cr_black > cr_white else (255, 255, 255)
98+
99+
64100def rgb2eightbit (rgb ):
65101 """Convert floats in [0..1] to integers in [0..256)
66102 """
0 commit comments