Mip map what?
True to my reputation here at Adobe I added a miniature feature into Flash Player 9 Update 3 (9.0.60.120). It is Mip mapping. The Wikipedia entry is nice, but there is an in depth article I highly recommend to anyone interested in the subject: Part 1 and Part 2. As described in the article we use the fast and simple box filtering as apposed to the more complex methods which are not really suitable for real-time rendering. So no Kaiser in the Flash Player. Neither do we have trilinear or anisotropic filtering, but then again they make more sense with real 3D graphics. And since we are still stuck in software only land for bitmap rendering I was not interested in a performance loss either.
Why do I call it a miniature feature? Because the whole feature occupies less than 1Kb of compressed code in the binary. This is the kind of changes we engineers in the Flash Player love. Extremely small in code size, large in impact.
If you feel kind of overwhelmed with the descriptions in these articles let me summarize that the feature does in more simple words: This feature improves the quality and performance of downscaled bitmaps. Not slightly downscaled, but anything which is scaled down by more than 50%. Mip maps are nothing more than precomputed smaller and higher quality versions of an original bitmap. They are used instead of the original bitmap when something is downscaled a lot.
A few words about the Flash Player implementation and its limitation might be worth talking about here:
Good and well, but how does 'normal' Flash content benefit? Any time you create something like an image gallery with small thumbnails which are based on larger bitmaps you will see better bitmap quality and slightly higher performance.
Will this feature ever make things look worse? Not unless you do something really dumb like downscaling heavily aliased images and still expect it to look pixelized.
I made up a quick and dirty demo which shows the reduced aliasing effect: http://www.kaourantin.net/swf/mipmap.html Make sure you have Flash Player Update 3 Beta 1 installed, otherwise the two samples will look exactly the same.
What about control on this feature? Can you select the threshold or select your own mip map bitmaps? No, right now everything is automatic. That might change in a next major revision of the Flash Player. And the threshold value, well, let me simply tell you that we use the standard OpenGL value which is <= 0.5. If you want to know how this actually works, here is I would express it in pseudo ActionScript 3, you graphic experts will get it right away:
Why do I call it a miniature feature? Because the whole feature occupies less than 1Kb of compressed code in the binary. This is the kind of changes we engineers in the Flash Player love. Extremely small in code size, large in impact.
If you feel kind of overwhelmed with the descriptions in these articles let me summarize that the feature does in more simple words: This feature improves the quality and performance of downscaled bitmaps. Not slightly downscaled, but anything which is scaled down by more than 50%. Mip maps are nothing more than precomputed smaller and higher quality versions of an original bitmap. They are used instead of the original bitmap when something is downscaled a lot.
A few words about the Flash Player implementation and its limitation might be worth talking about here:
- Mip maps are only created for 'static' bitmaps, e.g. anything like a JPEG, GIF or PNG you display via loadMovie(), a bitmap in the library or a BitmapData object. They do not apply to filtered objects or bitmap cached movie clips.
- In case of video things are more tricky. If smoothing is turned on the mip mapping applies since this is overall faster than rendering the original bitmap. For non-smoothed video mip mapping is not used since it would make things much slower.
- Mip maps level generation stops when it encounters an odd width or height. What does that mean? In the most extreme case it means that if you have a bitmap with an odd width or height pixel value to begin with, no mip map can be generated at all and therefore you will not see any benefit. This is unfortunately hard technical limitation. That also means that 'perfect' mip maps are generated from bitmaps which have a width and height which are 2^n, e.g. 256x256, 512x512, 1024x1024 etc. On average though it is enough to have bitmaps sizes which are dividable by 8, meaning you get at least 8 levels, f.ex. 640x128 -> 320x64 -> 160x32 -> 80x16 -> 40x8 -> 20x4 -> 10x2 -> 5x1.
- The quality improvements are more visible when smoothing in turned on for a particular bitmap.
Good and well, but how does 'normal' Flash content benefit? Any time you create something like an image gallery with small thumbnails which are based on larger bitmaps you will see better bitmap quality and slightly higher performance.
Will this feature ever make things look worse? Not unless you do something really dumb like downscaling heavily aliased images and still expect it to look pixelized.
I made up a quick and dirty demo which shows the reduced aliasing effect: http://www.kaourantin.net/swf/mipmap.html Make sure you have Flash Player Update 3 Beta 1 installed, otherwise the two samples will look exactly the same.
What about control on this feature? Can you select the threshold or select your own mip map bitmaps? No, right now everything is automatic. That might change in a next major revision of the Flash Player. And the threshold value, well, let me simply tell you that we use the standard OpenGL value which is <= 0.5. If you want to know how this actually works, here is I would express it in pseudo ActionScript 3, you graphic experts will get it right away:
At last I should mention that mip maps apply to any SWF version 9 or newer content. SWF version 8 or lower will not use mip maps since we feared that this would impact on backwards compatibility.
var bitmapData:Array; // contains the mip map bitmaps
var m:Matrix; // the affine matrix to used for display
var i:int = 0;
while ( Math.sqrt(m.a*m.a+m.b*m.b) <= 0.5 &&
(bitmapData[i].width % 1) == 0 &&
(bitmapData[i].height % 1) == 0) {
// switch to next mip map level
i++;
m.a /= 2.0;
m.b /= 2.0;
m.c /= 2.0;
m.d /= 2.0;
m.tx /= 2.0;
m.ty /= 2.0;
}
mc.draw(bitmapData[i],m);
11 Comments:
Where did you come up with that formula? Is it based off of any of the links in your post?
this is huge! we had created a image gallery used by thousands of studios dealing with millions of photos. we had let flash scale the images and we had noticed some of this pixelization. they are going to love this.
THANK YOU!!! Tinic, thank you and your team for all of your hardwork on the Flash Player. This release is going to be fantastic!!! The Mip Map support and hardware scaling are a couple of things that I've wanted for a while and I'm sure a lot of AS3 developers have wanted this as well. Thanks for the addition.
Cheers,
Sam
Hi Tinic,
thank you for the posts about the update. Anyways I have two questions I would like to ask you about this and it would be nice if you could give an answer.
What impact has the mip maping on the BitmapData performance. Do you always calculate them new for every draw() or setPixel()?
Also on the constructor. I guess new BitmapData() will be slower now? Actually -- all BitmapData manipulations are affected by this?
For the downscaled versions. Do we get an extra performance boost for a scale of .5, .25, .125, .06125 etc?
I hope you have some time. The first question worries me a bit.
Tinic, I see inly pseudo-AS3 example here.
Is there real code example of how to use (switch on/off) mipmapping feature?
So what's going on with Linux Flash player development? What about Flex on Linux? Why all these rumors that iPhone won't have flash? You guys can't port it to ARM?
Are you guys working on fixing the bugs in the Linux flash player or did you just scrape something up to make us shut up, release it and then pull the project of the burner?
Well, i guess it´s a nice feature but it´s quite easy to do under flash 8 and it has been done.
just scale & copy the bitmap or mc to 50%, 25% 12.5% etc. during startup, put them in movieclips and use them as mipmap levels.
It's certainly not automatic, but it's still a good optimization and could be almost as fast as the plugin implementation, with more control.
;)
The pseudo code loos weired to me.
Shouldn't the condition be with % 2 instead of % 1?
And the last line of code should be inside the loop ...
Tinic, I hope you read this. Unsure of the best way to leave a comment for the Flash Player team.
Mipmapping makes a new site I'm working on look just FANTASTIC, we are using dozens of scaled down PNGs. (using 25% so the scaling will be fast)
I just put in a bit of an optimization which switches the stage quality to LOW while the camera is moving so that the camera moves are bleeding fast. However, it seems that all the mipmaps are flushed when I do this, because switching back to BEST quality hangs the player the same amount every time. I understand the reasoning behind this; for my particular application and ones like it, however, what we need is a way to flag bitmaps to not have their mipmaps flushed until the whole display object is GC'd.
Thanks Tinic, and if there's a better way to get in touch with the FP team for suggestions like this I recommend you sticky it on your blog!
Much thanks for all you do,
Roger
Glad to read articles like this. Thanks to author!
Excellent website. Good work. Very useful. I will bookmark!
Post a Comment
<< Home