MCPcopy Index your code
hub / github.com/K0lb3/texture2ddecoder-rs

github.com/K0lb3/texture2ddecoder-rs @0.1.1

Chat with this repo
repository ↗ · DeepWiki ↗ · release 0.1.1 ↗ · + Follow
277 symbols 632 edges 35 files 1 documented · 0%
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

texture2ddecoder Build Status Latest Version Docs License_MIT License_APACHE

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: - Crunch & Unity's Crunch (unity branch)

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

  • [x] ATC-RGB
  • [x] ATC-RGBA
  • [x] ASTC
  • [x] BC1
  • [x] BC3
  • [x] BC4
  • [x] BC5
  • [x] BC6
  • [x] BC7
  • [x] EAC-R
  • [x] EAC-RG
  • [x] ETC1
  • [x] ETC2
  • [x] ETC2-A1
  • [x] ETC2-A8
  • [x] PVRTCI-2bpp
  • [x] PVRTCI-4bpp
  • [x] Crunched
  • [x] DXT1
  • [x] DXT5
  • [x] ETC1
  • [x] 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

Core symbols most depended-on inside this repo

read
called by 273
src/bitreader.rs
cast_to_uint
called by 114
src/crunch/crn_decomp.rs
decode
called by 59
src/crunch/crn_symbol_codec.rs
color
called by 27
src/color.rs
assign_from_buffer
called by 21
src/crunch/crn_decomp.rs
decode_receive_static_data_model
called by 20
src/crunch/crn_symbol_codec.rs
limit
called by 16
src/crunch/crn_utils.rs
applicate_color
called by 15
src/etc/etc1.rs

Shape

Function 181
Method 72
Class 23
Enum 1

Languages

Rust82%
Python18%

Modules by API surface

tests/test.rs51 symbols
bindings/python/tests/test_main.py51 symbols
src/astc.rs28 symbols
src/unitycrunch/crn_unpacker.rs21 symbols
src/crunch/crn_unpacker.rs16 symbols
src/pvrtc.rs14 symbols
src/crunch/crn_decomp.rs10 symbols
src/crunch/crn_symbol_codec.rs9 symbols
src/bcn/bc6.rs9 symbols
src/crunch/crn_static_huffman_data_model.rs7 symbols
src/bitreader.rs7 symbols
src/etc/eac.rs6 symbols

For agents

$ claude mcp add texture2ddecoder-rs \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact