Skip to content

Commit 431489a

Browse files
committed
Added invertRect method
1 parent 4a30496 commit 431489a

File tree

3 files changed

+62
-0
lines changed

3 files changed

+62
-0
lines changed

src/FastEPD.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,11 @@ void FASTEPD::drawRect(int x, int y, int w, int h, uint8_t color)
9595
bbepRectangle(&_state, x, y, x+w-1, y+h-1, color, 0);
9696
}
9797

98+
void FASTEPD::invertRect(int x, int y, int w, int h)
99+
{
100+
bbepInvertRect(&_state, x, y, w, h);
101+
}
102+
98103
void FASTEPD::fillRect(int x, int y, int w, int h, uint8_t color)
99104
{
100105
bbepRectangle(&_state, x, y, x+w-1, y+h-1, color, 1);

src/FastEPD.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ class FASTEPD
229229
int setRotation(int iAngle);
230230
int getRotation(void) { return _state.rotation;}
231231
void backupPlane(void);
232+
void invertRect(int x, int y, int w, int h);
232233
void drawRoundRect(int x, int y, int w, int h, int r, uint8_t color);
233234
void fillRoundRect(int x, int y, int w, int h, int r, uint8_t color);
234235
void fillScreen(uint8_t iColor);

src/bb_ep_gfx.inl

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1609,6 +1609,62 @@ void bbepEllipse(FASTEPDSTATE *pBBEP, int iCenterX, int iCenterY, int32_t iRadiu
16091609
}
16101610
}
16111611
} /* bbepEllipse() */
1612+
1613+
//
1614+
// Invert a rectangle of pixels
1615+
//
1616+
void bbepInvertRect(FASTEPDSTATE *pBBEP, int x, int y, int w, int h)
1617+
{
1618+
int tx, ty;
1619+
uint8_t u8, u8Mask, *s;
1620+
int iPitch;
1621+
1622+
if (pBBEP == NULL) return;
1623+
if (x < 0 || y < 0 || w < 0 || h < 0 ||
1624+
x >= pBBEP->width || y >= pBBEP->height || (x+w) > pBBEP->width || (y+h) > pBBEP->height) {
1625+
pBBEP->last_error = BBEP_ERROR_BAD_PARAMETER;
1626+
return; // invalid coordinates
1627+
}
1628+
1629+
if (pBBEP->mode == BB_MODE_1BPP) {
1630+
iPitch = pBBEP->width / 8;
1631+
for (ty=y; ty<y+h; ty++) {
1632+
s = pBBEP->pCurrent;
1633+
s += (ty * iPitch) + (x >> 3);
1634+
u8Mask = 0x80 >> (x & 7);
1635+
u8 = s[0]; // read current pixels
1636+
for (tx=0; tx<w; tx++) {
1637+
u8 ^= u8Mask;
1638+
u8Mask >>= 1;
1639+
if (u8Mask == 0) { // next byte
1640+
*s++ = u8;
1641+
u8 = s[0];
1642+
u8Mask = 0x80;
1643+
}
1644+
} // for tx
1645+
if (u8Mask != 0x80) { // write final partial byte
1646+
s[0] = u8;
1647+
}
1648+
} // for ty
1649+
} else { // 4-bpp
1650+
iPitch = pBBEP->width / 2;
1651+
for (ty = y; ty < y+h; ty++) {
1652+
s = pBBEP->pCurrent;
1653+
s += (ty * iPitch) + (x >> 1);
1654+
u8Mask = 0xf0 >> ((x & 1)*4);
1655+
u8 = s[0];
1656+
for (tx=0; tx<w; tx++) {
1657+
u8 ^= u8Mask;
1658+
u8Mask = ~u8Mask;
1659+
if (u8Mask == 0xf0) { // next byte
1660+
*s++ = u8;
1661+
u8 = s[0];
1662+
}
1663+
} // for tx
1664+
} // for ty
1665+
}
1666+
} /* bbepInvertRect() */
1667+
16121668
//
16131669
// Draw an outline or filled rectangle
16141670
//

0 commit comments

Comments
 (0)