3

I'm using the native Flash PNGEncoder library to encode a byte array to PNG and it's taking about 300ms per image. Is there any thing I can do differently to speed it up or is there another library that is faster?

Here is my code:

http://pastebin.com/Q7MiWg9u - line 65

Note: The JPG encoder is about 10x slower than the PNG encoder but if one exists that is faster I would look into using JPG instead of PNGs.

Note: I don't have a problem using a JavaScript encoder if I can transfer the bitmap data out of Flash to the library and have it return before the AS3 library finishes.

1.21 gigawatts
  • 16,517
  • 32
  • 123
  • 231
  • possible duplicate of [jPeg encoder super slow, how to Optimize it?](http://stackoverflow.com/questions/15009938/jpeg-encoder-super-slow-how-to-optimize-it) – Vesper May 24 '14 at 11:17
  • It's said there to use `BitmapData.encode()` instead, if you're striving for performance. Maybe these encoders are unoptimized, deprecated and left for compatibility. (I had to do this within 10.1 Flash player, so I had no access to `BitmapData.encode()` and had to suffer 4-5s wait for 2880x2048 bitmap to encode.) – Vesper May 24 '14 at 11:31
  • Does your encoder have some speed options? The slow part of PNG encryption is searching the LZ buffer for matches. Usually encoders have a setting that limits the amount of searching. – user3344003 May 24 '14 at 20:01
  • @Vesper - I'll try that and run some tests. There are some encoding options which I'll also try. – 1.21 gigawatts May 26 '14 at 07:43

1 Answers1

2

This is a very nice article that might help you: http://jacksondunstan.com/articles/2143

There is a fast property of the PNGEncoderOptions which I guess is false by default. The article also shows benchmark comparison between different approaches.

There is also a follow-up which has more tests and techniques inside: http://jacksondunstan.com/articles/2152

So you can chose one of the listed there and test a few images to see how it works, but as you know - it pretty much depends no the image ;)

Hope that works!

Andrey Popov
  • 7,362
  • 4
  • 38
  • 58