From 3dc34ef835783cb522cb39ac3eb56ee13cfd5653 Mon Sep 17 00:00:00 2001 From: YariKartoshe4ka Date: Wed, 11 Jan 2023 22:06:30 +0300 Subject: [PATCH 1/2] Optimize Arduboy2Base::drawFastVLine --- src/Arduboy2.cpp | 24 ++++++++++++++++++++---- 1 file changed, 20 insertions(+), 4 deletions(-) diff --git a/src/Arduboy2.cpp b/src/Arduboy2.cpp index 552828d..fc00431 100644 --- a/src/Arduboy2.cpp +++ b/src/Arduboy2.cpp @@ -547,12 +547,28 @@ void Arduboy2Base::drawRect void Arduboy2Base::drawFastVLine (int16_t x, int16_t y, uint8_t h, uint8_t color) { - int end = y+h; - for (int a = max(0,y); a < min(end,HEIGHT); a++) + if (x < 0 || x >= WIDTH || y >= HEIGHT) return; + + color = (color == WHITE ? ~0 : 0); + + if (y < 0) { - drawPixel(x,a,color); + h += y; + y = 0; } -} + + int16_t end = y + h; + + sBuffer[(y & 0xf8) * WIDTH / 8 + x] = color << (y - (y & 0xf8)); + + for (uint8_t i = max(y + 7, 0); i < min(end, HEIGHT); i += 8) + { + sBuffer[(i & 0xf8) * WIDTH / 8 + x] = color; + } + + sBuffer[(min(end, HEIGHT - 1) & 0xf8) * WIDTH / 8 + x] = color >> (8 - (min(end, HEIGHT - 1) & 7)); +}; + void Arduboy2Base::drawFastHLine (int16_t x, int16_t y, uint8_t w, uint8_t color) From 8db5f35a4eb88ce631ccfeb12898d4fd0967c293 Mon Sep 17 00:00:00 2001 From: YariKartoshe4ka Date: Thu, 12 Jan 2023 15:22:07 +0300 Subject: [PATCH 2/2] Fix bug with overwriting --- src/Arduboy2.cpp | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/src/Arduboy2.cpp b/src/Arduboy2.cpp index fc00431..0f77e4c 100644 --- a/src/Arduboy2.cpp +++ b/src/Arduboy2.cpp @@ -558,15 +558,21 @@ void Arduboy2Base::drawFastVLine } int16_t end = y + h; + uint8_t data, colorUp = 0xff << (y - (y & 0xf8)), + colorDown = 0xff >> (8 - (min(end, HEIGHT - 1) & 7)); - sBuffer[(y & 0xf8) * WIDTH / 8 + x] = color << (y - (y & 0xf8)); + data = sBuffer[(y & 0xf8) * WIDTH / 8 + x] | colorUp; + if (!color) data ^= colorUp; + sBuffer[(y & 0xf8) * WIDTH / 8 + x] = data; - for (uint8_t i = max(y + 7, 0); i < min(end, HEIGHT); i += 8) + for (uint8_t i = max(y + 7, 0) & 0xf8; i <= min(end, HEIGHT - 1) - 7; i += 8) { - sBuffer[(i & 0xf8) * WIDTH / 8 + x] = color; + sBuffer[i * WIDTH / 8 + x] = color; } - sBuffer[(min(end, HEIGHT - 1) & 0xf8) * WIDTH / 8 + x] = color >> (8 - (min(end, HEIGHT - 1) & 7)); + data = sBuffer[(min(end, HEIGHT - 1) & 0xf8) * WIDTH / 8 + x] | colorDown; + if (!color) data ^= colorDown; + sBuffer[(min(end, HEIGHT - 1) & 0xf8) * WIDTH / 8 + x] = data; };