Palette generation func

This commit is contained in:
Luke Hubmayer-Werner 2017-03-18 14:23:09 +10:30
parent 7a3956877b
commit dcb8e8a8a4
1 changed files with 10 additions and 10 deletions

View File

@ -139,17 +139,17 @@ def generate_glyphs_large(rom, offset, num=0x100):
spritelist.append(create_tritile(rom[j:j+24])) spritelist.append(create_tritile(rom[j:j+24]))
return spritelist return spritelist
def generate_palette(self, offset, length=16): def generate_palette(rom, offset, length=16):
# Need to convert BGR555 to ARGB32
palette = [] palette = []
for i in range(offset, offset+length, 2): for i in range(offset, offset+length, 2):
# Need to convert BGR555 to RGB555 if (i+2) < len(rom):
if (i+2) < len(self.ROM): short = unpack('<H', rom[i:i+2])[0]
short = unpack('<H', self.ROM[i:i+2])[0] b = (short & 0x7C00) >> 7 # b 0XXXXX00 00000000 -> 00000000 00000000 XXXXX000
red = short & 0x1F g = (short & 0x03E0) << 6 # b 000000XX XXX00000 -> 00000000 XXXXX000 00000000
blue = (short >> 10) & 0x1F r = (short & 0x001F) << 19 # b 00000000 000XXXXX -> XXXXX000 00000000 00000000
green5 = short & 0x3E0 color = 0xFF000000|r|g|b
bits = (red << 10) | green5 | blue
else: else:
bits = 0 color = 0 # Transparent
palette.append[bits] palette.append(color)
return palette return palette