Skip to content

Commit

Permalink
enum InterIntraType: make a real enum
Browse files Browse the repository at this point in the history
  • Loading branch information
folkertdev committed Mar 18, 2024
1 parent f5bee55 commit 378e27a
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 57 deletions.
30 changes: 17 additions & 13 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ use crate::src::levels::BS_64x64;
use crate::src::levels::BlockLevel;
use crate::src::levels::BlockPartition;
use crate::src::levels::BlockSize;
use crate::src::levels::InterIntraType;
use crate::src::levels::MotionMode;
use crate::src::levels::RectTxfmSize;
use crate::src::levels::TxfmSize;
Expand All @@ -96,9 +97,6 @@ use crate::src::levels::FILTER_2D_BILINEAR;
use crate::src::levels::FILTER_PRED;
use crate::src::levels::GLOBALMV;
use crate::src::levels::GLOBALMV_GLOBALMV;
use crate::src::levels::INTER_INTRA_BLEND;
use crate::src::levels::INTER_INTRA_NONE;
use crate::src::levels::INTER_INTRA_WEDGE;
use crate::src::levels::MM_OBMC;
use crate::src::levels::MM_TRANSLATION;
use crate::src::levels::MM_WARP;
Expand Down Expand Up @@ -1163,7 +1161,10 @@ unsafe fn splat_oneref_mv(
r#ref: refmvs_refpair {
r#ref: [
b.r#ref()[0] + 1,
if b.interintra_type() != 0 { 0 } else { -1 },
match b.interintra_type() {
InterIntraType::None => -1,
_ => 0,
},
],
},
bs: bs as u8,
Expand Down Expand Up @@ -2970,27 +2971,30 @@ unsafe fn decode_b_inner(
N_INTER_INTRA_PRED_MODES as usize - 1,
) as u8;
let wedge_ctx = dav1d_wedge_ctx_lut[bs as usize] as c_int;
*b.interintra_type_mut() = INTER_INTRA_BLEND
+ rav1d_msac_decode_bool_adapt(
&mut ts.msac,
&mut ts.cdf.m.interintra_wedge[wedge_ctx as usize],
) as u8;
if b.interintra_type() == INTER_INTRA_WEDGE {
*b.interintra_type_mut() = if rav1d_msac_decode_bool_adapt(
&mut ts.msac,
&mut ts.cdf.m.interintra_wedge[wedge_ctx as usize],
) {
InterIntraType::Wedge
} else {
InterIntraType::Blend
};
if b.interintra_type() == InterIntraType::Wedge {
*b.wedge_idx_mut() = rav1d_msac_decode_symbol_adapt16(
&mut ts.msac,
&mut ts.cdf.m.wedge_idx[wedge_ctx as usize],
15,
) as u8;
}
} else {
*b.interintra_type_mut() = INTER_INTRA_NONE;
*b.interintra_type_mut() = InterIntraType::None;
}
if debug_block_info!(f, t)
&& seq_hdr.inter_intra != 0
&& interintra_allowed_mask & (1 << bs) != 0
{
println!(
"Post-interintra[t={},m={},w={}]: r={}",
"Post-interintra[t={:?},m={},w={}]: r={}",
b.interintra_type(),
b.interintra_mode(),
b.wedge_idx(),
Expand All @@ -3000,7 +3004,7 @@ unsafe fn decode_b_inner(

// motion variation
if frame_hdr.switchable_motion_mode != 0
&& b.interintra_type() == INTER_INTRA_NONE
&& b.interintra_type() == InterIntraType::None
&& cmp::min(bw4, bh4) >= 2
// is not warped global motion
&& !(!frame_hdr.force_integer_mv
Expand Down
16 changes: 9 additions & 7 deletions src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,12 @@ pub const COMP_INTER_AVG: CompInterType = 2;
pub const COMP_INTER_WEIGHTED_AVG: CompInterType = 1;
pub const COMP_INTER_NONE: CompInterType = 0;

pub type InterIntraType = u8;
pub const INTER_INTRA_WEDGE: InterIntraType = 2;
pub const INTER_INTRA_BLEND: InterIntraType = 1;
pub const INTER_INTRA_NONE: InterIntraType = 0;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum InterIntraType {
None = 0,
Blend = 1,
Wedge = 2,
}

/// Note that this is legitimately [`Copy`]
/// (unlike other transpiled types that are [`Copy`] due to being from C).
Expand Down Expand Up @@ -308,7 +310,7 @@ pub struct Av1Block_inter {
pub r#ref: [i8; 2],
pub max_ytx: u8,
pub filter2d: u8,
pub interintra_type: u8,
pub interintra_type: InterIntraType,
pub tx_split0: u8,
pub tx_split1: u16,
}
Expand Down Expand Up @@ -526,11 +528,11 @@ impl Av1Block {
&mut self.c2rust_unnamed.c2rust_unnamed_0.max_ytx
}

pub unsafe fn interintra_type(&self) -> u8 {
pub unsafe fn interintra_type(&self) -> InterIntraType {
self.c2rust_unnamed.c2rust_unnamed_0.interintra_type
}

pub unsafe fn interintra_type_mut(&mut self) -> &mut u8 {
pub unsafe fn interintra_type_mut(&mut self) -> &mut InterIntraType {
&mut self.c2rust_unnamed.c2rust_unnamed_0.interintra_type
}

Expand Down
78 changes: 41 additions & 37 deletions src/recon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ use crate::src::levels::mv;
use crate::src::levels::Av1Block;
use crate::src::levels::BlockSize;
use crate::src::levels::Filter2d;
use crate::src::levels::InterIntraType;
use crate::src::levels::IntraPredMode;
use crate::src::levels::RectTxfmSize;
use crate::src::levels::TxClass;
Expand All @@ -43,7 +44,6 @@ use crate::src::levels::GLOBALMV;
use crate::src::levels::GLOBALMV_GLOBALMV;
use crate::src::levels::IDTX;
use crate::src::levels::II_SMOOTH_PRED;
use crate::src::levels::INTER_INTRA_BLEND;
use crate::src::levels::MM_OBMC;
use crate::src::levels::MM_WARP;
use crate::src::levels::RTX_16X32;
Expand Down Expand Up @@ -3439,7 +3439,7 @@ pub(crate) unsafe fn rav1d_recon_b_inter<BD: BitDepth>(
}
}
}
if b.c2rust_unnamed.c2rust_unnamed_0.interintra_type != 0 {
if b.c2rust_unnamed.c2rust_unnamed_0.interintra_type != InterIntraType::None {
let interintra_edge = BD::select_mut(&mut t.scratch.c2rust_unnamed_0.interintra_edge);
let tl_edge_array = &mut interintra_edge.0.edge;
let tl_edge_offset = 32;
Expand Down Expand Up @@ -3510,22 +3510,25 @@ pub(crate) unsafe fn rav1d_recon_b_inter<BD: BitDepth>(
0 as c_int,
BD::from_c(f.bitdepth_max),
);
let ii_mask = if b.c2rust_unnamed.c2rust_unnamed_0.interintra_type as c_int
== INTER_INTRA_BLEND as c_int
{
dav1d_ii_masks[bs as usize][0][b
.c2rust_unnamed
.c2rust_unnamed_0
.c2rust_unnamed
.c2rust_unnamed
.interintra_mode as usize]
} else {
dav1d_wedge_masks[bs as usize][0][0][b
.c2rust_unnamed
.c2rust_unnamed_0
.c2rust_unnamed
.c2rust_unnamed
.wedge_idx as usize]
let ii_mask = match b.c2rust_unnamed.c2rust_unnamed_0.interintra_type {
InterIntraType::Blend => {
dav1d_ii_masks[bs as usize][0][b
.c2rust_unnamed
.c2rust_unnamed_0
.c2rust_unnamed
.c2rust_unnamed
.interintra_mode
as usize]
}
_ => {
dav1d_wedge_masks[bs as usize][0][0][b
.c2rust_unnamed
.c2rust_unnamed_0
.c2rust_unnamed
.c2rust_unnamed
.wedge_idx
as usize]
}
};
((*dsp).mc.blend)(
dst.cast(),
Expand Down Expand Up @@ -3839,25 +3842,26 @@ pub(crate) unsafe fn rav1d_recon_b_inter<BD: BitDepth>(
pl += 1;
}
}
if b.c2rust_unnamed.c2rust_unnamed_0.interintra_type != 0 {
let ii_mask = if b.c2rust_unnamed.c2rust_unnamed_0.interintra_type as c_int
== INTER_INTRA_BLEND as c_int
{
dav1d_ii_masks[bs as usize][chr_layout_idx as usize][b
.c2rust_unnamed
.c2rust_unnamed_0
.c2rust_unnamed
.c2rust_unnamed
.interintra_mode
as usize]
} else {
dav1d_wedge_masks[bs as usize][chr_layout_idx as usize][0][b
.c2rust_unnamed
.c2rust_unnamed_0
.c2rust_unnamed
.c2rust_unnamed
.wedge_idx
as usize]
if b.c2rust_unnamed.c2rust_unnamed_0.interintra_type != InterIntraType::None {
let ii_mask = match b.c2rust_unnamed.c2rust_unnamed_0.interintra_type {
InterIntraType::Blend => {
dav1d_ii_masks[bs as usize][chr_layout_idx as usize][b
.c2rust_unnamed
.c2rust_unnamed_0
.c2rust_unnamed
.c2rust_unnamed
.interintra_mode
as usize]
}
_ => {
dav1d_wedge_masks[bs as usize][chr_layout_idx as usize][0][b
.c2rust_unnamed
.c2rust_unnamed_0
.c2rust_unnamed
.c2rust_unnamed
.wedge_idx
as usize]
}
};
let mut pl = 0;
while pl < 2 {
Expand Down

0 comments on commit 378e27a

Please sign in to comment.