python wrapper for etcpak
Project description
etcpak
A python wrapper for etcpak
Some changes were made to the original code to make it cross-platform compatible.
Installation
pip install etcpak
or download/clone the git and use
python setup.py install
Example
from PIL import Image
import etcpak
# load image
img = Image.open(file_path)
# get image data
img_data = img.convert("RGBA").tobytes()
# compress data
compressed = etcpak.compress_to_dxt5(img_data, img.width, img.height)
composite image for format comparission
import os
import etcpak
import texture2ddecoder
from PIL import Image
FORMATS = [
("DXT1", etcpak.compress_to_dxt1, texture2ddecoder.decode_bc1),
("DXT1 Dither", etcpak.compress_to_dxt1_dither, texture2ddecoder.decode_bc1),
("DXT5", etcpak.compress_to_dxt5, texture2ddecoder.decode_bc3),
("ETC1", etcpak.compress_to_etc1, texture2ddecoder.decode_etc1),
("ETC1 Dither", etcpak.compress_to_etc1_dither, texture2ddecoder.decode_etc1),
("ETC2 RGB", etcpak.compress_to_etc2_rgb, texture2ddecoder.decode_etc2),
("ETC2 RGBA", etcpak.compress_to_etc2_rgba, texture2ddecoder.decode_etc2a8)
]
p = "S:\\Pictures"
for fp in os.listdir(p):
if not fp[-4:] in [".png", ".jpg", ".bmp", "jpeg"]:
continue
# load image and adjust format and size
print(fp)
img = Image.open(os.path.join(p, fp)).convert("RGBA")
img = img.crop((0,0,img.width-img.width%4, img.height-img.height%4))
# create composite image
comp = Image.new("RGBA", (img.width*8, img.height))
comp.paste(img, (0, 0))
print(img.width * img.height * 4)
# iterate over all formats
for i, (name, enc, dec) in enumerate(FORMATS):
print(name)
# make sure that the channel order is correct for the compression
if name[:3] == "DXT":
raw = img.tobytes()
elif name[:3] == "ETC":
r,g,b,a = img.split()
raw = Image.merge('RGBA', (b,g,r,a)).tobytes()
# compress
data = enc(raw, img.width, img.height)
# decompress
dimg = Image.frombytes("RGBA", img.size, dec(data, img.width, img.height), "raw", "BGRA")
# add to composite image
comp.paste(dimg, (img.width*(i+1), 0))
# save composite image
comp.save(os.path.splitext(fp)[0]+".png")
Functions
- all functions accept only arguments, no keywords
- the data has to be RGBA/BGRA for the RGB functions as well
- all DXT compressions require data in the RGBA format
- all ETC compressions require data in the BGRA format
compress_to_dxt1
Compresses RGBA to DXT1
:param data: RGBA data of the image :type data: bytes :param width: width of the image :type width: int :param height: height of the image :type height: int :returns: compressed data :rtype: bytes"
compress_to_dxt1_dither
Compresses RGBA to DXT1 Dither
:param data: RGBA data of the image
:type data: bytes
:param width: width of the image
:type width: int
:param height: height of the image
:type height: int
:returns: compressed data
:rtype: bytes"
compress_to_dxt5
Compresses RGBA to DXT5
:param data: RGBA data of the image
:type data: bytes
:param width: width of the image
:type width: int
:param height: height of the image
:type height: int
:returns: compressed data
:rtype: bytes"
compress_to_etc1
Compresses RGBA to ETC1 RGB
:param data: RGBA data of the image
:type data: bytes
:param width: width of the image
:type width: int
:param height: height of the image
:type height: int
:returns: compressed data
:rtype: bytes"
compress_to_etc1_dither
Compresses RGBA to ETC1 Dither
:param data: RGBA data of the image
:type data: bytes
:param width: width of the image
:type width: int
:param height: height of the image
:type height: int
:returns: compressed data
:rtype: bytes"
compress_to_etc1_alpha
Compresses A to ETC1 Alpha
:param data: RGBA data of the image
:type data: bytes
:param width: width of the image
:type width: int
:param height: height of the image
:type height: int
:returns: compressed data
:rtype: bytes"
compress_to_etc2_rgb
Compresses RGBA to ETC2 RGB
:param data: RGBA data of the image
:type data: bytes
:param width: width of the image
:type width: int
:param height: height of the image
:type height: int
:returns: compressed data
:rtype: bytes"
compress_to_etc2_rgba
Compresses RGBA to ETC2 RGBA
:param data: RGBA data of the image
:type data: bytes
:param width: width of the image
:type width: int
:param height: height of the image
:type height: int
:returns: compressed data
:rtype: bytes"
compress_to_etc2_alpha
Compresses RGBA to ETC2 Alpha
:param data: RGBA data of the image
:type data: bytes
:param width: width of the image
:type width: int
:param height: height of the image
:type height: int
:returns: compressed data
:rtype: bytes"
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Hashes for etcpak-0.9.1-py3.9-win-amd64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46a0e080431a280ae6b8af635f4888bbe812e88d5286cea3791d042d352d00ce |
|
MD5 | 4e987aab3567789df41873153f0fc9bd |
|
BLAKE2b-256 | 811ac41fab2fe59b1653f92d1886022c0abaeaf6f777033a8e3d8ea13ba82bd0 |
Hashes for etcpak-0.9.1-py3.8-win-amd64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0adee6cdef2a5370ab0acba05e82eb0ddb3a422c5c71bbae00bc0bffa87163ac |
|
MD5 | 815c092bae71d9c25206c7ec8e20d9cb |
|
BLAKE2b-256 | 8846f0d7eca258f8d2fa2065bb9ec120bb224b9e0540ced7307c711e59060b8f |
Hashes for etcpak-0.9.1-py3.7-win-amd64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | de1bac57a9278ee805e442aea9f02255d9ccb5f56e0fcd4c855a8649521ceb98 |
|
MD5 | 5235e03c7820fa594efa0188297f9818 |
|
BLAKE2b-256 | 5ec3e5b0f288a653a92e82f5c7656d61f15e0eac6df0f8e76b320da0949c7ace |
Hashes for etcpak-0.9.1-py3.6-win-amd64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | bf25026aaaef12e2fe73ab01ea0392e957941f77c2aa0b16df095610a73ba083 |
|
MD5 | 7405ddabe2ab05738bcc24ef36b6fec2 |
|
BLAKE2b-256 | 9bf94faf2094fccc8eabaceb1970e37414fe4fc96e05e33309537702224f5264 |
Hashes for etcpak-0.9.1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a3fdcb8cc7f7c2db972e36ef07591e5a2c1c4871d1f998868058599c2e8d95b7 |
|
MD5 | 7203badefb8c37b5c73ded05bb68f89f |
|
BLAKE2b-256 | b582c0acd7eb10ebffb94bd556fefc75da69bc2b5ec0d50e723cfd94e938d3a4 |
Hashes for etcpak-0.9.1-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | df551f2c93354148ee8ada30bd2c9ff0d3f7ae074ecf99f5d20fe02cb1ee0b36 |
|
MD5 | 3b25bd0b100801a8b04d4f219af466d1 |
|
BLAKE2b-256 | 79c2ce5ef9f6bb4b014b971ed94be3e17d40d3ff01fde79939a933bbc5e790ea |
Hashes for etcpak-0.9.1-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 26461d8907c3e3f717ee53c2ea328ed48bfd0ebe409a2071eb74aebb5490b5fa |
|
MD5 | 02c6c0c437c25faed7b6173a09ce7a38 |
|
BLAKE2b-256 | 54fed1dc8380aa985908d709ad06b997dc0c93a9c78bee9fd4e8184595b0882c |
Hashes for etcpak-0.9.1-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 12f892500109c2b91f84c7294c1beff2bd8a56b044b55cbebc0681369a635156 |
|
MD5 | ef9c3b4496c226b43cac71f99310f252 |
|
BLAKE2b-256 | 03b3ea35194f292f482ffd2bd21fe67b71c2a9d73242d3aa2b4bf3037348b4e2 |
Hashes for etcpak-0.9.1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d28d0c5c3d0c2b05821d08bcc69eaa77f6c026bc37fcf647cfd2eee10442f14f |
|
MD5 | d3cd0172d3c922af8d55ea37008a24f9 |
|
BLAKE2b-256 | a4662176a47730eba6f26e0a7aa4f484cec6149697610852c32520090e574c1c |
Hashes for etcpak-0.9.1-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ac59f1ed16f2bf48e7bd4d239d14c12d95741af64d7ec6c9a7bd9b1e309f2f6c |
|
MD5 | ac6c2423fe4b288a64c9690baab69881 |
|
BLAKE2b-256 | 603828f792b925ed1eaaac0693928fd4f50a57c137e32844925126aabeeabc45 |
Hashes for etcpak-0.9.1-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f2daa3552836ebffc04b197517518881bfb96619512f0ae89ba03f842f1bbd19 |
|
MD5 | a75e2d93ee24b38ed72d55a75dd069d1 |
|
BLAKE2b-256 | d618489c48ddfbc429a1dc629cd4ab5e9947fe5ae9f697fae0fcef41a91a3363 |
Hashes for etcpak-0.9.1-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8870cf988fc6ec3df4326709a7f4d8ef197ef286548369c7e2e850a697265f48 |
|
MD5 | 987902ac01f495d468a1f0bbd3603043 |
|
BLAKE2b-256 | f69cb762063ef1cc41085eff73469b2d165dbe21737ec95b72d16131a7d12e69 |