Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I do LZW decoding in Java?

Tags:

java

decoding

lzw

I have a database which contains picture data stored as a binary blob. The documentation says the data is encoded using LZW. I thought that I could decode it using the Zip or GZip input streams found in the Java library, but it didn't work - I got an exception that said the format of the data is not correct.

From what I've read, the library uses DEFLATE, which is not LZW. Also, I've read about some licensing problems for using the LZW algorithm.

What can I use to decode the data? Is there a library? Do I have to implement it myself? What about the licensing problems?

like image 471
Andrei Vajna II Avatar asked Mar 11 '10 12:03

Andrei Vajna II


2 Answers

I know the question is old, but I just wanted to add a great resource about LZW:

http://www.matthewflickinger.com/lab/whatsinagif/lzw_image_data.asp

It's more specifically about the use of LZW in GIF images, but it explains the compression and decompression algorithms pretty well.

like image 171
Thomas Levesque Avatar answered Nov 06 '22 12:11

Thomas Levesque


Here are a couple of links:

  • http://www.cs.sfu.ca/CC/365/li/squeeze/LZW.html

  • http://u.cs.biu.ac.il/~freskom1/AlgProg1/Progs/LZW.java

  • http://www.codeproject.com/KB/java/lzw.aspx

And there are others.

Indeed if the images are LZW compressed TIFF files, The Java Advanced Imaging API apparently supports decoding directly (though not encoding it seems).

like image 39
Stephen C Avatar answered Nov 06 '22 12:11

Stephen C