1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
use more_asserts::assert_ge;
use crate::bindings::kernel;
use crate::RgbaSurface;
#[derive(Debug, Copy, Clone)]
pub struct EncodeSettings {
pub slow_mode: bool,
pub fast_mode: bool,
pub refine_iterations_1p: u32,
pub refine_iterations_2p: u32,
pub fast_skip_threshold: u32,
}
#[inline(always)]
pub fn calc_output_size(width: u32, height: u32) -> usize {
let block_count = crate::cal_block_count(width, height, 4, 4) as usize;
block_count * 16
}
pub fn compress_blocks(settings: &EncodeSettings, surface: &RgbaSurface) -> Vec<u8> {
let output_size = calc_output_size(surface.width, surface.height);
let mut output = vec![0u8; output_size];
compress_blocks_into(settings, surface, &mut output);
output
}
pub fn compress_blocks_into(settings: &EncodeSettings, surface: &RgbaSurface, blocks: &mut [u8]) {
assert_ge!(
blocks.len(),
calc_output_size(surface.width, surface.height)
);
let mut surface = kernel::rgba_surface {
width: surface.width as i32,
height: surface.height as i32,
stride: surface.stride as i32,
ptr: surface.data.as_ptr() as *mut u8,
};
let mut settings = kernel::bc6h_enc_settings {
slow_mode: settings.slow_mode,
fast_mode: settings.fast_mode,
refineIterations_1p: settings.refine_iterations_1p as i32,
refineIterations_2p: settings.refine_iterations_2p as i32,
fastSkipTreshold: settings.fast_skip_threshold as i32,
};
unsafe {
kernel::CompressBlocksBC6H_ispc(&mut surface, blocks.as_mut_ptr(), &mut settings);
}
}
#[inline(always)]
pub fn very_fast_settings() -> EncodeSettings {
EncodeSettings {
slow_mode: false,
fast_mode: true,
fast_skip_threshold: 0,
refine_iterations_1p: 0,
refine_iterations_2p: 0,
}
}
#[inline(always)]
pub fn fast_settings() -> EncodeSettings {
EncodeSettings {
slow_mode: false,
fast_mode: true,
fast_skip_threshold: 2,
refine_iterations_1p: 0,
refine_iterations_2p: 1,
}
}
#[inline(always)]
pub fn basic_settings() -> EncodeSettings {
EncodeSettings {
slow_mode: false,
fast_mode: false,
fast_skip_threshold: 4,
refine_iterations_1p: 2,
refine_iterations_2p: 2,
}
}
#[inline(always)]
pub fn slow_settings() -> EncodeSettings {
EncodeSettings {
slow_mode: true,
fast_mode: false,
fast_skip_threshold: 10,
refine_iterations_1p: 2,
refine_iterations_2p: 2,
}
}
#[inline(always)]
pub fn very_slow_settings() -> EncodeSettings {
EncodeSettings {
slow_mode: true,
fast_mode: false,
fast_skip_threshold: 32,
refine_iterations_1p: 2,
refine_iterations_2p: 2,
}
}