Flash Player 10.1 on Google Nexus One [ by Thibault Imbert ]

Michael and I wanted to show you the Flash Player 10.1 running on the Google Nexus One, we tried different kind of websites, from typical FWA websites to games to video players. All of these applications from Yamago, Soleil Noir, Deezer, Canal+ or Ecodazoo were built for previous versions of the Flash Player some of […]

Native Rasterizer (bitmap slicing) and more [ by Thibault Imbert ]

Do you remember Banana Slice ? I already blogged about native rasterizing (bitmap slicing) in the Flash Player (here), but I realize I did not log a feature request in the Adobe bugs jira. I would love to see a native rasterizer in the Flash Player, which would rasterize or caches each frame of a […]

Optimizing Performance for the Adobe Flash Platform [ by Thibault Imbert ]

Paul Robertson and I just finished writing a paper about optimization for producing optimized content with the Flash Player 10.1. This whitepaper (87 pages) covers best practices for applications running inside a browser, but these best practices also apply to Adobe AIR or even the iPhone packager available in Flash CS5. It also covers some […]

New tutorial on ActionScript 3 performance testing

I just finished uploading a new tutorial showing how you can test the performance of your ActionScript 3 code. Grant Skinner recently released a great library called PerformanceTest which makes it easy to test out your code. In the tutorial I show how to use the library to test individual functions as well as a […]

New tutorial on augmented reality with FLARManager

I just uploaded a new tutorial on using the FLARManager library to create augmented reality applications. This library makes things much easier than using the FLARToolkit directly, especially when dealing with multiple markers. In this example I display a video on a 3D plane that follows the AR marker. The tutorial also covers how to […]

Using BitmapData.setVector for better performance

During the ByteArray workshop yesterday we wrote some code that parsed a PSD file and displayed it in the Flash Player. As part of this I showed setting the pixels of the BitmapData object using the setPixels method. I had heard that this method was slow but Thibault confirmed this for me. He suggested that I try a new method that was introduced in Flash Player 10 called setVector. This allows you to take a Vector object containing 32-bit floating point numbers and use it to set the pixels in the bitmap. Below is the original code using setPixel which required a nested for loop.

1
2
3
4
5
6
7
8
var bmd:BitmapData = new BitmapData(width, height);
for(var y:int=0; y<height; ++y)
{
    for(var x:int=0; x<width; ++x)
    {
        bmd.setPixel(x, y, r.readUnsignedByte()<<16 | g.readUnsignedByte()<<8 | b.readUnsignedByte());
    }          
}

The new code which takes advantage of setVector is shown below. There is one trick to getting this to work. You have to shift a value of 255 (aka 0xFF) to the far left byte as you need to provide an ARGB number for it to work. Otherwise your pixel would have an alpha of zero.

1
2
3
4
5
6
7
8
9
10
var numPixels:int = width*height;
var pixels:Vector.<uint> = new Vector.<uint>(numPixels, true);
           
for(i=0; i<numPixels; ++i)
{
    pixels[i] = 0xFF<<24 | r.readUnsignedByte()<<16 | g.readUnsignedByte()<<8 | b.readUnsignedByte();
}          
           
var bmd:BitmapData = new BitmapData(width, height);
bmd.setVector(new Rectangle(0, 0, width, height), pixels);

The BitmapData class is smart enough to put all the values into the right places in the bitmap so you don’t have to deal with nested loops.

Lee

New tutorial on Flash Builder 4 data integration

I just finished uploading a new tutorial that shows how easy it is to integrate server-side data into your Flex 4 applications using Flash Builder 4. In the example I display results from the Twitter search API in a datagrid without having to write a single line of code. These new features make it incredibly […]