Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[ Neko / Windows ] - BitmapTexture - BitmapData size vs performance #39

Open
Jeff94 opened this issue Mar 22, 2015 · 1 comment
Open

Comments

@Jeff94
Copy link

Jeff94 commented Mar 22, 2015

Hi all,

I have a performance problem to create a texture vs BitmapData size

Ex : "new BitmapTexture( new BitmapData( 2048, 2048, false ), false);"

Using 2048x2048 everything run perfectly under Flash but targeting Neko / Windows
my software hang for a second .... decreasing BitmapData size reduce the issue ( at 128*128
everything fine on all target ) ...

Edit 1 : Seems the problem comes from BitmapData.getRGBAPixels ( ~ 900ms to process a 2048 x 2048 BitmapData )

Edit 2 : Temporary ( Ugly !! :-) ) workaround :

******* openfl._v2.display.BitmapData.hx
public inline static function getRGBAPixels (bitmapData:BitmapData):ByteArray {
var data = bitmapData.getPixels (new Rectangle (0, 0, bitmapData.width, bitmapData.height));
var size = bitmapData.width * bitmapData.height;
var copy = new ByteArray(size-1);
copy.writeBytes( data, 1, 0);
return copy;
}

@Jeff94 Jeff94 changed the title BitmapTexture - BitmapData size vs performance > Neko & Windows [ neko & windows ] - BitmapTexture - BitmapData size vs performance Mar 28, 2015
@Jeff94 Jeff94 changed the title [ neko & windows ] - BitmapTexture - BitmapData size vs performance [ Neko / Windows ] - BitmapTexture - BitmapData size vs performance Mar 28, 2015
@ghost
Copy link

ghost commented Apr 21, 2015

A better way is

public inline static function getRGBAPixels (bitmapData:BitmapData):ByteArray {

    var rgbaData = new BitmapData( bitmapData.width, bitmapData.height, bitmapData.transparent );

    var rect = new Rectangle( 0, 0, bitmapData.width, bitmapData.height );
    var point = new Point( 0, 0 );

    rgbaData.copyChannel( bitmapData, rect, point, BitmapDataChannel.GREEN, BitmapDataChannel.RED );
    rgbaData.copyChannel( bitmapData, rect, point, BitmapDataChannel.BLUE, BitmapDataChannel.GREEN );
    rgbaData.copyChannel( bitmapData, rect, point, BitmapDataChannel.ALPHA, BitmapDataChannel.BLUE );
    rgbaData.copyChannel( bitmapData, rect, point, BitmapDataChannel.RED, BitmapDataChannel.ALPHA );

    return rgbaData.getPixels( rect );
}

My pull request for this change got merged recently: openfl/openfl#604

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant