PocketMatrix forums

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

PNG support

I've seen that ProcketFrog supports PNG graphic format...
It's cool but I'm wondering if you have a quick answer for... does it apply to alpha-channel of PNG too, including respective alpha-blending procedure? :wink:
Well, I guess Kzinti should answer this one, but until he does, I'll try my best.

PF:s LoadImage function uses the IMGDECMP.DLL supplied by IE5 on PPC to decode either a .BMP, .GIF, .JPG, .PNG or .XBM image into an intermediate 24 bit bitmap. This bitmap is used to create a Surface object and then it's memory is deallocated. LoadImage returns a pointer to the Surface it created (which needs to be deleted before exiting PF).

Because BMP doesn't support transparency, then neither transparent GIF:s nor alpha-channel PNG:s will be transparent in PF.

To get transparent behaviour out of PF, you save your images in a non transparent format having a special color for the transparent pixels. Remember the palette index of this color and then use Surface::SetColorMask(palette_index) to make the Surface transparent. To disable transparency of a Surface, use palete_index=-1 (this is the default color mask).

Sounds simple doesn't it. But there is a catch. The palette index has to be in regards to the standard palette used by the system. And this can be more or less hard to find out. I mostly use black as the transparent color since it always has index 0 and it has worked so far. And if you need black (#000000) in your image, then use a slightly (you will not notice the difference) brighter black (#030303) since it will get its own palette index (I think).
PocketFrog uses the imgdecmp.dll library to decompress a PNG file. The image is then accessible through a GDI device context which doesn't allow for alpha information.

If you need the alpha channel, you will have to use LIBPNG to load the images. Another issue you will have is that PocketFrog only supports one surface format: R5G6B5. This means that you will have to manage the image data yourself and write your own blitters.
adde wrote:
Sounds simple doesn't it. But there is a catch. The palette index has to be in regards to the standard palette used by the system. And this can be more or less hard to find out. I mostly use black as the transparent color since it always has index 0 and it has worked so far. And if you need black (#000000) in your image, then use a slightly (you will not notice the difference) brighter black (#030303) since it will get its own palette index (I think).


PF doesn't use any palette, everything is using the R5G6B5 pixel format. The value given to SetColorMask() is the actual color you want to be transparent.
OK!!! Thanks Kzinti for clearing this up. When I didn't find a palette I just asumed it used the standard palette, but this actually makes much more sense.
Viking · 21 Dec 2002, 20:53 UTC — Memory overflow when using HUGE images...
Ok... there is a bug with huge PNGs (I tried picture 9600*320 but 4 bits depth... it takes 50Kb of size but application hangs up on LoadImage PF's function.

Another thing: I want to use larger image as 10320*320 and 8 bits depth... (it's 43 screens of 240x320). It hangs up even on pure BITMAP resource of 3MB total size.

I guess the error is below... when you substitute width and height for above my values...

Code:
// Pitch is uint32_t aligned
MemoryGraphicBuffer::MemoryGraphicBuffer( int width, int height )
: GraphicBuffer( new Pixel[((width+1)&~1) * height], width, height, (width*2+3) & ~3 )
{
}


This method has been called from CreateSurface, that returns NULL as result for Pixels pointer. The Pixel is 16bit integer... maybe bug is here.

On my Jornada 568 the IE shows those picture very fine, but not PocketFrog...

P.S. Since all extentions as masked alphablending I did myself, I hope the developers will support existing version as promised... otherwise no bugreports anymore and I'll do all fixes myself for myself silently either, however it takes more time.