Use 16×16 bitmap as palette

I have a 16×16 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.

Answer

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)

Attribution
Source : Link , Question Author : TheBigH , Answer Author : TheBigH

Leave a Comment