Skip to main content

ImageData

Struct ImageData 

Source
pub struct ImageData {
    pub rgba: Vec<u8>,
    pub width: u32,
    pub height: u32,
    pub stride: usize,
}
Expand description

解码后的位图(直排 RGBA8,每像素 4 字节)。

stride 是一等信息,不是优化项(0.4 §V-P0-1 / RT-01):解码器(FFmpeg 等) 输出的行常带对齐 padding,stride > width * 4 是常态。以前没有这个字段, 运行时只能假设 packed(bytes_per_row = 4 * width),于是每一帧都得先在 CPU 上 整帧重打包一次(1080p 就是 7.9 MiB/帧)。现在两端都按 stride 读,直接透传即可。

Fields§

§rgba: Vec<u8>§width: u32§height: u32§stride: usize

行距(字节)。0 视为 packed(width * 4),由 ImageData::row_bytes 归一。

Implementations§

Source§

impl ImageData

Source

pub fn new(rgba: Vec<u8>, width: u32, height: u32) -> Self

从 packed(无行 padding)缓冲构造:stride == width * 4。

Source

pub fn with_stride( rgba: Vec<u8>, width: u32, height: u32, stride: usize, ) -> Self

从带行 padding 的缓冲构造(解码器输出走这条)。

不做隐式重打包 —— 静默拷贝整帧正是我们要消掉的开销。约束违反是调用方的 编程错误,在 debug 构建里直接 panic,release 下由绘制端按 row_bytes 夹紧。

Source

pub fn row_bytes(&self) -> usize

实际行距(字节)。stride == 0 表示 packed。

Source

pub fn is_packed(&self) -> bool

是否是 packed 缓冲(无行 padding)。

Source

pub fn min_len(&self) -> usize

缓冲至少需要的字节数。

Source

pub fn row(&self, y: usize) -> &[u8] ⓘ

第 y 行的字节切片;越界或缓冲不足时返回空切片(绘制端据此跳过坏行)。

Source

pub fn solid(width: u32, height: u32, color: Color) -> Self

纯色图(测试/占位用)

Source

pub fn pixel_count(&self) -> u32

像素数(宽 × 高)

Trait Implementations§

Source§

impl Clone for ImageData

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for ImageData

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

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

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.