mirror of
https://github.com/dylanaraps/pywal.git
synced 2025-01-09 15:38:30 +01:00
colors: Added saturate option. Closes #166
This commit is contained in:
parent
46351f20ac
commit
7704f529c1
@ -1,5 +1,5 @@
|
||||
[BASIC]
|
||||
good-names=i,j,k,n,x,y,fg,bg,r,g,b,i3,r1,r2,r3,g1,g2,g3,b1,b2,b3,h,s,v
|
||||
good-names=i,j,k,n,x,y,fg,bg,r,g,b,i3,r1,r2,r3,g1,g2,g3,b1,b2,b3,h,s,v,l
|
||||
|
||||
[MESSAGES CONTROL]
|
||||
# inconsistent-return-statements:
|
||||
|
@ -53,6 +53,9 @@ def get_args():
|
||||
"flag is used: Go through the images in order "
|
||||
"instead of shuffled.")
|
||||
|
||||
arg.add_argument("--saturate", metavar="0.0-1.0",
|
||||
help="Set the color saturation.")
|
||||
|
||||
arg.add_argument("-c", action="store_true",
|
||||
help="Delete all cached colorschemes.")
|
||||
|
||||
@ -147,7 +150,8 @@ def parse_args(parser):
|
||||
|
||||
if args.i:
|
||||
image_file = image.get(args.i, iterative=args.iterative)
|
||||
colors_plain = colors.get(image_file, args.l, args.backend)
|
||||
colors_plain = colors.get(image_file, args.l, args.backend,
|
||||
sat=args.saturate)
|
||||
|
||||
if args.theme:
|
||||
colors_plain = theme.file(args.theme, args.l)
|
||||
|
@ -73,13 +73,23 @@ def generic_adjust(colors, light):
|
||||
return colors
|
||||
|
||||
|
||||
def cache_fname(img, backend, light, cache_dir):
|
||||
def saturate_colors(colors, amount):
|
||||
"""Saturate all colors."""
|
||||
if float(amount) <= 1.0:
|
||||
for i, _ in enumerate(colors):
|
||||
if i not in [0, 7, 8, 15]:
|
||||
colors[i] = util.saturate_color(colors[i], float(amount))
|
||||
|
||||
return colors
|
||||
|
||||
|
||||
def cache_fname(img, backend, light, cache_dir, sat=""):
|
||||
"""Create the cache file name."""
|
||||
color_type = "light" if light else "dark"
|
||||
file_name = re.sub("[/|\\|.]", "_", img)
|
||||
|
||||
file_parts = [file_name, color_type, backend, __cache_version__]
|
||||
return [cache_dir, "schemes", "%s_%s_%s_%s.json" % (*file_parts,)]
|
||||
file_parts = [file_name, color_type, backend, sat, __cache_version__]
|
||||
return [cache_dir, "schemes", "%s_%s_%s_%s_%s.json" % (*file_parts,)]
|
||||
|
||||
|
||||
def get_backend(backend):
|
||||
@ -106,10 +116,10 @@ def palette():
|
||||
print("\n")
|
||||
|
||||
|
||||
def get(img, light=False, backend="wal", cache_dir=CACHE_DIR):
|
||||
def get(img, light=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)
|
||||
cache_name = cache_fname(img, backend, light, cache_dir, sat)
|
||||
cache_file = os.path.join(*cache_name)
|
||||
|
||||
if os.path.isfile(cache_file):
|
||||
@ -136,7 +146,8 @@ def get(img, light=False, backend="wal", cache_dir=CACHE_DIR):
|
||||
|
||||
logging.info("Using %s backend.", backend)
|
||||
backend = sys.modules["pywal.backends.%s" % backend]
|
||||
colors = colors_to_dict(getattr(backend, "get")(img, light), img)
|
||||
colors = getattr(backend, "get")(img, light)
|
||||
colors = colors_to_dict(saturate_colors(colors, sat), img)
|
||||
|
||||
util.save_file_json(colors, cache_file)
|
||||
logging.info("Generation complete.")
|
||||
|
@ -149,10 +149,9 @@ def saturate_color(color, amount):
|
||||
"""Saturate a hex color."""
|
||||
r, g, b = hex_to_rgb(color)
|
||||
r, g, b = [x/255.0 for x in (r, g, b)]
|
||||
h, s, v = colorsys.rgb_to_hsv(r, g, b)
|
||||
h, l, s = colorsys.rgb_to_hls(r, g, b)
|
||||
s = amount
|
||||
v = 0.2
|
||||
r, g, b = colorsys.hls_to_rgb(h, s, v)
|
||||
r, g, b = colorsys.hls_to_rgb(h, l, s)
|
||||
r, g, b = [x*255.0 for x in (r, g, b)]
|
||||
|
||||
return rgb_to_hex((int(r), int(g), int(b)))
|
||||
|
Loading…
Reference in New Issue
Block a user