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.4.tar.gz
(47.7 kB
view hashes)
Built Distributions
etcpak-0.9.4-py3.10-win-amd64.egg
(31.1 kB
view hashes)
etcpak-0.9.4-py3.9-win-amd64.egg
(31.1 kB
view hashes)
etcpak-0.9.4-py3.9-win32.egg
(27.5 kB
view hashes)
etcpak-0.9.4-py3.8-win-amd64.egg
(31.1 kB
view hashes)
etcpak-0.9.4-py3.8-win32.egg
(27.5 kB
view hashes)
etcpak-0.9.4-py3.7-win-amd64.egg
(31.1 kB
view hashes)
etcpak-0.9.4-py3.7-win32.egg
(27.5 kB
view hashes)
etcpak-0.9.4-cp39-cp39-win32.whl
(27.4 kB
view hashes)
etcpak-0.9.4-cp38-cp38-win32.whl
(27.4 kB
view hashes)
etcpak-0.9.4-cp37-cp37m-win32.whl
(27.4 kB
view hashes)
Close
Hashes for etcpak-0.9.4-py3.10-win-amd64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | c61eddd1169c9485cd095b8dfddc7a8c083828b277c2d10235ac58dd4a793ad5 |
|
MD5 | 90b4d3106330d934bdbb0410ff221f90 |
|
BLAKE2b-256 | 2e5c21042eee2da60013f2292793f854a726d0bcbfcb5404c14fff6184697e79 |
Close
Hashes for etcpak-0.9.4-py3.10-macosx-10.15-x86_64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2923db390ba09c8b0b6be9d82f5364347513b22abe97e5cb8109cdece4ea44ed |
|
MD5 | 147041a9e290f28e9a48dcad7b1b1899 |
|
BLAKE2b-256 | 45c1c6700ba9a826e01b65588733f4bbc9be1fa21699823aec184bc7a0452264 |
Close
Hashes for etcpak-0.9.4-py3.9-win-amd64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 228d4932fb4a8f6f0614b75148167310fafe3b564900beb648751a737634182f |
|
MD5 | 22df686c22bff6cee3de0cbba39f7ac6 |
|
BLAKE2b-256 | 44b3eb1677d1125f84d232afde77c75f1d61fd05d656ce93ebb91799cf8d7831 |
Close
Hashes for etcpak-0.9.4-py3.9-macosx-10.15-x86_64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 207b83e72fe3b3ede8dfba916a44e455c4a93c83d569b5465c6a5364ef2983fd |
|
MD5 | bb69b6af67461338812a80a144b8594b |
|
BLAKE2b-256 | 8b553a4495e47ad530d7b93a25c5f65efd6e5280a7a00185639699bef02cfcbd |
Close
Hashes for etcpak-0.9.4-py3.8-win-amd64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3220e7f485dc58d83a842aa578b8afc24b7e8d040ae3ed5894a32101dc98c150 |
|
MD5 | 0f3f71b7a9016239abf1b0c3d49d7fa5 |
|
BLAKE2b-256 | 05917db6313833fb86b56dbc75699de9ab1f3e3b204966af55e7f77c05d87777 |
Close
Hashes for etcpak-0.9.4-py3.8-macosx-10.14-x86_64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | f254c0e4f96e83f3db711375cc852ef89559913486326130513bb06254e054db |
|
MD5 | e971f258bcac21acaa543fb799935da3 |
|
BLAKE2b-256 | acdc3ef6514d778021c75d6b979d21dc88c40108164046c009330cc0790b3701 |
Close
Hashes for etcpak-0.9.4-py3.7-win-amd64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2c629772f6f914b735d8fec6edc1a0e9618052f3a035d3a0f31c2d3012a8e043 |
|
MD5 | e8cece7e4446a1869f7d9d01f73738ee |
|
BLAKE2b-256 | 160049efb83ba14d6b8ff2692c3a63e71d01b2cc89dd415306befc5a32423c21 |
Close
Hashes for etcpak-0.9.4-py3.7-macosx-10.14-x86_64.egg
Algorithm | Hash digest | |
---|---|---|
SHA256 | f309720d4ed97d72f061068c1ec41d5f214d358304a4cec4fe26f030af334446 |
|
MD5 | ea0d26f1ed99d3d000f7053cbc595220 |
|
BLAKE2b-256 | fcd308e34addd6698c17f5ab5942bebb23cb2fc62c5da076c4595d2078c69a54 |
Close
Hashes for etcpak-0.9.4-cp310-cp310-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 79951427d3ad2590bdde091eeb86d42283bd193c479439510459aa13b3ba4ec4 |
|
MD5 | 1177f66fd8ef9da1368f135e1811eee8 |
|
BLAKE2b-256 | 68fe9180b75f9f44cb7d1dbe4a1988fbe499fa6fc73a13da3afeab843f82d477 |
Close
Hashes for etcpak-0.9.4-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c179af6807d299e18c7dfc8deb51a81a6a715e6c0739e5bc8804739630b753de |
|
MD5 | 5513381f986ea761929edb49ba36f328 |
|
BLAKE2b-256 | 55b90eb632b3471fdfd2ae54a4171faf0480839182b4ac454c6af69d05d8487d |
Close
Hashes for etcpak-0.9.4-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5b7fadfbc956659e0d606f58d3abded4bf321fc19943ba8bcff60e8ce4ee906c |
|
MD5 | 6588a39eb29fe252d34e9a749a6acabd |
|
BLAKE2b-256 | 139e23e8ea0011c1bcbd3aad9070d29c33237acff84ebf8e242caef0739a45ad |
Close
Hashes for etcpak-0.9.4-cp39-cp39-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4fa39306c49f50b4f99aac034cdc481823a08d3fb8582f809cd15497ffebe104 |
|
MD5 | a98dc6a274a210c3b0a70acb4f2ca4c3 |
|
BLAKE2b-256 | 14ef87f70a5804c21cfc4d563e6b667b829e2112afc4b8f000f9b2cfa8fac245 |
Close
Hashes for etcpak-0.9.4-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a04a7715b912e8d52ea7ddca76ff7cea0a14f6bd3271611e1bce8bf33c599ead |
|
MD5 | 5f036d6aaceb17fff5cd8420f57d29da |
|
BLAKE2b-256 | f118670472164523becb8abd1b74e4ecbec04101e18369a75860ee9c866af98c |
Close
Hashes for etcpak-0.9.4-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6f090831c8d7eb2615f58894a39075a2c5b94239f5eb8fbb158993c823e95f9f |
|
MD5 | 2b8bc66c5d7fa90cf419390a6cdf68dd |
|
BLAKE2b-256 | 34b8f70a125f20c7d0f2dbcda85752233f7e5b20234b10080f6e016d358140a6 |
Close
Hashes for etcpak-0.9.4-cp38-cp38-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 354ed09e8403c2feb3a95be1b9d9e70f09693b61e463333fdb12299e4f8f60cd |
|
MD5 | 181c80d0a8439ab390c7f2ce51b06012 |
|
BLAKE2b-256 | 25e37859369dc9395bda41cfb59d0ed750ce90cb18ac3d928b528cfc46e9b96d |
Close
Hashes for etcpak-0.9.4-cp38-cp38-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c668d8f36c799df58f70b7a620e4fa89da8c0b5fab1596b9fad3476f90917685 |
|
MD5 | d17cb3dc1f40e6a1cf65ffc0db63d62e |
|
BLAKE2b-256 | d33a692d26b07ec417eb7e83746cbc1538dc9dc634375d421f832c1a440d5494 |
Close
Hashes for etcpak-0.9.4-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 138a1d2fbadb801a8c2e6ad2ac183284c5b66503e64d718fa9479bc500da10a7 |
|
MD5 | a280dec4474b694748e29b4d9e14b94f |
|
BLAKE2b-256 | 6b24c0d08ea499d5175d5091fc5e78c597302c0ebf6d900a542c0e5f702c48a0 |
Close
Hashes for etcpak-0.9.4-cp37-cp37m-win32.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 20fbc3cec2fd4838f98bf40f9afc6664e3d16374a1b2f1caa6fef6269668931e |
|
MD5 | eaf0ed0418dcd1e24e10a7221d0ac0ad |
|
BLAKE2b-256 | ef184d36f639fbce859fa8323ac2f6d54d8e60a9b0183e3837839198d9d0dd88 |
Close
Hashes for etcpak-0.9.4-cp37-cp37m-macosx_10_14_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd003bd6b223cec35570105ba624710b87bda8c7f2cc69384cbeb9bde345aa23 |
|
MD5 | 72c96c4c3ae966393243ebbf4edfaa27 |
|
BLAKE2b-256 | e02179ff93a9223a98c63dba9714e70477aa36b9e44e12c82c8612de087557f0 |