Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Faster char write #446

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 24 additions & 10 deletions Adafruit_GFX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1147,20 +1147,34 @@ 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);
rp++;
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,
size_y * rp, color);
}
rp = 0;
}
} 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);
rb++;
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,
size_y * rb, bg);
}
rb = 0;
}
}
}
}
Expand Down
25 changes: 15 additions & 10 deletions Adafruit_GFX.h
Original file line number Diff line number Diff line change
Expand Up @@ -294,16 +294,21 @@ class Adafruit_GFX_Button {
/**********************************************************************/
bool isPressed(void) { return currstate; };

private:
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];

bool currstate, laststate;
protected:
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; ///< 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
uint16_t _fillcolor; ///< button fill color
uint16_t _textcolor; ///< text color
char _label[10]; ///< text label on button

bool currstate; ///< current pressed state
bool laststate; ///< previous pressed state
};

/// A GFX 1-bit canvas context for graphics
Expand Down
Loading