idfxx 1.0.0
Modern C++23 components for ESP-IDF
Loading...
Searching...
No Matches
idfxx::lcd::rgb565_framebuffer Class Reference

In-memory framebuffer for RGB565 (16 bits per pixel) color displays. More...

Public Types

using pixel_type = rgb565
 The value type written by set_pixel.
 

Public Member Functions

 rgb565_framebuffer (size_t width, size_t height)
 Creates a framebuffer of the given dimensions, with all pixels black.
 
size_t width () const noexcept
 Returns the width in pixels.
 
size_t height () const noexcept
 Returns the height in pixels.
 
void set_pixel (size_t x, size_t y, rgb565 color) noexcept
 Sets a single pixel to the given color.
 
rgb565 get_pixel (size_t x, size_t y) const noexcept
 Returns the color of a single pixel.
 
void fill (rgb565 color) noexcept
 Sets every pixel to the given color.
 
void clear () noexcept
 Sets every pixel to black (equivalent to fill({})).
 
std::span< const rgb565data () const noexcept
 Returns the raw pixel data.
 
void flush (panel &panel, size_t x=0, size_t y=0) const
 Draws the full framebuffer to a panel.
 
void flush_rows (panel &panel, size_t y_start, size_t y_end) const
 Draws a horizontal band of the framebuffer to a panel.
 
void flush_region (panel &panel, size_t x_start, size_t y_start, size_t x_end, size_t y_end) const
 Draws a rectangular region of the framebuffer to a panel.
 
result< void > try_flush (panel &panel, size_t x=0, size_t y=0) const
 Draws the full framebuffer to a panel.
 
result< void > try_flush_rows (panel &panel, size_t y_start, size_t y_end) const
 Draws a horizontal band of the framebuffer to a panel.
 
result< void > try_flush_region (panel &panel, size_t x_start, size_t y_start, size_t x_end, size_t y_end) const
 Draws a rectangular region of the framebuffer to a panel.
 

Static Public Member Functions

static result< rgb565_framebuffermake (size_t width, size_t height)
 Creates a framebuffer of the given dimensions, with all pixels black.
 

Detailed Description

In-memory framebuffer for RGB565 (16 bits per pixel) color displays.

Pixels are stored row-major as rgb565 values (panel byte order), so the buffer can be passed directly to a color panel's draw_bitmap. The pixel (x, y) is at index y * width() + x.

Draw into the framebuffer with set_pixel and friends, then push it to a panel with flush. A full frame at 16 bpp is large (a 240x320 panel needs 150 KB), so the framebuffer may also be sized as a horizontal band and flushed at a destination offset, rendering the frame in slices:

idfxx::lcd::rgb565_framebuffer band(display.width(), 40);
for (size_t y = 0; y < display.height(); y += band.height()) {
band.fill({0, 0, 0});
// ... draw the slice covering rows [y, y + band.height()) ...
band.flush(display, 0, y);
}
In-memory framebuffer for RGB565 (16 bits per pixel) color displays.

This is a plain value type: copyable, movable, and independent of any panel.

Definition at line 53 of file rgb565_framebuffer.hpp.

Member Typedef Documentation

◆ pixel_type

The value type written by set_pixel.

Definition at line 56 of file rgb565_framebuffer.hpp.

Constructor & Destructor Documentation

◆ rgb565_framebuffer()

idfxx::lcd::rgb565_framebuffer::rgb565_framebuffer ( size_t  width,
size_t  height 
)
inline

Creates a framebuffer of the given dimensions, with all pixels black.

Parameters
widthWidth in pixels; must be non-zero.
heightHeight in pixels; must be non-zero.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron error (e.g. invalid dimensions).

Definition at line 68 of file rgb565_framebuffer.hpp.

Member Function Documentation

◆ clear()

void idfxx::lcd::rgb565_framebuffer::clear ( )
inlinenoexcept

Sets every pixel to black (equivalent to fill({})).

Definition at line 131 of file rgb565_framebuffer.hpp.

References fill().

◆ data()

std::span< const rgb565 > idfxx::lcd::rgb565_framebuffer::data ( ) const
inlinenoexcept

Returns the raw pixel data.

The span holds width() * height() values in the row-major layout described in the class documentation, suitable for passing directly to a color panel's draw_bitmap.

Returns
A read-only view of the pixel data.

Definition at line 142 of file rgb565_framebuffer.hpp.

◆ fill()

void idfxx::lcd::rgb565_framebuffer::fill ( rgb565  color)
inlinenoexcept

Sets every pixel to the given color.

Parameters
colorThe color to fill with.

Definition at line 128 of file rgb565_framebuffer.hpp.

Referenced by clear().

◆ flush()

void idfxx::lcd::rgb565_framebuffer::flush ( panel panel,
size_t  x = 0,
size_t  y = 0 
) const
inline

Draws the full framebuffer to a panel.

The framebuffer's top-left corner lands at (x, y) on the panel, so a band-sized framebuffer can render a taller frame in slices. The panel must use the RGB565 format.

Parameters
panelThe panel to draw to.
xDestination column of the framebuffer's left edge.
yDestination row of the framebuffer's top edge.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron error.

Definition at line 158 of file rgb565_framebuffer.hpp.

References try_flush(), and idfxx::unwrap().

◆ flush_region()

void idfxx::lcd::rgb565_framebuffer::flush_region ( panel panel,
size_t  x_start,
size_t  y_start,
size_t  x_end,
size_t  y_end 
) const
inline

Draws a rectangular region of the framebuffer to a panel.

The region spans columns [x_start, x_end) and rows [y_start, y_end), and is drawn to the same coordinates on the panel. Full-width regions transfer in a single draw; narrower regions transfer one draw per row. The panel must use the RGB565 format and should match the framebuffer's dimensions.

