ispc_tex/
bc3.rs

1use crate::bindings::kernel;
2use crate::RgbaSurface;
3
4#[inline(always)]
5pub fn calc_output_size(width: u32, height: u32) -> usize {
6    // BC3 uses 16 bytes to store each 4×4 block, giving it an average data rate of 1 byte per pixel.
7    let block_count = crate::divide_up_by_multiple(width * height, 16) as usize;
8    block_count * 16
9}
10
11pub fn compress_blocks(surface: &RgbaSurface) -> Vec<u8> {
12    let output_size = calc_output_size(surface.width, surface.height);
13    let mut output = vec![0u8; output_size];
14    compress_blocks_into(surface, &mut output);
15    output
16}
17
18pub fn compress_blocks_into(surface: &RgbaSurface, blocks: &mut [u8]) {
19    assert_eq!(
20        blocks.len(),
21        calc_output_size(surface.width, surface.height)
22    );
23    let mut surface = kernel::rgba_surface {
24        width: surface.width as i32,
25        height: surface.height as i32,
26        stride: surface.stride as i32,
27        ptr: surface.data.as_ptr() as *mut u8,
28    };
29
30    unsafe {
31        kernel::CompressBlocksBC3_ispc(&mut surface, blocks.as_mut_ptr());
32    }
33}