mirror of
https://github.com/dylanaraps/pywal.git
synced 2025-05-21 08:41:00 +02:00
backend: Add Schemer2
This commit is contained in:
parent
c10f7e7323
commit
dc09707a87
@ -11,10 +11,12 @@ Created by Dylan Araps.
|
|||||||
|
|
||||||
from . import colorthief
|
from . import colorthief
|
||||||
from . import colorz
|
from . import colorz
|
||||||
|
from . import schemer2
|
||||||
from . import wal
|
from . import wal
|
||||||
|
|
||||||
__all__ = [
|
__all__ = [
|
||||||
"colorthief",
|
"colorthief",
|
||||||
"colorz",
|
"colorz",
|
||||||
|
"schemer2",
|
||||||
"wal",
|
"wal",
|
||||||
]
|
]
|
||||||
|
@ -7,7 +7,7 @@ try:
|
|||||||
from colorthief import ColorThief
|
from colorthief import ColorThief
|
||||||
|
|
||||||
except ImportError:
|
except ImportError:
|
||||||
print("Error: ColorThief wasn't found on your system.",
|
print("error: ColorThief wasn't found on your system.",
|
||||||
"Try another backend. (wal --backend)")
|
"Try another backend. (wal --backend)")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
@ -10,8 +10,8 @@ from .. import util
|
|||||||
|
|
||||||
def gen_colors(img):
|
def gen_colors(img):
|
||||||
"""Generate a colorscheme using Colorz."""
|
"""Generate a colorscheme using Colorz."""
|
||||||
colorz = ["colorz", "-n", "6", "--bold", "0", "--no-preview"]
|
cmd = ["colorz", "-n", "6", "--bold", "0", "--no-preview"]
|
||||||
return subprocess.check_output([*colorz, img]).splitlines()
|
return subprocess.check_output([*cmd, img]).splitlines()
|
||||||
|
|
||||||
|
|
||||||
def adjust(colors, light):
|
def adjust(colors, light):
|
||||||
@ -43,7 +43,7 @@ def adjust(colors, light):
|
|||||||
def get(img, light=False):
|
def get(img, light=False):
|
||||||
"""Get colorscheme."""
|
"""Get colorscheme."""
|
||||||
if not shutil.which("colorz"):
|
if not shutil.which("colorz"):
|
||||||
print("Error: Colorz wasn't found on your system.",
|
print("error: Colorz wasn't found on your system.",
|
||||||
"Try another backend. (wal --backend)")
|
"Try another backend. (wal --backend)")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
52
pywal/backends/schemer2.py
Normal file
52
pywal/backends/schemer2.py
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
"""
|
||||||
|
Generate a colorscheme using Schemer2.
|
||||||
|
"""
|
||||||
|
import shutil
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
|
||||||
|
from .. import util
|
||||||
|
|
||||||
|
|
||||||
|
def gen_colors(img):
|
||||||
|
"""Generate a colorscheme using Colorz."""
|
||||||
|
cmd = ["schemer2", "-format", "img::colors", "-minBright", "75", "-in"]
|
||||||
|
return subprocess.check_output([*cmd, img]).splitlines()
|
||||||
|
|
||||||
|
|
||||||
|
def adjust(colors, light):
|
||||||
|
"""Create palette."""
|
||||||
|
# Create list with placeholder values.
|
||||||
|
colors.sort(key=util.rgb_to_yiq)
|
||||||
|
raw_colors = [*colors[8:], *colors[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
|
||||||
|
|
||||||
|
|
||||||
|
def get(img, light=False):
|
||||||
|
"""Get colorscheme."""
|
||||||
|
if not shutil.which("schemer2"):
|
||||||
|
print("error: Schemer2 wasn't found on your system.",
|
||||||
|
"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)
|
@ -26,7 +26,7 @@ def has_im():
|
|||||||
elif shutil.which("convert"):
|
elif shutil.which("convert"):
|
||||||
return ["convert"]
|
return ["convert"]
|
||||||
|
|
||||||
print("Error: ImageMagick wasn't found on your system.",
|
print("error: ImageMagick wasn't found on your system.",
|
||||||
"Try another backend. (wal --backend)")
|
"Try another backend. (wal --backend)")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user