Export for ILI9341_t3 with GIMP

Status
Not open for further replies.

iwanders

Well-known member
Yesterday I was working with the ILI9341 library and came across the pictureEmbed example. I quite liked the idea of using custom images into my project, when I got to the image conversion part I discovered that GIMP provides the required functionality out of the box. I thought I'd share this; a screenshot that explains the steps:
export_as_c_guid.png

In text:
1. File -> Export As
2. In the Export Image dialog, use 'C source code (*.c)' as filetype.
3. Press export to get the export options dialog.
4. Type the desired variable name into the 'prefixed name' box.
5. Uncheck 'GLIB types (guint8*)'
6. Check 'Save as RGB565 (16-bit)'
7. Press export to save your image.

This results in C file (attached as purple.c) that looks like this:
Code:
static const struct {
  unsigned int 	 width;
  unsigned int 	 height;
  unsigned int 	 bytes_per_pixel; /* 2:RGB16, 3:RGB, 4:RGBA */ 
  unsigned char	 pixel_data[240 * 320 * 2 + 1];
} image_name = {
  240, 320, 2,
  "\236\233\274\202...", // a lot more data here...
};

The advantage of using the GIMP to export the file this is that you get all the required information in this one file directly when you save the image. You can then read the width and height from the structure and use the image's data with the following code:
Code:
// include the image, just as in the example.
#include "purple.c"
// Write the image, taking the width, height and data from the structure in the purple.c file
tft.writeRect(0, 0, image_name.width, image_name.height, (uint16_t*)(image_name.pixel_data));


View attachment purple.c
 
Hello, How are you? I have an error like this: (Can you help me please?)
Arduino:1.8.7 (Windows 10), Tarjeta:"Arduino/Genuino Uno"

piso1.c:7:18: error: size of array 'pixel_data' is negative

unsigned char pixel_data[194 * 154 * 2 + 1];

^

exit status 1
size of array 'pixel_data' is negative
 
Hello, How are you? I have an error like this: (Can you help me please?)
Arduino:1.8.7 (Windows 10), Tarjeta:"Arduino/Genuino Uno"

piso1.c:7:18: error: size of array 'pixel_data' is negative

unsigned char pixel_data[194 * 154 * 2 + 1];

^

exit status 1
size of array 'pixel_data' is negative

You might want to ask this on Arduino forum or the like as this forum is specific to Teensy processors made by PJRC...

But: what you are asking for is an array of 59137 entries of byte size.
FIrst issue is the computation was probably done with signed 16 bit integers and that value won't fit into an signed 16 bit value (i.e. is > 327767) so is negative number.

But other real issue is, that even if this computation worked. (for example if you computed it using unsigned integers...
An array of about 59K bytes in size will not fit on an Arduino UNO which I believe only has 2K of RAM.
 
You might want to ask this on Arduino forum or the like as this forum is specific to Teensy processors made by PJRC...

But: what you are asking for is an array of 59137 entries of byte size.
FIrst issue is the computation was probably done with signed 16 bit integers and that value won't fit into an signed 16 bit value (i.e. is > 327767) so is negative number.

But other real issue is, that even if this computation worked. (for example if you computed it using unsigned integers...
An array of about 59K bytes in size will not fit on an Arduino UNO which I believe only has 2K of RAM.


I think const array should go to flash, anyway just 32k for UNO and to large (rest of program needs flash space also)
 
I think const array should go to flash, anyway just 32k for UNO and to large (rest of program needs flash space also)

Note: He did not mention const in his message...

But Yes - on Teensy const unsigned char[59137] = ...
Would be put into code space...

But on UNO (AVR) boards, which have different code spaces for Program versus data, for those you need to add the keyword PROGMEM
And you need to use special memory access functions/macros to get the data from the code space
 
Status
Not open for further replies.
Back
Top