Skip to content

Commit

Permalink
Default to the top color when the requested index is out of bounds
Browse files Browse the repository at this point in the history
  • Loading branch information
luisbocanegra committed Mar 23, 2024
1 parent 31c804f commit b9338a1
Showing 1 changed file with 9 additions and 17 deletions.
26 changes: 9 additions & 17 deletions src/kde_material_you_colors/utils/m3_scheme_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ def get_material_you_colors(wallpaper_data, ncolor, source_type):
hsize = int((float(img.size[1]) * float(wpercent)))
img = img.resize((basewidth, hsize), Image.Resampling.LANCZOS)
# get best colors
source_colors = sourceColorsFromImage(img, top=False)
source_colors = sourceColorsFromImage(img)
# close image file
img.close()
seed_color = source_colors[0]
Expand All @@ -167,24 +167,16 @@ def get_material_you_colors(wallpaper_data, ncolor, source_type):
best_colors.update({str(i): hexFromArgb(color)})
# generate theme from seed color

theme = themeFromSourceColor(seed_color)

# Given a image, the alt color and hex color
# return a selected color or a single color for hex code
# Given the best colors and the alt color index
# return a selected color or the first one if index is out of bounds
totalColors = len(best_colors)
if ncolor and ncolor is not None:
ncolor = math_utils.clip(ncolor, 0, totalColors, 0)
else:
if ncolor is None:
ncolor = 0
if ncolor > totalColors - 1:
ncolor = 0
seedColor = hexFromArgb(source_colors[ncolor])

if totalColors > ncolor:
seedColor = hexFromArgb(source_colors[ncolor])
seedNo = ncolor
else:
seedColor = hexFromArgb(source_colors[-1])
seedNo = totalColors - 1
if seedColor != 0:
theme = themeFromSourceColor(argbFromHex(seedColor))
theme = themeFromSourceColor(argbFromHex(seedColor))

dark_scheme = theme["schemes"]["dark"]
light_scheme = theme["schemes"]["light"]
Expand All @@ -207,7 +199,7 @@ def get_material_you_colors(wallpaper_data, ncolor, source_type):
materialYouColors = {
"best": best_colors,
"seed": {
seedNo: hexFromArgb(theme["source"]),
ncolor: hexFromArgb(theme["source"]),
},
"schemes": {
"light": light_scheme,
Expand Down

0 comments on commit b9338a1

Please sign in to comment.