Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
Bodmer committed Feb 23, 2021
1 parent 190fe54 commit 2bf4d15
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
30 changes: 19 additions & 11 deletions Extensions/Sprite.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ void TFT_eSprite::deleteSprite(void)
** Description: Push rotated Sprite to TFT screen
***************************************************************************************/
#define FP_SCALE 10
bool TFT_eSprite::pushRotated(int16_t angle, int32_t transp)
bool TFT_eSprite::pushRotated(int16_t angle, uint32_t transp)
{
if ( !_created || _tft->_vpOoB) return false;

Expand All @@ -414,10 +414,13 @@ bool TFT_eSprite::pushRotated(int16_t angle, int32_t transp)
int32_t yt = min_y - _tft->_yPivot;
uint32_t xe = _dwidth << FP_SCALE;
uint32_t ye = _dheight << FP_SCALE;
uint16_t tpcolor = transp; // convert to unsigned
if (_bpp == 4) tpcolor = _colorMap[transp & 0x0F];
tpcolor = tpcolor>>8 | tpcolor<<8; // Working with swapped color bytes
_tft->startWrite(); // Avoid transaction overhead for every tft pixel
uint32_t tpcolor = transp;

if (transp != 0x00FFFFFF) {
if (_bpp == 4) tpcolor = _colorMap[transp & 0x0F];
tpcolor = tpcolor>>8 | tpcolor<<8; // Working with swapped color bytes
}
_tft->startWrite(); // Avoid transaction overhead for every tft pixel

// Scan destination bounding box and fetch transformed pixels from source Sprite
for (int32_t y = min_y; y <= max_y; y++, yt++) {
Expand All @@ -430,11 +433,11 @@ bool TFT_eSprite::pushRotated(int16_t angle, int32_t transp)

uint32_t pixel_count = 0;
do {
uint16_t rp;
uint32_t rp;
int32_t xp = xs >> FP_SCALE;
int32_t yp = ys >> FP_SCALE;
if (_bpp == 16) {rp = _img[xp + yp * _iwidth]; }
else { rp = readPixel(xp, yp); rp = rp>>8 | rp<<8; }
else { rp = readPixel(xp, yp); rp = (uint16_t)(rp>>8 | rp<<8); }
if (tpcolor == rp) {
if (pixel_count) {
// TFT window is already clipped, so this is faster than pushImage()
Expand Down Expand Up @@ -465,7 +468,7 @@ bool TFT_eSprite::pushRotated(int16_t angle, int32_t transp)
** Description: Push a rotated copy of the Sprite to another Sprite
***************************************************************************************/
// Not compatible with 4bpp
bool TFT_eSprite::pushRotated(TFT_eSprite *spr, int16_t angle, int32_t transp)
bool TFT_eSprite::pushRotated(TFT_eSprite *spr, int16_t angle, uint32_t transp)
{
if ( !_created || _bpp == 4) return false; // Check this Sprite is created
if ( !spr->_created || spr->_bpp == 4) return false; // Ckeck destination Sprite is created
Expand All @@ -485,7 +488,12 @@ bool TFT_eSprite::pushRotated(TFT_eSprite *spr, int16_t angle, int32_t transp)
int32_t yt = min_y - spr->_yPivot;
uint32_t xe = _dwidth << FP_SCALE;
uint32_t ye = _dheight << FP_SCALE;
uint32_t tpcolor = transp>>8 | transp<<8; // convert to unsigned swapped bytes
uint32_t tpcolor = transp;

if (transp != 0x00FFFFFF) {
if (_bpp == 4) tpcolor = _colorMap[transp & 0x0F];
tpcolor = tpcolor>>8 | tpcolor<<8; // Working with swapped color bytes
}

bool oldSwapBytes = spr->getSwapBytes();
spr->setSwapBytes(false);
Expand All @@ -501,11 +509,11 @@ bool TFT_eSprite::pushRotated(TFT_eSprite *spr, int16_t angle, int32_t transp)

uint32_t pixel_count = 0;
do {
uint16_t rp;
uint32_t rp;
int32_t xp = xs >> FP_SCALE;
int32_t yp = ys >> FP_SCALE;
if (_bpp == 16) rp = _img[xp + yp * _iwidth];
else { rp = readPixel(xp, yp); rp = rp>>8 | rp<<8; }
else { rp = readPixel(xp, yp); rp = (uint16_t)(rp>>8 | rp<<8); }
if (tpcolor == rp) {
if (pixel_count) {
spr->pushImage(x - pixel_count, y, pixel_count, 1, sline_buffer);
Expand Down
4 changes: 2 additions & 2 deletions Extensions/Sprite.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,9 @@ class TFT_eSprite : public TFT_eSPI {
uint8_t getRotation(void);

// Push a rotated copy of Sprite to TFT with optional transparent colour
bool pushRotated(int16_t angle, int32_t transp = -1); // Using fixed point maths
bool pushRotated(int16_t angle, uint32_t transp = 0x00FFFFFF); // Using fixed point maths
// Push a rotated copy of Sprite to another different Sprite with optional transparent colour
bool pushRotated(TFT_eSprite *spr, int16_t angle, int32_t transp = -1); // Using fixed point maths
bool pushRotated(TFT_eSprite *spr, int16_t angle, uint32_t transp = 0x00FFFFFF); // Using fixed point maths

// Get the TFT bounding box for a rotated copy of this Sprite
bool getRotatedBounds(int16_t angle, int16_t *min_x, int16_t *min_y, int16_t *max_x, int16_t *max_y);
Expand Down

0 comments on commit 2bf4d15

Please sign in to comment.