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

In-memory framebuffer for 4-level grayscale ePaper displays. More...

Public Types

using pixel_type = gray4
 The value type written by set_pixel.
 

Public Member Functions

 gray4_framebuffer (size_t width, size_t height)
 Creates a framebuffer of the given dimensions, with all pixels white.
 
size_t width () const noexcept
 Returns the width in pixels.
 
size_t height () const noexcept
 Returns the height in pixels.
 
size_t stride_bytes () const noexcept
 Returns the number of bytes per row within each plane.
 
void set_pixel (size_t x, size_t y, gray4 level) noexcept
 Sets a single pixel to the given gray level.
 
gray4 get_pixel (size_t x, size_t y) const noexcept
 Returns the gray level of a single pixel.
 
void fill (gray4 level) noexcept
 Sets every pixel to the given gray level.
 
void clear () noexcept
 Blanks every pixel to white (equivalent to fill(gray4::white)).
 
std::span< const uint8_t > plane (size_t index) const noexcept
 Returns the raw pixel data of one plane.
 
std::span< const uint8_t > plane_row (size_t index, size_t y) const noexcept
 Returns the raw bytes of a single row of one plane.
 
void flush (panel &panel, size_t x=0, size_t y=0) const
 Uploads the full framebuffer to a panel's RAM.
 
void flush_rows (panel &panel, size_t y_start, size_t y_end) const
 Uploads a horizontal band of the framebuffer to a panel's RAM.
 
result< void > try_flush (panel &panel, size_t x=0, size_t y=0) const
 Uploads the full framebuffer to a panel's RAM.
 
result< void > try_flush_rows (panel &panel, size_t y_start, size_t y_end) const
 Uploads a horizontal band of the framebuffer to a panel's RAM.
 

Static Public Member Functions

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

Detailed Description

In-memory framebuffer for 4-level grayscale ePaper displays.

Each pixel is a gray4 level (2 bits). The levels are stored as two separate 1-bit-per-pixel planes — plane 0 holds bit 0 of each pixel's level, plane 1 holds bit 1 — because that is how ePaper controllers consume grayscale data: one plane per controller RAM bank. Within each plane the layout matches mono_framebuffer — row-major, MSB-first, with rows padded to whole bytes (stride_bytes).

A new framebuffer starts all-white (gray4::white, level 0), so generic drawing code that clears with a value-initialized pixel (e.g. idfxx::gfx::canvas::clear) clears to blank paper.

Draw into the framebuffer with set_pixel and friends, then upload it to a panel's RAM with flush or flush_rows, and make it visible with panel::refresh. This is a plain value type: copyable, movable, and independent of any panel.

display.set_color_mode(idfxx::epaper::color_mode::gray4);
idfxx::epaper::gray4_framebuffer fb(display.width(), display.height());
fb.set_pixel(10, 20, idfxx::epaper::gray4::dark);
fb.flush(display);
display.refresh();
In-memory framebuffer for 4-level grayscale ePaper displays.
@ gray4
2 bits per pixel, 4 gray levels (gray4_framebuffer).

Definition at line 58 of file gray4_framebuffer.hpp.

Member Typedef Documentation

◆ pixel_type

The value type written by set_pixel.

Definition at line 61 of file gray4_framebuffer.hpp.

Constructor & Destructor Documentation

◆ gray4_framebuffer()

idfxx::epaper::gray4_framebuffer::gray4_framebuffer ( size_t  width,
size_t  height 
)
inline

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

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 73 of file gray4_framebuffer.hpp.

Member Function Documentation

◆ clear()

void idfxx::epaper::gray4_framebuffer::clear ( )
inlinenoexcept

Blanks every pixel to white (equivalent to fill(gray4::white)).

Definition at line 167 of file gray4_framebuffer.hpp.

References fill(), and idfxx::epaper::white.

◆ fill()

void idfxx::epaper::gray4_framebuffer::fill ( gray4  level)
inlinenoexcept

Sets every pixel to the given gray level.

Parameters
levelThe gray level to fill with.

Definition at line 158 of file gray4_framebuffer.hpp.

Referenced by clear().

◆ flush()

void idfxx::epaper::gray4_framebuffer::flush ( panel panel,
size_t  x = 0,
size_t  y = 0 
) const
inline

Uploads the full framebuffer to a panel's RAM.

Places the framebuffer's origin at panel pixel (x, y). The upload is invisible until the next panel::refresh. The panel must be operating in color_mode::gray4.

Parameters
panelThe panel to upload to.
xDestination column; must be a multiple of 8.
yDestination row.
Note
Only available when CONFIG_COMPILER_CXX_EXCEPTIONS is enabled in menuconfig.
Exceptions
std::system_erroron error.

Definition at line 214 of file gray4_framebuffer.hpp.

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

