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
Posted on April 18, 2014 at 14:06

Ok, I have the manual for the SSD part, do you have any manual/documentation/schematics for the BOARD you are using?

Can you see and image of the flowers, but with the wrong colours? I can't make out anything through the flash glare.

Perhaps you have some #defines for RED, GREEN or BLUE colours passed to the functions you are using? Or a cite to the library/code?
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 18, 2014 at 14:21

Yes I can see flower but the color is not right,

Yes I have define :

#define Blue 0x001F

#define Red 0xF800

#define Green 0x07E0

I attached the schematic, please check it out, thanks

________________

Attachments :

schematic_stm32.jpg : https://st--c.eu10.content.force.com/sfc/dist/version/download/?oid=00Db0000000YtG6&ids=0680X000006I1I8&d=%2Fa%2F0X0000000bkr%2Fdneyq8Z1q_k5BZnBTOBusZpTZSKu41Lfl2osoufSjeA&asPdf=false
Posted on April 18, 2014 at 15:08

// RRRRRRRRGGGGGGGGBBBBBBBB 8:8:8
// RRRRRGGGGGGBBBBB 5:6:5
pal = ((pal & 0xF80000) >> 8) | ((pal & 0x00FC00) >> 5) | ((pal & 0x0000F8) >> 3);

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 18, 2014 at 15:24

Thanks for the info,

May I know how can you get those values ?

antonius
Senior
Posted on April 18, 2014 at 15:26

I tested and it gave me the same result, only the color was changing to blueish...

do I miss something here ?

Posted on April 18, 2014 at 15:54

May I know how can you get those values ?

I'm attempting to translate the colour space formats.

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 18, 2014 at 23:21

From my SSD1298 panel

0690X0000060MmMQAU.gif

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 00:59

I'm using SSD1289, is it the same with SSD1298 ?

Here's the complete function I used


void LCD_DrawBMPFromFile()

{ 


char temp_buffer[100],line[512];

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;




uint16_t icon[300] =

{

0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 

0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 

0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 

0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 

0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 

0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 

0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 

0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 

0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 

0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff

};










printf(''LCD_DrawBMPFromFile Function....
'');

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

// LCD_Clear(Black);

//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);




f_close(&fsrc);


//display welcome to LCD

delay_init();

//LCD_Initializtion();

//write LCD RAM here



//LCD_SetCursor(239,0);

//LCD_DrawPicture(0,0,239,319,icon);


// int i, x, y;

//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, 0x3E);


for(y=1; y<
240
; y++)

{

for(
x
=
1
; 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, 0xF0F0); // Colour

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

else

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

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


b <<= 1;

}

} // x

} // y


f_close(&fsrc);

//second picture

delay_ms(1500);

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


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

f_lseek(&fsrc, 0x3E);


for(
y
=
1
; y<240; y++)

{

for(
x
=
1
; 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, 0xF0F0); // Colour

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

else

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

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


b <<= 1;

}

} // x

} // y


f_close(&fsrc);

delay_ms(1500);

//test3 bmp 

res
= 
f_open
(&fsrc, ''button1.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;

//UINT bytesread;


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


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

{

//LCD_SetPoint(y,x+i, b); // Colour


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

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

else

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


b <<= 1;

}

} // x

} // y


f_close(&fsrc);


delay_ms(1500);

//256 color bmp

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


f_read(&fsrc, hdr_256, sizeof(hdr), &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<256; 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 & 0x001F00) >> 5) | ((pal & 0x7E0000) >> 19) | ((pal & 0x0000F8) << 8); 

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

delay_ms(5000);

}

antonius
Senior
Posted on April 19, 2014 at 01:09


if(DeviceCode==0x8989)

