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-20 09:13 PM
So if I follow :
http://upload.wikimedia.org/wikipedia/commons/thumb/a/a7/Bilin3.png/220px-Bilin3.png from http://en.wikipedia.org/wiki/Bilinear_interpolation#Application_in_image_processing I will shring the picture by half ? for example 1024 x 768 becoming 512 x 384 ?2014-04-20 10:28 PM
I have test6.bmp which is 2x2 pixel 24 bits:
Is offset 0x36 which value = 0xC0 equal to coordinate 0,0 (red color) ? Red color is defined from 0x36 until 0x38 ? ==> 0xC0,0x40,0x40, then (0,1) green color 0x00,0xFF,0xFF, then (1,0),blue color = 0x82,0x04,0x40,then (1,1) yellow color = 0x20, 0xE0,0x40 and then following :2014-04-21 05:17 PM
Am I on the right calculation and way of thinking ?
thanks2014-04-21 05:30 PM
Does it always begin from offset 0x3E on the file no matter the resolution of the picture ?
It's the same for 1bit,8bits,16bits and 24bits picture ? I can see from every pictures, it's started from 0x36, reference :Start of pixel array (bitmap data)
36h 3
00 00 FF
0 0 255 Red, Pixel (0,1)
http://en.wikipedia.org/wiki/BMP_file_format#Bitmap_file_header
Thanks2014-04-26 09:36 PM
I tried this code :
//262K picture
uint16_t destx;
uint16_t desty;
delay_ms(1500);
LCD_Clear(Black);
res = f_open(&fsrc, filename, FA_READ);
f_read(&fsrc, hdr_256,
sizeof
(hdr_256),&bytesread);
// Read header
off = *((uint32_t *)&hdr_256[0x0A]);
// offset to rasters
sourcewidth = *((uint32_t *)&hdr_256[0x12]);
// X pixels
sourceheight = *((uint32_t *)&hdr_256[0x16]);
// Y pixels
f_lseek(&fsrc, off);
// Seek to the data
destx = 0;
desty = 0;
for
(y = 0, ny = 0; y < sourceheight; ny += 3, ny++)
{
if
(ny == 5)
{
y++;
ny = 0;
}
for
(x = 0,nx = 0; x < sourcewidth; x += 3,nx++)
{
uint32_t rgb;
if
(nx == 5)
{
x++;
nx = 0;
}
f_read(&fsrc, &rgb, 3, &bytesread);
// Read pixel B G R
// RRRRRRRRGGGGGGGGBBBBBBBB 8:8:8
// RRRRRGGGGGGBBBBB 5:6:5
rgb = ((rgb & 0xF80000) >> 8) | ((rgb & 0x00FC00) >> 5) | ((rgb & 0x0000F8) >> 3);
LCD_SetPoint(desty, destx, rgb);
destx++;
if
(destx == 320)
{
destx = 0;
desty++;
}
}
}
f_close(&fsrc);
delay_ms(2000);
for displaying :
http://iphotobucket.com/albums/p231/picture_77/test32_zpsa24eb6e1.png
http://iphotobucket.com/albums/p231/picture_77/test32_zpsa24eb6e1.png
but it's displaying :http://iphotobucket.com/albums/p231/picture_77/IMG_20140427_095513_zpsd8864b8e.jpg
Does anyone have a clue ? thanks2014-04-27 09:40 AM
Yes, the logic there seems rather broken, and the PNG won't be handled by BMP code
2014-04-27 04:26 PM
I'm not using *.png on my SD card, that's for sure, photo bucket convert it...
I tried this function
void LCD_BMP_reading_shrink_test(char filename[120])
{
char temp_buffer[100],line[512];
int count,z,bmpData,bmpAddr;
int x = 0;
int i,y = 0;
int xx, yy,ny,nx;
uint8_t hdr[0x28];
UINT bytesread;
uint8_t hdr_256[0x36];
static uint16_t w[256];
uint32_t off,sourcewidth,sourceheight,pixeloff;
//262K picture
uint16_t destx;
uint16_t desty;
delay_ms(1500);
LCD_Clear(Black);
res = f_open(&fsrc, filename, FA_READ);
f_read(&fsrc, hdr_256, sizeof(hdr_256),&bytesread); // Read header
off = *((uint32_t *)&hdr_256[0x0A]); // offset to rasters
sourcewidth = *((uint32_t *)&hdr_256[0x12]); // X pixels
sourceheight = *((uint32_t *)&hdr_256[0x16]); // Y pixels
pixeloff = off + (y * 1024 * 3) + (x * 3); // Assuming three bytes per pixel
//f_lseek(&fsrc, pixeloff); // Seek to the desired pixel
f_lseek(&fsrc, off); // Seek to the data
destx = 0;
desty = 0;
//for(y = 0, ny = 0; y <
sourceheight
; ny += 3, ny++)
for(
y
=
0
,
ny
=
0
; y < sourceheight; y += 3, ny++)
{
if (ny == 5)
{
y++;
ny
=
0
;
}
for(
x
=
0
,
nx
=
0
; x < sourcewidth; x += 3,nx++)
{
uint32_t rgb;
if (nx == 5)
{
x++;
nx
=
0
;
}
f_read(&fsrc, &rgb, 3, &bytesread); // Read pixel B G R
// RRRRRRRRGGGGGGGGBBBBBBBB 8:8:8
// RRRRRGGGGGGBBBBB 5:6:5
rgb = ((rgb & 0xF80000) >> 8) | ((rgb & 0x00FC00) >> 5) | ((rgb & 0x0000F8) >> 3);
LCD_SetPoint(desty, destx, rgb);
destx++;
if(destx == 320)
{
destx = 0;
desty++;
}
}
}
f_close(&fsrc);
delay_ms(2000);
}
I want to convert 1024*768 :
http://iphotobucket.com/albums/p231/picture_77/test32_zpsa24eb6e1.png
The result I got from that function :http://iphotobucket.com/albums/p231/picture_77/IMG_20140427_095513_zpsd8864b8e.jpg
Do you have idea where I miss here ? thanks2014-04-28 04:06 AM
I was trying to display
but I got like this on LCD : The code I used :
int
count,z,bmpData,bmpAddr;
int
x = 0;
int
i,y = 0;
int
xx, yy,ny,nx;
uint8_t hdr[0x28];
UINT
bytesread;
uint8_t hdr_256[0x36];
static
uint16_t w[256];
uint32_t off,sourcewidth,sourceheight,pixeloff;
//262K picture
uint16_t destx;
uint16_t desty;
delay_ms(1500);
LCD_Clear(Black);
res = f_open(&fsrc, filename, FA_READ);
f_read(&fsrc, hdr_256,
sizeof
(hdr_256),&bytesread);
// Read header
off = *((uint32_t *)&hdr_256[0x0A]);
// offset to rasters
sourcewidth = *((uint32_t *)&hdr_256[0x12]);
// X pixels
sourceheight = *((uint32_t *)&hdr_256[0x16]);
// Y pixels
destx = 0;
desty = 0;
//for(y = 0, ny = 0; y < sourceheight; ny += 3, ny++)
for
(y = 0, ny = 0; y < sourceheight; y += 3, ny++)
{
if
(ny == 5)
{
y++;
ny = 0;
}
for
(x = 0,nx = 0; x < sourcewidth; x += 3,nx++)
{
uint32_t rgb;
if
(nx == 5)
{
x++;
nx = 0;
}
pixeloff = off + (y * 1024 * 3) + (x * 3);
// Assuming three bytes per pixel
f_lseek(&fsrc, pixeloff);
// Seek to the desired pixel
//f_lseek(&fsrc, off); // Seek to the data
f_read(&fsrc, &rgb, 3, &bytesread);
// Read pixel B G R
// RRRRRRRRGGGGGGGGBBBBBBBB 8:8:8
// RRRRRGGGGGGBBBBB 5:6:5
rgb = ((rgb & 0xF80000) >> 8) | ((rgb & 0x00FC00) >> 5) | ((rgb & 0x0000F8) >> 3);
LCD_SetPoint(desty, destx, rgb);
//sprintf(temp_buffer,''%.2d'',rgb);printf(temp_buffer);printf(''
'');
destx++;
if
(destx == 320)
{
destx = 0;
desty++;
}
}
}
f_close(&fsrc);
delay_ms(2000);
Any clues ? thanks
2014-04-28 05:27 AM
int count,z,bmpData,bmpAddr;
int x = 0;
int i,y = 0;
int xx, yy;
uint8_t hdr[0x28];
UINT bytesread;
uint8_t hdr_256[0x36];
static uint16_t w[256];
uint32_t off,sourcewidth,sourceheight,pixeloff;
//262K picture
delay_ms(1500);
LCD_Clear(Black);
res = f_open(&fsrc, filename, FA_READ);
f_read(&fsrc, hdr_256, sizeof(hdr_256),&bytesread); // Read header
off = *((uint32_t *)&hdr_256[0x0A]); // offset to rasters
sourcewidth = *((uint32_t *)&hdr_256[0x12]); // X pixels
sourceheight = *((uint32_t *)&hdr_256[0x16]); // Y pixels
for(y = 0; y <
sourceheight
; y += 3)
{
for(
x
=
0
; x < sourcewidth; x += 3)
{
pixeloff
= off + (((y * sourcewidth) + x) * 3); // Assuming three bytes per pixel
f_lseek(&fsrc, pixeloff); // Seek to the desired pixel
f_read(&fsrc, &rgb, 3, &bytesread); // Read pixel B G R
// RRRRRRRRGGGGGGGGBBBBBBBB 8:8:8
// RRRRRGGGGGGBBBBB 5:6:5
rgb = ((rgb & 0xF80000) >> 8) | ((rgb & 0x00FC00) >> 5) | ((rgb & 0x0000F8) >> 3);
LCD_SetPoint(y/3, x/3, rgb);
}
}
f_close(&fsrc);
delay_ms(2000);
2014-04-28 05:38 AM
It does the task but why can't I see the white color ? suppose to be blue and white,
but on LCD blue and dot dot white not complete white ? Have a look... Thanks