mirror of
https://github.com/Kaisaan/lostkefin.git
synced 2025-06-18 16:45:40 -04:00
Update graphics.py
This commit is contained in:
parent
f3ca4855e6
commit
c941ed5b8f
19
graphics.py
19
graphics.py
@ -1,6 +1,7 @@
|
|||||||
from PIL import Image
|
from PIL import Image
|
||||||
import sys
|
import sys
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
from struct import pack
|
||||||
|
|
||||||
def intlit(bytes):
|
def intlit(bytes):
|
||||||
return int.from_bytes(bytes, "little")
|
return int.from_bytes(bytes, "little")
|
||||||
@ -41,7 +42,6 @@ if (clutSize == 256):
|
|||||||
bpp = 8
|
bpp = 8
|
||||||
elif (clutSize == 16):
|
elif (clutSize == 16):
|
||||||
bpp = 4
|
bpp = 4
|
||||||
quit("4 BPP Image not supported yet")
|
|
||||||
else:
|
else:
|
||||||
quit("other BPP Image not supported yet")
|
quit("other BPP Image not supported yet")
|
||||||
|
|
||||||
@ -115,9 +115,9 @@ if clutSize == 256:
|
|||||||
colours = graphic.read(sectionSize)
|
colours = graphic.read(sectionSize)
|
||||||
clut = clut + colours
|
clut = clut + colours
|
||||||
|
|
||||||
#clut = graphic.read(clutSize * palSize)
|
elif bpp == 4:
|
||||||
|
clut = graphic.read(clutSize * palSize)
|
||||||
#print(clut)
|
print(clut)
|
||||||
|
|
||||||
#PIL.ImagePalette.ImagePalette("RGBA", clut)
|
#PIL.ImagePalette.ImagePalette("RGBA", clut)
|
||||||
|
|
||||||
@ -166,11 +166,20 @@ for x in range(sprCount):
|
|||||||
#print(sprDataSize)
|
#print(sprDataSize)
|
||||||
|
|
||||||
graphic.seek(pxlOffset + sprOffset)
|
graphic.seek(pxlOffset + sprOffset)
|
||||||
sprData = graphic.read(sprDataSize)
|
|
||||||
#print(sprData)
|
#print(sprData)
|
||||||
|
|
||||||
#if (bpp == 4):
|
#if (bpp == 4):
|
||||||
|
|
||||||
|
if (bpp == 4):
|
||||||
|
sprData4 = graphic.read(sprDataSize)
|
||||||
|
sprData = b""
|
||||||
|
for byte in sprData4:
|
||||||
|
# These might be backwards
|
||||||
|
sprData += pack("bb", byte & 0xF, byte >> 4)
|
||||||
|
else:
|
||||||
|
sprData = graphic.read(sprDataSize)
|
||||||
|
|
||||||
sprite = Image.frombytes("P", sprSize, bytes(sprData))
|
sprite = Image.frombytes("P", sprSize, bytes(sprData))
|
||||||
sprite.putpalette(clut, rawmode="RGBA")
|
sprite.putpalette(clut, rawmode="RGBA")
|
||||||
sprite.save(f"{filename}_{x}.png")
|
sprite.save(f"{filename}_{x}.png")
|
||||||
|
Loading…
Reference in New Issue
Block a user