You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Problem:
Using the TFT_ReadWrite_Test is returning some odd results when reading the pixel. I made some slight modifications to simply make wr static and return the bits and RGB equivalent, but I'm not getting the same value I push out. If it is 0 (black) it is always correct. However, anything above that most likely returns an invalid color due to what looks like some incorrect bit shifting.
Pixel value written = F800 (255, 0, 0)
bits: 11111000 00000000 00000000
RGB32: 248, 0, 0
Pixel value read = 7C0
bits: 00000000 11111000 00000000
RGB32: 0, 248, 0
static uint32_t wr = TFT_PURPLE;
results in:
Pixel value written = 780F (128, 0, 128)
bits: 01111000 00000000 01111000
RGB32: 120, 0, 120
Pixel value read = 3C0
bits: 00000000 01111000 00000000
RGB32: 0, 120, 0
As you can see above, the bits are getting mangled pretty good here but there is a clear pattern to it. I injected a Serial.printf in TFT_eSPI.cpp for the readpixel method:
uint8_t r = tft_Read_8();
uint8_t g = tft_Read_8();
uint8_t b = tft_Read_8();
Serial.printf("[r:%i g:%i b:%i] ", r, g, b); <--- Added this to line 1237
color = color565(r, g, b);
The output from this matches what my other code is seeing so this is not getting accurate reads. Output from TFT_PURPLE: [r:0 g:120 b:0]
Here's some pseudo code I used to read the image, then dump it afterward, along with pictures of the results; which speak for themselves.
Example 2:
#include <TFT_eSPI.h>
uint16_t SCREEN_WIDTH = 320;
uint16_t SCREEN_HEIGHT = 240;
TFT_eSPI tft = TFT_eSPI(SCREEN_WIDTH, SCREEN_HEIGHT);
uint16_t *framebuffer;
void setup() {
tft.init();
//tft.begin(); // Initialize the ILI9341 TFT Screen
tft.setRotation(0); // Rotate screen 90 clockwise
//tft.fillScreen(0);
tft.fillScreen(TFT_BLACK);
psramInit(); //initialize PSRAM
framebuffer = (uint16_t *)ps_malloc(SCREEN_WIDTH * SCREEN_HEIGHT * 16); //allocate enough space in the framefuffer
....
// draw some things here :)
....
if (framebuffer != NULL) {
fillFrameBuffer();
}
}
void fillFrameBuffer(){
int bufPos = 0;
for (uint16_t y=0; y< SCREEN_HEIGHT; y++){
for (uint16_t x=0; x< SCREEN_WIDTH; x++){
uint16_t pix = tft.readPixel(x,y);
framebuffer[bufPos] = pix;
bufPos++;
}
}
}
void drawFrameBuffer(){
TFT_eSprite fb_sprite(&tft);
fb_sprite.createSprite(back_width, back_height);
int bufPos = 0;
for (uint16_t y=0; y< SCREEN_HEIGHT; y++){
for (uint16_t x=0; x< SCREEN_WIDTH; x++){
fb_sprite.drawPixel(x, y, framebuffer[bufPos]);
bufPos++;
}
}
fb_sprite.pushSprite(0, 0);
fb_sprite.flush();
}
void loop{
delay(3000); // take picture here!
drawFrameBuffer();
}
Ignore the date, time, location and reflection with the red in it 😛
Image Before reading to frame buffer:
Image after drawing all pixels from the buffer in the sprite and pushing the sprite:
Am I missing something in the config or is there a problem with one of the settings? Or, is this a known issue with some of the drivers?
Thanks.
The text was updated successfully, but these errors were encountered:
JooJooBee666
changed the title
tft.readPixel returning mangled
tft.readPixel returning mangled colors
Jul 25, 2024
Problem:
Using the TFT_ReadWrite_Test is returning some odd results when reading the pixel. I made some slight modifications to simply make wr static and return the bits and RGB equivalent, but I'm not getting the same value I push out. If it is 0 (black) it is always correct. However, anything above that most likely returns an invalid color due to what looks like some incorrect bit shifting.
Setup information:
TFT_eSPI version: 2.5.43
PlatformIO Info: Platform espressif32 @ 6.7.0 (required: espressif32)
framework-arduinoespressif32 @ 3.20016.0 (required: platformio/framework-arduinoespressif32 @ ~3.20016.0)
Processor: ESP32 S3 N16R8V
Screen Info: SPI, IL9431 w/touch. For testing, I unhooked the TDO from MISO (they are shared normally in my setup)
Setup File: [SetupJNL_ILI9341_ESP32.zip](https://github.com/user-attachments/files/16380351/SetupJNL_ILI9341_ESP32.zip
Example 1 (Modified TFT_ReadWrite_Test):
static uint32_t wr = TFT_RED;
results in:
static uint32_t wr = TFT_PURPLE;
results in:
As you can see above, the bits are getting mangled pretty good here but there is a clear pattern to it. I injected a Serial.printf in TFT_eSPI.cpp for the readpixel method:
The output from this matches what my other code is seeing so this is not getting accurate reads. Output from TFT_PURPLE:
[r:0 g:120 b:0]
Here's some pseudo code I used to read the image, then dump it afterward, along with pictures of the results; which speak for themselves.
Example 2:
Ignore the date, time, location and reflection with the red in it 😛
Image Before reading to frame buffer:
![before-buffer-read](https://private-user-images.githubusercontent.com/1514297/352224077-4d883eaf-f2de-486e-bb25-2e18b4bd74e4.jpg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIxMDgyNjQsIm5iZiI6MTcyMjEwNzk2NCwicGF0aCI6Ii8xNTE0Mjk3LzM1MjIyNDA3Ny00ZDg4M2VhZi1mMmRlLTQ4NmUtYmIyNS0yZTE4YjRiZDc0ZTQuanBnP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcyNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MjdUMTkxOTI0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9MzVmYWY1MTkyZWY3NTYzODQ4YzRkYjRkYTc1NTkwNjNkNmNhNGIwNzdhMjAxNjViZGQ1ZTYzNjU1ZTBiYzE5OCZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.2iYz6a8Y8LZ2AB_XIqmSbaYAqM5a8yyt6oaJFFaUd2c)
Image after drawing all pixels from the buffer in the sprite and pushing the sprite:
![after-buffer-write](https://private-user-images.githubusercontent.com/1514297/352224262-1911fd21-5dcf-43f6-8e9b-4a17e5e6e05d.jpg?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjIxMDgyNjQsIm5iZiI6MTcyMjEwNzk2NCwicGF0aCI6Ii8xNTE0Mjk3LzM1MjIyNDI2Mi0xOTExZmQyMS01ZGNmLTQzZjYtOGU5Yi00YTE3ZTVlNmUwNWQuanBnP1gtQW16LUFsZ29yaXRobT1BV1M0LUhNQUMtU0hBMjU2JlgtQW16LUNyZWRlbnRpYWw9QUtJQVZDT0RZTFNBNTNQUUs0WkElMkYyMDI0MDcyNyUyRnVzLWVhc3QtMSUyRnMzJTJGYXdzNF9yZXF1ZXN0JlgtQW16LURhdGU9MjAyNDA3MjdUMTkxOTI0WiZYLUFtei1FeHBpcmVzPTMwMCZYLUFtei1TaWduYXR1cmU9ZDQwYWZlYWI3YzgwMmU2NDJmYTgwYmE1ZDgxOTFiODI0MDQ0ZDBiZTgzZTMwNzg1MGM4OTRkYzhmODc3NDQ0NiZYLUFtei1TaWduZWRIZWFkZXJzPWhvc3QmYWN0b3JfaWQ9MCZrZXlfaWQ9MCZyZXBvX2lkPTAifQ.879uqvJG_hMqahCOxb5kQdvnNC5dSSJGLUctmrEu3gY)
Am I missing something in the config or is there a problem with one of the settings? Or, is this a known issue with some of the drivers?
Thanks.
The text was updated successfully, but these errors were encountered: