Skip to content

Commit

Permalink
cdef_apply.rs: Use pixel_copy + minor cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
thedataking committed Dec 22, 2023
1 parent 106ad18 commit 7183c89
Show file tree
Hide file tree
Showing 2 changed files with 100 additions and 111 deletions.
170 changes: 90 additions & 80 deletions src/cdef_apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,47 +11,43 @@ use crate::src::internal::Rav1dDSPContext;
use crate::src::internal::Rav1dFrameContext;
use crate::src::internal::Rav1dTaskContext;
use crate::src::lf_mask::Av1Filter;

use libc::memcpy;
use libc::ptrdiff_t;
use std::cmp;
use std::ffi::c_int;
use std::ffi::c_uint;
use std::ffi::c_void;
use std::slice;

pub type Backup2x8Flags = c_uint;
pub const BACKUP_2X8_UV: Backup2x8Flags = 2;
pub const BACKUP_2X8_Y: Backup2x8Flags = 1;

// TODO(perl) Temporarily pub until mod is deduplicated
pub(crate) unsafe fn backup2lines<BD: BitDepth>(
unsafe fn backup2lines<BD: BitDepth>(
dst: *const *mut BD::Pixel,
src: *const *mut BD::Pixel,
stride: *const ptrdiff_t,
layout: Rav1dPixelLayout,
) {
let y_stride: ptrdiff_t = BD::pxstride(*stride.offset(0) as usize) as isize;
if y_stride < 0 {
let n = if BD::BITDEPTH == 8 {
(-2 * y_stride) as usize
} else {
(-2 * y_stride << 1) as usize
};
memcpy(
(*dst.offset(0)).offset(y_stride as isize) as *mut c_void,
(*src.offset(0)).offset((7 as c_int as isize * y_stride) as isize) as *const c_void,
n,
BD::pixel_copy(
slice::from_raw_parts_mut(
*dst.offset(y_stride as isize) as *mut BD::Pixel,
(-2 * y_stride) as usize,
),
slice::from_raw_parts(
*src.offset((7 as isize * y_stride) as isize) as *const BD::Pixel,
(-2 * y_stride) as usize,
),
(-2 * y_stride) as usize,
);
} else {
let n = if BD::BITDEPTH == 8 {
(2 * y_stride) as usize
} else {
(2 * y_stride << 1) as usize
};
memcpy(
*dst.offset(0) as *mut c_void,
(*src.offset(0)).offset(6 * y_stride as isize) as *const c_void,
n,
BD::pixel_copy(
slice::from_raw_parts_mut(*dst as *mut BD::Pixel, (2 * y_stride) as usize),
slice::from_raw_parts(
(*src.offset(0)).offset(6 as isize * y_stride as isize) as *const BD::Pixel,
(2 * y_stride) as usize,
),
(2 * y_stride) as usize,
);
}
if layout as c_uint != Rav1dPixelLayout::I400 as c_int as c_uint {
Expand All @@ -62,48 +58,59 @@ pub(crate) unsafe fn backup2lines<BD: BitDepth>(
} else {
7 as c_int
};
let n = if BD::BITDEPTH == 8 {
(-2 * uv_stride) as usize
} else {
(-2 * uv_stride << 1) as usize
};
memcpy(
(*dst.offset(1)).offset(uv_stride as isize) as *mut c_void,
(*src.offset(1)).offset((uv_off as isize * uv_stride) as isize) as *const c_void,
n,
BD::pixel_copy(
slice::from_raw_parts_mut(
(*dst.offset(1)).offset(uv_stride as isize) as *mut BD::Pixel,
(-2 * uv_stride) as usize,
),
slice::from_raw_parts(
(*src.offset(1)).offset((uv_off as isize * uv_stride) as isize)
as *const BD::Pixel,
(-2 * uv_stride) as usize,
),
(-2 * uv_stride) as usize,
);
memcpy(
(*dst.offset(2)).offset(uv_stride as isize) as *mut c_void,
(*src.offset(2)).offset((uv_off as isize * uv_stride) as isize) as *const c_void,
n,
BD::pixel_copy(
slice::from_raw_parts_mut(
(*dst.offset(2)).offset(uv_stride as isize) as *mut BD::Pixel,
(-2 * uv_stride) as usize,
),
slice::from_raw_parts(
(*src.offset(2)).offset((uv_off as isize * uv_stride) as isize)
as *const BD::Pixel,
(-2 * uv_stride) as usize,
),
(-2 * uv_stride) as usize,
);
} else {
let uv_off_0 = if layout as c_uint == Rav1dPixelLayout::I420 as c_int as c_uint {
let uv_off = if layout as c_uint == Rav1dPixelLayout::I420 as c_int as c_uint {
2 as c_int
} else {
6 as c_int
};
let n = if BD::BITDEPTH == 8 {
(2 * uv_stride) as usize
} else {
(2 * uv_stride << 1) as usize
};
memcpy(
*dst.offset(1) as *mut c_void,
(*src.offset(1)).offset((uv_off_0 as isize * uv_stride) as isize) as *const c_void,
n,
BD::pixel_copy(
slice::from_raw_parts_mut(*dst.offset(1) as *mut BD::Pixel, 2 * uv_stride as usize),
slice::from_raw_parts(
(*src.offset(1)).offset((uv_off as isize * uv_stride) as isize)
as *const BD::Pixel,
2 * uv_stride as usize,
),
2 * uv_stride as usize,
);
memcpy(
*dst.offset(2) as *mut c_void,
(*src.offset(2)).offset((uv_off_0 as isize * uv_stride) as isize) as *const c_void,
n,
BD::pixel_copy(
slice::from_raw_parts_mut(*dst.offset(2) as *mut BD::Pixel, 2 * uv_stride as usize),
slice::from_raw_parts(
(*src.offset(2)).offset((uv_off as isize * uv_stride) as isize)
as *const BD::Pixel,
2 * uv_stride as usize,
),
2 * uv_stride as usize,
);
}
}
}

// TODO(perl) Temporarily pub until mod is deduplicated
pub(crate) unsafe fn backup2x8<BD: BitDepth>(
unsafe fn backup2x8<BD: BitDepth>(
dst: *mut [[BD::Pixel; 2]; 8],
src: *const *mut BD::Pixel,
src_stride: *const ptrdiff_t,
Expand All @@ -112,19 +119,17 @@ pub(crate) unsafe fn backup2x8<BD: BitDepth>(
flag: Backup2x8Flags,
) {
let mut y_off: ptrdiff_t = 0 as c_int as ptrdiff_t;
let n = if BD::BITDEPTH == 8 {
2usize
} else {
(2usize << 1) as usize
};
if flag as c_uint & BACKUP_2X8_Y as c_int as c_uint != 0 {
let mut y = 0;
while y < 8 {
memcpy(
((*dst.offset(0))[y as usize]).as_mut_ptr() as *mut c_void,
&mut *(*src.offset(0)).offset((y_off + x_off as isize - 2 as isize) as isize)
as *mut BD::Pixel as *const c_void,
n,
BD::pixel_copy(
&mut (*dst.offset(0))[y as usize],
slice::from_raw_parts(
&mut *(*src.offset(0)).offset((y_off + x_off as isize - 2 as isize) as isize)
as *mut BD::Pixel,
2,
),
2,
);
y += 1;
y_off += BD::pxstride(*src_stride.offset(0) as usize) as isize;
Expand All @@ -139,27 +144,32 @@ pub(crate) unsafe fn backup2x8<BD: BitDepth>(
let ss_hor = (layout as c_uint != Rav1dPixelLayout::I444 as c_int as c_uint) as c_int;
x_off >>= ss_hor;
y_off = 0 as c_int as ptrdiff_t;
let mut y_0 = 0;
while y_0 < 8 >> ss_ver {
memcpy(
((*dst.offset(1))[y_0 as usize]).as_mut_ptr() as *mut c_void,
&mut *(*src.offset(1)).offset((y_off + x_off as isize - 2) as isize) as *mut BD::Pixel
as *const c_void,
n,
let mut y = 0;
while y < 8 >> ss_ver {
BD::pixel_copy(
&mut (*dst.offset(1))[y as usize],
slice::from_raw_parts(
&mut *(*src.offset(1)).offset((y_off + x_off as isize - 2 as isize) as isize)
as *mut BD::Pixel,
2,
),
2,
);
memcpy(
((*dst.offset(2))[y_0 as usize]).as_mut_ptr() as *mut c_void,
&mut *(*src.offset(2)).offset((y_off + x_off as isize - 2) as isize) as *mut BD::Pixel
as *const c_void,
n,
BD::pixel_copy(
&mut (*dst.offset(2))[y as usize],
slice::from_raw_parts(
&mut *(*src.offset(2)).offset((y_off + x_off as isize - 2 as isize) as isize)
as *mut BD::Pixel,
2,
),
2,
);
y_0 += 1;
y += 1;
y_off += BD::pxstride(*src_stride.offset(1) as usize) as isize;
}
}

// TODO(perl) Temporarily pub until mod is deduplicated
pub(crate) unsafe fn adjust_strength(strength: c_int, var: c_uint) -> c_int {
unsafe fn adjust_strength(strength: c_int, var: c_uint) -> c_int {
if var == 0 {
return 0 as c_int;
}
Expand Down Expand Up @@ -558,11 +568,11 @@ pub(crate) unsafe fn rav1d_cdef_brow<BD: BitDepth>(
edges as c_uint | CDEF_HAVE_LEFT as c_int as c_uint,
);
}
ptrs[0] = (ptrs[0]).offset((8 * BD::pxstride((*f).cur.stride[0] as usize)) as isize);
ptrs[0] = (ptrs[0]).offset(8 * BD::pxstride((*f).cur.stride[0] as usize) as isize);
ptrs[1] =
(ptrs[1]).offset((8 * BD::pxstride((*f).cur.stride[1] as usize) >> ss_ver) as isize);
(ptrs[1]).offset(8 * BD::pxstride((*f).cur.stride[1] as usize) as isize >> ss_ver);
ptrs[2] =
(ptrs[2]).offset((8 * BD::pxstride((*f).cur.stride[1] as usize) >> ss_ver) as isize);
(ptrs[2]).offset(8 * BD::pxstride((*f).cur.stride[1] as usize) as isize >> ss_ver);
(*tc).top_pre_cdef_toggle ^= 1 as c_int;
by += 2 as c_int;
edges = ::core::mem::transmute::<c_uint, CdefEdgeFlags>(
Expand Down
41 changes: 10 additions & 31 deletions src/recon.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
use crate::include::common::bitdepth::AsPrimitive;
use crate::include::common::bitdepth::BitDepth;
use crate::include::common::bitdepth::BitDepth16;
use crate::include::common::bitdepth::BitDepth8;
use crate::include::common::bitdepth::DynCoef;
use crate::include::common::bitdepth::BPC;
use crate::include::common::dump::ac_dump;
use crate::include::common::dump::coef_dump;
use crate::include::common::dump::hex_dump;
Expand Down Expand Up @@ -4557,37 +4554,19 @@ pub(crate) unsafe fn rav1d_filter_sbrow_cdef<BD: BitDepth>(tc: &mut Rav1dTaskCon
-((8 * BD::pxstride((*f).cur.stride[1] as usize) as isize >> ss_ver) as isize),
),
];
match BD::BPC {
BPC::BPC8 => rav1d_cdef_brow::<BitDepth8>(
tc,
p_up.as_mut_ptr().cast(),
prev_mask,
start - 2,
start,
1 as c_int,
sby,
),
BPC::BPC16 => rav1d_cdef_brow::<BitDepth16>(
tc,
p_up.as_mut_ptr().cast(),
prev_mask,
start - 2,
start,
1 as c_int,
sby,
),
};
rav1d_cdef_brow::<BD>(
tc,
p_up.as_mut_ptr(),
prev_mask,
start - 2,
start,
1 as c_int,
sby,
);
}
let n_blks = sbsz - 2 * ((sby + 1) < (*f).sbh) as c_int;
let end = cmp::min(start + n_blks, (*f).bh);
match BD::BPC {
BPC::BPC8 => {
rav1d_cdef_brow::<BitDepth8>(tc, p.as_ptr().cast(), mask, start, end, 0 as c_int, sby)
}
BPC::BPC16 => {
rav1d_cdef_brow::<BitDepth16>(tc, p.as_ptr().cast(), mask, start, end, 0 as c_int, sby)
}
};
rav1d_cdef_brow::<BD>(tc, p.as_ptr(), mask, start, end, 0 as c_int, sby);
}

pub(crate) unsafe fn rav1d_filter_sbrow_resize<BD: BitDepth>(
Expand Down

0 comments on commit 7183c89

Please sign in to comment.