mirror of
https://github.com/adafruit/Adafruit-GFX-Library.git
synced 2024-10-03 18:18:46 -04:00
Optimized drwChar and drawCircleHelper
This commit is contained in:
parent
1232016e3b
commit
1b93789997
@ -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 x = 0;
|
||||
int16_t y = r;
|
||||
int xold = x;
|
||||
|
||||
while (x < y) {
|
||||
if (f >= 0) {
|
||||
@ -421,22 +422,25 @@ void Adafruit_GFX::drawCircleHelper(int16_t x0, int16_t y0, int16_t r,
|
||||
x++;
|
||||
ddF_x += 2;
|
||||
f += ddF_x;
|
||||
if (cornername & 0x4) {
|
||||
writePixel(x0 + x, y0 + y, color);
|
||||
writePixel(x0 + y, y0 + x, color);
|
||||
}
|
||||
if (cornername & 0x2) {
|
||||
writePixel(x0 + x, y0 - y, color);
|
||||
writePixel(x0 + y, y0 - x, color);
|
||||
}
|
||||
if (cornername & 0x8) {
|
||||
writePixel(x0 - y, y0 + x, color);
|
||||
writePixel(x0 - x, y0 + y, color);
|
||||
}
|
||||
if (cornername & 0x1) {
|
||||
writePixel(x0 - y, y0 - x, color);
|
||||
writePixel(x0 - x, y0 - y, color);
|
||||
}
|
||||
if (f >= 0 || x == y) { // time to draw the new line segment
|
||||
if (cornername & 0x4) {
|
||||
drawFastHLine(x0 + xold+1, y0 + y, x-xold, color);
|
||||
drawFastVLine(x0 + y, y0 + xold+1, x-xold, color);
|
||||
}
|
||||
if (cornername & 0x2) {
|
||||
drawFastHLine(x0 + xold+1, y0 - y, x-xold, color);
|
||||
drawFastVLine(x0 + y, y0 - x, x-xold, color);
|
||||
}
|
||||
if (cornername & 0x8) {
|
||||
drawFastVLine(x0 - y, y0 + xold+1, x-xold, color);
|
||||
drawFastHLine(x0 - x, y0 + y, x-xold, color);
|
||||
}
|
||||
if (cornername & 0x1) {
|
||||
drawFastVLine(x0 - y, y0 - x, x-xold, 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();
|
||||
for (int8_t i = 0; i < 5; i++) { // 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);
|
||||
int count = 0;
|
||||
uint8_t jo, j, line = pgm_read_byte(&font[c * 5 + i]);
|
||||
j = jo = 0;
|
||||
while (j < 8) {
|
||||
while (jo < 8 && (line & 1) == 0) { // bg pixels
|
||||
count++; // count up bg pixels in a row
|
||||
jo++;
|
||||
line >>= 1;
|
||||
}
|
||||
}
|
||||
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 (size_x == 1 && size_y == 1)
|
||||
|
Loading…
x
Reference in New Issue
Block a user