mirror of
https://github.com/dylanaraps/pywal.git
synced 2025-06-19 17:19:08 +02:00
Merge a60a91f9f093ca8d3597257cedc0b3ab2f68c2fc into 236aa48e741ff8d65c4c3826db2813bf2ee6f352
This commit is contained in:
commit
69501dac7b
@ -53,6 +53,9 @@ def get_args():
|
||||
"flag is used: Go through the images in order "
|
||||
"instead of shuffled.")
|
||||
|
||||
arg.add_argument("--cols16", action="store_true",
|
||||
help="Use 16 color output. ")
|
||||
|
||||
arg.add_argument("--recursive", action="store_true",
|
||||
help="When pywal is given a directory as input and this "
|
||||
"flag is used: Search for images recursively in "
|
||||
@ -175,7 +178,7 @@ def parse_args(parser):
|
||||
if args.i:
|
||||
image_file = image.get(args.i, iterative=args.iterative,
|
||||
recursive=args.recursive)
|
||||
colors_plain = colors.get(image_file, args.l, args.backend,
|
||||
colors_plain = colors.get(image_file, args.l, args.cols16, args.backend,
|
||||
sat=args.saturate)
|
||||
|
||||
if args.theme:
|
||||
@ -186,7 +189,7 @@ def parse_args(parser):
|
||||
|
||||
if args.w:
|
||||
cached_wallpaper = util.read_file(os.path.join(CACHE_DIR, "wal"))
|
||||
colors_plain = colors.get(cached_wallpaper[0], args.l, args.backend,
|
||||
colors_plain = colors.get(cached_wallpaper[0], args.l, args.cols16, args.backend,
|
||||
sat=args.saturate)
|
||||
|
||||
if args.b:
|
||||
|
@ -12,6 +12,7 @@ except ImportError:
|
||||
logging.error("Try another backend. (wal --backend)")
|
||||
sys.exit(1)
|
||||
|
||||
from .. import colors
|
||||
from .. import util
|
||||
|
||||
|
||||
@ -36,29 +37,15 @@ def gen_colors(img):
|
||||
return [util.rgb_to_hex(color) for color in raw_colors]
|
||||
|
||||
|
||||
def adjust(cols, light):
|
||||
def adjust(cols, light, cols16):
|
||||
"""Create palette."""
|
||||
cols.sort(key=util.rgb_to_yiq)
|
||||
raw_colors = [*cols, *cols]
|
||||
|
||||
if light:
|
||||
raw_colors[0] = util.lighten_color(cols[0], 0.90)
|
||||
raw_colors[7] = util.darken_color(cols[0], 0.75)
|
||||
|
||||
else:
|
||||
for color in raw_colors:
|
||||
color = util.lighten_color(color, 0.40)
|
||||
|
||||
raw_colors[0] = util.darken_color(cols[0], 0.80)
|
||||
raw_colors[7] = util.lighten_color(cols[0], 0.60)
|
||||
|
||||
raw_colors[8] = util.lighten_color(cols[0], 0.20)
|
||||
raw_colors[15] = raw_colors[7]
|
||||
|
||||
return raw_colors
|
||||
return colors.generic_adjust(raw_colors, light, cols16)
|
||||
|
||||
|
||||
def get(img, light=False):
|
||||
def get(img, light=False, cols16=False):
|
||||
"""Get colorscheme."""
|
||||
cols = gen_colors(img)
|
||||
return adjust(cols, light)
|
||||
return adjust(cols, light, cols16)
|
||||
|
@ -23,15 +23,15 @@ def gen_colors(img):
|
||||
return [util.rgb_to_hex([*color[0]]) for color in raw_colors]
|
||||
|
||||
|
||||
def adjust(cols, light):
|
||||
def adjust(cols, light, cols16):
|
||||
"""Create palette."""
|
||||
raw_colors = [cols[0], *cols, "#FFFFFF",
|
||||
"#000000", *cols, "#FFFFFF"]
|
||||
|
||||
return colors.generic_adjust(raw_colors, light)
|
||||
return colors.generic_adjust(raw_colors, light, cols16)
|
||||
|
||||
|
||||
def get(img, light=False):
|
||||
def get(img, light=False, cols16=False):
|
||||
"""Get colorscheme."""
|
||||
cols = gen_colors(img)
|
||||
|
||||
@ -40,4 +40,4 @@ def get(img, light=False):
|
||||
logging.error("Try another backend or another image. (wal --backend)")
|
||||
sys.exit(1)
|
||||
|
||||
return adjust(cols, light)
|
||||
return adjust(cols, light, cols16)
|
||||
|
@ -13,6 +13,7 @@ except ImportError:
|
||||
sys.exit(1)
|
||||
|
||||
from .. import util
|
||||
from .. import colors
|
||||
|
||||
|
||||
def gen_colors(img):
|
||||
@ -22,29 +23,15 @@ def gen_colors(img):
|
||||
return [util.rgb_to_hex(color) for color in raw_colors]
|
||||
|
||||
|
||||
def adjust(cols, light):
|
||||
def adjust(cols, light, cols16):
|
||||
"""Create palette."""
|
||||
cols.sort(key=util.rgb_to_yiq)
|
||||
raw_colors = [*cols, *cols]
|
||||
|
||||
if light:
|
||||
raw_colors[0] = util.lighten_color(cols[0], 0.90)
|
||||
raw_colors[7] = util.darken_color(cols[0], 0.75)
|
||||
|
||||
else:
|
||||
for color in raw_colors:
|
||||
color = util.lighten_color(color, 0.40)
|
||||
|
||||
raw_colors[0] = util.darken_color(cols[0], 0.80)
|
||||
raw_colors[7] = util.lighten_color(cols[0], 0.60)
|
||||
|
||||
raw_colors[8] = util.lighten_color(cols[0], 0.20)
|
||||
raw_colors[15] = raw_colors[7]
|
||||
|
||||
return raw_colors
|
||||
return colors.generic_adjust(raw_colors, light, cols16)
|
||||
|
||||
|
||||
def get(img, light=False):
|
||||
def get(img, light=False, cols16=False):
|
||||
"""Get colorscheme."""
|
||||
cols = gen_colors(img)
|
||||
return adjust(cols, light)
|
||||
return adjust(cols, light, cols16)
|
||||
|
@ -22,16 +22,16 @@ def gen_colors(img):
|
||||
return [util.rgb_to_hex(col[1]) for col in palette]
|
||||
|
||||
|
||||
def adjust(cols, light):
|
||||
def adjust(cols, light, cols16):
|
||||
"""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)
|
||||
return colors.generic_adjust(raw_colors, light, cols16)
|
||||
|
||||
|
||||
def get(img, light=False):
|
||||
def get(img, light=False, cols16=False):
|
||||
"""Get colorscheme."""
|
||||
cols = gen_colors(img)
|
||||
return adjust(cols, light)
|
||||
return adjust(cols, light, cols16)
|
||||
|
@ -16,15 +16,15 @@ def gen_colors(img):
|
||||
return subprocess.check_output([*cmd, img]).splitlines()
|
||||
|
||||
|
||||
def adjust(cols, light):
|
||||
def adjust(cols, light, cols16):
|
||||
"""Create palette."""
|
||||
cols.sort(key=util.rgb_to_yiq)
|
||||
raw_colors = [*cols[8:], *cols[8:]]
|
||||
|
||||
return colors.generic_adjust(raw_colors, light)
|
||||
return colors.generic_adjust(raw_colors, light, cols16)
|
||||
|
||||
|
||||
def get(img, light=False):
|
||||
def get(img, light=False, cols16=False):
|
||||
"""Get colorscheme."""
|
||||
if not shutil.which("schemer2"):
|
||||
logging.error("Schemer2 wasn't found on your system.")
|
||||
@ -32,4 +32,4 @@ def get(img, light=False):
|
||||
sys.exit(1)
|
||||
|
||||
cols = [col.decode('UTF-8') for col in gen_colors(img)]
|
||||
return adjust(cols, light)
|
||||
return adjust(cols, light, cols16)
|
||||
|
@ -7,6 +7,7 @@ import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
from .. import colors
|
||||
from .. import util
|
||||
|
||||
|
||||
@ -54,34 +55,15 @@ def gen_colors(img):
|
||||
return [re.search("#.{6}", str(col)).group(0) for col in raw_colors[1:]]
|
||||
|
||||
|
||||
def adjust(colors, light):
|
||||
def adjust(cols, light, cols16):
|
||||
"""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]
|
||||
raw_colors = cols[:1] + cols[8:16] + cols[8:-1]
|
||||
|
||||
# Manually adjust colors.
|
||||
if light:
|
||||
for color in raw_colors:
|
||||
color = util.saturate_color(color, 0.5)
|
||||
|
||||
raw_colors[0] = util.lighten_color(colors[-1], 0.85)
|
||||
raw_colors[7] = colors[0]
|
||||
raw_colors[8] = util.darken_color(colors[-1], 0.4)
|
||||
raw_colors[15] = colors[0]
|
||||
|
||||
else:
|
||||
# Darken the background color slightly.
|
||||
if raw_colors[0][1] != "0":
|
||||
raw_colors[0] = util.darken_color(raw_colors[0], 0.40)
|
||||
|
||||
raw_colors[7] = util.blend_color(raw_colors[7], "#EEEEEE")
|
||||
raw_colors[8] = util.darken_color(raw_colors[7], 0.30)
|
||||
raw_colors[15] = util.blend_color(raw_colors[15], "#EEEEEE")
|
||||
|
||||
return raw_colors
|
||||
return colors.generic_adjust(raw_colors, light, cols16)
|
||||
|
||||
|
||||
def get(img, light=False):
|
||||
def get(img, light=False, cols16=False):
|
||||
"""Get colorscheme."""
|
||||
colors = gen_colors(img)
|
||||
return adjust(colors, light)
|
||||
return adjust(colors, light, cols16)
|
||||
|
@ -60,24 +60,51 @@ def colors_to_dict(colors, img):
|
||||
}
|
||||
|
||||
|
||||
def generic_adjust(colors, light):
|
||||
def generic_adjust(colors, light, cols16):
|
||||
"""Generic color adjustment for themers."""
|
||||
if light:
|
||||
for color in colors:
|
||||
color = util.saturate_color(color, 0.60)
|
||||
color = util.darken_color(color, 0.5)
|
||||
|
||||
if cols16:
|
||||
colors[0] = util.lighten_color(colors[0], 0.95)
|
||||
colors[7] = util.darken_color(colors[0], 0.50)
|
||||
colors[8] = util.darken_color(colors[0], 0.25)
|
||||
colors[1] = util.darken_color(colors[1], 0.25)
|
||||
colors[2] = util.darken_color(colors[2], 0.25)
|
||||
colors[3] = util.darken_color(colors[3], 0.25)
|
||||
colors[4] = util.darken_color(colors[4], 0.25)
|
||||
colors[5] = util.darken_color(colors[5], 0.25)
|
||||
colors[6] = util.darken_color(colors[6], 0.25)
|
||||
colors[15] = util.darken_color(colors[0], 0.75)
|
||||
|
||||
else:
|
||||
colors[0] = util.lighten_color(colors[0], 0.95)
|
||||
colors[7] = util.darken_color(colors[0], 0.75)
|
||||
colors[8] = util.darken_color(colors[0], 0.25)
|
||||
colors[15] = colors[7]
|
||||
|
||||
else:
|
||||
if cols16:
|
||||
colors[0] = util.darken_color(colors[0], 0.80)
|
||||
colors[7] = util.lighten_color(colors[0], 0.50)
|
||||
colors[8] = util.lighten_color(colors[0], 0.25)
|
||||
colors[1] = util.darken_color(colors[1], 0.25)
|
||||
colors[2] = util.darken_color(colors[2], 0.25)
|
||||
colors[3] = util.darken_color(colors[3], 0.25)
|
||||
colors[4] = util.darken_color(colors[4], 0.25)
|
||||
colors[5] = util.darken_color(colors[5], 0.25)
|
||||
colors[6] = util.darken_color(colors[6], 0.25)
|
||||
colors[15] = util.lighten_color(colors[0], 0.75)
|
||||
|
||||
else:
|
||||
colors[0] = util.darken_color(colors[0], 0.80)
|
||||
colors[7] = util.lighten_color(colors[0], 0.75)
|
||||
colors[8] = util.lighten_color(colors[0], 0.25)
|
||||
colors[15] = colors[7]
|
||||
|
||||
|
||||
return colors
|
||||
|
||||
|
||||
@ -91,15 +118,16 @@ def saturate_colors(colors, amount):
|
||||
return colors
|
||||
|
||||
|
||||
def cache_fname(img, backend, light, cache_dir, sat=""):
|
||||
def cache_fname(img, backend, cols16, light, cache_dir, sat=""):
|
||||
"""Create the cache file name."""
|
||||
color_type = "light" if light else "dark"
|
||||
color_num = "16" if cols16 else "9"
|
||||
file_name = re.sub("[/|\\|.]", "_", img)
|
||||
file_size = os.path.getsize(img)
|
||||
|
||||
file_parts = [file_name, color_type, backend,
|
||||
file_parts = [file_name, color_num, color_type, backend,
|
||||
sat, file_size, __cache_version__]
|
||||
return [cache_dir, "schemes", "%s_%s_%s_%s_%s_%s.json" % (*file_parts,)]
|
||||
return [cache_dir, "schemes", "%s_%s_%s_%s_%s_%s_%s.json" % (*file_parts,)]
|
||||
|
||||
|
||||
def get_backend(backend):
|
||||
@ -126,10 +154,10 @@ def palette():
|
||||
print("\n")
|
||||
|
||||
|
||||
def get(img, light=False, backend="wal", cache_dir=CACHE_DIR, sat=""):
|
||||
def get(img, light=False, cols16=False, backend="wal", cache_dir=CACHE_DIR, sat=""):
|
||||
"""Generate a palette."""
|
||||
# home_dylan_img_jpg_backend_1.2.2.json
|
||||
cache_name = cache_fname(img, backend, light, cache_dir, sat)
|
||||
cache_name = cache_fname(img, backend, cols16, light, cache_dir, sat)
|
||||
cache_file = os.path.join(*cache_name)
|
||||
|
||||
if os.path.isfile(cache_file):
|
||||
@ -151,7 +179,7 @@ def get(img, light=False, backend="wal", cache_dir=CACHE_DIR, sat=""):
|
||||
|
||||
logging.info("Using %s backend.", backend)
|
||||
backend = sys.modules["pywal.backends.%s" % backend]
|
||||
colors = getattr(backend, "get")(img, light)
|
||||
colors = getattr(backend, "get")(img, light, cols16)
|
||||
colors = colors_to_dict(saturate_colors(colors, sat), img)
|
||||
|
||||
util.save_file_json(colors, cache_file)
|
||||
|
Loading…
x
Reference in New Issue
Block a user