开发者

Image coding library

Is there any good library for lossless image encoding/decoding that has compression rate more or less similar to PNG but decoding to raw RGB bitmap data would be much faster than PNG?

Also alpha transparency is needed, but not essential because, alpha channel could be taken from separate image.

Original problem lies in slowness of reading and decoding PNG files on iPhone using sta开发者_运维知识库ndard libraries. Obvious and the simples solution would have been storing raw RGB bitmap data, but then size of unpacked ipa is too large - 4 times larger than PNG files. So, I am trying to find some compromise solution.


As long as you don't need to compress on the iPhone, Lempel-Ziv decoding is quite fast. Whether you will get good compression is another question, however. Your first step should be to dump your image in raw ppm format and compress it with gzip. I've tried this on several SO screen shots, and because the number of colors is relatively small, the resulting files are about the same size as PNGs (slightly smaller). The test is

pngtopnm so.png | gzip -v9 | wc -c

If this test produces something small enough for your application, you're good to go—just run gzip on the raw bitmaps and use the tiny, fact libz decoder in your iPhone app. If that's not fast enough, you can try even faster decoders based on Lempel-Ziv.

If your images have a lot of colors and this doesn't work well, you might want to consider some form of lossy compression.


Why not just use the original raw RGB(A) data and compress and decompress it with zip, RLE, huffman etc?


Unless your images are constrained to a specific problem domain (e.g. computer generated screenshots) where a customized solution may be able to satisfy both compression ratio and speed of decoding objectives, these are generally tradeoffs where you'll have to choose between one or the other.

PNG compression is using entropy encoding techniques under the covers so re-implementing that on you own is unlikely to help.

You may pursue some sort of programmatic solution that "hides" the slowness from the user by lazy loading the images in a separate thread.


PNG compression is a a basic prediction (neighbour pixels) followed by Zip compression. If you really need lossless compression with low memory-CPU requirements, that strategy it's hard to beat... asumming you have a decent PNG creating library. The encoding bottleneck is the zip compression. (And, as another one has pointed out, bear in mind that decoding is much faster than coding). To just zip the raw image would be only marginally faster, and (except for very particular images) attain much lower compression efficiency.


Your best quick and dirty results are going to come from using the 7zip SDK to decode raw image data that has been formatted as ABGR (little endian). You can then blit this image data to the screen using UIKit APIs. If you want to take a look at example iOS code, do a google search on "AVAnimator iOS" and you will find an open source library that implements this approach. The main thing you need to do is make sure that each pixel of graphics data is already formatted in an optimal way for iOS, this is basically what xcode does when it prepares PNG files for use in and iOS project.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