use core::f32::consts::PI;
pub(super) fn idct8_basis_table() -> [f32; 64] {
let mut table = [0.0; 64];
for sample_idx in 0..8 {
for freq in 0..8 {
table[sample_idx * 8 + freq] = idct8_basis(sample_idx, freq);
}
}
table
}
#[expect(
clippy::cast_precision_loss,
reason = "IDCT basis indices are bounded to 0..8 and exactly represented by f32"
)]
fn idct8_basis(sample_idx: usize, freq: usize) -> f32 {
let scale = if freq == 0 {
(1.0_f32 / 8.0).sqrt()
} else {
(2.0_f32 / 8.0).sqrt()
};
scale * (((sample_idx as f32 + 0.5) * freq as f32 * PI) / 8.0).cos()
}