Skip to main content

a python wrapper for astc-encoder

Project description

astc-encoder-py

astc-encoder-py is a Python wrapper around astc-encoder. It can compress images into astc textures and decompress astc textures into images.

Requires Python 3.7+

docs

TODO, check the pyi for now.

example

from PIL import Image

from astc_encoder import (
 ASTCConfig,
 ASTCContext,
 ASTCImage,
 ASTCProfile,
 ASTCSwizzle,
 ASTCType,
)

# create config like astcenc_config_init,
# color profile, block dimensions, quality, flags
# and then allow editing by hand afterward
# optional args:
#   block depth = 1, quality = 60, flags = 0
config = ASTCConfig(ASTCProfile.LDR_SRGB, 4, 4)

# create a context from the config
# as the context creation is expensive,
# this solution allows re-using the context
context = ASTCContext(config)

# create a new image for testing
img = Image.new("RGBA", (512, 512), (255, 0, 0, 255))

# put it's data into an ASTCImage for handling 
image = ASTCImage(ASTCType.U8, *img.size, data=img.tobytes())

# create a RGBA swizzle
swizzle = ASTCSwizzle()

# compress the image with the given context
comp = context.compress(image, swizzle)

# create a destination image with the correct arguments
image_dec = ASTCImage(ASTCType.U8, *img.size)

# decompress the data into the image
# the result has always 4 channels
# DON'T RE-USE THE IMAGE OBJECT FROM COMPRESSION, IT MIGHT SEGFAULT
context.decompress(comp, image_dec, swizzle)

# load the decompressed image into PIL
img = Image.frombytes("RGBA", img.size, image_dec.data)

TODO

  • figuring out segfault for re-using ASTCImage
  • [] creating ASTCSwizzle from strings instead of from ints
  • [] creating ASTCImage directly from PIL.Image
  • [] export ASTCImage directly to PIL.Image
  • [] SVE support for arm
  • [] tests
  • [] docs page

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

astc_encoder_py-0.1.1.tar.gz (138.6 kB view hashes)

Uploaded Source

Built Distributions

astc_encoder_py-0.1.1-pp310-pypy310_pp73-win_amd64.whl (150.0 kB view hashes)

Uploaded PyPy Windows x86-64

astc_encoder_py-0.1.1-pp310-pypy310_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (140.6 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

astc_encoder_py-0.1.1-pp310-pypy310_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (137.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

astc_encoder_py-0.1.1-pp310-pypy310_pp73-macosx_11_0_arm64.whl (133.1 kB view hashes)

Uploaded PyPy macOS 11.0+ ARM64

astc_encoder_py-0.1.1-pp310-pypy310_pp73-macosx_10_15_x86_64.whl (139.4 kB view hashes)

Uploaded PyPy macOS 10.15+ x86-64

astc_encoder_py-0.1.1-pp39-pypy39_pp73-win_amd64.whl (150.0 kB view hashes)

Uploaded PyPy Windows x86-64

astc_encoder_py-0.1.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (140.6 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

astc_encoder_py-0.1.1-pp39-pypy39_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (137.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

astc_encoder_py-0.1.1-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (133.1 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

astc_encoder_py-0.1.1-pp39-pypy39_pp73-macosx_11_0_arm64.whl (133.1 kB view hashes)

Uploaded PyPy macOS 11.0+ ARM64

astc_encoder_py-0.1.1-pp39-pypy39_pp73-macosx_10_15_x86_64.whl (139.4 kB view hashes)

Uploaded PyPy macOS 10.15+ x86-64

astc_encoder_py-0.1.1-pp38-pypy38_pp73-win_amd64.whl (150.0 kB view hashes)

Uploaded PyPy Windows x86-64

astc_encoder_py-0.1.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (140.6 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

astc_encoder_py-0.1.1-pp38-pypy38_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (137.3 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

astc_encoder_py-0.1.1-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (133.1 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

astc_encoder_py-0.1.1-pp38-pypy38_pp73-macosx_11_0_arm64.whl (133.1 kB view hashes)

Uploaded PyPy macOS 11.0+ ARM64

astc_encoder_py-0.1.1-pp38-pypy38_pp73-macosx_10_9_x86_64.whl (141.7 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

astc_encoder_py-0.1.1-pp37-pypy37_pp73-win_amd64.whl (150.0 kB view hashes)

Uploaded PyPy Windows x86-64

astc_encoder_py-0.1.1-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (141.5 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

astc_encoder_py-0.1.1-pp37-pypy37_pp73-manylinux_2_17_i686.manylinux2014_i686.whl (138.0 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ i686

astc_encoder_py-0.1.1-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (133.5 kB view hashes)

Uploaded PyPy manylinux: glibc 2.17+ ARM64

astc_encoder_py-0.1.1-pp37-pypy37_pp73-macosx_10_9_x86_64.whl (141.7 kB view hashes)

Uploaded PyPy macOS 10.9+ x86-64

astc_encoder_py-0.1.1-cp37-abi3-win_arm64.whl (119.0 kB view hashes)

Uploaded CPython 3.7+ Windows ARM64

astc_encoder_py-0.1.1-cp37-abi3-win_amd64.whl (149.9 kB view hashes)

Uploaded CPython 3.7+ Windows x86-64

astc_encoder_py-0.1.1-cp37-abi3-win32.whl (124.5 kB view hashes)

Uploaded CPython 3.7+ Windows x86

astc_encoder_py-0.1.1-cp37-abi3-musllinux_1_2_x86_64.whl (1.9 MB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.2+ x86-64

astc_encoder_py-0.1.1-cp37-abi3-musllinux_1_2_s390x.whl (2.0 MB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.2+ s390x

astc_encoder_py-0.1.1-cp37-abi3-musllinux_1_2_ppc64le.whl (1.9 MB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.2+ ppc64le

astc_encoder_py-0.1.1-cp37-abi3-musllinux_1_2_i686.whl (2.0 MB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.2+ i686

astc_encoder_py-0.1.1-cp37-abi3-musllinux_1_2_armv7l.whl (1.7 MB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.2+ ARMv7l

astc_encoder_py-0.1.1-cp37-abi3-musllinux_1_2_aarch64.whl (1.8 MB view hashes)

Uploaded CPython 3.7+ musllinux: musl 1.2+ ARM64

astc_encoder_py-0.1.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (945.1 kB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ x86-64

astc_encoder_py-0.1.1-cp37-abi3-manylinux_2_17_s390x.manylinux2014_s390x.whl (938.5 kB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ s390x

astc_encoder_py-0.1.1-cp37-abi3-manylinux_2_17_ppc64le.manylinux2014_ppc64le.whl (940.8 kB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ppc64le

astc_encoder_py-0.1.1-cp37-abi3-manylinux_2_17_i686.manylinux2014_i686.whl (942.8 kB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ i686

astc_encoder_py-0.1.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (866.6 kB view hashes)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARM64

astc_encoder_py-0.1.1-cp37-abi3-macosx_11_0_arm64.whl (135.6 kB view hashes)

Uploaded CPython 3.7+ macOS 11.0+ ARM64

astc_encoder_py-0.1.1-cp37-abi3-macosx_10_9_x86_64.whl (144.6 kB view hashes)

Uploaded CPython 3.7+ macOS 10.9+ x86-64

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page