mirror of
https://github.com/slint-ui/slint.git
synced 2025-09-26 11:59:29 +00:00
esp-idf: Rename SlintPlatformConfiguration's color_swap to byte_swap and deprecate color_swap_16
This commit is contained in:
parent
287bd922a4
commit
f5909807ea
6 changed files with 16 additions and 16 deletions
|
@ -30,7 +30,7 @@ Make sure that the stack is big enough (~8KiB), and that all the RAM was made av
|
||||||
If colors look inverted on your display, it may be an incompatibility between how RGB565 colors are ordered in little-endian
|
If colors look inverted on your display, it may be an incompatibility between how RGB565 colors are ordered in little-endian
|
||||||
and your display expecting a different byte order. Typically, esp32 devices are little ending and display controllers often
|
and your display expecting a different byte order. Typically, esp32 devices are little ending and display controllers often
|
||||||
expect big-endian or `esp_lcd` configures them accordingly. Therefore, by default Slint converts pixels to big-endian.
|
expect big-endian or `esp_lcd` configures them accordingly. Therefore, by default Slint converts pixels to big-endian.
|
||||||
If your display controller expects little endian, set the `color_swap_16` field in `SlintPlatformConfiguration` to `false`.
|
If your display controller expects little endian, set the `byte_swap` field in `SlintPlatformConfiguration` to `false`.
|
||||||
|
|
||||||
## Errors about multiple symbol definitions when linking
|
## Errors about multiple symbol definitions when linking
|
||||||
|
|
||||||
|
|
|
@ -80,7 +80,7 @@ extern "C" void app_main(void)
|
||||||
.panel_handle = panel_handle,
|
.panel_handle = panel_handle,
|
||||||
.touch_handle = touch_handle,
|
.touch_handle = touch_handle,
|
||||||
.buffer1 = buffer,
|
.buffer1 = buffer,
|
||||||
.color_swap_16 = true });
|
.byte_swap = true });
|
||||||
|
|
||||||
/* Instantiate the UI */
|
/* Instantiate the UI */
|
||||||
auto ui = AppWindow::create();
|
auto ui = AppWindow::create();
|
||||||
|
|
|
@ -58,8 +58,8 @@ struct SlintPlatformConfiguration
|
||||||
/// Swap the 2 bytes of RGB 565 pixels before sending to the display, or turn 24-bit RGB into
|
/// Swap the 2 bytes of RGB 565 pixels before sending to the display, or turn 24-bit RGB into
|
||||||
/// BGR. Use this if your CPU is little endian but the display expects big-endian.
|
/// BGR. Use this if your CPU is little endian but the display expects big-endian.
|
||||||
union {
|
union {
|
||||||
bool color_swap_16;
|
[[deprecated("Renamed to byte_swap")]] bool color_swap_16;
|
||||||
bool color_swap = false;
|
bool byte_swap = false;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ struct EspPlatform : public slint::platform::Platform
|
||||||
touch_handle(config.touch_handle),
|
touch_handle(config.touch_handle),
|
||||||
buffer1(config.buffer1),
|
buffer1(config.buffer1),
|
||||||
buffer2(config.buffer2),
|
buffer2(config.buffer2),
|
||||||
color_swap(config.color_swap),
|
byte_swap(config.byte_swap),
|
||||||
rotation(config.rotation)
|
rotation(config.rotation)
|
||||||
{
|
{
|
||||||
#if !defined(SLINT_FEATURE_EXPERIMENTAL)
|
#if !defined(SLINT_FEATURE_EXPERIMENTAL)
|
||||||
|
@ -72,7 +72,7 @@ private:
|
||||||
esp_lcd_touch_handle_t touch_handle;
|
esp_lcd_touch_handle_t touch_handle;
|
||||||
std::optional<std::span<PixelType>> buffer1;
|
std::optional<std::span<PixelType>> buffer1;
|
||||||
std::optional<std::span<PixelType>> buffer2;
|
std::optional<std::span<PixelType>> buffer2;
|
||||||
bool color_swap;
|
bool byte_swap;
|
||||||
slint::platform::SoftwareRenderer::RenderingRotation rotation;
|
slint::platform::SoftwareRenderer::RenderingRotation rotation;
|
||||||
class EspWindowAdapter<PixelType> *m_window = nullptr;
|
class EspWindowAdapter<PixelType> *m_window = nullptr;
|
||||||
|
|
||||||
|
@ -122,13 +122,13 @@ extern "C" bool on_vsync_event(esp_lcd_panel_handle_t panel,
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace {
|
namespace {
|
||||||
void swap_colors(slint::platform::Rgb565Pixel *pixel)
|
void byte_swap_color(slint::platform::Rgb565Pixel *pixel)
|
||||||
{
|
{
|
||||||
// Swap endianness to big endian
|
// Swap endianness to big endian
|
||||||
auto px = reinterpret_cast<uint16_t *>(pixel);
|
auto px = reinterpret_cast<uint16_t *>(pixel);
|
||||||
*px = (*px << 8) | (*px >> 8);
|
*px = (*px << 8) | (*px >> 8);
|
||||||
}
|
}
|
||||||
void swap_colors(slint::Rgb8Pixel *pixel)
|
void byte_swap_color(slint::Rgb8Pixel *pixel)
|
||||||
{
|
{
|
||||||
std::swap(pixel->r, pixel->b);
|
std::swap(pixel->r, pixel->b);
|
||||||
}
|
}
|
||||||
|
@ -240,11 +240,11 @@ void EspPlatform<PixelType>::run_event_loop()
|
||||||
auto region = m_window->m_renderer.render(buffer1.value(),
|
auto region = m_window->m_renderer.render(buffer1.value(),
|
||||||
rotated ? size.height : size.width);
|
rotated ? size.height : size.width);
|
||||||
|
|
||||||
if (color_swap) {
|
if (byte_swap) {
|
||||||
for (auto [o, s] : region.rectangles()) {
|
for (auto [o, s] : region.rectangles()) {
|
||||||
for (int y = o.y; y < o.y + s.height; y++) {
|
for (int y = o.y; y < o.y + s.height; y++) {
|
||||||
for (int x = o.x; x < o.x + s.width; x++) {
|
for (int x = o.x; x < o.x + s.width; x++) {
|
||||||
swap_colors(&buffer1.value()[y * size.width + x]);
|
byte_swap_color(&buffer1.value()[y * size.width + x]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -285,10 +285,10 @@ void EspPlatform<PixelType>::run_event_loop()
|
||||||
std::span<slint::platform::Rgb565Pixel> view { lb.get(),
|
std::span<slint::platform::Rgb565Pixel> view { lb.get(),
|
||||||
line_end - line_start };
|
line_end - line_start };
|
||||||
render_fn(view);
|
render_fn(view);
|
||||||
if (color_swap) {
|
if (byte_swap) {
|
||||||
// Swap endianness to big endian
|
// Swap endianness to big endian
|
||||||
std::for_each(view.begin(), view.end(),
|
std::for_each(view.begin(), view.end(),
|
||||||
[](auto &rgbpix) { swap_colors(&rgbpix); });
|
[](auto &rgbpix) { byte_swap_color(&rgbpix); });
|
||||||
}
|
}
|
||||||
esp_lcd_panel_draw_bitmap(panel_handle, line_start, line_y, line_end,
|
esp_lcd_panel_draw_bitmap(panel_handle, line_start, line_y, line_end,
|
||||||
line_y + 1, lb.get());
|
line_y + 1, lb.get());
|
||||||
|
@ -349,8 +349,8 @@ void slint_esp_init(slint::PhysicalSize size, esp_lcd_panel_handle_t panel,
|
||||||
.buffer1 = buffer1,
|
.buffer1 = buffer1,
|
||||||
.buffer2 = buffer2,
|
.buffer2 = buffer2,
|
||||||
// For compatibility with earlier versions of Slint, we compute the value of
|
// For compatibility with earlier versions of Slint, we compute the value of
|
||||||
// color_swap_16 the way it was implemented in Slint (slint-esp) <= 1.6.0:
|
// byte_swap the way it was implemented in Slint (slint-esp) <= 1.6.0:
|
||||||
.color_swap_16 = buffer2.has_value()
|
.byte_swap = buffer2.has_value()
|
||||||
};
|
};
|
||||||
slint_esp_init(config);
|
slint_esp_init(config);
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,7 +56,7 @@ extern "C" void app_main(void)
|
||||||
.panel_handle = panel_handle,
|
.panel_handle = panel_handle,
|
||||||
.touch_handle = touch_handle,
|
.touch_handle = touch_handle,
|
||||||
.buffer1 = buffer,
|
.buffer1 = buffer,
|
||||||
.color_swap_16 = true });
|
.byte_swap = true });
|
||||||
|
|
||||||
auto printer_demo = MainWindow::create();
|
auto printer_demo = MainWindow::create();
|
||||||
printer_demo->set_ink_levels(std::make_shared<InkLevelModel>());
|
printer_demo->set_ink_levels(std::make_shared<InkLevelModel>());
|
||||||
|
|
|
@ -52,7 +52,7 @@ extern "C" void app_main(void)
|
||||||
.panel_handle = panel_handle,
|
.panel_handle = panel_handle,
|
||||||
.touch_handle = touch_handle,
|
.touch_handle = touch_handle,
|
||||||
.buffer1 = buffer,
|
.buffer1 = buffer,
|
||||||
.color_swap_16 = true });
|
.byte_swap = true });
|
||||||
|
|
||||||
auto carousel_demo = MainWindow::create();
|
auto carousel_demo = MainWindow::create();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue