public override AsRectangle getBounds(AsDisplayObject targetSpace, AsRectangle resultRect) { if ((resultRect == null)) { resultRect = new AsRectangle(); } if ((targetSpace == this)) { resultRect.x = getX(); resultRect.y = getY(); resultRect.width = mBitmapData.getWidth(); resultRect.height = mBitmapData.getHeight(); return(resultRect); } float minX = AsMathHelper.MAX_NUMBER; float maxX = -AsMathHelper.MAX_NUMBER; float minY = AsMathHelper.MAX_NUMBER; float maxY = -AsMathHelper.MAX_NUMBER; getTransformationMatrix(targetSpace, sHelperMatrix); sPosition.x = getX(); sPosition.y = getY(); AsGlobal.transformCoords(sHelperMatrix, sPosition.x, sPosition.y, sHelperPoint); minX = (((minX < sHelperPoint.x)) ? (minX) : (sHelperPoint.x)); maxX = (((maxX > sHelperPoint.x)) ? (maxX) : (sHelperPoint.x)); minY = (((minY < sHelperPoint.y)) ? (minY) : (sHelperPoint.y)); maxY = (((maxY > sHelperPoint.y)) ? (maxY) : (sHelperPoint.y)); sPosition.x = (sPosition.x + getBitmapData().getWidth()); AsGlobal.transformCoords(sHelperMatrix, sPosition.x, sPosition.y, sHelperPoint); minX = (((minX < sHelperPoint.x)) ? (minX) : (sHelperPoint.x)); maxX = (((maxX > sHelperPoint.x)) ? (maxX) : (sHelperPoint.x)); minY = (((minY < sHelperPoint.y)) ? (minY) : (sHelperPoint.y)); maxY = (((maxY > sHelperPoint.y)) ? (maxY) : (sHelperPoint.y)); sPosition.y = (sPosition.y + getBitmapData().getHeight()); AsGlobal.transformCoords(sHelperMatrix, sPosition.x, sPosition.y, sHelperPoint); minX = (((minX < sHelperPoint.x)) ? (minX) : (sHelperPoint.x)); maxX = (((maxX > sHelperPoint.x)) ? (maxX) : (sHelperPoint.x)); minY = (((minY < sHelperPoint.y)) ? (minY) : (sHelperPoint.y)); maxY = (((maxY > sHelperPoint.y)) ? (maxY) : (sHelperPoint.y)); sPosition.x = getX(); AsGlobal.transformCoords(sHelperMatrix, sPosition.x, sPosition.y, sHelperPoint); minX = (((minX < sHelperPoint.x)) ? (minX) : (sHelperPoint.x)); maxX = (((maxX > sHelperPoint.x)) ? (maxX) : (sHelperPoint.x)); minY = (((minY < sHelperPoint.y)) ? (minY) : (sHelperPoint.y)); maxY = (((maxY > sHelperPoint.y)) ? (maxY) : (sHelperPoint.y)); resultRect.x = minX; resultRect.y = minY; resultRect.width = (maxX - minX); resultRect.height = (maxY - minY); return(resultRect); }
public static void uploadBitmapData(bc.flash.display3D.textures.AsTexture nativeTexture, AsBitmapData data, bool generateMipmaps) { nativeTexture.uploadFromBitmapData(data); if(generateMipmaps && data.getWidth() > 1 && data.getHeight() > 1) { int currentWidth = data.getWidth() >> 1; int currentHeight = data.getHeight() >> 1; int level = 1; AsBitmapData canvas = new AsBitmapData(currentWidth, currentHeight, true, 0); AsMatrix transform = new AsMatrix(.5f, 0, 0, .5f); AsRectangle bounds = new AsRectangle(); while(currentWidth >= 1 || currentHeight >= 1) { bounds.width = currentWidth; bounds.height = currentHeight; canvas.fillRect(bounds, (uint)(0)); canvas.draw(data, transform, null, null, null, true); nativeTexture.uploadFromBitmapData(canvas, (uint)(level++)); transform.scale(0.5f, 0.5f); currentWidth = currentWidth >> 1; currentHeight = currentHeight >> 1; } canvas.dispose(); } }
public static AsTexture fromBitmapData(AsBitmapData data, bool generateMipMaps, bool optimizeForRenderTexture, float scale) { int origWidth = data.getWidth(); int origHeight = data.getHeight(); int legalWidth = AsGlobal.getNextPowerOfTwo(origWidth); int legalHeight = AsGlobal.getNextPowerOfTwo(origHeight); AsContext3D context = AsStarling.getContext(); AsBitmapData potData = null; if(context == null) { throw new AsMissingContextError(); } bc.flash.display3D.textures.AsTexture nativeTexture = context.createTexture(legalWidth, legalHeight, AsContext3DTextureFormat.BGRA, optimizeForRenderTexture); if(legalWidth > origWidth || legalHeight > origHeight) { potData = new AsBitmapData(legalWidth, legalHeight, true, 0); potData.copyPixels(data, data.getRect(), sOrigin); data = potData; } uploadBitmapData(nativeTexture, data, generateMipMaps); AsConcreteTexture concreteTexture = new AsConcreteTexture(nativeTexture, AsContext3DTextureFormat.BGRA, legalWidth, legalHeight, generateMipMaps, true, optimizeForRenderTexture, scale); if(AsStarling.getHandleLostContext()) { concreteTexture.restoreOnLostContext(data); } else { if(potData != null) { potData.dispose(); } } if(origWidth == legalWidth && origHeight == legalHeight) { return concreteTexture; } else { return new AsSubTexture(concreteTexture, new AsRectangle(0, 0, origWidth / scale, origHeight / scale), true); } }