View Full Version : What is the fastest way to get RGBA?
Ashenwraith
07-14-2009, 04:52 PM
What is the fastest and most efficient way to get RGBA from an image you don't want to display?
I don't care if it uses air or is backwards compatible with a previous version of the player.
Should I be using file io and reading in the bytes and writing my own parser?
Maybe loadBitmap and getPixel?
Are there certain tricks and optimizations to prevent excess work on the player's side?
If anyone has any examples or code that would be great too.
Tilpo
07-14-2009, 05:13 PM
It's called ARGB to be precise, but i think t's best to take a ook at the BitmapData class documentation (http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/display/BitmapData.html)
And do you mean the getPixel32() function or is it something else? anyway, I'd just check the documentation if i were you.
Ashenwraith
07-15-2009, 12:39 AM
It's called ARGB to be precise, but i think t's best to take a ook at the BitmapData class documentation (http://help.adobe.com/en_US/AS3LCR/Flash_10.0/flash/display/BitmapData.html)
And do you mean the getPixel32() function or is it something else? anyway, I'd just check the documentation if i were you.
1 - ARGB is just macromedia putting the A first. Most image formats are stored in RGB(A).
2 - I've read the documentation and it doesn't answer my question.
3 - If I used getpixel I would also use getpixel32 if the image first returned alpha support.
Anyways, thanks for your time.
I'll just make my own tests and benchmarks.
lordofduct
07-15-2009, 01:29 AM
ummm he answered your question though.
fastest way to get ARGB (as it would be in flash as it is the way it is defined bitwise in flash) is to use BitmapData objects and read utilize "getPixel32()". The main reason being that loading in just the data (i.e. using a URLLoader and loading it as a ByteArray) will result in the compressed data as a binary chunk. Loader will translate this for you and give you direct "bitmap" access to each pixel.
Anyways, your question isn't directly specific. There is two parts to what you are assuming.
loading of said data
accessing said data
both can be done a couple of ways and can be considered independent of each other.
so recap
fastest way to get pixel data? Use a BitmapData object to realize the info, and utilize getPixel32 to get the data (if no alpha is available the alpha value of getPixel32 will just be 0xFF).
fastest way to load the data? Probably the Loader object.
var loader:Loader = new Loader();
loader.contentLoaderInfo.addEventListener(Event.CO MPLETE, imageLoaded);
loader.load( new URLRequest("myImage") );
function imageLoaded(e:Event):void
{
var bmp:Bitmap = loader.content as Bitmap;
if (!bmp)
{
trace("file loaded was not an image");
return;
}
var bmd:BitmapData = bmp.bitmapData;
trace(bmd.getPixel32(14,14);//some arbitrary pixel
}
you can even use "getPixels()" to get a bytearray of a rectangular area of the BitmapData. They will be 32-bit and contain un-multiplied alpha info as well. As it is a ByteArray this is the only way to get it as there is no "read semi-short integer" method. Just a "read integer" method which assumes the integer is 32 bits in length.
|
vBulletin® v3.8.5, Copyright ©2000-2012, Jelsoft Enterprises Ltd.