Lossless image compression
dimula73 at gmail.com
Tue Feb 7 13:58:26 UTC 2012
> Before it can be useful, however, I need input about the API design.
> The plan is to have a low-level C++ template based compression
> library, allowing to code raw 8/16 bit RGB(A) pixel image data from/to
> memory, where the layout of the pixels (RGB vs. BGR, ARGB vs. RGBA,
> etc.) and the resulting code stream (bytes vs. machine words) can be
> customized via custom templates or template arguments.
I can tell what we currently have.
We have tiling, pooling and swapping at the level higher than the
compression itself. Every tile, which is 64 by 64 pixels is compressed
independently. The compressed data is written to a file mapped to RAM and
OS decides when this mapped data should be actually swapped out to the hard
drive. Of course the size of the mapped region is limited so the data is
flushed automatically when the "sliding window" of the mapped region moves
forward in the file. The size of the window is 16 MiB. It is chosen in
consideration to house 8-bit RGBA image of size 2048x2048 pixels (not
counting the reduction of size due to compression). No benchmarks were
actually done, so the size of the window might be not optimal. Actually, I
think we can make this window larger on modern machines, but I haven't
finished the benchmark yet.
For the actual compression of the tile data we use LZF algorithm. I did
some research on the compression times of LZO and LZF , . It turned
out that LZF has better times. It takes twice faster to compress the image
with LZF while keeping almost the same compression rate. One more thing I
found then is that it is faster to "linearize" colors before compression
and then compress the image than compress the image directly (RGBARGBA ->
RRGGBBAA). It boosts both the speed and the compression rate. The time of
the "linearization" itself is negligible in comparison with the boost it
give, so now we do it this way.
The compression is done at the level of the datamanager so it doesn't know
the colorspace we work in. It knows the size of a tile and the size of a
pixel. The algorithm is split into two classes: KisTileCompressor2  and
KisLzfCompression . The benchmarks are placed in .
 - http://dimula73.narod.ru/lzo_vs_lzf.pdf
In "Linearized" column you see the total time of linearization +
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the kimageshop