PageRenderTime 202ms CodeModel.GetById 120ms app.highlight 3ms RepoModel.GetById 78ms app.codeStats 0ms

/src/away3d/tools/utils/TextureUtils.as

http://github.com/away3d/away3d-core-fp11
ActionScript | 40 lines | 31 code | 9 blank | 0 comment | 8 complexity | 07900f0f23e8224b9d77d0d6e1d36b8e MD5 | raw file
 1package away3d.tools.utils
 2{
 3	import flash.display.BitmapData;
 4	
 5	public class TextureUtils
 6	{
 7		private static const MAX_SIZE:uint = 4096;
 8		
 9		public static function isBitmapDataValid(bitmapData:BitmapData):Boolean
10		{
11			if (bitmapData == null)
12				return true;
13			
14			return isDimensionValid(bitmapData.width) && isDimensionValid(bitmapData.height);
15		}
16		
17		public static function isDimensionValid(d:uint):Boolean
18		{
19			return d >= 1 && d <= MAX_SIZE && isPowerOfTwo(d);
20		}
21		
22		public static function isPowerOfTwo(value:int):Boolean
23		{
24			return value? ((value & -value) == value) : false;
25		}
26		
27		public static function getBestPowerOf2(value:uint):uint
28		{
29			var p:uint = 1;
30			
31			while (p < value)
32				p <<= 1;
33			
34			if (p > MAX_SIZE)
35				p = MAX_SIZE;
36			
37			return p;
38		}
39	}
40}