Skip to content

Commit

Permalink
mod obu: Cleanup part 1 (#590)
Browse files Browse the repository at this point in the history
Main cleanups so far:
* Make args refs.
* Make some vars refs.
* Remove redundant `as` casts.
* Remove redundant type annotations.
* Remove `.wrapping_*` calls.
* Translate `for` loops.
* Use indexing for arrays.
* Add back comments.
  • Loading branch information
kkysen authored Dec 2, 2023
2 parents 41d2302 + 6c6bce2 commit 3bc2e0b
Show file tree
Hide file tree
Showing 8 changed files with 1,374 additions and 1,520 deletions.
24 changes: 12 additions & 12 deletions include/dav1d/headers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ pub const RAV1D_WM_TYPE_IDENTITY: Rav1dWarpedMotionType = DAV1D_WM_TYPE_IDENTITY
#[derive(Clone)]
#[repr(C)]
pub struct Dav1dWarpedMotionParams {
pub type_0: Dav1dWarpedMotionType,
pub r#type: Dav1dWarpedMotionType,
pub matrix: [i32; 6],
pub abcd: [i16; 4],
}
Expand All @@ -139,7 +139,7 @@ impl Dav1dWarpedMotionParams {
#[derive(Clone)]
#[repr(C)]
pub(crate) struct Rav1dWarpedMotionParams {
pub type_0: Rav1dWarpedMotionType,
pub r#type: Rav1dWarpedMotionType,
pub matrix: [i32; 6],
pub abcd: [i16; 4],
}
Expand Down Expand Up @@ -169,12 +169,12 @@ impl Rav1dWarpedMotionParams {
impl From<Dav1dWarpedMotionParams> for Rav1dWarpedMotionParams {
fn from(value: Dav1dWarpedMotionParams) -> Self {
let Dav1dWarpedMotionParams {
type_0,
r#type,
matrix,
abcd,
} = value;
Self {
type_0,
r#type,
matrix,
abcd,
}
Expand All @@ -184,12 +184,12 @@ impl From<Dav1dWarpedMotionParams> for Rav1dWarpedMotionParams {
impl From<Rav1dWarpedMotionParams> for Dav1dWarpedMotionParams {
fn from(value: Rav1dWarpedMotionParams) -> Self {
let Rav1dWarpedMotionParams {
type_0,
r#type,
matrix,
abcd,
} = value;
Self {
type_0,
r#type,
matrix,
abcd,
}
Expand Down Expand Up @@ -1902,28 +1902,28 @@ impl From<Rav1dFrameHeader_cdef> for Dav1dFrameHeader_cdef {
#[derive(Clone)]
#[repr(C)]
pub struct Dav1dFrameHeader_restoration {
pub type_0: [Dav1dRestorationType; 3],
pub r#type: [Dav1dRestorationType; 3],
pub unit_size: [c_int; 2],
}

#[derive(Clone)]
#[repr(C)]
pub(crate) struct Rav1dFrameHeader_restoration {
pub type_0: [Rav1dRestorationType; 3],
pub r#type: [Rav1dRestorationType; 3],
pub unit_size: [c_int; 2],
}

impl From<Dav1dFrameHeader_restoration> for Rav1dFrameHeader_restoration {
fn from(value: Dav1dFrameHeader_restoration) -> Self {
let Dav1dFrameHeader_restoration { type_0, unit_size } = value;
Self { type_0, unit_size }
let Dav1dFrameHeader_restoration { r#type, unit_size } = value;
Self { r#type, unit_size }
}
}

impl From<Rav1dFrameHeader_restoration> for Dav1dFrameHeader_restoration {
fn from(value: Rav1dFrameHeader_restoration) -> Self {
let Rav1dFrameHeader_restoration { type_0, unit_size } = value;
Self { type_0, unit_size }
let Rav1dFrameHeader_restoration { r#type, unit_size } = value;
Self { r#type, unit_size }
}
}

Expand Down
24 changes: 12 additions & 12 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -676,7 +676,7 @@ unsafe fn derive_warpmv(
}
}

wmp.type_0 = if !rav1d_find_affine_int(&pts, ret, bw4, bh4, mv, &mut wmp, t.bx, t.by)
wmp.r#type = if !rav1d_find_affine_int(&pts, ret, bw4, bh4, mv, &mut wmp, t.bx, t.by)
&& !rav1d_get_shear_params(&mut wmp)
{
RAV1D_WM_TYPE_AFFINE
Expand Down Expand Up @@ -1546,9 +1546,9 @@ unsafe fn decode_b(
&& b.motion_mode() as MotionMode == MM_WARP
{
if b.matrix()[0] == i16::MIN {
t.warpmv.type_0 = RAV1D_WM_TYPE_IDENTITY;
t.warpmv.r#type = RAV1D_WM_TYPE_IDENTITY;
} else {
t.warpmv.type_0 = RAV1D_WM_TYPE_AFFINE;
t.warpmv.r#type = RAV1D_WM_TYPE_AFFINE;
t.warpmv.matrix[2] = b.matrix()[0] as i32 + 0x10000;
t.warpmv.matrix[3] = b.matrix()[1] as i32;
t.warpmv.matrix[4] = b.matrix()[2] as i32;
Expand Down Expand Up @@ -2646,7 +2646,7 @@ unsafe fn decode_b(
}
GLOBALMV => {
has_subpel_filter |=
frame_hdr.gmv[b.r#ref()[idx] as usize].type_0 == RAV1D_WM_TYPE_TRANSLATION;
frame_hdr.gmv[b.r#ref()[idx] as usize].r#type == RAV1D_WM_TYPE_TRANSLATION;
b.mv_mut()[idx] = get_gmv_2d(
&frame_hdr.gmv[b.r#ref()[idx] as usize],
t.bx,
Expand Down Expand Up @@ -2852,7 +2852,7 @@ unsafe fn decode_b(
frame_hdr,
);
has_subpel_filter = cmp::min(bw4, bh4) == 1
|| frame_hdr.gmv[b.r#ref()[0] as usize].type_0 == RAV1D_WM_TYPE_TRANSLATION;
|| frame_hdr.gmv[b.r#ref()[0] as usize].r#type == RAV1D_WM_TYPE_TRANSLATION;
} else {
has_subpel_filter = true;
if rav1d_msac_decode_bool_adapt(
Expand Down Expand Up @@ -3006,7 +3006,7 @@ unsafe fn decode_b(
// is not warped global motion
&& !(frame_hdr.force_integer_mv == 0
&& b.inter_mode() == GLOBALMV
&& frame_hdr.gmv[b.r#ref()[0] as usize].type_0 > RAV1D_WM_TYPE_TRANSLATION)
&& frame_hdr.gmv[b.r#ref()[0] as usize].r#type > RAV1D_WM_TYPE_TRANSLATION)
// has overlappable neighbours
&& (have_left && findoddzero(&t.l.intra.0[by4 as usize..][..h4 as usize])
|| have_top && findoddzero(&(*t.a).intra.0[bx4 as usize..][..w4 as usize]))
Expand Down Expand Up @@ -3063,7 +3063,7 @@ unsafe fn decode_b(
);
}
if t.frame_thread.pass != 0 {
if t.warpmv.type_0 == RAV1D_WM_TYPE_AFFINE {
if t.warpmv.r#type == RAV1D_WM_TYPE_AFFINE {
b.matrix_mut()[0] = (t.warpmv.matrix[2] - 0x10000) as i16;
b.matrix_mut()[1] = t.warpmv.matrix[3] as i16;
b.matrix_mut()[2] = t.warpmv.matrix[4] as i16;
Expand Down Expand Up @@ -3273,7 +3273,7 @@ unsafe fn decode_b(
if cmp::min(bw4, bh4) > 1
&& (b.inter_mode() == GLOBALMV && f.gmv_warp_allowed[b.r#ref()[0] as usize] != 0
|| b.motion_mode() == MM_WARP as u8
&& t.warpmv.type_0 > RAV1D_WM_TYPE_TRANSLATION)
&& t.warpmv.r#type > RAV1D_WM_TYPE_TRANSLATION)
{
affine_lowest_px_luma(
t,
Expand Down Expand Up @@ -3371,7 +3371,7 @@ unsafe fn decode_b(
&& (b.inter_mode() == GLOBALMV
&& f.gmv_warp_allowed[b.r#ref()[0] as usize] != 0
|| b.motion_mode() == MM_WARP as u8
&& t.warpmv.type_0 > RAV1D_WM_TYPE_TRANSLATION)
&& t.warpmv.r#type > RAV1D_WM_TYPE_TRANSLATION)
{
affine_lowest_px_chroma(
t,
Expand Down Expand Up @@ -4155,7 +4155,7 @@ pub(crate) unsafe fn rav1d_decode_tile_sbrow(t: &mut Rav1dTaskContext) -> Result
continue;
}

let frame_type = (*f.frame_hdr).restoration.type_0[p as usize];
let frame_type = (*f.frame_hdr).restoration.r#type[p as usize];

if (*f.frame_hdr).width[0] != (*f.frame_hdr).width[1] {
let w = f.sr_cur.p.p.w + ss_hor >> ss_hor;
Expand Down Expand Up @@ -4561,7 +4561,7 @@ pub(crate) unsafe fn rav1d_decode_frame_init(f: &mut Rav1dFrameContext) -> Rav1d
}
f.lf.restore_planes = (*f.frame_hdr)
.restoration
.type_0
.r#type
.iter()
.enumerate()
.map(|(i, &r#type)| ((r#type != RAV1D_RESTORATION_NONE) as u8) << i)
Expand Down Expand Up @@ -5135,7 +5135,7 @@ pub unsafe fn rav1d_submit_frame(c: &mut Rav1dContext) -> Rav1dResult {
f.svc[i][1].scale = 0;
f.svc[i][0].scale = f.svc[i][1].scale;
}
f.gmv_warp_allowed[i] = ((*f.frame_hdr).gmv[i].type_0 > RAV1D_WM_TYPE_TRANSLATION
f.gmv_warp_allowed[i] = ((*f.frame_hdr).gmv[i].r#type > RAV1D_WM_TYPE_TRANSLATION
&& (*f.frame_hdr).force_integer_mv == 0
&& !rav1d_get_shear_params(&mut (*f.frame_hdr).gmv[i])
&& f.svc[i][0].scale == 0) as u8;
Expand Down
2 changes: 1 addition & 1 deletion src/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ pub(crate) fn get_gmv_2d(
bh4: c_int,
hdr: &Rav1dFrameHeader,
) -> mv {
match gmv.type_0 {
match gmv.r#type {
2 => {
assert!(gmv.matrix[5] == gmv.matrix[2]);
assert!(gmv.matrix[4] == -gmv.matrix[3]);
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,7 +544,7 @@ pub(crate) unsafe fn rav1d_parse_sequence_header(
}

while buf.sz > 0 {
let res = rav1d_parse_obus(c, &mut buf, 1 as c_int);
let res = rav1d_parse_obus(&mut *c, &mut buf, 1 as c_int);
let res = match res {
Ok(res) => res,
Err(res) => return rav1d_parse_sequence_header_error(Err(res), c, &mut buf),
Expand Down Expand Up @@ -737,7 +737,7 @@ unsafe fn gen_picture(c: *mut Rav1dContext) -> Rav1dResult {
return Ok(());
}
while (*in_0).sz > 0 {
res = rav1d_parse_obus(c, in_0, 0 as c_int);
res = rav1d_parse_obus(&mut *c, &mut *in_0, 0 as c_int);
match res {
Err(_) => rav1d_data_unref_internal(in_0),
Ok(res) => {
Expand Down
Loading

0 comments on commit 3bc2e0b

Please sign in to comment.