{

LCD_WriteReg(0x0000,0x0001); LCD_Delay(5); /* ´ò¿ª¾§Õñ */

LCD_WriteReg(0x0003,0xA8A4); LCD_Delay(5); 

LCD_WriteReg(0x000C,0x0000); LCD_Delay(5); 

LCD_WriteReg(0x000D,0x080C); LCD_Delay(5); 

LCD_WriteReg(0x000E,0x2B00); LCD_Delay(5); 

LCD_WriteReg(0x001E,0x00B0); LCD_Delay(5); 

LCD_WriteReg(0x0001,0x2B3F); LCD_Delay(5); /* Çý¶¯Êä³ö¿ØÖÆ320*240 0x2B3F */

LCD_WriteReg(0x0002,0x0600); LCD_Delay(5);

LCD_WriteReg(0x0010,0x0000); LCD_Delay(5);

LCD_WriteReg(0x0011,0x6070); LCD_Delay(5); /* ¶¨ÒåÊý¾�?¸ñʽ 16λɫ ºáÆ�? 0x6070 */

//LCD_WriteReg(0x0011,0x4070); LCD_Delay(5); /* ¶¨ÒåÊý¾�?¸ñʽ 16λɫ ºáÆ�? 0x6070 262K page 41 SSD1289 datasheet */


LCD_WriteReg(0x0005,0x0000); LCD_Delay(5);

LCD_WriteReg(0x0006,0x0000); LCD_Delay(5);

LCD_WriteReg(0x0016,0xEF1C); LCD_Delay(5);

LCD_WriteReg(0x0017,0x0003); LCD_Delay(5);

LCD_WriteReg(0x0007,0x0133); LCD_Delay(5); 

LCD_WriteReg(0x000B,0x0000); LCD_Delay(5);

LCD_WriteReg(0x000F,0x0000); LCD_Delay(5); /* ɨÃ迪ʼµØÖ· */

LCD_WriteReg(0x0041,0x0000); LCD_Delay(5);

LCD_WriteReg(0x0042,0x0000); LCD_Delay(5);

LCD_WriteReg(0x0048,0x0000); LCD_Delay(5);

LCD_WriteReg(0x0049,0x013F); LCD_Delay(5);

LCD_WriteReg(0x004A,0x0000); LCD_Delay(5);

LCD_WriteReg(0x004B,0x0000); LCD_Delay(5);

LCD_WriteReg(0x0044,0xEF00); LCD_Delay(5);

LCD_WriteReg(0x0045,0x0000); LCD_Delay(5);

LCD_WriteReg(0x0046,0x013F); LCD_Delay(5);

LCD_WriteReg(0x0030,0x0707); LCD_Delay(5);

LCD_WriteReg(0x0031,0x0204); LCD_Delay(5);

LCD_WriteReg(0x0032,0x0204); LCD_Delay(5);

LCD_WriteReg(0x0033,0x0502); LCD_Delay(5);

LCD_WriteReg(0x0034,0x0507); LCD_Delay(5);

LCD_WriteReg(0x0035,0x0204); LCD_Delay(5);

LCD_WriteReg(0x0036,0x0204); LCD_Delay(5);

LCD_WriteReg(0x0037,0x0502); LCD_Delay(5);

LCD_WriteReg(0x003A,0x0302); LCD_Delay(5);

LCD_WriteReg(0x003B,0x0302); LCD_Delay(5);

LCD_WriteReg(0x0023,0x0000); LCD_Delay(5);

LCD_WriteReg(0x0024,0x0000); LCD_Delay(5);

LCD_WriteReg(0x0025,0x8000); LCD_Delay(5);

LCD_WriteReg(0x004f,0); /* �?�?Ê×Ö·0 */

LCD_WriteReg(0x004e,0); /* �?�?Ê×Ö·0 */

}
 My LCD initialization code, is it the same with SSD1298 ? may I see it please ? thanks

Posted on April 19, 2014 at 02:05

