PNG 處理最佳化
[
PNG (Portable Network Graphics)] 已經成為今日相當重要的圖形格式,兼具品質與處理效能,而且沒有專利使用上的問題,近來連 [
APNG (Animation PNG)] 這樣以 PNG 為基礎的動態圖形格式也現身了。我最近有一份基礎研究就是希望能針對特定的硬體平台,改善大量 PNG 圖形的顯示處理,重點會在於 renderer speed 與 memory usage 上。當然啦,這種「改善」絕對沒辦法讀篇類似 [
Optimization in GCC] 的文章,把 CFLAGS 用力調整後 (Gentoo-ish?),就可以獲得顯著的提昇。
在這個 model 中,將會在短暫的時間內載入 35 到 75 個 PNG 圖檔,解析度基本上是 QCIF / CIF,renderer 必須快速的給予呈現與切換,對於資源有限的 Embedded Systems 來說,是個很特別的挑戰。所以我決定先在 x86 上透過 Intel MMX/SSE 指令級來作驗證,並且閱讀 [
A guide to PNG optimization] 一文做出發點。誠如 Cosmin Truţa 在這篇文章所提及 PNG 的特性:
Unlike other lossless compression schemes, PNG compression does not depend solely on the statistics of the input, but it may vary within wide limits, depending on the compressor's implementation. A good PNG compressor must be able to take informed decisions about the factors that affect the size of the output.
PNG 壓縮不參考統計模型的方式,而是依據底層壓縮器的實做,影響 PNG 大小的因素有:
- PNG 圖形的類型
- PNG delta filter
- Ziv-Lempel algorithm (LZ77) 的搜尋策略,依據 [zlib Reference Library] 這個參考的 Deflate 實做,透過 strategy 參數指定類型:
- Z_DEFAULT_STRATEGY = 0, the default greedy search strategy.
- Z_FILTERED = 1, a strategy in which the matches are accepted only if their length is 6 or bigger.
- Z_HUFFMAN_ONLY = 2, a fast strategy in which the Ziv-Lempel algorithm is entirely bypassed, and all the symbols from the input are encoded directly by the Huffman coder.
- Z_RLE = 3 (appeared in the zlib-1.2.x series), a fast strategy in which the LZ77 algorithm is essentially reduced to the Run-Length Encoding algorithm.
- Deflate encoder 內部 Huffman-coding buffer 的空間
該文後半部的 [PNG (lossless) optimization programs] 就羅列許多基於以上參數處理作出發的最佳化工具程式,而我傍晚就開始依據 [
How to optimize code for MMX processors] 一文的提示,開始研讀 libpng 裡面 MMX optimization implementations 以及 zlib compressions 可以最佳化處理的部份,著手驗證。
由 jserv 發表於 August 23, 2005 07:54 PM