Skip to main content

RgbaIndexedFrameBuffer

Struct RgbaIndexedFrameBuffer 

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

Source

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

Source

pub fn display_palette(&self) -> &Palette<C>

The current display palette.

Source

pub fn set_palette(&mut self, palette: Palette<C>)

Replace the display palette (fade/flash effect).

Source

pub fn reset_palette(&mut self)

Restore the display palette to the base palette.

Source

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

Source

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

Source

pub fn indexed(&self) -> &IndexedFrameBuffer<C>

Read-only access to the underlying indexed buffer.

Source

pub fn indexed_mut(&mut self) -> &mut IndexedFrameBuffer<C>

Mutable access to the underlying indexed buffer (C-index API).

Source

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

Raw packed 2bpp storage (see IndexedFrameBuffer::packed).

Source

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

Mutable raw packed storage.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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

Clear the entire buffer to a single palette index.

Source

pub fn len(&self) -> usize

Total number of pixels.

Source

pub fn width(&self) -> u32

Screen width in pixels.

Source

pub fn height(&self) -> u32

Screen height in pixels.

Source

pub fn is_empty(&self) -> bool

Whether the buffer holds no pixels.

Source

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.

Source

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.

Source

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.

Source

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

pub fn blit_row(&mut self, x: u32, y: u32, src: &[u8], count: u32) -> bool

Copy a horizontal line of RGBA data into the buffer (each pixel quantized through the base palette). src must be exactly count * 4 bytes. Returns false if the line goes out of bounds.

Source

pub fn save_png(&self, path: &Path) -> Result<()>

Save the framebuffer as a PNG file (display palette applied).

Source§

impl<C: ColorIndex + DefaultPalette> RgbaIndexedFrameBuffer<C>

Source

pub fn new(config: RenderConfig, clear: Rgba) -> Self

Create a config-sized buffer using the type’s default base palette, cleared to clear.

Source§

impl RgbaIndexedFrameBuffer<GbColor>

Source

pub fn apply_bgp(&mut self, bgp: u8)

Apply a DMG BGP register byte: display color i becomes the base palette’s shade (bgp >> (2 * i)) & 3. This is exactly how the original hardware performs fades (by writing the BGP register).

Trait Implementations§

Source§

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

Source§

fn clone(&self) -> RgbaIndexedFrameBuffer<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 RgbaIndexedFrameBuffer<C>

Source§

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

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

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

Source§

impl<C: ColorIndex + DefaultPalette> FbSurface for RgbaIndexedFrameBuffer<C>

Source§

fn new_screen(width: u32, height: u32) -> Self

Create a new width × height surface, cleared to black.
Source§

fn width(&self) -> u32

Screen width in pixels.
Source§

fn height(&self) -> u32

Screen height in pixels.
Source§

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

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

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

Get the current color of a single pixel. Returns None if out of bounds.
Source§

fn clear(&mut self, color: Rgba)

Clear the entire surface to a single color.
Source§

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

Fill a rectangular region with a color (clamped to bounds).
Source§

fn present_into(&self, out: &mut [u8])

Dump the whole surface as row-major RGBA into out, which must hold at least width * height * 4 bytes.
Source§

fn pixel_rgba(&self, x: u32, y: u32) -> Rgba

Read a single pixel as RGBA; out-of-bounds reads return transparent.
Source§

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

Source§

fn eq(&self, other: &RgbaIndexedFrameBuffer<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 RgbaIndexedFrameBuffer<C>

Source§

impl<C: ColorIndex> TransitionFb for RgbaIndexedFrameBuffer<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§

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