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>
impl<C: ColorIndex> IndexedFrameBuffer<C>
Sourcepub fn new(width: usize, height: usize, clear: C) -> Self
pub fn new(width: usize, height: usize, clear: C) -> Self
Create a new width × height buffer, cleared to clear.
Sourcepub fn set_pixel(&mut self, x: u32, y: u32, color: C) -> bool
pub fn set_pixel(&mut self, x: u32, y: u32, color: C) -> bool
Set a single pixel. Returns false if out of bounds.
Sourcepub fn get_pixel(&self, x: u32, y: u32) -> Option<C>
pub fn get_pixel(&self, x: u32, y: u32) -> Option<C>
Get the index of a single pixel. Returns None if out of bounds.
Sourcepub fn fill_rect(
&mut self,
x: u32,
y: u32,
rect_width: u32,
rect_height: u32,
color: C,
)
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.
Sourcepub fn to_rgba(&self, palette: &Palette<C>, out: &mut [u8]) -> bool
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.
Sourcepub fn packed(&self) -> &[u8] ⓘ
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.
Sourcepub fn packed_mut(&mut self) -> &mut [u8] ⓘ
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>
impl<C: Clone + ColorIndex> Clone for IndexedFrameBuffer<C>
Source§fn clone(&self) -> IndexedFrameBuffer<C>
fn clone(&self) -> IndexedFrameBuffer<C>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl<C: Debug + ColorIndex> Debug for IndexedFrameBuffer<C>
impl<C: Debug + ColorIndex> Debug for IndexedFrameBuffer<C>
Source§impl<C: ColorIndex> Default for IndexedFrameBuffer<C>
The default IndexedFrameBuffer is a 160×144 Game Boy screen,
cleared to index 0.
impl<C: ColorIndex> Default for IndexedFrameBuffer<C>
The default IndexedFrameBuffer is a 160×144 Game Boy screen,
cleared to index 0.
impl<C: Eq + ColorIndex> Eq for IndexedFrameBuffer<C>
Source§impl<C: PartialEq + ColorIndex> PartialEq for IndexedFrameBuffer<C>
impl<C: PartialEq + ColorIndex> PartialEq for IndexedFrameBuffer<C>
impl<C: PartialEq + ColorIndex> StructuralPartialEq for IndexedFrameBuffer<C>
Source§impl<C: ColorIndex> TransitionFb for IndexedFrameBuffer<C>
impl<C: ColorIndex> TransitionFb for IndexedFrameBuffer<C>
Source§fn tile_black(&mut self, tx: usize, ty: usize)
fn tile_black(&mut self, tx: usize, ty: usize)
tx, ty) with black.
Out-of-bounds tiles are clamped to the visible area.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> 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> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&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> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.