summaryrefslogtreecommitdiff
path: root/pywal/backends
diff options
context:
space:
mode:
authorDylan Araps <dylan.araps@gmail.com>2018-03-31 10:30:11 +1100
committerDylan Araps <dylan.araps@gmail.com>2018-03-31 10:30:11 +1100
commit37bc93cc0327e131c2640082a19ed3b18c3a5a21 (patch)
tree3009fff89194a418de58f6ba0eff99208822f68e /pywal/backends
parent6430724400e698c6971bf605216cbf4a4d203a12 (diff)
backend: Add Colorz
Diffstat (limited to 'pywal/backends')
-rw-r--r--pywal/backends/__init__.py2
-rw-r--r--pywal/backends/colorthief.py56
-rw-r--r--pywal/backends/colorz.py49
-rw-r--r--pywal/backends/wal.py9
4 files changed, 87 insertions, 29 deletions
diff --git a/pywal/backends/__init__.py b/pywal/backends/__init__.py
index 90cae0c..99ef00d 100644
--- a/pywal/backends/__init__.py
+++ b/pywal/backends/__init__.py
@@ -10,9 +10,11 @@ Created by Dylan Araps.
"""
from . import colorthief
+from . import colorz
from . import wal
__all__ = [
"colorthief",
+ "colorz",
"wal",
]
diff --git a/pywal/backends/colorthief.py b/pywal/backends/colorthief.py
index 71877aa..78ad928 100644
--- a/pywal/backends/colorthief.py
+++ b/pywal/backends/colorthief.py
@@ -9,31 +9,6 @@ from .. import util
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):
"""Loop until 16 colors are generated."""
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]
+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):
"""Get colorscheme."""
colors = gen_colors(img, color_count)
- return adjust(img, colors)
+ return adjust(img, colors, light)
diff --git a/pywal/backends/colorz.py b/pywal/backends/colorz.py
new file mode 100644
index 0000000..84acf16
--- /dev/null
+++ b/pywal/backends/colorz.py
@@ -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)
diff --git a/pywal/backends/wal.py b/pywal/backends/wal.py
index 814ef20..5d18663 100644
--- a/pywal/backends/wal.py
+++ b/pywal/backends/wal.py
@@ -57,7 +57,7 @@ def gen_colors(img, color_count):
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."""
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[15] = util.blend_color(raw_colors[15], "#EEEEEE")
- colors = {"wallpaper": img, "alpha": util.Color.alpha_num,
- "special": {}, "colors": {}}
+ colors = {"wallpaper": img,
+ "alpha": util.Color.alpha_num,
+ "special": {},
+ "colors": {}}
+
colors["special"]["background"] = raw_colors[0]
colors["special"]["foreground"] = raw_colors[15]
colors["special"]["cursor"] = raw_colors[15]