forked from Bodmer/TFT_eSPI
Fixed color data type and using new random utils
This commit is contained in:
@@ -10,6 +10,9 @@ set(dependencies
|
||||
arduino-esp32
|
||||
freertos
|
||||
esp_system
|
||||
|
||||
cpputils
|
||||
espcpputils
|
||||
)
|
||||
|
||||
idf_component_register(
|
||||
|
21
TFT_eSPI.cpp
21
TFT_eSPI.cpp
@@ -16,6 +16,9 @@
|
||||
|
||||
#include "TFT_eSPI.h"
|
||||
|
||||
#include <esprandom.h>
|
||||
#include <randomutils.h>
|
||||
|
||||
#if defined (ESP32)
|
||||
#if defined(CONFIG_IDF_TARGET_ESP32S3)
|
||||
#include "Processors/TFT_eSPI_ESP32_S3.c" // Tested with SPI and 8 bit parallel
|
||||
@@ -3006,7 +3009,7 @@ int16_t TFT_eSPI::fontHeight(void)
|
||||
** Function name: drawChar
|
||||
** Description: draw a single character in the GLCD or GFXFF font
|
||||
***************************************************************************************/
|
||||
void TFT_eSPI::drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uint32_t bg, uint8_t size)
|
||||
void TFT_eSPI::drawChar(int32_t x, int32_t y, uint16_t c, uint16_t color, uint16_t bg, uint8_t size)
|
||||
{
|
||||
if (_vpOoB) return;
|
||||
|
||||
@@ -3391,7 +3394,7 @@ void TFT_eSPI::readAddrWindow(int32_t xs, int32_t ys, int32_t w, int32_t h)
|
||||
** Function name: drawPixel
|
||||
** Description: push a single pixel at an arbitrary position
|
||||
***************************************************************************************/
|
||||
void TFT_eSPI::drawPixel(int32_t x, int32_t y, uint32_t color)
|
||||
void TFT_eSPI::drawPixel(int32_t x, int32_t y, uint16_t color)
|
||||
{
|
||||
if (_vpOoB) return;
|
||||
|
||||
@@ -3675,7 +3678,7 @@ void TFT_eSPI::pushColors(uint16_t *data, uint32_t len, bool swap)
|
||||
***************************************************************************************/
|
||||
// Bresenham's algorithm - thx wikipedia - speed enhanced by Bodmer to use
|
||||
// an efficient FastH/V Line draw routine for line segments of 2 pixels or more
|
||||
void TFT_eSPI::drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint32_t color)
|
||||
void TFT_eSPI::drawLine(int32_t x0, int32_t y0, int32_t x1, int32_t y1, uint16_t color)
|
||||
{
|
||||
if (_vpOoB) return;
|
||||
|
||||
@@ -3985,7 +3988,7 @@ inline float TFT_eSPI::wedgeLineDistance(float xpax, float ypay, float bax, floa
|
||||
** Function name: drawFastVLine
|
||||
** Description: draw a vertical line
|
||||
***************************************************************************************/
|
||||
void TFT_eSPI::drawFastVLine(int32_t x, int32_t y, int32_t h, uint32_t color)
|
||||
void TFT_eSPI::drawFastVLine(int32_t x, int32_t y, int32_t h, uint16_t color)
|
||||
{
|
||||
if (_vpOoB) return;
|
||||
|
||||
@@ -4015,7 +4018,7 @@ void TFT_eSPI::drawFastVLine(int32_t x, int32_t y, int32_t h, uint32_t color)
|
||||
** Function name: drawFastHLine
|
||||
** Description: draw a horizontal line
|
||||
***************************************************************************************/
|
||||
void TFT_eSPI::drawFastHLine(int32_t x, int32_t y, int32_t w, uint32_t color)
|
||||
void TFT_eSPI::drawFastHLine(int32_t x, int32_t y, int32_t w, uint16_t color)
|
||||
{
|
||||
if (_vpOoB) return;
|
||||
|
||||
@@ -4045,7 +4048,7 @@ void TFT_eSPI::drawFastHLine(int32_t x, int32_t y, int32_t w, uint32_t color)
|
||||
** Function name: fillRect
|
||||
** Description: draw a filled rectangle
|
||||
***************************************************************************************/
|
||||
void TFT_eSPI::fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color)
|
||||
void TFT_eSPI::fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t color)
|
||||
{
|
||||
if (_vpOoB) return;
|
||||
|
||||
@@ -4214,7 +4217,7 @@ uint32_t TFT_eSPI::color16to24(uint16_t color565)
|
||||
** Function name: color24to16
|
||||
** Description: convert 24 bit colour to a 16 bit 565 colour value
|
||||
***************************************************************************************/
|
||||
uint32_t TFT_eSPI::color24to16(uint32_t color888)
|
||||
uint16_t TFT_eSPI::color24to16(uint32_t color888)
|
||||
{
|
||||
uint16_t r = (color888 >> 8) & 0xF800;
|
||||
uint16_t g = (color888 >> 5) & 0x07E0;
|
||||
@@ -4398,7 +4401,7 @@ uint16_t TFT_eSPI::alphaBlend(uint8_t alpha, uint16_t fgc, uint16_t bgc)
|
||||
uint16_t TFT_eSPI::alphaBlend(uint8_t alpha, uint16_t fgc, uint16_t bgc, uint8_t dither)
|
||||
{
|
||||
if (dither) {
|
||||
int16_t alphaDither = (int16_t)alpha - dither + random(2*dither+1); // +/-4 randomised
|
||||
int16_t alphaDither = (int16_t)alpha - dither + cpputils::randomNumber<long>(2*dither, espcpputils::esp_random_device{}); // +/-4 randomised
|
||||
alpha = (uint8_t)alphaDither;
|
||||
if (alphaDither < 0) alpha = 0;
|
||||
if (alphaDither >255) alpha = 255;
|
||||
@@ -4415,7 +4418,7 @@ uint32_t TFT_eSPI::alphaBlend24(uint8_t alpha, uint32_t fgc, uint32_t bgc, uint8
|
||||
{
|
||||
|
||||
if (dither) {
|
||||
int16_t alphaDither = (int16_t)alpha - dither + random(2*dither+1); // +/-dither randomised
|
||||
int16_t alphaDither = (int16_t)alpha - dither + cpputils::randomNumber<long>(2*dither, espcpputils::esp_random_device{}); // +/-dither randomised
|
||||
alpha = (uint8_t)alphaDither;
|
||||
if (alphaDither < 0) alpha = 0;
|
||||
if (alphaDither >255) alpha = 255;
|
||||
|
66
TFT_eSPI.h
66
TFT_eSPI.h
@@ -262,31 +262,31 @@ const PROGMEM fontinfo fontdata [] = {
|
||||
** Section 6: Colour enumeration
|
||||
***************************************************************************************/
|
||||
// Default color definitions
|
||||
constexpr auto TFT_BLACK = 0x0000; /* 0, 0, 0 */
|
||||
constexpr auto TFT_NAVY = 0x000F; /* 0, 0, 128 */
|
||||
constexpr auto TFT_DARKGREEN = 0x03E0; /* 0, 128, 0 */
|
||||
constexpr auto TFT_DARKCYAN = 0x03EF; /* 0, 128, 128 */
|
||||
constexpr auto TFT_MAROON = 0x7800; /* 128, 0, 0 */
|
||||
constexpr auto TFT_PURPLE = 0x780F; /* 128, 0, 128 */
|
||||
constexpr auto TFT_OLIVE = 0x7BE0; /* 128, 128, 0 */
|
||||
constexpr auto TFT_LIGHTGREY = 0xD69A; /* 211, 211, 211 */
|
||||
constexpr auto TFT_DARKGREY = 0x7BEF; /* 128, 128, 128 */
|
||||
constexpr auto TFT_BLUE = 0x001F; /* 0, 0, 255 */
|
||||
constexpr auto TFT_GREEN = 0x07E0; /* 0, 255, 0 */
|
||||
constexpr auto TFT_CYAN = 0x07FF; /* 0, 255, 255 */
|
||||
constexpr auto TFT_RED = 0xF800; /* 255, 0, 0 */
|
||||
constexpr auto TFT_MAGENTA = 0xF81F; /* 255, 0, 255 */
|
||||
constexpr auto TFT_YELLOW = 0xFFE0; /* 255, 255, 0 */
|
||||
constexpr auto TFT_WHITE = 0xFFFF; /* 255, 255, 255 */
|
||||
constexpr auto TFT_GREY = 0x5AEB;
|
||||
constexpr auto TFT_ORANGE = 0xFDA0; /* 255, 180, 0 */
|
||||
constexpr auto TFT_GREENYELLOW = 0xB7E0; /* 180, 255, 0 */
|
||||
constexpr auto TFT_PINK = 0xFE19; /* 255, 192, 203 */ //Lighter pink, was 0xFC9F
|
||||
constexpr auto TFT_BROWN = 0x9A60; /* 150, 75, 0 */
|
||||
constexpr auto TFT_GOLD = 0xFEA0; /* 255, 215, 0 */
|
||||
constexpr auto TFT_SILVER = 0xC618; /* 192, 192, 192 */
|
||||
constexpr auto TFT_SKYBLUE = 0x867D; /* 135, 206, 235 */
|
||||
constexpr auto TFT_VIOLET = 0x915C; /* 180, 46, 226 */
|
||||
constexpr uint16_t TFT_BLACK = 0x0000; /* 0, 0, 0 */
|
||||
constexpr uint16_t TFT_NAVY = 0x000F; /* 0, 0, 128 */
|
||||
constexpr uint16_t TFT_DARKGREEN = 0x03E0; /* 0, 128, 0 */
|
||||
constexpr uint16_t TFT_DARKCYAN = 0x03EF; /* 0, 128, 128 */
|
||||
constexpr uint16_t TFT_MAROON = 0x7800; /* 128, 0, 0 */
|
||||
constexpr uint16_t TFT_PURPLE = 0x780F; /* 128, 0, 128 */
|
||||
constexpr uint16_t TFT_OLIVE = 0x7BE0; /* 128, 128, 0 */
|
||||
constexpr uint16_t TFT_LIGHTGREY = 0xD69A; /* 211, 211, 211 */
|
||||
constexpr uint16_t TFT_DARKGREY = 0x7BEF; /* 128, 128, 128 */
|
||||
constexpr uint16_t TFT_BLUE = 0x001F; /* 0, 0, 255 */
|
||||
constexpr uint16_t TFT_GREEN = 0x07E0; /* 0, 255, 0 */
|
||||
constexpr uint16_t TFT_CYAN = 0x07FF; /* 0, 255, 255 */
|
||||
constexpr uint16_t TFT_RED = 0xF800; /* 255, 0, 0 */
|
||||
constexpr uint16_t TFT_MAGENTA = 0xF81F; /* 255, 0, 255 */
|
||||
constexpr uint16_t TFT_YELLOW = 0xFFE0; /* 255, 255, 0 */
|
||||
constexpr uint16_t TFT_WHITE = 0xFFFF; /* 255, 255, 255 */
|
||||
constexpr uint16_t TFT_GREY = 0x5AEB;
|
||||
constexpr uint16_t TFT_ORANGE = 0xFDA0; /* 255, 180, 0 */
|
||||
constexpr uint16_t TFT_GREENYELLOW = 0xB7E0; /* 180, 255, 0 */
|
||||
constexpr uint16_t TFT_PINK = 0xFE19; /* 255, 192, 203 */ //Lighter pink, was 0xFC9F
|
||||
constexpr uint16_t TFT_BROWN = 0x9A60; /* 150, 75, 0 */
|
||||
constexpr uint16_t TFT_GOLD = 0xFEA0; /* 255, 215, 0 */
|
||||
constexpr uint16_t TFT_SILVER = 0xC618; /* 192, 192, 192 */
|
||||
constexpr uint16_t TFT_SKYBLUE = 0x867D; /* 135, 206, 235 */
|
||||
constexpr uint16_t TFT_VIOLET = 0x915C; /* 180, 46, 226 */
|
||||
|
||||
// Next is a special 16 bit colour value that encodes to 8 bits
|
||||
// and will then decode back to the same 16 bit value.
|
||||
@@ -398,12 +398,12 @@ class TFT_eSPI { friend class TFT_eSprite; // Sprite class has access to protect
|
||||
void init(uint8_t tc = TAB_COLOUR), begin(uint8_t tc = TAB_COLOUR);
|
||||
|
||||
// These are virtual so the TFT_eSprite class can override them with sprite specific functions
|
||||
virtual void drawPixel(int32_t x, int32_t y, uint32_t color),
|
||||
drawChar(int32_t x, int32_t y, uint16_t c, uint32_t color, uint32_t bg, uint8_t size),
|
||||
drawLine(int32_t xs, int32_t ys, int32_t xe, int32_t ye, uint32_t color),
|
||||
drawFastVLine(int32_t x, int32_t y, int32_t h, uint32_t color),
|
||||
drawFastHLine(int32_t x, int32_t y, int32_t w, uint32_t color),
|
||||
fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color);
|
||||
virtual void drawPixel(int32_t x, int32_t y, uint16_t color),
|
||||
drawChar(int32_t x, int32_t y, uint16_t c, uint16_t color, uint16_t bg, uint8_t size),
|
||||
drawLine(int32_t xs, int32_t ys, int32_t xe, int32_t ye, uint16_t color),
|
||||
drawFastVLine(int32_t x, int32_t y, int32_t h, uint16_t color),
|
||||
drawFastHLine(int32_t x, int32_t y, int32_t w, uint16_t color),
|
||||
fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint16_t color);
|
||||
|
||||
virtual int16_t drawChar(uint16_t uniCode, int32_t x, int32_t y, uint8_t font),
|
||||
drawChar(uint16_t uniCode, int32_t x, int32_t y),
|
||||
@@ -634,7 +634,7 @@ class TFT_eSPI { friend class TFT_eSprite; // Sprite class has access to protect
|
||||
|
||||
// Convert 16 bit colour to/from 24 bit, R+G+B concatenated into LS 24 bits
|
||||
uint32_t color16to24(uint16_t color565);
|
||||
uint32_t color24to16(uint32_t color888);
|
||||
uint16_t color24to16(uint32_t color888);
|
||||
|
||||
// Alpha blend 2 colours, see generic "alphaBlend_Test" example
|
||||
// alpha = 0 = 100% background colour
|
||||
@@ -722,7 +722,7 @@ class TFT_eSPI { friend class TFT_eSprite; // Sprite class has access to protect
|
||||
// Global variables
|
||||
static SPIClass& getSPIinstance(void); // Get SPI class handle
|
||||
|
||||
uint32_t textcolor, textbgcolor; // Text foreground and background colours
|
||||
uint16_t textcolor, textbgcolor; // Text foreground and background colours
|
||||
|
||||
uint32_t bitmap_fg, bitmap_bg; // Bitmap foreground (bit=1) and background (bit=0) colours
|
||||
|
||||
|
Reference in New Issue
Block a user