Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use explicit table lookup for ac_q and dc_q #2667

Merged
merged 2 commits into from
Feb 10, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 8 additions & 16 deletions src/quantize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,17 @@ pub fn get_log_tx_scale(tx_size: TxSize) -> usize {
}

pub fn dc_q(qindex: u8, delta_q: i8, bit_depth: usize) -> i16 {
let &table = match bit_depth {
8 => &dc_qlookup_Q3,
10 => &dc_qlookup_10_Q3,
12 => &dc_qlookup_12_Q3,
_ => unimplemented!(),
};

table[(qindex as isize + delta_q as isize).max(0).min(255) as usize]
static DC_Q: [&[i16; 256]; 3] =
[&dc_qlookup_Q3, &dc_qlookup_10_Q3, &dc_qlookup_12_Q3];
let bd = ((bit_depth ^ 8) >> 1).min(2);
DC_Q[bd][((qindex as isize + delta_q as isize).max(0) as usize).min(255)]
}

pub fn ac_q(qindex: u8, delta_q: i8, bit_depth: usize) -> i16 {
let &table = match bit_depth {
8 => &ac_qlookup_Q3,
10 => &ac_qlookup_10_Q3,
12 => &ac_qlookup_12_Q3,
_ => unimplemented!(),
};

table[(qindex as isize + delta_q as isize).max(0).min(255) as usize]
static AC_Q: [&[i16; 256]; 3] =
[&ac_qlookup_Q3, &ac_qlookup_10_Q3, &ac_qlookup_12_Q3];
let bd = ((bit_depth ^ 8) >> 1).min(2);
AC_Q[bd][((qindex as isize + delta_q as isize).max(0) as usize).min(255)]
}

// TODO: Handle lossless properly.
Expand Down