Skip to main content

DocBuffer

Struct DocBuffer 

Source
pub struct DocBuffer<'a> {
    pub data: &'a [u8],
    pub width: u32,
    pub height: u32,
    pub stride: u32,
}
Expand description

核心图像缓冲区,支持非连续内存 (Row Stride)。

§生命周期

'a 绑定到原始数据切片,确保编译期内存安全。

§字段说明

  • data:原始 Y 通道字节切片引用
  • width:图像有效像素宽度
  • height:图像高度
  • stride:每行实际字节数(含 Padding,stride >= width)

Fields§

§data: &'a [u8]

原始 Y 通道数据引用

§width: u32

图像宽度(像素)

§height: u32

图像高度(像素)

§stride: u32

行步长(字节数,含 Padding)

Implementations§

Source§

impl<'a> DocBuffer<'a>

Source

pub fn new( data: &'a [u8], width: u32, height: u32, stride: u32, ) -> Result<Self, DocQuadError>

创建新的缓冲区实例,执行边界合法性校验。

§错误
  • stride < width:步长小于宽度,布局非法
  • height * stride > data.len():数据长度不足
  • 乘法溢出(32 位平台超大分辨率)
Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.