Skip to content

Commit

Permalink
Rav1dFrameContext_lf::cdef_lpf_line: Make ptrs into offsets
Browse files Browse the repository at this point in the history
  • Loading branch information
randomPoison committed Mar 1, 2024
1 parent 73689be commit 7e4c4a0
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 25 deletions.
20 changes: 14 additions & 6 deletions src/cdef_apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,10 @@ pub(crate) unsafe fn rav1d_cdef_brow<BD: BitDepth>(
} else if sbrow_start && by == by_start {
if resize {
offset = ((sby - 1) * 4) as isize * y_stride + (bx * 4) as isize;
top = f.lf.cdef_lpf_line[0].cast::<BD::Pixel>().offset(offset);
top = cdef_line_buf
.as_mut_ptr()
.add(f.lf.cdef_lpf_line[0])
.offset(offset);
} else {
offset = (sby * ((4 as c_int) << sb128) - 4) as isize * y_stride
+ (bx * 4) as isize;
Expand All @@ -337,7 +340,10 @@ pub(crate) unsafe fn rav1d_cdef_brow<BD: BitDepth>(
.offset(offset);
if resize {
offset = (sby * 4 + 2) as isize * y_stride + (bx * 4) as isize;
bot = f.lf.cdef_lpf_line[0].cast::<BD::Pixel>().offset(offset);
bot = cdef_line_buf
.as_mut_ptr()
.add(f.lf.cdef_lpf_line[0])
.offset(offset);
} else {
let line = sby * ((4 as c_int) << sb128) + 4 * sb128 + 2;
offset = line as isize * y_stride + (bx * 4) as isize;
Expand Down Expand Up @@ -407,8 +413,9 @@ pub(crate) unsafe fn rav1d_cdef_brow<BD: BitDepth>(
if resize {
offset = ((sby - 1) * 4) as isize * uv_stride
+ (bx * 4 >> ss_hor) as isize;
top = f.lf.cdef_lpf_line[pl]
.cast::<BD::Pixel>()
top = cdef_line_buf
.as_mut_ptr()
.add(f.lf.cdef_lpf_line[pl])
.offset(offset);
} else {
let line_0 = sby * ((4 as c_int) << sb128) - 4;
Expand All @@ -429,8 +436,9 @@ pub(crate) unsafe fn rav1d_cdef_brow<BD: BitDepth>(
if resize {
offset = (sby * 4 + 2) as isize * uv_stride
+ (bx * 4 >> ss_hor) as isize;
bot = f.lf.cdef_lpf_line[pl]
.cast::<BD::Pixel>()
bot = cdef_line_buf
.as_mut_ptr()
.add(f.lf.cdef_lpf_line[pl])
.offset(offset);
} else {
let line_1 = sby * ((4 as c_int) << sb128) + 4 * sb128 + 2;
Expand Down
21 changes: 8 additions & 13 deletions src/decode.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4427,28 +4427,23 @@ pub(crate) unsafe fn rav1d_decode_frame_init(
f.lf.cdef_line[1][2] = offset.wrapping_add_signed(uv_stride_px * 6);
}

let mut ptr =
f.lf.cdef_line_buf
.as_mut_ptr()
.add(32)
.offset(y_stride.abs() * f.sbh as isize * 4);
if need_cdef_lpf_copy != 0 {
ptr = ptr.offset(uv_stride.abs() * f.sbh as isize * 8);
offset = offset.wrapping_add_signed(uv_stride_px.abs() * f.sbh as isize * 8);
if y_stride < 0 {
f.lf.cdef_lpf_line[0] =
ptr.offset(-(y_stride * (f.sbh as isize * 4 - 1))) as *mut DynPixel;
offset.wrapping_add_signed(-(y_stride_px * (f.sbh as isize * 4 - 1)));
} else {
f.lf.cdef_lpf_line[0] = ptr as *mut DynPixel;
f.lf.cdef_lpf_line[0] = offset;
}
ptr = ptr.offset(y_stride.abs() * f.sbh as isize * 4);
offset = offset.wrapping_add_signed(y_stride_px.abs() * f.sbh as isize * 4);
if uv_stride < 0 {
f.lf.cdef_lpf_line[1] =
ptr.offset(-(uv_stride * (f.sbh as isize * 4 - 1))) as *mut DynPixel;
offset.wrapping_add_signed(-(uv_stride_px * (f.sbh as isize * 4 - 1)));
f.lf.cdef_lpf_line[2] =
ptr.offset(-(uv_stride * (f.sbh as isize * 8 - 1))) as *mut DynPixel;
offset.wrapping_add_signed(-(uv_stride_px * (f.sbh as isize * 8 - 1)));
} else {
f.lf.cdef_lpf_line[1] = ptr as *mut DynPixel;
f.lf.cdef_lpf_line[2] = ptr.offset(uv_stride * f.sbh as isize * 4) as *mut DynPixel;
f.lf.cdef_lpf_line[1] = offset;
f.lf.cdef_lpf_line[2] = offset.wrapping_add_signed(uv_stride_px * f.sbh as isize * 4);
}
}

Expand Down
6 changes: 3 additions & 3 deletions src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -435,9 +435,9 @@ pub struct Rav1dFrameContext_lf {
pub tx_lpf_right_edge: Vec<u8>, /* len = h*2 */
pub cdef_line_buf: AlignedVec32<u8>, /* AlignedVec32<DynPixel> */
pub lr_line_buf: *mut u8,
pub cdef_line: [[usize; 3]; 2], /* [2 pre/post][3 plane] */
pub cdef_lpf_line: [*mut DynPixel; 3], /* plane */
pub lr_lpf_line: [*mut DynPixel; 3], /* plane */
pub cdef_line: [[usize; 3]; 2], /* [2 pre/post][3 plane] */
pub cdef_lpf_line: [usize; 3], /* plane */
pub lr_lpf_line: [*mut DynPixel; 3], /* plane */

// in-loop filter per-frame state keeping
pub start_of_tile_row: *mut u8,
Expand Down
24 changes: 21 additions & 3 deletions src/lf_apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use libc::ptrdiff_t;
use std::cmp;
use std::ffi::c_int;
use std::ffi::c_uint;
use std::mem;
use std::slice;

// The loop filter buffer stores 12 rows of pixels. A superblock block will
Expand Down Expand Up @@ -191,6 +192,12 @@ pub(crate) unsafe fn rav1d_copy_lpf<BD: BitDepth>(
.offset(tt_off as isize * BD::pxstride(*lr_stride.offset(1) as usize) as isize),
];
let restore_planes = f.lf.restore_planes;

// Temporarily take ownership of `cdef_line_buf` so that we can mutate while
// still being able to take references to `f`.
let mut cdef_line_buf_tmp = mem::take(&mut f.lf.cdef_line_buf);
let cdef_line_buf = BD::cast_pixel_slice_mut(&mut cdef_line_buf_tmp);

if seq_hdr.cdef != 0 || restore_planes & LR_RESTORE_Y as c_int != 0 {
let h = f.cur.p.h;
let w = f.bw << 2;
Expand Down Expand Up @@ -222,7 +229,10 @@ pub(crate) unsafe fn rav1d_copy_lpf<BD: BitDepth>(
backup_lpf::<BD>(
c,
f,
(f.lf.cdef_lpf_line[0] as *mut BD::Pixel).offset(cdef_off_y as isize),
cdef_line_buf
.as_mut_ptr()
.add(f.lf.cdef_lpf_line[0])
.offset(cdef_off_y),
*src_stride.offset(0),
(*src.offset(0)).offset(
-offset as isize * BD::pxstride(*src_stride.offset(0) as usize) as isize,
Expand Down Expand Up @@ -276,7 +286,10 @@ pub(crate) unsafe fn rav1d_copy_lpf<BD: BitDepth>(
backup_lpf::<BD>(
c,
f,
(f.lf.cdef_lpf_line[1] as *mut BD::Pixel).offset(cdef_off_uv as isize),
cdef_line_buf
.as_mut_ptr()
.add(f.lf.cdef_lpf_line[1])
.offset(cdef_off_uv),
*src_stride.offset(1),
(*src.offset(1)).offset(
-offset_uv as isize * BD::pxstride(*src_stride.offset(1) as usize) as isize,
Expand Down Expand Up @@ -318,7 +331,10 @@ pub(crate) unsafe fn rav1d_copy_lpf<BD: BitDepth>(
backup_lpf::<BD>(
c,
f,
(f.lf.cdef_lpf_line[2] as *mut BD::Pixel).offset(cdef_off_uv as isize),
cdef_line_buf
.as_mut_ptr()
.add(f.lf.cdef_lpf_line[2])
.offset(cdef_off_uv),
*src_stride.offset(1),
(*src.offset(2)).offset(
-offset_uv as isize * BD::pxstride(*src_stride.offset(1) as usize) as isize,
Expand All @@ -336,6 +352,8 @@ pub(crate) unsafe fn rav1d_copy_lpf<BD: BitDepth>(
}
}
}

f.lf.cdef_line_buf = cdef_line_buf_tmp;
}

/// Slice `[u8; 4]`s from `lvl`, but "unaligned",
Expand Down

0 comments on commit 7e4c4a0

Please sign in to comment.