开发者

Custom DEFLATE implementation to speed up PNG encoding

开发者 https://www.devze.com 2023-03-12 17:04 出处:网络
I\'m optimizing a PNG encoder for use within Flash SWFs (but I\'m writing it in Haxe). I\'ve so far managed to speed things up a fair bit, mostly by using speedy memory read/writes.

I'm optimizing a PNG encoder for use within Flash SWFs (but I'm writing it in Haxe).

I've so far managed to speed things up a fair bit, mostly by using speedy memory read/writes.

While profiling my code, I noticed that about 75% of the time is spent in a single call to Flash's built-in compress() method, which uses the zlib algorithm (which uses DEFLATE in turn).

I'm not too fussy about compression ratio, but faster compression would be awesome. So, I was wondering if it's worthwhile to try to implement zlib/DEFLATE myself. A little searching has turned up the zlib C-implementation source, but it's not exactly light reading (or easy to port!).

Are there any simple implementations of zlib/DEFLATE that I could use as a starting point? I'd rather not have to wade through the two specs, especially since I don't know whether an implementation running i开发者_运维百科n AVM2 could even perform as fast as the native Flash one in the first place.


I don't think you will be able to achieve better performances with a non-native deflate algorithm. You might be able to run it asynchronously, though, which could make a difference. If you want to port it, I think it would be best to find an AS3 or JavaScript implementation, like https://github.com/dankogai/js-deflate . Good Luck!


I ended up implementing deflate/zlib from scratch, and have just released it, and the PNG encoder that's built on top of it, on GitHub (README). I also wrote a blog post about the PNG encoder, with a benchmark comparing it to other encoders.

The compression implementation is contained in DeflateStream.hx, and does manage to speed up the encoding process significantly (and allows it to be made completely asynchronous).


try to use fzip or ascompress

0

精彩评论

暂无评论...
验证码 换一张
取 消