libepaper 2.0.0
A C++23 library for controlling Waveshare e-paper displays on Raspberry Pi, featuring transparent sleep/wake management and a fluent builder API.
Loading...
Searching...
No Matches
framebuffer.hpp
Go to the documentation of this file.
1#pragma once
2
7#include <array>
8#include <cstddef>
9#include <span>
10#include <vector>
11
12namespace epaper {
13
52public:
60 MonoFramebuffer(std::size_t width, std::size_t height, DisplayMode mode);
61
63 [[nodiscard]] auto width() const -> std::size_t;
65 [[nodiscard]] auto height() const -> std::size_t;
67 [[nodiscard]] auto mode() const -> DisplayMode;
69 [[nodiscard]] auto data() const -> std::span<const std::byte>;
71 [[nodiscard]] auto get_planes() const -> std::vector<std::span<const std::byte>>;
79 auto set_pixel(std::size_t x, std::size_t y, Color color, Orientation orientation) -> void;
87 [[nodiscard]] auto get_pixel(std::size_t x, std::size_t y, Orientation orientation) const -> Color;
92 auto clear(Color color) -> void;
93
99 [[nodiscard]] static constexpr auto supports_mode(DisplayMode mode) noexcept -> bool {
101 }
102
103private:
104 std::size_t width_;
105 std::size_t height_;
106 std::size_t stride_{0};
107 DisplayMode mode_;
108 std::vector<std::byte> buffer_;
109};
110
151template <internal::PlaneCount PlaneCount> class MultiPlaneFramebuffer {
152public:
160 MultiPlaneFramebuffer(std::size_t width, std::size_t height, DisplayMode mode);
161
163 [[nodiscard]] auto width() const -> std::size_t;
165 [[nodiscard]] auto height() const -> std::size_t;
167 [[nodiscard]] auto mode() const -> DisplayMode;
169 [[nodiscard]] auto data() const -> std::span<const std::byte>;
171 [[nodiscard]] auto get_planes() const -> std::vector<std::span<const std::byte>>;
179 auto set_pixel(std::size_t x, std::size_t y, Color color, Orientation orientation) -> void;
187 [[nodiscard]] auto get_pixel(std::size_t x, std::size_t y, Orientation orientation) const -> Color;
192 auto clear(Color color) -> void;
193
199 [[nodiscard]] static constexpr auto supports_mode(DisplayMode mode) noexcept -> bool {
200 return num_planes(mode) == internal::plane_count_value(PlaneCount);
201 }
202
203private:
204 static constexpr std::size_t PLANE_COUNT = internal::plane_count_value(PlaneCount);
205 std::size_t width_;
206 std::size_t height_;
207 std::size_t stride_;
208 DisplayMode mode_;
209 std::array<std::vector<std::byte>, PLANE_COUNT> planes_;
210};
211
214
217
218} // namespace epaper
Definition framebuffer.hpp:51
auto data() const -> std::span< const std::byte >
Get raw buffer as a byte span.
Definition mono_framebuffer.cpp:63
auto clear(Color color) -> void
Clear the framebuffer to a color.
Definition mono_framebuffer.cpp:265
auto mode() const -> DisplayMode
Get display mode represented by this framebuffer.
Definition mono_framebuffer.cpp:61
static constexpr auto supports_mode(DisplayMode mode) noexcept -> bool
Check if the mode is compatible with mono framebuffer.
Definition framebuffer.hpp:99
auto height() const -> std::size_t
Get framebuffer height in pixels.
Definition mono_framebuffer.cpp:59
auto get_pixel(std::size_t x, std::size_t y, Orientation orientation) const -> Color
Get a pixel color with orientation transform.
Definition mono_framebuffer.cpp:190
auto get_planes() const -> std::vector< std::span< const std::byte > >
Get plane spans (single plane for mono).
Definition mono_framebuffer.cpp:65
auto width() const -> std::size_t
Get framebuffer width in pixels.
Definition mono_framebuffer.cpp:57
auto set_pixel(std::size_t x, std::size_t y, Color color, Orientation orientation) -> void
Set a pixel with orientation transform.
Definition mono_framebuffer.cpp:67
Definition framebuffer.hpp:151
static constexpr auto supports_mode(DisplayMode mode) noexcept -> bool
Check if the mode is compatible with this plane count.
Definition framebuffer.hpp:199
auto clear(Color color) -> void
Clear the framebuffer to a color.
Definition multi_plane_framebuffer.cpp:125
auto set_pixel(std::size_t x, std::size_t y, Color color, Orientation orientation) -> void
Set a pixel with orientation transform.
Definition multi_plane_framebuffer.cpp:53
auto height() const -> std::size_t
Get framebuffer height in pixels.
Definition multi_plane_framebuffer.cpp:29
auto get_planes() const -> std::vector< std::span< const std::byte > >
Get plane spans (one per plane).
Definition multi_plane_framebuffer.cpp:43
auto width() const -> std::size_t
Get framebuffer width in pixels.
Definition multi_plane_framebuffer.cpp:25
auto mode() const -> DisplayMode
Get display mode represented by this framebuffer.
Definition multi_plane_framebuffer.cpp:33
auto get_pixel(std::size_t x, std::size_t y, Orientation orientation) const -> Color
Get a pixel color with orientation transform.
Definition multi_plane_framebuffer.cpp:107
auto data() const -> std::span< const std::byte >
Get raw buffer as a byte span (first plane).
Definition multi_plane_framebuffer.cpp:38
Definition framebuffer_concepts.hpp:60
Internal utilities for libepaper implementation details.
constexpr auto plane_count_value(PlaneCount count) noexcept -> std::size_t
Definition internal.hpp:63
constexpr std::size_t PLANE_COUNT_ONE
Number of planes for single-plane displays (BW, Gray4, Spectra6)
Definition internal.hpp:23
Definition color.hpp:5
constexpr auto num_planes(DisplayMode mode) noexcept -> std::size_t
Get number of color planes required for a display mode.
Definition driver.hpp:97
Orientation
Definition types.hpp:66
Color
Definition types.hpp:32
DisplayMode
Definition driver.hpp:46