Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix page positions for sprites #39

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions out_spriteblock.py
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ def pixel_a8r8g8b8():
pixels = im.load()
x = 0
y = 0
prev_page_height = 0
for j in range(0, len(pages)):
page = pages[j]

Expand All @@ -200,6 +201,11 @@ def pixel_a8r8g8b8():
page_height = page[1]
page_offset = page[2]

if (x + page_width) > width:
print("Reached border")
x = 0
y += prev_page_height

if fmt == 0x0201:
page_width = (page_width + 0x7) & 0xFFFFFFF8
elif fmt == 0x0400:
Expand All @@ -208,6 +214,15 @@ def pixel_a8r8g8b8():
page_width = (page_width + 0xF) & 0xFFFFFFF0
elif fmt == 0x0401:
page_width = (page_width + 0x7) & 0xFFFFFFF8
elif fmt == 0x0003:
pass
#page_width = (page_width + 0xF) & 0xFFFFFFF0
else:
print("Unknown format: 0x%04X" % fmt)
assert(False)

im_page = Image.new("RGBA", (page_width, page_height))
pixels_page = im_page.load()

f.seek(off_a + page_offset)

Expand All @@ -216,18 +231,21 @@ def pixel_a8r8g8b8():
for page_y in range(0, page_height):
for page_x in range(0, page_width):
r, g, b, a = reader()
#print(page_x)
#print(page_y)
pixels_page[page_x, page_y] = (r, g, b, a)

abs_x = x + page_x
abs_y = y - page_y + page_height - 1
if (abs_x < width):
if (abs_y < height):
pixels[abs_x, abs_y] = (r, g, b, a)

x += page_width
if x >= width:
print("Reached border")
x = 0
y += page_height
if y == height:
print("Complete")
break
prev_page_height = page_height



#im_page.save("/tmp/swep1r/sprite-%d_%d-0x%04X.png" % (i, j, fmt), 'PNG')

im.save("/tmp/swep1r/sprite-%d.png" % i, 'PNG')