I have a 16x16 bitmap containing 256 pixels of distinct colours that I want to use as a palette for 8-bit indexed mode. Is there a way to convert this bitmap into one that GIMP can use as a custom palette? I also need the order of the colours to be preserved.
Thanks to xenoid's hint, I was able to get this working with a python script.
from PIL import Image print "GIMP Palette" print "Name: my-new-palette" print "Columns: 16\n#" bmp = Image.open( "my-palette.bmp" ) bmp_im = bmp.convert('RGB') for row in range(16): for col in range(16): r,g,b = bmp_im.getpixel((col, row)) print "%3d %3d %3d Index %d" % (r, g, b, 16*row+col)
- Open the image,
- Open the palettes list (Windows>Dockable dialogs>Palettes`)
- Righ-click any palette on the list
- Make adequate choices in the dialog that opens:
Now the palette is pretty much randomly sorted. If the initial bitmap is sorted on some criteria it is possible to re-sort the palette on the same criteria with a script.
A completely different method is to export the image is some easy to process format (possibly text based: C, XMP, HTML) and process that with a script tp generate the Gimp palette (which is ASCII text with a rather trivial format).