GIMP 2.99 need help with palette

I have an indexed image with 5 colours.

I can get the palette using
colormap = Gimp.Image.get_palette(new_image)

I can get the number of colours like so:
num_colors = colormap.get_color_count()

But I have no idea how to list those 5 colors in a form like RGBA
for example colorA = “.31 0.31 0.55 1.0”

Can anybody help a Sunday Coder, please

I think you just do
colarray = colormap.get_colors()
and you get an array of the colors in the palette. You can then do
for item in colarray:
item_col = item.get_rgba()
This worked in one of my plugins a couple of weeks ago !
From another Sunday Coder

Ahh yes,
which when run gives something like

(red=0.1620294749736786, green=0.13563334941864014, blue=0.35640034079551697, alpha=1.0)

and If I do
print(item_col[0], item_col[1], item_col[2], item_col[3])
I get the pure colours:
0.16202938556671143 0.13563333451747894 0.35640016198158264 1.0

That’s fine.
Thanks a lot, Jim.

This topic was automatically closed 45 days after the last reply. New replies are no longer allowed.