mirror of
https://github.com/dylanaraps/pywal.git
synced 2025-01-10 07:58:12 +01:00
backend: Add Colorz
This commit is contained in:
parent
6430724400
commit
37bc93cc03
@ -10,9 +10,11 @@ Created by Dylan Araps.
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
from . import colorthief
|
from . import colorthief
|
||||||
|
from . import colorz
|
||||||
from . import wal
|
from . import wal
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"colorthief",
|
"colorthief",
|
||||||
|
"colorz",
|
||||||
"wal",
|
"wal",
|
||||||
]
|
]
|
||||||
|
@ -9,31 +9,6 @@ from .. import util
|
|||||||
from ..settings import COLOR_COUNT
|
from ..settings import COLOR_COUNT
|
||||||
|
|
||||||
|
|
||||||
def adjust(img, colors):
|
|
||||||
"""Create palette."""
|
|
||||||
raw_colors = colors[:1] + colors[8:16] + colors[8:-1]
|
|
||||||
|
|
||||||
# Modify colors to make a better scheme.
|
|
||||||
raw_colors[0] = util.darken_color(colors[0], 0.80)
|
|
||||||
raw_colors[15] = util.lighten_color(colors[15], 0.80)
|
|
||||||
raw_colors[7] = raw_colors[15]
|
|
||||||
|
|
||||||
colors = {"wallpaper": img, "alpha": util.Color.alpha_num,
|
|
||||||
"special": {}, "colors": {}}
|
|
||||||
|
|
||||||
for i, color in enumerate(raw_colors):
|
|
||||||
colors["colors"]["color%s" % i] = util.lighten_color(color, 0.25)
|
|
||||||
|
|
||||||
raw_colors[8] = util.blend_color(raw_colors[0], raw_colors[15])
|
|
||||||
|
|
||||||
colors["colors"]["color0"] = raw_colors[0]
|
|
||||||
colors["special"]["background"] = raw_colors[0]
|
|
||||||
colors["special"]["foreground"] = raw_colors[15]
|
|
||||||
colors["special"]["cursor"] = raw_colors[1]
|
|
||||||
|
|
||||||
return colors
|
|
||||||
|
|
||||||
|
|
||||||
def gen_colors(img, color_count):
|
def gen_colors(img, color_count):
|
||||||
"""Loop until 16 colors are generated."""
|
"""Loop until 16 colors are generated."""
|
||||||
color_thief = ColorThief(img)
|
color_thief = ColorThief(img)
|
||||||
@ -58,7 +33,36 @@ def gen_colors(img, color_count):
|
|||||||
return [util.rgb_to_hex(color) for color in raw_colors]
|
return [util.rgb_to_hex(color) for color in raw_colors]
|
||||||
|
|
||||||
|
|
||||||
|
def adjust(img, colors, light):
|
||||||
|
"""Create palette."""
|
||||||
|
if light:
|
||||||
|
print("colors: Colortheif backend doesn't support light themes.")
|
||||||
|
|
||||||
|
raw_colors = colors[:1] + colors[8:16] + colors[8:-1]
|
||||||
|
|
||||||
|
raw_colors[0] = util.darken_color(colors[0], 0.80)
|
||||||
|
raw_colors[15] = util.lighten_color(colors[15], 0.80)
|
||||||
|
raw_colors[7] = raw_colors[15]
|
||||||
|
|
||||||
|
colors = {"wallpaper": img,
|
||||||
|
"alpha": util.Color.alpha_num,
|
||||||
|
"special": {},
|
||||||
|
"colors": {}}
|
||||||
|
|
||||||
|
for i, color in enumerate(raw_colors):
|
||||||
|
colors["colors"]["color%s" % i] = util.lighten_color(color, 0.25)
|
||||||
|
|
||||||
|
raw_colors[8] = util.blend_color(raw_colors[0], raw_colors[15])
|
||||||
|
|
||||||
|
colors["colors"]["color0"] = raw_colors[0]
|
||||||
|
colors["special"]["background"] = raw_colors[0]
|
||||||
|
colors["special"]["foreground"] = raw_colors[15]
|
||||||
|
colors["special"]["cursor"] = raw_colors[1]
|
||||||
|
|
||||||
|
return colors
|
||||||
|
|
||||||
|
|
||||||
def get(img, color_count=COLOR_COUNT, light=False):
|
def get(img, color_count=COLOR_COUNT, light=False):
|
||||||
"""Get colorscheme."""
|
"""Get colorscheme."""
|
||||||
colors = gen_colors(img, color_count)
|
colors = gen_colors(img, color_count)
|
||||||
return adjust(img, colors)
|
return adjust(img, colors, light)
|
||||||
|
49
pywal/backends/colorz.py
Normal file
49
pywal/backends/colorz.py
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
"""
|
||||||
|
Generate a colorscheme using Colorz.
|
||||||
|
"""
|
||||||
|
import subprocess
|
||||||
|
|
||||||
|
from .. import util
|
||||||
|
from ..settings import COLOR_COUNT
|
||||||
|
|
||||||
|
|
||||||
|
def gen_colors(img, color_count):
|
||||||
|
"""Generate a colorscheme using Colorz."""
|
||||||
|
flags = ["-n", "6", "--bold", "0", "--no-preview"]
|
||||||
|
|
||||||
|
return subprocess.check_output(["colorz", *flags, img]).splitlines()
|
||||||
|
|
||||||
|
|
||||||
|
def adjust(img, colors, light):
|
||||||
|
"""Create palette."""
|
||||||
|
if light:
|
||||||
|
print("colors: Colorz backend doesn't support light themes.")
|
||||||
|
|
||||||
|
raw_colors = ["#000000", *colors, "#FFFFFF",
|
||||||
|
"#333333", *colors, "#FFFFFF"]
|
||||||
|
|
||||||
|
raw_colors[0] = util.darken_color(colors[0], 0.75)
|
||||||
|
raw_colors[8] = util.darken_color(colors[0], 0.25)
|
||||||
|
raw_colors[7] = util.lighten_color(colors[0], 0.75)
|
||||||
|
raw_colors[15] = raw_colors[7]
|
||||||
|
|
||||||
|
colors = {"wallpaper": img,
|
||||||
|
"alpha": util.Color.alpha_num,
|
||||||
|
"special": {},
|
||||||
|
"colors": {}}
|
||||||
|
|
||||||
|
for i, color in enumerate(raw_colors):
|
||||||
|
colors["colors"]["color%s" % i] = color
|
||||||
|
|
||||||
|
colors["special"]["background"] = raw_colors[0]
|
||||||
|
colors["special"]["foreground"] = raw_colors[15]
|
||||||
|
colors["special"]["cursor"] = raw_colors[1]
|
||||||
|
|
||||||
|
return colors
|
||||||
|
|
||||||
|
|
||||||
|
def get(img, color_count=COLOR_COUNT, light=False):
|
||||||
|
"""Get colorscheme."""
|
||||||
|
colors = gen_colors(img, color_count)
|
||||||
|
colors = [color.decode('UTF-8').split()[0] for color in colors]
|
||||||
|
return adjust(img, colors, light)
|
@ -57,7 +57,7 @@ def gen_colors(img, color_count):
|
|||||||
|
|
||||||
|
|
||||||
def adjust(img, colors, light):
|
def adjust(img, colors, light):
|
||||||
"""Sort the generated colors and store them in a dict that
|
"""Adjust the generated colors and store them in a dict that
|
||||||
we will later save in json format."""
|
we will later save in json format."""
|
||||||
raw_colors = colors[:1] + colors[8:16] + colors[8:-1]
|
raw_colors = colors[:1] + colors[8:16] + colors[8:-1]
|
||||||
|
|
||||||
@ -78,8 +78,11 @@ def adjust(img, colors, light):
|
|||||||
raw_colors[8] = util.darken_color(raw_colors[7], 0.30)
|
raw_colors[8] = util.darken_color(raw_colors[7], 0.30)
|
||||||
raw_colors[15] = util.blend_color(raw_colors[15], "#EEEEEE")
|
raw_colors[15] = util.blend_color(raw_colors[15], "#EEEEEE")
|
||||||
|
|
||||||
colors = {"wallpaper": img, "alpha": util.Color.alpha_num,
|
colors = {"wallpaper": img,
|
||||||
"special": {}, "colors": {}}
|
"alpha": util.Color.alpha_num,
|
||||||
|
"special": {},
|
||||||
|
"colors": {}}
|
||||||
|
|
||||||
colors["special"]["background"] = raw_colors[0]
|
colors["special"]["background"] = raw_colors[0]
|
||||||
colors["special"]["foreground"] = raw_colors[15]
|
colors["special"]["foreground"] = raw_colors[15]
|
||||||
colors["special"]["cursor"] = raw_colors[15]
|
colors["special"]["cursor"] = raw_colors[15]
|
||||||
|
@ -13,6 +13,7 @@ def get(backend_type="wal"):
|
|||||||
"""Get backend function name from name."""
|
"""Get backend function name from name."""
|
||||||
return {
|
return {
|
||||||
"colorthief": backends.colorthief.get,
|
"colorthief": backends.colorthief.get,
|
||||||
|
"colorz": backends.colorz.get,
|
||||||
"wal": backends.wal.get,
|
"wal": backends.wal.get,
|
||||||
}.get(backend_type, backend_type)
|
}.get(backend_type, backend_type)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user