Parameters
panelThe panel to draw to.
x_startFirst column of the region, inclusive.
y_startFirst row of the region, inclusive.
x_endEnd column, exclusive; must satisfy x_start < x_end <= width().
y_endEnd row, exclusive; must satisfy y_start < y_end <= height().
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron error (e.g. an invalid region).

Definition at line 192 of file rgb565_framebuffer.hpp.

References try_flush_region(), and idfxx::unwrap().

◆ flush_rows()

void idfxx::lcd::rgb565_framebuffer::flush_rows ( panel panel,
size_t  y_start,
size_t  y_end 
) const
inline

Draws a horizontal band of the framebuffer to a panel.

The band spans rows [y_start, y_end) across the full width, and is drawn to the same rows on the panel. The panel must use the RGB565 format and should match the framebuffer's dimensions.

Parameters
panelThe panel to draw to.
y_startFirst row of the band, inclusive.
y_endEnd row of the band, exclusive; must satisfy y_start < y_end <= height().
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron error (e.g. an invalid row range).

Definition at line 173 of file rgb565_framebuffer.hpp.

References try_flush_rows(), and idfxx::unwrap().

◆ get_pixel()

rgb565 idfxx::lcd::rgb565_framebuffer::get_pixel ( size_t  x,
size_t  y 
) const
inlinenoexcept

Returns the color of a single pixel.

Parameters
xColumn, in [0, width()).
yRow, in [0, height()).
Returns
The pixel's color, or black if the coordinates are out of range.

Definition at line 117 of file rgb565_framebuffer.hpp.

◆ height()

size_t idfxx::lcd::rgb565_framebuffer::height ( ) const
inlinenoexcept

Returns the height in pixels.

Definition at line 92 of file rgb565_framebuffer.hpp.

Referenced by make().

◆ make()

static result< rgb565_framebuffer > idfxx::lcd::rgb565_framebuffer::make ( size_t  width,
size_t  height 
)
inlinestatic

Creates a framebuffer of the given dimensions, with all pixels black.

Parameters
widthWidth in pixels; must be non-zero.
heightHeight in pixels; must be non-zero.
Returns
The new rgb565_framebuffer, or an error.
Return values
idfxx::errc::invalid_argif width or height is zero.

Definition at line 81 of file rgb565_framebuffer.hpp.

References idfxx::error(), height(), idfxx::invalid_arg, and width().

◆ set_pixel()

void idfxx::lcd::rgb565_framebuffer::set_pixel ( size_t  x,
size_t  y,
rgb565  color 
)
inlinenoexcept

Sets a single pixel to the given color.

Out-of-range coordinates are ignored.

Parameters
xColumn, in [0, width()).
yRow, in [0, height()).
colorThe color to write.

Definition at line 103 of file rgb565_framebuffer.hpp.

◆ try_flush()

result< void > idfxx::lcd::rgb565_framebuffer::try_flush ( panel panel,
size_t  x = 0,
size_t  y = 0 
) const
inline

Draws the full framebuffer to a panel.

The framebuffer's top-left corner lands at (x, y) on the panel, so a band-sized framebuffer can render a taller frame in slices. The panel must use the RGB565 format.

Parameters
panelThe panel to draw to.
xDestination column of the framebuffer's left edge.
yDestination row of the framebuffer's top edge.
Returns
Success, or an error.

Definition at line 209 of file rgb565_framebuffer.hpp.

References idfxx::lcd::panel::try_draw_bitmap().

Referenced by flush().

◆ try_flush_region()

result< void > idfxx::lcd::rgb565_framebuffer::try_flush_region ( panel panel,
size_t  x_start,
size_t  y_start,
size_t  x_end,
size_t  y_end 
) const
inline

Draws a rectangular region of the framebuffer to a panel.

The region spans columns [x_start, x_end) and rows [y_start, y_end), and is drawn to the same coordinates on the panel. Full-width regions transfer in a single draw; narrower regions transfer one draw per row. The panel must use the RGB565 format and should match the framebuffer's dimensions.

Parameters
panelThe panel to draw to.
x_startFirst column of the region, inclusive.
y_startFirst row of the region, inclusive.
x_endEnd column, exclusive; must satisfy x_start < x_end <= width().
y_endEnd row, exclusive; must satisfy y_start < y_end <= height().
Returns
Success, or an error.
Return values
idfxx::errc::invalid_argif the region is invalid.

Definition at line 254 of file rgb565_framebuffer.hpp.

References idfxx::error(), idfxx::invalid_arg, and idfxx::lcd::panel::try_draw_bitmap().

Referenced by flush_region(), and try_flush_rows().

◆ try_flush_rows()

result< void > idfxx::lcd::rgb565_framebuffer::try_flush_rows ( panel panel,
size_t  y_start,
size_t  y_end 
) const
inline

Draws a horizontal band of the framebuffer to a panel.

The band spans rows [y_start, y_end) across the full width, and is drawn to the same rows on the panel. The panel must use the RGB565 format and should match the framebuffer's dimensions.

Parameters
panelThe panel to draw to.
y_startFirst row of the band, inclusive.
y_endEnd row of the band, exclusive; must satisfy y_start < y_end <= height().
Returns
Success, or an error.
Return values
idfxx::errc::invalid_argif the row range is invalid.

Definition at line 232 of file rgb565_framebuffer.hpp.

References try_flush_region().

Referenced by flush_rows().

◆ width()

size_t idfxx::lcd::rgb565_framebuffer::width ( ) const
inlinenoexcept

Returns the width in pixels.

Definition at line 89 of file rgb565_framebuffer.hpp.

Referenced by make().


The documentation for this class was generated from the following file: