pub struct RgbaIndexedFrameBuffer<C: ColorIndex = GbColor> {
pub palette: Palette<C>,
/* private fields */
}Expand description
An IndexedFrameBuffer with an RGBA-facing facade: RGBA writes are
quantized through a fixed base palette (so drawing is stable no matter
what display effect is active), while a separate display palette is
applied at present time.
Fades and flashes become palette operations, the way real GB hardware
does them: swap the display palette (Self::set_palette,
Self::remap_shades, Self::scale_shades, Self::apply_bgp)
instead of touching every pixel. The buffer itself stays packed 2bpp —
5,760 bytes for a 160×144 screen instead of 92,160.
base doubles as the initial display palette; Self::reset_palette
restores it. The indexed API remains reachable via Self::indexed /
Self::indexed_mut.
Fields§
§palette: Palette<C>Display palette applied at present time; fades/flashes remap this.
Implementations§
Source§impl<C: ColorIndex> RgbaIndexedFrameBuffer<C>
impl<C: ColorIndex> RgbaIndexedFrameBuffer<C>
Sourcepub fn with_palette(config: RenderConfig, clear: Rgba, base: Palette<C>) -> Self
pub fn with_palette(config: RenderConfig, clear: Rgba, base: Palette<C>) -> Self
Create a config-sized buffer with an explicit base palette, cleared
to clear (quantized through base).
Sourcepub fn display_palette(&self) -> &Palette<C>
pub fn display_palette(&self) -> &Palette<C>
The current display palette.
Sourcepub fn set_palette(&mut self, palette: Palette<C>)
pub fn set_palette(&mut self, palette: Palette<C>)
Replace the display palette (fade/flash effect).
Sourcepub fn reset_palette(&mut self)
pub fn reset_palette(&mut self)
Restore the display palette to the base palette.
Sourcepub fn remap_shades(&mut self, map: &[u8])
pub fn remap_shades(&mut self, map: &[u8])
Remap every display shade through map: display color i becomes the
base palette entry map[i]. This is the indexed-buffer equivalent of
the per-pixel remap_shades loops (rBGP-style register writes).
Sourcepub fn scale_shades(&mut self, scale: f32)
pub fn scale_shades(&mut self, scale: f32)
Scale the display colors toward black by scale (0.0 = black,
1.0 = base palette). Alpha is preserved. Mirrors the per-pixel
“brighten/darken” loops (e.g. the Ghost Marowak reveal).
Sourcepub fn indexed(&self) -> &IndexedFrameBuffer<C>
pub fn indexed(&self) -> &IndexedFrameBuffer<C>
Read-only access to the underlying indexed buffer.
Sourcepub fn indexed_mut(&mut self) -> &mut IndexedFrameBuffer<C>
pub fn indexed_mut(&mut self) -> &mut IndexedFrameBuffer<C>
Mutable access to the underlying indexed buffer (C-index API).
Sourcepub fn packed(&self) -> &[u8] ⓘ
pub fn packed(&self) -> &[u8] ⓘ
Raw packed 2bpp storage (see IndexedFrameBuffer::packed).
Sourcepub fn packed_mut(&mut self) -> &mut [u8] ⓘ
pub fn packed_mut(&mut self) -> &mut [u8] ⓘ
Mutable raw packed storage.
Sourcepub fn to_rgba(&self, out: &mut [u8]) -> bool
pub fn to_rgba(&self, out: &mut [u8]) -> bool
Expand the buffer into RGBA using the display palette.
Writes width * height * 4 bytes into out; returns false (and
writes nothing) if out is too small.
Sourcepub fn copy_from(&mut self, other: &Self)
pub fn copy_from(&mut self, other: &Self)
Copy the pixels and display palette of other into this buffer.
Both buffers must have the same dimensions.
Sourcepub fn set_pixel_index(&mut self, x: u32, y: u32, color: C) -> bool
pub fn set_pixel_index(&mut self, x: u32, y: u32, color: C) -> bool
Set a single pixel by palette index. Returns false if out of bounds.
Sourcepub fn get_index(&self, x: u32, y: u32) -> Option<C>
pub fn get_index(&self, x: u32, y: u32) -> Option<C>
Get the palette index of a single pixel. Returns None if out of bounds.
Sourcepub fn clear_index(&mut self, color: C)
pub fn clear_index(&mut self, color: C)
Clear the entire buffer to a single palette index.
Sourcepub fn set_pixel(&mut self, x: u32, y: u32, color: Rgba) -> bool
pub fn set_pixel(&mut self, x: u32, y: u32, color: Rgba) -> bool
Set a single pixel, quantized through the base palette. Returns false if out of 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 current display color of a single pixel (through the display palette). Returns None if out of bounds.
Sourcepub fn clear(&mut self, color: Rgba)
pub fn clear(&mut self, color: Rgba)
Clear the entire buffer to a single color (quantized through the base palette).
Also restores the display palette to the base palette. This mirrors the RGBA buffer’s contract — after a clear the framebuffer is in a pristine state — and is what prevents fade/flash palettes from leaking into the next frame: every frame starts with a clear, so the display mapping always begins from the base and effects re-apply their palette at the end of the frame.
Sourcepub fn fill_rect(
&mut self,
x: u32,
y: u32,
rect_width: u32,
rect_height: u32,
color: Rgba,
)
pub fn fill_rect( &mut self, x: u32, y: u32, rect_width: u32, rect_height: u32, color: Rgba, )
Fill a rectangular region with a color (quantized through the base palette). Coordinates are clamped to buffer bounds.
Source§impl<C: ColorIndex + DefaultPalette> RgbaIndexedFrameBuffer<C>
impl<C: ColorIndex + DefaultPalette> RgbaIndexedFrameBuffer<C>
Sourcepub fn new(config: RenderConfig, clear: Rgba) -> Self
pub fn new(config: RenderConfig, clear: Rgba) -> Self
Create a config-sized buffer using the type’s default base palette,
cleared to clear.
Trait Implementations§
Source§impl<C: Clone + ColorIndex> Clone for RgbaIndexedFrameBuffer<C>
impl<C: Clone + ColorIndex> Clone for RgbaIndexedFrameBuffer<C>
Source§fn clone(&self) -> RgbaIndexedFrameBuffer<C>
fn clone(&self) -> RgbaIndexedFrameBuffer<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 RgbaIndexedFrameBuffer<C>
impl<C: Debug + ColorIndex> Debug for RgbaIndexedFrameBuffer<C>
impl<C: Eq + ColorIndex> Eq for RgbaIndexedFrameBuffer<C>
Source§impl<C: ColorIndex + DefaultPalette> FbSurface for RgbaIndexedFrameBuffer<C>
impl<C: ColorIndex + DefaultPalette> FbSurface for RgbaIndexedFrameBuffer<C>
Source§fn new_screen(width: u32, height: u32) -> Self
fn new_screen(width: u32, height: u32) -> Self
width × height surface, cleared to black.Source§fn set_pixel(&mut self, x: u32, y: u32, color: Rgba) -> bool
fn set_pixel(&mut self, x: u32, y: u32, color: Rgba) -> bool
Source§fn get_pixel(&self, x: u32, y: u32) -> Option<Rgba>
fn get_pixel(&self, x: u32, y: u32) -> Option<Rgba>
Source§fn fill_rect(
&mut self,
x: u32,
y: u32,
rect_width: u32,
rect_height: u32,
color: Rgba,
)
fn fill_rect( &mut self, x: u32, y: u32, rect_width: u32, rect_height: u32, color: Rgba, )
Source§fn present_into(&self, out: &mut [u8])
fn present_into(&self, out: &mut [u8])
out, which must hold
at least width * height * 4 bytes.Source§impl<C: PartialEq + ColorIndex> PartialEq for RgbaIndexedFrameBuffer<C>
impl<C: PartialEq + ColorIndex> PartialEq for RgbaIndexedFrameBuffer<C>
impl<C: PartialEq + ColorIndex> StructuralPartialEq for RgbaIndexedFrameBuffer<C>
Source§impl<C: ColorIndex> TransitionFb for RgbaIndexedFrameBuffer<C>
impl<C: ColorIndex> TransitionFb for RgbaIndexedFrameBuffer<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 RgbaIndexedFrameBuffer<C>
impl<C> RefUnwindSafe for RgbaIndexedFrameBuffer<C>where
C: RefUnwindSafe,
impl<C> Send for RgbaIndexedFrameBuffer<C>where
C: Send,
impl<C> Sync for RgbaIndexedFrameBuffer<C>where
C: Sync,
impl<C> Unpin for RgbaIndexedFrameBuffer<C>where
C: Unpin,
impl<C> UnsafeUnpin for RgbaIndexedFrameBuffer<C>
impl<C> UnwindSafe for RgbaIndexedFrameBuffer<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.