void lcd_init(void)
{
port_fsmc_init();
//GPIO_ResetBits(GPIOD,GPIO_Pin_3); 
//delay(500);
//GPIO_SetBits(GPIOD,GPIO_Pin_3); 
//delay(50);
GPIO_SetBits(GPIOF,GPIO_Pin_9);
delay(100);
DeviceCode = read_reg(0x0000);
DeviceCode = 0x8999;
if (DeviceCode == 0x8999)
{
// power supply setting
// set R07h at 0021h (GON=1,DTE=0,D[1:0]=01)
write_reg(0x07,0x0021);
// set R00h at 0001h (OSCEN=1)
write_reg(0x00,0x0001);
// set R07h at 0023h (GON=1,DTE=0,D[1:0]=11)
write_reg(0x07,0x0023);
// set R10h at 0000h (Exit sleep mode)
write_reg(0x10,0x0000);
// Wait 30ms
delay(3000);
// set R07h at 0033h (GON=1,DTE=1,D[1:0]=11)
write_reg(0x07,0x0033);
// Entry mode setting (R11h)
// R11H Entry mode
// vsmode DFM1 DFM0 TRANS OEDef WMode DMode1 DMode0 TY1 TY0 ID1 ID0 AM LG2 LG2 LG0
// 0 1 1 0 0 0 0 0 0 1 1 1 * 0 0 0
write_reg(0x11,0x6070);
// LCD driver AC setting (R02h)
write_reg(0x02,0x0600);
// power control 1
// DCT3 DCT2 DCT1 DCT0 BT2 BT1 BT0 0 DC3 DC2 DC1 DC0 AP2 AP1 AP0 0
// 1 0 1 0 1 0 0 0 1 0 1 0 0 1 0 0
// DCT[3:0] fosc/4 BT[2:0] DC{3:0] fosc/4
write_reg(0x03,0x0804);//0xA8A4
write_reg(0x0C,0x0000);//
write_reg(0x0D,0x080C);//
// power control 4
// 0 0 VCOMG VDV4 VDV3 VDV2 VDV1 VDV0 0 0 0 0 0 0 0 0
// 0 0 1 0 1 0 1 1 0 0 0 0 0 0 0 0
write_reg(0x0E,0x2900);
write_reg(0x1E,0x00B8);
write_reg(0x01,0x2B3F);//Çý¶¯Êä³ö¿ØÖÆ320*240 0x6B3F
write_reg(0x10,0x0000);
write_reg(0x05,0x0000);
write_reg(0x06,0x0000);
write_reg(0x16,0xEF1C);
write_reg(0x17,0x0003);
write_reg(0x07,0x0233);//0x0233
write_reg(0x0B,0x0000|(3<<6));
write_reg(0x0F,0x0000);//ɨÃ迪ʼµØÖ·
write_reg(0x41,0x0000);
write_reg(0x42,0x0000);
write_reg(0x48,0x0000);
write_reg(0x49,0x013F);
write_reg(0x4A,0x0000);
write_reg(0x4B,0x0000);
write_reg(0x44,0xEF00);
write_reg(0x45,0x0000);
write_reg(0x46,0x013F);
write_reg(0x30,0x0707);
write_reg(0x31,0x0204);
write_reg(0x32,0x0204);
write_reg(0x33,0x0502);
write_reg(0x34,0x0507);
write_reg(0x35,0x0204);
write_reg(0x36,0x0204);
write_reg(0x37,0x0502);
write_reg(0x3A,0x0302);
write_reg(0x3B,0x0302);
write_reg(0x23,0x0000);
write_reg(0x24,0x0000);
write_reg(0x25,0x8000); // 65hz
write_reg(0x4f,0); // �?�?Ê×Ö·0
write_reg(0x4e,0); // �?�?Ê×Ö·0
}
else
{
//printf(''LCD model is not recognized,DeviceCode = 0x%x!

'',DeviceCode);
//return;
}
//Êý¾�?×Ü�?ß²âÊÔ,ÓÃÓÚ²âÊÔÓ²¼þ�?¬½ÓÊÇ·ñÕý³£.
lcd_data_bus_test();
lcd_clear(Red);
}

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..