diff --git a/src/cdef.rs b/src/cdef.rs index a768431af..464e94386 100644 --- a/src/cdef.rs +++ b/src/cdef.rs @@ -86,7 +86,7 @@ impl cdef::Fn { let stride = dst.stride(); let left = ptr::from_ref(left).cast(); let top_ptr = top.as_ptr::().cast(); - let bottom_ptr = bottom.as_ptr::().cast(); + let bottom_ptr = bottom.wrapping_as_ptr::().cast(); let top = FFISafe::new(&top); let bottom = FFISafe::new(&bottom); let sec_strength = sec_strength as c_int; diff --git a/src/pixels.rs b/src/pixels.rs index 5c17f6b65..a52029489 100644 --- a/src/pixels.rs +++ b/src/pixels.rs @@ -28,7 +28,7 @@ pub trait Pixels { self.as_mut_ptr::().cast_const() } - /// Absolute ptr to [`BitDepth::Pixel`]s starting at `offset`. + /// Absolute ptr to [`BitDepth::Pixel`]s starting at `pixel_offset`. /// /// Bounds checked, but not [`DisjointMut`]-checked. #[cfg_attr(debug_assertions, track_caller)] @@ -49,12 +49,26 @@ pub trait Pixels { unsafe { self.as_mut_ptr::().add(pixel_offset) } } - /// Absolute ptr to [`BitDepth::Pixel`]s starting at `offset`. + /// Absolute ptr to [`BitDepth::Pixel`]s starting at `pixel_offset`. /// /// Bounds checked, but not [`DisjointMut`]-checked. #[cfg_attr(debug_assertions, track_caller)] - fn as_ptr_at(&self, offset: usize) -> *const BD::Pixel { - self.as_mut_ptr_at::(offset).cast_const() + fn as_ptr_at(&self, pixel_offset: usize) -> *const BD::Pixel { + self.as_mut_ptr_at::(pixel_offset).cast_const() + } + + /// Absolute ptr to [`BitDepth::Pixel`]s starting at `pixel_offset`. + /// + /// There is no bounds checking and this ptr may wrap and go out of bounds. + fn wrapping_as_mut_ptr_at(&self, pixel_offset: usize) -> *mut BD::Pixel { + self.as_mut_ptr::().wrapping_add(pixel_offset) + } + + /// Absolute ptr to [`BitDepth::Pixel`]s starting at `pixel_offset`. + /// + /// There is no bounds checking and this ptr may wrap and go out of bounds. + fn wrapping_as_ptr_at(&self, pixel_offset: usize) -> *const BD::Pixel { + self.as_ptr::().wrapping_add(pixel_offset) } /// Determine if they reference the same data. diff --git a/src/with_offset.rs b/src/with_offset.rs index 1aa76f388..b057d9ad5 100644 --- a/src/with_offset.rs +++ b/src/with_offset.rs @@ -92,6 +92,14 @@ impl WithOffset

{ pub fn as_mut_ptr(&self) -> *mut BD::Pixel { self.data.as_mut_ptr_at::(self.offset) } + + pub fn wrapping_as_ptr(&self) -> *const BD::Pixel { + self.data.wrapping_as_ptr_at::(self.offset) + } + + pub fn wrapping_as_mut_ptr(&self) -> *const BD::Pixel { + self.data.wrapping_as_mut_ptr_at::(self.offset) + } } impl Strided for WithOffset {