astc-encoder-py
astc-encoder-py
is a Python binding of astc-encoder.
It can compress images into astc textures and decompress astc textures into images.
Installation
Python 3.7+
pip install astc-encoder-py
There are prebuild wheels for all platforms covered by cibuildwheel.
Examples
simple astc via PIL.Image
import astc_encoder.pil_codec
profile: int = 1
block_width: int = 4
block_height: int = 4
Image.frombytes("RGBA", (512, 512), comp, "astc", (profile, block_width, block_height)).show()
quality: float = 100
Image.tobytes("astc", (profile, quality, block_width, block_height))
compressing and decompressing using astc_encoder
from PIL import Image
from astc_encoder import (
ASTCConfig,
ASTCContext,
ASTCImage,
ASTCProfile,
ASTCSwizzle,
ASTCType,
)
config = ASTCConfig(ASTCProfile.LDR_SRGB, 4, 4)
context = ASTCContext(config)
img = Image.new("RGBA", (512, 512), (255, 0, 0, 255))
image = ASTCImage(ASTCType.U8, *img.size, data=img.tobytes())
swizzle = ASTCSwizzle.from_str("RGBA")
comp = context.compress(image, swizzle)
image_dec = ASTCImage(ASTCType.U8, *img.size)
context.decompress(comp, image_dec, swizzle)
img = Image.frombytes("RGBA", img.size, image_dec.data)
TODO