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
impl ImageData
Sourcepub fn new(rgba: Vec<u8>, width: u32, height: u32) -> Self
pub fn new(rgba: Vec<u8>, width: u32, height: u32) -> Self
从 packed(无行 padding)缓冲构造:stride == width * 4。
Sourcepub fn with_stride(
rgba: Vec<u8>,
width: u32,
height: u32,
stride: usize,
) -> Self
pub fn with_stride( rgba: Vec<u8>, width: u32, height: u32, stride: usize, ) -> Self
从带行 padding 的缓冲构造(解码器输出走这条)。
不做隐式重打包 —— 静默拷贝整帧正是我们要消掉的开销。约束违反是调用方的
编程错误,在 debug 构建里直接 panic,release 下由绘制端按 row_bytes 夹紧。
Sourcepub fn pixel_count(&self) -> u32
pub fn pixel_count(&self) -> u32
像素数(宽 × 高)
Trait Implementations§
Auto Trait Implementations§
impl Forget for ImageData
impl Freeze for ImageData
impl Move for ImageData
impl RefUnwindSafe for ImageData
impl Send for ImageData
impl Sync for ImageData
impl Unpin for ImageData
impl UnsafeUnpin for ImageData
impl UnwindSafe for ImageData
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