python wrapper for etcpak
Project description
etcpak
A python wrapper for wolfpld/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.2-py3.9-win-amd64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 514282e10653fa78ec82e602f107b817ca8a1079f90c39fa641510d62a6e7e97 |
|
MD5 | f1977677d2644b189ad5dbe293ae5647 |
|
BLAKE2b-256 | 4b73319d4d35edc8c269026166505100a9007d91c432eaf3b3114c77ea387fbd |
Hashes for etcpak-0.9.2-py3.9-macosx-10.14-x86_64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e8fcf6ba6b1235c297f4f3e19088fc3aa2aa18d50c94ca0adc6a72e1f9da59e |
|
MD5 | ce9046ae1d9863ce1ec2dfe58ec4968c |
|
BLAKE2b-256 | aa9f5170da95209e1fee45cf0f037b911e428f121d4ce90e127a707ef0b1dd1d |
Hashes for etcpak-0.9.2-py3.8-win-amd64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 57cc19b6565a2b9d3ec82628162ed142dc530847c09d8e468b7b36c4c86db30b |
|
MD5 | 324d34125f0e491778964d541b534908 |
|
BLAKE2b-256 | b4dfbfbea5ad34ee21fc6c85212ee6c675b52e23fefe5c39a429b4ce5e540056 |
Hashes for etcpak-0.9.2-py3.8-macosx-10.14-x86_64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 87fe8025b04d2c0a485949fe85df017dde93e2f713a8cc9589802e04754c472f |
|
MD5 | 08b59421d6e4e980921fb74b38b07eff |
|
BLAKE2b-256 | 7e5261a66d4b290ea3ecea82fc71056b5131828ce14832d036add09f4ccd26f5 |
Hashes for etcpak-0.9.2-py3.7-win-amd64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | e350fdefc27eee4c04a16283531bbe64ff00e4ab5d9300252e6ca9f0bb7003d6 |
|
MD5 | d8db50e5d10792dee144574343b88911 |
|
BLAKE2b-256 | 80487ccd041b60bdf783d395c6f514f629ea0b78acff3a1214277a8ce582d926 |
Hashes for etcpak-0.9.2-py3.7-macosx-10.14-x86_64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | a0c0307d911537fae1477f8c385b9cc24d9306970eb6117da369646bedc95015 |
|
MD5 | 03bcb7d7f6a8a1d2139cc900f1961226 |
|
BLAKE2b-256 | fa9c034832552f4566fe2402266e5685d48d71ad83636815ea8f0f3b95433ef8 |
Hashes for etcpak-0.9.2-py3.6-win-amd64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f5dcbb6b39d0ecb7bfd04f953d8a3b39f63b4e849188c6ab054c6440aa1c985 |
|
MD5 | f50fdd90bf3287c20bfb2aab21dc79af |
|
BLAKE2b-256 | e796b147163699d5bca529cd42d7116ac50cd58ff25ae80779537e6634b8e454 |
Hashes for etcpak-0.9.2-py3.6-macosx-10.14-x86_64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | c8c39a56ff86bdd8ba8799438229b2ea322a79da64161e621a23481c6dd221b3 |
|
MD5 | 13aef65271a02dbb77c04d4fa9603b70 |
|
BLAKE2b-256 | d96355bbc354cb385bf00ad4a19c8a121796f3b19658ce4b3facaf73223f656e |
Hashes for etcpak-0.9.2-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 14a4df199725b8104ed6c93dcef48d0fd20d37bf4736dadb46a03d691dfcdadb |
|
MD5 | e73d1bfac8e1b192ffc1b729ff81178b |
|
BLAKE2b-256 | 693d0f5a63d935a00ec7310194941ed8e64de2a3d8219fa57c68c3cbbbcaf7a7 |
Hashes for etcpak-0.9.2-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 554ecf0f19da1db4554363eadb07bde0072601e13acf92f8913677efec960631 |
|
MD5 | 4e442d92f636a85834988fa959825d68 |
|
BLAKE2b-256 | acb1f3f9776050881238058a861acf6f06ebcdfddabe048b12b0a1571028df62 |
Hashes for etcpak-0.9.2-cp39-cp39-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 926fa76fc16637aec702d87c3483e1aa9ae8a969e0efbf51108bd9d0bc1162d9 |
|
MD5 | eb3787698ebf954bb2f2ba4ded05475f |
|
BLAKE2b-256 | c61ad7b0290159960db85b465b9cb6c283c7a529c56a0b75cf9f6432db5d74a9 |
Hashes for etcpak-0.9.2-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3826eeee37802a366648ee577b3547b6b41f7df6634735111926cb387c1fae23 |
|
MD5 | c3c860e97b2712f6837ab73c1956d0b7 |
|
BLAKE2b-256 | 8186420af0c4517aaa18727f7ed37d0f20dad9033194f5bd1feb8c1c26097883 |
Hashes for etcpak-0.9.2-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | aa52ed1e48b2d4037c8de66a102611e0d69b8b6b31cdda43188a84655c4ab22d |
|
MD5 | 0390578357f50195fdcd920e1f120955 |
|
BLAKE2b-256 | e5f48df26d66ee5265aee31b69006c0ad22a3d6a9db42487cec48ec7cd1f26a6 |
Hashes for etcpak-0.9.2-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2abdce3b3065ac6ad10f83ddc8dc7095a601c69579101acaeab8f797384d1657 |
|
MD5 | d4e83a34f321d9a6296b6ddc9fca07ab |
|
BLAKE2b-256 | 1892c4635818579a022e094405fa17d2be655be4337ad527d46c4eaf1d8c966b |
Hashes for etcpak-0.9.2-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7c62cf01256023a15b456c4ff9a87132b1a4cb528fdd618fd94866a29669fa3c |
|
MD5 | 509aba048c7b81d103f6f4a1dc821510 |
|
BLAKE2b-256 | cd38aa7639f76d5e70313a0b2aaff3efb223db0f1d4c054c354b2d5004f7ffd9 |
Hashes for etcpak-0.9.2-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a380d9a5207a71c9420f473eccc377b53195391479a916ebef64d75352358d1f |
|
MD5 | 28dab2a9469e52a8707e9eafeb234ed2 |
|
BLAKE2b-256 | 640d08708c85a0471c3ac8f7332a202a22caad876d5191d85827ffe8786acea5 |
Hashes for etcpak-0.9.2-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 98884fe224c87152e480dda452cd8bcb27170b2c8e80c88b9a1e578cceec1928 |
|
MD5 | e4bb942c4b1bbe5aac766f5842b742a1 |
|
BLAKE2b-256 | 439eefc29dcb3270aa8650c9fe43a25eeda3e7423db9a7ba49a7d4d321b819f8 |
Hashes for etcpak-0.9.2-cp36-cp36m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ff20f927e6149ac38cf1b20f7e1fd3ed9787a7a4e0af5ef5920a2abb18caf3f |
|
MD5 | 37a4c0c1344c9f42da5936249a714ad6 |
|
BLAKE2b-256 | 4edb7490b4386a0184b4d1730e4a994f6a8b8577472488de9ec83f1c95f6c682 |
Hashes for etcpak-0.9.2-cp36-cp36m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | faec2a769b39b2497723b88ccce4481a803ac73e4816b127ed36cea726f4c2d4 |
|
MD5 | aa7f3824c7b51eb0a3a70ec1063b12a8 |
|
BLAKE2b-256 | ca3a046cc0a9a59b022249df7ba4aaa3ee14170445580eb7231f8bce1535d952 |
Hashes for etcpak-0.9.2-cp36-cp36m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5dc87d1d9b37af473d3b06b2632b964dee7fe8a481b7e8c24ccaac766b66fba5 |
|
MD5 | 2a1ac2f9b703749e9125a28a36c86960 |
|
BLAKE2b-256 | 047befa62f9fe19a01dde069028c48dece76c4bf4d1a23a0ec0548274f31be7a |