1use more_asserts::assert_ge;
2
3use crate::bindings::kernel;
4use crate::RgbaSurface;
5
6#[inline(always)]
7pub fn calc_output_size(width: u32, height: u32) -> usize {
8 let block_count = crate::cal_block_count(width, height, 4, 4) as usize;
10 block_count * 16
11}
12
13pub fn compress_blocks(surface: &RgbaSurface) -> Vec<u8> {
14 let output_size = calc_output_size(surface.width, surface.height);
15 let mut output = vec![0u8; output_size];
16 compress_blocks_into(surface, &mut output);
17 output
18}
19
20pub fn compress_blocks_into(surface: &RgbaSurface, blocks: &mut [u8]) {
21 assert_ge!(
22 blocks.len(),
23 calc_output_size(surface.width, surface.height)
24 );
25 let mut surface = kernel::rgba_surface {
26 width: surface.width as i32,
27 height: surface.height as i32,
28 stride: surface.stride as i32,
29 ptr: surface.data.as_ptr() as *mut u8,
30 };
31
32 unsafe {
33 kernel::CompressBlocksBC3_ispc(&mut surface, blocks.as_mut_ptr());
34 }
35}