예제 #1
0
bag_palette_pal = gba.decode_palette(bag_palette_data, alpha=True)
bag_male_img = gba.decode_image(bag_male_data, codec, bag_palette_pal, 8)
bag_male_img.save("export/textures/bag_male.png")
bag_female_img = gba.decode_image(bag_female_data, codec, bag_palette_pal, 8)
bag_female_img.save("export/textures/bag_female.png")

arrow_data = lz77.decompress(rom[arrow_addr:])
arrow_palette_data = lz77.decompress(rom[arrow_palette_addr:])
arrow_palette = gba.decode_palette(arrow_palette_data, alpha=True)
arrow_image = gba.decode_image(arrow_data, codec, arrow_palette, 2)
arrow_image.save("export/textures/arrow.png")

bkgr_data = lz77.decompress(rom[bkgr_addr:])
bkgr_tiles = list(gba.iter_decode_tiles(codec, bkgr_data))

bkgr_palettes = [None, None]
bkgr_palettes_data0 = lz77.decompress(rom[bkgr_palettes_addr[0]:])
bkgr_palettes_data1 = lz77.decompress(rom[bkgr_palettes_addr[1]:])
bkgr_palettes[0] = list(gba.iter_decode_palettes(bkgr_palettes_data0, alpha=True))
bkgr_palettes[1] = copy.copy(bkgr_palettes[0])
bkgr_palettes[1][0] = gba.decode_palette(bkgr_palettes_data1)

for mode in (0,1):
    bkgr_map = lz77.decompress(rom[bkgr_maps_addr[mode]:])
    for gender in (0,1):
        bkgr_map_tiles = gba.decode_tilemap(bkgr_map, bkgr_tiles, bkgr_palettes[gender])
        bkgr_img = gba.combine_tiles(bkgr_map_tiles, 32)
        bkgr_img = bkgr_img.crop((0, 0, 240, 160))
        bkgr_img.save("export/textures/background{}_{}.png".format(mode, GENDERNAMES[gender]))
예제 #2
-1
파일: decode.py 프로젝트: Yepoleb/aiv
def decode_tilemap_at(rom, codec, image_ptr, palettes_ptr, tilemap_ptr, width=16):
    image_offset = get_rom_addr(image_ptr)
    palettes_offset = get_rom_addr(palettes_ptr)
    tilemap_offset = get_rom_addr(tilemap_ptr)
    bpp = codec.getBitsPerPixel()

    if check_valid(rom, image_offset, strict=True):
        print("Loading compressed image at", hex(image_ptr))
        image_data = lz77.decompress(rom, image_offset)
    else:
        print("Loading uncompressed image at", hex(image_ptr))
        image_len = 1024 * codec.getTileSize()  # Max amount of tiles
        image_data = rom[image_offset : image_offset + image_len]

    tile_size = codec.getTileSize()
    if len(image_data) % tile_size:
        # Fill remaining tile with padding bytes
        image_data += b"\x00" * (tile_size - len(image_data) % tile_size)

    pal_size = gba.get_palette_size(bpp)
    if check_valid(rom, palettes_offset, strict=True):
        print("Loading compressed palettes at", hex(palettes_ptr))
        palettes_data = lz77.decompress(rom, palettes_offset)
        if len(palettes_data) < pal_size:
            return "PALETTE_TOO_SMALL"
    else:
        print("Loading uncompressed palettes at", hex(palettes_ptr))
        palettes_len = 16 * pal_size  # Max amount of palettes
        palettes_data = rom[palettes_offset : palettes_offset + palettes_len]

    if check_valid(rom, tilemap_offset, strict=True):
        print("Loading compressed tilemap at", hex(tilemap_ptr))
        tilemap = lz77.decompress(rom, tilemap_offset)
    else:
        print("Loading uncompressed tilemap at", hex(tilemap_ptr))
        tilemap_len = 1024  # Max tilemap size (maybe)
        tilemap = rom[tilemap_offset : tilemap_offset + tilemap_len]

    try:
        tiles = list(gba.iter_decode_tiles(codec, image_data))
    except:
        return "IMAGE_DECODE_FAILED"

    try:
        palettes = list(gba.iter_decode_palettes(palettes_data, bpp=bpp, alpha=True))
    except:
        return "PALETTE_DECODE_FAILED"

    try:
        tilemap_tiles = gba.decode_tilemap(tilemap, tiles, palettes)
        img = gba.combine_tiles(tilemap_tiles, width)
    except:
        return "TILEMAP_DECODE_FAILED"

    return img