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
etcpak-0.9.5.tar.gz
(47.6 kB
view hashes)
Built Distributions
etcpak-0.9.5-py3.10-win-amd64.egg
(31.2 kB
view hashes)
etcpak-0.9.5-py3.10-win32.egg
(27.6 kB
view hashes)
etcpak-0.9.5-py3.9-win-amd64.egg
(31.1 kB
view hashes)
etcpak-0.9.5-py3.9-win32.egg
(27.5 kB
view hashes)
etcpak-0.9.5-py3.8-win-amd64.egg
(31.1 kB
view hashes)
etcpak-0.9.5-py3.8-win32.egg
(27.5 kB
view hashes)
etcpak-0.9.5-py3.7-win-amd64.egg
(31.1 kB
view hashes)
etcpak-0.9.5-py3.7-win32.egg
(27.5 kB
view hashes)
etcpak-0.9.5-cp39-cp39-win32.whl
(27.4 kB
view hashes)
etcpak-0.9.5-cp38-cp38-win32.whl
(27.4 kB
view hashes)
etcpak-0.9.5-cp37-cp37m-win32.whl
(27.4 kB
view hashes)
Close
Hashes for etcpak-0.9.5-py3.10-win-amd64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 76c383b58ca54a47e5401b08a691c032f67b2c4e4bf4250c757414bc7add595b |
|
MD5 | 65fc0f7175920f113f08efd0de7824d3 |
|
BLAKE2b-256 | a61fb3971110ce19e6ed76e13ca17cf2d58e84a4ee735af53410ca0bba525742 |
Close
Hashes for etcpak-0.9.5-py3.10-macosx-10.15-x86_64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8816abdc508cb3dcd9fa84a492bb5d073808e752ee7f1e262e87a8364450e1ca |
|
MD5 | 5f7621d7fa090e93c781598a2367a46b |
|
BLAKE2b-256 | 7663ff7e7d660e48ec1e2f14070ff4d1b5ad8ecee3df82b42f29c0b5b8c42bf4 |
Close
Hashes for etcpak-0.9.5-py3.9-win-amd64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | dcf80a4699fc0e20bc8f8a06b6cfb49d8ba412c2ac3a3bb7de2b38f239985bf7 |
|
MD5 | b7056d3ab76f9d9f6b589912a4121a8d |
|
BLAKE2b-256 | 9b5b540303295ed45a9cd7419e5be641b26df18202ca1dda3aec07b3a0e8f062 |
Close
Hashes for etcpak-0.9.5-py3.9-macosx-10.15-x86_64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2af91d8b7c5ff37a27032898398dc5545909a555aa2d5878a44b3905c5b3a652 |
|
MD5 | 30a1451a21bdf7c1c2bc5a0b5ea1f378 |
|
BLAKE2b-256 | d631b858d3eb22bbd26835a5eb3f7cd020ec9d5cc318e9a92883ef348c267a4d |
Close
Hashes for etcpak-0.9.5-py3.8-win-amd64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ae7f0581fcabcf705e73226fe2a2fd1ad96331ef54499ea1dc2f756ba82a879 |
|
MD5 | 79b4a06ac81efef5f82fc2f6754d8f05 |
|
BLAKE2b-256 | 529ed5a4d3b3eb05cc02f6d097f325026eb583449af50acc322e0ff65d249e5b |
Close
Hashes for etcpak-0.9.5-py3.8-macosx-10.14-x86_64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | da2ee6d47c32883d5f8cd6add594ecb8aabeaa9dcf51da320a2931b0934827ff |
|
MD5 | ee047083a7b928987fc37c98959bcd19 |
|
BLAKE2b-256 | 7a5401a95fe151cf9e16368912635200b1db4cb32ce815a80e8fee668637420b |
Close
Hashes for etcpak-0.9.5-py3.7-win-amd64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | a153b0f2d03616e850f4ce6bb396616f2d5f3763aa361c1b60951b07358badfe |
|
MD5 | 16c367a5b00ba88aa2a1b4f1028d0756 |
|
BLAKE2b-256 | 8c8bb7f6f108b2182b0fd3962076a3d0f229243f98ce6252a32b307c4defd569 |
Close
Hashes for etcpak-0.9.5-py3.7-macosx-10.14-x86_64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9841ce1e91c887359c7bf2681e0890266a4a95f800504c73a706dc802bf19551 |
|
MD5 | f68aad6f895189bdf45fde1417d5b504 |
|
BLAKE2b-256 | 137b76a5a99b5868061ee9b625728d16b293c6e7983a7f0e6a708385af2a1c31 |
Close
Hashes for etcpak-0.9.5-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d25c53f7b26c5b3a9ee9fc9287adb2239e2923ffb385db9cb93954df83729989 |
|
MD5 | 436328ec80b2e66f12bee6b475bf4e37 |
|
BLAKE2b-256 | c59fe5011382296d1598f4e8063024ed606c95ae0c5d9c1c1e6a3ed1166f51ea |
Close
Hashes for etcpak-0.9.5-cp310-cp310-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 706794fcfa3574cad98af803d918f25b9ffd57ae4e1b34c145a8ade8a6a2546c |
|
MD5 | 83d16ac7ae2dfe76bce63846816d46b2 |
|
BLAKE2b-256 | ee5d07601dbbfa4d0591f1b1a9649d2841f9edb50d6d4cbebca365c058dc4b6a |
Close
Hashes for etcpak-0.9.5-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 70453a1b838f6790dd9cbe68da46dea1f6a94eb938090f7cd19e7a0ee71f4bdb |
|
MD5 | bab6ea571e889d86f059341b1a8aedb9 |
|
BLAKE2b-256 | f442d00557b0dd3b1b6c799aa0f6f864b3d91d908466ca1765d54a3a17f5cdd7 |
Close
Hashes for etcpak-0.9.5-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6bb9d2fcab3db238c4a59a4dc67a0b6e2a0d34c3abb5440cf787e84dc80b63cc |
|
MD5 | bb4c1f474fc95ea6a7bd6f9d84947bf9 |
|
BLAKE2b-256 | aa1debdd5010c40c0b2ba51701451436dda261d8a407d4fc96c10e637ad01d02 |
Close
Hashes for etcpak-0.9.5-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b346194127f73e3744a70399e6aa6a34373ff76fdbcc37f6ace1c3f4c256d91 |
|
MD5 | 1feb120b8ad6dff9cf4941cb9cbc49bb |
|
BLAKE2b-256 | c5ded8c4521c7017393657e625321e45dbedb8eb4f523d7196729557910e5811 |
Close
Hashes for etcpak-0.9.5-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b92076c793318184fc336399193f7ef722dd5d7e6d7a888e691a62ea5d08c9fe |
|
MD5 | cf2a0acf43ec2d2fd239cb3cfe509f2a |
|
BLAKE2b-256 | c81dde43c22cfcff03b6a183ae7beba16294dc18482f5ea81e768f10c3b61d2f |
Close
Hashes for etcpak-0.9.5-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3f4c67e8a941faff3ddb66d453ccd09727cafff5bf666f6fccc6032a4533263e |
|
MD5 | d425b0e9fb55dad5067c3d6220046892 |
|
BLAKE2b-256 | 6156e5e3e671274f6822da4706dcd52a179fd2decfb2e08c671e45af966b46f0 |
Close
Hashes for etcpak-0.9.5-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ae0dc251a16923e8b0560f234aadf8e5ee9524ef0ec279aea1c77740db3b22b |
|
MD5 | 615713b462fcabd4df013d70008642cc |
|
BLAKE2b-256 | 28ddde93be93927f138a8f3558c4b1ca39ffc597495638e7a000bfcef702faa3 |
Close
Hashes for etcpak-0.9.5-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7ff761285d5547b425c35e485526cee689dd4a715f0982e69057228c3899207d |
|
MD5 | c713f22d625f5e0b9a376605cafc0511 |
|
BLAKE2b-256 | 910f210a772b5499a012cd0b806bd2fb40a40ade348a63d3df7e2078ff43a376 |
Close
Hashes for etcpak-0.9.5-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 95a0c2de6562617cf790be3690c28e32617d3bec4fcf7ddd4a785a64d5d48ae0 |
|
MD5 | a1358f33252a504ab4e9819297e99fdd |
|
BLAKE2b-256 | 0f7bb62cbc75efe04a59f3d324fbcc154c1b3f5a3933a565c23861d192bb7d38 |
Close
Hashes for etcpak-0.9.5-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebb62fb4b4bef36d310950ebc7f119f8e370a9560462dccacb3d2e4001253f29 |
|
MD5 | 67842aaf23c20e055185720ab53674f6 |
|
BLAKE2b-256 | fc81a9f30ea465b285b05663d00766844334be2662e4c912f3332405a979d68a |
Close
Hashes for etcpak-0.9.5-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9b3582afa217a9a0019fd598a532ce3c24b02244cf3e1e8d0994eee2df4b510 |
|
MD5 | 5468c6d0d61e4695d84d76b9fbd60bc3 |
|
BLAKE2b-256 | 2faf5f7b58e07b3f342f9f411c1eb3b23763f83c1e7c4c8913c73c3b4d4b607c |
Close
Hashes for etcpak-0.9.5-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 193896d6d8924c6b4fe31a2c55bb20afe41cada09edf03b0020c387318371a2a |
|
MD5 | 17d46b7707cb3f1fa4718f5344eb502e |
|
BLAKE2b-256 | b37f204ffee7864100147160b0993694c375887f1a6743b95be85b75b5d6e1ec |
Close
Hashes for etcpak-0.9.5-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4ece16016aeff6f351df7805774cedd03478c074bdd477b152a33650edaa4a48 |
|
MD5 | dfb7afebe96ec662c646ee63e166074f |
|
BLAKE2b-256 | 2b4b562ea73f0315467d72564c7e9641eca2699c49d8cc8276fae7f80ceb766e |
Close
Hashes for etcpak-0.9.5-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b0380310ede5c63ca51756212b02f576d70d7989a7346b32b8c6d8ed3fc2b1ca |
|
MD5 | 0c2366db73e156dfc0a24b646ffe61b4 |
|
BLAKE2b-256 | eadc555b0a480bf5e7382d9f309827d21434a1d6440ccf8f9584732659cd3f51 |
Close
Hashes for etcpak-0.9.5-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ee1ba775691510f07f5d73227a7c5be434e715ed01250829ed2d96c6d4d836c0 |
|
MD5 | 81dd6f73705714f0e075099845d384c5 |
|
BLAKE2b-256 | d407e5b279d7e488f10b1c444a4d3916ca42aa26fa74bcdbdfe323baa9c45550 |
Close
Hashes for etcpak-0.9.5-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b593cce495c59016b67243c88c3c7a2dd3437eecbabd7725a1477ec839b8dfa4 |
|
MD5 | a02ca649f4be80991758d933db8dca6f |
|
BLAKE2b-256 | d56f942c10e5721558896b35ee63660b73d16944254d76e762795ec4e7adc084 |
Close
Hashes for etcpak-0.9.5-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 145eb4d1da867af53bdf561aac81cb3e80c30f0046ff01a8bf244c3b54d549b7 |
|
MD5 | a782c47f9f0e306886d49c2f3a4a95ce |
|
BLAKE2b-256 | a477487d1be7627a51f6b030b055c5274b5ca89404678243aa01b47c2436db96 |
Close
Hashes for etcpak-0.9.5-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8d56d9ad6d09c1752dcb0058f45293cbf8cdea1bc3f7b1a0cf0a9e70429233a7 |
|
MD5 | ef20bbb4eb4b551d1554d21a49e821fc |
|
BLAKE2b-256 | fec191b8d58bc8dd2fc20246d211dd910c81bf5f9f5830c7e70770b6ba9f620d |
Close
Hashes for etcpak-0.9.5-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27d85371bc8275a61705217f5dce72e0392a598042ab56f8f0dfdf26501f4bd7 |
|
MD5 | a7b3fdd446bc246bac6c4eba51f6b166 |
|
BLAKE2b-256 | 850b09025d2882b2a6dc455729fc9741337ecdff2dc9381ad3325debb6884436 |
Close
Hashes for etcpak-0.9.5-cp37-cp37m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97049e39b0c718c8795fec5440c977cd1dced603b2a5e397c2707e51e1bfee62 |
|
MD5 | 9ffc47456735e6c977fc3152927a9a33 |
|
BLAKE2b-256 | ddde769c5a4c51ce14be04fdf25c483ca780d8e5979f1220a63f509e1d19af91 |
Close
Hashes for etcpak-0.9.5-cp37-cp37m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7afba64f817f2feadb0f2441970cd56649810f5339c76f061521213e2111fea |
|
MD5 | 9e4fe51fd9228e6bd72bd102e37604bc |
|
BLAKE2b-256 | 2df78e5425aaea898e358442812a65dd0f4609cddd888f1adea2398415936e51 |
Close
Hashes for etcpak-0.9.5-cp37-cp37m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | f7ead6abbc4a8ea244667432e8d142d44591cadd5decb959d6c8a5c8477c7255 |
|
MD5 | 8c0476d764a69255ae5431a2dc3c8402 |
|
BLAKE2b-256 | a473be4f36612cc4c2f004b4579537caff3a180a8a7cc3bc52dfd5a46a6c5002 |
Close
Hashes for etcpak-0.9.5-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 06d2add940198384c5677fef00ba5ca3e9e10c064b1287ef9472a5b90fe4ae39 |
|
MD5 | 9f22937b4030b379ecb897fcb2432d5c |
|
BLAKE2b-256 | f61c163eb83ce2aea553e42dda5ee94cd79e3d64b053b1cc41ed74886b60cbe4 |
Close
Hashes for etcpak-0.9.5-cp36-cp36m-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 554431c54858d4f1b119d16bdbd20d87c29a3da3675f26d3175d911d95de5cb0 |
|
MD5 | 1b73ae2387f62b83367f008ebe09aa8e |
|
BLAKE2b-256 | 65b1a4810a34ad6ab171ac50882ae08a31325560545df019d181f02744fde9d0 |
Close
Hashes for etcpak-0.9.5-cp36-cp36m-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 77a908dfc4ecf0c23a6acf466a43bdea5cf4c3f7fea8f508ebb739a71086cece |
|
MD5 | b57360335a8cd593e8d9d8f286faf322 |
|
BLAKE2b-256 | e751958ce0e33b130938c0273b154a53fe1737c9dfa9f34812e31109e3cef590 |
Close
Hashes for etcpak-0.9.5-cp36-cp36m-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c7493b8164c1382f13f942666a5fabe9240fae2dd0efe49fb5ae1907a3738104 |
|
MD5 | aa7d57ef9982177ef0c64d88db34219b |
|
BLAKE2b-256 | bb5ad393bcfbb939588fb39fb48b938fe2a3ac7698c829f8b7f2d71386b712b0 |