lexus2k / lcdgfx

Driver for LCD displays running on Arduino/Avr/ESP32/Linux (including Rasperry) platforms
MIT License
375 stars 52 forks source link

Problem displaying RGB .bmp #15

Closed drewmo closed 4 years ago

drewmo commented 4 years ago

For some reason when I am trying to call display.drawBitmap16() and pass in my converted .bmp file I am not seeing the images in the correct color on the screens. I have some SSD1351 OLEDs which displays colored fonts fine when I use display.setColor() and pass in RGB_COLOR(XXX, XXX,XXX). The RGB images being displayed seem to end up shifted or switched.

For reference here is a converted image that I have created it in Photoshop using RGB mode with 8Bits/channel and saved in 565 format as required in the docs.

I convert the .bmp files using bmp2hex which outputs the following struct, I did slightly alter the output as they originally output the pixel data as a uint8_t *pixel_data which wasn't right for this library.

PROGMEM const struct {
  unsigned int   width;
  unsigned int   height;
  unsigned int   bitDepth;
  uint8_t pixel_data[1250];
} RGBTEST = {
25, 25, 16, {
0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8,
0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8,
0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8,
0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8,
0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8,
0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8,
0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0xf8, 0x00, 0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x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00,
0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00, 0x1f, 0x00,
0x1f, 0x00
}
};

//Display my image
display.drawBitmap16(0, 0, RGBTEST.width, RGBTEST.height, RGBTEST.pixel_data);

Here is what I see in Photoshop:

RGB

and here is what it looks like on my screen:

BRG

I've tried looking in the library to see if there is somewhere I need to specify the RGB order, or other similar image requirements but I am scratching my head over this. I have some more complex images I would like to display on screen which would be very difficult to alter in a way to fudge them into looking correct on the screen so I am hoping someone can let me know if maybe I am doing something wrong.

lexus2k commented 4 years ago

Hello,

First of all, I see that the tool, you use to convert bitmap to code, uses different RGB components order, than it should be for your display:

The library sends bytes from bitmap to display using the following code:

    this->m_intf.send( buffer[0] );
    this->m_intf.send( buffer[1] );

The library uses 8-bits serial 65k color mode. According to datasheet the color components should be encoded in thee sequence CCCCCBBB (first byte) BBBAAAAA (second byte). So in your case red component from your bitmap will look like 00000000 11111000 (blue with a little green shade), green will look like 11100000 00000111 ( red with a little blue shade ).

Change byte order in your bitmap. It should help

drewmo commented 4 years ago

Thanks for the help. I am trying to figure out this the conversion tool but am not where where the section is that handles the RGB order. I see there is an invert function but I am not calling that argument and it's only for XBM format images. I am working off of that and seeing if I can do some bitwise operations to change the order but that is all new to me.

For your library (lcdgfx) does it require red to be 0x00 or 0xf8? or do you mean it's a two byte pair of RED = (0x00, 0xf8), GREEN = (0xe0, 0x07), BLUE = (0x1f, 0x00). From what I can tell the image is that format.

lexus2k commented 4 years ago

I'm sorry for long reply. You need to swap bytes in your bitmap: 0x00, 0xf8, 0x00, 0xf8 -> 0xf8, 0x00, 0xf8, 0x00