Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from PIL import Image
- import struct
- # no idea to what these offsets correspond
- magic = b"\x07\x00\x85\x80\x04\x8A\x80\x08\xCF\xE0\x0B\xD4\xE0\x1B\x99\xC1\x1F\xDE\xA1\x23"
- with open('data.bundle', 'wb') as bundle:
- bundle.write(magic)
- # images 1..6, with alpha
- for i in range(1, 7):
- img = Image.open(f"{i}.png")
- w, h = img.size
- bundle.write(struct.pack("<H", w))
- bundle.write(struct.pack("<H", h))
- bundle.write(b"\x04")
- # "fixes" coordinates, was too lazy to reverse the cycles
- img = img.transpose(Image.FLIP_TOP_BOTTOM)
- for r, g, b, a in img.getdata():
- # ALPHA PREMULTIPLYING!!
- r = (r * a) // 255
- g = (g * a) // 255
- b = (b * a) // 255
- # R G B A !!
- bundle.write(struct.pack("B", b))
- bundle.write(struct.pack("B", g))
- bundle.write(struct.pack("B", r))
- bundle.write(struct.pack("B", a))
- img.close()
- # background with no alpha, otherwise the same
- img = Image.open("7.png").convert("RGB")
- w, h = img.size
- bundle.write(struct.pack("<H", w))
- bundle.write(struct.pack("<H", h))
- bundle.write(b"\x03")
- img = img.transpose(Image.FLIP_TOP_BOTTOM)
- for r, g, b in img.getdata():
- bundle.write(struct.pack("B", b))
- bundle.write(struct.pack("B", g))
- bundle.write(struct.pack("B", r))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement