Optimized drwChar and drawCircleHelper

This commit is contained in:
Laurence Bank 2020-06-06 18:51:57 -04:00
parent 1232016e3b
commit 1b93789997

View File

@ -411,6 +411,7 @@ void Adafruit_GFX::drawCircleHelper(int16_t x0, int16_t y0, int16_t r,
int16_t ddF_y = -2 * r; int16_t ddF_y = -2 * r;
int16_t x = 0; int16_t x = 0;
int16_t y = r; int16_t y = r;
int xold = x;
while (x < y) { while (x < y) {
if (f >= 0) { if (f >= 0) {
@ -421,22 +422,25 @@ void Adafruit_GFX::drawCircleHelper(int16_t x0, int16_t y0, int16_t r,
x++; x++;
ddF_x += 2; ddF_x += 2;
f += ddF_x; f += ddF_x;
if (f >= 0 || x == y) { // time to draw the new line segment
if (cornername & 0x4) { if (cornername & 0x4) {
writePixel(x0 + x, y0 + y, color); drawFastHLine(x0 + xold+1, y0 + y, x-xold, color);
writePixel(x0 + y, y0 + x, color); drawFastVLine(x0 + y, y0 + xold+1, x-xold, color);
} }
if (cornername & 0x2) { if (cornername & 0x2) {
writePixel(x0 + x, y0 - y, color); drawFastHLine(x0 + xold+1, y0 - y, x-xold, color);
writePixel(x0 + y, y0 - x, color); drawFastVLine(x0 + y, y0 - x, x-xold, color);
} }
if (cornername & 0x8) { if (cornername & 0x8) {
writePixel(x0 - y, y0 + x, color); drawFastVLine(x0 - y, y0 + xold+1, x-xold, color);
writePixel(x0 - x, y0 + y, color); drawFastHLine(x0 - x, y0 + y, x-xold, color);
} }
if (cornername & 0x1) { if (cornername & 0x1) {
writePixel(x0 - y, y0 - x, color); drawFastVLine(x0 - y, y0 - x, x-xold, color);
writePixel(x0 - x, y0 - y, color); drawFastHLine(x0 - x, y0 - y, x-xold, color);
} }
xold = x;
} // draw the line segment
} }
} }
@ -1148,21 +1152,29 @@ void Adafruit_GFX::drawChar(int16_t x, int16_t y, unsigned char c,
startWrite(); startWrite();
for (int8_t i = 0; i < 5; i++) { // Char bitmap = 5 columns for (int8_t i = 0; i < 5; i++) { // Char bitmap = 5 columns
uint8_t line = pgm_read_byte(&font[c * 5 + i]); int count = 0;
for (int8_t j = 0; j < 8; j++, line >>= 1) { uint8_t jo, j, line = pgm_read_byte(&font[c * 5 + i]);
if (line & 1) { j = jo = 0;
if (size_x == 1 && size_y == 1) while (j < 8) {
writePixel(x + i, y + j, color); while (jo < 8 && (line & 1) == 0) { // bg pixels
else count++; // count up bg pixels in a row
writeFillRect(x + i * size_x, y + j * size_y, size_x, size_y, jo++;
color); line >>= 1;
} 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);
} }
if (count && bg != color) { // need to draw background color
writeFillRect(x + i * size_x, y + j * size_y, size_x, size_y * count, bg);
} }
count = 0;
j = jo;
while (jo < 8 && (line & 1) == 1) { // fg pixels
count++; // count up fg pixels
jo++;
line >>= 1;
}
if (count) { // need to draw foreground color
writeFillRect(x + i * size_x, y + j * size_y, size_x, size_y * count, color);
}
} // while (j < 8)
} }
if (bg != color) { // If opaque, draw vertical line for last column if (bg != color) { // If opaque, draw vertical line for last column
if (size_x == 1 && size_y == 1) if (size_x == 1 && size_y == 1)