14#include <idfxx/lcd/panel>
54#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
85 [[nodiscard]]
size_t width() const noexcept {
return _width; }
88 [[nodiscard]]
size_t height() const noexcept {
return _height; }
99 void set_pixel(
size_t x,
size_t y,
bool on)
noexcept {
100 if (x >= _width || y >= _height) {
103 uint8_t&
byte = _data[(y / 8) * _width + x];
104 uint8_t mask =
static_cast<uint8_t
>(1u << (y % 8));
108 byte &=
static_cast<uint8_t
>(~mask);
119 [[nodiscard]]
bool get_pixel(
size_t x,
size_t y)
const noexcept {
120 if (x >= _width || y >= _height) {
123 return (_data[(y / 8) * _width + x] & (1u << (y % 8))) != 0;
130 void fill(
bool on)
noexcept { std::ranges::fill(_data, on ? uint8_t{0xFF} : uint8_t{0x00}); }
144 [[nodiscard]] std::span<const uint8_t>
data() const noexcept {
return _data; }
146#ifdef CONFIG_COMPILER_CXX_EXCEPTIONS
208 return panel.
try_draw_bitmap(0, 0,
static_cast<int>(_width),
static_cast<int>(_height), _data.data());
249 if (x_start >= x_end || x_end > _width || y_start >= y_end || y_end > _height) {
252 size_t first_page = y_start / 8;
253 size_t end_page = (y_end + 7) / 8;
254 if (x_start == 0 && x_end == _width) {
259 static_cast<int>(first_page * 8),
260 static_cast<int>(_width),
261 static_cast<int>(end_page * 8),
262 _data.data() + first_page * _width
265 for (
size_t page = first_page; page < end_page; ++page) {
267 static_cast<int>(x_start),
268 static_cast<int>(page * 8),
269 static_cast<int>(x_end),
270 static_cast<int>((page + 1) * 8),
271 _data.data() + page * _width + x_start
284 , _data(std::move(
data)) {}
288 std::vector<uint8_t> _data;
In-memory framebuffer for monochrome (1 bit per pixel) displays.
bool get_pixel(size_t x, size_t y) const noexcept
Returns the state of a single pixel.
void set_pixel(size_t x, size_t y, bool on) noexcept
Sets or clears a single pixel.
void clear() noexcept
Clears every pixel (equivalent to fill(false)).
void flush(panel &panel) const
Draws the full framebuffer to a panel.
bool pixel_type
The value type written by set_pixel.
size_t height() const noexcept
Returns the height in pixels.
static result< mono_framebuffer > make(size_t width, size_t height)
Creates a framebuffer of the given dimensions, with all pixels off.
void fill(bool on) noexcept
Sets every pixel to the given state.
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_rows(panel &panel, size_t y_start, size_t y_end) const
Draws a horizontal band of the 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.
size_t width() const noexcept
Returns the width in pixels.
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.
mono_framebuffer(size_t width, size_t height)
Creates a framebuffer of the given dimensions, with all pixels off.
result< void > try_flush(panel &panel) const
Draws the full framebuffer to a panel.
std::span< const uint8_t > data() const noexcept
Returns the raw page-packed pixel data.
Abstract base class for LCD panels.
result< void > try_draw_bitmap(int x_start, int y_start, int x_end, int y_end, const void *color_data)
Draws bitmap data to a region of the display.
constexpr std::unexpected< std::error_code > error(E e) noexcept
Creates an unexpected error from an error code enum.
T unwrap(result< T > result)
Throws a std::system_error if the result is an error.
@ invalid_arg
Invalid argument.
std::expected< T, std::error_code > result
result type wrapping a value or error code.