efficient vim config
[dotfiles/.git] / .local / lib / python3.9 / site-packages / pywal / backends / colorz.py
1 """
2 Generate a colorscheme using Colorz.
3 """
4 import logging
5 import sys
6
7 try:
8     import colorz
9
10 except ImportError:
11     logging.error("colorz wasn't found on your system.")
12     logging.error("Try another backend. (wal --backend)")
13     sys.exit(1)
14
15 from .. import colors
16 from .. import util
17
18
19 def gen_colors(img):
20     """Generate a colorscheme using Colorz."""
21     # pylint: disable=not-callable
22     raw_colors = colorz.colorz(img, n=6, bold_add=0)
23     return [util.rgb_to_hex([*color[0]]) for color in raw_colors]
24
25
26 def adjust(cols, light):
27     """Create palette."""
28     raw_colors = [cols[0], *cols, "#FFFFFF",
29                   "#000000", *cols, "#FFFFFF"]
30
31     return colors.generic_adjust(raw_colors, light)
32
33
34 def get(img, light=False):
35     """Get colorscheme."""
36     cols = gen_colors(img)
37
38     if len(cols) < 6:
39         logging.error("colorz failed to generate enough colors.")
40         logging.error("Try another backend or another image. (wal --backend)")
41         sys.exit(1)
42
43     return adjust(cols, light)