backend: Add haishoku

This commit is contained in:
Dylan Araps 2018-03-31 16:31:26 +11:00
parent b514de8e8a
commit 435e4cd2a8
4 changed files with 39 additions and 2 deletions

View File

@ -11,12 +11,14 @@ Created by Dylan Araps.
from . import colorthief
from . import colorz
from . import haishoku
from . import schemer2
from . import wal
__all__ = [
"colorthief",
"colorz",
"haishoku",
"schemer2",
"wal",
]

View File

@ -17,8 +17,8 @@ def gen_colors(img):
def adjust(cols, light):
"""Create palette."""
# Create list with placeholder values.
bg = util.blend_color("#555555", cols[1])
raw_colors = [bg, *cols, "#FFFFFF",
"#333333", *cols, "#FFFFFF"]

View File

@ -0,0 +1,36 @@
"""
Generate a colorscheme using Haishoku.
"""
import sys
try:
from haishoku.haishoku import Haishoku
except ImportError:
print("error: Haishoku wasn't found on your system.",
"Try another backend. (wal --backend)")
sys.exit(1)
from .. import colors
from .. import util
def gen_colors(img):
"""Generate a colorscheme using Colorz."""
palette = Haishoku.getPalette(img)
return [util.rgb_to_hex(col[1]) for col in palette]
def adjust(cols, light):
"""Create palette."""
cols.sort(key=util.rgb_to_yiq)
raw_colors = [*cols, *cols]
raw_colors[0] = util.lighten_color(cols[0], 0.40)
return colors.generic_adjust(raw_colors, light)
def get(img, light=False):
"""Get colorscheme."""
cols = gen_colors(img)
return adjust(cols, light)

View File

@ -17,7 +17,6 @@ def gen_colors(img):
def adjust(cols, light):
"""Create palette."""
# Create list with placeholder values.
cols.sort(key=util.rgb_to_yiq)
raw_colors = [*cols[8:], *cols[8:]]