use super::engine::CtxModel;
pub(crate) struct ContextSet {
#[allow(unused)]
pub(crate) qp: u8,
pub(crate) split_cu_flag: [CtxModel; 3],
#[allow(unused)]
pub(crate) split_transform_flag: [CtxModel; 3],
pub(crate) cbf_luma: [CtxModel; 2],
pub(crate) cbf_chroma: [CtxModel; 5],
pub(crate) last_sig_coeff_x_prefix: [CtxModel; 18],
pub(crate) last_sig_coeff_y_prefix: [CtxModel; 18],
pub(crate) sig_coeff_flag: [CtxModel; 44],
pub(crate) coded_sub_block_flag: [CtxModel; 4],
pub(crate) coeff_abs_level_greater1: [CtxModel; 24],
pub(crate) coeff_abs_level_greater2: [CtxModel; 6],
pub(crate) sao_merge_flag: CtxModel,
pub(crate) sao_type_idx: CtxModel,
}
impl ContextSet {
pub(crate) fn init_islice(qp: u8) -> Self {
fn c(iv: u8, qp: u8) -> CtxModel {
CtxModel::init(iv, qp)
}
fn arr<const N: usize>(ivs: [u8; N], qp: u8) -> [CtxModel; N] {
ivs.map(|iv| CtxModel::init(iv, qp))
}
Self {
qp,
split_cu_flag: arr([139, 141, 157], qp),
split_transform_flag: arr([153, 138, 138], qp),
cbf_luma: arr([111, 141], qp),
cbf_chroma: arr([94, 138, 182, 154, 154], qp),
last_sig_coeff_x_prefix: arr(
[
110, 110, 124, 125, 140, 153, 125, 127, 140, 109, 111, 143, 127, 111, 79, 108,
123, 63,
],
qp,
),
last_sig_coeff_y_prefix: arr(
[
110, 110, 124, 125, 140, 153, 125, 127, 140, 109, 111, 143, 127, 111, 79, 108,
123, 63,
],
qp,
),
sig_coeff_flag: arr(
[
111, 111, 125, 110, 110, 94, 124, 108, 124, 107, 125, 141, 179, 153, 125, 107,
125, 141, 179, 153, 125, 107, 125, 141, 179, 153, 125, 140, 139, 182, 182, 152,
136, 152, 136, 153, 136, 139, 111, 136, 139, 111, 141, 111,
],
qp,
),
coded_sub_block_flag: arr([91, 171, 134, 141], qp),
coeff_abs_level_greater1: arr(
[
140, 92, 137, 138, 140, 152, 138, 139, 153, 74, 149, 92, 139, 107, 122, 152,
140, 179, 166, 182, 140, 227, 122, 197,
],
qp,
),
coeff_abs_level_greater2: arr([138, 153, 136, 167, 152, 152], qp),
sao_merge_flag: c(153, qp),
sao_type_idx: c(200, qp),
}
}
}
pub(crate) struct IntraModeContexts {
pub(crate) part_mode: CtxModel,
pub(crate) prev_intra_luma_pred_flag: CtxModel,
pub(crate) intra_chroma_pred_mode: CtxModel,
}
impl IntraModeContexts {
pub(crate) fn init_islice(qp: u8) -> Self {
Self {
part_mode: CtxModel::init(184, qp),
prev_intra_luma_pred_flag: CtxModel::init(184, qp),
intra_chroma_pred_mode: CtxModel::init(63, qp),
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn intra_mode_contexts() {
let ictx = IntraModeContexts::init_islice(26);
assert!(ictx.prev_intra_luma_pred_flag.p_state_idx < 64);
assert!(ictx.intra_chroma_pred_mode.p_state_idx < 64);
}
}