texture2ddecoder/lib.rs
1//! A pure Rust no-std texture decoder for the following formats:
2//! - [ATC - Adreno Texture Compression](https://registry.khronos.org/OpenGL/extensions/AMD/AMD_compressed_ATC_texture.txt)
3//! - [ASTC - Adaptive Scalable Texture Compression](https://en.wikipedia.org/wiki/Adaptive_Scalable_Texture_Compression)
4//! - [BCn - Block Compression](https://en.wikipedia.org/wiki/S3_Texture_Compression)
5//! - [ETC - Ericsson Texture Compression](https://en.wikipedia.org/wiki/Ericsson_Texture_Compression)
6//! - [PVRTC - PowerVR Texture Compression](https://en.wikipedia.org/wiki/PVRTC)
7//! - [Crunch](https://github.com/BinomialLLC/crunch) & [Unity's Crunch](https://github.com/Unity-Technologies/crunch)
8//!
9//! ## Functions
10//! Provides a decode function for each format, as well as a block decode function all formats besides PVRTC.
11//! Besides some exceptions, the signature of the decode functions is as follows:
12//! ```ignore
13//! fn decode_format(data: &[u8], width: usize, height: usize, image: &mut [u32]) -> Result<(), &'static str>
14//! // data: the compressed data, expected to be width * height / block_size in size
15//! // width: the width of the image
16//! // height: the height of the image
17//! // image: the buffer to write the decoded image to, expected to be width * height in size
18//! fn decode_format_block(data: &[u8], image: &mut [u32]) -> Result<(), &'static str>
19//! // data: the compressed data (block), expected to be block_size in size
20//! // image: the buffer to write the decoded image to, expected to be block_size in size
21//! ```
22//! The exceptions are:
23//! - ASTC: the (block) decode function takes the block size as an additional parameter
24//! - BC6: there are two additional decode functions for the signed and unsigned variants
25//! - 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
26//! - Crunch & Unity's Crunch: The texture's dimensions and metadata are stored in the file itself, one's must parse the header with crnd_get_texture_info() from crn_texture_info struct first, then pass the metadata to the decoder as in the format. There's no block decomp. function.
27//!
28//! To make these excetions easier to use, there are helper functions to enable decode functions with identical arguments and returns.
29//!
30//! Here is a list of the formats and their corresponding functions:
31//! - ATC
32//! - [`decode_atc_rgb4()`]
33//! - [`decode_atc_rgb4_block()`]
34//! - [`decode_atc_rgba8()`]
35//! - [`decode_atc_rgba8_block()`]
36//! - ASTC
37//! - [`decode_astc()`]
38//! - [`decode_astc_block()`]
39//! - various decode_astc_(block_)_x_y functions, where x and y are the block size
40//! - BCn
41//! - [`decode_bc1()`]
42//! - [`decode_bc1_block()`]
43//! - [`decode_bc3()`]
44//! - [`decode_bc3_block()`]
45//! - [`decode_bc4()`]
46//! - [`decode_bc4_block()`]
47//! - [`decode_bc5()`]
48//! - [`decode_bc5_block()`]
49//! - [`decode_bc6()`]
50//! - [`decode_bc6_block()`]
51//! - [`decode_bc6_signed()`]
52//! - [`decode_bc6_block_signed()`]
53//! - [`decode_bc6_unsigned()`]
54//! - [`decode_bc6_block_unsigned()`]
55//! - [`decode_bc7()`]
56//! - [`decode_bc7_block()`]
57//! - ETC
58//! - [`decode_etc1()`]
59//! - [`decode_etc1_block()`]
60//! - [`decode_etc2_rgb()`]
61//! - [`decode_etc2_rgb_block()`]
62//! - [`decode_etc2_rgba1()`]
63//! - [`decode_etc2_rgba1_block()`]
64//! - [`decode_etc2_rgba8()`]
65//! - [`decode_etc2_rgba8_block()`]
66//! - [`decode_eacr()`]
67//! - [`decode_eacr_block()`]
68//! - [`decode_eacr_signed()`]
69//! - [`decode_eacr_signed_block()`]
70//! - [`decode_eacrg()`]
71//! - [`decode_eacrg_block()`]
72//! - PVRTC
73//! - [`decode_pvrtc()`]
74//! - [`decode_pvrtc_2bpp()`]
75//! - [`decode_pvrtc_4bpp()`]
76//! - Crunch
77//! - [`decode_crunch()`]
78//! - Unity Crunch
79//! - [`decode_unity_crunch()`]
80//!
81#![no_std]
82
83mod bitreader;
84mod color;
85mod f16;
86mod macros;
87
88mod astc;
89mod atc;
90mod bcn;
91mod crnlib;
92#[cfg(feature = "alloc")]
93mod crunch;
94mod etc;
95mod pvrtc;
96#[cfg(feature = "alloc")]
97mod unitycrunch;
98
99// import decode functions
100pub use astc::*;
101pub use atc::*;
102pub use bcn::*;
103pub use crnlib::CrnTextureInfo;
104pub use crunch::decode_crunch;
105pub use etc::*;
106pub use pvrtc::*;
107pub use unitycrunch::decode_unity_crunch;