pub struct Framebuffer<const W: usize, const H: usize> { /* private fields */ }Expand description
A W×H RGB565 framebuffer in display wire format.
At 240×135 it is 64 800 bytes, so it should live in a static, never on
the stack. Framebuffer::new is const and all-zero, which places the
buffer in .bss: it costs RAM but no flash. A non-zero initial value
would put 64 KB of initialiser data in the firmware image.
use oxstack_gfx::{Framebuffer, Rgb565};
use embedded_graphics::prelude::*;
static mut FB: Framebuffer<240, 135> = Framebuffer::new();
fb.clear(Rgb565::BLUE).unwrap();
let dirty = fb.take_dirty().unwrap();
assert_eq!((dirty.y, dirty.rows), (0, 135));
assert_eq!(dirty.bytes.len(), 240 * 135 * 2);Implementations§
Source§impl<const W: usize, const H: usize> Framebuffer<W, H>
impl<const W: usize, const H: usize> Framebuffer<W, H>
Sourcepub fn pixel(&self, x: usize, y: usize) -> Option<Rgb565>
pub fn pixel(&self, x: usize, y: usize) -> Option<Rgb565>
Colour at (x, y), or None outside the buffer.
Sourcepub fn mark_all_dirty(&mut self)
pub fn mark_all_dirty(&mut self)
Marks every row as changed, e.g. after the panel lost its contents.
Sourcepub fn take_dirty(&mut self) -> Option<DirtyRows<'_>>
pub fn take_dirty(&mut self) -> Option<DirtyRows<'_>>
Hands out the changed rows and marks the buffer clean. The caller must send them to the display before drawing again.
Sourcepub fn wire_rows_mut(&mut self, rows: Range<usize>) -> &mut [[u16; W]]
pub fn wire_rows_mut(&mut self, rows: Range<usize>) -> &mut [[u16; W]]
Mutable access to rows rows in wire format, for renderers that
write pixels one by one (a 3D rasteriser testing depth per pixel
cannot use fill_solid). Those rows are marked dirty, so a flush
cannot miss them. Store colours converted with wire_color.
§Panics
If rows is out of bounds or decreasing, like slice indexing.
use oxstack_gfx::{Framebuffer, Rgb565, wire_color};
use embedded_graphics::prelude::*;
let mut fb = Framebuffer::<8, 6>::new();
let red = wire_color(Rgb565::RED);
for row in fb.wire_rows_mut(2..4) {
row[1..3].fill(red);
}
assert_eq!(fb.pixel(1, 3), Some(Rgb565::RED));
let dirty = fb.take_dirty().unwrap();
assert_eq!((dirty.y, dirty.rows), (2, 2));