From caff87ec59ea228faaa634f4d2ad44aa5f19fbb9 Mon Sep 17 00:00:00 2001 From: nathanjshaffer Date: Sat, 30 Dec 2023 15:44:58 -0500 Subject: [PATCH 1/4] Update Adafruit_GFX.h change GFXbutton private members to protected --- Adafruit_GFX.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Adafruit_GFX.h b/Adafruit_GFX.h index 63c6ab68..258c60bb 100644 --- a/Adafruit_GFX.h +++ b/Adafruit_GFX.h @@ -294,7 +294,7 @@ class Adafruit_GFX_Button { /**********************************************************************/ bool isPressed(void) { return currstate; }; -private: +protected: Adafruit_GFX *_gfx; int16_t _x1, _y1; // Coordinates of top-left corner uint16_t _w, _h; From ccdbcbf28017c4e4bac78c23889ede2099a6ae67 Mon Sep 17 00:00:00 2001 From: nathanjshaffer Date: Sat, 6 Jan 2024 11:49:33 -0500 Subject: [PATCH 2/4] Update Adafruit_GFX.cpp reduced drawChar function write time by about half by collecting similar pixels in a column and writing once with faster rect function --- Adafruit_GFX.cpp | 37 ++++++++++++++++++++++++++----------- 1 file changed, 26 insertions(+), 11 deletions(-) diff --git a/Adafruit_GFX.cpp b/Adafruit_GFX.cpp index af989002..27e0bf0c 100644 --- a/Adafruit_GFX.cpp +++ b/Adafruit_GFX.cpp @@ -1147,20 +1147,35 @@ void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c, c++; // Handle 'classic' charset behavior startWrite(); - for (int8_t i = 0; i < 5; i++) { // Char bitmap = 5 columns + int8_t rp, rb;//Count sequential FG and BG pixels in column + for (int8_t i = 0; i < 5; i++, rp=0, rb=0) { // Char bitmap = 5 columns uint8_t line = pgm_read_byte(&font[c * 5 + i]); for (int8_t j = 0; j < 8; j++, line >>= 1) { if (line & 1) { - if (size_x == 1 && size_y == 1) - writePixel(x + i, y + j, color); - else - writeFillRect(x + i * size_x, y + j * size_y, size_x, size_y, - color); - } else if (bg != color) { - if (size_x == 1 && size_y == 1) - writePixel(x + i, y + j, bg); - else - writeFillRect(x + i * size_x, y + j * size_y, size_x, size_y, bg); + rp++; + if (!(1 & (line >> 1))) { //write sequential pixels with writeFillRect + if(rp == 1 && size_x == 1 && size_y == 1) { + writePixel(x + i, y + j, color); + } + else if(rp > 0) { + writeFillRect(x + i * size_x, y + (j - (rp -1)) * size_y, size_x, + size_y * rp, color); + } + rp = 0; + } + } + else if (bg != color) { + rb++; + if( 1 & (line >> 1)) { //write sequential pixels with writeFillRect + if (rb == 1 && size_x == 1 && size_y == 1) { + writePixel(x + i, y + j, bg); + } + else if(rb > 0) { + writeFillRect(x + i * size_x, y + (j - (rb -1)) * size_y, size_x, + size_y * rb, bg); + } + rb = 0; + } } } } From 4e3a95f51703e381e94977b7a0bd1e9959255250 Mon Sep 17 00:00:00 2001 From: nathan Date: Sat, 13 Jan 2024 21:08:42 -0500 Subject: [PATCH 3/4] Update Adafruit_GFX.cpp Bugfix clang Document member variables in Adafruit_GFX_Button corrected compile arrors more clang fixed variable documentation --- Adafruit_GFX.cpp | 25 ++++++++++++------------- Adafruit_GFX.h | 17 ++++++++++------- 2 files changed, 22 insertions(+), 20 deletions(-) diff --git a/Adafruit_GFX.cpp b/Adafruit_GFX.cpp index 27e0bf0c..ceefa7bb 100644 --- a/Adafruit_GFX.cpp +++ b/Adafruit_GFX.cpp @@ -1147,31 +1147,30 @@ void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c, c++; // Handle 'classic' charset behavior startWrite(); - int8_t rp, rb;//Count sequential FG and BG pixels in column - for (int8_t i = 0; i < 5; i++, rp=0, rb=0) { // Char bitmap = 5 columns + int8_t rp, rb; // Count sequential FG and BG pixels in column + for (int8_t i = 0; i < 5; i++, rp = 0, rb = 0) { // Char bitmap = 5 columns uint8_t line = pgm_read_byte(&font[c * 5 + i]); for (int8_t j = 0; j < 8; j++, line >>= 1) { if (line & 1) { rp++; - if (!(1 & (line >> 1))) { //write sequential pixels with writeFillRect - if(rp == 1 && size_x == 1 && size_y == 1) { + if (!(1 & (line >> 1)) || + j == 7) { // write sequential pixels with writeFillRect + if (rp == 1 && size_x == 1 && size_y == 1) { writePixel(x + i, y + j, color); - } - else if(rp > 0) { - writeFillRect(x + i * size_x, y + (j - (rp -1)) * size_y, size_x, + } else if (rp > 0) { + writeFillRect(x + i * size_x, y + (j - (rp - 1)) * size_y, size_x, size_y * rp, color); } rp = 0; } - } - else if (bg != color) { + } else if (bg != color) { rb++; - if( 1 & (line >> 1)) { //write sequential pixels with writeFillRect + if (1 & (line >> 1) || + j == 7) { // write sequential pixels with writeFillRect if (rb == 1 && size_x == 1 && size_y == 1) { writePixel(x + i, y + j, bg); - } - else if(rb > 0) { - writeFillRect(x + i * size_x, y + (j - (rb -1)) * size_y, size_x, + } else if (rb > 0) { + writeFillRect(x + i * size_x, y + (j - (rb - 1)) * size_y, size_x, size_y * rb, bg); } rb = 0; diff --git a/Adafruit_GFX.h b/Adafruit_GFX.h index 258c60bb..a2a1f816 100644 --- a/Adafruit_GFX.h +++ b/Adafruit_GFX.h @@ -295,13 +295,16 @@ class Adafruit_GFX_Button { bool isPressed(void) { return currstate; }; protected: - Adafruit_GFX *_gfx; - int16_t _x1, _y1; // Coordinates of top-left corner - uint16_t _w, _h; - uint8_t _textsize_x; - uint8_t _textsize_y; - uint16_t _outlinecolor, _fillcolor, _textcolor; - char _label[10]; + Adafruit_GFX *_gfx; ///< gfx display pointer + int16_t _x1; ///< x Coordinate of top-left corner + int16_t _y1; ///< y Coordinate of top-left corner + uint16_t _w, _h; ///< width and heaight of button + uint8_t _textsize_x; ///< width of text character in pixels + uint8_t _textsize_y; ///< height of text character in pixels + uint16_t _outlinecolor; ///< button outline color + uint16_t _fillcolor; ///< button fill color + uint16_t _textcolor; ///< text color + char _label[10]; ///< text label on button bool currstate, laststate; }; From 1085844377bf843e60c1403f77374c929bc60fd0 Mon Sep 17 00:00:00 2001 From: nathan Date: Sat, 13 Jan 2024 21:19:49 -0500 Subject: [PATCH 4/4] more variables --- Adafruit_GFX.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Adafruit_GFX.h b/Adafruit_GFX.h index a2a1f816..30ec03ba 100644 --- a/Adafruit_GFX.h +++ b/Adafruit_GFX.h @@ -298,7 +298,8 @@ class Adafruit_GFX_Button { Adafruit_GFX *_gfx; ///< gfx display pointer int16_t _x1; ///< x Coordinate of top-left corner int16_t _y1; ///< y Coordinate of top-left corner - uint16_t _w, _h; ///< width and heaight of button + uint16_t _w; ///< width of button + uint16_t _h; ///< height of button uint8_t _textsize_x; ///< width of text character in pixels uint8_t _textsize_y; ///< height of text character in pixels uint16_t _outlinecolor; ///< button outline color @@ -306,7 +307,8 @@ class Adafruit_GFX_Button { uint16_t _textcolor; ///< text color char _label[10]; ///< text label on button - bool currstate, laststate; + bool currstate; ///< current pressed state + bool laststate; ///< previous pressed state }; /// A GFX 1-bit canvas context for graphics