pywal
pywal copied to clipboard
Error with haishoku backend on wallpapers with limited colors
Sample image that triggers the error: https://i.imgur.com/1gKSbJ0.png
[I] image: Using image Untitled.png.
[I] colors: Generating a colorscheme.
[I] colors: Using haishoku backend.
Traceback (most recent call last):
File "/usr/bin/wal", line 11, in <module>
load_entry_point('pywal==3.3.0', 'console_scripts', 'wal')()
File "/usr/lib/python3.7/site-packages/pywal/__main__.py", line 208, in main
parse_args(parser)
File "/usr/lib/python3.7/site-packages/pywal/__main__.py", line 164, in parse_args
sat=args.saturate)
File "/usr/lib/python3.7/site-packages/pywal/colors.py", line 144, in get
colors = getattr(backend, "get")(img, light)
File "/usr/lib/python3.7/site-packages/pywal/backends/haishoku.py", line 37, in get
return adjust(cols, light)
File "/usr/lib/python3.7/site-packages/pywal/backends/haishoku.py", line 31, in adjust
return colors.generic_adjust(raw_colors, light)
File "/usr/lib/python3.7/site-packages/pywal/colors.py", line 71, in generic_adjust
colors[15] = colors[7]
IndexError: list assignment index out of range
Same issue!
If it helps, I've found another image that triggers this bug.
This bug starts in this place (in current code base).
I tried to see why (with REPL):
from haishoku.haishoku import Haishoku
palette = Haishoku.getPalette("https://i.imgur.com/1gKSbJ0.png")
print(len(palette))
# 8
palette = Haishoku.getPalette("https://user-images.githubusercontent.com/23202923/128759243-fecd7209-fed4-44fb-8019-13d086579260.jpg")
print(len(palette))
# 7
For some reason, the length returned by haishoku
may be 7, not 8.
A chain of calls led me to:
Good find. Going a little deeper, in the call to getColorsMean
, by the time the weighted mean colors are computed and the nested for loops have finished executing, the resulting colors_mean
has only 7 entries:
# haishoku/haishoku/haishoku.py
# get the weighted mean of all colors
colors_mean = []
for i in range(3):
for j in range(3):
for k in range(3):
grouped_image_color = grouped_image_colors[i][j][k]
if 0 != len(grouped_image_color):
color_mean = alg.get_weighted_mean(grouped_image_color)
colors_mean.append(color_mean)