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

enum InterIntraType: make a real enum #832

Merged
merged 3 commits into from
Mar 19, 2024
Merged
Show file tree
Hide file tree
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
28 changes: 15 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,7 @@ unsafe fn splat_oneref_mv(
r#ref: refmvs_refpair {
r#ref: [
b.r#ref()[0] + 1,
if b.interintra_type() != 0 { 0 } else { -1 },
b.interintra_type().map(|_| 0).unwrap_or(-1),
],
},
bs: bs as u8,
Expand Down Expand Up @@ -2970,27 +2968,31 @@ 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 {
let ii_type = if rav1d_msac_decode_bool_adapt(
&mut ts.msac,
&mut ts.cdf.m.interintra_wedge[wedge_ctx as usize],
) {
InterIntraType::Wedge
} else {
InterIntraType::Blend
};
*b.interintra_type_mut() = Some(ii_type);
if ii_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() = 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 +3002,7 @@ unsafe fn decode_b_inner(

// motion variation
if frame_hdr.switchable_motion_mode != 0
&& b.interintra_type() == INTER_INTRA_NONE
&& b.interintra_type() == None
&& cmp::min(bw4, bh4) >= 2
// is not warped global motion
&& !(!frame_hdr.force_integer_mv
Expand Down
15 changes: 8 additions & 7 deletions src/levels.rs
Original file line number Diff line number Diff line change
Expand Up @@ -209,10 +209,11 @@ 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 {
Blend,
Wedge,
}

/// Note that this is legitimately [`Copy`]
/// (unlike other transpiled types that are [`Copy`] due to being from C).
Expand Down Expand Up @@ -308,7 +309,7 @@ pub struct Av1Block_inter {
pub r#ref: [i8; 2],
pub max_ytx: u8,
pub filter2d: u8,
pub interintra_type: u8,
pub interintra_type: Option<InterIntraType>,
pub tx_split0: u8,
pub tx_split1: u16,
}
Expand Down Expand Up @@ -526,11 +527,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) -> Option<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 Option<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 let Some(interintra_type) = b.c2rust_unnamed.c2rust_unnamed_0.interintra_type {
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 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]
}
InterIntraType::Wedge => {
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 let Some(interintra_type) = b.c2rust_unnamed.c2rust_unnamed_0.interintra_type {
let ii_mask = match 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]
}
InterIntraType::Wedge => {
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
Loading