backend: cleanup

This commit is contained in:
Dylan Araps 2018-03-31 15:47:11 +11:00
parent dc09707a87
commit b514de8e8a
4 changed files with 46 additions and 59 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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