/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

  1. package away3d.tools.utils
  2. {
  3. import flash.display.BitmapData;
  4. public class TextureUtils
  5. {
  6. private static const MAX_SIZE:uint = 4096;
  7. public static function isBitmapDataValid(bitmapData:BitmapData):Boolean
  8. {
  9. if (bitmapData == null)
  10. return true;
  11. return isDimensionValid(bitmapData.width) && isDimensionValid(bitmapData.height);
  12. }
  13. public static function isDimensionValid(d:uint):Boolean
  14. {
  15. return d >= 1 && d <= MAX_SIZE && isPowerOfTwo(d);
  16. }
  17. public static function isPowerOfTwo(value:int):Boolean
  18. {
  19. return value? ((value & -value) == value) : false;
  20. }
  21. public static function getBestPowerOf2(value:uint):uint
  22. {
  23. var p:uint = 1;
  24. while (p < value)
  25. p <<= 1;
  26. if (p > MAX_SIZE)
  27. p = MAX_SIZE;
  28. return p;
  29. }
  30. }
  31. }