Flash: More Efficient Blur filter Values
Friday, February 27th, 2009 by LuisLast year during the development of a project where blur filters were used extensively we put into practice several tips and tricks to be able to render this visual effects quicker.
What caught my attention on top of everything was something really obviuos, in fact it is mentioned in the Flash documentation (I never read every single line), values that are a power of 2 (such as 2, 4, 8, 16 and 32) are optimized to render more quickly than other values.
Having this into account, the problem (a fairly common problem in systems programming) was to locate the "next highest power of 2", whenever I need the value to be dynamic.
Here there are a few AS3 algorithms to find the next highest power of 2:
- var powerOf2:int=1;
- var val:int=456;
- while ( powerOf2 <val )
- {
- trace(powerOf2 <<= 1);
- }
- function nextPowerOfTwo( value_ : int ):int
- {
- value_--;
- value_ = (value_>> 1) | value_;
- value_ = (value_>> 2) | value_;
- value_ = (value_>> 4) | value_;
- value_ = (value_>> 8) | value_;
- value_ = (value_>> 16) | value_;
- value_++;
- return value_;
- }
- function nextPowerOfTwo( value_ : int ):int
- {
- return int(Math.pow(2,Math.ceil(Math.log(value_) / Math.log(2))));
- }



