#纹理压缩 #图形 #无分配 #编码

无std texture2ddecoder

纯Rust无std纹理解码器

3个不稳定版本

0.1.1 2024年6月25日
0.1.0 2024年6月19日
0.0.5 2023年7月25日

#80 in 图像

每月 38次下载
3 crate 中使用

MIT/Apache

345KB
7.5K SLoC

texture2ddecoder 构建状态 最新版本 文档 License_MIT License_APACHE

支持以下格式的纯Rust无std纹理解码器

以及带有alloc

特性

alloc(可选,默认)

  • ~35%更快的pvrtc解码速度
  • Crunch解码

函数

为每种格式提供解码函数,以及除PVRTC之外所有格式的块解码函数。除了某些异常情况,解码函数的签名如下

    fn decode_format(data: &[u8], width: usize, height: usize, image: &mut [u32]) -> Result<(), &'static str>
    // data: the compressed data, expected to be width * height / block_size in size
    // width: the width of the image
    // height: the height of the image
    // image: the buffer to write the decoded image to, expected to be width * height in size
    fn decode_format_block(data: &[u8], outbuf: &mut [u32]) -> Result<(), &'static str>
    // data: the compressed data (block), expected to be block_size in size
    // outbuf: the buffer to write the decoded image to, expected to be block_size in size

异常情况包括

  • ASTC:解码函数(块)接收块大小作为附加参数
  • BC6:有两个额外的解码函数用于有符号和无符号版本
  • PVRTC:解码函数接收块大小作为附加参数,并且有两个额外的解码函数用于2bpp和4bpp版本
  • Crunch 和 Unity 的 Crunch:纹理的尺寸和元数据存储在文件本身中,必须首先使用 CrnTextureInfo 结构的 crnd_get_texture_info() 解析头部,然后将元数据传递给解码器。没有块解压缩函数。

以下是格式列表及其对应函数

  • ATC
    • decode_atc_rgb4
    • decode_atc_rgb4_block
    • decode_atc_rgba8
    • decode_atc_rgba8_block
  • ASTC
    • decode_astc
    • decode_astc_block
    • 各种 decode_astc_(block_)_x_y 函数,其中 x 和 y 是块大小
  • BCn
    • decode_bc1
    • decode_bc1_block
    • decode_bc3
    • decode_bc3_block
    • decode_bc4
    • decode_bc4_block
    • decode_bc5
    • decode_bc5_block
    • decode_bc6
    • decode_bc6_block
    • decode_bc6_signed
    • decode_bc6_block_signed
    • decode_bc6_unsigned
    • decode_bc6_block_unsigned
    • decode_bc7
    • decode_bc7_block
  • ETC
    • decode_etc1
    • decode_etc1_block
    • decode_etc2_rgb
    • decode_etc2_rgb_block
    • decode_etc2_rgba1
    • decode_etc2_rgba1_block
    • decode_etc2_rgba8
    • decode_etc2_rgba8_block
    • decode_eacr
    • decode_eacr_block
    • decode_eacr_signed
    • decode_eacr_signed_block
    • decode_eacrg
    • decode_eacrg_block
  • PVRTC
    • decode_pvrtc
    • decode_pvrtc_2bpp
    • decode_pvrtc_4bpp
  • Crunch
    • decode_crunch
  • Unity Crunch
    • decode_unity_crunch

路线图

  • 文档
  • 将 u32 颜色输出替换为 RGBA 结构
  • 寻找解码器的原始源代码
  • 支持 BGRA32 以外的输出
  • 添加其他格式

格式进度

  • ATC-RGB
  • ATC-RGBA
  • ASTC
  • BC1
  • BC3
  • BC4
  • BC5
  • BC6
  • BC7
  • EAC-R
  • EAC-RG
  • ETC1
  • ETC2
  • ETC2-A1
  • ETC2-A8
  • PVRTCI-2bpp
  • PVRTCI-4bpp
  • Crunched
    • DXT1
    • DXT5
    • ETC1
    • ETC2-A8

许可证 & 致谢

这个crate本身是 MIT + Apache2 双许可。

纹理压缩编解码器本身的许可证如下

编解码器 许可证 来源
ATC MIT Perfare/AssetStudio - Texture2DDecoderNative/atc.cpp
ASTC MIT* Ishotihadus/mikunyan - ext/decoders/native/astc.c
BCn MIT* Perfare/AssetStudio - Texture2DDecoderNative/bcn.cpp
ETC MIT* Ishotihadus/mikunyan - ext/decoders/native/etc.c
f16 MIT Maratyszcza/FP16
PVRTC MIT* Ishotihadus/mikunyan - ext/decoders/native/pvrtc.c
Crunch 公共领域 BinomialLLC/crunch
Crunch (Unity) ZLIB Unity-Technologies/crunch
* 如果这些是原始源代码,并且不仅仅是从其他地方获取/采用代码,请告知

依赖关系