Wednesday, January 2, 2013

Making Calculations

NOTE: This post is personal notes. Not writing it to be understood by anyone else. Wondering if there is a way to extract alpha from a PNG using adobes PNG utility. To avoid this problem:
//TAKEN FROM STACK OVERFLOW:--------------------------------------------

Your problem is caused by the fact that Flash uses pre-multiplied alpha. Usually this is not a big issue, but it becomes very apparent if you have pixel values with very low alpha values which unfortunately are very common when you use a blurred soft-feathered brush. The pre-multiplication causes an information loss in the pixels - and when you have low alpha values the color values are effectively getting rounded down which when you are drawing slowly in your app and the same pixels are getting drawn over each other again and again will cause the area to get darker and darker. For some more details on the pre-multiplication issue check an old post of mine: http://www.quasimondo.com/archives/000665.php There is nothing you can do about this except if you handle the alpha channel and the rgb channel separately. But then you will also have to do all the compositing yourself which is not a trivial task and might slow down your app too much.

-------------------------------------------------------------------------
Hmm... Even if it was fixable, saving out PNG files with the correct alpha channel would still have problems. Don't use alpha channel.
 1234 5678  --Set bits describe which channel pixel exists on.
[1111 1111]R
[1111 1111]G
[1111 1111]B

Thus, each pixel becomes defined by 3 bits.
There are 8 possible combinations for bits:
BINARY  RGB-EQUIVALENT:

000 [000,000,000] BLACK
001 [000,000,255] BLUE
010 [000,255,000] GREEN
011 [000,255,255] CYAN
100 [255,000,000] RED
101 [255,000,255] MAGENTA
110 [255,255,000] YELLOW
111 [255,255,255] WHITE

Basically: Compressing 3bit color tilemap into a 24bit PNG. 24/3 = 8. Making file size 1/8th of what it would be otherwise. Of course, this limits your selection of tiles. But with clever auto-tiling, we've got something good here. Special items like entrance/exits will be defined in a text file. Shouldn't use a whole channel for something that is only ever going to use up, say TWO pixels on the entire level PNG.

No comments:

Post a Comment