ctt_intel_texture_compressor/
etc1.rs1use crate::RgbaSurface;
14use crate::bindings::kernel;
15
16#[derive(Debug, Copy, Clone)]
17pub struct EncodeSettings {
18 pub fast_skip_threshold: u32,
19}
20
21#[must_use]
22pub fn calc_output_size(width: u32, height: u32) -> usize {
23 let block_count = (width.div_ceil(4) * height.div_ceil(4)) as usize;
25 block_count * 8
26}
27
28#[must_use]
29pub fn compress_blocks(settings: &EncodeSettings, surface: &RgbaSurface) -> Vec<u8> {
30 let output_size = calc_output_size(surface.width, surface.height);
31 let mut output = vec![0u8; output_size];
32 compress_blocks_into(settings, surface, &mut output);
33 output
34}
35
36pub fn compress_blocks_into(settings: &EncodeSettings, surface: &RgbaSurface, blocks: &mut [u8]) {
47 assert_eq!(
48 blocks.len(),
49 calc_output_size(surface.width, surface.height)
50 );
51 let mut surface = kernel::rgba_surface {
54 width: surface.width as i32,
55 height: surface.height as i32,
56 stride: surface.stride as i32,
57 ptr: surface.data.as_ptr() as *mut u8,
58 };
59 let mut settings = kernel::etc_enc_settings {
60 fastSkipThreshold: settings.fast_skip_threshold as i32,
61 };
62
63 unsafe {
64 kernel::CompressBlocksETC1_ispc(&mut surface, blocks.as_mut_ptr(), &mut settings);
65 }
66}
67
68pub fn slow_settings() -> EncodeSettings {
69 EncodeSettings {
70 fast_skip_threshold: 6,
71 }
72}