compression - LZW bit packing for GIF images in JavaScript -
I am working on a JavaScript application that can generate animated GIF images. GIF images use the LZW compression algorithm, and as such I need to implement it in JavaScript.
So far, I have found that the string (binary or not) can be aligned to an array of integers, then delete all this, see the pastebin link for the complete code (if you think that this Is required), but here I am running this snippet, showing that compression and decompression work fine:
var lzw = new LJW (8); Var input = "TOBEORNOTTOBEORTOBEORNOT #"; Var compressed = lzw.compress (input); Console.log (input); // "ToberototubeBarot #" console.log (compressed); // [84, 79, 66, 69, 79, 82, 78, 79, 84, 256, 258, 260, 265, 25 9, 261, 263, 35] console.log (lzw.decompress (compressed)); // "Toberototrobotroorer #" The problem is, now that I do not know how to make binary packing. If I understand correctly the LJW algorithm, then only the bit pattern can be fit on the 8-bit limitations before the narrow , the rest should be on the 9-bit limitations. I went through, and it seems that, I always align the least significant bit of a compressed pattern with the least significant bit of a byte; But I tried to do it and my GIF did not work, and GIF parser is not very clear about the failures, so I'm not sure whether it's due to compression or something else I like a big waste of bits too. Looks, so it only creates more suspicious approaches.
Can anyone tell me in the right direction?
Comments
Post a Comment