16-bit BMP image not loading

Emans

Member
"I'm once again asking for your [financial] support"

Hi everyone, I'm back on this forum.
Last time I asked some questions about a RA8875 display, and after solving the problem (many many thanks to the guys who guided me) I'm ready to implement the system in its final destination... or that's what I thought.

A new challenger approached: the UI layout.

After ditching the idea to use the standard RA8875.h draw functions to make my own graphics (since it's a bit too cumbersome and little polished I'm leaving it as a last resort), I've tried the BMP-file-on-SD approach, with discrete success...
I still have not managed to make the RA8875 on-board SD slot to work via SPI, but the Teensy 4.1 integrated one works like a charm, and the loading times for a 480x272 (~250 ms) is good enough for a one-time loaded image (on startup).

The only problem is that the SDTest example file (alert.bmp) is a 24-bit file and the display is only capable of displaying 16-bit colors, and the result is a completely wrong colour (but with the correct shading).

If I try to feed a BMP RGB565 (or any other Bitmap 16-bit formats such as A1RGB555 or X1RGB555) to the example code, it triggers this
C-like:
//previous code
    if ((bmpDepth == 16) && (read32(bmpFile)) == 0)  {
    //rest of code here
    }
//some } from previous conditions
  bmpFile.close();
  if (!goodBmp) {
    Serial.println("BMP format not recognized.");
    //else condition
  }
part of the code, displaying "BMP format not recognized".
I also found that changing
C-like:
 (read32(bmpFile)) == 0)
to
C-like:
 (read32(bmpFile)) == 3)
does not trigger the BMP invalid format condition, and displays the image like in the attached photo (incorrectly). Every value between 0 and 2 triggers the invalid format warning. If I get it right, a value of 0 means an uncompressed image, a 1 or a 2 means a RLE compressed file?
Also, converting the 24-bit to 16-bit 565 with ImageMagick ended the same way as exporting the file through GIMP in RGB565 format, which means a garbage and almost monochromatic image.

I'm currently seeking any advice possible on how to read and correctly display these type of images, the easier the better...

( Reference for the photos: alert.bmp is 24-bit, alert1.bmp is the 16-bit RGB one, alert.jpg is the original test image)
 

Attachments

  • alert16-bit_display.jpg
    alert16-bit_display.jpg
    157.6 KB · Views: 20
  • Alert24-bit_output.jpg
    Alert24-bit_output.jpg
    235.1 KB · Views: 18
  • alert16-bit_output.jpg
    alert16-bit_output.jpg
    248.1 KB · Views: 25
  • Alert24-bit_display.jpg
    Alert24-bit_display.jpg
    169.5 KB · Views: 24
  • alert.jpg
    alert.jpg
    17.9 KB · Views: 20
Most of the BMP loading sketches I have played with (and adapted) look for 24 bit BMP files and require the read to be zero, which I believe says that file is not compressed.

Example sketch is included in several of our graphic libraries, like, my ILI9341_t3n, here is a link to some of that sketch


The sketches take the RGB888 format and convert it to RGB565 (16 bits) as it reads in the data.

I have some other sketches I am playing with, for some displays that support 24 bit mode, it converts it to the sortof RGB8888 format,
where high byte is 0xff (like the JPEG decoder does)...

I don't know if anyone around has code that handles compression.
 
Most of the BMP loading sketches I have played with (and adapted) look for 24 bit BMP files and require the read to be zero, which I believe says that file is not compressed.

Example sketch is included in several of our graphic libraries, like, my ILI9341_t3n, here is a link to some of that sketch


The sketches take the RGB888 format and convert it to RGB565 (16 bits) as it reads in the data.
Thanks for the link, it seems quite a complicated sketch... I'll try to understand what happens there.

As I have access to 'native' RGB565 BMP files, do you reckon I could extrapolate the 'reading' part of your sketch (without the conversion) and combine it with the 'writing' part of the RA8875 example?

Since the problem with the examples seems to lie in the way it reads the data, maybe swapping that part with a 16-bit code may be enough...?
 
Thanks for the link, it seems quite a complicated sketch... I'll try to understand what happens there.
Sorry, yes it it setup to loop through the root folder of SDCard and display BMP, JPEG, and PNG files.

I should mention that a lot of the initial code for reading BMP files was from Adafruit. They used to have a sketch to display a file
from SD in their Adafruit_ILI9341 library. They have since then moved the example out of this sketch and created a new library for it

You can read more about this library up at:
 
Sorry, yes it it setup to loop through the root folder of SDCard and display BMP, JPEG, and PNG files.

I should mention that a lot of the initial code for reading BMP files was from Adafruit. They used to have a sketch to display a file
from SD in their Adafruit_ILI9341 library. They have since then moved the example out of this sketch and created a new library for it

You can read more about this library up at:
Thanks, I'm reading the description of the library, but it says that only uncompressed 24-bit bmp files can be read... Seems like no one really care about 16 bit ones.
At this point I'm unsure if I should try to implement the previous code, using 24-bit images and converting them to 16-bit within the code...

I'm not too fancy about this option, but definitely unable to make a new code from scratch since I have mostly no Informatics experience
 
Back
Top