From 78c353703d2cd3ee30fdef53a012a74c2e5a56c6 Mon Sep 17 00:00:00 2001 From: Todd Sonjiku Date: Mon, 3 May 2021 08:31:25 +0300 Subject: [PATCH] Made all backend scripts, use the newly modified adjust function from colors.py, that makes pywal generate darker shades for 1-7 --- pywal/backends/colorthief.py | 19 +++---------------- pywal/backends/wal.py | 28 +++++----------------------- pywal/colors.py | 33 +++++++++++++++++++++++---------- 3 files changed, 31 insertions(+), 49 deletions(-) diff --git a/pywal/backends/colorthief.py b/pywal/backends/colorthief.py index aae5bd0..961b120 100644 --- a/pywal/backends/colorthief.py +++ b/pywal/backends/colorthief.py @@ -13,6 +13,7 @@ except ImportError: sys.exit(1) from .. import util +from .. import colors def gen_colors(img): @@ -25,7 +26,7 @@ def gen_colors(img): if len(raw_colors) >= 8: break - if i == 10: + elif i == 10: logging.error("ColorThief couldn't generate a suitable palette.") sys.exit(1) @@ -41,21 +42,7 @@ def adjust(cols, light): cols.sort(key=util.rgb_to_yiq) raw_colors = [*cols, *cols] - if light: - raw_colors[0] = util.lighten_color(cols[0], 0.90) - raw_colors[7] = util.darken_color(cols[0], 0.75) - - else: - for color in raw_colors: - color = util.lighten_color(color, 0.40) - - raw_colors[0] = util.darken_color(cols[0], 0.80) - raw_colors[7] = util.lighten_color(cols[0], 0.60) - - raw_colors[8] = util.lighten_color(cols[0], 0.20) - raw_colors[15] = raw_colors[7] - - return raw_colors + return colors.generic_adjust(raw_colors, light) def get(img, light=False): diff --git a/pywal/backends/wal.py b/pywal/backends/wal.py index f05db41..521747c 100644 --- a/pywal/backends/wal.py +++ b/pywal/backends/wal.py @@ -8,6 +8,7 @@ import subprocess import sys from .. import util +from .. import colors def imagemagick(color_count, img, magick_command): @@ -43,7 +44,7 @@ def gen_colors(img): if len(raw_colors) > 16: break - if i == 19: + elif i == 19: logging.error("Imagemagick couldn't generate a suitable palette.") sys.exit(1) @@ -54,31 +55,12 @@ def gen_colors(img): return [re.search("#.{6}", str(col)).group(0) for col in raw_colors[1:]] -def adjust(colors, light): +def adjust(cols, light): """Adjust the generated colors and store them in a dict that we will later save in json format.""" - raw_colors = colors[:1] + colors[8:16] + colors[8:-1] + raw_colors = cols[:1] + cols[8:16] + cols[8:-1] - # Manually adjust colors. - if light: - for color in raw_colors: - color = util.saturate_color(color, 0.5) - - raw_colors[0] = util.lighten_color(colors[-1], 0.85) - raw_colors[7] = colors[0] - raw_colors[8] = util.darken_color(colors[-1], 0.4) - raw_colors[15] = colors[0] - - else: - # Darken the background color slightly. - if raw_colors[0][1] != "0": - raw_colors[0] = util.darken_color(raw_colors[0], 0.40) - - raw_colors[7] = util.blend_color(raw_colors[7], "#EEEEEE") - raw_colors[8] = util.darken_color(raw_colors[7], 0.30) - raw_colors[15] = util.blend_color(raw_colors[15], "#EEEEEE") - - return raw_colors + return colors.generic_adjust(raw_colors, light) def get(img, light=False): diff --git a/pywal/colors.py b/pywal/colors.py index 99d346d..36dd24a 100644 --- a/pywal/colors.py +++ b/pywal/colors.py @@ -59,16 +59,31 @@ def generic_adjust(colors, light): color = util.saturate_color(color, 0.60) color = util.darken_color(color, 0.5) - colors[0] = util.lighten_color(colors[0], 0.95) - colors[7] = util.darken_color(colors[0], 0.75) + + colors[0] = util.lighten_color(colors[0], 0.75) + colors[7] = util.darken_color(colors[0], 0.50) colors[8] = util.darken_color(colors[0], 0.25) - colors[15] = colors[7] + colors[1] = util.darken_color(colors[9], 0.25) + colors[2] = util.darken_color(colors[10], 0.25) + colors[3] = util.darken_color(colors[11], 0.25) + colors[4] = util.darken_color(colors[12], 0.25) + colors[5] = util.darken_color(colors[13], 0.25) + colors[6] = util.darken_color(colors[14], 0.25) + colors[15] = util.darken_color(colors[0], 0.75) else: - colors[0] = util.darken_color(colors[0], 0.80) - colors[7] = util.lighten_color(colors[0], 0.75) + + colors[0] = util.darken_color(colors[0], 0.75) + colors[7] = util.lighten_color(colors[0], 0.50) colors[8] = util.lighten_color(colors[0], 0.25) - colors[15] = colors[7] + colors[1] = util.darken_color(colors[9], 0.25) + colors[2] = util.darken_color(colors[10], 0.25) + colors[3] = util.darken_color(colors[11], 0.25) + colors[4] = util.darken_color(colors[12], 0.25) + colors[5] = util.darken_color(colors[13], 0.25) + colors[6] = util.darken_color(colors[14], 0.25) + colors[15] = util.lighten_color(colors[0], 0.75) + return colors @@ -87,11 +102,9 @@ def cache_fname(img, backend, light, cache_dir, sat=""): """Create the cache file name.""" color_type = "light" if light else "dark" file_name = re.sub("[/|\\|.]", "_", img) - file_size = os.path.getsize(img) - file_parts = [file_name, color_type, backend, - sat, file_size, __cache_version__] - return [cache_dir, "schemes", "%s_%s_%s_%s_%s_%s.json" % (*file_parts,)] + file_parts = [file_name, color_type, backend, sat, __cache_version__] + return [cache_dir, "schemes", "%s_%s_%s_%s_%s.json" % (*file_parts,)] def get_backend(backend):