epub converter: prettify color_reader.py

This commit is contained in:
shirshasa
2021-04-29 09:32:46 +03:00
parent 39bc2b92a9
commit e06bc58257

View File

@@ -13,11 +13,11 @@ def closest_colour_rgb(requested_colour):
return min_colours[min(min_colours.keys())]
def get_rgb_colour_name(c):
def get_rgb_color_name(color):
try:
closest_name = actual_name = rgb_to_name(c, 'html4')
closest_name = actual_name = rgb_to_name(color, 'html4')
except ValueError:
closest_name = closest_colour_rgb(c)
closest_name = closest_colour_rgb(color)
actual_name = None
if actual_name:
return actual_name
@@ -25,16 +25,16 @@ def get_rgb_colour_name(c):
return closest_name
def get_hex_colour_name(c):
def get_hex_color_name(color):
try:
c = hex_to_rgb(c)
color = hex_to_rgb(color)
except ValueError:
return ''
try:
closest_name = actual_name = rgb_to_name(c, 'html4')
closest_name = actual_name = rgb_to_name(color, 'html4')
except ValueError:
closest_name = closest_colour_rgb(c)
closest_name = closest_colour_rgb(color)
actual_name = None
if actual_name:
return actual_name
@@ -52,11 +52,11 @@ def str2color_name(s: str):
return ''
if len(rgb) != 3:
return ''
name = get_rgb_colour_name(rgb)
return name
name = get_rgb_color_name(rgb)
return name
elif '#' in s:
name = get_hex_colour_name(s)
name = get_hex_color_name(s)
return name
elif s in html4_hex_to_names.items():
@@ -80,10 +80,10 @@ if __name__ == '__main__':
]
for c in colors:
name = get_rgb_colour_name(c)
print("Actual colour:", c, ", closest colour name:", name)
n = get_rgb_color_name(c)
print("Actual colour:", c, ", closest colour name:", n)
for c in hex_colors:
name = get_hex_colour_name(c)
print("Actual colour:", c, ", closest colour name:", name)
n = get_hex_color_name(c)
print("Actual colour:", c, ", closest colour name:", n)
print()