Skip to content

Commit 68f5eb3

Browse files
committed
Improved calculation of color luminosity from tint. Closes #124
1 parent e8345d5 commit 68f5eb3

1 file changed

Lines changed: 12 additions & 4 deletions

File tree

styleframe/styler.py

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,11 +188,19 @@ def _calc_new_hex_from_theme_hex_and_tint(theme_hex, color_tint):
188188
color_obj.luminance = _calc_lum_from_tint(color_tint, color_obj.luminance)
189189
return color_obj.hex_l[1:]
190190

191-
def _calc_lum_from_tint(color_tint, current_lum):
192-
# based on http://ciintelligence.blogspot.co.il/2012/02/converting-excel-theme-color-and-tint.html
193-
if not color_tint:
191+
def _calc_lum_from_tint(color_tint: Optional[float], current_lum: float) -> float:
192+
""""
193+
Based on https://ciintelligence.blogspot.co.il/2012/02/converting-excel-theme-color-and-tint.html
194+
"""
195+
if color_tint is None:
194196
return current_lum
195-
return current_lum * (1.0 + color_tint)
197+
198+
current_lum *= 255
199+
200+
if color_tint < 0:
201+
return current_lum * (1.0 + color_tint) / 255
202+
203+
return (current_lum * (1.0 - color_tint) + (255 - 255 * (1.0 - color_tint))) / 255
196204

197205
bg_color = openpyxl_style.fill.fgColor.rgb
198206

0 commit comments

Comments
 (0)