Skip to main content

IndexedFrameBuffer

Struct IndexedFrameBuffer 

Source
pub struct IndexedFrameBuffer<C: ColorIndex = GbColor> { /* private fields */ }
Expand description

A fixed-size framebuffer storing palette indices instead of RGBA pixels.

C is the palette index type (GbColor for 4-color DMG, GbaColor for 16-color GBA). Dimensions are chosen at construction (see Default for the 160×144 Game Boy screen). Storage is a packed planar bitplane array (see the module docs); index values are implicitly masked to the storage width on write.

Implementations§

Source§

impl<C: ColorIndex> IndexedFrameBuffer<C>

Source

pub fn new(width: usize, height: usize, clear: C) -> Self

Create a new width × height buffer, cleared to clear.

Source

pub const fn width(&self) -> usize

Screen width in pixels.

Source

pub const fn height(&self) -> usize

Screen height in pixels.

Source

pub fn len(&self) -> usize

Total number of pixels.

Source

pub fn is_empty(&self) -> bool

Whether the buffer holds no pixels.

Source

pub fn clear(&mut self, color: C)

Clear the entire buffer to a single index.

Source

pub fn set_pixel(&mut self, x: u32, y: u32, color: C) -> bool

Set a single pixel. Returns false if out of bounds.

Source

pub fn get_pixel(&self, x: u32, y: u32) -> Option<C>

Get the index of a single pixel. Returns None if out of bounds.

Source

pub fn fill_rect( &mut self, x: u32, y: u32, rect_width: u32, rect_height: u32, color: C, )

Fill a rectangular region with an index. Coordinates are clamped to buffer bounds.

Source

pub fn to_rgba(&self, palette: &Palette<C>, out: &mut [u8]) -> bool

Expand the indexed buffer into RGBA using palette.

Writes width * height * 4 bytes of row-major [r, g, b, a] pixel data into out. Returns false (and writes nothing) if out is too small. The palette should define an entry for every index in the buffer.

Source

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

Raw packed storage, in the planar bitplane format described in the module docs. For GbColor this is GB 2bpp tile data, so any 8×8-aligned region can be fed directly to crate::tile::Tile::from_2bpp.

Source

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

Mutable raw packed storage (e.g. for tile blits into 8×8-aligned regions, or for serialization). The caller must preserve the planar bitplane layout.

Trait Implementations§

Source§

impl<C: Clone + ColorIndex> Clone for IndexedFrameBuffer<C>

Source§

fn clone(&self) -> IndexedFrameBuffer<C>

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<C: Debug + ColorIndex> Debug for IndexedFrameBuffer<C>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<C: ColorIndex> Default for IndexedFrameBuffer<C>

The default IndexedFrameBuffer is a 160×144 Game Boy screen, cleared to index 0.

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<C: Eq + ColorIndex> Eq for IndexedFrameBuffer<C>

Source§

impl<C: PartialEq + ColorIndex> PartialEq for IndexedFrameBuffer<C>

Source§

fn eq(&self, other: &IndexedFrameBuffer<C>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<C: PartialEq + ColorIndex> StructuralPartialEq for IndexedFrameBuffer<C>

Source§

impl<C: ColorIndex> TransitionFb for IndexedFrameBuffer<C>

Source§

fn size(&self) -> (usize, usize)

(width, height) in pixels.
Source§

fn tile_black(&mut self, tx: usize, ty: usize)

Fill the 8×8 tile at tile coordinates (tx, ty) with black. Out-of-bounds tiles are clamped to the visible area.
Source§

fn tile_copy( &mut self, tx: usize, ty: usize, src: &Self, stx: usize, sty: usize, )

Copy the 8×8 tile at tile coordinates (stx, sty) of src into tile (tx, ty) of self. Out-of-bounds areas are clamped.

Auto Trait Implementations§

§

impl<C> Freeze for IndexedFrameBuffer<C>

§

impl<C> RefUnwindSafe for IndexedFrameBuffer<C>
where C: RefUnwindSafe,

§

impl<C> Send for IndexedFrameBuffer<C>
where C: Send,

§

impl<C> Sync for IndexedFrameBuffer<C>
where C: Sync,

§

impl<C> Unpin for IndexedFrameBuffer<C>
where C: Unpin,

§

impl<C> UnsafeUnpin for IndexedFrameBuffer<C>

§

impl<C> UnwindSafe for IndexedFrameBuffer<C>
where C: UnwindSafe,

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

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> Downcast<T> for T

Source§

fn downcast(&self) -> &T

Source§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

Source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> 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<T> WasmNotSend for T
where T: Send,

Source§

impl<T> WasmNotSendSync for T

Source§

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

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more