Skip to main content
antonius
Associate III
April 11, 2014
Question

Decoding bmp ?

  • April 11, 2014
  • 90 replies
  • 37500 views
Posted on April 11, 2014 at 11:21

Guys,

Does anyone of you have experience on decoding bmp ?

I want to display bmp file to my LCD...

Any clues ?

thanks

#i-have-a-clue
    This topic has been closed for replies.

    90 replies

    antonius
    antoniusAuthor
    Associate III
    April 19, 2014
    Posted on April 19, 2014 at 04:06

    I don't understand, it's already working on your side ? do I miss some registers on my init ?

    I used your LCD init, still the same result....it's not from the init...

    antonius
    antoniusAuthor
    Associate III
    April 19, 2014
    Posted on April 19, 2014 at 04:08

    I used the same init you have, still the same result,

    Do I miss something in my LCD bitmap function ? thanks

    antonius
    antoniusAuthor
    Associate III
    April 19, 2014
    Posted on April 19, 2014 at 04:26

    wild guess

        pal = ((pal & 0x1F0000) >> 8) | ((pal & 0x007E00) >> 5) | ((pal & 0x0000F8) >> 3);

    giving me a greenish mix with blueish....

    antonius
    antoniusAuthor
    Associate III
    April 19, 2014
    Posted on April 19, 2014 at 04:34

    I fixed it,

     f_read(&fsrc, hdr_256, sizeof(hdr_256), &bytesread); // Read header

    I missed

    sizeof(hdr) supposed to be sizeof(hdr_256),

     

     f_read(&fsrc, hdr_256, sizeof(hdr), &bytesread); // Read header

    Thanks a lot for helping me out,

    for example I want to use 16K colors, I just change the 256 loop ?

    It works now

    http://youtu.be/BC2m2Yg5xDg

    antonius
    antoniusAuthor
    Associate III
    April 19, 2014
    Posted on April 19, 2014 at 04:58

    for 16K color will be like this ? please correct me if I'm wrong, thanks

    
    //16K color bmp
    
    res = f_open(&fsrc, ''test9.bmp'', FA_READ);
    
    
    f_read(&fsrc, hdr_256, sizeof(hdr_256), &bytesread); // Read header
    
    
    off = *((uint32_t *)&hdr_256[0x0A]); // offset to rasters
    
    
    xx = *((uint32_t *)&hdr_256[0x12]); // X pixels
    
    
    yy = *((uint32_t *)&hdr_256[0x16]); // Y pixels
    
    
    for(i=0; i<
    16384
    ; i++) // Build palette conversion (+0x46 count?)
    
    {
    
    uint32_t pal;
    
    
    f_read(&fsrc, &pal, 4, &bytesread); // Read palette B G R
    
    
    // RRRRRRRRGGGGGGGGBBBBBBBB 8:8:8
    
    // BBBBBGGGGGGRRRRR 5:6:5
    
    
    //pal = ((pal & 0x00FC00) >> 5) | ((pal & 0xF80000) >> 19) | ((pal & 0x0000F8) << 
    8
    );
    
    pal = ((pal & 0xF80000) >> 8) | ((pal & 0x00FC00) >> 5) | ((pal & 0x0000F8) >> 3);
    
    //pal = ((pal & 0x1F0000) >> 8) | ((pal & 0x007E00) >> 5) | ((pal & 0x0000F8) >> 3);
    
    
    w[i] = (uint16_t)pal; 
    
    }
    
    
    f_lseek(&fsrc, off); // Seek to the data
    
    
    for(y=0; y<yy; y++)
    
    {
    
    for(x=0; x<xx; x++)
    
    {
    
    uint8_t b;
    
    
    f_read(&fsrc, &b, 1, &bytesread); // Read byte
    
    
    LCD_SetPoint(y, x, w[b]); // Colour Map
    
    } // x
    
    } // y
    
    
    f_close(&fsrc);

    Tesla DeLorean
    Guru
    April 19, 2014
    Posted on April 19, 2014 at 04:59

    for example I want to use 16M colors, I just change the 256 loop ?

    The high colour depth files don't need the palette tables, each pixel is described individually, and you'd need to transform into the 5:6:5 64K colour space of the display, or whatever it is capable of.

    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    antonius
    antoniusAuthor
    Associate III
    April 19, 2014
    Posted on April 19, 2014 at 05:02

    for 16K color will be like this ? please correct me if I'm wrong, thanks

    
    //16K color bmp
    
    res = f_open(&fsrc, ''test9.bmp'', FA_READ);
    
    
    f_read(&fsrc, hdr_256, sizeof(hdr_256), &bytesread); // Read header
    
    
    off = *((uint32_t *)&hdr_256[0x0A]); // offset to rasters
    
    
    xx = *((uint32_t *)&hdr_256[0x12]); // X pixels
    
    
    yy = *((uint32_t *)&hdr_256[0x16]); // Y pixels
    
    
    for(i=0; i<
    16384
    ; i++) // Build palette conversion (+0x46 count?)
    
    {
    
    uint32_t pal;
    
    
    f_read(&fsrc, &pal, 4, &bytesread); // Read palette B G R
    
    
    // RRRRRRRRGGGGGGGGBBBBBBBB 8:8:8
    
    // BBBBBGGGGGGRRRRR 5:6:5
    
    
    //pal = ((pal & 0x00FC00) >> 5) | ((pal & 0xF80000) >> 19) | ((pal & 0x0000F8) << 
    8
    );
    
    pal = ((pal & 0xF80000) >> 8) | ((pal & 0x00FC00) >> 5) | ((pal & 0x0000F8) >> 3);
    
    //pal = ((pal & 0x1F0000) >> 8) | ((pal & 0x007E00) >> 5) | ((pal & 0x0000F8) >> 3);
    
    
    w[i] = (uint16_t)pal; 
    
    }
    
    
    f_lseek(&fsrc, off); // Seek to the data
    
    
    for(y=0; y<yy; y++)
    
    {
    
    for(x=0; x<xx; x++)
    
    {
    
    uint8_t b;
    
    
    f_read(&fsrc, &b, 1, &bytesread); // Read byte
    
    
    LCD_SetPoint(y, x, w[b]); // Colour Map
    
    } // x
    
    } // y
    
    
    f_close(&fsrc);

    antonius
    antoniusAuthor
    Associate III
    April 19, 2014
    Posted on April 19, 2014 at 05:11

    do you have example for it ? thanks

    Tesla DeLorean
    Guru
    April 19, 2014
    Posted on April 19, 2014 at 05:14

    for 16K color will be like this ? please correct me if I'm wrong, thanks

    16K? Don't you mean 24-bit 16M? There isn't a palette table, you go directly to the pixel data, and then you have to convert that to the colour space of your display.
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
    Tesla DeLorean
    Guru
    April 19, 2014
    Posted on April 19, 2014 at 05:19

    do you have example for it ? thanks

    Like all of these I'd have to write one, do you have a sample 24-bit 320x240 image as a reference?
    Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..