pub struct Framebuffer { /* private fields */ }Expand description
SIMD-aligned framebuffer for efficient pixel operations.
The pixel buffer is aligned to 64 bytes for optimal SIMD performance on AVX-512 and other wide SIMD architectures.
§SIMD Acceleration
Operations like clear(), fill_rect(), and blend() are SIMD-accelerated
using trueno’s automatic backend selection (SSE2/AVX2/AVX512/NEON).
Implementations§
Source§impl Framebuffer
impl Framebuffer
Sourcepub fn new(width: u32, height: u32) -> Result<Self>
pub fn new(width: u32, height: u32) -> Result<Self>
Create a new framebuffer with the given dimensions.
The buffer is aligned to 64 bytes for optimal SIMD performance.
§Errors
Returns an error if width or height is zero.
§Example
use trueno_viz::framebuffer::Framebuffer;
let fb = Framebuffer::new(800, 600).unwrap();
assert_eq!(fb.width(), 800);
assert_eq!(fb.height(), 600);Sourcepub const fn stride(&self) -> usize
pub const fn stride(&self) -> usize
Get the stride (row width in bytes, including any padding).
Sourcepub const fn pixel_count(&self) -> usize
pub const fn pixel_count(&self) -> usize
Get the total number of pixels.
Sourcepub fn pixels_mut(&mut self) -> &mut [u8] ⓘ
pub fn pixels_mut(&mut self) -> &mut [u8] ⓘ
Get the raw pixel data as a mutable slice.
Sourcepub fn clear(&mut self, color: Rgba)
pub fn clear(&mut self, color: Rgba)
Clear the framebuffer to a solid color.
This operation is optimized for SIMD by processing 16 pixels at a time (64 bytes = 16 RGBA pixels on AVX-512).
Sourcepub fn fill_rect(&mut self, x: u32, y: u32, w: u32, h: u32, color: Rgba)
pub fn fill_rect(&mut self, x: u32, y: u32, w: u32, h: u32, color: Rgba)
Fill a rectangular region with a solid color.
Coordinates are clamped to framebuffer bounds.
Sourcepub fn get_pixel(&self, x: u32, y: u32) -> Option<Rgba>
pub fn get_pixel(&self, x: u32, y: u32) -> Option<Rgba>
Get the color at a specific pixel coordinate.
Returns None if the coordinates are out of bounds.
Sourcepub fn set_pixel(&mut self, x: u32, y: u32, color: Rgba)
pub fn set_pixel(&mut self, x: u32, y: u32, color: Rgba)
Set the color at a specific pixel coordinate.
Does nothing if the coordinates are out of bounds.
Sourcepub fn blend_pixel(&mut self, x: u32, y: u32, color: Rgba)
pub fn blend_pixel(&mut self, x: u32, y: u32, color: Rgba)
Blend a color at a specific pixel coordinate using alpha blending.
Uses the standard “over” compositing operation:
out = src * src_alpha + dst * dst_alpha * (1 - src_alpha)
Sourcepub fn blend_over(&mut self, other: &Framebuffer, alpha: f32) -> Result<()>
pub fn blend_over(&mut self, other: &Framebuffer, alpha: f32) -> Result<()>
Blend an entire framebuffer over this one using SIMD-accelerated operations.
Uses trueno’s Vector operations for alpha blending.
§Errors
Returns an error if the framebuffers have different dimensions.
Sourcepub fn adjust_brightness(&mut self, factor: f32)
pub fn adjust_brightness(&mut self, factor: f32)
Apply a brightness adjustment using SIMD-accelerated operations.
factor of 1.0 is no change, < 1.0 darkens, > 1.0 brightens.
Sourcepub fn luminance_stats(&self) -> (f32, f32, f32)
pub fn luminance_stats(&self) -> (f32, f32, f32)
Get statistics about the framebuffer using SIMD-accelerated reduction.
Returns (min_luminance, max_luminance, avg_luminance).
Sourcepub fn is_aligned(&self) -> bool
pub fn is_aligned(&self) -> bool
Check if the pixel buffer is properly aligned for SIMD.
Sourcepub fn to_compact_pixels(&self) -> Vec<u8> ⓘ
pub fn to_compact_pixels(&self) -> Vec<u8> ⓘ
Get pixel data as a compact buffer without stride padding.
This is useful for encoding to formats like PNG that expect tightly-packed pixel data.
Trait Implementations§
Source§impl Clone for Framebuffer
impl Clone for Framebuffer
Source§fn clone(&self) -> Framebuffer
fn clone(&self) -> Framebuffer
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for Framebuffer
impl RefUnwindSafe for Framebuffer
impl Send for Framebuffer
impl Sync for Framebuffer
impl Unpin for Framebuffer
impl UnsafeUnpin for Framebuffer
impl UnwindSafe for Framebuffer
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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 more