KCZI My image format ​

Kczi i my own image format. Developing this software was quite journey. All started as small project to compress image by using color dictionaries. Later it became a testing ground to various compression methods. Now KCZI version 7 supports two modes of compression. Indexed mode and YUV mode.

Compression in detail ​

Every image is broke down into regions. Creating sort of binary tree. Bigger regions represents places on images with less detail where compression can be more aggressive. Then regions are divided into blocks. Block is the smallest encoding unit. Each block can be compressed suing few available methods. Different methods are possible in YUV mode different are possible in indexed mode. To dive deeper read next sections. After serializing image all data except image header is compressed by ZSTD.

Regions and block visualization ​

blocks

Index mode ​

Index mode is simpler. Color palette is reduce and colors are indexed. Each region can reference one color palette but color palette can be referenced by multiple regions. Thanks to this similar region share palette reducing file weight. Each block is written as array of pixels - full resolution or just corners and inner part is interpolated by decoder.

YUV mode ​

YUV mode changes color model to yuv as first step. Reduce file size using chroma subsampling. Then there is 4 possible modes of compressing a block. Interpolation - works same as in indexed mode. Prediction mode - try to blend block up and block on left to get new block. TO be honest it's not working well. DCT uses discrete cosine transform to represent block as cosine coefficients, then quantizes them and serialize in zigzag order to get best image lossless compression ratio.

Results ​

On test image i got 95.5% compression without sharp drop in quality. Just take a look.

Original image 24.8MiB uncompressed ​

yanfei-orginal

Compressed in YUV mode 1.1MiB ​

yanfei-kczi

Speed ​

Wast time takes ZSTD compression. DCT uses some tricks to run pretty fast. First of all for most popular block sizes cosine function results are precalculated during compilation. Non standard sizes uses cache to store cosine values. Interpolation for some sizes is unrolled and precalculated.

Detailed docs ​

Detailed docs are only in Polish. read it here