◆ flush_rows()

void idfxx::epaper::gray4_framebuffer::flush_rows ( panel panel,
size_t  y_start,
size_t  y_end 
) const
inline

Uploads a horizontal band of the framebuffer to a panel's RAM.

The band spans rows [y_start, y_end) across the full width and lands at the same rows on the panel. The upload is invisible until the next panel::refresh. The panel must be operating in color_mode::gray4.

Parameters
panelThe panel to upload 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 230 of file gray4_framebuffer.hpp.

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

◆ get_pixel()

gray4 idfxx::epaper::gray4_framebuffer::get_pixel ( size_t  x,
size_t  y 
) const
inlinenoexcept

Returns the gray level of a single pixel.

Parameters
xColumn, in [0, width()).
yRow, in [0, height()).
Returns
The pixel's gray level; gray4::white if the coordinates are out of range.

Definition at line 138 of file gray4_framebuffer.hpp.

References stride_bytes(), and idfxx::epaper::white.

◆ height()

size_t idfxx::epaper::gray4_framebuffer::height ( ) const
inlinenoexcept

Returns the height in pixels.

Definition at line 98 of file gray4_framebuffer.hpp.

Referenced by make().

◆ make()

static result< gray4_framebuffer > idfxx::epaper::gray4_framebuffer::make ( size_t  width,
size_t  height 
)
inlinestatic

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

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

Definition at line 86 of file gray4_framebuffer.hpp.

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

◆ plane()

std::span< const uint8_t > idfxx::epaper::gray4_framebuffer::plane ( size_t  index) const
inlinenoexcept

Returns the raw pixel data of one plane.

Each plane holds stride_bytes() * height() bytes in the row-major MSB-first layout described in the class documentation. Plane 0 holds bit 0 of each pixel's gray level, plane 1 holds bit 1.

Unlike set_pixel / get_pixel, the raw views do not tolerate out-of-range arguments: passing one is undefined behavior.

Parameters
indexThe plane to view: 0 or 1.
Returns
A read-only view of the plane's pixel data.

Definition at line 182 of file gray4_framebuffer.hpp.

Referenced by plane_row().

◆ plane_row()

std::span< const uint8_t > idfxx::epaper::gray4_framebuffer::plane_row ( size_t  index,
size_t  y 
) const
inlinenoexcept

Returns the raw bytes of a single row of one plane.

Unlike set_pixel / get_pixel, the raw views do not tolerate out-of-range arguments: passing one is undefined behavior.

Parameters
indexThe plane to view: 0 or 1.
yRow, in [0, height()).
Returns
A read-only view of the row's stride_bytes bytes.

Definition at line 196 of file gray4_framebuffer.hpp.

References plane(), and stride_bytes().

◆ set_pixel()

void idfxx::epaper::gray4_framebuffer::set_pixel ( size_t  x,
size_t  y,
gray4  level 
)
inlinenoexcept

Sets a single pixel to the given gray level.

Out-of-range coordinates are ignored.

Parameters
xColumn, in [0, width()).
yRow, in [0, height()).
levelThe gray level to write.

Definition at line 119 of file gray4_framebuffer.hpp.

References stride_bytes().

◆ stride_bytes()

size_t idfxx::epaper::gray4_framebuffer::stride_bytes ( ) const
inlinenoexcept

Returns the number of bytes per row within each plane.

Rows are padded to whole bytes: (width() + 7) / 8. Padding bits sit past the right edge and stay white.

Returns
The row stride, in bytes.

Definition at line 108 of file gray4_framebuffer.hpp.

Referenced by get_pixel(), plane_row(), and set_pixel().

◆ try_flush()

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

Uploads the full framebuffer to a panel's RAM.

Places the framebuffer's origin at panel pixel (x, y). The upload is invisible until the next panel::try_refresh. The panel must be operating in color_mode::gray4.

Parameters
panelThe panel to upload to.
xDestination column; must be a multiple of 8.
yDestination row.
Returns
Success, or an error.

Definition at line 245 of file gray4_framebuffer.hpp.

References idfxx::epaper::panel::try_write().

Referenced by flush().

◆ try_flush_rows()

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

Uploads a horizontal band of the framebuffer to a panel's RAM.

The band spans rows [y_start, y_end) across the full width and lands at the same rows on the panel. The upload is invisible until the next panel::try_refresh. The panel must be operating in color_mode::gray4.

Parameters
panelThe panel to upload 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 263 of file gray4_framebuffer.hpp.

References idfxx::epaper::panel::try_write_rows().

Referenced by flush_rows().

◆ width()

size_t idfxx::epaper::gray4_framebuffer::width ( ) const
inlinenoexcept

Returns the width in pixels.

Definition at line 95 of file gray4_framebuffer.hpp.

Referenced by make().


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