From Data Crystal
Revision as of 05:57, 20 May 2006 by (talk)
Jump to: navigation, search

Compression is any process that transforms data so that it takes less storage. The process must be reversible, so that the original data can be obtained. Compression works by exploiting the fact that most data has high redundancy; that is, that given a set of data there will generally be strings that occur much more frequently than others.

Below, some common compression methods used in games are described. When looking at the examples, keep in mind that they are only to illustrate the concepts, and actual implementations may store the data very differently.

RLE (Run Length Encoding)

RLE is the simplest type of compression, in which a run (a sequence consisting of one byte repeated) is replaced with the byte along with the length of the run.

Here is an example of RLE. Given the data

<tt>4B 68 61 61 61 61 61 61 61 6E 21</tt>

a naive implementation of RLE might compress it as follows. The run-length bytes are shown in bold.

<tt>4B 01 68 01 61 07 6E 01 21 01</tt>

The string of 61s has been shrunk, but the one-byte "runs" have doubled in size, making the compressed data almost as long as the original. If it is known that the original data never uses the most significant bit (i.e. every byte is in the range of 00-7F), then this can be improved by using that bit to indicate a run, eliminating the need to store the length for single bytes. Now the data will become

<tt>4B 68 E1 07 6E 21</tt>

which is almost half the original size.

RLE was often used to compress maps in NES games. The NES had very little RAM, so a large map generally could not be loaded all at once. Because RLE allows the program to decompress from any point by counting lengths, the desired sections could be loaded while ignoring the rest of the map.


In dictionary compression, commonly used strings are replaced with one- or two- byte sequences that don't occur in the original data. For example, if the character ~ is defined as representing " dog", then the string

If you dog a dog during the dog days of summer, you'll be a dog tired dogcatcher.

would become

If you~ a~ during the~ days of summer, you'll be a~ tired~catcher.

In dictionary compression, one dictionary can be used to compress many small blocks, making it a good method for text.

Huffman coding

In Huffman coding, each character is assigned a sequence of bits to represent it. More common characters get shorter codes, while rarer characters get longer codes. It is named after David Huffman, who discovered an algorithm for generating an optimal code given a set of character frequencies.

Example: With the code 000=e, 001=g, 010=C, 011=(end), 10=a, 11=b, the string "Cabbage" will become 010 10 11 11 10 001 000 011. Putting the bits into groups of 8 to form bytes, this becomes 01010111 11000100 00110000, or "WÄ0".

Like dictionary compression, Huffman coding is often used for text because one Huffman code can be used to compress many small blocks of text.

LZSS (Lempel-Ziv-Storer-Szymanski)

LZSS is sort of like dictionary compression, except that instead of a fixed dictionary, the dictionary is a "sliding window" that consists of the last few kilobytes of data. In LZSS there are single bytes, and references to strings inside the sliding window. These references contain a displacement that says how many bytes before the current position the string starts at, and the length. These are distinguished by the use of "flag bytes", in which each bit determines whether a byte or a reference is to come.

LZSS is sometimes confused with LZ77, an older compression type that it is based on. LZ77 did not use flag bytes, instead the compressed data just alternated between bytes and references.

LZSS works well for large blocks of data, but poorly for small blocks due to the lack of repetition. It is often used for graphics, tiles, and maps. Chrono Trigger uses LZSS, as does the standard GBA compression

Excuse for my post but I do not have money to buy meal to my children. Forgive me please. motivational games young sweet girls history of dogs michigan adult clubs microsoft windows xp home edition japanese language download preemployment job verification specialists free dogs vip auto free hindi music downloading caitlin corbett music hog catch dogs hog dogs for sale hog dogs rich mullins sheet music adult entertainment in jacksonville fla st joseph s college suffolk free adult catalog discount car rental honolulu download playstation games tony s furniture troy nc french provincial furniture sex gadgets las vegas real estate agents sharpe spray gun home page vortox air filters music sounds home remedy for garden repellent for dogs and cats home made spells home security dogs stevie wonder home pics of sex postions world cup2006 fantasy game sex slave torture real estate in mn how to tell if your dog is pregnant herts car rental hoodles of dogs norris real estate hopkinton ma sheep dogs free online games largest shooter lunasarabella email sex couple network girls and hand jobs call of duty finest hour cheats real estate sale prescott arizona sexy cartoon girl desktops getting what you both want without playing games closing costs for real estate sale illinois basic html codes hot dogs at wedding receptions jobs and southpole midnight club 2 cheats kamatari sex free adult online flash games the best car for the best price sex christians honeymoon colibre furniture marydale catholic school for girls indianapolis indiana gay gods brandon furniture store home beer brew kit english football live songs paper auto floor mats hotels chantilly va dogs bizzaro sex rank philadelphia college of osteopathic medicine pschology mexico music and art belfast hotels html codes for music on page air vice marshalls wilson community college north carolina pokemon cheats game boy advance house dogs lawn furniture tables freeware games kids greek dog air rifles springer music file conversions cheap dropshipping game video wholesale home business opportunity canada caldwell idaho real estate white wolf games heartland home care hospice part time home jobs how are dogs related to wolves job opportunity in hawaii teenage music purchase trends preipod gay sex artist auto blog last minute deals air dog repellents lawrence o toole football home improvement companies in toledo normal obs for a 3 yr old girl japanese car sterios steps to buying a home how do dogs see garage music haverfordwest horny girls how do dogs sleep red sea hotels real estate research home made gate latch sports and entertainment marketing jobs what kind of jobs can i get with a psychology degree adult group activities real estate mortgage form starband 360 home network haunted house on sex hill thor how does a hairball cough sound in dogs lesbian sex comic sex bratislava compressed air powered vehicle southern oaks girl school renoir young girl in pink cma discount real estate listing in phoenix az real estate in arkansasbentonville how dogs evolved from wolves gorgeous page 3 girls gay adonis cheats for starwars battlefront 2 for pc philippine air lines music box memories lyrics delta air cargo kentucky real estate for sale city of fort bragg nc jobs how long do dogs stay in heat take this job and shove it lyric neonatologist jobs in newzealand will new job come out in maplestory free home job legitimate work how many breeds of dogs are there pembroke and petawawa dog breeders kid rap music girl next door movie how many dogs are aloud on a jr iditarod sled team hardcore gay male porn stories linon home decor product personal fan with color and music kennels for dogs is it normal not to have oral sex resident evil 4 cheats and walkthroughs not that kind of girl lyrics by jojo how many dogs survived the sinking of the titanic steamship html image fade code westers music wisconsin real estate for sale download sims game 1 euro job zwangsarbeit car parking at manchester airport how much chocolate is fatle to dogs