by j.edwards » Oct 5, 2007 @ 12:59am
In my code I check for alpha == 0 (ignore that pixel and move to next), and alpha == 31 - just copy src pixel directly as no alpha necessary. Haven't done any performance tests, but am assuming it's quicker because most images I use have a large chunk of alpha=31 but with edge transparency.
Png can store a variety of pixel formats but I just use the simple 32bit - 8r, 8g, 8b, 8a - because it's easy to convert. Wouldn't be surprised if you can store in a 16bit 565 format and have an alpha channel as well though.
For png I used libpng (which also required zlib), which took a bit to get building, and I could never get it to build for ppc, which wasn't a big problem for my purposes because most of my images are icons so I convert them on desktop to a simple run-length encoding that isn't as well compressed as png obviously. if you need large images then you will need to spend the time to get it building for ppc so you can store them as png on the client. There are posts in this forum about using jpegs as well which compress better than pngs because png are lossless.
Depending on how each image is used I choose to keep it as run-length encoded in memory or expanded out to a full surface - if it can be drawn without dropping framerate as runlength then that is done to reduce memory, but if there are clipping issues or need maximum performance then expand them out.
It was a bit of work to get it all working, but has made life so much easier since. Now I can just work with the graphics tools like photoshop or inkscape, save as png, double click a batch file that converts all png images in the folder, package them as part of that process, F5 and go. If you are going to get back into ppc development seriously, it's probably worth your while getting it sorted out to start with.