Sign in to follow this  
Eps

LZH Compression

Recommended Posts

I've just finished up a huffman compression file packer and am rather disappointed with the level of compression when dealing with binary data. LZH seems like the next logical step as it would offer better compression and uses a familar technique (the h stands for huffman.) I can't seem to find any good articles on how this compression works and would appreciate it if I could get pointed in the right direction.

Share this post


Link to post
Share on other sites
Yes I've looked there already :/

The problem with those links is that none offer an explanation of what the algorithm is. I'd rather have an explanation than a code example. That said, I can deal with a code example if it is commented (I'd rather understand that just perform a copy paste.) Some of those links have code examples but none are commented and are also in pascal. I don't understand a alot of the syntax that I see there.

So what I'm looking for is a link to an explanation, a code example in C++, or an explanation from one of the forums members if they would be so gracious :D

Share this post


Link to post
Share on other sites
Well it's been a while since I've looked at it so I can't really give you an in depth explanation, but IIRC the basic idea behind LZH is that it uses dynamic huffman codes instead of the static ones you'd be using currently. Think of it this way, as you move through a block of data the probability of any one symbol appearing isn't constant. For example, the number 10 might occur regularly in the first half of a file but not at all in the second half.

To do this you use what is called a sliding window. For any symbol, the hoffman code for that symbol is determined only from the probabilities in the current window, not from the entire file. Here, take a look at some dodgy ASCII art.....

currently encoding
|
data: 0 1 2 3 1 2 3 1 2 3 0 0 0 1 0 0 2 0
|<----window----->|

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this