Skip to content

Commit

Permalink
Fix fillCircleHelper for SSD1306 INVERT mode
Browse files Browse the repository at this point in the history
Function would previously draw certain line segments repeatedly; minor performance drain on most displays, but especially problematic for SSD1306's INVERT drawing mode.
  • Loading branch information
PaintYourDragon committed Nov 8, 2018
1 parent 96f5acf commit 0521944
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 18 deletions.
41 changes: 24 additions & 17 deletions Adafruit_GFX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ void Adafruit_GFX::drawCircle(int16_t x0, int16_t y0, int16_t r,

/**************************************************************************/
/*!
@brief Quarter-circle drawer, used to do circles and roundrects
@brief Quarter-circle drawer, used to do circles and roundrects
@param x0 Center-point x coordinate
@param y0 Center-point y coordinate
@param r Radius of circle
Expand Down Expand Up @@ -417,25 +417,29 @@ void Adafruit_GFX::fillCircle(int16_t x0, int16_t y0, int16_t r,

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

int16_t f = 1 - r;
int16_t ddF_x = 1;
int16_t ddF_y = -2 * r;
int16_t x = 0;
int16_t y = r;
int16_t px = x;
int16_t py = y;

while (x<y) {
delta++; // Avoid some +1's in the loop

while(x < y) {
if (f >= 0) {
y--;
ddF_y += 2;
Expand All @@ -444,15 +448,18 @@ void Adafruit_GFX::fillCircleHelper(int16_t x0, int16_t y0, int16_t r,
x++;
ddF_x += 2;
f += ddF_x;

if (cornername & 0x1) {
writeFastVLine(x0+x, y0-y, 2*y+1+delta, color);
writeFastVLine(x0+y, y0-x, 2*x+1+delta, color);
// These checks avoid double-drawing certain lines, important
// for the SSD1306 library which has an INVERT drawing mode.
if(x < (y + 1)) {
if(corners & 1) writeFastVLine(x0+x, y0-y, 2*y+delta, color);
if(corners & 2) writeFastVLine(x0-x, y0-y, 2*y+delta, color);
}
if (cornername & 0x2) {
writeFastVLine(x0-x, y0-y, 2*y+1+delta, color);
writeFastVLine(x0-y, y0-x, 2*x+1+delta, color);
if(y != py) {
if(corners & 1) writeFastVLine(x0+py, y0-px, 2*px+delta, color);
if(corners & 2) writeFastVLine(x0-py, y0-px, 2*px+delta, color);
py = y;
}
px = x;
}
}

Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=Adafruit GFX Library
version=1.3.0
version=1.3.1
author=Adafruit
maintainer=Adafruit <info@adafruit.com>
sentence=Adafruit GFX graphics core library, this is the 'core' class that all our other graphics libraries derive from.
Expand Down

0 comments on commit 0521944

Please sign in to comment.