Skip to main content

Module texture_compress

Module texture_compress 

Source
Expand description

Multi-format texture compression (BC1 and BC4) for OxiGDAL GPU.

This module provides both pure-Rust CPU implementations and GPU-accelerated (wgpu compute shader) paths for compressing raster data into BC1 (DXT1) and BC4 (ATI1) block-compressed texture formats.

§Format overview

FormatInputOutputRatio
TextureFormat::Bc1RgbUnormRGBA8 (4 B/px)8 B / 4×4 block6:1
TextureFormat::Bc4RUnormR8 (1 B/px)8 B / 4×4 block2:1

§BC1 block layout (8 bytes)

[u16 c0 LE] [u16 c1 LE] [u32 lookup LE]

When c0 > c1 four colours are interpolated (opaque mode, always used here). When c0 <= c1 three colours + transparent; this module never emits that mode.

§BC4 block layout (8 bytes)

[u8 ep0] [u8 ep1] [48-bit LE packed 3-bit indices for 16 pixels]

When ep0 > ep1 eight interpolated values are used (always in this module).

§GPU path

TextureCompressor drives a wgpu compute shader that processes one 4×4 block per workgroup thread. When wgpu is unavailable the compress method falls back silently to the CPU path.

Structs§

TextureCompressor
GPU-accelerated texture compressor for BC1 and BC4 block formats.

Enums§

TextureFormat
Target block-compressed texture format produced by TextureCompressor.

Functions§

compress_bc1_block_cpu
Compress one 4×4 RGBA block (64 bytes, row-major) to an 8-byte BC1 block.
compress_bc4_block_cpu
Compress one 4×4 R-channel block (16 bytes) to an 8-byte BC4 block.
dequantize_rgb565
Reverse a packed RGB565 value back to approximate 8-bit R, G, B.
nearest_index_4
Return the index (0..4) of the endpoint in endpoints nearest to value_rgb under the squared-Euclidean distance metric in RGB space.
quantize_rgb565
Quantise 8-bit RGB components to packed 16-bit RGB565.
validate_texture_dimensions
Validate that width and height are both multiples of 4 (required for block-compressed textures).