Skip to main content

Framebuffer

Struct Framebuffer 

Source
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

Source

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);
Source

pub const fn width(&self) -> u32

Get the width in pixels.

Source

pub const fn height(&self) -> u32

Get the height in pixels.

Source

pub const fn stride(&self) -> usize

Get the stride (row width in bytes, including any padding).

Source

pub const fn pixel_count(&self) -> usize

Get the total number of pixels.

Source

pub fn pixels(&self) -> &[u8]

Get the raw pixel data as a slice.

Source

pub fn pixels_mut(&mut self) -> &mut [u8]

Get the raw pixel data as a mutable slice.

Source

pub fn row(&self, y: u32) -> Option<&[u8]>

Get a row of pixels as a slice.

Source

pub fn row_mut(&mut self, y: u32) -> Option<&mut [u8]>

Get a row of pixels as a mutable slice.

Source

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).

Source

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.

Source

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.

Source

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.

Source

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)

Source

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.

Source

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.

Source

pub fn luminance_stats(&self) -> (f32, f32, f32)

Get statistics about the framebuffer using SIMD-accelerated reduction.

Returns (min_luminance, max_luminance, avg_luminance).

Source

pub fn is_aligned(&self) -> bool

Check if the pixel buffer is properly aligned for SIMD.

Source

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.

Source

pub fn backend() -> Backend

Get the selected SIMD backend.

Trait Implementations§

Source§

impl Clone for Framebuffer

Source§

fn clone(&self) -> Framebuffer

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 Framebuffer

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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> Downcast<T> for T

Source§

fn downcast(&self) -> &T

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> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

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

impl<T> Upcast<T> for T

Source§

fn upcast(&self) -> Option<&T>

Source§

impl<S, T> Upcast<T> for S
where T: UpcastFrom<S> + ?Sized, S: ?Sized,

Source§

fn upcast(&self) -> &T
where Self: ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider ref type within the Wasm bindgen generics type system. Read more
Source§

fn upcast_into(self) -> T
where Self: Sized + ErasableGeneric, T: Sized + ErasableGeneric<Repr = Self::Repr>,

Perform a zero-cost type-safe upcast to a wider type within the Wasm bindgen generics type system. Read more
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

impl<T> WasmNotSync for T
where T: Sync,