diff options
Diffstat (limited to 'tools/mkasset.py')
-rw-r--r-- | tools/mkasset.py | 28 |
1 files changed, 7 insertions, 21 deletions
diff --git a/tools/mkasset.py b/tools/mkasset.py index 9b9dc76..62d1d88 100644 --- a/tools/mkasset.py +++ b/tools/mkasset.py | |||
@@ -51,14 +51,9 @@ def carve_image(rgba_bytes, tile_width, tile_height, columns) -> Generator[bytea | |||
51 | image_width = columns * tile_width | 51 | image_width = columns * tile_width |
52 | image_height = len(rgba_bytes) // image_width // 4 | 52 | image_height = len(rgba_bytes) // image_width // 4 |
53 | 53 | ||
54 | tiles_x = image_width // tile_width | ||
55 | tiles_y = image_height // tile_height | ||
56 | |||
57 | tile_bytes = bytearray(tile_width * tile_height * 4) | 54 | tile_bytes = bytearray(tile_width * tile_height * 4) |
58 | for i in range(tiles_y): | 55 | for image_y0 in range(0, image_height, tile_height): # y-origin of tile inside image |
59 | image_y0 = i * tile_height # y-origin of tile inside image | 56 | for image_x0 in range(0, image_width, tile_width): # x-origin of tile inside image |
60 | for j in range(tiles_x): | ||
61 | image_x0 = j * tile_width # x-origin of tile inside image | ||
62 | for y in range(tile_height): | 57 | for y in range(tile_height): |
63 | image_y = image_y0 + y # y of current pixel inside image | 58 | image_y = image_y0 + y # y of current pixel inside image |
64 | for x in range(tile_width): | 59 | for x in range(tile_width): |
@@ -349,25 +344,16 @@ def convert_sprite_sheet(input_file_paths, sprite_width, sprite_height, | |||
349 | # that. getcolors() returns the number of unique colors. | 344 | # that. getcolors() returns the number of unique colors. |
350 | # getpalette() also returns a flattened list, which is why we must *4. | 345 | # getpalette() also returns a flattened list, which is why we must *4. |
351 | num_colours = len(im.getcolors()) | 346 | num_colours = len(im.getcolors()) |
352 | colours = im.getpalette(rawmode="RGBA")[:4 * num_colours] | 347 | palette = bytearray(im.getpalette(rawmode="RGBA")[:4 * num_colours]) |
353 | # TODO: This palette list does not seem really necessary. | 348 | assert (num_colours == (len(palette) // 4)) |
354 | # Define palette = bytearray(im.getpalette(...)) | ||
355 | palette = [] | ||
356 | for i in range(0, 4 * num_colours, 4): | ||
357 | palette.append((colours[i], colours[i + 1], colours[i + 2], | ||
358 | colours[i + 3])) | ||
359 | 349 | ||
360 | output.write(ctypes.c_uint16(len(palette))) | 350 | output.write(ctypes.c_uint16(num_colours)) |
361 | output.write(bytearray(colours)) | 351 | output.write(palette) |
362 | 352 | ||
363 | print(f"Sprite width: {sprite_width}") | 353 | print(f"Sprite width: {sprite_width}") |
364 | print(f"Sprite height: {sprite_height}") | 354 | print(f"Sprite height: {sprite_height}") |
365 | print(f"Rows: {len(rows)}") | 355 | print(f"Rows: {len(rows)}") |
366 | print(f"Colours: {len(palette)}") | 356 | print(f"Colours: {num_colours}") |
367 | |||
368 | # print("Palette") | ||
369 | # for i, colour in enumerate(palette): | ||
370 | # print(f"{i}: {colour}") | ||
371 | 357 | ||
372 | for row, num_columns in enumerate(rows): | 358 | for row, num_columns in enumerate(rows): |
373 | output.write(ctypes.c_uint16(num_columns)) | 359 | output.write(ctypes.c_uint16(num_columns)) |