Lempel-Ziv-Oberhumer Compressed Animation (LZA) version 2 --------------------------------------------------------- The following is a description of the LZA animation file format. The LZA format was invented by Brian Strack Jensen, aka. goto64 of Purple, and can be used freely. I have released two PC utilities for the LZA format. One is an animation player for MCGA and SVGA (VESA 2.0 only). The other utility is an animation file converter from FLI/FLC to LZA. Both utilities require 386 or higher, and at least 2Mb RAM. Contacting info: E-mail: purple@diku.dk WWW homepages for Purple: http://www.diku.dk/students/purple/ Snail Mail: Brian Jensen Lindevej 2 Jorlunde DK-3550 Slangerup Denmark ----------------------------------------------------------------------------- File format for LZA ------------------- General header at the beginning of the file: Size in bytes |Type |Description ----------------------------------------------------------------------- 6 |Char |File signature: "LZANIM" 1 |Byte |Version (currently: 2) 2 |Word |Number of frames in animation 2 |Word |Screen width 2 |Word |Screen height 4 |Longint |Pause between frames (millisec.) Following this header is the actual frames, each with a header: Size in bytes |Type |Description ----------------------------------------------------------------------- 1 |Byte |Frame type, 1 = pixels, 2 = palette 2 |Word |Number of blocks A palette frame has just one block, containing the RGB data for the 256 color palette. This is not compressed, so the palette size is always 768 bytes. The pixel blocks all have this header: Size in bytes |Type |Description ----------------------------------------------------------------------- 2 |Word |Horizontal lines to skip 1 |Byte |Block Type, 1 = LZO, 2 = SKIP 4 |LongInt |Size of the compressed data block NOTE: In version 1 of the LZA format, the block type is not part of the pixel block header. The only block type used in LZA v1 is LZO. Skip block data: Following the block header is the skip-compressed data block. It contains a number of packets. Each packet starts with a skip-count byte. This number of pixels can be skipped, since they are the same as the previous frame. The next byte is a pixel count. This is the number of pixels to be drawn. The color data for these pixels follows. Then the next packet follows. LZO block data: Following the block header, is the LZO compressed pixels in the block. The compression scheme used is LZO1C-9 (see LZO note at the end of this file). ----------------------------------------------------------------------------- Implementation notes -------------------- If you want to write a LZA player, there is a few things to remember. First of all, compared to flic, each line is NOT compressed individually. This means that decompression directly to the screen, can only be done with full screen animations. If you wish to play a non-full screen animation, or scale an animation, you need to decompress each frame to a virtual screen, before moving these data to the screen. You must also remember, that LZA skips the horizontal lines that are exactly the same as on the previous frame, so if you scale the animation, you must preserve the original frame. Pseudo code for LZA version 2 player: Initialize player, open LZA file, read the LZA header. Check signature and version. Clear the screen. For each frame in the animation do: Read frame header. If frame is a palette frame: Read 768 byte palette data, and set palette. Else if frame is a pixel frame: For each block in pixel frame: Read block header. Skip the number of lines stated in the header. Read the block's compressed data. If the block is a LZO block: Decompress and show the data using LZO1C. Else if the block is a skip block: While there are compressed bytes left: Read the skip count, and skip this number of pixels. Read the number of uncompressed pixels. For all uncompressed pixels: Copy the pixel to screen Pause for the number of milliseconds stated in the LZA header. Performance of LZA ------------------ When I designed LZA, my aim was to get a higher compression than FLI/FLC, without reducing the replay speed too much. Compared to FLI/FLC, LZA compresses better, when only a small part of a frame is repeated on the next frame. The replay speed is generally a little slower than FLI/FLC, but with an assembler implementation of the LZO1C-9 algorithm the replay speed could probably be improved. I have tested the LZA format with four FLI/FLC files. The files have the following characteristics: - PC2.FLI: Every frame is almost completely different from the previous. - SPACE2.FLC: Most of the top and bottom of the frame is the same in each frame, while the center part changes. - HIRES.FLC: Three stars change size or move across the unchanging background. - CAR01.FLC: Small rotating car on black background. Name |FLI/FLC size |LZA v1 size |LZA v2 size | ------------------------------------------------------- PC2.FLI |1376948 bytes |664886 bytes |665430 bytes | SPACE2.FLC | 675776 bytes |505834 bytes |497683 bytes | HIRES.FLC | 231904 bytes |598154 bytes |277074 bytes | CAR01.FLC | 83214 bytes | 69820 bytes | 69892 bytes | Name |LZA v1 size compared to FLI/FLC |LZA v2 size compared to FLI/FLC ---------------------------------------------------------------------------- PC2.FLI | 48.3 % | 48.3 % SPACE2.FLC | 74.9 % | 73.6 % HIRES.FLC |257.9 % |119.5 % CAR01.FLC | 83.9 % | 84.0 % The FLI/FLC files were created with Autodesk 3D Studio, while the LZA files were created with the FLI2LZA utility. The LZA v1 compression used in FLI2LZA is believed to be optimal in at least 99% of all animations with a resolution of 320x200 or higher. The LZA v2 compression scheme used in FLI2LZA is almost certainly not the optimal one very often, but it gives quite decent results. I have fiddled around with the skip-percent setting in FLI2LZA to find the best possible result. 80% was used with HIRES.FLC, 90% with PC2.FLI, 92% with SPACE2.FLC and 99% with CAR01.FLC. LZO Note -------- The LZO1C-9 algoritm was invented by Markus Franz Xaver Johannes Oberhumer. His C library for the LZO routines version 0.13 was released for Public Domain the 20th of June 1996. Note that there are certain restrictions to the use of the LZO library. These are stated in the GNU Library General Public License version 2, June 1991. His e-mail address is: markus.oberhumer@jk.uni-linz.ac.at His WWW homepage address is: http://www.infosys.tuwien.ac.at/Staff/lux/marco