Thread: LZW compression

    #1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Location
    New Zealand
    Posts
    4
    Rep Power
    0

    LZW compression


    Hey There!

    im wondering if anyone knows the basics of LZW compression and can give me some sample code (in c) of LZW in its most simple form (both encoding and decoding). im trying to get a handle on how it works but all the code i find is quite complex, i need something simple to get me started.

    Thanks anyone

    richard
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed God 1st Plane (5500 - 5999 posts)

    Join Date
    Oct 2000
    Location
    Back in the real world.
    Posts
    5,966
    Rep Power
    191
    LZW is not too hard. But you really should not learn from the code how it works. Code implementations are made for machines to read, not for humans. They probably contain many optimizations (eg. for speed) which make them hard to be read.

    The algorithm behind it is afaik "Huffman"-encoding, this is what you should read some theory about. (www.google.com)

    Short:
    Try to think of a book. In English afaik the letters "e" and "a" are used the most.
    In standard ASCII representation any letter uses 8 bits. Why not use only one bit for "e" and "a" like e=0 and a=1? YouŽll save a lot of space then...

    The algorithm afaik sorts all letters (any codes, not only letters) by their frequency and puts it into a table (the "key" if you see huffmann as a en/decoding algorithm).
    then the most often used one gets the shortest number of bits.

    do you understand what i want to say?
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jan 2002
    Location
    New Zealand
    Posts
    4
    Rep Power
    0
    ok thanks man :)

IMN logo majestic logo threadwatch logo seochat tools logo