From 3b5e673603bf3016dc848e50b472659cc96c3279 Mon Sep 17 00:00:00 2001 From: Bodmer Date: Wed, 22 Nov 2017 00:53:09 +0000 Subject: [PATCH] Version update, minor tweaks and typos --- TFT_eSPI.cpp | 14 ++++++++-- .../Sprite_RLE_Font_test.ino | 26 +++++++++---------- .../Sprite_drawPixel/Sprite_drawPixel.ino | 13 +++++++--- .../Sprite_scroll_16bit.ino | 2 +- library.json | 2 +- library.properties | 2 +- 6 files changed, 37 insertions(+), 22 deletions(-) diff --git a/TFT_eSPI.cpp b/TFT_eSPI.cpp index d84b966..e0cdf53 100644 --- a/TFT_eSPI.cpp +++ b/TFT_eSPI.cpp @@ -4228,9 +4228,19 @@ void TFT_eSprite::createSprite(int16_t w, int16_t h) void TFT_eSprite::setColorDepth(int8_t b) { - if (_created) deleteSprite(); + // Can't change an existing sprite's colour depth so delete it + if (_created) + { + if (_bpp16) free(_img); + else free(_img8); + } + + // Now define the new colour depth if ( b > 8 ) _bpp16 = true; // Bytes per pixel else _bpp16 = false; + + // If it existed, re-create the sprite with the new colour depth + if (_created) createSprite(_iwidth, _iheight); } @@ -4724,7 +4734,7 @@ void TFT_eSprite::drawFastHLine(int32_t x, int32_t y, int32_t w, uint32_t color) color = (color >> 8) | (color << 8); while (w--) _img[_iwidth * y + x++] = (uint16_t) color; } - else + else { color = (color & 0xE000)>>8 | (color & 0x0700)>>6 | (color & 0x0018)>>3; //while (w--) _img8[_iwidth * y + x++] = (uint8_t) color; diff --git a/examples/Sprite/Sprite_RLE_Font_test/Sprite_RLE_Font_test.ino b/examples/Sprite/Sprite_RLE_Font_test/Sprite_RLE_Font_test.ino index 32c22b3..8a8d519 100644 --- a/examples/Sprite/Sprite_RLE_Font_test/Sprite_RLE_Font_test.ino +++ b/examples/Sprite/Sprite_RLE_Font_test/Sprite_RLE_Font_test.ino @@ -1,5 +1,5 @@ /* - Display all the fast rendering fonts. + Display all the fast rendering fonts in a sprite Make sure all the display driver and pin comnections are correct by editting the User_Setup.h file in the TFT_eSPI library folder. @@ -9,13 +9,10 @@ ######################################################################### */ -// Create a sprite 160 x 128 pixels (needs 40Kbytes of RAM!) +// Specify sprite 160 x 128 pixels (needs 40Kbytes of RAM for 16 bit colour) #define IWIDTH 160 #define IHEIGHT 128 -// New background colour -#define TFT_BROWN 0x38E0 - // Pause in milliseconds between screens, change to 0 to time font rendering #define WAIT 500 @@ -34,6 +31,7 @@ void setup(void) { tft.fillScreen(TFT_BLUE); + //img.setColorDepth(8); // Optionally set depth to 8 to reduce RAM use img.createSprite(IWIDTH, IHEIGHT); img.fillSprite(TFT_BLACK); } @@ -125,7 +123,7 @@ void loop() { targetTime = millis(); img.setTextSize(1); - img.fillSprite(TFT_BROWN); + img.fillSprite(TFT_BLACK); img.setTextColor(TFT_GREEN); img.drawString(" !\"#$%&'()*+,-./0123456", 0, 0, 2); @@ -137,7 +135,7 @@ void loop() { img.drawChar(127, xpos, 64, 2); img.pushSprite(0, 0); delay(WAIT); - img.fillSprite(TFT_BROWN); + img.fillSprite(TFT_BLACK); img.setTextColor(TFT_GREEN); img.drawString(" !\"#$%&'()*+,-.", 0, 0, 4); @@ -147,7 +145,7 @@ void loop() { img.drawString("PQRSTUVWX", 0, 104, 4); img.pushSprite(0, 0); delay(WAIT); - img.fillSprite(TFT_BROWN); + img.fillSprite(TFT_BLACK); img.drawString("YZ[\\]^_`abc", 0, 0, 4); img.drawString("defghijklmno", 0, 26, 4); img.drawString("pqrstuvwxyz", 0, 52, 4); @@ -156,7 +154,7 @@ void loop() { img.drawChar(127, xpos, 78, 4); img.pushSprite(0, 0); delay(WAIT); - img.fillSprite(TFT_BROWN); + img.fillSprite(TFT_BLACK); img.setTextColor(TFT_BLUE); img.drawString("012345", 0, 0, 6); @@ -164,29 +162,29 @@ void loop() { img.drawString("apm-:.", 0, 80, 6); img.pushSprite(0, 0); delay(WAIT); - img.fillSprite(TFT_BROWN); + img.fillSprite(TFT_BLACK); img.setTextColor(TFT_RED); img.drawString("0123", 0, 0, 7); img.drawString("4567", 0, 60, 7); img.pushSprite(0, 0); delay(WAIT); - img.fillSprite(TFT_BROWN); + img.fillSprite(TFT_BLACK); img.drawString("890:.", 0, 0, 7); img.drawString("", 0, 60, 7); img.pushSprite(0, 0); delay(WAIT); - img.fillSprite(TFT_BROWN); + img.fillSprite(TFT_BLACK); img.setTextColor(TFT_YELLOW); img.drawString("0123", 0, 0, 8); img.pushSprite(0, 0); delay(WAIT); - img.fillSprite(TFT_BROWN); + img.fillSprite(TFT_BLACK); img.drawString("4567", 0, 0, 8); img.pushSprite(0, 0); delay(WAIT); - img.fillSprite(TFT_BROWN); + img.fillSprite(TFT_BLACK); img.drawString("890:.", 0, 0, 8); img.pushSprite(0, 0); delay(WAIT); diff --git a/examples/Sprite/Sprite_drawPixel/Sprite_drawPixel.ino b/examples/Sprite/Sprite_drawPixel/Sprite_drawPixel.ino index 8dc295e..78e02f2 100644 --- a/examples/Sprite/Sprite_drawPixel/Sprite_drawPixel.ino +++ b/examples/Sprite/Sprite_drawPixel/Sprite_drawPixel.ino @@ -7,17 +7,21 @@ Example for library: https://github.com/Bodmer/TFT_eSPI - A Sprite is notionally an invisibly graphics screen that is + A Sprite is notionally an invisible graphics screen that is kept in the processors RAM. Graphics can be drawn into the Sprite just as it can be drawn directly to the screen. Once the Sprite is completed it can be plotted onto the screen in any position. If there is sufficient RAM then the Sprite can be the same size as the screen and used as a frame buffer. - The Sprite occupies (2 * width * height) bytes in RAM. + A 16 bit Sprite occupies (2 * width * height) bytes in RAM. On a ESP8266 Sprite sizes up to 126 x 160 can be accomodated, - this size requires 40kBytes of RAM. + this size requires 40kBytes of RAM for a 16 bit colour depth. + + When 8 bit colour depth sprites are created they occupy + (width * height) bytes in RAM, so larger sprites can be + created, or the RAM required is halved. */ @@ -42,6 +46,9 @@ void setup() // Initialise the TFT registers tft.init(); + // Optionally set colour depth to 8 or 16 bits, default is 16 if not spedified + // spr.setColorDepth(8); + // Create a sprite of defined size spr.createSprite(WIDTH, HEIGHT); diff --git a/examples/Sprite/Sprite_scroll_16bit/Sprite_scroll_16bit.ino b/examples/Sprite/Sprite_scroll_16bit/Sprite_scroll_16bit.ino index ce8cc1b..9d2c81b 100644 --- a/examples/Sprite/Sprite_scroll_16bit/Sprite_scroll_16bit.ino +++ b/examples/Sprite/Sprite_scroll_16bit/Sprite_scroll_16bit.ino @@ -7,7 +7,7 @@ The sketch has been tested on a 320x240 ILI9341 based TFT, it coule be adapted for other screen sizes. - A Sprite is notionally an invisibly graphics screen that is + A Sprite is notionally an invisible graphics screen that is kept in the processors RAM. Graphics can be drawn into the Sprite just as it can be drawn directly to the screen. Once the Sprite is completed it can be plotted onto the screen in diff --git a/library.json b/library.json index 8f2ba01..272da16 100644 --- a/library.json +++ b/library.json @@ -1,6 +1,6 @@ { "name": "TFT_eSPI", - "version": "0.16.16", + "version": "0.16.20", "keywords": "TFT, ESP8266, NodeMCU, ESP32, ILI9341, ST7735, ILI9163, S6D02A1, ILI9486", "description": "A TFT SPI graphics library for ESP8266", "repository": diff --git a/library.properties b/library.properties index e0ba602..e6d2e96 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=TFT_eSPI -version=0.16.16 +version=0.16.20 author=Bodmer maintainer=Bodmer sentence=A fast TFT library for ESP8266 processors and the Arduino IDE