From 2bf4d15b0298a3acb759244b7a6e7fac37c45a5a Mon Sep 17 00:00:00 2001 From: Bodmer Date: Tue, 23 Feb 2021 22:38:03 +0000 Subject: [PATCH] Fix #1022 --- Extensions/Sprite.cpp | 30 +++++++++++++++++++----------- Extensions/Sprite.h | 4 ++-- 2 files changed, 21 insertions(+), 13 deletions(-) diff --git a/Extensions/Sprite.cpp b/Extensions/Sprite.cpp index 7eea64bc..0a056758 100644 --- a/Extensions/Sprite.cpp +++ b/Extensions/Sprite.cpp @@ -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; @@ -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++) { @@ -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() @@ -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 @@ -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); @@ -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); diff --git a/Extensions/Sprite.h b/Extensions/Sprite.h index 73c168c9..951099b5 100644 --- a/Extensions/Sprite.h +++ b/Extensions/Sprite.h @@ -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);