rgbcx-sys
Rust FFI bindings to the rgbcx (BC1-BC5 decoder/encoder) from Rich Geldreich's bc7enc_rdo project.
This provides access to BC1-BC5 texture compression and decompression functionality through the underlying C++ library.
I made these bindings for fuzz testing my own implementations only, so they're not super polished;
but feel free to use for anything else.
Example Usage
use rgbcx_sys::root::rgbcx;
unsafe { rgbcx::init(rgbcx::bc1_approx_mode::cBC1Ideal) };
fn encode_decode_example() {
let mut source_pixels = [0u8; 16 * 4];
for y in 0..4 {
for x in 0..4 {
let pixel_idx = (y * 4 + x) * 4;
if (x + y) % 2 == 0 {
source_pixels[pixel_idx] = 255; source_pixels[pixel_idx + 1] = 0; source_pixels[pixel_idx + 2] = 0; source_pixels[pixel_idx + 3] = 255; } else {
source_pixels[pixel_idx] = 0; source_pixels[pixel_idx + 1] = 255; source_pixels[pixel_idx + 2] = 0; source_pixels[pixel_idx + 3] = 255; }
}
}
let mut encoded_block = [0u8; 8];
unsafe {
rgbcx::encode_bc1(
10, encoded_block.as_mut_ptr() as *mut std::ffi::c_void,
source_pixels.as_ptr(),
true, false, std::ptr::null() );
}
let mut decoded_pixels = [0u8; 16 * 4];
unsafe {
rgbcx::unpack_bc1(
encoded_block.as_ptr() as *const std::ffi::c_void,
decoded_pixels.as_mut_ptr() as *mut std::ffi::c_void,
true,
rgbcx::bc1_approx_mode::cBC1Ideal,
);
}
}