Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use kwargs for cols16 and contrast #83

Merged
merged 2 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions pywal/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,10 +268,10 @@ def parse_args(parser):
colors_plain = colors.get(
image_file,
args.l,
args.cols16,
args.backend,
sat=args.saturate,
contrast=args.contrast,
c16=args.cols16,
cst=args.contrast,
)

if args.theme:
Expand All @@ -287,10 +287,10 @@ def parse_args(parser):
colors_plain = colors.get(
cached_wallpaper[0],
args.l,
args.cols16,
args.backend,
sat=args.saturate,
contrast=args.contrast,
c16=args.cols16,
cst=args.contrast,
)

if args.b:
Expand Down
26 changes: 20 additions & 6 deletions pywal/backends/colorthief.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,32 @@ def gen_colors(img):
return [util.rgb_to_hex(color) for color in raw_colors]


def adjust(cols, light, cols16):
"""Create palette."""
def adjust(cols, light, **kwargs):
"""Create palette.
:keyword-args:
- c16: use 16 colors through specified method - [ "lighten" | "darken" ]
"""
if 'c16' in kwargs:
cols16 = kwargs["c16"]
else:
cols16 = False
cols.sort(key=util.rgb_to_yiq)
raw_colors = [*cols, *cols]
for color in raw_colors:
color = util.lighten_color(color, 0.40)
raw_colors[0] = util.darken_color(cols[0], 0.80)

return colors.generic_adjust(raw_colors, light, cols16)
return colors.generic_adjust(raw_colors, light, c16=cols16)


def get(img, light=False, cols16=False):
"""Get colorscheme."""
def get(img, light=False, **kwargs):
"""Get colorscheme.
:keyword-args:
- c16: use 16 colors through specified method - [ "lighten" | "darken" ]
"""
if 'c16' in kwargs:
cols16 = kwargs["c16"]
else:
cols16 = False
cols = gen_colors(img)
return adjust(cols, light, cols16)
return adjust(cols, light, c16=cols16)
26 changes: 20 additions & 6 deletions pywal/backends/colorz.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,21 +24,35 @@ def gen_colors(img):
return [util.rgb_to_hex([*color[0]]) for color in raw_colors]


def adjust(cols, light, cols16):
"""Create palette."""
def adjust(cols, light, **kwargs):
"""Create palette.
:keyword-args:
- c16: use 16 colors through specified method - [ "lighten" | "darken" ]
"""
if 'c16' in kwargs:
cols16 = kwargs["c16"]
else:
cols16 = False
raw_colors = [cols[0], *cols, "#FFFFFF", "#000000", *cols, "#FFFFFF"]
raw_colors[0] = util.darken_color(cols[0], 0.80)

return colors.generic_adjust(raw_colors, light, cols16)
return colors.generic_adjust(raw_colors, light, c16=cols16)


def get(img, light=False, cols16=False):
"""Get colorscheme."""
def get(img, light=False, **kwargs):
"""Get colorscheme.
:keyword-args:
- c16: use 16 colors through specified method - [ "lighten" | "darken" ]
"""
if 'c16' in kwargs:
cols16 = kwargs["c16"]
else:
cols16 = False
cols = gen_colors(img)

if len(cols) < 6:
logging.error("colorz failed to generate enough colors.")
logging.error("Try another backend or another image. (wal --backend)")
sys.exit(1)

return adjust(cols, light, cols16)
return adjust(cols, light, c16=cols16)
26 changes: 20 additions & 6 deletions pywal/backends/fast_colorthief.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,30 @@ def gen_colors(img):
return [util.rgb_to_hex(color) for color in raw_colors]


def adjust(cols, light, cols16):
"""Create palette."""
def adjust(cols, light, **kwargs):
"""Create palette.
:keyword-args:
- c16: use 16 colors through specified method - [ "lighten" | "darken" ]
"""
if 'c16' in kwargs:
cols16 = kwargs["c16"]
else:
cols16 = False
cols.sort(key=util.rgb_to_yiq)
raw_colors = [*cols, *cols]
raw_colors[0] = util.darken_color(cols[0], 0.80)

return colors.generic_adjust(raw_colors, light, cols16)
return colors.generic_adjust(raw_colors, light, c16=cols16)


def get(img, light=False, cols16=False):
"""Get colorscheme."""
def get(img, light=False, **kwargs):
"""Get colorscheme.
:keyword-args:
- c16: use 16 colors through specified method - [ "lighten" | "darken" ]
"""
if 'c16' in kwargs:
cols16 = kwargs["c16"]
else:
cols16 = False
cols = gen_colors(img)
return adjust(cols, light, cols16)
return adjust(cols, light, c16=cols16)
26 changes: 20 additions & 6 deletions pywal/backends/haishoku.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,31 @@ def gen_colors(img):
return [util.rgb_to_hex(col[1]) for col in palette]


def adjust(cols, light, cols16):
"""Create palette."""
def adjust(cols, light, **kwargs):
"""Create palette.
:keyword-args:
- c16: use 16 colors through specified method - [ "lighten" | "darken" ]
"""
if 'c16' in kwargs:
cols16 = kwargs["c16"]
else:
cols16 = False
cols.sort(key=util.rgb_to_yiq)
raw_colors = [*cols, *cols]
raw_colors[0] = util.lighten_color(cols[0], 0.40)
raw_colors[0] = util.darken_color(cols[0], 0.80)

return colors.generic_adjust(raw_colors, light, cols16)
return colors.generic_adjust(raw_colors, light, c16=cols16)


