Strange behaviour with setColorDepth #2822
Replies: 3 comments 1 reply
-
I tried this code and it works fine:
Note that you must use the palette index rather than a 16 bit colour for fill/draw operations in a 4 bit sprite. So index 6 is blue in the default palette. In your sketch the (uint16_t)0b0000000000011111 would be trucated to a 4 bit index of valu 15 which is pink in the palette. However that is not the cause of the strange output in your case. Since it works for me (try tha above sketch just to be sure) there must be something different about your software environment (version numbers etc). |
Beta Was this translation helpful? Give feedback.
-
Good morning, I got it .... but I have no explanation. The code you posted produces at my environment the same weird graphics. Something must have changed at this stage of the lib and maybe you know it. Any way! Thank you! |
Beta Was this translation helpful? Give feedback.
-
Hello Bodmer,
and once again thank you for your work!
I wanted to create a sprite with screen size. RAM on ESP32 is large enough for 8-Bit color depth,
but I do not need this depth so I changed it with setColorDepth(4) and made first small tests.
I encountered then a (for me) strange thing:
As a test I created a filled rectangle in the sprite and then pushed it. The fill color I set to full blue.
(Bits 0-4 of color = 1)
(As a template I used for that your example Sprite_image_4bit and changed the pushImage to fillRect and cut the code at this position)
With setColorDepth(8) everything works as expected.
After changing to setColorDepth(4) I expected only some change in color. But what I saw is a rectangle 4 times in size filled with something streched ....
Why does setColorDepth has an impact to the given coordinates or dimensions?
Or better said: What did I wrong?
In the following the code and pictures with 8 and 4 bit colorDepth (sorry for the dirty displays... :-).
Can you help?
Best regards from Hamburg
Andree
`
// Set delay after plotting the sprite
#define DELAY 30
// Width and height of sprite
//#define WIDTH 164
//#define HEIGHT 164 (I use TFT_WIDTH/HEIGHT
#include "sample_images.h"
TFT_eSPI tft = TFT_eSPI(); // Declare object "tft"
TFT_eSprite spr = TFT_eSprite(&tft); // Declare Sprite object "spr" with pointer to "tft" object
byte red = 31; // Red is the top 5 bits of a 16 bit colour value
byte green = 0;// Green is the middle 6 bits
byte blue = 0; // Blue is the bottom 5 bits
byte state = 0;
int rloop = 0;
int incr = 1;
uint16_t cmap[16];
void setup()
{
Serial.begin(9600);
Serial.println();
delay(50);
// Initialise the TFT registers
tft.init();
spr.setColorDepth(8); //<<<<<<<<<<<<<< CHANGE HERE
// spr.setColorDepth(4); //<<<<<<<<<<<<<< CHANGE HERE
// Create a sprite of defined size
spr.createSprite(TFT_WIDTH, TFT_HEIGHT);
// Clear the TFT screen to black
tft.fillScreen(TFT_BLACK);
spr.fillRect(10, 10, 40, 40, (uint16_t)0b0000000000011111);
spr.pushSprite(10,10);
}
void loop(void)
{
}
`
Beta Was this translation helpful? Give feedback.
All reactions