Skip to content

Commit

Permalink
Rename struct WithOffset to struct Cursor
Browse files Browse the repository at this point in the history
  • Loading branch information
rinon committed Aug 5, 2024
1 parent e358772 commit b6fd9f3
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 74 deletions.
4 changes: 2 additions & 2 deletions include/dav1d/picture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ use crate::include::dav1d::headers::Rav1dPixelLayout;
use crate::include::dav1d::headers::Rav1dSequenceHeader;
use crate::src::assume::assume;
use crate::src::c_arc::RawArc;
use crate::src::cursor::Cursor;
use crate::src::disjoint_mut::AsMutPtr;
use crate::src::disjoint_mut::DisjointImmutGuard;
use crate::src::disjoint_mut::DisjointMut;
Expand All @@ -29,7 +30,6 @@ use crate::src::error::Rav1dResult;
use crate::src::pixels::Pixels;
use crate::src::send_sync_non_null::SendSyncNonNull;
use crate::src::strided::Strided;
use crate::src::with_offset::WithOffset;
use libc::ptrdiff_t;
use libc::uintptr_t;
use std::array;
Expand Down Expand Up @@ -351,7 +351,7 @@ impl Rav1dPictureDataComponent {
}
}

pub type Rav1dPictureDataComponentOffset<'a> = WithOffset<&'a Rav1dPictureDataComponent>;
pub type Rav1dPictureDataComponentOffset<'a> = Cursor<&'a Rav1dPictureDataComponent>;

