Skip to content

Commit

Permalink
rename variants
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Mar 27, 2024
1 parent 8ecd7c3 commit 5711bfe
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 65 deletions.
6 changes: 3 additions & 3 deletions src/cdf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ use crate::src::internal::Rav1dContext;
use crate::src::levels::BlockLevel;
use crate::src::levels::BlockPartition;
use crate::src::levels::BlockSize;
use crate::src::levels::CompInterPredMode;
use crate::src::levels::MVJoint;
use crate::src::levels::N_COMP_INTER_PRED_MODES;
use crate::src::levels::N_INTRA_PRED_MODES;
use crate::src::levels::N_TX_SIZES;
use crate::src::levels::N_UV_INTRA_PRED_MODES;
Expand Down Expand Up @@ -91,7 +91,7 @@ pub struct CdfModeContext {
pub cfl_sign: Align16<[u16; 8]>,
pub angle_delta: Align16<[[u16; 8]; 8]>,
pub filter_intra: Align16<[u16; 8]>,
pub comp_inter_mode: Align16<[[u16; N_COMP_INTER_PRED_MODES]; 8]>,
pub comp_inter_mode: Align16<[[u16; CompInterPredMode::COUNT]; 8]>,
pub seg_id: Align16<[[u16; RAV1D_MAX_SEGMENTS as usize]; 3]>,
pub pal_sz: Align16<[[[u16; 8]; 7]; 2]>,
pub color_map: Align16<[[[[u16; 8]; 5]; 7]; 2]>,
Expand Down Expand Up @@ -5029,7 +5029,7 @@ pub(crate) fn rav1d_cdf_thread_update(
update_bit_1d!(2, m.globalmv_mode);
update_bit_1d!(6, m.refmv_mode);
update_bit_1d!(3, m.drl_bit);
update_cdf_2d!(8, N_COMP_INTER_PRED_MODES - 1, m.comp_inter_mode);
update_cdf_2d!(8, CompInterPredMode::COUNT - 1, m.comp_inter_mode);
update_bit_1d!(4, m.intra);
update_bit_1d!(5, m.comp);
update_bit_1d!(5, m.comp_dir);
Expand Down
49 changes: 24 additions & 25 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,6 @@ use crate::src::levels::TxfmSize;
use crate::src::levels::CFL_PRED;
use crate::src::levels::DC_PRED;
use crate::src::levels::FILTER_PRED;
use crate::src::levels::N_COMP_INTER_PRED_MODES;
use crate::src::levels::N_INTRA_PRED_MODES;
use crate::src::levels::N_RECT_TX_SIZES;
use crate::src::levels::N_UV_INTRA_PRED_MODES;
Expand Down Expand Up @@ -1133,8 +1132,8 @@ unsafe fn splat_oneref_mv(
],
},
bs,
mf: (mode == InterPredMode::GLOBALMV.into() && cmp::min(bw4, bh4) >= 2) as u8
| (mode == InterPredMode::NEWMV.into()) as u8 * 2,
mf: (mode == InterPredMode::Global.into() && cmp::min(bw4, bh4) >= 2) as u8
| (mode == InterPredMode::New.into()) as u8 * 2,
}));
c.refmvs_dsp.splat_mv(
&mut t.rt.r[((t.by & 31) + 5) as usize..],
Expand Down Expand Up @@ -1188,7 +1187,7 @@ unsafe fn splat_tworef_mv(
r#ref: [b.r#ref()[0] + 1, b.r#ref()[1] + 1],
},
bs,
mf: (mode == CompInterPredMode::GLOBALMV_GLOBALMV) as u8
mf: (mode == CompInterPredMode::GlobalGlobal) as u8
| (1 << mode as u8 & 0xbc != 0) as u8 * 2,
}));
c.refmvs_dsp.splat_mv(
Expand Down Expand Up @@ -2418,7 +2417,7 @@ unsafe fn decode_b_inner(
frame_hdr.skip_mode.refs[1] as i8,
];
*b.comp_type_mut() = Some(CompInterType::Avg);
*b.inter_mode_mut() = CompInterPredMode::NEARESTMV_NEARESTMV;
*b.inter_mode_mut() = CompInterPredMode::NearestNearest;
*b.drl_idx_mut() = DrlProximity::Nearest;
has_subpel_filter = false;

Expand Down Expand Up @@ -2543,7 +2542,7 @@ unsafe fn decode_b_inner(
*b.inter_mode_mut() = CompInterPredMode::from_repr(rav1d_msac_decode_symbol_adapt8(
&mut ts.msac,
&mut ts.cdf.m.comp_inter_mode[ctx as usize],
N_COMP_INTER_PRED_MODES as usize - 1,
CompInterPredMode::COUNT as usize - 1,
) as usize)
.expect("valid variant");
if debug_block_info!(f, t) {
Expand All @@ -2558,7 +2557,7 @@ unsafe fn decode_b_inner(

let im = &dav1d_comp_inter_pred_modes[b.inter_mode() as usize];
*b.drl_idx_mut() = DrlProximity::Nearest;
if b.inter_mode() == CompInterPredMode::NEWMV_NEWMV {
if b.inter_mode() == CompInterPredMode::NewNew {
if n_mvs > 1 {
// `Nearer` or `Near`
let drl_ctx_v1 = get_drl_context(&mvstack, 0);
Expand Down Expand Up @@ -2588,7 +2587,7 @@ unsafe fn decode_b_inner(
);
}
}
} else if im[0] == InterPredMode::NEARMV || im[1] == InterPredMode::NEARMV {
} else if im[0] == InterPredMode::Near || im[1] == InterPredMode::Near {
*b.drl_idx_mut() = DrlProximity::Nearer;
if n_mvs > 2 {
// `Near` or `Nearish`
Expand Down Expand Up @@ -2621,13 +2620,13 @@ unsafe fn decode_b_inner(
}

has_subpel_filter =
cmp::min(bw4, bh4) == 1 || b.inter_mode() != CompInterPredMode::GLOBALMV_GLOBALMV;
cmp::min(bw4, bh4) == 1 || b.inter_mode() != CompInterPredMode::GlobalGlobal;
let mut assign_comp_mv = |idx: usize| match im[idx] {
InterPredMode::NEARMV | InterPredMode::NEARESTMV => {
InterPredMode::Near | InterPredMode::Nearest => {
b.mv_mut()[idx] = mvstack[b.drl_idx() as usize].mv.mv[idx];
fix_mv_precision(frame_hdr, &mut b.mv_mut()[idx]);
}
InterPredMode::GLOBALMV => {
InterPredMode::Global => {
has_subpel_filter |= frame_hdr.gmv[b.r#ref()[idx] as usize].r#type
== Rav1dWarpedMotionType::Translation;
b.mv_mut()[idx] = get_gmv_2d(
Expand All @@ -2639,7 +2638,7 @@ unsafe fn decode_b_inner(
frame_hdr,
);
}
InterPredMode::NEWMV => {
InterPredMode::New => {
b.mv_mut()[idx] = mvstack[b.drl_idx() as usize].mv.mv[idx];
read_mv_residual(
t,
Expand Down Expand Up @@ -2843,7 +2842,7 @@ unsafe fn decode_b_inner(
&mut ts.cdf.m.globalmv_mode[(ctx >> 3 & 1) as usize],
)
{
*b.inter_mode_mut() = InterPredMode::GLOBALMV.into();
*b.inter_mode_mut() = InterPredMode::Global.into();
b.mv_mut()[0] = get_gmv_2d(
&frame_hdr.gmv[b.r#ref()[0] as usize],
t.bx,
Expand All @@ -2862,7 +2861,7 @@ unsafe fn decode_b_inner(
&mut ts.cdf.m.refmv_mode[(ctx >> 4 & 15) as usize],
) {
// `Nearer`, `Near` or `Nearish`
*b.inter_mode_mut() = InterPredMode::NEARMV.into();
*b.inter_mode_mut() = InterPredMode::Near.into();
*b.drl_idx_mut() = DrlProximity::Nearer;
if n_mvs > 2 {
// `Nearer`, `Near` or `Nearish`
Expand All @@ -2886,7 +2885,7 @@ unsafe fn decode_b_inner(
}
}
} else {
*b.inter_mode_mut() = InterPredMode::NEARESTMV.into();
*b.inter_mode_mut() = InterPredMode::Nearest.into();
*b.drl_idx_mut() = DrlProximity::Nearest;
}
b.mv_mut()[0] = mvstack[b.drl_idx() as usize].mv.mv[0];
Expand All @@ -2908,7 +2907,7 @@ unsafe fn decode_b_inner(
}
} else {
has_subpel_filter = true;
*b.inter_mode_mut() = InterPredMode::NEWMV.into();
*b.inter_mode_mut() = InterPredMode::New.into();
*b.drl_idx_mut() = DrlProximity::Nearest;
if n_mvs > 1 {
// `Nearer`, `Near` or `Nearish`
Expand Down Expand Up @@ -3018,7 +3017,7 @@ unsafe fn decode_b_inner(
&& cmp::min(bw4, bh4) >= 2
// is not warped global motion
&& !(!frame_hdr.force_integer_mv
&& b.inter_mode() == InterPredMode::GLOBALMV.into()
&& b.inter_mode() == InterPredMode::Global.into()
&& frame_hdr.gmv[b.r#ref()[0] as usize].r#type > Rav1dWarpedMotionType::Translation)
// has overlappable neighbours
&& (have_left && findoddzero(&t.l.intra.0[by4 as usize..][..h4 as usize])
Expand Down Expand Up @@ -3162,9 +3161,9 @@ unsafe fn decode_b_inner(
if frame_hdr.loopfilter.level_y != [0, 0] {
let is_globalmv = (b.inter_mode()
== if is_comp {
CompInterPredMode::GLOBALMV_GLOBALMV
CompInterPredMode::GlobalGlobal
} else {
InterPredMode::GLOBALMV.into()
InterPredMode::Global.into()
}) as c_int;
let tx_split = [b.tx_split0() as u16, b.tx_split1()];
let mut ytx = b.max_ytx() as RectTxfmSize;
Expand Down Expand Up @@ -3295,7 +3294,7 @@ unsafe fn decode_b_inner(
if b.comp_type().is_none() {
// y
if cmp::min(bw4, bh4) > 1
&& (b.inter_mode() == InterPredMode::GLOBALMV.into()
&& (b.inter_mode() == InterPredMode::Global.into()
&& f.gmv_warp_allowed[b.r#ref()[0] as usize] != 0
|| b.motion_mode() == MotionMode::Warp
&& t.warpmv.r#type > Rav1dWarpedMotionType::Translation)
Expand Down Expand Up @@ -3404,7 +3403,7 @@ unsafe fn decode_b_inner(
&f.svc[b.r#ref()[0] as usize][1],
);
} else if cmp::min(cbw4, cbh4) > 1
&& (b.inter_mode() == InterPredMode::GLOBALMV.into()
&& (b.inter_mode() == InterPredMode::Global.into()
&& f.gmv_warp_allowed[b.r#ref()[0] as usize] != 0
|| b.motion_mode() == MotionMode::Warp
&& t.warpmv.r#type > Rav1dWarpedMotionType::Translation)
Expand Down Expand Up @@ -3450,7 +3449,7 @@ unsafe fn decode_b_inner(
let refmvs =
|| std::iter::zip(b.r#ref(), b.mv()).map(|(r#ref, mv)| (r#ref as usize, mv));
for (r#ref, mv) in refmvs() {
if b.inter_mode() == CompInterPredMode::GLOBALMV_GLOBALMV
if b.inter_mode() == CompInterPredMode::GlobalGlobal
&& f.gmv_warp_allowed[r#ref] != 0
{
affine_lowest_px_luma(
Expand All @@ -3471,7 +3470,7 @@ unsafe fn decode_b_inner(
}
}
for (r#ref, mv) in refmvs() {
if b.inter_mode() == CompInterPredMode::GLOBALMV_GLOBALMV
if b.inter_mode() == CompInterPredMode::GlobalGlobal
&& f.gmv_warp_allowed[r#ref] != 0
{
affine_lowest_px_luma(
Expand All @@ -3495,7 +3494,7 @@ unsafe fn decode_b_inner(
// uv
if has_chroma {
for (r#ref, mv) in refmvs() {
if b.inter_mode() == CompInterPredMode::GLOBALMV_GLOBALMV
if b.inter_mode() == CompInterPredMode::GlobalGlobal
&& cmp::min(cbw4, cbh4) > 1
&& f.gmv_warp_allowed[r#ref] != 0
{
Expand Down Expand Up @@ -3882,7 +3881,7 @@ fn reset_context(ctx: &mut BlockContext, keyframe: bool, pass: c_int) {
r#ref.fill(-1);
}
ctx.comp_type.0.fill(None);
ctx.mode.0.fill(InterPredMode::NEARESTMV as u8);
ctx.mode.0.fill(InterPredMode::Nearest as u8);
}
ctx.lcoef.0.fill(0x40);
for ccoef in &mut ctx.ccoef.0 {
Expand Down
43 changes: 21 additions & 22 deletions src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -189,14 +189,6 @@ pub enum MVJoint {
HV = 3,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum InterPredMode {
NEARESTMV = 0,
NEARMV = 1,
GLOBALMV = 2,
NEWMV = 3,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord)]
pub enum DrlProximity {
Nearest,
Expand All @@ -205,26 +197,33 @@ pub enum DrlProximity {
Nearish,
}

pub const N_COMP_INTER_PRED_MODES: usize = 8;
#[derive(Debug, Clone, Copy, PartialEq, Eq, FromRepr)]
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum InterPredMode {
Nearest = 0,
Near = 1,
Global = 2,
New = 3,
}

#[derive(Debug, Clone, Copy, PartialEq, Eq, FromRepr, EnumCount)]
pub enum CompInterPredMode {
NEARESTMV_NEARESTMV = 0,
NEARMV_NEARMV = 1,
NEARESTMV_NEWMV = 2,
NEWMV_NEARESTMV = 3,
NEARMV_NEWMV = 4,
NEWMV_NEARMV = 5,
GLOBALMV_GLOBALMV = 6,
NEWMV_NEWMV = 7,
NearestNearest = 0,
NearNear = 1,
NearestNew = 2,
NewNearest = 3,
NearNew = 4,
NewNear = 5,
GlobalGlobal = 6,
NewNew = 7,
}

impl From<InterPredMode> for CompInterPredMode {
fn from(value: InterPredMode) -> Self {
match value {
InterPredMode::NEARESTMV => CompInterPredMode::NEARESTMV_NEARESTMV,
InterPredMode::NEARMV => CompInterPredMode::NEARMV_NEARMV,
InterPredMode::GLOBALMV => CompInterPredMode::NEARESTMV_NEWMV,
InterPredMode::NEWMV => CompInterPredMode::NEWMV_NEARESTMV,
InterPredMode::Nearest => CompInterPredMode::NearestNearest,
InterPredMode::Near => CompInterPredMode::NearNear,
InterPredMode::Global => CompInterPredMode::NearestNew,
InterPredMode::New => CompInterPredMode::NewNearest,
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/recon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3342,7 +3342,7 @@ pub(crate) unsafe fn rav1d_recon_b_inter<BD: BitDepth>(
.as_ptr()
.offset(i as isize) as isize,
) as *const Rav1dThreadPicture;
if b.c2rust_unnamed.c2rust_unnamed_0.inter_mode == CompInterPredMode::GLOBALMV_GLOBALMV
if b.c2rust_unnamed.c2rust_unnamed_0.inter_mode == CompInterPredMode::GlobalGlobal
&& f.gmv_warp_allowed[b.c2rust_unnamed.c2rust_unnamed_0.r#ref[i as usize] as usize]
as c_int
!= 0
Expand Down Expand Up @@ -3512,7 +3512,7 @@ pub(crate) unsafe fn rav1d_recon_b_inter<BD: BitDepth>(
)
as *const Rav1dThreadPicture;
if b.c2rust_unnamed.c2rust_unnamed_0.inter_mode
== CompInterPredMode::GLOBALMV_GLOBALMV
== CompInterPredMode::GlobalGlobal
&& cmp::min(cbw4, cbh4) > 1
&& f.gmv_warp_allowed
[b.c2rust_unnamed.c2rust_unnamed_0.r#ref[i as usize] as usize]
Expand Down Expand Up @@ -3628,7 +3628,7 @@ pub(crate) unsafe fn rav1d_recon_b_inter<BD: BitDepth>(
as *const Rav1dThreadPicture;
let filter_2d: Filter2d = b.c2rust_unnamed.c2rust_unnamed_0.filter2d as Filter2d;
if cmp::min(bw4, bh4) > 1
&& (b.c2rust_unnamed.c2rust_unnamed_0.inter_mode == InterPredMode::GLOBALMV.into()
&& (b.c2rust_unnamed.c2rust_unnamed_0.inter_mode == InterPredMode::Global.into()
&& f.gmv_warp_allowed[b.c2rust_unnamed.c2rust_unnamed_0.r#ref[0] as usize] as c_int
!= 0
|| b.c2rust_unnamed.c2rust_unnamed_0.motion_mode == MotionMode::Warp
Expand Down Expand Up @@ -4015,7 +4015,7 @@ pub(crate) unsafe fn rav1d_recon_b_inter<BD: BitDepth>(
} else {
if cmp::min(cbw4, cbh4) > 1
&& (b.c2rust_unnamed.c2rust_unnamed_0.inter_mode
== InterPredMode::GLOBALMV.into()
== InterPredMode::Global.into()
&& f.gmv_warp_allowed[b.c2rust_unnamed.c2rust_unnamed_0.r#ref[0] as usize]
as c_int
!= 0
Expand Down
21 changes: 10 additions & 11 deletions src/tables.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ use crate::src::levels::H_ADST;
use crate::src::levels::H_DCT;
use crate::src::levels::H_FLIPADST;
use crate::src::levels::IDTX;
use crate::src::levels::N_COMP_INTER_PRED_MODES;
use crate::src::levels::N_INTRA_PRED_MODES;
use crate::src::levels::N_RECT_TX_SIZES;
use crate::src::levels::N_TX_TYPES_PLUS_LL;
Expand Down Expand Up @@ -468,19 +467,19 @@ pub static dav1d_txtp_from_uvmode: [TxfmType; N_UV_INTRA_PRED_MODES] = {
tbl
};

pub static dav1d_comp_inter_pred_modes: [[InterPredMode; 2]; N_COMP_INTER_PRED_MODES] = {
pub static dav1d_comp_inter_pred_modes: [[InterPredMode; 2]; CompInterPredMode::COUNT] = {
use CompInterPredMode::*;
use InterPredMode::*;

let mut tbl = [[InterPredMode::NEARESTMV; 2]; 8];
tbl[NEARESTMV_NEARESTMV as usize] = [NEARESTMV, NEARESTMV];
tbl[NEARMV_NEARMV as usize] = [NEARMV, NEARMV];
tbl[NEWMV_NEWMV as usize] = [NEWMV, NEWMV];
tbl[GLOBALMV_GLOBALMV as usize] = [GLOBALMV, GLOBALMV];
tbl[NEWMV_NEARESTMV as usize] = [NEWMV, NEARESTMV];
tbl[NEWMV_NEARMV as usize] = [NEWMV, NEARMV];
tbl[NEARESTMV_NEWMV as usize] = [NEARESTMV, NEWMV];
tbl[NEARMV_NEWMV as usize] = [NEARMV, NEWMV];
let mut tbl = [[InterPredMode::Nearest; 2]; 8];
tbl[NearestNearest as usize] = [Nearest, Nearest];
tbl[NearNear as usize] = [Near, Near];
tbl[NewNew as usize] = [New, New];
tbl[GlobalGlobal as usize] = [Global, Global];
tbl[NewNearest as usize] = [New, Nearest];
tbl[NewNear as usize] = [New, Near];
tbl[NearestNew as usize] = [Nearest, New];
tbl[NearNew as usize] = [Near, New];

tbl
};
Expand Down

0 comments on commit 5711bfe

Please sign in to comment.