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
Andrew Neil
Evangelist III
Posted on April 11, 2014 at 21:39

There is nothing in the BMP file format that's specific to STM32 - so just google it...

Posted on April 11, 2014 at 21:58

There are several formats, you'll need to decode the header, figure out the dimensions, figure out the colour depth or palette tables, and then convert the format into one that is suitable for your display.

As I recall some of the raster formats have the image paint from bottom-to-top, where as displays tend to be the other way round.

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 12, 2014 at 03:12

could you suggest me the keywords ?

I read already the first 56 bytes is the information of the picture,

so I just jump on it....

In my mind now is

320x240, so, the first line of the picture is 1x240, and repeat it until ...to complete the picture....

I'll make a test with simple black and white 320x240, (box shape) to understand the idea, am I right ?

Please see the file test_lcd.bmp....I'll use it for a test...or I need simpler to understand the idea ?

thanks

________________

Attachments :

test_lcd.bmp : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I1Ds&d=%2Fa%2F0X0000000bkt%2Fv8EB0ALhGNn9677rz6MNSQYnLsx40lfaa3070mU2jM0&asPdf=false
antonius
Senior
Posted on April 12, 2014 at 03:26

I saw hexa editor, mostly FF on test_lcd.bmp ?0690X00000602sxQAA.jpg

Posted on April 12, 2014 at 14:13

The picture data begins are 0x3E (62)

You'd need to decode the bit stream, describing each line, into a pixel format suitable for your display. It's a monochrome image, black/white going by the RGB palette.

http://www.ue.eti.pg.gda.pl/fpgalab/zadania.spartan3/zad_vga_struktura_pliku_bmp_en.html

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 17, 2014 at 01:26

Is it possible like this ?


LCD_WriteRAM_Prepare(); 
/* Prepare to write GRAM */

LCD_Clear(Yellow);

res = f_open( &fsrc , 
''test.bmp''
, FA_READ ); 

//res = f_open( &fsrc , ''Demo.TXT'' , FA_READ); 

printf
(
''res value = ''
);

sprintf
(temp_buffer,
''%.2d''
,res);
printf
(temp_buffer);
printf
(
''
''
);

printf
(
''Content of the file :''
);

NEXT_LINE;

while
(f_gets(line, 
sizeof
line, &fsrc))

printf
(line);



while
(y <320)

{

x = 0;

while
(x <240)

{


//LCD_SetPoint (x, y, 0x0F0F);

LCD_DrawPicture(0,0,239,319,line);

delay_ms(1);


x = x +1;

}

y = y +1;

} 

f_close(&fsrc);

Posted on April 17, 2014 at 02:34

Is it possible like this?

Not so much, I think you need to familiarize yourself with C File IO (and FatFs variants) and manipulating blocks of data.

http://rakanalysis.wordpress.com/2012/04/27/566/

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on April 17, 2014 at 04:34

This is cruder than I'd like,

// a more general solution would read dimensions from header
// and handle errors, etc.
// For the specific BMP, 1-bit per pixel, 320x240
{
int i, x, y;
res = f_open(&fsrc, ''test.bmp'', FA_READ);
f_seek(&fsrc, 0x3E, F_SEEK_SET); // Seek to the data
for(y=0; y<320; y++)
{
for(x=0; x<240; x+=8) // advance 8 pixels (one byte of bits)
{
uint8_t b;
UINT bytesread;
f_read(&fsrc, &b, 1, &bytesread); // Read byte
for(i=0; i<8; i++) // Process bits in byte, MSB first
{
if (b & 0x80) // Pixel On?
LCD_SetPoint(x + i, y, 0x0F0F); // Colour
else
LCD_SetPoint(x + i, y, 0x0000); // Black
b <<= 1;
}
} // x
} // y
f_close(&fsrc);
}

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 17, 2014 at 06:45

I modify a little bit,

f_seek(&fsrc, 0x3E, F_SEEK_SET); // Seek to the data <== I can't find SEEK_SET so I commented out, It can display bmp but smaller and 4 times, do I miss something in the loop ? suppose to be : 0690X00000602Q0QAI.bmp I got : 0690X00000602tHQAQ.jpg


LCD_SetCursor(0,0);

res = f_open(&fsrc, ''test1.bmp'', FA_READ);


//f_seek(&fsrc, 0x3E, F_SEEK_SET); // Seek to the data

//f_lseek(&fsrc, 0x0A);


for(y=0; y<320; y++)

{

for(x=0; x<240; x+=2) // advance 8 pixels (one byte of bits)

{

uint8_t b;

UINT bytesread;


f_read(&fsrc, &b, 1, &bytesread); // Read byte


for(i=0; i<8; i++) // Process bits in byte, MSB first

{

if (b & 0x80) // Pixel On?

LCD_SetPoint(x+1, y, 0x0000); // Colour

else

LCD_SetPoint(x+i, y, 0xF0F0); // Black


b <<= 1;

}

} // x

} // y


f_close(&fsrc);

thanks