Advertisement
Guest User

Riders on the space solver, the one and only

a guest
Dec 5th, 2017
145
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.42 KB | None | 0 0
  1. from PIL import Image
  2. import struct
  3. # no idea to what these offsets correspond
  4. magic = b"\x07\x00\x85\x80\x04\x8A\x80\x08\xCF\xE0\x0B\xD4\xE0\x1B\x99\xC1\x1F\xDE\xA1\x23"
  5.  
  6. with open('data.bundle', 'wb') as bundle:
  7.     bundle.write(magic)
  8.     # images 1..6, with alpha
  9.     for i in range(1, 7):
  10.         img = Image.open(f"{i}.png")
  11.         w, h = img.size
  12.         bundle.write(struct.pack("<H", w))
  13.         bundle.write(struct.pack("<H", h))
  14.         bundle.write(b"\x04")
  15.         # "fixes" coordinates, was too lazy to reverse the cycles
  16.         img = img.transpose(Image.FLIP_TOP_BOTTOM)
  17.         for r, g, b, a in img.getdata():
  18.             # ALPHA PREMULTIPLYING!!
  19.             r = (r * a) // 255
  20.             g = (g * a) // 255
  21.             b = (b * a) // 255
  22.             # R G B A !!
  23.             bundle.write(struct.pack("B", b))
  24.             bundle.write(struct.pack("B", g))
  25.             bundle.write(struct.pack("B", r))
  26.             bundle.write(struct.pack("B", a))
  27.         img.close()
  28.     # background with no alpha, otherwise the same
  29.     img = Image.open("7.png").convert("RGB")
  30.     w, h = img.size
  31.     bundle.write(struct.pack("<H", w))
  32.     bundle.write(struct.pack("<H", h))
  33.     bundle.write(b"\x03")
  34.     img = img.transpose(Image.FLIP_TOP_BOTTOM)
  35.     for r, g, b in img.getdata():
  36.         bundle.write(struct.pack("B", b))
  37.         bundle.write(struct.pack("B", g))
  38.         bundle.write(struct.pack("B", r))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement