cocos2d/cocos2d-iphone — pull request #208 by KidstamaticApps (2012-05-24 21:58:19+00:00)
Title: Fixed a bug in CCTexture2D convert to RGB5A1 function

When you convert RGBA8888 texture to RGB5A1 texture and then render it on black background, you'll see a "ghost" image as if the texture is still RGBA8888.

On background lighter than the pixel color this effect disappers.
This happens because the old convertion function doesn't premultiply old RGB with new A.

As Result = sourceRGB + destination*(1-source A), then
if Destination = 0000, then Result = source.

Here comes the ghost!

We need to check new alpha value first (it may be 1 or 0) and depending on it whether convert RGB values or just set pixel to 0