Lossless Codec Libraries

From MultimediaWiki
(Redirected from LCL)
Jump to navigation Jump to search

This page is based on the document 'Description of the LCL codecs (MSZH and ZLIB)' by Roberto Togni found at http://multimedia.cx/lcl.txt.

These two codecs, used in AVI files, were created by Kenji Oshima to compress digital animation. MSZH is based on a simple proprietary compressor while ZLIB uses deflate method found in the zlib library to compress frames.

This description is based on LCL Ver 2.23 dated 2000.09.20.

Basic Description

The codec converts original RGB24 image data to a target colorspace and compresses it with a selected algorithm. The codec can also remove unchanged frames and replace them with null frames, and can filter image data before compression. The only difference between avimszh and avizlib is in the stream compressor. PNG filtering is available only in avizlib. Except for null frames, there is no temporal compression, and all frames can be decoded independently from the others. Each AVI chunk contains one frame. In case of multithreaded mode the two sections are stored into the same chunk.

File Header

Codec information is stored at the end of BITMAPINFOHEADER structure into AVI header. This structure is 8 bytes longer than the standard structure.

struct {
  standard BITMAPINFOHEADER fields

  unsigned char unknown[4];
  unsigned char imagetype;
  unsigned char compression;
  unsigned char flags;
  unsigned char codec;
} BITMAPINFOHEADER_extended


  • unknown:
always [4, 0, 0, 0]
  • codec:
1 mszh
3 zlib
  • imagetype:
0 YUV 1:1:1
1 YUV 4:2:2
2 RGB24
3 YUV 4:1:1
4 YUV 2:1:1
5 YUV 4:2:0
  • compression:
0 mszh: compression
1 mszh: no compression, zlib: hispeed compression
9 zlib: high compression
-1 zlib: normal compression (zlib standard level)
  • flags:
bit 0: multithread used
bit 1: nullframe insertion used
bit 3: png fileter used (zlib only)

Image Types

(TODO: These should probably be moved to their own pages)

RGB24

This colorspace is laid out as standard Blue-Green-Red order color data, totaling 3 bytes per pixel.

YUV

YUV formats can be converted to RGB using the following equations:

   R = Y + 1.403V'
   G = Y - 0.344U' - 0.714V'
   B = Y + 1.770U'

or, in a programmer-friendly form (integer math)

   b = ((y << 20) + u * 1858076 + 0x80000) >> 20;
   g = ((y << 20) - u * 360857 - v * 748830 + 0x80000) >> 20;
   r = ((y << 20) + v * 1470103 + 0x80000) >> 20;

Values are then clamped to 0-255 range.

Please note that these equations don't have the 128 offset value into U and V components.

YUV structure: packed format with various subsampling factors (TODO: add byte order and description for every YUV format)

Please note that byte order is different from standard YUV formats with the same name!

Compression

As the codec name suggests, all compressors are lossless.

Zlib compression

This mode uses the standard zlib deflate method. For algorithm description refer to the zlib docs. The compressor state is reset every frame (decode every frame independently). Compression codes (1, 9, -1) have the same meaning as zlib compression flags. Zlib does not require compression level at decompressor so the value is there only for informational purposes.

Mszh

No compression: Just does what it says, image is not compressed at all.

Mszh compression: Works by copying blocks from already decoded data. (TODO: add mszh decompression algorithm)

Flags

Multithreaded

The encoded image is split in two independent blocks. The decoder must decode them separately and concatenate the resulting images. (TODO: add length and offset fields)

Nullframe

If one frame is unchanged from the previous frame, the coder replaces the new frame with a null frame.

PNG Filter (zlib only)

It is unclear why this is called a PNG filter since it has nothing to do with filters used in pnglib. All filters share the same structure, but the implementation depends on the colorspace. PNG filters are line-based, first pixel is stored unchanged, then other values are stored as difference from the previous ones. The filter (if any) is applied between decompression and colorspace conversion.

(TODO: add structure for each pngfilter)