cancel
Showing results for 
Search instead for 
Did you mean: 

Decoding bmp ?

antonius
Senior
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
90 REPLIES 90
antonius
Senior
Posted on April 19, 2014 at 03:28

Thanks for the init code,

Could it be because of init code ? It's a bit strange for me, it's working in your side but not in me ?? We are doing the same code and the same STM32

antonius
Senior
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
Senior
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
Senior
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
Senior
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
Senior
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);

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
Up vote any posts that you find helpful, it shows what's working..
antonius
Senior
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
Senior
Posted on April 19, 2014 at 05:11

do you have example for it ? thanks

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
Up vote any posts that you find helpful, it shows what's working..