def get(img, light=False, cols16=False):
"""Get colorscheme."""
def get(img, light=False, **kwargs):
"""Get colorscheme.
:keyword-args:
- c16: use 16 colors through specified method - [ "lighten" | "darken" ]
"""
if 'c16' in kwargs:
cols16 = kwargs["c16"]
else:
cols16 = False
cols = gen_colors(img)
return adjust(cols, light, cols16)
return adjust(cols, light, c16=cols16)
26 changes: 20 additions & 6 deletions pywal/backends/modern_colorthief.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,30 @@ def gen_colors(img):
return [util.rgb_to_hex(color) for color in raw_colors]


def adjust(cols, light, cols16):
"""Create palette."""
def adjust(cols, light, **kwargs):
"""Create palette.
:keyword-args:
- c16: use 16 colors through specified method - [ "lighten" | "darken" ]
"""
if 'c16' in kwargs:
cols16 = kwargs["c16"]
else:
cols16 = False
cols.sort(key=util.rgb_to_yiq)
raw_colors = [*cols, *cols]
raw_colors[0] = util.darken_color(cols[0], 0.80)

return colors.generic_adjust(raw_colors, light, cols16)
return colors.generic_adjust(raw_colors, light, c16=cols16)


def get(img, light=False, cols16=False):
"""Get colorscheme."""
def get(img, light=False, **kwargs):
"""Get colorscheme.
:keyword-args:
- c16: use 16 colors through specified method - [ "lighten" | "darken" ]
"""
if 'c16' in kwargs:
cols16 = kwargs["c16"]
else:
cols16 = False
cols = gen_colors(img)
return adjust(cols, light, cols16)
return adjust(cols, light, c16=cols16)
30 changes: 22 additions & 8 deletions pywal/backends/okthief.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,32 @@ def gen_colors(img):
return cols


def adjust(cols, light, cols16):
"""Create palette."""
return colors.generic_adjust(cols, light, cols16)


def get(img, light=False, cols16=False):
"""Get colorscheme."""
def adjust(cols, light, **kwargs):
"""Create palette.
:keyword-args:
- c16: use 16 colors through specified method - [ "lighten" | "darken" ]
"""
if 'c16' in kwargs:
cols16 = kwargs["c16"]
else:
cols16 = False
return colors.generic_adjust(cols, light, c16=cols16)


def get(img, light=False, **kwargs):
"""Get colorscheme.
:keyword-args:
- c16: use 16 colors through specified method - [ "lighten" | "darken" ]
"""
if 'c16' in kwargs:
cols16 = kwargs["c16"]
else:
cols16 = False
if not shutil.which("okthief"):
logging.error("okthief wasn't found on your system.")
logging.error("Try another backend. (wal --backend)")
sys.exit(1)

cols = gen_colors(img)
cols[0] = util.darken_color(cols[0], 0.80)
return adjust(cols, light, cols16)
return adjust(cols, light, c16=cols16)
26 changes: 20 additions & 6 deletions pywal/backends/schemer2.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,35 @@ def gen_colors(img):
return subprocess.check_output([*cmd, img]).splitlines()


def adjust(cols, light, cols16):
"""Create palette."""
def adjust(cols, light, **kwargs):
"""Create palette.
:keyword-args:
- c16: use 16 colors through specified method - [ "lighten" | "darken" ]
"""
if 'c16' in kwargs:
cols16 = kwargs["c16"]
else:
cols16 = False
cols.sort(key=util.rgb_to_yiq)
raw_colors = [*cols[8:], *cols[8:]]
raw_colors[0] = util.darken_color(cols[0], 0.80)

return colors.generic_adjust(raw_colors, light, cols16)
return colors.generic_adjust(raw_colors, light, c16=cols16)


def get(img, light=False, cols16=False):
"""Get colorscheme."""
def get(img, light=False, **kwargs):
"""Get colorscheme.
:keyword-args:
- c16: use 16 colors through specified method - [ "lighten" | "darken" ]
"""
if 'c16' in kwargs:
cols16 = kwargs["c16"]
else:
cols16 = False
if not shutil.which("schemer2"):
logging.error("Schemer2 wasn't found on your system.")
logging.error("Try another backend. (wal --backend)")
sys.exit(1)

cols = [col.decode("UTF-8") for col in gen_colors(img)]
return adjust(cols, light, cols16)
return adjust(cols, light, c16=cols16)
26 changes: 20 additions & 6 deletions pywal/backends/wal.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,33 @@ def gen_colors(img):
return out


def adjust(cols, light, cols16):
def adjust(cols, light, **kwargs):
"""Adjust the generated colors and store them in a dict that
we will later save in json format."""
we will later save in json format.
:keyword-args:
- c16: use 16 colors through specified method - [ "lighten" | "darken" ]
"""
if 'c16' in kwargs:
cols16 = kwargs["c16"]
else:
cols16 = False
raw_colors = cols[:1] + cols[8:16] + cols[8:-1]

return colors.generic_adjust(raw_colors, light, cols16)
return colors.generic_adjust(raw_colors, light, c16=cols16)


def get(img, light=False, cols16=False):
"""Get colorscheme."""
def get(img, light=False, **kwargs):
"""Get colorscheme.
:keyword-args:
- c16: use 16 colors through specified method - [ "lighten" | "darken" ]
"""
if 'c16' in kwargs:
cols16 = kwargs["c16"]
else:
cols16 = False
colors = gen_colors(img)
# it is possible we could have picked garbage data
garbage = "# Image"
if garbage in colors:
colors.remove(garbage)
return adjust(colors, light, cols16)
return adjust(colors, light, c16=cols16)
Loading