impl<'a> Rav1dPictureDataComponentOffset<'a> {
#[inline] // Inline to see bounds checks in order to potentially elide them.
Expand Down
2 changes: 1 addition & 1 deletion lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ pub mod src {
mod const_fn;
pub mod cpu;
mod ctx;
pub(crate) mod cursor;
mod data;
mod decode;
mod dequant_tables;
Expand All @@ -55,7 +56,6 @@ pub mod src {
pub(crate) mod relaxed_atomic;
pub mod send_sync_non_null;
pub(crate) mod strided;
pub(crate) mod with_offset;
pub(crate) mod wrap_fn_ptr;
// TODO(kkysen) Temporarily `pub(crate)` due to a `pub use` until TAIT.
mod extensions;
Expand Down
6 changes: 3 additions & 3 deletions src/cdef.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ use crate::include::common::intops::iclip;
use crate::include::dav1d::picture::Rav1dPictureDataComponentOffset;
use crate::src::align::AlignedVec64;
use crate::src::cpu::CpuFlags;
use crate::src::cursor::Cursor;
use crate::src::disjoint_mut::DisjointMut;
use crate::src::ffi_safe::FFISafe;
use crate::src::pic_or_buf::PicOrBuf;
use crate::src::strided::Strided as _;
use crate::src::tables::dav1d_cdef_directions;
use crate::src::with_offset::WithOffset;
use crate::src::wrap_fn_ptr::wrap_fn_ptr;
use bitflags::bitflags;
use libc::ptrdiff_t;
Expand Down Expand Up @@ -60,8 +60,8 @@ wrap_fn_ptr!(pub unsafe extern "C" fn cdef(
_bottom: *const FFISafe<CdefBottom>,
) -> ());

pub type CdefTop<'a> = WithOffset<&'a DisjointMut<AlignedVec64<u8>>>;
pub type CdefBottom<'a> = WithOffset<PicOrBuf<'a, AlignedVec64<u8>>>;
pub type CdefTop<'a> = Cursor<&'a DisjointMut<AlignedVec64<u8>>>;
pub type CdefBottom<'a> = Cursor<PicOrBuf<'a, AlignedVec64<u8>>>;

impl cdef::Fn {
/// CDEF operates entirely on pre-filter data.
Expand Down
38 changes: 19 additions & 19 deletions src/cdef_apply.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ use crate::include::dav1d::picture::Rav1dPictureDataComponentOffset;
use crate::src::align::Align16;
use crate::src::align::AlignedVec64;
use crate::src::cdef::CdefEdgeFlags;
use crate::src::cursor::Cursor;
use crate::src::disjoint_mut::DisjointMut;
use crate::src::internal::Rav1dContext;
use crate::src::internal::Rav1dFrameData;
use crate::src::internal::Rav1dTaskContext;
use crate::src::pic_or_buf::PicOrBuf;
use crate::src::strided::Strided as _;
use crate::src::strided::WithStride;
use crate::src::with_offset::WithOffset;
use bitflags::bitflags;
use libc::ptrdiff_t;
use std::cmp;
Expand Down Expand Up @@ -271,43 +271,43 @@ pub(crate) fn rav1d_cdef_brow<BD: BitDepth>(
None
} else if sbrow_start && by == by_start {
let top = if resize {
WithOffset {
Cursor {
data: &f.lf.cdef_line_buf,
offset: f.lf.cdef_lpf_line[0],
} + ((sby - 1) * 4) as isize * y_stride
+ (bx * 4) as isize
} else {
WithOffset {
Cursor {
data: &f.lf.lr_line_buf,
offset: f.lf.lr_lpf_line[0],
} + (sby * (4 << sb128) - 4) as isize * y_stride
+ (bx * 4) as isize
};
let bottom = bptrs[0] + (8 * y_stride);
Some((top, WithOffset::pic(bottom)))
Some((top, Cursor::pic(bottom)))
} else if !sbrow_start && by + 2 >= by_end {
let top = WithOffset {
let top = Cursor {
data: &f.lf.cdef_line_buf,
offset: f.lf.cdef_line[tf as usize][0],
} + (sby * 4) as isize * y_stride
+ (bx * 4) as isize;
let buf = if resize {
WithOffset {
Cursor {
data: &f.lf.cdef_line_buf,
offset: f.lf.cdef_lpf_line[0],
} + (sby * 4 + 2) as isize * y_stride
+ (bx * 4) as isize
} else {
let line = sby * (4 << sb128) + 4 * sb128 as c_int + 2;
WithOffset {
Cursor {
data: &f.lf.lr_line_buf,
offset: f.lf.lr_lpf_line[0],
} + line as isize * y_stride
+ (bx * 4) as isize
};
Some((
top,
WithOffset {
Cursor {
data: PicOrBuf::Buf(WithStride {
buf: buf.data,
stride: y_stride,
Expand All @@ -320,13 +320,13 @@ pub(crate) fn rav1d_cdef_brow<BD: BitDepth>(
};

let (top, bot) = top_bot.unwrap_or_else(|| {
let top = WithOffset {
let top = Cursor {
data: &f.lf.cdef_line_buf,
offset: f.lf.cdef_line[tf as usize][0],
} + have_tt as isize * (sby * 4) as isize * y_stride
+ (bx * 4) as isize;
let bottom = bptrs[0] + (8 * y_stride);
(top, WithOffset::pic(bottom))
(top, Cursor::pic(bottom))
});

if y_pri_lvl != 0 {
Expand Down Expand Up @@ -373,44 +373,44 @@ pub(crate) fn rav1d_cdef_brow<BD: BitDepth>(
None
} else if sbrow_start && by == by_start {
let top = if resize {
WithOffset {
Cursor {
data: &f.lf.cdef_line_buf,
offset: f.lf.cdef_lpf_line[pl],
} + ((sby - 1) * 4) as isize * uv_stride
+ (bx * 4 >> ss_hor) as isize
} else {
let line = sby * (4 << sb128) - 4;
WithOffset {
Cursor {
data: &f.lf.lr_line_buf,
offset: f.lf.lr_lpf_line[pl],
} + line as isize * uv_stride
+ (bx * 4 >> ss_hor) as isize
};
let bottom = bptrs[pl] + ((8 >> ss_ver) * uv_stride);
Some((top, WithOffset::pic(bottom)))
Some((top, Cursor::pic(bottom)))
} else if !sbrow_start && by + 2 >= by_end {
let top = WithOffset {
let top = Cursor {
data: &f.lf.cdef_line_buf,
offset: f.lf.cdef_line[tf as usize][pl],
} + (sby * 8) as isize * uv_stride
+ (bx * 4 >> ss_hor) as isize;
let buf = if resize {
WithOffset {
Cursor {
data: &f.lf.cdef_line_buf,
offset: f.lf.cdef_lpf_line[pl],
} + (sby * 4 + 2) as isize * uv_stride
+ (bx * 4 >> ss_hor) as isize
} else {
let line = sby * (4 << sb128) + 4 * sb128 as c_int + 2;
WithOffset {
Cursor {
data: &f.lf.lr_line_buf,
offset: f.lf.lr_lpf_line[pl],
} + line as isize * uv_stride
+ (bx * 4 >> ss_hor) as isize
};
Some((
top,
WithOffset {
Cursor {
data: PicOrBuf::Buf(WithStride {
buf: buf.data,
stride: uv_stride,
Expand All @@ -423,13 +423,13 @@ pub(crate) fn rav1d_cdef_brow<BD: BitDepth>(
};

let (top, bot) = top_bot.unwrap_or_else(|| {
let top = WithOffset {
let top = Cursor {
data: &f.lf.cdef_line_buf,
offset: f.lf.cdef_line[tf as usize][pl],
} + have_tt as isize * (sby * 8) as isize * uv_stride
+ (bx * 4 >> ss_hor) as isize;
let bottom = bptrs[pl] + ((8 >> ss_ver) * uv_stride);
(top, WithOffset::pic(bottom))
(top, Cursor::pic(bottom))
});

f.dsp.cdef.fb[uv_idx as usize].call::<BD>(
Expand Down
30 changes: 15 additions & 15 deletions src/with_offset.rs → src/cursor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,55 +9,55 @@ use std::ops::Sub;
use std::ops::SubAssign;

#[derive(Clone, Copy)]
pub struct WithOffset<T> {
pub struct Cursor<T> {
pub data: T,
pub offset: usize,
}

pub type CursorMut<'a, T> = WithOffset<&'a mut [T]>;
pub type CursorMut<'a, T> = Cursor<&'a mut [T]>;

impl<'a, T> CursorMut<'a, T> {
pub fn new(data: &'a mut [T]) -> Self {
WithOffset { data, offset: 0 }
Cursor { data, offset: 0 }
}

pub fn clone(&mut self) -> WithOffset<&mut [T]> {
WithOffset {
pub fn clone(&mut self) -> Cursor<&mut [T]> {
Cursor {
data: self.data,
offset: self.offset,
}
}
}

impl<T> AddAssign<usize> for WithOffset<T> {
impl<T> AddAssign<usize> for Cursor<T> {
#[cfg_attr(debug_assertions, track_caller)]
fn add_assign(&mut self, rhs: usize) {
self.offset += rhs;
}
}

impl<T> SubAssign<usize> for WithOffset<T> {
impl<T> SubAssign<usize> for Cursor<T> {
#[cfg_attr(debug_assertions, track_caller)]
fn sub_assign(&mut self, rhs: usize) {
self.offset -= rhs;
}
}

impl<T> AddAssign<isize> for WithOffset<T> {
impl<T> AddAssign<isize> for Cursor<T> {
#[cfg_attr(debug_assertions, track_caller)]
fn add_assign(&mut self, rhs: isize) {
self.offset = self.offset.wrapping_add_signed(rhs);
}
}

impl<T> SubAssign<isize> for WithOffset<T> {
impl<T> SubAssign<isize> for Cursor<T> {
#[cfg_attr(debug_assertions, track_caller)]
fn sub_assign(&mut self, rhs: isize) {
self.offset = self.offset.wrapping_add_signed(-rhs);
}
}

impl<T> Add<usize> for WithOffset<T> {
impl<T> Add<usize> for Cursor<T> {
type Output = Self;

#[cfg_attr(debug_assertions, track_caller)]
Expand All @@ -67,7 +67,7 @@ impl<T> Add<usize> for WithOffset<T> {
}
}

impl<T> Sub<usize> for WithOffset<T> {
impl<T> Sub<usize> for Cursor<T> {
type Output = Self;

#[cfg_attr(debug_assertions, track_caller)]
Expand All @@ -77,7 +77,7 @@ impl<T> Sub<usize> for WithOffset<T> {
}
}

impl<T> Add<isize> for WithOffset<T> {
impl<T> Add<isize> for Cursor<T> {
type Output = Self;

#[cfg_attr(debug_assertions, track_caller)]
Expand All @@ -87,7 +87,7 @@ impl<T> Add<isize> for WithOffset<T> {
}
}

impl<T> Sub<isize> for WithOffset<T> {
impl<T> Sub<isize> for Cursor<T> {
type Output = Self;

#[cfg_attr(debug_assertions, track_caller)]
Expand All @@ -97,7 +97,7 @@ impl<T> Sub<isize> for WithOffset<T> {
}
}

impl<P: Pixels> WithOffset<P> {
impl<P: Pixels> Cursor<P> {
#[inline] // Inline to see bounds checks in order to potentially elide them.
#[cfg_attr(debug_assertions, track_caller)]
pub fn as_ptr<BD: BitDepth>(&self) -> *const BD::Pixel {
Expand All @@ -111,7 +111,7 @@ impl<P: Pixels> WithOffset<P> {
}
}

impl<S: Strided> Strided for WithOffset<S> {
impl<S: Strided> Strided for Cursor<S> {
fn stride(&self) -> isize {
self.data.stride()
}
Expand Down
Loading

0 comments on commit b6fd9f3

Please sign in to comment.