From 9bf9c0940f42d7f3107b7ee00a69c34f43317d1c Mon Sep 17 00:00:00 2001 From: Bodmer Date: Sun, 28 Nov 2021 13:57:15 +0000 Subject: [PATCH] Update for GC9A01 display Correct sprite rendering GC9A01 expects exact number of pixels to fill setWindow area. --- Extensions/Sprite.cpp | 4 ++-- TFT_eSPI.cpp | 51 ++++++++++++++++++++++++------------------- TFT_eSPI.h | 2 +- library.json | 2 +- library.properties | 2 +- 5 files changed, 34 insertions(+), 27 deletions(-) diff --git a/Extensions/Sprite.cpp b/Extensions/Sprite.cpp index 62e8e0c..10348f1 100644 --- a/Extensions/Sprite.cpp +++ b/Extensions/Sprite.cpp @@ -441,7 +441,7 @@ bool TFT_eSprite::pushRotated(int16_t angle, uint32_t transp) if (tpcolor == rp) { if (pixel_count) { // TFT window is already clipped, so this is faster than pushImage() - _tft->setWindow(x - pixel_count, y, x, y); + _tft->setWindow(x - pixel_count, y, x - 1, y); _tft->pushPixels(sline_buffer, pixel_count); pixel_count = 0; } @@ -452,7 +452,7 @@ bool TFT_eSprite::pushRotated(int16_t angle, uint32_t transp) } while (++x < max_x && (xs += _cosra) < xe && (ys += _sinra) < ye); if (pixel_count) { // TFT window is already clipped, so this is faster than pushImage() - _tft->setWindow(x - pixel_count, y, x, y); + _tft->setWindow(x - pixel_count, y, x - 1, y); _tft->pushPixels(sline_buffer, pixel_count); } } diff --git a/TFT_eSPI.cpp b/TFT_eSPI.cpp index 84d8a09..0afa10b 100644 --- a/TFT_eSPI.cpp +++ b/TFT_eSPI.cpp @@ -1272,7 +1272,7 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *d { int32_t len = dw; uint16_t* ptr = data; - int32_t px = x; + int32_t px = x, sx = x; bool move = true; uint16_t np = 0; @@ -1280,7 +1280,7 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *d { if (transp != *ptr) { - if (move) { move = false; setWindow(px, y, xe, ye); } + if (move) { move = false; sx = px; } lineBuf[np] = *ptr; np++; } @@ -1289,14 +1289,15 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *d move = true; if (np) { - pushPixels((uint16_t*)lineBuf, np); - np = 0; + setWindow(sx, y, sx + np - 1, y); + pushPixels((uint16_t*)lineBuf, np); + np = 0; } } px++; ptr++; } - if (np) pushPixels((uint16_t*)lineBuf, np); + if (np) { setWindow(sx, y, sx + np - 1, y); pushPixels((uint16_t*)lineBuf, np); } y++; data += w; @@ -1361,7 +1362,7 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint1 while (dh--) { int32_t len = dw; uint16_t* ptr = (uint16_t*)data; - int32_t px = x; + int32_t px = x, sx = x; bool move = true; uint16_t np = 0; @@ -1369,21 +1370,22 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, const uint1 while (len--) { uint16_t color = pgm_read_word(ptr); if (transp != color) { - if (move) { move = false; setWindow(px, y, xe, ye); } + if (move) { move = false; sx = px; } lineBuf[np] = color; np++; } else { move = true; if (np) { - pushPixels(lineBuf, np); - np = 0; + setWindow(sx, y, sx + np - 1, y); + pushPixels(lineBuf, np); + np = 0; } } px++; ptr++; } - if (np) pushPixels(lineBuf, np); + if (np) { setWindow(sx, y, sx + np - 1, y); pushPixels(lineBuf, np); } y++; data += w; @@ -1694,13 +1696,13 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *da uint8_t* ptr = data; uint8_t* linePtr = (uint8_t*)lineBuf; - int32_t px = x; + int32_t px = x, sx = x; bool move = true; uint16_t np = 0; while (len--) { if (transp != *ptr) { - if (move) { move = false; setWindow(px, y, xe, ye);} + if (move) { move = false; sx = px; } uint8_t color = *ptr; // Shifts are slow so check if colour has changed first @@ -1718,6 +1720,7 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *da else { move = true; if (np) { + setWindow(sx, y, sx + np - 1, y); pushPixels(lineBuf, np); linePtr = (uint8_t*)lineBuf; np = 0; @@ -1727,7 +1730,7 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *da ptr++; } - if (np) pushPixels(lineBuf, np); + if (np) { setWindow(sx, y, sx + np - 1, y); pushPixels(lineBuf, np); } y++; data += w; } @@ -1749,7 +1752,7 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *da uint32_t len = dw; uint8_t * ptr = data; - int32_t px = x; + int32_t px = x, sx = x; bool move = true; uint16_t np = 0; @@ -1758,7 +1761,7 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *da if (splitFirst) { index = (*ptr & 0x0F); // odd = bits 3 .. 0 if (index != transp) { - move = false; setWindow(px, y, xe, ye); + move = false; sx = px; lineBuf[np] = cmap[index]; np++; } @@ -1775,7 +1778,7 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *da uint16_t index = ((color & 0xF0) >> 4) & 0x0F; // high bits are the even numbers if (index != transp) { if (move) { - move = false; setWindow(px, y, xe, ye); + move = false; sx = px; } lineBuf[np] = cmap[index]; np++; // added a pixel @@ -1783,6 +1786,7 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *da else { move = true; if (np) { + setWindow(sx, y, sx + np - 1, y); pushPixels(lineBuf, np); np = 0; } @@ -1794,7 +1798,7 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *da index = color & 0x0F; // the odd number is 3 .. 0 if (index != transp) { if (move) { - move = false; setWindow(px, y, xe, ye); + move = false; sx = px; } lineBuf[np] = cmap[index]; np++; @@ -1802,6 +1806,7 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *da else { move = true; if (np) { + setWindow(sx, y, sx + np - 1, y); pushPixels(lineBuf, np); np = 0; } @@ -1815,6 +1820,7 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *da } if (np) { + setWindow(sx, y, sx + np - 1, y); pushPixels(lineBuf, np); np = 0; } @@ -1830,29 +1836,30 @@ void TFT_eSPI::pushImage(int32_t x, int32_t y, int32_t w, int32_t h, uint8_t *da for (int32_t yp = dy; yp < dy + dh; yp++) { - int32_t px = x; + int32_t px = x, sx = x; bool move = true; for (int32_t xp = dx; xp < dx + dw; xp++) { if (data[(xp>>3)] & (0x80 >> (xp & 0x7))) { if (move) { move = false; - setWindow(px, y, xe, ye); + sx = px; } np++; } else { + move = true; if (np) { + setWindow(sx, y, sx + np - 1, y); pushBlock(bitmap_fg, np); np = 0; - move = true; } } px++; } y++; data += ww; - if (np) { pushBlock(bitmap_fg, np); np = 0; } + if (np) { setWindow(sx, y, sx + np - 1, y); pushBlock(bitmap_fg, np); np = 0; } } } _swapBytes = swap; // Restore old value @@ -2900,7 +2907,7 @@ void TFT_eSPI::drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uint32 uint8_t mask = 0x1; begin_tft_write(); - setWindow(xd, yd, xd+5, yd+8); + setWindow(xd, yd, xd+5, yd+7); for (int8_t i = 0; i < 5; i++ ) column[i] = pgm_read_byte(font + (c * 5) + i); column[5] = 0; diff --git a/TFT_eSPI.h b/TFT_eSPI.h index 5ecd25a..d6c0a0a 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.82" +#define TFT_ESPI_VERSION "2.3.83" // Bit level feature flags // Bit 0 set: viewport capability diff --git a/library.json b/library.json index 4e58238..872f3c1 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TFT_eSPI", - "version": "2.3.82", + "version": "2.3.83", "keywords": "Arduino, tft, ePaper, display, Pico, RP2040, STM32, ESP8266, NodeMCU, ESP32, M5Stack, ILI9341, ST7735, ILI9163, S6D02A1, ILI9481, ILI9486, ILI9488, ST7789, RM68140, SSD1351, SSD1963, ILI9225, HX8357D", "description": "A TFT and ePaper SPI graphics library with optimisation for Raspberry Pi Pico, ESP8266, ESP32 and STM32", "repository": diff --git a/library.properties b/library.properties index 18cf5c9..5769750 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TFT_eSPI -version=2.3.82 +version=2.3.83 author=Bodmer maintainer=Bodmer sentence=TFT graphics library for Arduino processors with performance optimisation for RP2040, STM32, ESP8266 and ESP32