pub struct ImageView<'a> {
pub data: &'a [u8],
pub width: usize,
pub height: usize,
pub stride: usize,
}Expand description
A view into an image buffer with explicit stride support. This allows handling NumPy arrays with padding or non-standard layouts.
Fields§
§data: &'a [u8]The raw image data slice.
width: usizeThe width of the image in pixels.
height: usizeThe height of the image in pixels.
stride: usizeThe stride (bytes per row) of the image.
Implementations§
Source§impl<'a> ImageView<'a>
impl<'a> ImageView<'a>
Sourcepub fn new(
data: &'a [u8],
width: usize,
height: usize,
stride: usize,
) -> Result<Self, String>
pub fn new( data: &'a [u8], width: usize, height: usize, stride: usize, ) -> Result<Self, String>
Create a new ImageView after validating that the buffer size matches the dimensions and stride.
Sourcepub fn has_simd_padding(&self) -> bool
pub fn has_simd_padding(&self) -> bool
Returns true if the image buffer has sufficient padding for safe SIMD gather operations.
Some SIMD kernels (e.g. AVX2 gather) may perform 32-bit loads on 8-bit data, which can read up to 3 bytes past the end of the logical buffer.
Sourcepub fn get_pixel(&self, x: usize, y: usize) -> u8
pub fn get_pixel(&self, x: usize, y: usize) -> u8
Get a pixel value at (x, y) with boundary clamping.
Sourcepub unsafe fn get_pixel_unchecked(&self, x: usize, y: usize) -> u8
pub unsafe fn get_pixel_unchecked(&self, x: usize, y: usize) -> u8
Get a pixel value at (x, y) without bounds checking.
§Safety
Caller must ensure x < width and y < height.
Sourcepub fn sample_bilinear(&self, x: f64, y: f64) -> f64
pub fn sample_bilinear(&self, x: f64, y: f64) -> f64
Sample pixel value with bilinear interpolation at sub-pixel coordinates.
Sourcepub unsafe fn sample_bilinear_unchecked(&self, x: f64, y: f64) -> f64
pub unsafe fn sample_bilinear_unchecked(&self, x: f64, y: f64) -> f64
Sample pixel value with bilinear interpolation at sub-pixel coordinates without bounds checking.
§Safety
Caller must ensure 0.0 <= x <= width - 1.001 and 0.0 <= y <= height - 1.001
such that floor(x), floor(x)+1, floor(y), floor(y)+1 are all valid indices.
Sourcepub fn sample_gradient_bilinear(&self, x: f64, y: f64) -> [f64; 2]
pub fn sample_gradient_bilinear(&self, x: f64, y: f64) -> [f64; 2]
Compute the gradient [gx, gy] at sub-pixel coordinates using bilinear interpolation.
Trait Implementations§
Auto Trait Implementations§
impl<'a> Freeze for ImageView<'a>
impl<'a> RefUnwindSafe for ImageView<'a>
impl<'a> Send for ImageView<'a>
impl<'a> Sync for ImageView<'a>
impl<'a> Unpin for ImageView<'a>
impl<'a> UnsafeUnpin for ImageView<'a>
impl<'a> UnwindSafe for ImageView<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.