From b514de8e8a79c7524e43284c86be61f97063d3a9 Mon Sep 17 00:00:00 2001 From: Dylan Araps Date: Sat, 31 Mar 2018 15:47:11 +1100 Subject: [PATCH] backend: cleanup --- pywal/backends/colorthief.py | 20 ++++++++++---------- pywal/backends/colorz.py | 32 ++++++++------------------------ pywal/backends/schemer2.py | 31 +++++++------------------------ pywal/colors.py | 22 +++++++++++++++++++++- 4 files changed, 46 insertions(+), 59 deletions(-) diff --git a/pywal/backends/colorthief.py b/pywal/backends/colorthief.py index 7e1eec2..180af5f 100644 --- a/pywal/backends/colorthief.py +++ b/pywal/backends/colorthief.py @@ -36,23 +36,23 @@ def gen_colors(img): return [util.rgb_to_hex(color) for color in raw_colors] -def adjust(colors, light): +def adjust(cols, light): """Create palette.""" - colors.sort(key=util.rgb_to_yiq) - raw_colors = [*colors, *colors] + cols.sort(key=util.rgb_to_yiq) + raw_colors = [*cols, *cols] if light: - raw_colors[0] = util.lighten_color(colors[0], 0.90) - raw_colors[7] = util.darken_color(colors[0], 0.75) + 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(colors[0], 0.80) - raw_colors[7] = util.lighten_color(colors[0], 0.60) + 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(colors[0], 0.20) + raw_colors[8] = util.lighten_color(cols[0], 0.20) raw_colors[15] = raw_colors[7] return raw_colors @@ -60,5 +60,5 @@ def adjust(colors, light): def get(img, light=False): """Get colorscheme.""" - colors = gen_colors(img) - return adjust(colors, light) + cols = gen_colors(img) + return adjust(cols, light) diff --git a/pywal/backends/colorz.py b/pywal/backends/colorz.py index 776678e..44e75cb 100644 --- a/pywal/backends/colorz.py +++ b/pywal/backends/colorz.py @@ -5,6 +5,7 @@ import shutil import subprocess import sys +from .. import colors from .. import util @@ -14,30 +15,14 @@ def gen_colors(img): return subprocess.check_output([*cmd, img]).splitlines() -def adjust(colors, light): +def adjust(cols, light): """Create palette.""" # Create list with placeholder values. - raw_colors = ["#000000", *colors, "#FFFFFF", - "#333333", *colors, "#FFFFFF"] + bg = util.blend_color("#555555", cols[1]) + raw_colors = [bg, *cols, "#FFFFFF", + "#333333", *cols, "#FFFFFF"] - # Update placeholder values. - if light: - for color in raw_colors: - color = util.saturate_color(color, 0.50) - color = util.darken_color(color, 0.4) - - raw_colors[0] = util.lighten_color(colors[0], 0.9) - raw_colors[7] = util.darken_color(colors[0], 0.75) - raw_colors[8] = util.darken_color(colors[0], 0.25) - raw_colors[15] = raw_colors[7] - - else: - raw_colors[0] = util.darken_color(colors[0], 0.75) - raw_colors[7] = util.lighten_color(colors[0], 0.75) - raw_colors[8] = util.darken_color(colors[0], 0.25) - raw_colors[15] = raw_colors[7] - - return raw_colors + return colors.generic_adjust(raw_colors, light) def get(img, light=False): @@ -47,6 +32,5 @@ def get(img, light=False): "Try another backend. (wal --backend)") sys.exit(1) - colors = gen_colors(img) - colors = [color.decode('UTF-8').split()[0] for color in colors] - return adjust(colors, light) + cols = [col.decode('UTF-8').split()[0] for col in gen_colors(img)] + return adjust(cols, light) diff --git a/pywal/backends/schemer2.py b/pywal/backends/schemer2.py index 9523972..c3d81d7 100644 --- a/pywal/backends/schemer2.py +++ b/pywal/backends/schemer2.py @@ -5,6 +5,7 @@ import shutil import subprocess import sys +from .. import colors from .. import util @@ -14,30 +15,13 @@ def gen_colors(img): return subprocess.check_output([*cmd, img]).splitlines() -def adjust(colors, light): +def adjust(cols, light): """Create palette.""" # Create list with placeholder values. - colors.sort(key=util.rgb_to_yiq) - raw_colors = [*colors[8:], *colors[8:]] + cols.sort(key=util.rgb_to_yiq) + raw_colors = [*cols[8:], *cols[8:]] - # Update placeholder values. - if light: - for color in raw_colors: - color = util.saturate_color(color, 0.50) - color = util.darken_color(color, 0.4) - - raw_colors[0] = util.lighten_color(colors[0], 0.9) - raw_colors[7] = util.darken_color(colors[0], 0.75) - raw_colors[8] = util.darken_color(colors[0], 0.25) - raw_colors[15] = raw_colors[7] - - else: - raw_colors[0] = util.darken_color(colors[0], 0.75) - raw_colors[7] = util.lighten_color(colors[0], 0.75) - raw_colors[8] = util.lighten_color(colors[0], 0.25) - raw_colors[15] = raw_colors[7] - - return raw_colors + return colors.generic_adjust(raw_colors, light) def get(img, light=False): @@ -47,6 +31,5 @@ def get(img, light=False): "Try another backend. (wal --backend)") sys.exit(1) - colors = gen_colors(img) - colors = [color.decode('UTF-8') for color in colors] - return adjust(colors, light) + cols = [col.decode('UTF-8') for col in gen_colors(img)] + return adjust(cols, light) diff --git a/pywal/colors.py b/pywal/colors.py index d169c00..164f34a 100644 --- a/pywal/colors.py +++ b/pywal/colors.py @@ -3,7 +3,6 @@ Generate a palette using various backends. """ import os import re -import shutil import sys from . import backends @@ -33,6 +32,27 @@ def colors_to_dict(colors, img): return scheme +def generic_adjust(colors, light): + """Generic color adjustment for themers.""" + if light: + for color in colors: + color = util.saturate_color(color, 0.50) + color = util.darken_color(color, 0.4) + + colors[0] = util.lighten_color(colors[0], 0.9) + colors[7] = util.darken_color(colors[0], 0.75) + colors[8] = util.darken_color(colors[0], 0.25) + colors[15] = colors[7] + + else: + colors[0] = util.darken_color(colors[0], 0.75) + colors[7] = util.lighten_color(colors[0], 0.75) + colors[8] = util.lighten_color(colors[0], 0.25) + colors[15] = colors[7] + + return colors + + def gen(img, light=False, backend="wal", cache_dir=CACHE_DIR): """Generate a palette.""" # home_dylan_img_jpg_backend_1.2.2.json