Hi All,
My first post here, so I hope it is useful (although I might have had a login for this site a long time ago, I don't remember). I have used the Arduino in projects for years.
If anybody is interested, I have created a utility which will autogenerate code that can be pasted into the IDE from a source image file. A function is also provided to draw the image on an Elegoo TFT (maybe it will work on others - feedback please). The image is run length encoded to save space and is placed in the Flash memory.
Example:
const PROGMEM uint16_t water_image[] = {
22, //Image Width
19, //Image Height
10 , 65535 , 3 , 0 , 9 , 65535 ,
12 , 65535 , 1 , 0 , 9 , 65535 ,
11 , 65535 , 2 , 0 , 9 , 65535 ,
10 , 65535 , 2 , 0 , 10 , 65535 ,
22 , 65535 ,
10 , 65535 , 2 , 0 , 10 , 65535 ,
22 , 65535 ,
9 , 0 , 4 , 65535 , 9 , 0 ,
1 , 0 , 20 , 65535 , 1 , 0 ,
1 , 0 , 20 , 65535 , 1 , 0 ,
1 , 0 , 20 , 65535 , 1 , 0 ,
1 , 0 , 20 , 65535 , 1 , 0 ,
1 , 0 , 3 , 65535 , 1 , 0 , 6 , 65535 , 1 , 0 , 5 , 65535 , 1 , 0 , 3 , 65535 , 1 , 0 ,
1 , 0 , 2 , 65535 , 2 , 0 , 5 , 65535 , 2 , 0 , 5 , 65535 , 2 , 0 , 2 , 65535 , 1 , 0 ,
6 , 0 , 3 , 65535 , 4 , 0 , 3 , 65535 , 6 , 0 ,
22 , 0 ,
22 , 0 ,
22 , 0 ,
22 , 0 ,
0,0};
void translateDraw(unsigned int cx, unsigned int cy, unsigned int repeat, uint16_t value)
{
if (repeat>1)
{
tft.drawFastHLine(cx, cy,repeat, value);
}
else
{
tft.drawPixel(cx,cy,value);
}
}
void rlebmpdraw(int x, int y, const uint16_t *sram_address, bool inverted)
{
uint32_t time = millis();
unsigned int cx,cy;
cx=0;
cy=0;
unsigned int arrayIndex=0;
unsigned int width = pgm_read_word(sram_address+arrayIndex++);
unsigned int height = pgm_read_word(sram_address+arrayIndex++);
uint16_t white = 0xffff;
do
{
unsigned int repeat = pgm_read_word(sram_address+arrayIndex);
unsigned int value = pgm_read_word(sram_address+arrayIndex+1);
if (repeat==0)
break;
unsigned int colour = value;
while ((cx+repeat)>width)
{
if (colour!=white)
{
translateDraw(x+cx, y+cy, width-cx, colour);
}
int newValue=repeat - (width-cx);
if (newValue<0)
{
repeat = 0;
}
else
{
repeat = newValue;
}
cx=0;
cy++;
}
if (colour!=white)
{
translateDraw(x+cx, y+cy, repeat, colour);
}
cx+=repeat;
if (cx>=width)
{
cx=0;
cy++;
}
arrayIndex+=2;
}while(1);
}
//Call with - rlebmpdraw(xpos, ypos, water_image, false); //Draw at x,y
//It is expected that tft has been defined and initialised
In summary you select an image file (.jpg, .gif, .png) and it generates code for you.
You can then draw the image with a call to this function,
void rlebmpdraw(int x, int y, const uint16_t *sram_address, bool inverted)
e.g.
rlebmpdraw(20,10,water_image, false); //draw water image (not colour inverted) at 20, 10.
The link to the page with the software on it is here...
https://www.dragons-fire.co.uk/image-to-tft/
(I should mention it is Windows only currently but it is written in Qt, so if anyone wants to convert it... )
Thanks,
Taf.