PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

ColorKey with PNG files

I can blit a bitmap image with a color key just fine. But if I try to blit a png file - (loaded as a resource) the color key only works if I compile for the Desktop. If I compile the same code for the Pocket PC (emulators 2000 and 2002) then the color key dosn't work (i.e no transparent areas). Are the color values changing slightly due to the different color depth capabilities of the end displays - and why dont I see the problem with a bmp loaded as a resource?
Strange. Could you try the following code and let me know what's going on:

Code:
COLORREF transcolor;
mypngsurface.GetPixel(0, 0, &transcolor);

TCHAR str[128];
_stprintf(str, TEXT("r=%u, g=%u, b=%u"), GetRValue(transcolor), GetGColor(transcolor), GetBValue(transcolor));
backbuffer.DrawText(10, 10, str, RGB(255, 255, 0), 0, NULL, NULL);


Assuming pixel [0, 0] is the same as your color key the RGB values should differ...

/Johan
Johan - Thanks for the speedy response. I will read back one of the transparency pixels tonight and let you know the result.
Johan - I read back some of the color key pixels - yes they are changing, they are different for Win XP and CE. It dosn't matter if they are png or BMP or loaded from disk or resource.
Original color (0,0,0)
WinXP read pixel (0,0,0) CE (248,248,240)

Original color (255,0,255)
WinXP (204,204,204)

I have changed code and graphics to ensure first pixel is color key - now read first pixel and use that as the color key.
Hi,

Lots of oddities here. My guess is that:

(1) You must be using an old version of GapiDraw.
and
(2) You do not use the same images on the WinXP and WinCE projects

Test the latest sample applications. They use PNG and color keys and work perfectly on both WinXP, Win98, WinME and WinCE.

/Johan
Johan
I found some time to look at this a bit more carefully. Using GD104 - code is common to all compiled versions. Get the same results in all OS enviroments and all file formats for the following:
Pixel set to (0,0,0) read back (0,0,0)
Pixel set to (255,255,255) read back (248,252,248)
Pixel set to (255,0,255) read back (248,0,248).
This is not a problem when you set the color key to the actual bmp pixel value - either there is a tolerance on the key - or the same variation happens to the key.
The problem occurs with png images (made with PaintShopPro 7). If you set an area to black then it is read back in a surface as black. But if you have an area on the png file as transparent (not color keyed - but no color) then when compiled for desktop the area reads back as (0,0,0) but when compiled for WinCe the area reads back as (248,248,240).
If you want I can send you a sample image that does this.
Hi,

Ok, I know what's wrong here. This is not related to GapiDraw.

GapiDraw uses a built in library in the Pocket PC called IMGDECMP.DLL. This library is responsible for decoding GIF, JPG and PNG images.

IMGDECMP.DLL however has a severe bug where transparent parts in GIF and PNG images ALWAYS are filled with white color! So if you have a GIF or PNG image, even if the transparent parts are set to render as black the Pocket PC will always render them as white.

Why does IMGDECMP.DLL do this? Simple - it's due to a bug in Pocket Internet Explorer. :) Create an image consisting of some pure white elements. Make some parts of the image transparent and save as GIF. Create a colored web page and place your GIF there. When shown in Pocket IE ALL white elements of your picture will be transparent. Basically the process works like this:

(1) IMGDECMP.DLL: Load GIF or PNG. Replace all transparent parts with white color. Send image to Pocket IE.
(2) Render background on web page. Take image from IMGDECMP.DLL. Replace all white parts with background. So what if the picture contains white elements that should not be transparent, all web pages are white anyways in my world.

You can clearly see this error if you open the web page http://www.opentrek.com/ in Pocket Internet Explorer. Check the main logo for black dots (they should be white).

GapiDraw sets the correct flags in calling the IMGDECMP.DLL, so if IMGDECMP.DLL is corrected in a future PPC update (not very probable) GapiDraw would work ok on these future devices.

Until then: Stay away from transparent PNGs and GIFs. Always make them opaque and draw "transparent" parts with for example a pink color.

I will update the documentation on CreateSurface and SetColorKey / GetColorKey to also reflect PNG images.

/Johan