Performance of PNG Actionscript file and user interface blocking

I am trying to use PNGEncoder to encode a bitmapData object in png ByteArray so that I can send data to the server. Everything would be peachy, except for bitmapData 4000x4000px, and when I run the PNGEncoder.encode function, the entire application stops (the user interface is blocked) for 5-8 seconds while it starts. Does anyone have any suggestions on how to not block it so badly, I read about how to split the process (since you cannot multi-threaded in AS3), but cannot find any sample code to break the process .

Thanks Sam

+4
source share
6 answers

There are basically two ways to do this.

a) Use pixel bending: You can turn off the operation to the pixel giant (a tint such as the language in as3). This has the advantage of using gpu in some cases, but it is also asynchronous and non-blocking (works in a different thread). But this requires a 10+ player. I have not seen the bender png pixel encoder, and frankly, this may not be possible (I'm not familiar with PNG encoding enough to say), but it may be an option. This is a measure of performance, the best you can get. More here

b) Use chuncking. Basically, you rewrite the encoder to encode blocks (rows, columns, or a smaller area) and connect them to the frame input event, each frame that you call further in the encoder until there is more encoding. Zeh has a neat LWZ chunked encoder with source code that can give you an idea of ​​the details.

Cheers Arthur

+3
source

In addition to Arthur's comment, you can also write it in C / C ++ for Alchemy , as alchemy supports green streams. Like PixelBender, Alchemy also requires Flash 10.

+4
source

Another shameless plugin!

You can use my recently completed PNGEncoder2 library (Flash 10+ is also required), which easily supports giant images. It performs correct asynchronous encoding without a single compression step at the end. Also, it is very fast ,-)

Take it from GitHub ( README ) and check the benchmark by comparing it to other encoders in my blog post.

It is very tuned for speed and uses Alchemy opcodes and domain memory to speed it up (thanks to haXe ), so it should be comparable to anything you compile with Alchemy.

+1
source

You can encode multiple PNG files separately and send them to the server. Once on the server you can restore a larger image.

0
source

This is for JPEG encoding, but should be useful - see this post http://segfaultlabs.com/blog/post/asynchronous-jpeg-encoding/

0
source

As Arthur Debert said, you can use chunking. I would suggest that instead of encoding once / frame you are trying to use setTimeout( chunkingFunction, 0 ); . A timeout with a delay of 0 ms will occur as soon as possible, allowing the process to process quickly, but without destroying the user interface.

0
source

All Articles