.Bmp to LCD ??

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 2 and 3.

Moderators: Benj, Mods

cobra1
Posts: 175
Joined: Thu Feb 04, 2010 7:44 am
Has thanked: 3 times
Been thanked: 3 times
Contact:

Re: .Bmp to LCD ??

Postby cobra1 » Tue Feb 28, 2012 12:14 am

Hi,

I just wrote that piece of code and it counts ok, the first few numbers were in colour then 6 and 7 were white, then 8 onwards is just black characters.

Does this help?

/*Macro_SetForeColor_Start*/

#if MX_GCXLCD_TYPE == 1

if (Red > 0x3F)
Red = 0x3F;

if (Green > 0x1F)
Green = 0x1F;

if (Blue > 0x1F)
Blue = 0x1F;

GFX_Fore_Color = Green | (Red << 5);
GFX_Fore_Color = GFX_Fore_Color | (Blue << 11);

#else

if (Red > 7)
Red = 7;

if (Green > 7)
Green = 7;

if (Blue > 3)
Blue = 3;

Green = Green << 2;
Red = Red << 5;
GFX_Fore_Color = (Blue | Red) | Green;

#endif



/*Macro_SetForeColor_End*/

When i use the set_forecolour macro i use 3 numbers between 0 and 255 to set the colour.
That suggests to me that the numbers leaving the memory card need to be between 0 and 255, i think that as its 16bit data from the memory card its going to be a bigger number than 255, so the glcd software cant handle it.

cobra1
Posts: 175
Joined: Thu Feb 04, 2010 7:44 am
Has thanked: 3 times
Been thanked: 3 times
Contact:

Re: .Bmp to LCD ??

Postby cobra1 » Tue Feb 28, 2012 12:43 am

If i were to use 8bit images would that make things easier??
If so how would i adjust the code to suit, i tried to do it but the image was just all over the place on the LCD.

User avatar
JonnyW
Posts: 1230
Joined: Fri Oct 29, 2010 9:13 am
Location: Matrix Multimedia Ltd
Has thanked: 64 times
Been thanked: 306 times
Contact:

Re: .Bmp to LCD ??

Postby JonnyW » Tue Feb 28, 2012 11:19 am

Hi. I would avoid storing as 8-bit images. 8-bit colour usually uses a palette which is stored in 32-bit true colour. This would have to be loaded and would be an extra load of messing about, unless you hard-coded the palette, like some things do.

I'm afraid I would have to know the exact colours you see with your test to know what pixel format youre using. It may be that your LCD has an in-built palette, or that it has 8-bit true colour instead. For now, we could assume its 8 bit true colour.

True colour is stored in the bitmap on the card as red, green, blue components. When you load the pixel from your 16-bit image, the pixel has 5 bits of red then 5 bits of green then 5 bits of blue, and one spare:

Code: Select all

 rgb = ?bbbbbgggggrrrrr


What you need is to convert this to 8 bits, and looking at the code in your example we are assuming a format like:

Code: Select all

 rgb = bbgggrrr

Which is 3 bits for red and green, and 2 bits for blue.

If this is the case, then your test program will show {dark red, mid red, red, dark green, mid green, green, dark blue, blue}. Could you send me the test program so I could have a quick check?

To perform this conversion, with pix0 being your 16-bit per pixel colour and pix1 being your 8-bit per pixel colour:

Code: Select all

r = pix0 & 0x1F               // Extract red
g = (pix0 >> 5) & 0x1F        // Extract green
b = (pix0 >> 10) & 0x1F       // Extract blue
// Convert to 8 bpp
r = r >> 2                    // 3 bits for red
g = g >> 2                    // 3 bits for green
b = b >> 3                    // 2 bits for blue
// Build up the pixel
pix1 = r | (g << 3) | (b << 6)


You should be able to copy the code above into a calculation box as-is. If you just need the r, g, b components, you don't need to build up pix1 from these, and can pass them in direct.

Note: If you do this and it works but your blue and red are the wrong way round, Windows bitmaps store BGR (not RGB) in some formats - swap the 'b' and 'r' in Extract blue and Extract red and this should work OK.

Let me know if any of this works/makes sense.

Jonny