Friday, 15 April 2011

LZW Decompression in C -


I have a LZW compressor / decompressor written in C.

In the initial table there are ASCII characters and to save it in the table, now each string has a prefix and a character saved in the list. is.

My compression works but

  Little; Title & gt; Playful & lt; / Title & gt; & Lt; Body & gt; & Lt; H1 & gt; Playful & lt; / H1> & Lt;  

; / Body & gt; & Lt; / Html & gt;

The output I get (note the missing 'E' and '<'):

  & lt; Title & gt; Playful & lt; / Title & gt; & Lt; Body & gt; & Lt; H1 & gt; Agile & lt; / H1> & Lt; / Body & gt; / Html & gt;  

This is the code I use (the relevant part):

  zero extension (int * input, int inputSize) {// int precode, currcode Int previousCode; Int currentCode; Int nextCode = 256; Start with a single dictionary of 255 characters; Init (); // prevcode = read code in a previouscode = input [0]; Int pointer = 1; // While (there is still data to read) (pointer  = next code) printf ("!"); // XXX has not been implemented yet! CurrentCode = decode (currentcode); // Add a new code in the string table dictionary Add (lastcode, currentcode, nextCode ++); // prevcode = currcode previouscode = currentCode; }} Int decode (int code) {int letter; Int temporary; If (code> 255) {// decode character = dictionary cursor (code); Temp = decode (dictionary;); // repetition} and {character = code; // ASCII temp = code; } Append character (character); // Output Return to Temp; }  

Can you see it? I'll be grateful.

Your decode function returns the first letter in the string. You should add this character to the dictionary, but if you should do it not set previousCode then your code should look like this:

  ... first-hand = decode (currentCode); DictionaryAdd (PreviousCode, First Time, next code ++); PreviousCode = currentCode; ...  

No comments:

Post a Comment