From 1b6f15920a2d96d7de539654275acfad8196ece4 Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Mon, 1 Sep 2025 19:41:11 -0700 Subject: Simplify --- tools/mkasset.py | 28 +++++++--------------------- 1 file changed, 7 insertions(+), 21 deletions(-) (limited to 'tools/mkasset.py') 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 image_width = columns * tile_width image_height = len(rgba_bytes) // image_width // 4 - tiles_x = image_width // tile_width - tiles_y = image_height // tile_height - tile_bytes = bytearray(tile_width * tile_height * 4) - for i in range(tiles_y): - image_y0 = i * tile_height # y-origin of tile inside image - for j in range(tiles_x): - image_x0 = j * tile_width # x-origin of tile inside image + for image_y0 in range(0, image_height, tile_height): # y-origin of tile inside image + for image_x0 in range(0, image_width, tile_width): # x-origin of tile inside image for y in range(tile_height): image_y = image_y0 + y # y of current pixel inside image for x in range(tile_width): @@ -349,25 +344,16 @@ def convert_sprite_sheet(input_file_paths, sprite_width, sprite_height, # that. getcolors() returns the number of unique colors. # getpalette() also returns a flattened list, which is why we must *4. num_colours = len(im.getcolors()) - colours = im.getpalette(rawmode="RGBA")[:4 * num_colours] - # TODO: This palette list does not seem really necessary. - # Define palette = bytearray(im.getpalette(...)) - palette = [] - for i in range(0, 4 * num_colours, 4): - palette.append((colours[i], colours[i + 1], colours[i + 2], - colours[i + 3])) + palette = bytearray(im.getpalette(rawmode="RGBA")[:4 * num_colours]) + assert (num_colours == (len(palette) // 4)) - output.write(ctypes.c_uint16(len(palette))) - output.write(bytearray(colours)) + output.write(ctypes.c_uint16(num_colours)) + output.write(palette) print(f"Sprite width: {sprite_width}") print(f"Sprite height: {sprite_height}") print(f"Rows: {len(rows)}") - print(f"Colours: {len(palette)}") - - # print("Palette") - # for i, colour in enumerate(palette): - # print(f"{i}: {colour}") + print(f"Colours: {num_colours}") for row, num_columns in enumerate(rows): output.write(ctypes.c_uint16(num_columns)) -- cgit v1.2.3