Skip to content

Instantly share code, notes, and snippets.

@alecmce
Created January 31, 2012 04:37
Show Gist options
  • Save alecmce/1708844 to your computer and use it in GitHub Desktop.
Save alecmce/1708844 to your computer and use it in GitHub Desktop.
Neko BitmapData Bongo Madness
// due to Neko's 31 bit integers and other nonsense, when you set a bitmap data's alpha value
// through Neko and then read it back out, the number ranges from -127 to 127 rather than from
// 0 to 255. Bongo madness. To unbongo, convert as follows:
var bitmapData = new BitmapData(1, 1, true, {rgb:0, a:0});
for (i in 0...256)
{
bitmapData.setPixel32(0, 0, {rgb:0xFFFFFF, a:i});
var alpha = bitmapData.getPixel32(0, 0).a;
var converted = alpha < 0 ? 255 + alpha : alpha;
trace(i + ": " + alpha + " -> " + converted);
}
// i == converted
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment