diff --git a/Extensions/Sprite.cpp b/Extensions/Sprite.cpp index e377013..4c6ee81 100644 --- a/Extensions/Sprite.cpp +++ b/Extensions/Sprite.cpp @@ -734,30 +734,59 @@ bool TFT_eSprite::pushToSprite(TFT_eSprite *dspr, int32_t x, int32_t y) ** Function name: pushToSprite ** Description: Push the sprite to another sprite at x, y with transparent colour ***************************************************************************************/ -/* >>>>>> Using a transparent color is not supported at the moment <<<<<< -void TFT_eSprite::pushToSprite(TFT_eSprite *spr, int32_t x, int32_t y, uint16_t transp) -{ - if (!_created) return; +// Note: The following sprite to sprite colour depths are currently supported: +// Source Destination +// 16bpp -> 16bpp +// 16bpp -> 8bpp +// 8bpp -> 8bpp +// 1bpp -> 1bpp - if (_bpp == 16) - { - bool oldSwapBytes = spr->getSwapBytes(); - spr->setSwapBytes(false); - spr->pushImage(x, y, _dwidth, _dheight, _img, transp ); - spr->setSwapBytes(oldSwapBytes); +bool TFT_eSprite::pushToSprite(TFT_eSprite *dspr, int32_t x, int32_t y, uint16_t transp) +{ + if ( !_created || !dspr->_created) return false; // Check Sprites exist + + // Check destination sprite compatibility + int8_t ds_bpp = dspr->getColorDepth(); + if (_bpp == 16 && ds_bpp != 16 && ds_bpp != 8) return false; + if (_bpp == 8 && ds_bpp != 8) return false; + if (_bpp == 4 || ds_bpp == 4) return false; + if (_bpp == 1 && ds_bpp != 1) return false; + + bool oldSwapBytes = dspr->getSwapBytes(); + uint16_t sline_buffer[width()]; + + transp = transp>>8 | transp<<8; + + // Scan destination bounding box and fetch transformed pixels from source Sprite + for (int32_t ys = 0; ys < height(); ys++) { + int32_t ox = x; + uint32_t pixel_count = 0; + + for (int32_t xs = 0; xs < width(); xs++) { + uint16_t rp = 0; + if (_bpp == 16) rp = _img[xs + ys * width()]; + else { rp = readPixel(xs, ys); rp = rp>>8 | rp<<8; } + //dspr->drawPixel(xs, ys, rp); + + if (transp == rp) { + if (pixel_count) { + dspr->pushImage(ox, y, pixel_count, 1, sline_buffer, _bpp); + ox += pixel_count; + pixel_count = 0; + } + else ox++; + } + else { + sline_buffer[pixel_count++] = rp; + } + } + if (pixel_count) dspr->pushImage(ox, y, pixel_count, 1, sline_buffer); + y++; } - else if (_bpp == 8) - { - transp = (uint8_t)((transp & 0xE000)>>8 | (transp & 0x0700)>>6 | (transp & 0x0018)>>3); - spr->pushImage(x, y, _dwidth, _dheight, _img8, (uint8_t)transp, (bool)true); - } - else if (_bpp == 4) - { - spr->pushImage(x, y, _dwidth, _dheight, _img4, (uint8_t)(transp & 0x0F), false, _colorMap); - } - else spr->pushImage(x, y, _dwidth, _dheight, _img8, 0, (bool)false); + dspr->setSwapBytes(oldSwapBytes); + return true; } -*/ + /*************************************************************************************** ** Function name: pushSprite diff --git a/TFT_eSPI.h b/TFT_eSPI.h index 07a6b85..1556aa6 100644 --- a/TFT_eSPI.h +++ b/TFT_eSPI.h @@ -16,7 +16,7 @@ #ifndef _TFT_eSPIH_ #define _TFT_eSPIH_ -#define TFT_ESPI_VERSION "2.3.5" +#define TFT_ESPI_VERSION "2.3.51" // Bit level feature flags // Bit 0 set: viewport capability diff --git a/library.json b/library.json index 3e5afe6..da10acd 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TFT_eSPI", - "version": "2.3.5", + "version": "2.3.51", "keywords": "Arduino, tft, ePaper, display, STM32, ESP8266, NodeMCU, ESP32, M5Stack, ILI9341, ST7735, ILI9163, S6D02A1, ILI9486, ST7789, RM68140", "description": "A TFT and ePaper SPI graphics library with optimisation for ESP8266, ESP32 and STM32", "repository": diff --git a/library.properties b/library.properties index abca8da..b3f0209 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TFT_eSPI -version=2.3.5 +version=2.3.51 author=Bodmer maintainer=Bodmer sentence=TFT graphics library for Arduino processors with performance optimisation for STM32, ESP8266 and ESP32