3 unstable releases
0.1.1 | Jun 25, 2024 |
---|---|
0.1.0 | Jun 19, 2024 |
0.0.5 | Jul 25, 2023 |
#87 in Images
35 downloads per month
Used in 3 crates
345KB
7.5K
SLoC
texture2ddecoder
A pure Rust no-std texture decoder for the following formats:
- ATC - Adreno Texture Compression (detailed paper)
- ASTC - Adaptive Scalable Texture Compression
- BCn - Block Compression
- ETC - Ericsson Texture Compression
- PVRTC - PowerVR Texture Compression
and with alloc:
Features
alloc (optional, default)
- ~35% faster pvrtc decoding
- crunch 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
- Crunch & Unity's Crunch: The texture's dimensions and metadata are stored in the file itself, the header must be parsed with crnd_get_texture_info() from CrnTextureInfo struct first, then pass the metadata to the decoder. There's no block decompression function.
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
- Crunch
- decode_crunch
- Unity Crunch
- decode_unity_crunch
Roadmap
- 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
- 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 |