python: Fix Autoslice in Sort Palette after Color Space Invasion

Resolves #12827.
The Autoslice option was not updated to expect GeglColors instead of GimpRGB
arrays after the Color Space invasion. This patch updates the find_index() and
hexcolor() functions accordingly.
This commit is contained in:
Alx Sa
2025-01-30 01:52:26 +00:00
parent f8cc2ff416
commit ebc4a245e4

View File

@ -202,18 +202,19 @@ def palette_sort(palette, selection, slice_expr, channel1, ascending1,
if selection == "auto-slice": if selection == "auto-slice":
def find_index(color, startindex=0): def find_index(color, startindex=0):
for i in range(startindex, num_colors): for i in range(startindex, num_colors):
c = palette.get_entry_color(i) rgba = palette.get_entry_color(i)
rgba = c.get_rgba()
if rgba[0] == color[1].r and rgba[1] == color[1].g and rgba[2] == color[1].b: if hexcolor(rgba) == hexcolor(color):
return i return i
return None return None
def hexcolor(c): def hexcolor(c):
rgba = c.get_rgba()
return "#%02x%02x%02x" % (int(255 * rgba[0]), int(255 * rgba[1]), int(255 * rgba[2])) return "#%02x%02x%02x" % (int(255 * rgba[0]), int(255 * rgba[1]), int(255 * rgba[2]))
fg = Gimp.context_get_foreground() fg = Gimp.context_get_foreground()
bg = Gimp.context_get_background() bg = Gimp.context_get_background()
start = find_index(fg) start = find_index(fg)
end = find_index(bg) end = find_index(bg)
if start is None: if start is None:
raise ValueError("Couldn't find foreground color %s in palette" % hexcolor(fg)) raise ValueError("Couldn't find foreground color %s in palette" % hexcolor(fg))
if end is None: if end is None:
@ -260,7 +261,6 @@ def palette_sort(palette, selection, slice_expr, channel1, ascending1,
result.append((index, entry)) result.append((index, entry))
return result return result
print (selection)
if selection == "all": if selection == "all":
entry_list = get_colors(0, num_colors) entry_list = get_colors(0, num_colors)
entry_list.sort(key=lambda v: v[0]) entry_list.sort(key=lambda v: v[0])