自定义 DEFLATE 实现以加速 PNG 编码

发布于 2024-11-15 06:38:00 字数 888 浏览 4 评论 0原文

我正在优化在 Flash SWF 中使用的 PNG 编码器(但我在 Haxe 中编写它)。

到目前为止,我已经成功地加快了速度,主要是通过使用 快速内存读/写

在分析我的代码时,我注意到大约 75% 的时间花费在对 Flash 内置 compress() 方法,该方法使用了 zlib 算法(依次使用 DEFLATE)。

我对压缩比不太挑剔,但是更快压缩就很棒了。所以,我想知道是否值得尝试自己实现 zlib/DEFLATE。稍微搜索一下就找到了 zlib C 实现源代码,但它并不是很轻松的阅读(或者易于移植!)。

有没有 zlib/DEFLATE 的简单实现可以作为起点?我不想费力地浏览两个 规范,特别是因为我不知道在 AVM2 中运行的实现是否可以甚至一开始就与原生 Flash 一样快。

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 in AVM2 could even perform as fast as the native Flash one in the first place.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

简单气质女生网名 2024-11-22 06:38:00

我认为使用非本机放气算法无法获得更好的性能。不过,您也许能够异步运行它,这可能会有所不同。如果你想移植它,我认为最好找到 AS3 或 JavaScript 实现,例如 https:// /github.com/dankogai/js-deflate 。祝你好运!

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!

寄与心 2024-11-22 06:38:00

我最终从头开始实现 deflate/zlib,并刚刚在 GitHub 上发布了它以及基于它构建的 PNG 编码器 (自述文件)。我还写了一篇关于 PNG 编码器的博客文章,其中 基准测试将其与其他编码器进行比较。

压缩实现包含在 DeflateStream.hx 中,并且确实能够提高速度显着提高编码过程(并允许其完全异步)。

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).

夏の忆 2024-11-22 06:38:00

尝试使用 fzipascompress

try to use fzip or ascompress

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文