pub struct DocBuffer<'a> {
pub data: &'a [u8],
pub width: u32,
pub height: u32,
pub stride: u32,
}Expand description
Fields§
§data: &'a [u8]原始 Y 通道数据引用
width: u32图像宽度(像素)
height: u32图像高度(像素)
stride: u32行步长(字节数,含 Padding)
Implementations§
Source§impl<'a> DocBuffer<'a>
impl<'a> DocBuffer<'a>
Sourcepub fn new(
data: &'a [u8],
width: u32,
height: u32,
stride: u32,
) -> Result<Self, DocQuadError>
pub fn new( data: &'a [u8], width: u32, height: u32, stride: u32, ) -> Result<Self, DocQuadError>
创建新的缓冲区实例,执行边界合法性校验。
§错误
stride < width:步长小于宽度,布局非法height * stride > data.len():数据长度不足- 乘法溢出(32 位平台超大分辨率)
Sourcepub fn as_array_view(&self) -> Result<ArrayView2<'_, u8>, DocQuadError>
pub fn as_array_view(&self) -> Result<ArrayView2<'_, u8>, DocQuadError>
将缓冲区转换为 ndarray 二维视图,支持零拷贝处理 Row Stride。
§注意
from_shape_ptr 为 unsafe 函数,直接返回 ArrayView2(非 Result),
因此先通过 ndarray::Ix2 + strides 构造合法 shape,再进入 unsafe 块。
若将来扩展至其他像素格式(如 u16 深度图),需将 stride 除以 sizeof(T)。
Auto Trait Implementations§
impl<'a> Freeze for DocBuffer<'a>
impl<'a> RefUnwindSafe for DocBuffer<'a>
impl<'a> Send for DocBuffer<'a>
impl<'a> Sync for DocBuffer<'a>
impl<'a> Unpin for DocBuffer<'a>
impl<'a> UnsafeUnpin for DocBuffer<'a>
impl<'a> UnwindSafe for DocBuffer<'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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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 more