Skip to content
This repository has been archived by the owner on Apr 26, 2024. It is now read-only.

pywal vs colorz: repeating color values #493

Closed
prankousky opened this issue Mar 19, 2020 · 6 comments
Closed

pywal vs colorz: repeating color values #493

prankousky opened this issue Mar 19, 2020 · 6 comments

Comments

@prankousky
Copy link

Hi,

I noticed that pywal and colorz produce different values for the same image; when I run wal -i ~/.wp/current.png, it will create a ~/.cache/wal/colors.Xresources file containing this

! X colors.
! Generated by 'wal'
*foreground:        #d3d3d3
*background:        #0e1215
*.foreground:       #d3d3d3
*.background:       #0e1215
emacs*foreground:   #d3d3d3
emacs*background:   #0e1215
URxvt*foreground:   #d3d3d3
XTerm*foreground:   #d3d3d3
UXTerm*foreground:  #d3d3d3
URxvt*color0e1215:   [100]#0e1215
XTerm*background:   #0e1215
UXTerm*background:  #0e1215
URxvt*cursorColor:  #d3d3d3
XTerm*cursorColor:  #d3d3d3
UXTerm*cursorColor: #d3d3d3
URxvt*borderColor:  [100]#0e1215

! Colors 0-15.
*.color0: #0e1215
*color0:  #0e1215
*.color1: #F4E70A
*color1:  #F4E70A
*.color2: #0F7898
*color2:  #0F7898
*.color3: #E30689
*color3:  #E30689
*.color4: #E3678D
*color4:  #E3678D
*.color5: #0F8FAD
*color5:  #0F8FAD
*.color6: #01ABE9
*color6:  #01ABE9
*.color7: #d3d3d3
*color7:  #d3d3d3
*.color8: #939393
*color8:  #939393
*.color9: #F4E70A
*color9:  #F4E70A
*.color10: #0F7898
*color10:  #0F7898
*.color11: #E30689
*color11:  #E30689
*.color12: #E3678D
*color12:  #E3678D
*.color13: #0F8FAD
*color13:  #0F8FAD
*.color14: #01ABE9
*color14:  #01ABE9
*.color15: #d3d3d3
*color15:  #d3d3d3

! Black color that will not be affected by bold highlighting.
*.color66: #0e1215
*color66:  #0e1215

! Xclock colors.
XClock*foreground: #d3d3d3
XClock*background: #0e1215
XClock*majorColor:  rgba:d3/d3/d3/ff
XClock*minorColor:  rgba:d3/d3/d3/ff
XClock*hourColor:   rgba:d3/d3/d3/ff
XClock*minuteColor: rgba:d3/d3/d3/ff
XClock*secondColor: rgba:d3/d3/d3/ff

! Set depth to make transparency work.
URxvt*depth: 32

Here, color0/color9, color1/color10, color2/color11 etc. are a always the same color!

When I run colorz ~/.wp/current.png, the color palette looks a bit different

grafik
(sorry for the crappy screenshot, there is something wrong with my script)

These colors are always similar, but not exactly the same.

Am I doing something wrong, or do I have to finetune paywal more? Thank you for your ideas :)

@dylanaraps
Copy link
Owner

Yes. pywal has multiple backends for color generation and the default is imagemagick (not colorz). Use --backend colorz. 👍

@prankousky
Copy link
Author

Thank you @dylanaraps

When I use --backend colorz, I still get the same value for color1/color9 etc.; in other words, instead of 16 colors, I only get 8 colors that are the same value for dark and light. Is there another option I can use to fix this?

I used the same image as before, and colorz will generate those slightly different colors when used on its own, but not when used as --backend.

@billbrod
Copy link

billbrod commented Jul 8, 2020

I noticed the same thing. No matter which backend I use, pywal only gives me 9 colors: all of color0 through color8 are unique, then color9 is a repeat of color1, and so on through color15

I poked around in pywal/backends/colorz.py, and on line 22 it calls raw_colors = colorz.colorz(img, n=6, bold_add=0). raw_colors is a list with 6 elements, each of which contains a 2-tuple with 2 RGB triplets: the first triplet is the "darker" version of the color, the second is the "brighter" one. By setting bold_add=0, pywal makes sure that the two triplets are identical, but if you use the default value of 50, you get what @prankousky showed in their screenshot above. pywal then converts only the first triplet to hex codes, so you end up with a list of 6 hex codes. The adjust function, on line 26, then repeats this list to get the full 16 colors, then calls pywal.colors.generic_adjust to do some small adjustment of the lightness / darkness of color7 and color8.

Is there a reason why pywal does this duplication instead of using all the values colorz returns? And why it uses bold_add=0?

I haven't checked the other backends, but I assume something similar is going on.

This is all with wal 3.3.0

@billbrod
Copy link

billbrod commented Jul 8, 2020

If I make some small changes, I can get the two separate bold values, like colorz returns by default:

original pywal/backends/colorz.py:

"""
Generate a colorscheme using Colorz.
"""
import logging
import sys

try:
    import colorz

except ImportError:
    logging.error("colorz wasn't found on your system.")
    logging.error("Try another backend. (wal --backend)")
    sys.exit(1)

from .. import colors
from .. import util


def gen_colors(img):
    """Generate a colorscheme using Colorz."""
    raw_colors = colorz.colorz(img, n=6, bold_add=0)
    return [util.rgb_to_hex([*color[0]]) for color in raw_colors]


def adjust(cols, light):
    """Create palette."""
    raw_colors = [cols[0], *cols, "#FFFFFF",
                  "#000000", *cols, "#FFFFFF"]
    return colors.generic_adjust(raw_colors, light)


def get(img, light=False):
    """Get colorscheme."""
    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)

modified version (the differences are in the value of bold_add, what gen_colors() returns and how adjusts() creates raw_colors from cols):

"""
Generate a colorscheme using Colorz.
"""
import logging
import sys

try:
    import colorz

except ImportError:
    logging.error("colorz wasn't found on your system.")
    logging.error("Try another backend. (wal --backend)")
    sys.exit(1)

from .. import colors
from .. import util


def gen_colors(img):
    """Generate a colorscheme using Colorz."""
    # pylint: disable=not-callable
    raw_colors = colorz.colorz(img, n=6, bold_add=50)
    return ([util.rgb_to_hex([*color[0]]) for color in raw_colors] +
            [util.rgb_to_hex([*color[1]]) for color in raw_colors])


def adjust(cols, light):
    """Create palette."""
    raw_colors = [cols[0], *cols[:6], "#FFFFFF",
                  "#000000", *cols[6:], "#FFFFFF"]
    return colors.generic_adjust(raw_colors, light)


def get(img, light=False):
    """Get colorscheme."""
    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)

@prankousky
Copy link
Author

This is great! @dylanaraps would it be possible to integrate the solution @billbrod found into pywal?

@sonjiku
Copy link

sonjiku commented May 19, 2021

I made a pull request of my fix. Check #601, it makes all the backends generate 16 colors. The first 8 are a darker shade of the latter 8.

billbrod added a commit to billbrod/pywal that referenced this issue Dec 20, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants