2014-04-11 02:21 AM
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-clue2014-04-16 09:51 PM
if I used
1.
for
(y=0; y<320; y++)
2.
{
3.
for
(x=0; x<240; x+=8)
// advance 8 pixels (one byte of bits)
I got :
Do you have a clue ? thanks
2014-04-17 08:25 AM
Got the x/y sizes switched
// 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_lseek(&fsrc, 0x3E); // Seek to the data
for(y=0; y<240; y++)
{
for(x=0; x<320; 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);
}
// For the specific BMP, 1-bit per pixel
{
int i, x, y, xx, yy;
uint8_t hdr[0x28];
UINT bytesread;
res = f_open(&fsrc, ''test.bmp'', FA_READ);
f_read(&fsrc, hdr, sizeof(hdr), &bytesread); // Read header
xx = *((uint32_t *)&hdr[0x12]); // X pixels (want multiple of 8)
yy = *((uint32_t *)&hdr[0x16]); // Y pixels
f_lseek(&fsrc, 0x3E); // Seek to the data
for(y=0; y<yy; y++)
{
for(x=0; x<xx; x+=8) // advance 8 pixels (one byte of bits)
{
uint8_t b;
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);
}
2014-04-17 06:59 PM
Thanks a lot, it works for the star, but why isn't it finished to the end of the screen ?
2014-04-17 07:00 PM
I haven't tried the second code, is it possible if I have 640x480 and resize directly to 320x240 without a code ( automatically resize )? thanks
2014-04-17 07:10 PM
I tested with different picture, it seems that the x/y is reversed ?
originally : on lcd :2014-04-17 07:20 PM
fixed :
for
(i=0; i<8; i++)
// Process bits in byte, MSB first
{
if
(b & 0x80)
// Pixel On?
LCD_SetPoint(y, x+i, 0xF0F0);
// Colour
else
LCD_SetPoint(y, x+i, 0x0000);
// Black
b <<= 1;
}
If I want to play with color, what should I change ? for example 256 color of BMP ?
2014-04-17 07:27 PM
2014-04-17 08:03 PM
For 256 colour, you'd need to process a byte at a time, index into the palette table to extract the 24-bit RGB data, and then you'd have to translate that into the colour space of your display.
2014-04-17 08:58 PM
so byte after 0x3E or after 0x36 since it's 256 color (offset 0x0A), then process a byte at a time, index into the palette table to extract the 24-bit RGB data ....
Am I right ? thanks2014-04-17 09:00 PM
Pixel format
In a bitmap image file on a disk or a bitmap image in memory, the pixels can be defined by a varying number of bits.
http://en.wikipedia.org/wiki/BMP_file_format#cite_note-DIBhelp-5
Each bit is an index into a table of 2 colors. An unset bit will refer to the first color table entry, and a set bit will refer to the last (second) color table entry.http://en.wikipedia.org/wiki/Windows_CE
only:http://en.wikipedia.org/wiki/BMP_file_format#cite_note-PSformats-16
). Each pixel value is a 2-bit index into a table of up to 4 colors.http://en.wikipedia.org/wiki/Nibble
.http://en.wikipedia.org/wiki/BMP_file_format#cite_note-DIBhelp-5
Each pixel value is a 4-bit index into a table of up to 16 colors.http://en.wikipedia.org/wiki/BMP_file_format#cite_note-DIBhelp-5