PNG Alpha Channel Workaround

BlitzPlus Forums/BlitzPlus Programming/PNG Alpha Channel Workaround

Aeronux(Posted 2007) [#1]
EDIT: I've found a solution for my game using .alpha files created from PNG's that someone made. It works alright for -moderately- smaller images with alpha, so I'll live. But I'll keep this post incase anyone else has any knowledge on the subject they'd like to share :)

----------------------------------------------------------

Hello,

I have been searching like mad the past few days on ways to get Alpha masking, Alpha channel, or Alpha map support for PNG files, or any image for that matter.

The closest I've gotten is using BP's ReadPixelFast and WritePixelFast commands to do it's own blending based off of an image and an alpha file (separate).

There has got to be a better way to do this.

I think we should explore the options. Obviously, blitting and such is not a good choice. Sure, it might work for small graphics, but many projects (including mine) require more. Therefore, I think it would be a good idea to try to come up with some possible alternatives.

My ideas so far are:
1. Use a DLL for support. (However, which DLL? Can FreeImage handle it? If so, how can I use it for that?)
2. Use OpenGL in BlitzPlus. (But would it work for Alpha masked PNGs?)
3. Make a special function in BP that reads images not with the LoadImage command, but maybe just reading all the contents of the file and distinguishing between the mask and the actual image inside blitz and output it to a generated image or bank?
4. Make a function that only blends the Alpha image with the part it overlaps, not the whole buffer? (Do most of the functions already do this?)

I'm sure my theories are not correct for some of these.. But I have to find a way! I'm sure it would benefit everyone who uses BlitzPlus also. :)


Matty(Posted 2007) [#2]
There was a method that someone posted once, it is in the code archives under LoadTGA image.

The LoadTGA image function generates an image which is used to blit with which contains all pixels which have an alpha of 255 and an alpha of 0. This is blitted to the screen using the regular image commands. Then the individual pixels which have an alpha between 0 and 255 are plotted using writepixelfast/readpixelfast. For a speed boost again, if you are blitting against a static background then load the background image into a bank and read the pixel colors from the bank (or an array) instead of from the drawing buffer.