Skip to content

Commit 0521944

Browse files
Fix fillCircleHelper for SSD1306 INVERT mode
Function would previously draw certain line segments repeatedly; minor performance drain on most displays, but especially problematic for SSD1306's INVERT drawing mode.
1 parent 96f5acf commit 0521944

File tree

2 files changed

+25
-18
lines changed

2 files changed

+25
-18
lines changed

Adafruit_GFX.cpp

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ void Adafruit_GFX::drawCircle(int16_t x0, int16_t y0, int16_t r,
353353

354354
/**************************************************************************/
355355
/*!
356-
@brief Quarter-circle drawer, used to do circles and roundrects
356+
@brief Quarter-circle drawer, used to do circles and roundrects
357357
@param x0 Center-point x coordinate
358358
@param y0 Center-point y coordinate
359359
@param r Radius of circle
@@ -417,25 +417,29 @@ void Adafruit_GFX::fillCircle(int16_t x0, int16_t y0, int16_t r,
417417

418418
/**************************************************************************/
419419
/*!
420-
@brief Quarter-circle drawer with fill, used to do circles and roundrects
421-
@param x0 Center-point x coordinate
422-
@param y0 Center-point y coordinate
423-
@param r Radius of circle
424-
@param cornername Mask bit #1 or bit #2 to indicate which quarters of the circle we're doing
425-
@param delta Offset from center-point, used for round-rects
426-
@param color 16-bit 5-6-5 Color to fill with
420+
@brief Quarter-circle drawer with fill, used for circles and roundrects
421+
@param x0 Center-point x coordinate
422+
@param y0 Center-point y coordinate
423+
@param r Radius of circle
424+
@param corners Mask bits indicating which quarters we're doing
425+
@param delta Offset from center-point, used for round-rects
426+
@param color 16-bit 5-6-5 Color to fill with
427427
*/
428428
/**************************************************************************/
429429
void Adafruit_GFX::fillCircleHelper(int16_t x0, int16_t y0, int16_t r,
430-
uint8_t cornername, int16_t delta, uint16_t color) {
430+
uint8_t corners, int16_t delta, uint16_t color) {
431431

432432
int16_t f = 1 - r;
433433
int16_t ddF_x = 1;
434434
int16_t ddF_y = -2 * r;
435435
int16_t x = 0;
436436
int16_t y = r;
437+
int16_t px = x;
438+
int16_t py = y;
437439

438-
while (x<y) {
440+
delta++; // Avoid some +1's in the loop
441+
442+
while(x < y) {
439443
if (f >= 0) {
440444
y--;
441445
ddF_y += 2;
@@ -444,15 +448,18 @@ void Adafruit_GFX::fillCircleHelper(int16_t x0, int16_t y0, int16_t r,
444448
x++;
445449
ddF_x += 2;
446450
f += ddF_x;
447-
448-
if (cornername & 0x1) {
449-
writeFastVLine(x0+x, y0-y, 2*y+1+delta, color);
450-
writeFastVLine(x0+y, y0-x, 2*x+1+delta, color);
451+
// These checks avoid double-drawing certain lines, important
452+
// for the SSD1306 library which has an INVERT drawing mode.
453+
if(x < (y + 1)) {
454+
if(corners & 1) writeFastVLine(x0+x, y0-y, 2*y+delta, color);
455+
if(corners & 2) writeFastVLine(x0-x, y0-y, 2*y+delta, color);
451456
}
452-
if (cornername & 0x2) {
453-
writeFastVLine(x0-x, y0-y, 2*y+1+delta, color);
454-
writeFastVLine(x0-y, y0-x, 2*x+1+delta, color);
457+
if(y != py) {
458+
if(corners & 1) writeFastVLine(x0+py, y0-px, 2*px+delta, color);
459+
if(corners & 2) writeFastVLine(x0-py, y0-px, 2*px+delta, color);
460+
py = y;
455461
}
462+
px = x;
456463
}
457464
}
458465

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name=Adafruit GFX Library
2-
version=1.3.0
2+
version=1.3.1
33
author=Adafruit
44
maintainer=Adafruit <[email protected]>
55
sentence=Adafruit GFX graphics core library, this is the 'core' class that all our other graphics libraries derive from.

0 commit comments

Comments
 (0)