Python的DXT压缩

2024-09-28 05:20:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我目前正在处理图像,有些是DXT压缩的,我需要一个简单的方法来解压和压缩这些文件与Python。不幸的是,我找不到任何能为我做这件事的图书馆。在

有人知道一个很好的Python dxtcompression库,或者一个Compression库的接口吗?在

——dav1d型

编辑:

libsquish是这里的方法,但不幸的是Python绑定不起作用,所以这里是解决方案。在

在C++中制作一个挤压包装器,它导出内部访问函数:

#include <squish.h>

typedef unsigned char u8;

extern "C" {
    void CompressMasked( u8 const* rgba, int mask, void* block, int flags ) {
        squish::CompressMasked(rgba, mask, block, flags);
    }

    void Compress( u8 const* rgba, void* block, int flags ) {
        squish::Compress(rgba, block, flags);
    }

    void Decompress( u8* rgba, void const* block, int flags ) {
        squish::Decompress(rgba, block, flags);
    }

    int GetStorageRequirements( int width, int height, int flags ) {
        return squish::GetStorageRequirements(width, height, flags);
    }

    void CompressImage( u8 const* rgba, int width, int height, void* blocks, int flags ) {
        squish::CompressImage(rgba, width, height, blocks, flags);
    }

    void DecompressImage( u8* rgba, int width, int height, void const* blocks, int flags ) {
        squish::DecompressImage(rgba, width, height, blocks, flags);
    }
}

创建一个动态库(在windows上是dll,在linux上是这样的,我称之为libsquishc.so),然后用ctypes打开它。在

我的方法(只导出我需要的函数):

^{pr2}$

Tags: 方法函数maskwidthblockintflagsheight
2条回答

libSquish有{a2}。在

编辑:安装过程似乎

  1. 下载squish-1.11.zip
  2. 解包和编译-应生成libsquish.a文件
  3. 下载并安装Cython(听起来像是你做的)
  4. 创建一个临时目录并“应用”补丁-它会删除一堆新文件,这些文件是绑定代码
  5. 运行安装程序(sudo python设置.py安装)

如果您这样做了,但仍然有错误,那么也许您应该(a)共享实际的错误消息,以便我们能够找出原因,或者(b)直接联系补丁作者-mat(at)kivy.org网站在

Edit2:编译错误足够短,我将在这里包括它:

running install
running build
running build_ext
skipping 'squish.c' Cython extension (up-to-date)
building 'squish' extension
gcc -pthread -fno-strict-aliasing -march=i686 -mtune=generic -O2 -pipe -fstack-protector  param=ssp-buffer-size=4 -D_FORTIFY_SOURCE=2 -DNDEBUG -march=i686 -mtune=generic -O2 -pipe -fstack-protector  param=ssp-buffer-size=4 -D_FORTIFY_SOURCE=2 -fPIC -I.. -I/usr/include/python2.7 -c squish.c -o build/temp.linux-i686-2.7/squish.o
In file included from squish.c:274:0:
/usr/include/squish.h:32:1: error: unknown type name 'namespace'
/usr/include/squish.h:32:18: error: expected '=', ',', ';', 'asm' or '__attribute__' before '{' token
squish.c: In function '__pyx_pf_6squish_compressImage':
squish.c:790:22: error: 'squish' undeclared (first use in this function)
squish.c:790:22: note: each undeclared identifier is reported only once for each function it appears in
squish.c:790:28: error: expected ';' before ':' token
squish.c:866:10: error: expected expression before ':' token
squish.c: In function '__pyx_pf_6squish_2decompressImage':
squish.c:1202:10: error: expected expression before ':' token
error: command 'gcc' failed with exit status 1

shush.h的相关部分看起来像

^{pr2}$

它看起来像是在^ {< CD1>}关键字上阻塞,我想说它是编译成C时编译成C++。在

libsquish提供了一些python绑定:http://code.google.com/p/libsquish/issues/detail?id=17但是我没有使用它们。在

相关问题 更多 >

    热门问题