Skip to content

Commit

Permalink
Rav1dFrameContext_lf::p: Make into offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
randomPoison committed Mar 12, 2024
1 parent f65d252 commit f0bee52
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 19 deletions.
11 changes: 5 additions & 6 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4603,13 +4603,12 @@ pub(crate) unsafe fn rav1d_decode_frame_init(
}
}

// Init loopfilter pointers. Increasing NULL pointers is technically UB,
// so just point the chroma pointers in 4:0:0 to the luma plane here
// to avoid having additional in-loop branches in various places.
// We never dereference those pointers, so it doesn't really matter
// what they point at, as long as the pointers are valid.
// Init loopfilter offsets. Point the chroma offsets in 4:0:0 to the luma
// plane here to avoid having additional in-loop branches in various places.
// We never use those values, so it doesn't really matter what they point
// at, as long as the offsets are valid.
let has_chroma = (f.cur.p.layout != Rav1dPixelLayout::I400) as usize;
f.lf.p = array::from_fn(|i| f.cur.data.data[has_chroma * i].cast());
f.lf.p = array::from_fn(|i| has_chroma * i);
f.lf.sr_p = array::from_fn(|i| f.sr_cur.p.data.data[has_chroma * i].cast());

Ok(())
Expand Down
2 changes: 1 addition & 1 deletion src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ pub struct Rav1dFrameContext_lf {

// in-loop filter per-frame state keeping
pub start_of_tile_row: Vec<u8>,
pub p: [*mut DynPixel; 3],
pub p: [usize; 3], // Offsets into `f.cur.data.data`.
pub sr_p: [*mut DynPixel; 3],
pub restore_planes: c_int, // enum LrRestorePlanes
}
Expand Down
46 changes: 34 additions & 12 deletions src/recon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4510,15 +4510,21 @@ pub(crate) unsafe fn rav1d_filter_sbrow_deblock_cols<BD: BitDepth>(

let p: [&mut [BD::Pixel]; 3] = [
slice::from_raw_parts_mut(
(f.lf.p[0] as *mut BD::Pixel).offset(cmp::min(y_span, 0)),
f.cur.data.data[f.lf.p[0]]
.cast::<BD::Pixel>()
.offset(cmp::min(y_span, 0)),
y_span.unsigned_abs() + y_width as usize + RAV1D_PICTURE_ALIGNMENT,
),
slice::from_raw_parts_mut(
(f.lf.p[1] as *mut BD::Pixel).offset(cmp::min(uv_span, 0)),
f.cur.data.data[f.lf.p[1]]
.cast::<BD::Pixel>()
.offset(cmp::min(uv_span, 0)),
uv_span.unsigned_abs() + uv_width as usize + RAV1D_PICTURE_ALIGNMENT,
),
slice::from_raw_parts_mut(
(f.lf.p[2] as *mut BD::Pixel).offset(cmp::min(uv_span, 0)),
f.cur.data.data[f.lf.p[2]]
.cast::<BD::Pixel>()
.offset(cmp::min(uv_span, 0)),
uv_span.unsigned_abs() + uv_width as usize + RAV1D_PICTURE_ALIGNMENT,
),
];
Expand Down Expand Up @@ -4562,15 +4568,21 @@ pub(crate) unsafe fn rav1d_filter_sbrow_deblock_rows<BD: BitDepth>(

let p: [&mut [BD::Pixel]; 3] = [
slice::from_raw_parts_mut(
(f.lf.p[0] as *mut BD::Pixel).offset(cmp::min(y_span, 0)),
f.cur.data.data[f.lf.p[0]]
.cast::<BD::Pixel>()
.offset(cmp::min(y_span, 0)),
y_span.unsigned_abs() + y_width as usize + RAV1D_PICTURE_ALIGNMENT,
),
slice::from_raw_parts_mut(
(f.lf.p[1] as *mut BD::Pixel).offset(cmp::min(uv_span, 0)),
f.cur.data.data[f.lf.p[1]]
.cast::<BD::Pixel>()
.offset(cmp::min(uv_span, 0)),
uv_span.unsigned_abs() + uv_width as usize + RAV1D_PICTURE_ALIGNMENT,
),
slice::from_raw_parts_mut(
(f.lf.p[2] as *mut BD::Pixel).offset(cmp::min(uv_span, 0)),
f.cur.data.data[f.lf.p[2]]
.cast::<BD::Pixel>()
.offset(cmp::min(uv_span, 0)),
uv_span.unsigned_abs() + uv_width as usize + RAV1D_PICTURE_ALIGNMENT,
),
];
Expand Down Expand Up @@ -4608,10 +4620,14 @@ pub(crate) unsafe fn rav1d_filter_sbrow_cdef<BD: BitDepth>(
let y = sby * sbsz * 4;
let ss_ver = (f.cur.p.layout as c_uint == Rav1dPixelLayout::I420 as c_int as c_uint) as c_int;
let p: [*mut BD::Pixel; 3] = [
(f.lf.p[0] as *mut BD::Pixel).offset((y as isize * BD::pxstride(f.cur.stride[0])) as isize),
(f.lf.p[1] as *mut BD::Pixel)
f.cur.data.data[f.lf.p[0]]
.cast::<BD::Pixel>()
.offset((y as isize * BD::pxstride(f.cur.stride[0])) as isize),
f.cur.data.data[f.lf.p[1]]
.cast::<BD::Pixel>()
.offset((y as isize * BD::pxstride(f.cur.stride[1]) >> ss_ver) as isize),
(f.lf.p[2] as *mut BD::Pixel)
f.cur.data.data[f.lf.p[2]]
.cast::<BD::Pixel>()
.offset((y as isize * BD::pxstride(f.cur.stride[1]) >> ss_ver) as isize),
];
let seq_hdr = &***f.seq_hdr.as_ref().unwrap();
Expand Down Expand Up @@ -4644,9 +4660,15 @@ pub(crate) unsafe fn rav1d_filter_sbrow_resize<BD: BitDepth>(
let y = sby * sbsz * 4;
let ss_ver = (f.cur.p.layout as c_uint == Rav1dPixelLayout::I420 as c_int as c_uint) as c_int;
let p: [*const BD::Pixel; 3] = [
(f.lf.p[0] as *mut BD::Pixel).offset(y as isize * BD::pxstride(f.cur.stride[0])),
(f.lf.p[1] as *mut BD::Pixel).offset(y as isize * BD::pxstride(f.cur.stride[1]) >> ss_ver),
(f.lf.p[2] as *mut BD::Pixel).offset(y as isize * BD::pxstride(f.cur.stride[1]) >> ss_ver),
f.cur.data.data[f.lf.p[0]]
.cast::<BD::Pixel>()
.offset(y as isize * BD::pxstride(f.cur.stride[0])),
f.cur.data.data[f.lf.p[1]]
.cast::<BD::Pixel>()
.offset(y as isize * BD::pxstride(f.cur.stride[1]) >> ss_ver),
f.cur.data.data[f.lf.p[2]]
.cast::<BD::Pixel>()
.offset(y as isize * BD::pxstride(f.cur.stride[1]) >> ss_ver),
];
let sr_p: [*mut BD::Pixel; 3] = [
(f.lf.sr_p[0] as *mut BD::Pixel)
Expand Down

0 comments on commit f0bee52

Please sign in to comment.