Made a small python script to convert a PNG image to a 16-color and 16-pixels wide sprite, if someone is interested.
It prints out assembler code to paste into your source code. Don't forget to set the transparent color.
Code
- from PIL import Image
- import sys
- import math
- nargs = len(sys.argv)-1
- for i in range(nargs):
- image = Image.open(sys.argv[i+1])
- colors = image.getcolors(16)
- data = image.getdata()
- height = image.size[1]
- width = image.size[0]
- palette = image.getpalette()
- print ("Image width: "+str(width)+"\nImage height: "+str(height))
- print ("Number of colors: "+str(len(colors)))
- rgb = [".red:",".green:",".blue:"]
- for j in range(3):
- print (rgb[j])
- print ("\t.byte $"+hex(palette[j])[2:].zfill(2),end='')
- for i in range(1,len(colors)):
- print (",$"+hex(palette[i*3+j])[2:].zfill(2),end='')
- print ("")
- print (".sprite:")
- for y in range(height):
- print ("\t.byte $"+hex(data[y*width]*16+data[y*width+1])[2:].zfill(2),end='')
- for x in range(1,width-1,2):
- print (",$"+hex(data[y*width+x]*16+data[y*width+x+1])[2:].zfill(2),end='')
- print ("")