def test_astc():
    for name in zip.namelist():
        if "ASTC" not in name or name[-5:] != ".data":
            continue
        name = name[:-5]

        # load sample data
        data: bytes = zip.open(name + ".data", "r").read()
        details: dict = json.loads(zip.open(name + ".json", "r").read())
        ori_img: Image = Image.open(zip.open(name + ".png", "r"))

        # decompress data
        width = details["m_Width"]
        height = details["m_Height"]
        bw = bh = int(name.rsplit("x", 1)[1])
        dec = texture2ddecoder.decode_astc(data, width, height, bw, bh)

        # load raw image data
        dec_img = Image.frombytes("RGBA", (width, height), dec, 'raw',
                                  ("BGRA"))
        dec_img = dec_img.convert(ori_img.mode)
Example #2
0
def astc(image_data: bytes, width: int, height: int, block_size: tuple) -> Image:
    image_data = texture2ddecoder.decode_astc(image_data, width, height, *block_size)
    return Image.frombytes("RGBA", (width, height), image_data, "raw", "BGRA")