Add off-screen support to readRect()

See #803
This commit is contained in:
Bodmer
2020-10-25 15:56:13 +00:00
parent 1c1ec8cfa3
commit c8c6317241
4 changed files with 55 additions and 49 deletions

View File

@@ -1023,57 +1023,52 @@ void TFT_eSPI::setCallback(getColorCallback getCol)
***************************************************************************************/ ***************************************************************************************/
void TFT_eSPI::readRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data) void TFT_eSPI::readRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *data)
{ {
if (_vpOoB) return; PI_CLIP ;
x+= _xDatum;
y+= _yDatum;
// Clipping
if ((x >= _vpW) || (y >= _vpH)) return;
if (x < _vpX) { w += x - _vpX; x = _vpX; }
if (y < _vpY) { h += y - _vpY; y = _vpY; }
if ((x + w) > _vpW) w = _vpW - x;
if ((y + h) > _vpH) h = _vpH - y;
if ((w < 1) || (h < 1)) return;
#if defined(TFT_PARALLEL_8_BIT) #if defined(TFT_PARALLEL_8_BIT)
CS_L; CS_L;
readAddrWindow(x, y, w, h); readAddrWindow(x, y, dw, dh);
data += dx + dy * w;
// Set masked pins D0- D7 to input // Set masked pins D0- D7 to input
busDir(dir_mask, INPUT); busDir(dir_mask, INPUT);
// Total pixel count
uint32_t len = w * h;
#if defined (ILI9341_DRIVER) | defined (ILI9488_DRIVER) // Read 3 bytes #if defined (ILI9341_DRIVER) | defined (ILI9488_DRIVER) // Read 3 bytes
// Dummy read to throw away don't care value // Dummy read to throw away don't care value
readByte(); readByte();
// Fetch the 24 bit RGB value // Fetch the 24 bit RGB value
while (len--) { while (dh--) {
// Assemble the RGB 16 bit colour int32_t lw = dw;
uint16_t rgb = ((readByte() & 0xF8) << 8) | ((readByte() & 0xFC) << 3) | (readByte() >> 3); uint16_t* line = data;
while (lw--) {
// Assemble the RGB 16 bit colour
uint16_t rgb = ((readByte() & 0xF8) << 8) | ((readByte() & 0xFC) << 3) | (readByte() >> 3);
// Swapped byte order for compatibility with pushRect() // Swapped byte order for compatibility with pushRect()
*data++ = (rgb<<8) | (rgb>>8); *line++ = (rgb<<8) | (rgb>>8);
}
data += w;
} }
#elif defined (SSD1963_DRIVER) #elif defined (SSD1963_DRIVER)
// Fetch the 18 bit BRG pixels // Fetch the 18 bit BRG pixels
while (len--) { while (dh--) {
uint16_t bgr = ((readByte() & 0xF8) >> 3);; // CS_L adds a small delay int32_t lw = dw;
bgr |= ((readByte() & 0xFC) << 3); uint16_t* line = data;
bgr |= (readByte() << 8); while (lw--) {
// Swap Red and Blue (could check MADCTL setting to see if this is needed) uint16_t bgr = ((readByte() & 0xF8) >> 3);; // CS_L adds a small delay
uint16_t rgb = (bgr>>11) | (bgr<<11) | (bgr & 0x7E0); bgr |= ((readByte() & 0xFC) << 3);
// Swapped byte order for compatibility with pushRect() bgr |= (readByte() << 8);
*data++ = (rgb<<8) | (rgb>>8); // Swap Red and Blue (could check MADCTL setting to see if this is needed)
uint16_t rgb = (bgr>>11) | (bgr<<11) | (bgr & 0x7E0);
// Swapped byte order for compatibility with pushRect()
*line++ = (rgb<<8) | (rgb>>8);
}
data += w;
} }
#else // ILI9481 reads as 16 bits #else // ILI9481 reads as 16 bits
@@ -1081,18 +1076,23 @@ void TFT_eSPI::readRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *da
readByte(); readByte();
// Fetch the 16 bit BRG pixels // Fetch the 16 bit BRG pixels
while (len--) { while (dh--) {
int32_t lw = dw;
uint16_t* line = data;
while (lw--) {
#ifdef ILI9486_DRIVER #ifdef ILI9486_DRIVER
// Read the RGB 16 bit colour // Read the RGB 16 bit colour
*data++ = readByte() | (readByte() << 8); *line++ = readByte() | (readByte() << 8);
#else #else
// Read the BRG 16 bit colour // Read the BRG 16 bit colour
uint16_t bgr = (readByte() << 8) | readByte(); uint16_t bgr = (readByte() << 8) | readByte();
// Swap Red and Blue (could check MADCTL setting to see if this is needed) // Swap Red and Blue (could check MADCTL setting to see if this is needed)
uint16_t rgb = (bgr>>11) | (bgr<<11) | (bgr & 0x7E0); uint16_t rgb = (bgr>>11) | (bgr<<11) | (bgr & 0x7E0);
// Swapped byte order for compatibility with pushRect() // Swapped byte order for compatibility with pushRect()
*data++ = (rgb<<8) | (rgb>>8); *line++ = (rgb<<8) | (rgb>>8);
#endif #endif
}
data += w;
} }
#endif #endif
@@ -1107,7 +1107,9 @@ void TFT_eSPI::readRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *da
begin_tft_read(); begin_tft_read();
readAddrWindow(x, y, w, h); readAddrWindow(x, y, dw, dh);
data += dx + dy * w;
#ifdef TFT_SDA_READ #ifdef TFT_SDA_READ
begin_SDA_Read(); begin_SDA_Read();
@@ -1117,8 +1119,10 @@ void TFT_eSPI::readRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *da
tft_Read_8(); tft_Read_8();
// Read window pixel 24 bit RGB values // Read window pixel 24 bit RGB values
uint32_t len = w * h; while (dh--) {
while (len--) { int32_t lw = dw;
uint16_t* line = data;
while (lw--) {
#if !defined (ILI9488_DRIVER) #if !defined (ILI9488_DRIVER)
@@ -1136,16 +1140,18 @@ void TFT_eSPI::readRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t *da
#else #else
// The 6 colour bits are in MS 6 bits of each byte but we do not include the extra clock pulse // The 6 colour bits are in MS 6 bits of each byte but we do not include the extra clock pulse
// so we use a trick and mask the middle 6 bits of the byte, then only shift 1 place left // so we use a trick and mask the middle 6 bits of the byte, then only shift 1 place left
uint8_t r = (tft_Read_8()&0x7E)<<1; uint8_t r = (tft_Read_8()&0x7E)<<1;
uint8_t g = (tft_Read_8()&0x7E)<<1; uint8_t g = (tft_Read_8()&0x7E)<<1;
uint8_t b = (tft_Read_8()&0x7E)<<1; uint8_t b = (tft_Read_8()&0x7E)<<1;
color = color565(r, g, b); color = color565(r, g, b);
#endif #endif
// Swapped colour byte order for compatibility with pushRect() // Swapped colour byte order for compatibility with pushRect()
*data++ = color << 8 | color >> 8; *line++ = color << 8 | color >> 8;
}
data += w;
} }
//CS_H; //CS_H;

View File

@@ -16,7 +16,7 @@
#ifndef _TFT_eSPIH_ #ifndef _TFT_eSPIH_
#define _TFT_eSPIH_ #define _TFT_eSPIH_
#define TFT_ESPI_VERSION "2.3.2" #define TFT_ESPI_VERSION "2.3.3"
// Bit level feature flags // Bit level feature flags
// Bit 0 set: viewport capability // Bit 0 set: viewport capability

View File

@@ -1,6 +1,6 @@
{ {
"name": "TFT_eSPI", "name": "TFT_eSPI",
"version": "2.3.2", "version": "2.3.3",
"keywords": "Arduino, tft, ePaper, display, STM32, ESP8266, NodeMCU, ESP32, M5Stack, ILI9341, ST7735, ILI9163, S6D02A1, ILI9486, ST7789, RM68140", "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", "description": "A TFT and ePaper SPI graphics library with optimisation for ESP8266, ESP32 and STM32",
"repository": "repository":

View File

@@ -1,5 +1,5 @@
name=TFT_eSPI name=TFT_eSPI
version=2.3.2 version=2.3.3
author=Bodmer author=Bodmer
maintainer=Bodmer maintainer=Bodmer
sentence=TFT graphics library for Arduino processors with performance optimisation for STM32, ESP8266 and ESP32 sentence=TFT graphics library for Arduino processors with performance optimisation for STM32, ESP8266 and ESP32