Package: etcpak
etcpakA python wrapper forwolfpld/etcpakSome changes were made to the original code to make it cross-platform compatible.InstallationExampleFunctionsInstallationpip install etcpakor download/clone the git and usepython setup.py installExamplefromPILimportImageimportetcpak# load imageimg=Image.open(file_path)# get image dataimg_data=img.convert("RGBA").tobytes()# compress datacompressed=etcpak.compress_to_dxt5(img_data,img.width,img.height)composite image for format comparissionimportosimportetcpakimporttexture2ddecoderfromPILimportImageFORMATS=[("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"forfpinos.listdir(p):ifnotfp[-4:]in[".png",".jpg",".bmp","jpeg"]:continue# load image and adjust format and sizeprint(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 imagecomp=Image.new("RGBA",(img.width*8,img.height))comp.paste(img,(0,0))print(img.width*img.height*4)# iterate over all formatsfori,(name,enc,dec)inenumerate(FORMATS):print(name)# make sure that the channel order is correct for the compressionifname[:3]=="DXT":raw=img.tobytes()elifname[:3]=="ETC":r,g,b,a=img.split()raw=Image.merge('RGBA',(b,g,r,a)).tobytes()# compressdata=enc(raw,img.width,img.height)# decompressdimg=Image.frombytes("RGBA",img.size,dec(data,img.width,img.height),"raw","BGRA")# add to composite imagecomp.paste(dimg,(img.width*(i+1),0))# save composite imagecomp.save(os.path.splitext(fp)[0]+".png")Functionsall functions accept only arguments, no keywordsthe data has to be RGBA/BGRA for the RGB functions as wellallDXTcompressions require data in theRGBAformatallETCcompressions require data in theBGRAformatcompress_to_dxt1Compresses 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_ditherCompresses 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_dxt5Compresses 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_etc1Compresses 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_ditherCompresses 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_alphaCompresses 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_rgbCompresses 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_rgbaCompresses 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_alphaCompresses 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"