pub fn compute_quantizer(q0: i32, dq: usize, qmax: i32, i: i32) -> i32 {
const DQ_TABLE: [i32; 8] = [0, 2, 3, 4, 6, 8, 12, 16];
let quant = q0 + (DQ_TABLE[dq] * i + 8) / 16;
quant.min(qmax)
}
#[cfg(test)]
mod tests {
use super::compute_quantizer;
#[test]
fn quantizer_rises_with_the_step_and_stops_at_qmax() {
assert_eq!(compute_quantizer(6, 0, 15, 25), 6);
assert_eq!(compute_quantizer(6, 7, 15, 3), 9);
assert_eq!(compute_quantizer(6, 7, 15, 20), 15);
assert_eq!(compute_quantizer(4, 2, 15, 2), 4);
assert_eq!(compute_quantizer(4, 2, 15, 3), 5);
}
}