5 releases

0.0.5 Jul 25, 2023
0.0.4 Jul 18, 2023
0.0.3 Jul 15, 2023
0.0.2 Jul 13, 2023
0.0.1 Jul 9, 2023

#145 in Images

Download history 15/week @ 2024-01-05 1/week @ 2024-01-12 1/week @ 2024-02-16 9/week @ 2024-02-23 6/week @ 2024-03-01 4/week @ 2024-03-08 4/week @ 2024-03-15 1/week @ 2024-03-22 56/week @ 2024-03-29

65 downloads per month
Used in tonytools

MIT/Apache

180KB
4.5K SLoC

texture2ddecoder Build Status Latest Version Docs License_MIT License_APACHE

A pure Rust no-std texture decoder for the following formats:

Features

alloc (optional, default)

  • ~35% faster pvrtc decoding

Functions

Provides a decode function for each format, as well as a block decode function all formats besides PVRTC. Besides some exceptions, the signature of the decode functions is as follows:

    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

The exceptions are:

  • ASTC: the (block) decode function takes the block size as an additional parameter
  • BC6: there are two additional decode functions for the signed and unsigned variants
  • PVRTC: the decode function takes the block size as an additional parameter, and there are two additional decode functions for the 2bpp and 4bpp variants To make these excetions easier to use, there are helper functions to enable decode functions with identical arguments and returns. Here is a list of the formats and their corresponding functions:
  • ATC
    • decode_atc_rgb4
    • decode_atc_rgb4_block
    • decode_atc_rgba8
    • decode_atc_rgba8_block
  • ASTC
    • decode_astc
    • decode_astc_block
    • various decode_astc_(block_)_x_y functions, where x and y are the block size
  • 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

Roadmap

  • implementing & testing all formats
  • documentation
  • replacing u32 color output with RGBA structure
  • finding the original sources for the decoders
  • supporting more than BGRA32 output
  • adding additional formats

Format Progress

  • 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 (not implemented)
    • DXT1
    • DXT5
    • ETC1
    • ETC2-A8

License & Credits

This crate itself is dual-licensed under MIT + Apache2.

The texture compression codecs themselves have following licenses:

Codec License Source
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 PUBLIC DOMAIN BinomialLLC/crunch
Crunch (Unity) ZLIB Unity-Technologies/crunch
* in doubt if these are the original source and have not just taken/adopted the code from somewhere else

Dependencies